00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 $cmd = $_GET['cmd'];
00035
00036 if ($cmd == "run_camogm")
00037 {
00038 exec('camogm /var/state/camogm_cmd > /dev/null 2>&1 &');
00039 }
00040 else if ($cmd == "status")
00041 {
00042 $pipe="/var/state/camogm.state";
00043 $cmd_pipe="/var/state/camogm_cmd";
00044 $mode=0777;
00045 if(!file_exists($pipe)) {
00046 umask(0);
00047 posix_mkfifo($pipe,$mode);
00048 }
00049 $fcmd=fopen($cmd_pipe,"w");
00050 fprintf($fcmd, "xstatus=%s\n",$pipe);
00051 fclose($fcmd);
00052
00053 $status=file_get_contents($pipe);
00054 header("Content-Type: text/xml");
00055 header("Content-Length: ".strlen($status)."\n");
00056 header("Pragma: no-cache\n");
00057 printf($status);
00058 }
00059 else
00060 {
00061
00062 header("Content-type: text/xml");
00063 header("Pragma: no-cache\n");
00064
00065 function xml_header() {
00066 echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
00067 echo "<camogm_interface>\n";
00068 }
00069 function xml_footer() {
00070 echo "</camogm_interface>\n";
00071 }
00072
00073 $cmd_pipe = "/var/state/camogm_cmd";
00074 $fcmd = fopen($cmd_pipe, "w");
00075
00076 xml_header();
00077 echo "<command>".$cmd."</command>";
00078 echo "<".$cmd.">";
00079
00080 switch ($cmd)
00081 {
00082 case "start":
00083 fprintf($fcmd,"start;\n");
00084 break;
00085 case "stop":
00086 fprintf($fcmd,"stop;\n");
00087 break;
00088 case "file_rename":
00089 if ((!isset($_GET['file_old'])) || (!isset($_GET['file_new'])))
00090 {
00091 echo "failed";
00092 break;
00093 }
00094 $old_name = $_GET['file_old'];
00095 $new_name = $_GET['file_new'];
00096 if ($old_name == $new_name)
00097 echo "1";
00098 else if (file_exists("/var/hdd/".$new_name))
00099 echo "file exists";
00100 else
00101 echo rename("/var/hdd/".$old_name, "/var/hdd/".$new_name);
00102 break;
00103 case "mount":
00104 exec('mkdir /var/hdd');
00105 exec('mount /dev/hda1 /var/hdd');
00106 echo "done";
00107 break;
00108 case "get_hdd_space":
00109 echo disk_free_space("/var/hdd");
00110 break;
00111 case "is_hdd_mounted":
00112 exec('mount', $arr);
00113 $mounted = implode("", $arr);
00114 if (strstr($mounted, "/dev/hda1"))
00115 echo substr($mounted, strpos($mounted, "/dev/hda1"),22);
00116 else
00117 echo "no HDD mounted";
00118 break;
00119 case "create_symlink":
00120 exec('ln -s /var/hdd /mnt/flash/html/hdd');
00121 break;
00122 case "list_files":
00123 if (!file_exists('/mnt/flash/html/hdd')) {
00124 echo "no webshare found";
00125 break;
00126 }
00127 if ($handle = opendir('/mnt/flash/html/hdd'))
00128 {
00129 while ($file = readdir($handle))
00130 {
00131 if ($file != "." && $file != "..")
00132 {
00133 echo "<file>";
00134 echo "<name>".$file."</name>";
00135 $size = filesize("/var/hdd/".$file);
00136 echo "<size>".$size."</size>";
00137 echo "</file>";
00138 }
00139 }
00140 closedir($handle);
00141 }
00142 else
00143 echo "no webshare found<br>";
00144 break;
00145 case "set_prefix":
00146 $prefix = $_GET['prefix'];
00147 fprintf($fcmd, "prefix=%s;\n", $prefix);
00148 setcookie("directory", $prefix);
00149 break;
00150 case "init_compressor":
00151 elphel_compressor_run();
00152 break;
00153 }
00154 if ($fcmd)
00155 fclose($fcmd);
00156 echo "</".$cmd.">";
00157 xml_footer();
00158 }
00159 ?>