diff options
Diffstat (limited to 'lib/oxidized')
-rw-r--r-- | lib/oxidized/input/http.rb | 39 | ||||
-rw-r--r-- | lib/oxidized/model/cambium.rb | 22 | ||||
-rw-r--r-- | lib/oxidized/model/openbsd.rb | 76 | ||||
-rw-r--r-- | lib/oxidized/string.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/version.rb | 2 |
5 files changed, 139 insertions, 2 deletions
diff --git a/lib/oxidized/input/http.rb b/lib/oxidized/input/http.rb new file mode 100644 index 0000000..5ce1e2b --- /dev/null +++ b/lib/oxidized/input/http.rb @@ -0,0 +1,39 @@ +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 callback + instance_exec(&callback) + end + + private + + def log str + @log.write(str) if @log + end + + def disconnect + @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..fe1f3c2 --- /dev/null +++ b/lib/oxidized/model/cambium.rb @@ -0,0 +1,22 @@ +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/model/openbsd.rb b/lib/oxidized/model/openbsd.rb new file mode 100644 index 0000000..898e9e3 --- /dev/null +++ b/lib/oxidized/model/openbsd.rb @@ -0,0 +1,76 @@ +class Openbsd < Oxidized::Model + # OpenBSD with custom promp, like user@hostname:~$ + # you can edit the one that your user uses, with root would be /root/.profile using the next PS1 def + # export PS1="\033[32m\u@\h\033[00m:\033[36m\w\033[00m$ " + + prompt /^.+@.+\:.+\$/ + comment '# ' + + # Add a comment between files/configs + def add_comment comment + "\n+++++++++++++++++++++++++++++++++++++++++ #{comment} ++++++++++++++++++++++++++++++++++++++++++++++\n" + end + + def add_small_comment comment + "\n=============== #{comment} ===============\n" + end + + cmd :all do |cfg| + cfg.each_line.to_a[1..-2].join + end + + # Issue the show commands + pre do + cfg = add_comment('HOSTNAME FILE') + cfg += cmd('cat /etc/myname') + + cfg += add_comment('HOSTS FILE') + cfg += cmd('cat /etc/hosts') + + cfg += add_comment('INTERFACE FILES') + cfg += cmd('tail -n +1 /etc/hostname.*') + + cfg += add_comment('RESOLV.CONF FILE') + cfg += cmd('cat /etc/resolv.conf') + + cfg += add_comment('NTP.CONF FILE') + cfg += cmd('cat /etc/ntp.conf') + + cfg += add_comment('IP ROUTES PER ROUTING DOMAIN') + cfg += add_small_comment('Routing Domain 0') + cfg += cmd('route -T0 exec netstat -rn') + cfg += add_small_comment('Routing Domain 1') + cfg += cmd('route -T1 exec netstat -rn') + cfg += add_small_comment('Routing Domain 2') + cfg += cmd('route -T2 exec netstat -rn') + cfg += add_small_comment('Routing Domain 3') + cfg += cmd('route -T3 exec netstat -rn') + cfg += add_small_comment('Routing Domain 4') + cfg += cmd('route -T4 exec netstat -rn') + cfg += add_small_comment('Routing Domain 5') + cfg += cmd('route -T5 exec netstat -rn') + + cfg += add_comment('SNMP FILE') + cfg += cmd('cat /etc/snmpd.conf') + + cfg += add_comment('PF FILE') + cfg += cmd('cat /etc/pf.conf') + + cfg += add_comment('MOTD FILE') + cfg += cmd('cat /etc/motd') + + cfg += add_comment('PASSWD FILE') + cfg += cmd('cat /etc/passwd') + + cfg += add_small_comment('END') + end + + cfg :telnet do + username /^Username:/ + password /^Password:/ + end + + cfg :telnet, :ssh do + pre_logout 'exit' + end +end diff --git a/lib/oxidized/string.rb b/lib/oxidized/string.rb index ca4862d..9c09f61 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 "" |