#!/bin/sh

uci set uhttpd.main.script_timeout='300'
uci set uhttpd.main.network_timeout='300'
uci set uhttpd.main.rpctimeout='300'
uci set uhttpd.main.max_requests='6'
uci set uhttpd.main.redirect_https='1'
uci set uhttpd.main.http_keepalive='1'
uci set uhttpd.defaults.key_type='ec'
uci set uhttpd.defaults.ec_curve='P-256'

SERIALNUM=`head -c6 /proc/device-tree/lantronix/macaddrs/macaddr0/mac-address | hexdump -v -e '/1 "%2X"' | sed 's/\ /0/g'`
MODEL=`cat /proc/device-tree/lantronix/pid | awk '{print substr($0,0,4)}' | tr -d '\n'`
G526RP=`cat /proc/device-tree/lantronix/hwcfg 2>/dev/null | grep 'G526RP' | awk -F'sku=' '{print $2}' | awk -F',' '{print $1}' | awk '{print substr($0,0,6)}' | tr -d '\n'`
if [[ "$G526RP" != "" ]]; then
	MODEL=$G526RP
fi
[ "$MODEL" == "X30x" ] && {
  	MODEL=`cat /proc/device-tree/lantronix/pid | awk '{print substr($0,6,4)}' | tr -d '\n'`
}
uci set uhttpd.defaults.commonname='Lantronix-'$MODEL-$SERIALNUM
uci commit uhttpd

# remove LuCI cache
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache

exit 0
