Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
* Redis cache fix
* getObject method fix
* Simple Devices: now user can set additional conditions to some properties on Settings tab.
  • Loading branch information
sergejey committed Sep 11, 2022
1 parent fe0ac29 commit 5b6fc7c
Show file tree
Hide file tree
Showing 16 changed files with 1,382 additions and 1,276 deletions.
2 changes: 1 addition & 1 deletion lib/caching.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function saveToCache($key, $value)
$redisConnection = new Redis();
$redisConnection->pconnect(USE_REDIS);
}
$redisConnection->set($key, $value);
$redisConnection->set($key, (string)$value);
return;
}

Expand Down
20 changes: 19 additions & 1 deletion lib/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function runScheduledJobs()
SQLExec("UPDATE jobs SET PROCESSED=" . $jobs[$i]['PROCESSED'] . ", STARTED='" . $jobs[$i]['STARTED'] . "' WHERE ID=" . $jobs[$i]['ID']);

if ($jobs[$i]['COMMANDS'] != '') {
$url = BASE_URL . '/objects/?system_call=1&job=' . $jobs[$i]['ID'];
$url = BASE_URL . '/objects/?system_call=1&job=' . $jobs[$i]['ID'] . '&title=' . urlencode($jobs[$i]['TITLE']);
$result = trim(getURL($url, 0));
$result = preg_replace('/<!--.+-->/is', '', $result);
if (!preg_match('/OK$/', $result)) {
Expand Down Expand Up @@ -845,6 +845,24 @@ function checkAccess($object_type, $object_id)
return $result;
}

function checkAccessDefined($object_type, $object_id)
{
$rec = SQLSelectOne("SELECT ID FROM security_rules WHERE OBJECT_TYPE='" . DBSafe($object_type) . "' AND OBJECT_ID=" . (int)$object_id);
if ($rec['ID']) return true;
return false;
}

function checkAccessCopy($object_type, $src_id, $dst_id)
{
$rec = SQLSelectOne("SELECT * FROM security_rules WHERE OBJECT_TYPE='" . DBSafe($object_type) . "' AND OBJECT_ID=" . (int)$src_id);
if ($rec['ID']) {
SQLExec("DELETE FROM security_rules WHERE OBJECT_TYPE='".DBSafe($object_type)."' AND OBJECT_ID=".(int)$dst_id);
unset($rec['ID']);
$rec['OBJECT_ID']=(int)$dst_id;
SQLInsert('security_rules',$rec);
}
}

/**
* Summary of registerError
* @param mixed $code Code (default 'custom')
Expand Down
8 changes: 6 additions & 2 deletions modules/devices/darknessmode_activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
$objects = getObjectsByProperty('groupSunset', '=', 1);
$total = count($objects);
for ($i = 0; $i < $total; $i++) {
usleep(50000);

$obj = getObject($objects[$i]);
if (is_object($obj) && $obj->device_id && !checkAccess('prop_groupSunset', $obj->device_id)) continue;

callMethodSafe($objects[$i] . '.turnOn', array('source' => 'DarknessMode'));
//sleep(1);
usleep(50000);

}
16 changes: 10 additions & 6 deletions modules/devices/darknessmode_deactivate.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<?php

if (defined('DISABLE_SIMPLE_DEVICES') && DISABLE_SIMPLE_DEVICES==1) return;
if (defined('DISABLE_SIMPLE_DEVICES') && DISABLE_SIMPLE_DEVICES == 1) return;

//groupSunrise
$objects = getObjectsByProperty('groupSunrise', '=', 1);
$total = count($objects);
for ($i = 0; $i < $total; $i++) {
if (getGlobal($objects[$i] . '.status')) {
usleep(50000);
callMethodSafe($objects[$i] . '.turnOff', array('source' => 'DarknessMode'));
//sleep(1);
}
if (getGlobal($objects[$i] . '.status')) {

$obj = getObject($objects[$i]);
if (is_object($obj) && $obj->device_id && !checkAccess('prop_groupSunrise', $obj->device_id)) continue;

callMethodSafe($objects[$i] . '.turnOff', array('source' => 'DarknessMode'));
usleep(50000);

}
}
16 changes: 14 additions & 2 deletions modules/devices/devices_edit.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,14 @@
}
setGlobal($rec['LINKED_OBJECT'] . '.' . $k, $value);
if (is_array($apply_others)) {
foreach($apply_others as $other_dev) {
foreach ($apply_others as $other_dev) {
setGlobal($other_dev . '.' . $k, $value);
if ($v['_CONFIG_RESTRICTIONS'] && checkAccessDefined('prop_' . $k, $rec['ID'])) {
$other_obj = getObject($other_dev);
if (is_object($other_obj) && $other_obj->device_id) {
checkAccessCopy('prop_' . $k, $rec['ID'], $other_obj->device_id);
}
}
}
}
}
Expand Down Expand Up @@ -204,6 +210,11 @@
$styles = $scene_class->getAllTypes();
$v['FOLDERS'] = $styles;
}

if ($v['_CONFIG_RESTRICTIONS'] && checkAccessDefined('prop_' . $v['NAME'], $rec['ID'])) {
$v['_CONFIG_RESTRICTIONS_SET'] = 1;
}

$res_properties[] = $v;
}
}
Expand Down Expand Up @@ -446,7 +457,8 @@
$class_2b_changed = 0;
break;
}
$tmp_class_id = current(SQLSelectOne("SELECT PARENT_ID FROM classes WHERE ID=" . (int)$tmp_class_id));
$tmp = SQLSelectOne("SELECT PARENT_ID FROM classes WHERE ID=" . (int)$tmp_class_id);
$tmp_class_id = (int)$tmp['PARENT_ID'];
}
if ($class_2b_changed) {
//move object to new class
Expand Down
8 changes: 6 additions & 2 deletions modules/devices/devices_schedule.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
if ($point['SET_TIME']) {

}

if (checkAccessDefined('spoint',$point_id)) {
$out['POINT_ACCESS_DEFINED']=1;
}

}


Expand Down Expand Up @@ -71,8 +76,7 @@
}
}
$point_item['SET_DAYS']=implode(', ',$point_days_title);
$rule=SQLSelectOne("SELECT ID FROM security_rules WHERE OBJECT_TYPE='spoint' AND OBJECT_ID=".$point_item['ID']);
if ($rule['ID']) {
if (checkAccessDefined('spoint',$point_item['ID'])) {
$point_item['HAS_RULE']=1;
}
}
Expand Down
10 changes: 5 additions & 5 deletions modules/devices/devices_structure.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
'PARENT_CLASS'=>'SDevices',
'DESCRIPTION'=>'Controllable device',
'PROPERTIES'=>array(
'groupEco'=>array('DESCRIPTION'=>LANG_DEVICES_GROUP_ECO,'_CONFIG_TYPE'=>'yesno','_CONFIG_HELP'=>'SdGroupEco'),
'groupEcoOn'=>array('DESCRIPTION'=>LANG_DEVICES_GROUP_ECO_ON,'_CONFIG_TYPE'=>'yesno','_CONFIG_HELP'=>'SdGroupEcoOn'),
'groupSunrise'=>array('DESCRIPTION'=>LANG_DEVICES_GROUP_SUNRISE,'_CONFIG_TYPE'=>'yesno','_CONFIG_HELP'=>'SdGroupSunrise'),
'groupSunset'=>array('DESCRIPTION'=>LANG_DEVICES_GROUP_SUNSET,'_CONFIG_TYPE'=>'yesno','_CONFIG_HELP'=>'SdGroupSunset'),
'groupNight'=>array('DESCRIPTION'=>LANG_DEVICES_GROUP_NIGHT,'_CONFIG_TYPE'=>'yesno','_CONFIG_HELP'=>'SdGroupNight'),
'groupEco'=>array('DESCRIPTION'=>LANG_DEVICES_GROUP_ECO,'_CONFIG_TYPE'=>'yesno','_CONFIG_RESTRICTIONS'=>1,'_CONFIG_HELP'=>'SdGroupEco'),
'groupEcoOn'=>array('DESCRIPTION'=>LANG_DEVICES_GROUP_ECO_ON,'_CONFIG_TYPE'=>'yesno','_CONFIG_RESTRICTIONS'=>1,'_CONFIG_HELP'=>'SdGroupEcoOn'),
'groupSunrise'=>array('DESCRIPTION'=>LANG_DEVICES_GROUP_SUNRISE,'_CONFIG_TYPE'=>'yesno','_CONFIG_RESTRICTIONS'=>1,'_CONFIG_HELP'=>'SdGroupSunrise'),
'groupSunset'=>array('DESCRIPTION'=>LANG_DEVICES_GROUP_SUNSET,'_CONFIG_TYPE'=>'yesno','_CONFIG_RESTRICTIONS'=>1,'_CONFIG_HELP'=>'SdGroupSunset'),
'groupNight'=>array('DESCRIPTION'=>LANG_DEVICES_GROUP_NIGHT,'_CONFIG_TYPE'=>'yesno','_CONFIG_RESTRICTIONS'=>1,'_CONFIG_HELP'=>'SdGroupNight'),
'isActivity'=>array('DESCRIPTION'=>LANG_DEVICES_IS_ACTIVITY,'_CONFIG_TYPE'=>'yesno','_CONFIG_HELP'=>'SdIsActivity'),
'loadType'=>array('DESCRIPTION'=>LANG_DEVICES_LOADTYPE,
'_CONFIG_TYPE'=>'select','_CONFIG_HELP'=>'SdLoadType',
Expand Down
15 changes: 9 additions & 6 deletions modules/devices/econommode_activate.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php

if (defined('DISABLE_SIMPLE_DEVICES') && DISABLE_SIMPLE_DEVICES==1) return;
if (defined('DISABLE_SIMPLE_DEVICES') && DISABLE_SIMPLE_DEVICES == 1) return;

//groupEco
$objects = getObjectsByProperty('groupEco', '=', 1);
$total = count($objects);
for ($i = 0; $i < $total; $i++) {
if (getGlobal($objects[$i] . '.status')) {
usleep(50000);
callMethodSafe($objects[$i] . '.turnOff', array('source' => 'EconomMode'));
//sleep(1);
}
if (getGlobal($objects[$i] . '.status')) {

$obj = getObject($objects[$i]);
if (is_object($obj) && $obj->device_id && !checkAccess('prop_groupEco', $obj->device_id)) continue;

callMethodSafe($objects[$i] . '.turnOff', array('source' => 'EconomMode'));
usleep(50000);
}
}
7 changes: 5 additions & 2 deletions modules/devices/econommode_deactivate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
$objects = getObjectsByProperty('groupEcoOn', '=', 1);
$total = count($objects);
for ($i = 0; $i < $total; $i++) {
usleep(50000);

$obj = getObject($objects[$i]);
if (is_object($obj) && $obj->device_id && !checkAccess('prop_groupEcoOn', $obj->device_id)) continue;

callMethodSafe($objects[$i] . '.turnOn', array('source' => 'EconomMode'));
//sleep(1);
usleep(50000);
}
9 changes: 7 additions & 2 deletions modules/devices/nightmode_activate.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?php
if (defined('DISABLE_SIMPLE_DEVICES') && DISABLE_SIMPLE_DEVICES==1) return;
if (defined('DISABLE_SIMPLE_DEVICES') && DISABLE_SIMPLE_DEVICES == 1) return;

//groupNight
$objects = getObjectsByProperty('groupNight', '=', 1);
$total = count($objects);
for ($i = 0; $i < $total; $i++) {
$currentStatus = gg($objects[$i] . '.status');
if ($currentStatus) {
usleep(50000);

$obj = getObject($objects[$i]);
if (is_object($obj) && $obj->device_id && !checkAccess('prop_groupNight', $obj->device_id)) continue;

callMethodSafe($objects[$i] . '.turnOff', array('source' => 'NightMode'));
usleep(50000);

}
}
Loading

0 comments on commit 5b6fc7c

Please sign in to comment.