mirror of
https://github.com/opnsense/plugins.git
synced 2026-05-28 04:34:15 -04:00
sysutils/nut: merge version 0.3 from master
This commit is contained in:
parent
543e51f7ee
commit
4695795cf6
11 changed files with 117 additions and 8 deletions
|
|
@ -1,5 +1,5 @@
|
|||
PLUGIN_NAME= nut
|
||||
PLUGIN_VERSION= 0.2
|
||||
PLUGIN_VERSION= 0.3
|
||||
PLUGIN_COMMENT= Network UPS Tools
|
||||
PLUGIN_DEPENDS= nut
|
||||
PLUGIN_MAINTAINER= m.muenz@gmail.com
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2017 Michael Muenz
|
||||
Copyright (C) 2017-2018 Michael Muenz
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -36,6 +36,16 @@ function nut_enabled()
|
|||
return false;
|
||||
}
|
||||
|
||||
function nut_netclient()
|
||||
{
|
||||
$model = new \OPNsense\Nut\Nut();
|
||||
if ((string)$model->general->mode == 'netclient') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function nut_services()
|
||||
{
|
||||
$services = array();
|
||||
|
|
@ -52,5 +62,17 @@ function nut_services()
|
|||
'pidfile' => '/var/run/nut.pid'
|
||||
);
|
||||
}
|
||||
if (nut_netclient()) {
|
||||
$services[] = array(
|
||||
'description' => gettext('Network UPS Monitor'),
|
||||
'configd' => array(
|
||||
'restart' => array('nut restart'),
|
||||
'start' => array('nut start'),
|
||||
'stop' => array('nut stop'),
|
||||
),
|
||||
'name' => 'upsmon'
|
||||
);
|
||||
}
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,12 @@
|
|||
<type>checkbox</type>
|
||||
<help>Enable or disable the nut service.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>nut.general.mode</id>
|
||||
<label>Service Mode</label>
|
||||
<type>dropdown</type>
|
||||
<help>Set the service mode. Currently only standalone and netclient are available.</help>
|
||||
</field>
|
||||
</subtab>
|
||||
<subtab id="nut-general-account" description="Nut Account Settings">
|
||||
<field>
|
||||
|
|
@ -44,6 +50,38 @@
|
|||
<help>Set extra arguments for this UPS, e.g. "port=auto".</help>
|
||||
</field>
|
||||
</subtab>
|
||||
<subtab id="nut-ups-netclient" description="Netclient">
|
||||
<field>
|
||||
<id>nut.netclient.enable</id>
|
||||
<label>Enable</label>
|
||||
<type>checkbox</type>
|
||||
<help>Enable the Netclient driver.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>nut.netclient.name</id>
|
||||
<label>Name</label>
|
||||
<type>text</type>
|
||||
<help>Set a name for your UPS.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>nut.netclient.address</id>
|
||||
<label>IP Address</label>
|
||||
<type>text</type>
|
||||
<help>Set the IP address of the remote NUT server.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>nut.netclient.user</id>
|
||||
<label>Username</label>
|
||||
<type>text</type>
|
||||
<help>Set the username of the remote NUT server.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>nut.netclient.password</id>
|
||||
<label>Password</label>
|
||||
<type>password</type>
|
||||
<help>Set the password of the remote NUT server.</help>
|
||||
</field>
|
||||
</subtab>
|
||||
</tab>
|
||||
|
||||
<activetab>nut-general-settings</activetab>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,14 @@
|
|||
<default>0</default>
|
||||
<Required>Y</Required>
|
||||
</enable>
|
||||
<mode type="OptionField">
|
||||
<default>standalone</default>
|
||||
<Required>Y</Required>
|
||||
<OptionValues>
|
||||
<standalone>standalone</standalone>
|
||||
<netclient>netclient</netclient>
|
||||
</OptionValues>
|
||||
</mode>
|
||||
</general>
|
||||
|
||||
<account>
|
||||
|
|
@ -34,5 +42,25 @@
|
|||
<Required>N</Required>
|
||||
</args>
|
||||
</usbhid>
|
||||
<netclient>
|
||||
<enable type="BooleanField">
|
||||
<Required>Y</Required>
|
||||
<default>0</default>
|
||||
</enable>
|
||||
<name type="TextField">
|
||||
<default>UPS-Name</default>
|
||||
<Required>Y</Required>
|
||||
</name>
|
||||
<address type="HostnameField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
</address>
|
||||
<user type="TextField">
|
||||
<Required>N</Required>
|
||||
</user>
|
||||
<password type="TextField">
|
||||
<Required>N</Required>
|
||||
</password>
|
||||
</netclient>
|
||||
</items>
|
||||
</model>
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
[start]
|
||||
command:/usr/local/opnsense/scripts/OPNsense/Nut/setup.sh;/usr/local/etc/rc.d/nut start
|
||||
command:/usr/local/opnsense/scripts/OPNsense/Nut/setup.sh;/usr/local/etc/rc.d/nut start;/usr/local/etc/rc.d/nut_upsmon start
|
||||
parameters:
|
||||
type:script
|
||||
message:starting nut
|
||||
|
||||
[stop]
|
||||
command:/usr/local/etc/rc.d/nut onestop
|
||||
command:/usr/local/etc/rc.d/nut stop;/usr/local/etc/rc.d/nut_upsmon stop;exit 0
|
||||
parameters:
|
||||
type:script
|
||||
message:stopping nut
|
||||
|
||||
[restart]
|
||||
command:/usr/local/opnsense/scripts/OPNsense/Nut/setup.sh;/usr/local/etc/rc.d/nut restart
|
||||
command:/usr/local/opnsense/scripts/OPNsense/Nut/setup.sh;/usr/local/etc/rc.d/nut restart;/usr/local/etc/rc.d/nut_upsmon restart
|
||||
parameters:
|
||||
type:script
|
||||
message:restarting nut
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
nut:/etc/rc.conf.d/nut
|
||||
nut_upsmon:/etc/rc.conf.d/nut_upsmon
|
||||
nut.conf:/usr/local/etc/nut/nut.conf
|
||||
ups.conf:/usr/local/etc/nut/ups.conf
|
||||
upsd.conf:/usr/local/etc/nut/upsd.conf
|
||||
|
|
|
|||
|
|
@ -2,5 +2,7 @@
|
|||
# the next update.
|
||||
#
|
||||
{% if helpers.exists('OPNsense.Nut.general.enable') and OPNsense.Nut.general.enable == '1' %}
|
||||
MODE=standalone
|
||||
{% if helpers.exists('OPNsense.Nut.general.mode') and OPNsense.Nut.general.mode != '' %}
|
||||
MODE={{ OPNsense.Nut.general.mode }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
{% if helpers.exists('OPNsense.Nut.general.enable') and OPNsense.Nut.general.enable == '1' %}
|
||||
{% if helpers.exists('OPNsense.Nut.general.mode') and OPNsense.Nut.general.mode == 'netclient' %}
|
||||
nut_upsmon_enable="YES"
|
||||
{% else %}
|
||||
nut_upsmon_enable="NO"
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
# the next update.
|
||||
#
|
||||
{% if helpers.exists('OPNsense.Nut.general.enable') and OPNsense.Nut.general.enable == '1' %}
|
||||
{% if helpers.exists('OPNsense.Nut.general.mode') and OPNsense.Nut.general.mode == 'standalone' %}
|
||||
LISTEN 127.0.0.1
|
||||
LISTEN ::1
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,19 @@
|
|||
# the next update.
|
||||
#
|
||||
{% if helpers.exists('OPNsense.Nut.general.enable') and OPNsense.Nut.general.enable == '1' %}
|
||||
{% if helpers.exists('OPNsense.Nut.account.admin_password') and OPNsense.Nut.account.admin_password != '' %}
|
||||
{% if helpers.exists('OPNsense.Nut.general.mode') and OPNsense.Nut.general.mode == 'standalone' %}
|
||||
{% if helpers.exists('OPNsense.Nut.account.admin_password') and OPNsense.Nut.account.admin_password != '' %}
|
||||
[admin]
|
||||
password={{ OPNsense.Nut.account.admin_password }}
|
||||
actions=set
|
||||
instcmds=all
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.Nut.account.mon_password') and OPNsense.Nut.account.mon_password != '' %}
|
||||
{% if helpers.exists('OPNsense.Nut.general.mode') and OPNsense.Nut.general.mode == 'standalone' %}
|
||||
{% if helpers.exists('OPNsense.Nut.account.mon_password') and OPNsense.Nut.account.mon_password != '' %}
|
||||
[monuser]
|
||||
password={{ OPNsense.Nut.account.mon_password }}
|
||||
upsmon master
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -6,3 +6,8 @@ MONITOR {{ OPNsense.Nut.usbhid.name }} 1 monuser {{ OPNsense.Nut.account.mon_pas
|
|||
SHUTDOWNCMD "/sbin/shutdown -p +0"
|
||||
POWERDOWNFLAG /etc/killpower
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.Nut.netclient.enable') and OPNsense.Nut.netclient.enable == '1' %}
|
||||
MONITOR {{ OPNsense.Nut.netclient.name }}@{{ OPNsense.Nut.netclient.address }} 1 {{ OPNsense.Nut.netclient.user }} {{ OPNsense.Nut.netclient.password }} slave
|
||||
SHUTDOWNCMD "/sbin/shutdown -p +0"
|
||||
POWERDOWNFLAG /etc/killpower
|
||||
{% endif %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue