1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
<?php
class LocationInfoHooks
{
/**
* @param string $uuid panel uuid
* @return false|string panel name if exists, false otherwise
*/
public static function getPanelName(string $uuid)
{
$ret = Database::queryFirst('SELECT panelname FROM locationinfo_panel WHERE paneluuid = :uuid', compact('uuid'));
if ($ret === false)
return false;
return $ret['panelname'];
}
/**
* Hook called by runmode module where we should modify the client config according to our
* needs. Disable standby/logout timeouts, enable autologin, set URL.
*/
public static function configHook(string $machineUuid, string $panelUuid): void
{
$type = InfoPanel::getConfig($panelUuid, $data);
if ($type === null)
return; // TODO: Invalid panel - what should we do?
if ($type === 'URL') {
if ($data['reload-minutes'] > 0) {
ConfigHolder::add('SLX_BROWSER_RELOAD_SECS', $data['reload-minutes'] * 60);
}
ConfigHolder::add('SLX_BROWSER_URL', $data['url']);
// Mangle non-upgraded panels
if (empty($data['blacklist']) && $data['whitelist'] === '*' && !empty($data['urllist'])) {
if ($data['iswhitelist']) {
$data['whitelist'] = str_replace(' ', "\n", $data['urllist']);
} else {
$data['blacklist'] = str_replace(' ', "\n", $data['urllist']);
}
}
ConfigHolder::add('SLX_BROWSER_WHITELIST', self::mangleList($data['whitelist']));
ConfigHolder::add('SLX_BROWSER_BLACKLIST', self::mangleList($data['blacklist']));
// Additionally, update runmode "isclient" flag depending on whether split-login is allowed or not
if (isset($data['split-login']) && $data['split-login']) {
RunMode::updateClientFlag($machineUuid, 'locationinfo', true);
} else { // Automatic login
RunMode::updateClientFlag($machineUuid, 'locationinfo', false);
ConfigHolder::add('SLX_AUTOLOGIN', 'ON', 1000);
ConfigHolder::add('SLX_ADDONS', '', 1000);
}
if (!empty($data['browser'])) {
$browser = $data['browser'];
if ($browser === 'chromium') {
$browser = 'chromium chrome';
} elseif ($browser === 'slx-browser') {
$browser = 'slxbrowser slx-browser';
}
ConfigHolder::add('SLX_BROWSER', $browser, 1000);
// There was probably some reason for this: When split-login is enabled, we force
// an interactive browser (full UI). I guess because some users might not
// know how to exit the browser otherwise? Past me was stupid enough not to leave
// a comment here or in the commit message....
if ($data['split-login'] ?? false) {
$data['interactive'] = true;
}
}
// Check if we should enable insecure SSL mode (accept invalid/self-signed certs etc.),
// if we should display the full UI, and whether we force HW acceleration for video playback
$features = [
'insecure-ssl' => 'SLX_BROWSER_INSECURE',
'interactive' => 'SLX_BROWSER_INTERACTIVE',
'hw-video' => 'SLX_BROWSER_HWVIDEO',
];
foreach ($features as $key => $var) {
if ($data[$key] ?? false) {
ConfigHolder::add($var, '1', 1000);
}
}
if (!empty($data['bookmarks'])) {
ConfigHolder::add('SLX_BROWSER_BOOKMARKS', $data['bookmarks'], 1000);
}
if ($data['allow-tty'] === 'yes' || $data['allow-tty'] === 'no') {
ConfigHolder::add('SLX_TTY_SWITCH', $data['allow-tty'], 1000);
}
if (($data['zoom-factor'] ?? 100) != 100) {
ConfigHolder::add('SLX_BROWSER_ZOOM', $data['zoom-factor']);
}
} else {
// Not URL panel
ConfigHolder::add('SLX_BROWSER_URL', 'http://' . $_SERVER['SERVER_ADDR'] . '/panel/' . $panelUuid);
ConfigHolder::add('SLX_AUTOLOGIN', 'ON', 1000);
ConfigHolder::add('SLX_ADDONS', '', 1000);
}
$al = ConfigHolder::get('SLX_AUTOLOGIN');
if (!empty($al) && $al !== 'OFF' && $al != 0) {
ConfigHolder::add('SLX_SHUTDOWN_TIMEOUT', '', 1000);
}
ConfigHolder::add('SLX_LOGOUT_TIMEOUT', '', 1000);
ConfigHolder::add('SLX_SCREEN_STANDBY_TIMEOUT', '', 1000);
ConfigHolder::add('SLX_SYSTEM_STANDBY_TIMEOUT', '', 1000);
}
/**
* Turn multiline list into space separated list, removing any
* comments (starting with #)
*/
private static function mangleList(string $list): string
{
return preg_replace('/\s*(#[^\n]*)?(\n|$)/', ' ', $list);
}
}
|