File: 0.04.28a/server/web/node.edit.php (View as Code)

1: 2: /* ------------------------------------------------------------- 3: This file is part of FreeNATS 4: 5: FreeNATS is (C) Copyright 2008 PurplePixie Systems 6: 7: FreeNATS is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeNATS is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeNATS. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freenats 21: -------------------------------------------------------------- */ 22: 23: ob_start(); 24: require("include.php"); 25: $NATS->Start(); 26: if (!$NATS_Session->Check($NATS->DB)) 27: { 28: header("Location: ./?login_msg=Invalid+Or+Expired+Session"); 29: exit(); 30: } 31: if ($NATS_Session->userlevel<5) UL_Error("Edit Node"); 32: ob_end_flush(); 33: Screen_Header("Node Editor",1); 34: echo "\n\n\n"; 43: ?> 44:
45: 46: if (isset($_REQUEST['action'])) 47: { 48: if ($_REQUEST['action']=="save_edit") 49: { 50: if (isset($_REQUEST['nodeenabled'])) $nodeenabled=1; 51: else $nodeenabled=0; 52: if (isset($_REQUEST['pingtest'])) $pingtest=1; 53: else $pingtest=0; 54: if (isset($_REQUEST['pingfatal'])) $pingfatal=1; 55: else $pingfatal=0; 56: if (isset($_REQUEST['nodealert'])) $nodealert=1; 57: else $nodealert=0; 58: 59: $q="UPDATE fnnode SET "; 60: $q.="nodename=\"".ss($_REQUEST['nodename'])."\","; 61: $q.="nodedesc=\"".ss($_REQUEST['nodedesc'])."\","; 62: if (isset($_REQUEST['scheduleid'])) $q.="scheduleid=".ss($_REQUEST['scheduleid']).","; 63: $q.="nodeicon=\"".ss($_REQUEST['nodeicon'])."\","; 64: $q.="nodealert=".ss($nodealert).","; 65: $q.="nodeenabled=".ss($nodeenabled).",pingtest=".ss($pingtest).",pingfatal=".ss($pingfatal).","; 66: $q.="hostname=\"".ss($_REQUEST['hostname'])."\""; 67: 68: $q.=" WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 69: //echo $q; 70: $NATS->DB->Query($q); 71: 72: if ($NATS->DB->Affected_Rows()<=0) 73: { 74: echo "Failed to Save Changes or Nothing Changed
";
75: $poplist[]="Failed to Save or Nothing Changed"; 76: } 77: else 78: { 79: echo "Saved Changes
";
80: $poplist[]="Saved Changes"; 81: } 82: } 83: else if ($_REQUEST['action']=="save_actions") 84: { 85: // build the two lists... 86: $cur=array(); 87: $cc=0; 88: $nl=array(); 89: $nc=0; 90: 91: if (isset($_REQUEST['links'])) 92: { 93: foreach($_REQUEST['links'] as $link) 94: { 95: $nl[$link]['proc']=false; // not processed or existing i.e. outstanding 96: $nl[$link]['aaid']=$link; 97: $nc++; 98: } 99: } 100: 101: $q="SELECT nalid,aaid FROM fnnalink WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 102: $r=$NATS->DB->Query($q); 103: while ($row=$NATS->DB->Fetch_Array($r)) 104: { 105: //echo $row['aaid'].":"; 106: $cur[$row['aaid']]['proc']=false; 107: $cur[$row['aaid']]['nalid']=$row['nalid']; 108: $cur[$row['aaid']]['aaid']=$row['aaid']; 109: $cc++; 110: } 111: 112: // now we have the two lists lets process them 113: foreach($nl as $newone) 114: { 115: if (isset($cur[$newone['aaid']])) // exists - do nothing to both 116: { 117: //echo "
".$newone['aaid'].":";
118: $cur[$newone['aaid']]['proc']=true; 119: $nl[$newone['aaid']]['proc']=true; 120: } 121: // otherwise news are left false to insert and curs false to delete 122: } 123: 124: // so lets do that 125: foreach($nl as $newone) 126: { 127: if ($newone['proc']==false) 128: { 129: //echo $q; 130: $q="INSERT INTO fnnalink(aaid,nodeid) VALUES(".ss($newone['aaid']).",\"".ss($_REQUEST['nodeid'])."\")"; 131: $NATS->DB->Query($q); 132: } 133: } 134: foreach($cur as $curone) 135: { 136: if ($curone['proc']==false) 137: { 138: $q="DELETE FROM fnnalink WHERE nalid=".$curone['nalid']; 139: $NATS->DB->Query($q); 140: //echo $q; 141: } 142: } 143: 144: echo "Saved Alert List Preferences
";
145: $poplist[]="Saved Alert List Preferences"; 146: 147: 148: } 149: 150: } 151: 152: 153: 154: echo "Editing Node: ".$_REQUEST['nodeid']."

";
155: 156: $q="SELECT * FROM fnnode WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\" LIMIT 0,1"; 157: $r=$NATS->DB->Query($q); 158: if (!$row=$NATS->DB->Fetch_Array($r)) 159: { 160: echo "No such node.

";
161: Screen_Footer(); 162: exit(); 163: } 164: $NATS->DB->Free($r); 165: 166: echo ""; 167: echo "
";
168: echo ""; 169: echo ""; 170: echo ""; 171: 172: echo ""; 177: 178: echo ""; 183: 184: echo ""; 189: 190: echo ""; 195: 196: echo ""; 207: 208: echo ""; 225: 226: echo ""; 234: 235: echo ""; 243: 244: echo ""; 252: 253: echo ""; 261: 262: echo ""; 266: echo ""; 267: 268: if (isset($_REQUEST['show_icons'])) 269: { 270: echo ""; 273: } 274: 275: echo ""; 276: 277: 278: echo ""; 279: 280: $q="SELECT * FROM fnlocaltest WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\" AND testtype!=\"ICMP\" ORDER BY localtestid ASC"; 281: $r=$NATS->DB->Query($q); 282: while ($row=$NATS->DB->Fetch_Array($r)) 283: { 284: echo ""; 293: 294: echo ""; 301: } 302: 303: echo "
";
304: echo "\n"; 305: echo ""; 306: echo ""; 307: echo ""; 323: 324: 325: echo "
Node Settings

173: NodeID 174: :"; 175: echo $row['nodeid']; 176: echo "
179: Node Name 180: :"; 181: echo ""; 182: echo "
185: Hostname 186: :"; 187: echo ""; 188: echo "
191: Description 192: :"; 193: echo ""; 194: echo "
197: Node Icon 198: :"; 199: echo " [ Show Icons ]"; 205: echo " [ Show Icons ]"; 206: echo "
209: Test Schedule 210: :"; 211: echo ""; 222: $NATS->DB->Free($sr); 223: echo " ".hlink("Schedule"); 224: echo "
227: Enabled 228: :"; 229: if ($row['nodeenabled']==1) $s=" checked"; 230: else $s=""; 231: echo ""; 232: echo " ".hlink("Node:Enabled"); 233: echo "
236: Alerts Active 237: :"; 238: if ($row['nodealert']==1) $s=" checked"; 239: else $s=""; 240: echo ""; 241: echo " ".hlink("Node:AlertActive"); 242: echo "
245: Ping Test 246: :"; 247: if ($row['pingtest']==1) $s=" checked"; 248: else $s=""; 249: echo ""; 250: echo " ".hlink("Node:PingTest"); 251: echo "
254: Require Ping 255: :"; 256: if ($row['pingfatal']==1) $s=" checked"; 257: else $s=""; 258: echo ""; 259: echo " ".hlink("Node:RequirePing"); 260: echo "
"; 263: echo " Cancel Changes"; 264: echo "

";
265: echo "


"; 271: ShowIcons(); 272: echo "


Node Tests

"; 285: 286: echo ""; 287: if (strlen($row['testparam'])>10) $tp=substr($row['testparam'],0,8).".."; 288: else $tp=$row['testparam']; 289: if ($row['testname']=="") echo lText($row['testtype'])." (".$tp.")"; 290: else echo $row['testname']; 291: echo ""; 292: echo " "; 295: echo " "; 296: echo ""; 297: echo ""; 298: 299: echo "  Last Tested: ".dtago($row['lastrunx']).""; 300: echo "
 
Add Test : "; 315: 316: // one day will do fancy JS option here but for now moved to the edit 317: //echo " "; 318: echo ""; 319: echo ""; 320: 321: echo ""; 322: echo "
";
326: 327: echo "

Alert Actions ".hlink("AlertAction")."

";
328: echo ""; 329: echo ""; 330: echo ""; 331: $q="SELECT aaid,aname FROM fnalertaction"; 332: $r=$NATS->DB->Query($q); 333: $c=0; 334: while ($row=$NATS->DB->Fetch_Array($r)) 335: { 336: // has link? 337: $lq="SELECT nalid FROM fnnalink WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\" AND aaid=".ss($row['aaid'])." LIMIT 0,1"; 338: $lr=$NATS->DB->Query($lq); 339: if ($NATS->DB->Num_Rows($lr)>0) $s=" checked"; 340: else $s=""; 341: $NATS->DB->Free($lr); 342: echo ""; 344: } 345: $NATS->DB->Free($r); 346: echo ""; 347: echo "
"; 343: echo "".$row['aaid']." - ".$row['aname']."
";
348: ?> 349: 350: 351: 352: Screen_Footer(); 353: ?> 354: