Typo in xml for expansion of helper plugins. Update to latest letsencryp and add nutups panel

This commit is contained in:
Brian Read 2025-01-20 12:04:42 +00:00
parent 076b604722
commit c7dc45ccb5
19 changed files with 919 additions and 60 deletions

View File

@ -1,6 +1,6 @@
package SrvMngr::Controller::Letsencrypt;
#
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:20:08
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:25:37
#
#----------------------------------------------------------------------
# heading : Network

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:20:08
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:25:37
%#
<div id="Letsencrypt-CHECKALLDOMAINS" class="partial Letsencrypt-CHECKALLDOMAINS">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:20:08
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:25:37
%#
<div id="Letsencrypt-CHECKALLENABLEDDOMAINS" class="partial Letsencrypt-CHECKALLENABLEDDOMAINS">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:20:08
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:25:37
%#
<div id="Letsencrypt-CHECKONEDOMAIN" class="partial Letsencrypt-CHECKONEDOMAIN">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:20:08
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:25:37
%#
<div id="Letsencrypt-LIST" class="partial Letsencrypt-LIST">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:20:08
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:25:37
%#
<div id="Letsencrypt-PARAMS" class="partial Letsencrypt-PARAMS">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:20:08
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:25:37
%#
% layout 'default', title => "Sme server 2 - Letsencrypt certificate", share_dir => './';
%# css specific to this panel:

View File

@ -1,54 +1,54 @@
#
# Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:20:08
# Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-09 17:25:37
#
'lets_API_STATUS' => 'ape Status',
'lets_Loop_through_and_check_the' => 'Loop through and check the letsencrypt status for a specific domain',
'lets_EMAIL' => 'Email',
'lets_Issuer' => 'Issuer',
'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for each configured domain',
'lets_CHECKONEDOMAIN_panel_action_was_successful' => 'CHECKONEDOMAIN panel action was successful',
'lets_Content' => 'Content',
'lets_KEYSIZE_STATUS' => 'Keysize Status',
'lets_Check_all_enabled_domains' => 'Check all enabled domains',
'lets_SERVICE_STATUS' => 'Service Status',
'lets_Letsencrypt_certificate' => 'Letsencrypt certificate',
'lets_CHECK_ALL_ENABLED_DOMAINS' => 'Check All Enabled Domains',
'lets_Domains_name' => 'Domains name',
'lets_Internet_IP' => 'Internet IP',
'lets_CONFIG_LETSENCRYPT' => 'confirm Letsencrypt',
'lets_Enabled_domains_check_result' => 'Enabled domains check result',
'lets_All_domains_check_result' => 'All domains check result',
'lets_CHECKALLDOMAINS_panel_action_was_successful' => 'CHECKALLDOMAINS panel action was successful',
'lets_For_this_Server' => 'For this Server',
'lets_LABEL_NAMESERVERS' => 'Label timeservers',
'lets_LABEL_LECERT' => 'Label secret',
'lets_Brief_description' => 'Brief description',
'lets_Expiry' => 'Expiry',
'lets_Not_Before' => 'Not Before',
'lets_Save' => 'Save',
'lets_Internal_IP' => 'Internal IP',
'lets_HOOKSCRIPT_STATUS' => 'Hookscript Status',
'lets_Back' => 'Back',
'lets_Domain_name_/_HOSTNAME' => 'Domain name / HOSTNAME',
'lets_IS_IN_CERT' => 'Is In cart',
'lets_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
'lets_APPLY' => 'Apply',
'lets_CHECKALLENABLEDDOMAINS_panel_action_was_successful' => 'CHECKALLENABLEDDOMAINS panel action was successful',
'lets_List_of_Domains_and_Hosts' => 'List of Domains and Hosts',
'lets_One_domain_check_result' => 'One domain check result',
'lets_CHECK_ALL_DOMAINS' => 'Check All Domains',
'lets_CONFIGUREMODE_STATUS' => 'Configuremode Status',
'lets_Manage_letsencrypt-config_settings:' => 'Manage letsencrypt-config settings',
'lets_LIST_panel_action_was_successful' => 'LIST panel action was successful',
'lets_CONFIG' => 'Config',
'lets_HOSTOVERRIDE_STATUS' => 'Hostoverride Status',
'lets_Check_just_one_domain' => 'Check just one domain',
'lets_Current_certificate_details' => 'Current certificate details',
'lets_Status_Report' => 'Status Report',
'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for each configured domain which is enabled',
'lets_ACCEPT_TERMS_STATUS' => 'Accept Terms Status',
'lets_CHECK' => 'Check',
'lets_Error_Status_Report' => 'Error Status Report',
'lets_LABEL_POINT' => 'Label Point',
'lets_Check_all_domains' => 'Check all domains',
'lets_Current_certificate_details' => 'Current certificate details',
'lets_SERVICE_STATUS' => 'Service Status',
'lets_HOOKSCRIPT_STATUS' => 'Hookscript Status',
'lets_EMAIL' => 'Email',
'lets_Brief_description' => 'Brief description',
'lets_KEYSIZE_STATUS' => 'Keysize Status',
'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for each configured domain',
'lets_LABEL_NAMESERVERS' => 'Label timeservers',
'lets_CHECKALLDOMAINS_panel_action_was_successful' => 'CHECKALLDOMAINS panel action was successful',
'lets_Letsencrypt_certificate' => 'Letsencrypt certificate',
'lets_APPLY' => 'Apply',
'lets_All_domains_check_result' => 'All domains check result',
'lets_API_STATUS' => 'ape Status',
'lets_External_Interface_IP' => 'External Interface IP',
'lets_CHECK' => 'Check',
'lets_Check_just_one_domain' => 'Check just one domain',
'lets_One_domain_check_result' => 'One domain check result',
'lets_LABEL_LECERT' => 'Label secret',
'lets_Internet_IP' => 'Internet IP',
'lets_CONFIG' => 'Config',
'lets_Check_all_enabled_domains' => 'Check all enabled domains',
'lets_Issuer' => 'Issuer',
'lets_CHECKONEDOMAIN_panel_action_was_successful' => 'CHECKONEDOMAIN panel action was successful',
'lets_CONFIG_LETSENCRYPT' => 'confirm Letsencrypt',
'lets_Content' => 'Content',
'lets_Check_all_domains' => 'Check all domains',
'lets_HOSTOVERRIDE_STATUS' => 'Hostoverride Status',
'lets_Internal_IP' => 'Internal IP',
'lets_Back' => 'Back',
'lets_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
'lets_Expiry' => 'Expiry',
'lets_Error_Status_Report' => 'Error Status Report',
'lets_For_this_Server' => 'For this Server',
'lets_List_of_Domains_and_Hosts' => 'List of Domains and Hosts',
'lets_Loop_through_and_check_the' => 'Loop through and check the letsencrypt status for a specific domain',
'lets_CHECK_ALL_DOMAINS' => 'Check All Domains',
'lets_IS_IN_CERT' => 'Is In cart',
'lets_Manage_letsencrypt-config_settings:' => 'Manage letsencrypt-config settings',
'lets_LABEL_POINT' => 'Label Point',
'lets_Domain_name_/_HOSTNAME' => 'Domain name / HOSTNAME',
'lets_LIST_panel_action_was_successful' => 'LIST panel action was successful',
'lets_Domains_name' => 'Domains name',
'lets_Loop_through_checking_the_letsencrypt' => 'Loop through checking the letsencrypt status for each configured domain which is enabled',
'lets_CHECK_ALL_ENABLED_DOMAINS' => 'Check All Enabled Domains',
'lets_CONFIGUREMODE_STATUS' => 'Configuremode Status',
'lets_Save' => 'Save',
'lets_ACCEPT_TERMS_STATUS' => 'Accept Terms Status',
'lets_Not_Before' => 'Not Before',

View File

@ -0,0 +1,177 @@
#
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2025-01-20 12:01:10
#
#
# 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('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',
'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: 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;
}
1;

311
Targets/Nutups/Nutups.pm Normal file
View File

@ -0,0 +1,311 @@
package SrvMngr::Controller::Nutups;
#
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2025-01-20 12:01:10
#
#----------------------------------------------------------------------
# heading : Network
# description : NutUPS configuration
# navigation : 6000 6700
#
# name : nutups, method : get, url : /nutups, ctlact : Nutups#main
# name : nutupsu, method : post, url : /nutupsu, ctlact : Nutups#do_update
# name : nutupsd, method : get, url : /nutupsd, ctlact : Nutups#do_display
#
# routes : end
#
# Documentation: https://wiki.contribs.org/Nutups
#----------------------------------------------------------------------
#
# Scheme of things:
#
# TBA!!
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::util::network;
use esmith::ConfigDB;
use esmith::AccountsDB;
use esmith::NetworksDB;
use esmith::HostsDB;
use esmith::DomainsDB;
require '/usr/share/smanager/lib/SrvMngr/Controller/Nutups-Custom.pm'; #The code that is to be added by the developer
sub main {
#
# 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
my $c = shift;
$c->app->log->info( $c->log_req );
#The most common ones
my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %nut_data = ();
my $title = $c->l('nut_NutUPS_configuration');
my $modul = '';
$nut_data{'trt'} = 'STATUS';
#Load any DB entries into the <prefix>_data area so as they are preset in the form
# 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
$c->do_display($nut_data{'trt'});
}
# Post request with params - submit from the form
sub do_update {
#
# 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
my $c = shift;
$c->app->log->info($c->log_req);
my $modul = '';
#The most common ones - you might want to comment out any not used.
my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %nut_data = ();
my $title = $c->l('nut_NutUPS_configuration');
# 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}) {
# $nut_data{$key} = $value;
#}
# the value of trt will tell you which panel has returned
my $trt = $c->param('trt') || 'STATUS'; #hidden control on every form.
my $ret = 'ok';
#Validate the parameters in a custom sub one for each panel (although only one of these will be executed)
my $thispanel;
if ($trt eq 'STATUS'){
#Validate form parameters for panel STATUS
$ret = $c->validate_STATUS(\%nut_data);
$thispanel = 'STATUS';
}
if ($trt eq 'CONFIG'){
#Validate form parameters for panel CONFIG
$ret = $c->validate_CONFIG(\%nut_data);
$thispanel = 'CONFIG';
}
if ($ret ne "ok"){
$c->do_display($thispanel);
} else {
#Do whatever is needed, including writing values to the DB
if ($trt eq 'STATUS'){
#do whatever is required ...
$ret = $c->perform_STATUS(\%nut_data);
if ($ret ne "ok") {
# return to the panel with error message
$c->stash(error => $c->l($ret));
$c->stash(
title => $title,
modul => $modul,
nut_data => \%nut_data
);
$c->render(template => "nutups");
} else {
$c->stash( success => $c->l('nut_STATUS_panel_action_was_successful')); #A bit bland - edit it in the lex file
}
}
if ($trt eq 'CONFIG'){
#do whatever is required ...
$ret = $c->perform_CONFIG(\%nut_data);
if ($ret ne "ok") {
# return to the panel with error message
$c->stash(error => $c->l($ret));
$c->stash(
title => $title,
modul => $modul,
nut_data => \%nut_data
);
$c->render(template => "nutups");
} else {
$c->stash( success => $c->l('nut_CONFIG_panel_action_was_successful')); #A bit bland - edit it in the lex file
}
}
# and call any signal-events needed
#TBD
# Setup shared data and call panel
if ('none' eq 'none') {
$nut_data{'trt'} = 'STATUS';
} else {
$nut_data{'trt'} = 'none';
}
$c->do_display($nut_data{'trt'});
}
}
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
#
# OR it maybe a post from the main panel to add a new record
#
#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,$trt) = @_;
$c->app->log->info($c->log_req);
#The most common ones - you might want to comment out any not used.
my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %nut_data = ();
my $title = $c->l('nut_NutUPS_configuration');
my $modul = "";
# Accessing all parameters
my %params = $c->req->params->to_hash;
# Get number of parameters
my $num_params = keys %params;
#Tag as Post or Get (ie. create new entry or edit existing one
my $is_new_record = ($c->req->method() eq 'POST');
#Params are available in the hash "params" - copy to the prefix_data hash
#while (my ($key, $value) = each %{$c->req->params->to_hash}) {
# $nut_data{$key} = $value;
#}
# the value of trt will tell you which panel has returned
if (! $trt){
$trt = $c->param('trt') || 'STATUS'; #Indicates where to go now
}
# Now add in the params from the selected row from the table
my %selectedrow;
if ($trt eq 'STATUS'){
#Validate Get selected row (if applicable) STATUS
%selectedrow = $c->get_selected_STATUS($nut_data{'Selected'},$is_new_record);
}
if ($trt eq 'CONFIG'){
#Validate Get selected row (if applicable) CONFIG
%selectedrow = $c->get_selected_CONFIG($nut_data{'Selected'},$is_new_record);
}
#Copy in the selected row params to the prefix_data hash to pass to the panel
while (my ($key, $value) = each %selectedrow){
$nut_data{$key} = $value;
}
# Where to go now
$nut_data{'trt'} = $trt;
# Set up other shared data according to the panel to go to
if ($trt eq 'STATUS'){
# pickup any other contents needed and load them into hash shared with panel
my %returned_hash;
# subroutine returns a hash directly
%returned_hash = $c->get_data_for_panel_STATUS();
# Copy each key-value pair from the returned hash to the prefix data hash
while (my ($key, $value) = each %returned_hash) {
$nut_data{$key} = $value;
}
}
if ($trt eq 'CONFIG'){
# pickup any other contents needed and load them into hash shared with panel
my %returned_hash;
# subroutine returns a hash directly
%returned_hash = $c->get_data_for_panel_CONFIG();
# Copy each key-value pair from the returned hash to the prefix data hash
while (my ($key, $value) = each %returned_hash) {
$nut_data{$key} = $value;
}
}
# and table control fields
# Data for panel
$c->stash(
title => $title,
modul => $modul,
nut_data => \%nut_data
);
$c->render(template => "nutups");
}
1;

View File

@ -0,0 +1,95 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2025-01-20 12:01:10
%#
<div id="Nutups-CONFIG" class="partial Nutups-CONFIG">
<script>
window.onload = function() {
SelectInput();
};
</script>
% if ($config->{debug} == 1) {
<pre>
%= dumper $nut_data
</pre>
% }
% my $btn = l('nut_APPLY');
%= form_for "nutupsu" => (method => 'POST') => begin
% param 'trt' => $nut_data->{trt} unless param 'trt';
%= hidden_field 'trt' => $nut_data->{trt}
%# Inputs etc in here.
<h2 class='subh2'><%=l('nut_Manage_Nutups-config_settings:')%></h2>
<p><span class=label>
%=l('nut_Nut_status')
</span><span class=data>
% my @status_options = [['Disabled' => 'disabled'], ['Enabled' => 'enabled']];
% param 'status' => $nut_data->{status} unless param 'status';
%= select_field 'status' => @status_options, class => 'input'
<br></span> </p>
<p><span class=label>
%=l('nut_Nut_mode')
</span><span class=data>
% my @Nutmode_options = [['Standalone' => 'standalone'], ['Net Server' => 'netserver'], ['Net Client ' => 'netclient']];
% param 'Nutmode' => $nut_data->{Nutmode} unless param 'Nutmode';
%= select_field 'Nutmode' => @Nutmode_options, class => 'input'
<br></span> </p>
<h2 class='subh3'><%=l('nut_if_Net_Client')%></h2>
<p><span class=label>
%=l('nut_SlaveUPS_UPSNAME@IP')
</span><span class=data>
% param 'SlaveUPS_Name' => $nut_data->{SlaveUPS_Name} unless param 'SlaveUPS_Name';
%= text_field 'SlaveUPS_Name', size => '50', class => 'textinput SlaveUPS_Name' , pattern=>'.*' , placeholder=>'SlaveUPS_Name'
<br></span></p>
<p><span class='label'>
%=l('nut_SlaveUPS_Password')
</span><span class=data>
% param 'SlaveUPS_Password' => $nut_data->{SlaveUPS_Password} unless param 'SlaveUPS_Password';
%=password_field 'SlaveUPS_Password', class => 'pass4 sme-password'
</span>span></p>
<p><span class=label>
%=l('nut_UPS_Model')
</span><span class=data>
% param 'UPS_Model' => $nut_data->{UPS_Model} unless param 'UPS_Model';
%= text_field 'UPS_Model', size => '50', class => 'textinput UPS_Model' , pattern=>'.*' , placeholder=>'UPS_Model'
<br></span></p>
<p><span class=label>
%=l('nut_UPS_Device')
</span><span class=data>
% param 'UPS_Device' => $nut_data->{UPS_Device} unless param 'UPS_Device';
%= text_field 'UPS_Device', size => '50', class => 'textinput UPS_Device' , pattern=>'.*' , placeholder=>'UPS_Device'
<br></span></p>
<h2 class='subh4'><%=l('nut_if_genericups')%></h2>
<p><span class=label>
%=l('nut_UPS_Generic_Type')
</span><span class=data>
% param 'UPS_gen_Type' => $nut_data->{UPS_gen_Type} unless param 'UPS_gen_Type';
%= text_field 'UPS_gen_Type', size => '50', class => 'textinput UPS_gen_Type' , pattern=>'.*' , placeholder=>'UPS_gen_Type'
<br></span></p>
<p><span class=label>
%=l('nut_UPS_Generic_Manufacturer')
</span><span class=data>
% param 'UPS_gen_Mfr' => $nut_data->{UPS_gen_Mfr} unless param 'UPS_gen_Mfr';
%= text_field 'UPS_gen_Mfr', size => '50', class => 'textinput UPS_gen_Mfr' , pattern=>'.*' , placeholder=>'UPS_gen_Mfr'
<br></span></p>
<p><span class=label>
%=l('nut_UPS_Generic_Model')
</span><span class=data>
% param 'UPS_gen_Model' => $nut_data->{UPS_gen_Model} unless param 'UPS_gen_Model';
%= text_field 'UPS_gen_Model', size => '50', class => 'textinput UPS_gen_Model' , pattern=>'.*' , placeholder=>'UPS_gen_Model'
<br></span></p>
%# Probably finally by a submit.
%end
</div>

View File

@ -0,0 +1,48 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2025-01-20 12:01:10
%#
<div id="Nutups-STATUS" class="partial Nutups-STATUS">
<script>
window.onload = function() {
SelectInput();
};
</script>
% if ($config->{debug} == 1) {
<pre>
%= dumper $nut_data
</pre>
% }
% my $btn = l('nut_APPLY');
%= form_for "nutupsu" => (method => 'POST') => begin
% param 'trt' => $nut_data->{trt} unless param 'trt';
%= hidden_field 'trt' => $nut_data->{trt}
%# Inputs etc in here.
<div class=inline-buttons>
<a href='nutupsd?trt=CONFIG' class='link link1'>
%= l('nut_Configure_NutUPS')
</a>
%#= link_to l('nut_Configure_NutUPS'), 'nutupsd?trt=CONFIG' , class=>'link link1'
</div>
<h2 class='subh1'><%=l('nut_Status_of_the_controlled_UPS')%></h2>
<p class='paragraph para1'>
%=l('nut_Descriptive_paragraph')
</p>
<span class=label>
%=l('nut_Status_(from_upsd)')
</span><span class=data>
% param 'UPSStatus' => $nut_data->{UPSStatus} unless param 'UPSStatus';
%= text_area 'UPSStatus', cols=>40, rows=>10, Readonly=>'true'
</span><br>
%# Probably finally by a submit.
%end
</div>

26
Targets/Nutups/nutups.css Normal file
View File

@ -0,0 +1,26 @@
/*
Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2025-01-20 12:01:10
*/
.Nutups-panel {}
.name {}
.rout {}
.grou {}
.link1 {}
.endg {}
.subh1 {}
.para1 {}
.text1 {}
.name {}
.rout {}
.subh2 {}
.sele1 {}
.sele2 {}
.subh3 {}
.text3 {}
.pass4 {}
.text5 {}
.text6 {}
.subh4 {}
.text7 {}
.text8 {}
.text9 {}

View File

@ -0,0 +1,57 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2025-01-20 12:01:10
%#
% layout 'default', title => "Sme server 2 - NutUPS configuration", share_dir => './';
%# css specific to this panel:
% content_for 'module' => begin
%= stylesheet '/css/nutups.css'
<div id="module" class="module Nutups-panel">
% if ($config->{debug} == 1) {
<pre>
%= dumper $c->current_route
%= dumper $nut_data->{trt}
</pre>
% }
<h1><%=$title%></h1>
% if ( stash('modul')) {
%= $c->render_to_string(inline => stash('modul') );
% }
%if ($c->stash('first')) {
<br><p>
%=$c->render_to_string(inline =>$c->l($c->stash('first')))
</p>
%} elsif ($c->stash('success')) {
<div class='success '>
<h2><%=$c->l('nut_Status_Report') %></h2><p>
%= $c->l($c->stash('success'));
</p>
</div>
%} elsif ($c->stash('error')) {
<div class='sme-error'>
<h2><%=$c->l('nut_Error_Status_Report') %></h2><p>
%= $c->l($c->stash('error'));
</p>
</div>
%}
%#Routing to partials according to trt parameter.
%#This ought to be cascading if/then/elsif, but is easier to just stack the if/then's rather like a case statement'
% if ($nut_data->{trt} eq "STATUS") {
%= include 'partials/_nut_STATUS'
%}
% if ($nut_data->{trt} eq "CONFIG") {
%= include 'partials/_nut_CONFIG'
%}
</div>
%end

View File

@ -0,0 +1,25 @@
#
# Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2025-01-20 12:01:10
#
'nut_Nut_mode' => 'Nut mode',
'nut_UPS_Generic_Type' => 'UPS Generic Type',
'nut_Error_Status_Report' => 'Error Status Report',
'nut_Manage_Nutups-config_settings:' => 'Manage Nutups-config settings',
'nut_if_Net_Client' => 'If Net Client',
'nut_Status_of_the_controlled_UPS' => 'Status of the controlled UPS',
'nut_Status_(from_upsd)' => 'Status from upset',
'nut_if_genericups' => 'If generic's',
'nut_NutUPS_configuration' => 'cutups configuration',
'nut_Nut_status' => 'Nut status',
'nut_UPS_Generic_Manufacturer' => 'UPS Generic Manufacturer',
'nut_Configure_NutUPS' => 'Configure cutups',
'nut_Descriptive_paragraph' => 'Descriptive paragraph',
'nut_UPS_Device' => 'UPS Device',
'nut_Status_Report' => 'Status Report',
'nut_SlaveUPS_Password' => 'slaves Password',
'nut_UPS_Model' => 'UPS Model',
'nut_APPLY' => 'Apply',
'nut_UPS_Generic_Model' => 'UPS Generic Model',
'nut_SlaveUPS_UPSNAME@IP' => 'slaves UPSNAME@IP',
'nut_CONFIG_panel_action_was_successful' => 'CONFIG panel action was successful',
'nut_STATUS_panel_action_was_successful' => 'STATUS panel action was successful',

View File

@ -1,5 +1,5 @@
<root>
<!-- Todo - add password visibility to password type -->
<!-- Todo - add password visibility to password type - DONE -->
<Select><![CDATA[
<p><span class=label>
%=l('${prefix}_${Label}')
@ -122,8 +122,8 @@
%=l('${Label}')
</span><span class=data>
% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';
%=password_field '${Name}', class => 'pass${type_serial}'
</span>span></p>
%=password_field '${Name}', class => 'pass${type_serial} sme-password'
</span></p>
]]>
</Password>
@ -252,7 +252,7 @@
</Link>
<ButtonLink><![CDATA[
<button href='${structure:href}' class='buttonlink buttonlink${type_serial}'>
<button type='button' href='${structure:href}' class='buttonlink buttonlink${type_serial}'>
%= l('${title}')
</button>
%#= button_to l('${title}'), '${structure:href}' , class=>'buttonlink buttonlink${type_serial}'

120
json5/Nutups.json5 Normal file
View File

@ -0,0 +1,120 @@
//
// Generated by sm1-html-2-json5 version:0.5 Chameleon version:4.5.4 On Python:3.12.3 at 2024-10-18 14:47:03
//
{
'PackageName': 'Nutups',
'prefix': 'nut',
'MenuHeading': 'Network',
'MenuDescription': 'NutUPS configuration',
'MenuNavigation': '6000 6700',
'firstPanel': 'STATUS',
'signalEvent': 'smeserver-nutups-update',
'html': [
{
'Name': 'Status',
'route': 'STATUS',
'Group': 'class=inline-buttons',
'Link1': {
'Type': 'Link',
'href': 'nutupsd?trt=CONFIG',
'title': 'Configure NutUPS'
},
'Endgroup': '',
SubHeader1: 'Status of the controlled UPS ',
'Paragraph1': 'Descriptive paragraph',
'Input1': {
'Type': 'Textarea',
'Name': 'UPSStatus',
'Label': 'Status (from upsd)',
'Rows':20,
'Readonly':'true'
}
},
{
'Name': 'config',
'route': 'CONFIG',
'SubHeader2': 'Manage Nutups-config settings:',
'Input1': {
'Type': 'Select',
'Value': 'Disabled',
'Name': 'status',
'Label': 'Nut status',
'Options': [
{
'Value': 'disabled',
'Text': 'Disabled'
},
{
'Value': 'enabled',
'Text': 'Enabled'
},
]
},
'Input2': {
'Type': 'Select',
'Value': '',
'Name': 'Nutmode',
'Label': 'Nut mode',
'Options': [
{
'Value': 'standalone',
'Text': 'Standalone'
},
{
'Value': 'netserver',
'Text': 'Net Server'
},
{
'Value': 'netclient',
'Text': 'Net Client '
}
]
},
SubHeader3: 'if Net Client',
Input3: {
Name: 'SlaveUPS_Name',
Type: 'Text',
Label: 'SlaveUPS UPSNAME@IP',
Value: '")',
},
Input4: {
Name: 'SlaveUPS_Password',
Type: 'Password',
Label: 'SlaveUPS Password',
Value: '',
},
Input5: {
Name: 'UPS_Model',
Type: 'Text',
Label: 'UPS Model',
Value: '',
},
Input6: {
Name: 'UPS_Device',
Type: 'Text',
Label: 'UPS Device',
Value: '',
},
SubHeader4: 'if genericups',
Input7: {
Name: 'UPS_gen_Type',
Type: 'Text',
Label: 'UPS Generic Type',
Value: '',
},
Input8: {
Name: 'UPS_gen_Mfr',
Type: 'Text',
Label: 'UPS Generic Manufacturer',
Value: '',
},
Input9: {
Name: 'UPS_gen_Model',
Type: 'Text',
Label: 'UPS Generic Model',
Value: '',
},
}
]
}

BIN
sent_bugs.db Normal file

Binary file not shown.

View File

@ -831,7 +831,7 @@ if __name__ == "__main__":
# Write the modified content back to the file
with open(partial_files[i], "w") as file:
file.writelines(lines)
logger.info(f"Content modified and saved to {partial_files[i]}")
logger.info(f"Content modified and saved to {highlight_occurrences(partial_files[i])}")
i += 1
# Create the css file (the header, followed by a dummy entry for each class created/used above)