2024-04-09 11:36:36 +02:00
|
|
|
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}
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2024-04-25 17:23:07 +02:00
|
|
|
#
|
|
|
|
# Scheme of things:
|
|
|
|
#
|
|
|
|
#main:
|
|
|
|
##
|
|
|
|
## Initial entry
|
|
|
|
##
|
|
|
|
#set initial panel
|
|
|
|
#for initial panel:
|
|
|
|
# load up _data hash with DB fields
|
|
|
|
# load up stash with pointer(s) to control fields hash(= get-))
|
|
|
|
#render initial panel
|
|
|
|
#
|
|
|
|
#do_display
|
|
|
|
##
|
|
|
|
## Return after submit pushed on panel
|
|
|
|
##
|
|
|
|
#load up all params into local hash
|
|
|
|
# by panel:
|
|
|
|
# by param:
|
|
|
|
# validate param (return ret = ok or error message) - call validate-
|
|
|
|
# break out on error
|
|
|
|
#if validation not ok
|
|
|
|
# render back to current panel with error message in stash
|
|
|
|
#otherwise
|
|
|
|
# By panel:
|
|
|
|
# Copy back to DB any that have changed (how to easily tell if it has changed?)
|
|
|
|
# do whatever is required (inc signal_event smeserver-<whatever>-update?)
|
|
|
|
# set success
|
|
|
|
# call main?
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2024-04-25 17:23:07 +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 {
|
|
|
|
|
|
|
|
my $c = shift;
|
|
|
|
$c->app->log->info( $c->log_req );
|
|
|
|
|
|
|
|
my %nfs_data = ();
|
|
|
|
my $title = $c->l("nfs_NFS data share");
|
|
|
|
my $modul = '';
|
|
|
|
|
2024-04-25 17:23:07 +02:00
|
|
|
$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
|
|
|
|
# which DB
|
2024-04-25 17:23:07 +02:00
|
|
|
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
|
|
|
|
2024-04-25 17:23:07 +02:00
|
|
|
# and table control fields
|
|
|
|
$c->stash(ibays=>get_ibays());
|
|
|
|
|
|
|
|
|
2024-04-09 11:36:36 +02:00
|
|
|
$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:
|
2024-04-25 17:23:07 +02:00
|
|
|
my @result;
|
2024-04-09 11:36:36 +02:00
|
|
|
foreach my $key (keys %params) {
|
|
|
|
my $value = $params{$key};
|
2024-04-25 17:23:07 +02:00
|
|
|
push @result, { $key => $value };
|
2024-04-09 11:36:36 +02:00
|
|
|
$c->app->log->debug("$key: $value");
|
|
|
|
}
|
|
|
|
|
|
|
|
# the value of trt will tell you which panel has returned
|
2024-04-24 17:09:23 +02:00
|
|
|
my $trt = $c->param('trt') || 'TABLE' ; #hidden control on every form.
|
2024-04-09 11:36:36 +02:00
|
|
|
my $ret = 'ok';
|
|
|
|
#Validate the parameters accordingly
|
2024-04-25 17:23:07 +02:00
|
|
|
my $thispanel;
|
2024-04-09 11:36:36 +02:00
|
|
|
|
2024-04-25 17:23:07 +02:00
|
|
|
if ($trt eq 'PARAMS'){
|
|
|
|
#Validate form parameters for panel PARAMS
|
|
|
|
$ret = validate_PARAMS();
|
|
|
|
$thispanel = 'PARAMS';
|
|
|
|
}
|
2024-04-09 11:36:36 +02:00
|
|
|
|
2024-04-25 17:23:07 +02:00
|
|
|
if ($trt eq 'TABLE'){
|
|
|
|
#Validate form parameters for panel TABLE
|
|
|
|
$ret = validate_TABLE();
|
|
|
|
$thispanel = 'TABLE';
|
|
|
|
}
|
2024-04-09 11:36:36 +02:00
|
|
|
|
2024-04-25 17:23:07 +02:00
|
|
|
if ($ret eq "ok") {
|
|
|
|
#Do whatever is needed, including writing values to the DB
|
|
|
|
my $db = $cdb; #pickup local or global db or Default to config
|
|
|
|
|
|
|
|
# anything else here...
|
|
|
|
$c->stash( success => $c->l("$thispanel successfull message"));
|
|
|
|
$c->stash(
|
|
|
|
title => $title,
|
|
|
|
nfs_data => \%nfs_data
|
|
|
|
# Extra data in here - repeat for each stash data entry needed for panels
|
|
|
|
);
|
|
|
|
nfs_data{'trt'} = 'TABLE';
|
|
|
|
$c->render("Nfsshare");
|
|
|
|
}
|
2024-04-09 11:36:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|