} else {
                    $url = "http://{$newvoucher['vouchersyncdbip']}";
                }
                $execcmd = <<<EOF
\t\t\t\t\$toreturn = array();
\t\t\t\t\$toreturn['voucher'] = \$config['voucher']['{$cpzone}'];
\t\t\t\tunset(\$toreturn['vouchersyncport'], \$toreturn['vouchersyncpass'], \$toreturn['vouchersyncusername'], \$toreturn['vouchersyncdbip']);

EOF;
                /* assemble xmlrpc payload */
                $params = array(XML_RPC_encode($newvoucher['vouchersyncpass']), XML_RPC_encode($execcmd));
                $port = $newvoucher['vouchersyncport'];
                log_error("voucher XMLRPC sync data {$url}:{$port}.");
                $msg = new XML_RPC_Message('pfsense.exec_php', $params);
                $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
                $cli->setCredentials($newvoucher['vouchersyncusername'], $newvoucher['vouchersyncpass']);
                $resp = $cli->send($msg, "250");
                if (!is_object($resp)) {
                    $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).");
<?php 
    //we're logged in.
} else {
    // store login info
    if (!empty($_REQUEST["user"])) {
        $_SESSION["user"] = $_REQUEST["user"];
        $_SESSION["pass"] = $_REQUEST["pass"];
        $_SESSION["server"] = $_REQUEST["server"];
    }
    //include XMLRPC for php. (uses PEAR !)
    require_once "XML/RPC.php";
    require_once "xmlrpcpln.php";
    //connect to the server
    $XMLRPC = new XML_RPC_Client("/", $_SESSION["server"], 80);
    $XMLRPC->setCredentials($_SESSION["user"], sha1("irate" . sha1($_SESSION["pass"])));
    // if there's a rating to do
    if (!empty($_REQUEST["rate_id"])) {
        $action = "irate.rate";
        if ($_REQUEST["rate_rating"] == "-1") {
            //if -1 given, unrate the track
            $action = "irate.unrate";
        }
        $msg = new XML_RPC_Message($action, array(XML_RPC_PLN::php2xmlrpc(array(array("id" => $_REQUEST["rate_id"], "rating" => $_REQUEST["rate_rating"])))));
        $XMLRPC->send($msg);
        echo "<!-- XMLRPC CALL : \n" . $msg->serialize() . "\n -->";
        //debug
    }
    //ask for all the previous ratings
    $msg = new XML_RPC_Message("irate.getRatings");
    $rep = $XMLRPC->send($msg);
Exemple #3
0
 function call($method)
 {
     $_args = $args = func_get_args();
     $server_channel = $this->config->get('default_channel');
     $channel = $this->_registry->getChannel($server_channel);
     if (!PEAR::isError($channel)) {
         $mirror = $this->config->get('preferred_mirror');
         if ($channel->getMirror($mirror)) {
             if ($channel->supports('xmlrpc', $method, $mirror)) {
                 $server_channel = $server_host = $mirror;
                 // use the preferred mirror
                 $server_port = $channel->getPort($mirror);
             } elseif (!$channel->supports('xmlrpc', $method)) {
                 return $this->raiseError("Channel {$server_channel} does not " . "support xml-rpc method {$method}");
             }
         }
         if (!isset($server_host)) {
             if (!$channel->supports('xmlrpc', $method)) {
                 return $this->raiseError("Channel {$server_channel} does not support " . "xml-rpc method {$method}");
             } else {
                 $server_host = $server_channel;
                 $server_port = $channel->getPort();
             }
         }
     } else {
         return $this->raiseError("Unknown channel '{$server_channel}'");
     }
     array_unshift($_args, $server_channel);
     // cache by channel
     $this->cache = $this->getCache($_args);
     $cachettl = $this->config->get('cache_ttl');
     // If cache is newer than $cachettl seconds, we use the cache!
     if ($this->cache !== null && $this->cache['age'] < $cachettl) {
         return $this->cache['content'];
     }
     $fp = false;
     if (extension_loaded("xmlrpc")) {
         $result = call_user_func_array(array(&$this, 'call_epi'), $args);
         if (!PEAR::isError($result)) {
             $this->saveCache($_args, $result);
         }
         return $result;
     } elseif (!($fp = fopen('XML/RPC.php', 'r', true))) {
         return $this->raiseError("For this remote PEAR operation you need to load the xmlrpc extension or install XML_RPC");
     }
     include_once 'XML/RPC.php';
     if ($fp) {
         fclose($fp);
     }
     array_shift($args);
     $username = $this->config->get('username');
     $password = $this->config->get('password');
     $eargs = array();
     foreach ($args as $arg) {
         $eargs[] = $this->_encode($arg);
     }
     $f = new XML_RPC_Message($method, $eargs);
     if ($this->cache !== null) {
         $maxAge = '?maxAge=' . $this->cache['lastChange'];
     } else {
         $maxAge = '';
     }
     $proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
     if ($proxy = parse_url($this->config->get('http_proxy'))) {
         $proxy_host = isset($proxy['host']) ? $proxy['host'] : null;
         if (isset($proxy['scheme']) && $proxy['scheme'] == 'https') {
             $proxy_host = 'https://' . $proxy_host;
         }
         $proxy_port = isset($proxy['port']) ? $proxy['port'] : 8080;
         $proxy_user = isset($proxy['user']) ? urldecode($proxy['user']) : null;
         $proxy_pass = isset($proxy['pass']) ? urldecode($proxy['pass']) : null;
     }
     $shost = $server_host;
     if ($channel->getSSL()) {
         $shost = "https://{$shost}";
     }
     $c = new XML_RPC_Client('/' . $channel->getPath('xmlrpc') . $maxAge, $shost, $server_port, $proxy_host, $proxy_port, $proxy_user, $proxy_pass);
     if ($username && $password) {
         $c->setCredentials($username, $password);
     }
     if ($this->config->get('verbose') >= 3) {
         $c->setDebug(1);
     }
     $r = $c->send($f);
     if (!$r) {
         return $this->raiseError("XML_RPC send failed");
     }
     $v = $r->value();
     if ($e = $r->faultCode()) {
         if ($e == $GLOBALS['XML_RPC_err']['http_error'] && strstr($r->faultString(), '304 Not Modified') !== false) {
             return $this->cache['content'];
         }
         return $this->raiseError($r->faultString(), $e);
     }
     $result = XML_RPC_decode($v);
     $this->saveCache($_args, $result);
     return $result;
 }
Exemple #4
0
 function call($method)
 {
     $_args = $args = func_get_args();
     $this->cache = $this->getCache($args);
     $cachettl = $this->config->get('cache_ttl');
     // If cache is newer than $cachettl seconds, we use the cache!
     if ($this->cache !== null && $this->cache['age'] < $cachettl) {
         return $this->cache['content'];
     }
     if (extension_loaded("xmlrpc")) {
         $result = call_user_func_array(array(&$this, 'call_epi'), $args);
         if (!PEAR::isError($result)) {
             $this->saveCache($_args, $result);
         }
         return $result;
     }
     if (!@(include_once "XML/RPC.php")) {
         return $this->raiseError("For this remote PEAR operation you need to install the XML_RPC package");
     }
     array_shift($args);
     $server_host = $this->config->get('master_server');
     $username = $this->config->get('username');
     $password = $this->config->get('password');
     $eargs = array();
     foreach ($args as $arg) {
         $eargs[] = $this->_encode($arg);
     }
     $f = new XML_RPC_Message($method, $eargs);
     if ($this->cache !== null) {
         $maxAge = '?maxAge=' . $this->cache['lastChange'];
     } else {
         $maxAge = '';
     }
     $proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
     if ($proxy = parse_url($this->config->get('http_proxy'))) {
         $proxy_host = @$proxy['host'];
         $proxy_port = @$proxy['port'];
         $proxy_user = @urldecode(@$proxy['user']);
         $proxy_pass = @urldecode(@$proxy['pass']);
     }
     $c = new XML_RPC_Client('/xmlrpc.php' . $maxAge, $server_host, 80, $proxy_host, $proxy_port, $proxy_user, $proxy_pass);
     if ($username && $password) {
         $c->setCredentials($username, $password);
     }
     if ($this->config->get('verbose') >= 3) {
         $c->setDebug(1);
     }
     $r = $c->send($f);
     if (!$r) {
         return $this->raiseError("XML_RPC send failed");
     }
     $v = $r->value();
     if ($e = $r->faultCode()) {
         if ($e == $GLOBALS['XML_RPC_err']['http_error'] && strstr($r->faultString(), '304 Not Modified') !== false) {
             return $this->cache['content'];
         }
         return $this->raiseError($r->faultString(), $e);
     }
     $result = XML_RPC_decode($v);
     $this->saveCache($_args, $result);
     return $result;
 }
$user = '******';
$password = '******';
// Create XML_RPC_Value objects containing the method to be called and our arguments.
$section = 'shaper';
$section_xml = backup_config_section($section);
$params = array(new XML_RPC_Value($password, 'string'), new XML_RPC_Value($section, 'string'), new XML_RPC_Value($section_xml, 'string'));
// Create the message that we will be sending the XMLRPC server.
$method = 'pfsense.restore_config_section';
$msg = new XML_RPC_Message($method, $params);
// Create a new client object.
// XXX: SSL is *not* supported yet.
$cli = new XML_RPC_Client($path, $url);
// Print out additional debugging information.
// $cli->setDebug(1);
// Use http basic auth.
$cli->setCredentials($user, $password);
// Send our message and get our response.
$resp = $cli->send($msg);
if ($resp) {
    print "Configuration restored on remote system.\n";
}
/* Uncomment for more debugging.
if (!$resp) {
    echo 'Communication error: ' . $cli->errstr;
    exit;
}

if ($resp->faultCode()) {
    echo 'Fault Code: ' . $resp->faultCode() . "\n";
    echo 'Fault Reason: ' . $resp->faultString() . "\n";
}
function get_remote_log()
{
    global $config, $g, $postfix_dir;
    $curr_time = time();
    $log_time = date('YmdHis', $curr_time);
    if (is_array($config['installedpackages']['postfixsync'])) {
        $synctimeout = $config['installedpackages']['postfixsync']['config'][0]['synctimeout'] ?: '250';
        foreach ($config['installedpackages']['postfixsync']['config'][0]['row'] as $sh) {
            // Get remote data for enabled fetch hosts
            if ($sh['enabless'] && $sh['sync_type'] == 'fetch') {
                $sync_to_ip = $sh['ipaddress'];
                $port = $sh['syncport'];
                $username = $sh['username'] ?: 'admin';
                $password = $sh['password'];
                $protocol = $sh['syncprotocol'];
                $file = '/var/db/postfix/' . $server . '.sql';
                $error = '';
                $valid = TRUE;
                if ($password == "") {
                    $error = "Password parameter is empty. ";
                    $valid = FALSE;
                }
                if ($protocol == "") {
                    $error = "Protocol parameter is empty. ";
                    $valid = FALSE;
                }
                if (!is_ipaddr($sync_to_ip) && !is_hostname($sync_to_ip) && !is_domain($sync_to_ip)) {
                    $error .= "Misconfigured Replication Target IP Address or Hostname. ";
                    $valid = FALSE;
                }
                if (!is_port($port)) {
                    $error .= "Misconfigured Replication Target Port. ";
                    $valid = FALSE;
                }
                if ($valid) {
                    // Take care of IPv6 literal address
                    if (is_ipaddrv6($sync_to_ip)) {
                        $sync_to_ip = "[{$sync_to_ip}]";
                    }
                    $url = "{$protocol}://{$sync_to_ip}";
                    print "{$sync_to_ip} {$url}, {$port}\n";
                    $method = 'pfsense.exec_php';
                    $execcmd = "require_once('/usr/local/www/postfix.php');\n";
                    $execcmd .= '$toreturn = get_sql(' . $log_time . ');';
                    /* Assemble XMLRPC payload. */
                    $params = array(XML_RPC_encode($password), XML_RPC_encode($execcmd));
                    log_error("[postfix] Fetching sql data from {$sync_to_ip}.");
                    $msg = new XML_RPC_Message($method, $params);
                    $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
                    $cli->setCredentials($username, $password);
                    //$cli->setDebug(1);
                    $resp = $cli->send($msg, $synctimeout);
                    $a = $resp->value();
                    $errors = 0;
                    //var_dump($sql);
                    foreach ($a as $b) {
                        foreach ($b as $c) {
                            foreach ($c as $d) {
                                foreach ($d as $e) {
                                    $update = unserialize($e['string']);
                                    print $update['day'] . "\n";
                                    if ($update['day'] != "") {
                                        create_db($update['day'] . ".db");
                                        if ($debug) {
                                            print $update['day'] . " writing from remote system to db...";
                                        }
                                        $dbhandle = sqlite_open($postfix_dir . '/' . $update['day'] . ".db", 0666, $error);
                                        //file_put_contents("/tmp/" . $key . '-' . $update['day'] . ".sql", gzuncompress(base64_decode($update['sql'])), LOCK_EX);
                                        $ok = sqlite_exec($dbhandle, gzuncompress(base64_decode($update['sql'])), $error);
                                        if (!$ok) {
                                            $errors++;
                                            die("Cannot execute query. {$error}\n" . $update['sql'] . "\n");
                                        } elseif ($debug) {
                                            print "ok\n";
                                        }
                                        sqlite_close($dbhandle);
                                    }
                                }
                            }
                        }
                    }
                    if ($errors == 0) {
                        $method = 'pfsense.exec_php';
                        $execcmd = "require_once('/usr/local/www/postfix.php');\n";
                        $execcmd .= 'flush_sql(' . $log_time . ');';
                        /* Assemble XMLRPC payload. */
                        $params = array(XML_RPC_encode($password), XML_RPC_encode($execcmd));
                        log_error("[postfix] Flushing sql buffer file from {$sync_to_ip}.");
                        $msg = new XML_RPC_Message($method, $params);
                        $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
                        $cli->setCredentials($username, $password);
                        //$cli->setDebug(1);
                        $resp = $cli->send($msg, $synctimeout);
                    }
                } else {
                    log_error("[postfix] Fetch sql database from '{$sync_to_ip}' aborted due to the following error(s): {$error}");
                }
            }
        }
        log_error("[postfix] Fetch sql database completed.");
    }
}
Exemple #7
0
function get_remote_log()
{
    global $config, $g, $postfix_dir;
    $curr_time = time();
    $log_time = date('YmdHis', $curr_time);
    #get protocol
    if ($config['system']['webgui']['protocol'] != "") {
        $synchronizetoip = $config['system']['webgui']['protocol'] . "://";
    }
    #get port
    $port = $config['system']['webgui']['port'];
    #if port is empty lets rely on the protocol selection
    if ($port == "") {
        $port = $config['system']['webgui']['protocol'] == "http" ? "80" : "443";
    }
    $synchronizetoip .= $sync_to_ip;
    if (is_array($config['installedpackages']['postfixsync'])) {
        foreach ($config['installedpackages']['postfixsync']['config'][0]['row'] as $sh) {
            $sync_to_ip = $sh['ipaddress'];
            $sync_type = $sh['sync_type'];
            $password = $sh['password'];
            $file = '/var/db/postfix/' . $server . '.sql';
            #get remote data
            if ($sync_type == 'fetch') {
                $url = $synchronizetoip . $sync_to_ip;
                print "{$sync_to_ip} {$url}, {$port}\n";
                $method = 'pfsense.exec_php';
                $execcmd = "require_once('/usr/local/www/postfix.php');\n";
                $execcmd .= '$toreturn=get_sql(' . $log_time . ');';
                /* assemble xmlrpc payload */
                $params = array(XML_RPC_encode($password), XML_RPC_encode($execcmd));
                log_error("postfix get sql data from {$sync_to_ip}.");
                $msg = new XML_RPC_Message($method, $params);
                $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
                $cli->setCredentials('admin', $password);
                #$cli->setDebug(1);
                $resp = $cli->send($msg, "250");
                $a = $resp->value();
                $errors = 0;
                #var_dump($sql);
                foreach ($a as $b) {
                    foreach ($b as $c) {
                        foreach ($c as $d) {
                            foreach ($d as $e) {
                                $update = unserialize($e['string']);
                                print $update['day'] . "\n";
                                if ($update['day'] != "") {
                                    create_db($update['day'] . ".db");
                                    if ($debug = true) {
                                        print $update['day'] . " writing from remote system to db...";
                                    }
                                    $dbhandle = sqlite_open($postfix_dir . '/' . $update['day'] . ".db", 0666, $error);
                                    #file_put_contents("/tmp/".$key.'-'.$update['day'].".sql",gzuncompress(base64_decode($update['sql'])), LOCK_EX);
                                    $ok = sqlite_exec($dbhandle, gzuncompress(base64_decode($update['sql'])), $error);
                                    if (!$ok) {
                                        $errors++;
                                        die("Cannot execute query. {$error}\n" . $update['sql'] . "\n");
                                    } else {
                                        if ($debug = true) {
                                            print "ok\n";
                                        }
                                    }
                                    sqlite_close($dbhandle);
                                }
                            }
                        }
                    }
                }
                if ($errors == 0) {
                    $method = 'pfsense.exec_php';
                    $execcmd = "require_once('/usr/local/www/postfix.php');\n";
                    $execcmd .= 'flush_sql(' . $log_time . ');';
                    /* assemble xmlrpc payload */
                    $params = array(XML_RPC_encode($password), XML_RPC_encode($execcmd));
                    log_error("postfix flush sql buffer file from {$sync_to_ip}.");
                    $msg = new XML_RPC_Message($method, $params);
                    $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
                    $cli->setCredentials('admin', $password);
                    #$cli->setDebug(1);
                    $resp = $cli->send($msg, "250");
                }
            }
        }
    }
}
function snort_do_xmlrpc_sync()
{
    return;
    /* need to fix the bug which whipes out carp sync settings, etc */
    global $config, $g;
    $syncxmlrpc = $config['installedpackages']['snort']['config'][0]['syncxmlrpc'];
    /* option enabled? */
    if (!$syncxmlrpc) {
        return;
    }
    $carp =& $config['installedpackages']['carpsettings']['config'][0];
    $password = $carp['password'];
    if (!$carp['synchronizetoip']) {
        return;
    }
    log_error("[SNORT] snort_xmlrpc_sync.php is starting.");
    $xmlrpc_sync_neighbor = $carp['synchronizetoip'];
    if ($config['system']['webgui']['protocol'] != "") {
        $synchronizetoip = $config['system']['webgui']['protocol'];
        $synchronizetoip .= "://";
    }
    $port = $config['system']['webgui']['port'];
    /* if port is empty lets rely on the protocol selection */
    if ($port == "") {
        if ($config['system']['webgui']['protocol'] == "http") {
            $port = "80";
        } else {
            $port = "443";
        }
    }
    $synchronizetoip .= $carp['synchronizetoip'];
    /* xml will hold the sections to sync */
    $xml = array();
    $xml['installedpackages']['snort'] =& $config['installedpackages']['snort'];
    $xml['installedpackages']['snortwhitelist'] =& $config['installedpackages']['snortwhitelist'];
    /* assemble xmlrpc payload */
    $params = array(XML_RPC_encode($password), XML_RPC_encode($xml));
    /* set a few variables needed for sync code borrowed from filter.inc */
    $url = $synchronizetoip;
    $method = 'pfsense.restore_config_section';
    /* Sync! */
    log_error("Beginning Snort XMLRPC sync to {$url}:{$port}.");
    $msg = new XML_RPC_Message($method, $params);
    $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
    $cli->setCredentials('admin', $password);
    if ($g['debug']) {
        $cli->setDebug(1);
    }
    /* send our XMLRPC message and timeout after 240 seconds */
    $resp = $cli->send($msg, "999");
    if (!$resp) {
        $error = "A communications error occured while attempting Snort XMLRPC sync with {$url}:{$port}.";
        log_error($error);
        file_notice("sync_settings", $error, "Snort Settings Sync", "");
    } elseif ($resp->faultCode()) {
        $error = "An error code was received while attempting Snort XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
        log_error($error);
        file_notice("sync_settings", $error, "Snort Settings Sync", "");
    } else {
        log_error("Snort XMLRPC sync successfully completed with {$url}:{$port}.");
    }
    log_error("[SNORT] snort_xmlrpc_sync.php is ending.");
}