Fix error return from params screen

This commit is contained in:
Brian Read 2024-11-22 14:00:54 +00:00
parent 9e0b42a266
commit b9b939223b
13 changed files with 173 additions and 109 deletions

View File

@ -435,4 +435,33 @@ sub get_my_ip
my $output = `/usr/sbin/e-smith/getmyip`;
return $output || "IP";
}
1;
sub update_one_domain
{
my $self = shift;
my $q = $self->{cgi};
my $domain = $q->param('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 $q = $self->{cgi};
my $output = `/etc/e-smith/events/actions/letsencrypt-setdomains "" "" all `;
return $output || "-empty-";
}
sub update_enabled_domains
{
my $self = shift;
my $q = $self->{cgi};
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-11-13 16:29:07
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-17 14:48:52
#
#----------------------------------------------------------------------
# heading : Network
@ -35,6 +35,7 @@ use SrvMngr qw(theme_list init_session);
use Data::Dumper;
use esmith::util;
use esmith::util::network;
use esmith::ConfigDB;
use esmith::AccountsDB;
use esmith::NetworksDB;
@ -80,16 +81,15 @@ sub main {
#pickup any other contents needed and load them into hash shared with panel
my %returned_hash;
# subroutine returns a hash directly
%returned_hash = get_data_for_panel_LIST();
%returned_hash = $c->get_data_for_panel_LIST();
# Copy each key-value pair from the returned hash to the prefix data hash
while (my ($key, $value) = each %returned_hash) {
$lets_data{$key} = $value;
}
# and table control fields
$c->stash(DomainList=>$c->get_DomainList());
$c->stash(DomainList=>$c->get_DomainList());
$c->stash(
title => $title,
@ -173,10 +173,10 @@ sub do_update {
$thispanel = 'CHECKALLENABLEDDOMAINS';
}
if ($trt eq 'CHECKONEDDOMAIN'){
#Validate form parameters for panel CHECKONEDDOMAIN
$ret = $c->validate_CHECKONEDDOMAIN(\%lets_data);
$thispanel = 'CHECKONEDDOMAIN';
if ($trt eq 'CHECKONEDOMAIN'){
#Validate form parameters for panel CHECKONEDOMAIN
$ret = $c->validate_CHECKONEDOMAIN(\%lets_data);
$thispanel = 'CHECKONEDOMAIN';
}
@ -235,15 +235,15 @@ sub do_update {
}
}
if ($trt eq 'CHECKONEDDOMAIN'){
if ($trt eq 'CHECKONEDOMAIN'){
#do whatever is required ...
$ret = $c->perform_CHECKONEDDOMAIN(\%lets_data);
$ret = $c->perform_CHECKONEDOMAIN(\%lets_data);
if ($ret ne "ok") {
# return to the panel with error message
$c->stash(error => $c->l($ret));
$c->render("letsencrypt");
} else {
$c->stash( success => $c->l('lets_CHECKONEDDOMAIN_panel_action_was_successful')); #A bit bland - edit it in the lex file
$c->stash( success => $c->l('lets_CHECKONEDOMAIN_panel_action_was_successful')); #A bit bland - edit it in the lex file
}
}
@ -323,9 +323,9 @@ sub do_display {
%selectedrow = $c->get_selected_CHECKALLENABLEDDOMAINS($lets_data{'Selected'},$is_new_record);
}
if ($trt eq 'CHECKONEDDOMAIN'){
#Validate form parameters for panel CHECKONEDDOMAIN
%selectedrow = $c->get_selected_CHECKONEDDOMAIN($lets_data{'Selected'},$is_new_record);
if ($trt eq 'CHECKONEDOMAIN'){
#Validate form parameters for panel CHECKONEDOMAIN
%selectedrow = $c->get_selected_CHECKONEDOMAIN($lets_data{'Selected'},$is_new_record);
}
@ -342,7 +342,7 @@ sub do_display {
# pickup any other contents needed and load them into hash shared with panel
my %returned_hash;
# subroutine returns a hash directly
%returned_hash = get_data_for_panel_LIST();
%returned_hash = $c->get_data_for_panel_LIST();
# Copy each key-value pair from the returned hash to the prefix data hash
while (my ($key, $value) = each %returned_hash) {
$lets_data{$key} = $value;
@ -353,7 +353,7 @@ sub do_display {
# pickup any other contents needed and load them into hash shared with panel
my %returned_hash;
# subroutine returns a hash directly
%returned_hash = get_data_for_panel_PARAMS();
%returned_hash = $c->get_data_for_panel_PARAMS();
# Copy each key-value pair from the returned hash to the prefix data hash
while (my ($key, $value) = each %returned_hash) {
$lets_data{$key} = $value;
@ -364,7 +364,7 @@ sub do_display {
# pickup any other contents needed and load them into hash shared with panel
my %returned_hash;
# subroutine returns a hash directly
%returned_hash = get_data_for_panel_CHECKALLDOMAINS();
%returned_hash = $c->get_data_for_panel_CHECKALLDOMAINS();
# Copy each key-value pair from the returned hash to the prefix data hash
while (my ($key, $value) = each %returned_hash) {
$lets_data{$key} = $value;
@ -375,18 +375,18 @@ sub do_display {
# pickup any other contents needed and load them into hash shared with panel
my %returned_hash;
# subroutine returns a hash directly
%returned_hash = get_data_for_panel_CHECKALLENABLEDDOMAINS();
%returned_hash = $c->get_data_for_panel_CHECKALLENABLEDDOMAINS();
# Copy each key-value pair from the returned hash to the prefix data hash
while (my ($key, $value) = each %returned_hash) {
$lets_data{$key} = $value;
}
}
if ($trt eq 'CHECKONEDDOMAIN'){
if ($trt eq 'CHECKONEDOMAIN'){
# pickup any other contents needed and load them into hash shared with panel
my %returned_hash;
# subroutine returns a hash directly
%returned_hash = get_data_for_panel_CHECKONEDDOMAIN();
%returned_hash = $c->get_data_for_panel_CHECKONEDOMAIN();
# Copy each key-value pair from the returned hash to the prefix data hash
while (my ($key, $value) = each %returned_hash) {
$lets_data{$key} = $value;
@ -395,9 +395,8 @@ sub do_display {
# and table control fields
$c->stash(DomainList=>$c->get_DomainList());
$c->stash(DomainList=>$c->get_DomainList());
# Data for panel
$c->stash(

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-06 11:09:38
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-17 14:48:52
%#
<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-11-06 11:09:38
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-17 14:48:52
%#
<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-11-13 16:37:25
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-17 14:48:52
%#
<div id="Letsencrypt-CHECKONEDOMAIN" class="partial Letsencrypt-CHECKONEDOMAIN">
<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-11-14 12:01:28
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-17 14:48:52
%#
<div id="Letsencrypt-LIST" class="partial Letsencrypt-LIST">
<script>
@ -18,16 +18,31 @@
%= hidden_field 'trt' => $lets_data->{trt}
%# Inputs etc in here.
%= link_to l('lets_CONFIG'), 'letsencryptd?trt=PARAMS' , class=>'link link2'
<div class=inline-buttons>
<a href='letsencryptd?trt=PARAMS' class='link link2'>
%= l('lets_CONFIG')
</a>
%#= link_to l('lets_CONFIG'), 'letsencryptd?trt=PARAMS' , class=>'link link2'
%= link_to l('lets_CHECK_ALL_DOMAINS'), 'letsencryptd?trt=CHECKALLDOMAINS' , class=>'link link3'
<a href='letsencryptd?trt=CHECKALLDOMAINS' class='link link3'>
%= l('lets_CHECK_ALL_DOMAINS')
</a>
%#= link_to l('lets_CHECK_ALL_DOMAINS'), 'letsencryptd?trt=CHECKALLDOMAINS' , class=>'link link3'
%= link_to l('lets_CHECK_ENABLED_DOMAINS'), 'letsencryptd?trt=CHECKENABLEDDOMAINS' , class=>'link link4'
<a href='letsencryptd?trt=CHECKALLENABLEDDOMAINS' class='link link4'>
%= l('lets_CHECK_ALL_ENABLED_DOMAINS')
</a>
%#= link_to l('lets_CHECK_ALL_ENABLED_DOMAINS'), 'letsencryptd?trt=CHECKALLENABLEDDOMAINS' , class=>'link link4'
<h2 class='subh2'><%=l('lets_For_this_Server:')%></h2>
</div>
<h2 class='subh2'><%=l('lets_For_this_Server')%></h2>
<p><span class=label>
%=l('lets_Internal_IP')
@ -50,7 +65,7 @@
%= text_field 'InternetIP', size => '50', class => 'textinput InternetIP' , pattern=>'.*' , placeholder=>'InternetIP', Readonly=>'true'
<br></span></p>
<h2 class='subh3'><%=l('lets_Current_certificate_details:')%></h2>
<h2 class='subh3'><%=l('lets_Current_certificate_details')%></h2>
<p><span class=label>
%=l('lets_Issuer')
@ -73,7 +88,7 @@
%= text_field 'NotBefore', size => '50', class => 'textinput NotBefore' , pattern=>'.*' , placeholder=>'NotBefore', Readonly=>'true'
<br></span></p>
<h2 class='subh4'><%=l('lets_List_of_Domains_and_Hosts:')%></h2>
<h2 class='subh4'><%=l('lets_List_of_Domains_and_Hosts')%></h2>
<br /><table class="sme-border TableSort sme-table tabl1 ">
<thead class='tabl1'>
@ -89,7 +104,7 @@
</tr>
</thead>
<tbody class='tabl1'>
% my $control_data = $self->stash('DomainList');
% my $control_data = $c->stash('DomainList');
% foreach my $row (@$control_data) {
<tr class='table-row'>
<td class='sme-border table-col table-col-Table1-Domain name / HOSTNAME'><%=$c->render_to_string(inline=>$row->{'Table1-Domain name / HOSTNAME'})%></td>

View File

@ -1,26 +1,23 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-05 16:44:50
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-17 14:48:52
%#
<div id="Letsencrypt-PARAMS" class="partial Letsencrypt-PARAMS">
<script>
window.onload = function() {
SelectInput();
};
</script>
<script>
window.onload = function() {
SelectInput();
};
</script>
% if ($config->{debug} == 1) {
<pre>
%= dumper $lets_data
</pre>
% }
% my $btn = l('lets_APPLY');
%= form_for "letsencryptu" => (method => 'POST') => begin
% param 'trt' => $lets_data->{trt} unless param 'trt';
% my $btn = l('lets_APPLY');
%= form_for "letsencryptu" => (method => 'POST') => begin
% param 'trt' => $lets_data->{trt} unless param 'trt';
%= hidden_field 'trt' => $lets_data->{trt}
%# Inputs etc in here.
<h1 class='head'><%=l('lets_Configuration_for_Letsencrypt')%></h1>
<h2 class='subh'><%=l('lets_Manage_letsencrypt-config_settings:')%></h2>
<p class='paragraph para1'>
@ -83,6 +80,14 @@
%= select_field 'configure' => @configure_options, class => 'input'
<br></span> </p>
<p><span class=label>
%=l('lets_EMAIL')
</span><span class=data>
% param 'Email' => $lets_data->{Email} unless param 'Email';
%=email_field 'Email', class => 'emai8'
</span>span></p>
<span class='data'>
%= submit_button l('lets_Save'), class => 'action subm9'
</span>
@ -90,7 +95,8 @@
<span class='data'>
%= submit_button l('lets_Back'), class => 'action back', onclick =>'history.back()'
</span>
%# Probably finally by a submit.
%end
</div>

View File

@ -1,12 +1,14 @@
/*
Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-05 13:20:33
Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-17 14:48:52
*/
.Letsencrypt-panel {}
.name {}
.rout {}
.butt2 {}
.butt3 {}
.butt4 {}
.grou {}
.link2 {}
.link3 {}
.link4 {}
.endg {}
.subh2 {}
.read4 {}
.read5 {}
@ -21,7 +23,6 @@ thead .tabl1 {}
tbody .tabl1 {}
.name {}
.rout {}
.head {}
.subh {}
.para1 {}
.sele1 {}
@ -33,21 +34,28 @@ tbody .tabl1 {}
.sele7 {}
.emai8 {}
.subm9 {}
.back10 {}
.name {}
.rout {}
.head {}
.subh {}
.text1 {}
.subm2 {}
.back2 {}
.name {}
.rout {}
.head {}
.subh {}
.text1 {}
.subm2 {}
.back2 {}
.name {}
.rout {}
.head {}
.subh {}
.read1 {}
.text2 {}
.back3 {}
.inline-buttons {
.inline-buttons {
display: flex; /* Use flexbox to arrange items horizontally */
gap: 10px; /* Optional: Add space between buttons */
}

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-13 16:40:01
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-17 14:48:52
%#
% layout 'default', title => "Sme server 2 - Letsencrypt certificate", share_dir => './';
%# css specific to this panel:
@ -8,9 +8,10 @@
<div id="module" class="module Letsencrypt-panel">
% if ($config->{debug} == 1) {
<p>
<pre>
%= dumper $c->current_route
</p>
%# dumper $lets_data->{trt}
</pre>
% }
<h1><%=$title%></h1>

View File

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

View File

@ -129,7 +129,8 @@ sub do_update {
my $c = shift;
$c->app->log->info($c->log_req);
my $modul = '';
my %${prefix}_data = ();
my $title = $c->l('${prefix}_${MenuDescription}');
@ -159,9 +160,14 @@ sub do_update {
</tal:block>
if ($ret ne "ok") {
# return to the panel with error message
${prefix}_data{trt} = $thispanel;
$c->stash(error => $c->l($ret));
$c->render("${lcPackageName}");
$c->stash(
title => $title,
modul => $modul,
${prefix}_data => \%${prefix}_data
);
$c->render( template => "${lcPackageName}" );
} else {
#Do whatever is needed, including writing values to the DB
<tal:block tal:repeat="panel panels">

View File

@ -112,7 +112,7 @@
</span><span class=data>
% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';
%=email_field '${Name}', class => 'emai${type_serial}'
</span>span></p>
</span></p>
]]>
</Email>

View File

@ -29,7 +29,7 @@ ini_file_path = os.path.expanduser("~/.smegit/conf")
OPENAI_API_KEY = ""
# Configure the basic logging system
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# Create a logger
logger = logging.getLogger(__name__)