rlibiptc 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 764d36ed0a23f284a14df664c9397d588972b089
4
+ data.tar.gz: 75435cf19dd3e099cfc1ed3a0a5bef38cb0d5cbf
5
+ SHA512:
6
+ metadata.gz: 5f58c912858ccb409b9c95df5a519d78de95465658771d14a242ee95711ff03b8df5be85d59aa9c09586963bcbe1ffd899a424a68a1f2ff656314b1f4175052a
7
+ data.tar.gz: d55f9a6e5b32807afed30e95d772053b13c04e4bc848503c34785cc719835d4f9dd27634b3bdc7092665641144c12a02bc9193ebec5b3b05991158a6e322884e
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ Vagrantfile
16
+ .vagrant
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in libiptc.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Herman verschooten
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,31 @@
1
+ # Rlibiptc
2
+
3
+ An interface to libiptc for Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rlibiptc'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rlibiptc
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/Hermanverschooten/rlibiptc/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/extensiontask"
3
+
4
+ Rake::ExtensionTask.new('rlibiptc') do |ext|
5
+ ext.lib_dir = "lib/rlibiptc"
6
+ end
7
+
8
+
@@ -0,0 +1,12 @@
1
+ require 'mkmf'
2
+ unless find_header('libiptc/libiptc.h')
3
+ abort "Cannot find required header libiptc.h, maybe you need to apt-get install iptables-dev?"
4
+ end
5
+ unless find_library('ip4tc','iptc_init')
6
+ abort "Cannot find required library ip4tc"
7
+ end
8
+ have_library('iptc')
9
+ have_library('xtables')
10
+
11
+ create_makefile('rlibiptc')
12
+
@@ -0,0 +1,206 @@
1
+ /*
2
+ * rlibiptc.c
3
+ *
4
+ * Simple interface to some function of iptables through the use of libiptc.
5
+ *
6
+ * (c) 2015 Herman verschooten
7
+ *
8
+ */
9
+
10
+ #include <ruby.h>
11
+ #include <rlibiptc.h>
12
+ //#include <libiptc/xtcshared.h>
13
+ #include <libiptc/libiptc.h>
14
+ #include <errno.h>
15
+ #include <stdbool.h>
16
+
17
+ VALUE cClass = Qnil;
18
+
19
+ struct xtc_handle *my_handle;
20
+ bool opened = false;
21
+
22
+
23
+ void open_iptables(VALUE self) {
24
+ VALUE itable;
25
+
26
+ itable = rb_iv_get(self, "@table");
27
+
28
+ char *table = StringValueCStr(itable);
29
+ if(opened)
30
+ rb_raise(rb_eStandardError, "Iptables already opened!");
31
+
32
+ my_handle = iptc_init(table);
33
+ if(!my_handle)
34
+ rb_raise(rb_eStandardError, "Unable to initialize with table %s, %s", table, iptc_strerror(errno));
35
+
36
+ opened = true;
37
+ }
38
+
39
+ void close_iptables() {
40
+ if(opened) {
41
+ iptc_free(my_handle);
42
+ opened = false;
43
+ }
44
+ }
45
+
46
+ VALUE method_table(VALUE self) {
47
+ return rb_iv_get(self, "@table");
48
+ }
49
+
50
+ VALUE method_chains(VALUE self) {
51
+ open_iptables(self);
52
+
53
+ VALUE arr;
54
+
55
+ arr = rb_ary_new();
56
+
57
+ const char *chain = NULL;
58
+
59
+ for(chain = iptc_first_chain(my_handle); chain; chain = iptc_next_chain(my_handle)) {
60
+ rb_ary_push(arr, rb_str_new2(chain));
61
+ }
62
+
63
+ close_iptables();
64
+
65
+ return arr;
66
+ }
67
+
68
+ VALUE method_flush(VALUE self, VALUE chain_name) {
69
+
70
+ const char *chain = StringValueCStr(chain_name);
71
+
72
+ open_iptables(self);
73
+
74
+ if(iptc_flush_entries(chain, my_handle) == 0) {
75
+ close_iptables();
76
+ rb_raise(rb_eStandardError, "%s", iptc_strerror(errno));
77
+ }
78
+
79
+ iptc_commit(my_handle);
80
+
81
+ close_iptables();
82
+
83
+ return self;
84
+ }
85
+
86
+ VALUE method_zero(VALUE self, VALUE chain_name) {
87
+
88
+ const char *chain = StringValueCStr(chain_name);
89
+
90
+ open_iptables(self);
91
+
92
+ if(iptc_zero_entries(chain, my_handle) == 0) {
93
+ close_iptables();
94
+ rb_raise(rb_eStandardError, "%s", iptc_strerror(errno));
95
+ }
96
+
97
+ iptc_commit(my_handle);
98
+
99
+ close_iptables();
100
+
101
+ return self;
102
+ }
103
+
104
+ VALUE method_create(VALUE self, VALUE chain_name) {
105
+
106
+ const char *chain = StringValueCStr(chain_name);
107
+
108
+ open_iptables(self);
109
+
110
+ if(iptc_create_chain(chain, my_handle) == 0) {
111
+ close_iptables();
112
+ rb_raise(rb_eStandardError, "%s", iptc_strerror(errno));
113
+ }
114
+
115
+ iptc_commit(my_handle);
116
+
117
+ close_iptables();
118
+
119
+ return self;
120
+ }
121
+
122
+ VALUE method_delete(VALUE self, VALUE chain_name) {
123
+
124
+ const char *chain = StringValueCStr(chain_name);
125
+
126
+ open_iptables(self);
127
+
128
+ if(iptc_delete_chain(chain, my_handle) == 0) {
129
+ close_iptables();
130
+ rb_raise(rb_eStandardError, "%s", iptc_strerror(errno));
131
+ }
132
+
133
+ iptc_commit(my_handle);
134
+
135
+ close_iptables();
136
+
137
+ return self;
138
+ }
139
+
140
+ VALUE method_rename(VALUE self, VALUE chain_name, VALUE new_name) {
141
+
142
+ const char *chain = StringValueCStr(chain_name);
143
+ const char *name = StringValueCStr(new_name);
144
+
145
+ open_iptables(self);
146
+
147
+ if(iptc_rename_chain(chain, name, my_handle) == 0) {
148
+ close_iptables();
149
+ rb_raise(rb_eStandardError, "%s", iptc_strerror(errno));
150
+ }
151
+
152
+ iptc_commit(my_handle);
153
+
154
+ close_iptables();
155
+
156
+ return self;
157
+ }
158
+
159
+ VALUE method_rules(VALUE self, VALUE chain_name) {
160
+ const char *chain = StringValueCStr(chain_name);
161
+
162
+ const struct ipt_entry *e;
163
+
164
+ open_iptables(self);
165
+
166
+ VALUE arr;
167
+
168
+ arr = rb_ary_new();
169
+
170
+ int i = 0;
171
+
172
+ for(e = iptc_first_rule(chain, my_handle); e; e = iptc_next_rule(e,my_handle)) {
173
+ VALUE entry;
174
+ entry = rb_hash_new();
175
+ rb_hash_aset(entry, ID2SYM(rb_intern("line")), INT2NUM(i++));
176
+ rb_hash_aset(entry, ID2SYM(rb_intern("bytes")), LONG2NUM(e->counters.bcnt));
177
+ rb_hash_aset(entry, ID2SYM(rb_intern("packets")), LONG2NUM(e->counters.pcnt));
178
+
179
+ rb_ary_push(arr, entry);
180
+ }
181
+
182
+ close_iptables();
183
+
184
+ return arr;
185
+
186
+ }
187
+
188
+ VALUE method_init(VALUE self, VALUE tablename) {
189
+ rb_iv_set(self, "@table", tablename);
190
+ return self;
191
+ }
192
+
193
+ void Init_rlibiptc() {
194
+ VALUE Module;
195
+ Module = rb_define_module("Rlibiptc");
196
+ cClass = rb_define_class_under(Module, "Iptables", rb_cObject);
197
+ rb_define_method(cClass, "initialize", method_init, 1);
198
+ rb_define_method(cClass, "table", method_table, 0);
199
+ rb_define_method(cClass, "rules", method_rules, 1);
200
+ rb_define_method(cClass, "chains", method_chains, 0);
201
+ rb_define_method(cClass, "flush", method_flush, 1);
202
+ rb_define_method(cClass, "zero", method_zero, 1);
203
+ rb_define_method(cClass, "create", method_create, 1);
204
+ rb_define_method(cClass, "delete", method_delete, 1);
205
+ rb_define_method(cClass, "rename", method_rename, 2);
206
+ }
@@ -0,0 +1,13 @@
1
+ /*
2
+ * rlibiptc.h
3
+ *
4
+ * Simple interface to some function of iptables through the use of libiptc.
5
+ *
6
+ * (c) 2015 Herman verschooten
7
+ *
8
+ */
9
+
10
+ #ifndef _RUBY_LIBIPTC_H
11
+ #define _RUBY_LIBIPTC_H
12
+
13
+ #endif
@@ -0,0 +1,3 @@
1
+ module Rlibiptc
2
+ VERSION = "0.0.2"
3
+ end
data/lib/rlibiptc.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "rlibiptc/version"
2
+
3
+ module Rlibiptc
4
+ # Your code goes here...
5
+ end
data/rlibiptc.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rlibiptc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rlibiptc"
8
+ spec.version = Rlibiptc::VERSION
9
+ spec.authors = ["Herman verschooten"]
10
+ spec.email = ["Herman@verschooten.net"]
11
+ spec.summary = %q{Limited interface to libiptc.}
12
+ spec.description = %q{Interface to some features of iptables using libtipc}
13
+ spec.homepage = "https://github.com/Hermanverschooten/rlibiptc"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib", "ext"]
20
+ spec.extensions = Dir['ext/**/extconf.rb']
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rake-compiler"
25
+ spec.add_development_dependency "rspec"
26
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rlibiptc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Herman verschooten
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Interface to some features of iptables using libtipc
70
+ email:
71
+ - Herman@verschooten.net
72
+ executables: []
73
+ extensions:
74
+ - ext/rlibiptc/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - ext/rlibiptc/extconf.rb
83
+ - ext/rlibiptc/rlibiptc.c
84
+ - ext/rlibiptc/rlibiptc.h
85
+ - lib/rlibiptc.rb
86
+ - lib/rlibiptc/version.rb
87
+ - rlibiptc.gemspec
88
+ homepage: https://github.com/Hermanverschooten/rlibiptc
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ - ext
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.5
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Limited interface to libiptc.
113
+ test_files: []