141 lines
3.7 KiB
Bash
Executable File
141 lines
3.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# /etc/bewan/scripts/update_tr111_table
|
|
|
|
# Create/update TR-111 and WT-111 devices in the permanent table Services_TR111_Device
|
|
|
|
# Load configuration parmaters
|
|
ARG=''
|
|
. /etc/bewan/init.d/setparam
|
|
|
|
# Build a cli script
|
|
build_tr111_cli_script() {
|
|
|
|
rm -f $cli_file
|
|
local index
|
|
|
|
# Compute the number of entries in the table
|
|
local i=0
|
|
for index in $(strip $Services_TR111_Device_List); do
|
|
i=$(($i + 1))
|
|
done
|
|
# If the number of entries is greater than 15, remove not active/retained entries
|
|
if [ $i -gt 15 ]; then
|
|
for index in $(strip $Services_TR111_Device_List); do
|
|
local active="$(echo "status 1; cd _Services_TR111_Device_$index; get Active" | cli -q)"
|
|
local retain; eval retain=\${'Services_TR111_Device_'$index'_RetainDeviceEntry'}
|
|
if [ "$active" != 1 ] && [ "$retain" != 1 ]; then
|
|
base_log "Remove inactive device $index from TR-111 device table" debug
|
|
cat >>$cli_file <<EOF
|
|
cd _Services_TR111_Device
|
|
rm $index
|
|
EOF
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if [ -f $cli_file ]; then
|
|
# Commit the table entry removal
|
|
echo fcommit >>$cli_file
|
|
cli -s <$cli_file
|
|
rm -f $cli_file
|
|
# Reload modified config file
|
|
base_load_param
|
|
fi
|
|
|
|
# There is no TR111/WT111 device
|
|
[ ! -f "$device_file" ] && return
|
|
|
|
# Read device_file
|
|
local mac='' ip='' type='' oui='' serial='' class=''
|
|
while read mac ip type oui serial class; do
|
|
|
|
# Discard entry of type TR111 if TR111 is disabled
|
|
if [ "$type" = 'TR111' ] && [ "$Services_TR111_TR111Enable" != 1 ]; then
|
|
continue;
|
|
fi
|
|
# Discard entry of type WT111 if WT111 is disabled
|
|
if [ "$type" = 'WT111' ] && [ "$Services_TR111_WT111Enable" != 1 ]; then
|
|
continue;
|
|
fi
|
|
|
|
# Search for the device entry in the table
|
|
local found=0
|
|
for index in $(strip $Services_TR111_Device_List); do
|
|
local dev_mac; eval dev_mac=\${'Services_TR111_Device_'$index'_MACAddress'}
|
|
[ "$dev_mac" != "$mac" ] && continue
|
|
found=1
|
|
break
|
|
done
|
|
|
|
# Entry is not found, device is new (just being plugged)
|
|
# Compute the maximum index in the table
|
|
if [ $found = 0 ]; then
|
|
index=0
|
|
for i in $(strip $Services_TR111_Device_List); do
|
|
[ $i -le $index ] && continue
|
|
index=$i
|
|
done
|
|
# New entry will have maximum index + 1
|
|
index=$(($index + 1))
|
|
# Create the entry
|
|
cat >>$cli_file <<EOF
|
|
cd _Services_TR111_Device
|
|
mk $index
|
|
set MACAddress "$mac"
|
|
EOF
|
|
fi
|
|
|
|
# The entry exists, update it with the new parameters
|
|
cat >>$cli_file <<EOF
|
|
cd _Services_TR111_Device_$index
|
|
set IPAddress "$ip"
|
|
set Type "$type"
|
|
set ManufacturerOUI "$oui"
|
|
set SerialNumber "$serial"
|
|
set ProductClass "$class"
|
|
EOF
|
|
|
|
# Is the PassThroughEnable parameter already set (by the ACS) ?
|
|
if [ $found = 1 ]; then
|
|
local pt; eval pt=\${'Services_TR111_Device_'$index'_ConnectionRequestPassThroughEnable'}
|
|
# If passthrough is set and device is of type WT111
|
|
if [ "$pt" = 1 ] && [ "$type" = 'WT111' ]; then
|
|
# Need to recreate the NAT rule
|
|
# This is done by the onchange script of parameter ConnectionRequestPassThroughEnable
|
|
# Setting ConnectionRequestPassThroughEnable to 0 then 1 will force the script to be called
|
|
cat >>$cli_file <<EOF
|
|
set ConnectionRequestPassThroughEnable 0
|
|
set ConnectionRequestPassThroughEnable 1
|
|
EOF
|
|
fi
|
|
fi
|
|
done <$device_file
|
|
}
|
|
|
|
update_tr111_table() {
|
|
|
|
# TR-111 management enabled ?
|
|
if [ $Services_TR111_TR111Enable != 1 ] && [ $Services_TR111_WT111Enable != 1 ]; then
|
|
return
|
|
fi
|
|
|
|
local dir='/var/bewan/tr111.d'
|
|
local device_file="$dir/device_param"
|
|
local cli_file="$dir/device_cli"
|
|
|
|
mkdir -p $dir
|
|
|
|
# Build a cli script that update the permanent table from device_param file
|
|
build_tr111_cli_script
|
|
# Launch cli script if exists
|
|
if [ -f $cli_file ]; then
|
|
cat >>$cli_file <<EOF
|
|
fcommit
|
|
EOF
|
|
cli -s <$cli_file
|
|
fi
|
|
}
|
|
|
|
# main
|
|
update_tr111_table
|