Is there any way to activate a WAN (Wifi) and to switch it of e.g. during weekends to save energie? I was able to create a schedule, but I can only find ways to administrate services with the firewall but no way to ton on / turn of a Wifi?
Best, hirschferkel
have you thought about writing a simple script with ifconfig <WAN interface name> down and another one for up and add it to your CRON jobs?
Hmm I would... if I could...
Absolutely no idea how to write such a script and how to apply it. Anny help would be really appreciated. Sounds like it would work, but as I mentioned, I have no idea how to create it...
Quote from: littlepepper on September 15, 2020, 01:41:52 PM
have you thought about writing a simple script with ifconfig <WAN interface name> down and another one for up and add it to your CRON jobs?
In general brush you would need to ssh into your opnsense machine.
You would need to write 2 text files (scripts) one for up and one for down using a text editor like vi. It can be as simple as
#!/bin/sh
ifconfig <your interface here> up
then add the scripts to cron (of course you need to figure out the when)
Here is a reference: https://docs.opnsense.org/development/backend/configd.html
If you are not comfortable, it is best to buy some support hours and get it looked at instead
https://www.deciso.com/business-support/
Seems practicable, but where do I need to arrange the "when". Within the scripts or do I have to schedule the cron-jobs? Actually I found the reference, but it's one of those no one will ever understand. It's written for those who know how it works and don't need a description... those who need one, won't understand it.
Is it an external Wifi access point?
No it's an OPNsense Access Point so basically the idea is right, to switch on/off a ath0 interface temporarily.
OK. it's pretty simple, I'll try and guide you through it.
First thing you need as has been pointed out is a couple of scripts, one to enable, one to disable, this can actually be done in one script and we'll use that method. We need to call the function ifconfig igb0 up or ifconfig igb0 down, I've attached the script that calls these functions. You may need to change it as the interface may not be igb0.
Next you need to create the conf file that configd uses to add the functions to the Cron avalable functions list. I've created that too and attached it.
So you have the scripts and we need to put them in the correct directories. Copy the *.sh file to the folder /usr/local/etc/rc.d, once copied set its permissions to 755 so it's executable. Next copy the *.conf file to the /usr/local/opnsense/service/conf/actions.d folder. Now we need to tell opnsense to read the new config file so that the calls are added to the cron functions list. In a shell, enter the following command:
# service configd restart
Finally, we need to add the Cron events themselves, so go to System: Settings: Cron and click on the '+' to add a new event. Set the day, time etc of the interface down event and the select the 'Disable Interface' from the command list. Repeat for the up event and select the 'Enable Interface'.
That's it, it should all work. Try and understand what's happening rather than just copy and paste, it will prove beneficial down the line if you understand what's going on.
Oh great, I'll try to set it up next days and give a feedback on it!
Thanks a lot in advance.
Best, hirschferkel
@marjohn56
I replaced the interface igb0
in the script with ath0_wlan2
e.g. ifconfig ath0_wlan2 down
Than I tried to set it up and it took me a while, as I had to enable ssh. (Did not recognize that it was not activated a while, as I was able to login ...but as I saw later connection was closed immediately afterwards)
I had to enable root, too, with ssh (Copying files did not work with admin users, which I would not have expected to fail)
I had to move the files from my home to the ssh server... was tricky to find the right way to copy from home to ssh server.
Finally I finalized all steps and created a test cron job to see if it works
0 11 18 09 5 Test Disable Disable Interface
5 11 18 09 5 Test Enable Enable Interface
and --- it did not...
So time is 11.03 Friday 18th of September and Interface is up...
I tried a different setting:
14 11 * * * Test Disable Disable Interface
15 11 * * * Test Enable Enable Interface
...11:14:30... ath0_wlan2 Interface is still up.
Doesn't work so far, too.
Rebootet.
Applied the "button"... no result. Any idea?
So the cron job is being executed, but aborted with returned exit status 127?
Quote from: marjohn56 on September 17, 2020, 10:06:59 AM
That's it, it should all work. Try and understand what's happening rather than just copy and paste, it will prove beneficial down the line if you understand what's going on.
So i found these log entries:
2020-09-18T11:50:00 configd.py[32149] [83286599-3f93-4a5c-895d-149fcb25ad83] returned exit status 127
2020-09-18T11:50:00 configd.py[32149] [83286599-3f93-4a5c-895d-149fcb25ad83] Disabling Interface
tried to execute another test:
2020-09-18T14:14:32 configd.py[32149] [37f6a30b-8b51-41f0-8de3-fd7f528db74f] restarting cron
2020-09-18T14:14:32 configd.py[32149] OPNsense/Cron generated //var/cron/tabs/nobody
2020-09-18T14:14:32 configd.py[32149] generate template container OPNsense/Cron
same again:
2020-09-18T14:16:00 configd.py[32149] [9945d40d-1b08-47c1-b793-200f0cac8655] returned exit status 127
2020-09-18T14:16:00 configd.py[32149] [9945d40d-1b08-47c1-b793-200f0cac8655] Disabling Interface
Let me check locally, see if I can see what the issue is.
Ok, must have been having a 'doh' moment... replace the conf file with the one attached as there was an error. However, the error you are seeing would suggest you haven't set the executable flags on the sh file, so check that.
You can test from the shell to see if it works, type the following in a shell.
To bring the interface up
# /usr/local/etc/rc.d/interface_up_down.sh up
To take it down
# /usr/local/etc/rc.d/interface_up_down.sh down
You can also test using the configctl which is what Cron calls.
# configctl interface_up_down down
# configctl interface_up_down up
Quote from: marjohn56 on September 18, 2020, 05:09:22 PM
the error you are seeing would suggest you haven't set the executable flags on the sh file, so check that.
Do you mean the 755 rights? I've set the rc.d like
drwxr-xr-x 2 root wheel 1024 Sep 18 10:42 rc.d
and
-rwxr-xr-x 1 root wheel 220 Sep 18 10:17 Interface_up_down.sh
# /usr/local/etc/rc.d/interface_up_down.sh down
-sh: /usr/local/etc/rc.d/interface_up_down.sh: not found
Even with the new file it does not work. I still get the 127 error?
Made a restart and
2020-09-18T19:45:00 configd.py[35743] [c0de5caa-ec09-4a6a-bc82-d7d9933daf0c] returned exit status 127
# configctl interface_up_down down
Error (127)
# /usr/local/etc/rc.d/interface_up_down.sh down
-sh: /usr/local/etc/rc.d/interface_up_down.sh: not found
There was a wrong set up in the files...
You named it Interface_up_down.sh
An wrote
/usr/local/etc/rc.d/interface_up_down.sh up
Now it works! Thanks for your help.
Just seeing if you were awake. :)
OK,,, it works now, that's good.
:D
Quote from: marjohn56 on September 18, 2020, 11:17:17 PMJust seeing if you were awake. :)
One more question: The whole procedure was to save energy by stopping the Wifi activity while it is not being used. So I'm little bit unsure if this works this way, as the interface is down, now, but the interface still shows as being "active" in the GUI?
Any idea why it is still marked active although it was shut down by the cron job?
Hence I asked in an earlier message if it was an external IF. Not sure either, but if it's built in to the gateway maybe not, as the Kernel will enable it. So test it, take the interface down and see if the SSID is still visible.
I think you got me wrong. The Wifi is down, everything o.k it is not visible for devices anymore.
But in the Web GUI of OPNsense under Interfaces, the SSID is still marked as being active (See the screenshot)
I would have expected that it should be marked inactive, as it was switched of by the cron-job, wasn't it?
Best
Quote from: marjohn56 on September 19, 2020, 02:06:13 PM
Hence I asked in an earlier message if it was an external IF. Not sure either, but if it's built in to the gateway maybe not, as the Kernel will enable it. So test it, take the interface down and see if the SSID is still visible.
if the SSID is down that's the best you can hope for, it's not transmitting. I suspect it's the same as the WAN interface, could be enabled, but could still be down.