From 4b3ead8987e3c2e75acd87f97a4983aa202c78b1 Mon Sep 17 00:00:00 2001 From: zribiahmed Date: Tue, 5 Feb 2013 08:52:32 +0000 Subject: [PATCH] merge script modifications --- src/config/cwmp | 48 ++-- src/init/cwmpd.init | 4 +- src/scripts/freecwmp.sh | 356 ++++++++++++------------ src/scripts/functions/common | 199 ++++++++----- src/scripts/functions/device_hosts | 32 ++- src/scripts/functions/device_info | 165 ++++------- src/scripts/functions/device_routing | 42 ++- src/scripts/functions/device_users | 25 +- src/scripts/functions/lan_device | 83 +++--- src/scripts/functions/management_server | 125 +++++---- src/scripts/functions/misc | 17 +- src/scripts/functions/wan_device | 95 ++++--- 12 files changed, 628 insertions(+), 563 deletions(-) diff --git a/src/config/cwmp b/src/config/cwmp index 94c63a2..a256c61 100644 --- a/src/config/cwmp +++ b/src/config/cwmp @@ -32,38 +32,22 @@ config scripts list location /usr/share/freecwmp/functions/common # freecwmp specific functions list location /usr/share/freecwmp/functions/device_info - list get_value_function get_device_info - list get_name_function get_device_info_name - list get_notification_function get_device_info_notification - list set_value_function set_device_info - list set_notification_function set_device_info_notification - list get_value_function get_device_info_generic - list get_name_function get_device_info_generic_name - list get_notification_function get_device_info_generic_notification - list set_value_function set_device_info_generic - list set_notification_function set_device_info_generic_notification + list function device_info + list function device_info_generic list location /usr/share/freecwmp/functions/lan_device - list get_value_function get_lan_device - list get_name_function get_lan_device_name - list get_notification_function get_lan_device_notification - list set_value_function set_lan_device - list set_notification_function set_lan_device_notification - list add_object_function add_lan_device - list delete_object_function delete_lan_device + list function lan_device list location /usr/share/freecwmp/functions/management_server - list get_value_function get_management_server - list get_name_function get_management_server_name - list get_notification_function get_management_server_notification - list set_value_function set_management_server - list set_notification_function set_management_server_notification - list get_value_function get_management_server_generic - list get_name_function get_management_server_generic_name - list get_notification_function get_management_server_generic_notification - list set_value_function set_management_server_generic - list set_notification_function set_management_server_generic_notification + list function management_server + list function management_server_generic list location /usr/share/freecwmp/functions/wan_device - list get_value_function get_wan_device - list get_name_function get_wan_device_name - list get_notification_function get_wan_device_notification - list set_value_function set_wan_device - list set_notification_function set_wan_device_notification + list function wan_device + list location /usr/share/freecwmp/functions/misc + list function misc + list location /usr/share/freecwmp/functions/device_users + list function device_users + list location /usr/share/freecwmp/functions/device_hosts + list function device_hosts + list location /usr/share/freecwmp/functions/device_routing + list function device_routing + list location /usr/share/freecwmp/functions/device_ip + list function device_ip \ No newline at end of file diff --git a/src/init/cwmpd.init b/src/init/cwmpd.init index 4fca71a..cd60724 100644 --- a/src/init/cwmpd.init +++ b/src/init/cwmpd.init @@ -59,8 +59,8 @@ check_dhcp() { fi } -start_msg="Starting cwmpd..." -stop_msg="Stopping cwmpd..." +start_msg="Start cwmpd ..." +stop_msg="Stop cwmpd ..." run() { echo $start_msg;printf "\033[A" ;sleep 1 diff --git a/src/scripts/freecwmp.sh b/src/scripts/freecwmp.sh index 764958f..0f8965b 100644 --- a/src/scripts/freecwmp.sh +++ b/src/scripts/freecwmp.sh @@ -1,5 +1,6 @@ #!/bin/sh # Copyright (C) 2011-2012 Luka Perkov +# Copyright (C) 2012 Ahmed Zribi . /lib/functions.sh . /usr/share/shflags/shflags.sh @@ -8,6 +9,7 @@ # define a 'name' command-line string flag DEFINE_boolean 'newline' false 'do not output the trailing newline' 'n' DEFINE_boolean 'value' false 'output values only' 'v' +DEFINE_boolean 'ubus' false 'send values using ubus' 'b' DEFINE_boolean 'empty' false 'output empty parameters' 'e' DEFINE_boolean 'last' false 'output only last line ; for parameters that tend to have huge output' 'l' DEFINE_boolean 'debug' false 'give debug output' 'd' @@ -23,11 +25,13 @@ DEFINE_string 'delay' '' 'scheduled_time for downloading file [download only]' ' FLAGS_HELP=`cat << EOF USAGE: $0 [flags] command [parameter] [values] command: - get [value|notification|tags|all] + get [value|notification|tags|name|all] set [value|notification|tag] + apply [value|notification|download] download factory_reset reboot + end_session EOF` FLAGS "$@" || exit 1 @@ -46,7 +50,6 @@ case "$1" in if [ "$2" = "notification" ]; then __arg1="$3" __arg2="$4" - __arg3="`echo $5| tr '[A-Z]' '[a-z]'`" action="set_notification" elif [ "$2" = "tag" ]; then __arg1="$3" @@ -139,23 +142,33 @@ if [ ${FLAGS_debug} -eq ${FLAGS_TRUE} ]; then echo "[debug] started at \"`date`\"" fi +get_value_functions="" +set_value_functions="" +get_name_functions="" +get_notification_functions="" +set_notification_functions="" +add_object_functions="" +delete_object_functions="" + load_script() { . $1 } -get_value_functions="" -set_value_functions="" +load_function() { + get_value_functions="$get_value_functions get_$1" + set_value_functions="$set_value_functions set_$1" + get_name_functions="$get_name_functions get_$1_name" + get_notification_functions="$get_notification_functions get_$1_notification" + set_notification_functions="$set_notification_functions set_$1_notification" + add_object_functions="$add_object_functions add_$1" + delete_object_functions="$delete_object_functions delete_$1" +} + handle_scripts() { local section="$1" config_get prefix "$section" "prefix" config_list_foreach "$section" 'location' load_script - config_get get_value_functions "$section" "get_value_function" - config_get get_name_functions "$section" "get_name_function" - config_get get_notification_functions "$section" "get_notification_function" - config_get set_value_functions "$section" "set_value_function" - config_get set_notification_functions "$section" "set_notification_function" - config_get add_object_functions "$section" "add_object_function" - config_get delete_object_functions "$section" "delete_object_function" + config_list_foreach "$section" 'function' load_function } config_load cwmp @@ -185,94 +198,90 @@ FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED="18" FAULT_CPE_DOWNLOAD_FAIL_FILE_AUTHENTICATION="19" if [ "$action" = "get_value" -o "$action" = "get_all" ]; then - no_fault="0" + if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then + __tmp_arg="Device." + # TODO: don't check only string length ; but this is only used + # for getting correct prefix of CWMP parameter anyway and accepting empty string + if [ ${#__arg1} -lt ${#__tmp_arg} -a ${#__arg1} -ne 0 ]; then + echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' or '' " + echo "if you want to force script execution with provided parameter use '-f' flag." + exit -1 + fi + fi freecwmp_check_fault "$__arg1" fault_code="$?" if [ "$fault_code" = "0" ]; then - if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( "$__arg1" = "" \) ]; then - __arg1="InternetGatewayDevice." + # TODO: don't return only 'InternetGatewayDevice.' when getting an empty string; but we should both + # parameter with prefix 'InternetGatewayDevice.' and 'Device.' + if [ "$__arg1" = "InternetGatewayDevice." -a "$__arg1" = "" ]; then + __param="InternetGatewayDevice." + else + __param="$__arg1" fi - for function_name in $get_value_functions - do - $function_name "$__arg1" - fault_code="$?" - if [ "$fault_code" = "0" ]; then - no_fault="1" - fi - if [ "$fault_code" = "$FAULT_CPE_INVALID_ARGUMENTS" ]; then - break - fi - done - if [ "$no_fault" = "1" ]; then fault_code="0"; fi + freecwmp_execute_functions "$get_value_functions" "$__param" + fault_code="$?" fi if [ "$fault_code" != "0" ]; then let fault_code=$fault_code+9000 - ubus_freecwmp_output "$__arg1" "" "" "$fault_code" + freecwmp_output "$__arg1" "" "" "" "$fault_code" fi fi if [ "$action" = "get_name" -o "$action" = "get_all" ]; then - no_fault="0" + if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then + __tmp_arg="Device." + # TODO: don't check only string length ; but this is only used + # for getting correct prefix of CWMP parameter anyway and accepting empty string + if [ ${#__arg1} -lt ${#__tmp_arg} -a ${#__arg1} -ne 0 ]; then + echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' or '' " + echo "if you want to force script execution with provided parameter use '-f' flag." + exit -1 + fi + fi freecwmp_check_fault "$__arg1" fault_code="$?" if [ "$fault_code" = "0" ]; then - if [ \( "$__arg2" != "0" \) -a \( "$__arg2" != "1" \) -a \( "$__arg2" != "true" \) -a \( "$__arg2" != "false" \) ]; then - fault_code="$FAULT_CPE_INVALID_ARGUMENTS" - else - if [ "$__arg2" = "true" ]; then - __arg2="1" - elif [ "$__arg2" = "false" ]; then - __arg2="0" - fi + if [ "$__arg2" != "0" -a "$__arg2" != "1" ]; then + fault_code="$E_INVALID_ARGUMENTS" fi if [ "$fault_code" = "0" ]; then - if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( "$__arg1" = "" \) ]; then - ubus_freecwmp_output "InternetGatewayDevice." "0" - if [ \( "$__arg1" = "" \) -a \( "$__arg2" = "1" \) ]; then + # TODO: don't return only 'InternetGatewayDevice.' when getting an empty string; but we should both + # parameters with prefix 'InternetGatewayDevice.' and 'Device.' + if [ "$__arg1" = "InternetGatewayDevice." -o "$__arg1" = "" ]; then + freecwmp_output "InternetGatewayDevice." "" "0" + if [ "$__arg1" = "" -a "$__arg2" = "1" ]; then exit 0 fi - __arg1="InternetGatewayDevice." + __parm="InternetGatewayDevice." + else + __parm="$__arg1" fi - for function_name in $get_name_functions - do - $function_name "$__arg1" "$__arg2" - fault_code="$?" - if [ "$fault_code" = "0" ]; then - no_fault="1" - fi - if [ "$fault_code" = "$FAULT_CPE_INVALID_ARGUMENTS" ]; then - break - fi - done - if [ "$no_fault" = "1" ]; then fault_code="0"; fi + freecwmp_execute_functions "$get_name_functions" "$__parm" "$__arg2" + fault_code="$?" fi fi if [ "$fault_code" != "0" ]; then let fault_code=$fault_code+9000 - ubus_freecwmp_output "$__arg1" "" "" "$fault_code" + freecwmp_output "$__arg1" "" "" "" "$fault_code" fi fi if [ "$action" = "set_value" ]; then - no_fault="0" + if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then + __tmp_arg="Device." + # TODO: don't check only string length ; but this is only used + # for getting correct prefix of CWMP parameter anyway + if [ ${#__arg1} -lt ${#__tmp_arg} ]; then + echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' " + echo "if you want to force script execution with provided parameter use '-f' flag." + exit -1 + fi + fi freecwmp_check_fault "$__arg1" fault_code="$?" if [ "$fault_code" = "0" ]; then - if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( "$__arg1" = "" \) ]; then - __arg1="InternetGatewayDevice." - fi - for function_name in $set_value_functions - do - $function_name "$__arg1" "$__arg2" - fault_code="$?" - if [ "$fault_code" = "0" ]; then - no_fault="1" - fi - if [ "$fault_code" = "$FAULT_CPE_INVALID_ARGUMENTS" ]; then - break - fi - done - if [ "$no_fault" = "1" ]; then fault_code="0"; fi + freecwmp_execute_functions "$set_value_functions" "$__arg1" "$__arg2" + fault_code="$?" fi if [ "$fault_code" != "0" ]; then let fault_code=$fault_code+9000 @@ -281,64 +290,105 @@ if [ "$action" = "set_value" ]; then fi if [ "$action" = "get_notification" -o "$action" = "get_all" ]; then - no_fault="0" + if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then + __tmp_arg="Device." + # TODO: don't check only string length ; but this is only used + # for getting correct prefix of CWMP parameter anyway and accepting empty string + if [ ${#__arg1} -lt ${#__tmp_arg} -a ${#__arg1} -ne 0 ]; then + echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' or '' " + echo "if you want to force script execution with provided parameter use '-f' flag." + exit -1 + fi + fi freecwmp_check_fault "$__arg1" fault_code="$?" if [ "$fault_code" = "0" ]; then - if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( "$__arg1" = "" \) ]; then - __arg1="InternetGatewayDevice." + # TODO: don't return only 'InternetGatewayDevice.' when getting an empty string; but we should both + # parameters with prefix 'InternetGatewayDevice.' and 'Device.' + if [ "$__arg1" = "InternetGatewayDevice." -a "$__arg1" = "" ]; then + __param="InternetGatewayDevice." + else + __param="$__arg1" fi - for function_name in $get_notification_functions - do - $function_name "$__arg1" - fault_code="$?" - if [ "$fault_code" = "0" ]; then - no_fault="1" - fi - if [ "$fault_code" = "$FAULT_CPE_INVALID_ARGUMENTS" ]; then - break - fi - done - if [ "$no_fault" = "1" ]; then fault_code="0"; fi + freecwmp_execute_functions "$get_notification_functions" "$__param" + fault_code="$?" fi if [ "$fault_code" != "0" ]; then let fault_code=$fault_code+9000 - ubus_freecwmp_output "$__arg1" "" "" "$fault_code" + freecwmp_output "$__arg1" "" "" "" "$fault_code" fi fi if [ "$action" = "set_notification" ]; then - if [ "$__arg3" = "true" ]; then - __arg3="1" - elif [ "$__arg3" = "false" ]; then - __arg3="0" + if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then + __tmp_arg="Device." + # TODO: don't check only string length ; but this is only used + # for getting correct prefix of CWMP parameter anyway + if [ ${#__arg1} -lt ${#__tmp_arg} ]; then + echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' " + echo "if you want to force script execution with provided parameter use '-f' flag." + exit -1 + fi fi - if [ "$__arg3" = "1" ]; then - no_fault="0" - freecwmp_check_fault "$__arg1" + freecwmp_check_fault "$__arg1" + fault_code="$?" + if [ "$fault_code" = "0" ]; then + freecwmp_execute_functions "$set_notification_functions" "$__parm" "$__arg2" fault_code="$?" - if [ "$fault_code" = "0" ]; then - if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( "$__arg1" = "" \) ]; then - __arg1="InternetGatewayDevice." - fi - for function_name in $set_notification_functions - do - $function_name "$__arg1" "$__arg2" - fault_code="$?" - if [ "$fault_code" = "0" ]; then - no_fault="1" - fi - if [ "$fault_code" = "$FAULT_CPE_INVALID_ARGUMENTS" ]; then - break - fi - done - if [ "$no_fault" = "1" ]; then fault_code="0"; fi + fi + if [ "$fault_code" != "0" ]; then + let fault_code=$fault_code+9000 + freecwmp_set_parameter_fault "$__arg1" "$fault_code" + fi +fi + + +if [ "$action" = "add_object" ]; then + if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then + __tmp_arg="Device." + # TODO: don't check only string length ; but this is only used + # for getting correct prefix of CWMP parameter anyway + if [ ${#__arg1} -lt ${#__tmp_arg} ]; then + echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' " + echo "if you want to force script execution with provided parameter use '-f' flag." + exit -1 fi - if [ "$fault_code" != "0" ]; then - let fault_code=$fault_code+9000 - freecwmp_set_parameter_fault "$__arg1" "$fault_code" + fi + no_fault="0" + freecwmp_check_fault "$__arg1" + fault_code="$?" + if [ "$fault_code" = "0" ]; then + freecwmp_execute_functions "$add_object_functions" "$__arg1" + fault_code="$?" + fi + if [ "$fault_code" != "0" ]; then + let fault_code=$fault_code+9000 + freecwmp_output "" "" "" "" "$fault_code" + fi +fi + +if [ "$action" = "delete_object" ]; then + if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then + __tmp_arg="Device." + # TODO: don't check only string length ; but this is only used + # for getting correct prefix of CWMP parameter anyway + if [ ${#__arg1} -lt ${#__tmp_arg} ]; then + echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' " + echo "if you want to force script execution with provided parameter use '-f' flag." + exit -1 fi fi + no_fault="0" + freecwmp_check_fault "$__arg1" + fault_code="$?" + if [ "$fault_code" = "0" ]; then + freecwmp_execute_functions "$delete_object_functions" "$__arg1" + fault_code="$?" + fi + if [ "$fault_code" != "0" ]; then + let fault_code=$fault_code+9000 + freecwmp_output "" "" "" "" "$fault_code" + fi fi if [ "$action" = "get_tags" -o "$action" = "get_all" ]; then @@ -357,7 +407,7 @@ if [ "$action" = "download" ]; then wget -O /tmp/freecwmp_download "${FLAGS_url}" > /dev/null if [ "$?" != "0" ];then let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAILURE - ubus_freecwmp_fault_output "" "$fault_code" + freecwmp_fault_output "" "$fault_code" exit 1 fi else @@ -365,7 +415,7 @@ if [ "$action" = "download" ]; then wget -O /tmp/freecwmp_download "$url" > /dev/null if [ "$?" != "0" ];then let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAILURE - ubus_freecwmp_fault_output "" "$fault_code" + freecwmp_fault_output "" "$fault_code" exit 1 fi fi @@ -374,7 +424,7 @@ if [ "$action" = "download" ]; then if [ ! "$dl_size" -eq "${FLAGS_size}" ]; then let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAILURE rm /tmp/freecwmp_download 2> /dev/null - ubus_freecwmp_fault_output "" "$fault_code" + freecwmp_fault_output "" "$fault_code" else if [ "${FLAGS_type}" = "1" ];then mv /tmp/freecwmp_download /tmp/firmware_upgrade_image 2> /dev/null @@ -385,11 +435,11 @@ if [ "$action" = "download" ]; then if [ $flashsize -gt 0 -a $filesize -gt $flashsize ];then let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED rm /tmp/firmware_upgrade_image 2> /dev/null - ubus_freecwmp_fault_output "" "$fault_code" + freecwmp_fault_output "" "$fault_code" else rm /tmp/firmware_upgrade_image_last_valid 2> /dev/null mv /tmp/firmware_upgrade_image /tmp/firmware_upgrade_image_last_valid 2> /dev/null - ubus_freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" + freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" if [ "${FLAGS_delay}" = "0" ];then echo "/bin/sh /usr/sbin/freecwmp apply download \"${FLAGS_type}\"" > /tmp/end_session.sh ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "name": "action_end_session" }' 2> /dev/null @@ -398,25 +448,25 @@ if [ "$action" = "download" ]; then else let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED rm /tmp/firmware_upgrade_image 2> /dev/null - ubus_freecwmp_fault_output "" "$fault_code" + freecwmp_fault_output "" "$fault_code" fi elif [ "${FLAGS_type}" = "2" ];then mv /tmp/freecwmp_download /tmp/web_content.ipk 2> /dev/null - ubus_freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" + freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" if [ "${FLAGS_delay}" = "0" ];then echo "/bin/sh /usr/sbin/freecwmp apply download \"${FLAGS_type}\"" > /tmp/end_session.sh ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "name": "action_end_session" }' 2> /dev/null fi elif [ "${FLAGS_type}" = "3" ];then mv /tmp/freecwmp_download /tmp/vendor_configuration_file.cfg 2> /dev/null - ubus_freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" + freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" if [ "${FLAGS_delay}" = "0" ];then echo "/bin/sh /usr/sbin/freecwmp apply download \"${FLAGS_type}\"" > /tmp/end_session.sh ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "name": "action_end_session" }' 2> /dev/null fi else let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAILURE - ubus_freecwmp_fault_output "" "$fault_code" + freecwmp_fault_output "" "$fault_code" rm /tmp/freecwmp_download 2> /dev/null fi fi @@ -449,21 +499,25 @@ if [ "$action" = "reboot" ]; then fi fi -if [ \( "$action" = "apply_notification" \) -o \( "$action" = "apply_value" \) ]; then +if [ "$action" = "apply_notification" -o "$action" = "apply_value" ]; then __fault_count=`cat /var/state/cwmp 2> /dev/null |wc -l 2> /dev/null` let __fault_count=$__fault_count/3 if [ "$__fault_count" = "0" ]; then # applying /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit - if [ "$action" = "apply_value" ]; then ubus call tr069 SetParameterValuesStatus '{"status": "0"}'; fi - if [ "$action" = "apply_notification" ]; then ubus call tr069 SetParameterAttributes '{"success": "0", "fault_code":""}' 2> /dev/null; fi + if [ "$action" = "apply_value" ]; then + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 set_parameter_values_status '{ "status": "0" }' 2> /dev/null + fi + if [ "$action" = "apply_notification" ]; then + freecwmp_fault_output "" "" "0" + fi else let n=$__fault_count-1 for i in `seq 0 $n` do local parm=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get cwmp.@fault[$i].parameter 2> /dev/null` local fault_code=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get cwmp.@fault[$i].fault_code 2> /dev/null` - ubus_freecwmp_fault_output "$parm" "$fault_code" + freecwmp_fault_output "$parm" "$fault_code" if [ "$action" = "apply_notification" ]; then break; fi done rm -rf /var/state/cwmp 2> /dev/null @@ -471,60 +525,6 @@ if [ \( "$action" = "apply_notification" \) -o \( "$action" = "apply_value" \) ] fi fi -if [ "$action" = "add_object" ]; then - no_fault="0" - freecwmp_check_fault "$__arg1" - fault_code="$?" - if [ "$fault_code" = "0" ]; then - if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( "$__arg1" = "" \) ]; then - __arg1="InternetGatewayDevice." - fi - for function_name in $add_object_functions - do - $function_name "$__arg1" - fault_code="$?" - if [ "$fault_code" = "0" ]; then - no_fault="1" - fi - if [ "$fault_code" = "$FAULT_CPE_INVALID_ARGUMENTS" ]; then - break - fi - done - if [ "$no_fault" = "1" ]; then fault_code="0"; fi - fi - if [ "$fault_code" != "0" ]; then - let fault_code=$fault_code+9000 - ubus_freecwmp_output "" "" "" "$fault_code" - fi -fi - -if [ "$action" = "delete_object" ]; then - no_fault="0" - freecwmp_check_fault "$__arg1" - fault_code="$?" - if [ "$fault_code" = "0" ]; then - if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( "$__arg1" = "" \) ]; then - __arg1="InternetGatewayDevice." - fi - for function_name in $delete_object_functions - do - $function_name "$__arg1" - fault_code="$?" - if [ "$fault_code" = "0" ]; then - no_fault="1" - fi - if [ "$fault_code" = "$FAULT_CPE_INVALID_ARGUMENTS" ]; then - break - fi - done - if [ "$no_fault" = "1" ]; then fault_code="0"; fi - fi - if [ "$fault_code" != "0" ]; then - let fault_code=$fault_code+9000 - ubus_freecwmp_output "" "" "" "$fault_code" - fi -fi - if [ "$action" = "inform" ]; then action="get_value" diff --git a/src/scripts/functions/common b/src/scripts/functions/common index 78293ca..a3c1ec9 100644 --- a/src/scripts/functions/common +++ b/src/scripts/functions/common @@ -1,5 +1,6 @@ #!/bin/sh # Copyright (C) 2011-2012 Luka Perkov +# Copyright (C) 2012 Ahmed Zribi # TODO: merge this one somewhere in OpenWrt uci_remove_list_element() { @@ -17,85 +18,133 @@ uci_remove_list_element() { } freecwmp_output() { -local parameter="$1" -local value="$2" -local delimiter="$3" - -if [ "$delimiter" = "" ]; then - delimiter=":" -fi - -if [ -n "$value" -o ${FLAGS_empty} -eq ${FLAGS_TRUE} ]; then - if [ ${FLAGS_value} -eq ${FLAGS_TRUE} ]; then - echo $ECHO_newline $value - else - echo $ECHO_newline $parameter "$delimiter" $value + if [ "$FLAGS_value" = "${FLAGS_TRUE}" ]; then + local parameter="$1" + local value="$2" + local delimiter="$3" + + if [ "$delimiter" = "" ]; then + delimiter=":" + fi + if [ -n "$value" -o ${FLAGS_empty} -eq ${FLAGS_TRUE} ]; then + if [ ${FLAGS_value} -eq ${FLAGS_TRUE} ]; then + echo $ECHO_newline $value + else + echo $ECHO_newline $parameter "$delimiter" $value + fi + fi + fi + + if [ "$FLAGS_ubus" = "${FLAGS_TRUE}" ]; then + local parameter="$1" + local value="$2" + local permissions="$3" + local type="$4" + local fault_code="$5" + local status="$6" + local instance="$7" + + freecwmp_ubus_output "$parameter" "$value" "$permissions" "$type" "$fault_code" "$status" "$instance" fi -fi } -ubus_freecwmp_output() { -local parameter="$1" -local value="$2" -local type="$3" -local fault_code="$4" +freecwmp_ubus_output() { -if [ "$type" = "" ]; then - type="xsd:string" -fi + local parameter="$1" + local value="$2" + local permissions="$3" + local type="$4" + local fault_code="$5" + local status="$6" + local instance="$7" -case "$action" in - get_value) - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 GetParameterValues '{"parameter": "'$parameter'", "value": "'$value'", "type": "'$type'", "fault_code":"'$fault_code'"}' 2> /dev/null - ;; - get_name) - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 GetParameterNames '{"parameter": "'$parameter'", "writable": "'$value'", "fault_code":"'$fault_code'"}' 2> /dev/null - ;; - get_notification) - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 GetParameterAttributes '{"parameter": "'$parameter'", "notification": "'$value'", "fault_code":"'$fault_code'"}' 2> /dev/null - ;; - add_object) - local instance="$1" - local status="$2" - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 AddObject '{"instance":"'$instance'", "status":"'$status'", "fault_code":"'$fault_code'"}' 2> /dev/null - ;; - delete_object) - local status="$1" - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 DelObject '{ "status": "'$status'", "fault_code": "'$fault_code'" }' 2> /dev/null - ;; -esac + if [ "$type" = "" ]; then + type="xsd:string" + fi + + case "$action" in + get_value) + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 GetParameterValues '{ "parameter": "'$parameter'", "value": "'$value'", "type": "'$type'", "fault_code":"'$fault_code'" }' 2> /dev/null + ;; + get_name) + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 GetParameterNames '{ "parameter": "'$parameter'", "writable": "'$permissions'", "fault_code": "'$fault_code'" }' 2> /dev/null + ;; + get_notification) + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 GetParameterAttributes '{ "parameter": "'$parameter'", "notification": "'$value'", "fault_code": "'$fault_code'" }' 2> /dev/null + ;; + add_object) + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 AddObject '{"instance":"'$instance'", "status":"'$status'", "fault_code":"'$fault_code'"}' 2> /dev/null + ;; + delete_object) + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 DelObject '{ "status": "'$status'", "fault_code": "'$fault_code'" }' 2> /dev/null + ;; + esac } -ubus_freecwmp_fault_output() { -local parameter="$1" -local fault_code="$2" -case "$action" in - apply_value) - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 SetParameterValuesFault '{"parameter": "'$parameter'", "fault_code": "'$fault_code'"}' 2> /dev/null - ;; - apply_notification) - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 SetParameterAttributes '{"success": "", "fault_code": "'$fault_code'"}' 2> /dev/null - ;; - download) - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 download '{"fault_code": "'$fault_code'"}' 2> /dev/null - ;; -esac +freecwmp_fault_output() { + local parameter="$1" + local fault_code="$2" + local success="$3" + + case "$action" in + apply_value) + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 SetParameterValuesFault '{"parameter": "'$parameter'", "fault_code": "'$fault_code'"}' 2> /dev/null + ;; + apply_notification) + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 SetParameterAttributes '{"success": "'$success'", "fault_code": "'$fault_code'"}' 2> /dev/null + ;; + *download) + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 download '{"fault_code": "'$fault_code'"}' 2> /dev/null + ;; + esac } freecwmp_value_output() { + local tmp_value=${FLAGS_value} + FLAGS_value=${FLAGS_TRUE} + local tmp_ubus=${FLAGS_ubus} + FLAGS_ubus=${FLAGS_FALSE} + freecwmp_output "$1" "$2" "V" + + FLAGS_value=$tmp_value + FLAGS_ubus=$tmp_ubus } freecwmp_notification_output() { + local tmp_value=${FLAGS_value} + FLAGS_value=${FLAGS_TRUE} + local tmp_ubus=${FLAGS_ubus} + FLAGS_ubus=${FLAGS_FALSE} + freecwmp_output "$1" "$2" "N" + + FLAGS_value=$tmp_value + FLAGS_ubus=$tmp_ubus } freecwmp_tags_output() { + local tmp_value=${FLAGS_value} + FLAGS_value=${FLAGS_TRUE} + local tmp_ubus=${FLAGS_ubus} + FLAGS_ubus=${FLAGS_FALSE} + freecwmp_output "$1" "$2" "T" + + FLAGS_value=$tmp_value + FLAGS_ubus=$tmp_ubus } freecwmp_not_implemented() { + local tmp_value=${FLAGS_value} + FLAGS_value=${FLAGS_TRUE} + local tmp_ubus=${FLAGS_ubus} + FLAGS_ubus=${FLAGS_FALSE} + freecwmp_output "$1" "NOT_IMPLEMENTED" + + FLAGS_value=$tmp_value + FLAGS_ubus=$tmp_ubus } freecwmp_parse_formated_parameter() { @@ -355,6 +404,30 @@ if [ "$indice" != "" ]; then fi } +freecwmp_execute_functions() +{ + local function_list="$1" + local arg1="$2" + local arg2="$3" + local arg3="$4" + local no_fault="0" + local fault_code="" + + for function_name in $function_list + do + $function_name "$arg1" "$arg2" "$arg3" + fault_code="$?" + if [ "$fault_code" = "0" ]; then + no_fault="1" + fi + if [ "$fault_code" != "0" -a "$fault_code" != "$E_INVALID_PARAMETER_NAME" ]; then + return $fault_code + fi + done + if [ "$no_fault" = "1" ]; then fault_code="0"; fi + return $fault_code +} + freecwmp_check_image() { . /etc/functions.sh; include /lib/upgrade; platform_check_image /tmp/freecwmp_download @@ -403,9 +476,9 @@ freecwmp_apply_firmware() killall dropbear uhttpd; sleep 1; /sbin/sysupgrade /tmp/firmware_upgrade_image_last_valid if [ "$?" != "0" ];then let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED - ubus_freecwmp_fault_output "" "$fault_code" + freecwmp_fault_output "" "$fault_code" else - ubus_freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" + freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" fi } @@ -417,9 +490,9 @@ freecwmp_apply_web_content() if [ "$?" != "0" ];then rm /tmp/web_content.ipk 2> /dev/null let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED - ubus_freecwmp_fault_output "" "$fault_code" + freecwmp_fault_output "" "$fault_code" else - ubus_freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" + freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" fi } @@ -432,15 +505,15 @@ freecwmp_apply_vendor_configuration() /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit if [ "$?" != "0" ];then let fault_code=$fault_code+$FAULT_CPE_INTERNAL_ERROR - ubus_freecwmp_fault_output "" "$fault_code" + freecwmp_fault_output "" "$fault_code" else - ubus_freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" + freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" sync reboot fi else rm /tmp/vendor_configuration_file.cfg 2> /dev/null let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED - ubus_freecwmp_fault_output "" "$fault_code" + freecwmp_fault_output "" "$fault_code" fi } \ No newline at end of file diff --git a/src/scripts/functions/device_hosts b/src/scripts/functions/device_hosts index 5b41e62..05646bc 100644 --- a/src/scripts/functions/device_hosts +++ b/src/scripts/functions/device_hosts @@ -1,5 +1,6 @@ #!/bin/sh # Copyright (C) 2012 Luka Perkov +# Copyright (C) 2012 Ahmed Zribi get_device_hosts_number_of_leases() { local _static=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} show dhcp 2> /dev/null | fgrep 'dhcp.' | fgrep '.mac=' | wc -l` @@ -44,7 +45,7 @@ local parameter=`echo -n $1 | sed "s/InternetGatewayDevice\.LANDevice\.1\./Devic case "$parameter" in Device.Hosts.HostNumberOfEntries) let local val=$num_static_leases+$num_dynamic_leases - ubus_freecwmp_output "$parameter" "$val" + freecwmp_output "$parameter" "$val" return ;; esac @@ -66,7 +67,7 @@ if [ $rc -eq 0 ]; then local sed_cmd=`echo -n \'$num; echo p\'` val=`eval sed -n $sed_cmd $leases_file | awk '{ print $2 }'` fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -74,7 +75,7 @@ freecwmp_parse_formated_parameter "$parameter" "Device.Hosts.Host.{i}.IPAddress" if [ $rc -eq 0 ]; then local val get_device_hosts_ip_address "$leases_file" "$num" "$num_static_leases" "$num_dynamic_leases" "val" - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -88,7 +89,7 @@ if [ $rc -eq 0 ]; then if [ $num -gt 0 -a $num -le $num_dynamic_leases ]; then val="DHCP" fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -107,7 +108,7 @@ if [ $rc -eq 0 ]; then local t2=`date +%s` let val=$t1-$t2 fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -131,7 +132,7 @@ if [ $rc -eq 0 ]; then val=`eval sed -n $sed_cmd $leases_file | awk '{ print $4 }'` if [ "x$val" == "x*" ]; then val=""; fi fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -144,7 +145,7 @@ if [ $rc -eq 0 ]; then get_device_hosts_ip_address "$leases_file" "$num" "$num_static_leases" "$num_dynamic_leases" "ip" val=`ping -c 1 $ip 2>&1 > /dev/null ; echo $?` let val=!$val - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -156,7 +157,7 @@ if [ $rc -eq 0 ]; then if [ $num -le $n ]; then val=1 fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -168,7 +169,7 @@ if [ $rc -eq 0 ]; then if [ $num -le $n ]; then val=0 fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -182,7 +183,7 @@ if [ $rc -eq 0 ]; then if [ $num2 -eq 1 ]; then get_device_hosts_ip_address "$leases_file" "$num1" "$num_static_leases" "$num_dynamic_leases" "val" fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -190,3 +191,14 @@ fi return $FAULT_CPE_INVALID_PARAMETER_NAME } +get_device_hosts_name() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +get_device_hosts_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +set_device_hosts() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +set_device_hosts_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +add_device_hosts() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +delete_device_hosts() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } \ No newline at end of file diff --git a/src/scripts/functions/device_info b/src/scripts/functions/device_info index 7c38963..f0d9178 100644 --- a/src/scripts/functions/device_info +++ b/src/scripts/functions/device_info @@ -1,62 +1,47 @@ #!/bin/sh # Copyright (C) 2011-2012 Luka Perkov +# Copyright (C) 2012 Ahmed Zribi get_device_info_manufacturer() { local val="" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.cpe.manufacturer 2> /dev/null` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.Manufacturer" ;; esac -ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.Manufacturer" "$val" +freecwmp_output "InternetGatewayDevice.DeviceInfo.Manufacturer" "$val" "$permissions" } set_device_info_manufacturer() { -local val=$1 -local parm="InternetGatewayDevice.DeviceInfo.Manufacturer" -case "$action" in - set_value) - /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.manufacturer="$val" - ;; - set_notification) - freecwmp_set_parameter_notification "$parm" "$val" - ;; -esac + /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.manufacturer="$1" } get_device_info_oui() { local val="" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.cpe.oui 2> /dev/null` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.ManufacturerOUI" ;; esac -ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.ManufacturerOUI" "$val" +freecwmp_output "InternetGatewayDevice.DeviceInfo.ManufacturerOUI" "$val" "$permissions" } set_device_info_oui() { -local val=$1 -local parm="InternetGatewayDevice.DeviceInfo.ManufacturerOUI" -case "$action" in - set_value) - /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.oui="$val" - ;; - set_notification) - freecwmp_set_parameter_notification "$parm" "$val" - ;; -esac + /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.oui="$1" } get_device_info_product_class() { @@ -66,133 +51,102 @@ case "$action" in val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.cpe.product_class 2> /dev/null` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.ProductClass" ;; esac -ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.ProductClass" "$val" +freecwmp_output "InternetGatewayDevice.DeviceInfo.ProductClass" "$val" "$permissions" } set_device_info_product_class() { -local val=$1 -local parm="InternetGatewayDevice.DeviceInfo.ProductClass" -case "$action" in - set_value) - /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.product_class="$val" - ;; - set_notification) - freecwmp_set_parameter_notification "$parm" "$val" - ;; -esac + /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.product_class="$1" } get_device_info_serial_number() { local val="" +local permissions="" case "$action" in get_value) local val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.cpe.serial_number 2> /dev/null` ;; get_name) - local val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.SerialNumber" ;; esac -ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.SerialNumber" "$val" +freecwmp_output "InternetGatewayDevice.DeviceInfo.SerialNumber" "$val" "$permissions" } set_device_info_serial_number() { -local val=$1 -local parm="InternetGatewayDevice.DeviceInfo.SerialNumber" -case "$action" in - set_value) - /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.serial_number="$val" - ;; - set_notification) - freecwmp_set_parameter_notification "$parm" "$val" - ;; -esac + /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.serial_number="$1" } get_device_info_hardware_version() { local val="" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.cpe.hardware_version 2> /dev/null` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.HardwareVersion" ;; esac -ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.HardwareVersion" "$val" +freecwmp_output "InternetGatewayDevice.DeviceInfo.HardwareVersion" "$val" "$permissions" } set_device_info_hardware_version() { -local val=$1 -local parm="InternetGatewayDevice.DeviceInfo.HardwareVersion" -case "$action" in - set_value) - /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.hardware_version="$val" - ;; - set_notification) - freecwmp_set_parameter_notification "$parm" "$val" - ;; -esac + /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.hardware_version="$1" } get_device_info_software_version() { local val="" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.cpe.software_version 2> /dev/null` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.SoftwareVersion" ;; esac -ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.SoftwareVersion" "$val" +freecwmp_output "InternetGatewayDevice.DeviceInfo.SoftwareVersion" "$val" "$permissions" } set_device_info_software_version() { -local val=$1 -local parm="InternetGatewayDevice.DeviceInfo.SoftwareVersion" -case "$action" in - set_value) - /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.software_version="$val" - ;; - set_notification) - freecwmp_set_parameter_notification "$parm" "$val" - ;; -esac + /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.cpe.software_version="$1" } get_device_info_uptime() { local val="" +local permissions="" case "$action" in get_value) val=`cat /proc/uptime | awk -F "." '{ print $1 }'` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.UpTime" ;; esac -ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.UpTime" "$val" +freecwmp_output "InternetGatewayDevice.DeviceInfo.UpTime" "$val" "$permissions" } get_device_info_device_log() { local val="" +local permissions="" case "$action" in get_value) if [ ${FLAGS_last} -eq ${FLAGS_TRUE} ]; then @@ -202,13 +156,13 @@ case "$action" in fi ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.DeviceLog" ;; esac -ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.DeviceLog" "$val" +freecwmp_output "InternetGatewayDevice.DeviceInfo.DeviceLog" "$val" "$permissions" } get_device_info() { @@ -274,7 +228,7 @@ return $FAULT_CPE_INVALID_PARAMETER_NAME get_device_info_name() { case "$1" in InternetGatewayDevice.) - ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo." "0" + freecwmp_output "InternetGatewayDevice.DeviceInfo." "" "0" if [ "$2" = "0" ]; then get_device_info_manufacturer get_device_info_oui @@ -288,7 +242,7 @@ case "$1" in return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.DeviceInfo.) - ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo." "0" + freecwmp_output "InternetGatewayDevice.DeviceInfo." "" "0" get_device_info_manufacturer get_device_info_oui get_device_info_product_class @@ -450,37 +404,7 @@ return $FAULT_CPE_INVALID_PARAMETER_NAME } set_device_info_notification() { -case "$1" in - InternetGatewayDevice.DeviceInfo.) - freecwmp_set_parameter_notification "$1" "$2" - return $FAULT_CPE_NO_FAULT - ;; - InternetGatewayDevice.DeviceInfo.Manufacturer) - set_device_info_manufacturer "$2" - return $FAULT_CPE_NO_FAULT - ;; - InternetGatewayDevice.DeviceInfo.ManufacturerOUI) - set_device_info_oui "$2" - return $FAULT_CPE_NO_FAULT - ;; - InternetGatewayDevice.DeviceInfo.ProductClass) - set_device_info_product_class "$2" - return $FAULT_CPE_NO_FAULT - ;; - InternetGatewayDevice.DeviceInfo.SerialNumber) - set_device_info_serial_number "$2" - return $FAULT_CPE_NO_FAULT - ;; - InternetGatewayDevice.DeviceInfo.HardwareVersion) - set_device_info_hardware_version "$2" - return $FAULT_CPE_NO_FAULT - ;; - InternetGatewayDevice.DeviceInfo.SoftwareVersion) - set_device_info_software_version "$2" - return $FAULT_CPE_NO_FAULT - ;; -esac -return $FAULT_CPE_INVALID_PARAMETER_NAME +return $E_INVALID_PARAMETER_NAME } check_parameter_device_info_generic() { @@ -504,12 +428,13 @@ get_device_info_generic() { check_parameter_device_info_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi freecwmp_get_parameter_value "val" "$1" - ubus_freecwmp_output "$1" "$val" + freecwmp_output "$1" "$val" return $FAULT_CPE_NO_FAULT } get_device_info_generic_name() { local val="" + local permissions="" case "$1" in InternetGatewayDevice.DeviceInfo.ModelName|\ InternetGatewayDevice.DeviceInfo.Description|\ @@ -519,13 +444,13 @@ get_device_info_generic_name() { InternetGatewayDevice.DeviceInfo.AdditionalSoftwareVersion|\ InternetGatewayDevice.DeviceInfo.SpecVersion|\ InternetGatewayDevice.DeviceInfo.FirstUseDate) - val="0" - ubus_freecwmp_output "$1" "$val" + permissions="0" + freecwmp_output "$1" "" "$permissions" return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.DeviceInfo.ProvisioningCode) - val="1" - ubus_freecwmp_output "$1" "$val" + permissions="1" + freecwmp_output "$1" "" "$permissions" return $FAULT_CPE_NO_FAULT ;; esac @@ -537,8 +462,8 @@ get_device_info_generic_notification() { local val freecwmp_get_parameter_notification "val" "$1" - ubus_freecwmp_output "$1" "$val" - return $FAULT_CPE_NO_FAULT + freecwmp_output "$1" "$val" + return 0 } set_device_info_generic() { @@ -554,3 +479,11 @@ set_device_info_generic_notification() { freecwmp_set_parameter_notification "$1" "$2" return $FAULT_CPE_NO_FAULT } + +add_device_info() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +delete_device_info() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +add_device_info_generic() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +delete_device_info_generic() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } \ No newline at end of file diff --git a/src/scripts/functions/device_routing b/src/scripts/functions/device_routing index ca6dab1..186e97f 100644 --- a/src/scripts/functions/device_routing +++ b/src/scripts/functions/device_routing @@ -1,5 +1,6 @@ #!/bin/sh # Copyright (C) 2012 Luka Perkov +# Copyright (C) 2012 Ahmed Zribi # TODO: LIMITATIONS: we only handle one device router at the moment @@ -85,7 +86,7 @@ local parameter=$1 case "$parameter" in Device.Routing.RouterNumberOfEntries) - ubus_freecwmp_output "$parameter" "1" + freecwmp_output "$parameter" "1" return ;; esac @@ -101,7 +102,7 @@ if [ $rc -eq 0 ]; then else val="0" fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_output "$parameter" "$val" return fi @@ -113,7 +114,7 @@ if [ $rc -eq 0 ]; then else val="Disabled" fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_output "$parameter" "$val" return fi @@ -134,7 +135,7 @@ if [ $rc -eq 0 ]; then else return fi - ubus_freecwmp_output "$parameter" "$total" + freecwmp_output "$parameter" "$total" return fi @@ -146,7 +147,7 @@ if [ $rc -eq 0 ]; then else return fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_output "$parameter" "$val" return fi @@ -166,15 +167,15 @@ if [ $rc -eq 0 ]; then return fi if [ $num2 -gt $static ]; then - ubus_freecwmp_output "$parameter" "Enabled" + freecwmp_output "$parameter" "Enabled" return fi if [ $num2 -le $inactive ]; then - ubus_freecwmp_output "$parameter" "Error: not active but enabled" + freecwmp_output "$parameter" "Error: not active but enabled" return fi if [ $num2 -le $static ]; then - ubus_freecwmp_output "$parameter" "Enabled" + freecwmp_output "$parameter" "Enabled" return fi else @@ -197,11 +198,11 @@ if [ $rc -eq 0 ]; then return fi if [ $num2 -gt $static ]; then - ubus_freecwmp_output "$parameter" "0" + freecwmp_output "$parameter" "0" return fi if [ $num2 -le $static ]; then - ubus_freecwmp_output "$parameter" "1" + freecwmp_output "$parameter" "1" return fi else @@ -230,7 +231,7 @@ if [ $rc -eq 0 ]; then let local i=$static-$num2 target=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].target 2> /dev/null` fi - ubus_freecwmp_output "$parameter" "$target" + freecwmp_output "$parameter" "$target" return else return @@ -258,7 +259,7 @@ if [ $rc -eq 0 ]; then let local i=$static-$num2 netmask=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].netmask 2> /dev/null` fi - ubus_freecwmp_output "$parameter" "$netmask" + freecwmp_output "$parameter" "$netmask" return else return @@ -288,7 +289,7 @@ if [ $rc -eq 0 ]; then let local i=$static-$num2 gateway=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].gateway 2> /dev/null` fi - ubus_freecwmp_output "$parameter" "$gateway" + freecwmp_output "$parameter" "$gateway" return else return @@ -315,7 +316,7 @@ if [ $rc -eq 0 ]; then elif [ $num2 -le $static ]; then val="Static" fi - ubus_freecwmp_output "$parameter" "$val" + freecwmp_output "$parameter" "$val" return else return @@ -343,7 +344,7 @@ if [ $rc -eq 0 ]; then let local i=$static-$num2 metric=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].metric 2> /dev/null` fi - ubus_freecwmp_output "$parameter" "$metric" + freecwmp_output "$parameter" "$metric" return else return @@ -352,3 +353,14 @@ fi return $FAULT_CPE_INVALID_PARAMETER_NAME } +get_device_routing_name() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +get_device_routing_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +set_device_routing() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +set_device_routing_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +add_device_routing() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +delete_device_routing() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } \ No newline at end of file diff --git a/src/scripts/functions/device_users b/src/scripts/functions/device_users index d8dba61..2412b99 100644 --- a/src/scripts/functions/device_users +++ b/src/scripts/functions/device_users @@ -1,12 +1,13 @@ #!/bin/sh # Copyright (C) 2012 Luka Perkov +# Copyright (C) 2012 Ahmed Zribi get_device_users() { local parameter="$1" case "$parameter" in Device.Users.UserNumberOfEntries) local val=`wc -l /etc/passwd | awk '{ print $1 }'` - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return ;; esac @@ -21,7 +22,7 @@ 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` - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -30,7 +31,7 @@ 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` - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -38,7 +39,7 @@ freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Username" 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 }'` - ubus_freecwmp_output "$parameter" "$val" + freecwmp_value_output "$parameter" "$val" return fi @@ -48,13 +49,13 @@ if [ $rc -eq 0 ]; then # 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" - ubus_freecwmp_output "$parameter" "" + freecwmp_value_output "$parameter" "" return fi freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Language" "rc" "num" if [ $rc -eq 0 ]; then - ubus_freecwmp_output "$parameter" "" + freecwmp_value_output "$parameter" "" return fi return $FAULT_CPE_INVALID_PARAMETER_NAME @@ -125,3 +126,15 @@ 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; } \ No newline at end of file diff --git a/src/scripts/functions/lan_device b/src/scripts/functions/lan_device index bae16da..11a7ad6 100644 --- a/src/scripts/functions/lan_device +++ b/src/scripts/functions/lan_device @@ -1,10 +1,12 @@ #!/bin/sh # Copyright (C) 2012 Luka Perkov +# Copyright (C) 2012 Ahmed Zribi get_wlan_enable() { local num="$1" local type="xsd:boolean" local val="" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get wireless.@wifi-device[$num].disabled 2> /dev/null` @@ -14,17 +16,17 @@ case "$action" in else val="1" fi - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.Enable" "$val" "$type" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.Enable" "$val" "$permissions" "$type" ;; get_name) - val="1" + permissions="1" let num=$num+1 - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.Enable" "$val" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.Enable" "$val" "$permissions" ;; get_notification) let num=$num+1 freecwmp_get_parameter_notification "val" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.Enable" - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.Enable" "$val" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.Enable" "$val" ;; esac } @@ -53,21 +55,22 @@ esac get_wlan_ssid() { local num="$1" local val="" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get wireless.@wifi-iface[$num].ssid 2> /dev/null` -let num=$num+1 - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.SSID" "$val" + let num=$num+1 + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.SSID" "$val" ;; get_name) - val="1" + permissions="1" let num=$num+1 - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.SSID" "$val" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.SSID" "$val" "$permissions" ;; get_notification) let num=$num+1 freecwmp_get_parameter_notification "val" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.SSID" - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.SSID" "$val" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.SSID" "$val" ;; esac @@ -99,7 +102,7 @@ add_ip_interface() { let instance=$instance+1 freecwmp_add_lan_device_ip_interface "$1$instance." "$instance" /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit - ubus_freecwmp_output "$instance" "0" + freecwmp_output "" "" "" "" "" "0" "$instance" } get_ip_interface() { @@ -109,14 +112,15 @@ do if [ "$action" = "get_name" ];then let i=$i+1 local parm=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.@object[$i].parameter 2>/dev/null` - val="1" - ubus_freecwmp_output "$parm" "$val" + permissions="1" + freecwmp_output "$parm" "" "$permissions" fi done } get_ip_interface_ip_address() { local val="" +local permissions="" local i=0 while [ "`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.@object[$i].parameter 2>/dev/null`" != "" ] do @@ -125,11 +129,11 @@ do case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.lan$indice.ipaddr 2> /dev/null` - ubus_freecwmp_output $parm"IPInterfaceIPAddress" "$val" + freecwmp_output $parm"IPInterfaceIPAddress" "$val" ;; get_name) - val="1" - ubus_freecwmp_output $parm"IPInterfaceIPAddress" "$val" + permissions="1" + freecwmp_output $parm"IPInterfaceIPAddress" "" "$permissions" ;; esac let i=$i+1 @@ -158,6 +162,7 @@ set_ip_interface_ip_address() { get_ip_interface_netmask() { local val="" +local permissions="" local i=0 while [ "`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.@object[$i].parameter 2>/dev/null`" != "" ] do @@ -166,11 +171,11 @@ do case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.lan$indice.netmask 2> /dev/null` - ubus_freecwmp_output $parm"IPInterfaceSubnetMask" "$val" + freecwmp_output $parm"IPInterfaceSubnetMask" "$val" ;; get_name) - val="1" - ubus_freecwmp_output $parm"IPInterfaceSubnetMask" "$val" + permissions="1" + freecwmp_output $parm"IPInterfaceSubnetMask" "" "$permissions" ;; esac let i=$i+1 @@ -201,7 +206,7 @@ delete_ip_interface() { /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} delete cwmp.@object[$1] /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} delete network.lan$indice /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit - ubus_freecwmp_output "0" + freecwmp_output "" "" "" "" "" "0" } add_lan_device() { @@ -295,51 +300,51 @@ return $FAULT_CPE_INVALID_PARAMETER_NAME get_lan_device_name() { case "$1" in InternetGatewayDevice.) - ubus_freecwmp_output "InternetGatewayDevice.LANDevice." "1" + freecwmp_output "InternetGatewayDevice.LANDevice." "" "1" if [ "$2" = "0" ]; then - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1." "1" - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration." "1" - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1." "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1." "" "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration." "" "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1." "" "1" get_wlan_enable 0 get_wlan_ssid 0 fi return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.LANDevice.) - ubus_freecwmp_output "InternetGatewayDevice.LANDevice." "1" - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1." "1" + freecwmp_output "InternetGatewayDevice.LANDevice." "" "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1." "" "1" if [ "$2" = "0" ]; then - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration." "1" - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1." "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration." "" "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1." "" "1" get_wlan_enable 0 get_wlan_ssid 0 fi return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.LANDevice.1.) - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1." "1" - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration." "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1." "" "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration." "" "1" if [ "$2" = "0" ]; then - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1." "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1." "" "1" get_wlan_enable 0 get_wlan_ssid 0 fi return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.LANDevice.1.WLANConfiguration.) - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration." "1" - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1." "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration." "" "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1." "" "1" if [ "$2" = "0" ]; then - get_wlan_enable 0 - get_wlan_ssid 0 + get_wlan_enable 0 + get_wlan_ssid 0 fi return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.) - ubus_freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1." "1" + freecwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1." "" "1" if [ "$2" = "0" ]; then - get_wlan_enable 0 - get_wlan_ssid 0 + get_wlan_enable 0 + get_wlan_ssid 0 fi return $FAULT_CPE_NO_FAULT ;; @@ -422,7 +427,6 @@ case "$1" in ;; esac return $FAULT_CPE_INVALID_PARAMETER_NAME -# /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit } set_lan_device_notification() { @@ -444,5 +448,4 @@ case "$1" in ;; esac return $FAULT_CPE_INVALID_PARAMETER_NAME -# /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit -} +} \ No newline at end of file diff --git a/src/scripts/functions/management_server b/src/scripts/functions/management_server index 90a17f3..43c5e41 100644 --- a/src/scripts/functions/management_server +++ b/src/scripts/functions/management_server @@ -1,24 +1,26 @@ #!/bin/sh # Copyright (C) 2011-2012 Luka Perkov +# Copyright (C) 2012 Ahmed Zribi get_management_server_url() { local tmp=${FLAGS_value} FLAGS_value=${FLAGS_TRUE} FLAGS_value=$tmp local val="" +local permissions="" local parm="InternetGatewayDevice.ManagementServer.URL" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.acs.url 2> /dev/null` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_url() { @@ -38,19 +40,20 @@ esac get_management_server_username() { local val="" +local permissions="" local parm="InternetGatewayDevice.ManagementServer.Username" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.acs.userid 2> /dev/null` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_username() { @@ -68,19 +71,20 @@ esac get_management_server_password() { local val="" +local permissions="" local parm="InternetGatewayDevice.ManagementServer.Password" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.acs.passwd 2> /dev/null` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_password() { @@ -101,19 +105,20 @@ local tmp=${FLAGS_value} FLAGS_value=${FLAGS_TRUE} FLAGS_value=$tmp local val="" +local permissions="" local parm="InternetGatewayDevice.ManagementServer.ParameterKey" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.acs.ParameterKey 2> /dev/null` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_parameter_key() { @@ -133,19 +138,21 @@ esac get_management_server_periodic_inform_enable() { local val="" +local type="xsd:boolean" local parm="InternetGatewayDevice.ManagementServer.PeriodicInformEnable" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.acs.periodic_inform_enable` ;; get_name) - val="1" + permissions="1" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" "$type" } set_management_server_periodic_inform_enable() { @@ -163,19 +170,21 @@ esac get_management_server_periodic_inform_interval() { local val="" +local type="xsd:unsignedInt" local parm="InternetGatewayDevice.ManagementServer.PeriodicInformInterval" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.acs.periodic_inform_interval 2> /dev/null` ;; get_name) - val="1" + permissions="1" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" "$type" } set_management_server_periodic_inform_interval() { @@ -194,23 +203,40 @@ esac get_management_server_connection_request_url() { local val local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestURL" +local permissions="" case "$action" in get_value) - val=`uci get -q -P /etc/cwmpd/.iccu cwmp.cpe.iccu_url 2> /dev/null` + if [ -z "$default_management_server_connection_request_url" ]; then + local tmp_value=${FLAGS_value} + FLAGS_value=${FLAGS_TRUE} + local tmp_ubus=${FLAGS_ubus} + FLAGS_ubus=${FLAGS_FALSE} + local ip=`get_wan_device_mng_interface_ip` + local port=`get_management_server_x_freecwmp_org__connection_request_port` + FLAGS_value=$tmp_value + FLAGS_ubus=$tmp_ubus + + if [ -n "$ip" -a -n "$port" ]; then + val="http://$ip:$port/" + fi + else + val=$default_management_server_connection_request_url + fi ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" } get_management_server_connection_request_username() { local val="" local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.cpe.userid 2> /dev/null` @@ -222,7 +248,7 @@ case "$action" in freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_connection_request_username() { @@ -241,18 +267,19 @@ esac get_management_server_connection_request_password() { local val="" local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.cpe.passwd 2> /dev/null` ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_connection_request_password() { @@ -272,23 +299,20 @@ esac get_management_server_x_freecwmp_org__acs_scheme() { local val="" +local permissions="" local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Scheme" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.@acs[0].scheme 2> /dev/null` ;; get_name) - val="1" + permissions="1" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -if [ "$FLAGS_value" != "${FLAGS_TRUE}" ]; then - ubus_freecwmp_output "$parm" "$val" -else - freecwmp_output "$parm" "$val" -fi +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_x_freecwmp_org__acs_scheme() { @@ -307,22 +331,19 @@ esac get_management_server_x_freecwmp_org__acs_hostname() { local val="" local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Hostname" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.@acs[0].hostname 2> /dev/null` ;; get_name) - val="1" + permissions="1" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -if [ "$FLAGS_value" != "${FLAGS_TRUE}" ]; then - ubus_freecwmp_output "$parm" "$val" -else - freecwmp_output "$parm" "$val" -fi +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_x_freecwmp_org__acs_hostname() { @@ -345,22 +366,19 @@ esac get_management_server_x_freecwmp_org__acs_port() { local val="" local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Port" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.@acs[0].port 2> /dev/null` ;; get_name) - val="1" + permissions="1" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -if [ "$FLAGS_value" != "${FLAGS_TRUE}" ]; then - ubus_freecwmp_output "$parm" "$val" -else - freecwmp_output "$parm" "$val" -fi +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_x_freecwmp_org__acs_port() { @@ -379,22 +397,19 @@ esac get_management_server_x_freecwmp_org__acs_path() { local val="" local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Path" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.@acs[0].path 2> /dev/null` ;; get_name) - val="1" + permissions="1" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -if [ "$FLAGS_value" != "${FLAGS_TRUE}" ]; then - ubus_freecwmp_output "$parm" "$val" -else - freecwmp_output "$parm" "$val" -fi +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_x_freecwmp_org__acs_path() { @@ -413,22 +428,19 @@ esac get_management_server_x_freecwmp_org__connection_request_port() { local val="" local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__Connection_Request_Port" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get cwmp.@local[0].port 2> /dev/null` ;; get_name) - val="1" + permissions="1" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -if [ "$FLAGS_value" != "${FLAGS_TRUE}" ]; then - ubus_freecwmp_output "$parm" "$val" -else - freecwmp_output "$parm" "$val" -fi +freecwmp_output "$parm" "$val" "$permissions" } set_management_server_x_freecwmp_org__connection_request_port() { @@ -511,7 +523,7 @@ return $FAULT_CPE_INVALID_PARAMETER_NAME get_management_server_name() { case "$1" in InternetGatewayDevice.) - ubus_freecwmp_output "InternetGatewayDevice.ManagementServer." "0" + freecwmp_output "InternetGatewayDevice.ManagementServer." "" "0" if [ "$2" = "0" ]; then get_management_server_url get_management_server_username @@ -525,7 +537,7 @@ case "$1" in return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.ManagementServer.) - ubus_freecwmp_output "InternetGatewayDevice.ManagementServer." "0" + freecwmp_output "InternetGatewayDevice.ManagementServer." "" "0" get_management_server_url get_management_server_username get_management_server_password @@ -775,8 +787,8 @@ get_management_server_generic() { get_management_server_generic_name() { check_parameter_management_server_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi - local val="1" - ubus_freecwmp_output "$1" "$val" + local permissions="1" + freecwmp_output "$1" "" "$permissions" return $FAULT_CPE_NO_FAULT } @@ -785,7 +797,7 @@ get_management_server_generic_notification() { local val freecwmp_get_parameter_notification "val" "$1" - ubus_freecwmp_output "$1" "$val" + freecwmp_output "$1" "$val" return $FAULT_CPE_NO_FAULT } @@ -802,3 +814,10 @@ set_management_server_generic_notification() { freecwmp_set_parameter_notification "$1" "$2" return $FAULT_CPE_NO_FAULT } +add_management_server { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +delete_management_server { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +add_management_server_generic { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +delete_management_server_generic { return $FAULT_CPE_INVALID_PARAMETER_NAME; } \ No newline at end of file diff --git a/src/scripts/functions/misc b/src/scripts/functions/misc index 13f2142..acb711b 100644 --- a/src/scripts/functions/misc +++ b/src/scripts/functions/misc @@ -1,15 +1,16 @@ #!/bin/sh # Copyright (C) 2012 Luka Perkov +# Copyright (C) 2012 Ahmed Zribi get_misc_cpu_usage() { local val=`uptime | awk -F'average: ' '{ print $2 }' | awk -F',' '{ print $1 }' | awk -F'.' '{ print $2 }'` -ubus_freecwmp_output "Device.DeviceInfo.ProcessStatus.CPUUsage" "$val" +freecwmp_output "Device.DeviceInfo.ProcessStatus.CPUUsage" "$val" } get_misc_process_number() { local val=`ps | grep -v COMMAND | wc -l` local type="xsd:unsignedInt" -ubus_freecwmp_output "Device.DeviceInfo.ProcessStatus.ProcessNumberOfEntries" "$val" "$type" +freecwmp_output "Device.DeviceInfo.ProcessStatus.ProcessNumberOfEntries" "$val" "" "$type" } get_misc() { @@ -25,3 +26,15 @@ case "$1" in esac return $FAULT_CPE_INVALID_PARAMETER_NAME } + +get_misc_name () { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +get_misc_notification () { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +set_misc() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +set_misc_notification () { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +add_misc() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +delete_misc() { return $FAULT_CPE_INVALID_PARAMETER_NAME; } \ No newline at end of file diff --git a/src/scripts/functions/wan_device b/src/scripts/functions/wan_device index 76f488d..fb7d879 100644 --- a/src/scripts/functions/wan_device +++ b/src/scripts/functions/wan_device @@ -1,94 +1,91 @@ #!/bin/sh # Copyright (C) 2011-2012 Luka Perkov +# Copyright (C) 2012 Ahmed Zribi get_wan_device_mng_status() { # TODO: Unconfigured ; Connecting ; Connected ; PendingDisconnect ; Disconneting ; Disconnected local val="" local type="xsd:boolean" local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus" +local permissions="" case "$action" in get_value) val="Connected" ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" "$type" +freecwmp_output "$parm" "$val" "$permissions" "$type" } get_wan_device_mng_interface_ip() { local val="" local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress" +local permissions="" case "$action" in get_value) -if [ -z "$default_wan_device_mng_interface_ip" ]; then - val=`network_get_ipaddr val mng` -else - val=$default_wan_device_mng_interface_ip -fi + if [ -z "$default_wan_device_mng_interface_ip" ]; then + network_get_ipaddr val mng + else + val=$default_wan_device_mng_interface_ip + fi ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -if [ "$FLAGS_value" != "${FLAGS_TRUE}" ]; then - ubus_freecwmp_output "$parm" "$val" -else - freecwmp_output "$parm" "$val" -fi +freecwmp_output "$parm" "$val" "$permissions" } get_wan_device_mng_interface_mac() { local val="" local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress" +local permissions="" case "$action" in get_value) -if [ -z "$default_wan_device_mng_interface_mac" ]; then - val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.mng.macaddr` -else - val=$default_wan_device_mng_interface_mac -fi + if [ -z "$default_wan_device_mng_interface_mac" ]; then + val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.mng.macaddr` + else + val=$default_wan_device_mng_interface_mac + fi ;; get_name) - val="0" + permissions="0" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -if [ "$FLAGS_value" != "${FLAGS_TRUE}" ]; then - ubus_freecwmp_output "$parm" "$val" -else - freecwmp_output "$parm" "$val" -fi +freecwmp_output "$parm" "$val" "$permissions" } get_wan_device_wan_ppp_enable() { local val="" local type="xsd:boolean" local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.wan.auto 2> /dev/null` -if [ -z $val ]; then - val="1" -fi + if [ -z $val ]; then + val="1" + fi ;; get_name) - val="1" + permissions="1" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" "$type" +freecwmp_output "$parm" "$val" "$permissions" "$type" } set_wan_device_wan_ppp_enable() { @@ -113,18 +110,19 @@ esac get_wan_device_wan_ppp_username() { local val="" local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.wan.username 2> /dev/null` ;; get_name) - val="1" + permissions="1" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" } set_wan_device_wan_ppp_username() { @@ -143,18 +141,19 @@ esac get_wan_device_wan_ppp_password() { local val="" local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password" +local permissions="" case "$action" in get_value) val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.wan.password 2> /dev/null` ;; get_name) - val="1" + permissions="1" ;; get_notification) freecwmp_get_parameter_notification "val" "$parm" ;; esac -ubus_freecwmp_output "$parm" "$val" +freecwmp_output "$parm" "$val" "$permissions" } set_wan_device_wan_ppp_password() { @@ -260,7 +259,7 @@ return $FAULT_CPE_INVALID_PARAMETER_NAME get_wan_device_name() { case "$1" in InternetGatewayDevice.) - ubus_freecwmp_output "InternetGatewayDevice.WANDevice." "1" + freecwmp_output "InternetGatewayDevice.WANDevice." "" "1" if [ "$2" = "0" ]; then get_wan_device_mng_status get_wan_device_mng_interface_ip @@ -272,8 +271,8 @@ case "$1" in return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.WANDevice.) - ubus_freecwmp_output "InternetGatewayDevice.WANDevice." "1" - ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1." "1" + freecwmp_output "InternetGatewayDevice.WANDevice." "" "1" + freecwmp_output "InternetGatewayDevice.WANDevice.1." "" "1" if [ "$2" = "0" ]; then get_wan_device_mng_status get_wan_device_mng_interface_ip @@ -285,8 +284,8 @@ case "$1" in return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.WANDevice.1.) - ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1." "1" - ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice." "1" + freecwmp_output "InternetGatewayDevice.WANDevice.1." "" "1" + freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice." "" "1" if [ "$2" = "0" ]; then get_wan_device_mng_status get_wan_device_mng_interface_ip @@ -298,8 +297,8 @@ case "$1" in return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.WANDevice.1.WANConnectionDevice.) - ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice." "1" - ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1." "1" + freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice." "" "1" + freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1." "" "1" if [ "$2" = "0" ]; then get_wan_device_mng_status get_wan_device_mng_interface_ip @@ -311,8 +310,8 @@ case "$1" in return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.) - ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1." "1" - ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection." "1" + freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1." "1" + freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection." "" "1" if [ "$2" = "0" ]; then get_wan_device_mng_status get_wan_device_mng_interface_ip @@ -324,8 +323,8 @@ case "$1" in return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.) - ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection." "1" - ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1." "1" + freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection." "" "1" + freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1." "" "1" if [ "$2" = "0" ]; then get_wan_device_mng_status get_wan_device_mng_interface_ip @@ -334,7 +333,7 @@ case "$1" in return $FAULT_CPE_NO_FAULT ;; InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.) - ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1." "1" + freecwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1." "" "1" get_wan_device_mng_status get_wan_device_mng_interface_ip get_wan_device_mng_interface_mac @@ -516,4 +515,8 @@ case "$1" in ;; esac return $FAULT_CPE_INVALID_PARAMETER_NAME -} \ No newline at end of file +} + +add_wan_device { return $FAULT_CPE_INVALID_PARAMETER_NAME; } + +delete_wan_device { return $FAULT_CPE_INVALID_PARAMETER_NAME; } \ No newline at end of file