Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use systemd timer in lieu of cron + New Checkbox Support + Typo + New Script Support #51

Merged
merged 78 commits into from
Feb 11, 2023
Merged
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
c064a6d
add type setting
ipitio Jan 15, 2023
e7280b1
properly? handle type
ipitio Jan 15, 2023
155bbc7
use systemd service
ipitio Jan 19, 2023
15609b7
forgot about reload
ipitio Jan 19, 2023
21cfa7b
are the files created?
ipitio Jan 20, 2023
aeb38e6
explicit shell moves redirection into su process
ipitio Jan 20, 2023
c80be75
variable inside string
ipitio Jan 20, 2023
86ffe27
maybe escape
ipitio Jan 20, 2023
b888b6a
can i do this
ipitio Jan 20, 2023
68b3a58
no escape?
ipitio Jan 20, 2023
01a4d88
no "?
ipitio Jan 20, 2023
b2e6bf0
there we go
ipitio Jan 20, 2023
d739d4a
add support for update and uninstall functions
ipitio Jan 20, 2023
7323c1f
webpage.sh -> screen -> mod.sh
ipitio Jan 21, 2023
b3e1daf
org backup not needed
ipitio Jan 21, 2023
4c3dede
do i need the timer?
ipitio Jan 21, 2023
367b31c
forgot quotes
ipitio Jan 21, 2023
bb519ef
yeah timer's better
ipitio Jan 21, 2023
b8f6e1c
use my repo
ipitio Jan 21, 2023
af716ed
same thing
ipitio Jan 21, 2023
73bbefb
is it the arg
ipitio Jan 21, 2023
a3e76c5
let's put that back
ipitio Jan 21, 2023
9044676
tac tac?
ipitio Jan 21, 2023
db199e3
use tmux
ipitio Jan 21, 2023
4aaebf1
stop tmux from exiting
ipitio Jan 21, 2023
acb0762
switch to tmux
ipitio Jan 21, 2023
673e8d6
remove session if exists
ipitio Jan 21, 2023
00e3607
remove session if exists
ipitio Jan 21, 2023
b381bed
curl can manage buffer by itself like a big it
ipitio Jan 21, 2023
24cdfa9
change to how buffer is managed
ipitio Jan 21, 2023
91b1fef
maybe it was better this way
ipitio Jan 21, 2023
190efa0
undo
ipitio Jan 21, 2023
31a0a71
actually undo
ipitio Jan 21, 2023
8958fe0
dont kill
ipitio Jan 21, 2023
5c04432
is it the buffer
ipitio Jan 21, 2023
9b5bc4c
is it this
ipitio Jan 21, 2023
d2bdd35
forgot sudo
ipitio Jan 21, 2023
4103b91
add logging
ipitio Jan 21, 2023
cdb463e
undo log
ipitio Jan 21, 2023
62d9598
at this point ill try anything
ipitio Jan 21, 2023
6701906
put it back
ipitio Jan 22, 2023
bbf5894
log preserves output
ipitio Jan 22, 2023
7f26606
words
ipitio Jan 22, 2023
9c9c96e
save log in favor of a persistent session
ipitio Jan 22, 2023
e82d5cb
words
ipitio Jan 22, 2023
8d77189
Merge branch 'arevindh:master' into master
ipitio Jan 22, 2023
7d078bc
Merge branch 'master' of https://github.com/ipitio/pi-hole
ipitio Jan 22, 2023
45090eb
account for db
ipitio Jan 22, 2023
562c44a
persist tmux again
ipitio Jan 22, 2023
215a78a
word
ipitio Jan 22, 2023
a6be22f
support the other options
ipitio Jan 22, 2023
1daa0dd
undo persist again
ipitio Jan 22, 2023
9ec89f9
redo
ipitio Jan 22, 2023
ff9d1ed
redo
ipitio Jan 22, 2023
27aa3c7
undo
ipitio Jan 22, 2023
7bb014a
what
ipitio Jan 22, 2023
2988341
forgot that
ipitio Jan 22, 2023
ec38715
forgot those
ipitio Jan 22, 2023
6a6dbf1
change repos
ipitio Jan 22, 2023
24c6fd6
test button
ipitio Jan 22, 2023
251be73
make it nonblocking
ipitio Jan 22, 2023
9b81447
add test
ipitio Jan 22, 2023
6427761
add test
ipitio Jan 22, 2023
912c670
fix timer
ipitio Jan 23, 2023
c23be9b
fix timer
ipitio Jan 23, 2023
2b79fef
simplify help
ipitio Jan 23, 2023
2983b8b
Merge branch 'master' into ipitio
ipitio Jan 23, 2023
fd4da5a
use sn
ipitio Jan 23, 2023
1b2b27d
change repo
ipitio Jan 23, 2023
5abbeb4
fix freq
ipitio Jan 24, 2023
d313747
fix if
ipitio Jan 25, 2023
a868751
Merge branch 'arevindh:master' into speedOverTimeChart
ipitio Jan 26, 2023
db5bea8
local script support
ipitio Jan 29, 2023
0a06ef8
rm var
ipitio Jan 29, 2023
b533e87
always use local speedtest
ipitio Jan 29, 2023
0a963e5
rename to speedtest.sh
ipitio Jan 29, 2023
7f8e02c
Merge branch 'arevindh:master' into speedOverTimeChart
ipitio Jan 30, 2023
236ae44
trailing whitespace
ipitio Feb 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 82 additions & 26 deletions advanced/Scripts/webpage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ Options:
-k, kelvin Set Kelvin as preferred temperature unit
-h, --help Show this help dialog
-i, interface Specify dnsmasq's interface listening behavior
-s, speedtest Set speedtest intevel , user 0 to disable Speedtests use -sn to prevent logging to results list
-s, speedtest Set speedtest interval, user 0 to disable Speedtests, use -sn to prevent logging to results list
-in Reinstall Speedtest Mod
-up [un] [db] Update Pi-hole (and | but uninstall) the Mod (and flush the database)
-un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete the database)
-db Flush the database
-sd Set speedtest display range
-sn Run speedtest now
-sm Speedtest Mode
-sc Clear speedtest data
-ss Set custom server
-st Set default speedtest chart type (line, bar)
-l, privacylevel Set privacy level (0 = lowest, 3 = highest)
-t, teleporter Backup configuration as an archive
-t, teleporter myname.tar.gz Backup configuration to archive with name myname.tar.gz as specified"
Expand Down Expand Up @@ -498,21 +503,19 @@ SetWebUILayout() {
}

ClearSpeedtestData() {
mv $speedtestdb $speedtestdb"_old"
mv $speedtestdb $speedtestdb.old
cp /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.db $speedtestdb
}

ChageSpeedTestSchedule() {
ChangeSpeedTestSchedule() {
if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then
if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 24 ]; then
addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}"
SetCronTab ${args[2]}
SetService ${args[2]}
fi
fi
}



SpeedtestServer() {
if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then
addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "${args[2]}"
Expand All @@ -522,10 +525,6 @@ SpeedtestServer() {
fi
}

RunSpeedtestNow() {
/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh
}

SpeedtestMode() {
if [[ "${args[2]}" ]]; then
addOrEditKeyValPair "${setupVars}" "SPEEDTEST_MODE" "${args[2]}"
Expand All @@ -536,38 +535,90 @@ SpeedtestMode() {

}

function UpdateSpeedTestRange() {
UpdateSpeedTestRange() {
if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then
if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 30 ]; then
addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_DAYS" "${args[2]}"
fi
fi
}

SetCronTab() {
UpdateSpeedTestChartType() {
if [[ "${args[2]}" =~ ^(bar|line)$ ]]; then
addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "${args[2]}"
else
addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "line"
fi
}

SetService() {
# Remove OLD
crontab -l >crontab.tmp || true

sed -i '/speedtest/d' crontab.tmp
crontab crontab.tmp && rm -f crontab.tmp
if [[ "$1" == "0" ]]; then
sed -i '/speedtest/d' crontab.tmp
crontab crontab.tmp && rm -f crontab.tmp
systemctl disable --now pihole-speedtest.timer &> /dev/null
else
sed -i '/speedtest/d' crontab.tmp
sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF
[Unit]
Description=Pi-hole Speedtest
After=network.target

[Service]
User=root
CPUQuota=20%
Type=oneshot
ExecStart=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh

[Install]
WantedBy=multi-user.target
EOF'
freq=$([ "$1" -lt "24" ] && echo "00/$1:00" || [ "$1" -eq "24" ] && echo "daily" || echo "daily,$(($1/24)):$((($1%24)*60))")
sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF
[Unit]
Description=Pi-hole Speedtest Timer

[Timer]
OnCalendar='$freq'
Persistent=true

[Install]
WantedBy=timers.target
EOF'
systemctl daemon-reload
systemctl reenable pihole-speedtest.timer &> /dev/null
systemctl restart pihole-speedtest.timer
fi
}

mode=$(sed -n -e '/SPEEDTEST_MODE/ s/.*\= *//p' $setupVars)
RunSpeedtestNow() {
if ! command -v tmux &> /dev/null; then
apt-get install tmux -y
fi
tmux new-session -d -s pimod "cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh | sudo bash"
}

if [[ "$mode" =~ "official" ]]; then
speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh"
else
speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh"
fi
ReinstallSpeedTest() {
if ! command -v tmux &> /dev/null; then
apt-get install tmux -y
fi
tmux new-session -d -s pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | sudo bash"
}

newtab="0 */"${1}" * * * sudo \""${speedtest_file}"\" > /dev/null 2>&1"
printf '%s\n' "$newtab" >>crontab.tmp
crontab crontab.tmp && rm -f crontab.tmp
UpdateSpeedTest() {
if ! command -v tmux &> /dev/null; then
apt-get install tmux -y
fi
tmux new-session -d -s pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}"
}

UninstallSpeedTest() {
if ! command -v tmux &> /dev/null; then
apt-get install tmux -y
fi
uninstallfile="/var/www/html/admin/scripts/pi-hole/speedtest/uninstall.sh"
tmux new-session -d -s pimod "cat $uninstallfile | sudo bash -s -- ${args[2]}"
}

SetWebUITheme() {
addOrEditKeyValPair "${setupVars}" "WEBTHEME" "${args[2]}"
Expand Down Expand Up @@ -912,12 +963,17 @@ main() {
"audit" ) addAudit "$@";;
"clearaudit" ) clearAudit;;
"-l" | "privacylevel" ) SetPrivacyLevel;;
"-s" | "speedtest" ) ChageSpeedTestSchedule;;
"-s" | "speedtest" ) ChangeSpeedTestSchedule;;
"-in" ) ReinstallSpeedTest;;
"-up" ) UpdateSpeedTest;;
"-un" ) UninstallSpeedTest;;
"-db" ) ClearSpeedtestData;;
"-sd" ) UpdateSpeedTestRange;;
"-sn" ) RunSpeedtestNow;;
"-sm" ) SpeedtestMode;;
"-sc" ) ClearSpeedtestData;;
"-ss" ) SpeedtestServer;;
"-st" ) UpdateSpeedTestChartType;;
"addcustomdns" ) AddCustomDNSAddress;;
"removecustomdns" ) RemoveCustomDNSAddress;;
"addcustomcname" ) AddCustomCNAMERecord;;
Expand Down