-
Notifications
You must be signed in to change notification settings - Fork 0
/
include.php
executable file
·236 lines (200 loc) · 6.67 KB
/
include.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
//打开session,如果打开了,可以删除
if ( session_status () == 1 ) {
session_start ();
}
#注册插件
RegisterPlugin ( "commentGeetest" , "ActivePlugin_commentGeetest" );
$GLOBALS[ 'actions' ][ 'verification' ] = 6;
function ActivePlugin_commentGeetest () {
global $zbp;
//验证
Add_Filter_Plugin ( "Filter_Plugin_Cmd_Begin" , "commentGeetestCmdBegin" );
/**
* 开关检查,开启了,才会用到
*/
if ( $zbp->Config ( 'commentGeetest' )->active ) {
Add_Filter_Plugin ( 'Filter_Plugin_Zbp_Load' , 'commentGeetest_Load' );
}
/**
* 开关检查,开启了,才会用到
*/
if ( $zbp->Config ( 'commentGeetest' )->loginActive ) {
//JS插入
Add_Filter_Plugin ( "Filter_Plugin_Login_Header" , "commentGeetest_Set_Header_js" );
}
}
//Zbp类的加载接口
function commentGeetest_Load () {
global $zbp;
if ($zbp->user->Level != 1) {
Add_Filter_Plugin ( 'Filter_Plugin_ViewPost_Template' , 'commentGeetestJsAdd' );
}
}
function InstallPlugin_commentGeetest () {
global $zbp;
//看看有没有
if ( ! $zbp->Config ( 'commentGeetest' )->appId ) {
$zbp->Config ( 'commentGeetest' )->appId = '3386e03c620a4067f18fa92c370f1594';
$zbp->Config ( 'commentGeetest' )->appKey = '5fe89444b54d3a3b8e49594c42a770cf';
$zbp->Config ( 'commentGeetest' )->active = 0;
$zbp->Config ( 'commentGeetest' )->loginActive = 0;
$zbp->Config ( 'commentGeetest' )->loginStyle = 'float:left;';
$zbp->Config ( 'commentGeetest' )->loginPosition = '.password';
$zbp->SaveConfig ( 'commentGeetest' );
}
}
function UninstallPlugin_commentGeetest () {
global $zbp;
$zbp->DelConfig('commentGeetest');
}
/**
* 路由开始
*/
function commentGeetestCmdBegin () {
global $zbp;
$action = GetVars ( 'act' , 'GET' );
switch ( $action ) {
case 'verify':
if ( $zbp->Config ( 'commentGeetest' )->loginActive ) {
commentGeetest_Login_Validate ($_POST);//登陆验证
}
break;
case "verification":
$param = GetVars ( 'type' , 'GET' );
switch ( $param ) {
case 'getcode':
commentGeetestGetCode ();//获取验证码
break;
case 'validate_captcha':
commentGeetestGetCodeValidateCaptcha ( $_POST );//极验证二次验证
break;
}
break;
default:
return true;
}
}
/**
* 获取验证码
*/
function commentGeetestGetCode () {
global $zbp;
require_once $zbp->path . 'zb_users/plugin/commentGeetest/sdk/gt-php-sdk/lib/class.geetestlib.php';
$GtSdk = new \GeetestLib();
$return = $GtSdk->register ();
if ( $return ) {
$_SESSION[ 'gtserver' ] = 1;
$result = array (
'success' => 1 ,
'gt' => CAPTCHA_ID ,
'challenge' => $GtSdk->challenge,
);
} else {
$_SESSION[ 'gtserver' ] = 0;
$rnd1 = md5 ( rand ( 0 , 100 ) );
$rnd2 = md5 ( rand ( 0 , 100 ) );
$challenge = $rnd1 . substr ( $rnd2 , 0 , 2 );
$result = array (
'success' => 0 ,
'gt' => CAPTCHA_ID ,
'challenge' => $challenge
);
$_SESSION[ 'challenge' ] = $result[ 'challenge' ];
}
if ($zbp->Config ( 'commentGeetest' )->loginActive) {
$result[ 'style' ] = $zbp->Config ( 'commentGeetest' )->loginStyle;
$result[ 'position' ] = $zbp->Config ( 'commentGeetest' )->loginPosition;
}
echo json_encode ( $result );
die;
}
/**
* 这里二次验证极验证是否正确
*/
function commentGeetestGetCodeValidateCaptcha ( $postData ) {
global $zbp;
require_once $zbp->path . 'zb_users/plugin/commentGeetest/sdk/gt-php-sdk/lib/class.geetestlib.php';
$result = false;
$GtSdk = new \GeetestLib();
if ( $_SESSION[ 'gtserver' ] == 1 ) {
$result = $GtSdk->validate ( $postData[ 'geetest_challenge' ] , $postData[ 'geetest_validate' ] , $postData[ 'geetest_seccode' ] );
if ( $result == TRUE ) {
$result = true;
} else if ( $result == FALSE ) {
$result = false;
} else {
$result = false;
}
} else {
if ( $GtSdk->get_answer ( $postData[ 'geetest_validate' ] ) ) {
$result = true;
} else {
$result = false;
}
}
if ( ! $result ) {
echo json_encode ( [
'code' => 0 ,
'msg' => '错误'
] );
} else {
echo json_encode ( [
'code' => 200 ,
'msg' => '正确'
] );
}
die;
}
/**
* 添加js
*/
function commentGeetestJsAdd ( &$template ) {
global $zbp;
$src = '<script src="' . $zbp->host . 'zb_users/plugin/commentGeetest/resources/commentGeetest.js' . '" type="text/javascript"></script>';
$src .= '<script src="' . $zbp->host . 'zb_users/plugin/commentGeetest/resources/gt.js' . '" type="text/javascript"></script>';
$src .= <<<eof
eof;
$content = $template->GetTags ( 'article' )->Content;
$template->GetTags ( 'article' )->Content = $content . $src;
}
/**
* 登陆设置
*/
function commentGeetest_Set_Header_js () {
global $zbp;
?>
<script type='text/javascript' src="<?php echo $zbp->host; ?>zb_users/plugin/commentGeetest/resources/gt.js"></script>
<script type='text/javascript' src="<?php echo $zbp->host; ?>zb_users/plugin/commentGeetest/resources/LoginGeetest.js"></script>
<?php
}
/**
* 登陆验证
* @param $postData
*/
function commentGeetest_Login_Validate ( $postData ) {
global $zbp;
require_once $zbp->path . 'zb_users/plugin/commentGeetest/sdk/gt-php-sdk/lib/class.geetestlib.php';
$result = false;
$GtSdk = new \GeetestLib();
if ( $_SESSION[ 'gtserver' ] == 1 ) {
$result = $GtSdk->validate ( $postData[ 'geetest_challenge' ] , $postData[ 'geetest_validate' ] , $postData[ 'geetest_seccode' ] );
if ( $result == TRUE ) {
$result = true;
} else if ( $result == FALSE ) {
$result = false;
} else {
$result = false;
}
} else {
if ( $GtSdk->get_answer ( $postData[ 'geetest_validate' ] ) ) {
$result = true;
} else {
$result = false;
}
}
if ( ! $result ) {
$zbp->ShowError('验证失败:拖动滑块将悬浮图像正确拼合');
die();
}
}