Skip to content

Commit

Permalink
Merge pull request #13 from desertwitch/master
Browse files Browse the repository at this point in the history
2023.07.26
  • Loading branch information
SimonFair authored Jul 26, 2023
2 parents 0d1c4bf + 72f7545 commit 44c76c4
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
30 changes: 24 additions & 6 deletions plugin/nut-2.8.0.plg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
- add: implement battery replacement notification in settings

Thanks to forum member Rysz for the PR.
###2023.06.03
- Add Small footer style thanks ich777 for the PR.
###2023.02.14
-6.12 Dashboard support
-PHP8 fixes
-Refresh option.
###2022.03.20
-fix for filetree top level
-update nut footer
Expand Down Expand Up @@ -249,10 +255,16 @@ sum1=$(/usr/bin/md5sum &plgPATH;/&plgNAME;.txz)
sum2=$(/usr/bin/cat &plgPATH;/&plgNAME;.md5)
if [ "${sum1:0:32}" != "${sum2:0:32}" ]; then
echo "Wrong 'plugin' package md5 hash."
rm &plgPATH;/&plgNAME;.txz
rm &plgPATH;/&plgNAME;.md5
rm -f &plgPATH;/&plgNAME;.txz
rm -f &plgPATH;/&plgNAME;.md5
exit 1
else
# if upgrading on live system, stop the services here
# to release any remaining file locks before patching
if [ -x /etc/rc.d/rc.nut ]; then
/etc/rc.d/rc.nut stop 2>/dev/null
fi

# nut-2.7.4 and nut plugin expects:
# Config: /etc/nut
# Pid : /var/run/nut/upsmon.pid
Expand All @@ -264,12 +276,12 @@ else
if [ ! -d /etc/nut ]; then
# Link nut-2.8.0 config to nut-2.7.4 config
mkdir /etc/nut
cp /etc/ups/* /etc/nut
cp -f /etc/ups/* /etc/nut
rm -rf /etc/ups
ln -s /etc/nut /etc/ups
ln -sf /etc/nut /etc/ups
# Link nut-2.7.4 pid to nut-2.8.0 pid
mkdir /var/run/nut
ln -s /var/run/upsmon.pid /var/run/nut/upsmon.pid
ln -sf /var/run/upsmon.pid /var/run/nut/upsmon.pid
fi

# upgrade plugin package
Expand Down Expand Up @@ -327,7 +339,13 @@ rm -f &plgPATH;/*.txz \

# Remove links for nut-2.8.0 vs nut-2.7.4
rm -rf /etc/nut
rm /etc/ups
rm -f /etc/ups
rm -rf /var/run/nut

# clean up folders after the removed installation
# in case of re-installation of package on live system
rm -rf /etc/nut
rm -rf /etc/ups
rm -rf /var/run/nut

echo ""
Expand Down
16 changes: 14 additions & 2 deletions plugin/nut.plg
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,16 @@ sum1=$(/usr/bin/md5sum &plgPATH;/&plgNAME;.txz)
sum2=$(/usr/bin/cat &plgPATH;/&plgNAME;.md5)
if [ "${sum1:0:32}" != "${sum2:0:32}" ]; then
echo "Wrong 'plugin' package md5 hash."
rm &plgPATH;/&plgNAME;.txz
rm &plgPATH;/&plgNAME;.md5
rm -f &plgPATH;/&plgNAME;.txz
rm -f &plgPATH;/&plgNAME;.md5
exit 1
else
# if upgrading on live system, stop the services here
# to release any remaining file locks before patching
if [ -x /etc/rc.d/rc.nut ]; then
/etc/rc.d/rc.nut stop 2>/dev/null
fi

# upgrade plugin package
upgradepkg --install-new &plgPATH;/&plgNAME;.txz

Expand Down Expand Up @@ -300,6 +306,12 @@ rm -rf &plgPATH;/ups
rm -f &plgPATH;/*.txz \
&plgPATH;/*.md5

# clean up folders after the removed installation
# in case of re-installation of package on live system
rm -rf /etc/nut
rm -rf /etc/ups
rm -rf /var/run/nut

echo ""
echo "-----------------------------------------------------------"
echo " &name; has been removed."
Expand Down
4 changes: 3 additions & 1 deletion source/nut/etc/rc.d/rc.nut
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ write_config() {
mkdir $PLGPATH/ups
fi

cp -f /etc/nut/* $PLGPATH/ups
cp -f /etc/nut/* $PLGPATH/ups >/dev/null 2>&1

# update permissions
if [ -d /etc/nut ]; then
Expand All @@ -214,6 +214,8 @@ write_config() {
chmod 640 /etc/nut/*
chown root:nut /var/run/nut
chmod 0770 /var/run/nut
chown root:nut /var/state/ups
chmod 0770 /var/state/ups
#chown -R 218:218 /etc/nut
#chmod -R 0644 /etc/nut
fi
Expand Down
11 changes: 8 additions & 3 deletions source/nut/install/doinst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@ chmod +0755 $DOCROOT/scripts/* \
/usr/sbin/nut-notify

# copy the default
cp -nr $DOCROOT/default.cfg $BOOT/nut.cfg
cp -nr $DOCROOT/default.cfg $BOOT/nut.cfg >/dev/null 2>&1

# remove nut symlink
if [ -L /etc/nut ]; then
rm -f /etc/nut
mkdir /etc/nut
fi

# create nut directory
if [ ! -d /etc/nut ]; then
mkdir /etc/nut
fi

# prepare conf backup directory on flash drive, if it does not already exist
if [ ! -d $BOOT/ups ]; then
mkdir $BOOT/ups
fi

# copy default conf files to flash drive, if no backups exist there
cp -nr $DOCROOT/nut/* $BOOT/ups
cp -nr $DOCROOT/nut/* $BOOT/ups >/dev/null 2>&1

# copy conf files from flash drive to local system, for our services to use
cp -f $BOOT/ups/* /etc/nut
cp -f $BOOT/ups/* /etc/nut >/dev/null 2>&1

# update permissions
if [ -d /etc/nut ]; then
Expand Down
2 changes: 2 additions & 0 deletions source/nut/usr/local/emhttp/plugins/nut/NUTdetails.page
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ table.tablesorter tbody tr:nth-child(even) {
<tbody id="nut_status"><tr><td colspan="4" style="text-align:center"><i class="fa fa-spinner fa-spin icon"></i><em>Please wait, retrieving UPS information...</em></td></tr></tbody>
</table>

<div style="font-size:x-small;font-weight:bold;"><a href="/plugins/nut/include/nut_status.php?diagsave=true&all=true">Save Diagnostics</a></div>

<script>
function getNUTstatus() {
$.get('/plugins/nut/include/nut_status.php',{all:'true'},function(data) {
Expand Down
22 changes: 22 additions & 0 deletions source/nut/usr/local/emhttp/plugins/nut/include/nut_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,30 @@
$result = [];

if (file_exists('/var/run/nut/upsmon.pid')) {

exec("/usr/bin/upsc ".escapeshellarg($nut_name)."@$nut_ip 2>/dev/null", $rows);

if ($_GET['diagsave'] == "true") {

$diagarray = $rows;

array_walk($diagarray, function(&$var) {
if (preg_match('/^(device|ups)\.(serial|macaddr):/i', $var, $matches)) {
$var = $matches[1] . '.' . $matches[2] . ': REMOVED';
}
});

$diagstring = implode("\n",$diagarray);
header('Content-Disposition: attachment; filename="nut-diagnostics.dev"');
header('Content-Type: text/plain');
header('Content-Length: ' . strlen($diagstring));
header('Connection: close');
die($diagstring);

}

$upsStatus = nut_ups_status($rows);

for ($i=0; $i<count($rows); $i++) {
$row = array_map('trim', explode(':', $rows[$i], 2));
$key = $row[0];
Expand Down

0 comments on commit 44c76c4

Please sign in to comment.