From f238fcfa705b8f6d913ec7b82bb5e7f9ec36a577 Mon Sep 17 00:00:00 2001 From: Brian Read Date: Mon, 4 Nov 2024 17:08:38 +0000 Subject: [PATCH] Add list of singleton pamraeters to custom, refine letsencrypt json --- .gitignore | 2 +- Targets/Letsencrypt/Letsencrypt-Custom.pm | 112 +++++++- Targets/Letsencrypt/Letsencrypt.pm | 130 +++++++++- .../Letsencrypt/_lets_CHECKALLDOMAINS.html.ep | 34 +++ .../_lets_CHECKALLENABLEDDOMAINS.html.ep | 34 +++ Targets/Letsencrypt/_lets_LIST.html.ep | 54 +++- Targets/Letsencrypt/_lets_PARAMS.html.ep | 26 +- Targets/Letsencrypt/letsencrypt.css | 14 +- Targets/Letsencrypt/letsencrypt.html.ep | 14 +- Targets/Letsencrypt/letsencrypt_en.lex | 62 +++-- .../letsencrypt-config/_lets_PARAMS.html.ep | 2 +- .../letsencrypt-config-Custom.pm | 2 +- .../letsencrypt-config/letsencrypt-config.css | 2 +- .../letsencrypt-config.html.ep | 2 +- .../letsencrypt-config/letsencrypt-config.pm | 2 +- .../letsencrypt-config_en.lex | 24 +- Templates/controller.pm.tem | 41 ++- Templates/custom.pm.tem | 22 +- Templates/html_controls.html.ep.xml | 11 +- Templates/layout.html.ep.tem | 2 +- Templates/partial.html.ep.tem | 5 +- html/letsencrypt-list-1.html | 61 +++++ json5/Letsencrypt.json5 | 63 ++++- json5/letsencrypt-list-1.json5 | 109 ++++++++ sm1-html-2-json5.py | 240 +++++++++--------- sm2gen.py | 39 ++- trykoji.py | 10 - 27 files changed, 868 insertions(+), 251 deletions(-) create mode 100644 Targets/Letsencrypt/_lets_CHECKALLDOMAINS.html.ep create mode 100644 Targets/Letsencrypt/_lets_CHECKALLENABLEDDOMAINS.html.ep create mode 100644 html/letsencrypt-list-1.html create mode 100644 json5/letsencrypt-list-1.json5 delete mode 100644 trykoji.py diff --git a/.gitignore b/.gitignore index 61f6aee..342ca5a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ lib/ lib64 pyvenv.cfg *.new - +*.sav diff --git a/Targets/Letsencrypt/Letsencrypt-Custom.pm b/Targets/Letsencrypt/Letsencrypt-Custom.pm index 271a526..810d17e 100644 --- a/Targets/Letsencrypt/Letsencrypt-Custom.pm +++ b/Targets/Letsencrypt/Letsencrypt-Custom.pm @@ -1,5 +1,5 @@ # -# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-18 19:00:38 +# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-04 16:03:10 # # # Routines to be edited by the developer to provide validation for parameters @@ -36,8 +36,86 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); return $ret; } + sub validate_CHECKALLDOMAINS { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + my $ret = 'ok'; + return $ret; + } + + sub validate_CHECKALLENABLEDDOMAINS { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + my $ret = 'ok'; + return $ret; + } + + +# Get singleton data for each panel + + sub get_data_for_panel_LIST { + # Return a hash with the fields required which will be loaded into the shared data + my $c = shift; + my %ret = ( + 'Data1'=>'Data for LIST', #Example + # fields from Inputs in LIST $fields['LIST'] + + 'InternalIP'=>'InternalIP contents', + + 'ExternalIP'=>'ExternalIP contents', + + 'InternetIP'=>'InternetIP contents', + + 'Issuer'=>'Issuer contents', + + 'Expiry'=>'Expiry contents', + + 'NotBefore'=>'NotBefore contents', + + + ); + return %ret; + } + + sub get_data_for_panel_PARAMS { + # Return a hash with the fields required which will be loaded into the shared data + my $c = shift; + my %ret = ( + 'Data1'=>'Data for PARAMS', #Example + # fields from Inputs in PARAMS $fields['PARAMS'] + + + ); + return %ret; + } + + sub get_data_for_panel_CHECKALLDOMAINS { + # Return a hash with the fields required which will be loaded into the shared data + my $c = shift; + my %ret = ( + 'Data1'=>'Data for CHECKALLDOMAINS', #Example + # fields from Inputs in CHECKALLDOMAINS $fields['CHECKALLDOMAINS'] + + + ); + return %ret; + } + + sub get_data_for_panel_CHECKALLENABLEDDOMAINS { + # Return a hash with the fields required which will be loaded into the shared data + my $c = shift; + my %ret = ( + 'Data1'=>'Data for CHECKALLENABLEDDOMAINS', #Example + # fields from Inputs in CHECKALLENABLEDDOMAINS $fields['CHECKALLENABLEDDOMAINS'] + + + ); + return %ret; + } + + -# Get control data for tables(s) +# Get control data for table(s) sub get_DomainList { # Return an array of hashes of the contents for each row and column for DomainList @@ -70,6 +148,22 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); return $ret; } + sub get_selected_CHECKALLDOMAINS { + my $c = shift; + my $selected = shift; #Parameter is name of selected row. + my $is_new_record = shift; #Indicates new record required (defaults) + my %ret = {}; + return $ret; + } + + sub get_selected_CHECKALLENABLEDDOMAINS { + my $c = shift; + my $selected = shift; #Parameter is name of selected row. + my $is_new_record = shift; #Indicates new record required (defaults) + my %ret = {}; + return $ret; + } + #after sucessful modify or create or whatever and submit then perfom (if the params validate) @@ -87,6 +181,20 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); return $ret; } + sub perform_CHECKALLDOMAINS { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + my $ret = 'ok'; + return $ret; + } + + sub perform_CHECKALLENABLEDDOMAINS { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + my $ret = 'ok'; + return $ret; + } + sub create_link{ # WIP diff --git a/Targets/Letsencrypt/Letsencrypt.pm b/Targets/Letsencrypt/Letsencrypt.pm index 7b75d3e..c6b03e5 100644 --- a/Targets/Letsencrypt/Letsencrypt.pm +++ b/Targets/Letsencrypt/Letsencrypt.pm @@ -1,11 +1,11 @@ package SrvMngr::Controller::Letsencrypt; # -# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-18 19:00:38 +# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-04 16:03:10 # #---------------------------------------------------------------------- -# heading : Miscellaneous -# description : letsencrypt -# navigation : 2000 400 +# heading : Network +# description : Letsencrypt certificate +# navigation : 6000 6600 # # name : letsencrypt, method : get, url : /letsencrypt, ctlact : Letsencrypt#main # name : letsencryptu, method : post, url : /letsencryptu, ctlact : Letsencrypt#do_update @@ -67,7 +67,7 @@ sub main { $c->app->log->info( $c->log_req ); my %lets_data = (); - my $title = $c->l('lets_letsencrypt'); + my $title = $c->l('lets_Letsencrypt_certificate'); my $modul = ''; $lets_data{'trt'} = 'LIST'; @@ -76,9 +76,19 @@ sub main { # which DB - this only really works if the initial panel is a PARAMS type panel and not a TABLE my $db = $cdb; #pickup local or global db or Default to config + + #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(); + # 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( @@ -119,7 +129,7 @@ sub do_update { $c->app->log->info($c->log_req); my %lets_data = (); - my $title = $c->l('lets_letsencrypt'); + my $title = $c->l('lets_Letsencrypt_certificate'); # Accessing all POST parameters my %params = $c->req->params->to_hash; @@ -151,6 +161,18 @@ sub do_update { $thispanel = 'PARAMS'; } + if ($trt eq 'CHECKALLDOMAINS'){ + #Validate form parameters for panel CHECKALLDOMAINS + $ret = $c->validate_CHECKALLDOMAINS(\%lets_data); + $thispanel = 'CHECKALLDOMAINS'; + } + + if ($trt eq 'CHECKALLENABLEDDOMAINS'){ + #Validate form parameters for panel CHECKALLENABLEDDOMAINS + $ret = $c->validate_CHECKALLENABLEDDOMAINS(\%lets_data); + $thispanel = 'CHECKALLENABLEDDOMAINS'; + } + if ($ret ne "ok") { # return to the panel with error message @@ -183,9 +205,33 @@ sub do_update { } } + if ($trt eq 'CHECKALLDOMAINS'){ + #do whatever is required ... + $ret = $c->perform_CHECKALLDOMAINS(\%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_CHECKALLDOMAINS_panel_action_was_successful')); #A bit bland - edit it in the lex file + } + } + + if ($trt eq 'CHECKALLENABLEDDOMAINS'){ + #do whatever is required ... + $ret = $c->perform_CHECKALLENABLEDDOMAINS(\%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_CHECKALLENABLEDDOMAINS_panel_action_was_successful')); #A bit bland - edit it in the lex file + } + } + # and call any signal-events needed - + # Setup shared data and call panel $c->stash( title => $title, @@ -196,7 +242,7 @@ sub do_update { } else { $lets_data{'trt'} = 'none'; } - $c->render("letsencrypt"); + $c->do_display() } } @@ -216,7 +262,7 @@ sub do_display { $c->app->log->info($c->log_req); my %lets_data = (); - my $title = $c->l('lets_letsencrypt'); + my $title = $c->l('lets_Letsencrypt_certificate'); # Accessing all parameters my %params = $c->req->params->to_hash; @@ -249,6 +295,16 @@ sub do_display { %selectedrow = $c->get_selected_PARAMS($lets_data{'Selected'},$is_new_record); } + if ($trt eq 'CHECKALLDOMAINS'){ + #Validate form parameters for panel CHECKALLDOMAINS + %selectedrow = $c->get_selected_CHECKALLDOMAINS($lets_data{'Selected'},$is_new_record); + } + + if ($trt eq 'CHECKALLENABLEDDOMAINS'){ + #Validate form parameters for panel CHECKALLENABLEDDOMAINS + %selectedrow = $c->get_selected_CHECKALLENABLEDDOMAINS($lets_data{'Selected'},$is_new_record); + } + #Copy in the selected row params to the prefix_data hash to pass to the panel while (my ($key, $value) = each %selectedrow){ @@ -257,6 +313,58 @@ sub do_display { # Where to go now $lets_data{'trt'} = $trt; + # Set up other shared data according to the panel to go to + + if ($trt eq 'LIST'){ + # 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(); + # 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 'PARAMS'){ + # 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(); + # 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 'CHECKALLDOMAINS'){ + # 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(); + # 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 'CHECKALLENABLEDDOMAINS'){ + # 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(); + # 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()); + + # Data for panel $c->stash( title => $title, @@ -264,4 +372,4 @@ sub do_display { ); $c->render("letsencrypt"); } -1; +1; \ No newline at end of file diff --git a/Targets/Letsencrypt/_lets_CHECKALLDOMAINS.html.ep b/Targets/Letsencrypt/_lets_CHECKALLDOMAINS.html.ep new file mode 100644 index 0000000..b320300 --- /dev/null +++ b/Targets/Letsencrypt/_lets_CHECKALLDOMAINS.html.ep @@ -0,0 +1,34 @@ +%# +%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-04 16:03:10 +%# +
+ + % my $btn = l('lets_APPLY'); + %= form_for "Letsencryptd" => (method => 'POST') => begin + + % param 'trt' => $lets_data->{trt} unless param 'trt'; + %= hidden_field 'trt' => $lets_data->{trt} + %# Inputs etc in here. + +

<%=l('lets_Check_all_domains')%>

+ +

<%=l('lets_Loop_through_checking_the_letsencrypt')%>

+ + + %=l('lets_All_domains_check_result') + + % param 'AllDomainsCheck' => $lets_data->{AllDomainsCheck} unless param 'AllDomainsCheck'; + %= text_area 'AllDomainsCheck', cols=>40, rows=>10, Readonly=>True +
+ + + %= submit_button l('lets_Back'), class => 'action subm2' + + + %# Probably finally by a submit. + %end +
\ No newline at end of file diff --git a/Targets/Letsencrypt/_lets_CHECKALLENABLEDDOMAINS.html.ep b/Targets/Letsencrypt/_lets_CHECKALLENABLEDDOMAINS.html.ep new file mode 100644 index 0000000..b46ed82 --- /dev/null +++ b/Targets/Letsencrypt/_lets_CHECKALLENABLEDDOMAINS.html.ep @@ -0,0 +1,34 @@ +%# +%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-04 16:03:10 +%# +
+ + % my $btn = l('lets_APPLY'); + %= form_for "Letsencryptd" => (method => 'POST') => begin + + % param 'trt' => $lets_data->{trt} unless param 'trt'; + %= hidden_field 'trt' => $lets_data->{trt} + %# Inputs etc in here. + +

<%=l('lets_Check_all_enabled_domains')%>

+ +

<%=l('lets_Loop_through_checking_the_letsencrypt')%>

+ + + %=l('lets_Enabled_domains_check_result') + + % param 'EnabledDomainsCheck' => $lets_data->{EnabledDomainsCheck} unless param 'EnabledDomainsCheck'; + %= text_area 'EnabledDomainsCheck', cols=>40, rows=>10, Readonly=>True +
+ + + %= submit_button l('lets_Back'), class => 'action subm2' + + + %# Probably finally by a submit. + %end +
\ No newline at end of file diff --git a/Targets/Letsencrypt/_lets_LIST.html.ep b/Targets/Letsencrypt/_lets_LIST.html.ep index 51ac398..b348b6c 100644 --- a/Targets/Letsencrypt/_lets_LIST.html.ep +++ b/Targets/Letsencrypt/_lets_LIST.html.ep @@ -1,5 +1,5 @@ %# -%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-18 19:00:38 +%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-04 16:03:10 %#
-

- %= l('lets_Hello_LIST'); -

% my $btn = l('lets_APPLY'); %= form_for "Letsencryptd" => (method => 'POST') => begin @@ -17,9 +14,16 @@ %= hidden_field 'trt' => $lets_data->{trt} %# Inputs etc in here. -

<%=l('lets_List_of_Domains')%>

+ %= link_to l('lets_CONFIG'), 'letsencrypt?page=0&page_stack=&Next=Next&wherenext=CONFIG_PAGE' , class=>'link link2' -

<%=l('lets_FORM_DESCRIPTION')%>

+ + %= link_to l('lets_CHECK_ALL_DOMAINS'), 'letsencrypt?page=0&page_stack=&Next=Next&wherenext=CHECK_DOMAINS_PAGE' , class=>'link link3' + + + %= link_to l('lets_CHECK_ENABLED_DOMAINS'), 'letsencrypt?page=0&page_stack=&Next=Next&wherenext=CHECK_ENABLED_DOMAINS_PAGE' , class=>'link link4' + + +

<%=l('lets_IPs_for_this_Server')%>

%=l('lets_Internal_IP') @@ -28,13 +32,45 @@ %= text_field 'InternalIP', size => '50', class => 'textinput InternalIP' , pattern=>'.*' , placeholder=>'InternalIP', Readonly=>'true'

+

+ %=l('lets_External_Interface_IP') + + % param 'ExternalIP' => $lets_data->{ExternalIP} unless param 'ExternalIP'; + %= text_field 'ExternalIP', size => '50', class => 'textinput ExternalIP' , pattern=>'.*' , placeholder=>'ExternalIP', Readonly=>'true' +

+

%=l('lets_Internet_IP') - % param 'ObserverIP' => $lets_data->{ObserverIP} unless param 'ObserverIP'; - %= text_field 'ObserverIP', size => '50', class => 'textinput ObserverIP' , pattern=>'.*' , placeholder=>'ObserverIP', Readonly=>'true' + % param 'InternetIP' => $lets_data->{InternetIP} unless param 'InternetIP'; + %= text_field 'InternetIP', size => '50', class => 'textinput InternetIP' , pattern=>'.*' , placeholder=>'InternetIP', Readonly=>'true'

+

<%=l('lets_Current_certificate_details')%>

+ +

+ %=l('lets_Issuer') + + % param 'Issuer' => $lets_data->{Issuer} unless param 'Issuer'; + %= text_field 'Issuer', size => '50', class => 'textinput Issuer' , pattern=>'.*' , placeholder=>'Issuer', Readonly=>'true' +

+ +

+ %=l('lets_Expiry') + + % param 'Expiry' => $lets_data->{Expiry} unless param 'Expiry'; + %= text_field 'Expiry', size => '50', class => 'textinput Expiry' , pattern=>'.*' , placeholder=>'Expiry', Readonly=>'true' +

+ +

+ %=l('lets_Not_Before') + + % param 'NotBefore' => $lets_data->{NotBefore} unless param 'NotBefore'; + %= text_field 'NotBefore', size => '50', class => 'textinput NotBefore' , pattern=>'.*' , placeholder=>'NotBefore', Readonly=>'true' +

+ +

<%=l('lets_List_of_Domains_and_Hosts')%>

+
@@ -68,4 +104,4 @@ %# Probably finally by a submit. %end - + \ No newline at end of file diff --git a/Targets/Letsencrypt/_lets_PARAMS.html.ep b/Targets/Letsencrypt/_lets_PARAMS.html.ep index 5ce400b..9867755 100644 --- a/Targets/Letsencrypt/_lets_PARAMS.html.ep +++ b/Targets/Letsencrypt/_lets_PARAMS.html.ep @@ -1,5 +1,5 @@ %# -%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-18 19:00:38 +%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-04 16:03:10 %#
-

- %= l('lets_Hello_PARAMS'); -

% my $btn = l('lets_APPLY'); %= form_for "Letsencryptd" => (method => 'POST') => begin @@ -28,7 +25,7 @@

%=l('lets_SERVICE_STATUS') - % my @status_options = [{'Value': 'disabled', 'Text': 'Disabled'}, {'Value': 'enabled', 'Text': 'Enabled'}, {'Value': 'test', 'Text': 'TEST'}]; + % my @status_options = [['Disabled' => 'disabled'], ['Enabled' => 'enabled'], ['TEST' => 'test']]; % param 'status' => $lets_data->{status} unless param 'status'; %= select_field 'status' => @status_options, class => 'input'

@@ -36,7 +33,7 @@

%=l('lets_HOOKSCRIPT_STATUS') - % my @hookScript_options = [{'Value': 'disabled', 'Text': 'Disabled'}, {'Value': 'enabled', 'Text': 'Enabled'}]; + % my @hookScript_options = [['Disabled' => 'disabled'], ['Enabled' => 'enabled']]; % param 'hookScript' => $lets_data->{hookScript} unless param 'hookScript'; %= select_field 'hookScript' => @hookScript_options, class => 'input'

@@ -44,7 +41,7 @@

%=l('lets_HOSTOVERRIDE_STATUS') - % my @hostOverride_options = [{'Value': 'disabled', 'Text': 'Disabled'}, {'Value': 'yes', 'Text': 'Yes'}]; + % my @hostOverride_options = [['Disabled' => 'disabled'], ['Yes' => 'yes']]; % param 'hostOverride' => $lets_data->{hostOverride} unless param 'hostOverride'; %= select_field 'hostOverride' => @hostOverride_options, class => 'input'

@@ -52,7 +49,7 @@

%=l('lets_ACCEPT_TERMS_STATUS') - % my @ACCEPT_TERMS_options = [{'Value': 'disabled', 'Text': 'Disabled'}, {'Value': 'yes', 'Text': 'Yes'}]; + % my @ACCEPT_TERMS_options = [['Disabled' => 'disabled'], ['Yes' => 'yes']]; % param 'ACCEPT_TERMS' => $lets_data->{ACCEPT_TERMS} unless param 'ACCEPT_TERMS'; %= select_field 'ACCEPT_TERMS' => @ACCEPT_TERMS_options, class => 'input'

@@ -60,7 +57,7 @@

%=l('lets_API_STATUS') - % my @API_options = [{'Value': '2', 'Text': '2'}]; + % my @API_options = [['2' => '2']]; % param 'API' => $lets_data->{API} unless param 'API'; %= select_field 'API' => @API_options, class => 'input'

@@ -68,7 +65,7 @@

%=l('lets_KEYSIZE_STATUS') - % my @keysize_options = [{'Value': '2048', 'Text': '2048'}, {'Value': '3072', 'Text': '3072'}, {'Value': '4096', 'Text': '4096'}]; + % my @keysize_options = [['2048' => '2048'], ['3072' => '3072'], ['4096' => '4096']]; % param 'keysize' => $lets_data->{keysize} unless param 'keysize'; %= select_field 'keysize' => @keysize_options, class => 'input'

@@ -76,18 +73,11 @@

%=l('lets_CONFIGUREMODE_STATUS') - % my @configure_options = [{'Value': 'all', 'Text': 'ALL'}, {'Value': 'domains', 'Text': 'Domains'}, {'Value': 'hosts', 'Text': 'HOSTS'}, {'Value': 'none', 'Text': 'NONE'}]; + % my @configure_options = [['ALL' => 'all'], ['Domains' => 'domains'], ['HOSTS' => 'hosts'], ['NONE' => 'none']]; % param 'configure' => $lets_data->{configure} unless param 'configure'; %= select_field 'configure' => @configure_options, class => 'input'

-

- %=l('lets_EMAIL') - - % param 'email' => $lets_data->{email} unless param 'email'; - %= text_field 'email', size => '50', class => 'textinput email' , pattern=>'.*' , placeholder=>'email' -

- %= submit_button l('lets_Save'), class => 'action subm9' diff --git a/Targets/Letsencrypt/letsencrypt.css b/Targets/Letsencrypt/letsencrypt.css index 0b98201..e19ee10 100644 --- a/Targets/Letsencrypt/letsencrypt.css +++ b/Targets/Letsencrypt/letsencrypt.css @@ -1,18 +1,10 @@ /* - Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-18 19:00:38 + Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-04 16:03:10 */ .Letsencrypt-panel {} .name {} .rout {} .head {} .subh {} -.para1 {} -.sele1 {} -.sele2 {} -.sele3 {} -.sele4 {} -.sele5 {} -.sele6 {} -.sele7 {} -.text8 {} -.subm9 {} +.text1 {} +.subm2 {} diff --git a/Targets/Letsencrypt/letsencrypt.html.ep b/Targets/Letsencrypt/letsencrypt.html.ep index 1d18d2c..f45b0d6 100644 --- a/Targets/Letsencrypt/letsencrypt.html.ep +++ b/Targets/Letsencrypt/letsencrypt.html.ep @@ -1,7 +1,7 @@ %# -%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-18 19:00:38 +%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-04 16:03:10 %# -% layout 'default', title => "Sme server 2 - letsencrypt", share_dir => './'; +% layout 'default', title => "Sme server 2 - Letsencrypt certificate", share_dir => './'; %# css specific to this panel: % content_for 'module' => begin %= stylesheet '/css/letsencrypt.css' @@ -50,7 +50,15 @@ %= include 'partials/_lets_PARAMS' %} + % if ($lets_data->{trt} eq "CHECKALLDOMAINS") { + %= include 'partials/_lets_CHECKALLDOMAINS' + %} + + % if ($lets_data->{trt} eq "CHECKALLENABLEDDOMAINS") { + %= include 'partials/_lets_CHECKALLENABLEDDOMAINS' + %} +
-%end +%end \ No newline at end of file diff --git a/Targets/Letsencrypt/letsencrypt_en.lex b/Targets/Letsencrypt/letsencrypt_en.lex index 28239d2..14e1fc3 100644 --- a/Targets/Letsencrypt/letsencrypt_en.lex +++ b/Targets/Letsencrypt/letsencrypt_en.lex @@ -1,33 +1,47 @@ # -# Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-18 19:00:38 +# Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-04 16:03:10 # -'lets_LABEL_LECERT' => 'LABEL LECERT', -'lets_Hello_LIST' => 'Hello LIST', -'lets_Domain_name_/_HOSTNAME' => 'Domain name / HOSTNAME', -'lets_IS_IN_CERT' => 'IS IN CERT', -'lets_Internet_IP' => 'Internet IP', -'lets_HOOKSCRIPT_STATUS' => 'HOOKSCRIPT STATUS', -'lets_Save' => 'Save', -'lets_FORM_DESCRIPTION' => 'FORM DESCRIPTION', -'lets_EMAIL' => 'Email', -'lets_Hello_PARAMS' => 'Hello PARAMS', -'lets_HOSTOVERRIDE_STATUS' => 'HOSTOVERRIDE STATUS', -'lets_Brief_description' => 'Brief description', -'lets_Internal_IP' => 'Internal IP', -'lets_CONFIG_LETSENCRYPT' => 'CONFIG LETSENCRYPT', -'lets_KEYSIZE_STATUS' => 'KEYSIZE STATUS', 'lets_CONFIGUREMODE_STATUS' => 'CONFIGUREMODE STATUS', -'lets_List_of_Domains' => 'List of Domains', -'lets_SERVICE_STATUS' => 'SERVICE STATUS', -'lets_Configuration_for_Letsencrypt' => 'Configuration for Letsencrypt', -'lets_LABEL_POINT' => 'LABEL POINT', -'lets_API_STATUS' => 'API STATUS', -'lets_letsencrypt' => 'Letsencrypt', 'lets_LIST_panel_action_was_successful' => 'LIST panel action was successful', -'lets_CHECK' => 'Check', +'lets_IS_IN_CERT' => 'IS IN CERT', +'lets_IPs_for_this_Server' => 'Ips for this Server', +'lets_LABEL_LECERT' => 'LABEL LECERT', 'lets_LABEL_NAMESERVERS' => 'LABEL NAMESERVERS', -'lets_Content' => 'Content', 'lets_ACCEPT_TERMS_STATUS' => 'ACCEPT TERMS STATUS', +'lets_HOOKSCRIPT_STATUS' => 'HOOKSCRIPT STATUS', +'lets_Check_all_enabled_domains' => 'Check all enabled domains', +'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for each configured domain wihch is enabled', +'lets_LABEL_POINT' => 'LABEL POINT', +'lets_Issuer' => 'Issuer', +'lets_CHECK_ALL_DOMAINS' => 'CHECK ALL DOMAINS', +'lets_Internet_IP' => 'Internet IP', +'lets_CHECK_ENABLED_DOMAINS' => 'CHECK ENABLED DOMAINS', +'lets_API_STATUS' => 'API STATUS', +'lets_Not_Before' => 'Not Before', +'lets_CONFIG_LETSENCRYPT' => 'CONFIG LETSENCRYPT', +'lets_Configuration_for_Letsencrypt' => 'Configuration for Letsencrypt', 'lets_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful', +'lets_CHECKALLDOMAINS_panel_action_was_successful' => 'CHECKALLDOMAINS panel action was successful', +'lets_Content' => 'Content', +'lets_KEYSIZE_STATUS' => 'KEYSIZE STATUS', +'lets_Back' => 'Back', +'lets_Domain_name_/_HOSTNAME' => 'Domain name / HOSTNAME', +'lets_Check_all_domains' => 'Check all domains', +'lets_Internal_IP' => 'Internal IP', +'lets_Save' => 'Save', +'lets_External_Interface_IP' => 'External Interface IP', +'lets_Expiry' => 'Expiry', +'lets_Brief_description' => 'Brief description', +'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for each configured domain', +'lets_HOSTOVERRIDE_STATUS' => 'HOSTOVERRIDE STATUS', +'lets_Enabled_domains_check_result' => 'Enabled domains check result', +'lets_Letsencrypt_certificate' => 'Letsencrypt certificate', +'lets_CHECKALLENABLEDDOMAINS_panel_action_was_successful' => 'CHECKALLENABLEDDOMAINS panel action was successful', +'lets_List_of_Domains_and_Hosts' => 'List of Domains and Hosts', 'lets_Manage_letsencrypt-config_settings:' => 'Manage letsencrypt-config settings:', +'lets_Current_certificate_details' => 'Current certificate details', +'lets_CONFIG' => 'Config', +'lets_SERVICE_STATUS' => 'SERVICE STATUS', 'lets_APPLY' => 'Apply', +'lets_CHECK' => 'Check', +'lets_All_domains_check_result' => 'All domains check result', diff --git a/Targets/letsencrypt-config/_lets_PARAMS.html.ep b/Targets/letsencrypt-config/_lets_PARAMS.html.ep index 050a14d..bb7c1cc 100644 --- a/Targets/letsencrypt-config/_lets_PARAMS.html.ep +++ b/Targets/letsencrypt-config/_lets_PARAMS.html.ep @@ -1,5 +1,5 @@ %# -%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-19 18:55:51 +%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-20 16:12:38 %#
-

- %= l('${prefix} Hello ${route}'); -

% my $btn = l('APPLY'); %= form_for "${PackageName}d" => (method => 'POST') => begin @@ -18,4 +15,4 @@ %# Inputs etc in here. %# Probably finally by a submit. %end -
+ \ No newline at end of file diff --git a/html/letsencrypt-list-1.html b/html/letsencrypt-list-1.html new file mode 100644 index 0000000..f91d794 --- /dev/null +++ b/html/letsencrypt-list-1.html @@ -0,0 +1,61 @@ + + + + + +SME Server sme11.thereadclan.me.uk + + + + + + + +
+ Warning: a reconfigure and reboot is required before proceeding! Failure to do so now + may leave your system in an unknown state!
+ URGENT NOTICE: As per June 30th 2024, SME Server 10 is obsolete, and potentially INSECURE. NO support will be offered for any issue found with this installed version. + Please migrate IMMEDIATELY to Koozali SME Server 11 or higher version. Failure to upgrade may lead to the compromise of this server. +
Please, consult https://wiki.koozali.org/SME_Server:Download to get last available version.
+

FORM_TITLE

+ +

FORM_DESCRIPTION

+

SERVER_IPS

< +

LABEL_INTERNALIP

192.168.1.11 +

LABEL_IP_FROM_OBSERVER

IP + CONFIG + CHECK_ALL_DOMAINS + CHECK_ENABLED_DOMAINS +

> Issuer: /C=--/ST=----/L=Ottawa/O=XYZ Corporation/OU=Main/CN=sme11.thereadclan.me.uk/emailAddress=admin@thereadclan.me.uk

Expiry: 2025-10-03T02:09:03Z

Not Before: 2024-10-03T02:09:03Z

> + +

CURRENT_LIST_OF_DOMAINS

+ +
+ + + + + + + + + +
Domain name / HOSTNAMEBrief descriptionContentLABEL_NAMESERVERSLABEL_POINTLABEL_LECERTIS_IN_CERTCHECK
thereadclan.me.ukPrimary domainPrimarylocalhostdisabledYCHECK
--> fred.thereadclan.me.ukSelflocalhostdisabledYCHECK
--> ftp.thereadclan.me.ukSelflocalhostdisabledYCHECK
--> mail.thereadclan.me.ukSelflocalhostdisabledYCHECK
--> proxy.thereadclan.me.ukSelflocalhostdisabledYCHECK
--> sme11.thereadclan.me.ukSelflocalhostdisabledYCHECK
--> wpad.thereadclan.me.ukSelflocalhostdisabledYCHECK
--> www.thereadclan.me.ukSelflocalhostdisabledYCHECK
+ + +
+ + SME Server 11.0.0
Copyright 1999-2006 Mitel Corporation
All rights reserved. + +
Copyright (c) 2013 - 2021 Koozali Foundation Inc.
+
+ + + \ No newline at end of file diff --git a/json5/Letsencrypt.json5 b/json5/Letsencrypt.json5 index bfe72a3..d1873d0 100644 --- a/json5/Letsencrypt.json5 +++ b/json5/Letsencrypt.json5 @@ -13,21 +13,61 @@ { 'Name': 'List', 'route': 'LIST', - 'Header': 'lets_List of Domains', - 'SubHeader': 'lets_FORM_DESCRIPTION', - 'Subheader': 'SERVER_IPS', - Input1: { + 'Link2': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=Next&wherenext=CONFIG_PAGE', + 'title': 'CONFIG' + }, + 'Link3': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=Next&wherenext=CHECK_DOMAINS_PAGE', + 'title': 'CHECK_ALL_DOMAINS' + }, + 'Link4': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=Next&wherenext=CHECK_ENABLED_DOMAINS_PAGE', + 'title': 'CHECK_ENABLED_DOMAINS' + }, + SubHeader2: 'IPs for this Server', + Input4: { Name: 'InternalIP', Type: 'ReadonlyText', Label: 'Internal IP', Value: 'stash("InternalIP")', }, - Input2: { - Name: 'ObserverIP', + Input5: { + Name: 'ExternalIP', + Type: 'ReadonlyText', + Label: 'External Interface IP', + Value: 'stash("ExternalIP")', + }, + Input6: { + Name: 'InternetIP', Type: 'ReadonlyText', Label: 'Internet IP', Value: 'stash("InternetIP")', }, + SubHeader3 : 'Current certificate details', + Input1: { + Name: 'Issuer', + Type: 'ReadonlyText', + Label: 'Issuer', + Value: 'stash("Issuer")', + }, + Input2: { + Name: 'Expiry', + Type: 'ReadonlyText', + Label: 'Expiry', + Value: 'stash("Expiry")', + }, + Input3: { + Name: 'NotBefore', + Type: 'ReadonlyText', + Label: 'Not Before', + Value: 'stash("NotBefore")', + }, + + SubHeader4: 'List of Domains and Hosts', 'Table1': { 'Type': 'Table', 'TableControl': 'DomainList', @@ -202,12 +242,11 @@ 'SubHeader': 'Loop through checking the letsencrypt status for each configured domain', 'Input1': { 'Type': 'Textarea', - 'Value': '', 'Name': 'AllDomainsCheck', 'Label': 'All domains check result', 'Rows':20, 'Readonly':true - } + }, 'Input2': { 'Type': 'Submit', 'Value': 'Back', @@ -219,17 +258,15 @@ 'SubHeader': 'Loop through checking the letsencrypt status for each configured domain wihch is enabled', 'Input1': { 'Type': 'Textarea', - 'Value': '', 'Name': 'EnabledDomainsCheck', 'Label': 'Enabled domains check result', - 'Rows':20 + 'Rows':20, 'Readonly':true - } + }, 'Input2': { 'Type': 'Submit', 'Value': 'Back', } } - - ] + ] } \ No newline at end of file diff --git a/json5/letsencrypt-list-1.json5 b/json5/letsencrypt-list-1.json5 new file mode 100644 index 0000000..97eca94 --- /dev/null +++ b/json5/letsencrypt-list-1.json5 @@ -0,0 +1,109 @@ +// +// Generated by sm1-html-2-json5 version:0.5 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-20 12:51:29 +// +{ + 'PackageName': 'letsencrypt-list-1', + 'prefix': '', + 'MenuHeading': 'Miscellaneous', + 'MenuDescription': 'letsencrypt-list-1', + 'MenuNavigation': '2000 400', + 'firstPanel': 'PARAMS', + 'signalEvent': 'smeserver-letsencrypt-list-1-update', + 'html': [ + { + 'Name': 'params', + 'route': 'PARAMS', + 'Header': 'FORM_TITLE', + 'SubHeader': 'CURRENT_LIST_OF_DOMAINS', + 'Link1': { + 'Type': 'Link', + 'href': 'https://wiki.koozali.org/SME_Server:Download', + 'title': 'https://wiki.koozali.org/SME_Server:Download' + }, + 'Paragraph1': 'FORM_DESCRIPTION', + 'Paragraph2': 'SERVER_IPS', + 'Paragraph3': 'LABEL_INTERNALIP', + 'Paragraph4': 'LABEL_IP_FROM_OBSERVER', + 'Link2': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=Next&wherenext=CONFIG_PAGE', + 'title': 'CONFIG' + }, + 'Link3': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=Next&wherenext=CHECK_DOMAINS_PAGE', + 'title': 'CHECK_ALL_DOMAINS' + }, + 'Link4': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=Next&wherenext=CHECK_ENABLED_DOMAINS_PAGE', + 'title': 'CHECK_ENABLED_DOMAINS' + }, + 'Paragraph5': '> Issuer: /C=--/ST=----/L=Ottawa/O=XYZ Corporation/OU=Main/CN=sme11.thereadclan.me.uk/emailAddress=admin@thereadclan.me.ukExpiry: 2025-10-03T02:09:03ZNot Before: 2024-10-03T02:09:03Z', + 'Table1': { + 'Type': 'Table', + 'TableControl': 'Table1', + 'TopHeadings': [ + 'Domain name / HOSTNAME', + 'Brief description', + 'Content', + 'LABEL_NAMESERVERS', + 'LABEL_POINT', + 'LABEL_LECERT', + 'IS_IN_CERT', + 'CHECK' + ], + 'Columns': [ + 'Table1-Domain name / HOSTNAME', + 'Table1-Brief description', + 'Table1-Content', + 'Table1-LABEL_NAMESERVERS', + 'Table1-LABEL_POINT', + 'Table1-LABEL_LECERT', + 'Table1-IS_IN_CERT', + 'Table1-CHECK' + ] + }, + 'Link5': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=First&Domain=thereadclan.me.uk&wherenext=UPDATE_ONE_DOMAIN_PAGE', + 'title': 'CHECK' + }, + 'Link6': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=First&Domain=--%3E%20fred.thereadclan.me.uk&wherenext=UPDATE_ONE_DOMAIN_PAGE', + 'title': 'CHECK' + }, + 'Link7': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=First&Domain=--%3E%20ftp.thereadclan.me.uk&wherenext=UPDATE_ONE_DOMAIN_PAGE', + 'title': 'CHECK' + }, + 'Link8': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=First&Domain=--%3E%20mail.thereadclan.me.uk&wherenext=UPDATE_ONE_DOMAIN_PAGE', + 'title': 'CHECK' + }, + 'Link9': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=First&Domain=--%3E%20proxy.thereadclan.me.uk&wherenext=UPDATE_ONE_DOMAIN_PAGE', + 'title': 'CHECK' + }, + 'Link10': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=First&Domain=--%3E%20sme11.thereadclan.me.uk&wherenext=UPDATE_ONE_DOMAIN_PAGE', + 'title': 'CHECK' + }, + 'Link11': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=First&Domain=--%3E%20wpad.thereadclan.me.uk&wherenext=UPDATE_ONE_DOMAIN_PAGE', + 'title': 'CHECK' + }, + 'Link12': { + 'Type': 'Link', + 'href': 'letsencrypt?page=0&page_stack=&Next=First&Domain=--%3E%20www.thereadclan.me.uk&wherenext=UPDATE_ONE_DOMAIN_PAGE', + 'title': 'CHECK' + } + } + ] +} \ No newline at end of file diff --git a/sm1-html-2-json5.py b/sm1-html-2-json5.py index 27468c6..51cd9ea 100644 --- a/sm1-html-2-json5.py +++ b/sm1-html-2-json5.py @@ -150,136 +150,141 @@ def sanitize_text(text): def extract_data(html): - """Extract paragraphs, inputs, tables, and pre blocks from HTML and organize them in order.""" - soup = BeautifulSoup(html, "lxml") - records = [] + """Extract paragraphs, inputs, tables, and pre blocks from HTML and organize them in order.""" + soup = BeautifulSoup(html, "lxml") + records = [] - hidden_input_names = ["page", "page_stack", ".id", "csrf_token"] + hidden_input_names = ["page", "page_stack", ".id", "csrf_token"] - header_text = None - sub_header_text = None + header_text = None + sub_header_text = None - # Counter for tables - table_counter = 0 + # Counter for tables + table_counter = 0 - # Extract elements while preserving order - for element in soup.find_all( - ["h1", "h2", "p", "pre", "input", "select", "textarea", "button", "table"] - ): - if element.name == "h1": - header_text = element.get_text(strip=True) - records.append({"Type": "Header", "Text": header_text}) + # Extract elements while preserving order + for element in soup.find_all( + ["h1", "h2", "p", "pre", "input", "select", "textarea", "button", "table","a"] + ): + if element.name == "h1": + header_text = element.get_text(strip=True) + records.append({"Type": "Header", "Text": header_text}) - elif element.name == "h2": - sub_header_text = element.get_text(strip=True) - records.append({"Type": "SubHeader", "Text": sub_header_text}) + elif element.name == "h2": + sub_header_text = element.get_text(strip=True) + records.append({"Type": "SubHeader", "Text": sub_header_text}) - elif element.name == "p": - text = element.get_text(strip=True) - if text: # Ignore empty paragraphs - # Sanitise text freom newlines,tabs and escape quotes. - sanitised_text = sanitize_text(text) - if sanitised_text == "": - continue - records.append({"Type": "Paragraph", "Text": sanitised_text}) + elif element.name == "p": + text = element.get_text(strip=True) + if text: # Ignore empty paragraphs + # Sanitise text from newlines,tabs and escape quotes. + sanitised_text = sanitize_text(text) + if sanitised_text == "": + continue + records.append({"Type": "Paragraph", "Text": sanitised_text}) - elif element.name == "pre": - text = element.get_text(strip=True) - if text: # Ensure non-empty before adding - records.append({"Type": "Preformatted", "Text": text}) + elif element.name == "pre": + text = element.get_text(strip=True) + if text: # Ensure non-empty before adding + records.append({"Type": "Preformatted", "Text": text}) - elif element.name == "input": - if ( - element.get("type") == "hidden" - or element.get("name") in hidden_input_names - ): - continue + elif element.name == "a": + title = element.get_text(strip=True) + href = element.get("href") + records.append({"Type": "Link", "href": href, "title": title}) - input_info = { - "Type": element.get("type", "text").capitalize(), - "Name": element.get("name"), - "Value": element.get("value", ""), - } - label = element.find_next("label") - input_info["Label"] = label.get_text(strip=True) if label else None - records.append(input_info) + elif element.name == "input": + if ( + element.get("type") == "hidden" + or element.get("name") in hidden_input_names + ): + continue - elif element.name == "select": - options = [ - {"Value": option.get("value"), "Text": option.get_text(strip=True)} - for option in element.find_all("option") - ] - select_info = { - "Type": "Select", - "Name": element.get("name"), - "Options": options, - "Label": element.find_previous("label").get_text(strip=True) - if element.find_previous("label") - else None, - } - records.append(select_info) + input_info = { + "Type": element.get("type", "text").capitalize(), + "Name": element.get("name"), + "Value": element.get("value", ""), + } + label = element.find_next("label") + input_info["Label"] = label.get_text(strip=True) if label else None + records.append(input_info) - elif element.name == "textarea": - textarea_info = { - "Type": "Textarea", - "Name": element.get("name"), - "Value": element.get_text(strip=True), - } - label = element.find_previous("label") - textarea_info["Label"] = label.get_text(strip=True) if label else None - records.append(textarea_info) + elif element.name == "select": + options = [ + {"Value": option.get("value"), "Text": option.get_text(strip=True)} + for option in element.find_all("option") + ] + select_info = { + "Type": "Select", + "Name": element.get("name"), + "Options": options, + "Label": element.find_previous("label").get_text(strip=True) + if element.find_previous("label") + else None, + } + records.append(select_info) - elif element.name == "button": - button_info = { - "Type": "Button", - "Name": element.get("name"), - "Value": element.get_text(strip=True), - "Label": element.find_previous("label").get_text(strip=True) - if label - else None, - } - records.append(button_info) - elif element.name == "table" and "sme-border" in element.get("class", []): - # Increment the table counter - table_counter += 1 + elif element.name == "textarea": + textarea_info = { + "Type": "Textarea", + "Name": element.get("name"), + "Value": element.get_text(strip=True), + } + label = element.find_previous("label") + textarea_info["Label"] = label.get_text(strip=True) if label else None + records.append(textarea_info) - # Prepare the TableControl format - table_control = f"Table{table_counter}" # e.g., "Table1", "Table2" - top_headings = [] - columns = [] + elif element.name == "button": + button_info = { + "Type": "Button", + "Name": element.get("name"), + "Value": element.get_text(strip=True), + "Label": element.find_previous("label").get_text(strip=True) + if label + else None, + } + records.append(button_info) - # Extract headings from the first row - first_row = element.find("tr") - if first_row: - for th in first_row.find_all("th"): - top_headings.append(th.get_text(strip=True)) + elif element.name == "table" and "sme-border" in element.get("class", []): + # Increment the table counter + table_counter += 1 - # Extract only the first data row's cell values for Columns - data_rows = element.find_all("tr")[1:] # Skip the heading row - if data_rows: - first_data_row = data_rows[0] # Take the first row of data - for idx, th in enumerate(first_row.find_all("th")): - td = ( - first_data_row.find_all("td")[idx] - if idx < len(first_data_row.find_all("td")) - else None - ) - if td: - columns.append( - f"{table_control}-{th.get_text(strip=True)}" - ) # Format as desired + # Prepare the TableControl format + table_control = f"Table{table_counter}" # e.g., "Table1", "Table2" + top_headings = [] + columns = [] - records.append( - { - "Type": "Table", - "TableControl": table_control, - "TopHeadings": top_headings, - "Columns": columns, - } - ) + # Extract headings from the first row + first_row = element.find("tr") + if first_row: + for th in first_row.find_all("th"): + top_headings.append(th.get_text(strip=True)) - return records, header_text, sub_header_text + # Extract only the first data row's cell values for Columns + data_rows = element.find_all("tr")[1:] # Skip the heading row + if data_rows: + first_data_row = data_rows[0] # Take the first row of data + for idx, th in enumerate(first_row.find_all("th")): + td = ( + first_data_row.find_all("td")[idx] + if idx < len(first_data_row.find_all("td")) + else None + ) + if td: + columns.append( + f"{table_control}-{th.get_text(strip=True)}" + ) # Format as desired + + records.append( + { + "Type": "Table", + "TableControl": table_control, + "TopHeadings": top_headings, + "Columns": columns, + } + ) + return records, header_text, sub_header_text def insert_spaces_before_caps(text): @@ -298,6 +303,7 @@ def save_to_json5(data, output_filename, package_name, header, sub_header,strVer preformatted_count = 1 input_count = 1 table_count = 1 + link_count = 1 for record in data: if record["Type"] == "Paragraph": @@ -308,6 +314,14 @@ def save_to_json5(data, output_filename, package_name, header, sub_header,strVer {f"Preformatted{preformatted_count}": record["Text"]} ) preformatted_count += 1 + elif record["Type"] == "Link": + link_structure = { + "Type": record["Type"], + "href": record["href"], + "title": record["title"] + } + structured_html.append({f"Link{link_count}": link_structure}) + link_count += 1 elif record["Type"] == "Header" or record["Type"] == "SubHeader": continue # Skip headers for input count elif record["Type"] == "Table": @@ -432,4 +446,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/sm2gen.py b/sm2gen.py index 73e43e9..ee2bf48 100644 --- a/sm2gen.py +++ b/sm2gen.py @@ -399,6 +399,35 @@ def convert_lex_to_dict(pairs_string): formatted_dict = [{"id": key, "text": value} for key, value in data_dict.items()] return formatted_dict +def extract_input_fields(json_data, value_type): + result = {} + + # Pattern to identify and strip the specified value type and surrounding brackets + pattern = re.compile(rf"{value_type}\((.*?)\)") + + # Iterate over each panel in the 'html' array + for panel in json_data['html']: + panel_name = panel['route'] + # Initialize an empty list for each panel + result[panel_name] = [] + + # Iterate over each item in the panel + for key, value in panel.items(): + if key.startswith('Input') and isinstance(value, dict): + if value.get('Type').lower() in ['readonlytext', 'text']: + input_value = value.get('Value', '') + # Match and extract the value without the value_type and parentheses + match = pattern.search(input_value) + if match: + # Extract the inner content of the matching pattern + clean_value = match.group(1) + # Take out any double quotes + clean_value = clean_value.replace('"','') + # Add the clean value to the list for the current panel + result[panel_name].append(clean_value) + + # Note: Empty lists are not removed, so all panels will be present in the result + return result if __name__ == "__main__": @@ -526,16 +555,16 @@ if __name__ == "__main__": # print(strVersion,tablecontrols,routes) # Generate controller file + dbfields = [] #extract_input_fields(json5_dict, 'db') # Params which correspond to Db fields - TBD try: controller_template = PageTemplateFile( "Templates/controller.pm.tem", CHAMELEON_DEBUG="true" ) - dbentries = get_db_fields() # Params which correspond to Db fields try: controller_perl = controller_template.render( version=strVersion, tablecontrols=tablecontrols, - dbentries=dbentries, + dbfields=dbfields, **json5_dict, panels=routes, lcPackageName=json5_dict["PackageName"].lower(), @@ -551,9 +580,13 @@ if __name__ == "__main__": # Generate Custom controller file try: custom_controller_template = PageTemplateFile("Templates/custom.pm.tem") + fields = extract_input_fields(json5_dict, 'stash') # Params which correspond to singleton values + #flatfields = flatten_hash_of_lists(fields) + #print(fields) + #quit(0) try: custom_controller_perl = custom_controller_template.render( - version=strVersion, panels=routes, tablecontrols=tablecontrols + version=strVersion, panels=routes, tablecontrols=tablecontrols, fields=fields, dbfields=dbfields ) # 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: diff --git a/trykoji.py b/trykoji.py deleted file mode 100644 index ab8f765..0000000 --- a/trykoji.py +++ /dev/null @@ -1,10 +0,0 @@ -import koji - -mytag = "mytag" -session = koji.ClientSession("http://koji.koozali.org/kojihub") -try: - repo_info = session.getRepo(mytag, koji.REPO_STATES["READY"], dist=True) - if not repo_info: - print(f"There is no active dist repo for {mytag}") -except koji.GenericError: - print(f"Tag {mytag} doesn't exist")