ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

install.php
Go to the documentation of this file.
1 <?php
2 // MP: Since we know ONA will generate a ton of notice level errors, lets turn them off here
3 error_reporting (E_ALL ^ E_NOTICE);
4 
5 // get adodb xml processing
6 require_once($conf['inc_adodb_xml']);
7 
8 $base = dirname(__FILE__);
9 
10 // Init and setup some variables.
11 $text = '';
12 $status = 0;
13 $onabase = dirname($base);
14 $runinstall = $onabase.'/www/local/config/run_install';
15 $xmlfile_tables = $base.'/ona-table_schema.xml';
16 $xmlfile_data = $base.'/ona-data.xml';
17 $license_text = file_get_contents($base.'/../docs/LICENSE');
18 $new_ver = trim(file_get_contents($onabase.'/VERSION'));
19 $curr_ver = '';
20 
21 // Get some pre-requisite information
22 $phpversion = phpversion() > '5.0' ? 'Yes' : '<font color="red">No</font>';
23 $hasgmp = function_exists( 'gmp_init' ) ? 'Yes' : '<font color="red">No</font>';
24 $hasmysql = function_exists( 'mysqli_connect' ) ? 'Yes' : 'Recommended';
25 $hasmbstring = function_exists( 'mb_internal_encoding' ) ? 'Yes' : 'Recommended';
26 $dbconfwrite = @is_writable($onabase.'/www/local/config/') ? 'Yes' : '<font color="red">No</font>';
27 
28 $blankmain = "<script>el('main').style.display = 'none';</script>";
29 
30 // This is the div that contains the license
32  <div id="license">
33  <center><b>OpenNetAdmin is released under the following license:</b></center>
34  <textarea class="edit" rows="25" cols="75">{$license_text}</textarea><br><br>
35  <center>
36  <input class='edit' type="button" value="I Agree!" onclick="el('work').style.display = '';el('input1').focus();el('license').style.display = 'none';" />&nbsp;&nbsp;
37  <a style="text-decoration: none;" href="/"><input class='edit' type="button" value="I don't like free stuff?" onclick="" /></a>
38  </center>
39  </div>
41 
42 // Div with the prerequisite checks
44  <div id="checksdiv">
45  <table id="checks">
46  <tr><th colspan="5">Prerequisite checks</th></tr>
47  <tr><td>PHP version > 5.0:</td><td>{$phpversion}</td></tr>
48  <tr title="The PHP mysqli database modules are used to connect to mysql databases"><td>PHP mysqli support:</td><td>{$hasmysql}</td></tr>
49  <tr title="The PHP GMP modules are required for IPv6 support."><td>Has GMP support:</td><td>{$hasgmp}</td></tr>
50  <tr title="The PHP mbstring modules provide better text encoding for UTF etc, but are not required."><td>Has mbstring support:</td><td>{$hasmbstring}</td></tr>
51  <tr title="The local config directory must be writable by the web server user: {$_ENV['APACHE_RUN_USER']}"><td>{$onabase}/www/local/config dir writable by '{$_ENV['APACHE_RUN_USER']}':</td><td>{$dbconfwrite}</td></tr>
52  </table>
53  </div>
54 EOL;
55 
56 // Initial text for the greeting div
57 $greet_txt = "It looks as though this is your first time running OpenNetAdmin. Please answer a few questions and we'll initialize the system for you. We've pre-populated some of the fields with suggested values. If the database you specify below already exists, it will be overwritten entirely.";
58 
59 
61 
62 // Get info from old $db_context[] array if ona_contexts does not exist
63 // this is transitional, hopefully I can remove this part soon.
64 if (!is_array($ona_contexts) and is_array($db_context)) {
65  $type='mysqli';
66  $context_name='default';
67  $ona_contexts[$context_name]['databases']['0']['db_type'] = $db_context[$type] [$context_name] ['primary'] ['db_type'];
68  $ona_contexts[$context_name]['databases']['0']['db_host'] = $db_context[$type] [$context_name] ['primary'] ['db_host'];
69  $ona_contexts[$context_name]['databases']['0']['db_login'] = $db_context[$type] [$context_name] ['primary'] ['db_login'];
70  $ona_contexts[$context_name]['databases']['0']['db_passwd'] = $db_context[$type] [$context_name] ['primary'] ['db_passwd'];
71  $ona_contexts[$context_name]['databases']['0']['db_database'] = $db_context[$type] [$context_name] ['primary'] ['db_database'];
72  $ona_contexts[$context_name]['databases']['0']['db_debug'] = $db_context[$type] [$context_name] ['primary'] ['db_debug'];
73  $ona_contexts[$context_name]['description'] = 'Default data context';
74  $ona_contexts[$context_name]['context_color'] = '#D3DBFF';
75 }
76 
77 
78 // If they already have a dbconffile, assume that we are doing and upgrade
79 if (@file_exists($dbconffile)) {
80  // Get the existing database config (again) so we can connect using its settings
81  include($dbconffile);
82 
83  $context_count = count($ona_contexts);
84 
85  $greet_txt = "It looks as though you already have a version of OpenNetAdmin installed. You should make a backup of the data for each context listed below before proceeding with this upgrade.<br><br>We will be upgrading to version '{$new_ver}'.<br><br>We have found {$context_count} context(s) in your current db configuration file.<br><br>";
86 
87  $greet_txt .= "<center><table><tr><th>Context Name</th><th>DB type</th><th>Server</th><th>DB name</th><th>Version</th><th>Upgrade Index</th></tr>";
88 
89  // Loop through each context and identify the Databases within
90  foreach(array_keys($ona_contexts) as $cname) {
91 
92  foreach($ona_contexts[$cname]['databases'] as $cdbs) {
93  $curr_ver = '<span style="background-color:#FF7375;">Unable to determine</span>';
94  // Make an initial connection to a DB server without specifying a database
95  $db = ADONewConnection($cdbs['db_type']);
96  @$db->Connect( $cdbs['db_host'], $cdbs['db_login'], $cdbs['db_passwd'], '' );
97 
98  if (!$db->IsConnected()) {
99  $status++;
100  printmsg("INFO => Unable to connect to server '{$cdbs['db_host']}'. ".$db->ErrorMsg(),0);
101  $err_txt .= " <img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> [{$cname}] Failed to connect as '{$cdbs['db_login']}'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
102  } else {
103  if ($db->SelectDB($cdbs['db_database'])) {
104  $rs = $db->Execute("SELECT value FROM sys_config WHERE name like 'version'");
105  $array = $rs->FetchRow();
106  $curr_ver = $array['value'];
107 
108  $rs = $db->Execute("SELECT value FROM sys_config WHERE name like 'upgrade_index'");
109  $array = $rs->FetchRow();
110  $upgrade_index = $array['value'];
111 
112  $levelinfo = $upgrade_index;
113 
114  if ($upgrade_index < 8) { $levelinfo = "<span style='background-color:#FF7375;'>Must upgrade to at least v09.09.15 first!</span>"; }
115  } else {
116  $status++;
117  $err_txt .= " <img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> [{$cname}] Failed to select DB '{$cdbs['db_database']}'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
118  }
119  }
120  // Close the database connection
121  @$db->Close();
122 
123 
124  $greet_txt .= "<tr style='background-color:{$ona_contexts[$cname]['context_color']};'><td >{$cname}</td><td>{$cdbs['db_type']}</td><td>{$cdbs['db_host']}</td><td>{$cdbs['db_database']}</td><td>{$curr_ver}</td><td><center>{$levelinfo}</center></td></tr>";
125  }
126 
127  }
128 
129  $greet_txt .= "</table></center>";
130 
131 
132  if ($status == 0) {
133  $upgrademain = <<<EOL
134  <div id="upgrademain">
135  <form id="upgradeform">
136  <input type='hidden' name='install_submit' value='Y' />
137  <input id='upgrade' type='hidden' name='upgrade' value='N' />
138  <a style="text-decoration: none;" href="{$baseURL}"><input class='edit' type="button" value="Cancel upgrade" onclick="" /></a>
139  <input class='edit' type='button' name='upgrade' value='Perform the upgrade.' onclick="el('upgrade').value='Y';el('upgradeform').submit();" />
140  </form>
141  </div>
142 EOL;
143  } else {
144  $upgrademain = <<<EOL
145  <div id='status'>There was an error determining database context versions. Please correct them before proceeding.<br><br>Check that the content of your database configuration file:<br> '<i>{$dbconffile}</i>'<br>is accurate and that the databases themselves are configured properly.<br><br>{$err_txt}</div><br>
146  <div id="upgrademain">
147  <form id="upgradeform">
148  <input type='hidden' name='install_submit' value='Y' />
149  <input id='upgrade' type='hidden' name='upgrade' value='N' />
150  <a style="text-decoration: none;" href="{$baseURL}"><input class='edit' type="button" value="Retry upgrade" onclick="" /></a>
151  </form>
152  </div>
153 EOL;
154  }
155 
156 }
157 
158 $main = <<<EOL
159  <div id="main" style="{$mainstyle}">
160  <form id="mainform">
161  <input type='hidden' name='install_submit' value='Y' />
162  <input id='overwrite' type='hidden' name='overwrite' value='N' />
163  <input id='keep' type='hidden' name='keep' value='N' />
164  <table>
165  <tr onmouseover="el('help').innerHTML = input1text;">
166  <td>Database Host:</td><td><input id='input1' class='edit' type='text' name='database_host' value='localhost' onfocus="el('help').innerHTML = input1text;"/></td></tr>
167  <tr onmouseover="el('help').innerHTML = inputtext_dbtype;">
168  <td>Database Type:</td>
169  <td>
170  <select class='edit' name='dbtype' onfocus="el('help').innerHTML = inputtext_dbtype;">
171  <option value="mysqli" selected="true">MySQL</option>
172  <!-- <option value="oci8">Oracle (oci8 driver)</option>
173  <option value="oci8po">Oracle (oci8po driver)</option>
174  <option value="postgres7">Postgres7</option>
175  <option value="postgres8">Postgres8</option>-->
176  </select>
177  </td>
178  </tr>
179  <tr onmouseover="el('help').innerHTML = input2text;">
180  <td>Database Admin:</td><td><input class='edit' type='text' name='admin_login' value='root' onfocus="el('help').innerHTML = input2text;" /></td></tr>
181  <tr onmouseover="el('help').innerHTML = input3text;">
182  <td>Database Admin Password:</td><td><input class='edit' type='password' name='admin_passwd' value='{$admin_passwd}' onfocus="el('help').innerHTML = input3text;"/></td></tr>
183  <tr onmouseover="el('help').innerHTML = input4text;">
184  <td>Database Name:</td><td><input class='edit' type='text' name='database_name' value='default' onfocus="el('help').innerHTML = input4text;"/></td></tr>
185  <tr onmouseover="el('help').innerHTML = input5text;">
186  <td>Application Database User Name:</td><td><input class='edit' type='text' name='sys_login' value='ona_sys' onfocus="el('help').innerHTML = input5text;"/></td></tr>
187  <tr onmouseover="el('help').innerHTML = input6text;">
188  <td>Application Database User Password:</td><td><input class='edit' type='password' name='sys_passwd' value='{$sys_passwd}' onfocus="el('help').innerHTML = input6text;"/></td></tr>
189  <tr onmouseover="el('help').innerHTML = input7text;">
190  <td>Default Domain Name:</td><td><input class='edit' type='text' name='default_domain' value='example.com' onfocus="el('help').innerHTML = input7text;"/></td></tr>
191  <tr><td colspan=2 style="text-align: center;"><br><input class='edit' type='submit' value='Create my database!' /></td></tr>
192  </table>
193  </form>
194  <script type="text/javascript" language="javascript">
195 
196  var input1text = '<b>Database Host:</b> The hostname or IP address of the database server where your database will be located.';
197  var input2text = '<b>Database Admin:</b> The username for the database administrator. This account will be used to create the new database and must have proper privledges to do so.';
198  var input3text = '<b>Database Admin Password:</b> The password for the database administrator account.';
199  var input4text = '<b>Database Name:</b> The name of the database that will store the OpenNetAdmin tables. We suggest "default", which will become "ona_default" when created.';
200  var input5text = '<b>System User Name:</b> The application username used by the php code to connect to the database. We suggest "ona_sys"';
201  var input6text = '<b>System User Password:</b> The password for the application user.';
202  var input7text = '<b>Default Domain Name:</b> The default DNS domain for your site. This will be your primary domain to add hosts to and will serve the default domain for certain tasks.';
203  var inputtext_dbtype = '<b>Database Type:</b> The type of database running on the database host.';
204 
205  </script>
206  </div>
207 EOL;
208 
209 
210 
211 
212 
213 
214 
215 // If they have selected to keep the tables then remove the run_install file
216 if ($install_submit == 'Y' && $upgrade == 'Y') {
217 
218  // Loop through each context and upgrade the Databases within
219  foreach(array_keys($ona_contexts) as $cname) {
220 
221  foreach($ona_contexts[$cname]['databases'] as $cdbs) {
222  printmsg("INFO => [{$cname}/{$cdbs['db_host']}] Performing an upgrade.",0);
223 
224  // Make an initial connection to a DB server without specifying a database
225  $db = ADONewConnection($cdbs['db_type']);
226  @$db->NConnect( $cdbs['db_host'], $cdbs['db_login'], $cdbs['db_passwd'], '' );
227 
228  if (!$db->IsConnected()) {
229  $status++;
230  printmsg("INFO => Unable to connect to server '{$cdbs['db_host']}'. ".$db->ErrorMsg(),0);
231  $text .= " <img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> [{$cname}] Failed to connect to '{$cdbs['db_host']}' as '{$cdbs['db_login']}'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
232  } else {
233  $db->Close();
234  if ($db->NConnect( $database_host, $cdbs['db_login'], $cdbs['db_passwd'], $cdbs['db_database'])) {
235 
236 
237  // Get the current upgrade index if there is one.
238  $rs = $db->Execute("SELECT value FROM sys_config WHERE name like 'upgrade_index'");
239  $array = $rs->FetchRow();
240  $upgrade_index = $array['value'];
241 
242  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Keeping your original data.<br>";
243 
244  // update existing tables in our database to match our baseline xml schema
245  // create a schema object and build the query array.
246  $schema = new adoSchema( $db );
247  // Build the SQL array from the schema XML file
248  $sql = $schema->ParseSchema($xmlfile_tables);
249  // Execute the SQL on the database
250  //$text .= "<pre>".$schema->PrintSQL('TEXT')."</pre>";
251  if ($schema->ExecuteSchema( $sql ) == 2) {
252  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Upgrading tables within database '{$cdbs['db_database']}'.<br>";
253  printmsg("INFO => [{$cname}/{$cdbs['db_host']}] Upgrading tables within database: {$cdbs['db_database']}",0);
254  } else {
255  $status++;
256  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> There was an error upgrading tables.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
257  printmsg("ERROR => There was an error processing tables: ".$db->ErrorMsg(),0);
258  break;
259  }
260 
261 
262 
263 
264 
265  $script_text = '';
266  if ($upgrade_index == '') {
267  $text .= "<img src=\"{$images}/silk/error.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Auto upgrades not yet supported. Please see docs/UPGRADES<br>";
268  } else {
269  // loop until we have processed all the upgrades
270  while(1 > 0) {
271  // Find out what the next index will be
272  $new_index = $upgrade_index + 1;
273  // Determine file name
274  //$upgrade_sqlfile = "{$base}/{$upgrade_index}-to-{$new_index}.sql";
275  $upgrade_xmlfile = "{$base}/{$upgrade_index}-to-{$new_index}.xml";
276  $upgrade_phpfile = "{$base}/{$upgrade_index}-to-{$new_index}.php";
277  // Check that the upgrade script exists
278  if (file_exists($upgrade_phpfile)) {
279  $script_text .= "<img src=\"{$images}/silk/error.png\" border=\"0\" />Please go to a command prompt and execute 'php {$upgrade_phpfile}' manually to complete the upgrade!<br>";
280  }
281  // Check that the upgrade file exists
282  if (file_exists($upgrade_xmlfile)) {
283  // get the contents of the sql update file
284  // create new tables in our database
285  // create a schema object and build the query array.
286  $schema = new adoSchema( $db );
287  // Build the SQL array from the schema XML file
288  $sql = $schema->ParseSchema($upgrade_xmlfile);
289  // Execute the SQL on the database
290  if ($schema->ExecuteSchema( $sql ) == 2) {
291  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Processed XML update file.<br>";
292  printmsg("INFO => [{$cname}/{$cdbs['db_host']}] Processed XML update file.",0);
293 
294  // update index info in the DB
295  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Upgraded from index {$upgrade_index} to {$new_index}.<br>";
296  // Update the upgrade_index element in the sys_config table
297  if($db->Execute("UPDATE sys_config SET value='{$new_index}' WHERE name like 'upgrade_index'")) {
298  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Updated DB upgrade_index variable to '{$new_index}'.<br>";
299  }
300  else {
301  $status++;
302  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Failed to update upgrade_index variable in table 'sys_config'.<br>";
303  break;
304  }
305  $upgrade_index++;
306  } else {
307  $status++;
308  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Failed to process XML update file.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
309  printmsg("ERROR => [{$cname}/{$cdbs['db_host']}] Failed to process XML update file. ".$db->ErrorMsg(),0);
310  break;
311  }
312  } else {
313  break;
314  }
315  }
316 
317  }
318 
319 
320  // Update the version element in the sys_config table if there were no previous errors
321  if($status == 0) {
322  if($db->Execute("UPDATE sys_config SET value='{$new_ver}' WHERE name like 'version'")) {
323  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Updated DB version variable to '{$new_ver}'.<br>";
324  }
325  else {
326  $status++;
327  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Failed to update version info in table 'sys_config'.<br>";
328  }
329  }
330  } else {
331  $status++;
332  $text .= " <img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> [{$cname}/{$cdbs['db_host']}] Failed to select DB '{$cdbs['db_database']}'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
333  }
334  }
335  // Close the database connection
336  @$db->Close();
337 
338  }
339 
340  }
341 
342  // If we still have the old reference to db_context in our config, upgrade it
343  if (is_array($db_context)) {
344  // set default db name to uppercase
345  $ona_contexts['DEFAULT'] = $ona_contexts['default'];unset($ona_contexts['default']);
346 
347  // Open the database config and write the contents to it.
348  if (!$fh = @fopen($dbconffile, 'w')) {
349  $status++;
350  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to open config file for writing: '{$dbconffile}'.<br>";
351  printmsg("ERROR => Failed to open config file for writing: '{$dbconffile}'.",0);
352  }
353  else {
354  fwrite($fh, "<?php\n\n\$ona_contexts=".var_export($ona_contexts,TRUE).";\n\n?>");
355  fclose($fh);
356  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Upgraded database connection config file to new format.<br>";
357  printmsg("INFO => Upgraded database connection config file to new format.",0);
358  }
359  }
360 
361 
362  if($status == 0) {
363  $text .= $script_text;
364  $text .= "You can now <a href='".parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH)."'>CLICK HERE</a> to start using OpenNetAdmin! Enjoy!";
365 
366  if (@file_exists($runinstall)) {
367  if (!@unlink($runinstall)) {
368  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to delete the file '{$runinstall}'.<br>";
369  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Please remove '{$runinstall}' manually.<br>";
370  }
371  }
372  } else {
373  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> There was a fatal error. Upgrade may be incomplete. Fix the issue and <a href=\"{$baseURL}\">try again</a>.<br>";
374  }
375 
376 }
377 
378 
379 
380 
381 
382 
383 
384 // This is the section for an brand new install
385 if ($install_submit == 'Y' && !isset($upgrade)) {
386 
387  // Just to keep things a little bit grouped, lets prepend the database with ona_
388  $database_name = 'ona_'.$database_name;
389 
390  // set up initial context connection information
391  $context_name = 'DEFAULT';
392  $ona_contexts[$context_name]['databases']['0']['db_type'] = $dbtype;
393  $ona_contexts[$context_name]['databases']['0']['db_host'] = $database_host;
394  $ona_contexts[$context_name]['databases']['0']['db_login'] = $sys_login;
395  $ona_contexts[$context_name]['databases']['0']['db_passwd'] = $sys_passwd;
396  $ona_contexts[$context_name]['databases']['0']['db_database'] = $database_name;
397  $ona_contexts[$context_name]['databases']['0']['db_debug'] = FALSE;
398  $ona_contexts[$context_name]['description'] = 'Default data context';
399  $ona_contexts[$context_name]['context_color'] = '#D3DBFF';
400 
401  // switch from mysqlt to mysql becuase of adodb problems with innodb and opt stuff when doing xml
402  $adotype = $dbtype;
403  // if ($adotype == 'mysqlt') $adotype = 'mysql';
404 
405  // Make an initial connection to a DB server without specifying a database
406  $db = ADONewConnection($adotype);
407 #$db->debug = true;
408  $db->NConnect( $database_host, $admin_login, $admin_passwd, '' );
409 
410  if (!$db->IsConnected()) {
411  $status++;
412  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to connect to '{$database_host}' as '{$admin_login}'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
413  printmsg("INFO => Unable to connect to server '$database_host'. ".$db->ErrorMsg(),0);
414  } else {
415  $text .= "<script>el('mainform').style.display = 'none';</script><img src=\"{$images}/silk/accept.png\" border=\"0\" /> Connected to '{$database_host}' as '{$admin_login}'.<br>";
416 
417  // Drop out any existing database and user
418  if (@$db->Execute("DROP DATABASE IF EXISTS {$database_name}")) {
419  //@$db->Execute("DROP USER IF EXISTS '{$sys_login}'@'%'");
420  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Dropped existing instance of '{$database_name}'.<br>";
421  printmsg("INFO => Dropped existing DB: $database_name",0);
422  }
423  else {
424  $status++;
425  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to drop existing instance of '{$database_name}'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
426  }
427 
428  // MP TODO: when this is done as part of an add conext, we must copy the system_config data from the default context to populate it
429  // so that plugins that have created options will show up etc. Prompt the user that this happened so they can change what they want.
430 
431  // Create the new database
432  $datadict = NewDataDictionary($db);
433  $sqlarray = $datadict->CreateDatabase($database_name);
434  if ($datadict->ExecuteSQLArray($sqlarray) == 2) {
435  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Created new database '{$database_name}'.<br>";
436  printmsg("INFO => Added new DB: $database_name",0);
437  }
438  else {
439  $status++;
440  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to create new database '{$database_name}'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
441  printmsg("ERROR => Failed to create new database '{$database_name}'. ".$db->ErrorMsg(),0);
442  }
443 
444 
445  // select the new database we just created
446  $db->Close();
447  if ($db->NConnect( $database_host, $admin_login, $admin_passwd, $database_name)) {
448 
449  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Selected existing DB: '{$database_name}'.<br>";
450 
451  // create new tables in our database
452  // create a schema object and build the query array.
453  $schema = new adoSchema( $db );
454  // Build the SQL array from the schema XML file
455  $sql = $schema->ParseSchema($xmlfile_tables);
456  // Execute the SQL on the database
457  if ($schema->ExecuteSchema( $sql ) == 2) {
458  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Creating and updating tables within database '{$database_name}'.<br>";
459  printmsg("INFO => Creating and updating tables within new DB: {$database_name}",0);
460  } else {
461  $status++;
462  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> There was an error processing tables.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
463  printmsg("ERROR => There was an error processing tables: ".$db->ErrorMsg(),0);
464  }
465 
466  // Load initial data into the new tables
467  if ($status == 0) {
468  $schema = new adoSchema( $db );
469  // Build the SQL array from the schema XML file
470  $sql = $schema->ParseSchema($xmlfile_data);
471  //$text .= "<pre>".$schema->PrintSQL('TEXT')."</pre>";
472  // Execute the SQL on the database
473  if ($schema->ExecuteSchema( $sql ) == 2) {
474  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Loaded tables with default data.<br>";
475  printmsg("INFO => Loaded data to new DB: {$database_name}",0);
476  } else {
477  $status++;
478  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed load default data.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
479  printmsg("ERROR => There was an error loading the data: ".$db->ErrorMsg(),0);
480  }
481  }
482 
483  // Add the system user to the database
484  // Run the query
485 
486  if ($status == 0) {
487  // it is likely that this method here is mysql only?
488  if(@$db->Execute("GRANT ALL ON {$database_name}.* TO '{$sys_login}'@'localhost' IDENTIFIED BY '{$sys_passwd}'")) {
489  @$db->Execute("GRANT ALL ON {$database_name}.* TO '{$sys_login}'@'%' IDENTIFIED BY '{$sys_passwd}'");
490  @$db->Execute("GRANT ALL ON {$database_name}.* TO '{$sys_login}'@'{$database_host}' IDENTIFIED BY '{$sys_passwd}'");
491  @$db->Execute("FLUSH PRIVILEGES");
492  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Created system user '{$sys_login}'.<br>";
493  printmsg("INFO => Created new DB user: {$sys_login}",0);
494  }
495  else {
496  $status++;
497  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to create system user '{$sys_login}'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
498  printmsg("ERROR => There was an error creating DB user: ".$db->ErrorMsg(),0);
499  }
500 
501  // add the default domain to the system
502  // This is a manual add with hard coded values for timers.
503  $xmldefdomain = <<<EOL
504 <?xml version="1.0"?>
505 <schema version="0.3">
506 <sql>
507  <query>INSERT INTO domains (id,name,admin_email,default_ttl,refresh,retry,expiry,minimum,parent_id,serial,primary_master) VALUES (1,'{$default_domain}','hostmaster', 86400, 86400, 3600, 3600, 3600,0,0,0)</query>
508  <query>UPDATE sys_config SET value='{$default_domain}' WHERE name like 'dns_defaultdomain'</query>
509 </sql>
510 </schema>
511 EOL;
512  $schema = new adoSchema( $db );
513 
514  // Build the SQL array from the schema XML file
515  $domainsql = $schema->ParseSchemaString($xmldefdomain);
516 
517  // Execute the SQL on the database
518  if ($schema->ExecuteSchema( $domainsql ) == 2) {
519  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Created default DNS domain '{$default_domain}'.<br>";
520  } else {
521  $status++;
522  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to create default DNS domain '{$default_domain}'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
523  }
524 
525 
526  // Open the database config and write the contents to it.
527  if (!$fh = @fopen($dbconffile, 'w')) {
528  $status++;
529  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to open config file for writing: '{$dbconffile}'.<br>";
530  }
531  else {
532  fwrite($fh, "<?php\n\n\$ona_contexts=".var_export($ona_contexts,TRUE).";\n\n?>");
533  fclose($fh);
534  $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Created database connection config file.<br>";
535  }
536 
537  // Update the version element in the sys_config table
538  if(@$db->Execute("UPDATE sys_config SET value='{$new_ver}' WHERE name like 'version'")) {
539  // $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Updated local version info.<br>";
540  }
541  else {
542  $status++;
543  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to update version info in table 'sys_config'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
544  }
545  }
546 
547  } else {
548  $status++;
549  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to select DB '{$database_name}'.<br><span style='font-size: xx-small;'>".$db->ErrorMsg()."</span><br>";
550  printmsg("ERROR => Failed to select DB: {$database_name}. ".$db->ErrorMsg(),0);
551  }
552 
553 
554 
555  if ($status > 0) {
556  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> There was a fatal error. Install may be incomplete. Fix the issue and <a href=\"{$baseURL}\">try again</a>.<br>";
557  } else {
558  // remove the run_install file in the install dir
559  if (@file_exists($runinstall)) {
560  if (!@unlink($runinstall)) {
561  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to delete the file '{$runinstall}'.<br>";
562  $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Please remove '{$runinstall}' manually.<br>";
563  }
564  }
565  $text .= "You can now <a href='".parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH)."'>CLICK HERE TO START</a> using OpenNetAdmin!<br>You can log in as 'admin' with a password of 'admin'<br>Enjoy!";
566  }
567 
568  // Close the database connection
569  @$db->Close();
570  }
571 
572 }
573 
574 
575 
576 // Start printing the html
577 print <<<EOL
578 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
579 <html>
580  <head>
581  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
582  <script type="text/javascript" src="{$baseURL}/include/js/global.js" language="javascript"></script>
583  </head>
584  <style type="text/css">
585 
586  body {
587  margin: 0px;
588  font-family: Arial, Sans-Serif;
589  color: 000000;
590  background-color: FFFFFF;
591  vertical-align: top;
592  }
593 
594  textarea.edit {
595  font-family: monospace;
596  border: 1px solid #8CACBB;
597  color: Black;
598  background-color: white;
599  padding: 3px;
600  width:100%;
601  }
602 
603  table {
604  font-size: small;
605  font-family: Arial, Sans-Serif;
606  }
607  td {
608  margin: 0px;
609  font-family: {$style['font-family']};
610  color: {$color['font_default']};
611  vertical-align: top;
612  }
613  input.edit,select.edit {
614  border: 1px solid #8CACBB;
615  color: Black;
616  background-color: white;
617  vertical-align: middle;
618  padding: 1px;
619  display: inline;
620  }
621  #checks {
622  font-size: small;
623  border: 1px solid;
624  margin-top: 15px;
625  }
626  #license {
627  width: 550px;
628  padding: 35px 0px;
629  text-align: left;
630  }
631  #greeting, #upgreeting {
632  width: 450px;
633  padding: 20px 0px;
634  text-align: left;
635  }
636  #help {
637  -moz-border-radius: 6;
638  padding: 5px;
639  border: 1px solid;
640  text-align: left;
641  width:500px;
642  }
643  #maintitle {
644  background-color: #D3DBFF;
645  font-size: xx-large;
646  width: 100%;
647  padding: 0px 60px;
648  -moz-border-radius-bottomleft: 10;
649  -moz-border-radius-bottomright: 10;
650  }
651  #status {
652  padding: 5px;
653  border: 1px solid;
654  text-align: left;
655  width:500px;
656  }
657 
658  </style>
659  <body>
660  <div align="center" style="width:100%;">
661  <span id="maintitle">OpenNetAdmin Install</span><br>
662 EOL;
663 
664 
665 
666 
667 // print the GPL license and have them "ok" it to continue.
668 if ($install_submit != 'Y' and $overwrite != 'Y') { echo $licensediv; }
669 
670 // Print a status to the user
671 print <<<EOL
672  <div id="work" style="display: none;">
673  <div id="prereq">{$requisitediv}</div>
674  <div id="Greeting">{$greet_txt}</div>
675 EOL;
676 
677 if ($install_submit == 'Y') { print "<script>el('work').style.display = '';</script>"; }
678 
679 if ($upgrademain != '') {
680  print $upgrademain;
681  print $main;
682  print $blankmain;
683 } else {
684  print $main;
685 }
686 
687 if ($install_submit == 'Y') {print "<div id='status'>{$text}</div><br>"; }
688 
689 if ($install_submit == 'Y') {print '<div id="help">Thanks for using ONA. Please visit <a href="http://opennetadmin.com">http://opennetadmin.com</a></div>';}
690 if ($upgrademain == '' and $install_submit != 'Y') {print '<div id="help"></div>';}
691 
692 print <<<EOL
693  </div>
694  </div>
695  </body>
696 </html>
697 EOL;
698 
699 
700 
701 
702 
703 
704 
705 
706 
707 ?>
$hasmbstring
$hasmbstring
Definition: install.php:25
$hasmysql
$hasmysql
Definition: install.php:24
$license_text
$license_text
Definition: install.php:17
onclick
_button onclick
Definition: app_advanced_search.inc.php:50
$base
$base
Definition: install.php:8
$rs
if(isset($_REQUEST['nrows'])) else $rs
Definition: server.php:94
Name
Full Name
Definition: app_user_info.inc.php:101
$sql
$sql
Definition: server.php:84
inputtext_dbtype
inputtext_dbtype
Definition: install.php:203
input2text
input2text
Definition: install.php:197
$status
$status
Definition: install.php:12
$xmlfile_data
$xmlfile_data
Definition: install.php:16
input3text
input3text
Definition: install.php:198
adoSchema
Definition: adodb-xmlschema.inc.php:1219
$runinstall
$runinstall
Definition: install.php:14
$conf
global $conf
Definition: install.php:4
$upgrademain
$upgrademain
Definition: install.php:60
$xmlfile_tables
$xmlfile_tables
Definition: install.php:15
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
$blankmain
$blankmain
Definition: install.php:28
$type
$type
Definition: dcm.php:17
input4text
input4text
Definition: install.php:199
$requisitediv
$requisitediv
Definition: install.php:43
$main
if(!is_array($ona_contexts) and is_array($db_context)) if(@file_exists($dbconffile)) $main
Definition: install.php:158
EOL
< a style="text-decoration: none;" href="/">< input class='edit' type="button" value="I don't like free stuff?" onclick=""/></a ></center ></div > EOL
Definition: install.php:40
input5text
input5text
Definition: install.php:200
input7text
input7text
Definition: install.php:202
$style
$style['font-family']
Definition: config.inc.php:158
$curr_ver
$curr_ver
Definition: install.php:19
nbsp
& nbsp
Definition: install.php:36
$licensediv
$licensediv
Definition: install.php:31
$greet_txt
$greet_txt
Definition: install.php:57
$dbconffile
$dbconffile
Definition: installcli.php:40
$new_ver
$new_ver
Definition: install.php:18
$onabase
$onabase
Definition: install.php:13
$text
$text
Definition: install.php:11
input6text
input6text
Definition: install.php:201
$ona_contexts
n n $ona_contexts
Definition: install.php:354
$dbconfwrite
$dbconfwrite
Definition: install.php:26
$color
if($_SERVER['SERVER_PORT']==443) $color['bg']
Definition: config.inc.php:119
$phpversion
$phpversion
Definition: install.php:22
$hasgmp
$hasgmp
Definition: install.php:23