#!/bin/sh
. /lib/functions.sh
CONFIG="firewall"

migrate_rule() {
	local section="$1"
	config_get name "$section" "name"
	[ "$name" != "BACnet" ] && return
	config_get src_port "$section" "src_dport"
	uci_remove "$CONFIG" "$section"
	uci_add "$CONFIG" "rule" "$section"
	uci_set "$CONFIG" "$CONFIG_SECTION" "enabled" "1"
	uci_set "$CONFIG" "$CONFIG_SECTION" "proto" "udp"
	uci_set "$CONFIG" "$CONFIG_SECTION" "name" "BACnet"
	uci_set "$CONFIG" "$CONFIG_SECTION" "target" "ACCEPT"
	uci_set "$CONFIG" "$CONFIG_SECTION" "src" "wan"
	uci_set "$CONFIG" "$CONFIG_SECTION" "dest_port" "$src_port"
}
config_load "$CONFIG"
config_foreach migrate_rule "redirect"
uci_commit "$CONFIG"

exit 0
