about summary refs log tree commit diff stats
path: root/central
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2008-09-28 22:53:48 +0000
committerKelly Rauchenberger <fefferburbia@gmail.com>2008-09-28 22:53:48 +0000
commit6f881a9f11d80e2bc27ec5ade72ac55eaef495c6 (patch)
tree735a8f7c59ffb5d0c8f442a80c3bd9d5e92689b1 /central
parent9c696344683332400000e40c2c54dc98e98d947b (diff)
downloadinstadisc-6f881a9f11d80e2bc27ec5ade72ac55eaef495c6.tar.gz
instadisc-6f881a9f11d80e2bc27ec5ade72ac55eaef495c6.tar.bz2
instadisc-6f881a9f11d80e2bc27ec5ade72ac55eaef495c6.zip
Central: Added createUser()
Refs #63
Diffstat (limited to 'central')
-rw-r--r--central/trunk/includes/instadisc.php4
-rw-r--r--central/trunk/index.php33
-rw-r--r--central/trunk/instadisc.sql1
-rw-r--r--central/trunk/install.php176
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
98 } 98 }
99} 99}
100 100
101function instaDisc_createUser($username, $password, $email) 101function instaDisc_createUser($username, $password)
102{ 102{
103 $insuser = "INSERT INTO users (username, password, email) VALUES (\"" . mysql_real_escape_string($username) . "\", \"" . mysql_real_escape_string($password) . "\", \"" . mysql_real_escape_string($email) . "\")"; 103 $insuser = "INSERT INTO users (username, password) VALUES (\"" . mysql_real_escape_string($username) . "\", \"" . mysql_real_escape_string($password) . "\")";
104 $insuser2 = mysql_query($insuser); 104 $insuser2 = mysql_query($insuser);
105} 105}
106 106
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)
246 return new xmlrpcresp(new xmlrpcval($cntsub3[0], 'int')); 246 return new xmlrpcresp(new xmlrpcval($cntsub3[0], 'int'));
247} 247}
248 248
249function createUser($username, $password)
250{
251 $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\"";
252 $getuser2 = mysql_query($getuser);
253 $getuser3 = mysql_fetch_array$($getuser2);
254 if ($getuser3['username'] == $username)
255 {
256 $ij = 0;
257
258 while ($ij == 0)
259 {
260 $fakeUN = $username . rand(10,9999);
261
262 $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($fakeUN) . "\"";
263 $getuser2 = mysql_query($getuser);
264 $getuser3 = mysql_fetch_array$($getuser2);
265 if ($getuser3['username'] != $username)
266 {
267 $ij = 1;
268 }
269 }
270
271 return new xmlrpcresp(new xmlrpcval($fakeUN, 'string'));
272 } else {
273 instaDisc_createUser($username, $password);
274
275 return new xmlrpcresp(new xmlrpcval($username, 'string'));
276 }
277}
278
249$s = new xmlrpc_server( array( "InstaDisc.checkRegistration" => array("function" => "checkRegistration"), 279$s = new xmlrpc_server( array( "InstaDisc.checkRegistration" => array("function" => "checkRegistration"),
250 "InstaDisc.deleteItem" => array("function" => "deleteItem"), 280 "InstaDisc.deleteItem" => array("function" => "deleteItem"),
251 "InstaDisc.resendItem" => array("function" => "resendItem"), 281 "InstaDisc.resendItem" => array("function" => "resendItem"),
@@ -258,7 +288,8 @@ $s = new xmlrpc_server( array( "InstaDisc.checkRegistration" => array("function"
258 "InstaDisc.setDownloadItemMode" => array("function" => "setDownloadItemMode"), 288 "InstaDisc.setDownloadItemMode" => array("function" => "setDownloadItemMode"),
259 "InstaDisc.initalizePort" => array("function" => "initalizePort"), 289 "InstaDisc.initalizePort" => array("function" => "initalizePort"),
260 "InstaDisc.deinitalizePort" => array("function" => "deinitalizePort"), 290 "InstaDisc.deinitalizePort" => array("function" => "deinitalizePort"),
261 "InstaDisc.countSubscribers" => array("function" => "countSubscribers") 291 "InstaDisc.countSubscribers" => array("function" => "countSubscribers"),
292 "InstaDisc.createUser" => array("function" => "createUser")
262 ),0); 293 ),0);
263$s->functions_parameters_type = 'phpvals'; 294$s->functions_parameters_type = 'phpvals';
264$s->service(); 295$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` (
84 `id` int(11) NOT NULL auto_increment, 84 `id` int(11) NOT NULL auto_increment,
85 `username` varchar(255) NOT NULL, 85 `username` varchar(255) NOT NULL,
86 `password` varchar(255) NOT NULL, 86 `password` varchar(255) NOT NULL,
87 `email` varchar(255) NOT NULL,
88 `ip` varchar(255) NOT NULL, 87 `ip` varchar(255) NOT NULL,
89 `port` int(11) NOT NULL, 88 `port` int(11) NOT NULL,
90 `nextItemID` int(11) NOT NULL, 89 `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 @@
2 2
3/* InstaDisc Server - A Four Island Project */ 3/* InstaDisc Server - A Four Island Project */
4 4
5include('includes/class.phpmailer.php');
6
7$softwareVersion = 1;
8
9if (!isset($_GET['submit'])) 5if (!isset($_GET['submit']))
10{ 6{
11 showHeader('1'); 7 showHeader('1');
@@ -90,132 +86,49 @@ if (!isset($_GET['submit']))
90 break; 86 break;
91 87
92 case 2: 88 case 2:
93 if ($_POST['smtpHost'] == '') 89 if ($_POST['adminUser'] == '')
94 { 90 {
95 addError($numOfErrors, $errors, 'smtpHost', 'SMTP Host is a required field'); 91 addError($numOfErrors, $errors, 'adminUser', 'Admin Username is a required field');
96 } 92 }
97 93
98 if ($_POST['smtpAuth'] == 'on') 94 if ($_POST['adminPass'] == '')
99 { 95 {
100 if ($_POST['smtpUser'] == '') 96 addError($numOfErrors, $errors, 'adminPass', 'Admin Password is a required field');
101 {
102 addError($numOfErrors, $errors, 'smtpUser', 'When "SMTP Authentication Required?" is checked, SMTP Username is a required field');
103 }
104
105 if ($_POST['smtpPass'] == '')
106 {
107 addError($numOfErrors, $errors, 'smtpPass', 'When "SMTP Authentication Required?" is checked, SMTP Password is a required field');
108 }
109 } 97 }
110 98
111 if ($numOfErrors > 0) 99 if ($numOfErrors > 0)
112 { 100 {
113 showHeader('2'); 101 showHeader('2');
114 showStepTwo($_POST['mailDomain'], $_POST['smtpHost'], ($_POST['smtpAuth'] == 'on' ? ' CHECKED' : ''), $_POST['smtpUser'], $_POST['smtpPass'], $_POST['siteName'], $_POST['xmlrpcURL'], $_POST['adminUser'], $_POST['adminPass'], $_POST['adminEmail'], $errors); 102 showStepTwo($_POST['adminUser'], $_POST['adminPass'], $errors);
115 } else { 103 } else {
116 $mail = new PHPMailer(); 104 include_once('includes/config.php');
117 $mail->IsSMTP();
118 $mail->From = 'instadisc@' . $_POST['mailDomain'];
119 $mail->FromName = 'InstaDisc';
120 $mail->Host = $_POST['smtpHost'];
121 if ($_POST['smtpAuth'] == 'on')
122 {
123 $mail->SMTPAuth = true;
124 $mail->Username = $_POST['smtpUser'];
125 $mail->Password = $_POST['smtpPass'];
126 }
127 $mail->Helo = $_SERVER['HTTP_HOST'];
128 $mail->ClearAddresses();
129 $mail->AddAddress("test@fourisland.com");
130 $mail->Subject = 'Test Email';
131 $mail->Body = 'Please discard this email.';
132 $mail->Send();
133 if ($mail->IsError())
134 {
135 addError($numOfErrors, $errors, '', $mail->ErrorInfo);
136 }
137 105
138 if ($_POST['mailDomain'] == '') 106 mysql_connect($dbhost, $dbuser, $dbpass);
139 { 107 mysql_select_db($dbname);
140 addError($numOfErrors, $errors, 'mailDomain', 'Mail Domain is a required field');
141 }
142 108
143 if ($_POST['siteName'] == '') 109 $sql[0] = "INSERT INTO config (name,value) VALUES (\"owner\",\"" . mysql_real_escape_string($_POST['adminUser']) . "\")";
144 { 110 $sql[1] = "INSERT INTO config (name,value) VALUES (\"verIDBufferSize\",\"10000\")";
145 addError($numOfErrors, $errors, 'siteName', 'Site Name is a required field'); 111 $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']) . "\")";
146 }
147 112
148 if ($_POST['xmlrpcURL'] == '') 113 foreach ($sql as $name => $value)
149 { 114 {
150 addError($numOfErrors, $errors, 'xmlrpcURL', 'XML-RPC URL is a required field'); 115 if (!trim($value) == '')
151 } else {
152 include_once('includes/xmlrpc/xmlrpc.inc');
153
154 $client = new xmlrpc_client($_POST['xmlrpcURL']);
155 $msg = new xmlrpcmsg('system.listMethods');
156 $r = $client->send($msg);
157 if (stripos($r->faultString(),'Connect error') !== FALSE)
158 { 116 {
159 addError($numOfErrors, $errors, 'xmlrpcURL', $r->faultString()); 117 $sql2 = @mysql_query($value);
118 if (!$sql2)
119 {
120 addError($numOfErrors, $errors, '', "MySQL error \"" . mysql_error() . "\" while filling database");
121 }
160 } 122 }
161 } 123 }
162 124
163 if ($_POST['adminUser'] == '')
164 {
165 addError($numOfErrors, $errors, 'adminUser', 'Admin Username is a required field');
166 }
167
168 if ($_POST['adminPass'] == '')
169 {
170 addError($numOfErrors, $errors, 'adminPass', 'Admin Password is a required field');
171 }
172
173 if ($_POST['adminEmail'] == '')
174 {
175 addError($numOfErrors, $errors, 'adminEmail', 'Admin Email is a required field');
176 }
177
178 if ($numOfErrors > 0) 125 if ($numOfErrors > 0)
179 { 126 {
180 showHeader('2'); 127 showHeader('2');
181 showStepTwo($_POST['mailDomain'], $_POST['smtpHost'], ($_POST['smtpAuth'] == 'on' ? ' CHECKED' : ''), $_POST['smtpUser'], $_POST['smtpPass'], $_POST['siteName'], $_POST['xmlrpcURL'], $_POST['adminUser'], $_POST['adminPass'], $_POST['adminEmail'], $errors); 128 showStepTwo($_POST['adminUser'], $_POST['adminPass'], $errors);
182 } else { 129 } else {
183 include_once('includes/config.php'); 130 showHeader('3');
184 131 showStepThree();
185 mysql_connect($dbhost, $dbuser, $dbpass);
186 mysql_select_db($dbname);
187
188 $sql[0] = "INSERT INTO config (name,value) VALUES (\"mailDomain\",\"" . mysql_real_escape_string($_POST['mailDomain']) . "\")";
189 $sql[1] = "INSERT INTO config (name,value) VALUES (\"smtpHost\",\"" . mysql_real_escape_string($_POST['smtpHost']) . "\")";
190 $sql[2] = "INSERT INTO config (name,value) VALUES (\"smtpAuth\",\"" . mysql_real_escape_string(($_POST['smtpAuth'] == 'on' ? 'true' : 'false')) . "\")";
191 $sql[3] = "INSERT INTO config (name,value) VALUES (\"smtpUser\",\"" . mysql_real_escape_string($_POST['smtpUser']) . "\")";
192 $sql[4] = "INSERT INTO config (name,value) VALUES (\"smtpPass\",\"" . mysql_real_escape_string($_POST['smtpPass']) . "\")";
193 $sql[5] = "INSERT INTO config (name,value) VALUES (\"siteName\",\"" . mysql_real_escape_string($_POST['siteName']) . "\")";
194 $sql[6] = "INSERT INTO config (name,value) VALUES (\"xmlrpcURL\",\"" . mysql_real_escape_string($_POST['xmlrpcURL']) . "\")";
195 $sql[7] = "INSERT INTO config (name,value) VALUES (\"owner\",\"" . mysql_real_escape_string($_POST['adminUser']) . "\")";
196 $sql[8] = "INSERT INTO config (name,value) VALUES (\"verIDBufferSize\",\"10000\")";
197 $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']) . "\")";
198
199 foreach ($sql as $name => $value)
200 {
201 if (!trim($value) == '')
202 {
203 $sql2 = @mysql_query($value);
204 if (!$sql2)
205 {
206 addError($numOfErrors, $errors, '', "MySQL error \"" . mysql_error() . "\" while filling database");
207 }
208 }
209 }
210
211 if ($numOfErrors > 0)
212 {
213 showHeader('2');
214 showStepTwo($_POST['mailDomain'], $_POST['smtpHost'], ($_POST['smtpAuth'] == 'on' ? ' CHECKED' : ''), $_POST['smtpUser'], $_POST['smtpPass'], $_POST['siteName'], $_POST['xmlrpcURL'], $_POST['adminUser'], $_POST['adminPass'], $_POST['adminEmail'], $errors);
215 } else {
216 showHeader('3');
217 showStepThree();
218 }
219 } 132 }
220 } 133 }
221 134
@@ -270,7 +183,7 @@ function showStepOne($host, $username, $password, $dbname, $errors)
270</DIV></FORM><?php 183</DIV></FORM><?php
271} 184}
272 185
273function showStepTwo($mailDomain, $smtpHost, $smtpAuth, $smtpUser, $smtpPass, $siteName, $xmlrpcURL, $adminUser, $adminPass, $adminEmail, $errors) 186function showStepTwo($adminUser, $adminPass, $errors)
274{ 187{
275?>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: 188?>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:
276<FORM CLASS="uniform" ACTION="./install.php?submit=2" METHOD="POST"> 189<FORM CLASS="uniform" ACTION="./install.php?submit=2" METHOD="POST">
@@ -286,43 +199,7 @@ function showStepTwo($mailDomain, $smtpHost, $smtpAuth, $smtpUser, $smtpPass, $s
286?></OL></DIV><?php 199?></OL></DIV><?php
287 } 200 }
288?> 201?>
289<FIELDSET CLASS="inlineLabels"><LEGEND>Email</LEGEND> 202<FIELDSET CLASS="inlineLabels"><LEGEND>Administrator's Account</LEGEND>
290<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'mailDomain'); ?>">
291<?php doErrors($errors, 'mailDomain'); ?> <LABEL FOR="mailDomain"><EM>*</EM> Mail Domain: </LABEL>
292 <INPUT TYPE="text" ID="mailDomain" NAME="mailDomain" CLASS="textInput" VALUE="<?php echo($mailDomain); ?>">
293 <P CLASS="formHint">Type in the part that comes after the @ in your email addresses. This is used when InstaDisc needs to send an email to someone.</P>
294</DIV>
295<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'smtpHost'); ?>">
296<?php doErrors($errors, 'smtpHost'); ?> <LABEL FOR="smtpHost"><EM>*</EM> SMTP Host: </LABEL>
297 <INPUT TYPE="text" ID="smtpHost" NAME="smtpHost" CLASS="textInput" VALUE="<?php echo($smtpHost); ?>">
298 <P CLASS="formHint">This is required because InstaDisc has to be able to send emails to people.</P>
299</DIV>
300<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'smtpAuth'); ?>">
301<?php doErrors($errors, 'smtpAuth'); ?> <LABEL FOR="smtpAuth">SMTP Authentication Required? </LABEL>
302 <INPUT TYPE="checkbox" ID="smtpAuth" NAME="smtpAuth" CLASS="textInput"<?php echo($smtpAuth); ?>">
303 <P CLASS="formHint">If your SMTP server requires authentication (most do), you need to check this box and enter the authentication details in the fields below.</P>
304</DIV>
305<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'smtpUser'); ?>">
306<?php doErrors($errors, 'smtpUser'); ?> <LABEL FOR="smtpUser">SMTP Username: </LABEL>
307 <INPUT TYPE="text" ID="smtpUser" NAME="smtpUser" CLASS="textInput" VALUE="<?php echo($smtpUser); ?>">
308</DIV>
309<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'smtpPass'); ?>">
310<?php doErrors($errors, 'smtpPass'); ?> <LABEL FOR="smtpPass">SMTP Password: </LABEL>
311 <INPUT TYPE="password" ID="smtpPass" NAME="smtpPass" CLASS="textInput" VALUE="<?php echo($smtpPass); ?>">
312 <P CLASS="formHint">The two above fields only need be filled out if the "SMTP Authentication Required?" box is checked.</P>
313</DIV>
314</FIELDSET><FIELDSET CLASS="inlineLabels"><LEGEND>Website</LEGEND>
315<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'siteName'); ?>">
316<?php doErrors($errors, 'siteName'); ?> <LABEL FOR="siteName"><EM>*</EM> Site Name: </LABEL>
317 <INPUT TYPE="text" ID="siteName" NAME="siteName" CLASS="textInput" VALUE="<?php echo($siteName); ?>">
318 <P CLASS="formHint">Your website's name is required for a little personalization of emails.</P>
319</DIV>
320<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'xmlrpcURL'); ?>">
321<?php doErrors($errors, 'xmlrpcURL'); ?> <LABEL FOR="xmlrpcURL"><EM>*</EM> XML-RPC URL: </LABEL>
322 <INPUT TYPE="text" ID="xmlrpcURL" NAME="xmlrpcURL" CLASS="textInput" VALUE="<?php echo($xmlrpcURL); ?>">
323 <P CLASS="formHint">What is the URL of the xmlrpc.php file provided for you in the InstaDisc package?</P>
324</DIV>
325</FIELDSET><FIELDSET CLASS="inlineLabels"><LEGEND>Administrator's Account</LEGEND>
326<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'adminUser'); ?>"> 203<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'adminUser'); ?>">
327<?php doErrors($errors, 'adminUser'); ?> <LABEL FOR="adminUser"><EM>*</EM> Admin Username: </LABEL> 204<?php doErrors($errors, 'adminUser'); ?> <LABEL FOR="adminUser"><EM>*</EM> Admin Username: </LABEL>
328 <INPUT TYPE="text" ID="adminUser" NAME="adminUser" CLASS="textInput" VALUE="<?php echo($adminUser); ?>"> 205 <INPUT TYPE="text" ID="adminUser" NAME="adminUser" CLASS="textInput" VALUE="<?php echo($adminUser); ?>">
@@ -331,11 +208,6 @@ function showStepTwo($mailDomain, $smtpHost, $smtpAuth, $smtpUser, $smtpPass, $s
331<?php doErrors($errors, 'adminPass'); ?> <LABEL FOR="adminPass"><EM>*</EM> Admin Password: </LABEL> 208<?php doErrors($errors, 'adminPass'); ?> <LABEL FOR="adminPass"><EM>*</EM> Admin Password: </LABEL>
332 <INPUT TYPE="password" ID="adminPass" NAME="adminPass" CLASS="textInput" VALUE="<?php echo($adminPass); ?>"> 209 <INPUT TYPE="password" ID="adminPass" NAME="adminPass" CLASS="textInput" VALUE="<?php echo($adminPass); ?>">
333</DIV> 210</DIV>
334<DIV CLASS="ctrlHolder<?php ifErrors($errors, 'adminEmail'); ?>">
335<?php doErrors($errors, 'adminEmail'); ?> <LABEL FOR="adminEmail"><EM>*</EM> Admin Email: </LABEL>
336 <INPUT TYPE="text" ID="adminEmail" NAME="adminEmail" CLASS="textInput" VALUE="<?php echo($adminEmail); ?>">
337 <P CLASS="formHint">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.</P>
338</DIV>
339</FIELDSET> 211</FIELDSET>
340<DIV CLASS="buttonHolder"> 212<DIV CLASS="buttonHolder">
341 <INPUT TYPE="submit" VALUE="Next"> 213 <INPUT TYPE="submit" VALUE="Next">
@@ -344,7 +216,7 @@ function showStepTwo($mailDomain, $smtpHost, $smtpAuth, $smtpUser, $smtpPass, $s
344 216
345function showStepThree() 217function showStepThree()
346{ 218{
347?>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 <A HREF="http://fourisland.com/projects/instadisc/wiki/BecomingACentralServer">Becoming A Central Server</A>. 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!<P>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/BecomingACentralServer<?php 219?>Congradulations! You've successfully set up your InstaDisc Central Server's database!<?php
348} 220}
349 221
350function ifErrors($errors, $id) 222function ifErrors($errors, $id)