lenovo-powervfw 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
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'net-ssh'
4
+
5
+ # Add dependencies required to use your gem here.
6
+ # Example:
7
+ # gem "activesupport", ">= 2.3.5"
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "rspec", "~> 2.3.0"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.5.2"
15
+ gem "rcov", ">= 0"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ net-ssh (2.0.23)
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ rspec (2.3.0)
14
+ rspec-core (~> 2.3.0)
15
+ rspec-expectations (~> 2.3.0)
16
+ rspec-mocks (~> 2.3.0)
17
+ rspec-core (2.3.1)
18
+ rspec-expectations (2.3.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.3.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.0)
27
+ jeweler (~> 1.5.2)
28
+ net-ssh
29
+ rcov
30
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Online Dummy
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,30 @@
1
+ = lenovo-powervfw
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 firewall, and you can also program with the APIs.
4
+
5
+ == FEATURES/PROBLEMS:
6
+
7
+ * [feature] Connect to the Power V firewall through ssh.
8
+ * [feature] Add packet filter rules which type is deny.
9
+
10
+ == SYNOPSIS:
11
+
12
+ require 'lenovo-powervfw'
13
+
14
+ client = Lenovo::PowerVFw.new('host', 'user', 'password')
15
+ client.add_rule('sample', {:sa => 'any', :sport => 'any', :log => 'on'})
16
+ client.close
17
+
18
+ == REQUIREMENTS:
19
+
20
+ * net-ssh http://net-ssh.rubyforge.org
21
+
22
+ $bundle install
23
+
24
+ == INSTALL:
25
+
26
+ sudo gem install lenovo-powervfw
27
+
28
+ == COPYRIGHT:
29
+
30
+ Copyright (c) 2009-2011 Oldumy. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "lenovo-powervfw"
16
+ gem.homepage = "http://github.com/oldumy/lenovo-powervfw"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Lenovo PowerV Firewall}
19
+ gem.description = %Q{Provide a executable client and a series of APIs of Power V firewall of Lenovo. You can use the client to interact with the firewall, and you can also program with the APIs.}
20
+ gem.email = "oldumy@gmail.com"
21
+ gem.authors = ["Online Dummy"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "lenovo-powervfw #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{lenovo-powervfw}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Online Dummy"]
12
+ s.date = %q{2011-01-08}
13
+ s.description = %q{Provide a executable client and a series of APIs of Power V firewall of Lenovo. You can use the client to interact with the firewall, and you can also program with the APIs.}
14
+ s.email = %q{oldumy@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lenovo-powervfw.gemspec",
29
+ "lib/lenovo-powervfw.rb",
30
+ "spec/lenovo-powervfw_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/oldumy/lenovo-powervfw}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{Lenovo PowerV Firewall}
38
+ s.test_files = [
39
+ "spec/lenovo-powervfw_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<net-ssh>, [">= 0"])
49
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
52
+ s.add_development_dependency(%q<rcov>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<net-ssh>, [">= 0"])
55
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<net-ssh>, [">= 0"])
62
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ end
67
+ end
68
+
@@ -0,0 +1,60 @@
1
+ require 'net/ssh'
2
+
3
+ module Lenovo
4
+ class PowerVFw
5
+ def initialize(host, user, password)
6
+ begin
7
+ @session = Net::SSH.start(host, user, :password => password)
8
+ rescue
9
+ puts $!
10
+ end
11
+ end
12
+
13
+ def closed?
14
+ @session.nil? or @session.closed?
15
+ end
16
+
17
+ def close
18
+ @session.close
19
+ end
20
+
21
+ # Add a packet filter rule which type is deny.
22
+ #
23
+ # {
24
+ # :name => 'Rule Name', # rule name, required.
25
+ # :id => 'id', # rule id, must be in 1..65535, optional,
26
+ # # default value is the last one.
27
+ # :sa => 'any' | '<name>' | '<ip>', # source address, optional, default value is any.
28
+ # :sport => 'any' | '<port>', # source port, must be in 1..65535, optional, default value is any.
29
+ # :smac => 'any' | '<mac>', # source mac address, optional, default value is any.
30
+ # :da => 'any' | '<name>' | '<ip>', # destination address, optional, default value is any.
31
+ # :iif => 'any' | '<interface>', # input interface, optional, default value is any.
32
+ # :oif => 'any' | '<interface>', # output interface, optional, default value is any.
33
+ # :service => 'any' | '<name>', # service name, could be service name or group of services,
34
+ # # optional, default value is any.
35
+ # :time => '<name>' | 'none', # optional, default value is none.
36
+ # :log => 'on' | 'off', # whether to log, optional, default value is off.
37
+ # :active => 'on' | 'off', # whether to enable this rule, optional, default value is on.
38
+ # :comment => '<comment>' # comment of this rule, optional
39
+ # }
40
+ def add_rule(name, options = {})
41
+ type = 'deny'
42
+ cmd = "rule add type #{type} name #{name} "
43
+ cmd << "id #{options[:id]} " if options.has_key? :id
44
+ cmd << "sa #{options[:sa] || 'any'} " if options.has_key? :sa
45
+ cmd << "sport #{options[:sport] || 'any'} " if options.has_key? :sport
46
+ cmd << "smac #{options[:smac] || 'any'} " if options.has_key? :smac
47
+ cmd << "da #{options[:da] || 'any'} " if options.has_key? :da
48
+ cmd << "iif #{options[:iif] || 'any'} " if options.has_key? :iif
49
+ cmd << "oif #{options[:oif] || 'any'} " if options.has_key? :oif
50
+ cmd << "service #{options[:service] || 'any'} " if options.has_key? :service
51
+ cmd << "time #{options[:time] || 'none'} " if options.has_key? :time
52
+ cmd << "log #{options[:log] || 'off'} " if options.has_key? :log
53
+ cmd << "active #{options[:active] || 'on'} " if options.has_key? :active
54
+ cmd << "comment #{options[:comment]}" if options.has_key? :comment
55
+
56
+ output = @session.exec!(cmd.strip)
57
+ not output.include? 'Error'
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Lenovo::PowerVFw 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
+ @firewall = Lenovo::PowerVFw.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
+ @firewall.closed?.should == false
13
+ end
14
+
15
+ it "should establish a connection, but disconnected" do
16
+ @session.should_receive(:closed?).and_return(true)
17
+ @firewall.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
+ @firewall.closed?.should == false
23
+
24
+ @session.should_receive(:close).and_return(true)
25
+ @session.should_receive(:closed?).and_return(true)
26
+ @firewall.close
27
+ @firewall.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
+ @firewall.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
+ @firewall.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::PowerVFw.new('localhost', 'user', 'password')
51
+ client.closed?.should == true
52
+ end
53
+
54
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'lenovo-powervfw'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lenovo-powervfw
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Online Dummy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-08 00:00:00 +08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: net-ssh
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 2
42
+ - 3
43
+ - 0
44
+ version: 2.3.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 0
58
+ - 0
59
+ version: 1.0.0
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: jeweler
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 1
72
+ - 5
73
+ - 2
74
+ version: 1.5.2
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: rcov
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *id005
91
+ description: Provide a executable client and a series of APIs of Power V firewall of Lenovo. You can use the client to interact with the firewall, and you can also program with the APIs.
92
+ email: oldumy@gmail.com
93
+ executables: []
94
+
95
+ extensions: []
96
+
97
+ extra_rdoc_files:
98
+ - LICENSE.txt
99
+ - README.rdoc
100
+ files:
101
+ - .document
102
+ - .rspec
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.rdoc
107
+ - Rakefile
108
+ - VERSION
109
+ - lenovo-powervfw.gemspec
110
+ - lib/lenovo-powervfw.rb
111
+ - spec/lenovo-powervfw_spec.rb
112
+ - spec/spec_helper.rb
113
+ has_rdoc: true
114
+ homepage: http://github.com/oldumy/lenovo-powervfw
115
+ licenses:
116
+ - MIT
117
+ post_install_message:
118
+ rdoc_options: []
119
+
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 162892495
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ requirements: []
140
+
141
+ rubyforge_project:
142
+ rubygems_version: 1.3.7
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: Lenovo PowerV Firewall
146
+ test_files:
147
+ - spec/lenovo-powervfw_spec.rb
148
+ - spec/spec_helper.rb