lenovo-powervfw_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tower He
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = lenovo-powervfw_client
2
+
3
+ Provide a executable client and a series of APIs of Power V firewall of Lenovo. You can use the client to interact with the
4
+ Power V firewall of Lenove. And you can also program with the APIs provided by this project.
5
+
6
+ == FEATURES/PROBLEMS:
7
+
8
+ * [feature] Connect to the Power V firewall throw SSH.
9
+ * [feature] Add packet filter rules whose type is deny.
10
+
11
+ == SYNOPSIS:
12
+
13
+ require 'lenovo-powervfw_client'
14
+
15
+ client = Lenovo::PowerVFwClient.new('host', 'user', 'password')
16
+ client.add_rule('sample', {:sa => 'any', :sport => 'any', :log => 'on'})
17
+ client.close
18
+
19
+ == INSTALL:
20
+
21
+ sudo gem install lenovo-powervfw_client
22
+
23
+ == COPYRIGHT:
24
+
25
+ Copyright (c) 2009 Tower He. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "lenovo-powervfw_client"
8
+ gem.summary = %Q{A client for the Power V firewall of Lenovo}
9
+ gem.description = %Q{Provide a executable client and a client API of the Power V firewall of Lenovo}
10
+ gem.email = "towerhe@gmail.com"
11
+ gem.homepage = "http://github.com/towerhe/lenovo-powervfw_client"
12
+ gem.authors = ["Tower He"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "lenovo-powervfw_client #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'net/ssh'
3
+
4
+ module Lenovo
5
+ class PowerVFwClient
6
+ def initialize(host, user, password)
7
+ begin
8
+ @session = Net::SSH.start(host, user, :password => password)
9
+ rescue
10
+ puts $!
11
+ end
12
+ end
13
+
14
+ def closed?
15
+ @session.nil? or @session.closed?
16
+ end
17
+
18
+ def close
19
+ @session.close
20
+ end
21
+
22
+ # Add a packet filter rule whose type is deny.
23
+ #
24
+ # {
25
+ # :name => 'Rule Name', # rule name, required.
26
+ # :id => 'id', # rule id, must be in 1..65535, optional,
27
+ # # default value is the last one.
28
+ # :sa => 'any' | '<name>' | '<ip>', # source address, optional, default value is any.
29
+ # :sport => 'any' | '<port>', # source port, must be in 1..65535, optional, default value is any.
30
+ # :smac => 'any' | '<mac>', # source mac address, optional, default value is any.
31
+ # :da => 'any' | '<name>' | '<ip>', # destination address, optional, default value is any.
32
+ # :iif => 'any' | '<interface>', # input interface, optional, default value is any.
33
+ # :oif => 'any' | '<interface>', # output interface, optional, default value is any.
34
+ # :service => 'any' | '<name>', # service name, could be service name or group of services,
35
+ # # optional, default value is any.
36
+ # :time => '<name>' | 'none', # optional, default value is none.
37
+ # :log => 'on' | 'off', # whether to log, optional, default value is off.
38
+ # :active => 'on' | 'off', # whether to enable this rule, optional, default value is on.
39
+ # :comment => '<comment>' # comment of this rule, optional
40
+ # }
41
+ def add_rule(name, options = {})
42
+ type = 'deny'
43
+ cmd = "rule add type #{type} name #{name} "
44
+ cmd << "id #{options[:id]} " if options.has_key? :id
45
+ cmd << "sa #{options[:sa] || 'any'} " if options.has_key? :sa
46
+ cmd << "sport #{options[:sport] || 'any'} " if options.has_key? :sport
47
+ cmd << "smac #{options[:smac] || 'any'} " if options.has_key? :smac
48
+ cmd << "da #{options[:da] || 'any'} " if options.has_key? :da
49
+ cmd << "iif #{options[:iif] || 'any'} " if options.has_key? :iif
50
+ cmd << "oif #{options[:oif] || 'any'} " if options.has_key? :oif
51
+ cmd << "service #{options[:service] || 'any'} " if options.has_key? :service
52
+ cmd << "time #{options[:time] || 'none'} " if options.has_key? :time
53
+ cmd << "log #{options[:log] || 'off'} " if options.has_key? :log
54
+ cmd << "active #{options[:active] || 'on'} " if options.has_key? :active
55
+ cmd << "comment #{options[:comment]}" if options.has_key? :comment
56
+
57
+ output = @session.exec!(cmd.strip)
58
+ not output.include? 'Error'
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "LenovoPowervfwClient" do
4
+ describe "Create SSH connection successfully" do
5
+ before(:each) do
6
+ @session = mock(Net::SSH::Connection::Session)
7
+ Net::SSH.should_receive(:start).with('localhost', 'user', :password => 'password').and_return(@session)
8
+ @client = Lenovo::PowerVFwClient.new('localhost', 'user', 'password')
9
+ end
10
+ it "should successfully establish a connection to the local ssh server " do
11
+ @session.should_receive(:closed?).and_return(false)
12
+ @client.closed?.should == false
13
+ end
14
+
15
+ it "should establish a connection, but disconnected" do
16
+ @session.should_receive(:closed?).and_return(true)
17
+ @client.closed?.should == true
18
+ end
19
+
20
+ it "should disconnect the connection which linked to the local ssh server" do
21
+ @session.should_receive(:closed?).and_return(false)
22
+ @client.closed?.should == false
23
+
24
+ @session.should_receive(:close).and_return(true)
25
+ @session.should_receive(:closed?).and_return(true)
26
+ @client.close
27
+ @client.closed?.should == true
28
+ end
29
+
30
+ describe "Create a packet filter" do
31
+ it "should create a packet filter rule to deny packets" do
32
+ cmd = 'rule add type deny name test'
33
+ @session.should_receive(:exec!).with(cmd).and_return("")
34
+
35
+ @client.add_rule('test').should == true
36
+ end
37
+
38
+ it "should not create an invalid packet filter" do
39
+ cmd = 'rule add type deny name invalid_rule'
40
+ @session.should_receive(:exec!).with(cmd).and_return("Error")
41
+
42
+ @client.add_rule('invalid_rule').should == false
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ it "should not establish a connection to the local ssh server" do
49
+ Net::SSH.should_receive(:start).with('localhost', 'user', :password => 'password').and_raise("exception")
50
+ client = Lenovo::PowerVFwClient.new('localhost', 'user', 'password')
51
+ client.closed?.should == true
52
+ end
53
+
54
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'lenovo-powervfw_client'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lenovo-powervfw_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tower He
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-29 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ description: Provide a executable client and a client API of the Power V firewall of Lenovo
26
+ email: towerhe@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/lenovo-powervfw_client.rb
42
+ - spec/lenovo-powervfw_client_spec.rb
43
+ - spec/spec.opts
44
+ - spec/spec_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/towerhe/lenovo-powervfw_client
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: A client for the Power V firewall of Lenovo
73
+ test_files:
74
+ - spec/spec_helper.rb
75
+ - spec/lenovo-powervfw_client_spec.rb