Beispiel #1
0
// Run the console.
func Console(config core.Config) (err error) {
	fmt.Printf(`
Welcome to the Gate administration console!

Gate Copyright (C) 2012-2015 Cyril Adrian <*****@*****.**>
This program comes with ABSOLUTELY NO WARRANTY; for details type show w.
This is free software, and you are welcome to redistribute it
under certain conditions; type show c for details.

Type help for details on available options.
Just hit <enter> to exit.

`)

	srv, err := proxy(config)
	if err != nil {
		return
	}

	remoter := remote.NewRemoter(srv, config)
	if err != nil {
		return
	}

	mmi, err := ui.Ui(srv, config)
	if err != nil {
		return
	}

	commander, err := commands.NewCommander(remoter, srv, config, mmi)
	if err != nil {
		return
	}

	state := liner.NewLiner()
	defer state.Close()

	rl := &readline{
		commander: commander,
		server:    srv,
		state:     state,
	}

	complete := func(line string) (result []string) {
		result, err := rl.complete(line)
		if err != nil {
			fmt.Println(err)
			return
		}
		return
	}

	state.SetCompleter(complete)

	e := rl.loop(config)
	if e != io.EOF {
		err = e
	}
	return
}
Beispiel #2
0
// Run the console.
func CommandLine(config core.Config) (err error) {

	srv, err := proxy(config)
	if err != nil {
		return
	}

	remoter := remote.NewRemoter(srv, config)
	if err != nil {
		return
	}

	mmi, err := ui.Ui(srv, config)
	if err != nil {
		return
	}

	commander, err := commands.NewCommander(remoter, srv, config, mmi)
	if err != nil {
		return
	}

	cmd := commander.Command(os.Args[2])
	if cmd == nil {
		cmd = commander.Default()
	}

	err = cmd.Run(os.Args[2:])

	return
}
Beispiel #3
0
func displayMenu(config core.Config, srv server.Server, list []string) (err error) {
	command, err := config.Eval("", "menu", "command", os.Getenv)
	if err != nil {
		return
	}
	arguments, err := config.Eval("", "menu", "arguments", nil)
	if err != nil {
		return
	}

	barrier := make(chan error)
	pipe := make(chan io.WriteCloser, 1)

	prepare := func(cmd *exec.Cmd) (err error) {
		p, err := cmd.StdinPipe()
		if err != nil {
			return errors.Decorated(err)
		}

		out, err := cmd.StdoutPipe()
		if err != nil {
			return errors.Decorated(err)
		}

		mmi, err := ui.Ui(srv, config)
		if err != nil {
			return
		}

		go clipboard(mmi, out, barrier)

		pipe <- p
		return
	}

	run := func(cmd *exec.Cmd) (err error) {
		p := <-pipe

		for _, entry := range list {
			p.Write([]byte(entry + "\n"))
		}

		err = p.Close()
		if err != nil {
			return errors.Decorated(err)
		}

		e := <-barrier
		if e != io.EOF {
			err = errors.Decorated(e)
		}
		return
	}

	err = exec.Command(prepare, run, "bash", "-c", fmt.Sprintf("%s %s", command, arguments))

	return
}
Beispiel #4
0
func openVault(srv server.Server, config core.Config) (err error) {
	xdg, err := config.Xdg()
	if err != nil {
		return
	}

	data_home, err := xdg.DataHome()
	if err != nil {
		return
	}
	vault_path := fmt.Sprintf("%s/vault", data_home)
	vault_info, err := os.Stat(vault_path)
	if err != nil {
		return errors.Decorated(err)
	}

	mmi, err := ui.Ui(srv, config)
	if err != nil {
		return
	}

	var master string
	if vault_info == nil {
		master, err = readNewMaster(mmi, "This is a new vault")
		if err != nil {
			return
		}
	} else {
		master, err = mmi.ReadPassword("Please enter your encryption phrase\nto open the password vault.")
		if err != nil {
			return
		}
	}

	var isopen bool
	err = srv.Open(master, &isopen)
	if err != nil {
		return
	}
	if !isopen {
		return errors.New("Could not open vault")
	}

	return
}