mirror of
https://github.com/towalink/wgfrontend.git
synced 2025-04-19 08:55:11 +00:00
Add option to install suduers config for default on_change_command
This commit is contained in:
parent
038477b231
commit
6c478edf53
2
setup.py
2
setup.py
@ -7,7 +7,7 @@ with open('README.md', 'r') as f:
|
|||||||
|
|
||||||
setup_kwargs = {
|
setup_kwargs = {
|
||||||
'name': 'wgfrontend',
|
'name': 'wgfrontend',
|
||||||
'version': '0.5.0',
|
'version': '0.6.0',
|
||||||
'author': 'The Towalink Project',
|
'author': 'The Towalink Project',
|
||||||
'author_email': 'pypi.wgfrontend@towalink.net',
|
'author_email': 'pypi.wgfrontend@towalink.net',
|
||||||
'description': 'web-based user interface for configuring WireGuard for roadwarriors',
|
'description': 'web-based user interface for configuring WireGuard for roadwarriors',
|
||||||
|
@ -9,6 +9,7 @@ import os
|
|||||||
import pwd
|
import pwd
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import textwrap
|
||||||
import wgconfig
|
import wgconfig
|
||||||
import wgconfig.wgexec as wgexec
|
import wgconfig.wgexec as wgexec
|
||||||
|
|
||||||
@ -119,7 +120,8 @@ class QueryUser():
|
|||||||
"""Queries the user for a yes or no answer"""
|
"""Queries the user for a yes or no answer"""
|
||||||
while True:
|
while True:
|
||||||
answer = input(f' {display_text} ')
|
answer = input(f' {display_text} ')
|
||||||
if not answer.strip():
|
answer = answer.strip()
|
||||||
|
if not answer:
|
||||||
answer = default
|
answer = default
|
||||||
answer = answer.lower()
|
answer = answer.lower()
|
||||||
if answer in ['1', 'y', 'yes']:
|
if answer in ['1', 'y', 'yes']:
|
||||||
@ -130,7 +132,7 @@ class QueryUser():
|
|||||||
|
|
||||||
def query_expert(self):
|
def query_expert(self):
|
||||||
"""Queries the user on whether he wants expert configuration"""
|
"""Queries the user on whether he wants expert configuration"""
|
||||||
expert = self.input_yes_no('Do you want to use expert configuration? [No]:', default='No')
|
expert = self.input_yes_no('Do you want to use expert configuration? [No]:', default='No')
|
||||||
return expert
|
return expert
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -340,6 +342,16 @@ def setup_environment():
|
|||||||
wc.write_file()
|
wc.write_file()
|
||||||
print(' Config file written. Ok.')
|
print(' Config file written. Ok.')
|
||||||
eh = exechelper.ExecHelper()
|
eh = exechelper.ExecHelper()
|
||||||
|
if qu.input_yes_no(f'Would you like to allow the system user of the web frontend to reload WireGuard on config on changes (using sudo)? [Yes]:'):
|
||||||
|
sudoers_content = textwrap.dedent(f'''\
|
||||||
|
{cfg.user} ALL=(root) NOPASSWD: /etc/init.d/wgfrontend_interface start, /etc/init.d/wgfrontend_interface stop, /etc/init.d/wgfrontend_interface restart
|
||||||
|
{cfg.user} ALL=(root) NOPASSWD: /usr/bin/wg-quick down {cfg.wg_configfile}, /usr/bin/wg-quick up {cfg.wg_configfile}
|
||||||
|
''')
|
||||||
|
if os.path.isdir('/etc/sudoers.d'):
|
||||||
|
with open('/etc/sudoers.d/wgfrontend', 'w') as sudoers_file:
|
||||||
|
sudoers_file.write(sudoers_content)
|
||||||
|
else:
|
||||||
|
print(' Sorry, "/etc/sudoers.d" does not exist so that sudo could not be configured. Maybe "sudo" is not installed.')
|
||||||
if qu.input_yes_no(f'Would you like to activate the WireGuard interface "{cfg.wg_interface}" now? [Yes]:'):
|
if qu.input_yes_no(f'Would you like to activate the WireGuard interface "{cfg.wg_interface}" now? [Yes]:'):
|
||||||
eh.run_wgquick('up', cfg.wg_interface)
|
eh.run_wgquick('up', cfg.wg_interface)
|
||||||
if qu.input_yes_no(f'Would you like to activate the WireGuard interface "{cfg.wg_interface}" on boot? [Yes]:'):
|
if qu.input_yes_no(f'Would you like to activate the WireGuard interface "{cfg.wg_interface}" on boot? [Yes]:'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user