1.4 修复referer问题,添加删除日志功能

This commit is contained in:
Kokororin
2016-11-08 13:27:19 +08:00
parent c359f1b22c
commit a0ffc19ee1
5 changed files with 181 additions and 39 deletions

View File

@@ -4,11 +4,14 @@ class Access_Action implements Widget_Interface_Do
private $response;
private $request;
private $extend;
public function __construct()
{
$this->response = Typecho_Response::getInstance();
$this->request = Typecho_Request::getInstance();
require_once __DIR__ . '/Access.php';
$this->extend = new Access_Extend();
}
public function execute()
@@ -21,9 +24,51 @@ class Access_Action implements Widget_Interface_Do
public function ip()
{
$ip = $this->request->get('ip');
$response = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip);
exit($response);
$this->response->setContentType('application/json');
try {
$this->checkAuth();
$ip = $this->request->get('ip');
$response = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip);
if (!$response) {
throw new Exception('HTTP request failed');
}
exit($response);
} catch (Exception $e) {
exit(Json::encode(array(
'code' => 100,
'message' => $e->getMessage(),
)));
}
}
public function deleteLogs()
{
$this->response->setContentType('application/json');
try {
$this->checkAuth();
$data = @file_get_contents('php://input');
$data = Json::decode($data, true);
if (!is_array($data)) {
throw new Exception('params invalid');
}
$this->extend->deleteLogs($data);
exit(Json::encode(array(
'code' => 0,
)));
} catch (Exception $e) {
exit(Json::encode(array(
'code' => 100,
'message' => $e->getMessage(),
)));
}
}
protected function checkAuth()
{
if (!$this->extend->isAdmin()) {
throw new Exception('Access Denied');
}
}
}