summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.rubocop_todo.yml41
-rw-r--r--CHANGELOG.md1
-rw-r--r--README.md7
-rw-r--r--docs/Supported-OS-Types.md1
-rw-r--r--lib/oxidized/input/http.rb39
-rw-r--r--lib/oxidized/model/cambium.rb22
-rw-r--r--lib/oxidized/model/openbsd.rb76
-rw-r--r--lib/oxidized/string.rb2
-rw-r--r--lib/oxidized/version.rb2
9 files changed, 163 insertions, 28 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index c30ae22..c6a5e0d 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
-# on 2018-04-25 18:47:11 +0200 using RuboCop version 0.55.0.
+# on 2018-06-03 10:03:33 +0200 using RuboCop version 0.55.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -19,7 +19,7 @@ Lint/AmbiguousBlockAssociation:
- 'lib/oxidized/model/model.rb'
- 'lib/oxidized/model/nos.rb'
-# Offense count: 652
+# Offense count: 681
Lint/AmbiguousRegexpLiteral:
Enabled: false
@@ -92,13 +92,14 @@ Lint/UnusedMethodArgument:
- 'lib/oxidized/hook.rb'
- 'lib/oxidized/output/file.rb'
-# Offense count: 12
+# Offense count: 13
Lint/UselessAssignment:
Exclude:
- 'lib/oxidized/model/cumulus.rb'
- 'lib/oxidized/model/edgeos.rb'
- 'lib/oxidized/model/gaiaos.rb'
- 'lib/oxidized/model/mlnxos.rb'
+ - 'lib/oxidized/model/openbsd.rb'
- 'lib/oxidized/model/procurve.rb'
- 'lib/oxidized/model/trango.rb'
- 'lib/oxidized/model/voltaire.rb'
@@ -114,11 +115,11 @@ Lint/Void:
Exclude:
- 'lib/oxidized/model/voss.rb'
-# Offense count: 60
+# Offense count: 63
Metrics/AbcSize:
Max: 84
-# Offense count: 15
+# Offense count: 19
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 142
@@ -133,11 +134,11 @@ Metrics/BlockNesting:
Metrics/ClassLength:
Max: 210
-# Offense count: 13
+# Offense count: 14
Metrics/CyclomaticComplexity:
Max: 28
-# Offense count: 53
+# Offense count: 56
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 76
@@ -147,7 +148,7 @@ Metrics/MethodLength:
Metrics/ParameterLists:
Max: 6
-# Offense count: 14
+# Offense count: 15
Metrics/PerceivedComplexity:
Max: 32
@@ -336,7 +337,7 @@ Style/ConditionalAssignment:
- 'lib/oxidized/hook/githubrepo.rb'
- 'lib/oxidized/model/model.rb'
-# Offense count: 144
+# Offense count: 150
Style/Documentation:
Enabled: false
@@ -376,7 +377,7 @@ Style/GuardClause:
- 'lib/oxidized/source/sql.rb'
- 'lib/oxidized/string.rb'
-# Offense count: 104
+# Offense count: 97
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
@@ -388,7 +389,7 @@ Style/IfInsideElse:
Exclude:
- 'lib/oxidized/output/file.rb'
-# Offense count: 39
+# Offense count: 42
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Enabled: false
@@ -411,7 +412,7 @@ Style/LineEndConcatenation:
Exclude:
- 'lib/oxidized/hook.rb'
-# Offense count: 131
+# Offense count: 137
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
@@ -566,23 +567,13 @@ Style/RedundantSelf:
- 'lib/oxidized/node.rb'
- 'lib/oxidized/nodes.rb'
-# Offense count: 29
+# Offense count: 31
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Enabled: false
-# Offense count: 6
-# Cop supports --auto-correct.
-Style/RescueModifier:
- Exclude:
- - 'bin/oxidized'
- - 'extra/syslog.rb'
- - 'lib/oxidized/input/ssh.rb'
- - 'lib/oxidized/node.rb'
- - 'lib/oxidized/nodes.rb'
-
# Offense count: 19
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
@@ -716,8 +707,8 @@ Style/ZeroLengthPredicate:
- 'lib/oxidized/model/ciscosmb.rb'
- 'lib/oxidized/output/git.rb'
-# Offense count: 270
+# Offense count: 300
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
- Max: 257
+ Max: 283
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a336f39..e90fe56 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## Master
+* FEATURE: openbsd model (@amarti2038)
* FEATURE: comnet model (@jaylik)
* FEATURE: add enable to procurve model (@khobbits)
* FEATURE: stoneos model (@macaty)
diff --git a/README.md b/README.md
index bb19d64..f4db9d7 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,9 @@
-# Oxidized [![Build Status](https://api.travis-ci.com/ytti/oxidized.svg)](https://travis-ci.com/ytti/oxidized) [![codecov.io](https://codecov.io/gh/ytti/oxidized/coverage.svg?branch=master)](https://codecov.io/gh/ytti/oxidized?branch=master) [![Gem Version](https://badge.fury.io/rb/oxidized.svg)](http://badge.fury.io/rb/oxidized) [![Join the chat at https://gitter.im/oxidized/Lobby](https://badges.gitter.im/oxidized/Lobby.svg)](https://gitter.im/oxidized/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+# Oxidized
+[![Build Status](https://api.travis-ci.com/ytti/oxidized.svg)](https://travis-ci.com/ytti/oxidized)
+[![codecov.io](https://codecov.io/gh/ytti/oxidized/coverage.svg?branch=master)](https://codecov.io/gh/ytti/oxidized?branch=master)
+[![Code Climate](https://codeclimate.com/github/ytti/oxidized/badges/gpa.svg)](https://codeclimate.com/github/ytti/oxidized)
+[![Gem Version](https://badge.fury.io/rb/oxidized.svg)](http://badge.fury.io/rb/oxidized)
+[![Join the chat at https://gitter.im/oxidized/Lobby](https://badges.gitter.im/oxidized/Lobby.svg)](https://gitter.im/oxidized/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Oxidized is a network device configuration backup tool. It's a RANCID replacement!
diff --git a/docs/Supported-OS-Types.md b/docs/Supported-OS-Types.md
index 5850bd1..62c7989 100644
--- a/docs/Supported-OS-Types.md
+++ b/docs/Supported-OS-Types.md
@@ -129,6 +129,7 @@
* [SR OS (TiMOS)](/lib/oxidized/model/sros.rb)
* OneAccess
* [OneOS](/lib/oxidized/model/oneos.rb)
+* [OpenBSD](/lib/oxidized/model/openbsd.rb)
* Opengear
* [Opengear](/lib/oxidized/model/opengear.rb)
* [OpenWRT](/lib/oxidized/model/openwrt.rb)
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 ""