Skip to content
Permalink
Browse files

CONNECT update

Remote access now works correct with big forms (POST requests)
  • Loading branch information...
sergejey committed Sep 30, 2019
1 parent 6998b76 commit 8cab832299746e3dc2bcb625883d73bc4efc944e
Showing with 68 additions and 12 deletions.
  1. +61 −9 modules/connect/connect.class.php
  2. +2 −2 modules/thumb/thumb.php
  3. +5 −1 scripts/cycle_connect.php
@@ -404,6 +404,49 @@ function getConnectStatus() {
return $result;
}
function requestReverseFull($msg) {
$data = json_decode($msg,true);
$url = $data['url'];
$method = $data['method'];
if ($data['params']) {
$params = unserialize($data['params']);
} else {
$params = array();
}
ignore_user_abort(1);
$url = BASE_URL.$url;
if (preg_match('/\?/',$url)) {
$url.='&no_session=1';
} else {
$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);
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);
$result = curl_exec($ch);
$data['content_type'] = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
}
$this->sendReverseURL($data,$result);
}
function requestReverseURL($msg) {
ignore_user_abort(1);
$url = BASE_URL.$msg;
@@ -412,29 +455,35 @@ function requestReverseURL($msg) {
} else {
$url.='?no_session=1';
}
//debmes("Sending request $url",'reverse_urls');
$data=array();
$data['url']=$msg;
$result = getURL($url);
//debmes("Sending result to Connect",'reverse_urls');
$this->sendReverseURL($msg,$result);
//debmes("Sending $msg DONE",'reverse_urls');
$this->sendReverseURL($data,$result);
}
function sendReverseURL($url_requested, $result)
function sendReverseURL($data, $result)
{
// POST TO SERVER
$url = 'https://connect.smartliving.ru/reverse_proxy.php';
$header = array('Content-Type: multipart/form-data');
$url_requested = $data['url'];
$fields = array('url' => $url_requested);
//$probably_binary = (is_string($result) === true && ctype_print($result) === false);
if (preg_match('/\.css$/is', $url_requested) || preg_match('/\.js$/is', $url_requested) || !mb_detect_encoding($result)) {
if (IsSet($data['watermark'])) {
$fields['watermark']=$data['watermark'];
}
if (IsSet($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)) {
$binary_path = ROOT . 'cms/cached/reverse';
if (!is_dir($binary_path)) {
umask(0);
mkdir($binary_path, 0777);
}
$tmpfilename = $binary_path . '/' . preg_replace('/\W/', '_', $url_requested);
SaveFile($tmpfilename, $result);
if (!function_exists('getCurlValue')) {
function getCurlValue($filename, $contentType, $postname)
{
@@ -894,6 +943,9 @@ function usual(&$out)
if ($op=='reverse_request') {
$this->requestReverseURL($msg);
}
if ($op=='reverse_request_full') {
$this->requestReverseFull($msg);
}
}
}
@@ -13,7 +13,7 @@
}
}
define("_I_CACHING", "1"); // Chaching enabled, 1 - yes, 0 - no
define("_I_CACHING", "0"); // Chaching enabled, 1 - yes, 0 - no
define("_I_CACHE_PATH", "./cms/cached/"); // Path to cache dir
define("_I_CACHE_EXPIRED", "2592000"); // Expired time for images in seconds, 0 - never expired
@@ -87,7 +87,7 @@
header("Content-type: multipart/x-mixed-replace; boundary=$boundary");
print "--$boundary\n";
set_time_limit(0);
@apache_setenv('no-gzip', 1);
//@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
@@ -61,7 +61,7 @@
}
$query = $username . '/incoming_urls,' . $username . '/menu_session,' . $username . '/reverse_urls';
$query = $username . '/incoming_urls,' . $username . '/menu_session,' . $username . '/reverse_requests';
$ping_topic = $username . '/ping';
$client_name = "MajorDoMo " . $username . " Connect";
$mqtt_client = new Bluerhinos\phpMQTT($host, $port, $client_name, $ca_file);
@@ -157,6 +157,10 @@ function procmsg($topic, $msg)
$url = BASE_URL . '/ajax/connect.html?no_session=1&op=reverse_request&msg=' . urlencode($msg);
echo date("Y-m-d H:i:s") . " Incoming reverse url: $msg\n";
getURLBackground($url, 0);
} elseif (preg_match('/reverse_requests/is', $topic)) {
$url = BASE_URL . '/ajax/connect.html?no_session=1&op=reverse_request_full&msg=' . urlencode($msg);
echo date("Y-m-d H:i:s") . " Incoming reverse request: $msg\n";
getURLBackground($url, 0);
}
}

0 comments on commit 8cab832

Please sign in to comment.
You can’t perform that action at this time.