From 0df0e5f1e927ea1d04bd5ef3c12be3bc2c72837c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 4 Aug 2008 12:12:25 +0000 Subject: Central: Wrote installation script Closes #4 --- central/trunk/install.php | 346 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 338 insertions(+), 8 deletions(-) (limited to 'central/trunk/install.php') diff --git a/central/trunk/install.php b/central/trunk/install.php index d04e99b..7b5514f 100644 --- a/central/trunk/install.php +++ b/central/trunk/install.php @@ -2,20 +2,350 @@ /* InstaDisc Server - A Four Island Project */ -if (!isset($_GET['step'])) +$softwareVersion = 1; + +if (!isset($_GET['submit'])) +{ + showHeader('1'); + showStepOne('localhost', 'root', '', 'instadisc', array()); +} else { + $numOfErrors = 0; + $errors = array(); + + switch ($_GET['submit']) + { + case 1: + if ($_POST['host'] == '') + { + addError($numOfErrors, $errors, 'host', 'Hostname is a required field'); + } + + if ($_POST['username'] == '') + { + addError($numOfErrors, $errors, 'username', 'Username is a required field'); + } + + if ($_POST['password'] == '') + { + addError($numOfErrors, $errors, 'password', 'Password is a required field'); + } + + if ($_POST['dbname'] == '') + { + addError($numOfErrors, $errors, 'dbname', 'Name is a required field'); + } + + if ($numOfErrors > 0) + { + showHeader('1'); + showStepOne($_POST['host'], $_POST['username'], $_POST['password'], $_POST['dbname'], $errors); + } else { + if (!@mysql_connect($_POST['host'], $_POST['username'], $_POST['password'])) + { + addError($numOfErrors, $errors, '', 'Cannot connect to database server'); + showHeader('1'); + showStepOne($_POST['host'], $_POST['username'], $_POST['password'], $_POST['dbname'], $errors); + } else { + if (!@mysql_select_db($_POST['dbname'])) + { + addError($numOfErrors, $errors, 'dbname', 'Database does not exist'); + showHeader('1'); + showStepOne($_POST['host'], $_POST['username'], $_POST['password'], $_POST['dbname'], $errors); + } else { + $sql = file_get_contents('instadisc.sql'); + $makedb = split(';', $sql); + foreach ($makedb as $name => $value) + { + if (!trim($value) == '') + { + $makedb2 = @mysql_query($value); + if (!$makedb2) + { + addError($numOfErrors, $errors, '', "MySQL error \"" . mysql_error() . "\" while creating database"); + } + } + } + + @file_put_contents('config.php', ""); + + if (!file_exists('config.php')) + { + addError($numOfErrors, $errors, '', 'Could not write config.php file, please check directory permissions'); + } + + if ($numOfErrors > 0) + { + showHeader('1'); + showStepOne($_POST['host'], $_POST['username'], $_POST['password'], $_POST['dbname'], $errors); + } else { + showHeader('2'); + showStepTwo('','',' CHECKED','','','','','','','', array()); + } + } + } + } + + break; + + case 2: + if ($_POST['mailDomain'] == '') + { + addError($numOfErrors, $errors, 'mailDomain', 'Mail Domain is a required field'); + } + + if ($_POST['smtpHost'] == '') + { + addError($numOfErrors, $errors, 'smtpHost', 'SMTP Host is a required field'); + } + + if ($_POST['smtpAuth'] == 'on') + { + if ($_POST['smtpUser'] == '') + { + addError($numOfErrors, $errors, 'smtpUser', 'When "SMTP Authentication Required?" is checked, SMTP Username is a required field'); + } + + if ($_POST['smtpPass'] == '') + { + addError($numOfErrors, $errors, 'smtpPass', 'When "SMTP Authentication Required?" is checked, SMTP Password is a required field'); + } + } + + if ($_POST['siteName'] == '') + { + addError($numOfErrors, $errors, 'siteName', 'Site Name is a required field'); + } + + if ($_POST['xmlrpcURL'] == '') + { + addError($numOfErrors, $errors, 'xmlrpcURL', 'XML-RPC URL is a required field'); + } else { + include_once('xmlrpc/xmlrpc.inc'); + + $client = new xmlrpc_client($_POST['xmlrpcURL']); + $msg = new xmlrpcmsg('system.listMethods'); + $r = $client->send($msg); + if (stripos($r->faultString(),'Connect error') !== FALSE) + { + addError($numOfErrors, $errors, 'xmlrpcURL', $r->faultString()); + } + } + + if ($_POST['adminUser'] == '') + { + addError($numOfErrors, $errors, 'adminUser', 'Admin Username is a required field'); + } + + if ($_POST['adminPass'] == '') + { + addError($numOfErrors, $errors, 'adminPass', 'Admin Password is a required field'); + } + + if ($_POST['adminEmail'] == '') + { + addError($numOfErrors, $errors, 'adminEmail', 'Admin Email is a required field'); + } + + if ($numOfErrors > 0) + { + showHeader('2'); + showStepTwo($_POST['mailDomain'], $_POST['smtpHost'], ($_POST['smtpAuth'] == 'on' ? ' CHECKED' : ''), $_POST['smtpUser'], $_POST['smtpPass'], $_POST['siteName'], $_POST['xmlrpcURL'], $_POST['adminUser'], $_POST['adminPass'], $_POST['adminEmail'], $errors); + } else { + include_once('config.php'); + + mysql_connect($dbhost, $dbuser, $dbpass); + mysql_select_db($dbname); + + $sql[0] = "INSERT INTO config (name,value) VALUES (\"mailDomain\",\"" . mysql_real_escape_string($_POST['mailDomain']) . "\")"; + $sql[1] = "INSERT INTO config (name,value) VALUES (\"smtpHost\",\"" . mysql_real_escape_string($_POST['smtpHost']) . "\")"; + $sql[2] = "INSERT INTO config (name,value) VALUES (\"smtpAuth\",\"" . mysql_real_escape_string($_POST['smtpAuth']) . "\")"; + $sql[3] = "INSERT INTO config (name,value) VALUES (\"smtpUser\",\"" . mysql_real_escape_string($_POST['smtpUser']) . "\")"; + $sql[4] = "INSERT INTO config (name,value) VALUES (\"smtpPass\",\"" . mysql_real_escape_string($_POST['smtpPass']) . "\")"; + $sql[5] = "INSERT INTO config (name,value) VALUES (\"siteName\",\"" . mysql_real_escape_string($_POST['siteName']) . "\")"; + $sql[6] = "INSERT INTO config (name,value) VALUES (\"xmlrpcURL\",\"" . mysql_real_escape_string($_POST['xmlrpcURL']) . "\")"; + $sql[7] = "INSERT INTO config (name,value) VALUES (\"owner\",\"" . mysql_real_escape_string($_POST['adminUser']) . "\")"; + $sql[8] = "INSERT INTO config (name,value) VALUES (\"verIDBufferSize\",\"100\")"; + $sql[9] = "INSERT INTO config (name,value) VALUES (\"softwareVersion\",\"" . $softwareVersion . "\")"; + $sql[10] = "INSERT INTO config (name,value) VALUES (\"databaseVersion\",\"1\")"; + $sql[11] = "INSERT INTO users (username, password, email, ip) VALUES (\"" . mysql_real_escape_string($_POST['adminUser']) . "\",\"" . mysql_real_escape_string(md5($_POST['adminPass'])) . "\",\"" . mysql_real_escape_string($_POST['adminEmail']) . "\",\"" . mysql_real_escape_string($_SERVER['REMOTE_IP']) . "\")"; + $sql[12] = "INSERT INTO centralServers (url, code, xmlrpc) VALUES (\"" . mysql_real_escape_string('central.fourisland.com') . "\",\"" . mysql_real_escape_string(md5('central.fourisland.com')) . "\",\"" . mysql_real_escape_string('http://central.fourisland.com/xmlrpc.php') . "\")"; + + foreach ($sql as $name => $value) + { + if (!trim($value) == '') + { + $sql2 = @mysql_query($value); + if (!$sql2) + { + addError($numOfErrors, $errors, '', "MySQL error \"" . mysql_error() . "\" while filling database"); + } + } + } + + if ($numOfErrors > 0) + { + showHeader('2'); + showStepTwo($_POST['mailDomain'], $_POST['smtpHost'], ($_POST['smtpAuth'] == 'on' ? ' CHECKED' : ''), $_POST['smtpUser'], $_POST['smtpPass'], $_POST['siteName'], $_POST['xmlrpcURL'], $_POST['adminUser'], $_POST['adminPass'], $_POST['adminEmail'], $errors); + } else { + showHeader('3'); + showStepThree(); + } + } + + break; + } +} + +?>

InstaDisc (C) Starla Insigna 2008. InstaDisc Setup uses the UniForm form theme
Welcome to the InstaDisc Central Server installation! Please input your database details here:

Database host:
Username:
Password:
Database name: (Note: You must create this database BEFORE running installation)
InstaDisc Server Setup Step <?php echo($number); ?>

InstaDisc Installation

Welcome to the InstaDisc Central Server installation! Please input your database details below.

+

+Cannot connect to your database server! Please verify you typed you host, username and password correctly. Back
Uh oh! Validation errors!

+

    $value) + { +?>
+
Database Details +
+ + +
+
+ + +
+
+ + +
+
+ + +

You need to create this database before running this script.

+
+
+
+ +
Your database has been set up. All we need to do now is fill it up a little. Please answer the below questions to set up your configuration: +
+Cannot connect to your database! Please verify that the database you specified already exists and that you spelled it correctly. Back
Uh oh! Validation errors!

+

    $value) + { +?>
+
Email +
+ + +

Type in the part that comes after the @ in your email addresses. This is used when InstaDisc needs to send an email to someone.

+
+
+ + +

This is required because InstaDisc has to be able to send emails to people.

+
+
+ + "> +

If your SMTP server requires authentication (most do), you need to check this box and enter the authentication details in the fields below.

+
+
+ + +
+
+ + +

The two above fields only need be filled out if the "SMTP Authentication Required?" box is checked.

+
+
Website +
+ + +

Your website's name is required for a little personalization of emails.

+
+
+ + +

What is the URL of the xmlrpc.php file provided for you in the InstaDisc package?

+
+
Administrator's Account +
+ + +
+
+ + +
+
+ + +

You, the administrator, must have an account on your InstaDisc server to be able to edit configuration values (mostly the ones you just entered) at will.

+
+
+
+ +
Congradulations! You've successfully set up your InstaDisc Central Server's database! Now, the next step for you is to implement the functions in instadisc.php into your web application. Read README.txt for more information. + +function ifErrors($errors, $id) +{ + foreach ($errors as $name => $value) + { + if ($value['field'] == $id) + { + echo(' error'); + return; + } + } +} + + +function doErrors($errors, $id) +{ + foreach ($errors as $name => $value) + { + if ($value['field'] == $id) + { +?>

*

$field, 'msg' => $msg); +} -- cgit 1.4.1