getUserIdByUserName($user); /* * if the current user is a valid user... */ if ($userid) { $ownguis = $admin->getGuisByOwner($userid,true); /* * if monitoring is restricted to a single GUI... */ if ($gui) { // ... abort if the GUI doesn't exist if (!$admin->guiExists($gui)) { echo "GUI " . $gui . " doesn't exist.\n"; die(); } // ... add the GUI to the array of GUIs that will be monitored elseif (in_array($gui, $ownguis)) { $ownguis = array($gui); } // ... abort if the GUI is not owned by the current user else { echo "User " . $user . " is not owner of GUI " . $gui . ".\n"; die(); } } } /* * if current user is not a valid user, abort */ else { echo $user . " is not a valid username.\n"; die(); } /** * Array of WMS IDs. These are the WMS that the user owns. */ $wms_id_own = $admin->getWmsByOwnGuis($ownguis); // initialise monitoring processes echo "Starting monitoring cycle...\n\n"; if ($cl == 0) echo "

"; echo "WMS services are requested for availability.\n"; if ($cl == 0) echo "
"; echo "Capabilities documents are requested and all changes synchronized with the database cache.\n\n"; if ($cl == 0) echo "

"; $time = strval(time()-2); for ($k=0; $k ../tmp/output_".$time."_".$wms_id_own[$k].".txt &"; } else { $exec = PHP_PATH . "php5 mod_monitorCapabilities_write.php ".$wms_id_own[$k]." ".$time." 0 > ../tmp/output_".$time."_".$wms_id_own[$k].".txt &"; } /* * @security_patch exec done */ exec(escapeshellcmd($exec)); } echo "Monitoring Cycle completed (total: " . count($wms_id_own) . " wms).\n\n"; if ($cl == 0) echo "

"; set_time_limit(2*TIME_LIMIT); // wait until all monitoring processes are finished echo "please wait " . TIME_LIMIT . " seconds for the monitoring to finish...\n\n"; if ($cl == 0) echo "

"; sleep(TIME_LIMIT); $sql = "SELECT fkey_wms_id, status, status_comment, timestamp_begin, timestamp_end, upload_url FROM mb_monitor WHERE upload_id = $1"; $v = array($time); $t = array('i'); $res = db_prep_query($sql,$v,$t); $cnt=0; while ($row = db_fetch_array($res)) { $status[$cnt] = intval(db_result($res,$cnt,"status")); $wms_id[$cnt] = db_result($res,$cnt,"fkey_wms_id"); $comment[$cnt] = db_result($res,$cnt,"status_comment"); $upload_url[$cnt] = db_result($res,$cnt,"upload_url"); $timestamp_begin[$cnt] = db_result($res,0,"timestamp_begin"); $timestamp_end[$cnt] = db_result($res,0,"timestamp_end"); $cnt++; } $body = ""; for ($i=0; $i<$cnt; $i++) { // if monitoring is still in progress and time limit has expired, update database if ($status[$i] == -2 && intval(time())-intval($timestamp_begin[$i]) > intval(TIME_LIMIT)) { $comment[$i] = "Monitoring process timed out."; $status[$i] = -1; $new_sql = "UPDATE mb_monitor SET status = '-1', image = '-1', status_comment = 'Monitoring process timed out.', timestamp_end = $1 WHERE fkey_wms_id = $2 AND upload_id = $3"; $new_v = array((intval($upload_id[$i])+intval(TIME_LIMIT)), $wms_id[$i], $time); $new_t = array('s', 'i', 's'); $new_res = db_prep_query($new_sql,$new_v,$new_t); } // compose mail message echo $wms_id[$i] . ": status " . $status[$i] . "\n"; if ($cl == 0) echo "

"; if ($status[$i] == -1) { $body .= $admin->getWmsTitleByWmsId($wms_id[$i]) . " (" . $wms_id[$i] . "): " . $comment[$i] . "\n\n"; } } // Send an email to the user if ($body) { $error_msg = ""; if ($admin->getEmailByUserId($userid)) { // $admin->sendEmail(MAILADMIN, MAILADMINNAME, $admin->getEmailByUserId($userid), $user, "WMS monitor report " . date("F j, Y, G:i:s", $time), utf8_decode($body), &$error_msg); } else { $error_msg = "Email address of user '" . $admin->getUserNameByUserId($userid) . "' unknown!\n"; } if ($error_msg) { echo "\n ERROR: " . $error_msg; } } ?>