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")
|
||||
server_path_entry.delete(0, customtkinter.END)
|
||||
server_path_entry.insert(0, "C:/path/to/game/mount/")
|
||||
else:
|
||||
elif dropdown_var == "FTP/FTPS":
|
||||
user_entry.configure(state=customtkinter.NORMAL)
|
||||
password_entry.configure(state=customtkinter.NORMAL)
|
||||
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)
|
||||
server_path_entry.delete(0, customtkinter.END)
|
||||
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.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)
|
||||
|
||||
# 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.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,
|
||||
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))
|
||||
@@ -311,7 +319,6 @@ if __name__ == "__main__":
|
||||
|
||||
if not os.path.isfile(CONFIG_FILE):
|
||||
get_config_inputs()
|
||||
print("wtf")
|
||||
|
||||
# load config #
|
||||
with open(CONFIG_FILE) as f:
|
||||
@@ -332,6 +339,13 @@ if __name__ == "__main__":
|
||||
if backend_type == "FTP/FTPS":
|
||||
remote_root_dir = "/" + config_loaded["Server/Path:"].split("://")[1].split("/", 1)[1]
|
||||
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":
|
||||
remote_root_dir = config_loaded["Server/Path:"]
|
||||
server = None
|
||||
@@ -342,8 +356,8 @@ if __name__ == "__main__":
|
||||
print(user, password, install_dir, remote_root_dir, server, config_loaded["Server/Path:"])
|
||||
|
||||
# add db backend #
|
||||
if True:
|
||||
db = data_backend.HTTP(None, None, install_dir, remote_root_dir="./", server="http://localhost:5000", progress_bar_wrapper=pgw, tkinter_root=app)
|
||||
if backend_type == "HTTP/HTTPS":
|
||||
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":
|
||||
db = data_backend.FTP(user, password, install_dir, server=server,
|
||||
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)
|
||||
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)
|
||||
|
||||
@@ -133,7 +133,7 @@ class HTTP(DataBackend):
|
||||
|
||||
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 #
|
||||
# as there cannot be a meaningful UI-draw without it. #
|
||||
@@ -145,7 +145,11 @@ class HTTP(DataBackend):
|
||||
|
||||
# return the content #
|
||||
print("Content for", fullpath, ":", r.text)
|
||||
return r.text
|
||||
|
||||
if return_content:
|
||||
return r.text
|
||||
else:
|
||||
return local_file
|
||||
|
||||
else:
|
||||
print("Async Requested for:", local_file)
|
||||
@@ -173,6 +177,7 @@ class HTTP(DataBackend):
|
||||
else:
|
||||
|
||||
r = requests.get(self._get_url(), params={ "path" : path })
|
||||
r.raise_for_status()
|
||||
#print(r, r.status_code, r.content)
|
||||
paths = r.json()["contents"]
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
|
||||
# windows imports #
|
||||
if os.name == "nt":
|
||||
@@ -52,6 +53,15 @@ def resolve_lnk(lnk_file_path):
|
||||
def run_exe(path, synchronous=False):
|
||||
'''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 ".lnk" in path:
|
||||
subprocess.Popen(["wine64", "start", path])
|
||||
@@ -62,16 +72,18 @@ def run_exe(path, synchronous=False):
|
||||
if synchronous:
|
||||
raise NotImplementedError("SYNC not yet implemented")
|
||||
|
||||
if path.endswith(".lnk"):
|
||||
path = resolve_lnk(path)
|
||||
paths = [resolve_lnk(p) if p.endswith(".lnk") else p for p in paths]
|
||||
|
||||
print("Executing:", path)
|
||||
print("Executing:", paths)
|
||||
|
||||
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:
|
||||
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)
|
||||
print(p.communicate())
|
||||
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
|
||||
return jsonify({"error": "Invalid path type."}), 400
|
||||
|
||||
def create_app():
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
||||
1
server/req.txt
Normal file
1
server/req.txt
Normal file
@@ -0,0 +1 @@
|
||||
flask
|
||||
18
software.py
18
software.py
@@ -53,6 +53,7 @@ class Software:
|
||||
self.extra_files = meta.get("extra_files")
|
||||
self.run_exe = meta.get("run_exe")
|
||||
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.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True) ]
|
||||
@@ -104,6 +105,9 @@ class Software:
|
||||
def install(self):
|
||||
'''Install this software from the backend'''
|
||||
|
||||
# things to execute #
|
||||
admin_run_list = []
|
||||
|
||||
print("Installing:", self.title, self.directory)
|
||||
|
||||
# handle link-only software #
|
||||
@@ -139,7 +143,8 @@ class Software:
|
||||
print("Install dir Registry:", target_install_dir)
|
||||
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 #
|
||||
if self.dependencies:
|
||||
@@ -157,12 +162,19 @@ class Software:
|
||||
|
||||
|
||||
print("Running installer:", installer_path)
|
||||
localaction.run_exe(installer_path)
|
||||
if not self.installer_no_admin:
|
||||
admin_run_list.append(installer_path)
|
||||
else:
|
||||
localaction.run_exe(installer_path)
|
||||
|
||||
if admin_run_list:
|
||||
print("admin list", admin_run_list)
|
||||
localaction.run_exe(admin_run_list)
|
||||
|
||||
# install gamefiles #
|
||||
if self.extra_files:
|
||||
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)
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
shutil.copy(tmp, dest_dir)
|
||||
|
||||
@@ -1,7 +1,24 @@
|
||||
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
|
||||
$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$Principal = New-Object System.Security.Principal.WindowsPrincipal($CurrentUser)
|
||||
@@ -9,19 +26,40 @@ $IsAdmin = $Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::A
|
||||
|
||||
if (-not $IsAdmin) {
|
||||
# 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
|
||||
}
|
||||
|
||||
# Run the process and capture output
|
||||
try {
|
||||
$Process = Start-Process -FilePath $Path -NoNewWindow -PassThru -RedirectStandardOutput output.txt -RedirectStandardError error.txt
|
||||
$Process.WaitForExit()
|
||||
|
||||
# Read and display output
|
||||
Get-Content output.txt
|
||||
Get-Content error.txt | ForEach-Object { Write-Host $_ -ForegroundColor Red }
|
||||
foreach($Path in $Paths){
|
||||
|
||||
} catch {
|
||||
Write-Host "Error running the process: $_" -ForegroundColor Red
|
||||
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()
|
||||
|
||||
} catch {
|
||||
Write-Host "Error running the process: $_"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user