load config file for .phar files
[phancap.git] / www / setup.php
1 <?php
2 namespace phancap;
3 /**
4  * Check if everything is setup
5  */
6 header('HTTP/1.0 500 Internal Server Error');
7
8 if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
9     include_once __DIR__ . '/../src/phancap/Autoloader.php';
10     Autoloader::register();
11 } else {
12     include_once 'phancap/Autoloader.php';
13 }
14
15 $messages = array();
16
17 $config = new Config();
18 try {
19     $config->load();
20     $messages[][] = array('ok', 'Base configuration is ok');
21
22     if ($config->access === true) {
23         $messages[][] = array('ok', 'Everyone may access the API');
24     } else if ($config->access === false) {
25         $messages[][] = array('err', 'API access is disabled');
26     } else {
27         $messages[][] = array(
28             'ok',
29             count($config->access) . ' users may access the API'
30         );
31     }
32
33     foreach ($config->cfgFiles as $cfgFile) {
34         $messages[][] = array(
35             'info', 'Possible config file: ' . $cfgFile
36         );
37     }
38     if ($config->cfgFileExists) {
39         $messages[][] = array(
40             'ok', 'Configuration file loaded'
41         );
42     } else {
43         $messages[][] = array(
44             'info', 'No configuration file found'
45         );
46     }
47 } catch (\Exception $e) {
48     $messages[][] = array('err', $e->getMessage());
49 }
50
51 $adapter = array(
52     'Cutycapt'
53 );
54 foreach ($adapter as $classpart) {
55     $class = '\\phancap\\Adapter_' . $classpart;
56     $adapter = new $class();
57     $adapter->setConfig($config);
58     $errors = $adapter->isAvailable();
59     if ($errors === true) {
60         $messages[][] = array(
61             'ok', 'Adapter ' . $classpart . ' is available'
62         );
63     } else {
64         foreach ($errors as $msg) {
65             $messages['Adapter: '. $classpart][] = array('err', $msg);
66         }
67     }
68 }
69
70 $out = <<<HTM
71 <?xml version="1.0" encoding="utf-8"?>
72 <html>
73  <head>
74   <title>phancap setup check</title>
75   <style type="text/css">
76     li:before {
77         text-align: center;
78         display: inline-block;
79         width: 1em;
80         padding: 0 0.5ex;
81         margin-right: 0.5ex;
82     }
83     li.ok:before {
84         content: '✔';
85         color: green;
86     }
87     li.err:before {
88         content: "✘";
89         color: white;
90         background-color: red;
91     }
92     li.info:before {
93         content: "i";
94         font-weight: bold;
95         color: blue;
96     }
97   </style>
98  </head>
99  <body>
100   <h1>phancap setup check</h1>
101 <ul>
102 HTM;
103 foreach ($messages as $key => $messages) {
104     if (!is_numeric($key)) {
105         $out .= '<li>' . htmlspecialchars($key)
106             . '<ul>';
107     }
108     foreach ($messages as $data) {
109         list($state, $message) = $data;
110         $out .= '<li class="' . $state . '">';
111         $out .= htmlspecialchars($message);
112         $out .= '</li>' . "\n";
113     }
114     if (!is_numeric($key)) {
115         $out .= '</ul></li>' . "\n";
116     }
117 }
118 $out .= <<<HTM
119   </ul>
120   <p>
121    <a href="./">back</a> to the index
122   </p>
123  </body>
124 </html>
125 HTM;
126
127 header('HTTP/1.0 200 OK');
128 echo $out;
129 ?>