コード例 #1
0
ファイル: passman.go プロジェクト: seanpont/passman
func interactive(args []string) {
	cm := commandMap()
	_, err := loadServices(getPasswd())
	gobro.CheckErr(err, "Password invalid")
	for {
		cmd, err := commander.Prompt("passman$ ")
		if err != nil {
			return
		}
		if cmd == "" {
			continue
		}
		args := make([]string, 0, 3)
		args = append(args, "passman")
		args = append(args, strings.Split(cmd, " ")...)
		cm.Run(args)
	}
}
コード例 #2
0
ファイル: passman.go プロジェクト: seanpont/passman
func initialize(args []string) {
	_, err := loadConfig()
	if err != nil {
		u, err := user.Current()
		gobro.CheckErr(err)
		saveConfig(Config{PasswdFile: u.HomeDir + "/.passman"})
	}
	services, err := loadServices(getPasswd())
	if err == nil && services != nil && services.Len() > 0 {
		overwrite, err := commander.Prompt("   Overwrite existing password file? (y/N): ")
		if err != nil || strings.ToLower(overwrite) != "y" {
			return
		}
	}
	saveServices(getPasswd(), new(Services))
	_, err = loadServices(getPasswd()) // just to test that we have saved it properly
	gobro.CheckErr(err, "Unable to read password file")
}
コード例 #3
0
ファイル: passman.go プロジェクト: seanpont/passman
func add(args []string) {
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "Usage: passman add <service> [<options>]\n"+
			"  -g: Generate password\n  "+
			"    Additional options:\n"+
			"      l: include lowercase characters\n"+
			"      u: include uppercase characters\n"+
			"      n: include numbers\n"+
			"      c: include special characters\n"+
			"      w: generate a password using random words from the dictionary\n"+
			"      \\d+$: password must be at least this long."+
			"      example: add -glun24 will produce a password using, lowercase, characters,\n"+
			"      uppercase characters, and numbers, and will be 24 characters long"+
			"  -p: Enter password\n  "+
			"  -m: attach metadata\n")
		return
	}

	name := args[0]
	services, err := loadServices(getPasswd())
	gobro.CheckErr(err, "Password invalid")
	service := services.Get(name)
	service.Name = name

	generateParams, _ := strarr.FindMatchWithRegex(args, "-g.*")
	if generateParams != "" {
		service.Password = NewPasswordGenerator(generateParams).generate()
	}

	if strarr.Contains(args, "-p") {
		prompt := fmt.Sprintf("   Password for %s: ", service.Name)
		password, err := gopass.GetPass(prompt)
		gobro.CheckErr(err)
		service.Password = password
	}

	if strarr.Contains(args, "-m") {
		service.Meta, _ = commander.Prompt(fmt.Sprintf("   Meta for %s: ", service.Name))
	}

	services.Add(service)
	saveServices(getPasswd(), services)
}