|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
function trace($text) |
|
4
|
|
|
{ |
|
5
|
|
|
static $firstRun = true; |
|
6
|
|
|
if ($firstRun) { |
|
7
|
|
|
$firstRun = false; |
|
8
|
|
|
openlog("palma", LOG_PID, LOG_USER); |
|
9
|
|
|
} |
|
10
|
|
|
syslog(LOG_NOTICE, $text); |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
function monitor($action) |
|
14
|
|
|
{ |
|
15
|
|
|
if (!defined('CONFIG_MONITOR_URL')) { |
|
16
|
|
|
//trace('CONFIG_MONITOR_URL is undefined'); |
|
17
|
|
|
return; |
|
18
|
|
|
} |
|
19
|
|
|
//trace("monitor $action"); |
|
20
|
|
|
$ch = curl_init(); |
|
21
|
|
|
$url = CONFIG_MONITOR_URL; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
curl_setopt_array($ch, array( |
|
24
|
|
|
CURLOPT_RETURNTRANSFER => 1, |
|
25
|
|
|
CURLOPT_URL => CONFIG_MONITOR_URL . '/' . CONFIG_STATIONNAME . '/' . base64_encode($action), |
|
26
|
|
|
CURLOPT_USERAGENT => 'PalMA cURL Request' |
|
27
|
|
|
)); |
|
28
|
|
|
$resp = curl_exec($ch); |
|
|
|
|
|
|
29
|
|
|
curl_close($ch); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
function set_constants() |
|
33
|
|
|
{ |
|
34
|
|
|
// Get some constants from a configuration file. |
|
35
|
|
|
$conf_fn = 'palma.ini'; |
|
36
|
|
|
if (!file_exists($conf_fn)) { |
|
37
|
|
|
$conf_fn = '/etc/palma.ini'; |
|
38
|
|
|
} |
|
39
|
|
|
$conf = parse_ini_file($conf_fn); |
|
40
|
|
|
//~ print_r($conf); |
|
41
|
|
|
|
|
42
|
|
|
// Entries in group 'display'. |
|
43
|
|
|
if (array_key_exists('id', $conf)) { |
|
44
|
|
|
define('CONFIG_DISPLAY', $conf['id']); |
|
45
|
|
|
} else { |
|
46
|
|
|
define('CONFIG_DISPLAY', ':1'); |
|
47
|
|
|
} |
|
48
|
|
|
if (array_key_exists('ssh', $conf)) { |
|
49
|
|
|
define('CONFIG_SSH', $conf['ssh']); |
|
50
|
|
|
} // There is no default value for CONFIG_SSH. |
|
51
|
|
|
|
|
52
|
|
|
// Entries in group 'general'. |
|
53
|
|
|
if (array_key_exists('password', $conf)) { |
|
54
|
|
|
define('CONFIG_PASSWORD', $conf['password']); |
|
55
|
|
|
} else { |
|
56
|
|
|
define('CONFIG_PASSWORD', false); |
|
57
|
|
|
} |
|
58
|
|
|
if (array_key_exists('pin', $conf)) { |
|
59
|
|
|
define('CONFIG_PIN', $conf['pin']); |
|
60
|
|
|
} else { |
|
61
|
|
|
define('CONFIG_PIN', true); |
|
62
|
|
|
} |
|
63
|
|
|
if (array_key_exists('stationname', $conf)) { |
|
64
|
|
|
define('CONFIG_STATIONNAME', $conf['stationname']); |
|
65
|
|
|
} else { |
|
66
|
|
|
define( |
|
67
|
|
|
'CONFIG_STATIONNAME', |
|
68
|
|
|
str_replace(array("\r", "\n", " "), '', `hostname -f`) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
if (array_key_exists('theme', $conf)) { |
|
72
|
|
|
define('CONFIG_THEME', $conf['theme']); |
|
73
|
|
|
} else { |
|
74
|
|
|
define('CONFIG_THEME', 'demo/simple'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
// Entries in group 'path'. |
|
78
|
|
|
if (array_key_exists('start_url', $conf)) { |
|
79
|
|
|
define('CONFIG_START_URL', $conf['start_url']); |
|
80
|
|
|
} else { |
|
81
|
|
|
// By default we use the FQDN of the host |
|
82
|
|
|
define( |
|
83
|
|
|
'CONFIG_START_URL', |
|
84
|
|
|
'http://' . str_replace(array("\r", "\n", " "), '', `hostname -f`) . '/' |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
if (array_key_exists('control_file', $conf)) { |
|
88
|
|
|
define('CONFIG_CONTROL_FILE', $conf['control_file']); |
|
89
|
|
|
} else { |
|
90
|
|
|
define('CONFIG_CONTROL_FILE', CONFIG_START_URL . 'control.php'); |
|
91
|
|
|
} |
|
92
|
|
|
if (array_key_exists('policy', $conf)) { |
|
93
|
|
|
define('CONFIG_POLICY', $conf['policy']); |
|
94
|
|
|
} // There is no default value for CONFIG_POLICY. |
|
95
|
|
|
if (array_key_exists('upload_dir', $conf)) { |
|
96
|
|
|
define('CONFIG_UPLOAD_DIR', $conf['upload_dir']); |
|
97
|
|
|
} else { |
|
98
|
|
|
define('CONFIG_UPLOAD_DIR', '/tmp/palma'); |
|
99
|
|
|
} |
|
100
|
|
|
if (array_key_exists('institution_url', $conf)) { |
|
101
|
|
|
define('CONFIG_INSTITUTION_URL', $conf['institution_url']); |
|
102
|
|
|
} else { |
|
103
|
|
|
define('CONFIG_INSTITUTION_URL', ''); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// Entries in group 'monitoring'. |
|
107
|
|
|
if (array_key_exists('monitor_url', $conf)) { |
|
108
|
|
|
define('CONFIG_MONITOR_URL', $conf['monitor_url']); |
|
109
|
|
|
} // There is no default value for CONFIG_MONITOR_URL. |
|
110
|
|
|
} |
|
111
|
|
|
set_constants(); |
|
112
|
|
|
|