#!/usr/bin/php -Cq \n"; $headers .= "Cc: $from_email\n"; //$headers .= "Reply-To: <$from_email>\n"; $headers .= "X-Priority: 1\n"; function checkPort($ifaddr, $port) { global $portscan; $sock = @fsockopen($ifaddr, $port, $errno, $errstr, 6); if($sock) { $portscan="0"; fclose($sock); } else { sleep(5); $sock2 = @fsockopen($ifaddr, $port, $errno, $errstr, 6); if($sock2) { $portscan="0"; fclose($sock2); } else { $portscan="1"; } } } $query="select ports_monitor.*, ports.name, networking_ports.ifaddr, networking_ports.id, networking_ports.device_on, networking_ports.status as online from ports_monitor, ports, networking_ports where (ports_monitor.port=ports.ID) and (networking_ports.id=ports_monitor.port_id) and (networking_ports.status='0') order by port"; mysql_connect("$cfg_dbname","$cfg_dbuser","$cfg_dbpasswd"); mysql_db_query("$cfg_db", "$query"); $result=mysql_db_query("$cfg_db", "$query"); while ($r=mysql_fetch_array($result)) { $subject = "IRM Larm "; $message = "Larm:\n"; $ifaddr = $r["ifaddr"]; $name = $r["name"]; $port = $r["port"]; $port_id = $r["port_id"]; $status = $r["status"]; $device_on = $r["device_on"]; checkPort($ifaddr, $port); if($portscan=="0") { $query2="update ports_monitor set status='0' where port_id='$port_id' and port like '$port'"; if($status=="1") { $query3="select computers.name, computers.contact_i, users.fullname, users.email from computers, users where computers.id='$device_on' and (users.fullname=computers.contact_i)"; $result3=mysql_db_query("$cfg_db", "$query3"); while ($r3=mysql_fetch_array($result3)) { $name = $r3["name"]; $to_email = $r3["email"]; if ($to_email=="") { $to_email="$from_email"; } } $result3=mysql_db_query("$cfg_db", "$query3"); $message .= "$ifaddr:$port ok igen\n"; $subject .= "$name ok"; mail("$to_email", $subject, $message, $headers); //echo "$message\n"; } } else { $query2="update ports_monitor set status='1' where port_id='$port_id' and port like '$port'"; if($status=="0") { $query3="select computers.name, computers.contact_i, users.fullname, users.email from computers, users where computers.id='$device_on' and (users.fullname=computers.contact_i)"; $result3=mysql_db_query("$cfg_db", "$query3"); while ($r3=mysql_fetch_array($result3)) { $name = $r3["name"]; $to_email = $r3["email"]; if ($to_email=="") { $to_email="$from_email"; } } $message .= "$ifaddr:$port svarar ej\n"; $subject .= "$name"; mail("$to_email", $subject, $message, $headers); //echo "$message\n"; } } mysql_db_query("$cfg_db", "$query2"); } mysql_close(); ?>