mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2026-01-22 02:47:39 +01:00
Compare commits
5 Commits
1c48b033d3
...
d6f8e6ac4d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6f8e6ac4d | ||
|
|
c2d3a0f37a | ||
|
|
8c0e65c194 | ||
|
|
c13725cd84 | ||
|
|
4785517b6c |
26
client.py
26
client.py
@@ -71,7 +71,7 @@ def dropdown_changed(dropdown_var, user_entry, password_entry, server_path_entry
|
|||||||
user_entry.configure(fg_color="#CCCCCC")
|
user_entry.configure(fg_color="#CCCCCC")
|
||||||
server_path_entry.delete(0, customtkinter.END)
|
server_path_entry.delete(0, customtkinter.END)
|
||||||
server_path_entry.insert(0, "C:/path/to/game/mount/")
|
server_path_entry.insert(0, "C:/path/to/game/mount/")
|
||||||
else:
|
elif dropdown_var == "FTP/FTPS":
|
||||||
user_entry.configure(state=customtkinter.NORMAL)
|
user_entry.configure(state=customtkinter.NORMAL)
|
||||||
password_entry.configure(state=customtkinter.NORMAL)
|
password_entry.configure(state=customtkinter.NORMAL)
|
||||||
if non_disabled_entry_color: # else first run and nothing to do
|
if non_disabled_entry_color: # else first run and nothing to do
|
||||||
@@ -79,6 +79,14 @@ def dropdown_changed(dropdown_var, user_entry, password_entry, server_path_entry
|
|||||||
user_entry.configure(fg_color=non_disabled_entry_color)
|
user_entry.configure(fg_color=non_disabled_entry_color)
|
||||||
server_path_entry.delete(0, customtkinter.END)
|
server_path_entry.delete(0, customtkinter.END)
|
||||||
server_path_entry.insert(0, "ftp://server:port/path or ftps://server:port/path")
|
server_path_entry.insert(0, "ftp://server:port/path or ftps://server:port/path")
|
||||||
|
else:
|
||||||
|
user_entry.configure(state=customtkinter.NORMAL)
|
||||||
|
password_entry.configure(state=customtkinter.NORMAL)
|
||||||
|
if non_disabled_entry_color: # else first run and nothing to do
|
||||||
|
password_entry.configure(fg_color=non_disabled_entry_color)
|
||||||
|
user_entry.configure(fg_color=non_disabled_entry_color)
|
||||||
|
server_path_entry.delete(0, customtkinter.END)
|
||||||
|
|
||||||
|
|
||||||
install_dir_entry.delete(0, customtkinter.END)
|
install_dir_entry.delete(0, customtkinter.END)
|
||||||
install_dir_entry.insert(0, "./install-dir")
|
install_dir_entry.insert(0, "./install-dir")
|
||||||
@@ -117,10 +125,10 @@ def get_config_inputs():
|
|||||||
install_dir_entry.grid(row=4, column=1, padx=10, pady=5, sticky="ew", columnspan=2)
|
install_dir_entry.grid(row=4, column=1, padx=10, pady=5, sticky="ew", columnspan=2)
|
||||||
|
|
||||||
# Dropdown
|
# Dropdown
|
||||||
dropdown_var = customtkinter.StringVar(value="Local Filesystem")
|
dropdown_var = customtkinter.StringVar(value="HTTP/HTTPS")
|
||||||
dropdown_label = customtkinter.CTkLabel(input_window, text="Select option:")
|
dropdown_label = customtkinter.CTkLabel(input_window, text="Select option:")
|
||||||
dropdown_label.grid(row=0, column=0, sticky="w", padx=10, pady=5)
|
dropdown_label.grid(row=0, column=0, sticky="w", padx=10, pady=5)
|
||||||
dropdown = customtkinter.CTkOptionMenu(input_window, variable=dropdown_var, values=["FTP/FTPS", "Local Filesystem"],
|
dropdown = customtkinter.CTkOptionMenu(input_window, variable=dropdown_var, values=["HTTP/HTTPS", "FTP/FTPS", "Local Filesystem"],
|
||||||
command=lambda dropdown_var=dropdown_var, user_entry=user_entry, password_entry=password_entry,
|
command=lambda dropdown_var=dropdown_var, user_entry=user_entry, password_entry=password_entry,
|
||||||
server_path_entry=server_path_entry, install_dir_entry=install_dir_entry:
|
server_path_entry=server_path_entry, install_dir_entry=install_dir_entry:
|
||||||
dropdown_changed(dropdown_var, user_entry, password_entry, server_path_entry, install_dir_entry))
|
dropdown_changed(dropdown_var, user_entry, password_entry, server_path_entry, install_dir_entry))
|
||||||
@@ -311,7 +319,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
if not os.path.isfile(CONFIG_FILE):
|
if not os.path.isfile(CONFIG_FILE):
|
||||||
get_config_inputs()
|
get_config_inputs()
|
||||||
print("wtf")
|
|
||||||
|
|
||||||
# load config #
|
# load config #
|
||||||
with open(CONFIG_FILE) as f:
|
with open(CONFIG_FILE) as f:
|
||||||
@@ -332,6 +339,13 @@ if __name__ == "__main__":
|
|||||||
if backend_type == "FTP/FTPS":
|
if backend_type == "FTP/FTPS":
|
||||||
remote_root_dir = "/" + config_loaded["Server/Path:"].split("://")[1].split("/", 1)[1]
|
remote_root_dir = "/" + config_loaded["Server/Path:"].split("://")[1].split("/", 1)[1]
|
||||||
server = config_loaded["Server/Path:"][:-len(remote_root_dir)]
|
server = config_loaded["Server/Path:"][:-len(remote_root_dir)]
|
||||||
|
elif backend_type == "HTTP/HTTPS":
|
||||||
|
server = config_loaded["Server/Path:"]
|
||||||
|
remote_root_dir = None
|
||||||
|
if not server.startswith("http://") or "https://":
|
||||||
|
server = "http://" + server
|
||||||
|
if not ":" in server.split("://")[1]:
|
||||||
|
server = server + ":5000"
|
||||||
elif backend_type == "Local Filesystem":
|
elif backend_type == "Local Filesystem":
|
||||||
remote_root_dir = config_loaded["Server/Path:"]
|
remote_root_dir = config_loaded["Server/Path:"]
|
||||||
server = None
|
server = None
|
||||||
@@ -342,8 +356,8 @@ if __name__ == "__main__":
|
|||||||
print(user, password, install_dir, remote_root_dir, server, config_loaded["Server/Path:"])
|
print(user, password, install_dir, remote_root_dir, server, config_loaded["Server/Path:"])
|
||||||
|
|
||||||
# add db backend #
|
# add db backend #
|
||||||
if True:
|
if backend_type == "HTTP/HTTPS":
|
||||||
db = data_backend.HTTP(None, None, install_dir, remote_root_dir="./", server="http://localhost:5000", progress_bar_wrapper=pgw, tkinter_root=app)
|
db = data_backend.HTTP(None, None, install_dir, remote_root_dir="./", server=server, progress_bar_wrapper=pgw, tkinter_root=app)
|
||||||
elif backend_type == "FTP/FTPS":
|
elif backend_type == "FTP/FTPS":
|
||||||
db = data_backend.FTP(user, password, install_dir, server=server,
|
db = data_backend.FTP(user, password, install_dir, server=server,
|
||||||
remote_root_dir=remote_root_dir, progress_bar_wrapper=pgw, tkinter_root=app)
|
remote_root_dir=remote_root_dir, progress_bar_wrapper=pgw, tkinter_root=app)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class HTTP(DataBackend):
|
|||||||
#print(self.server + HTTP.REMOTE_PATH)
|
#print(self.server + HTTP.REMOTE_PATH)
|
||||||
return self.server + HTTP.REMOTE_PATH
|
return self.server + HTTP.REMOTE_PATH
|
||||||
|
|
||||||
def get(self, path, cache_dir="", return_content=False):
|
def get(self, path, cache_dir="", return_content=False, wait=False):
|
||||||
|
|
||||||
print("Getting", path, "cache dir", cache_dir, "return content:", return_content)
|
print("Getting", path, "cache dir", cache_dir, "return content:", return_content)
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ class HTTP(DataBackend):
|
|||||||
|
|
||||||
if not os.path.isfile(local_file) or os.stat(local_file).st_size == 0:
|
if not os.path.isfile(local_file) or os.stat(local_file).st_size == 0:
|
||||||
|
|
||||||
if return_content:
|
if return_content or wait:
|
||||||
|
|
||||||
# the content is needed for the UI now and not cached, it's needs to be downloaded synchroniously #
|
# the content is needed for the UI now and not cached, it's needs to be downloaded synchroniously #
|
||||||
# as there cannot be a meaningful UI-draw without it. #
|
# as there cannot be a meaningful UI-draw without it. #
|
||||||
@@ -145,7 +145,11 @@ class HTTP(DataBackend):
|
|||||||
|
|
||||||
# return the content #
|
# return the content #
|
||||||
print("Content for", fullpath, ":", r.text)
|
print("Content for", fullpath, ":", r.text)
|
||||||
|
|
||||||
|
if return_content:
|
||||||
return r.text
|
return r.text
|
||||||
|
else:
|
||||||
|
return local_file
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Async Requested for:", local_file)
|
print("Async Requested for:", local_file)
|
||||||
@@ -173,6 +177,7 @@ class HTTP(DataBackend):
|
|||||||
else:
|
else:
|
||||||
|
|
||||||
r = requests.get(self._get_url(), params={ "path" : path })
|
r = requests.get(self._get_url(), params={ "path" : path })
|
||||||
|
r.raise_for_status()
|
||||||
#print(r, r.status_code, r.content)
|
#print(r, r.status_code, r.content)
|
||||||
paths = r.json()["contents"]
|
paths = r.json()["contents"]
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
# windows imports #
|
# windows imports #
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
@@ -52,6 +53,15 @@ def resolve_lnk(lnk_file_path):
|
|||||||
def run_exe(path, synchronous=False):
|
def run_exe(path, synchronous=False):
|
||||||
'''Launches a given software'''
|
'''Launches a given software'''
|
||||||
|
|
||||||
|
if type(path) == str:
|
||||||
|
paths = [path]
|
||||||
|
else:
|
||||||
|
paths = path
|
||||||
|
|
||||||
|
# sanity check path is list #
|
||||||
|
if not type(path) == list:
|
||||||
|
raise AssertionError("ERROR: run_exe could not build a list of paths")
|
||||||
|
|
||||||
if os.name != "nt":
|
if os.name != "nt":
|
||||||
if ".lnk" in path:
|
if ".lnk" in path:
|
||||||
subprocess.Popen(["wine64", "start", path])
|
subprocess.Popen(["wine64", "start", path])
|
||||||
@@ -62,16 +72,18 @@ def run_exe(path, synchronous=False):
|
|||||||
if synchronous:
|
if synchronous:
|
||||||
raise NotImplementedError("SYNC not yet implemented")
|
raise NotImplementedError("SYNC not yet implemented")
|
||||||
|
|
||||||
if path.endswith(".lnk"):
|
paths = [resolve_lnk(p) if p.endswith(".lnk") else p for p in paths]
|
||||||
path = resolve_lnk(path)
|
|
||||||
|
|
||||||
print("Executing:", path)
|
print("Executing:", paths)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.Popen(path, cwd=os.path.dirname(path))
|
if paths[0].endswith(".reg"):
|
||||||
|
raise OSError("WinError 740")
|
||||||
|
subprocess.Popen(path, cwd=os.path.dirname(paths[0])) # TODO fix this BS
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if "WinError 740" in str(e):
|
if "WinError 740" in str(e):
|
||||||
p = subprocess.Popen(["powershell", "-ExecutionPolicy", "Bypass", "-File", "windows_run_as_admin.ps1", path],
|
p = subprocess.Popen(["powershell", "-ExecutionPolicy", "Bypass", "-File",
|
||||||
|
"windows_run_as_admin.ps1", json.dumps(paths)],
|
||||||
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
print(p.communicate())
|
print(p.communicate())
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
FROM alpine
|
||||||
|
|
||||||
|
RUN apk add --no-cache py3-pip
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN python3 -m pip install --no-cache-dir --break-system-packages waitress
|
||||||
|
|
||||||
|
COPY req.txt .
|
||||||
|
RUN python3 -m pip install --no-cache-dir --break-system-packages -r req.txt
|
||||||
|
|
||||||
|
COPY ./ .
|
||||||
|
|
||||||
|
EXPOSE 5000/tcp
|
||||||
|
|
||||||
|
ENTRYPOINT ["waitress-serve"]
|
||||||
|
CMD ["--host", "0.0.0.0", "--port", "5000", "--call", "app:createApp"]
|
||||||
5
server/app.py
Normal file
5
server/app.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import main as server
|
||||||
|
def createApp(envivorment=None, start_response=None):
|
||||||
|
with server.app.app_context():
|
||||||
|
server.create_app()
|
||||||
|
return server.app
|
||||||
@@ -62,5 +62,8 @@ def get_path():
|
|||||||
# If the path is neither a file nor a directory, return an error
|
# If the path is neither a file nor a directory, return an error
|
||||||
return jsonify({"error": "Invalid path type."}), 400
|
return jsonify({"error": "Invalid path type."}), 400
|
||||||
|
|
||||||
|
def create_app():
|
||||||
|
pass
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|||||||
1
server/req.txt
Normal file
1
server/req.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
flask
|
||||||
16
software.py
16
software.py
@@ -53,6 +53,7 @@ class Software:
|
|||||||
self.extra_files = meta.get("extra_files")
|
self.extra_files = meta.get("extra_files")
|
||||||
self.run_exe = meta.get("run_exe")
|
self.run_exe = meta.get("run_exe")
|
||||||
self.installer = meta.get("installer")
|
self.installer = meta.get("installer")
|
||||||
|
self.installer_no_admin = meta.get("installer_no_admin")
|
||||||
|
|
||||||
self.pictures = [ self.backend.get(pp, self.cache_dir) for pp in
|
self.pictures = [ self.backend.get(pp, self.cache_dir) for pp in
|
||||||
self.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True) ]
|
self.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True) ]
|
||||||
@@ -104,6 +105,9 @@ class Software:
|
|||||||
def install(self):
|
def install(self):
|
||||||
'''Install this software from the backend'''
|
'''Install this software from the backend'''
|
||||||
|
|
||||||
|
# things to execute #
|
||||||
|
admin_run_list = []
|
||||||
|
|
||||||
print("Installing:", self.title, self.directory)
|
print("Installing:", self.title, self.directory)
|
||||||
|
|
||||||
# handle link-only software #
|
# handle link-only software #
|
||||||
@@ -139,7 +143,8 @@ class Software:
|
|||||||
print("Install dir Registry:", target_install_dir)
|
print("Install dir Registry:", target_install_dir)
|
||||||
path = jinja_helper.render_path(path, target_install_dir, self.directory)
|
path = jinja_helper.render_path(path, target_install_dir, self.directory)
|
||||||
|
|
||||||
localaction.install_registry_file(path)
|
admin_run_list.append(path)
|
||||||
|
# localaction.install_registry_file(path)
|
||||||
|
|
||||||
# install dependencies #
|
# install dependencies #
|
||||||
if self.dependencies:
|
if self.dependencies:
|
||||||
@@ -157,12 +162,19 @@ class Software:
|
|||||||
|
|
||||||
|
|
||||||
print("Running installer:", installer_path)
|
print("Running installer:", installer_path)
|
||||||
|
if not self.installer_no_admin:
|
||||||
|
admin_run_list.append(installer_path)
|
||||||
|
else:
|
||||||
localaction.run_exe(installer_path)
|
localaction.run_exe(installer_path)
|
||||||
|
|
||||||
|
if admin_run_list:
|
||||||
|
print("admin list", admin_run_list)
|
||||||
|
localaction.run_exe(admin_run_list)
|
||||||
|
|
||||||
# install gamefiles #
|
# install gamefiles #
|
||||||
if self.extra_files:
|
if self.extra_files:
|
||||||
for src, dest in self.extra_files.items():
|
for src, dest in self.extra_files.items():
|
||||||
tmp = self.backend.get(os.path.join(self.directory, "extra_files", src), self.cache_dir)
|
tmp = self.backend.get(os.path.join(self.directory, "extra_files", src), self.cache_dir, wait=True)
|
||||||
dest_dir = os.path.expandvars(dest)
|
dest_dir = os.path.expandvars(dest)
|
||||||
os.makedirs(dest_dir, exist_ok=True)
|
os.makedirs(dest_dir, exist_ok=True)
|
||||||
shutil.copy(tmp, dest_dir)
|
shutil.copy(tmp, dest_dir)
|
||||||
|
|||||||
@@ -1,7 +1,24 @@
|
|||||||
param (
|
param (
|
||||||
[string]$Path
|
[string]$PathsJson
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
$Paths = $PathsJson | ConvertFrom-Json -ErrorAction Stop
|
||||||
|
} catch {
|
||||||
|
# If it fails, assume it's Base64-encoded and decode it
|
||||||
|
try {
|
||||||
|
$DecodedJson = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($PathsJson))
|
||||||
|
$Paths = $DecodedJson | ConvertFrom-Json -ErrorAction Stop
|
||||||
|
} catch {
|
||||||
|
Write-Error "Failed to parse PathsJson as JSON or Base64-encoded JSON."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Paths"
|
||||||
|
Write-Host $PathsJson
|
||||||
|
Write-Host $PWD
|
||||||
|
|
||||||
# Check if running as administrator
|
# Check if running as administrator
|
||||||
$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
||||||
$Principal = New-Object System.Security.Principal.WindowsPrincipal($CurrentUser)
|
$Principal = New-Object System.Security.Principal.WindowsPrincipal($CurrentUser)
|
||||||
@@ -9,19 +26,40 @@ $IsAdmin = $Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::A
|
|||||||
|
|
||||||
if (-not $IsAdmin) {
|
if (-not $IsAdmin) {
|
||||||
# Relaunch the script with elevated privileges
|
# Relaunch the script with elevated privileges
|
||||||
Start-Process powershell -ArgumentList "-File `"$PSCommandPath`" `"$Path`"" -Verb RunAs
|
$EncodedJson = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($PathsJson))
|
||||||
|
$TempFile = New-TemporaryFile
|
||||||
|
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -Command `"Set-Location -Path '$PWD'; & '$PSCommandPath' '$EncodedJson' *> '$TempFile'`" " -Verb RunAs -Wait
|
||||||
|
|
||||||
|
Start-Sleep 1
|
||||||
|
if (Test-Path $TempFile) {
|
||||||
|
# Output the captured output
|
||||||
|
Get-Content $TempFile | Write-Host
|
||||||
|
Remove-Item $TempFile
|
||||||
|
}else{
|
||||||
|
Write-Host "No output captured. Check if the script produces any output."
|
||||||
|
}
|
||||||
|
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run the process and capture output
|
|
||||||
try {
|
foreach($Path in $Paths){
|
||||||
$Process = Start-Process -FilePath $Path -NoNewWindow -PassThru -RedirectStandardOutput output.txt -RedirectStandardError error.txt
|
|
||||||
|
Write-Host "Running: $Path"
|
||||||
|
|
||||||
|
# Run the process and capture output
|
||||||
|
try {
|
||||||
|
|
||||||
|
if ($Path -match '\.reg$') {
|
||||||
|
# Run regedit silently to merge the .reg file
|
||||||
|
$Process = Start-Process -FilePath "regedit.exe" -ArgumentList "/s `"$Path`"" -NoNewWindow -PassThru
|
||||||
|
} else {
|
||||||
|
# Run the file normally
|
||||||
|
$Process = Start-Process -FilePath $Path -NoNewWindow -PassThru
|
||||||
|
}
|
||||||
$Process.WaitForExit()
|
$Process.WaitForExit()
|
||||||
|
|
||||||
# Read and display output
|
} catch {
|
||||||
Get-Content output.txt
|
Write-Host "Error running the process: $_"
|
||||||
Get-Content error.txt | ForEach-Object { Write-Host $_ -ForegroundColor Red }
|
}
|
||||||
|
|
||||||
} catch {
|
|
||||||
Write-Host "Error running the process: $_" -ForegroundColor Red
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user