apps/flash-R1_4_0/reflash.php

Go to the documentation of this file.
00001 <?php
00002 /*!***************************************************************************
00003 *! FILE NAME  : reflash.php
00004 *! DESCRIPTION: updating the camera firmware by running a remote script over NFS
00005 *! Copyright (C) 2007 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: reflash.php,v $
00022 *!  Revision 1.4  2007/12/23 04:24:23  elphel
00023 *!  umounts "store" flash partition
00024 *!
00025 *!  Revision 1.3  2007/12/11 23:28:15  spectr_rain
00026 *!  added NET_FOLDER to use this folder and IP of request source
00027 *!
00028 *!  Revision 1.2  2007/11/20 00:53:33  elphel
00029 *!  Verifies that  correct web server  is used
00030 *!
00031 *!  Revision 1.1  2007/11/08 06:29:37  elphel
00032 *!  added reflash.php that allows camera firmware update from the using HTTP GET request
00033 *!
00034 *!
00035 */
00036 
00037   $mount_point="/var/tmp/z";
00038   $mount_point_store="/mnt/.store";
00039   $remote_script="nfs_update";
00040   $error="";
00041   if (!$_SERVER["FCGI_ROLE"]) $error="wrong web server (please try different port number)";
00042   if ($_GET['SCRIPT']) $remote_script=$_GET['SCRIPT'];
00043   if (!(($NFS=$_GET['NFS']))) {
00044     if (!(($NFS_FOLDER=$_GET['NFS_FOLDER']))) {
00045       $default_nfs=preg_grep("/NFS=/",file("/etc/reflash.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
00046       parse_str($default_nfs[1]);
00047       $NFS=trim($NFS,'"\\');
00048     } else {
00049       $NFS_IP=$_SERVER["REMOTE_ADDR"];
00050       $NFS=$NFS_IP.":".$NFS_FOLDER;
00051     }
00052   }
00054   exec("umount ".$mount_point." ; umount ".$mount_point_store." ; rmdir ".$mount_point);
00055   if (!mkdir($mount_point, 0777))   $error="mkdir ".$mount_point." failed";
00056 
00058   if ($error=="") {
00059      system('mount -t nfs -o nolock '. $NFS.' '.$mount_point, $retval);
00060      if ($retval != 0) {
00061        $error="Mount NFS (".$NFS.")failed";
00062      }
00063   }
00065   if ($error=="") {
00066     if (!is_file($mount_point."/".$remote_script)) {
00067        $error="Remote script ".$remote_script." does not exist on NFS server at ".$NFS;
00068     }
00069   }
00070   if ($error=="") $msg="<?xml version=\"1.0\"?>\n<reflash>\n<status>OK</status>\n</reflash>\n";
00071   else            $msg=sprintf("<?xml version=\"1.0\"?>\n<reflash>\n  <error>\"%s\"</error>\n</reflash>\n",$error);
00075   header("Content-Type: text/xml");
00076   header("Content-Length: ".strlen($msg)."\n");
00077   header("Pragma: no-cache\n");
00078   printf($msg);
00080   ob_flush();
00081   flush();
00082   if ($error=="") {
00083     exec ("cd /var/tmp/z ; ./".$remote_script."  update");
00084   }
00085 ?>

Generated on Thu Aug 7 16:18:59 2008 for elphel by  doxygen 1.5.1