From e11bee305c6c0dfa06940beb57108c0257704cd7 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 7 Sep 2016 18:11:54 +0200 Subject: [PATCH] Adapted for deep telegram --- lib/Zyberspace/Telegram/Cli/Client.php | 6 +++--- lib/Zyberspace/Telegram/Cli/RawClient.php | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Zyberspace/Telegram/Cli/Client.php b/lib/Zyberspace/Telegram/Cli/Client.php index b8c81ff..5d34ebd 100644 --- a/lib/Zyberspace/Telegram/Cli/Client.php +++ b/lib/Zyberspace/Telegram/Cli/Client.php @@ -454,7 +454,7 @@ public function pwrsendFile($peer, $type, $path, $hash) */ $formattedPath = $this->formatFileName($path); $cmd = "send_" . $type . " " . $peer . " " . $formattedPath; - $res = shell_exec($GLOBALS["homedir"] . "/tg/bin/telegram-cli --json --permanent-msg-ids -U pwrtelegram -WNRe " . escapeshellarg($cmd) . " 2>&1"); + $res = shell_exec("export TELEGRAM_HOME=".$this->tgpath."; ".$GLOBALS["homedir"] . "/tg/bin/telegram-cli --json --permanent-msg-ids -U pwrtelegram -WNRe " . escapeshellarg($cmd) . " 2>&1"); $newres = null; $finalres = null; foreach (explode("\n", $res) as $line) { @@ -476,14 +476,14 @@ public function pwrsendFile($peer, $type, $path, $hash) */ public function getdFile($id, $type) { - $res = shell_exec($GLOBALS["homedir"] . "/tg/bin/telegram-cli --json --permanent-msg-ids -WNRe 'load_file $id' 2>&1 | sed 's/[>]//g;/{/!d;/{\"event\": \"download\"/!d;/^\s*$/d;s/^[^{]*{/{/;s/}[^}]*$/}/'"); + $res = shell_exec("export TELEGRAM_HOME=".$this->tgpath."; ".$GLOBALS["homedir"] . "/tg/bin/telegram-cli --json --permanent-msg-ids -WNRe 'load_file $id' 2>&1 | sed 's/[>]//g;/{/!d;/{\"event\": \"download\"/!d;/^\s*$/d;s/^[^{]*{/{/;s/}[^}]*$/}/'"); error_log($res); return json_decode($res); } public function getFile($user, $file_id, $type) { $script = escapeshellarg($GLOBALS["pwrhomedir"] . "/lua/download.lua"); - $res = shell_exec($GLOBALS["homedir"] . "/tg/bin/telegram-cli --json -WNRs " . $script . " --lua-param ".escapeshellarg($user." ".$file_id." ".$type)." 2>&1"); + $res = shell_exec("export TELEGRAM_HOME=".$this->tgpath."; ".$GLOBALS["homedir"] . "/tg/bin/telegram-cli --json -WNRs " . $script . " --lua-param ".escapeshellarg($user." ".$file_id." ".$type)." 2>&1"); foreach(explode("\n", $res) as $line) { if(preg_match('|.*{"event":"download", "result"|', $line)) $res = preg_replace(array('|.*{"event":"download", "result"|', "|}.*|"), array('{"event":"download", "result"', "}"), $line); } diff --git a/lib/Zyberspace/Telegram/Cli/RawClient.php b/lib/Zyberspace/Telegram/Cli/RawClient.php index ffc6909..e98d0b4 100755 --- a/lib/Zyberspace/Telegram/Cli/RawClient.php +++ b/lib/Zyberspace/Telegram/Cli/RawClient.php @@ -42,11 +42,14 @@ class RawClient * * @throws ClientException Throws an exception if no connection can be established. */ - public function __construct($remoteSocket) + public function __construct($deep = false) { + $path = $deep ? "/tmp/deeptg.sck" : "/tmp/tg.sck"; + $remoteSocket = "unix://" . $path; + $this->tgpath = $GLOBALS["homedir"] . ($deep ? "/deeptgstorage" : "/tgstorage"); $this->_fp = stream_socket_client($remoteSocket); if ($this->_fp === false) { - shell_exec("pkill telegram-cli; rm /tmp/tg.sck; " . $GLOBALS["homedir"] . "/tg/bin/telegram-cli --json --permanent-msg-ids -dWS /tmp/tg.sck&"); + shell_exec("pkill telegram-cli; rm ".$path."; export TELEGRAM_HOME=".$this->tgpath."; ". $GLOBALS["homedir"] . "/tg/bin/telegram-cli --json --permanent-msg-ids -dWS ".$path."&"); $this->_fp = stream_socket_client($remoteSocket); if ($this->_fp === false) { throw new ClientException('Could not connect to socket "' . $remoteSocket . '"');