File: 1.02.4b/server/web/node.action.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("Action Node"); 32: $msg=""; 33: 34: switch($_REQUEST['action']) 35: { 36: case "delete": 37: if (!isset($_REQUEST['confirm'])) 38: { 39: $go="confirm.php?action=Delete+Node+".$_REQUEST['nodeid']."+and+all+associated+data&back="; 40: $go.=urlencode("node.action.php?action=delete&nodeid=".$_REQUEST['nodeid']."&confirm=1"); 41: header("Location: ".$go); 42: exit(); 43: } 44: // delete it and shit! 45: 46: // node + localtests + lt results 47: 48: $dnc=0; 49: $dnt=0; 50: $dnd=0; 51: $q="SELECT localtestid FROM fnlocaltest WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 52: $r=$NATS->DB->Query($q); 53: while ($row=$NATS->DB->Fetch_Array($r)) 54: { 55: $NATS->DeleteTest("L".$row['localtestid']); 56: /* 57: $dq="DELETE FROM fnrecord WHERE testid=\"L".$row['localtestid']."\""; 58: $NATS->DB->Query($dq); 59: $dnd+=$NATS->DB->Affected_Rows(); 60: $dq="DELETE FROM fnlocaltest WHERE localtestid=".$row['localtestid']; 61: $NATS->DB->Query($dq); 62: $dnt+=$NATS->DB->Affected_Rows(); 63: */ 64: } 65: $NATS->DB->Free($r); 66: $q="SELECT nstestid FROM fnnstest WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 67: $r=$NATS->DB->Query($q); 68: while ($row=$NATS->DB->Fetch_Array($r)) 69: { 70: $NATS->DeleteTest("N".$row['nstestid']); 71: } 72: $NATS->DB->Free($r); 73: 74: // node record 75: $dq="DELETE FROM fnnode WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 76: $NATS->DB->Query($dq); 77: $dnc+=$NATS->DB->Affected_Rows(); 78: 79: // group links 80: $q="DELETE FROM fngrouplink WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 81: $NATS->DB->Query($q); 82: 83: // alerts 84: $q="DELETE FROM fnalert WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 85: $NATS->DB->Query($q); 86: 87: // test runs 88: $q="DELETE FROM fntestrun WHERE fnode=\"".ss($_REQUEST['nodeid'])."\""; 89: $NATS->DB->Query($q); 90: 91: // node to alert action links 92: $q="DELETE FROM fnnalink WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 93: $NATS->DB->Query($q); 94: 95: $msg="Node ".$_REQUEST['nodeid']." deleted (".$dnc." node)"; 96: break; 97: 98: case "create": 99: // get highest weight 100: $hw=0; 101: $hq="SELECT weight FROM fnnode ORDER BY weight DESC LIMIT 0,1"; 102: $hr=$NATS->DB->Query($hq); 103: if ($hrow=$NATS->DB->Fetch_Array($hr)) $hw=($hrow['weight'])+10; 104: else $hw=10; 105: $NATS->DB->Free($hr); 106: $nodename=strtolower($_REQUEST['nodeid']); 107: $nodename=str_replace(" ","_",$nodename); 108: if (strlen($nodename)>0) 109: { 110: $q="INSERT INTO fnnode(nodeid,weight) VALUES(\"".ss($nodename)."\",".$hw.")"; 111: $NATS->DB->Query($q); 112: if ($NATS->DB->Affected_Rows()>0) 113: { 114: header("Location: node.edit.php?nodeid=".$nodename."&showoptions=1"); 115: exit(); 116: } 117: } 118: $msg="Failed to Create Node"; 119: break; 120: 121: case "move": 122: // get my weight 123: $q="SELECT weight FROM fnnode WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 124: $r=$NATS->DB->Query($q); 125: $row=$NATS->DB->Fetch_Array($r); 126: $myweight=$row['weight']; 127: $NATS->DB->Free($r); 128: 129: // get next/prev one 130: $q="SELECT nodeid,weight FROM fnnode WHERE "; 131: if ($_REQUEST['dir']=="up") $q.="weight<".$myweight." ORDER BY weight DESC LIMIT 0,1"; 132: else $q.="weight>".$myweight." ORDER BY weight ASC LIMIT 0,1"; 133: $r=$NATS->DB->Query($q); 134: if ($row=$NATS->DB->Fetch_Array($r)) 135: { 136: // swap 'em 137: $uq="UPDATE fnnode SET weight=".$myweight." WHERE nodeid=\"".$row['nodeid']."\""; 138: $NATS->DB->Query($uq); 139: $uq="UPDATE fnnode SET weight=".$row['weight']." WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 140: $NATS->DB->Query($uq); 141: $msg="Updated Node Display Order"; 142: } 143: else $msg="No Higher/Lower Node"; 144: break; 145: 146: case "move_before": 147: // get nodeid of what to move before the and movebefore weight 148: $q="UPDATE fnnode SET weight=weight+1 WHERE weight>=".ss($_REQUEST['move_before']); 149: $msg=$q; 150: $NATS->DB->Query($q); 151: $q="UPDATE fnnode SET weight=".ss($_REQUEST['move_before'])." WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 152: $NATS->DB->Query($q); 153: //$msg="Moved Node"; 154: break; 155: 156: case "reorderweight": 157: $q="SELECT nodeid,weight FROM fnnode ORDER BY weight ASC"; 158: $r=$NATS->DB->Query($q); 159: $p=1; 160: while ($row=$NATS->DB->Fetch_Array($r)) 161: { 162: $uq="UPDATE fnnode SET weight=".$p." WHERE nodeid=\"".$row['nodeid']."\""; 163: $NATS->DB->Query($uq); 164: $p++; 165: } 166: $msg="Reorder Completed"; 167: break; 168: 169: default: $msg="Unknown Node Action"; 170: } 171: header("Location: main.php?mode=nodes&message=".urlencode($msg)); 172: exit(); 173: 174: ?> 175: