File: 1.06.1a/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: // remove from any other nodes with it as a parents 96: $q="UPDATE fnnode SET masterid=\"\" WHERE masterid=\"".ss($_REQUEST['nodeid'])."\""; 97: $NATS->DB->Query($q); 98: 99: $msg="Node ".$_REQUEST['nodeid']." deleted (".$dnc." node)"; 100: break; 101: 102: case "create": 103: // get highest weight 104: $hw=0; 105: $hq="SELECT weight FROM fnnode ORDER BY weight DESC LIMIT 0,1"; 106: $hr=$NATS->DB->Query($hq); 107: if ($hrow=$NATS->DB->Fetch_Array($hr)) $hw=($hrow['weight'])+10; 108: else $hw=10; 109: $NATS->DB->Free($hr); 110: $nodename=strtolower($_REQUEST['nodeid']); 111: $nodename=str_replace(" ","_",$nodename); 112: if (strlen($nodename)>0) 113: { 114: $q="INSERT INTO fnnode(nodeid,weight) VALUES(\"".ss($nodename)."\",".$hw.")"; 115: $NATS->DB->Query($q); 116: if ($NATS->DB->Affected_Rows()>0) 117: { 118: header("Location: node.edit.php?nodeid=".$nodename."&showoptions=1"); 119: exit(); 120: } 121: } 122: $msg="Failed to Create Node"; 123: break; 124: 125: case "move": 126: // get my weight 127: $q="SELECT weight FROM fnnode WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 128: $r=$NATS->DB->Query($q); 129: $row=$NATS->DB->Fetch_Array($r); 130: $myweight=$row['weight']; 131: $NATS->DB->Free($r); 132: 133: // get next/prev one 134: $q="SELECT nodeid,weight FROM fnnode WHERE "; 135: if ($_REQUEST['dir']=="up") $q.="weight<".$myweight." ORDER BY weight DESC LIMIT 0,1"; 136: else $q.="weight>".$myweight." ORDER BY weight ASC LIMIT 0,1"; 137: $r=$NATS->DB->Query($q); 138: if ($row=$NATS->DB->Fetch_Array($r)) 139: { 140: // swap 'em 141: $uq="UPDATE fnnode SET weight=".$myweight." WHERE nodeid=\"".$row['nodeid']."\""; 142: $NATS->DB->Query($uq); 143: $uq="UPDATE fnnode SET weight=".$row['weight']." WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 144: $NATS->DB->Query($uq); 145: $msg="Updated Node Display Order"; 146: } 147: else $msg="No Higher/Lower Node"; 148: break; 149: 150: case "move_before": 151: // get nodeid of what to move before the and movebefore weight 152: $q="UPDATE fnnode SET weight=weight+1 WHERE weight>=".ss($_REQUEST['move_before']); 153: $msg=$q; 154: $NATS->DB->Query($q); 155: $q="UPDATE fnnode SET weight=".ss($_REQUEST['move_before'])." WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 156: $NATS->DB->Query($q); 157: //$msg="Moved Node"; 158: break; 159: 160: case "reorderweight": 161: $q="SELECT nodeid,weight FROM fnnode ORDER BY weight ASC"; 162: $r=$NATS->DB->Query($q); 163: $p=1; 164: while ($row=$NATS->DB->Fetch_Array($r)) 165: { 166: $uq="UPDATE fnnode SET weight=".$p." WHERE nodeid=\"".$row['nodeid']."\""; 167: $NATS->DB->Query($uq); 168: $p++; 169: } 170: $msg="Reorder Completed"; 171: break; 172: 173: default: $msg="Unknown Node Action"; 174: } 175: header("Location: main.php?mode=nodes&message=".urlencode($msg)); 176: exit(); 177: 178: ?> 179: