File: 0.02.18a/server/web/admin.php (View as HTML)

  1: <?php
  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 Foobar.  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<9) UL_Error("Action Node");
 32: 
 33: if (isset($_REQUEST['action']))
 34: 	{
 35: 	switch($_REQUEST['action'])
 36: 		{
 37: 		case "save_user":
 38: 		$q="UPDATE fnuser SET realname=\"".ss($_REQUEST['realname'])."\",userlevel=".ss($_REQUEST['userlevel']);
 39: 		if ((isset($_REQUEST['pword']))&&($_REQUEST['pword']!="_NOTTHIS_")) $q.=",password=MD5(\"".ss($_REQUEST['pword'])."\")";
 40: 		$q.=" WHERE username=\"".ss($_REQUEST['username'])."\"";
 41: 		$NATS->DB->Query($q);
 42: 		if ($NATS->DB->Affected_Rows()<=0) $amsg="Save User Failed or Nothing Changed";
 43: 		else $amsg="Save User ".$_REQUEST['username']." Succeeded";
 44: 		break;
 45: 		
 46: 		case "create_user":
 47: 		$q="INSERT INTO fnuser(username,password,realname,userlevel) VALUES(\"".ss($_REQUEST['username'])."\",";
 48: 		$q.="MD5(\"".ss($_REQUEST['pword'])."\"),\"".ss($_REQUEST['realname'])."\",".ss($_REQUEST['userlevel']).")";
 49: 		$NATS->DB->Query($q);
 50: 		//echo $q;
 51: 		if ($NATS->DB->Affected_Rows()<=0) $amsg="Create User Failed";
 52: 		else $amsg="User ".$_REQUEST['username']." Created";
 53: 		break;
 54: 		
 55: 		case "delete_user": 
 56: 		if ($_REQUEST['username']=="admin")
 57: 			{
 58: 			$amsg="Can't delete the admin user";
 59: 			break;
 60: 			}
 61: 		if (!isset($_REQUEST['confirmed']))
 62: 			{
 63: 			$back=urlencode("admin.php?action=delete_user&username=".$_REQUEST['username']."&confirmed=1");
 64: 			$url="confirm.php?action=Delete+User+".$_REQUEST['username']."&back=".$back;
 65: 			header("Location: ".$url);
 66: 			exit();
 67: 			}
 68: 		$q="DELETE FROM fnuser WHERE username=\"".ss($_REQUEST['username'])."\"";
 69: 		$NATS->DB->Query($q);
 70: 		$amsg="User ".$_REQUEST['username']." Deleted";
 71: 		break;
 72: 		
 73: 		case "var_save":
 74: 		if ($_REQUEST['new_var']=="") // delete
 75: 			{
 76: 			$q="DELETE FROM fnconfig WHERE fnc_var=\"".ss($_REQUEST['orig_var'])."\"";
 77: 			}
 78: 		else // update
 79: 			{
 80: 			$q="UPDATE fnconfig SET fnc_var=\"".ss($_REQUEST['new_var'])."\",fnc_val=\"".ss($_REQUEST['new_val'])."\" ";
 81: 			$q.="WHERE fnc_var=\"".ss($_REQUEST['orig_var'])."\"";
 82: 			}
 83: 		$NATS->DB->Query($q);
 84: 		if ($NATS->DB->Affected_Rows()<=0) $amsg="Update/Delete Variable Failed";
 85: 		else $amsg="Updated/Deleted Variable";
 86: 		break;
 87: 		case "var_new":
 88: 		$q="INSERT INTO fnconfig(fnc_var,fnc_val) VALUES(\"".ss($_REQUEST['new_var'])."\",\"".ss($_REQUEST['new_val'])."\")";
 89: 		//echo $q;
 90: 		$NATS->DB->Query($q);
 91: 		if ($NATS->DB->Affected_Rows()<=0) $amsg="Create Variable Failed";
 92: 		else $amsg="Created Variable";
 93: 		break;
 94: 		
 95: 		case "save_aa":
 96: 		$q="UPDATE fnalertaction SET ";
 97: 		$q.="atype=\"".ss($_REQUEST['atype'])."\",";
 98: 		$q.="aname=\"".ss($_REQUEST['aname'])."\",";
 99: 		$q.="efrom=\"".ss($_REQUEST['efrom'])."\",";
100: 		$q.="etolist=\"".ss($_REQUEST['etolist'])."\",";
101: 		$q.="esubject=".ss($_REQUEST['esubject']).",";
102: 		$q.="etype=".ss($_REQUEST['etype']);
103: 		if (isset($_REQUEST['awarnings'])) $q.=",awarnings=".ss($_REQUEST['awarnings']);
104: 		else $q.=",awarnings=0";
105: 		if (isset($_REQUEST['adecrease'])) $q.=",adecrease=".ss($_REQUEST['adecrease']);
106: 		else $q.=",adecrease=0";
107: 		$q.=" WHERE aaid=".ss($_REQUEST['aaid']);
108: 		//echo $q;
109: 		$NATS->DB->Query($q);
110: 		if ($NATS->DB->Affected_Rows()<=0) $amsg="Action Update Failed or Nothing Changed";
111: 		else $amsg="Action Updated";
112: 		break;
113: 		
114: 		case "action_test":
115: 		$q="SELECT mdata FROM fnalertaction WHERE aaid=".ss($_REQUEST['aaid'])." LIMIT 0,1";
116: 		$r=$NATS->DB->Query($q);
117: 		$row=$NATS->DB->Fetch_Array($r);
118: 		$oldm=$row['mdata'];
119: 		$q="UPDATE fnalertaction SET mdata=\"** ACTION TEST **\" WHERE aaid=".ss($_REQUEST['aaid']);
120: 		$NATS->DB->Query($q);
121: 		$NATS->ActionFlush();
122: 		$q="UPDATE fnalertaction SET mdata=\"".ss($oldm)."\" WHERE aaid=".ss($_REQUEST['aaid']);
123: 		$NATS->DB->Query($q);
124: 		$amsg="Alert Action Tested &amp; Flushed";
125: 		break;
126: 		
127: 		case "action_create":
128: 		$q="INSERT INTO fnalertaction(atype) VALUES(\"\")";
129: 		$NATS->DB->Query($q);
130: 		$amsg="Created New Alert Action";
131: 		break;
132: 		
133: 		case "action_delete":
134: 		if (!isset($_REQUEST['confirmed']))
135: 			{
136: 			$back=urlencode("admin.php?aaid_del=".$_REQUEST['aaid_del']."&action=action_delete&confirmed=1");
137: 			$url="confirm.php?action=Delete+alert+action&back=".$back;
138: 			header("Location: ".$url);
139: 			exit();
140: 			}
141: 		// otherwise confirmed
142: 		$q="DELETE FROM fnalertaction WHERE aaid=".ss($_REQUEST['aaid_del']);
143: 		$NATS->DB->Query($q);
144: 		if ($NATS->DB->Affected_Rows()>0) $amsg="Alert Action Deleted";
145: 		else $amsg="Alert Action Delete Failed";
146: 		$q="DELETE FROM fnnalink WHERE aaid=".ss($_REQUEST['aaid_del']);
147: 		$NATS->DB->Query($q);
148: 		break;
149: 		
150: 		}
151: 	}
152: 
153: ob_end_flush();
154: Screen_Header("Administration Interface",1);
155: 
156: if (isset($_REQUEST['message'])) echo "<br><b>".$_REQUEST['message']."</b><br>";
157: if (isset($amsg)) echo "<br><b>".$amsg."</b><br>";
158: 
159: ?>
160: <br>
161: <b class="minortitle">Users</b><br><br>
162: 
163: <?php
164: function tul($l)
165: {
166: if ($l>9) return "Administrator";
167: if ($l>4) return "Power User";
168: if ($l>0) return "Normal User";
169: return "Disabled";
170: }
171: 
172: $q="SELECT username,realname,userlevel FROM fnuser";
173: $r=$NATS->DB->Query($q);
174: echo "<table border=0>";
175: echo "<tr><td><b>Username&nbsp;</b></td>";
176: echo "<td><b>Real Name</b></td><td><b>User Level</b></td><td><b>Password</b></td><td><b>Options</b></td></tr>";
177: while ($row=$NATS->DB->Fetch_Array($r))
178: 	{
179: 	echo "<form action=admin.php method=post>";
180: 	echo "<input type=hidden name=action value=save_user>";
181: 	echo "<input type=hidden name=username value=\"".$row['username']."\">";
182: 	echo "<tr><td>".$row['username']."</td>";
183: 	echo "<td><input type=text name=realname value=\"".$row['realname']."\" size=20 maxlength=120></td>";
184: 	echo "<td><select name=userlevel>";
185: 	echo "<option value=".$row['userlevel'].">".tul($row['userlevel'])."</option>";
186: 	echo "<option value=0>".tul(0)."</option>";
187: 	echo "<option value=1>".tul(1)."</option>";
188: 	echo "<option value=5>".tul(5)."</option>";
189: 	echo "<option value=10>".tul(10)."</option>";
190: 	echo "</select>";
191: 	echo "</td>";
192: 	echo "<td><input type=password name=pword value=\"_NOTTHIS_\" size=10 maxlength=128></td>";
193: 	echo "<td><input type=submit value=\"Save\"> <a href=admin.php?action=delete_user&username=".$row['username'].">Delete</a></td>";
194: 	echo "</tr>";
195: 	echo "</form>";
196: 	}
197: echo "<form action=admin.php method=post>";
198: echo "<input type=hidden name=action value=create_user>";
199: echo "<tr><td><input type=text name=username size=20 maxlength=60></td>";
200: echo "<td><input type=text name=realname size=20 maxlength=120></td>";
201: echo "<td><select name=userlevel>";
202: echo "<option value=1>".tul(1)."</option>";
203: echo "<option value=0>".tul(0)."</option>";
204: echo "<option value=5>".tul(5)."</option>";
205: echo "<option value=10>".tul(10)."</option>";
206: echo "</select></td>";
207: echo "<td><input type=password name=pword size=10 maxlength=60></td>";
208: echo "<td><input type=submit value=\"Create User\"></td>";
209: echo "</tr></form>";
210: echo "</table><br>";
211: echo "<br>";
212: $NATS->DB->Free($r);
213: 
214: echo "<b class=\"minortitle\">Test Sessions</b><br><br>";
215: $q="SELECT * FROM fntestrun ORDER BY trid DESC";
216: if (!isset($_REQUEST['ShowAllSessions'])) $q.=" LIMIT 0,5";
217: $r=$NATS->DB->Query($q);
218: echo "<table border=0>";
219: while ($row=$NATS->DB->Fetch_Array($r))
220: 	{
221: 	echo "<tr><td><a href=testrun.php?trid=".$row['trid'].">run/".$row['trid']."</a></td>";
222: 	echo "<td>".nicedt($row['startx'])." - ";
223: 	if ($row['finishx']>0) echo nicedt($row['finishx']);
224: 	else echo "Still Running";
225: 	echo " (<a href=log.php?f_entry=Tester+".$row['trid'].">System Logs</a>)";
226: 	echo "</td></tr>";
227: 	}
228: echo "</table>";
229: $NATS->DB->Free($r);
230: echo "<br>";
231: if (!isset($_REQUEST['ShowAllSessions'])) echo "<a href=admin.php?ShowAllSessions=1>Show All Testing Sessions</a><br><br>";
232: echo "<br>";
233: 
234: echo "<b class=\"minortitle\">Alert Actions</b><br><br>";
235: 
236: function aat_etype($type)
237: {
238: switch ($type)
239: 	{
240: 	case 0: return "Short";
241: 	case 1: return "Long";
242: 	default: return "Unknown";
243: 	}
244: }
245: 
246: function aat_esub($type)
247: {
248: switch ($type)
249: 	{
250: 	case 0: return "Blank";
251: 	case 1: return "Short";
252: 	case 2: return "Long";
253: 	default: return "Unknown";
254: 	}
255: }
256: 
257: function aat_atype($type)
258: {
259: switch($type)
260: 	{
261: 	case "": case "Disabled": return "Disabled";
262: 	case "email": return "EMail";
263: 	default: return "Unknown";
264: 	}
265: }
266: 
267: 
268: 
269: if (isset($_REQUEST['aaid']))
270: 	{ // view/edit aaid
271: 	$q="SELECT * FROM fnalertaction WHERE aaid=".ss($_REQUEST['aaid']);
272: 	$r=$NATS->DB->Query($q);
273: 	if (!$row=$NATS->DB->Fetch_Array($r))
274: 		{
275: 		echo "<b>Error Fetching AAID</b><br><br>";
276: 		Screen_Footer();
277: 		exit();
278: 		}
279: 	echo "<table border=0>";
280: 	echo "<form action=admin.php method=post>";
281: 	echo "<input type=hidden name=action value=save_aa>";
282: 	echo "<input type=hidden name=aaid value=".$_REQUEST['aaid'].">";
283: 	echo "<tr><td>ID : </td><td>action/".$_REQUEST['aaid']."</td></tr>";
284: 	
285: 	echo "<tr><td>Action Name : </td>";
286: 	echo "<td>";
287: 	echo "<input type=text name=aname size=30 maxlength=120 value=\"".$row['aname']."\">";
288: 	echo "</td></tr>";
289: 	
290: 	echo "<tr><td>Type : </td><td>";
291: 	echo "<select name=atype>";
292: 	echo "<option value=".$row['atype'].">".aat_atype($row['atype'])."</option>";
293: 	echo "<option value=Disabled>Disabled</option>";
294: 	echo "<option value=email>EMail</option>";
295: 	echo "</select>";
296: 	echo "</td></tr>";
297: 	
298: 	echo "<tr><td>Warnings : </td>";
299: 	if ($row['awarnings']==1) $s=" checked";
300: 	else $s="";
301: 	echo "<td><input type=checkbox name=awarnings value=1".$s."></td></tr>";
302: 	
303: 	echo "<tr><td>Decreases : </td>";
304: 	if ($row['adecrease']==1) $s=" checked";
305: 	else $s="";
306: 	echo "<td><input type=checkbox name=adecrease value=1".$s."></td></tr>";
307: 	
308: 	echo "<tr><td>Email From : </td>";
309: 	echo "<td>";
310: 	echo "<input type=text name=efrom size=30 maxlength=120 value=\"".$row['efrom']."\">";
311: 	echo "</td></tr>";
312: 	
313: 	echo "<tr><td>Email Subject : </td><td>";
314: 	echo "<select name=esubject>";
315: 	echo "<option value=".$row['esubject'].">".aat_esub($row['esubject'])."</option>";
316: 	echo "<option value=0>Blank</option>";
317: 	echo "<option value=1>Short</option>";
318: 	echo "<option value=2>Long</option>";
319: 	echo "</select>";
320: 	echo "</td></tr>";
321: 	
322: 	echo "<tr><td>Email Type : </td><td>";
323: 	echo "<select name=etype>";
324: 	echo "<option value=".$row['etype'].">".aat_etype($row['etype'])."</option>";
325: 	echo "<option value=0>Short</option>";
326: 	echo "<option value=1>Long</option>";
327: 	echo "</select>";
328: 	echo "</td></tr>";
329: 	
330: 	echo "<tr><td valign=top>Email To : </td><td>";
331: 	echo "<textarea name=etolist cols=40 rows=6>".$row['etolist']."</textarea>";
332: 	echo "</td></tr>";
333: 	
334: 	echo "<tr><td colspan=2><input type=submit value=\"Update Action\"> &nbsp; <a href=admin.php>Cancel Update</a> | ";
335: 	echo "<a href=admin.php?aaid=".$_REQUEST['aaid']."&action=action_test>Test Action</a> | ";
336: 	echo "<a href=admin.php?aaid_del=".$_REQUEST['aaid']."&action=action_delete>Delete Action</a>";
337: 	echo "</td></tr>";
338: 	
339: 	echo "</form></table><br><br>";
340: 	$NATS->DB->Free($r);
341: 	}
342: 
343: $q="SELECT aaid,atype,aname FROM fnalertaction";
344: $r=$NATS->DB->Query($q);
345: while ($row=$NATS->DB->Fetch_Array($r))
346: 	{
347: 	echo "<a href=admin.php?aaid=".$row['aaid'].">action/".$row['aaid']." : ".$row['aname']."</a> - ";
348: 	echo aat_atype($row['atype']);
349: 	echo "<br>";
350: 	}
351: 
352: echo "<br><a href=admin.php?action=action_create><b>Create New Alert Action</b></a><br>";
353: echo "<br><br>";
354: 
355: echo "<b class=\"minortitle\">System Logs</b><br><br>";
356: echo "<a href=log.php>System Event Log</a><br><br>";
357: 
358: echo "<br><br>";
359: 
360: echo "<b class=\"minortitle\">Variables</b> ".hlink("Variable")."<br><br>";
361: $q="SELECT * FROM fnconfig ORDER BY fnc_var ASC";
362: $r=$NATS->DB->Query($q);
363: echo "<table border=0>";
364: while ($row=$NATS->DB->Fetch_Array($r))
365: 	{
366: 	echo "<form action=admin.php method=post>";
367: 	echo "<input type=hidden name=action value=var_save>";
368: 	echo "<input type=hidden name=orig_var value=\"".$row['fnc_var']."\">";
369: 	echo "<input type=hidden name=orig_val value=\"".$row['fnc_val']."\">";
370: 	echo "<tr><td><input type=text size=20 maxlength=60 name=new_var value=\"".$row['fnc_var']."\"> ";
371: 	echo "</td>";
372: 	echo "<td>=</td>";
373: 	echo "<td><input type=text size=20 maxlength=60 name=new_val value=\"".$row['fnc_val']."\"></td>";
374: 	echo "<td><input type=submit value=\"Save\"> ";
375: 	echo hlink("Var:".$row['fnc_var']);
376: 	echo "</td>";
377: 	echo "</tr>";
378: 	echo "</form>";
379: 	}
380: echo "<form action=admin.php method=post>";
381: echo "<input type=hidden name=action value=var_new>";
382: echo "<tr><td><input type=text size=20 maxlength=60 name=new_var value=\"\"></td>";
383: echo "<td>=</td>";
384: echo "<td><input type=text size=20 maxlength=60 name=new_val value=\"\"></td>";
385: echo "<td><input type=submit value=\"Create\"></td>";
386: echo "</tr>";
387: echo "</form>";
388: echo "</table>";
389: 
390: ?>
391: 
392: 
393: <?php
394: Screen_Footer();
395: ?>
396: