From 1eb730d2811167d269693053c5c1590e0c758cb8 Mon Sep 17 00:00:00 2001 From: danogentili Date: Mon, 8 Aug 2016 18:24:41 +0200 Subject: [PATCH] Removed libpy2php files --- original_telepy/TL_schema.JSON | 1 + original_telepy/credentials | 5 + original_telepy/mtproto.py | 1 - src/danog/MadelineProto/Session.php | 5 + .../MadelineProto/libpy2php/libpy2php.php | 524 -------------- src/danog/MadelineProto/libpy2php/os.php | 683 ------------------ src/danog/MadelineProto/libpy2php/os_path.php | 251 ------- .../MadelineProto/libpy2php/strict_mode.php | 138 ---- 8 files changed, 11 insertions(+), 1597 deletions(-) create mode 100644 original_telepy/TL_schema.JSON create mode 100644 original_telepy/credentials delete mode 100644 src/danog/MadelineProto/libpy2php/libpy2php.php delete mode 100644 src/danog/MadelineProto/libpy2php/os.php delete mode 100644 src/danog/MadelineProto/libpy2php/os_path.php delete mode 100644 src/danog/MadelineProto/libpy2php/strict_mode.php diff --git a/original_telepy/TL_schema.JSON b/original_telepy/TL_schema.JSON new file mode 100644 index 00000000..3bd91940 --- /dev/null +++ b/original_telepy/TL_schema.JSON @@ -0,0 +1 @@ +{"constructors":[{"id":"481674261","predicate":"vector","params":[],"type":"Vector t"},{"id":"85337187","predicate":"resPQ","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"pq","type":"bytes"},{"name":"server_public_key_fingerprints","type":"Vector"}],"type":"ResPQ"},{"id":"-2083955988","predicate":"p_q_inner_data","params":[{"name":"pq","type":"bytes"},{"name":"p","type":"bytes"},{"name":"q","type":"bytes"},{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce","type":"int256"}],"type":"P_Q_inner_data"},{"id":"1013613780","predicate":"p_q_inner_data_temp","params":[{"name":"pq","type":"bytes"},{"name":"p","type":"bytes"},{"name":"q","type":"bytes"},{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce","type":"int256"},{"name":"expires_in","type":"int"}],"type":"P_Q_inner_data"},{"id":"2043348061","predicate":"server_DH_params_fail","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce_hash","type":"int128"}],"type":"Server_DH_Params"},{"id":"-790100132","predicate":"server_DH_params_ok","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"encrypted_answer","type":"bytes"}],"type":"Server_DH_Params"},{"id":"-1249309254","predicate":"server_DH_inner_data","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"g","type":"int"},{"name":"dh_prime","type":"bytes"},{"name":"g_a","type":"bytes"},{"name":"server_time","type":"int"}],"type":"Server_DH_inner_data"},{"id":"1715713620","predicate":"client_DH_inner_data","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"retry_id","type":"long"},{"name":"g_b","type":"bytes"}],"type":"Client_DH_Inner_Data"},{"id":"1003222836","predicate":"dh_gen_ok","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce_hash1","type":"int128"}],"type":"Set_client_DH_params_answer"},{"id":"1188831161","predicate":"dh_gen_retry","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce_hash2","type":"int128"}],"type":"Set_client_DH_params_answer"},{"id":"-1499615742","predicate":"dh_gen_fail","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce_hash3","type":"int128"}],"type":"Set_client_DH_params_answer"},{"id":"-212046591","predicate":"rpc_result","params":[{"name":"req_msg_id","type":"long"},{"name":"result","type":"Object"}],"type":"RpcResult"},{"id":"558156313","predicate":"rpc_error","params":[{"name":"error_code","type":"int"},{"name":"error_message","type":"string"}],"type":"RpcError"},{"id":"1579864942","predicate":"rpc_answer_unknown","params":[],"type":"RpcDropAnswer"},{"id":"-847714938","predicate":"rpc_answer_dropped_running","params":[],"type":"RpcDropAnswer"},{"id":"-1539647305","predicate":"rpc_answer_dropped","params":[{"name":"msg_id","type":"long"},{"name":"seq_no","type":"int"},{"name":"bytes","type":"int"}],"type":"RpcDropAnswer"},{"id":"155834844","predicate":"future_salt","params":[{"name":"valid_since","type":"int"},{"name":"valid_until","type":"int"},{"name":"salt","type":"long"}],"type":"FutureSalt"},{"id":"-1370486635","predicate":"future_salts","params":[{"name":"req_msg_id","type":"long"},{"name":"now","type":"int"},{"name":"salts","type":"vector"}],"type":"FutureSalts"},{"id":"880243653","predicate":"pong","params":[{"name":"msg_id","type":"long"},{"name":"ping_id","type":"long"}],"type":"Pong"},{"id":"-501201412","predicate":"destroy_session_ok","params":[{"name":"session_id","type":"long"}],"type":"DestroySessionRes"},{"id":"1658015945","predicate":"destroy_session_none","params":[{"name":"session_id","type":"long"}],"type":"DestroySessionRes"},{"id":"-1631450872","predicate":"new_session_created","params":[{"name":"first_msg_id","type":"long"},{"name":"unique_id","type":"long"},{"name":"server_salt","type":"long"}],"type":"NewSession"},{"id":"1945237724","predicate":"msg_container","params":[{"name":"messages","type":"vector<%Message>"}],"type":"MessageContainer"},{"id":"1538843921","predicate":"message","params":[{"name":"msg_id","type":"long"},{"name":"seqno","type":"int"},{"name":"bytes","type":"int"},{"name":"body","type":"Object"}],"type":"Message"},{"id":"-530561358","predicate":"msg_copy","params":[{"name":"orig_message","type":"Message"}],"type":"MessageCopy"},{"id":"812830625","predicate":"gzip_packed","params":[{"name":"packed_data","type":"bytes"}],"type":"Object"},{"id":"1658238041","predicate":"msgs_ack","params":[{"name":"msg_ids","type":"Vector"}],"type":"MsgsAck"},{"id":"-1477445615","predicate":"bad_msg_notification","params":[{"name":"bad_msg_id","type":"long"},{"name":"bad_msg_seqno","type":"int"},{"name":"error_code","type":"int"}],"type":"BadMsgNotification"},{"id":"-307542917","predicate":"bad_server_salt","params":[{"name":"bad_msg_id","type":"long"},{"name":"bad_msg_seqno","type":"int"},{"name":"error_code","type":"int"},{"name":"new_server_salt","type":"long"}],"type":"BadMsgNotification"},{"id":"2105940488","predicate":"msg_resend_req","params":[{"name":"msg_ids","type":"Vector"}],"type":"MsgResendReq"},{"id":"-630588590","predicate":"msgs_state_req","params":[{"name":"msg_ids","type":"Vector"}],"type":"MsgsStateReq"},{"id":"81704317","predicate":"msgs_state_info","params":[{"name":"req_msg_id","type":"long"},{"name":"info","type":"bytes"}],"type":"MsgsStateInfo"},{"id":"-1933520591","predicate":"msgs_all_info","params":[{"name":"msg_ids","type":"Vector"},{"name":"info","type":"bytes"}],"type":"MsgsAllInfo"},{"id":"661470918","predicate":"msg_detailed_info","params":[{"name":"msg_id","type":"long"},{"name":"answer_msg_id","type":"long"},{"name":"bytes","type":"int"},{"name":"status","type":"int"}],"type":"MsgDetailedInfo"},{"id":"-2137147681","predicate":"msg_new_detailed_info","params":[{"name":"answer_msg_id","type":"long"},{"name":"bytes","type":"int"},{"name":"status","type":"int"}],"type":"MsgDetailedInfo"},{"id":"1973679973","predicate":"bind_auth_key_inner","params":[{"name":"nonce","type":"long"},{"name":"temp_auth_key_id","type":"long"},{"name":"perm_auth_key_id","type":"long"},{"name":"temp_session_id","type":"long"},{"name":"expires_at","type":"int"}],"type":"BindAuthKeyInner"}],"methods":[{"id":"1615239032","method":"req_pq","params":[{"name":"nonce","type":"int128"}],"type":"ResPQ"},{"id":"-686627650","method":"req_DH_params","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"p","type":"bytes"},{"name":"q","type":"bytes"},{"name":"public_key_fingerprint","type":"long"},{"name":"encrypted_data","type":"bytes"}],"type":"Server_DH_Params"},{"id":"-184262881","method":"set_client_DH_params","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"encrypted_data","type":"bytes"}],"type":"Set_client_DH_params_answer"},{"id":"1491380032","method":"rpc_drop_answer","params":[{"name":"req_msg_id","type":"long"}],"type":"RpcDropAnswer"},{"id":"-1188971260","method":"get_future_salts","params":[{"name":"num","type":"int"}],"type":"FutureSalts"},{"id":"2059302892","method":"ping","params":[{"name":"ping_id","type":"long"}],"type":"Pong"},{"id":"-213746804","method":"ping_delay_disconnect","params":[{"name":"ping_id","type":"long"},{"name":"disconnect_delay","type":"int"}],"type":"Pong"},{"id":"-414113498","method":"destroy_session","params":[{"name":"session_id","type":"long"}],"type":"DestroySessionRes"},{"id":"-1835453025","method":"http_wait","params":[{"name":"max_delay","type":"int"},{"name":"wait_after","type":"int"},{"name":"max_wait","type":"int"}],"type":"HttpWait"}]} \ No newline at end of file diff --git a/original_telepy/credentials b/original_telepy/credentials new file mode 100644 index 00000000..bcd5101f --- /dev/null +++ b/original_telepy/credentials @@ -0,0 +1,5 @@ +[App data] +api_id = 25628 +api_hash = 1fe17cda7d355166cdaa71f04122873c +ip_address = 149.154.167.50 +port = 443 diff --git a/original_telepy/mtproto.py b/original_telepy/mtproto.py index a6dac452..e5a3f5ce 100644 --- a/original_telepy/mtproto.py +++ b/original_telepy/mtproto.py @@ -143,7 +143,6 @@ class Session: f = open(os.path.join(os.path.dirname(__file__), "rsa.pub")) key = RSA.importKey(f.read()) - print(getattr(key.key, 'n') . getattr(key.key, 'e')) ResPQ = self.method_call('req_pq', nonce=nonce) server_nonce = ResPQ['server_nonce'] # TODO: selecting RSA public key based on this fingerprint diff --git a/src/danog/MadelineProto/Session.php b/src/danog/MadelineProto/Session.php index aa304555..a6ec818f 100755 --- a/src/danog/MadelineProto/Session.php +++ b/src/danog/MadelineProto/Session.php @@ -219,14 +219,19 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB $this->log->log(sprintf('Factorization %s = %s * %s', $pq, $p, $q)); + // Serialize object for req_DH_params $p_bytes = $this->struct->pack('>Q', (string) $p); $q_bytes = $this->struct->pack('>Q', (string) $q); $new_nonce = \phpseclib\Crypt\Random::string(32); $data = $this->tl->serialize_obj('p_q_inner_data', ['pq' => $pq_bytes, 'p' => $p_bytes, 'q' => $q_bytes, 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'new_nonce' => $new_nonce]); $sha_digest = sha1($data, true); + + // Encrypt serialized object $random_bytes = \phpseclib\Crypt\Random::string(255 - strlen($data) - strlen($sha_digest)); $to_encrypt = $sha_digest.$data.$random_bytes; $encrypted_data = $this->key->encrypt($to_encrypt); + + // req_DH_params $this->log->log('Starting Diffie Hellman key exchange'); $server_dh_params = $this->method_call('req_DH_params', ['nonce' => $nonce, 'server_nonce' => $server_nonce, 'p' => $p_bytes, 'q' => $q_bytes, 'public_key_fingerprint' => $public_key_fingerprint, 'encrypted_data' => $encrypted_data]); if ($nonce != $server_dh_params['nonce']) { diff --git a/src/danog/MadelineProto/libpy2php/libpy2php.php b/src/danog/MadelineProto/libpy2php/libpy2php.php deleted file mode 100644 index 659b5436..00000000 --- a/src/danog/MadelineProto/libpy2php/libpy2php.php +++ /dev/null @@ -1,524 +0,0 @@ - 1 && $step > ($stop - $start)) { - $arr = [$start]; - } else { - $arr = range($start, $stop, $step); - array_pop($arr); - } - - return $arr; -} - -function pyjslib_filter($callback, $iterable) -{ - $a = []; - foreach ($iterable as $item) { - if (call_user_func($callback, $item)) { - $a[] = $item; - } - } - - return $a; -} - -function pyjslib_globals() -{ - return $GLOBALS; -} - - -function pyjslib_map($callable) -{ - $done = false; - $call_cnt = 0; - $results = []; - - $params = func_get_args(); - array_shift($params); - - while (!$done) { - $func_args = []; - $found = false; - for ($i = 0; $i < count($params); $i++) { - $func_args[] = @$params[$i][$call_cnt]; - if (count($params[$i]) > $call_cnt + 1) { - $found = true; - } - } - if (!$found) { - $done = true; - } - $results[] = call_user_func_array($callable, $func_args); - $call_cnt++; - } - - return $results; -} - -function pyjslib_zip() -{ - $params = func_get_args(); - if (count($params) === 1) { // this case could be probably cleaner - // single iterable passed - $result = []; - foreach ($params[0] as $item) { - $result[] = [$item]; - } - - return $result; - } - $result = call_user_func_array('array_map', array_merge([null], $params)); - $length = min(array_map('count', $params)); - - return array_slice($result, 0, $length); -} - -function pyjslib_is_assoc($arr) -{ - return array_keys($arr) !== range(0, count($arr) - 1); -} - -function pyjslib_dict($arg = null) -{ - if ($arg === null) { - return []; - } - if (pyjslib_is_assoc($arg)) { - return $arg; - } - $dict = []; - foreach ($arg as $a) { - if (count($a) == 2) { - $dict[$a[0]] = $a[1]; - } - } - - return $dict; -} - -function pyjslib_printWorker($objs, $nl, $multi_arg, $depth = 1) -{ - $buf = ''; - if (is_array($objs) && $multi_arg && $depth == 1) { - $cnt = 0; - foreach ($objs as $obj) { - if ($cnt++ > 0) { - $buf .= ' '; - } - $buf .= pyjslib_printWorker($obj, $nl, $multi_arg, $depth + 1); - } - } elseif (is_bool($objs)) { - $buf = $objs ? 'True' : 'False'; - } elseif (is_null($objs)) { - $buf = 'None'; - } elseif (is_float($objs)) { - $buf = (int) $objs; - } elseif (is_string($objs) && ($multi_arg && $depth > 2 || (!$multi_arg && $depth > 1))) { - $buf = "'$objs'"; - } elseif (is_array($objs)) { - $buf = '['; - $cnt = 0; - foreach ($objs as $obj) { - $val = pyjslib_printWorker($obj, $nl, false, $depth + 1); - if ($cnt++ > 0) { - $buf .= ', '; - } - $buf .= $val; - } - $buf .= ']'; -// $buf = '[' . implode( ", ", $objs ) . ']'; - } else { - $buf = $objs; - } - if ($depth == 1 && (!strlen($buf) || $buf[strlen($buf) - 1] != "\n")) { - $buf .= $nl ? "\n" : ' '; - } - - return $buf; -} - -function pyjslib_repr($obj) -{ - return pyjslib_printWorker($obj, false, false); -} - -function pyjslib_print($objs, $multi_arg = false) -{ - echo pyjslib_printWorker($objs, false, $multi_arg); -} - -function pyjslib_printnl($objs, $multi_arg = false) -{ - echo pyjslib_printWorker($objs, true, $multi_arg); -} - -function py2php_kwargs_function_call($funcname, $ordered, $named) -{ - if ($funcname == 'array' || $funcname == 'pyjslib_dict') { - return $named; - } - - $num_ordered = count($ordered); - $count = 1; - - $refFunc = new ReflectionFunction($funcname); - foreach ($refFunc->getParameters() as $param) { - if ($param->isVariadic()) { - $ordered[$count - 1] = $named; - break; - } - //invokes ReflectionParameter::__toString - if ($count > $num_ordered) { - $name = $param->name; - $default = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null; - $ordered[] = @$named[$name] ?: $default; - } - - $count++; - } - //var_dump($ordered); - return call_user_func_array($funcname, $ordered); -} - -function py2php_kwargs_method_call($obj, $method, $ordered, $named) -{ - $num_ordered = count($ordered); - $count = 1; - - $refFunc = new ReflectionMethod($obj, $method); - foreach ($refFunc->getParameters() as $param) { - //invokes ReflectionParameter::__toString - if ($count > $num_ordered) { - $name = $param->name; - $default = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null; - $ordered[] = @$named[$name] ?: $default; - } - - $count++; - } - - $callable = [$obj, $method]; - - return call_user_func_array($callable, $ordered); -} - -class IOError extends Exception -{ -} - -class ValueError extends Exception -{ -} - - -function pyjslib_open($name, $mode = 'r', $buffering = null) -{ - return new pyjslib_file($name, $mode, $buffering); -} - -class pyjslib_file implements Iterator -{ - private $fh = false; - private $current_line = null; - - // public attributes of python file class. - public $closed = true; - public $encoding = null; - public $errors = []; - public $mode = null; - public $newlines = null; - public $softspace = false; - - public function __construct($name_or_fd, $mode = 'r', $buffering = null) - { - if (is_resource($name_or_fd)) { - $this->fh = $name_or_fd; - $this->closed = false; - $meta = stream_get_meta_data($name_or_df); - $this->mode = $meta['mode']; - - return; - } - $name = $name_or_fd; - try { - $this->fh = fopen($name, $mode); - if (!$this->fh) { - throw new Exception("Could not open $name"); - } - $this->closed = false; - $this->mode = $mode; - } catch (Exception $e) { - throw new IOError($e->getMessage(), $e->getCode()); - } - } - - public function close() - { - if ($this->fh) { - fclose($this->fh); - $this->fh = null; - $this->closed = true; - } - } - - public function flush() - { - if (!$this->fh) { - throw new ValueError('File is closed.'); - } - fflush($this->fh); - } - - public function fileno() - { - if (!$this->fh) { - throw new ValueError('File is closed.'); - } - - return $this->fh; - } - - public function isatty() - { - if (!$this->fh) { - throw new ValueError('File is closed.'); - } - - return posix_isatty($this->fh); - } - - /* --- - * Begin PHP Iterator implementation - * --- - */ - public function rewind() - { - fseek($this->fh, 0); - $this->line = 0; - } - - public function current() - { - if (!$this->current_line) { - $this->current_line = fgets($this->fh); - } - - return $this->current_line; - } - - public function key() - { - return $this->line; - } - - public function next() - { - $this->current(); // ensure current line has been retrieved. - $this->current_line = fgets($this->fh); - $this->line++; - - return $this->current_line; - } - - public function valid() - { - return $this->fh != false && !feof($this->fh); - } - - /* --- - * End PHP Iterator implementation - * --- - */ - - public function read($size = null) - { - if ($size !== null) { - return fread($this->fh, $size); - } - - return stream_get_contents($this->fh); - } - - public function readline($size = null) - { - return fgets($this->fh, $size); - } - - public function readlines($sizehint = null) - { - $len = 0; - $lines = []; - while ($line = fgets($this->fh)) { - $len += strlen($line); - $lines[] = $line; - if ($sizehint && $len >= $sizehint) { - break; - } - } - - return $lines; - } - - public function seek($offset, $whence = SEEK_SET) - { - return fseek($this->fh, $offset, $whence); - } - - public function tell() - { - return ftell($this->fh); - } - - public function truncate($size) - { - $rc = ftruncate($this->fh, $size); - } - - public function write($str) - { - fwrite($this->fh, $str); - } - - public function writelines($sequence) - { - foreach ($sequence as $line) { - $this->write($line); - } - } -} diff --git a/src/danog/MadelineProto/libpy2php/os.php b/src/danog/MadelineProto/libpy2php/os.php deleted file mode 100644 index ec91573d..00000000 --- a/src/danog/MadelineProto/libpy2php/os.php +++ /dev/null @@ -1,683 +0,0 @@ - $v) { - $attr = 'st_'.$key; - $obj->$attr = $v; - } - - return $obj; - } - - public static function fstatvfs($fd) - { - self::_unimplemented(); - } - - public static function fsync($fd) - { - fsync($fd); - } - - public static function ftruncate($fd, $length) - { - ftruncate($fd, $length); - } - - public static function isatty($fd) - { - return posix_isatty($fd); - } - - public static function lseek($fd, $pos, $how) - { - lseek($fd, $pos, $how); - } - - public static function open($file, $flags, $mode = 0777) - { - // todo: define and map flag constants. See list at: - // https://docs.python.org/2/library/os.html#open-flag-constants - - $fl = ''; - if ($flags & self::O_RDONLY) { - $fl .= 'r'; - } - if ($flags & self::O_WRONLY) { - $fl .= 'w'; - } - if ($flags & self::O_RDWR) { - $fl .= 'rw'; - } - if ($flags & self::O_APPEND) { - $fl .= 'a'; - } - if ($flags & self::O_CREAT) { - $fl .= 'c'; - } - if ($flags & self::O_EXCL) { - $fl .= 'x'; - } - if ($flags & self::O_TRUNC) { - $fl .= 'w'; - } - - return fopen($file, $fl, false); - } - - public static function pipe() - { - self::_unimplemented(); - } - - public static function read($fd, $n) - { - return fread($fd, $n); - } - - public static function tcgetpgrp($fd) - { - self::_unimplemented(); - } - - public static function tcsetpgrp($fd, $pg) - { - self::_unimplemented(); - } - - public static function ttyname($fd) - { - return posix_ttyname($fd); - } - - public static function write($fd, $str) - { - return fwrite($fd, $str); - } - - public static function access($path, $mode) - { - return posix_access($path, $mode); - } - - public static function chdir($path) - { - chdir($path); - } - - public static function fchdir($path) - { - fchdir($path); - } - - public static function getcwd() - { - return getcwd(); - } - - public static function getcwdu() - { - return getcwd(); - } - - public static function chflags($path, $flags) - { - self::_unimplemented(); - } - - public static function chroot($path) - { - chroot($path); - } - - public static function chmode($path, $mode) - { - self::_unimplemented(); - } - - public static function chown($path, $uid, $gid) - { - chown($path, $uid, $gid); - } - - public static function lchflags($path, $flags) - { - self::_unimplemented(); - } - - public static function lchmod($path, $mode) - { - self::_unimplemented(); - } - - public static function lchown($path, $uid, $gid) - { - self::_unimplemented(); - } - - public static function link($source, $link_name) - { - link($source, $link_name); - } - - public static function listdir($path) - { - self::_unimplemented(); - } - - public static function lstat($path) - { - self::_unimplemented(); - } - - public static function mkfifo($path, $mode = 0666) - { - posix_mkfifo($path, $mode); - } - - public static function mknod($filename, $mode = 0666, $device = 0) - { - return posix_mknod($filename, $mode); - } - - public static function major($path, $flags) - { - self::_unimplemented(); - } - - public static function minor($path, $flags) - { - self::_unimplemented(); - } - - public static function makedev($major, $minor) - { - self::_unimplemented(); - } - - public static function mkdir($path, $mode = 0777) - { - mkdir($path, $mode, $recursive = false); - } - - public static function makedirs($path, $mode = 0777) - { - mkdir($path, $mode, $recursive = true); - } - - public static function pathconf($path, $name) - { - self::_unimplemented(); - } - - public static function readlink($path) - { - return readlink($path); - } - - public static function remove($path) - { - if (!is_file($path)) { - throw new OSError("Path is not a file. $path"); - } - try { - unlink($path); - } catch (Exception $e) { - throw new OSError($e->getMessage(), $e->getCode()); - } - } - - public static function removedirs($path) - { - self::_unimplemented(); - } - - public static function rename($src, $dst) - { - if (is_dir($dst)) { - throw new OSError("Destination is a directory. $dst"); - } - rename($src, $dst); - } - - public static function renames($old, $new) - { - self::makedirs(dirname($new)); - self::rename($old, $new); - } - - public static function rmdir($path) - { - rmdir($pat); - } - - public static function stat($path) - { - $arr = stat($path); - if (!$arr) { - throw new OSError("Path does not exist. $path"); - } - $obj = new stdClass(); - foreach ($arr as $key => $v) { - $attr = 'st_'.$key; - $obj->$attr = $v; - } - - return $obj; - } - - public static function stat_float_times($newvalue = null) - { - self::_unimplemented(); - } - - public static function statvfs() - { - self::_unimplemented(); - } - - public static function symlink($source, $link_name) - { - symlink($source, $link_name); - } - - public static function tempnam($dir = null, $prefix = '') - { - if (!$dir) { - $dir = sys_get_temp_dir(); - } - $name = tempnam($dir, $prefix); - unlink($name); - - return $name; - } - - public static function tmpnam() - { - return self::tempnam(); - } - - public static function unlink($path) - { - unlink($path); - } - - public static function utime($path, $times) - { - self::_unimplemented(); - } - - public static function walk($top, $topdown = true, $onerror = null, $followlinks = false) - { - self::_unimplemented(); - } - - /** - * Begin Process Management. - */ - public static function abort() - { - self::_unimplemented(); - } - - public static function execl($path, $arg0, $arg1) - { - self::_unimplemented(); - } - - public static function execle($path, $arg0, $arg1, $env) - { - self::_unimplemented(); - } - - public static function execlp($file, $arg0, $arg1) - { - self::_unimplemented(); - } - - public static function execlpe($file, $arg0, $arg1, $env) - { - self::_unimplemented(); - } - - public static function execv($path, $args) - { - self::_unimplemented(); - } - - public static function execve($path, $args, $env) - { - self::_unimplemented(); - } - - public static function execvp($file, $args) - { - self::_unimplemented(); - } - - public static function execvpe($file, $args, $env) - { - self::_unimplemented(); - } - - public static function _exit($n) - { - exit($n); - } - - public static function fork() - { - return pcntl_fork(); - } - - public static function forkpty() - { - self::_unimplemented(); - } - - public static function kill($pid, $sig) - { - posix_kill($pid, $sig); - } - - public static function killpg($pgid, $sig) - { - self::_unimplemented(); - } - - public static function nice($increment) - { - proc_nice($increment); - } - - public static function plock($op) - { - self::_unimplemented(); - } - - private static function _unimplemented() - { - throw new Exception('Unimplemented. Please consider submitting a patch to py2php project on github.'); - } -} diff --git a/src/danog/MadelineProto/libpy2php/os_path.php b/src/danog/MadelineProto/libpy2php/os_path.php deleted file mode 100644 index ee7a6ffd..00000000 --- a/src/danog/MadelineProto/libpy2php/os_path.php +++ /dev/null @@ -1,251 +0,0 @@ - $v) { - if (!is_scalar($v)) { - continue; - } - $map['$'.$k] = $v; - $map['${'.$k.'}'] = $v; - } - - return strtr($path, $map); - } - - public static function getatime($path) - { - try { - $rc = fileatime($path); - - return $rc; - } catch (Exception $e) { - throw new OSError($e->getMessage, $e->getCode()); - } - } - - public static function getmtime($path) - { - try { - $rc = filemtime($path); - - return $rc; - } catch (Exception $e) { - throw new OSError($e->getMessage, $e->getCode()); - } - } - - public static function getctime($path) - { - try { - $rc = filectime($path); - - return $rc; - } catch (Exception $e) { - throw new OSError($e->getMessage, $e->getCode()); - } - } - - public static function getsize($path) - { - try { - $rc = filesize($path); - - return $rc; - } catch (Exception $e) { - throw new OSError($e->getMessage, $e->getCode()); - } - } - - public static function isabs($path) - { - // fixme: implement check for windows. - return $path[0] == '/'; - } - - public static function isfile($path) - { - return is_file($path); - } - - public static function isdir($path) - { - return is_dir($path); - } - - public static function islink($path) - { - return is_link($path); - } - - public static function ismount($path) - { - self::_unimplemented(); - } - - public static function split($path) - { - $parts = explode(DIRECTORY_SEPARATOR, $path); - $first = implode(DIRECTORY_SEPARATOR, array_slice($parts, 0, count($parts) - 1)); - $last = $parts[count($parts) - 1]; - - return [$first, $last]; - } - - public static function join($path, ...$paths) - { - $buf = rtrim($path, '/'); - foreach ($paths as $p) { - $i = 0; - $p = trim($p, '/'); - $buf .= DIRECTORY_SEPARATOR.$p; - } - - return $buf; - } - - public static function normcase($path) - { - // fixme: different behavior on windows. - return $path; - } - - public static function normpath($path) - { - return realpath($path); - } - - public static function realpath($path) - { - return realpath($path); - } - - public static function relpath($path, $start) - { - self::_unimplemented(); - } - - public static function samefile($path1, $path2) - { - return fileinode($path1) == fileinode($path2); - } - - public static function sameopenfile($fd1, $fd2) - { - $s1 = fstat($fd1); - $s2 = fstat($fd2); - - return $s1['ino'] == $s2['ino']; - } - - public static function samestat($stat1, $stat2) - { - return $stat1 == $stat2; - } - - public static function splitdrive($path) - { - //fixme: implement windows case. - return ['', $path]; - } - - public static function splitext($path) - { - $first = $path; - $second = ''; - - $pos = strrpos($path, '.'); - if ($pos !== false) { - $first = substr($path, 0, $pos); - $second = substr($path, $pos); - } - - return [$first, $second]; - } - - public static function splitunc($path) - { - self::_unimplemented(); - } - - public static function walk($path, $visit, $arg) - { - // Note: deprecated in python 3 in favor of os.walk() - self::_unimplemented(); - } - - private static function _unimplemented() - { - throw new Exception('Unimplemented. Please consider submitting a patch to py2php project on github.'); - } -} diff --git a/src/danog/MadelineProto/libpy2php/strict_mode.php b/src/danog/MadelineProto/libpy2php/strict_mode.php deleted file mode 100644 index 156d04d1..00000000 --- a/src/danog/MadelineProto/libpy2php/strict_mode.php +++ /dev/null @@ -1,138 +0,0 @@ -getCode(), $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()); - while (($e = $e->getPrevious())) { - $msg .= sprintf("\nPrevious Exception. code: %s, message: %s\n%s : %s\n\nStack Trace:\n%s\n", $e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()); - } - echo $msg; - // error_log( $msg ); - strict_mode_mail_admin('Uncaught exception!', $msg); - echo "\n\nNow exiting. Please report this problem to the software author\n\n"; - exit(1); -} - -/** - * This shutdown handler callback prints a message and sends email on any PHP fatal error. - */ -function shutdown_handler() -{ - $error = error_get_last(); - - $ignore = E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED; - if ($error && ($error['type'] & $ignore) == 0) { - - // error keys: type, file, line, message - $msg = "Ouch! Encountered PHP Fatal Error. Shutting down.\n".print_r($error, true); - echo $msg; - strict_mode_mail_admin('PHP Fatal Error!', $msg); - } -} - -/** - * email admin if defined. - */ -function strict_mode_mail_admin($subject, $msg) -{ - $subject = sprintf('[%s] [%s] %s [pid: %s]', gethostname(), basename($_SERVER['PHP_SELF']), $subject, getmypid()); - if (defined('ALERTS_MAIL_TO')) { - mail(ALERTS_MAIL_TO, $subject, $msg); - } else { - echo "\nWARNING: ALERTS_MAIL_TO not defined in environment. alert not sent with subject: $subject\n"; - } -}