Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/telnet'
- class SDTDSay
- def initialize(options)
- @options = options
- if @options[:device] == 'STDOUT' then
- @device = STDOUT
- else
- @device = Net::Telnet::new('Host' => options[:host],
- 'Port' => options[:port],
- 'Telnetmode' => true,
- 'Timeout' => 60,
- 'Prompt' => /\n/)
- @device.cmd(options[:password])
- end
- end
- def send(line)
- if @device.class == STDOUT.class then
- @device.puts "#{self.fix_msg(line)}"
- else
- @device.cmd("#{self.fix_msg(line)}") do |resp|
- puts "#{resp}" unless @options[:quiet]
- end
- end
- end
- def close
- @device.puts('exit') unless @device.class == STDOUT.class
- @device.close unless @device.class == STDOUT.class
- end
- def fix_msg(msg)
- # _GREEN_ translated to color [00FFCC]
- # _RED_ translated to color [FF3300]
- # _WHITE_ translated to color [FFFFFF]
- # _YELLOW_ translated to color [FFFF99]
- # _BLUE_ translated to color [00CCFF]
- # _NOCOLOR_ translated to color [-]
- if @device.class == STDOUT.class then
- msg.gsub!(/_GREEN_/, '')
- msg.gsub!(/_RED_/, '')
- msg.gsub!(/_WHITE_/, '')
- msg.gsub!(/_YELLOW_/, '')
- msg.gsub!(/_BLUE_/, '')
- msg.gsub!(/_NOCOLOR_/, '')
- else
- msg.gsub!(/_GREEN_/, '[00FFCC]')
- msg.gsub!(/_RED_/, '[FF3300]')
- msg.gsub!(/_WHITE_/, '[FFFFFF]')
- msg.gsub!(/_YELLOW_/, '[FFFF99]')
- msg.gsub!(/_BLUE_/, '[00CCFF]')
- msg.gsub!(/_NOCOLOR_/, '[-]')
- end
- return msg
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement