mirror of
https://github.com/tursom/typecho-plugin-Access.git
synced 2026-08-19 08:13:27 +08:00
1.4 修复referer问题,添加删除日志功能
This commit is contained in:
51
Action.php
51
Action.php
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user