From patchwork Fri Jun 21 16:04:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adolf Belka X-Patchwork-Id: 7895 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384 client-signature ECDSA (secp384r1) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W5MdD11zQz3wxG for ; Fri, 21 Jun 2024 16:05:04 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W5Md34mvrz17q; Fri, 21 Jun 2024 16:04:55 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W5Md32Xyvz33H3; Fri, 21 Jun 2024 16:04:55 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384 client-signature ECDSA (secp384r1) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W5Md03n4bz335Q for ; Fri, 21 Jun 2024 16:04:52 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W5Mcz3707z131; Fri, 21 Jun 2024 16:04:51 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718985891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KyHtKLj5n0vWqb1my7XVowoeGTd6AyCRMXQ6AUlHaMM=; b=LHV06xDpURtJbWkFK/5DgK+z2UStvko3c5HQziZQXrV78K49FBy2XifAtaV83DKjFmi6kC 5/NfhQm/C1RfnUAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718985891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KyHtKLj5n0vWqb1my7XVowoeGTd6AyCRMXQ6AUlHaMM=; b=BwpdZTMSO9bSvW5njQHiK84U8DZm7GcuWHThNkMBvRb9eevyNKe95eECcic3Bb6ciVonva dl5AhIOgUVufCDSN8ocsFKGnVrX7p3EjcJR5thhVPVm7O0PQUNwXU2EaAijBLy9iroIDnO jHU9m5sbJkSbLIPobh7K/Nw4Us+CWj0pBgR6rsj4Sl7uf9xpOv4j3fdfMJUp5Cjlz86DcX dct6DIVnNyl5FSCzYC38DS0/NfuhVphJshpt1+nkZWMMCggsRQMh6/TpTUSeGdG/48Grzx x1LKeLKR+jB8Q5Cmih0A7tWbwzKxw9bbDQN3GbALOhYbuXp6iyV813CXHp8hPg== From: Adolf Belka To: development@lists.ipfire.org Subject: [PATCH] apcupsd: Update email scripts to work with dma Date: Fri, 21 Jun 2024 18:04:46 +0200 Message-ID: <20240621160446.2596141-1-adolf.belka@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: T3ILEIAZFBL5XHN6CFD7JBOBUXOD6VTD X-Message-ID-Hash: T3ILEIAZFBL5XHN6CFD7JBOBUXOD6VTD X-MailFrom: adolf.belka@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: - The standard email scripts supllied with apcupsd are coded on the basis that sendmail is being used. The format of the email information in those scripts does not work with the dma mail system implemented in IPFire. - The scripts provided in the config/apcupsd directory have been updated to work with dma. The scripts have been confirmed to work with my production system that is using a UPS. - This patch will replace the standard apcupsd scripts with the ones tailored for IPFire. - If any existing users have modified their scripts to already work with dma then their versions will be saved in their backup. - The apcupsd-3.14.14-2.ipfire package created in the build with the above changes has been installed on a vm system and confirmed to provide the IPFire tailored scripts. - The lfs change is the addition of the copying of the scripts to the /etc/apcupsd directory. - No change to the rootfile as the scripts names are the same. - The only thing a user will need to do is to ensure the IPFire email system is enabled, configure and confirmed working. Then valid FROM and TO email addresses need to be added to each script. - Once this patch submission is accepted then I will do an update to the apcupsd IPFire documentation page to describe these scripts and how to update the email addresses. Tested-by: Adolf Belka Signed-off-by: Adolf Belka --- config/apcupsd/changeme | 24 ++++++++++++++++++++++++ config/apcupsd/commfailure | 23 +++++++++++++++++++++++ config/apcupsd/commok | 24 ++++++++++++++++++++++++ config/apcupsd/offbattery | 24 ++++++++++++++++++++++++ config/apcupsd/onbattery | 24 ++++++++++++++++++++++++ lfs/apcupsd | 18 +++++++++++------- 6 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 config/apcupsd/changeme create mode 100644 config/apcupsd/commfailure create mode 100644 config/apcupsd/commok create mode 100644 config/apcupsd/offbattery create mode 100644 config/apcupsd/onbattery diff --git a/config/apcupsd/changeme b/config/apcupsd/changeme new file mode 100644 index 000000000..166b6e0cb --- /dev/null +++ b/config/apcupsd/changeme @@ -0,0 +1,24 @@ +#!/bin/sh +# +# This shell script if placed in /etc/apcupsd +# will be called by /etc/apcupsd/apccontrol when apcupsd +# detects that the battery should be replaced. +# We send an email message to root to notify him. +# + +FROM="enter from email address" +TO="enter to email address" + +HOSTNAME=`hostname` +MSG="$HOSTNAME Battery needs changing now on UPS $1" +# +( +echo From: $FROM +echo To: $TO +echo Subject: $MSG +echo " " +echo "$MSG" +echo " " +echo -ne $(echo "\r\n"; while read line; do echo "$line\r\n"; done < <(echo "$(/sbin/apcaccess status)")) +) | sudo -u nobody /usr/sbin/sendmail -t -f $FROM +exit 0 diff --git a/config/apcupsd/commfailure b/config/apcupsd/commfailure new file mode 100644 index 000000000..4771dcfa7 --- /dev/null +++ b/config/apcupsd/commfailure @@ -0,0 +1,23 @@ +#!/bin/sh +# +# This shell script if placed in /etc/apcupsd +# will be called by /etc/apcupsd/apccontrol when apcupsd +# loses contact with the UPS (i.e. the serial connection is not responding). +# We send an email message to root to notify him. +# + +FROM="enter from email address" +TO="enter to email address" + +HOSTNAME=`hostname` +MSG="$HOSTNAME Communications with UPS $1 lost" +( +echo From: $FROM +echo To: $TO +echo Subject: $MSG +echo " " +echo "$MSG" +echo " " +echo -ne $(echo "\r\n"; while read line; do echo "$line\r\n"; done < <(echo "$(/sbin/apcaccess status)")) +) | sudo -u nobody /usr/sbin/sendmail -t -f $FROM +exit 0 diff --git a/config/apcupsd/commok b/config/apcupsd/commok new file mode 100644 index 000000000..5871eda5d --- /dev/null +++ b/config/apcupsd/commok @@ -0,0 +1,24 @@ +#!/bin/sh +# +# This shell script if placed in /etc/apcupsd +# will be called by /etc/apcupsd/apccontrol when apcupsd +# restores contact with the UPS (i.e. the serial connection is restored). +# We send an email message to root to notify him. +# + +FROM="enter from email address" +TO="enter to email address" + +HOSTNAME=`hostname` +MSG="$HOSTNAME Communications with UPS $1 restored" +# +( +echo From: $FROM +echo To: $TO +echo Subject: $MSG +echo " " +echo "$MSG" +echo " " +echo -ne $(echo "\r\n"; while read line; do echo "$line\r\n"; done < <(echo "$(/sbin/apcaccess status)")) +) | sudo -u nobody /usr/sbin/sendmail -t -f $FROM +exit 0 diff --git a/config/apcupsd/offbattery b/config/apcupsd/offbattery new file mode 100644 index 000000000..99e773c42 --- /dev/null +++ b/config/apcupsd/offbattery @@ -0,0 +1,24 @@ +#!/bin/sh +# +# This shell script if placed in /etc/apcupsd +# will be called by /etc/apcupsd/apccontrol when the +# UPS goes back on to the mains after a power failure. +# We send an email message to root to notify him. +# + +FROM="enter from email address" +TO="enter to email address" + +HOSTNAME=`hostname` +MSG="$HOSTNAME Power has returned on UPS $1" +# +( +echo From: $FROM +echo To: $TO +echo Subject: $MSG +echo " " +echo "$MSG" +echo " " +echo -ne $(echo "\r\n"; while read line; do echo "$line\r\n"; done < <(echo "$(/sbin/apcaccess status)")) +) | sudo -u nobody /usr/sbin/sendmail -t -f $FROM +exit 0 diff --git a/config/apcupsd/onbattery b/config/apcupsd/onbattery new file mode 100644 index 000000000..b1df7dafd --- /dev/null +++ b/config/apcupsd/onbattery @@ -0,0 +1,24 @@ +#!/bin/sh +# +# This shell script if placed in /etc/apcupsd +# will be called by /etc/apcupsd/apccontrol when the UPS +# goes on batteries. +# We send an email message to root to notify him. +# + +FROM="enter from email address" +TO="enter to email address" + +HOSTNAME=`hostname` +MSG="$HOSTNAME Power Failure on UPS $1" +# +( +echo From: $FROM +echo To: $TO +echo Subject: $MSG +echo " " +echo "$MSG" +echo " " +echo -ne $(echo "\r\n"; while read line; do echo "$line\r\n"; done < <(echo "$(/sbin/apcaccess status)")) +) | sudo -u nobody /usr/sbin/sendmail -t -f $FROM +exit 0 diff --git a/lfs/apcupsd b/lfs/apcupsd index 8ed9bbd8c..82b55272b 100644 --- a/lfs/apcupsd +++ b/lfs/apcupsd @@ -1,7 +1,7 @@ ############################################################################### # # # IPFire.org - A linux based firewall # -# Copyright (C) 2007-2023 IPFire Team # +# Copyright (C) 2007-2024 IPFire Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -34,7 +34,7 @@ DL_FROM = $(URL_IPFIRE) DIR_APP = $(DIR_SRC)/$(THISAPP) TARGET = $(DIR_INFO)/$(THISAPP) PROG = apcupsd -PAK_VER = 11 +PAK_VER = 2 DEPS = @@ -82,14 +82,18 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) @$(PREBUILD) @rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar zxf $(DIR_DL)/$(DL_FILE) $(UPDATE_AUTOMAKE) - cd $(DIR_APP) && ./configure --prefix=/usr --enable-usb --enable-cgi \ - --with-cgi-bin=/srv/web/ipfire/cgi-bin + cd $(DIR_APP) && ./configure \ + --prefix=/usr \ + --enable-usb \ + --enable-cgi \ + --with-cgi-bin=/srv/web/ipfire/cgi-bin cd $(DIR_APP) && make $(MAKETUNING) cd $(DIR_APP) && make install - - #install initscripts + # Copy the IPFire specific scripts for apccontrol to use. + # These have been modified to be able to use the dma mail agent in IPFire. + cp -rf $(DIR_SRC)/config/apcupsd/* /etc/apcupsd/ + # install initscripts $(call INSTALL_INITSCRIPTS,$(SERVICES)) - ln -sf ../init.d/apcupsd /etc/rc.d/rc3.d/S65apcupsd ln -sf ../init.d/apcupsd /etc/rc.d/rc0.d/K35apcupsd ln -sf ../init.d/apcupsd /etc/rc.d/rc6.d/K35apcupsd