File: 0.04.28a/server/web/firstrun-.php (View as Code)

1: 2: /* ------------------------------------------------------------- 3: This file is part of FreeNATS 4: 5: FreeNATS is (C) Copyright 2008 PurplePixie Systems 6: 7: FreeNATS is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeNATS is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeNATS. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freenats 21: -------------------------------------------------------------- */ 22: 23: require("include.php"); 24: $sn=$_SERVER['SCRIPT_NAME']; 25: $script=""; 26: for ($a=strlen($sn)-1; $a>0; $a--) 27: { 28: $c=$sn[$a]; 29: if ($c=="/") $a=-1; 30: else $script=$c.$script; 31: } 32: if ($script!="firstrun.php") 33: { 34: echo "Error: This script is not correctly named. In order to run it please rename "".$script."" to "firstrun.php"."; 35: echo "

";
36: exit(); 37: } 38: if (isset($_REQUEST['stage'])) $stage=$_REQUEST['stage']; 39: else $stage=0; 40: 41: function sqlfile($file) 42: { 43: global $BaseDir; 44: $fn=$BaseDir."sql/".$file.".sql"; 45: echo "Processing ".$fn."

";
46: $fp=fopen($fn,"r"); 47: if ($fp<=0) 48: { 49: echo "ERROR: Cannot Open File!

";
50: return false; 51: } 52: $q=""; 53: $qc=0; 54: $qok=0; 55: $qerr=0; 56: while ($s=fgets($fp,1024)) 57: { 58: if ($s[0]!="-") 59: { 60: for ($a=0; $a 61: { 62: $c=$s[$a]; 63: if ($c==";") 64: { 65: mysql_query($q); 66: $qc++; 67: if (mysql_errno()!=0) 68: { 69: echo "Warning/Error
";
70: echo "SQL: ".$q."
";
71: echo "Error: ".mysql_error()." (Code ".mysql_errno().")

";
72: $qerr++; 73: } 74: else $qok++; 75: $q=""; 76: } 77: else 78: $q.=$c; 79: } 80: } 81: } 82: echo "Finished Processing: ".$qc." queries (".$qok." ok, ".$qerr." warnings/errors)

";
83: fclose($fp); 84: } 85: 86: echo "FreeNATS Setup\n"; 87: echo "

First Run Setup: Stage ".$stage."

";
88: 89: echo "Testing database connectivity...
";
90: $sql=mysql_connect($fnCfg['db.server'],$fnCfg['db.username'],$fnCfg['db.password']) 91: or die("Failed to connect to database server ".$fnCfg['db.server']." with username ".$fnCfg['db.username']."
Details: ".mysql_error());
92: mysql_select_db($fnCfg['db.database']) 93: or die("Connected ok but failed to select database ".$fnCfg['db.database']."
Details: ".mysql_error());
94: echo "Database connection succeeded!

";
95: 96: switch($stage) 97: { 98: case 0: 99: echo "Users Performing an Upgrade Please Note:
this will only update the database and not ";
100: echo "the files which you must do manually or with the shell-install/vm-upgrade scripts.

";
101: echo "
"; 102: echo ""; 103: echo "Setup Database Schema and Defaults

";
104: echo "Select installation/update type...

";
105: echo ""; 106: echo "
"; 107: echo ""; 108: echo ""; 109: echo "Fresh Install/Upgrade
";
110: echo "First time users should select this. For upgrades this is
";
111: echo "the recommended choice and should work but will loose your
";
112: echo "data and configuration.

";
113: echo "
"; 114: echo ""; 115: echo ""; 116: echo "Database Upgrade (highly experimental)
";
117: echo "Select this to attempt to update your schema (add new tables
";
118: echo "and fields etc keeping your data and config intact. You may
";
119: echo "need to come back and do a fresh update or update the schema
";
120: echo "by hand if it fails."; 121: echo "

";
122: echo " Submit Anonymous Usage Data Automatically
";
123: echo "This will help us track use of the product and aid future development.

";
124: echo " Include Example Setup (Recommended) (n/a if upgrade selected)

";
125: echo ""; 126: echo "";
127: exit(); 128: break; 129: 130: case 1: 131: if ($_REQUEST['insttype']=="fresh") 132: { 133: echo "Fresh Install or Clean Update

";
134: echo "Setting Up Schema...

";
135: sqlfile("schema.drop"); 136: echo "Setting Up Defaults...

";
137: sqlfile("default"); 138: if (isset($_REQUEST['example'])) 139: { 140: echo "Setting Up Examples...

";
141: sqlfile("example"); 142: } 143: } 144: else if ($_REQUEST['insttype']=="upgrade") 145: { 146: echo "Experimental Upgrade... Expect to See Errors
";
147: echo "Doesn't mean it hasn't worked if you see already exists/duplicate errors

";
148: echo "Basically ignore errors: 1050, 1060, 1068 and 1054

";
149: echo "Importing New Schema (sans drop tables)

";
150: sqlfile("schema"); 151: echo "

Doing Schema Upgrade

";
152: sqlfile("schema.upgrade"); 153: echo "

";
154: } 155: else echo "Error: Incorrect or Unknown Installation Type!

";
156: 157: if (isset($_REQUEST['tracker'])) 158: { 159: echo "Enabling Usage Tracker

";
160: $q="INSERT INTO fnconfig(fnc_var,fnc_val) VALUES(\"freenats.tracker\",\"1\")"; 161: mysql_query($q); 162: } 163: echo "

";
164: echo "CONGRATULATIONS!!

";
165: echo "Setup should now be complete. If you saw errors etc above please see the "; 166: echo "project homepage for help.

";
167: echo "RENAME THIS FILE "firstrun.php" TO SOMETHING ELSE LIKE "firstrun-.php" TO STOP OTHERS RUNNING IT"; 168: echo "

";
169: echo "Click here to continue - login admin password admin (click settings once logged in to change)

";
170: 171: 172: exit(); 173: break; 174: 175: default: 176: echo "Sorry - unknown step in setup process!

";
177: exit(); 178: } 179: 180: ?>