Initial upload

This commit is contained in:
Brian Read 2024-04-09 09:36:36 +00:00
parent 21e377a22e
commit 3926fb5a64
4 changed files with 326 additions and 0 deletions

50
Targets/Nfsshare.html.ep Normal file
View File

@ -0,0 +1,50 @@
% layout 'default', title => "Sme server 2 - NFS data share", share_dir => './';
% content_for 'module' => begin
<div id="module" class="module Nfsshare-panel">
% if ($config->{debug} == 1) {
<p>
%= dumper $c->current_route
</p>
% }
<h1><%=$title%></h1>
% if ( stash('modul') ) {
%= $c->render_to_string(inline => stash('modul') );
% }
%if ($nfs_data->{first}) {
<br><p>
%=$c->render_to_string(inline =>$c->l($nfs_data->{first}))
</p>
%} elsif ($nfs_data->{success}) {
<div class='sme-border'>
<h2> Operation Status Report</h2><p>
%= $c->l($nfs_data->{success});
</p>
</div>
%} elsif ($nfs_data->{error}) {
<div class='sme-error'>
<h2> Operation Status Report - error</h2><p>
%= $c->l($nfs_data->{error});
</p>
</div>
%}
%#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'
%}
</div>
%end

135
Targets/Nfsshare.pm Normal file
View File

@ -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} = <route>;
$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;

122
Targets/_nfs_PARAMS.html.ep Normal file
View File

@ -0,0 +1,122 @@
<div id="Nfsshare-PARAMS">
<script>
window.onload = function() {
SelectInput();
};
</script>
<h2>
%= l("nfs Hello PARAMS");
</h2>
% 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.
<h2>Manage NFS Ibay settings:</h2><p>These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays/$(STASH:ibayname)/files</p>
<p><span class=label>
%=l('Information Bay name'), class => 'label'
</span><span class=data>
%= stash("IbayName"), class => 'data'
</span></p>
<p><span class=label>
%=l('Share owner Group')
</span><span class=data>
% 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'
<br></span> </p>
<p><span class=label>
%=l('Enable the NFS Share')
</span><span class=data>
% my @EnableNFSshare_options = ['Disabled', 'Enabled'];
% param 'EnableNFSshare' => $nfs_data->{EnableNFSshare} unless param 'EnableNFSshare';
%= select_field 'EnableNFSshare' => @EnableNFSshare_options, class => 'input'
<br></span> </p>
<p><span class=label>
%=l('EnableShare on local network')
</span><span class=data>
% my @ShareOnLocalNetwork_options = ['Disabled', 'Enabled'];
% param 'ShareOnLocalNetwork' => $nfs_data->{ShareOnLocalNetwork} unless param 'ShareOnLocalNetwork';
%= select_field 'ShareOnLocalNetwork' => @ShareOnLocalNetwork_options, class => 'input'
<br></span> </p>
<p>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).</p>
<span class=label>
%=l('NFS Client(s) allowed.')
</span><span class=data>
% param 'NFSClientsAllowed' => $nfs_data->{NFSClientsAllowed} unless param 'NFSClientsAllowed';
%= text_area 'NFSClientsAllowed', cols=>50, rows=>15
</span><br>
<p><span class=label>
%=l('File system permissions')
</span><span class=data>
% my @FileSystemPermissions_options = ['Read only', 'Read and Write'];
% param 'FileSystemPermissions' => $nfs_data->{FileSystemPermissions} unless param 'FileSystemPermissions';
%= select_field 'FileSystemPermissions' => @FileSystemPermissions_options, class => 'input'
<br></span> </p>
<p><span class=label>
%=l('Write (a)synchronously.')
</span><span class=data>
% my @WriteAsync_options = ['Synchronous', 'Asynchronous'];
% param 'WriteAsync' => $nfs_data->{WriteAsync} unless param 'WriteAsync';
%= select_field 'WriteAsync' => @WriteAsync_options, class => 'input'
<br></span> </p>
<p><span class=label>
%=l('Delays the disk writings.')
</span><span class=data>
% my @DelayWrite_options = ['Write delay', 'No write delay'];
% param 'DelayWrite' => $nfs_data->{DelayWrite} unless param 'DelayWrite';
%= select_field 'DelayWrite' => @DelayWrite_options, class => 'input'
<br></span> </p>
<p><span class=label>
%=l('Squash the power of users.')
</span><span class=data>
% 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'
<br></span> </p>
<p><span class=label>
%=l('Browse the parent folders')
</span><span class=data>
% my @BrowseParents_options = ['Hide folder', 'Show folder'];
% param 'BrowseParents' => $nfs_data->{BrowseParents} unless param 'BrowseParents';
%= select_field 'BrowseParents' => @BrowseParents_options, class => 'input'
<br></span> </p>
<p><span class=label>
%=l('Requests on secure ports.')
</span><span class=data>
% my @SecurePorts_options = ['Secure', 'Insecure'];
% param 'SecurePorts' => $nfs_data->{SecurePorts} unless param 'SecurePorts';
%= select_field 'SecurePorts' => @SecurePorts_options, class => 'input'
<br></span> </p>
<p>Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank.</p>
<p><span class=label>
%=l('Set the UID.')
</span><span class=data>
% param 'SetUID' => $nfs_data->{SetUID} unless param 'SetUID';
%= text_field 'SetUID', size => '60', class => 'input'
<br></span></p>
<p><span class=label>
%=l('Set the GID.')
</span><span class=data>
% param 'SetGID' => $nfs_data->{SetGID} unless param 'SetGID';
%= text_field 'SetGID', size => '60', class => 'input'
<br></span></p>
<span class='data'>
%= submit_button l('Save'), class => 'action'
</span>
%# Probably finally by a submit.
% end
</div>

View File

@ -0,0 +1,19 @@
<div id="Nfsshare-TABLE">
<script>
window.onload = function() {
SelectInput();
};
</script>
<h2>
%= l("nfs Hello TABLE");
</h2>
% 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
</div>