From d89d742bc36f5857594a46e067fd88492a354bda Mon Sep 17 00:00:00 2001 From: nagyrobi Date: Thu, 19 Sep 2013 14:43:08 +0200 Subject: Update asterisk_edit_file.php Update to be compatible with 2.1-RELEASE, NanoBSD. Added complete Asterisk config backup and restore options. --- config/asterisk/asterisk_edit_file.php | 144 +++++++++++++++++++++++++++++++-- 1 file changed, 136 insertions(+), 8 deletions(-) diff --git a/config/asterisk/asterisk_edit_file.php b/config/asterisk/asterisk_edit_file.php index 50d00279..495703a2 100644 --- a/config/asterisk/asterisk_edit_file.php +++ b/config/asterisk/asterisk_edit_file.php @@ -2,7 +2,7 @@ /* edit.php Copyright (C) 2004, 2005 Scott Ullrich - Copyright (C) 2012 robreg@zsurob.hu + Copyright (C) 2013 robi All rights reserved. Redistribution and use in source and binary forms, with or without @@ -34,12 +34,76 @@ ##|*IDENT=page-status-asterisk ##|*NAME=Status: Asterisk config editor page ##|*DESCR=Allow access to the 'Status: Asterisk configuration files' page. -##|*MATCH=status_asterisk_edit.php* +##|*MATCH=asterisk_edit_file.php* ##|-PRIV $pgtitle = array(gettext("Status"),gettext("Asterisk configuration files")); 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']}"; +$downname = "asterisk-config-{$host}-".date("YmdHis").".bak.tgz"; //put the date in the filename + +if (($_GET['a'] == "download") && $_GET['t'] == "backup") { + conf_mount_rw(); + system("cd {$files_dir} && tar czf {$backup_path} *"); + 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"); // HTTP/1.1 + header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past + 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)) { + //echo "The file $filename exists"; + conf_mount_rw(); + //$sysretval = system("tar -xzC {$files_dir} -f {$backup_path} 2>&1"); + exec("tar -xzC {$files_dir} -f {$backup_path} 2>&1", $sysretval); + $savemsg = "Backup has been restored " . $sysretval[1]; + //$savemsg = "Backup has been restored " . $sysretval; + system("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 (($_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('chmod -R 644 {$backup_path}'); + if ($upfiltim) { //take the date from the filename and update modified time accordingly + 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': @@ -93,6 +157,13 @@ outputJavaScriptFileInline("javascript/base64.js"); + +