packages/web/353/camogmgui/camogm_interface.php

Go to the documentation of this file.
00001 <?
00002 /*!***************************************************************************
00003 *! FILE NAME  : camogmgui.php
00004 *! DESCRIPTION: command interface for the camogm recorder and camogm GUI
00005 *! Copyright (C) 2008 Elphel, Inc
00006 *! -----------------------------------------------------------------------------**
00007 *!
00008 *!  This program is free software: you can redistribute it and/or modify
00009 *!  it under the terms of the GNU General Public License as published by
00010 *!  the Free Software Foundation, either version 3 of the License, or
00011 *!  (at your option) any later version.
00012 *!
00013 *!  This program is distributed in the hope that it will be useful,
00014 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 *!  GNU General Public License for more details.
00017 *!
00018 *!  You should have received a copy of the GNU General Public License
00019 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 *! -----------------------------------------------------------------------------**
00021 *!  $Log: camogm_interface.php,v $
00022 *!  Revision 1.1.1.1  2008/11/27 20:04:03  elphel
00023 *!
00024 *!
00025 *!  Revision 1.1  2008/11/21 02:46:33  elphel
00026 *!  added camogmgui
00027 *!
00028 *!
00029 
00030 *!  Revision 1.0  2008/09/21 Sebastian Pichelhofer
00031 *!  start and stop commands for ajax execution
00032 *!
00033 */
00034 $cmd = $_GET['cmd'];
00035 
00036 if ($cmd == "run_camogm")
00037 {
00038         exec('camogm /var/state/camogm_cmd > /dev/null 2>&1 &'); // Can I simply use camogm2 here?
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 ?>

Generated on Fri Nov 28 00:06:24 2008 for elphel by  doxygen 1.5.1