Moved adding multiple URLs to record into kpwriter class.
This commit is contained in:
parent
4bf76d1b30
commit
c1b57c05a9
115
convert.py
115
convert.py
@ -5,10 +5,9 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
import onepif
|
import onepif
|
||||||
import kpwriter
|
import kpwriter
|
||||||
import pykeepass.icons
|
|
||||||
|
|
||||||
from os.path import splitext
|
from os.path import splitext
|
||||||
from urllib.parse import urlparse, quote_plus
|
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")
|
||||||
@ -46,27 +45,85 @@ def getField(item, designation):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
ICON_MAP = {
|
# Mapping of 1P types for best conversion
|
||||||
"112": "GEAR", # API Credential
|
RECORD_MAP = {
|
||||||
"wallet.financial.BankAccountUS": "DOLLAR_SIGN", # Bank Account
|
"112": {
|
||||||
"wallet.financial.CreditCard": "DOLLAR_SIGN", # Credit Card
|
# API Credential
|
||||||
"wallet.computer.Database": "SERVER", # Database
|
"icon": "GEAR",
|
||||||
|
},
|
||||||
|
"wallet.financial.BankAccountUS": {
|
||||||
|
# Bank Account
|
||||||
|
"icon": "DOLLAR_SIGN",
|
||||||
|
},
|
||||||
|
"wallet.financial.CreditCard": {
|
||||||
|
# Credit Card
|
||||||
|
"icon": "DOLLAR_SIGN",
|
||||||
|
},
|
||||||
|
"wallet.computer.Database": {
|
||||||
|
# Database
|
||||||
|
"icon": "SERVER",
|
||||||
|
},
|
||||||
# Not exported: Document
|
# Not exported: Document
|
||||||
"wallet.government.DriversLicense": "BUSINESS_CARD", # Driver License
|
"wallet.government.DriversLicense": {
|
||||||
"wallet.onlineservices.Email.v2": "ENVELOPE", # Email Account
|
# Driver License
|
||||||
"identities.Identity": "BUSINESS_CARD", # Identity
|
"icon": "BUSINESS_CARD",
|
||||||
"webforms.WebForm": "MANAGER", # Login
|
},
|
||||||
"113": "WARNING_SIGN", # Medical Record
|
"wallet.onlineservices.Email.v2": {
|
||||||
"wallet.membership.Membership": "BUSINESS_CARD", # Membership
|
# Email Account
|
||||||
"wallet.government.HuntingLicense": "BUSINESS_CARD", # Outdoor License
|
"icon": "ENVELOPE",
|
||||||
"wallet.government.Passport": "BUSINESS_CARD", # Passport
|
},
|
||||||
"passwords.Password": "KEY", # Password
|
"identities.Identity": {
|
||||||
"wallet.membership.RewardProgram": "PERCENT_SIGN", # Reward Program
|
# Identity
|
||||||
"securenotes.SecureNote": "POST_IT", # Secure Note
|
"icon": "BUSINESS_CARD",
|
||||||
"wallet.computer.UnixServer": "SERVER_2", # Server
|
},
|
||||||
"wallet.government.SsnUS": "BUSINESS_CARD", # Social Security Number
|
"webforms.WebForm": {
|
||||||
"wallet.computer.License": "CARDBOARD", # Software License
|
# Login
|
||||||
"wallet.computer.Router": "12", # Wireless Router
|
"icon": "MANAGER",
|
||||||
|
},
|
||||||
|
"113": {
|
||||||
|
# Medical Record
|
||||||
|
"icon": "WARNING_SIGN",
|
||||||
|
},
|
||||||
|
"wallet.membership.Membership": {
|
||||||
|
# Membership
|
||||||
|
"icon": "BUSINESS_CARD",
|
||||||
|
},
|
||||||
|
"wallet.government.HuntingLicense": {
|
||||||
|
# Outdoor License
|
||||||
|
"icon": "BUSINESS_CARD",
|
||||||
|
},
|
||||||
|
"wallet.government.Passport": {
|
||||||
|
# Passport
|
||||||
|
"icon": "BUSINESS_CARD",
|
||||||
|
},
|
||||||
|
"passwords.Password": {
|
||||||
|
# Password
|
||||||
|
"icon": "KEY",
|
||||||
|
},
|
||||||
|
"wallet.membership.RewardProgram": {
|
||||||
|
# Reward Program
|
||||||
|
"icon": "PERCENT_SIGN",
|
||||||
|
},
|
||||||
|
"securenotes.SecureNote": {
|
||||||
|
# Secure Note
|
||||||
|
"icon": "POST_IT",
|
||||||
|
},
|
||||||
|
"wallet.computer.UnixServer": {
|
||||||
|
# Server
|
||||||
|
"icon": "SERVER_2",
|
||||||
|
},
|
||||||
|
"wallet.government.SsnUS": {
|
||||||
|
# Social Security Number
|
||||||
|
"icon": "BUSINESS_CARD",
|
||||||
|
},
|
||||||
|
"wallet.computer.License": {
|
||||||
|
# Software License
|
||||||
|
"icon": "CARDBOARD",
|
||||||
|
},
|
||||||
|
"wallet.computer.Router": {
|
||||||
|
# Wireless Router
|
||||||
|
"icon": "12",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for item in opif:
|
for item in opif:
|
||||||
@ -82,13 +139,13 @@ for item in opif:
|
|||||||
entry = kp.add_entry(target_group_name, item["title"])
|
entry = kp.add_entry(target_group_name, item["title"])
|
||||||
|
|
||||||
# Icon
|
# Icon
|
||||||
kp_icon = ICON_MAP[item.type]
|
kp_icon = RECORD_MAP[item.type]["icon"]
|
||||||
kp.set_icon(kp_icon)
|
kp.set_icon(kp_icon)
|
||||||
|
|
||||||
# Tags
|
# Tags
|
||||||
kp.set_tags(item.get_tags())
|
kp.set_tags(item.get_tags())
|
||||||
|
|
||||||
# TOTP
|
# TOTPs
|
||||||
totps = item.get_totps()
|
totps = item.get_totps()
|
||||||
if totps:
|
if totps:
|
||||||
for totp in totps:
|
for totp in totps:
|
||||||
@ -210,15 +267,7 @@ for item in opif:
|
|||||||
if "URLs" in secure:
|
if "URLs" in secure:
|
||||||
kp2idx = 0
|
kp2idx = 0
|
||||||
for u in secure["URLs"]:
|
for u in secure["URLs"]:
|
||||||
if not entry.url:
|
kp.add_url(u["url"])
|
||||||
entry.url = u["url"]
|
|
||||||
else:
|
|
||||||
# https://github.com/keepassxreboot/keepassxc/pull/3558
|
|
||||||
prop_name = "KP2A_URL"
|
|
||||||
if kp2idx > 0:
|
|
||||||
prop_name += "_{}".format(kp2idx)
|
|
||||||
entry.set_custom_property(prop_name, u["url"])
|
|
||||||
kp2idx += 1
|
|
||||||
url = urlparse(u["url"])
|
url = urlparse(u["url"])
|
||||||
settings["Allow"].append(url.hostname)
|
settings["Allow"].append(url.hostname)
|
||||||
applySettings = True
|
applySettings = True
|
||||||
|
12
kpwriter.py
12
kpwriter.py
@ -48,6 +48,18 @@ class KpWriter:
|
|||||||
if len(title) > 0:
|
if len(title) > 0:
|
||||||
self.set_prop("otp_title{}".format(suffix), title)
|
self.set_prop("otp_title{}".format(suffix), title)
|
||||||
|
|
||||||
|
def add_url(self, url):
|
||||||
|
if not self.current_entry.url:
|
||||||
|
self.current_entry.url = url
|
||||||
|
else:
|
||||||
|
# https://github.com/keepassxreboot/keepassxc/pull/3558
|
||||||
|
suffix = ""
|
||||||
|
suffix_ctr = 0
|
||||||
|
while self.current_entry.get_custom_property("KP2A_URL{}".format(suffix)):
|
||||||
|
suffix_ctr += 1
|
||||||
|
suffix = "_{}".format(suffix_ctr)
|
||||||
|
self.set_prop("KP2A_URL{}".format(suffix), url)
|
||||||
|
|
||||||
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