-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcbedit
executable file
·67 lines (52 loc) · 2.29 KB
/
cbedit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
import tempfile
import subprocess
import os
import getpass
import argparse
import sys
import lib.config as config
import lib.crypto as crypto
from lib.generate import generate_all, backup
import lib.log as log
def edit(f, editor, backup_path, backup_files):
EDITOR = os.environ.get('EDITOR', editor)
mtime_begin = os.stat(file_name).st_mtime
subprocess.call([EDITOR, file_name])
mtime_end = os.stat(file_name).st_mtime
if mtime_begin == mtime_end:
log.p("No update to database")
sys.exit(0)
try:
backup(backup_path, backup_files)
except:
ans = log.yn("Couldn't perform a backup, continue?")
if not ans in ['Y', 'y']:
sys.exit(0)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Edit cryptobox database')
parser.add_argument('-v', '--version', action='version', version='Cryptobox ' + config.version)
parser.add_argument('-V', '--verbose', action='store_true', help='enable verbose mode')
parser.add_argument('-e', '--edit-only', action='store_true', help='don\'t update HTML and bookmarklets')
parser.add_argument('-u', '--update-only', action='store_true', help='just update HTML and bookmarklets')
parser.add_argument('-c', '--config', action='store', help='use specified config')
defines = config.read(parser.parse_args())
args = vars(parser.parse_args())
password = getpass.getpass()
db_conf = crypto.read_db_conf(defines['path.db_conf'], config.format_version)
plaintext = crypto.dec_db(db_conf, password, defines['path.db_cipher'], defines['path.db_hmac'])
if 'update_only' in args and args['update_only'] == True:
generate_all(db_conf, password, defines)
sys.exit(0)
try:
with tempfile.NamedTemporaryFile(suffix='.ini', delete=False, prefix='cryptobox') as f:
file_name = f.name
f.write(plaintext.encode('utf-8'))
f.flush()
edit(f, defines['ui.editor'], defines['backup.path'], defines['backup.files'])
crypto.enc_db(db_conf, password, file_name, defines['path.db_cipher'], defines['path.db_hmac'])
finally:
os.remove(file_name)
if 'edit_only' in args and args['edit_only'] == True:
sys.exit(0)
generate_all(db_conf, password, defines)