Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
fix(Tracker): Fix TrackerException Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jul 25, 2019
1 parent b018663 commit b4543b1
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions apps/controllers/TrackerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,8 @@ public function actionIndex()
}
} catch (TrackerException $e) {
// Record agent deny log in Table `agent_deny_log`
if ($e->getCode() >= 120) {
$raw_header = "";
foreach (app()->request->header() as $key => $value) {
$raw_header .= "$key : $value \n";
}
$req_info = app()->request->server('query_string') . "\n\n" . $raw_header;

app()->pdo->createCommand("INSERT INTO `agent_deny_log`(`tid`, `uid`, `user_agent`, `peer_id`, `req_info`,`create_at`, `msg`)
VALUES (:tid,:uid,:ua,:peer_id,:req_info,CURRENT_TIMESTAMP,:msg)
ON DUPLICATE KEY UPDATE `user_agent` = VALUES(`user_agent`),`peer_id` = VALUES(`peer_id`),
`req_info` = VALUES(`req_info`),`msg` = VALUES(`msg`),
`last_action_at` = NOW();")->bindParams([
"tid" => $torrentInfo ? $torrentInfo["id"] : 0,
'uid' => $userInfo ? $userInfo["id"] : 0,
'ua' => app()->request->header("user-agent", ""),
'peer_id' => app()->request->get("peer_id", ""),
'req_info' => $req_info,
'msg' => $e->getMessage()
])->execute();
if ($e->getCode() >= 124) {
$this->logException($e, $userInfo, $torrentInfo);
}

return Bencode::encode([
Expand All @@ -152,6 +135,28 @@ public function actionIndex()
}
}

protected function logException(\Exception $exception, $userInfo = null, $torrentInfo = null)
{
$raw_header = "";
foreach (app()->request->header() as $key => $value) {
$raw_header .= "$key : $value \n";
}
$req_info = app()->request->server('query_string') . "\n\n" . $raw_header;

app()->pdo->createCommand("INSERT INTO `agent_deny_log`(`tid`, `uid`, `user_agent`, `peer_id`, `req_info`,`create_at`, `msg`)
VALUES (:tid,:uid,:ua,:peer_id,:req_info,CURRENT_TIMESTAMP,:msg)
ON DUPLICATE KEY UPDATE `user_agent` = VALUES(`user_agent`),`peer_id` = VALUES(`peer_id`),
`req_info` = VALUES(`req_info`),`msg` = VALUES(`msg`),
`last_action_at` = NOW();")->bindParams([
"tid" => $torrentInfo ? $torrentInfo["id"] : 0,
'uid' => $userInfo ? $userInfo["id"] : 0,
'ua' => app()->request->header("user-agent", ""),
'peer_id' => app()->request->get("peer_id", ""),
'req_info' => $req_info,
'msg' => $exception->getMessage()
])->execute();
}

/** Check Client's User-Agent, (If not pass this Check , A TrackerException will throw)
* @throws TrackerException
*/
Expand Down

0 comments on commit b4543b1

Please sign in to comment.