// Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . global $HTTP_POST_VARS, $HTTP_GET_VARS; include('authenticate.php'); include('display_view.php'); if (isset($reset_filters)) { //$filter_shard = ""; $filter_server = ""; $filter_service = ""; $filter_entity = ""; } $HTTP_VARS = array_merge($HTTP_POST_VARS, $HTTP_GET_VARS); unset($sel); unset($tid); unset($tname); unset($updateResult); unset($overriden); if (isset($active_player) && $active_player != "") { $arr = explode(',', $active_player); foreach($arr as $player) { $pl = explode(' ', $player); nel_query("*.*.EGS.loadPlayer ".$pl[0], $dummyResult); nel_query("*.*.EGS.activePlayer ".$pl[0]." ".$pl[1], $dummyResult); } } if (isset($current_tid) && $current_tid != "") $tid = $current_tid; $updatedShardAnnot = false; // select table and display name foreach ($HTTP_VARS as $var => $value) { if (strncmp($var, "selectTid_", 10) == 0) $tid = (int)substr($var, 10); else if (strncmp($var, "upd_annot_button_", 17) == 0) { $shard = substr($var, 17); if ($shardLockState[$shard]['lock_state'] == 1) { $annot = $GLOBALS["upd_annot_text_".$shard]; $result = sqlquery("SELECT shard FROM shard_annotation WHERE shard='$shard'"); if (!$result || sqlnumrows($result) == 0) sqlquery("INSERT INTO shard_annotation SET shard='$shard'"); sqlquery("UPDATE shard_annotation SET annotation='$annot', user='$uid', post_date=NOW() WHERE shard='$shard'"); $updatedShardAnnot = true; } } else if (strncmp($var, "upd_lock_button_", 16) == 0) { $shard = substr($var, 16); if ($shardLockState[$shard]['lock_state'] != 1) { $result = sqlquery("SELECT shard FROM shard_annotation WHERE shard='$shard'"); if (!$result || sqlnumrows($result) == 0) sqlquery("INSERT INTO shard_annotation SET shard='$shard', annotation='locked by $admlogin', user='$uid', post_date=NOW()"); sqlquery("UPDATE shard_annotation SET lock_user='$uid', lock_ip='$REMOTE_ADDR', lock_date=NOW() WHERE shard='$shard'"); $updatedShardAnnot = true; } } else if (strncmp($var, "upd_unlock_button_", 18) == 0) { $shard = substr($var, 18); if ($shardLockState[$shard]['lock_state'] == 1) { $result = sqlquery("SELECT shard FROM shard_annotation WHERE shard='$shard'"); if (!$result || sqlnumrows($result) == 0) sqlquery("INSERT INTO shard_annotation SET shard='$shard', annotation='locked by $admlogin', user='$uid', post_date=NOW()"); sqlquery("UPDATE shard_annotation SET lock_user='0' WHERE shard='$shard'"); $updatedShardAnnot = true; } } } if ($updatedShardAnnot) { getShardLockState(); } if (isset($select_view) && $select_view != "") $tname = explode(',', $select_view); if (isset($tname) && count($tname)>0 && !isset($tid)) { $found = false; foreach($tname as $tbname) { $result = sqlquery("SELECT tid, name FROM view_table WHERE uid='$uid' AND name='$tbname'"); if ($result && ($arr=sqlfetch($result))) { $tid = $arr["tid"]; $tname = $tbname; $found = true; break; } $result = sqlquery("SELECT tid, name FROM view_table WHERE uid='$gid' AND name='$tbname'"); if ($result && ($arr=sqlfetch($result))) { $tid = $arr["tid"]; $tname = $tbname; $found = true; break; } } if (!$found) { unset($tname); } } if (!isset($tid)) { $result = sqlquery("SELECT default_view FROM user, view_table WHERE user.uid='$uid' AND (view_table.uid='$uid' OR view_table.uid='$gid') AND view_table.tid=user.default_view"); if ($result && ($arr=sqlfetch($result))) { $tid=$arr["default_view"]; if ($tid == 0) unset($tid); } if (!isset($tid)) { $result = sqlquery("SELECT tid, name FROM view_table WHERE uid='$uid' ORDER BY ordering LIMIT 1"); if ($result && ($arr=sqlfetch($result))) { $tid = $arr["tid"]; $tname = $arr["name"]; } else { $result = sqlquery("SELECT tid, name FROM view_table WHERE uid='$gid' ORDER BY ordering LIMIT 1"); if ($result && ($arr=sqlfetch($result))) { $tid = $arr["tid"]; $tname = $arr["name"]; } } } } $refreshRate = 0; if (isset($tid)) $current_tid = $tid; $result = sqlquery("SELECT name, refresh_rate FROM view_table WHERE tid='$tid'"); if ($result && ($result=sqlfetch($result))) { $tname = $result["name"]; $refreshRate = $result["refresh_rate"]; } // get selection foreach ($HTTP_VARS as $var => $value) { if (strncmp($var, "select_", 7) == 0) { $sel_arr = explode(":", substr($var, 7)); if (!$keep_shard) $sel_arr[0] = '*'; if (!$keep_server) $sel_arr[1] = '*'; if (!$keep_service) $sel_arr[2] = '*'; $sel[] = $sel_arr[0].".".$sel_arr[1].".".$sel_arr[2].".*"; } else if (strncmp($var, "execServCommand_", 16) == 0) { $execServCommand = substr($var, 16); } } if (!isset($sel) || !is_array($sel)) $sel = array("*.*.*.*"); unset($shards); $selShards = array(); // add shard access to selection if ($admlogin != "root" && !$IsNevrax) { if (count($shardAccess)>0) { $unfiltered = $sel; unset($sel); foreach ($shardAccess as $sshard) { $shards[] = $sshard["shard"]; $filtershard = $sshard["shard"]; foreach ($unfiltered as $filter) { list($shard, $server, $service, $variable) = explode(".", $filter); if ($shard == "*" || $shard == $filtershard) { $sel[] = "$filtershard.$server.$service.$variable"; } } } } else { unset($sel); $shards = array(); } } else { $result = sqlquery("SELECT DISTINCT shard FROM service ORDER BY shard"); while ($result && ($arr=sqlfetch($result))) { $shards[] = $arr["shard"]; } } unset($cmdResult); if (isset($execServCommand) && isset($factPaths) && isset($execServParams) && isset($variableData[$execServCommand])) { // get command path $cmd = $variableData[$execServCommand]; $path = $cmd["path"]; $paths = expandQuery($factPaths); for ($i=0; $i 0) { echo "\n"; } echo "
\n"; echo "\n"; if (count($ownerTables)>0) { $clr = array("#E8E8E8", "#E0E0E0"); $o = 0; foreach ($ownerTables as $owner => $ownerViews) { $i=0; $bgcolor=$clr[$o]; $o = 1-$o; foreach ($ownerViews as $arr) { if ($i%4 == 0) { if ($i>0) echo "
\n"; else echo "\n"; } } echo "\n"; // $use_filter_shard = $filter_shard; $use_filter_server = $filter_server; $use_filter_service = $filter_service; $use_filter_entity = $filter_entity; if (!isset($use_filter_shard) || $use_filter_shard == "") $use_filter_shard = "*"; if (!isset($use_filter_server) || $use_filter_server == "") $use_filter_server = "*"; if (!isset($use_filter_service) || $use_filter_service == "") $use_filter_service = "*"; if (!isset($use_filter_entity) || $use_filter_entity == "") $use_filter_entity = "*"; $view_filter = $use_filter_shard.".".$use_filter_server.".".$use_filter_service.".".$use_filter_entity; $selAllShards = false; for ($i=0; $i\n"; if (count($shards) > 0) { echo "Shard shortcuts
 
\n"; } if ($tname == $arr["name"]) echo ""; else echo ""; ++$i; } echo "
$owner views
".$arr["name"]."
".$arr["name"]."
 
\n"; $i = 1; echo ""; echo ""; foreach ($shards as $link_shard) { if ($i%5 == 0 && $i>0) echo "
All
\n"; echo ""; echo ($selShards[$link_shard]) ? '"; ++$i; } echo "
' : ''; $alias = $shardLockState[$link_shard]['alias']; if ($alias == '') $alias = $link_shard; else $alias .= "($link_shard)"; echo "$alias"; if ($selShards[$link_shard]) echo ""; echo "
"; echo "
\n"; } echo "\n"; echo "\n"; echo "\n"; echo "
Refresh rate
\n"; echo "\n"; echo "\n"; if (count($sel) > 0) foreach ($sel as $s) echo "\n"; echo "
Selection
$s
\n"; echo "
Content of view $tname

\n"; echo "
\n"; $queryErrors = array(); // update values if ($upd_values) { unset($update); $tid = $current_tid; foreach ($HTTP_VARS as $var => $value) if (strncmp($var, "override_", 9) == 0) $overriden[substr($var, 9)]=$value; $shardAccessForbidden = array(); foreach ($HTTP_VARS as $var => $value) { if (strncmp($var, "updvar_", 7) == 0) { $vv = substr($var, 7); $prevValue = $GLOBALS["prevvar_$vv"]; $var_split = explode("|", $vv); $shard = $var_split[0]; $var_split = $var_split[count($var_split)-1]; $override = $overriden[$var_split]; if ($shardLockState[$shard]['lock_state'] != 1) { if (!$shardAccessForbidden[$shard]) { $shardAccessForbidden[$shard] = true; $queryErrors[] = "You can't update values on shard '$shard', access is not locked for you"; } continue; } if ($value != $prevValue) { $address = str_replace("|", ".", $vv); $update[] = "$address=$value"; } else if (isset($override) && $override != "" && $override != $prevValue) { $address = str_replace("|", ".", $vv); $update[] = "$address=$override"; } } else if (strncmp($var, "current_select_", 15) == 0) { $sel[] = $value; } } $sel = array_unique($sel); if (isset($update) && count($update > 0)) { if (count($update) > 1) { $query = "[".join(",", $update)."]"; $query = factorizeQuery($query); } else $query = $update[0]; $executeQuery = $query; $bef = microtime(); logUser($uid, "UPDATE=".$executeQuery); $qstate = nel_query($executeQuery, $updateResult); $aft = microtime(); list($usec, $sec) = explode(" ", $bef); $bef = ((float)$sec + (float)$usec); list($usec, $sec) = explode(" ", $aft); $aft = ((float)$sec + (float)$usec); $tm = (int)(($aft-$bef)*1000.0); $queryResult = "Executed $executeQuery
$tm milliseconds computation time
\n"; } } else if (isset($executeQuery)) { $bef = microtime(); $qstate = nel_query($executeQuery, $updateResult); $aft = microtime(); list($usec, $sec) = explode(" ", $bef); $bef = ((float)$sec + (float)$usec); list($usec, $sec) = explode(" ", $aft); $aft = ((float)$sec + (float)$usec); $tm = (int)(($aft-$bef)*1000.0); $queryResult = "Executed $executeQuery
$tm milliseconds computation time
\n"; } if ($updateResult) { buildVariableEnv($uid, $gid, $tid, $vardisp, $bounds, $privilege, $tree, $condensed, $autoDisplay); displayResult($updateResult, $vardisp, $bounds, $privilege); } else { // send select request if (count($sel) > 0) $sel = array_unique($sel); if (count($sel) == 1 && $sel[0] == "") unset($sel); $queryResult = displayViewTable($uid, $gid, $tid, $sel); } echo "\n"; $i=0; if (count($sel) > 0) foreach ($sel as $selec) echo "\n"; if (isset($tid) && $tid != "") { $result = sqlquery("SELECT view_row.name AS name, variable.vid AS vid FROM view_row, variable WHERE tid='$tid' AND variable.command='command' AND view_row.vid=variable.vid ORDER BY ordering"); if ($result && sqlnumrows($result) > 0) { echo "

Service commands The commands are sent to all services seen in the view above
\n"; echo "Command parameters
\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; $numInCol = 0; while ($result && ($arr=sqlfetch($result))) { if ($numInCol >= 5 || $arr["name"] == 'SEPARATOR') { echo "
\n"; $numInCol = 0; } if ($arr["name"] != 'SEPARATOR') { echo "\n"; ++$numInCol; } } if (isset($listPath) && count($listPath) > 0) { $address = "[".join(",", $listPath)."]"; $address = factorizeQuery($address); echo "\n"; } echo "
\n"; if (isset($cmdResult)) { echo "
Result of command '$fullPath $execServParams':
\n"; echo "
\n"; echo "
$cmdResult
\n"; echo "
\n"; } } } if (count($queryErrors) > 0) { echo "
Execution errors:\n"; foreach ($queryErrors as $error) echo "
$error\n"; } echo "

$queryResult\n"; echo "
\n"; function lvcmp($a, $b) { return ($a["path"] == $b["path"] ? 0 : $a["path"] < $b["path"] ? -1 : 1); } if (isset($tid) && $tid != "" && count($listPath) > 0) { $result = sqlquery("SELECT view_row.name AS name, variable.vid, variable.path, warning_bound, error_bound, alarm_order FROM view_row, variable WHERE tid='$tid' AND variable.vid=view_row.vid AND graph!='0' ORDER BY name"); if ($result && sqlnumrows($result) > 0) { unset($listVars); while ($result && ($arr=sqlfetch($result))) { $gname = $arr["name"]; $gvid = $arr["vid"]; $gfilter = $arr["path"]; $gwarn = $arr["warning_bound"]; $gerr = $arr["error_bound"]; $gord = $arr["alarm_order"]; for ($i=0; $i $varpath, "name" => $gname, "warn" => $gwarn, "err" => $gerr, "order" => $gord); } } if (count($listVars) > 0) { usort($listVars, "lvcmp"); echo "

View Graphs

\n"; echo "\n"; echo "\n"; echo "
\n"; $counter = 0; // remove too old picture files // opendir for scanning gif files if ($dir = @opendir($gifoutputpath)) { unset($eraseFiles); $curtime = time(); while($file = readdir($dir)) { if (substr($file, 0, 7) == "tmppic_") { $fstats = stat("$gifoutputpath/$file"); if ($fstats[9] < $curtime - $gifpersistence) $eraseFiles[] = "$gifoutputpath/$file"; } } closedir($dir); if (count($eraseFiles) > 0) foreach ($eraseFiles as $file) unlink($file); } mt_srand((float) microtime()*1000000); $randFilename = "tmppic_".mt_rand(10000, 99999); foreach ($listVars as $var) { $rrdvar = $var["path"]; $rrdpath = $rrdrootpath."/".$rrdvar.".rrd"; $rrdname = $var["name"]; $rrdwarn = $var["warn"]; $rrderr = $var["err"]; $rrdord = strtoupper($var["order"]); echo "\n"; // generate a temp filename $tempFilename_0 = "$gifhttplocation/".$randFilename."_".$counter."_0.gif"; $tempFilename_1 = "$gifhttplocation/".$randFilename."_".$counter."_1.gif"; $tempFilename_2 = "$gifhttplocation/".$randFilename."_".$counter."_2.gif"; $tempFilenameout_0 = "$gifoutputpath/".$randFilename."_".$counter."_0.gif"; $tempFilenameout_1 = "$gifoutputpath/".$randFilename."_".$counter."_1.gif"; $tempFilenameout_2 = "$gifoutputpath/".$randFilename."_".$counter."_2.gif"; ++$counter; // generate picture according to the temp filename unset($result); $rrdDEF = "DEF:val=$rrdpath:var:AVERAGE"; $rrdDraw = ""; if ($rrdwarn != -1) { $rrdDEF .= " CDEF:warn=val,$rrdwarn,$rrdord,val,0,IF"; $rrdDraw .= "AREA:warn#FFCC88 "; } if ($rrderr != -1) { $rrdDEF .= " CDEF:err=val,$rrderr,$rrdord,val,0,IF"; $rrdDraw .= "AREA:err#FF4422 "; } $rrdDraw .= "LINE2:val#0000FF"; $execStr = "rrdtool graph $tempFilenameout_0 --start -1200 $rrdDEF $rrdDraw"; //echo "exec(\"$execStr\")
\n"; exec($execStr, $result, $retcode1); // echo ""; $execStr = "rrdtool graph $tempFilenameout_1 --start -10800 $rrdDEF $rrdDraw"; //echo "exec(\"$execStr\")
\n"; exec($execStr, $result, $retcode2); // echo ""; $execStr = "rrdtool graph $tempFilenameout_2 --start -86400 $rrdDEF $rrdDraw"; //echo "exec(\"$execStr\")
\n"; exec($execStr, $result, $retcode3); // echo ""; echo ""; echo ""; if ($retcode1 || $retcode2 || $retcode3) { echo "RRDTool output:
\n"; print_r($result); echo "
\n"; } } echo "
$rrdvar (using path $rrdpath)
\n"; } } } htmlEpilog(); //print_r($shardLockState); ?>