simple cache for rendered files
[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   <meta charset="utf-8" />
40   <link rel="stylesheet" href="css/bootstrap.min.css"/>
41   <link rel="stylesheet" href="css/font-awesome.css"/>
42   <link rel="stylesheet" href="css/phorkie.css"/>
43   <meta name="viewport" content="width=device-width, initial-scale=1"/>
44   <style type="text/css">
45     /**/
46     li:before {
47         text-align: center;
48         display: inline-block;
49         width: 1em;
50         padding: 0 0.5ex;
51         margin-right: 0.5ex;
52     }
53     li.list-group-item-success:before {
54         content: '✔';
55         color: green;
56     }
57     li.list-group-item-danger:before {
58         content: "✘";
59         color: white;
60         background-color: red;
61     }
62     li.list-group-item-info:before {
63         content: "i";
64         font-weight: bold;
65         color: blue;
66     }
67 /**/
68   </style>
69  </head>
70  <body>
71   <div class="container">
72    <div class="row">
73     <div class="span12">
74
75      <div class="page-header">
76       <h1>phorkie setup check</h1>
77      </div>
78      <h3>Check results</h3>
79
80      <ul class="list-group">
81 HTM;
82 $stateMap = array(
83     'ok'    => 'success',
84     'info'  => 'info',
85     'error' => 'danger'
86 );
87 foreach ($messages as $arMessage) {
88     list($type, $message) = $arMessage;
89     $out .= '<li class="list-group-item list-group-item-'
90         . $stateMap[$type] . '">';
91     $out .= htmlspecialchars($message);
92     $out .= '</li>' . "\n";
93 }
94 $out .= <<<HTM
95      </ul>
96 HTM;
97
98 if (array_sum($GLOBALS['phorkie']['cfgfiles']) == 0) {
99     //no config file loaded
100     reset($GLOBALS['phorkie']['cfgfiles']);
101     list($cfgFilePath, ) = each($GLOBALS['phorkie']['cfgfiles']);
102
103     $cfgFilePath = Tools::foldPath($cfgFilePath);
104     $cfgFileTemplate = htmlspecialchars(
105         file_get_contents(__DIR__ . '/../data/config.php.dist')
106     );
107     $cfgFileLines = count(explode("\n", $cfgFileTemplate));
108
109     $out .= <<<HTM
110      <h3 id="configfile">Configuration file</h3>
111      <p>
112       Phorkie did not find a configuration file.
113       Please create one at
114      </p>
115      <pre>$cfgFilePath</pre>
116      <p>
117       from the following template:
118      </p>
119      <textarea style="width:99%; background-color: #F5F5F5" rows="$cfgFileLines">$cfgFileTemplate</textarea>
120      <p>
121       Remove the leading <tt>//</tt> from a line if you want to adjust it.
122      </p>
123 HTM;
124 }
125
126 $out .= <<<HTM
127      <p style="margin-top: 4ex">
128       <a href="./"><i class="icon-arrow-left"></i> back</a> to the index
129      </p>
130     </div>
131    </div>
132   </div>
133
134   <div class="container footer">
135    <a href="//sf.net/p/phorkie/">phorkie</a>,
136    the self-hosted, git-based pastebin software is available under the
137    <a href="http://www.gnu.org/licenses/agpl-3.0.html">
138     <abbr title="GNU Affero General Public License">AGPL</abbr></a>.
139   </div>
140
141  </body>
142 </html>
143 HTM;
144 echo $out;
145 ?>