diff options
author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2001-08-11 19:30:44 +0000 |
---|---|---|
committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2001-08-11 19:30:44 +0000 |
commit | cf2559acb311684a357fe7babdeebab265a3e820 (patch) | |
tree | 608f474b1d2dea77e830447916c5a2f302b79826 | |
parent | 6861ee9f6bbe77fc150813eb7d7e15856ace7779 (diff) | |
download | zabbix-cf2559acb311684a357fe7babdeebab265a3e820.tar.gz zabbix-cf2559acb311684a357fe7babdeebab265a3e820.tar.xz zabbix-cf2559acb311684a357fe7babdeebab265a3e820.zip |
Error handling in PHP frontend.
git-svn-id: svn://svn.zabbix.com/trunk@164 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | frontends/php/config.html | 13 | ||||
-rw-r--r-- | frontends/php/hosts.html | 19 | ||||
-rw-r--r-- | frontends/php/include/config.inc | 204 | ||||
-rw-r--r-- | frontends/php/items.html | 12 | ||||
-rw-r--r-- | frontends/php/sysmaps.html | 10 | ||||
-rw-r--r-- | frontends/php/triggers.html | 20 | ||||
-rw-r--r-- | frontends/php/users.html | 24 |
8 files changed, 216 insertions, 94 deletions
@@ -1,8 +1,14 @@ +Changes for 1.0alpha9: + + - Added error checking to hosts.html + - Added error checking to users.html + - Added error checking to config.html + - Added error checking to items.html + Changes for 1.0alpha8: - changed type of actions.message and alerts.message to blob(text) - added new parameters: io[disk_*] - - zabbix_sucker renamed to zabbix_suckerd - new high performance zabbix_agentd - connect using IP address became possible diff --git a/frontends/php/config.html b/frontends/php/config.html index 7f2c3354..3d2f0756 100644 --- a/frontends/php/config.html +++ b/frontends/php/config.html @@ -7,11 +7,6 @@ ?> <? - show_table_header("CONFIGURATION OF ZABBIX"); - echo "<br>"; -?> - -<? if(isset($register) && ($register=="update")) { if(isset($password_required) && ($password_required=="true")) @@ -22,11 +17,17 @@ { $password_required="0"; } - update_config($smtp_server,$smtp_helo,$smtp_email,$password_required); + $result=update_config($smtp_server,$smtp_helo,$smtp_email,$password_required); + show_messages($result, "Configuration updated", "Configuation was NOT updated"); } ?> <? + show_table_header("CONFIGURATION OF ZABBIX"); + echo "<br>"; +?> + +<? $result=DBselect("select smtp_server,smtp_helo,smtp_email,password_required from config"); $smtp_server=DBget_field($result,0,0); $smtp_helo=DBget_field($result,0,1); diff --git a/frontends/php/hosts.html b/frontends/php/hosts.html index 0e3ab7e1..5240db53 100644 --- a/frontends/php/hosts.html +++ b/frontends/php/hosts.html @@ -6,30 +6,33 @@ ?> <? - show_table_header("CONFIGURATION OF HOSTS"); - echo "<br>"; -?> - -<? if(isset($register)) { if($register=="add") { - add_host($host,$port,$status,$template,$useip,$ip); + $result=add_host($host,$port,$status,$template,$useip,$ip); + show_messages($result,"Host added","Cannot add host"); } if($register=="changestatus") { - update_host_status($hostid,$status); + $result=update_host_status($hostid,$status); + show_messages($result,"Host status updated","Cannot update host status"); } if($register=="delete") { - delete_host($hostid); + $result=delete_host($hostid); + show_messages($result,"Host deleted","Cannot delete host"); unset($hostid); } } ?> <? + show_table_header("CONFIGURATION OF HOSTS"); + echo "<br>"; +?> + +<? show_table_header("HOSTS"); echo "<TABLE BORDER=0 COLS=4 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; echo "<TD WIDTH=\"10%\" NOSAVE><B>Host</B></TD>"; diff --git a/frontends/php/include/config.inc b/frontends/php/include/config.inc index 20e97988..885ec7f3 100644 --- a/frontends/php/include/config.inc +++ b/frontends/php/include/config.inc @@ -3,6 +3,34 @@ $USER_DETAILS =""; + function show_messages($bool,$msg,$errmsg) + { + if(!$bool) + { + $msg=$errmsg; + $color="#AA0000"; + } + else + { + $color="#000000"; + } + echo "<center>"; + echo "<font face='Helvetica' size=+1 color='$color'>"; + echo "<b>[$msg]</b>"; + echo "</font>"; + echo "</center><br>"; + } + + function show_message($msg) + { + show_messages(TRUE,$msg,''); + } + + function show_error_message($msg) + { + show_messages(FALSE,'',$msg); + } + function validate_float($str) { // echo "Validating float:$str<br>"; @@ -629,6 +657,10 @@ $sql="insert into functions (itemid,triggerid,function,parameter) values ($itemid,$triggerid,'$function',$parameter)"; # echo $sql,"<Br>"; $res=DBexecute($sql); + if(!$res) + { + return $res; + } $functionid=DBinsert_id($res,"functions","functionid"); # } # echo "FUNCTIONID:$functionid<BR>"; @@ -695,7 +727,7 @@ { $comments=addslashes($comments); $sql="update triggers set comments='$comments' where triggerid=$triggerid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Update Trigger status @@ -703,7 +735,7 @@ function update_trigger_status($triggerid,$status) { $sql="update triggers set istrue=$status where triggerid=$triggerid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Update Item status @@ -711,7 +743,7 @@ function update_item_status($itemid,$status) { $sql="update items set status=$status where itemid=$itemid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Update Host status @@ -719,7 +751,7 @@ function update_host_status($hostid,$status) { $sql="update hosts set status=$status where hostid=$hostid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Update Item definition @@ -727,7 +759,7 @@ function update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid) { $sql="update items set description='$description',key_='$key',hostid=$hostid,delay=$delay,history=$history,lastdelete=0,nextcheck=0,status=$status,type=$type,snmp_community='$snmp_community',snmp_oid='$snmp_oid' where itemid=$itemid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Add Action @@ -735,7 +767,7 @@ function add_action( $triggerid, $userid, $good, $delay, $subject, $message ) { $sql="insert into actions (triggerid,userid,good,delay,nextcheck,subject,message) values ($triggerid,$userid,$good,$delay,0,'$subject','$message')"; - $result=DBexecute($sql); + return DBexecute($sql); } # Update Action @@ -743,13 +775,13 @@ function update_action( $actionid, $userid, $good, $delay, $subject, $message ) { $sql="update actions set userid=$userid,good=$good,delay=$delay,nextcheck=0,subject='$subject',message='$message' where actionid=$actionid"; - $result=DBexecute($sql); + return DBexecute($sql); } function delete_graphs_item($gitemid) { $sql="delete from graphs_items where gitemid=$gitemid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete Graph @@ -758,8 +790,12 @@ { $sql="delete from graphs_items where graphid=$graphid"; $result=DBexecute($sql); + if(!$result) + { + return $result; + } $sql="delete from graphs where graphid=$graphid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete System Map @@ -768,10 +804,18 @@ { $sql="delete from sysmaps where sysmapid=$sysmapid"; $result=DBexecute($sql); + if(!$result) + { + return $result; + } $sql="delete from sysmaps_hosts where sysmapid=$sysmapid"; $result=DBexecute($sql); + if(!$result) + { + return $result; + } $sql="delete from sysmaps_links where sysmapid=$sysmapid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete Action by userid @@ -779,7 +823,7 @@ function delete_actions_by_userid( $userid ) { $sql="delete from actions where userid=$userid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete Action @@ -787,7 +831,7 @@ function delete_action( $actionid ) { $sql="delete from actions where actionid=$actionid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete from History @@ -796,7 +840,7 @@ { $sql="delete from history where itemid=$itemid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Add Item definition @@ -813,19 +857,19 @@ function delete_function_by_triggerid($triggerid) { $sql="delete from functions where triggerid=$triggerid"; - $result=DBexecute($sql); + return DBexecute($sql); } function delete_actions_by_triggerid($triggerid) { $sql="delete from actions where triggerid=$triggerid"; - $result=DBexecute($sql); + return DBexecute($sql); } function delete_alarms_by_triggerid($triggerid) { $sql="delete from alarms where triggerid=$triggerid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete Function and Trigger definitions by itemid @@ -839,7 +883,7 @@ delete_trigger(DBget_field($result,$i,0)); } $sql="delete from functions where itemid=$itemid"; - $result=DBexecute($sql); + return DBexecute($sql); } @@ -848,12 +892,24 @@ function delete_item($itemid) { - delete_triggers_functions_by_itemid($itemid); - delete_history_by_itemid($itemid); + $result=delete_triggers_functions_by_itemid($itemid); + if(!$result) + { + return $result; + } + $result=delete_history_by_itemid($itemid); $sql="delete from graphs_items where itemid=$itemid"; + if(!$result) + { + return $result; + } $result=DBexecute($sql); + if(!$result) + { + return $result; + } $sql="delete from items where itemid=$itemid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Add alarm @@ -862,7 +918,7 @@ { $now=time(); $sql="insert into alarms(triggerid,clock,istrue) values($triggerid,$now,$istrue)"; - $result=DBexecute($sql); + return DBexecute($sql); } # Add Trigger definition @@ -871,42 +927,57 @@ { $description=addslashes($description); $sql="insert into triggers (description,priority,istrue,comments) values ('$description',$priority,$istrue,'$comments')"; -# echo $sql,"<Br>"; $result=DBexecute($sql); + if(!$result) + { + return $result; + } $triggerid=DBinsert_id($result,"triggers","triggerid"); $expression=implode_exp($expression,$triggerid); $sql="update triggers set expression='$expression' where triggerid=$triggerid"; -# echo $sql,"<Br>"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete Trigger definition function delete_trigger($triggerid) { - delete_function_by_triggerid($triggerid); - delete_alarms_by_triggerid($triggerid); - delete_actions_by_triggerid($triggerid); + $result=delete_function_by_triggerid($triggerid); + if(!$result) + { + return $result; + } + $result=delete_alarms_by_triggerid($triggerid); + if(!$result) + { + return $result; + } + $result=delete_actions_by_triggerid($triggerid); + if(!$result) + { + return $result; + } $sql="delete from triggers where triggerid=$triggerid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Update Trigger definition function update_trigger($triggerid,$expression,$description,$priority,$istrue,$comments) { -# delete_trigger($triggerid); -# $triggerid=add_trigger($expression,$description,$priority,$istrue,$comments); - delete_function_by_triggerid($triggerid); + $result=delete_function_by_triggerid($triggerid); + if(!$result) + { + return $result; + } $expression=implode_exp($expression,$triggerid); $sql="update triggers set expression='$expression',description='$description',priority=$priority,istrue=$istrue,comments='$comments' where triggerid=$triggerid"; -# echo $sql,"<Br>"; - $result=DBexecute($sql); + return DBexecute($sql); } # Update User definition @@ -922,8 +993,7 @@ $passwd=bin2hex(mhash (MHASH_MD5,$passwd)); $sql="update users set groupid=$groupid,name='$name',surname='$surname',alias='$alias',passwd='$passwd' where userid=$userid"; } - $result=DBexecute($sql); - return $result; + return DBexecute($sql); } @@ -933,9 +1003,7 @@ { $passwd=bin2hex(mhash (MHASH_MD5,$passwd)); $sql="insert into users (groupid,name,surname,alias,passwd) values ($groupid,'$name','$surname','$alias','$passwd')"; - $result=DBexecute($sql); - - return $result; + return DBexecute($sql); } # Add Items and Triggers from template @@ -973,6 +1041,7 @@ add_trigger($expression,$description,0,0,""); } } + return TRUE; } # Update Graph @@ -980,7 +1049,7 @@ function update_graph($graphid,$name,$width,$height) { $sql="update graphs set name='$name',width=$width,height=$height where graphid=$graphid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Update System Map @@ -988,7 +1057,7 @@ function update_sysmap($sysmapid,$name,$width,$height) { $sql="update sysmaps set name='$name',width=$width,height=$height where sysmapid=$sysmapid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Add Graph @@ -996,13 +1065,13 @@ function add_graph($name,$width,$height) { $sql="insert into graphs (name,width,height) values ('$name',$width,$height)"; - $result=DBexecute($sql); + return DBexecute($sql); } function add_item_to_graph($graphid,$itemid,$color) { $sql="insert into graphs_items (graphid,itemid,color) values ($graphid,$itemid,'$color')"; - $result=DBexecute($sql); + return DBexecute($sql); } # Add System Map @@ -1010,19 +1079,19 @@ function add_sysmap($name,$width,$height) { $sql="insert into sysmaps (name,width,height) values ('$name',$width,$height)"; - $result=DBexecute($sql); + return DBexecute($sql); } function add_link($sysmapid,$shostid1,$shostid2) { $sql="insert into sysmaps_links (sysmapid,shostid1,shostid2) values ($sysmapid,$shostid1,$shostid2)"; - $result=DBexecute($sql); + return DBexecute($sql); } function delete_link($linkid) { $sql="delete from sysmaps_links where linkid=$linkid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Add Host to system map @@ -1030,13 +1099,13 @@ function add_host_to_sysmap($sysmapid,$hostid,$label,$x,$y,$icon) { $sql="insert into sysmaps_hosts (sysmapid,hostid,label,x,y,icon) values ($sysmapid,$hostid,'$label',$x,$y,'$icon')"; - $result=DBexecute($sql); + return DBexecute($sql); } function update_sysmap_host($shostid,$sysmapid,$hostid,$label,$x,$y,$icon) { $sql="update sysmaps_hosts set hostid=$hostid,label='$label',x=$x,y=$y,icon='$icon' where shostid=$shostid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Add Host definition @@ -1053,13 +1122,18 @@ } $sql="insert into hosts (host,port,status,useip,ip) values ('$host',$port,$status,$useip,'$ip')"; $result=DBexecute($sql); + if(!$result) + { + return $result; + } + $hostid=DBinsert_id($result,"hosts","hostid"); if($template=="true") { - add_from_templates($hostid,$host); + $result=add_from_templates($hostid,$host); } - + return $result; } # Add Media definition @@ -1067,7 +1141,7 @@ function add_media( $userid, $type, $sendto) { $sql="insert into media (userid,type,sendto,active) values ($userid,'$type','$sendto',0)"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete Media definition @@ -1075,7 +1149,7 @@ function delete_media($mediaid) { $sql="delete from media where mediaid=$mediaid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete Media definition by userid @@ -1083,7 +1157,7 @@ function delete_media_by_userid($userid) { $sql="delete from media where userid=$userid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Update configuration @@ -1091,7 +1165,7 @@ function update_config($smtp_server,$smtp_helo,$smtp_email,$password_required) { $sql="update config set smtp_server='$smtp_server',smtp_helo='$smtp_helo',smtp_email='$smtp_email',password_required=$password_required"; - $result=DBexecute($sql); + return DBexecute($sql); } @@ -1100,7 +1174,7 @@ function activate_media($mediaid) { $sql="update media set active=0 where mediaid=$mediaid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Disactivate Media @@ -1108,7 +1182,7 @@ function disactivate_media($mediaid) { $sql="update media set active=1 where mediaid=$mediaid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete Host from sysmap definition @@ -1117,8 +1191,12 @@ { $sql="delete from sysmaps_hosts where shostid=$shostid"; $result=DBexecute($sql); + if(!$result) + { + return $result; + } $sql="delete from sysmaps_links where shostid1=$shostid or shostid2=$shostid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete Host @@ -1127,13 +1205,19 @@ { $sql="select itemid from items where hostid=$hostid"; $result=DBselect($sql); + if(!$result) + { + return $result; + } for($i=0;$i<DBnum_rows($result);$i++) { - delete_item(DBget_field($result,$i,0)); + if(!delete_item(DBget_field($result,$i,0))) + { + return FALSE; + } } - $sql="delete from hosts where hostid=$hostid"; - $result=DBexecute($sql); + return DBexecute($sql); } # Delete User definition @@ -1144,7 +1228,7 @@ delete_actions_by_userid($userid); $sql="delete from users where userid=$userid"; - $result=DBexecute($sql); + return DBexecute($sql); } function show_table_h_delimiter() diff --git a/frontends/php/items.html b/frontends/php/items.html index e9dad0a7..3c831786 100644 --- a/frontends/php/items.html +++ b/frontends/php/items.html @@ -11,19 +11,23 @@ { if($register=="update") { - update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid); + $result=update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid); + show_messages($result,"Item updated","Cannot update item"); } if($register=="changestatus") { - update_item_status($itemid,$status); + $result=update_item_status($itemid,$status); + show_messages($result,"Status of item changed","Cannot change item status"); } if($register=="add") { - add_item($description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid); + $result=add_item($description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid); + show_messages($result,"Item added","Cannot add item"); } if($register=="delete") { - delete_item($itemid); + $result=delete_item($itemid); + show_messages($result,"Item deleted","Cannot delete item"); unset($itemid); } } diff --git a/frontends/php/sysmaps.html b/frontends/php/sysmaps.html index 06b1f629..c701b527 100644 --- a/frontends/php/sysmaps.html +++ b/frontends/php/sysmaps.html @@ -6,11 +6,6 @@ ?> <? - show_table_header("CONFIGURATION OF NETWORK MAPS"); - echo "<br>"; -?> - -<? if(isset($register)) { if($register=="add") @@ -30,6 +25,11 @@ ?> <? + show_table_header("CONFIGURATION OF NETWORK MAPS"); + echo "<br>"; +?> + +<? show_table_header("NETWORK MAPS"); echo "<TABLE BORDER=0 COLS=4 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; echo "<TD WIDTH=\"10%\" NOSAVE><B>Name</B></TD>"; diff --git a/frontends/php/triggers.html b/frontends/php/triggers.html index 08bf94ca..c19560b8 100644 --- a/frontends/php/triggers.html +++ b/frontends/php/triggers.html @@ -11,7 +11,8 @@ { if($register=="changestatus") { - update_trigger_status($triggerid,$status); + $result=update_trigger_status($triggerid,$status); + show_messages($result,"Trigger status updated","Cannot update trigger status"); } if($register=="update") { @@ -21,7 +22,12 @@ if(isset($disabled)) { $istrue=2; } else { $istrue=3; } - update_trigger($triggerid,$expression,$description,$priority,$istrue,$comments); + $result=update_trigger($triggerid,$expression,$description,$priority,$istrue,$comments); + show_messages($result,"Trigger updated","Cannot update trigger"); + } + else + { + show_error_message("Invalid trigger expression"); } } if($register=="add") @@ -31,12 +37,18 @@ if(isset($disabled)) { $istrue=2; } else { $istrue=0; } - add_trigger($expression,$description,$priority,$istrue,$comments); + $result=add_trigger($expression,$description,$priority,$istrue,$comments); + show_messages($result,"Trigger added","Cannot add trigger"); + } + else + { + show_error_message("Invalid trigger expression"); } } if($register=="delete") { - delete_trigger($triggerid); + $result=delete_trigger($triggerid); + show_messages($result,"Trigger deleted","Cannot delete trigger"); unset($triggerid); } } diff --git a/frontends/php/users.html b/frontends/php/users.html index d85eec92..5e00581b 100644 --- a/frontends/php/users.html +++ b/frontends/php/users.html @@ -6,10 +6,6 @@ show_header($page["title"],0,0); ?> -<? - show_table_header("CONFIGURATION OF USERS"); - echo "<br>"; -?> <? if(isset($register)) @@ -19,24 +15,40 @@ if($password1==$password2) { $result=add_user($groupid,$name,$surname,$alias,$password1); + show_messages($result, "User added", "Cannot add user"); + } + else + { + show_error_message("Cannot add user. Both passwords must be equal."); } } if($register=="delete") { - delete_user($userid); + $result=delete_user($userid); + show_messages($result, "User successfully deleted", "Cannot delete user"); unset($userid); } if($register=="update") { if($password1==$password2) { - update_user($userid,$groupid,$name,$surname,$alias,$password1); + $result=update_user($userid,$groupid,$name,$surname,$alias,$password1); + show_messages($result, "Information successfully updated", "Cannot update information"); + } + else + { + show_error_message("Cannot update user. Both passwords must be equal."); } } } ?> <? + show_table_header("CONFIGURATION OF USERS"); + echo "<br>"; +?> + +<? show_table_header("USERS"); echo "<TABLE BORDER=0 COLS=4 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; echo "<TR><TD WIDTH=\"10%\"><B>Group</B></TD>"; |