* Tue Mar 18 2025 Jean-Philippe Pialasse <jpp@koozali.org> 11.0.0-9.sme
- update config for Nut 2.8.2 [SME: 12657] TODO review master/slave mode TODO convert master/slave to primary/secondary TODO convert to new config data + migrate TODO event and action
This commit is contained in:
		| @@ -49,11 +49,11 @@ my $cdb = esmith::ConfigDB->open()   || die("Couldn't open config db"); | ||||
| 			{$ret .= 'Validation for status failed';}	 | ||||
| 		if (! TRUE) #validate $c->param('Nutmode') | ||||
| 			{$ret .= 'Validation for Nutmode failed';} | ||||
| #do we want the Slave validated ? we should just display read only	 | ||||
| 		#do we want the Slave validated ? we should just display read only	 | ||||
| 		if (! TRUE) #validate $c->param('SlaveUPS_Name') | ||||
| 			{$ret .= 'Validation for SlaveUPS_Name failed';} | ||||
|     if (! TRUE) #validate $c->param('ClientUPS_Name') | ||||
|       {$ret .= 'Validation for ClientUPS_Name failed';}	 | ||||
| 		if (! TRUE) #validate $c->param('ClientUPS_Name') | ||||
| 			{$ret .= 'Validation for ClientUPS_Name failed';}	 | ||||
| 		if (! TRUE) #validate $c->param('MasterUPS_Name') | ||||
| 			{$ret .= 'Validation for MasterUPS_Name failed';}	 | ||||
| 		if (! TRUE) #validate $c->param('UPS_Model') | ||||
| @@ -76,14 +76,14 @@ my $cdb = esmith::ConfigDB->open()   || die("Couldn't open config db"); | ||||
| 	sub get_data_for_panel_STATUS { | ||||
| 		# Return a hash with the fields required which will be loaded into the shared data  | ||||
| 		my $c = shift; | ||||
|     $cdb = esmith::ConfigDB->open()   || die("Couldn't open config db"); | ||||
| 		$cdb = esmith::ConfigDB->open()   || die("Couldn't open config db"); | ||||
| 		my %ret = ( | ||||
| 			#'Data1'=>'Data for STATUS', #Example | ||||
| 			# fields from Inputs in STATUS $fields['STATUS'] | ||||
| 			'UPSStatus'=>$c->get_ups_status(), | ||||
| 			'ups_data' => $c->get_ups_status_as_hash(), | ||||
|       'Nutmode'=>$cdb->get_prop('nut', 'mode')||"none", | ||||
|       'localip'=>$cdb->get_value('LocalIP'), | ||||
| 			'Nutmode'=>$cdb->get_prop('nut', 'Mode')||"none", | ||||
| 			'localip'=>$cdb->get_value('LocalIP'), | ||||
| 			'SlaveUPS_Pass'=>$cdb->get_prop('nut', 'SecondaryPass'), | ||||
| 		); | ||||
| 		return %ret; | ||||
| @@ -95,22 +95,21 @@ my $cdb = esmith::ConfigDB->open()   || die("Couldn't open config db"); | ||||
| 		$cdb = esmith::ConfigDB->open()   || die("Couldn't open config db"); | ||||
| 		my %ret = ( | ||||
| 			'Data1'=>'Data for CONFIG', #Example | ||||
|       'localip'=>$cdb->get_value('LocalIP'), | ||||
| 			'localip'=>$cdb->get_value('LocalIP'), | ||||
| 			# fields from Inputs in CONFIG $fields['CONFIG'] | ||||
| 			'status'=>$cdb->get_prop('nut', 'status', 'disabled'), | ||||
| 			'Nutmode'=>$cdb->get_prop('nut', 'mode', 'standalone'), | ||||
| 			#'SlaveUPS_Name'=>$cdb->get_prop('nut', 'SlaveUPS'), | ||||
|       'ClientUPS_Name'=>$cdb->get_prop('nut', 'ClientUPS'), | ||||
|       'ClientUPS_User'=>$cdb->get_prop('nut', 'ClientUser'), | ||||
|       'ClientUPS_Pass'=>$cdb->get_prop('nut', 'ClientPass'), | ||||
|       'SlaveUPS_Pass'=>$cdb->get_prop('nut', 'SecondaryPass'), | ||||
| 			'status'=>$cdb->get_prop('nut', 'status') || 'disabled', | ||||
| 			'Nutmode'=>$cdb->get_prop('nut', 'Mode') || 'standalone', | ||||
| 			'ClientUPS_Name'=>$cdb->get_prop('nut', 'ClientUPS'), | ||||
| 			'ClientUPS_User'=>$cdb->get_prop('nut', 'ClientUser'), | ||||
| 			'ClientUPS_Pass'=>$cdb->get_prop('nut', 'ClientPass'), | ||||
| 			'SlaveUPS_Pass'=>$cdb->get_prop('nut', 'SecondaryPass'), | ||||
| 			'MasterUPS_Name'=>$cdb->get_prop('nut', 'MasterUPS'), | ||||
|       # TODO migrate to nut-driver@ups entry | ||||
| 			'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', ''), | ||||
| 			# nut-driver@ups entry | ||||
| 			'UPS_Model'=>$cdb->get_prop('nut-driver@ups', 'Model') || 'usbhid-ups', | ||||
| 			'UPS_Device'=>$cdb->get_prop('nut-driver@ups', 'Device')|| 'auto', | ||||
| 			'UPS_gen_Type'=>$cdb->get_prop('nut-driver@ups', 'Type'), | ||||
| 			'UPS_gen_Mfr'=>$cdb->get_prop('nut-driver@ups', 'mfr'), | ||||
| 			'UPS_gen_Model'=>$cdb->get_prop('nut-driver@ups', 'mdl'), | ||||
| 		); | ||||
| 		return %ret; | ||||
| 	} | ||||
| @@ -163,35 +162,35 @@ my $cdb = esmith::ConfigDB->open()   || die("Couldn't open config db"); | ||||
| 		$cdb = esmith::ConfigDB->open()   || die("Couldn't open config db"); | ||||
| 		my $db = $cdb; #maybe one of the others | ||||
| 		my $dbkey = 'nut'; | ||||
|     my $driverkey = 'nut-driver@ups'; | ||||
| 		my $driverkey = 'nut-driver@ups'; | ||||
| 		# 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 (!$db->set_prop($dbkey,'status',$c->param('status'))) | ||||
| 			{$ret .= 'Perform/save failed for status';} | ||||
| 		if (!$db->set_prop($dbkey,'mode',$c->param('Nutmode'))) | ||||
| 		if (!$db->set_prop($dbkey,'Mode',$c->param('Nutmode'))) | ||||
| 			{$ret .= 'Perform/save failed for Nutmode';} | ||||
|     # let only save info regarding the current mode | ||||
|  | ||||
|     # if client mode | ||||
| 		# let only save info regarding the current mode | ||||
| 		# if client mode | ||||
| 		if (! $db->set_prop($dbkey,'ClientUPS',$c->param('ClientUPS_Name'))) | ||||
| 			{$ret .= 'Perform/save failed for ClientUPS_Name';} | ||||
| 		if (! $db->set_prop($dbkey,'MasterUPS',$c->param('MasterUPS_Name'))) | ||||
| 			{$ret .= 'Perform/save failed for MasterUPS_Name';} | ||||
|     if (! $db->set_prop($dbkey,'ClientUser',$c->param('ClientUPS_User'))) | ||||
|       {$ret .= 'Perform/save failed for ClientUPS_USer';} | ||||
| 		if (! $db->set_prop($dbkey,'ClientUser',$c->param('ClientUPS_User'))) | ||||
| 			{$ret .= 'Perform/save failed for ClientUPS_USer';} | ||||
| 		if (! $db->set_prop($dbkey,'ClientPass',$c->param('ClientUPS_Pass'))) | ||||
| 			{$ret .= 'Perform/save failed for ClientUPS_Pass';} | ||||
|  | ||||
|     # if not client mode | ||||
| 		if (! $db->set_prop($dbkey,'Model',$c->param('UPS_Model'))) | ||||
| 		# if not client mode | ||||
| 		if (! $db->set_prop($driverkey,'Model',$c->param('UPS_Model'))) | ||||
| 			{$ret .= 'Perform/save failed for UPS_Model';} | ||||
| 		if (! $db->set_prop($dbkey,'Device',$c->param('UPS_Device'))) | ||||
| 		if (! $db->set_prop($driverkey,'Device',$c->param('UPS_Device'))) | ||||
| 			{$ret .= 'Perform/save failed for UPS_Device';} | ||||
| 		if (! $db->set_prop($dbkey,'Type',$c->param('UPS_gen_Type'))) | ||||
| 		if (! $db->set_prop($driverkey,'Type',$c->param('UPS_gen_Type'))) | ||||
| 			{$ret .= 'Perform/save failed for UPS_gen_Type';} | ||||
| 		if (! $db->set_prop($dbkey,'mfr',$c->param('UPS_gen_Mfr'))) | ||||
| 		if (! $db->set_prop($driverkey,'mfr',$c->param('UPS_gen_Mfr'))) | ||||
| 			{$ret .= 'Perform/save failed for UPS_gen_Mfr';} | ||||
| 		if (! $db->set_prop($dbkey,'mdl',$c->param('UPS_gen_Model'))) | ||||
| 		if (! $db->set_prop($driverkey,'mdl',$c->param('UPS_gen_Model'))) | ||||
| 			{$ret .= 'Perform/save failed for UPS_gen_Model';} | ||||
|  | ||||
| #changes from sme10 to sme11 | ||||
| @@ -208,17 +207,6 @@ my $cdb = esmith::ConfigDB->open()   || die("Couldn't open config db"); | ||||
|  | ||||
| 		if ($ret eq "") { | ||||
| 			$ret = 'ok'; | ||||
| 			#and set Master and access properties according to values | ||||
| 			if ($db->get_prop($dbkey,"mode",'standalone') eq 'netclient'){ | ||||
| 				$db->set_prop($dbkey,'Master','no'); | ||||
| 			} else { | ||||
| 				$db->set_prop($dbkey,'Master','yes'); | ||||
| 			} | ||||
| 			if ($db->get_prop($dbkey,"mode",'standalone') eq 'netserver'){ | ||||
| 				$db->set_prop($dbkey,'access','private'); | ||||
| 			} else { | ||||
| 				$db->set_prop($dbkey,'access','localhost'); | ||||
| 			} | ||||
| 			#And run signal-event to apply templates for config files and start task. | ||||
| 			my @result = qx{/usr/sbin/e-smith/signal-event smeserver-nutUPS-update}; | ||||
| 			if ($? != 0) { | ||||
| @@ -259,7 +247,7 @@ sub get_model_options { | ||||
| sub get_ups_status { | ||||
| 	my $c = shift; | ||||
| 	$cdb = esmith::ConfigDB->open()   || die("Couldn't open config db"); | ||||
| 	my $nutmode = $cdb->get_prop('nut', 'mode','standalone'); | ||||
| 	my $nutmode = $cdb->get_prop('nut', 'Mode','standalone'); | ||||
| 	if ($cdb->get_prop('nut', 'status', 'disabled') eq 'disabled'){ | ||||
| 		return $c->l('nut_status_is_disabled') | ||||
| 	} elsif ($nutmode eq 'netclient'){ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user