Example #1
0
func executeKey(ctx command.ConfContext, line string, c *Client) {
	log.Printf("executeKey(): [%v]", line)

	if line == "q" {
		c.outputQueue = nil // discard output queue
	}

	// key feedback
	// RETURN is empty line (line == "")
	c.Output() <- fmt.Sprintf("%s\r\n", line)

	commandFeedback(c, getHostname(ctx.ConfRootActive()))
}
Example #2
0
func executeLine(ctx command.ConfContext, line string, history bool, c *Client) {
	log.Printf("executeLine: [%v]", line)

	status := c.Status()

	switch status {
	case command.MOTD:
		c.Sendln("")
		c.Sendln("vty server ready")
		c.Sendln("")
		if isAnyUserDefined(ctx.ConfRootActive()) {
			c.StatusSet(command.USER) // request user/password auth
		} else {
			c.StatusSet(command.EXEC) // login without user/password auth
		}
	case command.USER:
		c.EchoDisable()
		c.StatusSet(command.PASS)
		c.UsernameSet(line)
	case command.PASS:
		c.EchoEnable()
		if checkPassword(ctx.ConfRootActive(), c.Username(), line) {
			c.StatusSet(command.EXEC) // login allowed
		} else {
			c.StatusSet(command.USER) // request user again
		}
	case command.EXEC, command.ENAB, command.CONF:
		if err := command.Dispatch(ctx, line, c, status, history); err != nil {
			c.Sendln(fmt.Sprintf("executeLine: error: %v", err))
		}
	default:
		msg := fmt.Sprintf("unknown state for command: [%s]", line)
		log.Print(msg)
		c.Sendln(msg)
	}

	commandFeedback(c, getHostname(ctx.ConfRootActive()))
}