5 # Copyright (C) 2009 Trend Micro Inc.
8 # This program is a free software; you can redistribute it
9 # and/or modify it under the terms of the GNU General Public
10 # License (version 2) as published by the FSF - Free Software
14 send_user "ERROR: ssh_pixconfig_diff <hostname> <commands>\n";
18 # NOTE: this script must be called from within /var/ossec for it to work
19 set passlist "agentless/.passlist"
20 set hostname [lindex $argv 0]
21 set commands [lrange $argv 1 end]
26 if {[string compare $hostname "test"] == 0} {
27 if {[string compare $commands "test"] == 0} {
32 # Read the password list
34 set in [open "$passlist" r]
36 send_user "ERROR: Password list not present (use \"register_host\" first).\n"
40 while {[gets $in line] != -1} {
41 set me [string first "|" $line]
42 set me2 [string last "|" $line]
43 set length [string length $line]
58 set host_list [string range $line 0 $me]
60 set pass_list [string range $line $me $me2]
62 set addpass_list [string range $line $me2 $length]
64 if {[string compare $host_list $hostname] == 0} {
66 set addpass "$addpass_list"
72 if {[string compare $pass "x"] == 0} {
73 send_user "ERROR: Password for '$hostname' not found.\n"
77 # SSH to the box and pass the directories to check
79 spawn ssh -c des $hostname
81 send_user "ERROR: Opening connection: $loc_error.\n"
86 "WARNING: REMOTE HOST" {
87 send_user "ERROR: RSA host key for '$hostname' has changed. Unable to access.\n"
90 "*sure you want to continue connecting*" {
92 expect "* password:*" {
97 send_user "ERROR: Incorrect password to remote host: $hostname .\n"
101 send_user "ERROR: Timeout while running on host (too long to finish): $hostname .\n"
105 send_user "\nINFO: Starting.\n"
110 "ssh: connect to host*" {
111 send_user "ERROR: Unable to connect to remote host: $hostname .\n"
114 "no address associated with name" {
115 send_user "ERROR: Unable to connect to remote host: $hostname .\n"
118 "*Connection refused*" {
119 send_user "ERROR: Unable to connect to remote host: $hostname .\n"
122 "*Connection closed by remote host*" {
123 send_user "ERROR: Unable to connect to remote host: $hostname .\n"
130 "Permission denied" {
131 send_user "ERROR: Incorrect password to remote host: $hostname .\n"
135 send_user "ERROR: Timeout while running on host (too long to finish): $hostname .\n"
139 send_user "INFO: Starting.\n"
144 send_user "ERROR: Timeout while connecting to host: $hostname . \n"
149 # Go into enable mode
157 send_user "ERROR: Incorrect enable password to remote host: $hostname .\n"
160 "*rror in authenticatio*" {
161 send_user "ERROR: Incorrect enable password to remote host: $hostname .\n"
165 send_user "ERROR: Timeout while going to enable mode on host: $hostname .\n"
169 send_user "ok on enable pass\n"
174 send_user "ERROR: Timeout while running enable on host: $hostname .\n"
181 send_user "\nSTORE: now\n"
185 send "terminal pager 0\r"
187 # Exclude uptime from the output
188 send "show version | grep -v Configuration last| up\r"
189 send "show running-config\r"
195 send_user "ERROR: Timeout while running commands on host: $hostname .\n"
199 send_user "\nINFO: Finished.\n"
204 send_user "ERROR: Unable to finish properly.\n"