Location: PHPKode > projects > Simple SMS Site Software > simple-sms-site-software/setup.php
<?php
$pword = substr(md5(mktime()),0,8);

$grant_1 = 'GRANT USAGE ON * . * TO "aqlssss"@"localhost" IDENTIFIED BY "'.$pword.'"';
$grant_2 = 'GRANT SELECT , INSERT , UPDATE , DELETE ON `'.$_POST['form_db'].'` . * TO "aqlssss"@"localhost"';
$table_1 = "
CREATE TABLE `sent_messages` (
`id` INT NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 50 ) NOT NULL ,
`wap_address` VARCHAR( 200 ) ,
`originator` VARCHAR( 20 ) ,
`message_type` VARCHAR( 20 ) NOT NULL ,
`flash` SET( 'yes', 'no' ) NOT NULL ,
`contents` VARCHAR( 160 ) NOT NULL ,
`datetime` DATETIME NOT NULL ,
PRIMARY KEY ( `id` )
)";

$table_2 = "
CREATE TABLE `users` (
`username` VARCHAR( 50 ) NOT NULL ,
`password` VARCHAR( 50 ) NOT NULL ,
`name` VARCHAR( 50 ) NOT NULL ,
`details` VARCHAR( 100 ) NOT NULL ,
`add1` VARCHAR( 100 ) NOT NULL ,
`add2` VARCHAR( 100 ) NOT NULL ,
`add3` VARCHAR( 100 ) NOT NULL ,
`postcode` VARCHAR( 10 ) NOT NULL ,
`email` VARCHAR( 100 ) NOT NULL ,
`mobile` VARCHAR( 15 ) NOT NULL ,
`landline` VARCHAR( 15 ) NOT NULL ,
`pword_lock` SET( 'yes', 'no' ) DEFAULT 'no' NOT NULL ,
`admin` SET( 'yes', 'no' ) DEFAULT 'no' NOT NULL ,
`credits` INT NOT NULL ,
`locked` SET( 'yes', 'no' ) DEFAULT 'yes' NOT NULL ,

PRIMARY KEY ( `username` )
)";


$table_3 = "
CREATE TABLE `delrep` (
`id` INT NOT NULL AUTO_INCREMENT ,
`reportcode` VARCHAR( 255 ) NOT NULL ,
`destinationnum` VARCHAR( 255 ) NOT NULL ,
`reference` VARCHAR( 255 ) NOT NULL ,
INDEX ( `id` ) ,
UNIQUE (
`reference`
)
)";


$table_4 = "
CREATE TABLE `address_book` (
`username` VARCHAR( 255 ) NOT NULL ,
`name` VARCHAR( 255 ) NOT NULL ,
`number` VARCHAR( 255 ) NOT NULL ,
`other_details` VARCHAR( 255 ) NOT NULL
)";

$table_5 = "
CREATE TABLE `config` (
`name` VARCHAR( 255 ) NOT NULL ,
`value` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `name` )
)";

$load_1 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('aqluser', 'username')";
$load_2 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('aqlpass', 'password')";
$load_3 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('account_lock', 'yes')";
$load_4 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('guest_active', 'yes')";
$load_5 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('init_cred', '0')";
$load_6 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('signup_notify', 'yes')";
$load_7 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('admin_email', 'hide@address.com')";
$load_8 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('site_title', 'this appears in the titlebar')";
$load_9 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('site_name', 'Simple SMS Site Software')";
$load_10 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('home_page', 'http://aql.com/')";
$load_11 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('site_url', 'http://aql.com/')";
$load_12 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('secure_send', 'no')";
$load_13 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('allow_concat', 'no')";
$load_14 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('max_concats', '1')";
$load_14 = "INSERT INTO `config` ( `name` , `value` ) VALUES ('version', '1.01')";
$load_15 = "
INSERT INTO `users` ( `username` , `password` , `name` , `details` , `add1` , `add2` , `add3` , `postcode` , `email` , `mobile` , `landline` , `pword_lock` , `admin` , `credits` , `locked`)
VALUES (
'Admin', '21232f297a57a5a743894a0e4a801fc3', 'Admin', 'The Admin', 'address1' , 'address2' , 'address3' , 'postcode' , 'hide@address.com' , '077123456789' , '01234123456' , 'no' , 'yes' , '0' , 'no'
)";

$load_16 = "
INSERT INTO `users` ( `username` , `password` , `name` , `details` , `add1` , `add2` , `add3` , `postcode` , `email` ,`mobile` , `landline` , `pword_lock` , `admin` , `credits` )
VALUES (
'guest', '084e0343a0486ff05530df6c705c8bb4', 'Guest', 'The Guest Account', 'address1' , 'address2' , 'address3' , 'postcode' , 'hide@address.com' ,  '077123456789' , '01234123456' , 'yes' , 'no' , '0'
)";

$reload_1 = "FLUSH PRIVILEGES";

?><html>
<head>
<title>AQL SSSS Setup</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>AQL SSSS Setup</p>
<?php
if ($_POST['action'] == "process") {
while (true) {
	if ($_POST['form_username'] == "") {
		echo "MySQL username not entered (usually root)";
		break;
	}
	if ($_POST['form_password'] == "") {
		echo "MySQL password not entered";
		break;
	}
	if ($_POST['form_hostname'] == "") {
		echo "MySQL hostname not entered";
		break;
	}
	if ($_POST['form_db'] == "") {
		echo "MySQL Database to Create not entered";
		break;
	}

	//Verifies existence of a MySQL database
	$db_exists = FALSE;
	if ($db_conn = @mysql_connect($_POST['form_hostname'], $_POST['form_username'], $_POST['form_password'])) {
		$result = mysql_list_dbs($db_conn);
		while ($row=mysql_fetch_array($result, MYSQL_NUM)) {
			if ($row[0] ==  $_POST['form_db'])
			$db_exists = TRUE;
		}
		mysql_free_result($result);
		mysql_close($db_conn);
	}	
	
	$db_conn = @mysql_connect($_POST['form_hostname'], $_POST['form_username'], $_POST['form_password']);
		
	if (!is_resource($db_conn)) {
		echo "Could not connect to mysql with those credentials. Mysql Error: ".mysql_error();
		break;
	}
	echo "* Connected to DB Server<br>";

	if (!$db_exists) {
		if (!mysql_query("CREATE DATABASE ".$_POST['form_db'])) { 
			echo "* Database not created (".mysql_error().")<br>";
			break;
		}

		echo "* Database Created<br>";
	}

	if (!mysql_select_db($_POST['form_db'])) {
		echo "Error selecting database: ".mysql_error();
		break;
	}

	echo "* Database Selected<br>";

	if (!mysql_query($grant_1)) {
		echo "Grant Statement 1 NOT written (".mysql_error().")<br>";
		break;
	}
        if (!mysql_query($grant_2)) {
                echo "Grant Statement 2 NOT written (".mysql_error().")<br>";
                break;
        }

	echo "* Grant Statements written<br>";

        if (!mysql_query($table_1)) {
                echo "Table 1 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($table_2)) {
                echo "Table 2 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($table_3)) {
                echo "Table 3 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($table_4)) {
                echo "Table 4 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($table_5)) {
                echo "Table 5 NOT written (".mysql_error().")<br>";
                break;
        }

	echo "* Tables Created<br>";


        if (!mysql_query($load_1)) {
                echo "Data Load 1 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_2)) {
                echo "Data Load 2 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_3)) {
                echo "Data Load 3 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_4)) {
                echo "Data Load 4 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_5)) {
                echo "Data Load 5 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_6)) {
                echo "Data Load 6 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_7)) {
                echo "Data Load 7 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_8)) {
                echo "Data Load 8 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_9)) {
                echo "Data Load 9 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_10)) {
                echo "Data Load 10 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_11)) {
                echo "Data Load 11 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_12)) {
                echo "Data Load 12 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_13)) {
                echo "Data Load 13 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_14)) {
                echo "Data Load 14 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_15)) {
                echo "Data Load 15 NOT written (".mysql_error().")<br>";
                break;
        }
        if (!mysql_query($load_16)) {
                echo "Data Load 16 NOT written (".mysql_error().")<br>";
                break;
        }

	echo "* Initial Data Loaded<br>";

        if (!mysql_query($reload_1)) {
                echo "Reloading Privileges failed (".mysql_error().")<br>";
                break;
        }

	echo "* Reloaded Privileges<br><br>";

	echo "You now need to alter the inc/dbinfo.inc.php file with the following details<br>";
	echo '<pre>
$dbhost     = "'.$_POST['form_hostname'].'";
$dbusername = "aqlssss";
$dbpassword = "'.$pword.'";
$dbname     = "'.$_POST['form_db'].'";
</pre>
';
	break;
}
}
?>
<form action="setup.php" method="post" name="setup_form" id="setup_form">
<input type="hidden" name="action" value="process">
  <table width="460" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>MySQL Username</td>
      <td><input name="form_username" type="text" id="form_username"></td>
    </tr>
    <tr>
      <td>MySQL Password</td>
      <td><input name="form_password" type="text" id="form_password"></td>
    </tr>
    <tr> 
      <td>MySQL Host</td>
      <td><input name="form_hostname" type="text" id="form_hostname"></td>
    </tr>
    <tr> 
      <td>Database to use</td>
      <td><input name="form_db" type="text" id="form_db"></td>
    </tr>
    <tr> 
      <td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
</form>
</body>
</html>

Return current item: Simple SMS Site Software