mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-31 20:26:40 +00:00
Add qr html export mode to key export
command
This commit is contained in:
parent
e0f36e8613
commit
179f1bc147
5 changed files with 27 additions and 6 deletions
|
@ -140,7 +140,7 @@
|
|||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['borg_theme']
|
||||
|
||||
html_extra_path = ['paperkey.html']
|
||||
html_extra_path = ['../src/borg/paperkey.html']
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
|
|
3
setup.py
3
setup.py
|
@ -666,6 +666,9 @@ def run(self):
|
|||
'borgfs = borg.archiver:main',
|
||||
]
|
||||
},
|
||||
package_data={
|
||||
'borg': ['paperkey.html']
|
||||
},
|
||||
cmdclass=cmdclass,
|
||||
ext_modules=ext_modules,
|
||||
setup_requires=['setuptools_scm>=1.7'],
|
||||
|
|
|
@ -271,7 +271,10 @@ def do_key_export(self, args, repository):
|
|||
if not args.path:
|
||||
self.print_error("output file to export key to expected")
|
||||
return EXIT_ERROR
|
||||
manager.export(args.path)
|
||||
if args.qr:
|
||||
manager.export_qr(args.path)
|
||||
else:
|
||||
manager.export(args.path)
|
||||
return EXIT_SUCCESS
|
||||
|
||||
@with_repository(lock=False, exclusive=False, manifest=False, cache=False)
|
||||
|
@ -1938,6 +1941,9 @@ def process_epilog(epilog):
|
|||
subparser.add_argument('--paper', dest='paper', action='store_true',
|
||||
default=False,
|
||||
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 = process_epilog("""
|
||||
This command allows to restore a key previously backed up with the
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import binascii
|
||||
import textwrap
|
||||
from hashlib import sha256
|
||||
import pkgutil
|
||||
|
||||
from .key import KeyfileKey, RepoKey, PassphraseKey, KeyfileNotFoundError, PlaintextKey
|
||||
from .helpers import Manifest, NoManifestError, Error, yes, bin_to_hex
|
||||
|
@ -77,16 +78,27 @@ def store_keyblob(self, args):
|
|||
elif self.keyblob_storage == KEYBLOB_REPO:
|
||||
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):
|
||||
with open(target, 'w') as fd:
|
||||
fd.write('%s %s\n' % (KeyfileKey.FILE_ID, bin_to_hex(self.repository.id)))
|
||||
fd.write(self.keyblob)
|
||||
if not self.keyblob.endswith('\n'):
|
||||
fd.write('\n')
|
||||
fd.write(self.get_keyfile_data())
|
||||
|
||||
def export(self, 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 grouped(s):
|
||||
ret = ''
|
||||
|
|
Loading…
Reference in a new issue