} if ($mode) { if ($mode == "download") { config_lock(); $fn = "config-" . $config['system']['hostname'] . "." . $config['system']['domain'] . "-" . date("YmdHis") . ".xml"; if ($options == "nopackages") { exec("sed '/<installedpackages>/,/<\\/installedpackages>/d' /conf/config.xml > /tmp/config.xml.nopkg"); $fs = filesize("{$g['tmp_path']}/config.xml.nopkg"); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename={$fn}"); header("Content-Length: {$fs}"); readfile("{$g['tmp_path']}/config.xml.nopkg"); } else { if ($_POST['backuparea'] != "") { /* user wishes to backup specific area of configuration */ $current_trafficshaper_section = backup_config_section($_POST['backuparea']); /* generate aliases xml */ $fout = fopen("{$g['tmp_path']}/backup_section.txt", "w"); fwrite($fout, $current_trafficshaper_section); fclose($fout); $fs = filesize($g['tmp_path'] . "/backup_section.txt"); header("Content-Type: application/octet-stream"); $fn = $_POST['backuparea'] . "-" . $fn; header("Content-Disposition: attachment; filename={$fn}"); header("Content-Length: {$fs}"); readfile($g['tmp_path'] . "/backup_section.txt"); unlink($g['tmp_path'] . "/backup_section.txt"); } else { $fs = filesize($g['conf_path'] . "/config.xml"); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename={$fn}");
} $sfn = "{$g['tmp_path']}/config.xml.nopkg"; file_put_contents($sfn, $data); exec("sed '/<installedpackages>/,/<\\/installedpackages>/d' {$sfn} > {$sfn}-new"); $data = file_get_contents($sfn . "-new"); } else { if (!$_POST['backuparea']) { /* backup entire configuration */ $data = file_get_contents("{$g['conf_path']}/config.xml"); } else { if ($_POST['backuparea'] === "rrddata") { $data = rrd_data_xml(); $name = "{$_POST['backuparea']}-{$name}"; } else { /* backup specific area of configuration */ $data = backup_config_section($_POST['backuparea']); $name = "{$_POST['backuparea']}-{$name}"; } } } //unlock($lockbckp); /* * Backup RRD Data */ if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) { $rrd_data_xml = rrd_data_xml(); $closing_tag = "</" . $g['xml_rootobj'] . ">"; $data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data); } if ($_POST['encrypt']) { $data = encrypt_data($data, $_POST['encrypt_password']);
* *insert pfSense license etc here* */ require_once "xmlrpc_client.inc"; // Include client classes from our XMLRPC implementation. require_once "xmlparse_pkg.inc"; // Include pfSense helper functions. require_once "config.inc"; require_once "functions.inc"; // Define remote server URL, path to xmlrpc.php, etc. $url = 'soekris.local'; $path = '/xmlrpc.php'; $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";