forked from limetech/dynamix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.apcupsd.php
33 lines (30 loc) · 1.48 KB
/
update.apcupsd.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?PHP
/* Copyright 2015, Dan Landon.
* Copyright 2015, Bergware International.
* Copyright 2015, Lime Technology
*
* 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";
$cable = $_POST['UPSCABLE']=='custom' ? $_POST['CUSTOMUPSCABLE'] : $_POST['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 '{$_POST['UPSTYPE']}'' $conf");
exec("sed -i -e '/^DEVICE/c\\DEVICE '{$_POST['DEVICE']}'' $conf");
exec("sed -i -e '/^BATTERYLEVEL/c\\BATTERYLEVEL '{$_POST['BATTERYLEVEL']}'' $conf");
exec("sed -i -e '/^MINUTES/c\\MINUTES '{$_POST['MINUTES']}'' $conf");
exec("sed -i -e '/^TIMEOUT/c\\TIMEOUT '{$_POST['TIMEOUT']}'' $conf");
exec("sed -i -e '/^UPSCABLE/c\\UPSCABLE '{$cable}'' $conf");
if ($_POST['KILLUPS']=='yes' && $_POST['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 ($_POST['SERVICE']=='enable') exec("/etc/rc.d/rc.apcupsd start");
?>