Skip to content
Permalink
Browse files
Updates
* Simple Devices: ability to set open/close/reminder message text
* CONNECT: fix for reverse-proxy redirect
  • Loading branch information
sergejey committed Jun 27, 2020
1 parent 4fd507d commit 98c07374c3de2f437c1c16c17bf665635ada8815
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 66 deletions.
@@ -104,3 +104,4 @@ Define('GETURL_WARNING_TIMEOUT',5); // TIMEOUT LIMIT FOR getUR
//Define('DISABLE_SIMPLE_DEVICES',1); // disables simple devices behavior
//Define('AUDIO_PLAYER','omxplayer --no-osd'); // audio-player for linux
//Define('ENABLE_FORK',1); // enables process fork (consumes more memory but speeds up some operations)
//Define('PYTHON_PATH','python'); // path to python
@@ -318,14 +318,15 @@
$to_stop = array();
$started_when = array();

$thisComputerObject = getObject('Computer.ThisComputer');

while (false !== ($result = $threads->iteration())) {

if ((time() - $last_cycles_control_check) >= 5 || !empty($result)) {

$last_cycles_control_check = time();

$qry = "OBJECT_ID=" . getObject('Computer.ThisComputer')->id . " AND (TITLE LIKE 'cycle%Run' OR TITLE LIKE 'cycle%Control')";
$qry = "OBJECT_ID=" . $thisComputerObject->id . " AND (TITLE LIKE 'cycle%Run' OR TITLE LIKE 'cycle%Control')";
$cycles = SQLSelect("SELECT properties.* FROM properties WHERE $qry ORDER BY TITLE");

$total = count($cycles);
@@ -1143,6 +1143,9 @@
'DEVICES_COUNTER' => 'Meter/Counter',
'DEVICES_BATTERY_LOW' => 'Low battery',
'DEVICES_UNKNOWN_COMMAND'=>'Unknown command...',
'DEVICES_MSG_OPENING'=>'Opening message text',
'DEVICES_MSG_CLOSING'=>'Closing message text',
'DEVICES_MSG_REMINDER'=>'Reminder message text',

// Measure
'M_VOLTAGE' => 'V',
@@ -1139,6 +1139,9 @@
'DEVICES_UNIT' => 'Единица измерения',
'DEVICES_BATTERY_LOW' => 'Низкий уровень заряда батареи',
'DEVICES_UNKNOWN_COMMAND'=>'Неизвестная команда...',
'DEVICES_MSG_OPENING'=>'Сообщение при открытии',
'DEVICES_MSG_CLOSING'=>'Сообщение при закрытии',
'DEVICES_MSG_REMINDER'=>'Сообщение при напоминании',

// Measure
'M_VOLTAGE' => 'В',
@@ -258,7 +258,7 @@ function admin(&$out)
$out['ERR_MSG'] = gr('err_msg');
}
if (gr('status')) {
$out['STATUS']=gr('status');
$out['STATUS'] = gr('status');
}

$this->getConfig();
@@ -301,7 +301,7 @@ function admin(&$out)
if (!$status) {
$status = LANG_CONNECT_LOGIN_FAILED;
}
$this->redirect("?status=".urlencode($status));
$this->redirect("?status=" . urlencode($status));
}

if ($this->mode == 'sendbackup') {
@@ -392,15 +392,16 @@ function admin(&$out)

}

function getConnectStatus() {
function getConnectStatus()
{
$url = 'https://connect.smartliving.ru/market/?op=connect_status';
if ($this->config['CONNECT_SYNC']) {
$url.="&sync=1";
$url .= "&sync=1";
}
if ($this->config['CONNECT_BACKUP']) {
$url.="&backup=1";
$url .= "&backup=1";
}
$url.="&local_url=".urlencode(getLocalIp());
$url .= "&local_url=" . urlencode(getLocalIp());
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@@ -421,8 +422,9 @@ function getConnectStatus() {
return $result;
}

function requestReverseFull($msg) {
$data = json_decode($msg,true);
function requestReverseFull($msg)
{
$data = json_decode($msg, true);
$url = $data['url'];
$method = $data['method'];
if ($data['params']) {
@@ -432,58 +434,65 @@ function requestReverseFull($msg) {
}
ignore_user_abort(1);

$url = BASE_URL.$url;
if (preg_match('/\?/',$url)) {
$url.='&no_session=1';
$url = BASE_URL . $url;
if (preg_match('/\?/', $url)) {
$url .= '&no_session=1';
} else {
$url.='?no_session=1';
$url .= '?no_session=1';
}
if ($method=='GET') {
$result = getURL($url);
} else {
//DebMes("$method request to $url: ".$msg,'connect_post');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//DebMes("$method request to $url: ".$msg,'connect_post');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if ($method != 'GET') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
//curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // connection timeout
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 45); // operation timeout 45 seconds
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // bad style, I know...
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$tmpfname = ROOT . 'cms/cached/cookie.txt';
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
if (defined('USE_PROXY') && USE_PROXY != '') {
curl_setopt($ch, CURLOPT_PROXY, USE_PROXY);
if (defined('USE_PROXY_AUTH') && USE_PROXY_AUTH != '') {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, USE_PROXY_AUTH);
}
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // connection timeout
//curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
//@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 45); // operation timeout 45 seconds
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // bad style, I know...
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$tmpfname = ROOT . 'cms/cached/cookie.txt';
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
if (defined('USE_PROXY') && USE_PROXY != '') {
curl_setopt($ch, CURLOPT_PROXY, USE_PROXY);
if (defined('USE_PROXY_AUTH') && USE_PROXY_AUTH != '') {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, USE_PROXY_AUTH);
}
$result = curl_exec($ch);
}
$result = curl_exec($ch);
$redirectURL = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
if ($redirectURL != '') {
$redirectURL = str_replace(BASE_URL,'',$redirectURL);
$result = 'redirect:' . $redirectURL;
$data['content_type'] = 'redirect';
} else {
$data['content_type'] = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
}
$this->sendReverseURL($data,$result);
curl_close($ch);
$this->sendReverseURL($data, $result);
}

function requestReverseURL($msg) {

function requestReverseURL($msg)
{
ignore_user_abort(1);
$url = BASE_URL.$msg;
if (preg_match('/\?/',$url)) {
$url.='&no_session=1';
$url = BASE_URL . $msg;
if (preg_match('/\?/', $url)) {
$url .= '&no_session=1';
} else {
$url.='?no_session=1';
$url .= '?no_session=1';
}
$data=array();
$data['url']=$msg;
$data = array();
$data['url'] = $msg;
$result = getURL($url);
$this->sendReverseURL($data,$result);
$this->sendReverseURL($data, $result);
}

function sendReverseURL($data, $result)
{
// POST TO SERVER
@@ -492,14 +501,15 @@ function sendReverseURL($data, $result)
$url_requested = $data['url'];
$fields = array('url' => $url_requested);
if (IsSet($data['watermark'])) {
$fields['watermark']=$data['watermark'];
$fields['watermark'] = $data['watermark'];
}
if (IsSet($data['content_type'])) {
$fields['content_type']=$data['content_type'];
$fields['content_type'] = $data['content_type'];
}
if (preg_match('/\.css$/is', $url_requested)
|| preg_match('/\.js$/is', $url_requested)
|| !mb_detect_encoding($result)) {
|| !mb_detect_encoding($result)
) {
$binary_path = ROOT . 'cms/cached/reverse';
if (!is_dir($binary_path)) {
umask(0);
@@ -555,7 +565,7 @@ function sendAllDevices()
// POST TO SERVER
$url = 'https://connect.smartliving.ru/sync_device_data.php';
$fields = array();
$devices = SQLSelect("SELECT devices.ID, devices.TITLE, devices.ALT_TITLES, devices.TYPE, devices.SUBTYPE, devices.LINKED_OBJECT, locations.TITLE as ROOM_TITLE FROM devices LEFT JOIN locations ON devices.LOCATION_ID=locations.ID WHERE devices.SYSTEM_DEVICE=0");
$devices = SQLSelect("SELECT devices.ID, devices.TITLE, devices.ALT_TITLES, devices.TYPE, devices.SUBTYPE, devices.LINKED_OBJECT, locations.TITLE AS ROOM_TITLE FROM devices LEFT JOIN locations ON devices.LOCATION_ID=locations.ID WHERE devices.SYSTEM_DEVICE=0");
include_once(DIR_MODULES . 'classes/classes.class.php');
$cl = new classes();

@@ -574,8 +584,8 @@ function sendAllDevices()
$value = $object->getProperty($v['TITLE']);
if ($value === '') continue;
$device['properties'][$v['TITLE']] = $value;
if (strtolower($v['TITLE'])=='linkedroom') {
$device['ROOM_OBJECT']=$value;
if (strtolower($v['TITLE']) == 'linkedroom') {
$device['ROOM_OBJECT'] = $value;
}
}
}
@@ -1002,12 +1012,12 @@ function usual(&$out)
if ($this->ajax) {
$op = gr('op');
$msg = gr('msg');
if ($op=='reverse_request') {
$this->requestReverseURL($msg);
if ($op == 'reverse_request') {
$this->requestReverseURL($msg);
}
if ($op=='reverse_request_full') {
if ($op == 'reverse_request_full') {
$this->requestReverseFull($msg);
}
}
}
}

@@ -14,26 +14,35 @@
}
if ($this->getProperty('notify_status')) {
if (isset($params['NEW_VALUE'])) {
if (!$params['NEW_VALUE'])
saySafe($description . ' ' . LANG_DEVICES_STATUS_OPEN, 2);
else
saySafe($description . ' ' . LANG_DEVICES_STATUS_CLOSED, 2);
if (!$params['NEW_VALUE']) {
$msg = $this->getProperty('notify_msg_opening');
if (!$msg) $msg = $description . ' ' . LANG_DEVICES_STATUS_OPEN;
saySafe($msg, 2);
} else {
$msg = $this->getProperty('notify_msg_closing');
if (!$msg) $msg = $description . ' ' . LANG_DEVICES_STATUS_CLOSED;
saySafe($msg, 2);
}
}
}


if ($this->getProperty('notify_nc')) {
if (isset($params['NEW_VALUE'])) {
if (!$params['NEW_VALUE']) {
setTimeout($ot . '_notify_timer_1', "saySafe('" . LANG_REMINDER_INTRO." ". $description . " " . LANG_DEVICES_STATUS_OPEN . "!', 5);", 10 * 60);
setTimeout($ot . '_notify_timer_2', "saySafe('" . LANG_REMINDER_INTRO." ". $description . " " . LANG_DEVICES_STATUS_OPEN . "!', 5);", 20 * 60);
setTimeout($ot . '_notify_timer_3', "saySafe('" . LANG_REMINDER_INTRO." ". $description . " " . LANG_DEVICES_STATUS_OPEN . "!', 5);", 30 * 60);
setTimeout($ot . '_notify_timer_4', "saySafe('" . LANG_REMINDER_INTRO." ". $description . " " . LANG_DEVICES_STATUS_OPEN . "!', 5);", 60 * 60);
$msg = $this->getProperty('notify_msg_reminder');
if (!$msg) $msg = LANG_REMINDER_INTRO." ". $description. " " . LANG_DEVICES_STATUS_OPEN . "!";
setTimeout($ot . '_notify_timer_1', "saySafe('" . $msg ."', 5);", 10 * 60);
setTimeout($ot . '_notify_timer_2', "saySafe('" . $msg ."', 5);", 20 * 60);
setTimeout($ot . '_notify_timer_3', "saySafe('" . $msg ."', 5);", 30 * 60);
setTimeout($ot . '_notify_timer_4', "saySafe('" . $msg ."', 5);", 60 * 60);
setTimeout($ot . '_notify_timer_5', "saySafe('" . $msg ."', 5);", 120 * 60);
} else {
clearTimeOut($ot . '_notify_timer_1');
clearTimeOut($ot . '_notify_timer_2');
clearTimeOut($ot . '_notify_timer_3');
clearTimeOut($ot . '_notify_timer_4');
clearTimeOut($ot . '_notify_timer_5');
}
}
}
@@ -230,7 +230,10 @@
',window='.LANG_DEVICES_OPENTYPE_WINDOW.
',door='.LANG_DEVICES_OPENTYPE_DOOR.
',curtains='.LANG_DEVICES_OPENTYPE_CURTAINS.
',shutters='.LANG_DEVICES_OPENTYPE_SHUTTERS)
',shutters='.LANG_DEVICES_OPENTYPE_SHUTTERS),
'notify_msg_opening'=>array('DESCRIPTION'=>LANG_DEVICES_MSG_OPENING,'_CONFIG_TYPE'=>'text'),
'notify_msg_closing'=>array('DESCRIPTION'=>LANG_DEVICES_MSG_CLOSING,'_CONFIG_TYPE'=>'text'),
'notify_msg_reminder'=>array('DESCRIPTION'=>LANG_DEVICES_MSG_REMINDER,'_CONFIG_TYPE'=>'text'),
),
'METHODS'=>array(
'statusUpdated'=>array('DESCRIPTION'=>'Status updated event'),

0 comments on commit 98c0737

Please sign in to comment.