Completed
Branch master (f6660f)
by Stefan
02:22
created

control.php (16 issues)

1
<?php
2
3
// Copyright (C) 2014 Universitätsbibliothek Mannheim
4
// See file LICENSE for license details.
5
6
// Authors: Alexander Wagner, Stefan Weil
7
8
// TODO: Authentisierung. Funktioniert hier nicht mit auth.php,
9
// daher vielleicht über Datenbankabfrage.
10
11
// Test whether the script was called directly (used for unit test). Use some
12
// heuristics to detect whether we are not running in a web application.
13
if (isset($unittest)) {
14
    $unittest = array();
15
}
16
$unittest[__FILE__] = !isset($_SERVER['SERVER_NAME']);
17
18
// Connect to database and get configuration constants.
19
require_once('DBConnector.class.php');
20
$db = new DBConnector();
21
22
if (!$unittest[__FILE__]) {
23
    trace("QUERY_STRING=" . $_SERVER['QUERY_STRING']);
24
}
25
26
function displayCommand($cmd)
27
{
28
    if (defined('CONFIG_SSH')) {
29
        $cmd = CONFIG_SSH . " 'DISPLAY=" . CONFIG_DISPLAY . " $cmd'";
30
    } else {
31
        $cmd = "DISPLAY=" . CONFIG_DISPLAY . " HOME=/var/www $cmd";
32
    }
33
34
    $result = shell_exec($cmd);
35
    trace("cmd=$cmd, result=$result");
36
    return $result;
37
}
38
39
function wmClose($id)
40
{
41
    // Close window gracefully.
42
    displayCommand("wmctrl -i -c $id");
43
}
44
45
function wmHide($id)
46
{
47
    // Hide window. This is done by moving it to desktop 1.
48
    displayCommand("wmctrl -i -r $id -t 1");
49
}
50
51
function wmShow($id)
52
{
53
    // Show window on current desktop.
54
    displayCommand("wmctrl -i -R $id");
55
}
56
57
function windowListOnScreen()
58
{
59
    $list = array();
60
    $windows = explode("\n", displayCommand('wmctrl -l'));
61
    foreach ($windows as $w) {
62
        $field = explode(' ', $w);
63
        $id = $field[0];
64
        if ($id != '') {
65
            array_push($list, $id);
66
        }
67
    }
68
    return $list;
69
}
70
71
// simple list with content from database
72
73
function windowList()
74
{
75
    $list = array();
76
    global $db;
77
78
    // Get ordered list of all windows from the database.
79
    $windows = $db->getWindows();
80
    foreach ($windows as $w) {
81
        $id = $w['win_id'];
82
        if ($id != '') {
83
            array_push($list, $id);
84
        }
85
    }
86
    return $list;
87
}
88
89
function closeAll()
90
{
91
    global $db;
92
93
    $windows_on_screen = windowListOnScreen();
94
95
    foreach ($windows_on_screen as $id) {
96
        wmClose($id);
97
        if ($db->getWindowState($id) != null) {
98
            $db->deleteWindow($id);
99
        }
100
    }
101
102
    // Remove any remaining window entries in database.
103
    $db->exec('DELETE FROM window');
104
105
    // Remove any remaining files in the upload directory.
106
    clearUploadDir();
107
}
108
109
function doLogout($username)
110
{
111
    global $db;
112
    if ($username == 'ALL') {
113
        // Terminate all user connections and reset system.
114
        closeAll();
115
        $db->resetTables();
116
    }
117
}
118
119
function clearUploadDir()
120
{
121
    # Remove all files in the upload directory.
122
    if (is_dir(CONFIG_UPLOAD_DIR)) {
123
        if ($dh = opendir(CONFIG_UPLOAD_DIR)) {
124
            while (($file = readdir($dh)) !== false) {
125
                if ($file != "." and $file != "..") {
126
                    unlink(CONFIG_UPLOAD_DIR . "/$file");
127
                }
128
            }
129
            closedir($dh);
130
        }
131
    }
132
}
133
134
function setLayout($layout)
135
{
136
    // Set layout of team display. Layouts are specified by their name.
137
    // We use names like g1x1, g2x1, g1x2, ...
138
    // Restore the last layout if the function is called with a null argument.
139
140
    global $db;
141
142
    if ($layout == null) {
143
        $layout = $db->querySingle("SELECT value FROM setting WHERE key='layout'");
144
    } else {
145
        $db->exec("UPDATE setting SET value='$layout' WHERE key='layout'");
146
    }
147
148
    trace("layout $layout");
149
150
    $geom = array();
151
    $geom['g1x1'] = array(
152
                        array(0, 0, 1, 1)
153
                    );
154
    $geom['g2x1'] = array(
155
                        array(0, 0, 2, 1), array(1, 0, 2, 1)
156
                    );
157
    $geom['g1x2'] = array(
158
                        array(0, 0, 1, 2), array(0, 1, 1, 2)
159
                    );
160
    $geom['g1a2'] = array(
161
                        array(0, 0, 2, 1), array(1, 0, 2, 2),
162
                        array(1, 1, 2, 2)
163
                    );
164
    $geom['g2x2'] = array(
165
                        array(0, 0, 2, 2), array(1, 0, 2, 2),
166
                        array(0, 1, 2, 2), array(1, 1, 2, 2)
167
                    );
168
169
    $dim = $geom[$layout];
170
171
    // Make sure that desktop 0 is selected.
172
    displayCommand('wmctrl -s 0');
173
174
    // Get width and height of desktop.
175
    $desktops = displayCommand("wmctrl -d");
176
    // $desktop looks like this.
177
    // 0  * DG: 1600x900  VP: 0,0  WA: 0,27 1600x873  Arbeitsfläche 1
1 ignored issue
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
178
    $fields = preg_split("/[\n ]+/", $desktops);
179
    $geom = preg_split("/x/", $fields[3]);
180
    $screenWidth = $geom[0];
181
    $screenHeight = $geom[1];
182
183
    // Show all windows for the current layout which are not disabled.
184
185
    $maxSection = count($dim);
186
    // Get ordered list of all windows from the database.
187
    $windows = $db->getWindows();
188
    foreach ($windows as $w) {
189
        $id = $w['win_id'];
190
        $enabled = $w['state'] == 'active';
191
        $section = $w['section'];
192
        if ($section >= 1 && $section <= $maxSection && $enabled) {
193
            // Show window, set size and position.
194
            $wi = $section - 1;
195
            $dx = $screenWidth / $dim[$wi][2];
196
            $dy = $screenHeight / $dim[$wi][3];
197
            $x = $dim[$wi][0] * $dx;
198
            $y = $dim[$wi][1] * $dy;
199
            wmShow($id);
200
            displayCommand("wmctrl -i -r $id -e 0,$x,$y,$dx,$dy");
201
        } else {
202
            // Hide window.
203
            wmHide($id);
204
        }
205
    }
206
}
207
208
function activateControls($windowhex)
209
{
210
    global $db;
211
    $fhandler = $db->querySingle("SELECT handler FROM window WHERE win_id='$windowhex'");
212
    error_log("activateControls for handler $fhandler");
213
}
214
215
function addNewWindow($db, $new)
216
{
217
    // Add a new window to the monitor. This window either uses the first
218
    // unused section or it will be hidden.
219
220
    trace('addNewWindow ' . serialize($new));
221
    // '$new' already contains 'file', 'handler' and 'date', as well as the
1 ignored issue
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
222
    // username for VNC connections only.
223
    // 'win_id', 'section' have to be defined afterwards.
224
225
    // Get new window. Wait up to 10 s for it.
226
    $t_total = 0;
227
    do {
228
        $window_ids_on_screen = windowListOnScreen();
229
        $windows_in_db = $db->getWindows();
230
231
        $existing_ids = array();
232
        $new_window_id = '';
233
234
        if (count($windows_in_db) > 0) {
235
            // Add db windows to existing_ids.
236
            foreach ($windows_in_db as $win) {
237
                $existing_ids[] = $win['win_id'];
238
            }
239
240
            $new_window = array_diff($window_ids_on_screen, $existing_ids);
241
            foreach ($new_window as $win_id) {
242
                if ($win_id != "") {
243
                    $new_window_id = $win_id;
244
                }
245
            }
246
        } elseif (!empty($window_ids_on_screen)) {
247
            $new_window_id = $window_ids_on_screen[0];
248
        }
249
    } while (!$new_window_id && $t_total++ <= 10 && !sleep(1));
250
251
    if (!$new_window_id) {
252
        trace('warning: no new window found');
253
        return;
254
    }
255
256
    trace("new window $new_window_id");
257
258
    // Determine last assigned monitor section.
259
    //~ $max_section = $db->querySingle('SELECT MAX(section) FROM window');
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
260
261
    // Get first unused monitor section.
262
    $section = $db->nextID();
263
264
    // If all information is available, create window object.
265
266
    $new['id'] = $section;
267
    $new['section'] = $section;
268
269
    if ($section <= 4) {
270
        $new['state'] = "active";
271
    } else {
272
        // All sections are used, so there is no free one for the new window.
273
        $new['state'] = "inactive";
274
        // We could hide the new window immediately, but don't do it here:
275
        // Each new window will be shown in the middle of the screen.
276
        //~ wmHide($new_window_id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
277
        //~ trace("hide new window $new_window_id");
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
278
    }
279
280
    // $new['file'] = $active_window; (?)
1 ignored issue
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
281
282
    // TODO: check how to insert the userid for all content, not just vnc.
283
    // Perhaps better add to array in upload.php ?
284
    $userid = "";
285
    $queryid = $db->querySingle('SELECT user.userid FROM user WHERE user.name="' . $new['userid'] .'"');
286
    if (!empty($queryid)) {
287
        $userid = $queryid;
288
    } else {
289
        $userid = "all";
290
    }
291
292
    $myWindow = array(
293
        $new['id'],
294
        $new_window_id,
295
        $new['section'],
296
        $new['state'],
297
        $new['file'],
298
        $new['handler'],
299
        $userid,
300
        $new['date']
301
    );
302
303
    // Save window in database.
304
    $db->insertWindow($myWindow);
305
}
306
307
function createNewWindow($db, $w)
308
{
309
    // '$w' already contains 'file', 'handler' and 'date'.
1 ignored issue
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
310
    // 'win_id', 'section' have to be defined afterwards.
311
312
    $handler = $w['handler'];
313
    // TODO: use escapeshellarg() for filename.
314
    $filename = $w['file'];
315
316
    $cmd = "$handler '$filename'";
317
    displayCommand("/usr/bin/nohup $cmd >/dev/null 2>&1 &");
318
319
    addNewWindow($db, $w);
320
}
321
322
function processRequests($db)
323
{
324
    if (array_key_exists('window', $_REQUEST)) {
325
        // All windows related commands must start with window=.
326
327
        $windownumber = $_REQUEST['window'];
328
        $windowname = false;
329
        $windowhex = 0;
330
        // TODO: $win_id und $windowname können vermutlich zusammengefasst werden.
331
        $win_id = 0;
332
333
        if ($windownumber != 'vncwin') {
334
            // This is the normal case.
335
            // Special handling is needed when called with window=vncwin, see below.
336
            $window = $windownumber - 1;
337
338
            $win_id = $db->getWindowIDBySection($windownumber);
339
            $windowlist = windowList();
340
341
            if (count($windowlist) == 0) {
342
                trace("no window found for command");
343
            } else {
344
                // TODO: improve test whether window exists.
345
                $windowname = $windowlist[$window];
346
                $windowhex = hexdec($windowname);
347
            }
348
        }
349
350
        if ($windowname && array_key_exists('key', $_REQUEST)) {
351
            $key = $_REQUEST['key'];
352
            trace("key '$key' in window '$windownumber'");
353
            wmShow($windowname);
354
            // activateControls($windowhex);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
355
            // displayCommand("xdotool windowfocus $windowhex key $key");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
356
357
            // trying mousemove and click for better vnc control
358
            displayCommand("xdotool mousemove --window $windowhex 100 100 " .
359
                       "key $key");
360
        }
361
362
        if ($windowname && array_key_exists('keydown', $_REQUEST)) {
363
            // TODO: keydown is currently mapped to key because we had problems
364
            // with sticking keys (no keyup seen). This should be fixed by a
365
            // better event handling.
366
            $key = $_REQUEST['keydown'];
367
            trace("keydown '$key' in window '$windownumber'");
368
            wmShow($windowname);
369
            // activateControls($windowhex);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
370
            // displayCommand("xdotool windowfocus $windowhex key $key");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
371
372
            // trying mousemove and click for better vnc control
373
            displayCommand("xdotool mousemove --window $windowhex 100 100 " .
374
                       "key $key");
375
            //~ displayCommand("xdotool windowfocus $windowhex keydown $key");
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
376
        }
377
378
        if ($windowname && array_key_exists('keyup', $_REQUEST)) {
379
            // TODO: keyup is currently ignored, see comment above.
380
            $key = $_REQUEST['keyup'];
381
            trace("keyup '$key' in window '$windownumber'");
382
            // activateControls($windowhex);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
383
            //~ wmShow($windowname);
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
384
            //~ displayCommand("xdotool windowfocus $windowhex keyup $key");
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
385
        }
386
387
        if (array_key_exists('delete', $_REQUEST)) {
388
389
            $delete = str_replace(" ", "\ ", addslashes($_REQUEST['delete']));
390
            trace("delete=$delete, close window $windownumber");
391
392
            if (file_exists($delete)) {
393
                trace("+++ DELETE FILE FROM WEBINTERFACE +++");
394
                unlink($delete);
395
            } elseif ($delete == "VNC") {
396
                trace("+++ DELETE VNC Client FROM DAEMON +++");
397
                // call via daemon: ?window=vncwin&delete=VNC&vncid=123
398
                trace("vnc delete in control");
399
                $win_id = $_REQUEST['vncid'];   // = hexWindow in database, but not on screen
400
                trace("VNC cia Daemon ... id=$win_id");
401
402
            } elseif (strstr($delete, "http")) {
403
                trace("+++ DELETE Browserwindow +++");
404
            } elseif (preg_match('/(^\w{3,}@\w{1,})/', $delete)) {
405
                trace("+++ DELETE VNC Client FROM WEBINTERFACE +++");
406
                // call via webinterface
407
                $win_id = $db->querySingle("SELECT win_id FROM window WHERE file='$delete' AND handler='vnc'");
408
                trace("DELETE VNC Window with ID=$win_id FROM Database ::
409
                SELECT win_id FROM window WHERE file='$delete' AND handler='vnc'");
410
            } else {
411
                trace("Unhandled delete for '$delete'");
412
            }
413
414
            wmClose($win_id);
415
            $db->deleteWindow($win_id);
416
        }
417
418
        if (array_key_exists('closeOrphans', $_REQUEST)) {
419
420
            // win_ids in db
421
            $windows_in_db = $db->getWindows();
422
            $db_ids = array();
423
424
            if (count($windows_in_db) > 0) {
425
                foreach ($windows_in_db as $win) {
426
                    array_push($db_ids, $win['win_id']);
427
                }
428
            }
429
430
            // win_ids on screen
431
            $screen_ids = windowListOnScreen();
432
433
            // orphaned windows
434
            $orphan_ids = array_diff($screen_ids, $db_ids);
435
436
            if (count($orphan_ids) > 0) {
437
                // close windows on screen not existing in database
438
                foreach ($orphan_ids as $id) {
439
                    wmClose($id);
440
                }
441
            }
442
443
        }
444
445
        if (array_key_exists('toggle', $_REQUEST)) {
446
            // Change window state from visible to invisible and vice versa.
447
            $state = $db->getWindowState($win_id);
448
            trace("toggle window $windownumber, id=$win_id, state=$state");
449
            if ($state == "active") {
450
                wmHide($win_id);
451
                $db->setWindowState($win_id, "inactive");
452
            } else {
453
                wmShow($win_id);
454
                $db->setWindowState($win_id, "active");
455
            }
456
        }
457
    } elseif (array_key_exists('layout', $_REQUEST)) {
458
        setLayout($_REQUEST['layout']);
459
    } elseif (array_key_exists('logout', $_REQUEST)) {
460
        doLogout($_REQUEST['logout']);
461
    } elseif (array_key_exists('newVncWindow', $_REQUEST)) {
462
        // TODO: Better write new code for VNC window.
463
        addNewWindow($db, unserialize(urldecode($_REQUEST['newVncWindow'])));
464
    } elseif (array_key_exists('newWindow', $_REQUEST)) {
465
        createNewWindow($db, unserialize(urldecode($_REQUEST['newWindow'])));
466
    }
467
468
    if (array_key_exists('switchWindows', $_REQUEST)) {
469
        $before = $_REQUEST['before'];
470
        $after = $_REQUEST['after'];
471
        trace("switching $before and $after");
472
473
        // exchange section
474
        $win_id1 = $db->getWindowIDBySection($before);
475
        $win_id2 = $db->getWindowIDBySection($after);
476
477
        $db->updateWindow($win_id1, 'section', $after);
478
        $db->updateWindow($win_id2, 'section', $before);
479
480
        trace("++updating database $win_id1 section=$after");
481
        trace("++updating database $win_id2 section=$before");
482
483
        // Update display (no layout change).
484
        setLayout(null);
485
    }
486
487
    if (array_key_exists('openURL', $_REQUEST)) {
488
        $openURL = $_REQUEST['openURL'];
489
        trace("openURL $openURL");
490
491
        // If URL leads to pdf file, download it and treat as upload
492
        if (preg_match("/.(pdf|PDF)$/", $openURL)) {
493
            trace("openURL $openURL is a pdf file. Downloading it.");
494
            $date = time();
495
            $temp_name = basename($openURL);
496
            $temp_dir = "/tmp/palma_$date";
497
            shell_exec("mkdir $temp_dir && wget $openURL -P $temp_dir/");
498
499
            $_FILES['file']['name'] = "$temp_name";
500
            $_FILES['file']['tmp_name'] = "$temp_dir/$temp_name";
501
            $_FILES['file']['error'] = "downloaded_from_url";
502
503
            trace("Handing over to upload.php");
504
            include 'upload.php';
505
        } else {
506
            $dt = new DateTime();
507
            $date = $dt->format('Y-m-d H:i:s');
508
            $window = array(
509
                "id" => "",
510
                "win_id" => "",
511
                "section" => "",
512
                "state" => "",
513
                "file" => $openURL,
514
                // "handler" => "iceweasel --new-window",
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
515
                "handler" => "/usr/bin/midori -e show-navigationbar=false -a",
516
                "userid" => "",
517
                "date" => $date
518
            );
519
            createNewWindow($db, $window);
520
        }
521
    }
522
523
    // TODO: chef if query redundant?
524
    if (array_key_exists('closeAll', $_REQUEST)) {
525
        $close = $_REQUEST['closeAll'];
526
        trace("close all windows $close");
527
        closeAll();
528
    }
529
530
} // processRequests
531
532
processRequests($db);
533
534
if ($unittest[__FILE__]) {
535
    // Experimental: Get function call from startx.
536
    parse_str(implode('&', array_slice($argv, 1)), $_GET);
537
    if (isset($_GET) && count($_GET) > 0) {
538
        foreach ($_GET as $key => $value) {
539
            // Only defined actions allowed.
540
            if ($key == "doLogout") {
541
                doLogout($value);
542
            }
543
        }
544
    } else {
545
        // Run unit test.
546
        echo("<p>Running unit test</p>");
547
        trace("Running unit test for " . __FILE__);
548
        trace("Finished unit test");
549
    }
550
}
551