Set Adguard to update blocklists at a specific time?

I have a MT6000 Flint 2. I have adguard setup with Hagezi’s normal list and thread intelligence. Whenever it updates, the whole network slows down for a few minutes. This is fine but it would be ideal to schedule it to happen at like 3am.

Adguard seems to only have an option for interval like daily and no way to set a time.

I thought I might be able to setup a cron job but i dont know how to autneticate to the adguard api properly. It seems it liked to GL somehow. It seems to use an “Auth-Token” cookie. If I copy it from the browser, it seems to work but I assume it will expire

I had this issue on 4.9.0 and it was doing my nut in. Went beck to 4.8.3 and now it’s fine.

Stay awake one night, run the manual update. It will update in the future 24h from that time :slight_smile:

I thought of this but if the router is ever rebooted, won’t this time get reset to the reboot time?

I did come up with a script that logs into the router, gets a token, then sends the command. The only downside is that I have to store my password in the script so I suppose its not exactly the most secure thing.

Hi,

This can be configured by using cron to call the AdGuard Home filter refresh API at a fixed time.
After the configuration is completed, the router can refresh the enabled AdGuard Home blocklists every day at 3:00 AM router local time.
In this way, AdGuard Home will be accessed through its own WebUI and native username/password authentication and after this change, AdGuard Home itself will still work, but the AdGuard section or statistics inside the GL.iNet router UI may no longer display it correctly.

Please follow the steps below.

  1. SSH into the router, back up the related files before making changes.
cp /etc/AdGuardHome/config.yaml /etc/AdGuardHome/config.yaml.bak
cp /etc/init.d/adguardhome /etc/init.d/adguardhome.bak
cp /etc/rc.local /etc/rc.local.bak
  1. Install the required tools.
opkg update
opkg install apache curl
  1. Set an AdGuard Home username and password.
    Replace admin and YOUR_PASSWORD_HERE with your own name and password before running the commands.
AGH_USER='admin'
AGH_PASS='YOUR_PASSWORD_HERE'

HASH="$(htpasswd -B -C 10 -n -b "$AGH_USER" "$AGH_PASS" | cut -d: -f2-)"

sed -i "/^users:/c\\users:\\
  - name: $AGH_USER\\
    password: $HASH" /etc/AdGuardHome/config.yaml
  1. Remove the GL.iNet authentication wrapper and restart AdGuard Home.
sed -i "s/--glinet //g" /etc/init.d/adguardhome
service adguardhome restart
  1. Add the cron job to refresh blocklists at the scheduled time.
    The example below refreshes the blocklists every day at 3:00 AM router local time.
( crontab -l 2>/dev/null | grep -v 'control/filtering/refresh' ; echo "0 3 * * * /usr/bin/curl -fsS -m 300 -u 'admin:YOUR_PASSWORD_HERE' -H 'Content-Type: application/json' --data '{\"whitelist\":false}' 'http://127.0.0.1:3000/control/filtering/refresh?force=true' >>/tmp/agh-filter-refresh.log 2>&1" ) | crontab -

You can change the "0 3" to set your own update time. In cron format, the first number is the minute and the second number is the hour.
6. Enable and restart cron.

/etc/init.d/cron enable
/etc/init.d/cron restart

After this, AdGuard Home will refresh the blocklists automatically every day at 3:00 AM router local time.

Ah, I did something similar (with the help of AI). I noticed that users was blank in the conf so I wasn’t sure if I could just add a user (like you did) without affecting anything.

RPC_URL="127.0.0.1/rpc"
AGH_URL="127.0.0.1:3000/control/filtering/refresh"
USERNAME="root"
PASSWORD="password"
challenge_resp=$(curl -s -X POST "$RPC_URL" -H 'Content-Type: application/json' -d "{"jsonrpc":"2.0","method":"challenge","params":{"username":"$USERNAME"},"id":0}")

alg=$(echo "$challenge_resp" | jq -r '.result.alg')
salt=$(echo "$challenge_resp" | jq -r '.result.salt')
nonce=$(echo "$challenge_resp" | jq -r '.result.nonce')

cipher_password=$(openssl passwd -"$alg" -salt "$salt" "$PASSWORD")

hash=$(printf '%s' "$USERNAME:$cipher_password:$nonce" | sha256sum | cut -d' ' -f1)

login_resp=$(curl -s -X POST "$RPC_URL" -H 'Content-Type: application/json' -d "{"jsonrpc":"2.0","method":"login","params":{"username":"$USERNAME","hash":"$hash"},"id":0}")

sid=$(echo "$login_resp" | jq -r '.result.sid')

curl -s --max-time 60 -X POST "$AGH_URL" -b "Admin-Token=$sid" -H "Content-Type: application/json" -d '{"whitelist": false}' >/dev/null 2>&1

I’m basically copying the typical flow where I login to the router, get the token, then pass it to adguard.