|
@@ -23,14 +23,60 @@
|
|
|
|
|
|
|
|
|
from pwman.ui.cli import PwmanCliNew
|
|
|
+from pwman.data.nodes import NewNode
|
|
|
from pwman.ui import tools
|
|
|
import time
|
|
|
import msvcrt
|
|
|
import pwman.util.config as config
|
|
|
-
|
|
|
+import ast
|
|
|
+from pwman.util.crypto import zerome
|
|
|
|
|
|
class PwmanCliWinNew(PwmanCliNew):
|
|
|
|
|
|
+ def do_new(self, args):
|
|
|
+ """
|
|
|
+ can override default config settings the following way:
|
|
|
+ Pwman3 0.2.1 (c) visit: http://github.com/pwman3/pwman3
|
|
|
+ pwman> n {'leetify':False, 'numerics':True, 'special_chars':True}
|
|
|
+ Password (Blank to generate):
|
|
|
+ """
|
|
|
+ errmsg = """could not parse config override, please input some"""\
|
|
|
+ + """ kind of dictionary, e.g.: n {'leetify':False, """\
|
|
|
+ + """'numerics':True, 'special_chars':True}"""
|
|
|
+ try:
|
|
|
+ username = self.get_username()
|
|
|
+ if args:
|
|
|
+ try:
|
|
|
+ args = ast.literal_eval(args)
|
|
|
+ except Exception:
|
|
|
+ raise Exception(errmsg)
|
|
|
+ if not isinstance(args, dict):
|
|
|
+ raise Exception(errmsg)
|
|
|
+ password = self.get_password(1, **args)
|
|
|
+ else:
|
|
|
+ numerics = config.get_value(
|
|
|
+ "Generator", "numerics").lower() == 'true'
|
|
|
+ # TODO: allow custom leetifying through the config
|
|
|
+ leetify = config.get_value(
|
|
|
+ "Generator", "leetify").lower() == 'true'
|
|
|
+ special_chars = config.get_value(
|
|
|
+ "Generator", "special_chars").lower() == 'true'
|
|
|
+ password = self.get_password(0,
|
|
|
+ numerics=numerics,
|
|
|
+ symbols=leetify,
|
|
|
+ special_signs=special_chars)
|
|
|
+ url = self.get_url()
|
|
|
+ notes = self.get_notes()
|
|
|
+ node = NewNode(username, password, url, notes)
|
|
|
+ tags = self.get_tags()
|
|
|
+ node.set_tags(tags)
|
|
|
+ self._db.addnodes([node])
|
|
|
+ print "Password ID: %d" % (node.get_id())
|
|
|
+ # when done with node erase it
|
|
|
+ zerome(password)
|
|
|
+ except Exception, e:
|
|
|
+ self.error(e)
|
|
|
+
|
|
|
def print_node(self, node):
|
|
|
width = str(tools._defaultwidth)
|
|
|
print "Node %d." % (node.get_id())
|