Moved KeePassHttp handling into kpwriter.
This commit is contained in:
parent
c1b57c05a9
commit
1ea51e6e28
36
convert.py
36
convert.py
@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
|
||||||
import onepif
|
import onepif
|
||||||
import kpwriter
|
import kpwriter
|
||||||
|
|
||||||
from os.path import splitext
|
from os.path import splitext
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Convert 1Password 1PIF exports into a KeePass KDBX file.")
|
parser = argparse.ArgumentParser(description="Convert 1Password 1PIF exports into a KeePass KDBX file.")
|
||||||
parser.add_argument("inpath", metavar="input.1pif", help="1Password export file/folder")
|
parser.add_argument("inpath", metavar="input.1pif", help="1Password export file/folder")
|
||||||
@ -153,9 +151,19 @@ for item in opif:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
secure = item["secureContents"]
|
secure = item["secureContents"]
|
||||||
|
|
||||||
|
# URLs
|
||||||
|
if "location" in item:
|
||||||
|
kp.add_url(item["location"])
|
||||||
|
if "URLs" in secure:
|
||||||
|
for u in secure["URLs"]:
|
||||||
|
kp.add_url(u["url"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Username
|
# Username
|
||||||
if "username" in secure:
|
if "username" in secure:
|
||||||
entry.username = secure["username"]
|
entry.username = secure["username"]
|
||||||
@ -254,28 +262,6 @@ for item in opif:
|
|||||||
if "notesPlain" in secure:
|
if "notesPlain" in secure:
|
||||||
entry.notes = secure["notesPlain"]
|
entry.notes = secure["notesPlain"]
|
||||||
|
|
||||||
# URLs
|
|
||||||
settings = {
|
|
||||||
"Allow": [],
|
|
||||||
"Deny": [],
|
|
||||||
"Realm": "",
|
|
||||||
}
|
|
||||||
applySettings = False
|
|
||||||
|
|
||||||
if "location" in item:
|
|
||||||
entry.url = item["location"]
|
|
||||||
if "URLs" in secure:
|
|
||||||
kp2idx = 0
|
|
||||||
for u in secure["URLs"]:
|
|
||||||
kp.add_url(u["url"])
|
|
||||||
url = urlparse(u["url"])
|
|
||||||
settings["Allow"].append(url.hostname)
|
|
||||||
applySettings = True
|
|
||||||
|
|
||||||
if applySettings:
|
|
||||||
settings["Allow"] = list(set(settings["Allow"]))
|
|
||||||
entry.set_custom_property("KeePassHttp Settings", json.dumps(settings))
|
|
||||||
|
|
||||||
# Dates
|
# Dates
|
||||||
entry.ctime = datetime.datetime.fromtimestamp(item["createdAt"])
|
entry.ctime = datetime.datetime.fromtimestamp(item["createdAt"])
|
||||||
entry.mtime = datetime.datetime.fromtimestamp(item["updatedAt"])
|
entry.mtime = datetime.datetime.fromtimestamp(item["updatedAt"])
|
||||||
|
18
kpwriter.py
18
kpwriter.py
@ -1,5 +1,6 @@
|
|||||||
|
import json
|
||||||
import pykeepass.icons
|
import pykeepass.icons
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus, urlparse
|
||||||
from pykeepass import create_database
|
from pykeepass import create_database
|
||||||
|
|
||||||
|
|
||||||
@ -60,6 +61,21 @@ class KpWriter:
|
|||||||
suffix = "_{}".format(suffix_ctr)
|
suffix = "_{}".format(suffix_ctr)
|
||||||
self.set_prop("KP2A_URL{}".format(suffix), url)
|
self.set_prop("KP2A_URL{}".format(suffix), url)
|
||||||
|
|
||||||
|
# KeePassHttp
|
||||||
|
current_settings = self.current_entry.get_custom_property("KeePassHttp Settings")
|
||||||
|
if current_settings:
|
||||||
|
current_settings = json.loads(current_settings)
|
||||||
|
else:
|
||||||
|
current_settings = {
|
||||||
|
"Allow": [],
|
||||||
|
"Deny": [],
|
||||||
|
"Realm": "",
|
||||||
|
}
|
||||||
|
parsed_url = urlparse(url)
|
||||||
|
current_settings["Allow"].append(parsed_url.hostname)
|
||||||
|
current_settings["Allow"] = list(set(current_settings["Allow"]))
|
||||||
|
self.set_prop("KeePassHttp Settings", json.dumps(current_settings))
|
||||||
|
|
||||||
def set_prop(self, key, value, protected=False):
|
def set_prop(self, key, value, protected=False):
|
||||||
self.current_entry.set_custom_property(key, value)
|
self.current_entry.set_custom_property(key, value)
|
||||||
if protected:
|
if protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user