| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 | 
							- #!/usr/bin/env python
 
- #============================================================================
 
- # This file is part of Pwman3.
 
- #
 
- # Pwman3 is free software; you can redistribute it and/or modify
 
- # it under the terms of the GNU General Public License, version 2
 
- # as published by the Free Software Foundation;
 
- #
 
- # Pwman3 is distributed in the hope that it will be useful,
 
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
- # GNU General Public License for more details.
 
- #
 
- # You should have received a copy of the GNU General Public License
 
- # along with Pwman3; if not, write to the Free Software
 
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
- #============================================================================
 
- # Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
 
- #============================================================================
 
- # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
 
- #============================================================================
 
- import os
 
- import os.path
 
- import argparse
 
- import sys
 
- _saveconfig = True
 
- parser = argparse.ArgumentParser(description=('pwman3 - a command line '
 
-                                               'password manager.'))
 
- parser.add_argument('-c', '--config', dest='cfile',
 
-                     default=os.path.expanduser("~/.pwman/config"),
 
-                     help='cofiguration file to read')
 
- parser.add_argument('-d', '--database', dest='dbase')
 
- parser.add_argument('-e', '--encryption', dest="algo",
 
-                     help=("Possible options are: AES(default), ARC2, ARC4, "
 
-                           "Blowfish, CAST, DES, DES3, IDEA, RC5"))
 
- parser.add_argument('-k', '--convert', dest='dbconvert',
 
-                     action='store_true', default=False,
 
-                     # os.path.expanduser('~/.pwman/pwman.db'),
 
-                     help=("Convert old DB format to version >= 0.4."
 
-                           " The database that will be converted is the"
 
-                           " one found in the config file, or the one given"
 
-                           " as command line argument.")
 
-                     )
 
- parser.add_argument('-t', '--test',  help="Run pwman from current directory \
 
- without installation", action="store_true")
 
- args = parser.parse_args()
 
- if args.test:
 
-     sys.path.insert(0, os.getcwd())
 
- from pwman.util.crypto import CryptoEngine
 
- from pwman import default_config, which
 
- if 'darwin' in sys.platform:
 
-     from pwman.ui.mac import PwmanCliMacNew as PwmanCliNew
 
-     OSX = True
 
- elif 'win' in sys.platform:
 
-     from pwman.ui.win import PwmanCliWinNew as PwmanCliNew
 
-     OSX = False
 
- else:
 
-     from pwman.ui.cli import PwmanCliNew
 
-     OSX = False
 
- from pwman.ui.tools import CLICallback
 
- import pwman.util.config as config
 
- import pwman.data.factory
 
- from pwman.data.convertdb import PwmanConvertDB
 
- try:
 
-     config_dir = os.path.expanduser("~/.pwman")
 
-     if not os.path.isdir(config_dir):
 
-         os.mkdir(config_dir)
 
-     if not os.path.exists(args.cfile):
 
-         config.set_defaults(default_config)
 
-     else:
 
-         config.load(args.cfile)
 
-         xselpath = config.get_value("Global", "xselpath")
 
-     if not OSX:
 
-         xselpath = which("xsel")
 
-         config.set_value("Global", "xsel", xselpath)
 
-     elif OSX:
 
-         pbcopypath = which("pbcopy")
 
-         config.set_value("Global", "xsel", pbcopypath)
 
-     if 'win' in sys.platform:
 
-         try:
 
-             import colorama
 
-             colorama.init()
 
-         except ImportError:
 
-             config.set_value("Global", "colors", 'no')
 
-     if args.dbase:
 
-         config.set_value("Database", "filename", args.dbase)
 
-         _saveconfig = False
 
-     if args.algo:
 
-             config.set_value("Encryption", "algorithm", args.algo)
 
-             _saveconfig = False
 
-     # set umask before creating/opening any files
 
-     umask = int(config.get_value("Global", "umask"))
 
-     os.umask(umask)
 
-     enc = CryptoEngine.get()
 
-     dbtype = config.get_value("Database", "type")
 
-     # if it is done here, we could do the following:
 
-     # if db.ver == 0.4 :
 
-     #     db = pwman.data.factory.create(dbtyp, new_version)
 
-     # else:
 
-     #     we use the old code untouched ... insecure, but
 
-     #     keeps backwards compatibility ...
 
-     # if the database file exists check it's version
 
-     # else: force version 0.4
 
-     if os.path.exists(config.get_value("Database", "filename")):
 
-         dbver = pwman.data.factory.check_db_version(dbtype)
 
-         dbver = float(dbver.strip("\'"))
 
-     else:
 
-         dbver = 0.4
 
-     # the method create could create an old instance that
 
-     # accepts cPickle object or new style instance that
 
-     # accepts only strings.
 
-     # The user should be STRONGLY Prompted to CONVERT the
 
-     # database to the new format using a command line tool.
 
-     # version 0.5 pwman will depreciate that old and insecure
 
-     # code ...
 
-     if args.dbconvert:
 
-         dbconvertor = PwmanConvertDB(args, config)
 
-         status = dbconvertor.run()
 
-         sys.exit(status)
 
-     db = pwman.data.factory.create(dbtype, dbver)
 
-     if dbver >= 0.4:
 
-         cli = PwmanCliNew(db, xselpath, CLICallback)
 
-     elif dbver < 0.4:
 
-         cli = PwmanCli(db, xselpath)
 
-         print cli._dbwarning
 
-         sys.exit(0)
 
- except SystemExit, e:
 
-     sys.exit(e)
 
- try:
 
-     try:
 
-         cli.cmdloop()
 
-     except KeyboardInterrupt, e:
 
-         print e
 
- finally:
 
-     try:
 
-         if _saveconfig:
 
-             config.save(args.cfile)
 
-     except Exception, e:
 
-         print "Error: %s" % (e)
 
-         sys.exit(-1)
 
 
  |