Skip to content

Instantly share code, notes, and snippets.

@mkrkn
Last active May 25, 2020 01:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkrkn/4ba4bef3f0d541aa1180bef4156b340c to your computer and use it in GitHub Desktop.
Save mkrkn/4ba4bef3f0d541aa1180bef4156b340c to your computer and use it in GitHub Desktop.
A sample snippet for editing OpenWrt firewall zone configuration via the UCI command interface. As zone sections are anonymous sections some extra code is needed to discover them. To the extent that the work is copyrightable, it is licensed under the MIT/X11 License.
#!/bin/sh
# Copyright (c) 2020 Magnus Kroken
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
. /lib/functions.sh
lanzone_cfgid=""
wanzone_cfgid=""
find_firewall_zones () {
local config="$1"
local zone_name
config_get zone_name "$config" name
if [ "$zone_name" == "lan" ]
then
lanzone_cfgid="$config"
elif [ "$zone_name" == "wan" ]
then
wanzone_cfgid="$config"
fi
return 0
}
config_load firewall
config_foreach find_firewall_zones zone
uci -q add_list firewall.${wanzone_cfgid}.network='wwan'
uci -q commit firewall
/etc/init.d/firewall reload
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment