From 6f881a9f11d80e2bc27ec5ade72ac55eaef495c6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 28 Sep 2008 22:53:48 +0000 Subject: Central: Added createUser() Refs #63 --- central/trunk/includes/instadisc.php | 4 +- central/trunk/index.php | 33 ++++++- central/trunk/instadisc.sql | 1 - central/trunk/install.php | 176 +++++------------------------------ 4 files changed, 58 insertions(+), 156 deletions(-) diff --git a/central/trunk/includes/instadisc.php b/central/trunk/includes/instadisc.php index 320ff80..99d06b1 100644 --- a/central/trunk/includes/instadisc.php +++ b/central/trunk/includes/instadisc.php @@ -98,9 +98,9 @@ function instaDisc_addItem($username, $subscription, $title, $author, $url, $sem } } -function instaDisc_createUser($username, $password, $email) +function instaDisc_createUser($username, $password) { - $insuser = "INSERT INTO users (username, password, email) VALUES (\"" . mysql_real_escape_string($username) . "\", \"" . mysql_real_escape_string($password) . "\", \"" . mysql_real_escape_string($email) . "\")"; + $insuser = "INSERT INTO users (username, password) VALUES (\"" . mysql_real_escape_string($username) . "\", \"" . mysql_real_escape_string($password) . "\")"; $insuser2 = mysql_query($insuser); } diff --git a/central/trunk/index.php b/central/trunk/index.php index ea77e3f..1d85fa1 100644 --- a/central/trunk/index.php +++ b/central/trunk/index.php @@ -246,6 +246,36 @@ function countSubscribers($url) return new xmlrpcresp(new xmlrpcval($cntsub3[0], 'int')); } +function createUser($username, $password) +{ + $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\""; + $getuser2 = mysql_query($getuser); + $getuser3 = mysql_fetch_array$($getuser2); + if ($getuser3['username'] == $username) + { + $ij = 0; + + while ($ij == 0) + { + $fakeUN = $username . rand(10,9999); + + $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($fakeUN) . "\""; + $getuser2 = mysql_query($getuser); + $getuser3 = mysql_fetch_array$($getuser2); + if ($getuser3['username'] != $username) + { + $ij = 1; + } + } + + return new xmlrpcresp(new xmlrpcval($fakeUN, 'string')); + } else { + instaDisc_createUser($username, $password); + + return new xmlrpcresp(new xmlrpcval($username, 'string')); + } +} + $s = new xmlrpc_server( array( "InstaDisc.checkRegistration" => array("function" => "checkRegistration"), "InstaDisc.deleteItem" => array("function" => "deleteItem"), "InstaDisc.resendItem" => array("function" => "resendItem"), @@ -258,7 +288,8 @@ $s = new xmlrpc_server( array( "InstaDisc.checkRegistration" => array("function" "InstaDisc.setDownloadItemMode" => array("function" => "setDownloadItemMode"), "InstaDisc.initalizePort" => array("function" => "initalizePort"), "InstaDisc.deinitalizePort" => array("function" => "deinitalizePort"), - "InstaDisc.countSubscribers" => array("function" => "countSubscribers") + "InstaDisc.countSubscribers" => array("function" => "countSubscribers"), + "InstaDisc.createUser" => array("function" => "createUser") ),0); $s->functions_parameters_type = 'phpvals'; $s->service(); diff --git a/central/trunk/instadisc.sql b/central/trunk/instadisc.sql index be4eef9..ef87a95 100644 --- a/central/trunk/instadisc.sql +++ b/central/trunk/instadisc.sql @@ -84,7 +84,6 @@ CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `username` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, - `email` varchar(255) NOT NULL, `ip` varchar(255) NOT NULL, `port` int(11) NOT NULL, `nextItemID` int(11) NOT NULL, diff --git a/central/trunk/install.php b/central/trunk/install.php index b7a97ab..4fd0172 100644 --- a/central/trunk/install.php +++ b/central/trunk/install.php @@ -2,10 +2,6 @@ /* InstaDisc Server - A Four Island Project */ -include('includes/class.phpmailer.php'); - -$softwareVersion = 1; - if (!isset($_GET['submit'])) { showHeader('1'); @@ -90,132 +86,49 @@ if (!isset($_GET['submit'])) break; case 2: - if ($_POST['smtpHost'] == '') + if ($_POST['adminUser'] == '') { - addError($numOfErrors, $errors, 'smtpHost', 'SMTP Host is a required field'); + addError($numOfErrors, $errors, 'adminUser', 'Admin Username is a required field'); } - if ($_POST['smtpAuth'] == 'on') + if ($_POST['adminPass'] == '') { - 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'); - } + addError($numOfErrors, $errors, 'adminPass', 'Admin Password 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); + showStepTwo($_POST['adminUser'], $_POST['adminPass'], $errors); } else { - $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, '', $mail->ErrorInfo); - } + include_once('includes/config.php'); - if ($_POST['mailDomain'] == '') - { - addError($numOfErrors, $errors, 'mailDomain', 'Mail Domain is a required field'); - } + mysql_connect($dbhost, $dbuser, $dbpass); + mysql_select_db($dbname); - if ($_POST['siteName'] == '') - { - addError($numOfErrors, $errors, 'siteName', 'Site Name is a required field'); - } + $sql[0] = "INSERT INTO config (name,value) VALUES (\"owner\",\"" . mysql_real_escape_string($_POST['adminUser']) . "\")"; + $sql[1] = "INSERT INTO config (name,value) VALUES (\"verIDBufferSize\",\"10000\")"; + $sql[2] = "INSERT INTO users (username, password, ip) VALUES (\"" . mysql_real_escape_string($_POST['adminUser']) . "\",\"" . mysql_real_escape_string(md5($_POST['adminPass'])) . "\",\"" . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . "\")"; - if ($_POST['xmlrpcURL'] == '') + foreach ($sql as $name => $value) { - addError($numOfErrors, $errors, 'xmlrpcURL', 'XML-RPC URL is a required field'); - } else { - include_once('includes/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) + if (!trim($value) == '') { - addError($numOfErrors, $errors, 'xmlrpcURL', $r->faultString()); + $sql2 = @mysql_query($value); + if (!$sql2) + { + addError($numOfErrors, $errors, '', "MySQL error \"" . mysql_error() . "\" while filling database"); + } } } - 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); + showStepTwo($_POST['adminUser'], $_POST['adminPass'], $errors); } else { - include_once('includes/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\",\"10000\")"; - $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']) . "\")"; - - 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(); - } + showHeader('3'); + showStepThree(); } } @@ -270,7 +183,7 @@ function showStepOne($host, $username, $password, $dbname, $errors) 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:
@@ -286,43 +199,7 @@ function showStepTwo($mailDomain, $smtpHost, $smtpAuth, $smtpUser, $smtpPass, $s ?> -
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 +
Administrator's Account
@@ -331,11 +208,6 @@ function showStepTwo($mailDomain, $smtpHost, $smtpAuth, $smtpUser, $smtpPass, $s
-
- - -

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.

-
@@ -344,7 +216,7 @@ function showStepTwo($mailDomain, $smtpHost, $smtpAuth, $smtpUser, $smtpPass, $s function showStepThree() { -?>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. See Becoming A Central Server. Also, it would be smart to subscribe to your InstaDisc Update Notice Subscription, which will notify you if your Central Server's software gets out of date. It's the subscription.php file in this directory. Please subscribe to it, thanks!

However, remember that to be any use to anyone, you need your Central Server database, and to be added to others'. To do this, please find the appropriate help section on http://fourisland.com/projects/instadisc/BecomingACentralServerCongradulations! You've successfully set up your InstaDisc Central Server's database!