Support IDNA - internationalized domain names
[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 if (!function_exists('idn_to_ascii')) {
86     $messages[][] = array(
87         'err', 'Function "idn_to_ascii" is not available'
88     );
89 }
90
91 $out = <<<HTM
92 <!DOCTYPE html>
93 <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
94  <head>
95   <title>phancap setup check</title>
96   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
97   <link rel="stylesheet" href="css/bootstrap.min.css"/>
98   <link rel="stylesheet" href="css/bootstrap-theme.min.css"/>
99   <link rel="stylesheet" href="css/phancap.css"/>
100   <meta name="viewport" content="width=device-width, initial-scale=1"/>
101   <style type="text/css">
102     /*
103     li:before {
104         text-align: center;
105         display: inline-block;
106         width: 1em;
107         padding: 0 0.5ex;
108         margin-right: 0.5ex;
109     }
110     li.ok:before {
111         content: '✔';
112         color: green;
113     }
114     li.err:before {
115         content: "✘";
116         color: white;
117         background-color: red;
118     }
119     li.info:before {
120         content: "i";
121         font-weight: bold;
122         color: blue;
123     }
124     */
125   </style>
126  </head>
127  <body>
128   <div class="container">
129    <div class="row">
130     <div class="col-md-2"></div>
131     <div class="col-md-8">
132
133      <div class="page-header">
134       <h1>phancap setup check</h1>
135      </div>
136
137      <ul class="list-group">
138 HTM;
139 $stateMap = array(
140     'ok' => 'success',
141     'info' => 'info',
142     'err' => 'danger'
143 );
144 foreach ($messages as $key => $messages) {
145     if (!is_numeric($key)) {
146         $out .= '<li class="list-group-item">' . htmlspecialchars($key)
147             . '<ul class="list-group">';
148     }
149     foreach ($messages as $data) {
150         list($state, $message) = $data;
151         $out .= '<li class="list-group-item list-group-item-'
152             . $stateMap[$state] . '">';
153         $out .= htmlspecialchars($message);
154         $out .= '</li>' . "\n";
155     }
156     if (!is_numeric($key)) {
157         $out .= '</ul></li>' . "\n";
158     }
159 }
160 $out .= <<<HTM
161      </ul>
162      <p>
163       <a href="./">back</a> to the index
164      </p>
165     </div>
166    </div>
167   </div>
168
169   <div class="container footer">
170    <a href="http://cweiske.de/phancap.htm">phancap</a>,
171    the self-hosted website screenshot service is available under the
172    <a href="http://www.gnu.org/licenses/agpl-3.0.html">
173     <abbr title="GNU Affero General Public License">AGPL</abbr></a>.
174   </div>
175
176  </body>
177 </html>
178 HTM;
179
180 header('HTTP/1.0 200 OK');
181 echo $out;
182 ?>