From 3926fb5a64cb2d748e8eed93ab4b15ac2787935b Mon Sep 17 00:00:00 2001 From: brianr Date: Tue, 9 Apr 2024 09:36:36 +0000 Subject: [PATCH] Initial upload --- Targets/Nfsshare.html.ep | 50 +++++++++++++ Targets/Nfsshare.pm | 135 ++++++++++++++++++++++++++++++++++++ Targets/_nfs_PARAMS.html.ep | 122 ++++++++++++++++++++++++++++++++ Targets/_nfs_TABLE.html.ep | 19 +++++ 4 files changed, 326 insertions(+) create mode 100644 Targets/Nfsshare.html.ep create mode 100644 Targets/Nfsshare.pm create mode 100644 Targets/_nfs_PARAMS.html.ep create mode 100644 Targets/_nfs_TABLE.html.ep diff --git a/Targets/Nfsshare.html.ep b/Targets/Nfsshare.html.ep new file mode 100644 index 0000000..0635265 --- /dev/null +++ b/Targets/Nfsshare.html.ep @@ -0,0 +1,50 @@ +% layout 'default', title => "Sme server 2 - NFS data share", share_dir => './'; +% content_for 'module' => begin +
+ + % if ($config->{debug} == 1) { +

+ %= dumper $c->current_route +

+ % } + +

<%=$title%>

+ + % if ( stash('modul') ) { + %= $c->render_to_string(inline => stash('modul') ); + % } + + %if ($nfs_data->{first}) { +

+ %=$c->render_to_string(inline =>$c->l($nfs_data->{first})) +

+ + %} elsif ($nfs_data->{success}) { +
+

Operation Status Report

+ %= $c->l($nfs_data->{success}); +

+
+ + %} elsif ($nfs_data->{error}) { +
+

Operation Status Report - error

+ %= $c->l($nfs_data->{error}); +

+
+ %} + + %#Routing to partials according to trt parameter. + + % if ($nfs_data->{trt} eq "PARAMS") { + %= include 'partials/_nfs_PARAMS' + %} + + % if ($nfs_data->{trt} eq "TABLE") { + %= include 'partials/_nfs_TABLE' + %} + + + +
+%end diff --git a/Targets/Nfsshare.pm b/Targets/Nfsshare.pm new file mode 100644 index 0000000..18b23bb --- /dev/null +++ b/Targets/Nfsshare.pm @@ -0,0 +1,135 @@ +package SrvMngr::Controller::Nfsshare; + +#---------------------------------------------------------------------- +# heading : Network +# description : NFS data share +# navigation : 2000 400 +# +# name : nfsshare, method : get, url : /nfsshare, ctlact : nfsshare#main +# name : nfsshared, method : post, url : /nfsshared, ctlact : nfsshare#do_update +# +# routes : end +# +# Documentation: https://wiki.contribs.org/{PackageName} +#---------------------------------------------------------------------- + +use strict; +use warnings; +use Mojo::Base 'Mojolicious::Controller'; + +use constant FALSE => 0; +use constant TRUE => 1; + +use Locale::gettext; +use SrvMngr::I18N; +use SrvMngr qw(theme_list init_session); + +use Data::Dumper; + +use esmith::util; +use esmith::HostsDB; +use esmith::AccountsDB; +use esmith::NetworksDB; +use esmith::HostsDB; +use esmith::DomainsDB; + + +#The most common ones +our $db = 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"); + +sub main { + + my $c = shift; + $c->app->log->info( $c->log_req ); + + my %nfs_data = (); + my $title = $c->l("nfs_NFS data share"); + my $modul = ''; + + $nfs_data{trt} = 'PARAMS'; + + $c->stash( + title => $title, + modul => $modul, + nfs_data => \%nfs_data + ); + $c->render( template => "Nfsshare" ); +} + +sub do_update { + my $c = shift; + $c->app->log->info($c->log_req); + + my %nfs_data = (); + my $title = $c->l("nfs_NFS data share"); + + # Accessing all POST parameters + my %params = $c->req->params->to_hash; + + # Get number of POST parameters + my $num_params = keys %params; + + #Params are available in the hash "params" + # you may use: + foreach my $key (keys %params) { + my $value = $params{$key}; + $c->app->log->debug("$key: $value"); + } + + # the value of trt will tell you which panel has returned + my $trt = $c->param('trt') || 'PARAMS' ; #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' + } + + if ($trt eq 'TABLE'){ + #Validate for panel TABLE + # set $ret = $c->l(''Error message') if invalid' + } + + 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, + nfs_data => \%nfs_data + # Extra data in here - repeat for each stash data entry needed for panels + ); + + $c->render("Nfsshare") +} + +# get routines for the stash contents here. + + +1; + + + + + + + + + + + + + + + + diff --git a/Targets/_nfs_PARAMS.html.ep b/Targets/_nfs_PARAMS.html.ep new file mode 100644 index 0000000..f7927bc --- /dev/null +++ b/Targets/_nfs_PARAMS.html.ep @@ -0,0 +1,122 @@ +
+ +

+ %= l("nfs Hello PARAMS"); +

+ % my $btn = l('APPLY'); + %= form_for "Nfsshared" => (method => 'POST') => begin + + % 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

+

+ %=l('Information Bay name'), class => 'label' + + %= stash("IbayName"), class => 'data' +

+ +

+ %=l('Share owner Group') + + % my @ShareOwnerGrp_options = ['Write = admin, Read = group', 'Write = group, Read = everyone', 'Write = group, Read = group']; + % param 'ShareOwnerGrp' => $nfs_data->{ShareOwnerGrp} unless param 'ShareOwnerGrp'; + %= select_field 'ShareOwnerGrp' => @ShareOwnerGrp_options, class => 'input' +

+ +

+ %=l('Enable the NFS Share') + + % my @EnableNFSshare_options = ['Disabled', 'Enabled']; + % param 'EnableNFSshare' => $nfs_data->{EnableNFSshare} unless param 'EnableNFSshare'; + %= select_field 'EnableNFSshare' => @EnableNFSshare_options, class => 'input' +

+ +

+ %=l('EnableShare on local network') + + % my @ShareOnLocalNetwork_options = ['Disabled', 'Enabled']; + % 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 Client(s) allowed.') + + % param 'NFSClientsAllowed' => $nfs_data->{NFSClientsAllowed} unless param 'NFSClientsAllowed'; + %= text_area 'NFSClientsAllowed', cols=>50, rows=>15 +
+ +

+ %=l('File system permissions') + + % my @FileSystemPermissions_options = ['Read only', 'Read and Write']; + % param 'FileSystemPermissions' => $nfs_data->{FileSystemPermissions} unless param 'FileSystemPermissions'; + %= select_field 'FileSystemPermissions' => @FileSystemPermissions_options, class => 'input' +

+ +

+ %=l('Write (a)synchronously.') + + % my @WriteAsync_options = ['Synchronous', 'Asynchronous']; + % param 'WriteAsync' => $nfs_data->{WriteAsync} unless param 'WriteAsync'; + %= select_field 'WriteAsync' => @WriteAsync_options, class => 'input' +

+ +

+ %=l('Delays the disk writings.') + + % my @DelayWrite_options = ['Write delay', 'No write delay']; + % param 'DelayWrite' => $nfs_data->{DelayWrite} unless param 'DelayWrite'; + %= select_field 'DelayWrite' => @DelayWrite_options, class => 'input' +

+ +

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

+ +

+ %=l('Browse the parent folders') + + % my @BrowseParents_options = ['Hide folder', 'Show folder']; + % param 'BrowseParents' => $nfs_data->{BrowseParents} unless param 'BrowseParents'; + %= select_field 'BrowseParents' => @BrowseParents_options, class => 'input' +

+ +

+ %=l('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('Set the UID.') + + % param 'SetUID' => $nfs_data->{SetUID} unless param 'SetUID'; + %= text_field 'SetUID', size => '60', class => 'input' +

+ +

+ %=l('Set the GID.') + + % param 'SetGID' => $nfs_data->{SetGID} unless param 'SetGID'; + %= text_field 'SetGID', size => '60', class => 'input' +

+ + + %= submit_button l('Save'), class => 'action' + + + %# Probably finally by a submit. + % end +
diff --git a/Targets/_nfs_TABLE.html.ep b/Targets/_nfs_TABLE.html.ep new file mode 100644 index 0000000..bc695e1 --- /dev/null +++ b/Targets/_nfs_TABLE.html.ep @@ -0,0 +1,19 @@ +
+ +

+ %= l("nfs Hello TABLE"); +

+ % my $btn = l('APPLY'); + %= form_for "Nfsshared" => (method => 'POST') => begin + + % param 'trt' => $nfs_data->{trt} unless param 'trt'; + %= hidden_field 'trt' => $nfs_data->{trt} + %# Inputs etc in here. + + %# Probably finally by a submit. + % end +