Example #1
0
func setup() {
	var dir string
	var username string
	var password []byte

	fmt.Println("Setup")
	fmt.Println("--------------------")
	fmt.Println("Bitte gib deine CampusOffice daten ein.")
	fmt.Println("Deine Zugangsdaten werden verschl├╝sselt auf deinem Computer abgelegt.")

	fmt.Printf("MatrNr: ")
	fmt.Scanln(&username)
	fmt.Printf("Passwort: ")
	password = gopass.GetPasswdMasked()

	for !login(string(username), string(password)) {
		fmt.Println("Falche MatrNr oder falsches Passwort!")

		fmt.Printf("MatrNr: ")
		fmt.Scanln(&username)
		fmt.Printf("Passwort: ")
		password = gopass.GetPasswdMasked()
	}

	fmt.Println("Erfolgreich eingeloggt")
	db.set_encrypted_setting(e, "username", username)
	db.set_encrypted_setting(e, "password", string(password))

	fmt.Println("Bitte gib den Speicherort an, an dem deine iCal exportiert werden soll.")
	fmt.Println("Beispiele:")
	fmt.Println("Windows: C:\\Users\\Benutzer\\Dropbox")
	fmt.Println("Linux: /home/Benutzer/Dropbox")

	fmt.Printf("Speicherort: ")
	fmt.Scanln(&dir)

	_, err := os.Stat(dir)
	for err != nil {
		if os.IsNotExist(err) {
			log.Print(err)
			fmt.Printf("Der Speicherort %s existiert nicht.\n", dir)
			fmt.Println("Bitte gibt einen g├╝ltigen Speicherort an")
		} else {
			fmt.Println("Es ist ein Fehler aufgetreten.")
			fmt.Println("Bist du sicher, dass du Zugriffsberechtigungn auf diesen Ordner hast?")
		}
		fmt.Printf("Speicherort: ")
		fmt.Scanln(&dir)
		_, err = os.Stat(dir)
	}
	db.set_setting("dir", dir)

	db.set_setting("setup", "1")
	fmt.Println("Setup abgeschlossen")
}
Example #2
0
func Login(args []string, opts map[string]interface{}) {
	user := &userInfo{CurDir: "/"}
	if len(args) == 3 {
		user.Bucket = args[0]
		user.Username = args[1]
		user.Password = args[2]
	} else {
		fmt.Printf("ServiceName: ")
		fmt.Scanf("%s\n", &user.Bucket)
		fmt.Printf("Operator: ")
		fmt.Scanf("%s\n", &user.Username)
		fmt.Printf("Password: "******"failed to log in. %v\n", err)
		os.Exit(-1)
	}

	// save
	conf.UpdateUserInfo(user)
	conf.Save(confname)
}
Example #3
0
func getAndVerifyMaster(master string) string {
	// prompt for a master password if necessary
	if len(master) == 0 {
		// get master password from environment, or from keyboard
		if s := os.Getenv("LETMEIN_MASTER"); s != "" {
			master = s
		} else {
			fmt.Printf("Master password: "******"master password is required")
				os.Exit(1)
			}
		}
	}

	// validate the master password
	if len(master) < minMasterLength || len(master) > maxMasterLength {
		fmt.Fprintf(os.Stderr, "master password must be between %d and %d characters\n", minMasterLength, maxMasterLength)
		os.Exit(1)
	}
	for _, r := range master {
		if r < minChar || r > maxChar {
			fmt.Fprintf(os.Stderr, "master password contains an illegal character\n")
			os.Exit(1)
		}
	}

	return master
}
Example #4
0
// SetupDb creates a new database or opens an existing one at a given directory.
// This will prompt the user to set a password if the database is being created.
func SetupDb(path string) (*Db, error) {
	imageDb, err := imagedb.NewDb(path)
	if err != nil {
		return nil, err
	}

	res := Db{imageDb, sync.RWMutex{}, filepath.Join(path, "config.json"), Config{}}
	saveConfig := false

	if res.loadConfig() != nil {
		saveConfig = true
	}
	if res.config.PasswordHash == "" {
		fmt.Print("Setup new password: ")
		pass := gopass.GetPasswdMasked()
		res.config.PasswordHash = HashPassword(string(pass))
		saveConfig = true
	}
	if res.config.MaxFileSize == 0 {
		res.config.MaxFileSize = DefaultMaxFileSize
		saveConfig = true
	}
	if res.config.MaxUploadsPerHour == 0 {
		res.config.MaxUploadsPerHour = DefaultMaxCountPerHour
		saveConfig = true
	}

	if saveConfig {
		if err := res.saveConfig(); err != nil {
			return nil, err
		}
	}

	return &res, nil
}
Example #5
0
// ReadPassword reads password from standard input without echoing the characters.
// If mask is true, each chracter will be represented with astericks '*'. Note that
// this only works as expected when the standard input is a terminal.
func (s *Shell) ReadPassword(mask bool) string {
	fmt.Fprint(s.writer, s.prompt)
	if mask {
		return string(gopass.GetPasswdMasked())
	}
	return string(gopass.GetPasswd())
}
Example #6
0
func (adc *ADC) AskCredentials() {
	fmt.Print("ADC username: "******"%s\n", &adc.username)

	fmt.Print("ADC password: ")
	adc.password = string(gopass.GetPasswdMasked())
}
Example #7
0
func GetPasswd() string {
	fmt.Printf("Password: ")
	p, err := gopass.GetPasswdMasked()
	if err != nil {
		log.Fatal(err)
	}
	return string(p)
}
Example #8
0
// Password prompt with mask.
func PasswordMasked(prompt string, args ...interface{}) string {
	fmt.Printf(prompt+": ", args...)
	var buf, err = gopass.GetPasswdMasked()
	if err != nil {
		return ""
	}
	s := string(buf[0:])
	return s
}
Example #9
0
// ReadPassword reads password from standard input without echoing the characters.
// If mask is true, each character will be represented with asterisks '*'. Note that
// this only works as expected when the standard input is a terminal.
func (s *Shell) ReadPassword(mask bool) string {
	if s.showPrompt {
		s.Print(s.prompt)
	}
	if mask {
		return string(gopass.GetPasswdMasked())
	}
	return string(gopass.GetPasswd())
}
Example #10
0
func getPassword() []byte {
	passFromEnv := os.Getenv("SCONSIFY_PASSWORD")
	if passFromEnv != "" {
		fmt.Println("Reading password from environment variable SCONSIFY_PASSWORD.")
		return []byte(passFromEnv)
	}
	fmt.Print("Password: ")
	return gopass.GetPasswdMasked()
}
Example #11
0
func (this *MergeAccount) input_SrcSeed() string {
	fmt.Printf(this.infoStrings[this.languageIndex][MA_INFO_INPUT_SOURCE_SEED])

	input := gopass.GetPasswdMasked()
	if publicdefine.VerifySAddress(string(input)) == nil {
		return string(input)
	}
	return ""
}
func (this *AccountInfoPayment) input_SrcSeed() string {
	fmt.Printf(this.infoStrings[this.languageIndex][AIP_INFO_INPUT_PRIVATE_SEED])

	input := gopass.GetPasswdMasked()
	if publicdefine.VerifySAddress(string(input)) == nil {
		return string(input)
	}
	return ""
}
Example #13
0
// PasswordMasked prompt with mask.
func PasswordMasked(prompt string, args ...interface{}) string {
	fmt.Printf(prompt, args...)

	b, err := gopass.GetPasswdMasked()
	if err != nil {
		panic(err)
	}

	return string(b)
}
Example #14
0
func main() {
	fmt.Print("Email/username: "******"Password: "******"Authenticating...")

	sess, err := fbmsgr.Auth(user, string(pass))
	if err != nil {
		fmt.Fprintln(os.Stderr, "Failed to login:"******"Destination filename: ")
	file := readLine()

	fmt.Println("Downloading messages...")
	var actions []map[string]interface{}

	actionChan, errChan := sess.FullActionLog(fbid, nil)
	for action := range actionChan {
		actions = append(actions, action.RawFields())
		fmt.Printf("\rGot %d actions...", len(actions))
	}
	fmt.Printf("\rTotal of %d actions...\n", len(actions))

	if err := <-errChan; err != nil {
		fmt.Fprintln(os.Stderr, "Fetch error:", err)
	}

	// Sort the actions chronologically.
	for i := 0; i < len(actions)/2; i++ {
		actions[i], actions[len(actions)-(i+1)] = actions[len(actions)-(i+1)], actions[i]
	}

	encoded, err := json.MarshalIndent(actions, "", "  ")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Serialization failed:", err)
		os.Exit(1)
	}

	if err := ioutil.WriteFile(file, encoded, 0755); err != nil {
		fmt.Fprintln(os.Stderr, "Failed to write file:", err)
		os.Exit(1)
	}
}
Example #15
0
func promptForString(field string, r io.Reader, show bool) (result string, err error) {
	fmt.Printf("Please enter %s: ", field)
	if show {
		_, err = fmt.Fscan(r, &result)
	} else {
		var data []byte
		data, err = gopass.GetPasswdMasked()
		result = string(data)
	}
	return result, err
}
Example #16
0
// main is the entry point for this app.
func main() {
	log.SetFlags(log.Lshortfile)
	// Command line flags
	configPtr := flag.String("config", "", "Config name to use.")
	userPtr := flag.String("user", "", "Username to use for sshing.")
	aConfigs := gsh.LoadConfigs()
	strConfig := ""
	flag.Parse()

	// Check command line options
	if len(*configPtr) > 0 {
		strConfig = *configPtr
		fmt.Printf("Using config: %s\n", strConfig)
	} else {
		strConfs := ""
		for _, conf := range aConfigs {
			if len(strConfs) > 0 {
				strConfs += ", "
			}
			strConfs += conf.Name
		}
		strConfig = readLine(fmt.Sprintf("Select configuration to load (%s): ", strConfs))
	}
	for _, conf := range aConfigs {
		if strings.EqualFold(conf.Name, strConfig) {
			gsh.CurrentConfig = &conf
			break
		}
	}
	if gsh.CurrentConfig == nil {
		log.Fatalf("Unable to load config %s", strConfig)
	}
	if len(*userPtr) > 0 {
		resources.SshUser = *userPtr
		fmt.Printf("Using user: %s\n", resources.SshUser)
	} else {
		resources.SshUser = readLine("Please enter the ssh user to use: ")
	}
	fmt.Printf("Password:"******"/hosts", resources.HostsResourceHandler)
	http.HandleFunc("/operations", resources.OperationsResourceHandler)
	http.HandleFunc("/subscribe/", resources.SubscribeResourceHandler)
	// static files
	http.Handle("/", http.FileServer(http.Dir("webroot")))

	//log.Fatal(http.ListenAndServe(":8080", nil))
	fmt.Println("gSSH Utilities started and serving data.")
	log.Fatal(http.ListenAndServeTLS(":7443", "cert.pem", "key.pem", nil))
}
Example #17
0
func getPasswd(prompt string) (string, error) {
	for {
		fmt.Print(prompt)
		pass, err := gopass.GetPasswdMasked()
		if err != nil {
			return "", fmt.Errorf("Failed to read password")
		}
		if 0 < len(pass) {
			return string(pass[:]), nil
		}
	}

}
Example #18
0
func main() {
	var domain, salt, master, note string = "", "", "", ""
	var pass_length int = 14

	if len(os.Args) == 1 {
		fmt.Printf("Usage: %s domain [password-length]\n", os.Args[0])
		os.Exit(1)
	}

	if len(os.Args) > 1 {
		// We do have domain
		domain = strings.TrimSpace(os.Args[1])
		display_notes(domain)
	}

	if len(os.Args) > 2 {
		// We do have password length
		p_length, err := strconv.Atoi(os.Args[2])
		if err != nil {
			fmt.Printf("Password Length should be a number\n")
			os.Exit(1)
		}
		pass_length = p_length
	}

	reader := bufio.NewReader(os.Stdin)

	fmt.Printf("Enter salt. Hit enter to leave it blank: ")
	salt, _ = reader.ReadString('\n')
	salt = strings.TrimRight(salt, "\n")

	fmt.Printf("Enter note to save. Hit enter to leave it blank: ")
	note, _ = reader.ReadString('\n')
	note = strings.TrimRight(note, "\n")

	if len(note) > 0 {
		add_note(domain, note)
	}

	fmt.Printf("Enter Master password. Hit enter to abort: ")
	master = string(gopass.GetPasswdMasked()[:])

	if len(master) == 0 {
		os.Exit(1)
	}

	password := gen_pwd(domain+salt, master)[:pass_length]
	clipboard.WriteAll(password)
	fmt.Println(password, "copied to your clipboard")
}
Example #19
0
func readLine(prompt string, private bool) (string, error) {
	fmt.Fprintf(os.Stdout, prompt)
	var line string
	var err error

	if private {
		line = string(gopass.GetPasswdMasked())
	} else {
		line, err = in.ReadString('\n')
		if err != nil {
			return "", err
		}
	}
	return strings.Trim(line, "\n"), nil
}
Example #20
0
File: upx.go Project: beepony/upx
func Login(args ...string) {
	config := &Config{CurDir: "/"}

	fmt.Printf("ServiceName: ")
	fmt.Scanf("%s\n", &config.Bucket)
	fmt.Printf("Operator: ")
	fmt.Scanf("%s\n", &config.Username)
	fmt.Printf("Password: "******"login: %v\n\n", err)
		os.Exit(-1)
	}
}
Example #21
0
// Interactive server configuration
func ConfigureServer() {
	var configuration ServerConfiguration

	reader := bufio.NewReader(os.Stdin)

	fmt.Printf("%-10s: ", "Port")
	port, _ := reader.ReadString(byte('\n'))
	port = strings.Trim(port, "\n\r\t ")
	configuration.Port, _ = strconv.ParseUint(port, 10, 0)

	fmt.Printf("%-10s: ", "Password")
	configuration.Secret = gopass.GetPasswdMasked()

	StoreServerConfiguration(&configuration)
}
Example #22
0
func getUserCredentials(email string, password string) (string, string) {
	email = strings.TrimSpace(email)
	if email == "" {
		fmt.Print("Email: ")
		email, err := bufio.NewReader(os.Stdin).ReadString('\n')
		handle(err)
		email = strings.TrimSpace(email)
	}

	password = strings.TrimSpace(password)
	if password == "" {
		fmt.Print("Password: ")
		password = strings.TrimSpace(string(gopass.GetPasswdMasked()))
	}

	return email, password
}
Example #23
0
func (c *Cli) CmdLogin() error {
	uri := fmt.Sprintf("%s/rest/auth/1/session", c.endpoint)
	for true {
		req, _ := http.NewRequest("GET", uri, nil)
		user, _ := c.opts["user"].(string)

		fmt.Printf("Jira Password [%s]: ", user)
		pw, err := gopass.GetPasswdMasked()
		if err != nil {
			return err
		}
		passwd := string(pw)

		req.SetBasicAuth(user, passwd)
		if resp, err := c.makeRequest(req); err != nil {
			return err
		} else {
			if resp.StatusCode == 403 {
				// probably got this, need to redirect the user to login manually
				// X-Authentication-Denied-Reason: CAPTCHA_CHALLENGE; login-url=https://jira/login.jsp
				if reason := resp.Header.Get("X-Authentication-Denied-Reason"); reason != "" {
					err := fmt.Errorf("Authenticaion Failed: %s", reason)
					log.Errorf("%s", err)
					return err
				}
				err := fmt.Errorf("Authentication Failed: Unknown Reason")
				log.Errorf("%s", err)
				return err

			} else if resp.StatusCode == 200 {
				// https://confluence.atlassian.com/display/JIRA043/JIRA+REST+API+%28Alpha%29+Tutorial#JIRARESTAPI%28Alpha%29Tutorial-CAPTCHAs
				// probably bad password, try again
				if reason := resp.Header.Get("X-Seraph-Loginreason"); reason == "AUTHENTICATION_DENIED" {
					log.Warning("Authentication Failed: %s", reason)
					continue
				}
			} else {
				log.Warning("Login failed")
				continue
			}
		}
		return nil
	}
	return nil
}
Example #24
0
// Interactive client configuration.
func ConfigureClient() {
	var configuration ClientConfiguration
	reader := bufio.NewReader(os.Stdin)

	fmt.Printf("%-10s: ", "Hostname")
	configuration.Hostname, _ = reader.ReadString(byte('\n'))
	configuration.Hostname = strings.Trim(configuration.Hostname, "\n\r\t ")

	fmt.Printf("%-10s: ", "Port")
	port, _ := reader.ReadString(byte('\n'))
	port = strings.Trim(port, "\n\r\t ")
	configuration.Port, _ = strconv.ParseUint(port, 10, 0)

	fmt.Printf("%-10s: ", "Password")
	configuration.Secret = gopass.GetPasswdMasked()

	configuration.ForwardedKeys = GetDefaultForwardedKeys()

	StoreClientConfiguration(&configuration)
}
Example #25
0
func SetUp() {
	fmt.Printf("User: "******"Password: "******"bad response")
	}

	var me Me
	meResErrMarshErr := json.Unmarshal(resBytes, &me)
	if meResErrMarshErr != nil {
		panic(meResErrMarshErr)
	}

	Switch(me)
}
Example #26
0
// login confirms the enrollmentID and secret password of the client with the
// CA and stores the enrollment certificate and key in the Devops server.
func login(args []string) {
	logger.Info("CLI client login...")

	// Check for username argument
	if len(args) == 0 {
		logger.Error("Error: must supply username.\n")
		return
	}

	// Check for other extraneous arguments
	if len(args) != 1 {
		logger.Error("Error: must supply username as the 1st and only parameter.\n")
		return
	}

	// Retrieve the CLI data storage path
	// Returns /var/openchain/production/client/
	localStore := getCliFilePath()
	logger.Info("Local data store for client loginToken: %s", localStore)

	// If the user is already logged in, return
	if _, err := os.Stat(localStore + "loginToken_" + args[0]); err == nil {
		logger.Info("User '%s' is already logged in.\n", args[0])
		return
	}

	// User is not logged in, prompt for password
	fmt.Printf("Enter password for user '%s': ", args[0])
	pw := gopass.GetPasswdMasked()

	// Log in the user
	logger.Info("Logging in user '%s' on CLI interface...\n", args[0])

	// Get a devopsClient to perform the login
	clientConn, err := peer.NewPeerClientConnection()
	if err != nil {
		logger.Error(fmt.Sprintf("Error trying to connect to local peer: %s", err))
		return
	}
	devopsClient := pb.NewDevopsClient(clientConn)

	// Build the login spec and login
	loginSpec := &pb.Secret{EnrollId: args[0], EnrollSecret: string(pw)}
	loginResult, err := devopsClient.Login(context.Background(), loginSpec)

	// Check if login is successful
	if loginResult.Status == pb.Response_SUCCESS {
		// If /var/openchain/production/client/ directory does not exist, create it
		if _, err := os.Stat(localStore); err != nil {
			if os.IsNotExist(err) {
				// Directory does not exist, create it
				if err := os.Mkdir(localStore, 0755); err != nil {
					panic(fmt.Errorf("Fatal error when creating %s directory: %s\n", localStore, err))
				}
			} else {
				// Unexpected error
				panic(fmt.Errorf("Fatal error on os.Stat of %s directory: %s\n", localStore, err))
			}
		}

		// Store client security context into a file
		logger.Info("Storing login token for user '%s'.\n", args[0])
		err = ioutil.WriteFile(localStore+"loginToken_"+args[0], []byte(args[0]), 0755)
		if err != nil {
			panic(fmt.Errorf("Fatal error when storing client login token: %s\n", err))
		}

		logger.Info("Login successful for user '%s'.\n", args[0])
	} else {
		logger.Error(fmt.Sprintf("Error on client login: %s", string(loginResult.Msg)))
	}

	return
}
Example #27
0
File: main.go Project: goopi/krane
func main() {
	args, _ := docopt.Parse(Usage, nil, true, Version, false)

	if args["push"].(bool) {
		token := args["TOKEN"].(string)
		cert := args["--certificate"].(string)
		sandbox := args["--develop"].(bool)
		passphrase := args["--passphrase"].(bool)

		alert, ok := args["--alert"].(string)
		if !ok {
			exitWithError("Enter your alert message")
		}

		if _, err := os.Stat(cert); os.IsNotExist(err) {
			exitWithError("Could not find certificate file")
		}

		var pass []byte
		if passphrase {
			fmt.Print("Password: "******"--badge"] != nil {
			badge, err := strconv.Atoi(args["--badge"].(string))
			if err != nil {
				exitWithError("Invalid badge")
			}

			payload.Badge = badge
		}

		if sound, ok := args["--sound"].(string); ok {
			payload.Sound = sound
		}

		n := apns.NewNotification()
		n.DeviceToken = token
		n.AddPayload(payload)

		notifications := make([]*apns.Notification, 0)
		notifications = append(notifications, n)

		err := client.Push(notifications)

		if err != nil {
			exitWithError("Push notifications unsuccessful")
		}

		sent := 0
		unsent := 0

		for _, n := range notifications {
			if n.Sent {
				sent++
			} else {
				unsent++
			}
		}

		if sent > 0 {
			msg := fmt.Sprintf("%d push notifications sent successfully", sent)
			successMessage(msg)
		}

		if unsent > 0 {
			msg := fmt.Sprintf("%d push notifications unsuccessful", unsent)
			errorMessage(msg)
		}
	}

	if args["feedback"].(bool) {
		cert := args["--certificate"].(string)
		sandbox := args["--develop"].(bool)
		passphrase := args["--passphrase"].(bool)

		if _, err := os.Stat(cert); os.IsNotExist(err) {
			exitWithError("Could not find certificate file")
		}

		var pass []byte
		if passphrase {
			fmt.Print("Password: "******"Error getting feedback")
		}

		if len(devices) > 0 {
			fmt.Println(devices)
		} else {
			successMessage("No feedback available")
		}
	}
}
Example #28
0
func loginRegistry(ctx *cobra.Command, args []string) {
	reg := client.INDEX_SERVER
	if len(args) > 0 {
		reg = args[0]
	}

	config, err := client.LoadConfig(configPath)
	if err != nil {
		log.Fatal(err)
	}

	ctx.Printf("Log in to a Docker registry at %s\n", reg)

	registry, _ := config.GetRegistry(reg)

	authConfig := api.AuthConfig{
		ServerAddress: registry.Registry,
	}

	promptDefault := func(prompt string, configDefault string) {
		if configDefault == "" {
			ctx.Printf("%s: ", prompt)
		} else {
			ctx.Printf("%s (%s): ", prompt, configDefault)
		}
	}

	readInput := func() string {
		reader := bufio.NewReader(os.Stdin)
		line, _, err := reader.ReadLine()
		if err != nil {
			log.Fatal(err)
		}
		return string(line)
	}

	promptDefault("Username", registry.Username)
	authConfig.Username = readInput()
	if authConfig.Username == "" {
		authConfig.Username = registry.Username
	}

	ctx.Print("Password: "******"Email", registry.Email)
	authConfig.Email = readInput()
	if authConfig.Email == "" {
		authConfig.Email = registry.Email
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	credentials, err := docker.Auth(&authConfig)
	if err != nil {
		log.Fatal(err)
	}

	registry.Username = authConfig.Username
	registry.Email = authConfig.Email
	registry.Credentials = credentials

	config.SetRegistry(registry)

	if err := config.SaveConfig(configPath); err != nil {
		log.Fatal(err)
	}

	ctx.Println("Login Succeeded!")

	listRegistries(ctx, args)
}
Example #29
0
// PasswordPrompt prompt a user for an interactive password
func (hp *HostFileParser) PasswordPrompt(hostname string) string {
	fmt.Printf("Enter password for %s: ", hostname)
	text := gopass.GetPasswdMasked()
	return string(text)
}
Example #30
0
// Password prompt with mask.
func PasswordMasked(prompt string, args ...interface{}) string {
	fmt.Printf(prompt+": ", args...)
	s := string(gopass.GetPasswdMasked()[0:])
	return s
}