Exemplo n.º 1
0
 /**
  * The function that actually sends an XML-RPC request to the server, handles
  * errors accordingly and returns the appropriately decoded data sent as response
  * from the server.
  *
  * @param XML_RPC_Message $request An appropriately encoded XML-RPC message
  *                                  that needs to be sent as a request to the
  *                                  server.
  * @param XML_RPC_Client  $client  The XML-RPC client as which the request
  *                                  is to be sent.
  *
  * @return Array The appropriately decoded response sent by the server.
  */
 public static function sendRequest($request, $client)
 {
     $response = $client->send($request);
     if (!$response) {
         throw new Services_Blogging_Exception('XML-RPC communication error: ' . $client->errstr);
     } else {
         if ($response->faultCode() != 0) {
             throw new Services_Blogging_Exception($response->faultString(), $response->faultCode());
         }
     }
     $value = XML_RPC_Decode($response->value());
     if (!is_array($value) || !isset($value['faultCode'])) {
         return $value;
     } else {
         throw new Services_Blogging_Exception($value['faultString'], $value['faultCode']);
     }
 }
Exemplo n.º 2
0
 /**
  * Connect to OpenX Sync to check for updates
  *
  * @param float $already_seen Only check for updates newer than this value.
  * @return array An array of two items:
  *
  *               Item 0 is the XML-RPC error code. Meanings:
  *                      -2  => The admin user has disabled update checking
  *                      -1  => No response from the server
  *                  0 - 799 => XML-RPC library error codes
  *                       0  => No error
  *                     800  => No updates
  *                     801+ => Error codes from the remote XML-RPC server
  *
  *               Item 1 is either the error message (item 1 != 0), or an array containing update info
  */
 function checkForUpdates($already_seen = 0)
 {
     global $XML_RPC_erruser;
     if (!$this->aConf['sync']['checkForUpdates']) {
         // Checking for updates has been disabled by the admin user,
         // so do not communicate with the server that provides the
         // details of what upgrades are available - just return an
         // 800 "error"
         $aReturn = array(-2, 'Check for updates has been disabled by the administrator.');
         return $aReturn;
     }
     // Create the XML-RPC client object
     $client = OA_Central::getXmlRpcClient($this->_conf);
     // Prepare the installation's platform hash
     $platform_hash = OA_Dal_ApplicationVariables::get('platform_hash');
     if (!$platform_hash) {
         // The installation does not have a platform hash; generate one,
         // and save it to the database for later use
         OA::debug("Generating a new platform_hash for the installation", PEAR_LOG_INFO);
         $platform_hash = OA_Dal_ApplicationVariables::generatePlatformHash();
         if (!OA_Dal_ApplicationVariables::set('platform_hash', $platform_hash)) {
             OA::debug("Could not save the new platform_hash to the database", PEAR_LOG_ERR);
             unset($platform_hash);
             OA::debug("Sync process proceeding without a platform_hash", PEAR_LOG_INFO);
         }
     }
     // Prepare the parameters required for the XML-RPC call to
     // obtain if an update is available for this installation
     $params = array(new XML_RPC_Value(PRODUCT_NAME, 'string'), new XML_RPC_Value($this->getConfigVersion(OA_Dal_ApplicationVariables::get('oa_version')), 'string'), new XML_RPC_Value($already_seen, 'string'), new XML_RPC_Value($platform_hash, 'string'));
     // Has the Revive Adserver admin user kindly agreed to share the
     // technology stack that it is running on, to help the community?
     $aTechStack = array('data' => false);
     if ($this->aConf['sync']['shareStack']) {
         // Thanks, admin user! You're a star! Prepare the technology stack
         // data and add it to the XML-RPC call
         if ($this->oDbh->dbsyntax == 'mysql') {
             $dbms = 'MySQL';
         } else {
             if ($this->oDbh->dbsyntax == 'pgsql') {
                 $dbms = 'PostgreSQL';
             } else {
                 $dbms = 'UnknownSQL';
             }
         }
         $aTechStack = array('os_type' => php_uname('s'), 'os_version' => php_uname('r'), 'webserver_type' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^(.*?)/.*$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'webserver_version' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^.*?/(.*?)(?: .*)?$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'db_type' => $dbms, 'db_version' => $this->oDbh->queryOne("SELECT VERSION()"), 'php_version' => phpversion(), 'php_sapi' => ucfirst(php_sapi_name()), 'php_extensions' => get_loaded_extensions(), 'php_register_globals' => (bool) ini_get('register_globals'), 'php_magic_quotes_gpc' => (bool) ini_get('magic_quotes_gpc'), 'php_safe_mode' => (bool) ini_get('safe_mode'), 'php_open_basedir' => (bool) strlen(ini_get('open_basedir')), 'php_upload_tmp_readable' => (bool) is_readable(ini_get('upload_tmp_dir') . DIRECTORY_SEPARATOR));
     }
     $params[] = XML_RPC_Encode($aTechStack);
     // Add the registered email address
     $params[] = new XML_RPC_Value(OA_Dal_ApplicationVariables::get('sync_registered_email'), 'string');
     // Create the XML-RPC request message
     $msg = new XML_RPC_Message("Revive.Sync", $params);
     // Send the XML-RPC request message
     if ($response = $client->send($msg, 10)) {
         // XML-RPC server found, now checking for errors
         if (!$response->faultCode()) {
             // No fault! Woo! Get the response and return it!
             $aReturn = array(0, XML_RPC_Decode($response->value()));
             // Prepare cache
             $cache = $aReturn[1];
             // Update last run
             OA_Dal_ApplicationVariables::set('sync_last_run', date('Y-m-d H:i:s'));
             // Also write to the debug log
             OA::debug("Sync: updates found!", PEAR_LOG_INFO);
         } else {
             // Boo! An error! (Well, maybe - if it's 800, yay!)
             $aReturn = array($response->faultCode(), $response->faultString());
             // Prepare cache
             $cache = false;
             // Update last run
             if ($response->faultCode() == 800) {
                 // Update last run
                 OA_Dal_ApplicationVariables::set('sync_last_run', date('Y-m-d H:i:s'));
                 // Also write to the debug log
                 OA::debug("Sync: {$aReturn[1]}", PEAR_LOG_INFO);
             } else {
                 // Write to the debug log
                 OA::debug("Sync: {$aReturn[1]} (code: {$aReturn[0]}", PEAR_LOG_ERR);
                 // Return immediately without writing to cache
                 return $aReturn;
             }
         }
         OA_Dal_ApplicationVariables::set('sync_cache', serialize($cache));
         OA_Dal_ApplicationVariables::set('sync_timestamp', time());
         return $aReturn;
     }
     $aReturn = array(-1, 'No response from the remote XML-RPC server.');
     // Also write to the debug log
     OA::debug("Sync: {$aReturn[1]}", PEAR_LOG_ERR);
     return $aReturn;
 }
     $error = "A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} (pfsense.exec_php).";
     log_error($error);
     file_notice("CaptivePortalVoucherSync", $error, "Communications error occurred", "");
     $input_errors[] = $error;
 } elseif ($resp->faultCode()) {
     $cli->setDebug(1);
     $resp = $cli->send($msg, "250");
     $error = "An error code was received while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
     log_error($error);
     file_notice("CaptivePortalVoucherSync", $error, "Error code received", "");
     $input_errors[] = $error;
 } else {
     log_error("The Captive Portal voucher database has been synchronized with {$url}:{$port} (pfsense.exec_php).");
 }
 if (!$input_errors) {
     $toreturn = XML_RPC_Decode($resp->value());
     if (!is_array($toreturn)) {
         if ($toreturn == "Authentication failed") {
             $input_errors[] = "Could not synchronize the voucher database: Authentication Failed.";
         }
     } else {
         // If we received back the voucher roll and other information then store it.
         if ($toreturn['voucher']['roll']) {
             $newvoucher['roll'] = $toreturn['voucher']['roll'];
         }
         if ($toreturn['voucher']['rollbits']) {
             $newvoucher['rollbits'] = $toreturn['voucher']['rollbits'];
         }
         if ($toreturn['voucher']['ticketbits']) {
             $newvoucher['ticketbits'] = $toreturn['voucher']['ticketbits'];
         }
Exemplo n.º 4
0
/**
 * A function to handle XML-RPC advertisement view requests. 2.0 version
 *
 * @deprecated
 *
 * @param XML_RPC_Message $params
 * @return XML_RPC_Response
 */
function OA_Delivery_XmlRpc_View_PAN($params)
{
    // Extract the remote_info parameter
    $remoteInfoXmlRpcValue = $params->getParam(0);
    $remote_info = XML_RPC_Decode($params->getParam(0));
    // Add empty cookies array
    $remote_info['cookies'] = array();
    // Create environment array
    $remoteInfoXmlRpcValue = XML_RPC_encode($remote_info);
    // Extract the context param
    if ($params->getNumParams() > 6) {
        $contextXmlRpcValue = $params->getParam(6);
    } else {
        $contextXmlRpcValue = new XML_RPC_Value(array(), $XML_RPC_Array);
    }
    // Recreate XML-RPC message
    $msg = new XML_RPC_Message('phpAds.view', array($remoteInfoXmlRpcValue, $params->getParam(1), $params->getParam(2), $params->getParam(3), $params->getParam(4), $params->getParam(5), $contextXmlRpcValue));
    // Relay call to openads.view
    $xmlResponse = OA_Delivery_XmlRpc_View($msg);
    // Check for errors as-is
    return $xmlResponse;
}
Exemplo n.º 5
0
 function call($url = "", $function = "", $arguments = array())
 {
     $arguments = XMLRPC::array_encode($arguments);
     $myResult = XMLRPC::call_raw($url, $function, $arguments);
     if (!$myResult) {
         $result = "XMLRPC::Error ErrNo: " . $myClient->errno . " ErrStr: " . $myClient->errstr;
     } else {
         if ($myResult->faultCode()) {
             $result = "XMLRPC::ResultError Code: " . $myResult->faultCode() . " Reason: " . $myResult->faultString();
         } else {
             // We have a valid response
             $result = array(XML_RPC_Decode($myResult->Value()));
         }
     }
     return $result;
 }
Exemplo n.º 6
0
function OA_Delivery_XmlRpc_View_PAN($params)
{
    $remoteInfoXmlRpcValue = $params->getParam(0);
    $remote_info = XML_RPC_Decode($params->getParam(0));
    $remote_info['cookies'] = array();
    $remoteInfoXmlRpcValue = XML_RPC_encode($remote_info);
    if ($params->getNumParams() > 6) {
        $contextXmlRpcValue = $params->getParam(6);
    } else {
        $contextXmlRpcValue = new XML_RPC_Value(array(), $XML_RPC_Array);
    }
    $msg = new XML_RPC_Message('phpAds.view', array($remoteInfoXmlRpcValue, $params->getParam(1), $params->getParam(2), $params->getParam(3), $params->getParam(4), $params->getParam(5), $contextXmlRpcValue));
    $xmlResponse = OA_Delivery_XmlRpc_View($msg);
    return $xmlResponse;
}
Exemplo n.º 7
0
function xmlrpc_scan_add($params)
{
    global $logger;
    $data = XML_RPC_Decode($params->getParam(0));
    if ($data['type'] == "mili") {
        $data['fleets'][0] = $data['fleet'][0];
        $data['fleets'][1] = $data['fleet'][1];
        $data['fleets'][2] = $data['fleet'][2];
        for ($i = 0; $i < 3; $i++) {
            $data['fleets'][$i]["type"] = utf8_decode($data['fleet'][$i]["type"]);
            $data['fleets'][$i]["dir"] = utf8_decode($data['fleet'][$i]["dir"]);
        }
        unset($data['fleet']);
    }
    if ($data['type'] == "news") {
        $data["newsdata"] = utf8_decode($data["newsdata"]);
    }
    $logger->debug("add scan, data: " . var_export($data, true));
    updateScan($data);
    return new XML_RPC_Response(new XML_RPC_Value(true, "boolean"));
}
Exemplo n.º 8
0
 /**
  * Method used to check the authentication of the current user.
  *
  * @access  public
  * @param   resource $rpc_conn The connection resource
  * @param   string $email The email address of the current user
  * @param   string $password The password of the current user
  */
 function checkAuthentication($rpc_conn, $email, $password)
 {
     $msg = new XML_RPC_Message("isValidLogin", array(new XML_RPC_Value($email), new XML_RPC_Value($password)));
     $result = $rpc_conn->send($msg);
     if ($result->faultCode()) {
         Command_Line::quit($result->faultString());
     }
     $is_valid = XML_RPC_Decode($result->value());
     if ($is_valid != 'yes') {
         Command_Line::quit("Login information could not be authenticated");
     }
 }
Exemplo n.º 9
0
 /**
  * Connect to OpenX Sync to check for updates
  *
  * @param float $already_seen Only check for updates newer than this value.
  * @return array An array of two items:
  *
  *               Item 0 is the XML-RPC error code. Meanings:
  *                      -2  => The admin user has disabled update checking
  *                      -1  => No response from the server
  *                  0 - 799 => XML-RPC library error codes
  *                       0  => No error
  *                     800  => No updates
  *                     801+ => Error codes from the remote XML-RPC server
  *
  *               Item 1 is either the error message (item 1 != 0), or an array containing update info
  */
 function checkForUpdates($already_seen = 0)
 {
     global $XML_RPC_erruser;
     if (!$this->aConf['sync']['checkForUpdates']) {
         // Checking for updates has been disabled by the admin user,
         // so do not communicate with the OpenX server that provides
         // the details of what upgrades are available - just return
         // an 800 "error"
         $aReturn = array(-2, 'Check for updates has been disabled by the OpenX administrator.');
         return $aReturn;
     }
     // Should this server's technology stack be shared with OpenX?
     $shareTechStack = false;
     if ($this->aConf['sync']['shareStack']) {
         $shareTechStack = true;
     }
     // Should this server's aggregate impression and click statistcs
     // be shared with OpenX?
     $shareStats = false;
     if ($this->aConf['sync']['shareData']) {
         $shareStats = true;
     }
     // Create the XML-RPC client object
     $client = OA_Central::getXmlRpcClient($this->_conf);
     // Prepare the parameters required for the XML-RPC call to
     // obtain if an update is available for this OpenX installation
     $params = array(new XML_RPC_Value(MAX_PRODUCT_NAME, 'string'), new XML_RPC_Value($this->getConfigVersion(OA_Dal_ApplicationVariables::get('oa_version')), 'string'), new XML_RPC_Value($already_seen, 'string'), new XML_RPC_Value('', 'string'), new XML_RPC_Value(OA_Dal_ApplicationVariables::get('platform_hash'), 'string'));
     // Has the OpenX admin user kindly agreed to share the technology
     // stack that OpenX is running on, so that OpenX can monitor what
     // technology stacks the community users, to help with supporting
     // OpenX?
     $aTechStack = array('data' => false);
     if ($shareTechStack) {
         // Thanks, OpenX admin user! You're a star! Prepare the
         // technology stack data and add it to the XML-RPC call
         if ($this->oDbh->dbsyntax == 'mysql') {
             $dbms = 'MySQL';
         } else {
             if ($this->oDbh->dbsyntax == 'pgsql') {
                 $dbms = 'PostgreSQL';
             } else {
                 $dbms = 'UnknownSQL';
             }
         }
         $aTechStack = array('os_type' => php_uname('s'), 'os_version' => php_uname('r'), 'webserver_type' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^(.*?)/.*$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'webserver_version' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^.*?/(.*?)(?: .*)?$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'db_type' => $dbms, 'db_version' => $this->oDbh->queryOne("SELECT VERSION()"), 'php_version' => phpversion(), 'php_sapi' => ucfirst(php_sapi_name()), 'php_extensions' => get_loaded_extensions(), 'php_register_globals' => (bool) ini_get('register_globals'), 'php_magic_quotes_gpc' => (bool) ini_get('magic_quotes_gpc'), 'php_safe_mode' => (bool) ini_get('safe_mode'), 'php_open_basedir' => (bool) strlen(ini_get('open_basedir')), 'php_upload_tmp_readable' => (bool) is_readable(ini_get('upload_tmp_dir') . DIRECTORY_SEPARATOR));
     }
     $params[] = XML_RPC_Encode($aTechStack);
     // Has the OpenX admin user kindly agreed to share their
     // aggregate impression and click statistics to help
     // OpenX monitor what sizes of OpenX installations exist
     // (to ensure OpenX scales to appropriate sizes), and also
     // so that the total community size can be shown in the
     // Dashboard?
     $aStats = array();
     if ($shareStats) {
         // Thanks, OpenX admin user! You're a star! Prepare the
         // aggregate impression and click statistics data and
         // add it to the XML-RPC call
         foreach ($this->buildStats() as $k => $v) {
             $aStats[$k] = XML_RPC_encode($v);
         }
     }
     $params[] = new XML_RPC_Value($aStats, 'struct');
     // Add the OpenX package Origin ID, if appropriate
     $originID = '';
     $originFile = MAX_PATH . '/etc/origin.txt';
     if (file_exists($originFile) && is_readable($originFile)) {
         $rOriginFile = @fopen($originFile, 'r');
         if ($rOriginFile !== false) {
             $originID = fread($rOriginFile, 32);
             fclose($rOriginFile);
         }
         if ($originID === false) {
             $originID = '';
         }
     }
     $params[] = new XML_RPC_Value($originID, 'string');
     // Add the registered email address
     $params[] = new XML_RPC_Value(OA_Dal_ApplicationVariables::get('sync_registered_email'), 'string');
     // Create the XML-RPC request message
     $msg = new XML_RPC_Message("OpenX.Sync", $params);
     // Send the XML-RPC request message
     if ($response = $client->send($msg, 10)) {
         // XML-RPC server found, now checking for errors
         if (!$response->faultCode()) {
             // No fault! Woo! Get the response and return it!
             $aReturn = array(0, XML_RPC_Decode($response->value()));
             // Prepare cache
             $cache = $aReturn[1];
             // Update last run
             OA_Dal_ApplicationVariables::set('sync_last_run', date('Y-m-d H:i:s'));
         } else {
             // Boo! An error! (Well, maybe - it it's 800, yay!)
             $aReturn = array($response->faultCode(), $response->faultString());
             // Prepare cache
             $cache = false;
             // Update last run
             if ($response->faultCode() == 800) {
                 OA_Dal_ApplicationVariables::set('sync_last_run', date('Y-m-d H:i:s'));
             }
         }
         OA_Dal_ApplicationVariables::set('sync_cache', serialize($cache));
         OA_Dal_ApplicationVariables::set('sync_timestamp', time());
         return $aReturn;
     }
     $aReturn = array(-1, 'No response from the remote XML-RPC server.');
     return $aReturn;
 }