1 | <?php |
---|
2 | |
---|
3 | include("./always.php"); |
---|
4 | include("DAViCalSession.php"); |
---|
5 | |
---|
6 | ob_start( ); |
---|
7 | phpinfo(); |
---|
8 | $phpinfo = ob_get_contents( ); |
---|
9 | ob_end_clean( ); |
---|
10 | |
---|
11 | $phpinfo = preg_replace( '{^.*?<body>}s', '', $phpinfo); |
---|
12 | $phpinfo = preg_replace( '{</body>.*?$}s', '', $phpinfo); |
---|
13 | |
---|
14 | $loaded_extensions = array_flip(get_loaded_extensions()); |
---|
15 | |
---|
16 | /** @TODO: work out something more than true/false returns for dependency checks */ |
---|
17 | function check_pgsql() { |
---|
18 | return function_exists('pg_connect'); |
---|
19 | } |
---|
20 | |
---|
21 | if ( check_pgsql() ) { |
---|
22 | $session->LoginRequired( (isset($c->restrict_setup_to_admin) && $c->restrict_setup_to_admin ? 'Admin' : null ) ); |
---|
23 | } |
---|
24 | |
---|
25 | function check_pdo() { |
---|
26 | return class_exists('PDO'); |
---|
27 | } |
---|
28 | |
---|
29 | function check_pdo_pgsql() { |
---|
30 | global $phpinfo, $loaded_extensions; |
---|
31 | |
---|
32 | if ( !class_exists('PDO') ) return false; |
---|
33 | return isset($loaded_extensions['pdo_pgsql']); |
---|
34 | } |
---|
35 | |
---|
36 | function check_gettext() { |
---|
37 | global $phpinfo, $loaded_extensions; |
---|
38 | |
---|
39 | if ( !function_exists('gettext') ) return false; |
---|
40 | return isset($loaded_extensions['gettext']); |
---|
41 | } |
---|
42 | |
---|
43 | function check_suhosin_server_strip() { |
---|
44 | global $phpinfo, $loaded_extensions; |
---|
45 | |
---|
46 | if ( !isset($loaded_extensions['suhosin']) ) return true; |
---|
47 | if ( ini_get('suhosin.server.strip') == "0" ) { |
---|
48 | return true; |
---|
49 | } |
---|
50 | |
---|
51 | return false; |
---|
52 | } |
---|
53 | |
---|
54 | include("interactive-page.php"); |
---|
55 | include("page-header.php"); |
---|
56 | |
---|
57 | require_once("AwlQuery.php"); |
---|
58 | |
---|
59 | function check_schema_version() { |
---|
60 | global $c; |
---|
61 | if ( $c->want_dbversion[0] == $c->schema_major |
---|
62 | && $c->want_dbversion[1] == $c->schema_minor |
---|
63 | && $c->want_dbversion[2] == $c->schema_patch ) { |
---|
64 | return true; |
---|
65 | } |
---|
66 | return false; |
---|
67 | } |
---|
68 | |
---|
69 | function check_davical_version() { |
---|
70 | global $c; |
---|
71 | $url = 'http://www.davical.org/current_davical_version?v='.$c->version_string; |
---|
72 | $version_file = @fopen($url, 'r'); |
---|
73 | if ( ! $version_file ) return translate("Could not retrieve") . " '$url'"; |
---|
74 | $current_version = trim(fread( $version_file,12)); |
---|
75 | fclose($version_file); |
---|
76 | return ( $c->version_string == $current_version ? true : $current_version ); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | function build_site_statistics() { |
---|
81 | $principals = translate('No. of Principals'); |
---|
82 | $collections = translate('No. of Collections'); |
---|
83 | $resources = translate('No. of Resources'); |
---|
84 | $table = <<<EOTABLE |
---|
85 | <table class="statistics"> |
---|
86 | <tr><th>$principals</th><th>$collections</th><th>$resources</th></tr> |
---|
87 | <tr>%s</tr> |
---|
88 | </table> |
---|
89 | EOTABLE; |
---|
90 | |
---|
91 | if ( !check_pdo_pgsql() ) { |
---|
92 | return sprintf( $table, '<td colspan="3">'.translate('Site Statistics require the database to be available!').'</td>'); |
---|
93 | } |
---|
94 | $sql = 'SELECT |
---|
95 | (SELECT count(1) FROM principal) AS principals, |
---|
96 | (SELECT count(1) FROM collection) AS collections, |
---|
97 | (SELECT count(1) FROM caldav_data) AS resources'; |
---|
98 | $qry = new AwlQuery($sql); |
---|
99 | if ( $qry->Exec('setup',__LINE__,__FILE__) && $s = $qry->Fetch() ) { |
---|
100 | $row = sprintf('<td align="center">%s</td><td align="center">%s</td><td align="center">%s</td>', |
---|
101 | $s->principals, $s->collections, $s->resources ); |
---|
102 | return sprintf( $table, $row ); |
---|
103 | } |
---|
104 | return sprintf( $table, '<td colspan="3">'.translate('Site Statistics require the database to be available!').'</td>'); |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | $dependencies = array( |
---|
109 | translate('Current DAViCal version '). $c->version_string => 'check_davical_version', |
---|
110 | translate('DAViCal DB Schema version '). implode('.',$c->want_dbversion) => 'check_schema_version', |
---|
111 | translate('PHP PDO module available') => 'check_pdo', |
---|
112 | translate('PDO PostgreSQL drivers') => 'check_pdo_pgsql', |
---|
113 | translate('PHP PostgreSQL available') => 'check_pgsql', |
---|
114 | translate('GNU gettext support') => 'check_gettext', |
---|
115 | translate('Suhosin "server.strip" disabled') => 'check_suhosin_server_strip' /*, |
---|
116 | 'YAML' => 'php5-syck' */ |
---|
117 | ); |
---|
118 | |
---|
119 | $dependencies_table = ''; |
---|
120 | $dep_tpl = '<tr class="%s"> |
---|
121 | <td>%s</td> |
---|
122 | <td>%s</td> |
---|
123 | </tr> |
---|
124 | '; |
---|
125 | foreach( $dependencies AS $k => $v ) { |
---|
126 | $ok = $v(); |
---|
127 | $dependencies_table .= sprintf( $dep_tpl, ($ok === true ? 'dep_ok' : 'dep_fail'), $k, (is_string($ok) ? $ok : ($ok ? translate('OK') : translate('Failed'))) ); |
---|
128 | } |
---|
129 | |
---|
130 | $want_dbversion = implode('.',$c->want_dbversion); |
---|
131 | |
---|
132 | $heading_setup = translate('Setup'); |
---|
133 | $paragraph_setup = translate('Currently this page does very little. Suggestions or patches to make it do more useful stuff will be gratefully received.'); |
---|
134 | |
---|
135 | $heading_versions = translate('Current Versions'); |
---|
136 | if ( check_schema_version() != true ) |
---|
137 | { |
---|
138 | $paragraph_versions = translate('You are currently running DAViCal version %s. The database schema should be at version %s and it is at version %d.%d.%d.'); |
---|
139 | $paragraph_versions = sprintf( $paragraph_versions, $c->version_string, $want_dbversion, $c->schema_major, $c->schema_minor, $c->schema_patch); |
---|
140 | } else { |
---|
141 | $paragraph_versions = translate('You are currently running DAViCal version %s. The database schema is at version %d.%d.%d.'); |
---|
142 | $paragraph_versions = sprintf( $paragraph_versions, $c->version_string, $c->schema_major, $c->schema_minor, $c->schema_patch); |
---|
143 | } |
---|
144 | |
---|
145 | $heading_dependencies = translate('Dependencies'); |
---|
146 | $th_dependency = translate('Dependency'); |
---|
147 | $th_status = translate('Status'); |
---|
148 | |
---|
149 | $heading_site_statistics = translate('Site Statistics'); |
---|
150 | $site_statistics_table = build_site_statistics(); |
---|
151 | |
---|
152 | $heading_config_clients = translate('Configuring Calendar Clients for DAViCal'); |
---|
153 | $heading_config_davical = translate('Configuring DAViCal'); |
---|
154 | $davical_configuration_errors = ''; |
---|
155 | if ( $config_warnings != '' ) { |
---|
156 | $davical_configuration_errors = '<div class="error"><h3 class="error">' . translate('Your configuration produced PHP errors which should be corrected') . '</h3> |
---|
157 | <pre> |
---|
158 | '.$config_warnings.' |
---|
159 | </pre></div> |
---|
160 | '; |
---|
161 | } |
---|
162 | |
---|
163 | echo <<<EOBODY |
---|
164 | <style> |
---|
165 | tr.dep_ok { |
---|
166 | background-color:#80ff80; |
---|
167 | } |
---|
168 | tr.dep_fail { |
---|
169 | background-color:#ffc0c0; |
---|
170 | } |
---|
171 | table, table.dependencies { |
---|
172 | border: 1px grey solid; |
---|
173 | border-collapse: collapse; |
---|
174 | padding: 0.1em; |
---|
175 | margin: 0 1em 1.5em; |
---|
176 | } |
---|
177 | table tr td, table tr th, table.dependencies tr td, table.dependencies tr th { |
---|
178 | border: 1px grey solid; |
---|
179 | padding: 0.1em 0.2em; |
---|
180 | } |
---|
181 | p { |
---|
182 | padding: 0.3em 0.2em 0.7em; |
---|
183 | } |
---|
184 | </style> |
---|
185 | |
---|
186 | <h1>$heading_setup</h1> |
---|
187 | <p>$paragraph_setup |
---|
188 | |
---|
189 | <h2>$heading_versions</h2> |
---|
190 | <p>$paragraph_versions |
---|
191 | <br> |
---|
192 | </p> |
---|
193 | |
---|
194 | <h2>$heading_dependencies</h2> |
---|
195 | <p> |
---|
196 | <table class="dependencies"> |
---|
197 | <tr> |
---|
198 | <th>$th_dependency</th> |
---|
199 | <th>$th_status</th> |
---|
200 | </tr> |
---|
201 | $dependencies_table |
---|
202 | </table> |
---|
203 | <br> |
---|
204 | </p> |
---|
205 | |
---|
206 | <script language="javascript"> |
---|
207 | function toggle_visible() { |
---|
208 | var argv = toggle_visible.arguments; |
---|
209 | var argc = argv.length; |
---|
210 | |
---|
211 | var fld_checkbox = document.getElementById(argv[0]); |
---|
212 | |
---|
213 | if ( argc < 2 ) { |
---|
214 | return; |
---|
215 | } |
---|
216 | |
---|
217 | for (var i = 1; i < argc; i++) { |
---|
218 | var block_id = argv[i].substr(1); |
---|
219 | var block_logical = argv[i].substr(0,1); |
---|
220 | var b = document.getElementById(block_id); |
---|
221 | if ( block_logical == '!' ) |
---|
222 | b.style.display = (fld_checkbox.checked ? 'none' : ''); |
---|
223 | else |
---|
224 | b.style.display = (!fld_checkbox.checked ? 'none' : ''); |
---|
225 | } |
---|
226 | } |
---|
227 | </script><p><label>Show phpinfo() output:<input type="checkbox" value="1" id="fld_show_phpinfo" onclick="toggle_visible('fld_show_phpinfo','=phpinfo')"></label></p> |
---|
228 | <div style="display:none" id="phpinfo">$phpinfo</div> |
---|
229 | |
---|
230 | <h2>$heading_site_statistics</h2> |
---|
231 | <p>$site_statistics_table</p> |
---|
232 | |
---|
233 | <h2>$heading_config_clients</h2> |
---|
234 | <p>The <a href="http://www.davical.org/clients.php">client setup page on the DAViCal website</a> has information on how |
---|
235 | to configure Evolution, Sunbird, Lightning and Mulberry to use remotely hosted calendars.</p> |
---|
236 | <p>The administrative interface has no facility for viewing or modifying calendar data.</p> |
---|
237 | |
---|
238 | <h2>$heading_config_davical</h2> |
---|
239 | <p>If you can read this then things must be mostly working already.</p> |
---|
240 | $davical_configuration_errors |
---|
241 | <p>The <a href="http://www.davical.org/installation.php">installation page on the DAViCal website</a> has |
---|
242 | some further information on how to install and configure this application.</p> |
---|
243 | EOBODY; |
---|
244 | |
---|
245 | include("page-footer.php"); |
---|