= intval(getConfig('verIDBufferSize'))) { $delverid = "DELETE FROM oldVerID WHERE username = \"" . mysql_escape_string($username) . "\""; $delverid2 = mysql_query($delverid); } $insverid = "INSERT INTO oldVerID (name, verID) VALUES (\"" . mysql_escape_string($username) . "\", " . $verificationID . ")"; $insverid2 = mysql_query($insverid); return true; } } } return false; } function instaDisc_sendItem($username, $id) { $getitem = "SELECT * FROM inbox WHERE username = \"" . mysql_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_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 = 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']] = $getdb3[$i]['key']; $i++; } $cserver2 = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; $getuk = "SELECT * FROM centralServers WHERE url = \"" . mysql_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_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_escape_string($username) . "\""; $setuser2 = mysql_query($setuser); $insitem = "INSERT INTO inbox (username, itemID, subscription, title, author, url, semantics) VALUES (\"" . mysql_escape_string($username) . "\", " . $itemID . ", \"" . mysql_escape_string($subscription) . "\", \"" . mysql_escape_string($title) . "\", \"" . mysql_escape_string($author) . "\", \"" . mysql_escape_string($url) . "\", \"" . mysql_escape_string(serialize($semantics)) . "\")"; $insitem2 = mysql_query($insitem); instaDisc_sendItem($username, $itemID); } } function instaDisc_phpMailer() { $mail = new PHPMailer(); $mail->IsSMTP(); $mail->From = 'instadisc@' . getConfig('mailDomain'); $mail->FromName = 'InstaDisc'; $mail->Host = getConfig('smtpHost'); if (getConfig('smtpAuth') == 'true') { $mail->SMTPAuth = true; $mail->Username = getConfig('smtpUser'); $mail->Password = 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_escape_string($username) . "\", \"" . mysql_escape_string($password) . "\", \"" . mysql_escape_string($email) . "\", \"" . mysql_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_escape_string($username) . "\" AND key = \"" . mysql_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_escape_string($username) . "\", \"" . mysql_escape_string($password) . "\", \"" . mysql_escape_string($email) . "\")"; $insuser2 = mysql_query($insuser); $delpending = "DELETE FROM pending WHERE username = \"" . mysql_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 " . 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: " . getConfig("xmlrpcURL") . "\r\n\r\nOnce again, thank you for choosing " . getConfig("siteName") . "!"; return $mail->Send(); } else { return false; } } function instaDisc_deactivateAccount($username, $penKey) { $getuser = "SELECT * FROM pending WHERE username = \"" . mysql_escape_string($username) . "\" AND key = \"" . mysql_escape_string($penKey) . "\""; $getuser2 = mysql_query($getuser); $getuser3 = mysql_fetch_array($getuser2); if ($getuser3['username'] == $username) { $delpending = "DELETE FROM pending WHERE username = \"" . mysql_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_escape_string($username) . "\""; $getuser2 = mysql_query($getuser); $getuser3 = mysql_fetch_array($getuser2); if ($getuser3['username'] == $username) { $deluser = "DELETE FROM users WHERE username = \"" . mysql_escape_string($username) . "\""; $deluser2 = mysql_query($deluser); $delsubs = "DELETE FROM subscriptions WHERE username = \"" . mysql_escape_string($username) . "\""; $delsubs2 = mysql_query($delsubs); $delitems = "DELETE FROM inbox WHERE username = \"" . mysql_escape_string($username) . "\""; $delitems2 = mysql_query($delitems); return true; } return false; } ?>