Skip to content

Commit

Permalink
security and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
noisecode3 committed Aug 15, 2024
1 parent e40b5df commit 36a19f1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
cd "$(dirname $0)"
cd "$(dirname "$0")"
rm -fr build
mkdir build
cd build
Expand Down
2 changes: 1 addition & 1 deletion clean_nvim_lsp.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
cd "$(dirname $0)"
cd "$(dirname "$0")"
# clean up command
rm -fr CMakeCache.txt CMakeFiles Makefile cmake_install.cmake \
compile_commands.json TombRaiderLinuxLauncher \
Expand Down
2 changes: 1 addition & 1 deletion setup_nvim_lsp.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
cd "$(dirname $0)"
cd "$(dirname "$0")"
# don't forget that you need to build it one time
# and look at .neovim how to use debuger
mkdir -p .gdb/qt5prettyprinters/
Expand Down
37 changes: 30 additions & 7 deletions utils/getData.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,43 @@
import logging
from bs4 import BeautifulSoup
from tqdm import tqdm
from urllib.parse import urlparse

# Set up logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s:%(message)s')
logging.getLogger("requests").setLevel(logging.DEBUG)

def validate_url(url):
# Kontrollera att URL:en har rätt format
parsed_url = urlparse(url)

# Kontrollera att URL:en har ett giltigt schema och nätverksplats (domän)
if not all([parsed_url.scheme, parsed_url.netloc]):
logging.error("Invalid URL format.")
sys.exit(1)

# Kontrollera att protokollet är https
if parsed_url.scheme != "https":
logging.error("Only HTTPS URLs are allowed.")
sys.exit(1)

# Kontrollera att domänen är trle.net eller subdomäner av trle.net
if not parsed_url.netloc.endswith("trle.net"):
logging.error("URL must belong to the domain 'trle.net'.")
sys.exit(1)

# Om alla kontroller passerar, returnera True (eller inget om du bara vill validera)
return True

def calculate_md5(url, cert):
try:
# Stream the response to handle large files
response = requests.get(url, verify=cert, stream=True, timeout=10)
response.raise_for_status()

# Get the total length of the file for the progress bar
total_length = int(response.headers.get('content-length', 0))

# Initialize the MD5 hash object
md5_hash = hashlib.md5()

Expand All @@ -34,19 +57,22 @@ def calculate_md5(url, cert):
if chunk: # filter out keep-alive new chunks
md5_hash.update(chunk)
progress_bar.update(len(chunk))

# Return the hex digest of the MD5 hash
return md5_hash.hexdigest()
except requests.exceptions.RequestException as e:
logging.error(f"Failed to download {url}: {e}")
return None

url = None

if __name__ == "__main__":
if len(sys.argv) != 2:
logging.error("Usage: python3 getData.py URL")
sys.exit(1)
else:
url = sys.argv[1]
validate_url(url)

lock_file = '/tmp/TRLE.lock'
try:
Expand Down Expand Up @@ -171,9 +197,6 @@ def calculate_md5(url, cert):
image_tag = soup.find('img', class_='border')
screen = 'https://www.trle.net' + image_tag['src']

def get_var(var_name):
return globals().get(var_name, "")

data = {
"title": title,
"author": author,
Expand All @@ -188,7 +211,7 @@ def get_var(var_name):
"zipFileName": zipFileName,
"zipFileMd5": zipFileMd5,
"body": body,
"walkthrough": get_var("walkthrough"),
"walkthrough": walkthrough,
"download_url": download_url,
}
if body:
Expand Down
3 changes: 2 additions & 1 deletion utils/makeDatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class INT NOT NULL,
# Add Game File data
for i in range(1, 6):
file = f'fileList-TR{i}.json'

# Load data from JSON file
with open(file, 'r') as json_file:
file_info = json.load(json_file)
Expand Down Expand Up @@ -225,3 +225,4 @@ class INT NOT NULL,

conn.commit()
conn.close()

1 change: 1 addition & 0 deletions utils/updateDB_1.0.0.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ class INT NOT NULL,

# Usage
update_table_schema_and_data(arg_path)

0 comments on commit 36a19f1

Please sign in to comment.