-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsign_action.php
100 lines (75 loc) · 2.22 KB
/
sign_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
<?php
require_once 'init.php';
$ag_ent = $_GET['agent'];
$agentip = $_SERVER['REMOTE_ADDR'];
if(!preg_match('/\w{12}/',$ag_ent)){
exit();
}
if(!checkip($agentip)){
echo 'You adddress are not allow!';
exit();
}
$current_time=date('H',time('HH'));
if(!checktime($current_time)){
echo 'You online_time are not allow!';
exit();
}
$db = new db_sql_functions();
$username = $db->check_agentid($ag_ent);
if($username){
$ntime = time();
//Check the heartbeat
$res = $db->check_heartbeat($username,$ntime-120);
if($res){
$uid = $res['uid'];
$stime = $res['stime'];
$db->update_heartbeat($uid,$stime);
echo 'Agent signing successed';
}else{
$db->add_heartheat($username);
echo 'Agent signing successed';
}
}else{
echo 'Agent not registered';
exit();
}
function checkip($ip){
global $ALLOW_HOST;
$len = count($ALLOW_HOST);
$ip_arr = explode('.',$ip);
for($i=0;$i<$len;$i++){
$flag = 0;
$host_arr = explode('.',$ALLOW_HOST[$i]);
for($j=0;$j<count($host_arr);$j++){
if($host_arr[$j] == '*'){
$flag += 1;
continue;
}
if($ip_arr[$j] != $host_arr[$j]){
break;
}
$flag += 1;
}
if($flag==4) return true;
}
return false;
}
function checktime($current_time){
global $DISALLOWED_TIME;
$len = count($DISALLOWED_TIME);
$tagArr = array();
for($i=0;$i<$len;$i++){
$time_point_arr = explode('-',$DISALLOWED_TIME[$i]);
if($current_time <= $time_point_arr[1] && $current_time >= $time_point_arr[0] ){
array_push($tagArr,'0');
}else{
array_push($tagArr,'1');
}
}
if($tagArr[0] == 1 && $tagArr[1] == 1){
return true;
}else{
return false;
}
}
?>