SM2Gen/Targets/Nfsshare.pm

278 lines
7.4 KiB
Perl
Raw Normal View History

2024-04-09 11:36:36 +02:00
package SrvMngr::Controller::Nfsshare;
2024-04-28 13:03:06 +02:00
#
# Generated by version:SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-04-28 11:53
#
2024-04-09 11:36:36 +02:00
#----------------------------------------------------------------------
# heading : Network
# description : NFS data share
# navigation : 2000 400
#
# name : nfsshare, method : get, url : /nfsshare, ctlact : nfsshare#main
2024-04-28 13:03:06 +02:00
# name : nfsshareu, method : post, url : /nfsshareu, ctlact : nfsshare#do_update
# name : nfsshared, method : get, url : /nfsshared, ctlact : nfsshare#do_display
2024-04-09 11:36:36 +02:00
#
# routes : end
#
2024-04-28 13:03:06 +02:00
# Documentation: https://wiki.contribs.org/Nfsshare
2024-04-09 11:36:36 +02:00
#----------------------------------------------------------------------
#
# Scheme of things:
#
2024-04-28 13:03:06 +02:00
# TBA!!
2024-04-09 11:36:36 +02:00
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
2024-04-24 17:09:23 +02:00
our $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
2024-04-09 11:36:36 +02:00
our $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
our $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
2024-04-24 17:09:23 +02:00
our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
2024-04-09 11:36:36 +02:00
require '/usr/share/smanager/lib/SrvMngr/Controller/Nfsshare-Custom.pm'; #The code that is to be added by the developer
2024-04-09 11:36:36 +02:00
sub main {
2024-04-28 13:03:06 +02:00
#
# Initial entry - route is "/<whatever>"
#
#set initial panel
#for initial panel:
#Specifiy panel to enter
#load up _data hash with DB fields
#load up stash with pointer(s) to control fields hash(= get-))
#and a pointer to the prefix_data hash
#render initial panel
2024-04-09 11:36:36 +02:00
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'} = 'TABLE';
2024-04-24 17:09:23 +02:00
#Load any DB entries into the <prefix>_data area so as they are preset in the form
2024-04-28 13:03:06 +02:00
# 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
2024-04-24 17:09:23 +02:00
2024-04-09 11:36:36 +02:00
# and table control fields
2024-04-28 13:03:06 +02:00
$c->stash(ibays=>get_ibays($c));
2024-04-09 11:36:36 +02:00
$c->stash(
title => $title,
modul => $modul,
nfs_data => \%nfs_data
);
$c->render( template => "Nfsshare" );
}
2024-04-28 13:03:06 +02:00
# Post request with params - submit from a form
2024-04-09 11:36:36 +02:00
sub do_update {
2024-04-28 13:03:06 +02:00
#
# Return after submit pushed on panel (this is a post) - route is "/<whatever>u"
# parameters in the params hash.
#
#load up all params into prefix_data hash:
#By panel (series of if statements - only one executed):
#call validate-PANEL() - return ret = ok or error message
#if validation not ok:
#render back to current panel with error message in stash
#otherwise:
#By panel (series of if statements - only one executed):
#do whatever is required: call perform-PANEL() - return "ok" or Error Message
#call signal-event for any global actions specified (check it exists - error and continue?)
#if action smeserver-<whatever>-update exists
#signal_event smeserver-<whatever>-update
#call signal-event for any specific actions for thids panel (check it exists first - error and continue)
#set success in stash
#if no "nextpanel" entry:
#set firstpanel
#else
#set nextpanel
#call render
2024-04-09 11:36:36 +02:00
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;
2024-04-28 13:03:06 +02:00
#Params are available in the hash "params" - copy to the prefix_data hash
while (my ($key, $value) = each %{$c->req->params->to_hash}) {
$nfs_data{$key} = $value;
2024-04-09 11:36:36 +02:00
}
# the value of trt will tell you which panel has returned
2024-04-28 13:03:06 +02:00
my $trt = $c->param('trt') || 'TABLE'; #hidden control on every form.
2024-04-09 11:36:36 +02:00
my $ret = 'ok';
2024-04-28 13:03:06 +02:00
#Validate the parameters in a custom sub one for each panel (although only one of these will be executed)
my $thispanel;
2024-04-09 11:36:36 +02:00
if ($trt eq 'PARAMS'){
#Validate form parameters for panel PARAMS
2024-04-28 13:03:06 +02:00
$ret = validate_PARAMS(\%nfs_data);
$thispanel = 'PARAMS';
}
2024-04-09 11:36:36 +02:00
if ($trt eq 'TABLE'){
#Validate form parameters for panel TABLE
2024-04-28 13:03:06 +02:00
$ret = validate_TABLE(\%nfs_data);
$thispanel = 'TABLE';
}
2024-04-09 11:36:36 +02:00
2024-04-28 13:03:06 +02:00
if ($ret ne "ok") {
# return to the panel with error message
$c->stash(error => $c->l($ret));
$c->render("Nfsshare");
} else {
#Do whatever is needed, including writing values to the DB
2024-04-28 13:03:06 +02:00
if ($trt eq 'PARAMS'){
#do whatever is required ...
$ret = perform_PARAMS(\%nfs_data);
if ($ret ne "ok") {
# return to the panel with error message
$c->stash(error => $c->l($ret));
$c->render("Nfsshare");
} else {
$c->stash( success => $c->l("PARAMS panel action was successfull")); #A bit bland - edit it in the lex file
}
}
if ($trt eq 'TABLE'){
#do whatever is required ...
$ret = perform_TABLE(\%nfs_data);
if ($ret ne "ok") {
# return to the panel with error message
$c->stash(error => $c->l($ret));
$c->render("Nfsshare");
} else {
$c->stash( success => $c->l("TABLE panel action was successfull")); #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,
nfs_data => \%nfs_data
);
2024-04-28 13:03:06 +02:00
if ('none' eq 'none') {
$nfs_data{'trt'} = 'TABLE';
} else {
$nfs_data{'trt'} = 'none';
}
$c->render("Nfsshare");
2024-04-28 13:03:06 +02:00
}
2024-04-09 11:36:36 +02:00
}
2024-04-28 13:03:06 +02:00
sub do_display {
#
# Return after link clicked in table (this is a get) - route is "/<whatever>d"
# Expects ?trt=PANEL&selected="TableRowName" plus any other required
#
#load up all supplied params into prefix_data hash
#call get-selected-PANEL() - returns hash of all relevent parameters
#load up returned hash into prefix_data
#render - to called panel
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" - copy to the prefix_data hash
while (my ($key, $value) = each %{$c->req->params->to_hash}) {
$nfs_data{$key} = $value;
}
# the value of trt will tell you which panel has returned
my $trt = $c->param('trt') || 'TABLE'; #Indicates where to go now
# Now add in the params from the selected row from the table
my %selectedrow;
if ($trt eq 'PARAMS'){
#Validate form parameters for panel PARAMS
%selectedrow = selected_PARAMS($nfs_data{'Selected'});
}
if ($trt eq 'TABLE'){
#Validate form parameters for panel TABLE
%selectedrow = selected_TABLE($nfs_data{'Selected'});
}
#Copy in the selected row params to the prefix_data hash to pass to the panel
while (my ($key, $value) = each %selectedrow){
$nfs_data{$key} = $value;
}
# Where to go now
$nfs_data{'trt'} = $trt;
# Data for panel
$c->stash(
title => $title,
nfs_data => \%nfs_data
);
$c->render("Nfsshare");
}
2024-04-09 11:36:36 +02:00
1;