not sure what i did, but you can bet it was AWESOME
[glcas.git] / bin / pinghelper.php
1 <?php
2
3
4
5 $WEB_ROOT_FS = realpath(dirname(__FILE__));
6 $BASE_URL = dirname($_SERVER["PHP_SELF"]);
7
8 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
9
10 // add libglcas as if it were a path in ../libglcas
11 if(file_exists("../libglcas")) {
12         $path = realpath($WEB_ROOT_FS."/../");
13         error_log("added glcas path as $path");
14         set_include_path(get_include_path().PATH_SEPARATOR.$path);
15 }
16
17 // include the based library
18 require_once("libglcas/lib.php");
19
20 // load plugins
21 glcas_pluginLoader();
22
23 // find our config
24 $configpath = "";
25
26 // TODO: do this better
27 $configpath = glcas_getWebConfigPath();
28 $glconfig = new GLCASConfig();
29 $glconfig->loadConfig($configpath);
30
31
32 $range = "";
33 if(isset($argv[1])) {
34         $range = $argv[1];
35 } else {
36         echo "Need at least one ip address\n";
37 }
38
39 for($i=1; $i < $argc; $i++) {
40         echo "pinging ".$argv[$i]."\n";
41         $ip = $argv[$i];
42         $res = exec("/bin/ping -c 1 $ip 2>&1", $arr, $returned);
43         
44         if($returned != 0) {
45                 $glconfig->delData("ping", "$ip");
46                 $glconfig->addData("ping", "$ip", time(), "failed");
47         } else {
48                 $res_v = preg_split("/[\/ ]+/",$res);
49                 $rettime = $res_v[7];
50                 print_r($res_v);
51                 $glconfig->delData("ping", "$ip");
52                 $glconfig->addData("ping", "$ip", time(), $rettime);
53         }
54 }
55
56 ?>