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