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