Add in check domains, and highlight any files created .new in red

This commit is contained in:
Brian Read 2024-12-01 15:29:08 +00:00
parent 918f49eaf2
commit b0393cfe8a
12 changed files with 131 additions and 68 deletions

View File

@ -159,7 +159,7 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %ret = (
'Data1'=>'Data for CHECKALLDOMAINS', #Example
# fields from Inputs in CHECKALLDOMAINS $fields['CHECKALLDOMAINS']
'AllDomainsCheck'=>'AllDomainsCheck contents',
'AllDomainsCheck'=>$c->update_all_domains(),
);
return %ret;
@ -171,7 +171,7 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %ret = (
'Data1'=>'Data for CHECKALLENABLEDDOMAINS', #Example
# fields from Inputs in CHECKALLENABLEDDOMAINS $fields['CHECKALLENABLEDDOMAINS']
'EnabledDomainsCheck'=>'EnabledDomainsCheck contents',
'EnabledDomainsCheck'=>$c->update_enabled_domains(),
);
return %ret;
@ -184,8 +184,7 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
'Data1'=>'Data for CHECKONEDOMAIN', #Example
# fields from Inputs in CHECKONEDOMAIN $fields['CHECKONEDOMAIN']
'OneDomainToCheck'=>$c->param("CHECKONEDOMAIN"),
'OneDomainsCheck'=>'OneDomainsCheck contents',
'OneDomainsCheck'=>$c->update_one_domain($c->param("CHECKONEDOMAIN"))
);
return %ret;
}
@ -445,4 +444,29 @@ sub get_my_ip
my $output = `/usr/sbin/e-smith/getmyip`;
return $output || "IP";
}
sub update_one_domain
{
my ($self,$domain) = @_;
return "$domain not domain" unless ($ddb->get($domain) || $hdb->get($domain));
($domain) = ($domain =~ /([\w\p{L}.]+)/);
my $output = `/etc/e-smith/events/actions/letsencrypt-setdomains " " $domain `;
return $output || "-empty-";
}
sub update_all_domains
{
my $self = shift;
my $output = `/etc/e-smith/events/actions/letsencrypt-setdomains "" "" all `;
return $output || "-empty-";
}
sub update_enabled_domains
{
my $self = shift;
my $output = `/etc/e-smith/events/actions/letsencrypt-setdomains "" "" enabled `;
return $output || "-empty-";
}
1;

View File

@ -1,6 +1,6 @@
package SrvMngr::Controller::Letsencrypt;
#
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 13:34:33
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43
#
#----------------------------------------------------------------------
# heading : Network

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 13:34:33
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43
%#
<div id="Letsencrypt-CHECKALLDOMAINS" class="partial Letsencrypt-CHECKALLDOMAINS">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 13:34:33
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43
%#
<div id="Letsencrypt-CHECKALLENABLEDDOMAINS" class="partial Letsencrypt-CHECKALLENABLEDDOMAINS">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 13:34:33
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43
%#
<div id="Letsencrypt-CHECKONEDOMAIN" class="partial Letsencrypt-CHECKONEDOMAIN">
<script>
@ -20,7 +20,7 @@
<h1 class='head'><%=l('lets_Check_just_one_domain')%></h1>
<h2 class='subh'><%=l('lets_Loop_through_checking_the_letsencrypt')%></h2>
<h2 class='subh'><%=l('lets_Loop_through_and_check_the')%></h2>
<p><span class=label>
%=l('lets_Domains_name')

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 13:34:33
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43
%#
<div id="Letsencrypt-LIST" class="partial Letsencrypt-LIST">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 13:34:33
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43
%#
<div id="Letsencrypt-PARAMS" class="partial Letsencrypt-PARAMS">
<script>

View File

@ -1,5 +1,5 @@
/*
Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 13:34:33
Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43
*/
.Letsencrypt-panel {}
.name {}

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 13:34:33
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43
%#
% layout 'default', title => "Sme server 2 - Letsencrypt certificate", share_dir => './';
%# css specific to this panel:

View File

@ -1,54 +1,54 @@
#
# Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 13:34:33
# Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43
#
'lets_CHECK' => 'Check',
'lets_Letsencrypt_certificate' => 'Letsencrypt certificate',
'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for each configured domain which is enabled',
'lets_APPLY' => 'Apply',
'lets_CHECK_ALL_ENABLED_DOMAINS' => 'Check All Enabled Domains',
'lets_Internet_IP' => 'Internet IP',
'lets_Domain_name_/_HOSTNAME' => 'Domain name / HOSTNAME',
'lets_Not_Before' => 'Not Before',
'lets_CHECKONEDOMAIN_panel_action_was_successful' => 'CHECKONEDOMAIN panel action was successful',
'lets_Expiry' => 'Expiry',
'lets_Domains_name' => 'Domains name',
'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for a specific domain',
'lets_Check_all_enabled_domains' => 'Check all enabled domains',
'lets_EMAIL' => 'Email',
'lets_KEYSIZE_STATUS' => 'Keysize Status',
'lets_Back' => 'Back',
'lets_Check_all_domains' => 'Check all domains',
'lets_LABEL_POINT' => 'Label Point',
'lets_Error_Status_Report' => 'Error Status Report',
'lets_CHECK_ALL_DOMAINS' => 'Check All Domains',
'lets_ACCEPT_TERMS_STATUS' => 'Accept Terms Status',
'lets_All_domains_check_result' => 'All domains check result',
'lets_List_of_Domains_and_Hosts' => 'List of Domains and Hosts',
'lets_CONFIG_LETSENCRYPT' => 'confirm Letsencrypt',
'lets_Internal_IP' => 'Internal IP',
'lets_Status_Report' => 'Status Report',
'lets_For_this_Server' => 'For this Server',
'lets_CHECKALLENABLEDDOMAINS_panel_action_was_successful' => 'CHECKALLENABLEDDOMAINS panel action was successful',
'lets_LABEL_LECERT' => 'Label secret',
'lets_Content' => 'Content',
'lets_Brief_description' => 'Brief description',
'lets_Manage_letsencrypt-config_settings:' => 'Manage letsencrypt-config settings',
'lets_HOOKSCRIPT_STATUS' => 'Hookscript Status',
'lets_Enabled_domains_check_result' => 'Enabled domains check result',
'lets_API_STATUS' => 'ape Status',
'lets_SERVICE_STATUS' => 'Service Status',
'lets_EMAIL' => 'Email',
'lets_Back' => 'Back',
'lets_Internal_IP' => 'Internal IP',
'lets_Save' => 'Save',
'lets_Issuer' => 'Issuer',
'lets_Current_certificate_details' => 'Current certificate details',
'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for each configured domain',
'lets_CONFIGUREMODE_STATUS' => 'Configuremode Status',
'lets_External_Interface_IP' => 'External Interface IP',
'lets_IS_IN_CERT' => 'Is In cart',
'lets_SERVICE_STATUS' => 'Service Status',
'lets_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
'lets_Manage_letsencrypt-config_settings:' => 'Manage letsencrypt-config settings',
'lets_LABEL_NAMESERVERS' => 'Label timeservers',
'lets_One_domain_check_result' => 'One domain check result',
'lets_CONFIG' => 'Config',
'lets_CHECKALLDOMAINS_panel_action_was_successful' => 'CHECKALLDOMAINS panel action was successful',
'lets_LIST_panel_action_was_successful' => 'LIST panel action was successful',
'lets_HOSTOVERRIDE_STATUS' => 'Hostoverride Status',
'lets_For_this_Server' => 'For this Server',
'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for each configured domain',
'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for each configured domain which is enabled',
'lets_Check_just_one_domain' => 'Check just one domain',
'lets_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
'lets_Check_all_domains' => 'Check all domains',
'lets_LIST_panel_action_was_successful' => 'LIST panel action was successful',
'lets_Status_Report' => 'Status Report',
'lets_LABEL_NAMESERVERS' => 'Label timeservers',
'lets_Loop_through_and_check_the' => 'Loop through and check the letsencrypt status for a specific domain',
'lets_Letsencrypt_certificate' => 'Letsencrypt certificate',
'lets_Error_Status_Report' => 'Error Status Report',
'lets_Not_Before' => 'Not Before',
'lets_Content' => 'Content',
'lets_CONFIG_LETSENCRYPT' => 'confirm Letsencrypt',
'lets_API_STATUS' => 'ape Status',
'lets_ACCEPT_TERMS_STATUS' => 'Accept Terms Status',
'lets_Check_all_enabled_domains' => 'Check all enabled domains',
'lets_All_domains_check_result' => 'All domains check result',
'lets_CHECKALLDOMAINS_panel_action_was_successful' => 'CHECKALLDOMAINS panel action was successful',
'lets_Domains_name' => 'Domains name',
'lets_HOSTOVERRIDE_STATUS' => 'Hostoverride Status',
'lets_List_of_Domains_and_Hosts' => 'List of Domains and Hosts',
'lets_Brief_description' => 'Brief description',
'lets_KEYSIZE_STATUS' => 'Keysize Status',
'lets_Domain_name_/_HOSTNAME' => 'Domain name / HOSTNAME',
'lets_Enabled_domains_check_result' => 'Enabled domains check result',
'lets_CHECKALLENABLEDDOMAINS_panel_action_was_successful' => 'CHECKALLENABLEDDOMAINS panel action was successful',
'lets_Internet_IP' => 'Internet IP',
'lets_Expiry' => 'Expiry',
'lets_CHECK_ALL_DOMAINS' => 'Check All Domains',
'lets_LABEL_POINT' => 'Label Point',
'lets_CHECK' => 'Check',
'lets_CONFIG' => 'Config',
'lets_Current_certificate_details' => 'Current certificate details',
'lets_LABEL_LECERT' => 'Label secret',
'lets_One_domain_check_result' => 'One domain check result',
'lets_CHECKONEDOMAIN_panel_action_was_successful' => 'CHECKONEDOMAIN panel action was successful',
'lets_CONFIGUREMODE_STATUS' => 'Configuremode Status',
'lets_CHECK_ALL_ENABLED_DOMAINS' => 'Check All Enabled Domains',
'lets_External_Interface_IP' => 'External Interface IP',
'lets_APPLY' => 'Apply',

View File

@ -256,7 +256,7 @@
{ 'Name':'CheckAllEnabledDomains',
'route':'CHECKALLENABLEDDOMAINS',
'Header': 'Check all enabled domains',
'SubHeader': 'Loop through checking the letsencrypt status for each configured domain wihch is enabled',
'SubHeader': 'Loop through checking the letsencrypt status for each configured domain which is enabled',
'Input1': {
'Type': 'Textarea',
'Name': 'EnabledDomainsCheck',
@ -272,7 +272,7 @@
{ 'Name':'CheckOneDomain',
'route':'CHECKONEDOMAIN',
'Header': 'Check just one domain',
'SubHeader': 'Loop through checking the letsencrypt status for a specific domain',
'SubHeader': 'Loop through and check the letsencrypt status for a specific domain',
'Input1': {
'Type': 'ReadonlyText',
'Name': 'OneDomainToCheck',

View File

@ -434,6 +434,45 @@ def check_file_version(filename,force_Files=False):
logger.warning(f"An error occurred: {traceback.format_exc()}")
return filename
def highlight_occurrences(text, keystring='new', highlight_color='red'):
"""
Highlights all occurrences of `keystring` in `text` with the specified `highlight_color`.
Parameters:
text (str): The original text where occurrences will be highlighted.
keystring (str): The substring to be highlighted.
highlight_color (str): The color name for highlighting. Defaults to 'yellow'.
Supported colors: black, red, green, yellow, blue, magenta, cyan, white.
Returns:
str: The modified text with highlighted occurrences.
"""
# ANSI escape codes for colors
colors = {
'black': '\033[30m',
'red': '\033[31m',
'green': '\033[32m',
'yellow': '\033[33m',
'blue': '\033[34m',
'magenta': '\033[35m',
'cyan': '\033[36m',
'white': '\033[37m',
'reset': '\033[0m'
}
if highlight_color not in colors:
raise ValueError(f"Unsupported color '{highlight_color}'. Supported colors: {', '.join(colors.keys())}")
# Escape keystring to handle any special regex characters
escaped_keystring = re.escape(keystring)
# Define the replacement pattern with the chosen color
colored_keystring = f"{colors[highlight_color]}{keystring}{colors['reset']}"
# Use regex to replace all occurrences, case-sensitive
highlighted_text = re.sub(escaped_keystring, colored_keystring, text)
return highlighted_text
def convert_lex_to_dict(pairs_string):
# Splitting pairs string by comma and newline, excluding empty lines
@ -630,7 +669,7 @@ if __name__ == "__main__":
)
with open(controller_file, "w") as file:
file.write(controller_perl)
logger.info(f"{controller_file} controller generated ok")
logger.info(f"{highlight_occurrences(controller_file)} controller generated ok")
except Exception as e:
logger.info(f"A Chameleon controller *render* error occurred: {e} {traceback.format_exc()}")
except Exception as e:
@ -654,7 +693,7 @@ if __name__ == "__main__":
# We must be careful to not overwrite the custom file if the developer has already written to it - TBD
with open(custom_controller_file, "w") as file:
file.write(custom_controller_perl)
logger.info(f"{custom_controller_file} custom controller generated ok")
logger.info(f"{highlight_occurrences(custom_controller_file,'new')} custom controller generated ok")
except Exception as e:
logger.info(f"A Chameleon custom controller *render* error occurred: {e} {traceback.format_exc()}")
except Exception as e:
@ -670,7 +709,7 @@ if __name__ == "__main__":
)
with open(layout_file, "w") as file:
file.write(layout_mojo)
logger.info(f"{layout_file} mojo template layout file generated ok")
logger.info(f"{highlight_occurrences(layout_file)} mojo template layout file generated ok")
except Exception as e:
logger.info(f"A Chameleon *render* on layout file error occurred: {e}")
except Exception as e:
@ -697,7 +736,7 @@ if __name__ == "__main__":
)
with open(partial_files[i], "w") as file:
file.write(partial_mojo_template)
logger.info(f"{partial_files[i]} mojo template generated ok - phase 1")
logger.info(f"{highlight_occurrences(partial_files[i])} mojo template generated ok - phase 1")
except Exception as e:
logger.info(
f"A Chameleon render error on partial file {html['route']} occurred: {e}"
@ -845,7 +884,7 @@ if __name__ == "__main__":
lex_all = ""
for lex_str in string_lib:
lex_all += f"'{lex_str['left']}' => '{lex_str['right']}',\n"
logger.info(f"Writing {lex_file}")
logger.info(f"Writing {highlight_occurrences(lex_file)}")
with open(lex_file, "w") as file:
file.write(f"#\n# Generated by SM2Gen version: {strVersion}\n#\n")
file.write(lex_all)
@ -866,7 +905,7 @@ if __name__ == "__main__":
# and write it back
with open(filename, "w") as file:
file.write(file_content)
logger.info(f"Write out modified:{filename}")
logger.info(f"Write out modified:{highlight_occurrences(filename)}")
# Now generate all the translated lex files from a list of the languages and codes
# if specifically requested