F
F
fdroid2019-08-29 20:28:22
linux
fdroid, 2019-08-29 20:28:22

How to emulate terminal input?

There is a system for centralized collection of network equipment configs - oxidized. In general, it works, with the exception of one nuance - D-Link switches that have RADIUS authentication configured, to access show config, which is required by oxidized to get the config, you need to enter the enable command and then enter a password to elevate privileges. There is a settings file for each vendor, for D-Link it is:

class Dlink < Oxidized::Model
  # D-LINK Switches

  prompt /^(\r*[\[email protected]()\/:-]+[#>]\s?)$/
  comment '# '

  cmd :secret do |cfg|
    cfg.gsub! /^(create snmp community) \S+/, '\\1 <removed>'
    cfg.gsub! /^(create snmp group) \S+/, '\\1 <removed>'
    cfg
  end

  cmd :all do |cfg|
    cfg.each_line.to_a[2..-2].map { |line| line.delete("\r").rstrip }.join("\n") + "\n"
  end

  cmd 'show switch' do |cfg|
    cfg.gsub! /^System Uptime\s.+/, '' # Omit constantly changing uptime info
    comment cfg
  end

  cmd 'show vlan' do |cfg|
    comment cfg
  end

  cmd 'show config current'

  cfg :telnet do
    username /\r*[Uu]ser[Nn]ame:/
    password /\r*[Pp]ass[Ww]ord:/
  end

  cfg :telnet, :ssh do
    post_login 'disable clipaging'
    pre_logout 'logout'
  end
end

Somewhere between show vlan and show config current, you need to emulate such a sequence that oxidized will send to the switch:
enable admin # increase privileges, then Enter # enter a password here that is not displayed, you can just hardcode in
this file, then Enter
zero, I tried to do it by analogy, but it doesn’t work, I’m missing something.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question