Skip to content

Commit

Permalink
Adapted for deep telegram
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Sep 7, 2016
1 parent 5862152 commit e11bee3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/Zyberspace/Telegram/Cli/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/Zyberspace/Telegram/Cli/RawClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '"');
Expand Down

0 comments on commit e11bee3

Please sign in to comment.