fixed detection + profile issues
This commit is contained in:
parent
575bdc4968
commit
f36bb0577a
20
main.py
20
main.py
@ -54,7 +54,7 @@ if getPublicIp() == "153.109.1.93":
|
|||||||
warningLogger.log("You are already in the HEI network. You cannot use the VPN")
|
warningLogger.log("You are already in the HEI network. You cannot use the VPN")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
IS_SNAP = b"snap" in subprocess.run(["which", "firefox"], stdout=subprocess.PIPE).stdout
|
IS_SNAP = os.path.isfile("/snap/bin/firefox") and os.access("/snap/bin/firefox", os.X_OK)
|
||||||
DRIVER_PATH = "/snap/bin/geckodriver" if IS_SNAP else "/usr/local/bin/geckodriver"
|
DRIVER_PATH = "/snap/bin/geckodriver" if IS_SNAP else "/usr/local/bin/geckodriver"
|
||||||
|
|
||||||
if IS_SNAP:
|
if IS_SNAP:
|
||||||
@ -97,21 +97,24 @@ def startBrowser(headless: bool = True) -> tuple[Firefox, FirefoxProfile]:
|
|||||||
if d.endswith(".default-release"):
|
if d.endswith(".default-release"):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
if profilePath == PERSISTENT_PROFILE_PATH:
|
||||||
warningLogger.log("Default firefox profile not found. Please create one manually")
|
warningLogger.log("Default firefox profile not found. Please create one manually")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
profile = FirefoxProfile(profilePath)
|
|
||||||
infoLogger.log(f"Using firefox profile in {profilePath}")
|
infoLogger.log(f"Using firefox profile in {profilePath}")
|
||||||
|
|
||||||
options = FirefoxOptions()
|
options = FirefoxOptions()
|
||||||
|
profile = FirefoxProfile(profilePath)
|
||||||
options.profile = profile
|
options.profile = profile
|
||||||
|
#options.set_preference("profile", profilePath)
|
||||||
|
#options.add_argument(f"-profile {profilePath}")
|
||||||
distinguishkey = "-distinguishkey" + str(random.randint(111111, 999999))
|
distinguishkey = "-distinguishkey" + str(random.randint(111111, 999999))
|
||||||
options.add_argument(distinguishkey)
|
options.add_argument(distinguishkey)
|
||||||
|
|
||||||
if headless:
|
if headless:
|
||||||
options.add_argument("--headless")
|
options.add_argument("--headless")
|
||||||
|
|
||||||
service = FirefoxService(executable_path=DRIVER_PATH)
|
service = FirefoxService(executable_path=DRIVER_PATH, log_output="/dev/null")
|
||||||
driver = Firefox(options, service)
|
driver = Firefox(options, service)
|
||||||
|
|
||||||
return driver, distinguishkey
|
return driver, distinguishkey
|
||||||
@ -139,7 +142,15 @@ def closeBrowser(driver: Firefox, distinguishkey: str) -> None:
|
|||||||
shutil.rmtree(PERSISTENT_PROFILE_PATH)
|
shutil.rmtree(PERSISTENT_PROFILE_PATH)
|
||||||
|
|
||||||
# Copy profile
|
# Copy profile
|
||||||
subprocess.run(["sudo", "cp", "-r", realProfilePath, PERSISTENT_PROFILE_PATH])
|
r = subprocess.run(["sudo", "cp", "-r", realProfilePath, PERSISTENT_PROFILE_PATH])
|
||||||
|
|
||||||
|
if r.returncode:
|
||||||
|
errorLogger.log("Could not copy temporary profile to persistent directory")
|
||||||
|
errorLogger.log(f"Tried: sudo cp -r {realProfilePath} {PERSISTENT_PROFILE_PATH}")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
# Remove lock
|
||||||
|
subprocess.run(["sudo", "rm", os.path.join(PERSISTENT_PROFILE_PATH, "lock")])
|
||||||
|
|
||||||
# Grant user access to directory
|
# Grant user access to directory
|
||||||
subprocess.run(["sudo", "chown", "-R", f"{os.getuid()}:{os.getgid()}", PERSISTENT_PROFILE_PATH])
|
subprocess.run(["sudo", "chown", "-R", f"{os.getuid()}:{os.getgid()}", PERSISTENT_PROFILE_PATH])
|
||||||
@ -221,6 +232,7 @@ if re.match(r"[a-f0-9]{32}", DSID):
|
|||||||
infoLogger.log("VPN is up and running")
|
infoLogger.log("VPN is up and running")
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
print()
|
||||||
proc.send_signal(signal.SIGINT)
|
proc.send_signal(signal.SIGINT)
|
||||||
proc.wait()
|
proc.wait()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user