Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Fixes to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Mar 2, 2018
1 parent 416fbd5 commit 8f83dfa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/PWRTelegram/PWRTelegram/Main.php
Expand Up @@ -137,7 +137,7 @@ public function __construct($vars)
}
$this->get_me();
require 'vendor/autoload.php';
$madeline = new \danog\MadelineProto\API(['logger' => ['logger' => 1], 'pwr' => ['pwr' => true, 'db_token' => $this->db_token, 'strict' => true], 'app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'connection_settings' => ['all' => ['test_mode' => $this->deep]]]);
$madeline = new \danog\MadelineProto\API(['logger' => ['logger' => 1, 'logger_level' => 5], 'pwr' => ['pwr' => true, 'db_token' => $this->db_token, 'strict' => true], 'app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'connection_settings' => ['all' => ['test_mode' => $this->deep]]]);
$madeline->bot_login($this->token);
$madeline->API->get_updates_difference();
$madeline->API->store_db([], true);
Expand Down Expand Up @@ -403,7 +403,7 @@ public function run_methods()
require 'vendor/autoload.php';
$this->real_token = $this->base64url_encode(\phpseclib\Crypt\Random::string(32));
$this->madeline_path = $this->homedir.'sessions/pwrusertemp_'.hash('sha256', $this->real_token).'.madeline';
$madeline = new \danog\MadelineProto\API(['logger' => ['logger' => 1], 'pwr' => ['pwr' => true, 'db_token' => $this->db_token, 'strict' => true], 'app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'connection_settings' => ['all' => ['test_mode' => $this->deep]]]);
$madeline = new \danog\MadelineProto\API(['logger' => ['logger' => 1, 'logger_level' => 5], 'pwr' => ['pwr' => true, 'db_token' => $this->db_token, 'strict' => true], 'app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'connection_settings' => ['all' => ['test_mode' => $this->deep]]]);
//$madeline->API->settings['pwr']['update_handler'] = $madeline->API->settings['updates']['callback'];
$madeline->phone_login($this->REQUEST['phone']);
\danog\MadelineProto\Serialization::serialize($this->madeline_path, $madeline);
Expand Down
8 changes: 6 additions & 2 deletions storage.php
Expand Up @@ -28,7 +28,7 @@ function analytics($ok, $uri, $bot_id, $user, $pass)
$pdo = new \PDO('mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=stats', $user, $pass);
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
$pdo->prepare('INSERT INTO pwrtelegram (method, id, peak_ram, duration, ok, params) VALUES (?, ?, ?, ?, ?, ?, ?)')->execute(['/file', $bot_id, memory_get_peak_usage(), getrusage()['ru_utime.tv_usec'], (int) $ok, $uri]);
$pdo->prepare('INSERT INTO pwrtelegram (method, id, peak_ram, duration, ok, params) VALUES (?, ?, ?, ?, ?, ?)')->execute(['/file', $bot_id, memory_get_peak_usage(), getrusage()['ru_utime.tv_usec'], (int) $ok, $uri]);
} catch (PDOException $e) {
error_log($e);
}
Expand Down Expand Up @@ -95,7 +95,11 @@ function analytics($ok, $uri, $bot_id, $user, $pass)
if ($servefile) {
$pdo->prepare('INSERT INTO dl_stats (file, count) VALUES (?, 1) ON DUPLICATE KEY UPDATE count = count + 1;')->execute([$file_path]);
$madeline = glob($homedir.'/sessions/pwr_'.$select['bot'].'*')[0];
$MadelineProto = \danog\MadelineProto\Serialization::deserialize($madeline, true);
if ($madeline === null) {
analytics(false, $file_path, null, $dbuser, $dbpassword);
no_cache(404, '<html><body><h1>404 File not found.</h1><br><p>Could not fetch file info from database.</p></body></html>');
}
$MadelineProto = new \danog\MadelineProto\API($madeline);
\danog\MadelineProto\Logger::log($file_path);
$MadelineProto->API->getting_state = true;

Expand Down

0 comments on commit 8f83dfa

Please sign in to comment.