Copyright (C) 2013 robi Copyright (C) 2015 ESF, LLC All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* pfSense_MODULE: asterisk */ ##|+PRIV ##|*IDENT=page-status-asterisk ##|*NAME=Status: Asterisk config editor page ##|*DESCR=Allow access to the 'Status: Asterisk configuration files' page. ##|*MATCH=asterisk_edit_file.php* ##|-PRIV require("guiconfig.inc"); $backup_dir = "/conf"; $backup_filename = "asterisk_config.bak.tgz"; $backup_path = "{$backup_dir}/{$backup_filename}"; $files_dir = "/conf/asterisk"; $host = "{$config['system']['hostname']}.{$config['system']['domain']}"; // Put the date in the filename $downname = "asterisk-config-{$host}-" . date("YmdHis") . ".bak.tgz"; if (($_GET['a'] == "download") && $_GET['t'] == "backup") { conf_mount_rw(); system("cd {$files_dir} && /usr/bin/tar czf {$backup_path} --exclude 'dist/*' --exclude dist *"); conf_mount_ro(); } if (($_GET['a'] == "download") && file_exists("{$backup_path}")) { session_cache_limiter('public'); $fd = fopen("{$backup_path}", "rb"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=\"{$downname}\""); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Content-Length: " . filesize("{$backup_path}")); fpassthru($fd); exit; } if ($_GET['a'] == "other") { if ($_GET['t'] == "restore") { // Extract files to $files_dir (/conf/asterisk) if (file_exists($backup_path)) { conf_mount_rw(); exec("/usr/bin/tar -xzC {$files_dir} -f {$backup_path} 2>&1", $sysretval); $savemsg = "Backup has been restored, please restart Asterisk now " . $sysretval[1]; system("/bin/chmod -R 644 {$files_dir}/*"); header('Location: asterisk_edit_file.php?savemsg=' . $savemsg); conf_mount_ro(); } else { header('Location: asterisk_edit_file.php?savemsg=Restore+failed.+Backup+file+not+found.'); } exit; } if ($_GET['t'] == "factrest") { // Extract files to $files_dir (/conf/asterisk) if (file_exists('/conf.default/asterisk_factory_defaults_config.tgz')) { conf_mount_rw(); exec("/usr/bin/tar -xzC {$files_dir} -f /conf.default/asterisk_factory_defaults_config.tgz 2>&1", $sysretval); $savemsg = "Factory configuration restored, please restart Asterisk now " . $sysretval[1]; system("/bin/chmod -R 644 {$files_dir}/*"); header('Location: asterisk_edit_file.php?savemsg=' . $savemsg); conf_mount_ro(); } exit; } if ($_GET['t'] == "deldist") { // Delete dist directory from $files_dir/dist (/conf/asterisk/dist) if (file_exists($files_dir . "/dist")) { conf_mount_rw(); exec("/bin/rm -r {$files_dir}/dist 2>&1", $sysretval); $savemsg = "Deleted dist files " . $sysretval[1]; header('Location: asterisk_edit_file.php?savemsg=' . $savemsg); conf_mount_ro(); } exit; } } if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) { $upfilnam = $_FILES['ulfile']['name']; $upfiltim = strtotime(str_replace(".bak.tgz", "", end(explode("-", $upfilnam)))); conf_mount_rw(); move_uploaded_file($_FILES['ulfile']['tmp_name'], "{$backup_path}"); $savemsg = "Uploaded " . htmlentities($_FILES['ulfile']['name']) . " file as " . $backup_path . "."; system("/bin/chmod -R 644 {$backup_path}"); // Take the date from the filename and update modified time accordingly if ($upfiltim) { touch($backup_path, $upfiltim); } unset($_POST['txtCommand']); conf_mount_ro(); header('Location: asterisk_edit_file.php?savemsg=' . $savemsg); } if ($_REQUEST['action']) { switch($_REQUEST['action']) { case 'load': if (strlen($_REQUEST['file']) < 1) { echo "|5|" . gettext("No file name specified") . ".|"; } elseif (is_dir($_REQUEST['file'])) { echo "|4|" . gettext("Loading a directory is not supported") . ".|"; } elseif (! is_file($_REQUEST['file'])) { echo "|3|" . gettext("File does not exist or is not a regular file") . ".|"; } else { $data = file_get_contents(urldecode($_REQUEST['file'])); if ($data === false) { echo "|1|" . gettext("Failed to read file") . ".|"; } else { echo "|0|{$_REQUEST['file']}|{$data}|"; } } exit; case 'save': if (strlen($_REQUEST['file']) < 1) { echo "|" . gettext("No file name specified") . ".|"; } else { conf_mount_rw(); $_REQUEST['data'] = str_replace("\r", "", base64_decode($_REQUEST['data'])); $ret = file_put_contents($_REQUEST['file'], $_REQUEST['data']); conf_mount_ro(); if ($_REQUEST['file'] == "/conf/config.xml" || $_REQUEST['file'] == "/cf/conf/config.xml") { if (file_exists("/tmp/config.cache")) { unlink("/tmp/config.cache"); } disable_security_checks(); } if ($ret === false) { echo "|" . gettext("Failed to write file") . ".|"; } elseif ($ret <> strlen($_REQUEST['data'])) { echo "|" . gettext("Error while writing file") . ".|"; } else { echo "|" . gettext("File successfully saved") . ".|"; } } exit; } exit; } $shortcut_section = "asterisk"; $pgtitle = array(gettext("Status"), gettext("Asterisk configuration files")); require("head.inc"); ?>

Backup / Restore The 'Backup' button will tar gzip asterisk configuration files to it then offers it to download.
The 'Restore' button will be visible only if the backup file exists.
You can upload a backup file to the system, if one already exists at , it will be overwritten.
\n"; if (file_exists($backup_path)) { echo "\n"; } ?>

" . date ("Y F d H:i:s.", filemtime($backup_path)); } ?>
Upload backup file:

:

enable   \n"; } if (file_exists("/conf.default/asterisk_factory_defaults_config.tgz")) { echo "enable \n"; } ?>