(@link http://blog.griffin.homelinux.org/projects/xmlrpc/)
1061 | * @version 0.2.0 26May2005 08:34 +0800
1062 | * @copyright (c) 2004-2005 Jason Stirk
1063 | * @package IXR
1064 | */
1065 | class IXR_ClientSSL extends IXR_Client
1066 | {
1067 | /**
1068 | * Filename of the SSL Client Certificate
1069 | * @access private
1070 | * @since 0.1.0
1071 | * @var string
1072 | */
1073 | var $_certFile;
1074 |
1075 | /**
1076 | * Filename of the SSL CA Certificate
1077 | * @access private
1078 | * @since 0.1.0
1079 | * @var string
1080 | */
1081 | var $_caFile;
1082 |
1083 | /**
1084 | * Filename of the SSL Client Private Key
1085 | * @access private
1086 | * @since 0.1.0
1087 | * @var string
1088 | */
1089 | var $_keyFile;
1090 |
1091 | /**
1092 | * Passphrase to unlock the private key
1093 | * @access private
1094 | * @since 0.1.0
1095 | * @var string
1096 | */
1097 | var $_passphrase;
1098 |
1099 | /**
1100 | * Constructor
1101 | * @param string $server URL of the Server to connect to
1102 | * @since 0.1.0
1103 | */
1104 | function IXR_ClientSSL($server, $path = false, $port = 443, $timeout = false)
1105 | {
1106 | parent::IXR_Client($server, $path, $port, $timeout);
1107 | $this->useragent = 'The Incutio XML-RPC PHP Library for SSL';
1108 |
1109 | // Set class fields
1110 | $this->_certFile=false;
1111 | $this->_caFile=false;
1112 | $this->_keyFile=false;
1113 | $this->_passphrase='';
1114 | }
1115 |
1116 | /**
1117 | * Set the client side certificates to communicate with the server.
1118 | *
1119 | * @since 0.1.0
1120 | * @param string $certificateFile Filename of the client side certificate to use
1121 | * @param string $keyFile Filename of the client side certificate's private key
1122 | * @param string $keyPhrase Passphrase to unlock the private key
1123 | */
1124 | function setCertificate($certificateFile, $keyFile, $keyPhrase='')
1125 | {
1126 | // Check the files all exist
1127 | if (is_file($certificateFile)) {
1128 | $this->_certFile = $certificateFile;
1129 | } else {
1130 | die('Could not open certificate: ' . $certificateFile);
1131 | }
1132 |
1133 | if (is_file($keyFile)) {
1134 | $this->_keyFile = $keyFile;
1135 | } else {
1136 | die('Could not open private key: ' . $keyFile);
1137 | }
1138 |
1139 | $this->_passphrase=(string)$keyPhrase;
1140 | }
1141 |
1142 | function setCACertificate($caFile)
1143 | {
1144 | if (is_file($caFile)) {
1145 | $this->_caFile = $caFile;
1146 | } else {
1147 | die('Could not open CA certificate: ' . $caFile);
1148 | }
1149 | }
1150 |
1151 | /**
1152 | * Sets the connection timeout (in seconds)
1153 | * @param int $newTimeOut Timeout in seconds
1154 | * @returns void
1155 | * @since 0.1.2
1156 | */
1157 | function setTimeOut($newTimeOut)
1158 | {
1159 | $this->timeout = (int)$newTimeOut;
1160 | }
1161 |
1162 | /**
1163 | * Returns the connection timeout (in seconds)
1164 | * @returns int
1165 | * @since 0.1.2
1166 | */
1167 | function getTimeOut()
1168 | {
1169 | return $this->timeout;
1170 | }
1171 |
1172 | /**
1173 | * Set the query to send to the XML-RPC Server
1174 | * @since 0.1.0
1175 | */
1176 | function query()
1177 | {
1178 | $args = func_get_args();
1179 | $method = array_shift($args);
1180 | $request = new IXR_Request($method, $args);
1181 | $length = $request->getLength();
1182 | $xml = $request->getXml();
1183 |
1184 | if ($this->debug) {
1185 | echo ''.htmlspecialchars($xml)."\n
\n\n";
1186 | }
1187 |
1188 | //This is where we deviate from the normal query()
1189 | //Rather than open a normal sock, we will actually use the cURL
1190 | //extensions to make the calls, and handle the SSL stuff.
1191 |
1192 | //Since 04Aug2004 (0.1.3) - Need to include the port (duh...)
1193 | //Since 06Oct2004 (0.1.4) - Need to include the colon!!!
1194 | // (I swear I've fixed this before... ESP in live... But anyhu...)
1195 | $curl=curl_init('https://' . $this->server . ':' . $this->port . $this->path);
1196 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
1197 |
1198 | //Since 23Jun2004 (0.1.2) - Made timeout a class field
1199 | curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
1200 |
1201 | if ($this->debug) {
1202 | curl_setopt($curl, CURLOPT_VERBOSE, 1);
1203 | }
1204 |
1205 | curl_setopt($curl, CURLOPT_HEADER, 1);
1206 | curl_setopt($curl, CURLOPT_POST, 1);
1207 | curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
1208 | curl_setopt($curl, CURLOPT_PORT, $this->port);
1209 | curl_setopt($curl, CURLOPT_HTTPHEADER, array(
1210 | "Content-Type: text/xml",
1211 | "Content-length: {$length}"));
1212 |
1213 | // Process the SSL certificates, etc. to use
1214 | if (!($this->_certFile === false)) {
1215 | // We have a certificate file set, so add these to the cURL handler
1216 | curl_setopt($curl, CURLOPT_SSLCERT, $this->_certFile);
1217 | curl_setopt($curl, CURLOPT_SSLKEY, $this->_keyFile);
1218 |
1219 | if ($this->debug) {
1220 | echo "SSL Cert at : " . $this->_certFile . "\n";
1221 | echo "SSL Key at : " . $this->_keyFile . "\n";
1222 | }
1223 |
1224 | // See if we need to give a passphrase
1225 | if (!($this->_passphrase === '')) {
1226 | curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $this->_passphrase);
1227 | }
1228 |
1229 | if ($this->_caFile === false) {
1230 | // Don't verify their certificate, as we don't have a CA to verify against
1231 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
1232 | } else {
1233 | // Verify against a CA
1234 | curl_setopt($curl, CURLOPT_CAINFO, $this->_caFile);
1235 | }
1236 | }
1237 |
1238 | // Call cURL to do it's stuff and return us the content
1239 | $contents = curl_exec($curl);
1240 | curl_close($curl);
1241 |
1242 | // Check for 200 Code in $contents
1243 | if (!strstr($contents, '200 OK')) {
1244 | //There was no "200 OK" returned - we failed
1245 | $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
1246 | return false;
1247 | }
1248 |
1249 | if ($this->debug) {
1250 | echo ''.htmlspecialchars($contents)."\n
\n\n";
1251 | }
1252 | // Now parse what we've got back
1253 | // Since 20Jun2004 (0.1.1) - We need to remove the headers first
1254 | // Why I have only just found this, I will never know...
1255 | // So, remove everything before the first <
1256 | $contents = substr($contents,strpos($contents, '<'));
1257 |
1258 | $this->message = new IXR_Message($contents);
1259 | if (!$this->message->parse()) {
1260 | // XML error
1261 | $this->error = new IXR_Error(-32700, 'parse error. not well formed');
1262 | return false;
1263 | }
1264 | // Is the message a fault?
1265 | if ($this->message->messageType == 'fault') {
1266 | $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
1267 | return false;
1268 | }
1269 |
1270 | // Message must be OK
1271 | return true;
1272 | }
1273 | }
1274 |
1275 | /**
1276 | * Extension of the {@link IXR_Server} class to easily wrap objects.
1277 | *
1278 | * Class is designed to extend the existing XML-RPC server to allow the
1279 | * presentation of methods from a variety of different objects via an
1280 | * XML-RPC server.
1281 | * It is intended to assist in organization of your XML-RPC methods by allowing
1282 | * you to "write once" in your existing model classes and present them.
1283 | *
1284 | * @author Jason Stirk
1285 | * @version 1.0.1 19Apr2005 17:40 +0800
1286 | * @copyright Copyright (c) 2005 Jason Stirk
1287 | * @package IXR
1288 | */
1289 | class IXR_ClassServer extends IXR_Server
1290 | {
1291 | var $_objects;
1292 | var $_delim;
1293 |
1294 | function IXR_ClassServer($delim = '.', $wait = false)
1295 | {
1296 | $this->IXR_Server(array(), false, $wait);
1297 | $this->_delimiter = $delim;
1298 | $this->_objects = array();
1299 | }
1300 |
1301 | function addMethod($rpcName, $functionName)
1302 | {
1303 | $this->callbacks[$rpcName] = $functionName;
1304 | }
1305 |
1306 | function registerObject($object, $methods, $prefix=null)
1307 | {
1308 | if (is_null($prefix))
1309 | {
1310 | $prefix = get_class($object);
1311 | }
1312 | $this->_objects[$prefix] = $object;
1313 |
1314 | // Add to our callbacks array
1315 | foreach($methods as $method)
1316 | {
1317 | if (is_array($method))
1318 | {
1319 | $targetMethod = $method[0];
1320 | $method = $method[1];
1321 | }
1322 | else
1323 | {
1324 | $targetMethod = $method;
1325 | }
1326 | $this->callbacks[$prefix . $this->_delimiter . $method]=array($prefix, $targetMethod);
1327 | }
1328 | }
1329 |
1330 | function call($methodname, $args)
1331 | {
1332 | if (!$this->hasMethod($methodname)) {
1333 | return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
1334 | }
1335 | $method = $this->callbacks[$methodname];
1336 |
1337 | // Perform the callback and send the response
1338 | if (count($args) == 1) {
1339 | // If only one paramater just send that instead of the whole array
1340 | $args = $args[0];
1341 | }
1342 |
1343 | // See if this method comes from one of our objects or maybe self
1344 | if (is_array($method) || (substr($method, 0, 5) == 'this:')) {
1345 | if (is_array($method)) {
1346 | $object=$this->_objects[$method[0]];
1347 | $method=$method[1];
1348 | } else {
1349 | $object=$this;
1350 | $method = substr($method, 5);
1351 | }
1352 |
1353 | // It's a class method - check it exists
1354 | if (!method_exists($object, $method)) {
1355 | return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
1356 | }
1357 |
1358 | // Call the method
1359 | $result = $object->$method($args);
1360 | } else {
1361 | // It's a function - does it exist?
1362 | if (!function_exists($method)) {
1363 | return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
1364 | }
1365 |
1366 | // Call the function
1367 | $result = $method($args);
1368 | }
1369 | return $result;
1370 | }
1371 | }
1372 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | PHP XML-RPC URL Ping
2 | ====================
3 |
4 | XML-RPC based Ping tool.
5 |
6 | More details coming soon!
--------------------------------------------------------------------------------
/ping.php:
--------------------------------------------------------------------------------
1 | timeout = 3;
97 | $client->useragent .= ' -- PingTool/1.0.0';
98 | $client->debug = false;
99 |
100 | if( $client->query( 'weblogUpdates.extendedPing', $myBlogName, $myBlogUrl, $myBlogUpdateUrl, $myBlogRSSFeedUrl ) )
101 | {
102 | return $client->getResponse();
103 | }
104 |
105 | echo 'Failed extended XML-RPC ping for "' . $url . '": ' . $client->getErrorCode() . '->' . $client->getErrorMessage() . '
';
106 |
107 | if( $client->query( 'weblogUpdates.ping', $myBlogName, $myBlogUrl ) )
108 | {
109 | return $client->getResponse();
110 | }
111 |
112 | echo 'Failed basic XML-RPC ping for "' . $url . '": ' . $client->getErrorCode() . '->' . $client->getErrorMessage() . '
';
113 |
114 | return false;
115 | }
116 |
117 | foreach( $xmlRpcPingUrls as $url )
118 | {
119 | echo 'XML-RPC pinging ' . $url . '
';
120 | echo '';
121 | print_r( xmlRpcPing( $url ) );
122 | echo '
';
123 | ob_flush();
124 | flush();
125 | }
--------------------------------------------------------------------------------