Example #1
0
	def adpw(self, usr, pwd=None, com=None):
		"""password adding method"""
		if self.dbg:
			print(bgre(tabd({
                self.adpw: {'user': self.user, 'entry': usr,
                            'pwd': pwd, 'comment': com}})))
		if not self.aal:
Example #2
0
def lscrypt(usr, dbg=None):
	"""passlist wrapper function"""
	if dbg:
		print(bgre(lscrypt))
Example #3
0
	def lspw(self, usr=None, aal=None):
		"""password listing method"""
		if self.dbg and not self.gui:
			print(bgre(tabd({self.lspw: {'user': self.user, 'entry': usr}})))
Example #4
0
	def rmpw(self, usr):
		"""remove password method"""
		if self.dbg:
			print(bgre(tabd({self.rmpw: {'user': self.user, 'entry': usr}})))
		if self.aal:
Example #5
0
	def chpw(self, usr, pwd=None, com=None):
		"""change existing password method"""
		if self.dbg:
			print(bgre(tabd({
                self.chpw: {'user': self.user, 'entry': usr, 'pwd': pwd}})))
		if not self.aal:
Example #6
0
	def _writecrypt(self, __weaks):
		"""crypt file writing method"""
		if self.dbg:
			print(bgre(self._writecrypt))
Example #7
0
	def _readcrypt(self):
		"""read crypt file method"""
		if self.dbg:
			print(bgre(self._readcrypt))
Example #8
0
def confpars(mode):
    """pwclip command line opt/arg parsing function"""
    _me = path.basename(path.dirname(__file__))
    cfg = path.expanduser('~/.config/%s.cfg' % _me)
    cfgs = {
        'crypt': path.expanduser('~/.passcrypt'),
        'plain': path.expanduser('~/.pwd.yaml'),
        'time': 3,
        'binary': 'gpg' if osname == 'nt' else 'gpg.exe',
        'user': whoami(),
    }
    try:
        with open(cfg, 'r') as cfh:
            confs = dict(load(cfh.read(), Loader=Loader))
    except (TypeError, FileNotFoundError):
        confs = {}
    cfgmap = {
        'gpg': {
            'recipients': 'recvs',
            'key': 'gpgkey',
            'delkey': True
        },
        'yubikey': {
            'slot': 'ykslot',
            'seerial': 'ykser',
            'delkey': True
        }
    }
    envmap = {
        'GPGKEY': 'gpgkey',
        'RECIPIENTS': 'recvs',
        'PWCLIPTIME': 'time',
        'YKSERIAL': 'ykser',
        'USER': '******',
        'USERNAME': '******',
        'YKSLOT': 'ykslot'
    }
    confs = dictreplace(confs, cfgmap)
    for (k, v) in confs.items():
        cfgs[k] = v
    envs = _envconf(envmap)
    for (k, v) in envs.items():
        cfgs[k] = v
    cfgs['binary'] = 'gpg2'
    if osname == 'nt':
        cfgs['binary'] = 'gpg'
    if 'crypt' not in cfgs.keys():
        cfgs['crypt'] = path.expanduser('~/.passcrypt')
    elif 'crypt' in cfgs.keys() and cfgs['crypt'].startswith('~'):
        cfgs['crypt'] = path.expanduser(cfgs['crypt'])
    if 'plain' not in cfgs.keys():
        cfgs['plain'] = path.expanduser('~/.pwd.yaml')
    elif 'plain' in cfgs.keys() and cfgs['plain'].startswith('~'):
        cfgs['plain'] = path.expanduser(cfgs['plain'])
    pars = optpars(cfgs, mode, 'pwcli')
    autocomplete(pars)
    pars = optpars(cfgs, mode, 'pwclip')
    autocomplete(pars)
    args = pars.parse_args()
    pargs = [
        a for a in [
            'aal' if args.aal else None, 'dbg' if args.dbg else None,
            'ent' if args.ent else None, 'gsm' if args.gpv else None,
            'gui' if mode == 'gui' else None, 'sho' if args.sho else None
        ] if a
    ]
    __bin = 'gpg2'
    if args.gpv:
        __bin = args.gpv
    if osname == 'nt':
        __bin = 'gpgsm.exe' if args.gpv else 'gpg.exe'
    pkwargs = {}
    pkwargs['binary'] = __bin
    pkwargs['sslcrt'] = args.sslcrt
    pkwargs['sslkey'] = args.sslkey
    if args.gpw:
        _genpwrex = '[a-zA-Z0-9\!$%%&/\(\)=\?\+#,\.-:]*:24'
        pargs.append('rnd')
        if args.rex is not False:
            getrex = input
            msg = 'enter regular expression for new password:'******'aborted due to empty input'
            if mode == 'gui':
                getrex = xinput
                msg = 'enter regular expression for new password'
                err = 'aborted due to empty input'
            _genpwrex = getrex('enter regular expression for new password')
            if not _genpwrex:

                xnotify('aborted due to empty input')
                exit(1)
        elif mode == 'gui':
            _genpwrex = '[a-zA-Z0-9\!$%%&/\(\)=\?\+#,\.-:]*:24'
        genpwrex = _genpwrex
        genpwlen = 24
        if ':' in genpwrex:
            genpwrex, genpwlen = \
                         ''.join(str(genpwrex).split(':')[:-1]), \
                         str(genpwrex).split(':')[-1]
        pkwargs['genpwrex'] = genpwrex
        pkwargs['genpwlen'] = genpwlen
    if args.pcr:
        pkwargs['crypt'] = args.pcr
    if args.recvs:
        pkwargs['recvs'] = str(args.recvs).split(' ')
    if args.gpgkey:
        pkwargs['gpgkey'] = args.gpgkey
    if args.usr:
        pkwargs['user'] = args.usr
    if args.time:
        pkwargs['time'] = args.time
    if args.yml:
        pkwargs['plain'] = args.yml
    if args.dbg:
        print(bgre(pars))
        print(bgre(tabd(args.__dict__, 2)))
        print(bgre('pargs:\n  %s\npkwargs:\n%s' % (pargs, tabd(pkwargs, 2))))
    if mode != 'gui' and (
             args.yks is False and args.lst is False and \
             args.add is False and args.chg is False and \
             args.rms is False and args.sslcrt is None and args.sslkey is None):
        pars.print_help()
        exit(0)
    if mode == 'gui':
        return args, pargs, pkwargs
    return args, pargs, pkwargs