rework setup check
[phorkie.git] / www / setup.php
1 <?php
2 /**
3  * Check if all is setup correctly
4  */
5 namespace phorkie;
6 header('HTTP/1.0 500 Internal Server Error');
7
8 $reqWritePermissions = false;
9 require_once 'www-header.php';
10
11 if (!$GLOBALS['phorkie']['cfg']['setupcheck']) {
12     header('HTTP/1.0 403 Forbidden');
13     header('Content-type: text/plain');
14     echo "Setup check is disabled\n";
15     exit(1);
16 }
17
18 $messages = SetupCheck::run();
19 $errors = 0;
20 foreach ($messages as $arMessage) {
21     list($type, $message) = $arMessage;
22     $type == 'error' && ++$errors;
23 }
24 if ($errors == 0) {
25     header('HTTP/1.0 200 OK');
26 }
27 header('Content-type: text/html');
28
29 if ($errors == 0) {
30     $messages[] =  array('ok', 'All fine');
31 }
32
33 $out = <<<HTM
34 <?xml version="1.0" encoding="utf-8"?>
35 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
36 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
37  <head>
38   <title>phorkie setup check</title>
39   <link rel="stylesheet" href="css/bootstrap.min.css"/>
40   <link rel="stylesheet" href="css/font-awesome.css"/>
41   <link rel="stylesheet" href="css/phorkie.css"/>
42   <meta name="viewport" content="width=device-width, initial-scale=1"/>
43   <style type="text/css">
44     /**/
45     li:before {
46         text-align: center;
47         display: inline-block;
48         width: 1em;
49         padding: 0 0.5ex;
50         margin-right: 0.5ex;
51     }
52     li.list-group-item-success:before {
53         content: '✔';
54         color: green;
55     }
56     li.list-group-item-danger:before {
57         content: "✘";
58         color: white;
59         background-color: red;
60     }
61     li.list-group-item-info:before {
62         content: "i";
63         font-weight: bold;
64         color: blue;
65     }
66 /**/
67   </style>
68  </head>
69  <body>
70   <div class="container">
71    <div class="row">
72     <div class="span12">
73
74      <div class="page-header">
75       <h1>phorkie setup check</h1>
76      </div>
77
78      <ul class="list-group">
79 HTM;
80 $stateMap = array(
81     'ok'    => 'success',
82     'info'  => 'info',
83     'error' => 'danger'
84 );
85 foreach ($messages as $arMessage) {
86     list($type, $message) = $arMessage;
87     $out .= '<li class="list-group-item list-group-item-'
88         . $stateMap[$type] . '">';
89     $out .= htmlspecialchars($message);
90     $out .= '</li>' . "\n";
91 }
92 $out .= <<<HTM
93      </ul>
94      <p>
95       <a href="./">back</a> to the index
96      </p>
97     </div>
98    </div>
99   </div>
100
101   <div class="container footer">
102    <a href="//sf.net/p/phorkie/">phorkie</a>,
103    the self-hosted, git-based pastebin software is available under the
104    <a href="http://www.gnu.org/licenses/agpl-3.0.html">
105     <abbr title="GNU Affero General Public License">AGPL</abbr></a>.
106   </div>
107
108  </body>
109 </html>
110 HTM;
111 echo $out;
112 ?>