diff --git a/README.md b/README.md
index 246436b..2ae5408 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# THMBot (For Educational Purpose Only)
+# THMBot
## TryHackMe bot for maintaining your streak
[](https://www.python.org/)
@@ -101,4 +101,4 @@ When THMBot runs, it logs actions and progress in tryhackmebot.log:
- To uninstall you can use the uninstall.bat script for Windows systems and the uninstall.sh as sudo for Linux systems.
Those scripts will revert the project back to the point of cloning, then you can delete the project's folder.
- the scheduled task or Cron Job will not work if you move the project's folder after setup.
If you need to change the location, please use uninstall.bat/sh and run setup.bat/sh after the location has changed.
-- Currently you have to join this [room](https://tryhackme.com/room/polkit) to be able to run THMBot (will be fixed soon).
\ No newline at end of file
+- Currently you have to join this [room](https://tryhackme.com/room/polkit) to be able to run THMBot (will be fixed soon).
diff --git a/browser.py b/browser.py
new file mode 100755
index 0000000..7ef7679
--- /dev/null
+++ b/browser.py
@@ -0,0 +1,49 @@
+import subprocess, platform, time, os
+from selenium import webdriver
+from selenium.webdriver.firefox.service import Service as ffService
+from selenium.webdriver.chrome.service import Service as chService
+from webdriver_manager.firefox import GeckoDriverManager as gdm
+from webdriver_manager.chrome import ChromeDriverManager as cdm
+
+os_family = platform.uname().system
+if os_family == "Linux":
+ s = ["sh",f"{os.getcwd()}/id_browser.sh"]
+elif os_family == "Windows":
+ s = ["powershell", f"{os.getcwd()}\id_browser.ps1"]
+
+def get_browser_bin(command):
+ with open("f", 'w') as file:
+ p = subprocess.Popen(command, stdout=file)
+ time.sleep(2)
+ file.close()
+ with open("f", 'r') as file:
+ e = file.readline().strip()
+ file.close()
+ try:
+ os.remove("f")
+ return e
+ except FileNotFoundError:
+ pass
+ except PermissionError:
+ pass
+
+
+browser_exec = get_browser_bin(s)
+print(browser_exec)
+
+def get_driver():
+ if "chrome" in browser_exec:
+ chrome_options = webdriver.ChromeOptions()
+ chrome_options.add_argument("--headless")
+ chrome_options.add_argument("--mute-audio")
+ driver = webdriver.Chrome(browser_exec, service=chService(cdm(path=os.getcwd()).install()), options=chrome_options)
+ elif "firefox" in browser_exec:
+ firefox_options = webdriver.FirefoxOptions()
+ firefox_options.add_argument('--headless')
+ firefox_options.set_preference("media.volume_scale", "0.0")
+ firefox_options.set_preference("dom.push.enabled", False)
+ driver = webdriver.Firefox(firefox_binary=browser_exec, service=ffService(gdm(path=os.getcwd()).install()), options=firefox_options)
+ else:
+ print("Could not create webdriver for browser.")
+ return driver
+
\ No newline at end of file
diff --git a/browser.sh b/browser.sh
new file mode 100755
index 0000000..10e27ac
--- /dev/null
+++ b/browser.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+## detects installed browser and returns location - only chrome & firefox supported
+got_chrome=$(which chrome 2>/dev/null)
+if [[ $? -ne 0 ]]; then
+ got_ffx=$(which firefox 2>/dev/null)
+ if [[ $? -ne 0 ]]; then
+ exit 1
+ else
+ echo $got_ffx
+ fi
+else
+ echo $got_chrome
+fi
+exit 1
+
diff --git a/id_browser.ps1 b/id_browser.ps1
new file mode 100755
index 0000000..b8d2be0
--- /dev/null
+++ b/id_browser.ps1
@@ -0,0 +1,5 @@
+# detects default nstalled browser and returns location - only chrome & firefox supported
+
+$browser = (Get-ItemProperty HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice -Name ProgId).ProgId
+$b_location = (Get-ItemProperty HKLM:\SOFTWARE\Classes\$browser\DefaultIcon).'(default)'.Split(",")[0]
+Write-Output $b_location
\ No newline at end of file
diff --git a/id_browser.sh b/id_browser.sh
new file mode 100755
index 0000000..5431650
--- /dev/null
+++ b/id_browser.sh
@@ -0,0 +1,14 @@
+# detects installed browser and returns location - only chrome & firefox supported
+got_chrome=$(which chrome)
+if [[ $? -ne 0 ]]; then
+ got_ffx=$(which firefox)
+ if [[ $? -ne 0 ]]; then
+ exit 1
+ else
+ echo $got_ffx
+ fi
+else
+ echo $got_chrome
+fi
+exit 1
+
\ No newline at end of file
diff --git a/login.py b/login.py
index d3bca3f..eb7069e 100644
--- a/login.py
+++ b/login.py
@@ -59,10 +59,15 @@ def recapcha(driver):
pass
driver.switch_to.default_content()
-
def login_form(driver):
- config = configparser.ConfigParser()
- config.read("account.conf")
+ if os.path.exists(r'account.conf'):
+ config = configparser.ConfigParser()
+ config.read("account.conf")
+ else:
+ with open("tryhackmebot.log", 'a') as f:
+ print("[+] Cannot load config. Please run setup.")
+ f.write("[+] Cannot load config. Please run setup\n")
+ exit(1)
try:
driver.get("https://tryhackme.com/login")
time.sleep(random.uniform(3,6))
diff --git a/main.py b/main.py
index 90f4884..a130b8a 100644
--- a/main.py
+++ b/main.py
@@ -2,21 +2,15 @@
import datetime
from login import *
from keepstreak import *
-from selenium import webdriver
-from selenium.webdriver.firefox.service import Service
-from webdriver_manager.firefox import GeckoDriverManager
+from browser import *
def main():
- firefox_options = webdriver.FirefoxOptions()
- firefox_options.headless = True
- firefox_options.set_preference("media.volume_scale", "0.0")
- firefox_options.set_preference("dom.push.enabled", False)
- driver = webdriver.Firefox(service=Service(GeckoDriverManager(path=os.getcwd()).install(), log_path=os.devnull), options=firefox_options)
+ driver = get_driver()
driver.implicitly_wait(10)
os.system("cls" if sys.platform == "win32" else "clear")
- with open("tryhackmebot.log", 'a') as f:
+ with open("tryhackmebot.log", 'w') as f:
print("[+] Starting...")
date = datetime.datetime.now().strftime("%d-%m-%Y, %H:%M:%S")
f.write(f"{date}\n")