-
Notifications
You must be signed in to change notification settings - Fork 2
/
vaddy.rb
68 lines (51 loc) · 1.81 KB
/
vaddy.rb
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
require 'net/http'
require 'uri'
require 'json'
require './vaddy_libs.rb'
API_SERVER = "https://" + (ENV["VADDY_API_SERVER"] || 'api.vaddy.net')
vaddy_token = ARGV[0] != nil ? ARGV[0] : ENV["VADDY_TOKEN"];
vaddy_user = ARGV[1] != nil ? ARGV[1] : ENV["VADDY_USER"];
vaddy_host = ARGV[2] != nil ? ARGV[2] : ENV["VADDY_HOST"];
vaddy_crawl = ARGV[3] != nil ? ARGV[3] : ENV["VADDY_CRAWL_ID"];
vaddy_project_id = ENV["VADDY_PROJECT_ID"];
if vaddy_token == nil || vaddy_user == nil || (vaddy_host == nil && vaddy_project_id == nil)
puts "ERROR: need more argument or env."
puts "USAGE: ruby vaddy.rb auth_key username host"
puts "or set env VADDY_TOKEN, VADDY_USER and VADDY_HOST or VADDY_PROJECT_ID"
exit(1)
end
base_info = {
"auth_key" => vaddy_token,
"user" => vaddy_user,
"fqdn" => vaddy_host,
}
base_info[:project_id] = vaddy_project_id unless vaddy_project_id.nil?
# Detect API version
api_version = vaddy_project_id.nil? ? "v1" : "v2"
# Set CrawlID
crawl_id = nil
if( vaddy_crawl != nil && vaddy_crawl.match(/\A\d+\Z/)) then
crawl_id = vaddy_crawl
elsif(vaddy_crawl != nil) then
crawl_api_url = API_SERVER + "/" + api_version + "/crawl"
crawl_id = search_crawl(crawl_api_url, vaddy_crawl, base_info)
end
# start scan
puts "== Start Scan =="
start_query_hash = base_info.dup
start_query_hash["action"] = "start"
start_query_hash["crawl_id"] = crawl_id
start_url = API_SERVER + "/" + api_version + "/scan"
scan_id = start_scan(start_url, start_query_hash)
if( scan_id == nil )
puts "ERROR: Can not get scan_id"
exit(1)
end
sleep(5)
# check status
check_query_hash = base_info.dup
check_query_hash["scan_id"] = scan_id
query_string = build_query(check_query_hash)
check_request_url = API_SERVER + "/" + api_version + "/scan/result?" + query_string
status = vaddy_check( check_request_url )
exit(status)