aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/fjdisplay.py
diff options
context:
space:
mode:
authorLibravatar SYN-cook <SYN-cook@users.noreply.github.com>2017-02-28 19:57:25 +0100
committerLibravatar GitHub <noreply@github.com>2017-02-28 19:57:25 +0100
commit0890a915daf92ef2e37bb28be3d887e699ec1de2 (patch)
tree785bfa9d2eded39c3df72f00071d1abedb5cec90 /contrib/fjdisplay.py
parentremove redundancy (diff)
parentprofile merges (diff)
downloadfirejail-0890a915daf92ef2e37bb28be3d887e699ec1de2.tar.gz
firejail-0890a915daf92ef2e37bb28be3d887e699ec1de2.tar.zst
firejail-0890a915daf92ef2e37bb28be3d887e699ec1de2.zip
Merge pull request #2 from netblue30/master
merge upstream
Diffstat (limited to 'contrib/fjdisplay.py')
-rwxr-xr-xcontrib/fjdisplay.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/contrib/fjdisplay.py b/contrib/fjdisplay.py
new file mode 100755
index 000000000..0e0ef01ec
--- /dev/null
+++ b/contrib/fjdisplay.py
@@ -0,0 +1,43 @@
1#!/usr/bin/env python
2
3import re
4import sys
5import subprocess
6
7usage = """fjdisplay.py name-of-firejail
8returns the display in the form of ':NNN'
9"""
10
11def 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
24def 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
36if __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])) \ No newline at end of file