95 && $result <= 100){return 0;} if ($result > 60 && $result <= 95){return 1;} if ($result > 10 && $result <= 60){return 2;} if ($result >= 0 && $result <= 10){return 3;} //If test fail much (90% fail) } function checkUptime($ID_C,$precision = 0){ global $db_conn; $time = $precision; if ($precision != 0){ $good = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C' AND code == 0 AND `timestamp` > $time")[0]; $all = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C' AND `timestamp` > $time")[0]; }else{ //Uptime of all time $good = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C' AND code == 0")[0]; $all = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C'")[0]; } if ($all != 0){ $uptime = ($good/$all)*100; return $uptime; }else{ return 100; } } /** Ping a WebSite */ function ping($host,$port = '80') { $fP = fSockOpen($host, $port, $errno, $errstr, 3); //Host,port,Err,ErrString,Timeout(Sec) //echo "Error:$errno"; return $fP ? "0" : "1"; } /** Returns web root (ie. http://jkanetwork.com) */ function webRoot(){ $root = $_SERVER['HTTPS'] ? "https://" : "http://"; //Variable = condicion ? Verdadero : Falso return $root . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); } /** Returns a system option */ function getSystemOpt($sysopt){ global $db_conn; return dbw_query_fetch_array($db_conn,"SELECT * FROM SYS WHERE option = '$sysopt'")['value']; } /** Return HttpCode of page. Returns false if page is not found */ function httpCode($url, $wait = 5) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_TIMEOUT, $wait); //timeout in seconds $head = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $head ? $httpCode : FALSE; } /** Return a String of $lenght chars */ function RandomString($length) { //https://phpes.wordpress.com/2007/06/12/generador-de-una-cadena-aleatoria/ $source = 'abcdefghijklmnopqrstuvwxyz'; $source .= '1234567890'; if($length>0){ $rstr = ""; $source = str_split($source,1); for($i=1; $i<=$length; $i++){ $num = mt_rand(1,count($source)); $rstr .= $source[$num-1]; } } return $rstr; } /** 1 if its logued, 0 if not */ function isLogued(){ if (isset($_COOKIE['SessionID'])){ return 1; }else{ return 0; } } function requireLogin(){ if (isLogued() == 0){ die('You dont have admin rights'); //This blocks edit or create nothing if its not logued } } function nameFromIDC($ID_C){ global $db_conn; return dbw_query_fetch_array($db_conn,"SELECT name FROM CHECKS WHERE ID_C='$ID_C'")[0]; } function nameGroupFromIDG($ID_G){ global $db_conn; return dbw_query_fetch_array($db_conn,"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name']; } function IDGFromIDC($ID_C){ global $db_conn; return dbw_query_fetch_array($db_conn,"SELECT ID_G FROM CHECKS WHERE ID_C='$ID_C'")['ID_G']; } /* This funtion returns the array with type of checks */ function arrayTypeChk(){ return array( '1' => 'PING_IP', '2' => 'HTTP_CODE', '3' => 'VISIT_COUNT', '4' => 'DATABASE'); } /* This funtion returns the translated text of a type check */ function textTypeChk($typeChk){ global $T_; $arr = array( '1' => $T_['PING_IP'], '2' => $T_['HTTP_CODE'], '3' => $T_['VISIT_COUNT'], '4' => $T_['DATABASE']); return $arr[$typeChk]; }