runc 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6aea65d1ea49b4078499456513c6c2018f06dde7d219f299a8179326773bc36a
4
+ data.tar.gz: b0a65d45b9a5e24e869dba1c30b211f4ba8a95795603ab76f8ee1f2cd32e5362
5
+ SHA512:
6
+ metadata.gz: 04d95885440f2506a240e9933c797e14f47410579b484af63096b2054bb9eca9fd6ba61cb2a3da889e3f3e3f6c748c4b9b850376d79166cb7ccb2390248b9348
7
+ data.tar.gz: 93294cef3f815dfa24eea7aacd9eba90784f86228413a001ef9592bd5152901e607ff689722dc43e88f40dde65a1591a7d3b5de3bef6c0dee90a0a311984a8b6
data/.gitignore ADDED
@@ -0,0 +1,57 @@
1
+ # files without extensions except directories
2
+ *
3
+ !/**/
4
+ !?*.*
5
+
6
+ # directories
7
+ .bundle/
8
+ _yardoc/
9
+ coverage/
10
+ doc/
11
+ pkg/
12
+ spec/reports/
13
+ tmp/
14
+ vendor/
15
+
16
+ # files
17
+ .rubocop.yml
18
+ .*.swp
19
+ *.dump
20
+ *.log
21
+ *.mod
22
+ *.o
23
+ *~
24
+ .DS_Store
25
+ .byebug
26
+ .idea
27
+ .project
28
+ .rake*
29
+ .rake*
30
+ .ruby-*
31
+ .rvmrc
32
+ .secret
33
+ .yardoc
34
+ TODO.md
35
+ core.*
36
+ cscope.out
37
+ secrets.yml
38
+ tags
39
+
40
+ # don't ignore
41
+ !.gitignore
42
+ !.keep
43
+ !Capfile
44
+ !Cheffile
45
+ !Gemfile
46
+ ![MR]akefile
47
+ !bin/**/[^.]*
48
+ !exe/**/[^.]*
49
+
50
+ /.bundle/
51
+ /.yardoc
52
+ /_yardoc/
53
+ /coverage/
54
+ /doc/
55
+ /pkg/
56
+ /spec/reports/
57
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.4
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in runc.gemspec
4
+ gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ runc (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ builder (3.2.4)
11
+ byebug (11.0.1)
12
+ minitest (5.14.0)
13
+ minitest-reporters (1.3.8)
14
+ ansi
15
+ builder
16
+ minitest (>= 5.0)
17
+ ruby-progressbar
18
+ rake (13.0.1)
19
+ ruby-progressbar (1.10.1)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ byebug (~> 11.0.1)
26
+ minitest (~> 5.0)
27
+ minitest-reporters (~> 1.3.8)
28
+ rake (~> 13.0.1)
29
+ runc!
30
+
31
+ BUNDLED WITH
32
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Sergio Romero
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Runc
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/runc`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'runc'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install runc
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/runc.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+
5
+ CLEAN.include ['**/.*.sw?', '**/*.gem', 'test/test.log']
6
+
7
+ task default: %i[test package]
8
+ task package: :clean
9
+
10
+ Rake::TestTask.new do |t|
11
+ t.libs << 'lib' << 'test'
12
+ t.test_files = FileList['test/**/*_test.rb']
13
+ t.warning = false
14
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "runc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/runc ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
+
5
+ require "runc"
6
+
7
+ Runc.main(ARGV)
data/lib/runc.rb ADDED
@@ -0,0 +1,164 @@
1
+ $LOAD_PATH.unshift __dir__
2
+
3
+ require "runc/version"
4
+ require 'net/http'
5
+ require 'readline'
6
+ require 'yaml'
7
+
8
+ ##
9
+ # nc REPL
10
+ class Runc
11
+ # :stopdoc:
12
+
13
+ attr_reader :header, :port
14
+
15
+ attr_accessor :protocol, :req, :uri
16
+
17
+ %w(INT TERM).each do |sig|
18
+ trap(sig) {puts; exit}
19
+ end
20
+
21
+ def self.main(args)
22
+ raise(RuntimeError, "Missing nc dependency") unless has_nc
23
+
24
+ help if(args.include?("-h") or args.include?("--help"))
25
+ version if (args.include?("-v") or args.include?("--version"))
26
+
27
+ if(args.include?('-p') or args.include?('--port'))
28
+ args.map! {|a| a == '--interval' ? '-i' : a}
29
+ _, port = args.slice!(args.index('-p'),2)
30
+ port = port.to_i
31
+ end
32
+ port ||= 8000
33
+
34
+ if(args.include?('-n') or args.include?('--host'))
35
+ args.map! {|a| a == '--host' ? '-n' : a}
36
+ _, hostname = args.slice!(args.index('-n'),2)
37
+ end
38
+ hostname ||= 'localhost'
39
+
40
+ body = (args.include?("-B") or args.include?("--no-body")) ? nil : true
41
+ res_header = (args.include?("-H") or args.include?("--no-header")) ? nil : true
42
+
43
+ puts "Hostname: #{hostname}", "Port: #{port}"
44
+ new(hostname, port, body, res_header).repl
45
+ rescue => e
46
+ abort e.message
47
+ end
48
+
49
+ # :startdoc:
50
+
51
+ ##
52
+ # check if nc is installed
53
+ def self.has_nc
54
+ system("type -p nc", [:out, :err] => File::NULL)
55
+ end
56
+
57
+ def self.help # :nodoc:
58
+ puts <<~eos
59
+ -B --no-body dont print response body
60
+ -H --no-header dont print response headers
61
+ -h, --help print this message
62
+ -n, --host host name, defaults to 'localhost'
63
+ -p, --port port, defaults to 8000
64
+ -v, --version print runc version
65
+ eos
66
+ exit
67
+ end
68
+
69
+ def self.version # :nodoc:
70
+ puts "runc #{VERSION}"
71
+ exit
72
+ end
73
+
74
+ def initialize(hostname, port, body, res_header) # :nodoc:
75
+ @header = {'host' => hostname}
76
+ @port = port
77
+ @body = body
78
+ @res_header = res_header
79
+ @req = 'get'
80
+ end
81
+
82
+ ##
83
+ # file with internet protocols and ports. More info in 'man services'
84
+ def protocol_file
85
+ '/etc/services'
86
+ end
87
+
88
+ ##
89
+ # generate a hash of protocols and port numbers
90
+ def read_protocols
91
+ @protocol = {}
92
+ File.open(protocol_file) do |f|
93
+ f.each_line do |l|
94
+ next if l.match?(/^#|$^/)
95
+ @protocol[l.split[1].sub(/\/.*/i,'').to_i] = l.split[0]
96
+ end
97
+ end
98
+
99
+ # default to http if +port+ is larger than 2000
100
+ @protocol.keys.each do |port|
101
+ @protocol[port] = 'http' if port > 2000
102
+ end
103
+ end
104
+
105
+ def repl # :nodoc:
106
+ read_protocols
107
+ loop do
108
+ req_tmp=ask('request')
109
+
110
+ @req = req_tmp.empty? ? @req : req_tmp
111
+
112
+ update_header
113
+
114
+ update_uri
115
+
116
+ request=Net::HTTP.const_get(@req[/^\w+/].capitalize).new(@uri, @header)
117
+
118
+ http=Net::HTTP.new(@uri.host,@uri.port)
119
+
120
+ http.use_ssl = port==443 ? true : false
121
+
122
+ response=http.request(request)
123
+
124
+ # request headers
125
+ @header.map {|h, v| puts "> \e[1m#{h}\e[m: #{v}"}
126
+ puts ">"
127
+
128
+ # response headers
129
+ if @res_header
130
+ puts "< HTTP/1.1 #{response.code} #{response.message}"
131
+ response.each_header {|h, v| puts "< \e[1m#{h}\e[m: #{v}"}
132
+ puts "<"
133
+ end
134
+
135
+ # response body
136
+ puts(response.body) if @body
137
+ rescue => e
138
+ puts "#{caller.first}: #{e.message}"
139
+ end
140
+ end
141
+
142
+ ##
143
+ # reads a hash from user input
144
+ # hash should be of the form: key1: val1 [, key2: val2 [, ...]]
145
+ def update_header
146
+ header_tmp=YAML.load("{#{ask('header')}}")
147
+
148
+ # if +header_tmp+ contains a +port+ key, update the port
149
+ @port=header_tmp.key?('port') ? header_tmp.delete('port') : @port
150
+
151
+ @header.update(header_tmp)
152
+ end
153
+
154
+ ##
155
+ # prompt user for input
156
+ def ask(prompt)
157
+ res = Readline.readline("#{prompt}> ", true)
158
+ res.nil? ? (puts; exit) : res
159
+ end
160
+
161
+ def update_uri # :nodoc:
162
+ @uri=URI("#{@protocol[port]}://#{@header['host']}:#{port}/#{@req.sub(/^\w+ */,'')}")
163
+ end
164
+ end
@@ -0,0 +1,4 @@
1
+ class Runc
2
+ # :nodoc
3
+ VERSION = "0.1.0"
4
+ end
data/runc.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/runc/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "runc"
5
+ spec.version = Runc::VERSION
6
+ spec.authors = ["sergioro"]
7
+ spec.email = ["yo@sergioro.com"]
8
+
9
+ spec.summary = %q{Network REPL}
10
+ spec.description = %q{"runc" stands for "ruby nc"}
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ spec.add_development_dependency "byebug", "~> 11.0.1"
23
+ spec.add_development_dependency "minitest", "~> 5.0"
24
+ spec.add_development_dependency "minitest-reporters", "~> 1.3.8"
25
+ spec.add_development_dependency "rake", "~> 13.0.1"
26
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: runc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sergioro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: byebug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 11.0.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 11.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-reporters
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.8
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.8
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 13.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 13.0.1
69
+ description: '"runc" stands for "ruby nc"'
70
+ email:
71
+ - yo@sergioro.com
72
+ executables:
73
+ - runc
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - exe/runc
87
+ - lib/runc.rb
88
+ - lib/runc/version.rb
89
+ - runc.gemspec
90
+ homepage:
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.3.0
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubygems_version: 3.0.6
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Network REPL
113
+ test_files: []