201 lines
7.0 KiB
Perl
201 lines
7.0 KiB
Perl
#
|
|
# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-01-20 16:21:33
|
|
#
|
|
#
|
|
# Routines to be edited by the developer to provide content and validation for parameters
|
|
# and provison of the control data for table(s)
|
|
#
|
|
use esmith::util;
|
|
use esmith::util::network;
|
|
use esmith::ConfigDB;
|
|
use esmith::HostsDB;
|
|
use esmith::AccountsDB;
|
|
use esmith::NetworksDB;
|
|
use esmith::DomainsDB;
|
|
|
|
use constant FALSE => 0;
|
|
use constant TRUE => 1;
|
|
|
|
|
|
#The most common ones
|
|
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");
|
|
|
|
# Validation routines - parameters for each panel
|
|
|
|
sub validate_STATUS {
|
|
my $c = shift;
|
|
my $prefix_data = shift; #Data hash as parameter
|
|
# Validation for each field
|
|
my $ret = "";
|
|
|
|
if (! TRUE) #validate $c->param('UPSStatus')
|
|
{$ret .= 'Validation for UPSStatus failed';}
|
|
if ($ret eq "") {$ret = 'ok';}
|
|
return $ret;
|
|
}
|
|
|
|
sub validate_CONFIG {
|
|
my $c = shift;
|
|
my $prefix_data = shift; #Data hash as parameter
|
|
# Validation for each field
|
|
my $ret = "";
|
|
|
|
if (! TRUE) #validate $c->param('status')
|
|
{$ret .= 'Validation for status failed';}
|
|
if (! TRUE) #validate $c->param('Nutmode')
|
|
{$ret .= 'Validation for Nutmode failed';}
|
|
if (! TRUE) #validate $c->param('SlaveUPS_Name')
|
|
{$ret .= 'Validation for SlaveUPS_Name failed';}
|
|
if (! TRUE) #validate $c->param('MasterUPS_Name')
|
|
{$ret .= 'Validation for MasterUPS_Name failed';}
|
|
if (! TRUE) #validate $c->param('UPS_Model')
|
|
{$ret .= 'Validation for UPS_Model failed';}
|
|
if (! TRUE) #validate $c->param('UPS_Device')
|
|
{$ret .= 'Validation for UPS_Device failed';}
|
|
if (! TRUE) #validate $c->param('UPS_gen_Type')
|
|
{$ret .= 'Validation for UPS_gen_Type failed';}
|
|
if (! TRUE) #validate $c->param('UPS_gen_Mfr')
|
|
{$ret .= 'Validation for UPS_gen_Mfr failed';}
|
|
if (! TRUE) #validate $c->param('UPS_gen_Model')
|
|
{$ret .= 'Validation for UPS_gen_Model failed';}
|
|
if ($ret eq "") {$ret = 'ok';}
|
|
return $ret;
|
|
}
|
|
|
|
|
|
# Get singleton data for each panel
|
|
|
|
sub get_data_for_panel_STATUS {
|
|
# Return a hash with the fields required which will be loaded into the shared data
|
|
my $c = shift;
|
|
my %ret = (
|
|
'Data1'=>'Data for STATUS', #Example
|
|
# fields from Inputs in STATUS $fields['STATUS']
|
|
'UPSStatus'=>'UPSStatus contents',
|
|
|
|
);
|
|
return %ret;
|
|
}
|
|
|
|
sub get_data_for_panel_CONFIG {
|
|
# Return a hash with the fields required which will be loaded into the shared data
|
|
my $c = shift;
|
|
my %ret = (
|
|
'Data1'=>'Data for CONFIG', #Example
|
|
# fields from Inputs in CONFIG $fields['CONFIG']
|
|
'status'=>'status contents',
|
|
'Nutmode'=>'Nutmode contents',
|
|
'SlaveUPS_Name'=>'SlaveUPS_Name contents',
|
|
'MasterUPS_Name'=>'MasterUPS_Name contents',
|
|
'UPS_Model'=>'UPS_Model contents',
|
|
'UPS_Device'=>'UPS_Device contents',
|
|
'UPS_gen_Type'=>'UPS_gen_Type contents',
|
|
'UPS_gen_Mfr'=>'UPS_gen_Mfr contents',
|
|
'UPS_gen_Model'=>'UPS_gen_Model contents',
|
|
|
|
);
|
|
return %ret;
|
|
}
|
|
|
|
|
|
|
|
# Get control data for table(s)
|
|
|
|
|
|
|
|
# Return hash with values from row in which link clicked on table
|
|
|
|
sub get_selected_STATUS {
|
|
my $c = shift;
|
|
my $selected = shift; #Parameter is name of selected row.
|
|
my $is_new_record = shift; #Indicates new record required (defaults)
|
|
my %ret = {};
|
|
return $ret;
|
|
}
|
|
|
|
sub get_selected_CONFIG {
|
|
my $c = shift;
|
|
my $selected = shift; #Parameter is name of selected row.
|
|
my $is_new_record = shift; #Indicates new record required (defaults)
|
|
my %ret = {};
|
|
return $ret;
|
|
}
|
|
|
|
|
|
#after sucessful modify or create or whatever and submit then perfom (if the params validate)
|
|
|
|
sub perform_STATUS {
|
|
my $c = shift;
|
|
my $prefix_data = shift; #Data hash as parameter
|
|
my $ret = "";
|
|
my $db = $cdb; #maybe one of the others
|
|
my $dbkey = 'ChangeThis';
|
|
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
|
|
|
|
if (! TRUE) #copy or perform with value: UPSStatus e.g. $db->set_prop($dbkey,'UPSStatus',$c->param('UPSStatus'),type=>'service'))
|
|
{$ret .= 'Perform/save failed for UPSStatus';}
|
|
if ($ret eq "") {$ret = 'ok';}
|
|
return $ret;
|
|
}
|
|
|
|
sub perform_CONFIG {
|
|
my $c = shift;
|
|
my $prefix_data = shift; #Data hash as parameter
|
|
my $ret = "";
|
|
my $db = $cdb; #maybe one of the others
|
|
my $dbkey = 'ChangeThis';
|
|
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
|
|
|
|
if (! TRUE) #copy or perform with value: status e.g. $db->set_prop($dbkey,'status',$c->param('status'),type=>'service'))
|
|
{$ret .= 'Perform/save failed for status';}
|
|
if (! TRUE) #copy or perform with value: Nutmode e.g. $db->set_prop($dbkey,'Nutmode',$c->param('Nutmode'),type=>'service'))
|
|
{$ret .= 'Perform/save failed for Nutmode';}
|
|
if (! TRUE) #copy or perform with value: SlaveUPS_Name e.g. $db->set_prop($dbkey,'SlaveUPS_Name',$c->param('SlaveUPS_Name'),type=>'service'))
|
|
{$ret .= 'Perform/save failed for SlaveUPS_Name';}
|
|
if (! TRUE) #copy or perform with value: MasterUPS_Name e.g. $db->set_prop($dbkey,'MasterUPS_Name',$c->param('MasterUPS_Name'),type=>'service'))
|
|
{$ret .= 'Perform/save failed for MasterUPS_Name';}
|
|
if (! TRUE) #copy or perform with value: UPS_Model e.g. $db->set_prop($dbkey,'UPS_Model',$c->param('UPS_Model'),type=>'service'))
|
|
{$ret .= 'Perform/save failed for UPS_Model';}
|
|
if (! TRUE) #copy or perform with value: UPS_Device e.g. $db->set_prop($dbkey,'UPS_Device',$c->param('UPS_Device'),type=>'service'))
|
|
{$ret .= 'Perform/save failed for UPS_Device';}
|
|
if (! TRUE) #copy or perform with value: UPS_gen_Type e.g. $db->set_prop($dbkey,'UPS_gen_Type',$c->param('UPS_gen_Type'),type=>'service'))
|
|
{$ret .= 'Perform/save failed for UPS_gen_Type';}
|
|
if (! TRUE) #copy or perform with value: UPS_gen_Mfr e.g. $db->set_prop($dbkey,'UPS_gen_Mfr',$c->param('UPS_gen_Mfr'),type=>'service'))
|
|
{$ret .= 'Perform/save failed for UPS_gen_Mfr';}
|
|
if (! TRUE) #copy or perform with value: UPS_gen_Model e.g. $db->set_prop($dbkey,'UPS_gen_Model',$c->param('UPS_gen_Model'),type=>'service'))
|
|
{$ret .= 'Perform/save failed for UPS_gen_Model';}
|
|
if ($ret eq "") {$ret = 'ok';}
|
|
return $ret;
|
|
}
|
|
|
|
|
|
sub create_link{
|
|
# WIP
|
|
my ($c,$route, $panel, $index) = @_;
|
|
my $link = "$route?trt=$panel&Selected=$index";
|
|
return $link;
|
|
}
|
|
|
|
sub get_model_options {
|
|
|
|
# Execute the RPM command and capture the output
|
|
my @output = qx{rpm -ql nut | grep /usr/sbin};
|
|
|
|
# Check for errors
|
|
if ($? != 0) {
|
|
warn "Error executing command: $!";
|
|
return ['Error occurred'];
|
|
}
|
|
|
|
# Remove "/usr/sbin" from the front of each line
|
|
s{^/usr/sbin}{} for @output;
|
|
|
|
# Trim whitespace from each element and return the array
|
|
chomp(@output); # Remove newline characters from each line
|
|
return ["fred","Art"] #@output; # Return the array of modified output lines
|
|
}
|
|
1; |