Index: trunk/tools/alertbot/irc/alertbot.php |
— | — | @@ -30,34 +30,30 @@ |
31 | 31 | |
32 | 32 | //configuration |
33 | 33 | include("config.inc.php"); |
34 | | - |
| 34 | + include("../web/config.php"); |
| 35 | + include("../web/data.inc.php"); |
35 | 36 | class alertbot |
36 | 37 | { |
37 | 38 | function check_msgs(&$irc) { //check for new reports |
38 | | - global $warnings;global $admins;global $channel; |
39 | | - if(!file_exists("/tmp/ab_msg.txt")) return; |
40 | | - $file=file("/tmp/ab_msg.txt"); |
41 | | - unlink("/tmp/ab_msg.txt"); |
42 | | - if(sizeof($file)>0) { |
43 | | - for($i=0;$i<sizeof($file);$i++) { |
44 | | - $msg=explode(chr(250),trim($file[$i])); |
45 | | - $user=$msg[1];$msg=$msg[0]; |
46 | | - if(strlen($msg)<=5) break; |
47 | | - $wid=sizeof($warnings)+1; |
48 | | - $warnings[$wid]["text"]=$msg; |
| 39 | + global $warnings;global $admins;global $channel;global $mysql_link; |
| 40 | + $res=mysqli_query($mysql_link,"SELECT * FROM alerts WHERE state = 0 ORDER BY time"); |
| 41 | + |
| 42 | + if(mysqli_num_rows($res)>0) { |
| 43 | + while($warn=mysqli_fetch_assoc($res)) { |
| 44 | + $wid=$warn["id"]; |
| 45 | + $warnings[$wid]["text"]=$warn["problem"]; |
49 | 46 | $warnings[$wid]["time"]=time(); |
50 | 47 | $warnings[$wid]["id"]=$wid; |
51 | | - $warnings[$wid]["action"]="PENDING"; |
52 | | - $warnings[$wid]["user"]=$user; |
53 | | - $irc->message(SMARTIRC_TYPE_CHANNEL, $channel,"$admins: $msg (id $wid)"); |
54 | | - echo "dumped $msg\n"; |
| 48 | + $warnings[$wid]["action"]=$warn["state"]; |
| 49 | + $warnings[$wid]["user"]=$warn["reporter"]; |
| 50 | + $irc->message(SMARTIRC_TYPE_CHANNEL, $channel,"$admins: ".$warn["project"]." (id $wid, pr ".$warn["affected"].")"); |
| 51 | + echo "dumped warning $wid\n"; |
55 | 52 | } |
56 | 53 | } |
57 | | - $fp=fopen("/tmp/ab_dump.txt","w");fwrite($fp,serialize($warnings));fclose($fp); |
58 | 54 | } |
59 | 55 | |
60 | 56 | function check_rep(&$irc) { //check for warnings whose warning time expired, and send SMS |
61 | | - global $warnings;global $channel;global $ttw;global $lastsms; |
| 57 | + global $warnings;global $channel;global $ttw;global $lastsms;global $mysql_link; |
62 | 58 | if(sizeof($warnings)<1) return; // less than one warning in the queue? don't even bother to scan it |
63 | 59 | foreach($warnings as $warning) { |
64 | 60 | if(time()-$warning["time"]>=$ttw && $warning["alerted"]!=true && time()-$lastsms>=$smsinterval) { //warning is older than TTL, and didn't get SMSed before, and there was no SMS for 10 minutes |
— | — | @@ -65,7 +61,7 @@ |
66 | 62 | // alert($warning["text"]); //send SMS |
67 | 63 | $warnings[$warning["id"]]["alerted"]=true; //mark as "sms sent" |
68 | 64 | $warnings[$warning["id"]]["action"]="SMS SENT"; |
69 | | - $fp=fopen("/tmp/ab_dump.txt","w");fwrite($fp,serialize($warnings));fclose($fp); |
| 65 | + mysqli_query($mysql_link,"UPDATE `alertbot`.`alerts` SET `state` = '2' WHERE `alerts`.`id` =".$warning["id"]." LIMIT 1 ;"); |
70 | 66 | } |
71 | 67 | } |
72 | 68 | } |
— | — | @@ -74,7 +70,7 @@ |
75 | 71 | global $warnings;global $channel; |
76 | 72 | if(isset($warnings[$ircdata->messageex[1]])) { |
77 | 73 | unset($warnings[$ircdata->messageex[1]]); |
78 | | - $fp=fopen("/tmp/ab_dump.txt","w");fwrite($fp,serialize($warnings));fclose($fp); |
| 74 | + mysqli_query($mysql_link,"UPDATE `alertbot`.`alerts` SET `state` = '4' WHERE `alerts`.`id` =".$ircdata->messageex[1]." LIMIT 1 ;"); |
79 | 75 | $irc->message(SMARTIRC_TYPE_CHANNEL, $channel,"Killed ".$ircdata->messageex[1]); |
80 | 76 | } |
81 | 77 | } |
— | — | @@ -99,7 +95,7 @@ |
100 | 96 | if(isset($warnings[$ircdata->messageex[1]])) { |
101 | 97 | $warnings[$ircdata->messageex[1]]["alerted"]=true; //so that no sms gets sent |
102 | 98 | $warnings[$ircdata->messageex[1]]["action"]="ACKd"; |
103 | | - $fp=fopen("/tmp/ab_dump.txt","w");fwrite($fp,serialize($warnings));fclose($fp); |
| 99 | + mysqli_query($mysql_link,"UPDATE `alertbot`.`alerts` SET `state` = '1' WHERE `alerts`.`id` =".$ircdata->messageex[1]." LIMIT 1 ;"); |
104 | 100 | $irc->message(SMARTIRC_TYPE_CHANNEL, $channel,"Killed ".$ircdata->messageex[1]); |
105 | 101 | } |
106 | 102 | } |
Index: trunk/tools/alertbot/web/db.sql |
— | — | @@ -0,0 +1,10 @@ |
| 2 | +CREATE TABLE IF NOT EXISTS `alerts` ( |
| 3 | + `id` int(11) NOT NULL auto_increment, |
| 4 | + `time` timestamp NOT NULL, |
| 5 | + `reporter` varchar(10) NOT NULL, |
| 6 | + `project` varchar(20) NOT NULL, |
| 7 | + `affected` varchar(100) NOT NULL, |
| 8 | + `problem` text NOT NULL, |
| 9 | + `state` int(11) NOT NULL default '0', |
| 10 | + PRIMARY KEY (`id`) |
| 11 | +); |
Property changes on: trunk/tools/alertbot/web/db.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 12 | + native |
Index: trunk/tools/alertbot/web/addwarn.php |
— | — | @@ -8,17 +8,23 @@ |
9 | 9 | <body> |
10 | 10 | <?PHP |
11 | 11 | require("data.inc.php"); |
12 | | -$problem=$_REQUEST["problem"]; |
13 | | -$project=$_REQUEST["project"]; |
14 | | -$language=$_REQUEST["language"]; |
15 | | -$level=$_REQUEST["affected"]; |
16 | | -$problem_other=$_REQUEST["problem-other"]; |
17 | | -$banlist=file("/tmp/ab_bans.txt"); |
| 12 | +require("config.php"); |
18 | 13 | |
| 14 | +$problem=mysqli_real_escape_string($mysql_link,$_REQUEST["problem"]); |
| 15 | +$project=mysqli_real_escape_string($mysql_link,$_REQUEST["project"]); |
| 16 | +$language=mysqli_real_escape_string($mysql_link,$_REQUEST["language"]); |
| 17 | +$level=mysqli_real_escape_string($mysql_link,$_REQUEST["affected"]); |
| 18 | +$problem_other=mysqli_real_escape_string($mysql_link,$_REQUEST["problem-other"]); |
| 19 | + |
19 | 20 | //prechecks for sanity |
20 | | -foreach($banlist as $ban) //check if user is banned |
21 | | - if($_SERVER['REMOTE_ADDR']==trim($ban)) |
22 | | - $msg.="You are banned from using this service."; |
| 21 | +$res=mysqli_query($mysql_link,"SELECT * FROM bans"); |
| 22 | +if(mysqli_num_rows($res)>0) { |
| 23 | + while($ban=mysqli_fetch_assoc($res)) { |
| 24 | + foreach($banlist as $ban) //check if user is banned |
| 25 | + if($_SERVER['REMOTE_ADDR']==trim($ban["host"])) |
| 26 | + $msg.="You were banned from using this service by ".$ban["user"]."."; |
| 27 | + } |
| 28 | +} |
23 | 29 | if(array_search($project,array_keys($acceptable_projects))===FALSE) |
24 | 30 | $msg.="Please choose a valid project.<br />\r\n"; |
25 | 31 | if(array_search($problem,array_keys($acceptable_problems))===FALSE) |
— | — | @@ -45,13 +51,13 @@ |
46 | 52 | else |
47 | 53 | $project=$language.".".$project; |
48 | 54 | |
49 | | - $sms=$level_correspond[$level].": ".$project." / ".$problem_correspond[$problem]; |
| 55 | + $problem=$problem_correspond[$problem]; |
50 | 56 | if($problem=="other" || $problem=="parts") |
51 | | - $sms.=$problem_other; |
52 | | - $fp=fopen("/tmp/ab_msg.txt","a"); |
53 | | - fwrite($fp,$sms.chr(250).$_SERVER['REMOTE_ADDR']."\r\n"); |
54 | | - fclose($fp); |
55 | | - $msg.="Thanks for your submission.<br />\r\nMessage sent: $sms<br />\r\n"; |
| 57 | + $problem.=$problem_other; |
| 58 | + $res=mysqli_query($mysql_link,"INSERT INTO `alertbot`.`alerts` (`id`, `time`, `reporter`, `project`, `affected`, `problem`, `state`) VALUES (NULL, CURRENT_TIMESTAMP, '".$_SERVER['REMOTE_ADDR']."', '$project', '".$level_correspond[$level]."', '".$problem."', '0');"); |
| 59 | + if(mysqli_affected_rows($mysql_link)!=1) |
| 60 | + $msg.="Error occurred: ".mysqli_error($mysql_link)." (".mysqli_errno($mysql_link).")"; |
| 61 | + $msg.="Thanks for your submission.<br />\r\n"."INSERT INTO `alertbot`.`alerts` (`id`, `time`, `reporter`, `project`, `affected`, `problem`, `state`) VALUES (NULL, CURRENT_TIMESTAMP, '".$_SERVER['REMOTE_ADDR']."', '$project', '".$level_correspond[$level]."', '".$problem."', '0');"; |
56 | 62 | } |
57 | 63 | $msg.="<a href='warning.php'>Back</a> to main page."; |
58 | 64 | ?> |
Index: trunk/tools/alertbot/web/data.inc.php |
— | — | @@ -16,5 +16,5 @@ |
17 | 17 | $problem_correspond=array( "sitedown"=>"Site totally down","slow"=>"Site abormally slow", |
18 | 18 | "replag"=>"Excessive replication lag", "parts"=>"Parts of site do not work:", |
19 | 19 | "other"=>"" ); |
20 | | - |
| 20 | +$states=array( 0=>"fresh",1=>"acknowledged",2=>"sms sent",3=>"fixed",4=>"spam" ); |
21 | 21 | ?> |
\ No newline at end of file |
Index: trunk/tools/alertbot/web/warning.php |
— | — | @@ -21,6 +21,7 @@ |
22 | 22 | </script> |
23 | 23 | <?PHP |
24 | 24 | require("data.inc.php"); |
| 25 | +require("config.php"); |
25 | 26 | ?> |
26 | 27 | </head> |
27 | 28 | |
— | — | @@ -70,11 +71,13 @@ |
71 | 72 | Current problems: |
72 | 73 | <table><tr><th>ID</th><th>Time</th><th>Problem</th><th>Status</th></tr> |
73 | 74 | <?PHP |
74 | | - $warnings=unserialize(file_get_contents("/tmp/ab_dump.txt")); |
75 | | - if(sizeof($warnings)>0) { |
76 | | - foreach($warnings as $warn) { |
77 | | - echo "<tr><td>".$warn["id"]."</td><td>".date("j.m.Y h:i:s",$warn["time"])."</td><td>".$warn["text"]."</td><td>".$warn["action"]."</td></tr>"; |
78 | | - } |
| 75 | + |
| 76 | + $res=mysqli_query($mysql_link,"SELECT * FROM alerts WHERE state = 0 OR state= 1 OR state= 2 ORDER BY time"); |
| 77 | + |
| 78 | + if(mysqli_num_rows($res)>0) { |
| 79 | + while($warn=mysqli_fetch_assoc($res)) { |
| 80 | + echo "<tr><td>".$warn["id"]."</td><td>".$warn["time"]."</td><td>".$warn["problem"]."</td><td>".$states[$warn["state"]]."</td></tr>"; |
| 81 | + } |
79 | 82 | } else { |
80 | 83 | echo "<tr><td colspan=\"4\">No current problems known to the Emergency tracker.</td></tr>"; |
81 | 84 | } |