Index: trunk/DataStoreServer/web/php/getskycalcmf.php
===================================================================
--- trunk/DataStoreServer/web/php/getskycalcmf.php	(revision 39659)
+++ trunk/DataStoreServer/web/php/getskycalcmf.php	(revision 39659)
@@ -0,0 +1,132 @@
+<?php // getskycalcmf.php
+// Simple cmf retrieval program
+// To download from the page use wget command line
+// wget 'http://ippc17/ipp-misc/getskycalcmf.php?release=3PI.PV3&skycell_id=skycell.2386.085&filter=i' --content-disposition
+// or 
+// curl --remote-name --remote-header-name --location 'http://misc.ipp.ifa.hawaii.edu/getskycalcmf.php?tess_id=RINGS.V3&skycell_id=skycell.2386.085&filter=i'
+// This will get the highest prirority (latest) release
+// For the cmf specfic release add something like    &release=3PI.PV3
+// To just list use wget 'http://ippc17/ipp-misc/getskycalcmf.php?release=3PI.PV3&skycell_id=skycell.2386.085&filter=i&list=1'
+
+$error_string = "";
+$debug = 0;
+
+$rvar_tess_id = getVar('tess_id');
+$rvar_skycell_id = getVar('skycell_id');
+$rvar_filter = getVar('filter');
+$rvar_release = getVar('release');
+
+$rvar_stack_id = getVar('stack_id');
+$rvar_skycal_id = getVar('skycal_id');
+$rvar_list = getVar('list');
+
+$command = "/data/ippc17.0/datastore/ds-cgi/findskycalcmf.pl";
+
+# skycal_id takes priority
+if ($skycal_id) {
+    $command .= " --skycal_id $skycal_id";
+} else if ($rvar_stack_id) {
+    $command .= " --stack_id $stack_id";
+} else if ($rvar_tess_id && $rvar_skycell_id && $rvar_filter) {
+    $command .= " --tess_id $rvar_tess_id --skycell_id $rvar_skycell_id --filter $rvar_filter%";
+} else {
+    $command = "";
+}
+
+if ($command) {
+    if ($rvar_release) {
+        if ($rvar_release == "3PI.GR1") {
+            $rvar_release = "3PI.PV1";
+        }
+        $command .= " --release $rvar_release";
+    } 
+}
+
+$gotFile = 0;
+if ($command) {
+    if ($debug) {
+        echo "<br>$command\n<br>";
+    }
+    $command = escapeshellcmd($command);
+    $output = array();
+
+    exec($command, $output, $command_status);
+
+    if ($command_status == 0) {
+        // we only expect one line of output
+        $len = count($output);
+        if ($len == 1) {
+            list($filename, $pathname) = explode(" ", $output[0]);
+            if ($filename && $pathname) {
+                if (!$debug) {
+                    $gotFile = 1;
+                } else {
+                    echo "$filename $pathname\n";
+                    echo "$command\n";
+                }
+            }
+        } else {
+            echo "<br>unexpected output from $command: $output[0] $output[1]\n";
+        }
+    } else {
+        if ($debug) {
+            echo "<br>command failed $command_status\n";
+        }
+    }
+} else {
+    // something went wrong with the paramters. Error message produced below.
+}
+
+if ($gotFile) {
+    if ($rvar_list) {
+        echo "cmf : $filename\n";
+        // echo "<br>path: $pathname\n<br>";
+    } else {
+        // All systems are go. Time to write the output.
+        // First set up the header
+        header('Content-type: application/fits');
+        header("Content-Disposition: attachment; filename=\"$filename\"");
+        $filesize = filesize($pathname);
+        header("Content-Length: $filesize");
+        header('Expires: now');
+
+        // copy the contents of the file to the stream
+        readfile($pathname);
+    }
+} else {
+    // XXX: Figure out how to stop wget from redirecting these error
+    // messages to the nasty filename
+    $error_string="Could not find cmf";
+    if ($rvar_skycal_id) {
+        $error_string .= " for skycal_id: $rvar_skycal_id";
+    } elseif ($rvar_skycell_id and $rvar_tess_id and $rvar_filter) {
+        $error_string .= " for tess_id $rvar_tess_id skycell_id: $rvar_skycell_id filter: $rvar_filter";
+    } else {
+        $error_string .= ".<br>Not enough parameters supplied";
+    }
+        
+    echo "$error_string.\n";
+}
+
+function getVar($var) {
+    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+        $rvar = $_POST[$var];
+    } else {
+        $rvar = $_GET[$var];
+    }
+    $rvar = stripslashes($rvar);
+    $rvar = htmlentities($rvar);
+    $rvar = strip_tags($rvar);
+    return $rvar;
+}
+
+
+if ($list) {
+    // print lots of information from the PHP installation
+    // phpinfo(-1);
+
+    // print the most useful variables
+    //    phpinfo(32);
+}
+
+?>
Index: trunk/DataStoreServer/web/php/getsmf.php
===================================================================
--- trunk/DataStoreServer/web/php/getsmf.php	(revision 39658)
+++ trunk/DataStoreServer/web/php/getsmf.php	(revision 39659)
@@ -5,16 +5,7 @@
 // To just list use wget 'http://ippc17/ipp-misc/getsmf.php?exp_name=o5732g0036o&list=1'
 
-// Only configuration variable here, the location of the cgi script to find smf files
-$command = "/data/ippc17.0/datastore/ds-cgi/findsmf.pl";
-
-$rvar_exp_name = "";
-$rvar_cam_id = "";
-$rvar_data_group = "";
-$rvar_list = 0;
 
 $error_string = "";
 $debug = 0;
-
-# import_request_variables("g", "rvar_");
 
 $rvar_exp_name = getVar('exp_name');
@@ -24,4 +15,6 @@
 $rvar_data_group = getVar('data_group');
 $rvar_list = getVar('list');
+
+$command = "/data/ippc17.0/datastore/ds-cgi/findsmf.pl";
 
 # cam_id takes priority
@@ -38,5 +31,8 @@
 if ($command) {
     if ($rvar_release) {
-        $command .= " --release $release";
+        if ($rvar_release == "3PI.GR1") {
+            $rvar_release = "3PI.PV1";
+        }
+        $command .= " --release $rvar_release";
     } 
     if ($rvar_data_group) {
@@ -69,9 +65,9 @@
             }
         } else {
-            echo "unexpected output from $command: $output[0] $output[1]\n";
+            echo "<br>unexpected output from $command: $output[0] $output[1]\n";
         }
     } else {
         if ($debug) {
-            echo "command failed $command_status\n";
+            echo "<br>command failed $command_status\n";
         }
     }
@@ -92,7 +88,7 @@
         readfile($pathname);
     } else {
-        echo "smf file name is $filename<br>\nfile is $pathname\n";
+        echo "smf : $filename\n";
+        # echo "path: $pathname\n";
     }
-
 } else {
     // XXX: Figure out how to stop wget from redirecting these error
Index: trunk/DataStoreServer/web/php/listsmfs.php
===================================================================
--- trunk/DataStoreServer/web/php/listsmfs.php	(revision 39659)
+++ trunk/DataStoreServer/web/php/listsmfs.php	(revision 39659)
@@ -0,0 +1,149 @@
+<?php // listsmfs.php
+// Simple smf listing program
+
+
+$error_string = "";
+$debug = 0;
+$list  = 0;  # another debugging tool. list phpinfo
+
+$rvar_date_min = getVar('date_min');
+$rvar_date_max = getVar('date_max');
+$rvar_filter   = getVar('filter');
+$rvar_label    = getVar('label');
+$rvar_data_group = getVar('data_group');
+$rvar_release  = getVar('release');
+$rvar_camera   = getVar('camera');
+
+# these params aren't yet used (and may not be)
+$rvar_exp_name = getVar('exp_name');
+$rvar_cam_id = getVar('cam_id');
+$rvar_exp_id = getVar('exp_id');
+
+$command = "/data/ippc17.0/datastore/ds-cgi/listsmfs.pl";
+
+# max date is ignored unless min date is supplied
+if ($rvar_date_min) {
+    $command .= " --dateobs_min $rvar_date_min";
+    if ($rvar_date_max) {
+        $command .= " --dateobs_max $rvar_date_max";
+    }
+}
+
+if ($rvar_filter) {
+    $command .= " --filter $rvar_filter";
+}
+
+if ($rvar_label) {
+    $command .= " --label $rvar_label";
+}
+
+if ($rvar_release) {
+    $command .= " --release $rvar_release";
+} 
+
+if ($rvar_data_group) {
+    $command .= " --data_group $rvar_data_group";
+} 
+
+if ($rvar_camera) {
+    $command .= " --dbname $rvar_camera";
+}
+
+
+
+
+$agent = $_SERVER['HTTP_USER_AGENT'];
+$pos_curl = stripos($agent, 'curl');
+$pos_wget = stripos($agent, 'wget');
+
+if ($pos_curl === false && $pos_wget === false) {
+    $not_browser = 0;
+} else {
+    $not_browser = 1;
+}
+
+$submitter_ip_addr = $_SERVER['HTTP_X_FORWARDED_FOR'];
+$remote_ip_addr = $_SERVER['REMOTE_ADDR'];
+if ($submitter_ip_addr  === false) {
+    $submitter_ip_addr = $remote_ip_addr;
+}
+if (!$submitter_ip_addr) {
+    $submitter_ip_addr = $remote_ip_addr;
+}
+
+# OUTPUT begins here
+
+# not sure whether this really makes a difference
+if ($not_browser) {
+    echo header('text/plain', '200 OK');
+} else {
+    echo header('text/html', '200 OK');
+}
+
+if ($list) {
+    # debug mode to list phpinfo, set the title
+    # to prevent title from being phpinfo
+    echo "<head> <title>smf list</title></head>\n";
+}
+
+if ($debug) {
+    echo "pos_curl: $pos_curl pos_wget: $pos_wget\n";
+}
+
+
+if ($command) {
+    $command = escapeshellcmd($command);
+    if ($debug) {
+        $agent = $_SERVER['HTTP_USER_AGENT'];
+        echo "HTTP_USER_AGENT is: $agent\n<br>";
+        echo "<br>$command\n<br>";
+    }
+    $output = array();
+
+    # RUN the command
+    exec($command, $output, $command_status);
+
+    if ($command_status == 0) {
+        if (!$not_browser) {
+            # when viewing in a web browser without this the newlines get lost
+            echo "<pre>";
+        }
+
+        # output the list
+        foreach( $output as $line) {
+            echo "$line\n";
+        }
+    } else {
+        if ($debug) {
+            echo "<br>command failed $command_status\n";
+        }
+    }
+} else {
+}
+
+
+function getVar($var) {
+    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+        $rvar = $_POST[$var];
+    } else {
+        $rvar = $_GET[$var];
+    }
+    $rvar = stripslashes($rvar);
+    $rvar = htmlentities($rvar);
+    $rvar = strip_tags($rvar);
+    return $rvar;
+}
+
+
+if ($list) {
+    // print lots of information
+    // phpinfo(-1);
+       print "</pre>\n";
+       print "<p>Submitter IP ADDR: $submitter_ip_addr\n";
+       print "<br>Remote IP ADDR: $remote_ip_addr\n";
+
+    // print the most useful variables
+       phpinfo(32);
+}
+
+?>
