2 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
3 // Copyright (C) 2010 Winch Gate Property Limited
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 global $HTTP_POST_VARS, $HTTP_GET_VARS;
19 $publicAccess = false;
20 include('authenticate.php');
22 // -----------------------------
27 // remove user, ask for confirmation
28 if (isset($rmUid) && isset($uuid) && $uuid!=$uid)
30 $result = sqlquery("SELECT login FROM user WHERE uid='$uuid'");
31 if ($result && mysql_num_rows($result) == 1)
33 htmlProlog($_SERVER['PHP_SELF'], "Administration");
34 $arr = mysql_fetch_array($result);
35 echo "You are about to delete user ".$arr["login"]." ($uid)<br>\n";
36 echo "Are you sure ?<br>\n";
37 echo "<font size=+6><a href='".$_SERVER['PHP_SELF']."?confirmRmUid=$uuid'>YES</a> | <a href='".$_SERVER['PHP_SELF']."?editUsers=true'>NO</a>\n";
42 // remove effectively user
43 else if (isset($confirmRmUid) && $confirmRmUid!=$uid)
45 sqlquery("DELETE FROM user WHERE uid='$confirmRmUid'");
46 $numUserDeleted = mysql_affected_rows();
47 sqlquery("DELETE FROM user_variable WHERE uid='$confirmRmUid'");
49 $result = sqlquery("SELECT tid FROM view_table WHERE uid='$confirmRmUid'");
50 sqlquery("DELETE FROM view_table WHERE uid='$confirmRmUid'");
52 while ($result && ($arr=mysql_fetch_array($result)))
54 sqlquery("DELETE FROM view_rows WHERE tid='".$arr["tid"]."'");
58 // force user password
59 else if (isset($forcePass))
61 sqlquery("UPDATE user SET password='".crypt($forcedPass, "NL")."' WHERE uid='$forcePass'");
63 // update user variables
64 else if (isset($updVars) && isset($editUser))
66 foreach ($HTTP_POST_VARS as $var => $value)
68 if (strncmp($var, "avv_", 4) != 0)
71 $vid = (int)substr($var, 4);
73 if (!isset($HTTP_POST_VARS[$ovar]))
76 $ovalue = $HTTP_POST_VARS[$ovar];
77 if ($value == $ovalue)
80 sqlquery("DELETE FROM user_variable WHERE uid='$editUser' AND vid='$vid'");
82 sqlquery("INSERT INTO user_variable SET privilege='$value', uid='$editUser', vid='$vid'");
86 $result = sqlquery("SELECT uid FROM user WHERE gid='$editUser' OR uid='$editUser'");
87 while ($result && ($arr=sqlfetch($result)))
89 sqlquery("DELETE FROM user_variable WHERE uid='".$arr["uid"]."' AND vid='$vid'");
91 sqlquery("INSERT INTO user_variable SET privilege='$value', uid='".$arr["uid"]."', vid='$vid'");
97 else if (isset($createUid) && isset($nulogin) && isset($nupassword) && isset($nuconfirmpassword) && isset($nugroup) && isset($nuallowedIp))
99 if ($nupassword != $nuconfirmpassword)
101 $error = $error."Password is invalid (password confirmation failed)<br>\n";
103 else if (strspn($nulogin, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") == 0)
105 $error = $error."Login '$admlogin' contains other characters than alphabetic and digits<br>\n";
109 $result = sqlquery("INSERT INTO user SET login='$nulogin', password='".crypt($nupassword, "NL")."', gid='$nugroup', allowed_ip='$nuallowedIp'");
110 if (mysql_affected_rows() != 1)
112 $error .= "Can't create user '$nulogin', database request failed (already used login?)<br>\n";
114 unset($nuconfirmpassword);
120 unset($nuconfirmpassword);
125 // reset user variables
128 $result = sqlquery("DELETE FROM user_variable WHERE uid='$editUser'");
130 // import user var setup
131 /* else if ($impVarSetup && isset($editUser) && isset($impUid))
133 $result = sqlquery("SELECT vid, privilege FROM user_variable WHERE uid='$impUid'");
134 if ($result && mysql_num_rows($result)>0)
136 $delete_query = "DELETE FROM user_variable WHERE uid='$editUser' AND (";
137 $copy_query = "INSERT INTO user_variable VALUES";
139 while ($result && ($arr=mysql_fetch_array($result)))
141 $delete_query .= ($first ? "" : " OR ") . "vid='".$arr["vid"]."'";
142 $copy_query .= ($first ? "" : ",") . " ('$editUser', '".$arr["vid"]."', '".$arr["privilege"]."')";
145 $delete_query .= ")";
146 // remove previous variables
147 sqlquery($delete_query);
149 sqlquery($copy_query);
150 //echo $delete_query."<br>".$copy_query;
151 if (mysql_affected_rows == -1)
152 $error .= "Import failed, database query failed<br>\n";
156 else if (isset($updUid) && isset($chugroup))
158 sqlquery("UPDATE user SET gid='$chugroup' WHERE uid='$updUid'");
161 // update user cookie
162 else if (isset($updUid) && isset($chucookie))
164 sqlquery("UPDATE user SET useCookie='$chucookie' WHERE uid='$updUid'");
167 // update user allowed ip
168 else if (isset($allowIp) && isset($allowedIp))
170 sqlquery("UPDATE user SET allowed_ip='$allowedIp' WHERE uid='$allowIp'");
175 else if (isset($rmVar) && isset($vid))
177 $editVariables = true;
178 sqlquery("DELETE FROM variable WHERE vid='$vid'");
179 if (mysql_affected_rows() != 1)
181 $error .= "Couldn't remove variable $vid/$chVarName, database request failed.<br>\n";
185 sqlquery("DELETE FROM user_variable WHERE vid='$vid'");
186 sqlquery("DELETE FROM view_row WHERE vid='$vid'");
187 $error .= "Removed effectively variable $vid/$chVarName/$chVarPath/$chVarState<br>\n";
191 else if (isset($createVid) && isset($nvname) && isset($nvpath) && isset($nvstate) && isset($chVarGroup) && isset($nvgraphupdate))
193 $editVariables = true;
194 $result = sqlquery("INSERT INTO variable SET name='$nvname', vgid='$chVarGroup', path='$nvpath', state='$nvstate', warning_bound='$nvwarning', error_bound='$nverror', alarm_order='$nvorder', graph_update='$nvgraphupdate', command=".(isset($nvvartype) ?
"'variable'" : "'command'"));
195 if (mysql_affected_rows() != 1)
197 $error .= "Can't create variable '$nvname', database request failed (already used variable name?)<br>\n";
203 $error .= "Effectively created variable '$nvname'<br>\n";
204 $result = sqlquery("SELECT vid FROM variable WHERE name='$nvname' AND vgid='$chVarGroup' AND path='$nvpath' AND state='$nvstate'");
205 if ($result && ($arr=sqlfetch($result)))
209 foreach ($HTTP_POST_VARS as $var => $value)
211 if (strncmp($var, "setgroup_", 9) != 0)
213 $id = (int)substr($var, 9);
216 if ($nvstate == 'rd' && $priv == 'rw')
221 $error .= "Set right '$priv' to users of group '$id':";
223 //$result = sqlquery("SELECT uid, login FROM user WHERE gid='$id'");
224 $query = "INSERT INTO user_variable VALUES ('$id', '$vid', '$priv')";
226 while ($result && ($arr=sqlfetch($result)))
228 $query .= (!$first ? "," : "")." ('".$arr["uid"]."', '$vid', '$priv')";
229 $error .= (!$first ? "," : "")." ".$arr["login"];
243 else if (isset($chVar) && isset($vid) && isset($chVarName) && isset($chVarPath) && isset($chVarState) && isset($chVarGraphUpdate))
245 $editVariables = true;
246 $result = sqlquery("UPDATE variable SET name='$chVarName', vgid='$chVarGroup', path='$chVarPath', state='$chVarState', warning_bound='$chVarWarning', error_bound='$chVarError', alarm_order='$chVarOrder', graph_update='$chVarGraphUpdate', command=".(isset($chVarType) ?
"'variable'" : "'command'")." WHERE vid='$vid'");
247 if (mysql_affected_rows() == -1)
249 $error .= "Can't update variable $vid properties, database query failed (name changed to already used?)<br>\n";
251 else if ($chVarState == "rd")
253 sqlquery("UPDATE user_variable SET privilege='rd' WHERE privilege='rw' AND vid='$vid'");
257 else if (isset($createVarGroup))
259 sqlquery("INSERT INTO variable_group SET name='$createVarGroup'");
262 else if (isset($rmVarGroup) && $rmVarGRoup!='1')
264 sqlquery("DELETE FROM variable_group WHERE vgid='$rmVarGroup'");
265 sqlquery("UPDATE variable SET vgid='1' WHERE vgid='$rmVarGroup'");
268 else if (isset($nshardaccess) && isset($editUser))
270 sqlquery("INSERT INTO shard_access SET uid='$editUser', shard='$nshardaccess'");
272 // remove shard access
273 else if (isset($rmShardAccess) && isset($editUser))
275 sqlquery("DELETE FROM shard_access WHERE uid='$editUser' AND shard='$rmShardAccess'");
277 // update shard access
278 else if (isset($chShardAccess) && isset($editUser))
280 sqlquery("DELETE FROM shard_access WHERE uid='$editUser'");
281 $query = "INSERT INTO shard_access VALUES";
283 if (isset($shardAccesses))
285 foreach($shardAccesses as $shard)
290 $query .= "('$editUser', '$shard')";
295 else if (isset($crViewCommand) && isset($nViewCommand) && isset($nViewCommandName) && isset($editTid))
297 sqlquery("INSERT INTO view_command SET name='$nViewCommandName', command='$nViewCommand', tid='$editTid'");
299 else if (isset($rmViewCommand) && isset($viewCommand) && isset($editTid))
301 sqlquery("DELETE FROM view_command WHERE name='$viewCommand' AND tid='$editTid'");
305 else if (isset($createServer) && isset($serverName) && isset($serverIP))
307 sqlquery("INSERT INTO server SET name='$serverName', address='$serverIP'");
310 else if (isset($rmServer) && isset($serverName))
312 sqlquery("DELETE FROM server WHERE name='$serverName'");
314 // update server name
315 else if (isset($updServerName) && isset($newServerName))
317 sqlquery("UPDATE server SET name='$newServerName' WHERE name='$updServerName'");
318 sqlquery("UPDATE service SET server='$newServerName' WHERE server='$updServerName'");
321 else if (isset($updServerIP) && isset($newServerIP))
323 sqlquery("UPDATE server SET address='$newServerIP' WHERE name='$updServerIP'");
327 else if (isset($createService) && isset($shardName) && isset($serverName) && isset($serviceName))
329 sqlquery("INSERT INTO service SET shard='$shardName', server='$serverName', name='$serviceName'");
332 else if (isset($rmService) && isset($serviceId))
334 sqlquery("DELETE FROM service WHERE service_id='$serviceId'");
337 else if (isset($newShardName) && isset($serviceId))
339 sqlquery("UPDATE service SET shard='$newShardName' WHERE service_id='$serviceId'");
341 // update server name
342 else if (isset($newServerName) && isset($serviceId))
344 sqlquery("UPDATE service SET server='$newServerName' WHERE service_id='$serviceId'");
346 // update service name
347 else if (isset($newServiceName) && isset($serviceId))
349 sqlquery("UPDATE service SET name='$newServiceName' WHERE service_id='$serviceId'");
352 else if ($editServices == 'update' && isset($updateList))
355 $services = explode("\r", $updateList);
357 $editServiceError = '';
358 $editServiceLog = '';
359 $insertList = array();
364 foreach ($services as $line)
369 if ($l == '' ||
$l[0] == '*')
372 if (!ereg("^[[:space:]]*([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]*$", $l, $regs))
374 $editServiceError = "Malformed string '$l' at line $lineCount";
379 list($reg, $shard, $server, $service) = $regs;
381 $insertList[] = array( 'shard' => $shard, 'server' => $server, 'service' => $service);
389 if (count($insertList) > 0)
391 foreach ($insertList as $l)
393 $query = "SELECT * FROM service WHERE shard='".$l['shard']."' AND server='".$l['server']."' AND name='".$l['service']."'";
394 $result = sqlquery($query);
395 if ($result && sqlnumrows($result) == 0)
397 $updateLog .= '<li>updated/inserted service '.$l['shard'].'.'.$l['server'].'.'.$l['service']."</li>\n";
403 $query = 'DELETE FROM service';
404 //echo $query."<br>\n";
405 $result = sqlquery($query);
410 if (count($insertList) > 0)
412 foreach ($insertList as $l)
414 $query = "INSERT INTO service SET shard='".$l['shard']."', server='".$l['server']."', name='".$l['service']."'";
415 //echo $query."<br>\n";
421 $editServiceLog .= "Successfully updated $insertSuccess services in database:\n<ul>\n".$updateLog."</ul>";
422 $editServiceError = '';
426 $editServiceError = 'Failed to delete all services from database';
431 else if ($editServers == 'update' && isset($updateList))
434 $servers = explode("\r", $updateList);
436 $editServerError = '';
438 $insertList = array();
443 foreach ($servers as $line)
448 if ($l == '' ||
$l[0] == '*')
451 if (!ereg("^[[:space:]]*([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]*$", $l, $regs))
453 $editServiceError = "Malformed string '$l' at line $lineCount";
458 list($reg, $server, $ip) = $regs;
460 $insertList[] = array( 'server' => $server, 'ip' => $ip);
468 if (count($insertList) > 0)
470 foreach ($insertList as $l)
472 $query = "SELECT * FROM server WHERE name='".$l['server']."' AND address='".$l['ip']."'";
473 $result = sqlquery($query);
474 if ($result && sqlnumrows($result) == 0)
476 $updateLog .= '<li>updated/inserted server '.$l['server'].' at '.$l['ip']."</li>\n";
482 $query = 'DELETE FROM server';
483 //echo $query."<br>\n"; $result=true;
484 $result = sqlquery($query);
489 if (count($insertList) > 0)
491 foreach ($insertList as $l)
493 $query = "INSERT INTO server SET name='".$l['server']."', address='".$l['ip']."'";
494 //echo $query."<br>\n";
500 $editServerLog .= "Successfully updated $insertSuccess servers in database:\n<ul>\n".$updateLog."</ul>";
501 $editServerError = '';
505 $editServerError = 'Failed to delete all servers from database';
510 // -----------------------------
513 htmlProlog($_SERVER['PHP_SELF'], "Administration");
514 subBar( array( "Users" => $_SERVER['PHP_SELF']."?editUsers=true",
515 "Variables" => $_SERVER['PHP_SELF']."?editVariables=true",
516 "Services" => $_SERVER['PHP_SELF']."?editServices=true",
517 "Servers" => $_SERVER['PHP_SELF']."?editServers=true",
518 "Shards" => $_SERVER['PHP_SELF']."?editShards=true" ));
520 echo "Administration tools<br>\n";
523 echo "<b>Reported errors:</b><br>\n$error<br>";
525 if (!$editUser && !$editUsers && !$editVariables && !$editShards && !$editServices && !$editServers)
528 // ---------------------------------------------------------------------------------
529 // edit a single user
530 // ---------------------------------------------------------------------------------
533 $resURL = $_SERVER['PHP_SELF']."?editUser=$editUser&selGroup=$selGroup";
535 $result = sqlquery("SELECT * FROM user WHERE uid='$editUser'");
536 if ($result && ($arr=mysql_fetch_array($result)))
538 $editLogin = $arr["login"];
539 $defaultView = $arr["default_view"];
540 $userGroup = $arr["gid"];
542 echo "<b>$editLogin variables/views setup edit</b><br><br>\n";
544 echo "<b>User variables setup</b><br>";
545 echo "<table cellpadding=0 cellspacing=0><tr valign=top><td>\n";
547 // User variables state display/modify
555 $result = sqlquery("SELECT * FROM variable_group ORDER BY name");
556 while ($result && ($arr=mysql_fetch_array($result)))
558 if ((!isset($selGroup) ||
$selGroup == "") && $arr["name"] == "NoGroup")
559 $selGroup = $arr["vgid"];
560 $groups[$arr["vgid"]] = $arr["name"];
563 $result = sqlquery("SELECT vid, variable.name AS name, path, state, variable.vgid AS vgid, variable_group.name AS group_name FROM variable, variable_group WHERE variable.vgid=variable_group.vgid".($selGroup>0 ?
" AND variable.vgid='$selGroup'" : "")." ORDER BY group_name, name");
564 while ($result && ($arr=mysql_fetch_array($result)))
566 $arr["priv"] = "inv";
570 $result = sqlquery("SELECT vid, privilege FROM user_variable WHERE uid='$editUser'");
571 while ($result && ($arr=mysql_fetch_array($result)))
573 for ($i=0; $i<count($vars) && $vars[$i]["vid"] != $arr["vid"]; ++
$i)
576 $vars[$i]["priv"] = $arr["privilege"];
579 $usrVarRights = getUserVariableRights($editUser, $userGroup);
581 echo "<table border=1>\n";
582 echo "<tr><th>Variable</th><form method=post action='".$_SERVER['PHP_SELF']."?editUser=$editUser'><th>";
583 echo "<select name='selGroup' onChange='submit()'>";
585 foreach ($groups as $vgid => $group )
586 echo "<option value='$vgid'".($selGroup == $vgid ?
" selected" : "").">$group";
587 echo "<option value='-1'".($selGroup == "-1" ?
" selected" : "").">All groups";
589 echo "</th></form><th>Path</th><th>Rights</th></tr>";
590 echo "<form method=post action='$resURL'>\n";
593 foreach ($vars as $var => $state)
595 $vid = $state["vid"];
597 $usrVar = $usrVarRights[$vid];
598 $vinherit = $usrVar[0];
599 $vstate = $usrVar[$vinherit];
601 echo "<tr><td>".$state["name"]."</td>".
602 "<td>".$state["group_name"]."</td>".
603 "<td>".$state["path"]."</td>".
604 "<td><select name='avv_$vid'>";
608 echo "<option value='inv' selected>Inherit ".($vstate == "none" ?
"unavailable" : ($vstate == "rd" ?
"read only" : "read write")).($vinherit == 1 ?
" (from variable)" : " (from group)");
609 echo "<option value='none'>Override unavailable";
610 echo "<option value='rd'>Override read only";
611 if ($state["state"] == "rw")
612 echo "<option value='rw'>Override read write";
616 if ($editUser==$userGroup)
617 echo "<option value='inv'>Inherit ".($usrVar[1] == "rd" ?
"read only" : "read write")." (from variable)";
619 echo "<option value='inv'>Inherit ".(!isset($usrVar[2]) ?
($usrVar[1] == "rd" ?
"read only" : "read write")." (from variable)" : ($usrVar[2] == "none" ?
"unavailable" : ($usrVar[2] == "rd" ?
"read only" : "read write"))." (from group)" );
620 echo "<option value='none'".($vstate == "none" ?
" selected" : "").">Override unavailable";
621 echo "<option value='rd'".($vstate == "rd" ?
" selected" : "").">Override read only";
622 if ($state["state"] == "rw")
623 echo "<option value='rw'".($vstate == "rw" ?
" selected" : "").">Override read write";
625 echo "</select><input type=hidden name='aovv_$vid' value='".$state["priv"]."'></td></tr>\n";
628 "<option value='inv'".($vstate == "none" ? " selected" : "").">Unavailable".
629 "<option value='none'".($state["priv"] == "none" ? " selected" : "").">Unavailable".
630 "<option value='rd'".($state["priv"] == "rd" ? " selected" : "").">Read only".
631 ($state["state"] == "rw" ? "<option value='rw'".($state["priv"] == "rw" ? " selected" : "").">Read Write" : "").
632 "</select><input type=hidden name='aovv_$vid' value='".$state["priv"]."'></td></tr>\n";
639 foreach ($vars as $var => $state)
641 $vid = $state["vid"];
642 echo "<tr><td>".$state["name"]."</td>".
643 "<td>".$state["group_name"]."</td>".
644 "<td>".$state["path"]."</td>".
645 "<td><select name='avv_$vid'>".
646 "<option value='inv'".($state["priv"] == "inv" ? " selected" : "").">Invisible".
647 "<option value='none'".($state["priv"] == "none" ? " selected" : "").">Unavailable".
648 "<option value='rd'".($state["priv"] == "rd" ? " selected" : "").">Read only".
649 ($state["state"] == "rw" ? "<option value='rw'".($state["priv"] == "rw" ? " selected" : "").">Read Write" : "").
650 "</select><input type=hidden name='aovv_$vid' value='".$state["priv"]."'></td></tr>\n";
654 echo "<tr height=5><td colspan=4 align=center></td></tr>\n";
655 echo "<tr><td colspan=4 align=center><input type=submit name='updVars' value='Update'> <input type=submit name='resetVars' value='Reset all'></td></tr>\n";
656 echo "</form></table><br>\n";
658 echo "</td><td width=30>\n</td><td align=left>\n";
660 if ($editUser != $uid)
662 echo "<table border=1>\n";
663 echo "<tr><th>Shard accesses</th></tr>\n";
665 $res = sqlquery("SELECT shard FROM shard_access WHERE uid='$editUser'");
667 while ($res && ($arr=sqlfetch($res)))
668 $shards[$arr["shard"]] = true;
670 $result = sqlquery("SELECT DISTINCT shard FROM service");
671 echo "<tr><form method=post action='$resURL&chShardAccess=true'><td align=center>";
672 echo "<select multiple size=".(sqlnumrows($result))." name='shardAccesses[]'>";
673 // display all shards and select if in user list
674 while ($result && ($arr = sqlfetch($result)))
676 $shard = $arr["shard"];
677 echo "<option value='$shard'".($shards[$shard] ?
" selected" : "").">$shard ";
679 echo "</select></td></tr>";
680 echo "<tr><td align=center><input type=submit value='Update'></td></form></tr>\n";
681 echo "</table><br>\n";
684 echo "</td><td width=30>\n</td><td align=center>\n";
686 echo "<table cellpadding=0 cellspacing>\n";
687 // Variable setup import form
688 echo "<tr><form method=post action='$resURL'><input type=hidden name=editUser value='$editUser'>\n";
689 echo "<td align=right><b>Import</b> variables setup from user </td>\n";
690 echo "<td><select name=impUid>\n";
691 $result = sqlquery("SELECT login, uid FROM user WHERE uid!='$editUser' ORDER BY login");
692 while ($result && ($arr=mysql_fetch_array($result)))
694 echo "<option value='".$arr["uid"]."'>".$arr["login"]."\n";
696 echo "</select></td>\n";
697 echo "<td><input type=submit name=impVarSetup value='Import'></td>\n";
698 echo "</tr></form>\n";
700 echo "<tr><td colspan=3><hr></td></tr>\n";
704 echo "</td></tr></table>\n";
707 echo "<b>User views setup</b>\n";
708 echo "<table><tr valign=top><td>\n";
710 echo "<table border=1 cellpadding=2><tr><th>Views</th></tr>\n";
711 $result = sqlquery("SELECT name, tid FROM view_table WHERE uid='$editUser' ORDER BY ordering");
712 while ($result && ($arr=sqlfetch($result)))
714 $disp = "<a href='$resURL&editTid=".$arr["tid"]."'>".$arr["name"]."</a>";
715 $bgcolor = ($editTid == $arr["tid"] ?
" bgcolor=#eeeeee" : "");
716 if ($arr["tid"] == $defaultView)
717 echo "<tr><td$bgcolor> <b>$disp</b> </td></tr>\n";
719 echo "<tr><td$bgcolor> $disp </td></tr>\n";
723 echo "</td><td width=30>\n";
727 if (isset($editTid) && $editTid != "")
729 echo "<b>Variables</b><br>\n";
730 echo "<table border=1 cellpadding=2><tr><th>User name</th><th>System name</th><th>Path</th><th>User filter</th></tr>\n";
731 $result = sqlquery("SELECT view_row.name AS name, variable.name AS sname, path, filter FROM view_row, variable WHERE tid='$editTid' AND view_row.vid=variable.vid ORDER BY ordering");
732 while ($result && ($arr=sqlfetch($result)))
734 echo "<tr><td>".$arr["name"]."</td><td>".$arr["sname"]."</td><td>".$arr["path"]."</td><td>".$arr["filter"]."</td></tr>\n";
736 echo "</table><br>\n";
738 echo "<b>Commands</b><br>\n";
739 echo "<table border=1 cellpadding=2><tr><th>Name</th><th colspan=2>Service command</th></tr>\n";
740 $result = sqlquery("SELECT name, command FROM view_command WHERE tid='$editTid' ORDER BY name");
741 while ($result && ($arr=sqlfetch($result)))
743 echo "<tr><form method=post action='$resURL&editTid=$editTid'><td>".$arr["name"]."</td><td>".$arr["command"]."</td><td><input type=hidden name=viewCommand value='".$arr["name"]."'><input type=submit name='rmViewCommand' value='Delete'></td></form></tr>\n";
745 echo "<tr><td colspan=3 height=5></td></tr>\n";
746 echo "<tr><form method=post action='$resURL&editTid=$editTid'><td><input name=nViewCommandName size=16 maxlength=32></td><td><input name=nViewCommand size=16 maxlength=32></td><td><input type=submit name='crViewCommand' value='Create'></td></form></tr>\n";
747 echo "</table><br>\n";
750 echo "</td></tr></table><br>\n";
752 // user activity display
753 echo "<b>User activity</b><br>\n";
754 echo "<textarea rows=15 cols=200 readOnly style='font-family: Terminal, Courier; font-size: 10pt;' nowrap>";
756 $logfilename = $userlogpath."/".$editLogin.".log";
758 exec("tail -n 40 $logfilename", $resExec);
760 echo join("\n", $resExec);
762 echo "</textarea><br>\n";
766 echo "User $editUser not found in database.<br><br>";
770 // ---------------------------------------------------------------------------------
772 // ---------------------------------------------------------------------------------
775 echo "<b>Users setup</b><br><br>\n";
778 unset($actualGroups);
779 $result = sqlquery("SELECT login AS gname, uid, gid FROM user");
780 while ($result && ($arr=mysql_fetch_array($result)))
782 $groupNames[$arr["gname"]] = $arr["uid"];
783 if ($arr["gid"] == $arr["uid"])
784 $actualGroups[$arr["gname"]] = $arr["uid"];
787 echo "<table border=1>\n";
788 echo "<tr><th>Login</th><th>Uid</th>";
789 echo "<form method=post action='".$_SERVER['PHP_SELF']."'><th><select name=uViewGroups onChange='submit()'>";
790 echo "<option value=''".((!isset($uViewGroups) ||
$uViewGroups=='') ?
" selected" : "").">All Groups\n";
791 foreach($actualGroups as $cgname => $cgid)
792 echo "<option value='$cgid'".($cgid==$uViewGroups ?
" selected" : "").">$cgname\n";
793 echo "</select></th></form>";
794 echo "<th>Cookie</th><th>Force password</th><th>Allowed IP mask</th><th>Commands</th></tr>\n";
796 if (!isset($uViewGroups) ||
$uViewGroups == '')
797 $query = "SELECT uuser.login AS login, uuser.uid AS uid, uuser.useCookie AS useCookie, uuser.gid AS gid, ugroup.login AS gname, uuser.allowed_ip AS allowed_ip FROM user AS uuser, user AS ugroup WHERE uuser.gid=ugroup.uid ORDER BY uid";
799 $query = "SELECT uuser.login AS login, uuser.uid AS uid, uuser.useCookie AS useCookie, uuser.gid AS gid, ugroup.login AS gname, uuser.allowed_ip AS allowed_ip FROM user AS uuser, user AS ugroup WHERE uuser.gid=ugroup.uid AND uuser.gid='$uViewGroups' ORDER BY uid";
800 $result = sqlquery($query);
801 while ($result && ($arr=mysql_fetch_array($result)))
803 $ulogin = $arr["login"];
806 $ugname = $arr["gname"];
807 $uallowedip = $arr["allowed_ip"];
808 $uuseCookie = ($arr["useCookie"] == "yes");
810 "<td><a href='".$_SERVER['PHP_SELF']."?editUser=$uuid'>$ulogin</a></td>\n".
812 "<form method=post action='".$_SERVER['PHP_SELF']."'>".
813 "<input type=hidden name=updUid value='$uuid'><td><select name=chugroup onChange='submit()'>\n";
814 foreach($groupNames as $cgname => $cgid)
815 echo "<option value='$cgid'".($cgid==$ugid ?
" selected" : "").">$cgname\n";
816 echo "</select></td></form>\n";
817 echo "<form method=post action='".$_SERVER['PHP_SELF']."'><input type=hidden name=updUid value='$uuid'><td><select name='chucookie' onChange='submit()'><option value='yes'".($uuseCookie ?
" selected" : "").">Yes<option value='no'".($uuseCookie ?
"" : " selected").">No</select></td></form>";
818 echo "<form method=post action='".$_SERVER['PHP_SELF']."'><input type=hidden name=forcePass value='$uuid'><td><input type=password name='forcedPass'></td></form>";
819 echo "<form method=post action='".$_SERVER['PHP_SELF']."'><input type=hidden name=allowIp value='$uuid'><td><input name='allowedIp' value='$uallowedip'></td></form>";
820 echo "<td><a href='".$_SERVER['PHP_SELF']."?confirmRmUid=$uuid' onClick=\"return confirm('You are about to delete user $ulogin')\">Delete</a></td></tr>\n";
822 echo "</table><br>\n";
824 $result = sqlquery("SELECT login, uid FROM user");
826 echo "<table border=1><form method=post action='".$_SERVER['PHP_SELF']."'>\n";
827 echo "<tr><th colspan=2>Create a new user</th></tr>\n";
828 echo "<tr><td>Login</td><td><input name=nulogin maxlength=16 size=16 value='$nulogin'></td></tr>\n";
829 echo "<tr><td>Group</td><td><select name=nugroup>\n";
830 while ($result && ($arr=mysql_fetch_array($result)))
831 echo "<option value='".$arr["uid"]."'>".$arr["login"]."\n";
832 echo "<tr><td>Allowed IP mask</td><td><input name=nuallowedIp maxlength=32 size=16 value='$nuallowedIp'></td></tr>\n";
833 echo "<tr><td>Password</td><td><input type=password name=nupassword maxlength=16 size=16></td></tr>\n";
834 echo "<tr><td>Renter password</td><td><input type=password name=nuconfirmpassword maxlength=16 size=16></td></tr>\n";
835 echo "<tr><td colspan=2 align=center><input type=submit name=createUid value='Create'></td></tr>\n";
836 echo "</form></table>\n";
839 // ---------------------------------------------------------------------------------
841 // ---------------------------------------------------------------------------------
844 echo "<b>Variables setup</b>".help("Variables")."<br><br>\n";
846 echo "<table cellpadding=0 cellspacing=0><tr valign=0><td>\n";
848 if ($importVarSetup && $importedVarSetup)
850 $result = sqlquery("SELECT name, vgid FROM variable_group");
852 while ($result && ($arr=mysql_fetch_array($result)))
854 if ((!isset($varGroup) ||
$varGroup=="") && $arr["name"] == "NoGroup")
855 $varGroup = $arr["vgid"];
856 $groups[$arr["vgid"]] = $arr["name"];
859 $array = explode("\n", $importedVarSetup);
861 if (count($array) > 0)
864 foreach ($groups as $vgid => $vgname)
865 $groupnames[$vgname] = $vgid;
867 foreach ($array as $varSetup)
871 list($vname, $vpath, $vstate, $vgname, $vwarn, $verr, $valarm, $vgraph, $vcmd) = explode("|", $varSetup);
873 $result = sqlquery("SELECT count(*) as count FROM variable WHERE name='$vname'");
874 if ($result && ($arr=sqlfetch($result)) && $arr["count"] == 0)
876 if (!isset($groupnames[$vgname]))
878 sqlquery("INSERT INTO variable_group SET name='$vgname'");
879 $result = sqlquery("SELECT vgid FROM variable_group WHERE name='$vgname'");
880 if ($result && ($arr=sqlfetch($result)))
882 $vgid = $arr["vgid"];
883 $groupnames[$vgname] = $vgid;
891 $vgid = $groupnames[$vgname];
895 sqlquery("INSERT INTO variable SET name='$vname', path='$vpath', state='$vstate', vgid='$vgid', warning_bound='$vwarn', error_bound='$verr', alarm_order='$valarm', graph_update='$vgraph', command='$vcmd'");
902 $result = sqlquery("SELECT name, vgid FROM variable_group");
904 while ($result && ($arr=mysql_fetch_array($result)))
906 if ((!isset($varGroup) ||
$varGroup=="") && $arr["name"] == "NoGroup") {
907 print "ERG! VARGROUP GUNNA BE: ".$arr["vgid"];
908 $varGroup = $arr["vgid"];
910 $groups[$arr["vgid"]] = $arr["name"];
914 $result = sqlquery("SELECT * FROM variable ORDER BY vgid, name");
916 $result = sqlquery("SELECT * FROM variable WHERE vgid='$varGroup' ORDER BY name");
917 echo "<table border=1>\n";
918 echo "<tr><th>Name</th><th>Vid</th><th>Group</th><th>Path</th><th>State</th><th>Warning</th><th>Error</th><th>Order</th><th>Graph</th><th>Variable</th><th colspan=2>Commands</th></tr>\n";
922 while ($result && ($arr=mysql_fetch_array($result)))
924 $name = $arr["name"];
926 $vgid = $arr["vgid"];
927 $path = $arr["path"];
928 $state = $arr["state"];
929 $warn_bound = $arr["warning_bound"];
930 $err_bound = $arr["error_bound"];
931 $alarm_order = $arr["alarm_order"];
932 $graph_update = $arr["graph_update"];
933 $var_type = $arr["command"];
935 if ($lastGroup != -1 && $lastGroup != $vgid)
936 echo "<tr height=5><td colspan=12></td></tr>\n";
939 echo "<tr><form method=post action='".$_SERVER['PHP_SELF']."?varGroup=$varGroup'><input type=hidden name=vid value='$vid'><input type=hidden name=chVar value='Update'>".
940 "<td><input name=chVarName maxlength=128 size=16 value='$name'></td>\n".
942 echo "<td><select name=chVarGroup onChange='submit()'>";
943 foreach ($groups as $chvgid => $chvgname)
944 echo "<option value='$chvgid'".($chvgid==$vgid ?
" selected":"").">$chvgname";
945 echo "</select></td>\n".
946 "<td><input name=chVarPath maxlength=255 size=32 value='$path'></td>\n".
947 "<td><select name=chVarState onChange='submit()'><option value='rd'".($state=="rd" ?
" selected":"").">Read only<option value='rw'".($state=="rw" ?
" selected":"").">Read write</select></td>".
948 "<td><input name=chVarWarning maxlength=11 size=11 value='$warn_bound'></td>".
949 "<td><input name=chVarError maxlength=11 size=11 value='$err_bound'></td>".
950 "<td><select name=chVarOrder onChange='submit()'><option value='gt'".($alarm_order=="gt" ?
" selected":"").">gt<option value='lt'".($alarm_order=="lt" ?
" selected":"").">lt</select></td>".
951 "<td><input name=chVarGraphUpdate maxlength=8 size=4 value='$graph_update'></td>".
952 "<td align=center><input type=checkbox name=chVarType".($var_type == "variable" ?
" checked" : "")." value='1'></td>".
953 "<td><input type=submit name=chVar value='Update'></td></form><form method=post action='".$_SERVER['PHP_SELF']."?varGroup=$varGroup'><td><input type=hidden name='vid' value='$vid'><input type=submit name=rmVar value='Delete' onClick=\"return confirm('You are about to delete a Variable')\"></td>".
956 echo "<tr height=10><td colspan=12></td></tr>\n";
957 if (!isset($nvpath)) $nvpath = "*.*.*.*[.*]";
958 if (!isset($nvstate)) $nvstate = "rd";
959 echo "<tr valign=top><form method=post action='".$_SERVER['PHP_SELF']."?editVariables=true&varGroup=$varGroup'><input type=hidden name=vid value='$vid'>".
960 "<td><input name=nvname maxlength=128 size=16 value='$nvname'></td>\n".
962 echo "<td><select name=chVarGroup>";
963 foreach ($groups as $chvgid => $chvgname)
964 echo "<option value='$chvgid'".($chvgid==$varGroup ?
" selected":"").">$chvgname";
965 echo "</select></td>\n".
966 "<td><input name=nvpath maxlength=255 size=32 value='$nvpath'></td>\n".
967 "<td><select name=nvstate><option value='rd'".($nvstate=="rd" ?
" selected":"").">Read only<option value='rw'".($nvstate=="rw" ?
" selected":"").">Read write</select></td>".
968 "<td><input name=nvwarning maxlength=11 size=11 value='-1'></td>".
969 "<td><input name=nverror maxlength=11 size=11 value='-1'></td>".
970 "<td><select name=nvorder><option value='gt'".($state=="gt" ?
" selected":"").">gt<option value='lt'".($state=="lt" ?
" selected":"").">lt</select></td>".
971 "<td><input name=nvgraphupdate maxlength=8 size=4 value='0'></td>".
972 "<td align=center><input type=checkbox name=nvvartype checked value='1'></td>".
973 "<td rowspan=2 colspan=2 align=center><input type=submit name=createVid value='Create'> ".help("Create Variable")."</td>".
975 echo "<tr><td></td><td colspan=9 align=center>\n";
977 echo "<table><tr><th></th><th width=80>Read Write</th><th width=80>Read only</th><th width=80>Invisible</th></tr>\n";
978 $result = sqlquery("SELECT uid, login FROM user WHERE uid=gid ORDER BY uid");
979 while ($result && ($arr=sqlfetch($result)))
981 echo "<tr><td>".$arr["login"]."</td>";
982 echo "<td align=center><input type=radio value='rw' name='setgroup_".$arr["uid"]."' checked></td>";
983 echo "<td align=center><input type=radio value='rd' name='setgroup_".$arr["uid"]."'></td>";
984 echo "<td align=center><input type=radio value='' name='setgroup_".$arr["uid"]."'></td>";
987 echo "</form></table>\n";
989 echo "</td><td></td></tr>\n";
990 echo "</table><br>\n";
992 echo "</td><td width=30> </td><td>\n";
995 echo "<tr><td align=center colspan=2>View by variable group</td></tr><tr><form method=post action='".$_SERVER['PHP_SELF']."?editVariables=true'>\n";
996 echo "<td align=center colspan=2><select name=varGroup onChange='submit()'>\n";
997 echo "<option value='-1'".($varGroup=="-1" ?
" selected":"").">All groups";
998 foreach ($groups as $vgid => $vgname)
999 echo "<option value='$vgid'".($vgid==$varGroup ?
" selected":"").">$vgname";
1000 echo "</select></td></form></tr>";
1002 echo "<tr><td colspan=2><hr></td></tr>\n";
1005 echo "<td align=center colspan=2>Create a variable group</td></tr><tr><form method=post action='".$_SERVER['PHP_SELF']."?varGroup=$varGroup&editVariables=true'>\n";
1006 echo "<td align=right><input name=createVarGroup size=16 maxlength=32></td><td><input type=submit value='Create'></td></form>\n";
1009 echo "<tr><td colspan=2><hr></td></tr>\n";
1011 echo "<tr><td align=center colspan=2>Delete a variable group</td></tr><tr><form method=post action='".$_SERVER['PHP_SELF']."?varGroup=$varGroup&editVariables=true'>\n";
1012 echo "<td align=right><select name=rmVarGroup>\n";
1013 foreach ($groups as $vgid => $vgname)
1015 echo "<option value='$vgid'".($vgid==$varGroup ?
" selected":"").">$vgname";
1016 echo "</select></td><td><input type=submit value='Delete'>\n";
1017 echo "</td></form></tr>";
1019 echo "<tr><td colspan=2><hr></td></tr>\n";
1022 echo "<td align=center colspan=2>Export variables setup</td></tr><tr><form method=post action='".$_SERVER['PHP_SELF']."?varGroup=$varGroup&editVariables=true'>\n";
1023 echo "<td align=center colspan=2><input type=submit name='exportVarSetup' value='Export'></td></form>\n";
1029 echo "</td></tr></table>\n";
1031 echo "<form method='post' action='".$_SERVER['PHP_SELF']."?varGroup=$varGroup&editVariables=true'>\n";
1032 echo "<b>Import/Exported setup</b> (use this to export to another admin tool):<br>\n";
1033 echo "<textarea rows=30 cols=160 name='importedVarSetup'>";
1034 if ($exportVarSetup)
1036 $result = sqlquery("SELECT * FROM variable ORDER BY vgid, name");
1037 while ($result && ($arr=sqlfetch($result)))
1038 echo $arr["name"]."|".$arr["path"]."|".$arr["state"]."|".$groups[$arr["vgid"]]."|".$arr["warning_bound"]."|".$arr["error_bound"]."|".$arr["alarm_order"]."|".$arr["graph_update"]."|".$arr["command"]."\n";
1040 echo "</textarea><br>\n";
1041 echo "<input type=submit name='importVarSetup' value='Import' onClick=\"return confirm('You are about to import setup')\">\n";
1045 // ---------------------------------------------------------------------------------
1046 // edit shard organization
1047 // ---------------------------------------------------------------------------------
1050 echo "<b>Shards setup</b>".help("Shards")."<br><br>\n";
1052 echo "<table cellpadding=0 cellspacing=0><tr valign=top><td>\n";
1054 if (!isset($serverOrder))
1055 $serverOrder = "name";
1057 if (!isset($serviceOrder))
1058 $serviceOrder = "shard, server, name";
1062 $result = sqlquery("SELECT * FROM server ORDER BY $serverOrder");
1063 echo "<table border=1><tr><th>Name</th><th>Address</th><th>Command</th></tr>\n";
1064 while ($result && ($arr=sqlfetch($result)))
1066 echo "<tr><form action='".$_SERVER['PHP_SELF']."?editShards=true&fshard=$fshard' method=post><td><input name=newServerName value=\"".$arr["name"]."\" size=16 maxlength=32><input type=hidden name=updServerName value=\"".$arr["name"]."\"></td></form>";
1067 echo "<form action='".$_SERVER['PHP_SELF']."?editShards=true&fshard=$fshard' method=post><td><input name=newServerIP value=\"".$arr["address"]."\" size=16 maxlength=32><input type=hidden name=updServerIP value=\"".$arr["name"]."\"></td></form>";
1068 echo "<form action='".$_SERVER['PHP_SELF']."?editShards=true&fshard=$fshard' method=post><td><input type=submit name=rmServer value=\"Delete\"><input type=hidden name=serverName value=\"".$arr["name"]."\"></td></form></tr>\n";
1069 $servers[] = $arr["name"];
1071 echo "<tr><form action='".$_SERVER['PHP_SELF']."?editShards=true&fshard=$fshard' method=post><td><input name=serverName size=16 maxlength=32></td><td><input name=serverIP size=16 maxlength=32></td><td><input type=submit name=createServer value=\"Create\"></td></form></tr>\n";
1074 echo "</td><td width=20> \n";
1079 else if ($fshard == "*")
1080 $result = sqlquery("SELECT * FROM service ORDER BY $serviceOrder");
1082 $result = sqlquery("SELECT * FROM service WHERE shard LIKE '%$fshard%' ORDER BY $serviceOrder");
1084 echo "<table border=1><tr><form method=post action='".$_SERVER['PHP_SELF']."?editShards=true'><th>Shard ";
1085 echo "<select name=fshard onChange='submit()'>";
1086 echo "<option value=''".($fshard=="" ?
" selected" : "").">No shard";
1087 echo "<option value='*'".($fshard=="*" ?
" selected" : "").">All shards";
1088 $res = sqlquery("SELECT DISTINCT shard FROM service");
1089 while ($res && ($arr=sqlfetch($res)))
1090 echo "<option value='".$arr["shard"]."'".($fshard==$arr["shard"] ?
" selected" : "").">".$arr["shard"];
1092 echo "</th></form><th>Server</th><th>Service</th><th>Command</th></tr>\n";
1093 while ($result && ($arr=sqlfetch($result)))
1095 echo "<tr><form action='".$_SERVER['PHP_SELF']."?editShards=true&fshard=$fshard' method=post><td><input name=newShardName value='".$arr["shard"]."' size=24 maxlength=32><input type=hidden name=serviceId value='".$arr["service_id"]."'></td></form>\n";
1096 echo "<form action='".$_SERVER['PHP_SELF']."?editShards=true&fshard=$fshard' method=post><input type=hidden name=serviceId value='".$arr["service_id"]."'><td>";
1097 echo "<select name=newServerName onChange='submit()'>";
1098 $foundServer = false;
1099 foreach ($servers as $server)
1101 echo "<option value='$server'";
1102 if ($server == $arr["server"])
1105 $foundServer = true;
1110 echo "<option value='".$arr["server"]."' selected>".$arr["server"];
1112 echo "</td></form><form action='".$_SERVER['PHP_SELF']."?editShards=true&fshard=$fshard' method=post><td><input name=newServiceName value='".$arr["name"]."' size=16 maxlength=32><input type=hidden name=serviceId value='".$arr["service_id"]."'></td></form>";
1113 echo "<form method=post action='".$_SERVER['PHP_SELF']."?editShards=true&fshard=$fshard'><td><input type=submit name=rmService value='Delete'><input type=hidden name=serviceId value='".$arr["service_id"]."'></td></form>";
1117 echo "<tr><form action='".$_SERVER['PHP_SELF']."?editShards=true&fshard=$fshard' method=post>";
1118 echo "<td><input name=shardName size=24 maxlength=32></td>\n";
1119 echo "<td><select name=serverName>";
1120 foreach ($servers as $server)
1121 echo "<option value='$server'>$server";
1122 echo "</select></td>";
1123 echo "<td><input name=serviceName size=16 maxlength=32></td>";
1124 echo "<td><input type=submit name=createService value='Create'></td></form>";
1129 echo "</td></tr></table>\n";
1134 echo "<b>Services setup</b>".help("Services")."<br><br>\n";
1136 if ($editServiceError != '')
1138 echo "<b><font color=#FF0000>WARNING: failed to rebuild services list: error '$editServiceError'. List is kept unmodified.</font></b><br><br>\n";
1141 if ($editServiceLog != '')
1143 echo "<b><font color=#0000FF>RESULT: $editServiceLog</font></b><br>\n";
1146 echo "<table cellpadding=0 cellspacing=0><tr valign=top><td>\n";
1147 echo "<form action='".$_SERVER['PHP_SELF']."?editServices=update' method=post>\n";
1148 echo "<textarea rows=30 cols=300 style='font-family: Terminal, Courier; font-size: 10pt;' name='updateList'>\n";
1150 $result = sqlquery("SELECT * FROM service ORDER BY shard, server, name");
1152 echo str_pad('* SHARD', 32)." ".str_pad('* SERVER', 32)." * SERVICE NAME\n";
1153 echo "*------------------------------------------------------------------------------------------------------------------------\n";
1155 while ($result && ($arr=sqlfetch($result)))
1157 echo str_pad($arr['shard'], 32)." ".str_pad($arr['server'], 32)." ".$arr['name']."\n";
1160 echo "</textarea>\n";
1161 echo "<input type='submit' name='update' value='Update'>\n";
1163 echo "</td></tr></table>\n";
1168 echo "<b>Servers setup</b>".help("Servers")."<br><br>\n";
1170 if ($editServerError != '')
1172 echo "<b><font color=#FF0000>WARNING: failed to rebuild servers list: error '$editServerError'. List is kept unmodified.</font></b><br><br>\n";
1175 if ($editServerLog != '')
1177 echo "<b><font color=#0000FF>RESULT: $editServerLog</font></b><br>\n";
1180 echo "<table cellpadding=0 cellspacing=0><tr valign=top><td>\n";
1181 echo "<form action='".$_SERVER['PHP_SELF']."?editServers=update' method=post>\n";
1182 echo "<textarea rows=30 cols=300 style='font-family: Terminal, Courier; font-size: 10pt;' name='updateList'>\n";
1184 echo str_pad('* SERVER NAME', 32)." * ADDRESS\n";
1185 echo "*------------------------------------------------------------------------------------------------------------------------\n";
1187 $result = sqlquery("SELECT * FROM server ORDER BY name, address");
1189 while ($result && ($arr=sqlfetch($result)))
1191 echo str_pad($arr['name'], 32)." ".$arr['address']."\n";
1194 echo "</textarea>\n";
1195 echo "<input type='submit' name='update' value='Update'>\n";
1197 echo "</td></tr></table>\n";