Merge remote-tracking branch 'refs/remotes/origin/main'

This commit is contained in:
Dpeta 2022-11-17 08:42:33 +01:00
commit c77f585e3a
3 changed files with 52 additions and 1 deletions

View file

@ -593,6 +593,8 @@ class PesterProfile(object):
return (False, "Cannot start with uppercase letter")
if re.search("[^A-Za-z0-9]", handle) is not None:
return (False, "Only alphanumeric characters allowed")
if handle[0].isnumeric(): # IRC doesn't allow this
return (False, "Handles may not start with a number")
return (True,)

View file

@ -1,5 +1,6 @@
import os
import sys
import ctypes
import platform
try:
@ -39,6 +40,21 @@ def osVer():
return " ".join(platform.linux_distribution())
def isRoot():
"""Return True if running with elevated privileges."""
# Windows
try:
if isWin32():
return ctypes.windll.shell32.IsUserAnAdmin() == 1
except OSError as win_issue:
print(win_issue)
# Unix
if hasattr(os, "getuid"):
return not os.getuid() # 0 if root
# Just assume it's fine otherwise ig
return False
def validateDataDir():
"""Checks if data directory is present"""
# Define paths

View file

@ -1305,7 +1305,6 @@ class PesterWindow(MovingWindow):
| QtCore.Qt.WindowType.FramelessWindowHint
),
)
# For debugging
_CONSOLE_ENV.PAPP = self
# TODO: karxi: SO! At the end of this function it seems like that
@ -1371,6 +1370,10 @@ class PesterWindow(MovingWindow):
)
self.theme = self.userprofile.getTheme()
# Silly guy prevention pt. 2
# We really shouldn't run as root.
self.root_check()
# karxi: For the record, these are set via commandline arguments. By
# default, they aren't usable any other way - you can't set them via
# the config files.
@ -1701,6 +1704,36 @@ class PesterWindow(MovingWindow):
self.updatemenu = None
"""
def root_check(self):
"""Raise a warning message box if Pesterchum has admin/root privileges."""
if ostools.isRoot():
msgbox = QtWidgets.QMessageBox()
msg = (
"Running with elevated privileges, "
"this is potentially a security risk."
"\nThere is no valid reason to run Pesterchum as an administrator or as root."
"\n\nQuit?"
)
msgbox.setWindowTitle("Unnecessary permissions warning")
msgbox.setStyleSheet(
"QMessageBox{ %s }" % self.theme["main/defaultwindow/style"]
)
msgbox.setInformativeText(msg)
msgbox.setIcon(QtWidgets.QMessageBox.Icon.Warning)
msgbox.setStandardButtons(
QtWidgets.QMessageBox.StandardButton.Yes
| QtWidgets.QMessageBox.StandardButton.No
)
continue_anyway = msgbox.button(QtWidgets.QMessageBox.StandardButton.No)
continue_anyway.setText(
"I'm a silly little guy and want to continue anyway"
)
msgbox.setDefaultButton(QtWidgets.QMessageBox.StandardButton.Yes)
ret = msgbox.exec()
if ret == QtWidgets.QMessageBox.StandardButton.Yes:
self.app.quit() # Optional
sys.exit()
@QtCore.pyqtSlot()
def checkPing(self):
"""Check if server is alive on app level,