Skip to content

Commit

Permalink
Clean-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
udhos committed Dec 8, 2016
1 parent 4576552 commit d89fc4a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
43 changes: 22 additions & 21 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,28 @@ func NewDevAttr() DevAttributes {
}

type DevAttributes struct {
NeedLoginChat bool // need login chat
NeedEnabledMode bool // need enabled mode
NeedPagingOff bool // need disabled pager
EnableCommand string // enable
UsernamePromptPattern string // Username:
PasswordPromptPattern string // Password:
EnablePasswordPromptPattern string // Password:
DisabledPromptPattern string // >
EnabledPromptPattern string // # ("" --> look for EOF)
CommandList []string // "show version", "show run"
DisablePagerCommand string // term len 0
SupressAutoLF bool // do not send auto LF
QuoteSentCommandsFormat string // !![%s] - empty means omitting
KeepControlChars bool // enable if you want to capture control chars (backspace, etc)
LineFilter string // line filter name - applied to every saved line
ChangesOnly bool // save new file only if it differs from previous one
S3ContentType string // ""=none "detect"=http.Detect "text/plain" etc
RunProg []string // "/path/to/external/command", "arg1", "arg2" for the run model
RunTimeout time.Duration // 60s - time allowed for external program to complete
ErrlogHistSize int // max number of lines in errlog history
SendExtraPostPasswordNewline bool
NeedLoginChat bool // need login chat
NeedEnabledMode bool // need enabled mode
NeedPagingOff bool // need disabled pager
EnableCommand string // enable
UsernamePromptPattern string // Username:
PasswordPromptPattern string // Password:
EnablePasswordPromptPattern string // Password:
DisabledPromptPattern string // >
EnabledPromptPattern string // # ("" --> look for EOF)
CommandList []string // "show version", "show run"
DisablePagerCommand string // term len 0
SupressAutoLF bool // do not send auto LF
QuoteSentCommandsFormat string // !![%s] - empty means omitting
KeepControlChars bool // enable if you want to capture control chars (backspace, etc)
LineFilter string // line filter name - applied to every saved line
ChangesOnly bool // save new file only if it differs from previous one
S3ContentType string // ""=none "detect"=http.Detect "text/plain" etc
RunProg []string // "/path/to/external/command", "arg1", "arg2" for the run model
RunTimeout time.Duration // 60s - time allowed for external program to complete
ErrlogHistSize int // max number of lines in errlog history
PostLoginPromptPattern string // mikrotik: Please press "Enter" to continue!
PostLoginPromptResponse string // mikrotik: \r\n

// readTimeout: per-read timeout (protection against inactivity)
// matchTimeout: full match timeout (protection against slow sender -- think 1 byte per second)
Expand Down
23 changes: 11 additions & 12 deletions dev/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (d *Device) createTransport(logger hasPrintf) (transp, string, bool, error)
return openTransportPipe(logger, modelName, d.Id, d.HostPort, d.Transports, d.LoginUser, d.LoginPassword, d.Attr.RunProg, d.Debug, d.Attr.RunTimeout)
}

return openTransport(logger, modelName, d.Id, d.HostPort, d.Transports, d.LoginUser, d.LoginPassword)
return openTransport(logger, modelName, d.Id, d.HostPort, d.Transports, d.Username(), d.LoginPassword)
}

func (d *Device) fetch(logger hasPrintf, delay time.Duration, repository string, maxFiles int, ft *FilterTable) FetchResult {
Expand Down Expand Up @@ -660,22 +660,21 @@ func (d *Device) login(logger hasPrintf, t transp, capture *dialog) (bool, error

d.debugf("login: sent password")

if d.Attr.SendExtraPostPasswordNewline {
if d.Attr.PostLoginPromptPattern != "" {

d.debugf("login: will send post-password newline")
d.debugf("post-login-prompt: looking for pattern=[%s]", d.Attr.PostLoginPromptPattern)

pattern := `Please press "Enter" to continue!`
d.debugf("login: waiting: [%s]", pattern)

if _, _, mismatch := d.match(logger, t, capture, []string{pattern}); mismatch != nil {
return false, fmt.Errorf("afterPasswordNL: match: %v", mismatch)
if _, _, mismatch := d.match(logger, t, capture, []string{d.Attr.PostLoginPromptPattern}); mismatch != nil {
return false, fmt.Errorf("post-login-prompt: match: %v", mismatch)
}

d.debugf("afterPasswordNL: prompt FOUND")
if nlErr := d.send(logger, t, "\n"); nlErr != nil {
return false, fmt.Errorf("afterPasswordNL: error: %v", nlErr)
d.debugf("post-login-prompt: prompt FOUND")

if nlErr := d.send(logger, t, d.Attr.PostLoginPromptResponse); nlErr != nil {
return false, fmt.Errorf("post-login-prompt: error: %v", nlErr)
}
d.debugf("afterPasswordNL: extra newline sent")

d.debugf("post-login-prompt: response sent: [%q]", d.Attr.PostLoginPromptResponse)
}

m, _, err := d.match(logger, t, capture, []string{d.Attr.DisabledPromptPattern, d.Attr.EnabledPromptPattern})
Expand Down
3 changes: 2 additions & 1 deletion dev/model_mikrotik.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func registerModelMikrotik(logger hasPrintf, t *DeviceTable) {
a.NeedLoginChat = true
a.UsernamePromptPattern = `Login:\s*$`
a.PasswordPromptPattern = `Password:\s*$`
a.SendExtraPostPasswordNewline = true
a.PostLoginPromptPattern = `Please press "Enter" to continue!`
a.PostLoginPromptResponse = "\r\n"
a.DisabledPromptPattern = promptPattern
a.EnabledPromptPattern = promptPattern
a.CommandList = []string{"/system resource print\r", "/export\r", "/export verbose\r"}
Expand Down

0 comments on commit d89fc4a

Please sign in to comment.