예제 #1
0
    def __init__(self, args):
        arguments = ArgumentParser(prog="bna")
        arguments.add_argument("-u",
                               "--update",
                               action="store_true",
                               dest="update",
                               help="update token every time")
        arguments.add_argument("-n",
                               "--new",
                               action="store_true",
                               dest="new",
                               help="request a new authenticator")
        arguments.add_argument("-r",
                               "--region",
                               type=str,
                               dest="region",
                               default="US",
                               help="desired region for new authenticators")
        arguments.add_argument(
            "--set-default",
            action="store_true",
            dest="setdefault",
            help=
            "set authenticator as default (also works when requesting a new authenticator)"
        )
        arguments.add_argument("serial", nargs="?")
        args = arguments.parse_args(args)

        self.config = ConfigParser()
        self.config.read([os.path.join(self.getConfigDir(), "bna.conf")])

        # Are we requesting a new authenticator?
        if args.new:
            self.queryNewAuthenticator(args)
            exit()

        if not args.serial:
            serial = self.getDefaultSerial()
            if serial is None:
                self.error("You must provide an authenticator serial")
        else:
            serial = args.serial
        serial = bna.normalizeSerial(serial)

        # Are we setting a serial as default?
        if args.setdefault:
            self.setDefaultSerial(serial)

        # Get the secret from the keyring
        secret = self.getSecret(serial)
        if secret is None:  # No such serial
            self.error("%r: No such serial" % (serial))

        # And print the token
        if args.update:
            self.runLive(secret)

        else:
            token, timeRemaining = bna.getToken(secret=unhexlify(secret))
            print(token)
예제 #2
0
파일: cli.py 프로젝트: jerub/python-bna
def runLive(secret):
	from time import sleep
	print "Ctrl-C to exit"
	while 1:
		token, timeRemaining = bna.getToken(secret=unhexlify(secret))
		print "\r%08i" % (token),
		sys.stdout.flush()
		sleep(timeRemaining)
예제 #3
0
 def sync(self):
     try:
         token, self._timeremaining = bna.getToken(secret=self._secret)
         self._token = unicode(token)
         self.on_tokenChanged.emit()
         self.on_timeremainingChanged.emit()
     except Exception, e:
         self.on_error.emit("Could not connect: %s" % (unicode(e)))
예제 #4
0
 def runLive(self, secret):
     from time import sleep
     print("Ctrl-C to exit")
     while 1:
         token, timeRemaining = bna.getToken(secret=unhexlify(secret))
         sys.stdout.write("\r%08i" % (token))
         sys.stdout.flush()
         sleep(1)
예제 #5
0
파일: cli.py 프로젝트: cdhowie/python-bna
	def runLive(self, secret):
		from time import sleep
		print("Ctrl-C to exit")
		while 1:
			token, timeRemaining = bna.getToken(secret=unhexlify(secret))
			sys.stdout.write("\r%08i" % (token))
			sys.stdout.flush()
			sleep(1)
예제 #6
0
파일: cli.py 프로젝트: jerub/python-bna
def main():
	import signal
	from optparse import OptionParser
	
	signal.signal(signal.SIGINT, signal.SIG_DFL)
	options = OptionParser()
	options.add_option("-u", "--update", action="store_true", dest="update", help="update token every time")
	options.add_option("-n", "--new", action="store_true", dest="new", help="request a new authenticator")
	options.add_option("-r", "--region", type="string", dest="region", default="US", help="desired region for new authenticators")
	options.add_option("--set-default", action="store_true", dest="setdefault", help="set authenticator as default (also works when requesting a new authenticator)")
	args, serial = options.parse_args(sys.argv[1:])
	
	# Are we requesting a new authenticator?
	if args.new:
		runAuthenticatorQuery(args)
		exit()
	
	# If not, we need a serial
	
	if not serial:
		serial = getDefaultSerial()
		if serial is None:
			ERROR("You must provide an authenticator serial")
	else:
		serial = serial[0]
	serial = normalizeSerial(serial)
	
	# Are we setting a serial as default?
	if args.setdefault:
		setDefaultSerial(serial)
	
	# Get the secret from the keyring
	secret = keyring.get_password(SERVICE, serial)
	if secret is None: # No such serial
		ERROR("%r: No such serial" % (serial))
	
	# And print the token
	if args.update:
		runLive(secret)
	
	else:
		token, timeRemaining = bna.getToken(secret=unhexlify(secret))
		print token
예제 #7
0
파일: cli.py 프로젝트: cdhowie/python-bna
	def __init__(self, args):
		arguments = ArgumentParser(prog="bna")
		arguments.add_argument("-u", "--update", action="store_true", dest="update", help="update token every time")
		arguments.add_argument("-n", "--new", action="store_true", dest="new", help="request a new authenticator")
		arguments.add_argument("-r", "--region", type=str, dest="region", default="US", help="desired region for new authenticators")
		arguments.add_argument("--set-default", action="store_true", dest="setdefault", help="set authenticator as default (also works when requesting a new authenticator)")
		arguments.add_argument("serial", nargs="?")
		args = arguments.parse_args(args)
		
		self.config = ConfigParser()
		self.config.read([os.path.join(self.getConfigDir(), "bna.conf")])
		
		# Are we requesting a new authenticator?
		if args.new:
			self.queryNewAuthenticator(args)
			exit()
		
		if not args.serial:
			serial = self.getDefaultSerial()
			if serial is None:
				self.error("You must provide an authenticator serial")
		else:
			serial = args.serial
		serial = bna.normalizeSerial(serial)
		
		# Are we setting a serial as default?
		if args.setdefault:
			self.setDefaultSerial(serial)
		
		# Get the secret from the keyring
		secret = self.getSecret(serial)
		if secret is None: # No such serial
			self.error("%r: No such serial" % (serial))
		
		# And print the token
		if args.update:
			self.runLive(secret)
		
		else:
			token, timeRemaining = bna.getToken(secret=unhexlify(secret))
			print(token)