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.1.1.1  2008/11/27 20:04:01  elphel
00023 *!
00024 *!
00025 *!  Revision 1.4  2008/10/15 22:26:44  elphel
00026 *!  Added warning (reflashing takes longer than script to run)
00027 *!
00028 *!  Revision 1.3  2008/10/13 05:14:19  elphel
00029 *!  updated to NFS_ROOT/NFS_DIR
00030 *!
00031 *!  Revision 1.2  2008/10/12 22:17:56  elphel
00032 *!  snapshot
00033 *!
00034 *!  Revision 1.4  2007/12/23 04:24:23  elphel
00035 *!  umounts "store" flash partition
00036 *!
00037 *!  Revision 1.3  2007/12/11 23:28:15  spectr_rain
00038 *!  added NET_FOLDER to use this folder and IP of request source
00039 *!
00040 *!  Revision 1.2  2007/11/20 00:53:33  elphel
00041 *!  Verifies that  correct web server  is used
00042 *!
00043 *!  Revision 1.1  2007/11/08 06:29:37  elphel
00044 *!  added reflash.php that allows camera firmware update from the using HTTP GET request
00045 *!
00046 *!
00047 */
00048 
00049   $mount_point="/var/tmp/nfs_mount_point";
00050   $mount_point_store="/mnt/.store";
00051   $remote_script="nfs_update";
00052   $error="";
00053   if (!$_SERVER["FCGI_ROLE"]) $error="wrong web server (please try different port number)";
00054   if ($_GET['SCRIPT']) $remote_script=$_GET['SCRIPT'];
00055   if (!(($NFS=$_GET['NFS']))) {
00056     if (!(($NFS_FOLDER=$_GET['NFS_FOLDER']))) {
00057       $default_nfs=preg_grep("/NFS=/",file("/etc/reflash.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
00058       foreach ($default_nfs as $str) parse_str($str);
00059       $NFS=trim($NFS,' "\\');
00060     } else {
00061       $NFS_IP=$_SERVER["REMOTE_ADDR"];
00062       $NFS=$NFS_IP.":".$NFS_FOLDER;
00063     }
00064   }
00065   $NFS_ROOT=dirname ($NFS);
00066   $NFS_DIR= basename ($NFS);
00067 
00069   exec("umount ".$mount_point." ; umount ".$mount_point_store." ; rmdir ".$mount_point);
00070   if (!mkdir($mount_point, 0777))   $error="mkdir ".$mount_point." failed";
00071 
00073   if ($error=="") {
00074      system('mount -t nfs -o nolock '. $NFS_ROOT.' '.$mount_point, $retval);
00075      if ($retval != 0) {
00076        $error="Mount NFS (".$NFS_ROOT.")failed";
00077      }
00078   }
00079 
00081   if ($error=="") {
00082     if (!is_file($mount_point."/".$NFS_DIR."/".$remote_script)) {
00083        $error="Remote script ".$NFS_DIR."/".$remote_script." does not exist on NFS server at ".$NFS_ROOT;
00084     }
00085   }
00086   if ($error=="") $msg="<?xml version=\"1.0\"?>\n<reflash>\n<status>OK</status>\n<warning>\"Please do not disconnect the camera until reflashing is complete (under 1 minute)\"</warning>\n</reflash>\n";
00087   else            $msg=sprintf("<?xml version=\"1.0\"?>\n<reflash>\n  <error>\"%s\"</error>\n</reflash>\n",$error);
00091   header("Content-Type: text/xml");
00092   header("Content-Length: ".strlen($msg)."\n");
00093   header("Pragma: no-cache\n");
00094   printf($msg);
00096   ob_flush();
00097   flush();
00098   if ($error=="") {
00099     exec ("cd ".$mount_point."/".$NFS_DIR." ; ./".$remote_script."  update");
00100   }
00101 ?>

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