Passed
Push — master ( 411303...7119c4 )
by
unknown
14:45 queued 11:45
created
download.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
     // file exists: return file for download
24 24
     header('Content-Type: application/octet-stream');
25 25
     header('Content-Disposition: attachment; filename="' .
26
-           addslashes($filename) . '"');
26
+            addslashes($filename) . '"');
27 27
     readfile($filepath);
28 28
 } else {
29 29
     // file does not exist: 404 Not Found
Please login to merge, or discard this patch.
FileHandler.class.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -7,37 +7,37 @@  discard block
 block discarded – undo
7 7
 
8 8
 abstract class FileHandler
9 9
 {
10
-  // Constants for allowed controls.
11
-  public const UP = 1;
12
-  public const DOWN = 2;
13
-  public const LEFT = 4;
14
-  public const RIGHT = 8;
15
-  public const ZOOMIN = 16;
16
-  public const ZOOMOUT = 32;
17
-  public const HOME = 64;
18
-  public const END = 128;
19
-  public const PRIOR = 256;
20
-  public const NEXT = 512;
21
-  public const DOWNLOAD = 1024;
22
-  public const COUNTERCLOCKWISE = 2048;
23
-  public const CLOCKWISE = 4096;
24
-
25
-  // Shortcuts for combinations of controls.
26
-  public const CURSOR = 15; // UP | DOWN | LEFT | RIGHT
27
-  public const ZOOM = 48;   // ZOOMIN | ZOOMOUT
28
-  public const ALL = 2047;
29
-
30
-  // up down left right zoomin zoomout home end prior next download
31
-
32
-  // protected $FILES = array();
33
-  // protected $UPLOAD_PATH;
34
-
35
-  abstract protected function getControls(): void;
36
-  abstract protected function show(string $path): void;
37
-
38
-  /** @return array<int,string> */
39
-  public static function getFileHandler(string $file): array
40
-  {
10
+    // Constants for allowed controls.
11
+    public const UP = 1;
12
+    public const DOWN = 2;
13
+    public const LEFT = 4;
14
+    public const RIGHT = 8;
15
+    public const ZOOMIN = 16;
16
+    public const ZOOMOUT = 32;
17
+    public const HOME = 64;
18
+    public const END = 128;
19
+    public const PRIOR = 256;
20
+    public const NEXT = 512;
21
+    public const DOWNLOAD = 1024;
22
+    public const COUNTERCLOCKWISE = 2048;
23
+    public const CLOCKWISE = 4096;
24
+
25
+    // Shortcuts for combinations of controls.
26
+    public const CURSOR = 15; // UP | DOWN | LEFT | RIGHT
27
+    public const ZOOM = 48;   // ZOOMIN | ZOOMOUT
28
+    public const ALL = 2047;
29
+
30
+    // up down left right zoomin zoomout home end prior next download
31
+
32
+    // protected $FILES = array();
33
+    // protected $UPLOAD_PATH;
34
+
35
+    abstract protected function getControls(): void;
36
+    abstract protected function show(string $path): void;
37
+
38
+    /** @return array<int,string> */
39
+    public static function getFileHandler(string $file): array
40
+    {
41 41
 
42 42
     // Get get directory, name and file extension
43 43
     $pathParts = pathinfo($file);
@@ -51,11 +51,11 @@  discard block
 block discarded – undo
51 51
     $imageHandler = '/usr/bin/feh --scale-down';
52 52
     $webHandler = '/usr/bin/x-www-browser';
53 53
     foreach (["/usr/lib/palma", "./scripts"] as $dir) {
54
-      $palmaBrowser = $dir . "/palma-browser";
55
-      if (file_exists($palmaBrowser)) {
54
+        $palmaBrowser = $dir . "/palma-browser";
55
+        if (file_exists($palmaBrowser)) {
56 56
         $webHandler = $palmaBrowser;
57 57
         break;
58
-      }
58
+        }
59 59
     }
60 60
     $avHandler = '/usr/bin/cvlc --no-audio';
61 61
     $officeApp = "writer";
@@ -63,33 +63,33 @@  discard block
 block discarded – undo
63 63
     // $params;
64 64
     // echo $ftype;
65 65
     if ($ftype === 'pdf') {
66
-      $fhandler = $pdfHandler;
66
+        $fhandler = $pdfHandler;
67 67
     } elseif ($ftype === 'gif' || $ftype === 'jpg' || $ftype === 'png') {
68
-      $fhandler = $imageHandler;
68
+        $fhandler = $imageHandler;
69 69
     } elseif ($ftype === 'html' || $ftype === 'url') {
70
-      $fhandler = $webHandler;
70
+        $fhandler = $webHandler;
71 71
     } elseif (
72 72
         $ftype === 'mpg' || $ftype === 'mpeg' || $ftype === 'avi' ||
73 73
         $ftype === 'mp3' || $ftype === 'mp4' || $ftype === 'wmv'
74 74
     ) {
75
-      $fhandler = $avHandler;
75
+        $fhandler = $avHandler;
76 76
     } else {
77
-      if ($ftype === 'doc' || $ftype === 'docx' || $ftype === 'odt' || $ftype === 'txt') {
77
+        if ($ftype === 'doc' || $ftype === 'docx' || $ftype === 'odt' || $ftype === 'txt') {
78 78
         $officeApp = "writer";
79
-      } elseif ($ftype === 'ppt' || $ftype === 'pptx' || $ftype === 'pps' || $ftype === 'ppsx' || $ftype === 'odp') {
79
+        } elseif ($ftype === 'ppt' || $ftype === 'pptx' || $ftype === 'pps' || $ftype === 'ppsx' || $ftype === 'odp') {
80 80
         $officeApp = "impress";
81
-      } elseif ($ftype === 'xls' || $ftype === 'xlsx' || $ftype === 'ods') {
81
+        } elseif ($ftype === 'xls' || $ftype === 'xlsx' || $ftype === 'ods') {
82 82
         $officeApp = "calc";
83
-      } elseif (shell_exec("/usr/bin/file -b '$file'") === "ASCII text") {
83
+        } elseif (shell_exec("/usr/bin/file -b '$file'") === "ASCII text") {
84 84
         $officeApp = "writer";
85
-      }
86
-      $convertedFile = convertOffice($file, $officeApp, $fdir, $fname);
87
-      if ($convertedFile) {
85
+        }
86
+        $convertedFile = convertOffice($file, $officeApp, $fdir, $fname);
87
+        if ($convertedFile) {
88 88
         $file = $convertedFile;
89 89
         $fhandler = $pdfHandler;
90
-      } else {
90
+        } else {
91 91
         $fhandler = "/usr/bin/libreoffice --'$officeApp' --nologo --norestore -o";
92
-      }
92
+        }
93 93
     }
94 94
 
95 95
     /*
@@ -104,20 +104,20 @@  discard block
 block discarded – undo
104 104
      */
105 105
 
106 106
     return array($fhandler, $file);
107
-  }
107
+    }
108 108
 }
109 109
 
110 110
 function convertOffice(string $inputFile, string $office, string $outputDir, string $fileName): mixed
111 111
 {
112
-  $cmd = "/usr/bin/libreoffice --headless" .
113
-         " --convert-to pdf:'$office'_pdf_Export" .
114
-         " --outdir '$outputDir'" .
115
-         " '$inputFile' >/dev/null 2>&1";
116
-  shell_exec($cmd);
117
-  $newFile = $outputDir . '/' . $fileName . '.pdf';
118
-  if (file_exists($newFile)) {
112
+    $cmd = "/usr/bin/libreoffice --headless" .
113
+            " --convert-to pdf:'$office'_pdf_Export" .
114
+            " --outdir '$outputDir'" .
115
+            " '$inputFile' >/dev/null 2>&1";
116
+    shell_exec($cmd);
117
+    $newFile = $outputDir . '/' . $fileName . '.pdf';
118
+    if (file_exists($newFile)) {
119 119
     return $newFile;
120
-  } else {
120
+    } else {
121 121
     return false;
122
-  }
122
+    }
123 123
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 
25 25
   // Shortcuts for combinations of controls.
26 26
   public const CURSOR = 15; // UP | DOWN | LEFT | RIGHT
27
-  public const ZOOM = 48;   // ZOOMIN | ZOOMOUT
27
+  public const ZOOM = 48; // ZOOMIN | ZOOMOUT
28 28
   public const ALL = 2047;
29 29
 
30 30
   // up down left right zoomin zoomout home end prior next download
Please login to merge, or discard this patch.
db.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -19,73 +19,73 @@
 block discarded – undo
19 19
 $oldJSON = '';
20 20
 
21 21
 if (!empty($_REQUEST['json'])) {
22
-  $oldJSON = $_REQUEST['json'];
23
-  $oldJSONarr = json_decode($oldJSON, true);
24
-  if ($oldJSONarr != null) {
22
+    $oldJSON = $_REQUEST['json'];
23
+    $oldJSONarr = json_decode($oldJSON, true);
24
+    if ($oldJSONarr != null) {
25 25
     array_walk_recursive($oldJSONarr, function (&$value, $key) {
26
-      if (is_string($value) && preg_match('/^http/', $value)) {
26
+        if (is_string($value) && preg_match('/^http/', $value)) {
27 27
         $value = rawurlencode($value);
28
-      }
28
+        }
29 29
     });
30 30
     $oldJSON = json_encode($oldJSONarr);
31
-  }
32
-  debug("db.php: old $oldJSON");
31
+    }
32
+    debug("db.php: old $oldJSON");
33 33
 }
34 34
 
35 35
 for ($t = 0; $t < 300; $t++) {
36
-  //~ echo("waiting for db change...<br>");
37
-  //~ $array = ['username' => 'stweil', 'quux' => 'baz'];
38
-  //~ $newJSON = json_encode($array);
36
+    //~ echo("waiting for db change...<br>");
37
+    //~ $array = ['username' => 'stweil', 'quux' => 'baz'];
38
+    //~ $newJSON = json_encode($array);
39 39
 
40
-  $database = array();
40
+    $database = array();
41 41
 
42
-  $table = $dbcon->query('select * from setting');
43
-  $data = array();
44
-  while ($row = $table->fetchArray(SQLITE3_ASSOC)) {
42
+    $table = $dbcon->query('select * from setting');
43
+    $data = array();
44
+    while ($row = $table->fetchArray(SQLITE3_ASSOC)) {
45 45
     array_push($data, $row);
46
-  }
47
-  $database['setting'] = $data;
46
+    }
47
+    $database['setting'] = $data;
48 48
 
49
-  $table = $dbcon->query('select * from address');
50
-  $data = array();
51
-  while ($row = $table->fetchArray(SQLITE3_ASSOC)) {
49
+    $table = $dbcon->query('select * from address');
50
+    $data = array();
51
+    while ($row = $table->fetchArray(SQLITE3_ASSOC)) {
52 52
     array_push($data, $row);
53 53
     $isAllowed = $isAllowed || ($row['address'] == $remote);
54
-  }
55
-  if (!$isAllowed) {
54
+    }
55
+    if (!$isAllowed) {
56 56
     // Some unauthorized host tried to read the database.
57 57
     // Don't return any data.
58 58
     break;
59
-  }
60
-  $database['address'] = $data;
59
+    }
60
+    $database['address'] = $data;
61 61
 
62
-  $table = $dbcon->query('select * from user');
63
-  $data = array();
64
-  while ($row = $table->fetchArray(SQLITE3_ASSOC)) {
62
+    $table = $dbcon->query('select * from user');
63
+    $data = array();
64
+    while ($row = $table->fetchArray(SQLITE3_ASSOC)) {
65 65
     array_push($data, $row);
66
-  }
67
-  $database['user'] = $data;
66
+    }
67
+    $database['user'] = $data;
68 68
 
69
-  $table = $dbcon->query('select * from window');
70
-  $data = array();
71
-  while ($row = $table->fetchArray(SQLITE3_ASSOC)) {
69
+    $table = $dbcon->query('select * from window');
70
+    $data = array();
71
+    while ($row = $table->fetchArray(SQLITE3_ASSOC)) {
72 72
     array_push($data, $row);
73
-  }
74
-  $database['window'] = $data;
73
+    }
74
+    $database['window'] = $data;
75 75
 
76
-  //~ $newJSON = json_encode($database, JSON_PRETTY_PRINT);
77
-  array_walk_recursive($database, function (&$value, $key) {
76
+    //~ $newJSON = json_encode($database, JSON_PRETTY_PRINT);
77
+    array_walk_recursive($database, function (&$value, $key) {
78 78
     if (is_string($value) && preg_match('/^http/', $value)) {
79
-      $value = rawurlencode($value);
79
+        $value = rawurlencode($value);
80 80
     }
81
-  });
82
-  $newJSON = json_encode($database);
83
-  if ($oldJSON != $newJSON) {
81
+    });
82
+    $newJSON = json_encode($database);
83
+    if ($oldJSON != $newJSON) {
84 84
     debug("db.php: new $newJSON");
85 85
     break;
86
-  }
86
+    }
87 87
 
88
-  sleep(1);
88
+    sleep(1);
89 89
 }
90 90
 
91 91
 touch("/var/run/palma/last_activity");
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
   $oldJSON = $_REQUEST['json'];
23 23
   $oldJSONarr = json_decode($oldJSON, true);
24 24
   if ($oldJSONarr != null) {
25
-    array_walk_recursive($oldJSONarr, function (&$value, $key) {
25
+    array_walk_recursive($oldJSONarr, function(&$value, $key) {
26 26
       if (is_string($value) && preg_match('/^http/', $value)) {
27 27
         $value = rawurlencode($value);
28 28
       }
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
   $database['window'] = $data;
75 75
 
76 76
   //~ $newJSON = json_encode($database, JSON_PRETTY_PRINT);
77
-  array_walk_recursive($database, function (&$value, $key) {
77
+  array_walk_recursive($database, function(&$value, $key) {
78 78
     if (is_string($value) && preg_match('/^http/', $value)) {
79 79
       $value = rawurlencode($value);
80 80
     }
Please login to merge, or discard this patch.
logout.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@
 block discarded – undo
11 11
 
12 12
 session_start();
13 13
 if (isset($_SESSION['username'])) {
14
-  $username = $_SESSION['username'];
15
-  $dbcon->delUser($username, $dbcon->ipAddress());
14
+    $username = $_SESSION['username'];
15
+    $dbcon->delUser($username, $dbcon->ipAddress());
16 16
 }
17 17
 session_destroy();
18 18
 header('Location: index.php');
Please login to merge, or discard this patch.
login.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,31 +30,31 @@  discard block
 block discarded – undo
30 30
 $pin = '';
31 31
 $posted_pin = '';
32 32
 if (isset($_REQUEST['pin'])) {
33
-  $posted_pin = escapeshellcmd($_REQUEST['pin']);
33
+    $posted_pin = escapeshellcmd($_REQUEST['pin']);
34 34
 }
35 35
 
36 36
 monitor("login.php: page loaded");
37 37
 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
38
-  session_start();
39
-  $username = escapeshellcmd($_POST['username']);
40
-  $password = '';
41
-  if (CONFIG_PASSWORD) {
38
+    session_start();
39
+    $username = escapeshellcmd($_POST['username']);
40
+    $password = '';
41
+    if (CONFIG_PASSWORD) {
42 42
     // The password must not be escaped.
43 43
     $password = $_POST['userpassword'];
44
-  }
45
-  if (CONFIG_PIN) {
44
+    }
45
+    if (CONFIG_PIN) {
46 46
     $posted_pin = escapeshellcmd($_POST['pin']);
47 47
     $pin = $dbcon->querySingle("SELECT value FROM setting WHERE key = 'pin'");
48
-  }
48
+    }
49 49
 
50
-  if (CONFIG_PASSWORD && !checkCredentials($username, $password)) {
50
+    if (CONFIG_PASSWORD && !checkCredentials($username, $password)) {
51 51
     monitor("login.php: access denied for user '$username'");
52 52
     // Invalid username or password.
53
-  } elseif (CONFIG_PIN && ($pin != $posted_pin)) {
53
+    } elseif (CONFIG_PIN && ($pin != $posted_pin)) {
54 54
     monitor("login.php: access denied for user '$username': invalid pin");
55 55
     debug("login.php: access denied for user '$username', wrong pin $posted_pin");
56 56
     $errtext = addslashes(__('Invalid PIN.'));
57
-  } else {
57
+    } else {
58 58
     // Successfully checked username, password and PIN.
59 59
     monitor("login.php: access granted for user '$username'");
60 60
     debug("login.php: access granted for user '$username'");
@@ -67,16 +67,16 @@  discard block
 block discarded – undo
67 67
 
68 68
     // Weiterleitung zur geschützten Startseite
69 69
     if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1') {
70
-      if (php_sapi_name() == 'cgi') {
70
+        if (php_sapi_name() == 'cgi') {
71 71
         header('Status: 303 See Other');
72
-      } else {
72
+        } else {
73 73
         header('HTTP/1.1 303 See Other');
74
-      }
74
+        }
75 75
     }
76 76
     debug('login.php: ' . CONFIG_START_URL);
77 77
     header('Location: ' . CONFIG_START_URL);
78 78
     exit;
79
-  }
79
+    }
80 80
 }
81 81
 ?>
82 82
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
             </div>
124 124
             <?php
125 125
             if (CONFIG_PASSWORD) {
126
-              ?>
126
+                ?>
127 127
               <div class="pure-control-group">
128 128
                 <label for="userpassword"><?=addslashes(__("Password"))?></label>
129 129
                 <input id="userpassword" name="userpassword" type="password">
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
               <?php
132 132
             }
133 133
             if (CONFIG_PIN) {
134
-              ?>
134
+                ?>
135 135
               <div class="pure-control-group">
136 136
                 <label for="pin"><?=addslashes(__("PIN"))?></label>
137 137
                 <input id="pin" name="pin" type="text" value="<?=htmlspecialchars($posted_pin)?>">
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
       </form>
151 151
 
152 152
       <?php
153
-      if ($errtext) {
153
+        if ($errtext) {
154 154
         echo("<p>$errtext</p>");
155
-      }
156
-      if (defined('CONFIG_POLICY')) {
155
+        }
156
+        if (defined('CONFIG_POLICY')) {
157 157
         echo('<div class="policy">' . CONFIG_POLICY . '</div>');
158
-      }
159
-      ?>
158
+        }
159
+        ?>
160 160
 
161 161
     </div>
162 162
 
Please login to merge, or discard this patch.
DBConnector.class.php 2 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 class DBConnector extends \SQLite3
11 11
 {
12
-  private const SQL_CREATE_TABLES = <<< eod
12
+    private const SQL_CREATE_TABLES = <<< eod
13 13
   BEGIN EXCLUSIVE TRANSACTION;
14 14
   PRAGMA foreign_keys = ON;
15 15
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
   END TRANSACTION;
52 52
   eod;
53 53
 
54
-  private const SQL_RESET_TABLES = <<< eod
54
+    private const SQL_RESET_TABLES = <<< eod
55 55
   DROP TABLE address;
56 56
   DROP TABLE setting;
57 57
   DROP TABLE IF EXISTS settings;
@@ -59,18 +59,18 @@  discard block
 block discarded – undo
59 59
   DROP TABLE window;
60 60
   eod;
61 61
 
62
-  private static ?DBConnector $instance = null;
62
+    private static ?DBConnector $instance = null;
63 63
 
64
-  public static function getInstance(): DBConnector
65
-  {
64
+    public static function getInstance(): DBConnector
65
+    {
66 66
     if (is_null(self::$instance)) {
67
-      self::$instance = new DBConnector('palma.db');
67
+        self::$instance = new DBConnector('palma.db');
68 68
     }
69 69
     return self::$instance;
70
-  }
70
+    }
71 71
 
72
-  private function __construct(string $filename)
73
-  {
72
+    private function __construct(string $filename)
73
+    {
74 74
     parent::__construct($filename);
75 75
 
76 76
     // Wait up to 10000 ms when the database is locked.
@@ -78,57 +78,57 @@  discard block
 block discarded – undo
78 78
 
79 79
     // Create any missing tables.
80 80
     $this->exec(self::SQL_CREATE_TABLES);
81
-  }
81
+    }
82 82
 
83
-  public function resetTables(): void
84
-  {
83
+    public function resetTables(): void
84
+    {
85 85
     $this->exec(self::SQL_RESET_TABLES . self::SQL_CREATE_TABLES);
86
-  }
86
+    }
87 87
 
88
-  public function countWindows(): int
89
-  {
88
+    public function countWindows(): int
89
+    {
90 90
     $numRows = $this->querySingle('SELECT count(*) FROM window WHERE state="active"');
91 91
     return $numRows;
92
-  }
92
+    }
93 93
 
94
-  public function nextID(): int
95
-  {
94
+    public function nextID(): int
95
+    {
96 96
     // Find the first unused monitor section and return its number.
97 97
     $quadrant_ids = array(1, 2, 3, 4);
98 98
     $window_db_ids = array();
99 99
 
100 100
     $window_keys = @$this->query('SELECT DISTINCT(id) FROM window');
101 101
     while ($row = $window_keys->fetchArray()) {
102
-      array_push($window_db_ids, $row['id']);
102
+        array_push($window_db_ids, $row['id']);
103 103
     }
104 104
     $window_keys->finalize();
105 105
     $next_ids = array_values(array_diff($quadrant_ids, $window_db_ids));
106 106
     if (count($next_ids) > 0) {
107
-      $next = $next_ids[0];
107
+        $next = $next_ids[0];
108 108
     } else {
109
-      $next = $this->querySingle('SELECT MAX(id) FROM window') + 1;
109
+        $next = $this->querySingle('SELECT MAX(id) FROM window') + 1;
110 110
     }
111 111
     return $next;
112
-  }
112
+    }
113 113
 
114
-  public function ipAddress(): string
115
-  {
114
+    public function ipAddress(): string
115
+    {
116 116
     $ip = 'unknown';
117 117
     if (isset($_SERVER['HTTP_X_FORWARED_FOR'])) {
118
-      // Server is hidden behind a proxy.
119
-      // Proxy for loopback ip might indicate spoofing
120
-      if (!in_array($_SERVER['HTTP_X_FORWARED_FOR'], array('127.0.0.1', '::1'))) {
118
+        // Server is hidden behind a proxy.
119
+        // Proxy for loopback ip might indicate spoofing
120
+        if (!in_array($_SERVER['HTTP_X_FORWARED_FOR'], array('127.0.0.1', '::1'))) {
121 121
         $ip = $_SERVER['HTTP_X_FORWARED_FOR'];
122
-      }
122
+        }
123 123
     } elseif (isset($_SERVER['REMOTE_ADDR'])) {
124
-      // Client has direct access to the server.
125
-      $ip = $_SERVER['REMOTE_ADDR'];
124
+        // Client has direct access to the server.
125
+        $ip = $_SERVER['REMOTE_ADDR'];
126 126
     }
127 127
     return $ip;
128
-  }
128
+    }
129 129
 
130
-  public function checkPermission(): bool
131
-  {
130
+    public function checkPermission(): bool
131
+    {
132 132
     // Check whether the remote IP address is allowed to run commands.
133 133
     // Only localhost or hosts of registered users are allowed.
134 134
     $ip = $this->ipAddress();
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
     $ip_list = array('127.0.0.1', '::1');
137 137
     $rows = $this->query("SELECT address FROM address");
138 138
     while ($row = $rows->fetchArray(SQLITE3_ASSOC)) {
139
-      array_push($ip_list, $row['address']);
139
+        array_push($ip_list, $row['address']);
140 140
     }
141 141
     $rows->finalize();
142 142
     $allowed = in_array($ip, $ip_list);
143 143
     return $allowed;
144
-  }
144
+    }
145 145
 
146
-  public function addUser(string $username, string $address, string $device = 'laptop'): void
147
-  {
146
+    public function addUser(string $username, string $address, string $device = 'laptop'): void
147
+    {
148 148
     // Add a new user with his/her address and the device to the database.
149 149
     $this->exec("INSERT OR IGNORE INTO user VALUES (NULL, '$username', 1, 0)");
150 150
     $usercount = intval($this->querySingle("SELECT COUNT(*) FROM user"));
@@ -153,99 +153,99 @@  discard block
 block discarded – undo
153 153
     require_once 'globals.php';
154 154
     debug("DBConnector::addUser: user $username connected with $device, $usercount user(s) now connected");
155 155
     if ($usercount == 1) {
156
-      // First user connected. Always enable this person.
157
-      $this->enableUser($username);
156
+        // First user connected. Always enable this person.
157
+        $this->enableUser($username);
158
+    }
158 159
     }
159
-  }
160 160
 
161
-  public function delUser(string $username, string $address): void
162
-  {
161
+    public function delUser(string $username, string $address): void
162
+    {
163 163
     // Remove an existing user with his/her address from the database.
164 164
     $ip = $this->ipAddress();
165 165
     $userid = $this->querySingle("SELECT userid from user where name='$username'");
166 166
     if (!is_null($userid)) {
167
-      // Kill VNC connection associated with the user
168
-      $this->deleteVNCWindow($userid);
169
-      $this->exec("DELETE FROM user WHERE userid = '$userid'");
167
+        // Kill VNC connection associated with the user
168
+        $this->deleteVNCWindow($userid);
169
+        $this->exec("DELETE FROM user WHERE userid = '$userid'");
170 170
     }
171 171
     $this->exec("DELETE FROM address WHERE userid = '$userid' AND address = '$ip'");
172 172
     $usercount = intval($this->querySingle("SELECT COUNT(*) FROM user"));
173 173
     require_once 'globals.php';
174 174
     debug("DBConnector::delUser: user $username disconnected, $usercount user(s) now connected");
175 175
     if ($usercount == 0) {
176
-      // Last user disconnected.
177
-      // Clean some tables, just to be sure that nothing is left.
178
-      $this->exec("DELETE FROM address; DELETE FROM window;");
176
+        // Last user disconnected.
177
+        // Clean some tables, just to be sure that nothing is left.
178
+        $this->exec("DELETE FROM address; DELETE FROM window;");
179
+    }
179 180
     }
180
-  }
181 181
 
182
-  public function enableUser(string $username): void
183
-  {
182
+    public function enableUser(string $username): void
183
+    {
184 184
     $state = $this->exec("UPDATE user SET enabled=1 WHERE name='$username'");
185 185
     if (!$state) {
186
-      require_once 'globals.php';
187
-      debug("DBConnector::enableUser: failed for $username");
186
+        require_once 'globals.php';
187
+        debug("DBConnector::enableUser: failed for $username");
188
+    }
188 189
     }
189
-  }
190 190
 
191
-  /** @return array<string> */
192
-  public function getUsers(): array
193
-  {
191
+    /** @return array<string> */
192
+    public function getUsers(): array
193
+    {
194 194
     $users = array();
195 195
     $rows = $this->query("SELECT name FROM user");
196 196
     while ($row = $rows->fetchArray(SQLITE3_ASSOC)) {
197
-      array_push($users, $row['name']);
197
+        array_push($users, $row['name']);
198 198
     }
199 199
     $rows->finalize();
200 200
     return $users;
201
-  }
201
+    }
202 202
 
203
-  public function checkUser(string $username): bool
204
-  {
203
+    public function checkUser(string $username): bool
204
+    {
205 205
     $users = $this->getUsers();
206 206
     // empty db (e.g. after PalMA restart) or old session
207 207
     if (count($users) === 0 || !in_array($username, $users)) {
208
-      return false;
208
+        return false;
209 209
     }
210 210
     return true;
211
-  }
211
+    }
212 212
 
213
-  /** @return array<array<string>> */
214
-  public function getWindows(): array
215
-  {
213
+    /** @return array<array<string>> */
214
+    public function getWindows(): array
215
+    {
216 216
     // Get list of all windows, ordered by their section.
217 217
     $window_objs = array();
218 218
     $windows = @$this->query('SELECT * FROM window ORDER BY section ASC');
219 219
     while ($row = $windows->fetchArray()) {
220
-      array_push($window_objs, $row);
220
+        array_push($window_objs, $row);
221 221
     }
222 222
     $windows->finalize();
223 223
 
224 224
     return $window_objs;
225
-  }
225
+    }
226 226
 
227
-  public function getWindowIDBySection(string $section): ?string
228
-  {
227
+    public function getWindowIDBySection(string $section): ?string
228
+    {
229 229
     $id = $this->querySingle("SELECT win_id FROM window WHERE section='$section'");
230 230
     return $id;
231
-  }
231
+    }
232 232
 
233
-  /** @return array<array<string>> */
234
-  public function getVNCClientInfo(): array
235
-  {
233
+    /** @return array<array<string>> */
234
+    public function getVNCClientInfo(): array
235
+    {
236 236
 
237 237
     $info = array();
238 238
 
239 239
     $i = @$this->query('SELECT * FROM window WHERE handler="vnc"');
240 240
     while ($row = $i->fetchArray()) {
241
-      array_push($info, $row);
241
+        array_push($info, $row);
242 242
     }
243 243
     $i->finalize();
244 244
 
245 245
     return $info;
246
-  }
246
+    }
247 247
 
248
-  /*
248
+    /*
249 249
      public function getVNC_ClientWindowIDs() {
250 250
      $ids = array();
251 251
      $rows = @$this->query('SELECT win_id FROM window WHERE handler="vnc"');
@@ -257,61 +257,61 @@  discard block
 block discarded – undo
257 257
      }
258 258
    */
259 259
 
260
-  public function getWindowState(string $window_id): string
261
-  {
260
+    public function getWindowState(string $window_id): string
261
+    {
262 262
     $state = @$this->querySingle('SELECT state FROM window WHERE win_id="' . $window_id . '"');
263 263
     return $state;
264
-  }
264
+    }
265 265
 
266
-  public function setWindowState(string $window_id, string $state): void
267
-  {
266
+    public function setWindowState(string $window_id, string $state): void
267
+    {
268 268
     $this->exec('UPDATE window SET state="' . $state . '" WHERE win_id="' . $window_id . '"');
269
-  }
269
+    }
270 270
 
271
-  /**
272
-   * @param array<string> $window
273
-   */
274
-  public function insertWindow(array $window): void
275
-  {
271
+    /**
272
+     * @param array<string> $window
273
+     */
274
+    public function insertWindow(array $window): void
275
+    {
276 276
     // transfer ob complete window object/array necessary
277 277
     $sql = 'INSERT INTO window (id, win_id, section, state, file, handler, userid, date) ' .
278
-           'VALUES ' . '("' .
279
-           $window[0] . '", "' . $window[1] . '", "' .
280
-           $window[2] . '", "' . $window[3] . '", "' .
281
-           $window[4] . '", "' . $window[5] . '", "' .
282
-           $window[6] . '", "' . $window[7] . '")';
278
+            'VALUES ' . '("' .
279
+            $window[0] . '", "' . $window[1] . '", "' .
280
+            $window[2] . '", "' . $window[3] . '", "' .
281
+            $window[4] . '", "' . $window[5] . '", "' .
282
+            $window[6] . '", "' . $window[7] . '")';
283 283
     $new = $this->exec($sql);
284 284
     require_once 'globals.php';
285 285
     debug("DBConnector::insertWindow: sql=$sql, result=$new");
286
-  }
286
+    }
287 287
 
288
-  public function deleteWindow(string $window_id): void
289
-  {
288
+    public function deleteWindow(string $window_id): void
289
+    {
290 290
     $this->exec('DELETE FROM window WHERE win_id="' . $window_id . '"');
291
-  }
291
+    }
292 292
 
293
-  public function deleteVNCWindow(string $userid): void
294
-  {
293
+    public function deleteVNCWindow(string $userid): void
294
+    {
295 295
     $winid = $this->querySingle('SELECT win_id FROM window WHERE handler="vnc" AND userid="' . $userid . '"');
296 296
     if (is_null($winid)) {
297
-      return;
297
+        return;
298 298
     }
299 299
     require_once 'globals.php';
300 300
     wmClose($winid);
301 301
     $this->deleteWindow($winid);
302 302
     //$this->exec('DELETE FROM window WHERE handler="vnc" AND userid="'.$userid.'"');
303
-  }
303
+    }
304 304
 
305
-  public function deleteDebug(string $table, string $id, string $gt): void
306
-  {
305
+    public function deleteDebug(string $table, string $id, string $gt): void
306
+    {
307 307
     $this->exec('DELETE FROM ' . $table . ' WHERE ' . $id . ' >"' . $gt . '"');
308
-  }
308
+    }
309 309
 
310
-  public function updateWindow(?string $window_id, string $field, string $value): void
311
-  {
310
+    public function updateWindow(?string $window_id, string $field, string $value): void
311
+    {
312 312
     if (is_null($window_id)) {
313
-      return;
313
+        return;
314 314
     }
315 315
     $this->exec('UPDATE window SET ' . $field . '="' . $value . '" WHERE win_id="' . $window_id . '"');
316
-  }
316
+    }
317 317
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@
 block discarded – undo
106 106
     if (count($next_ids) > 0) {
107 107
       $next = $next_ids[0];
108 108
     } else {
109
-      $next = $this->querySingle('SELECT MAX(id) FROM window') + 1;
109
+      $next = $this->querySingle('SELECT MAX(id) FROM window')+1;
110 110
     }
111 111
     return $next;
112 112
   }
Please login to merge, or discard this patch.
globals.php 2 patches
Indentation   +349 added lines, -349 removed lines patch added patch discarded remove patch
@@ -5,19 +5,19 @@  discard block
 block discarded – undo
5 5
 
6 6
 function confValue(string $name): ?string
7 7
 {
8
-  // Try setting constants from a configuration file.
9
-  static $conf = null;
10
-  if (is_null($conf)) {
8
+    // Try setting constants from a configuration file.
9
+    static $conf = null;
10
+    if (is_null($conf)) {
11 11
     $conf_fn = 'palma.ini';
12 12
     if (!file_exists($conf_fn)) {
13
-      $conf_fn = '/etc/palma.ini';
13
+        $conf_fn = '/etc/palma.ini';
14 14
     }
15 15
     $conf = parse_ini_file($conf_fn);
16
-  }
17
-  if (array_key_exists($name, $conf)) {
16
+    }
17
+    if (array_key_exists($name, $conf)) {
18 18
     return $conf[$name];
19
-  }
20
-  return null;
19
+    }
20
+    return null;
21 21
 }
22 22
 
23 23
 // Entries in group 'display'.
@@ -28,14 +28,14 @@  discard block
 block discarded – undo
28 28
 define('CONFIG_PASSWORD', confValue('password') ?? false);
29 29
 define('CONFIG_PIN', confValue('pin') ?? true);
30 30
 define('CONFIG_STATIONNAME', confValue('stationname') ??
31
-       str_replace(array("\r", "\n", " "), '', `hostname -f`));
31
+        str_replace(array("\r", "\n", " "), '', `hostname -f`));
32 32
 define('CONFIG_THEME', confValue('theme') ?? 'demo/simple');
33 33
 define('CONFIG_BROWSER', confValue('browser'));
34 34
 define('CONFIG_DEBUG', confValue('debug') ?? false);
35 35
 
36 36
 // Entries in group 'path'.
37 37
 define('CONFIG_START_URL', confValue('start_url') ??
38
-       'http://' . str_replace(array("\r", "\n", " "), '', `hostname -f`) . '/');
38
+        'http://' . str_replace(array("\r", "\n", " "), '', `hostname -f`) . '/');
39 39
 define('CONFIG_POLICY', confValue('policy'));
40 40
 define('CONFIG_CONTROL_FILE', confValue('control_file') ?? CONFIG_START_URL . 'control.php');
41 41
 define('CONFIG_UPLOAD_DIR', confValue('upload_dir') ?? '/tmp/palma');
@@ -46,87 +46,87 @@  discard block
 block discarded – undo
46 46
 
47 47
 function getDevice(): string
48 48
 {
49
-  // Try to determine the user's device type. The device which is
50
-  // returned is used to select the matching icon for the user list.
51
-  $agent = $_SERVER["HTTP_USER_AGENT"];
52
-  if (preg_match('/iPad/', $agent)) {
49
+    // Try to determine the user's device type. The device which is
50
+    // returned is used to select the matching icon for the user list.
51
+    $agent = $_SERVER["HTTP_USER_AGENT"];
52
+    if (preg_match('/iPad/', $agent)) {
53 53
     $device = 'tablet';
54
-  } elseif (preg_match('/iPhone/', $agent)) {
54
+    } elseif (preg_match('/iPhone/', $agent)) {
55 55
     $device = 'mobile';
56
-  } elseif (preg_match('/Android/', $agent)) {
56
+    } elseif (preg_match('/Android/', $agent)) {
57 57
     $device = 'android';
58
-  } elseif (preg_match('/Linux/', $agent)) {
58
+    } elseif (preg_match('/Linux/', $agent)) {
59 59
     $device = 'linux';
60
-  } elseif (preg_match('/OS X/', $agent)) {
60
+    } elseif (preg_match('/OS X/', $agent)) {
61 61
     $device = 'apple';
62
-  } elseif (preg_match('/Windows/', $agent)) {
62
+    } elseif (preg_match('/Windows/', $agent)) {
63 63
     $device = 'windows';
64
-  } else {
64
+    } else {
65 65
     $device = 'laptop';
66
-  }
67
-  return $device;
66
+    }
67
+    return $device;
68 68
 }
69 69
 
70 70
 function checkCredentials(string $username, string $password): bool
71 71
 {
72
-  // Check username + password against fixed internal value and
73
-  // external proxy with authentisation.
72
+    // Check username + password against fixed internal value and
73
+    // external proxy with authentisation.
74 74
 
75
-  global $errtext;
75
+    global $errtext;
76 76
 
77
-  $remote = $_SERVER['REMOTE_ADDR'];
78
-  if ($username == 'chef' && $password == 'chef') {
77
+    $remote = $_SERVER['REMOTE_ADDR'];
78
+    if ($username == 'chef' && $password == 'chef') {
79 79
     if (
80 80
         $remote == '::1' || $remote == '127.0.0.1' ||
81 81
         preg_match('/^134[.]155[.]36[.]/', $remote) &&
82 82
         $remote != '134.155.36.48'
83 83
     ) {
84
-      // Allow test access for restricted remote hosts (localhost,
85
-      // UB Mannheim library staff, but not via proxy server).
86
-      // TODO: PalMA installations which are accessible from
87
-      // the Internet may want to remove this test access.
88
-      return true;
84
+        // Allow test access for restricted remote hosts (localhost,
85
+        // UB Mannheim library staff, but not via proxy server).
86
+        // TODO: PalMA installations which are accessible from
87
+        // the Internet may want to remove this test access.
88
+        return true;
89 89
     } else {
90
-      trace("checkCredentials: Test access not allowed for IP address $remote");
91
-      return false;
90
+        trace("checkCredentials: Test access not allowed for IP address $remote");
91
+        return false;
92
+    }
92 93
     }
93
-  }
94 94
 
95
-  if ($username == '' || $password == '') {
95
+    if ($username == '' || $password == '') {
96 96
     // Don't allow empty user name or password.
97 97
     // Proxy authentisation can fail with empty values.
98 98
     trace("checkCredentials: access denied for user '$username'");
99 99
     return false;
100
-  }
101
-  // TODO: testurl sollte auf einem lokalen Server liegen.
102
-  $testurl = 'http://www.weilnetz.de/proxytest';
103
-  $proxy = 'proxy.bib.uni-mannheim.de:3150';
104
-  $curl = curl_init($testurl);
105
-  curl_setopt($curl, CURLOPT_HEADER, true);
106
-  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
107
-  curl_setopt($curl, CURLOPT_PROXY, $proxy);
108
-  curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
109
-  curl_setopt($curl, CURLOPT_PROXYUSERPWD, "$username:$password");
110
-  //~ trace("checkCredentials: Start curl");
111
-  $out = curl_exec($curl);
112
-  curl_close($curl);
113
-
114
-  if (!$out) {
100
+    }
101
+    // TODO: testurl sollte auf einem lokalen Server liegen.
102
+    $testurl = 'http://www.weilnetz.de/proxytest';
103
+    $proxy = 'proxy.bib.uni-mannheim.de:3150';
104
+    $curl = curl_init($testurl);
105
+    curl_setopt($curl, CURLOPT_HEADER, true);
106
+    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
107
+    curl_setopt($curl, CURLOPT_PROXY, $proxy);
108
+    curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
109
+    curl_setopt($curl, CURLOPT_PROXYUSERPWD, "$username:$password");
110
+    //~ trace("checkCredentials: Start curl");
111
+    $out = curl_exec($curl);
112
+    curl_close($curl);
113
+
114
+    if (!$out) {
115 115
     trace("checkCredentials: curl failed for user '$username'");
116 116
     $errtext = addslashes(__('Invalid credentials!'));
117
-  } elseif (preg_match('/404 Not Found/', $out)) {
117
+    } elseif (preg_match('/404 Not Found/', $out)) {
118 118
     return true;
119
-  } elseif (preg_match('/Could not resolve proxy/', $out)) {
119
+    } elseif (preg_match('/Could not resolve proxy/', $out)) {
120 120
     trace('checkCredentials: proxy authentication was not possible');
121 121
     $errtext = addslashes(__('Cannot check credentials, sorry!'));
122
-  } elseif (preg_match('/Cache Access Denied/', $out)) {
122
+    } elseif (preg_match('/Cache Access Denied/', $out)) {
123 123
     trace("checkCredentials: access denied for user '$username'");
124 124
     $errtext = addslashes(__('Invalid credentials!'));
125
-  } else {
125
+    } else {
126 126
     trace("checkCredentials: access not possible for user '$username'");
127 127
     $errtext = addslashes(__('Invalid credentials!'));
128
-  }
129
-  return false;
128
+    }
129
+    return false;
130 130
 }
131 131
 
132 132
 function showLogin(): void
@@ -136,14 +136,14 @@  discard block
 block discarded – undo
136 136
     //}
137 137
     $header = 'Location: login.php';
138 138
     $separator = '?';
139
-  if (isset($_REQUEST['lang'])) {
140
-      $header = $header . $separator . 'lang=' . $_REQUEST['lang'];
141
-      $separator = '&';
142
-  }
143
-  if (isset($_REQUEST['pin'])) {
144
-      $header = $header . $separator . 'pin=' . $_REQUEST['pin'];
145
-      $separator = '&';
146
-  }
139
+    if (isset($_REQUEST['lang'])) {
140
+        $header = $header . $separator . 'lang=' . $_REQUEST['lang'];
141
+        $separator = '&';
142
+    }
143
+    if (isset($_REQUEST['pin'])) {
144
+        $header = $header . $separator . 'pin=' . $_REQUEST['pin'];
145
+        $separator = '&';
146
+    }
147 147
     header($header);
148 148
 
149 149
     exit;
@@ -151,95 +151,95 @@  discard block
 block discarded – undo
151 151
 
152 152
 function trace(string $text): void
153 153
 {
154
-  static $firstRun = true;
155
-  if ($firstRun) {
154
+    static $firstRun = true;
155
+    if ($firstRun) {
156 156
     $firstRun = false;
157 157
     openlog("palma", LOG_PID, LOG_USER);
158
-  }
159
-  syslog(LOG_NOTICE, $text);
158
+    }
159
+    syslog(LOG_NOTICE, $text);
160 160
 }
161 161
 
162 162
 function debug(string $text): void
163 163
 {
164
-  if (CONFIG_DEBUG) {
164
+    if (CONFIG_DEBUG) {
165 165
     trace($text);
166
-  }
166
+    }
167 167
 }
168 168
 
169 169
 function monitor(string $action): void
170 170
 {
171
-  if (is_null(CONFIG_MONITOR_URL)) {
171
+    if (is_null(CONFIG_MONITOR_URL)) {
172 172
     return;
173
-  }
174
-
175
-  debug("monitor $action");
176
-
177
-  $ch = curl_init();
178
-  $url = CONFIG_MONITOR_URL;
179
-
180
-  curl_setopt_array(
181
-      $ch,
182
-      array(
183
-      CURLOPT_RETURNTRANSFER => 1,
184
-      CURLOPT_URL => CONFIG_MONITOR_URL . '/' . CONFIG_STATIONNAME . '/' . base64_encode($action),
185
-      CURLOPT_USERAGENT => 'PalMA cURL Request'
186
-      )
187
-  );
188
-  $resp = curl_exec($ch);
189
-  curl_close($ch);
173
+    }
174
+
175
+    debug("monitor $action");
176
+
177
+    $ch = curl_init();
178
+    $url = CONFIG_MONITOR_URL;
179
+
180
+    curl_setopt_array(
181
+        $ch,
182
+        array(
183
+        CURLOPT_RETURNTRANSFER => 1,
184
+        CURLOPT_URL => CONFIG_MONITOR_URL . '/' . CONFIG_STATIONNAME . '/' . base64_encode($action),
185
+        CURLOPT_USERAGENT => 'PalMA cURL Request'
186
+        )
187
+    );
188
+    $resp = curl_exec($ch);
189
+    curl_close($ch);
190 190
 }
191 191
 
192 192
 function displayCommand(string $cmd): ?string
193 193
 {
194
-  if (is_null(CONFIG_SSH)) {
194
+    if (is_null(CONFIG_SSH)) {
195 195
     $cmd = "DISPLAY=" . CONFIG_DISPLAY . " HOME=/var/www $cmd";
196
-  } else {
196
+    } else {
197 197
     $cmd = CONFIG_SSH . " 'DISPLAY=" . CONFIG_DISPLAY . " $cmd'";
198
-  }
198
+    }
199 199
 
200
-  monitor("control.php: displayCommand $cmd");
200
+    monitor("control.php: displayCommand $cmd");
201 201
 
202
-  // add directories with palma-browser to PATH
203
-  $result = shell_exec('PATH=/usr/lib/palma:./scripts:$PATH ' . $cmd);
204
-  trace("displayCommand: $cmd, result=$result");
205
-  return $result;
202
+    // add directories with palma-browser to PATH
203
+    $result = shell_exec('PATH=/usr/lib/palma:./scripts:$PATH ' . $cmd);
204
+    trace("displayCommand: $cmd, result=$result");
205
+    return $result;
206 206
 }
207 207
 
208 208
 function wmClose(string $id): void
209 209
 {
210
-  monitor("control.php: wmClose");
211
-  // Close window gracefully.
212
-  displayCommand("wmctrl -i -c $id");
210
+    monitor("control.php: wmClose");
211
+    // Close window gracefully.
212
+    displayCommand("wmctrl -i -c $id");
213 213
 }
214 214
 
215 215
 function wmHide(string $id): void
216 216
 {
217
-  monitor("control.php: wmHide");
218
-  // Hide window. This is done by moving it to desktop 1.
219
-  displayCommand("wmctrl -i -r $id -t 1");
217
+    monitor("control.php: wmHide");
218
+    // Hide window. This is done by moving it to desktop 1.
219
+    displayCommand("wmctrl -i -r $id -t 1");
220 220
 }
221 221
 
222 222
 function wmShow(string $id): void
223 223
 {
224
-  monitor("control.php: wmShow");
225
-  // Show window on current desktop.
226
-  displayCommand("wmctrl -i -R $id");
224
+    monitor("control.php: wmShow");
225
+    // Show window on current desktop.
226
+    displayCommand("wmctrl -i -R $id");
227 227
 }
228 228
 
229 229
 /** @return array<string> */
230 230
 function windowListOnScreen(): array
231 231
 {
232
-  monitor("control.php: windowListOnScreen");
233
-  $list = array();
234
-  $windows = explode("\n", displayCommand('wmctrl -l'));
235
-  foreach ($windows as $w) {
232
+    monitor("control.php: windowListOnScreen");
233
+    $list = array();
234
+    $windows = explode("\n", displayCommand('wmctrl -l'));
235
+    foreach ($windows as $w) {
236 236
     $field = explode(' ', $w);
237 237
     $id = $field[0];
238 238
     if ($id != '') {
239
-      array_push($list, $id);
239
+        array_push($list, $id);
240
+    }
240 241
     }
241
-  }
242
-  return $list;
242
+    return $list;
243 243
 }
244 244
 
245 245
 // simple list with content from database
@@ -247,116 +247,116 @@  discard block
 block discarded – undo
247 247
 /** @return array<string> */
248 248
 function windowList(): array
249 249
 {
250
-  monitor("control.php: windowList");
250
+    monitor("control.php: windowList");
251 251
 
252
-  require_once 'DBConnector.class.php';
253
-  $db = palma\DBConnector::getInstance();
252
+    require_once 'DBConnector.class.php';
253
+    $db = palma\DBConnector::getInstance();
254 254
 
255
-  $list = array();
255
+    $list = array();
256 256
 
257
-  // Get ordered list of all windows from the database.
258
-  $windows = $db->getWindows();
259
-  foreach ($windows as $w) {
257
+    // Get ordered list of all windows from the database.
258
+    $windows = $db->getWindows();
259
+    foreach ($windows as $w) {
260 260
     $id = $w['win_id'];
261 261
     if ($id != '') {
262
-      array_push($list, $id);
262
+        array_push($list, $id);
263 263
     }
264
-  }
265
-  return $list;
264
+    }
265
+    return $list;
266 266
 }
267 267
 
268 268
 function closeAll(): void
269 269
 {
270
-  monitor("control.php: closeAll");
270
+    monitor("control.php: closeAll");
271 271
 
272
-  require_once 'DBConnector.class.php';
273
-  $db = palma\DBConnector::getInstance();
272
+    require_once 'DBConnector.class.php';
273
+    $db = palma\DBConnector::getInstance();
274 274
 
275
-  $windows_on_screen = windowListOnScreen();
275
+    $windows_on_screen = windowListOnScreen();
276 276
 
277
-  foreach ($windows_on_screen as $id) {
277
+    foreach ($windows_on_screen as $id) {
278 278
     wmClose($id);
279 279
     if ($db->getWindowState($id) != null) {
280
-      $db->deleteWindow($id);
280
+        $db->deleteWindow($id);
281
+    }
281 282
     }
282
-  }
283 283
 
284
-  // Remove any remaining window entries in database.
285
-  $db->exec('DELETE FROM window');
284
+    // Remove any remaining window entries in database.
285
+    $db->exec('DELETE FROM window');
286 286
 
287
-  // Remove any remaining files in the upload directory.
288
-  clearUploadDir();
287
+    // Remove any remaining files in the upload directory.
288
+    clearUploadDir();
289 289
 }
290 290
 
291 291
 function doLogout(string $username): void
292 292
 {
293
-  monitor("control.php: doLogout");
293
+    monitor("control.php: doLogout");
294 294
 
295
-  require_once 'DBConnector.class.php';
296
-  $db = palma\DBConnector::getInstance();
295
+    require_once 'DBConnector.class.php';
296
+    $db = palma\DBConnector::getInstance();
297 297
 
298
-  if ($username == 'ALL') {
298
+    if ($username == 'ALL') {
299 299
     // Terminate all user connections and reset system.
300 300
     closeAll();
301 301
     $db->resetTables();
302
-  }
302
+    }
303 303
 }
304 304
 
305 305
 function clearUploadDir(): void
306 306
 {
307
-  monitor("control.php: clearUploadDir");
308
-  # Remove all files in the upload directory.
309
-  if (is_dir(CONFIG_UPLOAD_DIR)) {
307
+    monitor("control.php: clearUploadDir");
308
+    # Remove all files in the upload directory.
309
+    if (is_dir(CONFIG_UPLOAD_DIR)) {
310 310
     if ($dh = opendir(CONFIG_UPLOAD_DIR)) {
311
-      while (($file = readdir($dh)) !== false) {
311
+        while (($file = readdir($dh)) !== false) {
312 312
         if ($file != "." and $file != "..") {
313
-          unlink(CONFIG_UPLOAD_DIR . "/$file");
313
+            unlink(CONFIG_UPLOAD_DIR . "/$file");
314
+        }
314 315
         }
315
-      }
316
-      closedir($dh);
316
+        closedir($dh);
317
+    }
317 318
     }
318
-  }
319 319
 }
320 320
 
321 321
 function setLayout(?string $layout = null): void
322 322
 {
323
-  monitor("control.php: setLayout $layout");
324
-  // Set layout of team display. Layouts are specified by their name.
325
-  // We use names like g1x1, g2x1, g1x2, ...
326
-  // Restore the last layout if the function is called with a null argument.
323
+    monitor("control.php: setLayout $layout");
324
+    // Set layout of team display. Layouts are specified by their name.
325
+    // We use names like g1x1, g2x1, g1x2, ...
326
+    // Restore the last layout if the function is called with a null argument.
327 327
 
328
-  trace("setLayout: $layout");
328
+    trace("setLayout: $layout");
329 329
 
330
-  require_once 'DBConnector.class.php';
331
-  $db = palma\DBConnector::getInstance();
330
+    require_once 'DBConnector.class.php';
331
+    $db = palma\DBConnector::getInstance();
332 332
 
333
-  $geom = array();
334
-  $geom['g1x1'] = array(
333
+    $geom = array();
334
+    $geom['g1x1'] = array(
335 335
     array(0, 0, 1, 1)
336
-  );
337
-  $geom['g2x1'] = array(
336
+    );
337
+    $geom['g2x1'] = array(
338 338
     array(0, 0, 2, 1), array(1, 0, 2, 1)
339
-  );
340
-  $geom['g1x2'] = array(
339
+    );
340
+    $geom['g1x2'] = array(
341 341
     array(0, 0, 1, 2), array(0, 1, 1, 2)
342
-  );
343
-  $geom['g1a2'] = array(
342
+    );
343
+    $geom['g1a2'] = array(
344 344
     array(0, 0, 2, 1), array(1, 0, 2, 2),
345 345
     array(1, 1, 2, 2)
346
-  );
347
-  $geom['g2x2'] = array(
346
+    );
347
+    $geom['g2x2'] = array(
348 348
     array(0, 0, 2, 2), array(1, 0, 2, 2),
349 349
     array(0, 1, 2, 2), array(1, 1, 2, 2)
350
-  );
350
+    );
351 351
 
352
-  if ($layout == null) {
352
+    if ($layout == null) {
353 353
     $layout = $db->querySingle("SELECT value FROM setting WHERE key='layout'");
354
-  }
354
+    }
355 355
 
356
-  // Make sure $layout is valid
357
-  if (!array_key_exists($layout, $geom)) {
356
+    // Make sure $layout is valid
357
+    if (!array_key_exists($layout, $geom)) {
358 358
     trace("setLayout: layout invalid!");
359
-  } else {
359
+    } else {
360 360
     $db->exec("UPDATE setting SET value='$layout' WHERE key='layout'");
361 361
     $dim = $geom[$layout];
362 362
 
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
     // Get ordered list of all windows from the database.
379 379
     $windows = $db->getWindows();
380 380
     foreach ($windows as $w) {
381
-      $id = $w['win_id'];
382
-      $enabled = $w['state'] == 'active';
383
-      $section = intval($w['section']);
384
-      if ($section >= 1 && $section <= $maxSection && $enabled) {
381
+        $id = $w['win_id'];
382
+        $enabled = $w['state'] == 'active';
383
+        $section = intval($w['section']);
384
+        if ($section >= 1 && $section <= $maxSection && $enabled) {
385 385
         // Show window, set size and position.
386 386
         $wi = $section - 1;
387 387
         $dx = $screenWidth / $dim[$wi][2];
@@ -390,22 +390,22 @@  discard block
 block discarded – undo
390 390
         $y = $dim[$wi][1] * $dy;
391 391
         wmShow($id);
392 392
         displayCommand("wmctrl -i -r $id -e 0,$x,$y,$dx,$dy");
393
-      } else {
393
+        } else {
394 394
         // Hide window.
395 395
         wmHide($id);
396
-      }
396
+        }
397
+    }
397 398
     }
398
-  }
399 399
 }
400 400
 
401 401
 function activateControls(string $windowhex): void
402 402
 {
403
-  require_once 'DBConnector.class.php';
404
-  $db = palma\DBConnector::getInstance();
403
+    require_once 'DBConnector.class.php';
404
+    $db = palma\DBConnector::getInstance();
405 405
 
406
-  $fhandler = $db->querySingle("SELECT handler FROM window WHERE win_id='$windowhex'");
407
-  trace("activateControls: handler $fhandler");
408
-  monitor("control.php: activateControls $fhandler");
406
+    $fhandler = $db->querySingle("SELECT handler FROM window WHERE win_id='$windowhex'");
407
+    trace("activateControls: handler $fhandler");
408
+    monitor("control.php: activateControls $fhandler");
409 409
 }
410 410
 
411 411
 /**
@@ -413,22 +413,22 @@  discard block
 block discarded – undo
413 413
  */
414 414
 function addNewWindow(array $new): void
415 415
 {
416
-  // Add a new window to the monitor. This window either uses the first
417
-  // unused section or it will be hidden.
416
+    // Add a new window to the monitor. This window either uses the first
417
+    // unused section or it will be hidden.
418 418
 
419
-  monitor('control.php: addNewWindow ' . serialize($new));
420
-  trace('addNewWindow: ' . serialize($new));
419
+    monitor('control.php: addNewWindow ' . serialize($new));
420
+    trace('addNewWindow: ' . serialize($new));
421 421
 
422
-  require_once 'DBConnector.class.php';
423
-  $db = palma\DBConnector::getInstance();
422
+    require_once 'DBConnector.class.php';
423
+    $db = palma\DBConnector::getInstance();
424 424
 
425
-  // '$new' already contains 'file', 'handler' and 'date', as well as the
426
-  // username for VNC connections only.
427
-  // 'win_id', 'section' have to be defined afterwards.
425
+    // '$new' already contains 'file', 'handler' and 'date', as well as the
426
+    // username for VNC connections only.
427
+    // 'win_id', 'section' have to be defined afterwards.
428 428
 
429
-  // Get new window. Wait up to 10 s for it.
430
-  $t_total = 0;
431
-  do {
429
+    // Get new window. Wait up to 10 s for it.
430
+    $t_total = 0;
431
+    do {
432 432
     $window_ids_on_screen = windowListOnScreen();
433 433
     $windows_in_db = $db->getWindows();
434 434
 
@@ -436,64 +436,64 @@  discard block
 block discarded – undo
436 436
     $new_window_id = '';
437 437
 
438 438
     if (count($windows_in_db) > 0) {
439
-      // Add db windows to existing_ids.
440
-      foreach ($windows_in_db as $win) {
439
+        // Add db windows to existing_ids.
440
+        foreach ($windows_in_db as $win) {
441 441
         $existing_ids[] = $win['win_id'];
442
-      }
442
+        }
443 443
 
444
-      $new_window = array_diff($window_ids_on_screen, $existing_ids);
445
-      foreach ($new_window as $win_id) {
444
+        $new_window = array_diff($window_ids_on_screen, $existing_ids);
445
+        foreach ($new_window as $win_id) {
446 446
         if ($win_id != "") {
447
-          $new_window_id = $win_id;
447
+            $new_window_id = $win_id;
448
+        }
448 449
         }
449
-      }
450 450
     } elseif (!empty($window_ids_on_screen)) {
451
-      $new_window_id = $window_ids_on_screen[0];
451
+        $new_window_id = $window_ids_on_screen[0];
452 452
     }
453
-  } while (!$new_window_id && $t_total++ <= 10 && !sleep(1));
453
+    } while (!$new_window_id && $t_total++ <= 10 && !sleep(1));
454 454
 
455
-  if (!$new_window_id) {
455
+    if (!$new_window_id) {
456 456
     trace('addNewWindow: warning: no new window found');
457 457
     return;
458
-  }
458
+    }
459 459
 
460
-  trace("addNewWindow: new window $new_window_id");
460
+    trace("addNewWindow: new window $new_window_id");
461 461
 
462
-  // Determine last assigned monitor section.
463
-  //~ $max_section = $db->querySingle('SELECT MAX(section) FROM window');
462
+    // Determine last assigned monitor section.
463
+    //~ $max_section = $db->querySingle('SELECT MAX(section) FROM window');
464 464
 
465
-  // Get first unused monitor section.
466
-  $section = $db->nextID();
465
+    // Get first unused monitor section.
466
+    $section = $db->nextID();
467 467
 
468
-  // If all information is available, create window object.
468
+    // If all information is available, create window object.
469 469
 
470
-  $new['id'] = $section;
471
-  $new['section'] = $section;
470
+    $new['id'] = $section;
471
+    $new['section'] = $section;
472 472
 
473
-  if ($section <= 4) {
473
+    if ($section <= 4) {
474 474
     $new['state'] = "active";
475
-  } else {
475
+    } else {
476 476
     // All sections are used, so there is no free one for the new window.
477 477
     $new['state'] = "inactive";
478 478
     // We could hide the new window immediately, but don't do it here:
479 479
     // Each new window will be shown in the middle of the screen.
480 480
     //~ wmHide($new_window_id);
481 481
     //~ trace("addNewWindow: hide new window $new_window_id");
482
-  }
482
+    }
483 483
 
484
-  // $new['file'] = $active_window; (?)
484
+    // $new['file'] = $active_window; (?)
485 485
 
486
-  // TODO: check how to insert the userid for all content, not just vnc.
487
-  // Perhaps better add to array in upload.php ?
488
-  $userid = "";
489
-  $queryid = $db->querySingle('SELECT user.userid FROM user WHERE user.name="' . $new['userid'] . '"');
490
-  if (!empty($queryid)) {
486
+    // TODO: check how to insert the userid for all content, not just vnc.
487
+    // Perhaps better add to array in upload.php ?
488
+    $userid = "";
489
+    $queryid = $db->querySingle('SELECT user.userid FROM user WHERE user.name="' . $new['userid'] . '"');
490
+    if (!empty($queryid)) {
491 491
     $userid = $queryid;
492
-  } else {
492
+    } else {
493 493
     $userid = "all";
494
-  }
494
+    }
495 495
 
496
-  $myWindow = array(
496
+    $myWindow = array(
497 497
     $new['id'],
498 498
     $new_window_id,
499 499
     $new['section'],
@@ -502,12 +502,12 @@  discard block
 block discarded – undo
502 502
     $new['handler'],
503 503
     $userid,
504 504
     $new['date']
505
-  );
505
+    );
506 506
 
507
-  // Save window in database.
508
-  $db->insertWindow($myWindow);
507
+    // Save window in database.
508
+    $db->insertWindow($myWindow);
509 509
 
510
-  setLayout();
510
+    setLayout();
511 511
 }
512 512
 
513 513
 /**
@@ -515,21 +515,21 @@  discard block
 block discarded – undo
515 515
  */
516 516
 function createNewWindowSafe(array $w): void
517 517
 {
518
-  require_once 'DBConnector.class.php';
519
-  $db = palma\DBConnector::getInstance();
518
+    require_once 'DBConnector.class.php';
519
+    $db = palma\DBConnector::getInstance();
520 520
 
521
-  $inFile = $w['file'];
522
-  if (!file_exists($inFile)) {
521
+    $inFile = $w['file'];
522
+    if (!file_exists($inFile)) {
523 523
     trace("createNewWindowSafe: " . escapeshellarg($inFile) . " is not a file, aborting display");
524 524
     return;
525
-  }
525
+    }
526 526
 
527
-  require_once 'FileHandler.class.php';
528
-  list ($handler, $targetFile) =
527
+    require_once 'FileHandler.class.php';
528
+    list ($handler, $targetFile) =
529 529
     palma\FileHandler::getFileHandler($inFile);
530
-  trace("createNewWindowSafe: file is now $targetFile, its handler is $handler");
530
+    trace("createNewWindowSafe: file is now $targetFile, its handler is $handler");
531 531
 
532
-  $window = array(
532
+    $window = array(
533 533
     "id" => "",
534 534
     "win_id" => "",
535 535
     "name" => "",
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
     "userid" => "",
540 540
     "date" => $w['date']);
541 541
 
542
-  createNewWindow($window);
542
+    createNewWindow($window);
543 543
 }
544 544
 
545 545
 /**
@@ -547,31 +547,31 @@  discard block
 block discarded – undo
547 547
  */
548 548
 function createNewWindow($w): void
549 549
 {
550
-  // '$w' already contains 'file', 'handler' and 'date'.
551
-  // 'win_id', 'section' have to be defined afterwards.
550
+    // '$w' already contains 'file', 'handler' and 'date'.
551
+    // 'win_id', 'section' have to be defined afterwards.
552 552
 
553
-  require_once 'DBConnector.class.php';
554
-  $db = palma\DBConnector::getInstance();
553
+    require_once 'DBConnector.class.php';
554
+    $db = palma\DBConnector::getInstance();
555 555
 
556
-  $handler = $w['handler'];
557
-  // TODO: use escapeshellarg() for filename.
558
-  $filename = $w['file'];
556
+    $handler = $w['handler'];
557
+    // TODO: use escapeshellarg() for filename.
558
+    $filename = $w['file'];
559 559
 
560
-  $cmd = "$handler " . escapeshellarg($filename);
561
-  displayCommand("/usr/bin/nohup $cmd >/dev/null 2>&1 &");
560
+    $cmd = "$handler " . escapeshellarg($filename);
561
+    displayCommand("/usr/bin/nohup $cmd >/dev/null 2>&1 &");
562 562
 
563
-  addNewWindow($w);
564
-  monitor("control.php: createNewWindow");
563
+    addNewWindow($w);
564
+    monitor("control.php: createNewWindow");
565 565
 }
566 566
 
567 567
 function processRequests(): void
568 568
 {
569
-  monitor("control.php: processRequests");
569
+    monitor("control.php: processRequests");
570 570
 
571
-  require_once 'DBConnector.class.php';
572
-  $db = palma\DBConnector::getInstance();
571
+    require_once 'DBConnector.class.php';
572
+    $db = palma\DBConnector::getInstance();
573 573
 
574
-  if (array_key_exists('window', $_REQUEST)) {
574
+    if (array_key_exists('window', $_REQUEST)) {
575 575
     // All windows related commands must start with window=.
576 576
 
577 577
     $windownumber = escapeshellcmd($_REQUEST['window']);
@@ -581,79 +581,79 @@  discard block
 block discarded – undo
581 581
     $win_id = 0;
582 582
 
583 583
     if ($windownumber != 'vncwin') {
584
-      // This is the normal case.
585
-      // Special handling is needed when called with window=vncwin, see below.
586
-      $window = intval($windownumber) - 1;
584
+        // This is the normal case.
585
+        // Special handling is needed when called with window=vncwin, see below.
586
+        $window = intval($windownumber) - 1;
587 587
 
588
-      $win_id = $db->getWindowIDBySection($windownumber);
589
-      $windowlist = windowList();
588
+        $win_id = $db->getWindowIDBySection($windownumber);
589
+        $windowlist = windowList();
590 590
 
591
-      if (count($windowlist) == 0) {
591
+        if (count($windowlist) == 0) {
592 592
         trace("processRequests: no window found for command");
593
-      } elseif (is_numeric($window) && count($windowlist) <= $window) {
593
+        } elseif (is_numeric($window) && count($windowlist) <= $window) {
594 594
         trace("processRequests: window $window is out of bounds");
595
-      } elseif (!is_numeric($window)) {
595
+        } elseif (!is_numeric($window)) {
596 596
         trace("processRequests: unhandled window $window");
597
-      } else {
597
+        } else {
598 598
         trace("processRequests: command window");
599 599
         $windowname = $windowlist[$window];
600 600
         $windowhex = hexdec($windowname);
601
-      }
601
+        }
602 602
     }
603 603
 
604 604
     if ($windowname && array_key_exists('key', $_REQUEST)) {
605
-      $key = escapeshellcmd($_REQUEST['key']);
606
-      trace("processRequests: key '$key' in window '$windownumber'");
607
-      wmShow($windowname);
608
-      // activateControls($windowhex);
609
-      // displayCommand("xdotool windowfocus $windowhex key $key");
610
-
611
-      // trying mousemove and click for better vnc control
612
-      displayCommand("xdotool mousemove --window $windowhex 100 100 " .
613
-                     "key $key");
605
+        $key = escapeshellcmd($_REQUEST['key']);
606
+        trace("processRequests: key '$key' in window '$windownumber'");
607
+        wmShow($windowname);
608
+        // activateControls($windowhex);
609
+        // displayCommand("xdotool windowfocus $windowhex key $key");
610
+
611
+        // trying mousemove and click for better vnc control
612
+        displayCommand("xdotool mousemove --window $windowhex 100 100 " .
613
+                        "key $key");
614 614
     }
615 615
 
616 616
     if ($windowname && array_key_exists('keydown', $_REQUEST)) {
617
-      // TODO: keydown is currently mapped to key because we had problems
618
-      // with sticking keys (no keyup seen). This should be fixed by a
619
-      // better event handling.
620
-      $key = escapeshellcmd($_REQUEST['keydown']);
621
-      trace("processRequests: keydown '$key' in window '$windownumber'");
622
-      wmShow($windowname);
623
-      // activateControls($windowhex);
624
-      // displayCommand("xdotool windowfocus $windowhex key $key");
625
-
626
-      // trying mousemove and click for better vnc control
627
-      displayCommand("xdotool mousemove --window $windowhex 100 100 " .
628
-                     "key $key");
629
-      //~ displayCommand("xdotool windowfocus $windowhex keydown $key");
617
+        // TODO: keydown is currently mapped to key because we had problems
618
+        // with sticking keys (no keyup seen). This should be fixed by a
619
+        // better event handling.
620
+        $key = escapeshellcmd($_REQUEST['keydown']);
621
+        trace("processRequests: keydown '$key' in window '$windownumber'");
622
+        wmShow($windowname);
623
+        // activateControls($windowhex);
624
+        // displayCommand("xdotool windowfocus $windowhex key $key");
625
+
626
+        // trying mousemove and click for better vnc control
627
+        displayCommand("xdotool mousemove --window $windowhex 100 100 " .
628
+                        "key $key");
629
+        //~ displayCommand("xdotool windowfocus $windowhex keydown $key");
630 630
     }
631 631
 
632 632
     if ($windowname && array_key_exists('keyup', $_REQUEST)) {
633
-      // TODO: keyup is currently ignored, see comment above.
634
-      $key = escapeshellcmd($_REQUEST['keyup']);
635
-      trace("processRequests: keyup '$key' in window '$windownumber'");
636
-      // activateControls($windowhex);
637
-      //~ wmShow($windowname);
638
-      //~ displayCommand("xdotool windowfocus $windowhex keyup $key");
633
+        // TODO: keyup is currently ignored, see comment above.
634
+        $key = escapeshellcmd($_REQUEST['keyup']);
635
+        trace("processRequests: keyup '$key' in window '$windownumber'");
636
+        // activateControls($windowhex);
637
+        //~ wmShow($windowname);
638
+        //~ displayCommand("xdotool windowfocus $windowhex keyup $key");
639 639
     }
640 640
 
641 641
     if (array_key_exists('delete', $_REQUEST)) {
642
-      $delete = addslashes($_REQUEST['delete']);
643
-      trace("processRequests: delete='$delete', close window $windownumber");
642
+        $delete = addslashes($_REQUEST['delete']);
643
+        trace("processRequests: delete='$delete', close window $windownumber");
644 644
 
645
-      if ($delete == "VNC") {
645
+        if ($delete == "VNC") {
646 646
         trace("processRequests: delete vnc window");
647 647
         // call via daemon: ?window=vncwin&delete=VNC&vncid=123
648 648
         $win_id = escapeshellcmd($_REQUEST['vncid']);   // = hexWindow in database, but not on screen
649 649
         trace("VNC via Daemon ... id=$win_id");
650
-      } elseif (strstr($delete, "http")) {
650
+        } elseif (strstr($delete, "http")) {
651 651
         trace("processRequests: delete browser window");
652
-      } elseif (preg_match('/(^\w{3,}@\w{1,})/', $delete)) {
652
+        } elseif (preg_match('/(^\w{3,}@\w{1,})/', $delete)) {
653 653
         trace("processRequests: delete vnc client from webinterface");
654 654
         // call via webinterface
655 655
         $win_id = $db->querySingle("SELECT win_id FROM window WHERE file='$delete' AND handler='vnc'");
656
-      } else {
656
+        } else {
657 657
         // Restrict deletion to files known in the db.
658 658
         // TODO: check if given file and section match the values in the DB,
659 659
         // but currently, both those values can be ambiguous
@@ -661,67 +661,67 @@  discard block
 block discarded – undo
661 661
         $delete = str_replace(" ", "\ ", $delete);
662 662
         trace("processRequests: file in db: $file_in_db");
663 663
         if ($file_in_db) {
664
-          if(file_exists($delete)) {
664
+            if(file_exists($delete)) {
665 665
             trace("processRequests: delete file $delete");
666 666
             unlink($delete);
667
-          }
667
+            }
668 668
         } else {
669
-          trace("processRequests: given file not present in database!");
669
+            trace("processRequests: given file not present in database!");
670
+        }
670 671
         }
671
-      }
672
-      wmClose($win_id);
673
-      $db->deleteWindow($win_id);
672
+        wmClose($win_id);
673
+        $db->deleteWindow($win_id);
674 674
     }
675 675
 
676 676
     if (array_key_exists('closeOrphans', $_REQUEST)) {
677
-      // win_ids in db
678
-      $windows_in_db = $db->getWindows();
679
-      $db_ids = array();
677
+        // win_ids in db
678
+        $windows_in_db = $db->getWindows();
679
+        $db_ids = array();
680 680
 
681
-      if (count($windows_in_db) > 0) {
681
+        if (count($windows_in_db) > 0) {
682 682
         foreach ($windows_in_db as $win) {
683
-          array_push($db_ids, $win['win_id']);
683
+            array_push($db_ids, $win['win_id']);
684
+        }
684 685
         }
685
-      }
686 686
 
687
-      // win_ids on screen
688
-      $screen_ids = windowListOnScreen();
687
+        // win_ids on screen
688
+        $screen_ids = windowListOnScreen();
689 689
 
690
-      // orphaned windows
691
-      $orphan_ids = array_diff($screen_ids, $db_ids);
690
+        // orphaned windows
691
+        $orphan_ids = array_diff($screen_ids, $db_ids);
692 692
 
693
-      if (count($orphan_ids) > 0) {
693
+        if (count($orphan_ids) > 0) {
694 694
         // close windows on screen not existing in database
695 695
         foreach ($orphan_ids as $id) {
696
-          wmClose($id);
696
+            wmClose($id);
697
+        }
697 698
         }
698
-      }
699 699
     }
700 700
 
701 701
     if (array_key_exists('toggle', $_REQUEST)) {
702
-      // Change window state from visible to invisible and vice versa.
703
-      $state = $db->getWindowState($win_id);
704
-      trace("processRequests: toggle window $windownumber, id=$win_id, state=$state");
705
-      if ($state == "active") {
702
+        // Change window state from visible to invisible and vice versa.
703
+        $state = $db->getWindowState($win_id);
704
+        trace("processRequests: toggle window $windownumber, id=$win_id, state=$state");
705
+        if ($state == "active") {
706 706
         wmHide($win_id);
707 707
         $db->setWindowState($win_id, "inactive");
708
-      } else {
708
+        } else {
709 709
         wmShow($win_id);
710 710
         $db->setWindowState($win_id, "active");
711
-      }
711
+        }
712 712
     }
713
-  } elseif (array_key_exists('layout', $_REQUEST)) {
713
+    } elseif (array_key_exists('layout', $_REQUEST)) {
714 714
     setLayout(escapeshellcmd($_REQUEST['layout']));
715
-  } elseif (array_key_exists('logout', $_REQUEST)) {
715
+    } elseif (array_key_exists('logout', $_REQUEST)) {
716 716
     doLogout($_REQUEST['logout']);
717
-  } elseif (array_key_exists('newVncWindow', $_REQUEST)) {
717
+    } elseif (array_key_exists('newVncWindow', $_REQUEST)) {
718 718
     // TODO: Better write new code for VNC window.
719 719
     addNewWindow(unserialize(urldecode($_REQUEST['newVncWindow'])));
720
-  } elseif (array_key_exists('newWindow', $_REQUEST)) {
720
+    } elseif (array_key_exists('newWindow', $_REQUEST)) {
721 721
     createNewWindowSafe(unserialize(urldecode($_REQUEST['newWindow'])));
722
-  }
722
+    }
723 723
 
724
-  if (array_key_exists('switchWindows', $_REQUEST)) {
724
+    if (array_key_exists('switchWindows', $_REQUEST)) {
725 725
     $before = escapeshellcmd($_REQUEST['before']);
726 726
     $after = escapeshellcmd($_REQUEST['after']);
727 727
     trace("processRequests: switchWindows $before -> $after");
@@ -738,35 +738,35 @@  discard block
 block discarded – undo
738 738
 
739 739
     // Update display (no layout change).
740 740
     setLayout();
741
-  }
741
+    }
742 742
 
743
-  if (array_key_exists('openURL', $_REQUEST)) {
743
+    if (array_key_exists('openURL', $_REQUEST)) {
744 744
     $openURL = escapeshellcmd($_REQUEST['openURL']);
745 745
     trace("processRequests: openURL $openURL");
746 746
 
747 747
     // If URL leads to pdf file, download it and treat as upload
748 748
     $headers = get_headers($openURL, PHP_MAJOR_VERSION < 8 ? 1 : true);
749 749
     if ($headers["Content-Type"] == "application/pdf") {
750
-      debug("processRequests: url seems to lead to a pdf file, so downloading it...");
751
-      $temp_name = basename($openURL);
752
-      $temp_dir = "/tmp";
753
-      file_put_contents("$temp_dir/$temp_name", file_get_contents($openURL));
754
-      $mimetype = mime_content_type("$temp_dir/$temp_name");
755
-      debug("processRequests: mimetype is $mimetype");
756
-      if ($mimetype == "application/pdf") {
750
+        debug("processRequests: url seems to lead to a pdf file, so downloading it...");
751
+        $temp_name = basename($openURL);
752
+        $temp_dir = "/tmp";
753
+        file_put_contents("$temp_dir/$temp_name", file_get_contents($openURL));
754
+        $mimetype = mime_content_type("$temp_dir/$temp_name");
755
+        debug("processRequests: mimetype is $mimetype");
756
+        if ($mimetype == "application/pdf") {
757 757
         $_FILES['file']['name'] = "$temp_name";
758 758
         $_FILES['file']['tmp_name'] = "$temp_dir/$temp_name";
759 759
         $_FILES['file']['error'] = "downloaded_from_url";
760 760
         debug("processRequests: handing over to upload.php");
761 761
         include 'upload.php';
762
-      } else {
762
+        } else {
763 763
         debug("processRequests: deleting file");
764 764
         unlink("$temp_dir/$temp_name");
765
-      }
765
+        }
766 766
     } else {
767
-      $dt = new DateTime();
768
-      $date = $dt->format('Y-m-d H:i:s');
769
-      $window = array(
767
+        $dt = new DateTime();
768
+        $date = $dt->format('Y-m-d H:i:s');
769
+        $window = array(
770 770
         "id" => "",
771 771
         "win_id" => "",
772 772
         "section" => "",
@@ -775,15 +775,15 @@  discard block
 block discarded – undo
775 775
         "handler" => "palma-browser",
776 776
         "userid" => "",
777 777
         "date" => $date
778
-      );
779
-      createNewWindow($window);
778
+        );
779
+        createNewWindow($window);
780
+    }
780 781
     }
781
-  }
782 782
 
783
-  // TODO: check if query redundant?
784
-  if (array_key_exists('closeAll', $_REQUEST)) {
783
+    // TODO: check if query redundant?
784
+    if (array_key_exists('closeAll', $_REQUEST)) {
785 785
     $close = $_REQUEST['closeAll'];
786 786
     trace("processRequests: closeAll $close");
787 787
     closeAll();
788
-  }
788
+    }
789 789
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
       $section = intval($w['section']);
384 384
       if ($section >= 1 && $section <= $maxSection && $enabled) {
385 385
         // Show window, set size and position.
386
-        $wi = $section - 1;
386
+        $wi = $section-1;
387 387
         $dx = $screenWidth / $dim[$wi][2];
388 388
         $dy = $screenHeight / $dim[$wi][3];
389 389
         $x = $dim[$wi][0] * $dx;
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
     if ($windownumber != 'vncwin') {
584 584
       // This is the normal case.
585 585
       // Special handling is needed when called with window=vncwin, see below.
586
-      $window = intval($windownumber) - 1;
586
+      $window = intval($windownumber)-1;
587 587
 
588 588
       $win_id = $db->getWindowIDBySection($windownumber);
589 589
       $windowlist = windowList();
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
       if ($delete == "VNC") {
646 646
         trace("processRequests: delete vnc window");
647 647
         // call via daemon: ?window=vncwin&delete=VNC&vncid=123
648
-        $win_id = escapeshellcmd($_REQUEST['vncid']);   // = hexWindow in database, but not on screen
648
+        $win_id = escapeshellcmd($_REQUEST['vncid']); // = hexWindow in database, but not on screen
649 649
         trace("VNC via Daemon ... id=$win_id");
650 650
       } elseif (strstr($delete, "http")) {
651 651
         trace("processRequests: delete browser window");
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
         $delete = str_replace(" ", "\ ", $delete);
662 662
         trace("processRequests: file in db: $file_in_db");
663 663
         if ($file_in_db) {
664
-          if(file_exists($delete)) {
664
+          if (file_exists($delete)) {
665 665
             trace("processRequests: delete file $delete");
666 666
             unlink($delete);
667 667
           }
Please login to merge, or discard this patch.
upload.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -7,64 +7,64 @@  discard block
 block discarded – undo
7 7
 require_once 'auth.php';
8 8
 
9 9
 if (empty($_FILES)) {
10
-  $error = 99;
11
-  $filename = 'unknown';
10
+    $error = 99;
11
+    $filename = 'unknown';
12 12
 } else {
13
-  $error = $_FILES['file']['error'];
14
-  $filename = $_FILES['file']['name'];
13
+    $error = $_FILES['file']['error'];
14
+    $filename = $_FILES['file']['name'];
15 15
 }
16 16
 
17 17
 if (!is_dir(CONFIG_UPLOAD_DIR)) {
18
-  /* Target directory is missing, so create it now. */
19
-  mkdir(CONFIG_UPLOAD_DIR, 0755, true);
18
+    /* Target directory is missing, so create it now. */
19
+    mkdir(CONFIG_UPLOAD_DIR, 0755, true);
20 20
 }
21 21
 
22 22
 if ($error == UPLOAD_ERR_OK || $error == "downloaded_from_url") {
23
-  # All uploaded files are collected in the upload directory.
24
-  # If necessary, an index is added to get a unique filename.
25
-  $tempFile = $_FILES['file']['tmp_name'];
26
-  $targetFile = CONFIG_UPLOAD_DIR . "/$filename";
27
-  $index = 0;
28
-  $fparts = pathinfo($filename);
29
-  $fname = $fparts['filename'];
30
-  $ftype = null;
31
-  if (isset($fparts['extension'])) {
23
+    # All uploaded files are collected in the upload directory.
24
+    # If necessary, an index is added to get a unique filename.
25
+    $tempFile = $_FILES['file']['tmp_name'];
26
+    $targetFile = CONFIG_UPLOAD_DIR . "/$filename";
27
+    $index = 0;
28
+    $fparts = pathinfo($filename);
29
+    $fname = $fparts['filename'];
30
+    $ftype = null;
31
+    if (isset($fparts['extension'])) {
32 32
     $ftype = $fparts['extension'];
33
-  }
34
-  while (file_exists($targetFile)) {
33
+    }
34
+    while (file_exists($targetFile)) {
35 35
     $index++;
36 36
     if ($ftype) {
37
-      $targetFile = CONFIG_UPLOAD_DIR . "/$fname-$index.$ftype";
37
+        $targetFile = CONFIG_UPLOAD_DIR . "/$fname-$index.$ftype";
38 38
     } else {
39
-      $targetFile = CONFIG_UPLOAD_DIR . "/$fname-$index";
39
+        $targetFile = CONFIG_UPLOAD_DIR . "/$fname-$index";
40
+    }
40 41
     }
41
-  }
42
-  debug("upload.php: '$tempFile' to '$targetFile'");
43
-  if (is_uploaded_file($tempFile)) {
42
+    debug("upload.php: '$tempFile' to '$targetFile'");
43
+    if (is_uploaded_file($tempFile)) {
44 44
     move_uploaded_file($tempFile, $targetFile);
45
-  } elseif ($error == "downloaded_from_url") {
45
+    } elseif ($error == "downloaded_from_url") {
46 46
     rename($tempFile, $targetFile);
47
-  } else {
47
+    } else {
48 48
     trace("upload.php: upload failed!");
49
-  }
49
+    }
50 50
 } else {
51
-  // Support localisation.
52
-  require_once 'i12n.php';
51
+    // Support localisation.
52
+    require_once 'i12n.php';
53 53
 
54
-  $targetFile = CONFIG_UPLOAD_DIR . "/error.html";
55
-  $f = fopen($targetFile, 'w');
56
-  if ($f) {
54
+    $targetFile = CONFIG_UPLOAD_DIR . "/error.html";
55
+    $f = fopen($targetFile, 'w');
56
+    if ($f) {
57 57
     switch ($error) {
58
-      case UPLOAD_ERR_INI_SIZE:
58
+        case UPLOAD_ERR_INI_SIZE:
59 59
         $message = addslashes(__("This file is too large."));
60 60
         break;
61
-      case UPLOAD_ERR_FORM_SIZE:
61
+        case UPLOAD_ERR_FORM_SIZE:
62 62
         $message = addslashes(__("Large files are not supported."));
63 63
         break;
64
-      case UPLOAD_ERR_PARTIAL:
64
+        case UPLOAD_ERR_PARTIAL:
65 65
         $message = addslashes(__("File was only partially uploaded."));
66 66
         break;
67
-      default:
67
+        default:
68 68
         $message = sprintf(addslashes(__("Error code %s.")), $error);
69 69
         break;
70 70
     }
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
     fprintf($f, "</body>\n");
88 88
     fprintf($f, "</html>\n");
89 89
     fclose($f);
90
-  }
91
-  $targetFile = "file:///$targetFile";
90
+    }
91
+    $targetFile = "file:///$targetFile";
92 92
 }
93 93
 
94 94
 // create window object and send to nuc
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
 $date = $dt->format('Y-m-d H:i:s');
98 98
 
99 99
 $window = array(
100
-  "id" => "",
101
-  "win_id" => "",
102
-  "name" => "",
103
-  "state" => "",
104
-  "file" => $targetFile,
105
-  "userid" => "",
106
-  "date" => $date);
100
+    "id" => "",
101
+    "win_id" => "",
102
+    "name" => "",
103
+    "state" => "",
104
+    "file" => $targetFile,
105
+    "userid" => "",
106
+    "date" => $date);
107 107
 
108 108
 //echo "<body onLoad=\"sendToNuc('newWindow=".serialize($window)."')\" /></body>";
109 109
 
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 $curl = curl_init();
115 115
 // Set some options - we are passing in a useragent too here
116 116
 curl_setopt_array($curl, array(
117
-  CURLOPT_RETURNTRANSFER => 1,
118
-  CURLOPT_URL => CONFIG_CONTROL_FILE . '?newWindow=' . $sw,
119
-  CURLOPT_USERAGENT => 'PalMA cURL Request'
117
+    CURLOPT_RETURNTRANSFER => 1,
118
+    CURLOPT_URL => CONFIG_CONTROL_FILE . '?newWindow=' . $sw,
119
+    CURLOPT_USERAGENT => 'PalMA cURL Request'
120 120
 ));
121 121
 // Send the request & save response to $resp
122 122
 $resp = curl_exec($curl);
Please login to merge, or discard this patch.
Switch Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -55,18 +55,18 @@
 block discarded – undo
55 55
   $f = fopen($targetFile, 'w');
56 56
   if ($f) {
57 57
     switch ($error) {
58
-      case UPLOAD_ERR_INI_SIZE:
59
-        $message = addslashes(__("This file is too large."));
60
-        break;
61
-      case UPLOAD_ERR_FORM_SIZE:
62
-        $message = addslashes(__("Large files are not supported."));
63
-        break;
64
-      case UPLOAD_ERR_PARTIAL:
65
-        $message = addslashes(__("File was only partially uploaded."));
66
-        break;
67
-      default:
68
-        $message = sprintf(addslashes(__("Error code %s.")), $error);
69
-        break;
58
+    case UPLOAD_ERR_INI_SIZE:
59
+      $message = addslashes(__("This file is too large."));
60
+      break;
61
+    case UPLOAD_ERR_FORM_SIZE:
62
+      $message = addslashes(__("Large files are not supported."));
63
+      break;
64
+    case UPLOAD_ERR_PARTIAL:
65
+      $message = addslashes(__("File was only partially uploaded."));
66
+      break;
67
+    default:
68
+      $message = sprintf(addslashes(__("Error code %s.")), $error);
69
+      break;
70 70
     }
71 71
     fprintf($f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"");
72 72
     fprintf($f, "\"http://www.w3.org/TR/html4/strict.dtd\">");
Please login to merge, or discard this patch.
examples/screensaver/pictureshow.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -92,13 +92,13 @@
 block discarded – undo
92 92
 if (is_dir($pictures)) {
93 93
     $filelist = scandir($pictures);
94 94
     sort($filelist, SORT_NATURAL);
95
-  foreach ($filelist as $file) {
96
-      $picture = "$pictures/$file";
95
+    foreach ($filelist as $file) {
96
+        $picture = "$pictures/$file";
97 97
     if (is_file($picture)) {
98 98
         echo("<li style=\"background-image: url('$picture'); background-repeat: no-repeat\"></li>\n");
99 99
         //~ echo("<li><img src=\"$picture\"></li>\n");
100 100
     }
101
-  }
101
+    }
102 102
 } else {
103 103
     echo <<<EOD
104 104
         <li style="background-image: url('http://www.bib.uni-mannheim.de/typo3temp/pics/b1ad582e53.jpg');"></li>
Please login to merge, or discard this patch.