Completed
Pull Request — master (#154)
by Philipp
02:45
created

globals.php (3 issues)

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;
0 ignored issues
show
The assignment to $url is dead and can be removed.
Loading history...
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);
0 ignored issues
show
The assignment to $resp is dead and can be removed.
Loading history...
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
    {
38
        $conf_fn = '/etc/palma.ini';
39
    }
40
    $conf = parse_ini_file($conf_fn);
41
    //~ print_r($conf);
42
43
    // Entries in group 'display'.
44
    if (array_key_exists('id', $conf)) {
0 ignored issues
show
It seems like $conf can also be of type false; however, parameter $search of array_key_exists() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
    if (array_key_exists('id', /** @scrutinizer ignore-type */ $conf)) {
Loading history...
45
        define('CONFIG_DISPLAY', $conf['id']);
46
    } else {
47
        define('CONFIG_DISPLAY', ':1');
48
    }
49
    if (array_key_exists('ssh', $conf)) {
50
        define('CONFIG_SSH', $conf['ssh']);
51
    } // There is no default value for CONFIG_SSH.
52
53
    // Entries in group 'general'.
54
    if (array_key_exists('password', $conf)) {
55
        define('CONFIG_PASSWORD', $conf['password']);
56
    } else {
57
        define('CONFIG_PASSWORD', false);
58
    }
59
    if (array_key_exists('pin', $conf)) {
60
        define('CONFIG_PIN', $conf['pin']);
61
    } else {
62
        define('CONFIG_PIN', true);
63
    }
64
    if (array_key_exists('stationname', $conf)) {
65
        define('CONFIG_STATIONNAME', $conf['stationname']);
66
    } else {
67
        define('CONFIG_STATIONNAME',
68
               str_replace(array("\r", "\n", " "), '', `hostname -f`));
69
    }
70
    if (array_key_exists('theme', $conf)) {
71
        define('CONFIG_THEME', $conf['theme']);
72
    } else {
73
        define('CONFIG_THEME', 'demo/simple');
74
    }
75
76
    // Entries in group 'path'.
77
    if (array_key_exists('start_url', $conf)) {
78
        define('CONFIG_START_URL', $conf['start_url']);
79
    } else {
80
        // By default we use the FQDN of the host
81
      define('CONFIG_START_URL',
82
             'http://' . str_replace(array("\r", "\n", " "), '', `hostname -f`) . '/');
83
    }
84
    if (array_key_exists('control_file', $conf)) {
85
        define('CONFIG_CONTROL_FILE', $conf['control_file']);
86
    } else {
87
        define('CONFIG_CONTROL_FILE', CONFIG_START_URL . 'control.php');
88
    }
89
    if (array_key_exists('policy', $conf)) {
90
        define('CONFIG_POLICY', $conf['policy']);
91
    } // There is no default value for CONFIG_POLICY.
92
    if (array_key_exists('upload_dir', $conf)) {
93
        define('CONFIG_UPLOAD_DIR', $conf['upload_dir']);
94
    } else {
95
        define('CONFIG_UPLOAD_DIR', '/tmp/palma');
96
    }
97
    if (array_key_exists('institution_url', $conf)) {
98
        define('CONFIG_INSTITUTION_URL', $conf['institution_url']);
99
    } else {
100
        define('CONFIG_INSTITUTION_URL', '');
101
    }
102
103
    // Entries in group 'monitoring'.
104
    if (array_key_exists('monitor_url', $conf)) {
105
        define('CONFIG_MONITOR_URL', $conf['monitor_url']);
106
    } // There is no default value for CONFIG_MONITOR_URL.
107
}
108
set_constants();
109