about summary refs log tree commit diff stats
path: root/central/trunk/instadisc.php
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2008-08-15 15:02:00 +0000
committerKelly Rauchenberger <fefferburbia@gmail.com>2008-08-15 15:02:00 +0000
commitd7367564c1cda6bedc8316302f3f848b4d411aac (patch)
tree0b544f14973be1edf970d7910ddf6923f11c4d5b /central/trunk/instadisc.php
parent857ecf0581857ccf8d05209c5f77983f47ef3117 (diff)
downloadinstadisc-d7367564c1cda6bedc8316302f3f848b4d411aac.tar.gz
instadisc-d7367564c1cda6bedc8316302f3f848b4d411aac.tar.bz2
instadisc-d7367564c1cda6bedc8316302f3f848b4d411aac.zip
Central: Organized files
Refs #25
Diffstat (limited to 'central/trunk/instadisc.php')
-rw-r--r--central/trunk/instadisc.php400
1 files changed, 0 insertions, 400 deletions
diff --git a/central/trunk/instadisc.php b/central/trunk/instadisc.php deleted file mode 100644 index 1867757..0000000 --- a/central/trunk/instadisc.php +++ /dev/null
@@ -1,400 +0,0 @@
1<?php
2
3/* InstaDisc Server - A Four Island Project */
4
5include_once('db.php');
6include_once('class.phpmailer.php');
7
8function instaDisc_checkVerification($username, $verification, $verificationID, $table, $nameField, $passField)
9{
10 $getverid = "SELECT * FROM oldVerID WHERE username = \"" . mysql_real_escape_string($username) . "\" AND verID = " . $verificationID;
11 $getverid2 = mysql_query($getverid);
12 $getverid3 = mysql_fetch_array($getverid2);
13 if ($getverid3['id'] != $verificationID)
14 {
15 $getitem = "SELECT * FROM " . $table . " WHERE " . $nameField . " = \"" . mysql_real_escape_string($username) . "\"";
16 $getitem2 = mysql_query($getitem);
17 $getitem3 = mysql_fetch_array($getitem2);
18 if ($getitem3[$nameField] == $username)
19 {
20 $test = $username . ':' . $getitem3[$passField] . ':' . $verificationID;
21
22 if (md5($test) == $verification)
23 {
24 $cntverid = "SELECT COUNT(*) FROM oldVerID WHERE username = \"" . mysql_real_escape_string($username) . "\"";
25 $cntverid2 = mysql_query($cntverid);
26 $cntverid3 = mysql_fetch_array($cntverid2);
27 if ($cntverid3[0] >= intval(instaDisc_getConfig('verIDBufferSize')))
28 {
29 $delverid = "DELETE FROM oldVerID WHERE username = \"" . mysql_real_escape_string($username) . "\"";
30 $delverid2 = mysql_query($delverid);
31 }
32
33 $insverid = "INSERT INTO oldVerID (username, verID) VALUES (\"" . mysql_real_escape_string($username) . "\", " . $verificationID . ")";
34 $insverid2 = mysql_query($insverid);
35
36 if (($table == 'users') && ($getitem3['ip'] != $_SERVER['REMOTE_ADDR']))
37 {
38 $setuser = "UPDATE users SET ip = \"" . $_SERVER['REMOTE_ADDR'] . "\" WHERE id = " . $getitem3['id'];
39 $setuser2 = mysql_query($setuser);
40 }
41
42 return true;
43 }
44 }
45 }
46
47 return false;
48}
49
50function instaDisc_sendItem($username, $id)
51{
52 $getitem = "SELECT * FROM inbox WHERE username = \"" . mysql_real_escape_string($username) . "\" AND itemID = " . $id;
53 $getitem2 = mysql_query($getitem);
54 $getitem3 = mysql_fetch_array($getitem2);
55 if ($getitem3['username'] == $username)
56 {
57 $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\"";
58 $getuser2 = mysql_query($getuser);
59 $getuser3 = mysql_fetch_array($getuser2);
60
61 $fp = @fsockopen($getuser3['ip'], 1204, $errno, $errstr);
62 if ($fp)
63 {
64 $verID = rand(1,65536);
65
66 $title = str_replace(': ', '__INSTADISC__', $getitem3['title']);
67
68 $out = 'ID: ' . $id . "\r\n";
69 $out .= 'Verification: ' . md5($username . ':' . $getuser3['password'] . ':' . $verID) . "\r\n";
70 $out .= 'Verification-ID: ' . $verID . "\r\n";
71 $out .= 'Subscription: ' . $getitem3['subscription'] . "\r\n";
72 $out .= 'Title: ' . $title . "\r\n";
73 $out .= 'Author: ' . $getitem3['author'] . "\r\n";
74 $out .= 'URL: ' . $getitem3['url'] . "\r\n";
75
76 $semantics = unserialize($getitem3['semantics']);
77 foreach ($semantics as $name => $value)
78 {
79 $value = str_replace(': ', '__INSTADISC__', $value);
80 $out .= $name . ': ' . $value . "\r\n";
81 }
82
83 if ($getitem3['encryptionID'] != 0)
84 {
85 $out .= 'Encryption-ID: ' . $getitem3['encryptionID'] . "\r\n";
86 }
87
88 $out .= "\r\n\r\n";
89
90 fwrite($fp, $out);
91 fclose($fp);
92
93 return true;
94 } else {
95 return false;
96 }
97 }
98}
99
100function instaDisc_sendUpdateNotice($softwareVersion)
101{
102 $username = instaDisc_getConfig('owner');
103 $subscription = 'http://fourisland.com/' . $_SERVER['SERVER_NAME'] . '/';
104 $title = 'Update your software to ' . $software;
105 $author = 'Hatkirby';
106 $url = 'http://fourisland.com/projects/instadisc/wiki/CentralSoftwareUpdate';
107 $semantics = array();
108
109 instaDisc_addItem($username, $subscription, $title, $author, $url, $semantics);
110}
111
112function instaDisc_sendDatabase($cserver)
113{
114 $getdb = "SELECT * FROM centralServers";
115 $getdb2 = mysql_query($getdb);
116 $i=0;
117 while ($getdb3[$i] = mysql_fetch_array($getdb2))
118 {
119 $db[$getdb3[$i]['url']]['code'] = $getdb3[$i]['code'];
120 $db[$getdb3[$i]['url']]['xmlrpc'] = $getdb3[$i]['xmlrpc'];
121 $i++;
122 }
123
124 $cserver2 = $_SERVER['HTTP_HOST'];
125 $getuk = "SELECT * FROM centralServers WHERE url = \"" . mysql_real_escape_string($cserver2) . "\"";
126 $getuk2 = mysql_query($getuk);
127 $getuk3 = mysql_fetch_array($getuk2);
128
129 $verID = rand(1,65536);
130
131 $client = new xmlrpc_client($cserver);
132 $msg = new xmlrpcmsg("InstaDisc.sendDatabase", array( new xmlrpcval($cserver2, 'string'),
133 new xmlrpcval(md5($cserver2 . ":" . $getuk3['code'] . ":" . $verID), 'string'),
134 new xmlrpcval($verID, 'int'),
135 new xmlrpcval(serialize($db), 'string'),
136 new xmlrpcval(instaDisc_getConfig('databaseVersion'), 'string')));
137 $client->send($msg);
138}
139
140function instaDisc_addItem($username, $subscription, $title, $author, $url, $semantics, $encryptionID)
141{
142 $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\"";
143 $getuser2 = mysql_query($getuser);
144 $getuser3 = mysql_fetch_array($getuser2);
145 if ($getuser3['username'] == $username)
146 {
147 $itemID = $getuser3['nextItemID'];
148 $setuser = "UPDATE users SET nextItemID = nextItemID+1 WHERE username = \"" . mysql_real_escape_string($username) . "\"";
149 $setuser2 = mysql_query($setuser);
150
151 $insitem = "INSERT INTO inbox (username, itemID, subscription, title, author, url, semantics, encryptionID) VALUES (\"" . mysql_real_escape_string($username) . "\", " . $itemID . ", \"" . mysql_real_escape_string($subscription) . "\", \"" . mysql_real_escape_string($title) . "\", \"" . mysql_real_escape_string($author) . "\", \"" . mysql_real_escape_string($url) . "\", \"" . mysql_real_escape_string($semantics) . "\"," . $encryptionID . ")";
152 $insitem2 = mysql_query($insitem);
153
154 instaDisc_sendItem($username, $itemID);
155 }
156}
157
158function instaDisc_phpMailer()
159{
160 $mail = new PHPMailer();
161 $mail->IsSMTP();
162 $mail->From = 'instadisc@' . instaDisc_getConfig('mailDomain');
163 $mail->FromName = 'InstaDisc';
164 $mail->Host = instaDisc_getConfig('smtpHost');
165 if (instaDisc_getConfig('smtpAuth') == 'true')
166 {
167 $mail->SMTPAuth = true;
168 $mail->Username = instaDisc_getConfig('smtpUser');
169 $mail->Password = instaDisc_getConfig('smtpPass');
170 }
171 $mail->Helo = $_SERVER['SERVER_NAME'];
172 $mail->ClearAddresses();
173
174 return $mail;
175}
176
177function instaDisc_sendActivationEmail($username, $password, $email)
178{
179 $penKey = md5(rand(1,65536));
180
181 $inspending = "INSERT INTO pending (username, password, email, code) VALUES (\"" . mysql_real_escape_string($username) . "\", \"" . mysql_real_escape_string(md5($password)) . "\", \"" . mysql_real_escape_string($email) . "\", \"" . mysql_real_escape_string($penKey) . "\")";
182 $inspending2 = mysql_query($inspending);
183
184 $mail = instaDisc_phpMailer();
185 $mail->AddAddress($email, $username);
186 $mail->Subject = 'InstaDisc Account Verification';
187 $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.";
188 $mail->Send();
189
190 return ($mail->IsError() ? $mail->ErrorInfo : true);
191}
192
193function instaDisc_activateAccount($username, $penKey)
194{
195 $getuser = "SELECT * FROM pending WHERE username = \"" . mysql_real_escape_string($username) . "\" AND code = \"" . mysql_real_escape_string($penKey) . "\"";
196 $getuser2 = mysql_query($getuser);
197 $getuser3 = mysql_fetch_array($getuser2);
198 if ($getuser3['username'] == $username)
199 {
200 $insuser = "INSERT INTO users (username, password, email) VALUES (\"" . mysql_real_escape_string($username) . "\", \"" . mysql_real_escape_string($getuser3['password']) . "\", \"" . mysql_real_escape_string($getuser3['email']) . "\")";
201 $insuser2 = mysql_query($insuser);
202
203 $delpending = "DELETE FROM pending WHERE username = \"" . mysql_real_escape_string($username) . "\"";
204 $delpending2 = mysql_query($delpending);
205
206 $mail = instaDisc_phpMailer();
207 $mail->AddAddress($getuser3['email'], $username);
208 $mail->Subject = 'Welcome to InstaDisc!';
209 $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") . "!";
210 $mail->Send();
211
212 return ($mail->IsError() ? $mail->ErrorInfo : true);
213 } else {
214 return false;
215 }
216}
217
218function instaDisc_deactivateAccount($username, $penKey)
219{
220 $getuser = "SELECT * FROM pending WHERE username = \"" . mysql_real_escape_string($username) . "\" AND code = \"" . mysql_real_escape_string($penKey) . "\"";
221 $getuser2 = mysql_query($getuser);
222 $getuser3 = mysql_fetch_array($getuser2);
223 if ($getuser3['username'] == $username)
224 {
225 $delpending = "DELETE FROM pending WHERE username = \"" . mysql_real_escape_string($username) . "\"";
226 $delpending2 = mysql_query($delpending);
227
228 return true;
229 } else {
230 return false;
231 }
232}
233
234function instaDisc_verifyUser($username, $password)
235{
236 return instaDisc_checkVerification($username, md5($username . ':' . md5($password) . ':0'), 0, 'users', 'username', 'password');
237}
238
239function instaDisc_deleteAccount($username)
240{
241 $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\"";
242 $getuser2 = mysql_query($getuser);
243 $getuser3 = mysql_fetch_array($getuser2);
244 if ($getuser3['username'] == $username)
245 {
246 $deluser = "DELETE FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\"";
247 $deluser2 = mysql_query($deluser);
248
249 $delsubs = "DELETE FROM subscriptions WHERE username = \"" . mysql_real_escape_string($username) . "\"";
250 $delsubs2 = mysql_query($delsubs);
251
252 $delitems = "DELETE FROM inbox WHERE username = \"" . mysql_real_escape_string($username) . "\"";
253 $delitems2 = mysql_query($delitems);
254
255 return true;
256 }
257
258 return false;
259}
260
261function instaDisc_getConfig($key)
262{
263 $getconfig = "SELECT * FROM config WHERE name = \"" . mysql_real_escape_string($key) . "\"";
264 $getconfig2 = mysql_query($getconfig);
265 $getconfig3 = mysql_fetch_array($getconfig2);
266
267 return $getconfig3['value'];
268}
269
270function instaDisc_listSubscriptions($username)
271{
272 $getsubs = "SELECT * FROM subscriptions WHERE username = \"" . mysql_real_escape_string($username) . "\" AND owner = \"true\"";
273 $getsubs2 = mysql_query($getsubs);
274 $i=0;
275 while ($getsubs3[$i] = mysql_fetch_array($getsubs2))
276 {
277 $subs[$i] = $getsubs3[$i]['url'];
278
279 $i++;
280 }
281
282 $subs['size'] = $i;
283 return $subs;
284}
285
286function instaDisc_addSubscription($username, $url)
287{
288 $getcode = "SELECT * FROM pending2 WHERE username = \"" . mysql_real_escape_string($username) . "\" AND url = \"" . mysql_real_escape_string($url) . "\"";
289 $getcode2 = mysql_query($getcode);
290 $getcode3 = mysql_fetch_array($getcode2);
291 if ($getcode3['username'] == $username)
292 {
293 $delcode = "DELETE FROM pending2 WHERE username = \"" . mysql_real_escape_string($username) . "\" AND url = \"" . mysql_real_escape_string($url) . "\"";
294 $delcode2 = mysql_query($delcode);
295
296 $c = curl_init();
297 curl_setopt($c, CURLOPT_URL, $url);
298 curl_setopt($c, CURLOPT_HEADER, false);
299 curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
300 $page_data = curl_exec($c);
301 curl_close($c);
302
303 $headers = split("\n", $page_date);
304 foreach ($headers as $name => $value)
305 {
306 $header = split(": ", $value);
307 $headerMap[$header[0]] = $header[1];
308 }
309
310 if (isset($header['Subscription']))
311 {
312 if (isset($header['Title']))
313 {
314 if (isset($header['Category']))
315 {
316 if (isset($header['Key']))
317 {
318 if ($header['Key'] == $getcode3['code'])
319 {
320 $inssub = "INSERT INTO subscriptions (username,url,owner,category) VALUES (\"" . mysql_real_escape_string($username) . "\", \"" . mysql_real_escape_string($header['Subscription']) . "\", \"true\", \"" . mysql_real_escape_string($header['Category']) . "\")";
321 $inssub2 = mysql_query($inssub);
322
323 return true;
324 }
325 }
326 }
327 }
328 }
329 }
330
331 return false;
332}
333
334function instaDisc_listPendingSubscriptions($username)
335{
336 $getsubs = "SELECT * FROM pending2 WHERE username = \"" . mysql_real_escape_string($username) . "\"";
337 $getsubs2 = mysql_query($getsubs);
338 $i=0;
339 while ($getsubs3[$i] = mysql_fetch_array($getsubs2))
340 {
341 $subs[$i] = array('url' => $getsubs3[$i]['url'], 'code' => $getsubs3[$i]['code']);
342
343 $i++;
344 }
345
346 $subs['size'] = $i;
347 return $subs;
348}
349
350function instaDisc_generateSubscriptionActivation($username, $url)
351{
352 $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\"";
353 $getuser2 = mysql_query($getuser);
354 $getuser3 = mysql_fetch_array($getuser2);
355 if ($getuser3['username'] == $username)
356 {
357 $key = md5(rand(1,65536));
358
359 $inspending = "INSERT INTO pending2 (username, url, code) VALUES (\"" . mysql_real_escape_string($username) . "\", \"" . mysql_real_escape_string($url) . "\", \"" . mysql_real_escape_string($key) . "\")";
360 $inspending2 = mysql_query($inspending);
361
362 return $key;
363 }
364
365 return false;
366}
367
368function instaDisc_deleteSubscription($username, $url)
369{
370 $getsub = "SELECT * FROM subscriptions WHERE username = \"" . mysql_real_escape_string($username) . "\" AND url = \"" . mysql_real_escape_string($url) . "\")";
371 $getsub2 = mysql_query($getsub);
372 $getsub3 = mysql_fetch_array($getsub2);
373 if ($getsub3['username'] == $username)
374 {
375 $delsub = "DELETE FROM subscriptions WHERE username = \"" . mysql_real_escape_string($username) . "\" AND url = \"" . mysql_real_escape_string($url) . "\")";
376 $delsub2 = mysql_query($delsub);
377
378 return true;
379 }
380
381 return false;
382}
383
384function instaDisc_cancelSubscription($username, $url)
385{
386 $getsub = "SELECT * FROM pending2 WHERE username = \"" . mysql_real_escape_string($username) . "\" AND url = \"" . mysql_real_escape_string($url) . "\")";
387 $getsub2 = mysql_query($getsub);
388 $getsub3 = mysql_fetch_array($getsub2);
389 if ($getsub3['username'] == $username)
390 {
391 $delsub = "DELETE FROM pending2 WHERE username = \"" . mysql_real_escape_string($username) . "\" AND url = \"" . mysql_real_escape_string($url) . "\")";
392 $delsub2 = mysql_query($delsub);
393
394 return true;
395 }
396
397 return false;
398}
399
400?>