forked from markhedleyjones/dmenu-extended-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_sudo.py
More file actions
executable file
·66 lines (56 loc) · 2.71 KB
/
plugin_sudo.py
File metadata and controls
executable file
·66 lines (56 loc) · 2.71 KB
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
#!/usr/bin/python
import dmenu_extended
import sys
if __name__ == "__main__":
d = dmenu_extended.dmenu()
d.load_preferences()
# Find a way to hide the users password by setting the forground text colour
# to match the background text colour (so it's not readable)
if '-nb' in d.prefs['menu_arguments']:
index_background = d.prefs['menu_arguments'].index('-nb') + 1
if '-nf' in d.prefs['menu_arguments']:
index_foreground = d.prefs['menu_arguments'].index('-nf') + 1
d.prefs['menu_arguments'][index_foreground] = d.prefs['menu_arguments'][index_background]
else:
d.prefs['menu_arguments'] += ['-nf', d.prefs['menu_arguments'][index_background]]
else:
d.prefs['menu_arguments'] += ['-nf', '#000000']
d.prefs['menu_arguments'] += ['-nb', '#000000']
with open(dmenu_extended.path_plugins+'/plugin_sudo_counter.txt', 'r') as f:
message = f.readline()
pword = d.menu('', prompt=message)
if pword == '':
sys.exit()
else:
with open(dmenu_extended.path_plugins+'/plugin_sudo_counter.txt', 'w') as f:
f.write('Password incorrect, try again:')
print(pword+"\n")
class extension(dmenu_extended.dmenu):
# Set the name to appear in the menu
title = 'Sudo'
# Determines whether to attach the submenu indicator
is_submenu = True
# Required function, runs when the user fires the menu item
def run(self, inputText):
self.execute("chmod +x " + dmenu_extended.path_plugins+'/plugin_sudo.py')
# Accomodate for the change of name file_cacheScanned -> file_cache
try:
cache = self.cache_open(dmenu_extended.file_cache).split('\n')
except AttributeError:
cache = self.cache_open(dmenu_extended.file_cacheScanned).split('\n')
item = self.menu(cache)
if item[:len(self.prefs['indicator_alias'])] == self.prefs['indicator_alias']:
try:
item = self.retrieve_aliased_command(item)
except AttributeError:
self.menu("Please update dmenu-extended to run aliased commands with sudo")
sys.exit()
with open(dmenu_extended.path_plugins+'/plugin_sudo_counter.txt', 'w') as f:
f.write('Sudo password:')
try:
if self.preCommand is False:
self.preCommand = 'SUDO_ASKPASS="'+dmenu_extended.path_plugins+'/plugin_sudo.py" sudo -A '
dmenu_extended.handle_command(self, item)
except AttributeError:
print("NOTICE: Please update dmenu-extended to run non-binary items with sudo")
self.execute('SUDO_ASKPASS="'+dmenu_extended.path_plugins+'/plugin_sudo.py" sudo -A ' + item)