forked from kokororin/typecho-plugin-Access
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Action.php
103 lines (89 loc) · 2.93 KB
/
Action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
require_once __DIR__ . '/Access_Bootstrap.php';
class Access_Action extends Typecho_Widget implements Widget_Interface_Do
{
private $access;
public function __construct($request, $response, $params = null)
{
parent::__construct($request, $response, $params);
$this->access = new Access_Core();
}
public function execute()
{}
public function action()
{}
public function writeLogs()
{
$image = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAQUAP8ALAAAAAABAAEAAAICRAEAOw==');
$this->response->setContentType('image/gif');
if ($this->access->config->writeType == 1) {
$this->access->writeLogs(null, $this->request->u, $this->request->cid, $this->request->mid);
}
echo $image;
}
protected function checkAuth()
{
if (!$this->access->isAdmin()) {
throw new Exception('Access Denied', 401);
}
}
public function migration() {
try {
$this->checkAuth(); # 鉴权
$rpcType = $this->request->get('rpc'); # 业务类型
$logs = new Access_Migration($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 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
]);
}
}