ponmngr: Refactor code.

Cleanup code and make sure we can use whitespace
in passwords.
This commit is contained in:
Markus Gothe 2024-03-05 15:23:14 +01:00
parent 504d124486
commit b8b2dcb6fe
5 changed files with 69 additions and 68 deletions

View file

@ -3,39 +3,34 @@
. /lib/functions.sh . /lib/functions.sh
set_serial_number() { set_serial_number() {
vendor_id=$1 local vendor_id="$1"
vssn=$2 local vssn="$2"
# Vendor id is not taken from serial automatically, propagate it as well # Vendor id is not taken from serial automatically, propagate it as well
/userfs/bin/omcicfgCmd set vendorId ${vendor_id} /userfs/bin/omcicfgCmd set vendorId "${vendor_id}"
/userfs/bin/omcicfgCmd set sn ${vendor_id}${vssn} /userfs/bin/omcicfgCmd set sn "${vendor_id}${vssn}"
} }
set_equipment_id() { set_equipment_id() {
local eqid=$1 local eqid="$1"
local eq_id_default="KE2.119.241R2B"
if [ -z "$eqid" ]; then if [ -z "${eqid}" ]; then
return return
fi fi
if [ "$eqid" = "$eq_id_default" ]; then /userfs/bin/omcicfgCmd set equipmentId "${eqid}"
return
fi
/userfs/bin/omcicfgCmd set equipmentId ${eqid}
} }
set_loid_authentication() { set_loid_authentication() {
local loid=$1 local loid="$1"
local loid_pwd=$2 local loid_pwd="$2"
[ -z "$loid" ] && return [ -z "${loid}" ] && return
/userfs/bin/omcicfgCmd set loid ${loid} /userfs/bin/omcicfgCmd set loid "${loid}"
if [ -n "$loid_pwd" ]; then if [ -n "${loid_pwd}" ]; then
/userfs/bin/omcicfgCmd set loidPasswd ${loid_pwd} /userfs/bin/omcicfgCmd set loidPasswd "${loid_pwd}"
fi fi
} }

View file

@ -3,37 +3,39 @@
. /lib/functions.sh . /lib/functions.sh
set_serial_number() { set_serial_number() {
vendor_id=$1 local vendor_id="$1"
vssn=$2 local vssn="$2"
vendor_id="$(echo $vendor_id | hexdump -e '4/1 "%02X" "\n"')" vendor_id="$(echo "${vendor_id}" | hexdump -e '4/1 "%02X" "\n"')"
vendor_id=${vendor_id:0:8} vendor_id="${vendor_id:0:8}"
bs /b/c gpon onu_sn={vendor_id=$vendor_id,vendor_specific=$vssn} bs /b/c gpon onu_sn={vendor_id=$vendor_id,vendor_specific=$vssn}
} }
set_equipment_id() { set_equipment_id() {
equipment_id=$1 local equipment_id="$1"
[ -z "$equipment_id" ] && return [ -z "$equipment_id" ] && return
json_add_string "equipment_id" $equipment_id json_add_string "equipment_id" "$equipment_id"
} }
set_loid_authentication() { set_loid_authentication() {
loid=$1 local loid="$1"
loid_password=$2 local loid_password="$2"
[ -z "$loid" ] && return [ -z "$loid" ] && return
json_add_string "loid" $loid json_add_string "loid" "$loid"
json_add_string "loid_password" $loid_password json_add_string "loid_password" "$loid_password"
} }
apply_xpon_uci_config() { apply_xpon_uci_config() {
local sn
json_init json_init
json_add_object 'ani' json_add_object 'ani'
sn="$(uci -q get xpon.ani.serial_number)" sn="$(uci -q get xpon.ani.serial_number)"
json_add_string "serial_number" $sn json_add_string "serial_number" "$sn"
configure_loid_authentication configure_loid_authentication
configure_equipment_id configure_equipment_id
json_close_object json_close_object

View file

@ -11,21 +11,21 @@ include /lib/xpon
configure_serial_number() { configure_serial_number() {
# serial number generation is taken care in the uci defaults, so if # serial number generation is taken care in the uci defaults, so if
# serial number is not found here its a misconfig # serial number is not found here its a misconfig
serial_number="$(uci -q get xpon.ani.serial_number)" local serial_number="$(uci -q get xpon.ani.serial_number)"
if [ ${#serial_number} -eq 12 ]; then if [ ${#serial_number} -eq 12 ]; then
vendor_id="${serial_number:0:4}" local vendor_id="${serial_number:0:4}"
vssn="${serial_number:4:8}" local vssn="${serial_number:4:8}"
else else
logger -s -t "xpon" "Serial number not found in uci, ont will probably not be registered at the olt" logger -s -t "xpon" "Serial number not found in UCI, ONT will probably not be registered at the OLT."
logger -s -t "xpon" "Please configure a valid serial number" logger -s -t "xpon" "Please configure a valid serial number."
return return
fi fi
set_serial_number $vendor_id $vssn set_serial_number "${vendor_id}" "${vssn}"
} }
start_service() { start_service() {
if [ "$(uci -q get xpon.ani.enable)" == "1" ]; then if [ "$(uci -q get xpon.ani.enable)" = "1" ]; then
configure_serial_number configure_serial_number
apply_xpon_uci_config apply_xpon_uci_config
init_xpon init_xpon

View file

@ -3,14 +3,15 @@
configure_serial_number() { configure_serial_number() {
# check if serial number is present in the production data # check if serial number is present in the production data
production_sn="$(fw_printenv -n gponsn)" local production_sn="$(fw_printenv -n gponsn)"
if [ ${#production_sn} -eq 12 ]; then if [ ${#production_sn} -eq 12 ]; then
uci set xpon.ani.serial_number=$production_sn uci set xpon.ani.serial_number="${production_sn}"
else else
macaddr="$(fw_printenv -n ethaddr | tr -d ':' | tr 'a-z' 'A-Z')" local macaddr="$(fw_printenv -n ethaddr | tr -d ':' | tr 'a-z' 'A-Z')"
vendor_id="IOPS" local vendor_id="IOPS"
vssn="${macaddr:4:8}" local vssn="${macaddr:4:8}"
uci set xpon.ani.serial_number=$vendor_id$vssn
uci set xpon.ani.serial_number="${vendor_id}${vssn}"
fi fi
} }
@ -18,37 +19,38 @@ configure_loid_authentication() {
local production_loid local production_loid
local production_loidpwd local production_loidpwd
loid="$(uci -q get xpon.ani.loid)" local loid="$(uci -q get xpon.ani.loid)"
loidpwd="$(uci -q get xpon.ani.loid_password)" local loidpwd="$(uci -q get xpon.ani.loid_password)"
if [ -z $loid ]; then
if [ -z "${loid}" ]; then
production_loid="$(fw_printenv -n gponloid)" production_loid="$(fw_printenv -n gponloid)"
fi fi
if [ -z $loidpwd ]; then if [ -z "${loidpwd}" ]; then
production_loidpwd="$(fw_printenv -n gponloid_password)" production_loidpwd="$(fw_printenv -n gponloid_password)"
fi fi
if [ -n $production_loid ]; then if [ -n "${production_loid}" ]; then
uci set xpon.ani.loid=$production_loid uci set xpon.ani.loid="${production_loid}"
fi fi
if [ -n $production_loidpwd ]; then if [ -n "${production_loidpwd}" ]; then
uci set xpon.ani.loid_password=$production_loidpwd uci set xpon.ani.loid_password="${production_loidpwd}"
fi fi
} }
if [ -s "/etc/config/xpon" ]; then if [ -s "/etc/config/xpon" ]; then
if uci -q get xpon.ani >/dev/null; then if uci -q get xpon.ani >/dev/null; then
# generate serial number in case its not present and return # generate serial number in case its not present and return
serial_number="$(uci -q get xpon.ani.serial_number)" SERIAL_NUMBER="$(uci -q get xpon.ani.serial_number)"
if [ ${#serial_number} -ne 12 ]; then if [ ${#SERIAL_NUMBER} -ne 12 ]; then
configure_serial_number configure_serial_number
fi fi
configure_loid_authentication configure_loid_authentication
exit exit
else else
rm -f /etc/config/xpon rm -f /etc/config/xpon
fi fi
fi fi
touch /etc/config/xpon touch /etc/config/xpon
uci set xpon.ani=ani uci set xpon.ani=ani

View file

@ -1,13 +1,15 @@
#!/bin/sh #!/bin/sh
configure_equipment_id() { configure_equipment_id() {
eqid="$(uci -q get xpon.ani.equipment_id)" local eqid="$(uci -q get xpon.ani.equipment_id)"
set_equipment_id $eqid
} set_equipment_id "${eqid}"
}
configure_loid_authentication() {
loid="$(uci -q get xpon.ani.loid)" configure_loid_authentication() {
loid_pwd="$(uci -q get xpon.ani.loid_password)" local loid="$(uci -q get xpon.ani.loid)"
set_loid_authentication $loid $loid_pwd local loid_pwd="$(uci -q get xpon.ani.loid_password)"
set_loid_authentication "${loid}" "${loid_pwd}"
} }