From 1f3ccdbb990204d5238c78f0990496011ccb9902 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 1 Aug 2008 19:05:03 +0000 Subject: Central: Added sendDatabase functions Completed the instaDisc_sendDatabase() library function and the InstaDisc.sendDatabase() XML-RPC function. --- central/trunk/instadisc.php | 22 ++++++++++++++++++++++ central/trunk/xmlrpc.php | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 3 deletions(-) (limited to 'central') diff --git a/central/trunk/instadisc.php b/central/trunk/instadisc.php index d32d2d7..9920e51 100644 --- a/central/trunk/instadisc.php +++ b/central/trunk/instadisc.php @@ -37,6 +37,28 @@ function instaDisc_sendUpdateNotice($softwareVersion) 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) diff --git a/central/trunk/xmlrpc.php b/central/trunk/xmlrpc.php index 68ff92d..c10002a 100644 --- a/central/trunk/xmlrpc.php +++ b/central/trunk/xmlrpc.php @@ -26,7 +26,7 @@ function deleteItem($username, $verification, $verificationID, $id) $getitem3 = mysql_fetch_array($getitem2); if ($getitem3['id'] == $id) { - $delitem = "DELETE inbox WHERE username = \"" . mysql_escape_string($username) . "\" AND itemID = " . $id; + $delitem = "DELETE FROM inbox WHERE username = \"" . mysql_escape_string($username) . "\" AND itemID = " . $id; $delitem2 = mysql_query($delitem); return new xmlrpcresp(new xmlrpcval(0, "int")); @@ -195,7 +195,7 @@ function deleteSubscription($username, $verification, $verificationID, $subscrip $getsub3 = mysql_fetch_array($getsub2); if ($getsub3['url'] == $subscription) { - $delsub = "DELETE subscriptions WHERE url = \"" . mysql_escape_string($subscription) . "\" AND username = \"" . mysql_escape_string($username . "\" AND owner = \"false\""; + $delsub = "DELETE FROM subscriptions WHERE url = \"" . mysql_escape_string($subscription) . "\" AND username = \"" . mysql_escape_string($username) . "\" AND owner = \"false\""; $delsub2 = mysql_query($delsub); return new xmlrpcresp(new xmlrpcval(0, "int")); @@ -218,6 +218,35 @@ function addSubscription($username, $verification, $verificationID, $subscriptio return new xmlrpcresp(new xmlrpcval(1, "int")); } +function sendDatabase($cserver, $verification, $verificationID, $db) +{ + if (instaDisc_checkVerification($cserver, $verification, $verificationID, 'centralServers', 'url', 'key')) + { + if (isset($db['central.fourisland.com'])) + { + $getfi = "SELECT * FROM centralServers WHERE url = \"central.fourisland.com\""; + $getfi2 = mysql_query($getfi); + $getfi3 = mysql_fetch_array($getfi2); + + if ($db['central.fourisland.com'] == $getfi3['key']) + { + $deldb = "TRUNCATE TABLE centralServers"; + $deldb2 = mysql_query($deldb); + + foreach($db as $name => $value) + { + $insdb = "INSERT INTO centralServers (url, key) VALUES (\"" . mysql_escape_string($name) . "\", \"" . mysql_escape_string($value) . "\")"; + $insdb2 = mysql_query($insdb); + } + + return new xmlrpcresp(new xmlrpcval("0", 'int')); + } + } + } + + return new xmlrpcresp(new xmlrpcval(1, "int")); +} + $s = new xmlrpc_server( array( "InstaDisc.checkRegistration" => array("function" => "checkRegistration"), "InstaDisc.deleteItem" => array("function" => "deleteItem"), "InstaDisc.resendItem" => array("function" => "resendItem"), @@ -227,7 +256,8 @@ $s = new xmlrpc_server( array( "InstaDisc.checkRegistration" => array("function" "InstaDisc.sendUpdateNotice" => array("function" => "sendUpdateNotice"), "InstaDisc.askForDatabase" => array("function" => "askForDatabase"), "InstaDisc.deleteSubscription" => array("function" => "deleteSubscription"), - "InstaDisc.addSubscription" => array("function" => "addSubscription") + "InstaDisc.addSubscription" => array("function" => "addSubscription"), + "InstaDisc.sendDatabase" => array("function" => "sendDatabase") ),0); $s->functions_parameters_type = 'phpvals'; $s->service(); -- cgit 1.4.1