kawana 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +1 -0
- data/lib/kawana.rb +5 -0
- data/lib/kawana/client.rb +77 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 923deb5b2f85e6c63a85c1607ca37052cd1f5d3b
|
4
|
+
data.tar.gz: 7f7ff4399a7418606a7bf091abd38e1a0dd9ed6e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 47871dcab8092dbcbd0b30175c0784b0d7c118f1df69d8a1784a154d1e3dc4f29983265e09b6bcef92e2a14bce182435f7bc64d65ae0633354c85adbed694ab8
|
7
|
+
data.tar.gz: b3a24f44c3dd24a6c04425b36d9ed39ab6fa1091c25fd48f5f25b0731dab921f2c1272c791d1da51225236515df2bfb2f91a2428b8bce072627fac99d9d0818a
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Chris Kite
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# ruby-kawana
|
data/lib/kawana.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'ipaddr'
|
3
|
+
|
4
|
+
module Kawana
|
5
|
+
class Client
|
6
|
+
|
7
|
+
#
|
8
|
+
# +addr+ is a string remote address, e.g. <tt>'localhost'</tt> or <tt>'127.0.0.1'</tt>
|
9
|
+
#
|
10
|
+
def initialize(addr, port = 9291)
|
11
|
+
@addr = addr
|
12
|
+
@port = port
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Whitelist +ip+ in the Kawana server.
|
17
|
+
# +ip+ must be of type *IPAddr*, e.g. <tt>IPAddr.new('127.0.0.1')</tt>
|
18
|
+
# Raises an exception if an error occurs, otherwise returns nil if successful.
|
19
|
+
#
|
20
|
+
def whitelist(ip)
|
21
|
+
black_white_cmd(ip, 1)
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Un-whitelist +ip+ in the Kawana server.
|
26
|
+
# +ip+ must be of type *IPAddr*, e.g. <tt>IPAddr.new('127.0.0.1')</tt>
|
27
|
+
# Raises an exception if an error occurs, otherwise returns nil if successful.
|
28
|
+
#
|
29
|
+
def unwhitelist(ip)
|
30
|
+
black_white_cmd(ip, 2)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Blacklist +ip+ in the Kawana server.
|
35
|
+
# +ip+ must be of type *IPAddr*, e.g. <tt>IPAddr.new('127.0.0.1')</tt>
|
36
|
+
# Raises an exception if an error occurs, otherwise returns nil if successful.
|
37
|
+
#
|
38
|
+
def blacklist(ip)
|
39
|
+
black_white_cmd(ip, 3)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Un-blacklist +ip+ in the Kawana server.
|
44
|
+
# +ip+ must be of type *IPAddr*, e.g. <tt>IPAddr.new('127.0.0.1')</tt>
|
45
|
+
# Raises an exception if an error occurs, otherwise returns nil if successful.
|
46
|
+
#
|
47
|
+
def unblacklist(ip)
|
48
|
+
black_white_cmd(ip, 4)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def black_white_cmd(ip, modifier)
|
54
|
+
if !ip.is_a?(IPAddr)
|
55
|
+
raise ArgumentError.new("ip must be of type IPAddr")
|
56
|
+
end
|
57
|
+
|
58
|
+
bytes = [
|
59
|
+
0x03, # BlackWhite command byte
|
60
|
+
ip.to_i,
|
61
|
+
modifier # BlackWhite modifier byte
|
62
|
+
].pack("CVC")
|
63
|
+
|
64
|
+
send_and_recv bytes
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def send_and_recv(bytes)
|
69
|
+
s = TCPSocket.new @addr, @port
|
70
|
+
s.send bytes, 0
|
71
|
+
resp = s.recv 15 # kawana response is 15 bytes
|
72
|
+
puts resp.unpack("V3SC").inspect
|
73
|
+
s.close
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kawana
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Kite
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files:
|
18
|
+
- README.md
|
19
|
+
files:
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- lib/kawana.rb
|
23
|
+
- lib/kawana/client.rb
|
24
|
+
homepage: http://www.github.com/chriskite/ruby-kawana
|
25
|
+
licenses: []
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.4.5
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Kawana client
|
47
|
+
test_files: []
|