Skip to content

Commit

Permalink
Added flag to bypass admin warning
Browse files Browse the repository at this point in the history
  • Loading branch information
macarooni-man committed Nov 10, 2024
1 parent a7ab608 commit 3b65bfb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions source/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
back_clicked = False
session_splash = ''
boot_launches = []
bypass_admin_warning = False


# Global debug mode and app_compiled, set debug to false before release
Expand Down
9 changes: 7 additions & 2 deletions source/headless.py
Original file line number Diff line number Diff line change
Expand Up @@ -2540,8 +2540,13 @@ def open_console(server_name: str, force_start=False):

def run_application():
# Give an error if elevated
if constants.is_admin() and not constants.is_docker:
print(f"\n> Error: Running auto-mcs as {'administrator' if constants.os_name == 'windows' else 'root'} can expose your system to security vulnerabilities\n\nPlease restart with standard user privileges to continue")
# Give an error if elevated
if (constants.is_admin() and not constants.is_docker) and constants.bypass_admin_warning:
print(f"\n\033[31m> Privilege Warning: Running auto-mcs as {'administrator' if constants.os_name == 'windows' else 'root'} can expose your system to security vulnerabilities\n\nProceed with caution, this configuration is unsupported\033[0m\n\n< press 'ENTER' to continue >")
null = input()

elif (constants.is_admin() and not constants.is_docker) and not constants.bypass_admin_warning:
print(f"\n\033[31m> Privilege Error: Running auto-mcs as {'administrator' if constants.os_name == 'windows' else 'root'} can expose your system to security vulnerabilities\n\nPlease restart with standard user privileges to continue\033[0m")
return False


Expand Down
21 changes: 18 additions & 3 deletions source/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3692,6 +3692,8 @@ def fit_to_window(label_widget, path_string, *args):
version = AlignLabel(color=(0.6, 0.6, 1, 0.2), font_name=os.path.join(constants.gui_assets, 'fonts', f'{constants.fonts["italic"]}.ttf'), font_size=sp(23), markup=True, size_hint=(1.0, 1.0), halign="right", valign="bottom")
version.__translate__ = False
version.text = f"auto-mcs[size={round(sp(18))}] [/size]v{version_text}"
if constants.is_admin() and constants.bypass_admin_warning:
version.text = f"[color=#FF8793]{version.text}[/color]"

text_layout.bind(pos=functools.partial(fit_to_window, label, path_list))
text_layout.bind(size=functools.partial(fit_to_window, label, path_list))
Expand Down Expand Up @@ -9591,7 +9593,19 @@ def __init__(self, **kwargs):
# Prompt update/show banner when starting up
def on_enter(self, *args):
global shown_disk_error
if constants.is_admin():

if constants.is_admin() and constants.bypass_admin_warning:
def admin_error(*_):
self.show_popup(
"warning",
"Privilege Warning",
f"Running auto-mcs as ${'administrator' if constants.os_name == 'windows' else 'root'}$ can expose your system to security vulnerabilities.\n\nProceed with caution, this configuration is unsupported",
None
)
Clock.schedule_once(admin_error, 0.5)
return

elif constants.is_admin():
def admin_error(*_):
self.show_popup(
"warning",
Expand Down Expand Up @@ -9677,7 +9691,8 @@ def generate_menu(self, **kwargs):


version_text = f"{constants.app_version}{' (dev)' if constants.dev_version else ''}"
version = Label(pos=(330, 200), pos_hint={"center_y": 0.77}, color=(0.6, 0.6, 1, 0.5), font_name=os.path.join(constants.gui_assets, 'fonts', f'{constants.fonts["italic"]}.ttf'), font_size=sp(23))
color = "#FF8793" if constants.is_admin() else (0.6, 0.6, 1, 0.5)
version = Label(pos=(330, 200), pos_hint={"center_y": 0.77}, color=color, font_name=os.path.join(constants.gui_assets, 'fonts', f'{constants.fonts["italic"]}.ttf'), font_size=sp(23))
version.__translate__ = False
version.text = f"v{version_text}{(7 - len(version_text)) * ' '}"
splash.add_widget(version)
Expand Down Expand Up @@ -26334,7 +26349,7 @@ def raise_window(*a):

# Process --launch flag
if constants.boot_launches:
if not constants.is_admin():
if not constants.is_admin() or constants.bypass_admin_warning:

def launch_server(*_):
for server in constants.boot_launches:
Expand Down
2 changes: 2 additions & 0 deletions source/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
parser.add_argument('-d', '--debug', default='', help='execute auto-mcs with verbose console logging', action='store_true')
parser.add_argument('-l', '--launch', type=str, default='', help='specify a server name (or list of server names) to launch automatically', metavar='"Server 1, Server 2"')
parser.add_argument('--reset', default='', help='reset global configuration file before launch', action='store_true')
parser.add_argument('--bypass-admin-warning', default='', help='allow launch as admin/root (not recommended)', action='store_true')

# For now, Windows doesn't support headless when compiled due to the GUI entrypoint from Pyinstaller
if constants.os_name != 'windows' or not constants.app_compiled:
Expand All @@ -81,6 +82,7 @@
# Assign parsed arguments to global variables
constants.debug = args.debug
reset_config = args.reset
constants.bypass_admin_warning = args.bypass_admin_warning
if constants.os_name != 'windows' or not constants.app_compiled:
constants.headless = args.headless

Expand Down

0 comments on commit 3b65bfb

Please sign in to comment.