forked from DigitalBox98/SimpleExtJSApp
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor scheduled task handling and update version references in var…
…ious files
- Loading branch information
Showing
19 changed files
with
694 additions
and
704 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,73 @@ | ||
#!/usr/bin/env python3 | ||
import cgi | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import json | ||
import cgitb; cgitb.enable() # Enable CGI error reporting | ||
import cgi | ||
import cgitb | ||
|
||
print("Content-Type: application/json\n") # JSON is following, with an extra newline for headers end | ||
cgitb.enable() # Enable CGI error reporting | ||
|
||
# Authenticate the user | ||
f = os.popen('/usr/syno/synoman/webman/modules/authenticate.cgi', 'r') | ||
user = f.read().strip() | ||
|
||
def read_rrmanager_config(file_path): | ||
try: | ||
config = {} | ||
with open(file_path, 'r') as file: | ||
with open(file_path, "r") as file: | ||
for line in file: | ||
line = line.strip() | ||
if line and not line.startswith('#'): | ||
key, value = line.split('=') | ||
if line and not line.startswith("#"): | ||
key, value = line.split("=") | ||
config[key.strip()] = value.strip() | ||
return config | ||
except IOError as e: | ||
return f"Error reading user-config.yml: {e}" | ||
except e: | ||
return "{}" | ||
|
||
response = {} | ||
response['success'] = False | ||
|
||
if len(user) > 0: | ||
# Parse query string | ||
arguments = cgi.FieldStorage() | ||
rr_manager_config = read_rrmanager_config('/var/packages/rr-manager/target/app/config.txt') | ||
filename = rr_manager_config.get('RR_UPDATE_PROGRESS_FILE') | ||
|
||
if filename: | ||
# Construct file path | ||
file_path = os.path.join('/tmp', filename) | ||
|
||
if os.path.abspath(file_path).startswith('/tmp/'): | ||
try: | ||
with open(file_path, 'r') as file: | ||
content = file.read() | ||
# Attempt to parse the content as JSON | ||
parsed_content = json.loads(content) | ||
# Success, set the result | ||
response["result"] = parsed_content | ||
response['success'] = True | ||
except json.JSONDecodeError: | ||
response["status"] = "File content is not valid JSON." | ||
except Exception as e: | ||
response["status"] = f"Could not read file: {str(e)}" | ||
|
||
if __name__ == "__main__": | ||
user = os.popen("/usr/syno/synoman/webman/modules/authenticate.cgi", "r").read().strip() | ||
|
||
# Debug | ||
if not user: | ||
import getpass | ||
|
||
user = getpass.getuser() | ||
if user != "root": | ||
user = "" | ||
|
||
response = {} | ||
response["success"] = False | ||
if user: | ||
# Parse query string | ||
arguments = cgi.FieldStorage() | ||
rr_manager_config = read_rrmanager_config( | ||
"/var/packages/rr-manager/target/app/config.txt" | ||
) | ||
filename = rr_manager_config.get("RR_UPDATE_PROGRESS_FILE") | ||
|
||
if filename: | ||
# Construct file path | ||
file_path = os.path.join("/tmp", filename) | ||
|
||
if os.path.abspath(file_path).startswith("/tmp/"): | ||
try: | ||
with open(file_path, "r") as file: | ||
content = file.read() | ||
# Attempt to parse the content as JSON | ||
parsed_content = json.loads(content) | ||
# Success, set the result | ||
response["result"] = parsed_content | ||
response["success"] = True | ||
except json.JSONDecodeError: | ||
response["status"] = "File content is not valid JSON." | ||
except Exception as e: | ||
response["status"] = f"Could not read file: {str(e)}" | ||
else: | ||
response["status"] = "Invalid file path." | ||
else: | ||
response["status"] = "Invalid file path." | ||
response["status"] = "Filename parameter is missing." | ||
else: | ||
response["status"] = "Filename parameter is missing." | ||
else: | ||
response["status"] = "Authentication failed." | ||
response["status"] = "Authentication failed." | ||
|
||
# Print the JSON response at the end | ||
print(json.dumps(response)) | ||
print("Content-type: application/json\n") | ||
print(json.dumps(response, indent=4)) |
Oops, something went wrong.