From d0ef2fa264f522e067dd4e0a1b51dcf47086e90e Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Wed, 17 Jan 2007 21:27:14 +0000 Subject: Use itools style --- it.class | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'it.class') diff --git a/it.class b/it.class index 588d279..24653cd 100644 --- a/it.class +++ b/it.class @@ -37,7 +37,8 @@ function log($name /* ... */) $args = func_get_args(); $line = date("Y-m-d H:i:s") . "\t" . implode("\t", array_slice($args, 1)) . "\n"; - if ($fh = fopen($GLOBALS['ULTRAHOME'] . "/log/$name-" . date('Ymd'), "a")) { + if ($fh = fopen($GLOBALS['ULTRAHOME'] . "/log/$name-" . date('Ymd'), "a")) + { fputs($fh, $line); fclose($fh); } @@ -68,15 +69,18 @@ function timerlog($label = '') * @param named parameter ok_key indicates which variable to store failure counts in * @param named parameter ok_maxfail number of failures needed for alert; default 2. only 1 failure per 60 seconds counted */ -function error($p=array(), $body='', $to='') +function error($p = array(), $body = "", $to = "") { $p += array('ok_key' => "it_error", 'ok_maxfail' => 2); - if (is_array($p)) { + if (is_array($p)) + { $title = $p['title']; $body = $p['body']; $to = $p['to']; - } else { + } + else + { $title = $p; unset($p); } @@ -84,41 +88,53 @@ function error($p=array(), $body='', $to='') if (!$to) $to = strtr(trim(@file_get_contents($GLOBALS['ULTRAHOME'] . "/.diffnotice")), array("\n"=>',', ' '=>'')); - if (!isset($p['ok'])) - $sendalert = true; - else { + if (isset($p['ok'])) + { $counterfn = $GLOBALS['ULTRAHOME'] . "/tmp/" . urlencode($p['ok_key']); - if (time() - @filemtime($counterfn) >= 60) { # only modify counter if unmodified for 60 secs + + if (time() - @filemtime($counterfn) >= 60) # only modify counter if unmodified for 60 secs + { $oldcounter = intval(@file_get_contents($counterfn)); $newcounter = $p['ok'] ? 0 : $oldcounter + 1; - if ($newcounter != $oldcounter) { + + if ($newcounter != $oldcounter) + { $fh = fopen($counterfn, "w"); fputs($fh, "$newcounter\n"); fclose($fh); - if ($newcounter >= $p['ok_maxfail'] && (time() - @filemtime("$counterfn.mailsent")) >= 86400) { # 1 mail per day + if ($newcounter >= $p['ok_maxfail'] && (time() - @filemtime("$counterfn.mailsent")) >= 86400) # 1 mail per day + { $sendalert = true; + if (!ereg('twin|devel', $GLOBALS['ULTRASERVERTYPE'])) touch("$counterfn.mailsent"); } } } } + else + $sendalert = true; - if ($sendalert) { + if ($sendalert) + { $url = ($_SERVER['HTTPS'] ? "https://" : "http://") . $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI']; if (!$title) $title="Error in $url"; $body .= "\nUrl: $url\n\n\$_REQUEST: ".print_r($_REQUEST, true). "\nStack:\n" . print_r(array_slice(debug_backtrace(), 1), true) . "\n\$_SERVER: " . print_r($_SERVER, true); - if (ereg('twin|devel', $GLOBALS['ULTRASERVERTYPE'])) { + if (ereg('twin|devel', $GLOBALS['ULTRASERVERTYPE'])) + { echo "
$title\n$body\n"; - } else { + } + else + { $cmd = "alert -l " . escapeshellarg($to) . " 4 " . escapeshellarg($title); EDC('exec', $cmd); - if (($pipe = popen($cmd, "w"))) { + if (($pipe = popen($cmd, "w"))) + { fputs($pipe, $body); pclose($pipe); } -- cgit v1.2.3