rwenking 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +64 -0
- data/lib/rwenking.rb +3 -0
- data/lib/rwenking/client.rb +37 -0
- data/rwenking.gemspec +13 -0
- metadata +80 -0
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
RWenking
|
2
|
+
========
|
3
|
+
|
4
|
+
This is a Ruby REST Client for taobao's anti-phishing system called wenking
|
5
|
+
|
6
|
+
Install
|
7
|
+
-------
|
8
|
+
|
9
|
+
```bash
|
10
|
+
$ gem install rwenking
|
11
|
+
```
|
12
|
+
|
13
|
+
Configure
|
14
|
+
---------
|
15
|
+
|
16
|
+
create `wenking.yml` in your app's config directory
|
17
|
+
|
18
|
+
```yaml
|
19
|
+
development:
|
20
|
+
appname: 'xxx'
|
21
|
+
appkey: 'xxx'
|
22
|
+
|
23
|
+
production:
|
24
|
+
appname: 'xxx'
|
25
|
+
appkey: 'xxx'
|
26
|
+
```
|
27
|
+
create an initializer called `wenking.rb` in your rails initializers directory
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# -*- encoding : utf-8 -*-
|
31
|
+
require 'rwenking'
|
32
|
+
|
33
|
+
$wenking_config = YAML.load_file("#{Rails.root}/config/wenking.yml")[Rails.env]
|
34
|
+
$wenking = RWenking::Client.new(:appname => $wenking_config['appname'], :appkey => $wenking_config['appkey'])
|
35
|
+
```
|
36
|
+
|
37
|
+
Usage
|
38
|
+
-----
|
39
|
+
|
40
|
+
upload a url to wenking, if success, you'll get response `1`
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
url = "http://xxx" # the url you want to check
|
44
|
+
extradata = '{"post_id":"335"}' # a json object with content whatever you want, so you can get it when you call the get_phish api later
|
45
|
+
$wenking.scan(:url => url, :extradata => extradata)
|
46
|
+
```
|
47
|
+
get detection result by the `get_phish` api, it returns a hash array with all phish urls in it
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# return all results from id=0
|
51
|
+
arr = $wenking.get_phish
|
52
|
+
|
53
|
+
# return results from id=100, everytime you got the result, you'd better save the biggest id, so next time you call this api, you'll get the new results after this id
|
54
|
+
arr = $wenking.get_phish(100)
|
55
|
+
|
56
|
+
arr.each do |item|
|
57
|
+
puts item["id"] # result id
|
58
|
+
puts item["url"] # phish url
|
59
|
+
puts item["extradata"] #extradata you have posted in scan api
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
|
data/lib/rwenking.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# codeing: utf-8
|
2
|
+
require 'rest-client'
|
3
|
+
require 'cgi'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
module RWenking
|
7
|
+
class Client
|
8
|
+
def initialize(options)
|
9
|
+
return nil until options
|
10
|
+
@appname = options[:appname]
|
11
|
+
@key = options[:appkey]
|
12
|
+
end
|
13
|
+
|
14
|
+
def scan(options)
|
15
|
+
apiurl = "http://antiphishing.aliyun-inc.com/commonrecv"
|
16
|
+
url = CGI.escape(options[:url])
|
17
|
+
extra_data = options[:extradata]
|
18
|
+
response = RestClient.post(apiurl, {:sign => sign(@key, url), :appname => @appname, :url => url, :extradata => extra_data})
|
19
|
+
return response.body
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_phish(id=nil)
|
23
|
+
apiurl = "http://antiphishing.aliyun-inc.com/commonget"
|
24
|
+
id ||= 0
|
25
|
+
response = RestClient.get(apiurl, {:params => {:appname => @appname, :id => id, :sign => sign(@key, id)}})
|
26
|
+
xml = Nokogiri::XML(response.body)
|
27
|
+
xml.xpath("//item").map do |i|
|
28
|
+
{'id' => i.xpath('url').attr('id').value ,'url' => i.xpath('url').inner_text, 'extradata' => i.xpath('extradata').inner_text}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def sign(key, urlstr)
|
34
|
+
Digest::MD5.hexdigest("#{key}#{urlstr}#{key}")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/rwenking.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'rwenking'
|
4
|
+
s.version = '0.0.1'
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.summary = "This is a Ruby Client for taobao.com's anti-phishing system wenking"
|
7
|
+
s.authors = ["Fizz Wu"]
|
8
|
+
s.email = "fizzwu@gmail.com"
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
|
11
|
+
s.add_dependency("rest-client", ">=1.6.0")
|
12
|
+
s.add_dependency("nokogiri")
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rwenking
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Fizz Wu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.6.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description:
|
47
|
+
email: fizzwu@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- README.md
|
53
|
+
- lib/rwenking.rb
|
54
|
+
- lib/rwenking/client.rb
|
55
|
+
- rwenking.gemspec
|
56
|
+
homepage:
|
57
|
+
licenses: []
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.8.24
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: This is a Ruby Client for taobao.com's anti-phishing system wenking
|
80
|
+
test_files: []
|