File: 0.01.1a/setup.php (View as Code)

1: 2: /* ------------------------------------------------------------- 3: This file is part of FreeDESK 4: 5: FreeDESK is (C) Copyright 2012 David Cutting 6: 7: FreeDESK 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: FreeDESK 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 FreeDESK. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freedesk/ 21: -------------------------------------------------------------- */ 22: 23: /** 24: * The main setup file 25: **/ 26: ?> 27: 28: 29: FreeDESK Setup 30: 31: 54: 55: 56: 57: $setup=$_SERVER['SCRIPT_NAME']; 58: function step_list($steps, $current) 59: { 60: echo "
\n"; 61: for ($a=1; $a<=$steps; ++$a) 62: { 63: if ($a<$current) 64: echo ""; 65: else if ($a==$current) 66: echo ""; 67: else 68: echo ""; 69: echo $a; 70: echo ""; 71: } 72: echo "\n
\n";
73: } 74: 75: function fdsql($file, $prefix, &$sql) 76: { 77: $fp=@fopen("sql/".$file,"r"); 78: if (!$fp) 79: { 80: echo "Error opening ".$file."

";
81: return false; 82: } 83: $q=""; 84: while ($str = fgets($fp, 1024)) 85: { 86: if ($str[0]!="-") 87: { 88: for ($a=0; $a 89: { 90: $chr = $str[$a]; 91: if ($chr==";") 92: { 93: $q=str_replace("%%$%%", $prefix, $q); 94: mysql_query($q, $sql); 95: $q=""; 96: $a=strlen($str)+10; 97: } 98: else 99: $q.=$chr; 100: } 101: } 102: } 103: } 104: 105: if (!isset($_REQUEST['step'])) 106: $step=1; 107: else 108: $step=$_REQUEST['step']; 109: if (!is_numeric($step)) 110: $step=1; 111: 112: step_list(10, $step); 113: ?> 114:

FreeDESK Setup Process

115: 116: if ($step == 1) // First page 117: { 118: ?> 119:

Initial Setup

120: This process will take you through a fresh install or upgrade of the FreeDESK system.

121: If you are setup but are seeing this message then you need to delete the setup.php file in the freedesk directory

122: 123: if (file_exists("config/Config.php")) 124: { 125: echo "Configuration Already Exists - Keep Existing Database Connection Settings

";
126: } 127: echo "Create New Database Connection Settings"; 128: } 129: else if ($step == 2) // Database Connection Settings 130: { 131: ?> 132:

Database Connection Settings

133: The following settings are for a connection to a MySQL database where the FreeDESK data will be stored.

134: 135: echo "
\n"; 136: ?> 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160:
Server
Username
Password
Table Prefix
Database
Create Database
Password Salt e.g. three or four random characters
161: 162:
163: 164: 165: $fp=@fopen("config/Config.php","a"); 166: if (!$fp) 167: { 168: echo "Warning: the config/Config.php file is not writeable so you will have to manually update the file.

";
169: echo "Or if you make the file world-writeable (e.g. chmod 777 config in Linux) then the script will create it automatically."; 170: } 171: else 172: fclose($fp); 173: 174: } 175: 176: else if ($step == 3) // Validate and Write 177: { 178: echo "

Validating Connection Settings

";
179: $sql=mysql_connect($_REQUEST['db_server'],$_REQUEST['db_username'],$_REQUEST['db_password']); 180: if (!$sql) 181: { 182: echo "Error: Could not connect to the database. Please go back in your browser and input correct credentials

";
183: echo ""; 184: exit(); 185: } 186: echo "Successful connection to database server

";
187: 188: if (isset($_REQUEST['db_create']) && ($_REQUEST['db_create']=="1")) 189: { 190: echo "Creating Database...

";
191: $q="CREATE DATABASE ".$_REQUEST['db_database']; 192: mysql_query($q); 193: } 194: 195: if (mysql_select_db($_REQUEST['db_database'])) 196: { 197: echo "Connected to database ".$_REQUEST['db_database']."

";
198: } 199: else 200: { 201: echo "Error: Could not select database ".$_REQUEST['db_database'].", go back on your browser and input correct database

";
202: echo ""; 203: exit(); 204: } 205: 206: echo "

Creating Config File

";
207: $config = "208: $config.="\nclass FreeDESK_Configuration\n{\n"; 209: $config.="var \$db_System = \"MySQL\";\n"; 210: $config.="var \$db_Server = \"".$_REQUEST['db_server']."\";\n"; 211: $config.="var \$db_Username = \"".$_REQUEST['db_username']."\";\n"; 212: $config.="var \$db_Password = \"".$_REQUEST['db_password']."\";\n"; 213: $config.="var \$db_Database = \"".$_REQUEST['db_database']."\";\n"; 214: $config.="var \$db_Prefix = \"".$_REQUEST['db_prefix']."\";\n"; 215: $config.="var \$pwd_Hash = \"".$_REQUEST['pwd_salt']."\";\n"; 216: $config.="}\n?>"; 217: 218: $fp = @fopen("config/Config.php","w"); 219: if ($fp) 220: { 221: echo "Writing config/Config.php...

";
222: fputs($fp, $config); 223: fclose($fp); 224: } 225: else 226: { 227: echo "Sorry cannot write to config/Config.php file.

";
228: echo "Either make the file writeable by the web server and then refresh this page or...

";
229: echo "Copy and paste the following into a new file and upload it as config/Config.php within the freedesk directory.

";
230: echo "

\n";
231: } 232: echo "Continue With Installation"; 233: 234: } 235: 236: 237: else if ($step == 4) 238: { 239: echo "

Database Schema Setup/Upgrade

";
240: echo "Select a mode for the schema setup

";
241: echo "Perform a fresh install (any existing data will be lost or overriten) - SELECT FOR NEW INSTALL OR TO START FROM SCRATCH

";
242: echo "Perform an update install (no existing data will be lost) - SELECT TO UPDATE AN EXISTING SYSTEM

";
243: } 244: 245: else if ($step == 5) 246: { 247: require("config/Config.php"); 248: echo "

Import or Setup Schema

";
249: $fdc = new FreeDESK_Configuration(); 250: 251: $sql = mysql_connect($fdc->db_Server, $fdc->db_Username, $fdc->db_Password) 252: or die("Cannot connect to database"); 253: mysql_select_db($fdc->db_Database) 254: or die("Cannot select database"); 255: 256: if (isset($_REQUEST['mode']) && ($_REQUEST['mode']=="fresh")) 257: { 258: fdsql("schema-drop.fdsql", $fdc->db_Prefix, $sql); 259: fdsql("default.fdsql", $fdc->db_Prefix, $sql); 260: } 261: else 262: { 263: fdsql("schema.fdsql", $fdc->db_Prefix, $sql); 264: fdsql("upgrade.fdsql", $fdc->db_Prefix, $sql); 265: fdsql("default.fdsql", $fdc->db_Prefix, $sql); 266: } 267: echo "Database Schema setup - click here to continue

\n";
268: } 269: 270: else if ($step == 6) 271: { 272: echo "

Final Stages

";
273: echo "Trying to start FreeDESK...

";
274: require("core/FreeDESK.php"); 275: $DESK = new FreeDESK("./"); 276: if ($DESK->Start()) 277: { 278: echo "FreeDESK started!

";
279: echo "

Set Admin Password

";
280: echo "Set a password for the admin user - this is essential if this is a new install, fresh schema update or the password salt has changed.

";
281: echo "If you are using an existing setup and no connection data has changed just leave it blank to not set and just click go.

";
282: echo "
"; 283: echo "Password: "; 284: echo "";
285: } 286: else 287: { 288: echo "Sorry there was a problem starting FreeDESK

";
289: } 290: 291: $DESK->Stop(); 292: } 293: 294: else if ($step == 7) 295: { 296: require("core/FreeDESK.php"); 297: $DESK = new FreeDESK("./"); 298: $DESK->Start(); 299: 300: if (isset($_REQUEST['admin_password']) && ($_REQUEST['admin_password'] != "")) 301: { 302: echo "Setting admin password... "; 303: $amb=new AuthMethodStandard($DESK); 304: $amb->SetPassword("admin",$_REQUEST['admin_password']); 305: echo "Done

";
306: } 307: 308: echo "Your setup is now complete and can be further configured from within the system.

";
309: echo "PLEASE NOW DELETE THIS FILE (freedesk/setup.php) OR YOU WILL BE UNABLE TO USE FREEDESK.

";
310: echo "Click here to login to FreeDESK

";
311: 312: $DESK->Stop(); 313: } 314: else 315: { 316: echo "

Unknown Mode

";
317: } 318: ?> 319: 320: 321: 322: