typecho-plugin-Access/Action.php

83 lines
2.3 KiB
PHP
Raw Normal View History

<?php
2017-07-15 14:31:28 +08:00
require_once __DIR__ . '/Access_Bootstrap.php';
2018-01-26 17:20:26 +08:00
class Access_Action extends Typecho_Widget implements Widget_Interface_Do
{
2016-11-20 16:57:01 +08:00
private $access;
2018-01-26 17:20:26 +08:00
public function __construct($request, $response, $params = null)
{
2018-01-26 17:20:26 +08:00
parent::__construct($request, $response, $params);
2016-11-20 16:57:01 +08:00
$this->access = new Access_Core();
}
public function execute()
2018-01-25 18:55:06 +08:00
{}
public function action()
2018-01-25 18:55:06 +08:00
{}
public function writeLogs()
{
2017-07-14 11:09:10 +08:00
$image = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAQUAP8ALAAAAAABAAEAAAICRAEAOw==');
$this->response->setContentType('image/gif');
2017-07-15 14:31:28 +08:00
if ($this->access->config->writeType == 1) {
$this->access->writeLogs(null, $this->request->u, $this->request->cid, $this->request->mid);
}
2017-07-14 11:09:10 +08:00
echo $image;
}
protected function checkAuth()
{
2016-11-20 16:57:01 +08:00
if (!$this->access->isAdmin()) {
throw new Exception('Access Denied', 401);
}
}
public function logs() {
try {
$this->checkAuth(); # 鉴权
$rpcType = $this->request->get('rpc'); # 业务类型
$logs = new Access_Logs($this->request);
$data = $logs->invoke($rpcType); # 进行业务分发并调取数据
$errCode = 0;
$errMsg = 'ok';
} catch (Exception $e) {
$data = null;
$errCode = $e->getCode();
$errMsg = $e->getMessage();
}
$this->response->throwJson([
'code' => $errCode,
'message' => $errMsg,
'data' => $data
]);
}
public function statistic() {
try {
$this->checkAuth(); # 鉴权
if(!$this->request->isGet())
throw new Exception('Method Not Allowed', 405);
$rpcType = $this->request->get('rpc'); # 业务类型
$statistic = new Access_Statistic($this->request);
$data = $statistic->invoke($rpcType); # 进行业务分发并调取数据
$errCode = 0;
$errMsg = 'ok';
} catch (Exception $e) {
$data = null;
$errCode = $e->getCode();
$errMsg = $e->getMessage();
}
$this->response->throwJson([
'code' => $errCode,
'message' => $errMsg,
'data' => $data
]);
}
}