File:
1.01.5b/server/web/localtest.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 Local Test");
32:
33: switch ($_REQUEST['action'])
34: {
35: case "create":
36: if (isset($_REQUEST['testcreatedisabled'])) $tenable=0;
37: else $tenable=1;
38: $q="INSERT INTO fnlocaltest(nodeid,testtype,testparam,testenabled) VALUES(";
39: $q.="\"".ss($_REQUEST['nodeid'])."\",\"".ss($_REQUEST['testtype'])."\",\"".ss($_REQUEST['testparam'])."\",".$tenable.")";
40: //echo $q;
41: //exit();
42: $NATS->DB->Query($q);
43: //echo $q;
44: //exit();
45: // Following user feedback (added to 0.02.35a)
46: //$loc="localtest.edit.php?localtestid=".$NATS->DB->Insert_Id();
47:
48: /* -- the old code just to appear in the list, now opens like a node create for the options
49: $loc="node.edit.php?nodeid=".$_REQUEST['nodeid']; // no message - just appears in list like evals
50: */
51: $loc="localtest.edit.php?localtestid=".$NATS->DB->Insert_Id();
52: header("Location: ".$loc);
53: exit();
54:
55: break;
56: case "save_form":
57: if (isset($_REQUEST['testrecord'])) $tr=$_REQUEST['testrecord'];
58: else $tr=0;
59: if (isset($_REQUEST['simpleeval'])) $se=$_REQUEST['simpleeval'];
60: else $se=0;
61: if (isset($_REQUEST['testenabled'])) $te=1;
62: else $te=0;
63: if (isset($_REQUEST['clearparam'])) $_REQUEST['testparam']="";
64: if (isset($_REQUEST['testinterval'])) $interval=$_REQUEST['testinterval'];
65: else $interval=0;
66: if (!is_numeric($interval)) $interval=0;
67: $q="UPDATE fnlocaltest SET testparam=\"".ss($_REQUEST['testparam'])."\",testrecord=".ss($tr).",simpleeval=".ss($se).",testenabled=".$te.",";
68: $q.="testname=\"".ss($_REQUEST['testname'])."\",attempts=".ss($_REQUEST['attempts']).",timeout=".ss($_REQUEST['timeout']);
69: $q.=",testinterval=".ss($interval);
70:
71: // get and update parameters if available
72: for ($a=1; $a<10; $a++) // 1 to 9 - "0" taken care of
73: {
74: $paramstr="testparam".$a;
75: if (isset($_REQUEST[$paramstr])) $val=ss($_REQUEST[$paramstr]);
76: else $val="";
77: $clearstr="clearparam".$a;
78: $keepstr="keepparam".$a;
79: if ( (isset($_REQUEST[$clearstr]))&&($_REQUEST[$clearstr]==1) )
80: { // wants cleared so do for sure
81: $val="";
82: $q.=",".$paramstr."=\"".$val."\"";
83: }
84: else if (isset($_REQUEST[$keepstr]))
85: {
86: // keep if new input is blank
87: if ($val!="") $q.=",".$paramstr."=\"".$val."\"";
88: }
89: else
90: { // otherwise update unless cleared
91: $q.=",".$paramstr."=\"".$val."\"";
92: }
93: }
94:
95: $q.=" WHERE localtestid=".ss($_REQUEST['localtestid']);
96: //echo $q;
97: //exit();
98: $NATS->DB->Query($q);
99: if ($NATS->DB->Affected_Rows()<=0) $msg="Save+Failed+or+Nothing+Changed";
100: else $msg="Changes+Saved";
101:
102: // Handle Invalidation
103: if ( isset($_REQUEST['testinterval']) && isset($_REQUEST['original_testinterval']) &&
104: ($_REQUEST['testinterval'] != $_REQUEST['original_testinterval']) )
105: $NATS->InvalidateTest("L".$_REQUEST['localtestid']);
106:
107: header("Location: localtest.edit.php?localtestid=".$_REQUEST['localtestid']."&message=".$msg);
108: exit();
109: case "invalidate":
110: $tid="L".$_REQUEST['localtestid'];
111: $NATS->InvalidateTest($tid,true);
112: $msg="Test+Scheduled+for+ASAP";
113: header("Location: localtest.edit.php?localtestid=".$_REQUEST['localtestid']."&message=".$msg);
114: exit();
115: case "delete":
116: if (!isset($_REQUEST['confirmed']))
117: {
118: $back="localtest.action.php?action=delete&localtestid=".$_REQUEST['localtestid']."&confirmed=1";
119: $back=urlencode($back);
120: $url="confirm.php?action=Delete+test+and+all+historical+data&back=".$back;
121: header("Location: ".$url);
122: exit();
123: }
124: // history
125: $q="DELETE FROM fnrecord WHERE testid=\"L".ss($_REQUEST['localtestid'])."\"";
126: $NATS->DB->Query($q);
127: $hdel=$NATS->DB->Affected_Rows();
128: // test itself
129: $q="DELETE FROM fnlocaltest WHERE localtestid=".ss($_REQUEST['localtestid']);
130: $NATS->DB->Query($q);
131: $m="Deleted ".$NATS->DB->Affected_Rows()." test and ".$hdel." history items";
132: header("Location: main.php?message=".urlencode($m));
133: exit();
134:
135: default:
136: header("Location: main.php?message=Unknown+Local+Test+Action");
137: exit();
138: }
139:
140: ?>
141: