Add space in status messages
This commit is contained in:
@@ -69,13 +69,12 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
|
||||
# Get singleton data for each panel
|
||||
|
||||
sub get_data_for_panel_STATUS {
|
||||
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',
|
||||
'UPSStatus'=>get_ups_details()
|
||||
|
||||
);
|
||||
return %ret;
|
||||
@@ -85,18 +84,18 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
# 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',
|
||||
|
||||
'status'=>$cdb->get_prop('nut', 'status', 'disabled'),
|
||||
'Nutmode'=>$cdb->get_prop('nut', 'mode', 'standalone'),
|
||||
'SlaveUPS_Name'=>$cdb->get_prop('nut', 'SlaveUPS', ''),
|
||||
'MasterUPS_Name'=>$cdb->get_prop('nut', 'MasterUPS', ''),
|
||||
'UPS_Model'=>$cdb->get_prop('nut', 'Model', 'usbhid-ups'),
|
||||
'UPS_Device'=>$cdb->get_prop('nut', 'Device', 'auto'),
|
||||
'UPS_gen_Type'=>$cdb->get_prop('nut', 'Type', ''),
|
||||
'UPS_gen_Mfr'=>$cdb->get_prop('nut', 'mfr', ''),
|
||||
'UPS_gen_Model'=>$cdb->get_prop('nut', 'mdl', ''),
|
||||
'MasterUPS_Password'=>$cdb->get_prop('nut', 'MasterPass', ''),
|
||||
'SlaveUPS_Password'=>$cdb->get_prop('nut', 'SlavePass', ''),
|
||||
);
|
||||
return %ret;
|
||||
}
|
||||
@@ -114,7 +113,7 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
my $selected = shift; #Parameter is name of selected row.
|
||||
my $is_new_record = shift; #Indicates new record required (defaults)
|
||||
my %ret = {};
|
||||
return $ret;
|
||||
return %ret;
|
||||
}
|
||||
|
||||
sub get_selected_CONFIG {
|
||||
@@ -122,7 +121,7 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
my $selected = shift; #Parameter is name of selected row.
|
||||
my $is_new_record = shift; #Indicates new record required (defaults)
|
||||
my %ret = {};
|
||||
return $ret;
|
||||
return %ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,27 +145,28 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
my $c = shift;
|
||||
my $prefix_data = shift; #Data hash as parameter
|
||||
my $ret = "";
|
||||
our $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
|
||||
my $db = $cdb; #maybe one of the others
|
||||
my $dbkey = 'ChangeThis';
|
||||
my $dbkey = 'nut';
|
||||
# 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'))
|
||||
if (!$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'))
|
||||
if (!$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'))
|
||||
if (!$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'))
|
||||
if (!$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'))
|
||||
if (!$db->set_prop($dbkey,'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'))
|
||||
if (!$db->set_prop($dbkey,'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'))
|
||||
if (!$db->set_prop($dbkey,'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'))
|
||||
if (!$db->set_prop($dbkey,'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'))
|
||||
if (!$db->set_prop($dbkey,'mdl',$c->param('UPS_gen_Model'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for UPS_gen_Model';}
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
@@ -183,7 +183,7 @@ sub create_link{
|
||||
sub get_model_options {
|
||||
|
||||
# Execute the RPM command and capture the output
|
||||
my @output = qx{rpm -ql nut | grep /usr/sbin};
|
||||
my @output = qx{rpm -ql nut | grep /usr/sbin/};
|
||||
|
||||
# Check for errors
|
||||
if ($? != 0) {
|
||||
@@ -192,10 +192,43 @@ sub get_model_options {
|
||||
}
|
||||
|
||||
# Remove "/usr/sbin" from the front of each line
|
||||
s{^/usr/sbin}{} for @output;
|
||||
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
|
||||
return @output; # Return the array of modified output lines
|
||||
}
|
||||
|
||||
sub get_ups_details {
|
||||
my ($ups_system_name) = @_;
|
||||
# Determine the default based on $nut
|
||||
if ( ($cdb->get_prop('nut', 'Master', 'yes')) eq 'yes' ) {
|
||||
$ups_system_name //= $cdb->get_prop('nut', 'MasterUPS', 'UPS\@localhost'); # Master from DB
|
||||
} else {
|
||||
$ups_system_name //= $cdb->get_prop('nut', 'SlaveUPS', 'apc\@192.168.1.99'); # Use Slave UPS if Master is "no"
|
||||
}
|
||||
|
||||
# If ups_system_name is still empty or undefined, use the hardcoded default
|
||||
#$ups_system_name //= "apc\@192.168.1.99"; # Fallback default
|
||||
|
||||
|
||||
# Execute the 'upsc' command
|
||||
my $command = "/usr/bin/upsc $ups_system_name";
|
||||
my $result = qx/$command/;
|
||||
|
||||
# Check for execution errors
|
||||
if ($? != 0) {
|
||||
return "Error executing command: $! ($command)";
|
||||
}
|
||||
|
||||
# Format the output
|
||||
my @lines = split /\n/, $result; # Split the result into lines
|
||||
my $formatted_output = "UPS Details for $ups_system_name:\n";
|
||||
|
||||
foreach my $line (@lines) {
|
||||
$formatted_output .= " - $line\n"; # Format each line
|
||||
}
|
||||
|
||||
return $formatted_output;
|
||||
}
|
||||
1;
|
@@ -232,10 +232,10 @@ sub do_display {
|
||||
my $modul = "";
|
||||
|
||||
# Accessing all parameters
|
||||
my %params = $c->req->params->to_hash;
|
||||
my $params = $c->req->params->to_hash;
|
||||
|
||||
# Get number of parameters
|
||||
my $num_params = keys %params;
|
||||
my $num_params = scalar keys %$params;
|
||||
|
||||
#Tag as Post or Get (ie. create new entry or edit existing one
|
||||
my $is_new_record = ($c->req->method() eq 'POST');
|
||||
|
@@ -7,7 +7,7 @@
|
||||
SelectInput();
|
||||
};
|
||||
</script>
|
||||
% if ($config->{debug} == 1) {
|
||||
% if (config->{debug} == 1) {
|
||||
<pre>
|
||||
%= dumper $nut_data
|
||||
</pre>
|
||||
@@ -17,6 +17,8 @@
|
||||
% param 'trt' => $nut_data->{trt} unless param 'trt';
|
||||
%= hidden_field 'trt' => $nut_data->{trt}
|
||||
%# Inputs etc in here.
|
||||
%# my $ServerNameReg = '([A-Za-z0-9._%+-]+)@((?:(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,}|(?:\d{1,3}\.){3}\d{1,3})|(?:[A-Za-z0-9-]+))';
|
||||
% my $ServerNameReg = '(.*)@(.*)';
|
||||
|
||||
<h2 class='subh2'><%=l('nut_Manage_Nutups-config_settings:')%></h2>
|
||||
|
||||
@@ -45,14 +47,15 @@
|
||||
%=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'
|
||||
%= text_field 'SlaveUPS_Name', size => '50', class => 'textinput SlaveUPS_Name', pattern => "$ServerNameReg", placeholder=>'server@ip', title=>"Expecting UPSname\@IP or hostname"
|
||||
<br></span></p>
|
||||
|
||||
<p><span class='label'>
|
||||
%=l('nut_SlaveUPS_Password')
|
||||
</span><span class=data>
|
||||
% my $placeholder1 = ($nut_data->{MasterUPS_Password} && $nut_data->{MasterUPS_Password} =~ /\S/) ? "password set" : "password not set";
|
||||
% param 'SlaveUPS_Password' => $nut_data->{SlaveUPS_Password} unless param 'SlaveUPS_Password';
|
||||
%=password_field 'SlaveUPS_Password', class => 'pass4 sme-password'
|
||||
%=password_field 'SlaveUPS_Password', class => 'pass4 sme-password' , placeholder => $placeholder1
|
||||
</span></p>
|
||||
|
||||
|
||||
@@ -68,14 +71,15 @@
|
||||
%=l('nut_MasterUPS_UPSNAME@IP')
|
||||
</span><span class=data>
|
||||
% param 'MasterUPS_Name' => $nut_data->{MasterUPS_Name} unless param 'MasterUPS_Name';
|
||||
%= text_field 'MasterUPS_Name', size => '50', class => 'textinput MasterUPS_Name' , pattern=>'.*' , placeholder=>'MasterUPS_Name'
|
||||
%= text_field 'MasterUPS_Name', size => '50', class => 'textinput MasterUPS_Name' , pattern=>$ServerNameReg , placeholder=>'server@ip', title=>"Expecting UPSname\@IP or hostname"
|
||||
<br></span></p>
|
||||
|
||||
<p><span class='label'>
|
||||
%=l('nut_MasterUPS_Password')
|
||||
</span><span class=data>
|
||||
% my $placeholder2 = ($nut_data->{MasterUPS_Password} && $nut_data->{MasterUPS_Password} =~ /\S/) ? "password set" : "password not set";
|
||||
% param 'MasterUPS_Password' => $nut_data->{MasterUPS_Password} unless param 'MasterUPS_Password';
|
||||
%=password_field 'MasterUPS_Password', class => 'pass6 sme-password'
|
||||
%=password_field 'MasterUPS_Password', class => 'pass6 sme-password', placeholder => $placeholder2
|
||||
</span></p>
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user