repo reorg

This commit is contained in:
Tom Mortensen
2023-06-02 12:49:33 -07:00
parent 25e934f0a7
commit f9ec00b488
699 changed files with 6700 additions and 68456 deletions
+11
View File
@@ -0,0 +1,11 @@
Copyright 2015, by Dan Landon
This plugin provides APCUPSD support for Unraid V6. The plugin was modified from the original
work done by seeDrs.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2,
as published by the Free Software Foundation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
@@ -0,0 +1,33 @@
Menu="UPSsettings"
Title="UPS Details"
Tag="battery-3"
---
<?PHP
/* Copyright 2005-2022, Lime Technology
* Copyright 2012-2022, Bergware International.
* Copyright 2015, Dan Landon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<script>
function getUPSstatus() {
$.post('/plugins/dynamix.apcupsd/include/UPSstatus.php',{level:<?=$cfg['BATTERYLEVEL']?>,runtime:<?=$cfg['MINUTES']?>},function(data) {
data = data.split('\n');
$('#ups_summary').html(data[0]);
$('#ups_status').html(data[1]);
setTimeout(getUPSstatus,3000);
});
}
$(getUPSstatus);
</script>
<table class="tablesorter shift">
<thead><tr><th style="width:15%">_(Key)_</th><th style="width:35%">_(Value)_</th><th style="width:15%">_(Key)_</th><th style="width:35%">_(Value)_</th></tr></thead>
<tbody id="ups_status"><tr><td colspan="4"><div class="spinner"></div></td></tr></tbody>
</table>
@@ -0,0 +1,128 @@
Menu="OtherSettings"
Type="xmenu"
Title="UPS Settings"
Icon="icon-ups"
Tag="battery-3"
---
<?PHP
/* Copyright 2005-2022, Lime Technology
* Copyright 2012-2022, Bergware International.
* Copyright 2015, Dan Landon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$sName = "dynamix.apcupsd";
$cfg = parse_plugin_cfg($sName);
?>
<style>
table.ups thead tr th{width:16.6%;padding-left:10px}
table.ups tbody tr td{padding-left:10px;font-weight:bold}
tr.ups{height:3rem;line-height:3rem}
i.ups{margin-right:8px}
</style>
<script>
function toggleCustomCable(form) {
var readonly = form.UPSCABLE.value != 'custom';
form.CUSTOMUPSCABLE.readOnly = readonly;
if (readonly) form.CUSTOMUPSCABLE.value = '';
}
function toggleDevice(form) {
var readonly = form.UPSTYPE.value == 'usb';
form.DEVICE.readOnly = readonly;
if (readonly) form.DEVICE.value = '';
}
$(function() {
showStatus('pid','apcupsd');
toggleCustomCable(document.apcupsd_settings);
toggleDevice(document.apcupsd_settings);
});
</script>
<table class="tablesorter shift ups" <?if (!file_exists("/var/run/apcupsd.pid")):?>style="display:none"<?endif;?>>
<thead><tr><th><i class='ups fa fa-shield'></i>_(UPS Model)_</th><th><i class='ups fa fa-plug'></i>_(UPS Status)_</th><th><i class='ups fa fa-battery'></i>_(Battery Charge)_</th><th><i class='ups fa fa-clock-o'></i>_(Runtime Left)_</th><th><i class='ups fa fa-bolt'></i>_(Nominal Power)_</th><th><i class='ups fa fa-bars'></i>_(UPS Load)_</th><th><i class='ups fa fa-ellipsis-h'></i>_(Output Voltage)_</th></tr></thead>
<tbody id="ups_summary"><tr class="ups"><td colspan="7">&nbsp;</td></tr></tbody>
</table>
<span style="float:right;margin-right:10px"><a href="http://apcupsd.org/manual/manual.html" target="_blank" title="_(APC UPS Daemon user manual)_"><i class="fa fa-file-text-o"></i> <u>_(Online Manual)_</u></a></span>
<form markdown="1" name="apcupsd_settings" method="POST" action="/update.php" target="progressFrame">
<input type="hidden" name="#file" value="<?=$sName?>/<?=$sName?>.cfg">
<input type="hidden" name="#include" value="/plugins/<?=$sName?>/include/update.apcupsd.php">
_(Start APC UPS daemon)_:
: <select name="SERVICE">
<?=mk_option($cfg['SERVICE'], "disable", _("No"))?>
<?=mk_option($cfg['SERVICE'], "enable", _("Yes"))?>
</select>
:apc_ups_daemon_help:
_(UPS cable)_:
: <select name="UPSCABLE" onChange="toggleCustomCable(this.form)">
<?=mk_option($cfg['UPSCABLE'], "usb", _("USB"))?>
<?=mk_option($cfg['UPSCABLE'], "simple", _("Simple"))?>
<?=mk_option($cfg['UPSCABLE'], "smart", _("Smart"))?>
<?=mk_option($cfg['UPSCABLE'], "ether", _("Ether"))?>
<?=mk_option($cfg['UPSCABLE'], "custom", _("Custom"))?>
</select>
:apc_ups_cable_help:
_(Custom UPS cable)_:
: <input type="text" name="CUSTOMUPSCABLE" class="narrow" maxlength="40" value="<?=htmlspecialchars($cfg['CUSTOMUPSCABLE']);?>">
:apc_ups_custom_cable_help:
_(UPS type)_:
: <select name="UPSTYPE" onChange="toggleDevice(this.form)">
<?=mk_option($cfg['UPSTYPE'], "usb", _("USB"))?>
<?=mk_option($cfg['UPSTYPE'], "apcsmart", _("APCsmart"))?>
<?=mk_option($cfg['UPSTYPE'], "net", _("Net"))?>
<?=mk_option($cfg['UPSTYPE'], "snmp", _("SNMP"))?>
<?=mk_option($cfg['UPSTYPE'], "dumb", _("Dumb"))?>
<?=mk_option($cfg['UPSTYPE'], "pcnet", _("PCnet"))?>
<?=mk_option($cfg['UPSTYPE'], "modbus", _("ModBus"))?>
</select>
:apc_ups_type_help:
_(Device)_:
: <input type="text" name="DEVICE" maxlength="200" class="narrow" value="<?=htmlspecialchars($cfg['DEVICE']);?>">
:apc_ups_device_help:
_(Battery level to initiate shutdown)_ (%):
: <input type="text" name="BATTERYLEVEL" class="narrow" maxlength="3" value="<?=htmlspecialchars($cfg['BATTERYLEVEL']);?>">
:apc_battery_level_help:
_(Runtime left to initiate shutdown)_ (_(minutes)_):
: <input type="text" name="MINUTES" class="narrow" maxlength="3" value="<?=htmlspecialchars($cfg['MINUTES']);?>">
:apc_runtime_left_help:
_(Time on battery before shutdown)_ (_(seconds)_):
: <input type="text" name="TIMEOUT" class="narrow" maxlength="4" value="<?=htmlspecialchars($cfg['TIMEOUT']);?>">
:apc_battery_time_help:
<div></div>
:apc_note_help:
_(Turn off UPS after shutdown)_:
: <select name="KILLUPS">
<?=mk_option($cfg['KILLUPS'], "no", _("No"))?>
<?=mk_option($cfg['KILLUPS'], "yes", _("Yes"))?>
</select>
:apc_killups_help:
<input type="submit" name="#default" value="_(Default)_">
: <input type="submit" name="#apply" value="_(Apply)_" disabled><input type="button" value="_(Done)_" onclick="done()">
</form>
+6
View File
@@ -0,0 +1,6 @@
#
# Send system notify message from apcupsd
#
read MESSAGE
[[ "$MESSAGE" == *restored* || "$MESSAGE" == *returned* ]] && LEVEL=normal || LEVEL=alert
/usr/local/emhttp/webGui/scripts/notify -l "/Settings/UPSsettings" -e "Unraid Server Alert" -s "UPS Alert" -d "$MESSAGE" -i $LEVEL
@@ -0,0 +1,9 @@
SERVICE="disable"
UPSCABLE="usb"
CUSTOMUPSCABLE=""
UPSTYPE="usb"
DEVICE=""
BATTERYLEVEL="10"
MINUTES="10"
TIMEOUT="0"
KILLUPS="no"
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
conf=/etc/apcupsd/apcupsd.conf
cfg=/boot/config/plugins/dynamix.apcupsd/dynamix.apcupsd.cfg
# Daemon already running or no custom file?
[[ -f /var/run/apcupsd.pid || ! -f $cfg ]] && exit
# Read settings
source $cfg
# Apply settings
sed -i -e '/^NISIP/c\\NISIP 0.0.0.0' $conf
sed -i -e '/^UPSTYPE/c\\UPSTYPE '$UPSTYPE'' $conf
sed -i -e '/^DEVICE/c\\DEVICE '$DEVICE'' $conf
sed -i -e '/^BATTERYLEVEL/c\\BATTERYLEVEL '$BATTERYLEVEL'' $conf
sed -i -e '/^MINUTES/c\\MINUTES '$MINUTES'' $conf
sed -i -e '/^TIMEOUT/c\\TIMEOUT '$TIMEOUT'' $conf
if [[ $UPSCABLE == custom ]]; then
sed -i -e '/^UPSCABLE/c\\UPSCABLE '$CUSTOMUPSCABLE'' $conf
else
sed -i -e '/^UPSCABLE/c\\UPSCABLE '$UPSCABLE'' $conf
fi
if [[ $KILLUPS == yes && $SERVICE == enable ]]; then
! grep -q apccontrol /etc/rc.d/rc.6 && sed -i -e 's:/sbin/poweroff:/etc/apcupsd/apccontrol killpower; /sbin/poweroff:' /etc/rc.d/rc.6
else
grep -q apccontrol /etc/rc.d/rc.6 && sed -i -e 's:/etc/apcupsd/apccontrol killpower; /sbin/poweroff:/sbin/poweroff:' /etc/rc.d/rc.6
fi
# Start daemon
[[ $SERVICE == enable ]] && /etc/rc.d/rc.apcupsd start |& logger
@@ -0,0 +1,95 @@
<?PHP
/* Copyright 2005-2023, Lime Technology
* Copyright 2012-2023, Bergware International.
* Copyright 2015, Dan Landon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
// add translations
$_SERVER['REQUEST_URI'] = 'settings';
require_once "$docroot/webGui/include/Translations.php";
$state = [
'ONLINE' => _('Online'),
'SLAVE' => '('._('slave').')',
'TRIM' => '('._('trim').')',
'BOOST' => '('._('boost').')',
'COMMLOST' => _('Lost communication'),
'ONBATT' => _('On battery'),
'NOBATT' => _('No battery detected'),
'LOWBATT' => _('Low on battery'),
'OVERLOAD' => _('UPS overloaded'),
'SHUTTING DOWN' => _('System goes down')
];
$red = "class='red-text'";
$green = "class='green-text'";
$orange = "class='orange-text'";
$status = array_fill(0,7,"<td>-</td>");
$result = [];
$level = $_POST['level'] ?: 10;
$runtime = $_POST['runtime'] ?: 5;
if (file_exists("/var/run/apcupsd.pid")) {
exec("/sbin/apcaccess 2>/dev/null", $rows);
for ($i=0; $i<count($rows); $i++) {
[$key,$val] = array_map('trim',array_pad(explode(':',$rows[$i],2),2,''));
switch ($key) {
case 'MODEL':
$status[0] = "<td $green>$val</td>";
break;
case 'STATUS':
$text = strtr($val, $state);
$status[1] = $val ? (strpos($val,'ONLINE')!==false ? "<td $green>$text</td>" : "<td $red>$text</td>") : "<td $orange>"._('Refreshing')."...</td>";
break;
case 'BCHARGE':
$charge = round(strtok($val,' '));
$status[2] = $charge>$level ? "<td $green>$charge %</td>" : "<td $red>$charge %</td>";
break;
case 'TIMELEFT':
$time = round(strtok($val,' '));
$unit = _('minutes');
$status[3] = $time>$runtime ? "<td $green>$time $unit</td>" : "<td $red>$time $unit</td>";
break;
case 'NOMPOWER':
$power = strtok($val,' ');
$status[4] = $power>0 ? "<td $green>$power W</td>" : "<td $red>$power W</td>";
break;
case 'LOADPCT':
$load = strtok($val,' ');
$status[5] = round($load)." %";
break;
case 'OUTPUTV':
$output = round(strtok($val,' '));
$status[6] = "$output V";
break;
case 'NOMINV':
$volt = strtok($val,' ');
$minv = floor($volt / 1.1); // +/- 10% tolerance
$maxv = ceil($volt * 1.1);
break;
case 'LINEFREQ':
$freq = round(strtok($val,' '));
break;
}
if ($i%2==0) $result[] = "<tr>";
$result[]= "<td><strong>$key</strong></td><td>$val</td>";
if ($i%2==1) $result[] = "</tr>";
}
if (count($rows)%2==1) $result[] = "<td></td><td></td></tr>";
if ($power && isset($load)) $status[5] = ($load<90 ? "<td $green>" : "<td $red>").round($power*$load/100)." W (".$status[5].")</td>";
elseif (isset($load)) $status[5] = ($load<90 ? "<td $green>" : "<td $red>").$status[5]."</td>";
$status[6] = $output ? ((!$volt || ($minv<$output && $output<$maxv) ? "<td $green>" : "<td $red>").$status[6].($freq ? " ~ $freq Hz" : "")."</td>") : $status[6];
}
if (empty($rows)) $result[] = "<tr><td colspan='4' style='text-align:center'>"._('No information available')."</td></tr>";
echo "<tr class='ups'>",implode($status),"</tr>\n",implode($result);
?>
@@ -0,0 +1,34 @@
<?PHP
/* Copyright 2005-2018, Lime Technology
* Copyright 2012-2020, Bergware International.
* Copyright 2015, Dan Landon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$conf = "/etc/apcupsd/apcupsd.conf";
$new = array_replace_recursive($_POST, $default);
$cable = $new['UPSCABLE']=='custom' ? $new['CUSTOMUPSCABLE'] : $new['UPSCABLE'];
exec("/etc/rc.d/rc.apcupsd stop");
exec("sed -i -e '/^NISIP/c\\NISIP 0.0.0.0' $conf");
exec("sed -i -e '/^UPSTYPE/c\\UPSTYPE '".str_replace("'","\\'",$new['UPSTYPE'])."'' $conf");
exec("sed -i -e '/^DEVICE/c\\DEVICE '".str_replace("'","\\'",$new['DEVICE'])."'' $conf");
exec("sed -i -e '/^BATTERYLEVEL/c\\BATTERYLEVEL '".intval($new['BATTERYLEVEL'])."'' $conf");
exec("sed -i -e '/^MINUTES/c\\MINUTES '".intval($new['MINUTES'])."'' $conf");
exec("sed -i -e '/^TIMEOUT/c\\TIMEOUT '".intval($new['TIMEOUT'])."'' $conf");
exec("sed -i -e '/^UPSCABLE/c\\UPSCABLE '".str_replace("'","\\'",$cable)."'' $conf");
if ($new['KILLUPS']=='yes' && $new['SERVICE']=='enable')
exec("! grep -q apccontrol /etc/rc.d/rc.6 && sed -i -e 's:/sbin/poweroff:/etc/apcupsd/apccontrol killpower; /sbin/poweroff:' /etc/rc.d/rc.6");
else
exec("grep -q apccontrol /etc/rc.d/rc.6 && sed -i -e 's:/etc/apcupsd/apccontrol killpower; /sbin/poweroff:/sbin/poweroff:' /etc/rc.d/rc.6");
if ($new['SERVICE']=='enable') exec("/etc/rc.d/rc.apcupsd start");
?>