CDN: /

CDN

| | |

'."\n"; if ( escapeshellcmd($_POST["action"]) == "download" ) { $output = "Finding config files to be backed up\n"; $backupDir = "/tmp/config_backup"; $backupZip = "/tmp/config_backup.zip"; $hostNameInfo = exec('cat /etc/hostname'); $output .= shell_exec("sudo rm -rf $backupZip 2>&1"); $output .= shell_exec("sudo rm -rf $backupDir 2>&1"); $output .= shell_exec("sudo mkdir $backupDir 2>&1"); if (shell_exec('cat /etc/dhcpcd.conf | grep "static ip_address" | grep -v "#"')) { $output .= shell_exec("sudo cp /etc/dhcpcd.conf $backupDir 2>&1"); } $output .= shell_exec("sudo cp /etc/wpa_supplicant/wpa_supplicant.conf $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/ircddbgateway $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/mmdvmhost $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/dstarrepeater $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/dapnetgateway $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/p25gateway $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/m17gateway $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/ysfgateway $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/ysf2dmr $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/dgidgateway $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/nxdngateway $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/dmrgateway $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/mobilegps $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/starnetserver $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/timeserver $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/dstar-radio.* $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/pistar-remote $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/hosts $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/hostname $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/bmapi.key $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/dapnetapi.key $backupDir 2>&1"); $output .= shell_exec("sudo cp /etc/pistar-css.ini $backupDir 2>&1"); $output .= shell_exec("sudo cp /usr/local/etc/RSSI.dat $backupDir 2>&1"); $output .= shell_exec("sudo cp /var/www/dashboard/config/ircddblocal.php $backupDir 2>&1"); $output .= shell_exec("sudo cp /var/www/dashboard/config/config.php $backupDir 2>&1"); $output .= "Compressing backup files\n"; $output .= shell_exec("sudo zip -j $backupZip $backupDir/* 2>&1"); $output .= "Starting download\n"; echo "
$output
\n"; if (file_exists($backupZip)) { $utc_time = gmdate('Y-m-d H:i:s'); $utc_tz = new DateTimeZone('UTC'); $local_tz = new DateTimeZone(date_default_timezone_get ()); $dt = new DateTime($utc_time, $utc_tz); $dt->setTimeZone($local_tz); $local_time = $dt->format('Y-M-d'); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); if ($hostNameInfo != "cdn") { header('Content-Disposition: attachment; filename="'.basename("CDN_Config_".$hostNameInfo."_".$local_time.".zip").'"'); } else { header('Content-Disposition: attachment; filename="'.basename("CDN_Config_$local_time.zip").'"'); } header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($backupZip)); ob_clean(); flush(); readfile($backupZip); exit; } }; if ( escapeshellcmd($_POST["action"]) == "restore" ) { $output = "Uploading your Config data\n"; $target_dir = "/tmp/config_restore/"; shell_exec("sudo rm -rf $target_dir 2>&1"); shell_exec("mkdir $target_dir 2>&1"); if($_FILES["fileToUpload"]["name"]) { $filename = $_FILES["fileToUpload"]["name"]; $source = $_FILES["fileToUpload"]["tmp_name"]; $type = $_FILES["fileToUpload"]["type"]; $name = explode(".", $filename); $accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed'); foreach($accepted_types as $mime_type) { if($mime_type == $type) { $okay = true; break; } } } $continue = strtolower($name[1]) == 'zip' ? true : false; if(!$continue) { $output .= "The file you are trying to upload is not a .zip file. Please try again.\n"; } $target_path = $target_dir.$filename; if(move_uploaded_file($source, $target_path)) { $zip = new ZipArchive(); $x = $zip->open($target_path); if ($x === true) { $zip->extractTo($target_dir); // change this to the correct site path $zip->close(); unlink($target_path); } $output .= "Your .zip file was uploaded and unpacked.\n"; $output .= "Stopping Services.\n"; // Stop the DV Services shell_exec('sudo systemctl stop cron.service 2>&1'); //Cron shell_exec('sudo systemctl stop dstarrepeater.service 2>&1'); //D-Star Radio Service shell_exec('sudo systemctl stop mmdvmhost.service 2>&1'); //MMDVMHost Radio Service shell_exec('sudo systemctl stop ircddbgateway.service 2>&1'); //ircDDBGateway Service shell_exec('sudo systemctl stop timeserver.service 2>&1'); //Time Server Service shell_exec('sudo systemctl stop pistar-watchdog.service 2>&1'); //PiStar-Watchdog Service shell_exec('sudo systemctl stop pistar-remote.service 2>&1'); //PiStar-Remote Service shell_exec('sudo systemctl stop ysfgateway.service 2>&1'); //YSFGateway shell_exec('sudo systemctl stop ysf2dmr.service 2>&1'); //YSF2DMR shell_exec('sudo systemctl stop p25gateway.service 2>&1'); //P25Gateway shell_exec('sudo systemctl stop nxdngateway.service 2>&1'); //NXDNGateway shell_exec('sudo systemctl stop m17gateway.service 2>&1'); //M17Gateway shell_exec('sudo systemctl stop dapnetgateway.service 2>&1'); //DAPNETGateway shell_exec('sudo systemctl stop mobilegps.service 2>&1'); //MobileGPS // Make the disk Writable shell_exec('sudo mount -o remount,rw / 2>&1'); // Overwrite the configs $output .= "Writing new Config\n"; $output .= shell_exec("sudo rm -f /etc/dstar-radio.* 2>&1")."\n"; $output .= shell_exec("sudo mv -f /tmp/config_restore/RSSI.dat /usr/local/etc/ 2>&1")."\n"; $output .= shell_exec("sudo mv -f /tmp/config_restore/ircddblocal.php /var/www/dashboard/config/ 2>&1")."\n"; $output .= shell_exec("sudo mv -f /tmp/config_restore/config.php /var/www/dashboard/config/ 2>&1")."\n"; $output .= shell_exec("sudo mv -v -f /tmp/config_restore/wpa_supplicant.conf /etc/wpa_supplicant/ 2>&1")."\n"; $output .= shell_exec("sudo mv -v -f /tmp/config_restore/* /etc/ 2>&1")."\n"; //Restore the Timezone Config $timeZone = shell_exec('grep date /var/www/dashboard/config/config.php | grep -o "\'.*\'" | sed "s/\'//g"'); $timeZone = preg_replace( "/\r|\n/", "", $timeZone); //Remove the linebreaks shell_exec('sudo timedatectl set-timezone '.$timeZone.' 2>&1'); //Restore ircDDGBateway Link Manager Password $ircRemotePassword = shell_exec('grep remotePassword /etc/ircddbgateway | awk -F\'=\' \'{print $2}\''); shell_exec('sudo sed -i "/password=/c\\password='.$ircRemotePassword.'" /root/.Remote\ Control'); // Make the disk Read-Only shell_exec('sudo mount -o remount,ro / 2>&1'); // Start the services $output .= "Starting Services.\n"; shell_exec('sudo systemctl start dstarrepeater.service 2>&1'); //D-Star Radio Service shell_exec('sudo systemctl start mmdvmhost.service 2>&1'); //MMDVMHost Radio Service shell_exec('sudo systemctl start ircddbgateway.service 2>&1'); //ircDDBGateway Service shell_exec('sudo systemctl start timeserver.service 2>&1'); //Time Server Service shell_exec('sudo systemctl start pistar-watchdog.service 2>&1'); //PiStar-Watchdog Service shell_exec('sudo systemctl start pistar-remote.service 2>&1'); //PiStar-Remote Service if (substr(exec('grep "pistar-upnp.service" /etc/crontab | cut -c 1'), 0, 1) !== '#') { shell_exec('sudo systemctl start pistar-upnp.service 2>&1'); //PiStar-UPnP Service } shell_exec('sudo systemctl start ysfgateway.service 2>&1'); //YSFGateway shell_exec('sudo systemctl start ysf2dmr.service 2>&1'); //YSF2DMR shell_exec('sudo systemctl start p25gateway.service 2>&1'); //P25Gateway shell_exec('sudo systemctl start nxdngateway.service 2>&1'); //NXDNGateway shell_exec('sudo systemctl start m17gateway.service 2>&1'); //M17Gateway shell_exec('sudo systemctl start dapnetgateway.service 2>&1'); //DAPNETGateway shell_exec('sudo systemctl start mobilegps.service 2>&1'); //MobileGPS shell_exec('sudo systemctl start cron.service 2>&1'); //Cron // Complete $output .= "Configuration Restore Complete.\n"; } else { $output .= "There was a problem with the upload. Please try again.
"; $output .= "\n".'
'."\n"; $output .= ''."\n"; } echo "
$output
\n"; }; echo "
\n"; } else { ?>
" method="post" enctype="multipart/form-data">
Restore Config Restore Configuration
WARNING: Editing the files outside of CDN *could* have un-desireable side effects.
This backup and restore tool will back up your config files to a Zip file, and allow you to restore them later, either to this CDN or another one.
  • System Passwords / Dashboard passwords are NOT backed up / restored.
  • Wireless Configuration IS backed up and restored