add footer to html
[phancap.git] / www / setup.php
1 <?php
2 /**
3  * Check if everything is setup correctly
4  *
5  * PHP version 5
6  *
7  * @category  Tools
8  * @package   Phancap
9  * @author    Christian Weiske <cweiske@cweiske.de>
10  * @copyright 2014 Christian Weiske
11  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12  * @link      http://cweiske.de/phancap.htm
13  */
14 namespace phancap;
15 header('HTTP/1.0 500 Internal Server Error');
16
17 if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
18     include_once __DIR__ . '/../src/phancap/Autoloader.php';
19     Autoloader::register();
20 } else {
21     include_once 'phancap/Autoloader.php';
22 }
23
24 $messages = array();
25
26 $config = new Config();
27 try {
28     $config->load();
29     if ($config->disableSetup) {
30         header('HTTP/1.0 403 Forbidden');
31         header('Content-type: text/plain');
32         echo "Setup check is disabled.\n";
33         exit(1);
34     }
35     $messages[][] = array('ok', 'Base configuration is ok');
36
37     if ($config->access === true) {
38         $messages[][] = array('ok', 'Everyone may access the API');
39     } else if ($config->access === false) {
40         $messages[][] = array('err', 'API access is disabled');
41     } else {
42         $messages[][] = array(
43             'ok',
44             count($config->access) . ' users may access the API'
45         );
46     }
47
48     foreach ($config->cfgFiles as $cfgFile) {
49         $messages[][] = array(
50             'info', 'Possible config file: ' . $cfgFile
51         );
52     }
53     if ($config->cfgFileExists) {
54         $messages[][] = array(
55             'ok', 'Configuration file loaded'
56         );
57     } else {
58         $messages[][] = array(
59             'info', 'No configuration file found'
60         );
61     }
62 } catch (\Exception $e) {
63     $messages[][] = array('err', $e->getMessage());
64 }
65
66 $adapter = array(
67     'Cutycapt'
68 );
69 foreach ($adapter as $classpart) {
70     $class = '\\phancap\\Adapter_' . $classpart;
71     $adapter = new $class();
72     $adapter->setConfig($config);
73     $errors = $adapter->isAvailable();
74     if ($errors === true) {
75         $messages[][] = array(
76             'ok', 'Adapter ' . $classpart . ' is available'
77         );
78     } else {
79         foreach ($errors as $msg) {
80             $messages['Adapter: '. $classpart][] = array('err', $msg);
81         }
82     }
83 }
84
85 $out = <<<HTM
86 <?xml version="1.0" encoding="utf-8"?>
87 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
88 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
89  <head>
90   <title>phancap setup check</title>
91   <link rel="stylesheet" href="css/bootstrap.min.css"/>
92   <link rel="stylesheet" href="css/bootstrap-theme.min.css"/>
93   <link rel="stylesheet" href="css/phancap.css"/>
94   <meta name="viewport" content="width=device-width, initial-scale=1"/>
95   <style type="text/css">
96     /*
97     li:before {
98         text-align: center;
99         display: inline-block;
100         width: 1em;
101         padding: 0 0.5ex;
102         margin-right: 0.5ex;
103     }
104     li.ok:before {
105         content: '✔';
106         color: green;
107     }
108     li.err:before {
109         content: "✘";
110         color: white;
111         background-color: red;
112     }
113     li.info:before {
114         content: "i";
115         font-weight: bold;
116         color: blue;
117     }
118     */
119   </style>
120  </head>
121  <body>
122   <div class="container">
123    <div class="row">
124     <div class="col-md-2"></div>
125     <div class="col-md-8">
126
127      <div class="page-header">
128       <h1>phancap setup check</h1>
129      </div>
130
131      <ul class="list-group">
132 HTM;
133 $stateMap = array(
134     'ok' => 'success',
135     'info' => 'info',
136     'err' => 'danger'
137 );
138 foreach ($messages as $key => $messages) {
139     if (!is_numeric($key)) {
140         $out .= '<li class="list-group-item">' . htmlspecialchars($key)
141             . '<ul class="list-group">';
142     }
143     foreach ($messages as $data) {
144         list($state, $message) = $data;
145         $out .= '<li class="list-group-item list-group-item-'
146             . $stateMap[$state] . '">';
147         $out .= htmlspecialchars($message);
148         $out .= '</li>' . "\n";
149     }
150     if (!is_numeric($key)) {
151         $out .= '</ul></li>' . "\n";
152     }
153 }
154 $out .= <<<HTM
155      </ul>
156      <p>
157       <a href="./">back</a> to the index
158      </p>
159     </div>
160    </div>
161   </div>
162
163   <div class="container footer">
164    <a href="http://cweiske.de/phancap.htm">phancap</a>,
165    the self-hosted website screenshot service is available under the
166    <a href="http://www.gnu.org/licenses/agpl-3.0.html">
167     <abbr title="GNU Affero General Public License">AGPL</abbr></a>.
168   </div>
169
170  </body>
171 </html>
172 HTM;
173
174 header('HTTP/1.0 200 OK');
175 echo $out;
176 ?>