Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
* SQL code updates (INTERVAL added)
* Scheduled tasks timeout increased
* MySQL error with missing fields workaround (auto-reinstall modules)
* History functions update (value type cast)
* MySQL "text NOT NULL" fix
* XRay html encoding for values
  • Loading branch information
sergejey committed Oct 3, 2016
1 parent fc4e87a commit 0d48101
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 111 deletions.
3 changes: 2 additions & 1 deletion command.php
Expand Up @@ -106,7 +106,8 @@
processCommand($qrys[$i]);
*/
}
SQLExec('UPDATE terminals SET IS_ONLINE=0 WHERE (NOW()-LATEST_ACTIVITY)>30*60');
SQLExec('UPDATE terminals SET IS_ONLINE=0 WHERE LATEST_ACTIVITY < (NOW() - INTERVAL 30 MINUTE)');

}

?>
Expand Down
7 changes: 3 additions & 4 deletions lib/common.class.php
Expand Up @@ -10,12 +10,12 @@ function sayReply($ph, $level = 0, $replyto='') {
$source='';
if ($replyto) {
$terminal_rec=SQLSelectOne("SELECT * FROM terminals WHERE LATEST_REQUEST LIKE '%".DBSafe($replyto)."%' ORDER BY LATEST_REQUEST_TIME DESC LIMIT 1");
$orig_msg=SQLSelectOne("SELECT * FROM shouts WHERE SOURCE!='' AND MESSAGE LIKE '%".DBSafe($replyto)."%' AND (NOW()-ADDED)<=30 ORDER BY ADDED DESC LIMIT 1");
$orig_msg=SQLSelectOne("SELECT * FROM shouts WHERE SOURCE!='' AND MESSAGE LIKE '%".DBSafe($replyto)."%' AND ADDED>=(NOW() - INTERVAL 30 SECOND) ORDER BY ADDED DESC LIMIT 1");
if ($orig_msg['ID']) {
$source=$orig_msg['SOURCE'];
}
} else {
$terminal_rec=SQLSelectOne("SELECT * FROM terminals WHERE (NOW()-LATEST_REQUEST_TIME)<=5 ORDER BY LATEST_REQUEST_TIME DESC LIMIT 1");
$terminal_rec=SQLSelectOne("SELECT * FROM terminals WHERE LATEST_REQUEST_TIME>=(NOW() - INTERVAL 5 SECOND) ORDER BY LATEST_REQUEST_TIME DESC LIMIT 1");
}
if (!$terminal_rec) {
say($ph, $level);
Expand Down Expand Up @@ -347,10 +347,9 @@ function timeBetween($tm1, $tm2)
* @param mixed $expire Expire time (default 60)
* @return mixed
*/
function addScheduledJob($title, $commands, $datetime, $expire = 60)
function addScheduledJob($title, $commands, $datetime, $expire = 1800)
{
$rec = array();

$rec['TITLE'] = $title;
$rec['COMMANDS'] = $commands;
$rec['RUNTIME'] = date('Y-m-d H:i:s', $datetime);
Expand Down
4 changes: 4 additions & 0 deletions lib/mysqli.class.php
Expand Up @@ -373,6 +373,10 @@ public function Error($query = "")

$err_no = mysqli_errno($this->dbh);
$err_details = mysqli_error($this->dbh);
if (preg_match('/Unknown column/is',$err_details)) {
unlink(DIR_MODULES.'control_modules/installed');
//header("Location:".ROOTHTML);exit;
}
registerError('sql', $err_no . ": " . $err_details . "\n$query");
new custom_error($err_no . ": " . $err_details . "<br>$query", 1);

Expand Down
185 changes: 95 additions & 90 deletions lib/objects.class.php
Expand Up @@ -528,14 +528,14 @@ function getHistoryValueId($varname){
* @access public
*/
function getHistory($varname, $start_time, $stop_time = 0) {
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);

// Get hist val id
// Get hist val id
$id = getHistoryValueId($varname);

// Get data
return SQLSelect("SELECT VALUE, ADDED FROM phistory WHERE VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");
// Get data
return SQLSelect("SELECT VALUE, ADDED FROM phistory WHERE VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");
}

/**
Expand All @@ -546,19 +546,20 @@ function getHistory($varname, $start_time, $stop_time = 0) {
* @access public
*/
function getHistoryMin($varname, $start_time, $stop_time = 0) {
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);

// Get hist val id
$id = getHistoryValueId($varname);

// Get data
$data = SQLSelectOne("SELECT MIN(VALUE) AS VALUE FROM phistory WHERE VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");

if (!$data['VALUE'])
return false;

return $data['VALUE'];
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);

// Get hist val id
$id = getHistoryValueId($varname);

// Get data
$data = SQLSelectOne("SELECT MIN(VALUE+0.0) AS VALUE FROM phistory ".
"WHERE VALUE != \"\" AND VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");

if (!$data['VALUE'])
return false;

return $data['VALUE'];
}

/**
Expand All @@ -569,18 +570,19 @@ function getHistoryMin($varname, $start_time, $stop_time = 0) {
* @access public
*/
function getHistoryMax($varname, $start_time, $stop_time = 0) {
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);

// Get hist val id
// Get hist val id
$id = getHistoryValueId($varname);

// Get data
$data = SQLSelectOne("SELECT MAX(VALUE) AS VALUE FROM phistory WHERE VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");
if (!$data['VALUE'])
return false;

return $data['VALUE'];
// Get data
$data = SQLSelectOne("SELECT MAX(VALUE+0.0) AS VALUE FROM phistory ".
"WHERE VALUE != \"\" AND VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");
if (!$data['VALUE'])
return false;

return $data['VALUE'];
}

/**
Expand All @@ -591,18 +593,19 @@ function getHistoryMax($varname, $start_time, $stop_time = 0) {
* @access public
*/
function getHistoryCount($varname, $start_time, $stop_time = 0) {
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);

// Get hist val id
// Get hist val id
$id = getHistoryValueId($varname);

// Get data
$data = SQLSelectOne("SELECT COUNT(VALUE) AS VALUE FROM phistory WHERE VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");
if (!$data['VALUE'])
return false;

return $data['VALUE'];
// Get data
$data = SQLSelectOne("SELECT COUNT(VALUE+0.0) AS VALUE FROM phistory ".
"WHERE VALUE != \"\" AND VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");
if (!$data['VALUE'])
return false;

return $data['VALUE'];
}

/**
Expand All @@ -613,18 +616,19 @@ function getHistoryCount($varname, $start_time, $stop_time = 0) {
* @access public
*/
function getHistorySum($varname, $start_time, $stop_time = 0) {
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);

// Get hist val id
// Get hist val id
$id = getHistoryValueId($varname);

// Get data
$data = SQLSelectOne("SELECT SUM(VALUE) AS VALUE FROM phistory WHERE VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");
if (!$data['VALUE'])
return false;

return $data['VALUE'];
// Get data
$data = SQLSelectOne("SELECT SUM(VALUE+0.0) AS VALUE FROM phistory ".
"WHERE VALUE != \"\" AND VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");
if (!$data['VALUE'])
return false;

return $data['VALUE'];
}

/**
Expand All @@ -635,18 +639,19 @@ function getHistorySum($varname, $start_time, $stop_time = 0) {
* @access public
*/
function getHistoryAvg($varname, $start_time, $stop_time = 0) {
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);
if ($start_time <= 0) $start_time = (time() + $start_time);
if ($stop_time <= 0) $stop_time = (time() + $stop_time);

// Get hist val id
// Get hist val id
$id = getHistoryValueId($varname);

// Get data
$data = SQLSelectOne("SELECT AVG(VALUE) AS VALUE FROM phistory WHERE VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");
if (!$data['VALUE'])
return false;

return $data['VALUE'];
// Get data
$data = SQLSelectOne("SELECT AVG(VALUE+0.0) AS VALUE FROM phistory ".
"WHERE VALUE != \"\" AND VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $start_time)."') AND ADDED<=('".date('Y-m-d H:i:s', $stop_time)."')");
if (!$data['VALUE'])
return false;

return $data['VALUE'];
}
/**
* getHistoryValue
Expand All @@ -656,45 +661,45 @@ function getHistoryAvg($varname, $start_time, $stop_time = 0) {
* @access public
*/
function getHistoryValue($varname, $time, $nerest = false) {
if ($time <= 0) $time = (time() + $time);
if ($time <= 0) $time = (time() + $time);

// Get hist val id
// Get hist val id
$id = getHistoryValueId($varname);

// Get val before
$val1 = SQLSelectOne("SELECT VALUE, UNIX_TIMESTAMP(ADDED) AS ADDED FROM phistory WHERE VALUE_ID='".$id."' AND ADDED<=('".date('Y-m-d H:i:s', $time)."') ORDER BY ADDED DESC LIMIT 1");
// Get val after
$val2 = SQLSelectOne("SELECT VALUE, UNIX_TIMESTAMP(ADDED) AS ADDED FROM phistory WHERE VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $time)."') ORDER BY ADDED LIMIT 1");
// Not found values
if ((!$val1['VALUE']) && (!$val2['VALUE']))
return false;
// Only before
if (($val1['VALUE']) && (!$val2['VALUE']))
return $val1['VALUE'];
// Only after
if ((!$val1['VALUE']) && ($val2['VALUE']))
return $val2['VALUE'];
// Nerest
if ($nerest)
{
if (($time-$val1['ADDED']) < ($val2['ADDED']-$time))
return $val1['VALUE'];
else
return $val2['VALUE'];
}
// Interpolation
else
{
if ($val2['ADDED'] - $val1['ADDED'] == 0)
return $val1['VALUE'];
else
return $val1['VALUE'] + ($val2['VALUE'] - $val1['VALUE']) * ($time - $val1['ADDED']) / ($val2['ADDED'] - $val1['ADDED']);
}
// Get val before
$val1 = SQLSelectOne("SELECT VALUE, UNIX_TIMESTAMP(ADDED) AS ADDED FROM phistory WHERE VALUE_ID='".$id."' AND ADDED<=('".date('Y-m-d H:i:s', $time)."') ORDER BY ADDED DESC LIMIT 1");
// Get val after
$val2 = SQLSelectOne("SELECT VALUE, UNIX_TIMESTAMP(ADDED) AS ADDED FROM phistory WHERE VALUE_ID='".$id."' AND ADDED>=('".date('Y-m-d H:i:s', $time)."') ORDER BY ADDED LIMIT 1");
// Not found values
if ((!$val1['VALUE']) && (!$val2['VALUE']))
return false;
// Only before
if (($val1['VALUE']) && (!$val2['VALUE']))
return $val1['VALUE'];
// Only after
if ((!$val1['VALUE']) && ($val2['VALUE']))
return $val2['VALUE'];
// Nerest
if ($nerest)
{
if (($time-$val1['ADDED']) < ($val2['ADDED']-$time))
return $val1['VALUE'];
else
return $val2['VALUE'];
}
// Interpolation
else
{
if ($val2['ADDED'] - $val1['ADDED'] == 0)
return $val1['VALUE'];
else
return $val1['VALUE'] + ($val2['VALUE'] - $val1['VALUE']) * ($time - $val1['ADDED']) / ($val2['ADDED'] - $val1['ADDED']);
}
}
/**
* Summary of setGlobal
Expand Down
2 changes: 1 addition & 1 deletion modules/application.class.php
Expand Up @@ -226,7 +226,7 @@ function sortFiles($a, $b) {
$out['HIDE_TERMINALS']=1;
$session->data['TERMINAL']=$terminals[0]['NAME'];
}
SQLExec('UPDATE terminals SET IS_ONLINE=0 WHERE (NOW()-LATEST_ACTIVITY)>30*60');
SQLExec('UPDATE terminals SET IS_ONLINE=0 WHERE LATEST_ACTIVITY < (NOW() - INTERVAL 30 MINUTE)');

$users=SQLSelect("SELECT * FROM users ORDER BY NAME");
$total=count($users);
Expand Down
2 changes: 1 addition & 1 deletion modules/jobs/jobs.class.php
Expand Up @@ -230,7 +230,7 @@ function dbInstall($data) {
$data = <<<EOD
jobs: ID int(10) unsigned NOT NULL auto_increment
jobs: TITLE varchar(255) NOT NULL DEFAULT ''
jobs: COMMANDS text NOT NULL DEFAULT ''
jobs: COMMANDS text
jobs: RUNTIME datetime
jobs: EXPIRE datetime
jobs: STARTED datetime
Expand Down
4 changes: 2 additions & 2 deletions modules/objects/objects.class.php
Expand Up @@ -808,8 +808,8 @@ function dbInstall($data) {
phistory_queue: ID int(10) unsigned NOT NULL auto_increment
phistory_queue: VALUE_ID int(10) unsigned NOT NULL DEFAULT '0'
phistory_queue: VALUE text NOT NULL DEFAULT ''
phistory_queue: OLD_VALUE text NOT NULL DEFAULT ''
phistory_queue: VALUE text
phistory_queue: OLD_VALUE text
phistory_queue: KEEP_HISTORY int(10) unsigned NOT NULL DEFAULT '0'
phistory_queue: ADDED datetime
Expand Down
2 changes: 1 addition & 1 deletion modules/pvalues/pvalues.class.php
Expand Up @@ -206,7 +206,7 @@ function dbInstall($data) {
pvalues: PROPERTY_NAME varchar(100) NOT NULL DEFAULT ''
pvalues: PROPERTY_ID int(10) NOT NULL DEFAULT '0'
pvalues: OBJECT_ID int(10) NOT NULL DEFAULT '0'
pvalues: VALUE text NOT NULL DEFAULT ''
pvalues: VALUE text
pvalues: UPDATED datetime
pvalues: LINKED_MODULES varchar(255) NOT NULL DEFAULT ''
pvalues: INDEX (PROPERTY_ID)
Expand Down
2 changes: 1 addition & 1 deletion modules/pvalues/pvalues_edit.inc.php
Expand Up @@ -30,7 +30,7 @@
*/
//updating 'Value' (varchar)
global $value;
$rec['VALUE']=$value;
$rec['VALUE']=$value.'';
//UPDATING RECORD
if ($ok) {
if ($rec['ID']) {
Expand Down
2 changes: 1 addition & 1 deletion modules/scripts/scripts.class.php
Expand Up @@ -363,7 +363,7 @@ function dbInstall($data) {
safe_execs: ID int(10) unsigned NOT NULL auto_increment
safe_execs: COMMAND text NOT NULL DEFAULT ''
safe_execs: COMMAND text
safe_execs: EXCLUSIVE int(3) NOT NULL DEFAULT 0
safe_execs: PRIORITY int(10) NOT NULL DEFAULT 0
safe_execs: ADDED datetime
Expand Down
2 changes: 1 addition & 1 deletion modules/shoutbox/shouts_search.inc.php
Expand Up @@ -34,7 +34,7 @@
if ($terminal_rec['ID']) {
$terminal_rec['LATEST_ACTIVITY']=date('Y-m-d H:i:s');
$terminal_rec['LATEST_REQUEST_TIME']=$terminal_rec['LATEST_ACTIVITY'];
$terminal_rec['LATEST_REQUEST']=$rec['MESSAGE'];
$terminal_rec['LATEST_REQUEST']=$rec['MESSAGE'].'';
$terminal_rec['IS_ONLINE']=1;
SQLUpdate('terminals', $terminal_rec);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/webvars/webvars.class.php
Expand Up @@ -388,7 +388,7 @@ function dbInstall($data) {
webvars: TYPE int(30) NOT NULL DEFAULT '0'
webvars: SEARCH_PATTERN varchar(255) NOT NULL DEFAULT ''
webvars: CHECK_PATTERN varchar(255) NOT NULL DEFAULT ''
webvars: LATEST_VALUE text NOT NULL DEFAULT ''
webvars: LATEST_VALUE text
webvars: CHECK_LATEST datetime
webvars: CHECK_NEXT datetime
webvars: SCRIPT_ID int(10) NOT NULL DEFAULT '0'
Expand Down

0 comments on commit 0d48101

Please sign in to comment.