3 // This draft doesn't do anything useful at the moment. When it is finished,
4 // the README will be updated accordingly.
6 $stepfunc[1] = 'not_already_installed';
7 $stepfunc[2] = 'platform_is_ok';
8 $stepfunc[3] = 'init_config';
9 $stepfunc[4] = 'init_database_static';
10 $stepfunc[5] = 'init_database_dynamic';
11 $stepfunc[6] = 'congrats';
14 if (isset ($_REQUEST['step']))
15 $step = $_REQUEST['step'];
19 if ($step > count ($stepfunc))
21 require 'inc/init.php';
23 header ("Location: " . $root);
26 $title = "RackTables installation: step ${step} of " . count ($stepfunc);
28 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
29 <html xmlns
="http://www.w3.org/1999/xhtml" xml
:lang
="en" lang
="en">
30 <head
><title
><?php
echo $title; ?
></title
>
31 <meta http
-equiv
="Content-Type" content
="text/html; charset=UTF-8" />
32 <link rel
=stylesheet type
='text/css' href
=pi
.css
/>
37 echo "<h1>${title}</h1><p>";
39 echo "</p><form method=post>\n";
40 $testres = $stepfunc[$step] ();
43 $next_step = $step +
1;
44 echo "<input type=submit value='proceed'>";
49 echo "<input type=submit value='retry'>";
51 echo "<input type=hidden name=step value='${next_step}'>\n";
60 // Check if the software is already installed.
61 function not_already_installed()
63 @include
('inc/secret.php');
66 echo 'Your configuration file exists and seems to hold necessary data already.<br>';
71 echo 'There seem to be no existing installation here, I am going to setup one now.<br>';
76 // Check for PHP extensions.
77 function platform_is_ok ()
80 echo "<table border=1><tr><th>check item</th><th>result</th></tr>\n";
82 echo '<tr><td>PDO extension</td>';
83 if (class_exists ('PDO'))
84 echo '<td class=msg_success>Ok';
87 echo '<td class=msg_error>not found';
92 echo '<tr><td>PDO-MySQL</td>';
93 if (defined ('PDO::MYSQL_ATTR_READ_DEFAULT_FILE'))
94 echo '<td class=msg_success>Ok';
97 echo '<td class=msg_error>not found';
102 echo '<tr><td>hash functions</td>';
103 if (function_exists ('hash_algos'))
104 echo '<td class=msg_success>Ok';
107 echo '<td class=msg_error>not found';
112 echo '<tr><td>SNMP extension</td>';
113 if (defined ('SNMP_NULL'))
114 echo '<td class=msg_success>Ok';
116 echo '<td class=msg_warning>Not found. Live SNMP tab will not function properly until the extension is installed.';
119 echo '<tr><td>GD functions</td>';
120 if (defined ('IMG_PNG'))
121 echo '<td class=msg_success>Ok';
124 echo '<td class=msg_error>not found';
129 echo '<tr><td>HTTP scheme</td>';
130 if (!empty($_SERVER['HTTPS']))
131 echo '<td class=msg_success>HTTPs';
133 echo '<td class=msg_warning>HTTP (all your passwords will be transmitted in cleartext)';
136 echo '<tr><td>Multibyte string extension</td>';
137 if (defined ('MB_CASE_LOWER'))
138 echo '<td class=msg_success>Ok';
141 echo '<td class=msg_error>not found';
146 echo '<tr><td>LDAP extension</td>';
147 if (defined ('LDAP_OPT_DEREF'))
148 echo '<td class=msg_success>Ok';
151 echo '<td class=msg_warning>not found, LDAP authentication will not work';
159 // Check that we can write to configuration file.
160 // If so, ask for DB connection paramaters and test
161 // the connection. Neither save the parameters nor allow
162 // going further until we succeed with the given
164 function init_config ()
166 if (!is_writable ('inc/secret.php'))
168 echo "The inc/secret.php file is not writable by web-server. Make sure it is.";
169 echo "The following commands should suffice:<pre>touch inc/secret.php\nchmod 666 inc/secret.php</pre>";
170 echo 'Fedora Linux with SELinux may require this file to be owned by specific user (apache) and/or executing "setenforce 0" for the time of installation. ';
171 echo 'SELinux may be turned back on with "setenforce 1" command.';
176 !isset ($_REQUEST['save_config']) or
177 empty ($_REQUEST['mysql_host']) or
178 empty ($_REQUEST['mysql_db']) or
179 empty ($_REQUEST['mysql_username']) or
180 empty ($_REQUEST['mysql_password'])
183 echo "<input type=hidden name=save_config value=1>\n";
185 echo "<tr><td><label for=mysql_host>MySQL host:</label></td>";
186 echo "<td><input type=text name=mysql_host id=mysql_host value=localhost></td></tr>\n";
187 echo "<tr><td><label for=mysql_host>database:</label></td>";
188 echo "<td><input type=text name=mysql_db id=mysql_db value=racktables></td></tr>\n";
189 echo "<tr><td><label for=mysql_username>username:</label></td>";
190 echo "<td><input type=text name=mysql_username></td></tr>\n";
191 echo "<tr><td><label for=mysql_password>password:</label></td>";
192 echo "<td><input type=password name=mysql_password></td></tr>\n";
196 $pdo_dsn = 'mysql:host=' . $_REQUEST['mysql_host'] . ';dbname=' . $_REQUEST['mysql_db'];
199 $dbxlink = new PDO ($pdo_dsn, $_REQUEST['mysql_username'], $_REQUEST['mysql_password']);
201 catch (PDOException
$e)
203 echo "<input type=hidden name=save_config value=1>\n";
205 echo "<tr><td><label for=mysql_host>MySQL host:</label></td>";
206 echo "<td><input type=text name=mysql_host id=mysql_host value='" . $_REQUEST['mysql_host'] . "'></td></tr>\n";
207 echo "<tr><td><label for=mysql_host>database:</label></td>";
208 echo "<td><input type=text name=mysql_db id=mysql_db value='" . $_REQUEST['mysql_db'] . "'></td></tr>\n";
209 echo "<tr><td><label for=mysql_username>username:</label></td>";
210 echo "<td><input type=text name=mysql_username value='" . $_REQUEST['mysql_username'] . "'></td></tr>\n";
211 echo "<tr><td><label for=mysql_password>password:</label></td>";
212 echo "<td><input type=password name=mysql_password value='" . $_REQUEST['mysql_password'] . "'></td></tr>\n";
213 echo "<tr><td colspan=2>The above parameters did not work. Check and try again.</td></tr>\n";
217 $conf = fopen ('inc/secret.php', 'w+');
220 echo "Error: failed to open inc/secret.php for writing";
223 fwrite ($conf, "<?php\n/* This file has been generated automatically by RackTables installer.\n");
224 fwrite ($conf, " * you shouldn't normally edit it unless your database setup has changed.\n");
225 fwrite ($conf, " */\n");
226 fwrite ($conf, "\$pdo_dsn = '${pdo_dsn}';\n");
227 fwrite ($conf, "\$db_username = '" . $_REQUEST['mysql_username'] . "';\n");
228 fwrite ($conf, "\$db_password = '" . $_REQUEST['mysql_password'] . "';\n\n");
229 fwrite ($conf, "// This is only necessary for 'ldap' USER_AUTH_SRC\n");
230 fwrite ($conf, "\$ldap_server = 'some.server';\n");
231 fwrite ($conf, "\$ldap_domain = 'some.domain';\n");
232 fwrite ($conf, "?>\n");
234 echo "The configuration file has been written successfully.<br>";
238 function connect_to_db ()
240 require ('inc/secret.php');
244 $dbxlink = new PDO ($pdo_dsn, $db_username, $db_password);
246 catch (PDOException
$e)
248 die ('Error connecting to the database');
252 function init_database_static ()
256 $result = $dbxlink->query ('show tables');
257 $tables = $result->fetchAll (PDO
::FETCH_NUM
);
258 $result->closeCursor();
262 echo 'Your database is already holding ' . count ($tables);
263 echo ' tables, so I will stop here and let you check it yourself.<br>';
264 echo 'There is some important data there probably.<br>';
267 echo 'Initializing the database...<br>';
268 echo '<table border=1>';
269 echo "<tr><th>file</th><th>queries</th><th>errors</th></tr>";
271 foreach (array ('structure', 'dictbase', 'dictvendors') as $part)
273 $filename = "install/init-${part}.sql";
274 echo "<tr><td>${filename}</td>";
275 $f = fopen ("install/init-${part}.sql", 'r');
278 echo "Failed to open install/init-${part}.sql for reading";
285 if (ereg ('^--', $line))
291 foreach (explode (";\n", $longq) as $query)
296 if ($dbxlink->exec ($query) === FALSE)
302 echo "<td>${nq}</td><td>${nerrs}</td></tr>\n";
305 if (count ($errlist))
307 echo '<pre>The following queries failed:\n';
308 foreach ($errlist as $q)
316 function init_database_dynamic ()
320 if (!isset ($_REQUEST['password']) or empty ($_REQUEST['password']))
322 $result = $dbxlink->query ('select count(user_id) from UserAccount where user_id = 1');
323 $row = $result->fetch (PDO
::FETCH_NUM
);
325 $result->closeCursor();
328 echo '<table border=1>';
329 echo '<caption>Administrator password not set</caption>';
330 echo '<tr><td><input type=password name=password></td></tr>';
337 $query = "INSERT INTO `UserAccount` (`user_id`, `user_name`, `user_enabled`, `user_password_hash`, `user_realname`) " .
338 "VALUES (1,'admin','yes',sha1('${_REQUEST['password']}'),'RackTables Administrator')";
339 $result = $dbxlink->exec ($query);
340 echo "Administrator password has been set successfully.<br>";
347 echo 'Congratulations! RackTables installation is complete. After pressing Proceed you will ';
348 echo 'enter the system. Authenticate with <strong>admin</strong> username.<br>';
349 echo "RackTables web-site runs some <a href='http://racktables.org/trac/wiki'>wiki</a> pages ";
350 echo "and <a href='http://racktables.org/trac/report/1'>a bug tracker</a>.<br>We have also got ";
351 echo "a <a href='http://www.freelists.org/list/racktables-users'>mailing list</a> for users. Have fun.<br>";