00001 <?php
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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
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 ?>