Ticket #1483912: requirements.php

File requirements.php, 6.0 kB (added by jpingle, 19 months ago)

Simple script to check requirements

Line 
1<?
2
3/*
4  Simple RoundCube requirements checking script.
5  Originally coded by Jim Pingle
6 
7  This is a rough proof-of-concept and could use some cleanup or reworking.
8  I tried to keep the checks as generic as possible so it would be easy
9  to add more in the future.
10
11*/
12
13$REQUIRED_PHP_VERSION = "4.3.2";
14
15function rcube_check_requirement($descr, $check_type, $check_for, $true_action = "Pass", $false_action = "Fail")
16  #
17  # $name         - Requirement Name
18  # $descr        - Requirement Description
19  # $check_type   - Type of check to perform ("ini", "ini_bool", "extension", "writable")
20  # $check_for    - Name of ini setting, extension, path to file/dir to check, etc
21  # $true_action  - If the check is true, what to do (Pass, Fail, Warn, Info)
22  # $false_action - If the check is false, what to do (Pass, Fail, Warn, Info)
23  #     Special type "Info" results in the contents of the check call to be
24  #     fed back to the user.
25  #
26  {
27  $result = "";
28  $extra = "";
29  $requirement_check = false;
30 
31  #
32  # For each $check_type, perform the relevant check
33  #
34  switch ($check_type)
35    {
36  case "version":
37    $thisver = explode('.', phpversion());
38    $needver = explode('.', $check_for);
39    $requirement_check = (($thisver[0] >  $needver[0]) ||
40                         (($thisver[0] == $needver[0]) && ($thisver[1] >  $needver[1])) ||
41                         (($thisver[0] == $needver[0]) && ($thisver[1] == $needver[1]) && ($thisver[2] >= $needver[2])));
42    $extra = phpversion();
43    break;
44  case "ini":
45  case "ini_bool":
46    $requirement_check = ini_get($check_for);
47    break;
48  case "extension":
49    $requirement_check = extension_loaded($check_for);
50    break;
51  case "writable":
52    $requirement_check = is_writable($check_for);
53    break;
54    }
55
56  $result = ($requirement_check  || ($true_action == "Info")) ? $true_action : $false_action;
57 
58  $cssclass = $result;
59
60  if ($result == "Info")
61    {
62    switch ($check_type)
63      {
64    case "version":
65      $result = phpversion();
66      break;
67    case "ini":
68      $result = ini_get($check_for);
69      break;
70    case "ini_bool":
71      $result = (ini_get($check_for) == 1) ? 'On' : 'Off';
72      break;
73    case "extension":
74      $result = $requirement_check ? 'On' : 'Off';
75      break;
76    case "writable":
77      $result = $requirement_check ? 'Yes' : 'No';
78      break;
79      }
80    }
81
82  rcube_print_requirement_check($check_type . ': ' . $check_for, $descr, $cssclass, $result, $extra);
83  }
84
85function rcube_print_requirement_check($name, $descr, $cssclass, $result, $extra = '')
86  { ?>
87  <tr>
88    <td><?= $name ?></td>
89    <td><?= $descr ?></td>
90    <td class="<?= $cssclass ?>">
91      <?= $result ?>
92      <? if (!empty($extra))
93           echo '(' . $extra . ')'; ?>
94    </td>
95  </tr>
96  <?
97  }
98
99?>
100<html>
101<head>
102<title>Requirements Check</title>
103<style>
104body, td, th, h3
105{
106  font-family: "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
107  font-size: 12px;
108  color: #000000;
109}
110.pass {
111  background-color: #C0FED5;
112}
113
114.fail {
115  background-color: #FF9194;
116}
117
118.warn {
119  background-color: #FDFFAE;
120}
121.headerrow {
122  background-color: #eee;
123  height: 2em;
124}
125h2 {
126  text-align: center;
127}
128table {
129  margin-left: auto;
130  margin-right: auto;
131}                           
132td {
133  background-color: #F4F4F4;
134  border-spacing: 3px;
135  padding: 2px;
136}
137
138</style> 
139</head>
140<body>
141
142<h2>RoundCube Webmail - Requirement Checklist</h2>
143
144<table>
145<tr class="headerrow">
146  <th>Requirement</th>
147  <th>Description</th>
148  <th>Status</th>
149</tr>
150
151<? rcube_check_requirement("PHP version " . $GLOBALS['REQUIRED_PHP_VERSION'] . " or greater is required", 'version', $GLOBALS['REQUIRED_PHP_VERSION']) ?>
152
153<tr class="headerrow"><th colspan="3">PHP Configuration (php.ini values)</td></tr>
154
155<? rcube_check_requirement('Required for attachments',       'ini',      'file_uploads') ?>
156<? rcube_check_requirement('Maximum POST submission size',   'ini',      'post_max_size',           'Info') ?>
157<? rcube_check_requirement('Maximum attachment upload size', 'ini',      'upload_max_filesize',     'Info') ?>
158<? rcube_check_requirement('Per-process memory limit',       'ini',      'memory_limit',            'Info') ?>
159<? rcube_check_requirement('Max upload time (In seconds)',   'ini',      'default_socket_timeout''Info') ?>
160<? rcube_check_requirement('May help in debugging',          'ini_bool', 'track_errors',            'Info') ?>
161<? rcube_check_requirement('Restrictive but secure',         'ini_bool', 'safe_mode',               'Info') ?>
162<? rcube_check_requirement('ZLib output compression',        'ini_bool', 'zlib.output_compression', 'Info') ?>
163
164<tr class="headerrow"><th colspan="3">Database Extensions</td></tr>
165
166<? rcube_check_requirement('Needed <strong>only</strong> for MySQL backend',      'extension', 'mysql''Pass', 'Warn') ?>
167<? rcube_check_requirement('Needed <strong>only</strong> for Postgresql backend', 'extension', 'pgsql''Pass', 'Warn') ?>
168<? rcube_check_requirement('Needed <strong>only</strong> for SQLite backend',     'extension', 'sqlite', 'Pass', 'Warn') ?>
169
170<tr class="headerrow"><th colspan="3">Other Required Extensions</td></tr>
171
172<? rcube_check_requirement('Required', 'extension', 'session') ?>
173<? rcube_check_requirement('Required', 'extension', 'pcre') ?>
174
175<? rcube_check_requirement('Needed for spell check',                          'extension', 'sockets', 'Pass', 'Warn') ?>
176<? rcube_check_requirement('Needed if Google is the spell checker (default)', 'extension', 'openssl', 'Pass', 'Warn') ?>
177<? rcube_check_requirement('Needed for spell check in HTML editor',           'extension', 'curl',    'Pass', 'Warn') ?>
178
179<tr class="headerrow"><th colspan="3">File Permissions</td></tr>
180
181<? rcube_check_requirement('Logging directory: <br />' . realpath('logs/'),         'writable', 'logs/') ?>
182<? rcube_check_requirement('Temporary files directory: <br />' . realpath('temp/'), 'writable', 'temp/') ?>
183
184</table>
185</body>
186</html>