mirapoint 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ /nbproject/private/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mirapoint.gemspec
4
+ gemspec
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,3 @@
1
+ module Mirapoint
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mirapoint.rb ADDED
@@ -0,0 +1,169 @@
1
+ require 'socket'
2
+ require 'openssl'
3
+
4
+ module Mirapoint
5
+
6
+ class Connection
7
+
8
+ attr_reader :reported_hostname
9
+ attr_reader :version
10
+ attr_reader :connected
11
+ attr_reader :sessionid
12
+ attr_reader :okno
13
+
14
+ def initialize(hostname, port=10143, ssl=false)
15
+ @hostname = hostname
16
+ @port = port
17
+ @ssl = ssl
18
+ @connected = false
19
+ end
20
+
21
+ def connect
22
+ if @ssl
23
+ ctx = OpenSSL::SSL::SSLContext.new()
24
+ s = TCPSocket.new(@hostname, @port)
25
+ @socket = OpenSSL::SSL::SSLSocket.new(s, ctx)
26
+ @socket.connect
27
+ else
28
+ @socket = TCPSocket.new(@hostname, @port)
29
+ @socket.connect
30
+ end
31
+
32
+ @lasttag = 1
33
+
34
+ # handshake
35
+ response = @socket.gets
36
+
37
+ if response
38
+
39
+ r = /\* OK ([^ ]+) admind ([0-9\.]+).*/
40
+
41
+ if(m = r.match response)
42
+ @reported_hostname = m[1]
43
+ @version = m[2]
44
+ @connected = true
45
+ return true
46
+ end
47
+
48
+ return false
49
+ else
50
+ return false
51
+ end
52
+
53
+ end
54
+
55
+ def login(username, password)
56
+ response = command("LOGIN", username, password)
57
+ @sessionid = response[0]
58
+ if /^OK/.match @okno
59
+ return true
60
+ end
61
+ return false
62
+ end
63
+
64
+ def command(*cmds)
65
+
66
+ puts cmds.size
67
+ puts cmds.class
68
+
69
+ tag = send_command(cmds)
70
+
71
+ response = []
72
+
73
+ if tag
74
+ response = get_response(tag)
75
+ else
76
+ return nil
77
+ end
78
+
79
+ return response
80
+
81
+ end
82
+
83
+ private
84
+
85
+ def send_command(cmds)
86
+
87
+ @lasttag = @lasttag + 1
88
+
89
+ tag = @lasttag
90
+ cmd = tag.to_s
91
+
92
+ puts cmds.size
93
+ puts cmd
94
+ puts cmds.join(" ")
95
+
96
+ if cmds.size < 2
97
+ cmd = cmd + " " + cmds[0]
98
+ else
99
+ cmd = cmd + escape_args(cmds)
100
+ end
101
+
102
+ puts cmd
103
+
104
+ if xmit(cmd)
105
+ return tag
106
+ end
107
+
108
+ nil
109
+
110
+ end
111
+
112
+ def escape_args(cmds)
113
+
114
+ cmd = ""
115
+
116
+ cmds.each do |c|
117
+
118
+ if (/^$/.match c) || (/[\(\)\s]/.match c)
119
+ c = "\"" + c + "\""
120
+ end
121
+
122
+ cmd = cmd + " " + c
123
+
124
+ end
125
+
126
+ cmd
127
+
128
+ end
129
+
130
+ def get_response(tag)
131
+
132
+ response = Array.new
133
+ @okno = nil
134
+
135
+ loop do
136
+ line = @socket.gets
137
+
138
+ if /^\* #{tag} /.match line
139
+ line.sub!(/^\* #{tag} /, "")
140
+ elsif (/^#{tag} OK/.match line) || (/^#{tag} NO/.match line)
141
+ line.sub!(/^#{tag} /, "")
142
+ @okno = line
143
+ return response
144
+ else
145
+ if line == ""
146
+ return response
147
+ end
148
+ end
149
+
150
+ response.push(line)
151
+
152
+ end
153
+
154
+ end
155
+
156
+ def xmit(cmd)
157
+
158
+ if @connected
159
+ @socket.puts(cmd + "\r\n")
160
+ return true
161
+ end
162
+
163
+ false
164
+
165
+ end
166
+
167
+ end
168
+
169
+ end
data/mirapoint.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mirapoint/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mirapoint"
7
+ s.version = Mirapoint::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Mike Kennedy"]
10
+ s.email = ["mkennedy76@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Gem that provides an API to the Admin service on Mirapoint systems.}
13
+ s.description = %q{This gem assists with connecting to the admind protocol on Mirapoint systems.}
14
+
15
+ s.rubyforge_project = "mirapoint"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mirapoint
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Mike Kennedy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-21 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: This gem assists with connecting to the admind protocol on Mirapoint systems.
22
+ email:
23
+ - mkennedy76@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README
34
+ - Rakefile
35
+ - lib/mirapoint.rb
36
+ - lib/mirapoint/version.rb
37
+ - mirapoint.gemspec
38
+ has_rdoc: true
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project: mirapoint
64
+ rubygems_version: 1.3.6
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Gem that provides an API to the Admin service on Mirapoint systems.
68
+ test_files: []
69
+