manage_file.php 1.58 KB
<?php
 //include('../cfg/file_name.php');
 $open_ntp = '/etc/ntp.conf';
 $ntp_title = array('# pool: <http://www.pool.ntp.org/join.html>','#end');
 shell_exec("sudo chmod 777 ".$open_ntp);
 $open_network = '/etc/network/interfaces';
 $network_dhcp = 'iface eth0 inet dhcp';
 $network_static = 'iface eth0 inet static';
 shell_exec("sudo chmod 777 ".$open_network);
 $open_file = '/home/pi/Desktop/vAlert/bin/vAlert8.cfg';
 shell_exec("sudo chmod 777 ".$open_file);
 $opencommon_file = '/home/pi/Desktop/vAlert/bin/vAlert8Common.cfg';
 shell_exec("sudo chmod 777 ".$opencommon_file);
 if($_GET['type'] !=""){
  switch($_GET['type']){
   case"ntp":
    $file = $open_ntp;
    $filename= "ntp.conf";
   break;
   
   case "network":
    $file = $open_network;
    $filename= "interfaces";
   break;
   
   case "config":
    $file = $open_file;
    $filename= "vAlert8.cfg";
   break;
   
   case "vAlert8commonconfig":
    $file = $opencommon_file;
    $filename= "vAlert8Common.cfg";
   break;
  }
  if(!$file){ // file does not exist
   die('file not found');
  } else {
   header("Cache-Control: public");
   header("Content-Description: File Transfer");
   header("Content-Disposition: attachment; filename=$filename");
   header("Content-Type: application/zip");
   header("Content-Transfer-Encoding: binary");

   // read the file from disk
   readfile($file);
  }
 }else{
  alert('Error','../main.php?item=file');
 }
 function alert($message,$url){
  echo "<script>alert('".$message."');</script>";
  echo "<script>location.href = '".$url."'</script>";
 }
?>