-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvault_interface.py
58 lines (40 loc) · 1.29 KB
/
vault_interface.py
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
import re
import collections
vault_entry = collections.namedtuple("vault_entry", "name fstype src dest mounted")
def get_status():
fd = open("/proc/mounts", "r")
mounts = fd.read()
fd.close()
fd = open("/etc/fstab", "r")
fstab = fd.read().split('\n')
fd.close()
vault_dict = dict()
for line in fstab:
device = re.findall(r"(\S+)\s+(\S+)\s+(\S+)\s+.*?", line)
if not device:
continue
fs_src = device[0][0]
fs_dest = device[0][1]
fs_type = device[0][2]
name = fs_dest.split('/')[-1]
if re.findall(r"^encfs", fs_src) and fs_type == 'fuse':
fs_src = fs_src.split('#')[-1]
fs_type = 'encfs'
if re.findall(fs_dest, mounts):
fs_mount = True
else:
fs_mount = False
if fs_type in ('encfs','ecryptfs'):
entry = vault_entry(name, fs_type, fs_src, fs_dest, fs_mount)
vault_dict[entry.name] = entry
return vault_dict
def get_text():
vault_db = get_status()
if len(vault_db) == 0:
return []
ret = []
for name, rdev in vault_db.items():
ret.append("%s IS %s" % (rdev.name.upper(), 'OPEN' if rdev.mounted else 'LOCKED'))
return ret
if __name__ == "__main__":
print(get_text())