manage_file.php
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?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>";
 }
?>