watchdog.inc 1.35 KB
Newer Older
1 2
<?

Dries's avatar
 
Dries committed
3 4 5 6 7 8
$watchdog = array("comment" => array("0", $submission_rate["comment"]),
                  "diary"   => array("1", $submission_rate["diary"]),
                  "story"   => array("2", $submission_rate["story"]),
                  "message" => array("3", "0"),
                  "warning" => array("4", "0"),
                  "error"   => array("5", "0"));
9

Dries's avatar
 
Dries committed
10 11
function watchdog($id, $message) {
  global $user, $watchdog, $watchdog_history;
Dries's avatar
Dries committed
12

Dries's avatar
 
Dries committed
13
  if ($watchdog[$id][1] && !user_permission($user)) {
Dries's avatar
 
Dries committed
14
    if ($log = db_fetch_object(db_query("SELECT * FROM watchdog WHERE hostname = '". getenv("REMOTE_ADDR") ."' AND level = '". $watchdog[$id][0] ."'"))) {
Dries's avatar
 
Dries committed
15 16
      if (time() - $log->timestamp < $watchdog[$id][1]) {
        watchdog("warning", "'". getenv("REMOTE_ADDR") ."' exceeded '$id' submission rate");
Dries's avatar
Dries committed
17 18
        header("Location: error.php?op=flood");
        exit();
Dries's avatar
 
Dries committed
19 20 21 22 23 24
      }
    }
  }

  // Perform query to add new watchdog entry:
  db_query("INSERT INTO watchdog (level, timestamp, user, message, location, hostname) VALUES ('". $watchdog[$id][0] ."', '". time() ."', '". check_input($user->id) ."', '". check_input($message) ."', '". check_input(getenv("REQUEST_URI")) ."', '". check_input(getenv("REMOTE_ADDR")) ."')");
Dries's avatar
 
Dries committed
25
}
26

Dries's avatar
 
Dries committed
27
function watchdog_clean($history = 302400) {
Dries's avatar
 
Dries committed
28 29
  $timestamp = time() - $history;
  db_query("DELETE FROM watchdog WHERE timestamp < $timestamp");
30
}
Dries's avatar
 
Dries committed
31

32
?>