コード例 #1
0
ファイル: sitechecker.go プロジェクト: hahnicity/Projects
func main() {
	flag.StringVar(&url, "u", "http://gregoryrehm.com", "The url of the website to track")
	flag.IntVar(&sleepDuration, "d", 5, "The duration of time to sleep in between pinging the server")
	pass, _ = getpass.GetPassWithOptions("Password for "+from+": ", 0, getpass.DefaultMaxPass)
	flag.Parse()
	PollURL()
}
コード例 #2
0
ファイル: sudo.go プロジェクト: cgutierrez/gomez
func (sudo *sudoRunner) promptForPassword(runner *runner, writer io.Writer) (string, error) {

	if runner.host.Password == "" {

		password, err := getpass.GetPassWithOptions(fmt.Sprintf("enter sudo password for %s: ", runner.host.Host), 0, 100)

		if err != nil {
			return password, err
		}

		runner.host.Password = password
	}

	return runner.host.Password, nil
}
コード例 #3
0
ファイル: main.go プロジェクト: jmuk/gdsync
// Uploads a file to Google Drive
func main() {
	initFlags()

	if flag.NArg() != 2 {
		fmt.Printf("Usage: %s SRC DST\n", os.Args[0])
		fmt.Printf("SRC or DST must start with drive: prefix")
		flag.PrintDefaults()
		return
	}

	src := flag.Arg(0)
	dst := flag.Arg(1)

	client_file, err := os.Open(clientSettings)
	if err != nil {
		fmt.Printf("Failed to load the client settings: %v\n", err)
		return
	}
	defer client_file.Close()
	var clientData map[string]string
	if err := json.NewDecoder(client_file).Decode(&clientData); err != nil {
		fmt.Printf("Failed to parse the client settings: %v\n", err)
		return
	}
	clientId, id_ok := clientData["ClientId"]
	clientSecret, secret_ok := clientData["ClientSecret"]
	if !id_ok || !secret_ok {
		fmt.Printf("Cannot find value for ClientId or ClientSecret")
		return
	}
	config := gdsync.GetAuthConfig(clientId, clientSecret)

	if authfile != "" && passphrase == "\000" {
		var err error
		passphrase, err = getpass.GetPassWithOptions("Enter the passphrase: ", 0, getpass.DefaultMaxPass)
		if err != nil {
			fmt.Printf("Failed to read the passphrase: %v\n", err)
			return
		}
	}

	token_manager, err := gdsync.NewTokenManager(config, authfile, passphrase)
	if err != nil {
		fmt.Printf("Failed to initialize the auth token: %v\n", err)
		return
	}

	// Create a new authorized Drive client.
	syncer, err := gdsync.NewGDSyncer(token_manager.Transport)
	if err != nil {
		fmt.Printf("Cannot start drive service: %v\n", err)
		return
	}

	syncer.SetErrorLogger(log.New(os.Stderr, "", 0))
	if verbose {
		syncer.SetLogger(log.New(os.Stdout, "", 0))
	}

	if exclude != "" {
		syncer.AddExcludePattern(exclude)
	}
	if excludeFrom != "" {
		if exclude_file, err := os.Open(excludeFrom); err == nil {
			fmt.Printf("reading from %s...\n", excludeFrom)
			bufreader := bufio.NewReader(exclude_file)
			for {
				if pattern, err := bufreader.ReadString('\n'); err == nil {
					syncer.AddExcludePattern(strings.TrimSpace(pattern))
				} else {
					syncer.AddExcludePattern(strings.TrimSpace(pattern))
					break
				}
			}
		} else {
			fmt.Printf("Cannot read the file %s: %v\n", excludeFrom, err)
		}
	}

	if doDelete {
		syncer.DoDelete()
	}
	if useTextPlain {
		syncer.UseTextPlain()
	}

	syncer.DoSync(src, dst)
}
コード例 #4
0
ファイル: client.go プロジェクト: cgutierrez/gomez
func CreateSession(host *Host) (*ssh.Client, *ssh.Session, error) {

	// if the host configuration doesn't contain a key file, check the users .ssh/config file
	// appends any keys found for the matching host to be used for authentication
	foundHostConfig := userSshConfig.MatchHost(host.Host)
	if host.KeyFile == "" && foundHostConfig != nil {

		if foundHostConfig != nil {

			// set the host to the hostname found in the configuration
			// allows for using partial host names in the host argument
			if foundHostConfig.HostName != "" {
				host.Host = foundHostConfig.HostName
			}

			if host.KeyFile == "" && foundHostConfig.IdentityFile != "" {
				host.KeyFile = foundHostConfig.IdentityFile
			}

			// use the port form the ssh config if it's supplied
			if host.Port == "" && foundHostConfig.Port != "" {
				host.Port = foundHostConfig.Port
			}

			// use the user found in the foundHostConfig if one isn't provided
			if host.User == "" && foundHostConfig.User != "" {
				host.User = foundHostConfig.User
			}
		}
	}

	sshConfig := &ssh.ClientConfig{User: host.User, Auth: []ssh.AuthMethod{}}

	if host.Password != "" {
		sshConfig.Auth = append(sshConfig.Auth, ssh.Password(host.Password))
	}

	if host.KeyFile != "" {
		sshConfig.Auth = append(sshConfig.Auth, ssh.PublicKeysCallback(func() (signers []ssh.Signer, err error) {

			keyFiles, err := LoadDefaultKeyFiles()

			if host.KeyFile != "" {
				hostKeyFile, err := LoadKeyFile(host.KeyFile)
				if err != nil {
					return nil, err
				}

				keyFiles = append(keyFiles, hostKeyFile)
			}

			return keyFiles, err
		}))
	}

	if host.Password == "" && host.KeyFile == "" {
		sshConfig.Auth = append(sshConfig.Auth, ssh.PasswordCallback(func() (string, error) {
			password, err := getpass.GetPassWithOptions(fmt.Sprintf("enter password for %s@%s: ", host.User, host.Host), 0, 100)

			if err != nil {
				fmt.Println(err.Error())
				return password, err
			}

			host.Password = password
			return password, err
		}))
	}

	client, err := ssh.Dial("tcp", host.Host+":"+host.Port, sshConfig)

	if err != nil {
		fmt.Println(err.Error())
		return nil, nil, err
	}

	session, err := client.NewSession()

	if err != nil {
		return nil, nil, err
	}

	return client, session, err
}