Another small fix for BIT24 casting for the LDAP driver...
[davical.git] / htdocs / setup.php
blob7ba5b1763782249cc996f194002c2f6a5b7920f4
1 <?php
2 /** todo work out something more than true/false returns for dependency checks */
4 function i18n($value) {
5 return $value; /* Just pass the value through */
8 class CheckResult {
9 private $ok;
10 private $use_class;
11 private $description;
13 function __construct( $success, $description=null, $use_class=null ) {
14 $this->ok = (boolean) $success;
15 $this->description = (isset($description)?$description : ($success===true? i18n('Passed') : i18n('Fail')));
16 $this->use_class = (isset($use_class)?$use_class:($success===true?'dep_ok' : 'dep_fail'));
19 public function getClass() {
20 return $this->use_class;
23 public function setClass( $new_class ) {
24 $this->use_class = $new_class;
27 public function getOK() {
28 return $this->ok;
31 public function getDescription() {
32 return translate($this->description);
35 public function setDescription( $new_desc ) {
36 $this->description = $new_desc;
41 /**
42 * We put many of these checks before we even try to load always.php so that we
43 * can try and do some diagnostic work to ensure it will load OK.
45 function check_pgsql() {
46 return new CheckResult(function_exists('pg_connect'));
49 function check_pdo() {
50 return new CheckResult(class_exists('PDO'));
53 function check_pdo_pgsql() {
54 global $loaded_extensions;
56 if ( !check_pdo() ) return new CheckResult(false);
57 return new CheckResult(isset($loaded_extensions['pdo_pgsql']));
60 function check_gettext() {
61 global $phpinfo, $loaded_extensions;
63 if ( !function_exists('gettext') ) return new CheckResult(false);
64 return new CheckResult(isset($loaded_extensions['gettext']));
67 function check_iconv() {
68 global $phpinfo, $loaded_extensions;
70 if ( !function_exists('iconv') ) return new CheckResult(false);
71 return new CheckResult(isset($loaded_extensions['iconv']));
74 function check_ldap() {
75 global $phpinfo, $loaded_extensions;
77 if (!function_exists('ldap_connect')) return new CheckResult(false);
78 return new CheckResult(isset($loaded_extensions['ldap']));
81 function check_real_php() {
82 global $phpinfo, $loaded_extensions;
83 // Looking for "Server API </td><td class="v">Apache 2.0 Filter" in the phpinfo
84 if ( preg_match('{Server API.*Apache 2\.. Filter}', $phpinfo) ) return new CheckResult(false);
85 return new CheckResult(true);
88 function check_calendar() {
89 global $phpinfo, $loaded_extensions;
91 if (!function_exists('cal_days_in_month')) return new CheckResult(false);
92 return new CheckResult(isset($loaded_extensions['calendar']));
95 function check_suhosin_server_strip() {
96 global $loaded_extensions;
98 if ( !isset($loaded_extensions['suhosin']) ) return new CheckResult(true);
99 return new CheckResult( ini_get('suhosin.server.strip') == "0" || strtolower(ini_get('suhosin.server.strip')) == "off" );
102 function check_magic_quotes_gpc() {
103 return new CheckResult( (get_magic_quotes_gpc() == 0) );
106 function check_magic_quotes_runtime() {
107 return new CheckResult( (get_magic_quotes_runtime() == 0) );
110 $loaded_extensions = array_flip(get_loaded_extensions());
113 function do_error( $errormessage ) {
114 // We can't translate this because we're testing these things even before
115 // the translation interface is available...
116 printf("<p class='error'>%s</p>", $errormessage );
119 if ( !check_gettext()->getOK() ) do_error("The GNU 'gettext' extension for PHP is not available.");
120 if ( !check_pgsql()->getOK() ) do_error("PHP 'pgsql' functions are not available");
121 if ( !check_pdo()->getOK() ) do_error("PHP 'PDO' module is not available");
122 if ( !check_pdo_pgsql()->getOK() ) do_error("The PDO drivers for PostgreSQL are not available");
123 if ( !check_iconv()->getOK() ) do_error("The 'iconv' extension for PHP is not available");
125 function get_phpinfo() {
126 ob_start( );
127 phpinfo();
128 $phpinfo = ob_get_contents( );
129 ob_end_clean( );
131 $phpinfo = preg_replace( '{^.*?<body>}s', '', $phpinfo);
132 $phpinfo = preg_replace( '{</body>.*?$}s', '', $phpinfo);
133 return $phpinfo;
135 $phpinfo = get_phpinfo();
137 include("./always.php");
138 include("DAViCalSession.php");
141 if ( check_pgsql()->GetOK() ) {
142 $session->LoginRequired( (isset($c->restrict_setup_to_admin) && $c->restrict_setup_to_admin ? 'Admin' : null ) );
146 include("interactive-page.php");
147 include("page-header.php");
149 require_once("AwlQuery.php");
152 function check_datetime() {
153 if ( class_exists('DateTime') ) return new CheckResult(true);
154 $result = new CheckResult(false);
155 $result->setClass('dep_warning');
156 $result->setDescription(i18n('Most of DAViCal will work but upgrading to PHP 5.2 or later is strongly recommended.'));
157 return $result;
160 function check_schema_version() {
161 global $c;
162 if ( $c->want_dbversion[0] == $c->schema_major
163 && $c->want_dbversion[1] == $c->schema_minor
164 && $c->want_dbversion[2] == $c->schema_patch ) {
165 return new CheckResult( true );
167 $result = new CheckResult(false);
168 if ( $c->want_dbversion[0] < $c->schema_major
169 || ($c->want_dbversion[0] == $c->schema_major && $c->want_dbversion[1] < $c->schema_minor)
170 || ($c->want_dbversion[0] == $c->schema_major
171 && $c->want_dbversion[1] == $c->schema_minor
172 && $c->want_dbversion[2] < $c->schema_patch)
175 $result->setClass('dep_warning');
177 $result->setDescription( sprintf(i18n('Want: %s, Currently: %s'), implode('.',$c->want_dbversion),
178 $c->schema_major.'.'.$c->schema_minor.'.'.$c->schema_patch));
179 return $result;
182 function check_davical_version() {
183 global $c;
184 $url = 'http://www.davical.org/current_davical_version?v='.$c->version_string;
185 $version_file = @fopen($url, 'r');
186 if ( ! $version_file ) return new CheckResult( false, translate("Could not retrieve") . " '$url'", 'dep_warning' );
187 $current_version = trim(fread( $version_file,12));
188 fclose($version_file);
189 $result = new CheckResult($c->version_string == $current_version);
190 if ( ! $result->getOK() ) {
191 $result->setDescription( sprintf(i18n('Want: %s, Currently: %s'), $current_version, $c->version_string) );
192 if ( $c->version_string > $current_version ) $result->setClass('dep_warning');
194 return $result;
198 function check_awl_version() {
199 global $c;
201 if ( !function_exists('awl_version') ) return new CheckResult(false);
203 $result = new CheckResult($c->want_awl_version == awl_version());
204 if ( ! $result->getOK() ) {
205 $result->setDescription( sprintf(i18n('Want: %s, Currently: %s'), $c->want_awl_version, awl_version()) );
206 if ( $c->want_awl_version < awl_version() ) $result->setClass('dep_warning');
208 return $result;
213 function build_site_statistics() {
214 $principals = translate('No. of Principals');
215 $collections = translate('No. of Collections');
216 $resources = translate('No. of Resources');
217 $table = <<<EOTABLE
218 <table class="statistics">
219 <tr><th>$principals</th><th>$collections</th><th>$resources</th></tr>
220 <tr>%s</tr>
221 </table>
222 EOTABLE;
224 if ( !check_pdo_pgsql() ) {
225 return sprintf( $table, '<td colspan="3">'.translate('Site Statistics require the database to be available!').'</td>');
227 $sql = 'SELECT
228 (SELECT count(1) FROM principal) AS principals,
229 (SELECT count(1) FROM collection) AS collections,
230 (SELECT count(1) FROM caldav_data) AS resources';
231 $qry = new AwlQuery($sql);
232 if ( $qry->Exec('setup',__LINE__,__FILE__) && $s = $qry->Fetch() ) {
233 $row = sprintf('<td align="center">%s</td><td align="center">%s</td><td align="center">%s</td>',
234 $s->principals, $s->collections, $s->resources );
235 return sprintf( $table, $row );
237 return sprintf( $table, '<td colspan="3">'.translate('Site Statistics require the database to be available!').'</td>');
241 function build_dependencies_table( ) {
242 global $c;
244 $dependencies = array(
245 translate('Current DAViCal version ') => 'check_davical_version',
246 translate('DAViCal DB Schema version ') => 'check_schema_version',
247 translate('AWL Library version ') => 'check_awl_version',
248 translate('PHP not using Apache Filter mode') => 'check_real_php',
249 translate('PHP PDO module available') => 'check_pdo',
250 translate('PDO PostgreSQL drivers') => 'check_pdo_pgsql',
251 // translate('PHP PostgreSQL available') => 'check_pgsql',
252 translate('GNU gettext support') => 'check_gettext',
253 translate('PHP iconv support') => 'check_iconv',
254 translate('PHP DateTime class') => 'check_datetime',
255 translate('Suhosin "server.strip" disabled') => 'check_suhosin_server_strip',
256 translate('PHP Magic Quotes GPC off') => 'check_magic_quotes_gpc',
257 translate('PHP Magic Quotes runtime off') => 'check_magic_quotes_runtime',
258 translate('PHP calendar extension available') => 'check_calendar'
261 if ( isset($c->authenticate_hook) && isset($c->authenticate_hook['call']) && $c->authenticate_hook['call'] == 'LDAP_check') {
262 $dependencies[translate('PHP LDAP module available')] = 'check_ldap';
265 $dependencies_table = '';
266 $dep_tpl = '<tr class="%s">
267 <td>%s</td>
268 <td>%s</td>
269 <td><a href="http://wiki.davical.org/w/Setup_Failure_Codes/%s">Explanation on DAViCal Wiki</a></td>
270 </tr>
272 foreach( $dependencies AS $k => $v ) {
273 $check_result = $v();
274 $dependencies_table .= sprintf( $dep_tpl, $check_result->getClass(),
276 $check_result->getDescription(),
277 rawurlencode($k)
281 return $dependencies_table;
285 $heading_setup = translate('Setup');
286 $paragraph_setup = translate('This page primarily checks the environment needed for DAViCal to work correctly. Suggestions or patches to make it do more useful stuff will be gratefully received.');
289 $want_dbversion = implode('.',$c->want_dbversion);
290 $heading_versions = translate('Current Versions');
291 if ( check_schema_version() != true )
293 $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.');
294 $paragraph_versions = sprintf( $paragraph_versions, $c->version_string, $want_dbversion, $c->schema_major, $c->schema_minor, $c->schema_patch);
295 } else {
296 $paragraph_versions = translate('You are currently running DAViCal version %s. The database schema is at version %d.%d.%d.');
297 $paragraph_versions = sprintf( $paragraph_versions, $c->version_string, $c->schema_major, $c->schema_minor, $c->schema_patch);
301 $heading_dependencies = translate('Dependencies');
302 $th_dependency = translate('Dependency');
303 $th_status = translate('Status');
304 $dependencies_table = build_dependencies_table();
306 $heading_site_statistics = translate('Site Statistics');
307 $site_statistics_table = build_site_statistics();
309 $heading_config_clients = translate('Configuring Calendar Clients for DAViCal');
310 $heading_config_davical = translate('Configuring DAViCal');
311 $davical_configuration_errors = ( $config_warnings == '' ? '' : '<div class="error"><h3 class="error">'
312 . translate('Your configuration produced PHP errors which should be corrected') . '</h3><pre>'
313 . $config_warnings.'</pre></div>'
317 echo <<<EOBODY
318 <style>
319 tr.dep_ok {
320 background-color:#80ff80;
322 tr.dep_fail {
323 background-color:#ff8080;
325 tr.dep_warning {
326 background-color:#ffb040;
328 table, table.dependencies {
329 border: 1px grey solid;
330 border-collapse: collapse;
331 padding: 0.1em;
332 margin: 0 1em 1.5em;
334 table tr td, table tr th, table.dependencies tr td, table.dependencies tr th {
335 border: 1px grey solid;
336 padding: 0.1em 0.2em;
339 padding: 0.3em 0.2em 0.7em;
341 </style>
343 <h1>$heading_setup</h1>
344 <p>$paragraph_setup
346 <h2>$heading_dependencies</h2>
348 <table class="dependencies">
349 <tr>
350 <th>$th_dependency</th>
351 <th>$th_status</th>
352 </tr>
353 $dependencies_table
354 </table>
355 </p>
356 <h2>$heading_config_davical</h2>
357 <p>If you can read this then things must be mostly working already.</p>
358 $davical_configuration_errors
359 <p>The <a href="http://www.davical.org/installation.php">installation page on the DAViCal website</a> has
360 some further information on how to install and configure this application.</p>
362 <h2>$heading_config_clients</h2>
363 <p>The <a href="http://www.davical.org/clients.php">client setup page on the DAViCal website</a> has information on how
364 to configure Evolution, Sunbird, Lightning and Mulberry to use remotely hosted calendars.</p>
365 <p>The administrative interface has no facility for viewing or modifying calendar data.</p>
367 <h2>$heading_site_statistics</h2>
368 <p>$site_statistics_table</p>
370 <h2>PHP Information</h2>
371 <script language="javascript">
372 function toggle_visible() {
373 var argv = toggle_visible.arguments;
374 var argc = argv.length;
376 var fld_checkbox = document.getElementById(argv[0]);
378 if ( argc < 2 ) {
379 return;
382 for (var i = 1; i < argc; i++) {
383 var block_id = argv[i].substr(1);
384 var block_logical = argv[i].substr(0,1);
385 var b = document.getElementById(block_id);
386 if ( block_logical == '!' )
387 b.style.display = (fld_checkbox.checked ? 'none' : '');
388 else
389 b.style.display = (!fld_checkbox.checked ? 'none' : '');
392 </script><p><label>Show phpinfo() output:<input type="checkbox" value="1" id="fld_show_phpinfo" onclick="toggle_visible('fld_show_phpinfo','=phpinfo')"></label></p>
393 <div style="display:none" id="phpinfo">$phpinfo</div>
395 EOBODY;
397 include("page-footer.php");