Viewing File server/web/firstrun.php of 0.02.14a
|
1: <?php 2: require("include.php"); 3: $sn=$_SERVER['SCRIPT_NAME']; 4: $script=""; 5: for ($a=strlen($sn)-1; $a>0; $a--) 6: { 7: $c=$sn[$a]; 8: if ($c=="/") $a=-1; 9: else $script=$c.$script; 10: } 11: if ($script!="firstrun.php") 12: { 13: echo "<b>Error:</b> This script is not correctly named. In order to run it please rename "".$script."" to "firstrun.php"."; 14: echo "<br><br>"; 15: exit(); 16: } 17: if (isset($_REQUEST['stage'])) $stage=$_REQUEST['stage']; 18: else $stage=0; 19: 20: function sqlfile($file) 21: { 22: global $BaseDir; 23: $fn=$BaseDir."sql/".$file.".sql"; 24: echo "Processing ".$fn."<br><br>"; 25: $fp=fopen($fn,"r"); 26: if ($fp<=0) 27: { 28: echo "<b>ERROR: Cannot Open File!</b><br><br>"; 29: return false; 30: } 31: $q=""; 32: $qc=0; 33: $qok=0; 34: $qerr=0; 35: while ($s=fgets($fp,1024)) 36: { 37: if ($s[0]!="-") 38: { 39: for ($a=0; $a<strlen($s); $a++) 40: { 41: $c=$s[$a]; 42: if ($c==";") 43: { 44: mysql_query($q); 45: $qc++; 46: if (mysql_errno()!=0) 47: { 48: echo "<b>Warning/Error</b><br>"; 49: echo "<b>SQL:</b> ".$q."<br>"; 50: echo "<b>Error:</b> ".mysql_error()." (Code ".mysql_errno().")<br><br>"; 51: $qerr++; 52: } 53: else $qok++; 54: $q=""; 55: } 56: else 57: $q.=$c; 58: } 59: } 60: } 61: echo "Finished Processing: ".$qc." queries (".$qok." ok, ".$qerr." warnings/errors)<br><br>"; 62: fclose($fp); 63: } 64: 65: echo "<h1>First Run Setup: Stage ".$stage."</h1>"; 66: 67: echo "Testing database connectivity...<br>"; 68: $sql=mysql_connect($fnCfg['db.server'],$fnCfg['db.username'],$fnCfg['db.password']) 69: or die("Failed to connect to database server ".$fnCfg['db.server']." with username ".$fnCfg['db.username']."<br>Details: ".mysql_error()); 70: mysql_select_db($fnCfg['db.database']) 71: or die("Connected ok but failed to select database ".$fnCfg['db.database']."<br>Details: ".mysql_error()); 72: echo "Database connection succeeded!<br><br>"; 73: 74: switch($stage) 75: { 76: case 0: 77: echo "<form action=firstrun.php method=post>"; 78: echo "<input type=hidden name=stage value=1>"; 79: echo "<b>Setup Database Schema and Defaults</b><br><br>"; 80: echo "<input type=checkbox name=example value=1 checked> Include Example Setup (Recommended)<br><br>"; 81: echo "<input type=submit value=\"Proceed With Setup\">"; 82: echo "</form>"; 83: exit(); 84: break; 85: 86: case 1: 87: echo "<b>Setting Up Schema...</b><br><br>"; 88: sqlfile("schema"); 89: echo "<b>Setting Up Defaults...</b><br><br>"; 90: sqlfile("default"); 91: if (isset($_REQUEST['example'])) 92: { 93: echo "<b>Setting Up Examples...</b><br><br>"; 94: sqlfile("example"); 95: } 96: echo "<br><br>"; 97: echo "<b>CONGRATULATIONS!!</b><br><br>"; 98: echo "Setup should now be complete. If you saw errors etc above please see the <a href=http://www.purplepixie.org/freenats/>"; 99: echo "project homepage</a> for help.<br><br>"; 100: echo "<b>RENAME THIS FILE "firstrun.php" TO SOMETHING ELSE LIKE "firstrun-.php" TO STOP OTHERS RUNNING IT</b>"; 101: echo "<br><br>"; 102: echo "<a href=./>Click here to continue</a> - login admin password admin (click settings once logged in to change)<br><br>"; 103: 104: 105: exit(); 106: break; 107: 108: default: 109: echo "Sorry - unknown step in setup process!<br><br>"; 110: exit(); 111: } 112: 113: ?>