Skip to content

Commit

Permalink
Backup
Browse files Browse the repository at this point in the history
  • Loading branch information
EchterAlsFake committed Nov 24, 2023
1 parent eaea05b commit ce2646e
Showing 1 changed file with 258 additions and 20 deletions.
278 changes: 258 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
import sys
import qbittorrentapi
import getpass
import os

from configparser import ConfigParser
from datetime import datetime
from colorama import *
from hue_shift import return_color, reset

z = f"{Fore.LIGHTGREEN_EX}[+]"

Expand Down Expand Up @@ -78,6 +81,78 @@ def logger_debug(e):
print(f"{Fore.LIGHTWHITE_EX}{datetime.now()} {Fore.LIGHTBLUE_EX}DEBUG: {Fore.RESET}{e}")


def check_config_integrity():
sections = ["WebUi", "Blacklist", "Country"]
options_web_ui = ["username", "password", "host", "port"]
options_blacklist = ["blacklist"]
options_country = ["country"]

config_file = "config.ini"

if os.path.isfile(config_file):
config_object = ConfigParser()
config_object.read("config.ini")

try:
for idx, section in enumerate(sections):
if config_object.has_section(section) and idx == 0:
for option in options_web_ui:
if not config_object.has_option(section=section, option=option):
return False

if config_object.has_section(section) and idx == 1:
for option in options_blacklist:
if not config_object.has_option(section=section, option=option):
return False

if config_object.has_section(section) and idx == 2:
for option in options_country:
if not config_object.has_option(section=section, option=option):
return False

except Exception as e:
return [bool(False), str(e)]

else:
return True

else:
return False

def create_config_file():

data = """
[APP]
first_run=true
[WebUi]
username=
password=
host=
port=
[Blacklist]
blacklist=
[Country]
country=
"""

try:
with open("config.ini", "w") as config_file:
config_file.write(data)
return True

except PermissionError:
logger_error("Permission Error: Couldn't create the configuration file...")
return False

except Exception as e:
logger_error(f"Tried to create configuration file with error: {e}")
return False



class Legacy():
"""
This is the legacy version of the script (v1.0).
Expand Down Expand Up @@ -108,15 +183,20 @@ class V2():

def __init__(self):

self.conn_info = None
self.ban_by_country = False
self.country_codes = None
if self.authentication():
if not check_config_integrity():
if not create_config_file():
logger_error(f"Fatal error, when trying to use the configuration file!, please report that!")

self.menu()

self.get_peers()
else:
self.conn_info = None
self.ban_by_country = False
self.country_codes = None
self.conf = ConfigParser()
self.conf.read("config.ini")

if self.authentication():
while True:
self.menu()


def menu(self):
Expand All @@ -141,28 +221,186 @@ def menu(self):
self.menu()

def settings(self):
""
settings_options = input(f"""
1) Change WebUi Access configuration (username, password etc.)
2) Change Blacklist
3) Change ban by country
4) Back to man menu
--------------------------=>:""")

def configuration(self):
print(f"""
--------------------------------INFORMATION--------------------------------------------
if settings_options == "1":
self.settings_web_ui_configuration()

You will be prompted to configure your credentials for the WebUI, you've configured in the qBittorrent Client.
If you have enabled 'Bypass Authentication for localhost', just press enter when you get asked for Username and Password
elif settings_options == "2":
self.settings_blacklist()

Your WebUi will be probably at Localhost at Port 8080, so you can also just press enter if you left it on default.
elif settings_options == "3":
self.settings_ban_by_country()

elif settings_options == "4":
self.menu()

else:
print(f"Wrong O")


""")
def settings_web_ui_configuration(self):

username = input(f"Please enter your username [Enter to skip authentication]: ")
password = getpass.getpass("Please enter your password [None]: ")
host = self.conf["WebUi"]["host"]
port = self.conf["WebUi"]["port"]
username = self.conf["WebUi"]["username"]
password = self.conf["WebUi"]["password"]

password_length = len(password)
masked_password = '*' * password_length

options = input(f"""
1) Change Host {return_color()}[{host}]{reset()}
2) Change Port {return_color()}[{port}]{reset()}
3) Change Username {return_color()}[{username}]{reset()}
4) Change Password {return_color()}[{masked_password}]{reset()}
5) Change ALL
6) Go back
-------------------=>:""")

try:
if options == "1":
self.settings_host()

elif options == "2":
self.settings_port()

elif options == "3":
self.settings_username()

elif options == "4":
self.settings_password()

elif options == "5":
self.settings_host()
self.settings_port()
self.settings_username()
self.settings_password()

finally:
if not options == "6":
with open("config.ini", "w") as config_file:
self.conf.write(config_file)

def settings_host(self):
host_input = input(f"Please enter webUI host [localhost]: ")
port_input = input(f"Please enter webUI port [8080]: ")
host = host_input if host_input else "localhost"
self.conf.set("WebUi", "host", host)

def settings_port(self):
port_input = input(f"Please enter webUI port [8080]: ")
port = port_input if port_input else "8080"
self.conf.set("WebUi", "port", port)

def settings_username(self):
username = input(f"Please enter your username [Enter to skip authentication]: ")
self.conf.set("WebUi", "username", username)

def settings_password(self):
password = getpass.getpass("Please enter your password [None]: ")
self.conf.set("WebUi", "password", password)

def settings_blacklist(self):
blacklist = self.conf["Blacklist"]["blacklist"]
blacklist_list = blacklist.split(",")

while True:
print("Current Blacklist:")
for idx, item in enumerate(blacklist_list):
print(f"{idx}): {item}")

change = input("""
Enter one of the given numbers to remove the string from the Blacklist, or type a new word
to append to the blacklist. (Separate new words with a comma) Type 'exit' to abort the process!
-------------=>:""")

if change.lower() == 'exit':
break

try:
change_index = int(change)
if 0 <= change_index < len(blacklist_list):
blacklist_list.pop(change_index)
else:
print("Invalid index. Please enter a valid number or 'exit'.")
except ValueError:
# Assuming new words to add are separated by commas
new_words = change.split(',')
blacklist_list.extend(word.strip() for word in new_words if word.strip())

# Update the blacklist in the configuration
updated_blacklist = ','.join(blacklist_list)
self.conf.set("Blacklist", "blacklist", updated_blacklist)

with open("config.ini", "w") as config_file:
self.conf.write(config_file)

def settings_ban_by_country(self):

options = input(f"""
1) Update Country blacklist
2) Disable Country banning
3) Enable Country banning
4) Back
------------------------------=>:
""")

if options == "1":
countrys = input(f"Please enter country codes separated with , (e.g zn,de,ru) -----=>;")
country_list = countrys.split(",")
updated_country_list = ",".join(country_list)
self.conf.set("Country", "country", updated_country_list)
with open("config.ini", "w") as config_file:
self.conf.write(config_file)

elif options == "2":
self.conf.set("Country", "enabled", "false")

elif options == "3":
self.conf.set("Country", "enabled", "true")

elif options == "4":
self.settings()





def configuration(self):

if self.conf["APP"]["first_run"] == "true":
print(f"""
--------------------------------INFORMATION--------------------------------------------
You will be prompted to configure your credentials for the WebUI, you've configured in the qBittorrent Client.
If you have enabled 'Bypass Authentication for localhost', just press enter when you get asked for Username and Password
Your WebUi will be probably at Localhost at Port 8080, so you can also just press enter if you left it on default.
""")

username = input(f"Please enter your username [Enter to skip authentication]: ")
password = getpass.getpass("Please enter your password [None]: ")
host_input = input(f"Please enter webUI host [localhost]: ")
port_input = input(f"Please enter webUI port [8080]: ")
host = host_input if host_input else "localhost"
port = port_input if port_input else "8080"

else:

host = self.conf["WebUi"]["host"]
port = self.conf["WebUi"]["port"]
username = self.conf["WebUi"]["username"]
password = self.conf["WebUi"]["password"]

self.conn_info = dict(
host=host,
Expand Down Expand Up @@ -217,7 +455,7 @@ def start(self):
time.sleep(5)


'''version = input(f"""
version = input(f"""
{Fore.LIGHTWHITE_EX}Which Version do you want to use?
{Fore.LIGHTMAGENTA_EX}1) Legacy V1.0
Expand All @@ -238,7 +476,7 @@ def start(self):
{Fore.LIGHTRED_EX}- maybe less lightweight
---------------[2]--->:
""")'''
""")

Legacy()

Expand Down

0 comments on commit ce2646e

Please sign in to comment.