diff options
author | 2018-07-27 12:56:41 -0400 | |
---|---|---|
committer | 2018-07-27 12:56:41 -0400 | |
commit | 3cf75fe9a34c0bb579502b106649a1fc58d39f35 (patch) | |
tree | 3c696691a48205e6c73987f562bcc7a80aac69e4 /contrib/fjdisplay.py | |
parent | compile time marker for LTS code (diff) | |
download | firejail-3cf75fe9a34c0bb579502b106649a1fc58d39f35.tar.gz firejail-3cf75fe9a34c0bb579502b106649a1fc58d39f35.tar.zst firejail-3cf75fe9a34c0bb579502b106649a1fc58d39f35.zip |
phase 1
Diffstat (limited to 'contrib/fjdisplay.py')
-rwxr-xr-x | contrib/fjdisplay.py | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/contrib/fjdisplay.py b/contrib/fjdisplay.py deleted file mode 100755 index 3f409545f..000000000 --- a/contrib/fjdisplay.py +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | import re | ||
4 | import sys | ||
5 | import subprocess | ||
6 | |||
7 | usage = """fjdisplay.py name-of-firejail | ||
8 | returns the display in the form of ':NNN' | ||
9 | """ | ||
10 | |||
11 | def getfirejails(): | ||
12 | output = subprocess.check_output(['firemon','--x11']) | ||
13 | firejails = {} | ||
14 | name = '' | ||
15 | for line in output.split('\n'): | ||
16 | namematch = re.search('--name=(\w+\S*)',line) | ||
17 | if namematch: | ||
18 | name = namematch.group(1) | ||
19 | displaymatch = re.search('DISPLAY (:\d+)',line) | ||
20 | if displaymatch: | ||
21 | firejails[name] = displaymatch.group(1) | ||
22 | return firejails | ||
23 | |||
24 | def getdisplay(name): | ||
25 | firejails = getfirejails() | ||
26 | fjlist = '\n'.join(firejails.keys()) | ||
27 | namere = re.compile('^'+name+'.*', re.MULTILINE) | ||
28 | matchingjails = namere.findall(fjlist) | ||
29 | if len(matchingjails) == 1: | ||
30 | return firejails[matchingjails[0]] | ||
31 | if len(matchingjails) == 0: | ||
32 | raise NameError("firejail {} does not exist".format(name)) | ||
33 | else: | ||
34 | raise NameError("ambiguous firejail name") | ||
35 | |||
36 | if __name__ == '__main__': | ||
37 | if '-h' in sys.argv or '--help' in sys.argv or len(sys.argv) > 2: | ||
38 | print(usage) | ||
39 | exit() | ||
40 | if len(sys.argv) == 1: | ||
41 | print(getfirejails()) | ||
42 | if len(sys.argv) == 2: | ||
43 | print (getdisplay(sys.argv[1])) | ||