From 9840d4171eaf89661a5143372adcce30083d996b Mon Sep 17 00:00:00 2001 From: Brian Read Date: Wed, 24 Apr 2024 16:09:23 +0100 Subject: [PATCH] Add Table creation code --- Targets/Nfsshare.pm | 49 +++++++++++++++++++---------- Targets/_nfs_PARAMS.html.ep | 26 ++++++++++----- Targets/_nfs_TABLE.html.ep | 25 ++++++++++++++- Targets/nfsshare_en.lex | 35 +++++++++++---------- Templates/controller.pm.tem | 37 ++++++++++++++-------- Templates/html_controls.html.ep.xml | 26 +++++++++++++-- nfsshare.json5 | 29 +++++++++++------ sm2gen-ImportJSON5.py | 20 ++++++++---- 8 files changed, 174 insertions(+), 73 deletions(-) diff --git a/Targets/Nfsshare.pm b/Targets/Nfsshare.pm index 67de87a..093ff16 100644 --- a/Targets/Nfsshare.pm +++ b/Targets/Nfsshare.pm @@ -35,11 +35,11 @@ use esmith::DomainsDB; #The most common ones -our $db = esmith::ConfigDB->open() || die("Couldn't open config db"); +our $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); our $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); our $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db"); -our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); -our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); +our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); +our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); sub main { @@ -50,7 +50,12 @@ sub main { my $title = $c->l("nfs_NFS data share"); my $modul = ''; - $nfs_data{trt} = 'PARAMS'; + $nfs_data{trt} = 'TABLE'; + + #Load any DB entries into the _data area so as they are preset in the form + # which DB + my $db = $cdb; #Default to config + $c->stash( title => $title, @@ -81,28 +86,38 @@ sub do_update { } # the value of trt will tell you which panel has returned - my $trt = $c->param('trt') || 'PARAMS' ; #hidden control on every form. + my $trt = $c->param('trt') || 'TABLE' ; #hidden control on every form. my $ret = 'ok'; #Validate the parameters accordingly if ($trt eq 'PARAMS'){ - #Validate for panel PARAMS - # set $ret = $c->l('Error message') if invalid' + #Validate form parameters for panel PARAMS + # and set $ret = $c->l('Error message') if invalid' + # otherwise set $ret to "ok" + if ($ret ne "ok"){ + $c->stash(error => $c->l($ret)) + } else { + #Do whatever is needed, including writing values to the DB + my $db = $cdb; #Default to config + + + } $c->stash( success => $c->l('ok message')) } if ($trt eq 'TABLE'){ - #Validate for panel TABLE - # set $ret = $c->l('Error message') if invalid' + #Validate form parameters for panel TABLE + # and set $ret = $c->l('Error message') if invalid' + # otherwise set $ret to "ok" + if ($ret ne "ok"){ + $c->stash(error => $c->l($ret)) + } else { + #Do whatever is needed, including writing values to the DB + my $db = $cdb; #Default to config + + + } $c->stash( success => $c->l('ok message')) } - if ($ret ne "ok"){ - $c->stash(error => $c->l($ret)) - } else { - $c->stash( success => $c->l('ok message')) - } - if ($ret eq 'ok'){ - #Do whatever - } # set nfs_data{trt} = ; $c->stash( title => $title, diff --git a/Targets/_nfs_PARAMS.html.ep b/Targets/_nfs_PARAMS.html.ep index 32d994d..2d3c469 100644 --- a/Targets/_nfs_PARAMS.html.ep +++ b/Targets/_nfs_PARAMS.html.ep @@ -13,7 +13,11 @@ % param 'trt' => $nfs_data->{trt} unless param 'trt'; %= hidden_field 'trt' => $nfs_data->{trt} %# Inputs etc in here. -

Manage NFS Ibay settings:

These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays/$(STASH:ibayname)/files

+

Manage NFS Ibay settings:

+

+ %= l('nfs_These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays//files') +

+

%=l('nfs_Information Bay name'), class => 'label' @@ -43,7 +47,11 @@ % param 'ShareOnLocalNetwork' => $nfs_data->{ShareOnLocalNetwork} unless param 'ShareOnLocalNetwork'; %= select_field 'ShareOnLocalNetwork' => @ShareOnLocalNetwork_options, class => 'input'

-

For writing permissions,allowing the root user and using insecure ports, you must configure a list of one IP per line, being part of the local network(s).

+ +

+ %= l('nfs_For writing permissions,allowing the root user and using insecure ports, you must configure a list of one IP per line, being part of the local network(s).') +

+ %=l('nfs_NFS Client(s) allowed') @@ -60,7 +68,7 @@

- %=l('nfs_Write (a)synchronously.') + %=l('nfs_Write (a)synchronously') % my @WriteAsync_options = ['Synchronous', 'Asynchronous']; % param 'WriteAsync' => $nfs_data->{WriteAsync} unless param 'WriteAsync'; @@ -68,7 +76,7 @@

- %=l('nfs_Delays the disk writings.') + %=l('nfs_Delays the disk writing') % my @DelayWrite_options = ['Write delay', 'No write delay']; % param 'DelayWrite' => $nfs_data->{DelayWrite} unless param 'DelayWrite'; @@ -76,7 +84,7 @@

- %=l('nfs_Squash the power of users.') + %=l('nfs_Squash the power of users') % my @Squash_options = ['All users squash', 'No root squash', 'root squash']; % param 'Squash' => $nfs_data->{Squash} unless param 'Squash'; @@ -92,13 +100,17 @@

- %=l('nfs_Requests on secure ports.') + %=l('nfs_Requests on secure ports') % my @SecurePorts_options = ['Secure', 'Insecure']; % param 'SecurePorts' => $nfs_data->{SecurePorts} unless param 'SecurePorts'; %= select_field 'SecurePorts' => @SecurePorts_options, class => 'input'

-

Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank.

+ +

+ %= l('nfs_Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank') +

+

%=l('nfs_Set the UID.') diff --git a/Targets/_nfs_TABLE.html.ep b/Targets/_nfs_TABLE.html.ep index bc695e1..c0b0137 100644 --- a/Targets/_nfs_TABLE.html.ep +++ b/Targets/_nfs_TABLE.html.ep @@ -13,7 +13,30 @@ % param 'trt' => $nfs_data->{trt} unless param 'trt'; %= hidden_field 'trt' => $nfs_data->{trt} %# Inputs etc in here. - +

Manage NFS Ibay settings:

+ + + + + + + + + + + % my $control_data = $self->stash('ibays'); + % foreach my $row (@$control_data) { + + + + + + + %} + +
NameDescriptionNfs statusAction
<%=$row->Name%><%=$row->Description%><%=$row->flag%><%=$row->PARAMS%>
+ + %# Probably finally by a submit. % end diff --git a/Targets/nfsshare_en.lex b/Targets/nfsshare_en.lex index 8b34ad9..d8d393c 100644 --- a/Targets/nfsshare_en.lex +++ b/Targets/nfsshare_en.lex @@ -1,20 +1,23 @@ +'nfs_Set the UID.' => 'Set the UID.' +'nfs_Requests on secure ports' => 'Requests on secure ports' +'nfs_These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays//files' => 'These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays//files' +'nfs_Delays the disk writing' => 'Delays the disk writing' +'nfs_Information Bay name' => 'Information Bay name' +'nfs_EnableShare on local network' => 'EnableShare on local network' +'nfs_For writing permissions,allowing the root user and using insecure ports, you must configure a list of one IP per line, being part of the local network(s).' => 'For writing permissions,allowing the root user and using insecure ports, you must configure a list of one IP per line, being part of the local network(s).' +'nfs Hello TABLE' => 'Hello TABLE' +'nfs_NFS Client(s) allowed' => 'NFS Client(s) allowed' +'nfs_Error message' => 'Error message' +'nfs_Browse the parent folders' => 'Browse the parent folders' 'nfs_APPLY' => 'APPLY' 'nfs_Save' => 'Save' -'nfs_Squash the power of users.' => 'Squash the power of users.' -'nfs Hello PARAMS' => 'Hello PARAMS' -'nfs_Requests on secure ports.' => 'Requests on secure ports.' -'nfs_Error message' => 'Error message' -'nfs_Enable the NFS Share' => 'Enable the NFS Share' -'nfs_NFS data share' => 'NFS data share' -'nfs_Delays the disk writings.' => 'Delays the disk writings.' -'nfs_Browse the parent folders' => 'Browse the parent folders' -'nfs_Write (a)synchronously.' => 'Write (a)synchronously.' -'nfs_NFS Client(s) allowed' => 'NFS Client(s) allowed' -'nfs_EnableShare on local network' => 'EnableShare on local network' -'nfs_Information Bay name' => 'Information Bay name' -'nfs_ok message' => 'ok message' -'nfs_Set the GID.' => 'Set the GID.' 'nfs_Share owner Group' => 'Share owner Group' -'nfs Hello TABLE' => 'Hello TABLE' -'nfs_Set the UID.' => 'Set the UID.' 'nfs_File system permissions' => 'File system permissions' +'nfs_Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank' => 'Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank' +'nfs_Enable the NFS Share' => 'Enable the NFS Share' +'nfs_Write (a)synchronously' => 'Write (a)synchronously' +'nfs_ok message' => 'ok message' +'nfs Hello PARAMS' => 'Hello PARAMS' +'nfs_Set the GID.' => 'Set the GID.' +'nfs_Squash the power of users' => 'Squash the power of users' +'nfs_NFS data share' => 'NFS data share' diff --git a/Templates/controller.pm.tem b/Templates/controller.pm.tem index 6f6daf1..da044ae 100644 --- a/Templates/controller.pm.tem +++ b/Templates/controller.pm.tem @@ -35,11 +35,11 @@ use esmith::DomainsDB; #The most common ones -our $db = esmith::ConfigDB->open() || die("Couldn't open config db"); +our $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); our $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); our $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db"); -our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); -our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); +our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); +our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); sub main { @@ -51,6 +51,13 @@ sub main { my $modul = ''; $$${prefix}_data{trt} = '${firstPanel}'; + + #Load any DB entries into the _data area so as they are preset in the form + # which DB + my $db = $$${db | 'cdb'}; #Default to config + + $$${prefix}_data{${dbentry}} = $db->prop('${dbentry}') || ${dbdefault} + $c->stash( title => $title, @@ -86,18 +93,22 @@ sub do_update { #Validate the parameters accordingly if ($trt eq '${condition}'){ - #Validate for panel ${condition} - # set $ret = $c->l('Error message') if invalid' + #Validate form parameters for panel ${condition} + # and set $ret = $c->l('Error message') if invalid' + # otherwise set $ret to "ok" + if ($ret ne "ok"){ + $c->stash(error => $c->l($ret)) + } else { + #Do whatever is needed, including writing values to the DB + my $db = $$${db | 'cdb'}; #Default to config + + $db->set_prop('${dbentry}'=> param{'${dbentry}'}; #Copy back into db + $$${prefix}_data{${dbentry}} = $db->prop('${dbentry}'); #Copy out into stash + + + } $c->stash( success => $c->l('ok message')) } - if ($ret ne "ok"){ - $c->stash(error => $c->l($ret)) - } else { - $c->stash( success => $c->l('ok message')) - } - if ($ret eq 'ok'){ - #Do whatever - } # set ${prefix}_data{trt} = ; $c->stash( title => $title, diff --git a/Templates/html_controls.html.ep.xml b/Templates/html_controls.html.ep.xml index 1aa69d3..357c05b 100644 --- a/Templates/html_controls.html.ep.xml +++ b/Templates/html_controls.html.ep.xml @@ -44,7 +44,12 @@ ]]> ${value}]]> - ${value}

]]>
+ + + %= l('${prefix}_${value}') +

+ ]]>
@@ -92,8 +97,23 @@ ]]> - + + + ${ColHead} + + + + % my $control_data = $self->stash('${Control}'); + % foreach my $row (@$control_data) { + + <%=$row->${ColContent}%> + + %} + + ]]> - + diff --git a/nfsshare.json5 b/nfsshare.json5 index 0dc9140..fadc08b 100644 --- a/nfsshare.json5 +++ b/nfsshare.json5 @@ -4,14 +4,14 @@ MenuHeading: 'Network', MenuDescription: 'NFS data share', MenuNavigation: '2000 400', - firstPanel: 'PARAMS', + firstPanel: 'TABLE', html: [ { Name: 'params', route: 'PARAMS', Header: 'NFS Share Contrib', SubHeader: 'Manage NFS Ibay settings:', - Paragraph1: 'These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays/$(STASH:ibayname)/files', + Paragraph1: 'These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays//files', Input1: { Name: 'IbayName', Type: 'Text', @@ -69,7 +69,7 @@ Input7: { Name: 'WriteAsync', Type: 'Selection', - Label: 'Write (a)synchronously.', + Label: 'Write (a)synchronously', Value: [ 'Synchronous', 'Asynchronous', @@ -78,7 +78,7 @@ Input8: { Name: 'DelayWrite', Type: 'Selection', - Label: 'Delays the disk writings.', + Label: 'Delays the disk writing', Value: [ 'Write delay', 'No write delay', @@ -88,7 +88,7 @@ Input9: { Name: 'Squash', Type: 'Selection', - Label: 'Squash the power of users.', + Label: 'Squash the power of users', Value: [ 'All users squash', 'No root squash', @@ -109,14 +109,14 @@ Input11: { Name: 'SecurePorts', Type: 'Selection', - Label: 'Requests on secure ports.', + Label: 'Requests on secure ports', Value: [ 'Secure', 'Insecure', ], Default: 0, }, - Paragraph3: 'Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank.', + Paragraph3: 'Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank', Input12: { Name: 'SetUID', Type: 'Textinput', @@ -130,7 +130,16 @@ Submit: 'Save', }, { - Name: 'select_ibay',route:"TABLE" - }, - ], + Name: 'select_ibay', + route:"TABLE", + Header: 'NFS Share Contrib', + SubHeader: 'Manage NFS Ibay settings:', + Table1: { + Type:"Table", + Control:"ibays", + TopHeadings: ['Name','Description','Nfs status', 'Action'], + Columns: ['Name','Description','flag','PARAMS'] + } + } + ] } diff --git a/sm2gen-ImportJSON5.py b/sm2gen-ImportJSON5.py index bf991ba..fe13bcb 100644 --- a/sm2gen-ImportJSON5.py +++ b/sm2gen-ImportJSON5.py @@ -182,6 +182,8 @@ if __name__ == "__main__": # Routes for each panel routes = get_all_routes(); + #print(routes) + lc_routes =lc_get_all_routes(); #File names @@ -196,8 +198,9 @@ if __name__ == "__main__": #Generate controller file try: controller_template = PageTemplateFile("Templates/controller.pm.tem") + dbentries = [] try: - controller_perl = controller_template.render(**json5_dict,conditions=routes,lcPackageName=json5_dict['PackageName'].lower()) + controller_perl = controller_template.render(dbentries=dbentries,**json5_dict,conditions=routes,lcPackageName=json5_dict['PackageName'].lower()) #print() #print(controller_perl) # Map '$ 'to '$' to overcome problem with escaping $ signs @@ -219,7 +222,7 @@ if __name__ == "__main__": #layout_mojo = layout_mojo.replace("$ ", "$") with open(layout_file, 'w') as file: file.write(layout_mojo) - print(f"{layout_file} mojo template generated ok") + print(f"{layout_file} mojo template layout file generated ok") except Exception as e: print(f"An chameleon render on layout file error occurred: {e}") #print() @@ -245,9 +248,9 @@ if __name__ == "__main__": #partial_mojo_template = partial_mojo_template.replace("$ ", "$") with open( partial_files[i], 'w') as file: file.write(partial_mojo_template) - print(f"{partial_files[i]} mojo template generated ok") + print(f"{partial_files[i]} mojo template generated ok - phase 1") except Exception as e: - print(f"An chameleon render on partial file {html['route']} occurred: {e}") + print(f"An chameleon render error on partial file {html['route']} occurred: {e}") except Exception as e: print(f"An chameleon html {html['route']} error occurred: {e}") @@ -264,7 +267,7 @@ if __name__ == "__main__": try: control_template = PageTemplate(html_controls[inner_html['Type']]) try: - control_html = control_template.render(**inner_html,prefix=prefix_is) + control_html = control_template.render(**inner_html,prefix=prefix_is) #Contents=Contents,Headings=Headings) # Map '$ 'to '$' to overcome problem with escaping $ signs #control_html = control_html.replace("$ ", "$") # Add in two tabs before each newline @@ -272,6 +275,11 @@ if __name__ == "__main__": # and an extra tab before each "%" #control_html = control_html.replace("%", "\t%") #print(control_html) + # And re-run it if the type is "table" + #if inner_html['Type'] == 'Table' + #Another scan + # print("Another scan for the table") + #Else just move on. all_controls_html = all_controls_html + control_html except Exception as e: print(f"An chameleon render on partial file control {inner_html['Name']} error occurred: {e}") @@ -291,7 +299,7 @@ if __name__ == "__main__": #simple_control_html = simple_control_html.replace("\n", "\n\t\t") all_controls_html = all_controls_html + simple_control_html except Exception as e: - print(f"An chameleon render on partial file control {inner_html['Name']} error occurred: {e}") + print(f"An chameleon render on partial file control {html_control} error occurred: {e}") except Exception as e: print(f"An chameleon template partial file control {html_control} error occurred: {e}")