From 9969f54cea4d79af79ec1808d4c348b264939360 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 7 Aug 2008 23:49:13 +0000 Subject: Central: Added Email check to installation Now, the installation script checks the SMTP details entered to ensure that they are valid so as to avoid errors like #23. Also modified return for instaDisc_activateAccount(). Refs #23 --- central/trunk/instadisc.php | 7 +- central/trunk/install.php | 160 ++++++++++++++++++++++++++------------------ 2 files changed, 98 insertions(+), 69 deletions(-) (limited to 'central') diff --git a/central/trunk/instadisc.php b/central/trunk/instadisc.php index 34bf74e..a1d491a 100644 --- a/central/trunk/instadisc.php +++ b/central/trunk/instadisc.php @@ -180,9 +180,9 @@ function instaDisc_sendActivationEmail($username, $password, $email) $mail->AddAddress($email, $username); $mail->Subject = 'InstaDisc Account Verification'; $mail->Body = "Hello, someone has recently registered an account at " . $_SERVER['HTTP_HOST'] . " with your email address. If that was you, and your chosen username IS " . $username . ", then copy the account verification code below to our Account Verification page, enter your username and press Activate!\r\n\r\n" . $penKey . "\r\n\r\nIf that was not you, copy the above code to our Account Verification page, enter the above username, and click Delete."; - $mail->Send(); - return ($mail->IsError() ? $mail->ErrorInfo : true); //$mail->Send(); + + return ($mail->IsError() ? $mail->ErrorInfo : true); } function instaDisc_activateAccount($username, $penKey) @@ -202,8 +202,9 @@ function instaDisc_activateAccount($username, $penKey) $mail->AddAddress($getuser3['email'], $username); $mail->Subject = 'Welcome to InstaDisc!'; $mail->Body = "Welcome to InstaDisc! Thank you for registering at " . instaDisc_getConfig('siteName') . " Central Server, we hope you enjoy our service! Now, when you download an InstaDisc Client, it will ask you for the following information which you will need to enter into it for it to work:\r\n\r\nUsername: " . $username . "\r\nPassword: (you should know this, it's not displayed here for security reasons)\r\nCentral Server URL: " . instaDisc_getConfig("xmlrpcURL") . "\r\n\r\nOnce again, thank you for choosing " . instaDisc_getConfig("siteName") . "!"; + $mail->Send(); - return $mail->Send(); + return ($mail->IsError() ? $mail->ErrorInfo : true); } else { return false; } diff --git a/central/trunk/install.php b/central/trunk/install.php index 846140a..5022faf 100644 --- a/central/trunk/install.php +++ b/central/trunk/install.php @@ -88,11 +88,6 @@ if (!isset($_GET['submit'])) 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'); @@ -111,84 +106,117 @@ if (!isset($_GET['submit'])) } } - if ($_POST['siteName'] == '') - { - addError($numOfErrors, $errors, 'siteName', 'Site Name is a required field'); - } - - if ($_POST['xmlrpcURL'] == '') + if ($numOfErrors > 0) { - addError($numOfErrors, $errors, 'xmlrpcURL', 'XML-RPC URL is a required field'); + 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('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) + $mail = new PHPMailer(); + $mail->IsSMTP(); + $mail->From = 'instadisc@' . $_POST['mailDomain']; + $mail->FromName = 'InstaDisc'; + $mail->Host = $_POST['smtpHost']; + if ($_POST['smtpAuth'] == 'on') + { + $mail->SMTPAuth = true; + $mail->Username = $_POST['smtpUser']; + $mail->Password = $_POST['smtpPass']; + } + $mail->Helo = $_SERVER['HTTP_HOST']; + $mail->ClearAddresses(); + $mail->AddAddress("test@fourisland.com"); + $mail->Subject = 'Test Email'; + $mail->Body = 'Please discard this email.'; + $mail->Send(); + if ($mail->IsError()) { - addError($numOfErrors, $errors, 'xmlrpcURL', $r->faultString()); + addError($numOfErrors, $errors, '', $mail->ErrorInfo); } - } - 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['mailDomain'] == '') + { + addError($numOfErrors, $errors, 'mailDomain', 'Mail Domain is a required field'); + } - if ($_POST['adminEmail'] == '') - { - addError($numOfErrors, $errors, 'adminEmail', 'Admin Email is a required field'); - } + if ($_POST['siteName'] == '') + { + addError($numOfErrors, $errors, 'siteName', 'Site Name 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'] == 'on' ? 'true' : 'false')) . "\")"; - $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_ADDR']) . "\")"; - $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 ($_POST['xmlrpcURL'] == '') { - if (!trim($value) == '') + 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) { - $sql2 = @mysql_query($value); - if (!$sql2) - { - addError($numOfErrors, $errors, '', "MySQL error \"" . mysql_error() . "\" while filling database"); - } + 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 { - showHeader('3'); - showStepThree(); + 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'] == 'on' ? 'true' : 'false')) . "\")"; + $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_ADDR']) . "\")"; + $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(); + } } } -- cgit 1.4.1