GL-A1300 Custom Switch / Button Config

Hi All,

First dive into the world of GL.iNet Routers and OpenWRT. I’m testing the GL-A1300 with the hope that it’ll be a great solution for work and our employees who require VPN access back to the office along with switching between Router & Access Point Network Modes on the fly.

I’m trying to make this easy, ideally (and option #1) when holding the reset button for xx seconds, I Import a config saved in /root/router_mode.txt which imports a pre-setup router config for day-to-day operations.
Then when holding the reset button for xxx seconds, I recall the Access Point (or as I like to refer to it, Bridge Mode) file (/root/AP_mode.txt) to switch the device over to Access Point network mode.

I’ve had no luck editing the /etc/rc.button/reset file - although I don’t fully believe this is where I should be making changes anyway.

The second option is to do this with the switch. This will remove the convenience of the VPN being switched on/off easily but I change modes of the router far more than needing the VPN switch.

I have successfully created the 2 config backups and can SSH into the device & recall them using:
uci import < /root/ap_mode.txt
reboot

or

uci import < /root/router_mode.txt
reboot

and this works. However, I can’t for the life of me work out how to edit any of the config files for the button or switch to make this work. I have read many, many posts on similar things but the files either are slightly different or not there. My latest failed thought was to edit the TOR file in \etc\gl-switch-d\ so that I could use the GUI to select the Toggle Switch function as TOR and this would achieve what I want along with making it easy to switch back to Wireguard VPN.

For this I simply changed the \etc\gl-switch-d\TOR file to the following:

#!/bin/sh

action=$1

if [ “$action” = “on” ];then
uci import < /root/ap_mode.txt
reboot
fi

if [ “$action” = “off” ];then
uci import < /root/router_mode.txt
reboot
fi

But I get no response at all when I switch from off/on or reverse.

Anyone have any pointers, or have completed this themselves?

TIA.

Hi Just1,

Did you ever get this working? I've been trying to do the same thing, but I didn't like this method, because it would overwrite any other changes someone made to the configuration. I configured the router as an access point, took a config backup and a dump of all the uci settings, then configured it as a router and took another config backup and uci dump. There were five differences between the uci dumps, and examining the files from the config backup showed only the same five differences:

Gateway mode:
dhcp.lan.ignore='0'
glconfig.general.mode='router'
network.@device[0].ports='lan1' 'lan2'
network.lan.proto='static'
network.wan.disabled='0'

Access Point mode:
dhcp.lan.ignore='1'
glconfig.general.mode='ap'
network.@device[0].ports='lan1' 'lan2' 'wan'
network.lan.proto='dhcp'
network.wan.disabled='1'

I ran into some trouble getting the DHCP server to turn back on when going to gateway mode, so I ended up just running the reset_network script for that, but I got it working:

#!/bin/sh
. /lib/functions/gl_util.sh

action=$1

if [ -f "/tmp/lock/procd_change_routermode.lock" ];then
logger "Still executing previous routermode change"
else
touch /tmp/lock/procd_change_routermode.lock

#Turn on the pulsing blue light (0x00-off, 0x01-steady blue, 0x02-pulsing blue, 0x03-off, 0x04-on, 0x05-on max)
i2cset -f -y 0 0x30 0x04 0x02

if [ "$action" = "on" ];then
mcu_send_message "Switching to Access Point Mode"
uci -q set dhcp.lan.ignore='1'
uci -q set glconfig.general.mode='ap'
uci -q set network.@device[0].ports='lan1'
uci -q add_list network.@device[0].ports='lan2'
uci -q add_list network.@device[0].ports='wan'
uci -q set network.lan.proto='dhcp'
uci -q set network.wan.disabled='1'
uci commit
platform_network_restart
fi

if [ "$action" = "off" ];then
mcu_send_message "Switching to Router Mode"
reset_network
fi

sleep 5

#Turn on the blue light (0x00-off, 0x01-steady blue, 0x02-pulsing blue, 0x03-off, 0x04-on, 0x05-on max)
i2cset -f -y 0 0x30 0x04 0x01

rm -rf /tmp/lock/procd_change_routermode.lock
fi

(I added LED changes for some feedback, and put in a lock file so it doesn't get run repeatedly too quickly.)

I would like to get it to check which mode it's in on startup, and if I get really ambitious I want to try to figure out how to add it to the web interface as a legitimate separate option to pick through.

Oh, I also changed /lib/functions/gl_util.sh and etc/rc.button/switch so that the mcu_send_message() function doesn't run the WireGuard functions when the messages are sent by my script (I adapted the WireGuard script, since my model doesn't have a Tor option).

I hope this helps!

Hi @ealey,

I never did but I'll give this a shot. Thanks so much!