mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-10 07:44:41 +01:00
script optimization Voice parameters: AddObject/DeleteObject Voice parameters: Vendor specific parameter Concerning what we did in the optimization task: 1) The main script (freecwmp) is loaded only 1 time during the session. the load is done just before the start of the session. the function scripts are loaded within the load of the main script (freecwmp) only one time. The old behaviour consist to load the main script (freecwmp) and the function scripts for each parameter treatment. Core code (C) and Scripts are changed 2) Optimize the preparing of inform message. old script take ~30s and now it takes ~2s. Core code (C) and Scripts are changed 3) Execute only the function related to the parameter. For example if the requested parameter is "InternetGatewayDevice.ManagementServer.URL" then the main script freecwmp will execute only the related function of this parameter which is get_management_server(). The old behaviour consist to execute all get functions: get_wan_device(), get_lan_device(), get_device_info()... 4) Minimize the size of the script files: Replace some blocks o othe source code by a functions
141 lines
No EOL
4.4 KiB
Bash
141 lines
No EOL
4.4 KiB
Bash
#!/bin/sh
|
|
# Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
|
|
# Copyright (C) 2013 Inteno Broadband Technology AB
|
|
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
|
|
|
|
get_device_users() {
|
|
local parameter="$1"
|
|
case "$parameter" in
|
|
Device.Users.UserNumberOfEntries)
|
|
local val=`wc -l /etc/passwd | awk '{ print $1 }'`
|
|
freecwmp_value_output "$parameter" "$val"
|
|
return
|
|
;;
|
|
esac
|
|
|
|
local rc
|
|
local num
|
|
|
|
# TODO: Device.Users.User.{i}.Alias (alias support does not exist)
|
|
|
|
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Enable" "rc" "num"
|
|
if [ $rc -eq 0 ]; then
|
|
# TODO: this is very system dependent, for now just look at users shell
|
|
local sed_cmd=`echo -n \'$num; echo p\'`
|
|
local val=`eval sed -n $sed_cmd /etc/passwd | grep -v '/bin/false' | wc -l`
|
|
freecwmp_value_output "$parameter" "$val"
|
|
return
|
|
fi
|
|
|
|
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.RemoteAccessCapable" "rc" "num"
|
|
if [ $rc -eq 0 ]; then
|
|
# TODO: this is very system dependent, for now just look at users shell
|
|
local sed_cmd=`echo -n \'$num; echo p\'`
|
|
local val=`eval sed -n $sed_cmd /etc/passwd | grep -v '/bin/false' | wc -l`
|
|
freecwmp_value_output "$parameter" "$val"
|
|
return
|
|
fi
|
|
|
|
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Username" "rc" "num"
|
|
if [ $rc -eq 0 ]; then
|
|
local sed_cmd=`echo -n \'$num; echo p\'`
|
|
local val=`eval sed -n $sed_cmd /etc/passwd | awk -F ':' '{ print $1 }'`
|
|
freecwmp_value_output "$parameter" "$val"
|
|
return
|
|
fi
|
|
|
|
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Password" "rc" "num"
|
|
if [ $rc -eq 0 ]; then
|
|
# if we *really* wanted to get the password we could do it like this
|
|
# local sed_cmd=`echo -n \'$num; echo p\'`
|
|
# local val=`eval sed -n $sed_cmd /etc/shadow | awk -F ':' '{ print $2 }'`
|
|
# freecwmp_value_output "$parameter" "$val"
|
|
freecwmp_value_output "$parameter" ""
|
|
return
|
|
fi
|
|
|
|
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Language" "rc" "num"
|
|
if [ $rc -eq 0 ]; then
|
|
freecwmp_value_output "$parameter" ""
|
|
return
|
|
fi
|
|
return $FAULT_CPE_INVALID_PARAMETER_NAME
|
|
}
|
|
|
|
set_device_users() {
|
|
local parameter="$1"
|
|
local value="$2"
|
|
|
|
local rc
|
|
local num
|
|
|
|
# TODO: Device.Users.User.{i}.Alias (alias support does not exist)
|
|
|
|
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Enable" "rc" "num"
|
|
if [ $rc -eq 0 ]; then
|
|
# TODO: this is very system dependent, for now just look at users shell
|
|
local val
|
|
if [ "$value" = "1" ]; then
|
|
val="/bin/ash"
|
|
else
|
|
val="/bin/false"
|
|
fi
|
|
local sed_cmd
|
|
sed_cmd=`echo -n \'$num; echo p\'`
|
|
local orig=`eval sed -n $sed_cmd /etc/passwd | awk -F ':' '{ print $7 }'`
|
|
sed_cmd=`echo -n \'$num; echo s%:$orig%:$val%\'`
|
|
eval sed -i $sed_cmd /etc/passwd
|
|
return
|
|
fi
|
|
|
|
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.RemoteAccessCapable" "rc" "num"
|
|
if [ $rc -eq 0 ]; then
|
|
# TODO: this is very system dependent, for now just look at users shell
|
|
local val
|
|
if [ "$value" = "1" ]; then
|
|
val="/bin/ash"
|
|
else
|
|
val="/bin/false"
|
|
fi
|
|
local sed_cmd
|
|
sed_cmd=`echo -n \'$num; echo p\'`
|
|
local orig=`eval sed -n $sed_cmd /etc/passwd | awk -F ':' '{ print $7 }'`
|
|
sed_cmd=`echo -n \'$num; echo s%:$orig%:$val%\'`
|
|
eval sed -i $sed_cmd /etc/passwd
|
|
return
|
|
fi
|
|
|
|
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Username" "rc" "num"
|
|
if [ $rc -eq 0 ]; then
|
|
local sed_cmd
|
|
sed_cmd=`echo -n \'$num; echo p\'`
|
|
local orig=`eval sed -n $sed_cmd /etc/passwd | awk -F ':' '{ print $1 }'`
|
|
sed_cmd=`echo -n \'$num; echo s%$orig:%$value:%\'`
|
|
eval sed -i $sed_cmd /etc/passwd
|
|
return
|
|
fi
|
|
|
|
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Password" "rc" "num"
|
|
if [ $rc -eq 0 ]; then
|
|
local sed_cmd
|
|
sed_cmd=`echo -n \'$num; echo p\'`
|
|
local orig=`eval sed -n $sed_cmd /etc/shadow | awk -F ':' '{ print $2 }'`
|
|
sed_cmd=`echo -n \'$num; echo s%:$orig:%:$value:%\'`
|
|
eval sed -i $sed_cmd /etc/shadow
|
|
return
|
|
fi
|
|
|
|
# TODO: Device.Users.User.{i}.Language (why? look at the get value function for this parameter)
|
|
}
|
|
|
|
get_device_users_name() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
|
|
|
|
get_device_users_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
|
|
|
|
set_device_users() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
|
|
|
|
set_device_users_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
|
|
|
|
add_device_users() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
|
|
|
|
delete_device_users() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } |