-
Notifications
You must be signed in to change notification settings - Fork 550
/
taskscan.php
124 lines (109 loc) · 4.62 KB
/
taskscan.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
<?php
require(dirname(__FILE__).'/include/config.inc.php');
date_default_timezone_set('Asia/Shanghai');
function sub_days($a,$b){
$a_dt=getdate($a);
$b_dt=getdate($b);
$a_new=mktime(12,0,0,$a_dt['mon'],$a_dt['mday'],$a_dt['year']);
$b_new=mktime(12,0,0,$b_dt['mon'],$b_dt['mday'],$b_dt['year']);
return round(abs($a_new-$b_new)/86400);
}
global $db;
$sql = "select * from scan_list LEFT JOIN target_info ON scan_list.hash = target_info.hash";
$results = $db->query($sql);
if (mysql_num_rows($results) > 0){
$i = 1;
while ($fs = $db->fetch_array($results))
{
$url = $fs['1'];
$url = str_replace(array("\r\n", "\r","\n"), "", $url);
$pointserver = $fs['pointserver'];
$rule = $fs['rule'];
$siteuser = $fs['siteuser'];
$sitepwd = $fs['sitepwd'];
$cookie = $fs['cookie'];
$hash = $fs['11'];
$delay = $fs['delay'];
$status = $fs['status'];
$nextscan = $fs['nextscan'];
$customer = $fs['customer'];
if ($delay == '2'){
$delay_new='3';
}else if ($delay == '3'){
$delay_new='6';
}else if ($delay == '4') {
$delay_new = '12';
}else{
$delay_new = '1';
}
$finishtime = $fs['finishtime'];
$finishtime = explode(',',$finishtime);
list($day, $month, $year) = split ('[/.-]', $finishtime[0]);
$finishtime = $year.'-'.$month.'-'.$day;
$finishtime=strtotime($finishtime);
$time_now=strtotime(date("Y-m-d"));
$time_sub=sub_days($time_now,$finishtime);
$time_sub= floor($time_sub/30);
if ($status == 'new'){
$up_arr['status'] = 'ing';
//echo "$url|$pointserver|$rule|$siteuser|$sitepwd|$cookie|$hash";
$scan_arr['target_url'] = $url;
$scan_arr['scan_rule'] = $rule;
$scan_arr['siteuser'] = $siteuser;
$scan_arr['sitepwd'] = $sitepwd;
$scan_arr['sitecookie'] = $cookie;
$scan_arr['hash'] = $hash;
//echo '***'.json_encode($scan_arr).'***';
echo base64_encode(json_encode($scan_arr));
$update = $db->update('scan_list',$up_arr,"status='new' and hash='{$hash}'");
exit(0);
}else if (($status == 'ok') and ($nextscan =='')){
if ($time_sub == $delay_new){
// echo '---'.$url.'---';
$in_arr['url'] = $url;
$in_arr['createtime'] = date('Y-m-d');
$in_arr['user'] = $_SESSION['username'];//当前session用户
$in_arr['pointserver'] = specify_server();//分配节点服务器ip
$in_arr['group'] = "";//项目组名称
$in_arr['siteuser'] = $siteuser;
$in_arr['sitepwd'] = $sitepwd;
$in_arr['cookie'] = $cookie;
$in_arr['rule'] = $rule;
$in_arr['status'] = 'new';
$in_arr['customer'] = $customer;
$in_arr['delay'] = $delay;
$in_arr['hash'] = md5($in_arr['url'].time().authkey);
$up_arr['nextscan'] = $in_arr['hash'];
//$insert = $db->insert_into("scan_list",$in_arr);
//$update = $db->update('scan_list',$up_arr,"hash='{$hash}'");
$in_spider_arr['url'] = $url;
$in_spider_arr['createtime'] = date('Y-m-d');
$in_spider_arr['siteuser'] = $_POST['user'];
$in_spider_arr['sitepwd'] = $_POST['pwd'];
$in_spider_arr['status'] = 'new';
$in_spider_arr['check_status'] = 'new';
$in_spider_arr['customer'] = $_POST['customer'];
$in_spider_arr['delay'] = $_POST['delay'];
$in_spider_arr['hash'] = $in_arr['hash'];
// $insert = $db->insert_into("spider", $in_spider_arr);
}
}else if ($status == 'ing'){
// $sql = "select * from `scan_list` where status='ing'";
// $sf = $db->fetch_assoc($sql);
$get_hash = $fs['11'];
if (!empty($get_hash)){
$url = "http://127.0.0.1/file.php?p=$get_hash";
// echo '+++'.$url.'+++';
$scan_data = file_get_contents($url);
if ($scan_data != 'null'){
get_xml($url);
get_spider($url);
}else if ($scan_data == 'null'){
//print "aa";
continue;
}
}
}
}
}
?>