FFS! Thanks a lot!
These are distinctive different options!
Sadly I came up with something completely bonkers, home-grown up in the last hour what works well with the theme we use.
It changes the file /var/www/helpdesk/index.php and adds to the top 2 headings and the html content from
/var/www/status/welcome + /var/www/status/systemstatus
import os
def update_index_file(original_file_path, backup_file_path, insert_marker, new_content, target_line):
if not os.path.exists(backup_file_path):
# We expect a osticket update, keep a original file, just in case
os.system(f'cp {original_file_path} {backup_file_path}')
print("Backup file created.")
else:
print("Backup file already exists, not overwriting.")
# Read the content of the original file
with open(original_file_path, 'r') as file:
lines = file.readlines()
# Check if the content is already present
if insert_marker not in ''.join(lines):
# Find the target line to insert the new content before it
for i, line in enumerate(lines):
if target_line in line:
# Insert new content before the target line
lines.insert(i, new_content + insert_marker + "\n")
print("New content inserted.")
break
with open(original_file_path, 'w') as file:
file.writelines(lines)
else:
print("Marker found. New content insertion skipped.")
original_file_path = '/var/www/helpdesk/index.php'
backup_file_path = '/var/www/helpdesk/index.original'
insert_marker = "<!-- Content marker for status updates -->\n"
new_content = """
<style>
#status-update {
background-color: transparent;
border: none;
box-shadow: none;
padding: 20px 0;
margin-top: 20px;
}
#status-update h2 {
color: #606D7F;
font-size: 30px;
font-family: 'Montserrat', sans-serif;
margin: 0px -40px 24px 0px;
}
#status-update pre {
background-color: transparent;
border: none;
padding: 0;
margin: 0;
font-family: 'Montserrat', sans-serif;
color: #343a40;
}
#status-update p {
background-color: transparent;
border: none;
padding: 0;
margin: 0 0 0 40px; /* Add left margin for indenting */
font-family: 'Montserrat', sans-serif;
color: #343a40;
}
</style>
<!-- Added section for welcome -->
<div id="status-update">
<h1><?php echo __('Welcome to the Support Center'); ?></h1>
<p><?php echo file_get_contents('/var/www/status/welcome'); ?></p>
</div>
<!-- Added section for system status update -->
<div id="status-update">
<h1><?php echo __('Current System Status'); ?></h1>
<p><?php echo file_get_contents('/var/www/status/systemstatus'); ?></p>
</div>
"""
target_line = '<div id="landing_page">'
# now kiss
update_index_file(original_file_path, backup_file_path, insert_marker, new_content, target_line)