mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-11 14:48:22 +00:00
Add qr html export mode to key export
command
This commit is contained in:
parent
52e84a6e2d
commit
257e55f37e
5 changed files with 27 additions and 6 deletions
|
@ -198,7 +198,10 @@ class Archiver:
|
||||||
if not args.path:
|
if not args.path:
|
||||||
self.print_error("output file to export key to expected")
|
self.print_error("output file to export key to expected")
|
||||||
return EXIT_ERROR
|
return EXIT_ERROR
|
||||||
manager.export(args.path)
|
if args.qr:
|
||||||
|
manager.export_qr(args.path)
|
||||||
|
else:
|
||||||
|
manager.export(args.path)
|
||||||
return EXIT_SUCCESS
|
return EXIT_SUCCESS
|
||||||
|
|
||||||
@with_repository(lock=False, exclusive=False, manifest=False, cache=False)
|
@with_repository(lock=False, exclusive=False, manifest=False, cache=False)
|
||||||
|
@ -1259,6 +1262,9 @@ class Archiver:
|
||||||
subparser.add_argument('--paper', dest='paper', action='store_true',
|
subparser.add_argument('--paper', dest='paper', action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Create an export suitable for printing and later type-in')
|
help='Create an export suitable for printing and later type-in')
|
||||||
|
subparser.add_argument('--qr-html', dest='qr', action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Create an html file suitable for printing and later type-in or qr scan')
|
||||||
|
|
||||||
key_import_epilog = textwrap.dedent("""
|
key_import_epilog = textwrap.dedent("""
|
||||||
This command allows to restore a key previously backed up with the
|
This command allows to restore a key previously backed up with the
|
||||||
|
|
|
@ -2,6 +2,7 @@ from binascii import unhexlify, a2b_base64, b2a_base64
|
||||||
import binascii
|
import binascii
|
||||||
import textwrap
|
import textwrap
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
|
import pkgutil
|
||||||
|
|
||||||
from .key import KeyfileKey, RepoKey, PassphraseKey, KeyfileNotFoundError, PlaintextKey
|
from .key import KeyfileKey, RepoKey, PassphraseKey, KeyfileNotFoundError, PlaintextKey
|
||||||
from .helpers import Manifest, NoManifestError, Error, yes, bin_to_hex
|
from .helpers import Manifest, NoManifestError, Error, yes, bin_to_hex
|
||||||
|
@ -77,16 +78,27 @@ class KeyManager:
|
||||||
elif self.keyblob_storage == KEYBLOB_REPO:
|
elif self.keyblob_storage == KEYBLOB_REPO:
|
||||||
self.repository.save_key(self.keyblob.encode('utf-8'))
|
self.repository.save_key(self.keyblob.encode('utf-8'))
|
||||||
|
|
||||||
|
def get_keyfile_data(self):
|
||||||
|
data = '%s %s\n' % (KeyfileKey.FILE_ID, bin_to_hex(self.repository.id))
|
||||||
|
data += self.keyblob
|
||||||
|
if not self.keyblob.endswith('\n'):
|
||||||
|
data += '\n'
|
||||||
|
return data
|
||||||
|
|
||||||
def store_keyfile(self, target):
|
def store_keyfile(self, target):
|
||||||
with open(target, 'w') as fd:
|
with open(target, 'w') as fd:
|
||||||
fd.write('%s %s\n' % (KeyfileKey.FILE_ID, bin_to_hex(self.repository.id)))
|
fd.write(self.get_keyfile_data())
|
||||||
fd.write(self.keyblob)
|
|
||||||
if not self.keyblob.endswith('\n'):
|
|
||||||
fd.write('\n')
|
|
||||||
|
|
||||||
def export(self, path):
|
def export(self, path):
|
||||||
self.store_keyfile(path)
|
self.store_keyfile(path)
|
||||||
|
|
||||||
|
def export_qr(self, path):
|
||||||
|
with open(path, 'wb') as fd:
|
||||||
|
key_data = self.get_keyfile_data()
|
||||||
|
html = pkgutil.get_data('borg', 'paperkey.html')
|
||||||
|
html = html.replace(b'</textarea>', key_data.encode() + b'</textarea>')
|
||||||
|
fd.write(html)
|
||||||
|
|
||||||
def export_paperkey(self, path):
|
def export_paperkey(self, path):
|
||||||
def grouped(s):
|
def grouped(s):
|
||||||
ret = ''
|
ret = ''
|
||||||
|
|
|
@ -140,7 +140,7 @@ html_favicon = '_static/favicon.ico'
|
||||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||||
html_static_path = ['borg_theme']
|
html_static_path = ['borg_theme']
|
||||||
|
|
||||||
html_extra_path = ['paperkey.html']
|
html_extra_path = ['../borg/paperkey.html']
|
||||||
|
|
||||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||||
# using the given strftime format.
|
# using the given strftime format.
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -302,6 +302,9 @@ setup(
|
||||||
'borg = borg.archiver:main',
|
'borg = borg.archiver:main',
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
package_data={
|
||||||
|
'borg': ['paperkey.html']
|
||||||
|
},
|
||||||
cmdclass=cmdclass,
|
cmdclass=cmdclass,
|
||||||
ext_modules=ext_modules,
|
ext_modules=ext_modules,
|
||||||
setup_requires=['setuptools_scm>=1.7'],
|
setup_requires=['setuptools_scm>=1.7'],
|
||||||
|
|
Loading…
Add table
Reference in a new issue