summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2018-05-30 19:30:50 +0300
committerSaku Ytti <saku@ytti.fi>2018-05-30 19:30:50 +0300
commitc511a212c1388db35f0f42af2a33241986846e04 (patch)
tree833eff9264275822e8058d73b855c325127015ee /lib
parent42bf10b7bce34ff577c469f6c2f659f3913cbf4a (diff)
Add support for Cambium
Initial HTTP support
Diffstat (limited to 'lib')
-rw-r--r--lib/oxidized/input/http.rb41
-rw-r--r--lib/oxidized/model/cambium.rb23
-rw-r--r--lib/oxidized/string.rb2
-rw-r--r--lib/oxidized/version.rb2
4 files changed, 66 insertions, 2 deletions
diff --git a/lib/oxidized/input/http.rb b/lib/oxidized/input/http.rb
new file mode 100644
index 0000000..c7767b3
--- /dev/null
+++ b/lib/oxidized/input/http.rb
@@ -0,0 +1,41 @@
+module Oxidized
+ require_relative "cli"
+
+ begin
+ require "mechanize"
+ rescue LoadError
+ raise OxidizedError, "mechanize not found: sudo gem install mechanize"
+ end
+
+ class HTTP < Input
+ include Input::CLI
+
+ def connect node
+ @node = node
+ @m = Mechanize.new
+ @log = File.open(Oxidized::Config::Log + "/#{@node.ip}-http", "w") if Oxidized.config.input.debug?
+
+ @node.model.cfg["http"].each { |cb| instance_exec(&cb) }
+
+ url = URI::HTTP.build host: @node.ip, path: @main_page
+ @m_page = @m.get(url.to_s)
+ login
+ end
+
+ def cmd cb
+ instance_exec(&cb)
+ end
+
+ private
+
+ def log str
+ @log.write(str) if @log
+ end
+
+ def disconnect
+ ensure
+ @log.close if Oxidized.config.input.debug?
+ end
+
+ end
+end
diff --git a/lib/oxidized/model/cambium.rb b/lib/oxidized/model/cambium.rb
new file mode 100644
index 0000000..230282c
--- /dev/null
+++ b/lib/oxidized/model/cambium.rb
@@ -0,0 +1,23 @@
+class Cambium < Oxidized::Model
+
+ cfg_cb = lambda do
+ c_page = @m.click @m_page.link_with(text: "Configuration")
+ u_page = @m.click c_page.link_with(text: "Unit Settings")
+ cfg = @m.click u_page.link_with(text: /\.cfg$/)
+ cfg.body
+ end
+
+ cmd cfg_cb do |cfg|
+ cfg
+ end
+
+ cfg :http do
+ @main_page = "/main.cgi"
+ define_singleton_method :login do
+ @m_page = @m_page.form_with(action: "login.cgi") do |form|
+ form.CanopyUsername = @node.auth[:username]
+ form.CanopyPassword = @node.auth[:password]
+ end.submit
+ end
+ end
+end
diff --git a/lib/oxidized/string.rb b/lib/oxidized/string.rb
index ca4862d..87250c1 100644
--- a/lib/oxidized/string.rb
+++ b/lib/oxidized/string.rb
@@ -16,7 +16,7 @@ module Oxidized
# sets @cmd and @name unless @name is already set
def set_cmd command
@cmd = command
- @name ||= @cmd.strip.gsub(/\s+/, '_')
+ @name ||= @cmd.to_s.strip.gsub(/\s+/, '_') # what to do when command is proc? #to_s seems ghetto
end
def initialize str = ''
diff --git a/lib/oxidized/version.rb b/lib/oxidized/version.rb
index b607e12..d16d8e9 100644
--- a/lib/oxidized/version.rb
+++ b/lib/oxidized/version.rb
@@ -1,6 +1,6 @@
module Oxidized
VERSION = '0.21.0'
- VERSION_FULL = '0.21.0-180-g9691008'
+ VERSION_FULL = '0.21.0-282-g42bf10b'
def self.version_set
version_full = %x(git describe --tags).chop rescue ""
version = %x(git describe --tags --abbrev=0).chop rescue ""