not sure what i did, but you can bet it was AWESOME
[glcas.git] / bin / pinghelper.php
diff --git a/bin/pinghelper.php b/bin/pinghelper.php
new file mode 100644 (file)
index 0000000..d1e8533
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+
+
+$WEB_ROOT_FS = realpath(dirname(__FILE__));
+$BASE_URL = dirname($_SERVER["PHP_SELF"]);
+
+global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+
+// add libglcas as if it were a path in ../libglcas
+if(file_exists("../libglcas")) {
+       $path = realpath($WEB_ROOT_FS."/../");
+       error_log("added glcas path as $path");
+       set_include_path(get_include_path().PATH_SEPARATOR.$path);
+}
+
+// include the based library
+require_once("libglcas/lib.php");
+
+// load plugins
+glcas_pluginLoader();
+
+// find our config
+$configpath = "";
+
+// TODO: do this better
+$configpath = glcas_getWebConfigPath();
+$glconfig = new GLCASConfig();
+$glconfig->loadConfig($configpath);
+
+
+$range = "";
+if(isset($argv[1])) {
+       $range = $argv[1];
+} else {
+       echo "Need at least one ip address\n";
+}
+
+for($i=1; $i < $argc; $i++) {
+       echo "pinging ".$argv[$i]."\n";
+       $ip = $argv[$i];
+       $res = exec("/bin/ping -c 1 $ip 2>&1", $arr, $returned);
+       
+       if($returned != 0) {
+               $glconfig->delData("ping", "$ip");
+               $glconfig->addData("ping", "$ip", time(), "failed");
+       } else {
+               $res_v = preg_split("/[\/ ]+/",$res);
+               $rettime = $res_v[7];
+               print_r($res_v);
+               $glconfig->delData("ping", "$ip");
+               $glconfig->addData("ping", "$ip", time(), $rettime);
+       }
+}
+
+?>
\ No newline at end of file