developer | 15a4331 | 2022-04-12 11:23:23 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | #################################################################################### |
| 4 | # If not stated otherwise in this file or this component's Licenses.txt file the |
| 5 | # following copyright and licenses apply: |
| 6 | # |
| 7 | # Copyright 2018 RDK Management |
| 8 | # |
| 9 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | # you may not use this file except in compliance with the License. |
| 11 | # You may obtain a copy of the License at |
| 12 | # |
| 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | # |
| 15 | # Unless required by applicable law or agreed to in writing, software |
| 16 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | # See the License for the specific language governing permissions and |
| 19 | # limitations under the License. |
| 20 | ################################################################################## |
| 21 | |
| 22 | if [ -f /etc/os-release ] || [ -f /etc/device.properties ]; then |
| 23 | LOG_FOLDER="/rdklogs" |
| 24 | else |
| 25 | LOG_FOLDER="/var/tmp" |
| 26 | fi |
| 27 | |
| 28 | KEY_LEN="32" |
| 29 | CONSOLEFILE="$LOG_FOLDER/logs/Consolelog.txt.0" |
| 30 | |
| 31 | echo_time() |
| 32 | { |
| 33 | echo "`date +"%y%m%d-%T.%6N"` getAccountId() called from: $0 - $1" |
| 34 | } |
| 35 | |
| 36 | |
| 37 | check_accountid() |
| 38 | { |
| 39 | accountId="$1" |
| 40 | accountIdlen="$(echo ${#accountId})" |
| 41 | checkisalnum=`echo $accountId | grep -E '^[-_0-9a-zA-Z]*$'` |
| 42 | |
| 43 | if [ "$accountIdlen" -lt "$KEY_LEN" ] && [[ "$checkisalnum" != "" ]] && [[ "$accountId" != "*['!'@'#'"$"%^&*()+]*" ]]; then |
| 44 | echo_time "accountId is valid and value retrieved from tr181/webpa param..." >>$CONSOLEFILE |
| 45 | echo "$accountId" |
| 46 | else |
| 47 | echo_time "accountId is invalid as contains specail characters or larger than max $KEY_LEN characters..." >>$CONSOLEFILE |
| 48 | echo "Unknown" |
| 49 | fi |
| 50 | |
| 51 | } |
| 52 | |
| 53 | # Function to get account_id |
| 54 | getAccountId() |
| 55 | { |
| 56 | |
| 57 | #Get AccountID set in the system via syscfg get command |
| 58 | accountId=`syscfg get AccountID` |
| 59 | |
| 60 | #Try "dmcli" to retrieve accountId if "sysconf" returned null. It's a fallback check. |
| 61 | if [ "$accountId" == "" ];then |
| 62 | accountId=`dmcli eRT getv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AccountInfo.AccountID | grep string | awk '{print $5}'` |
| 63 | |
| 64 | if [ "$accountId" == "" ]; then |
| 65 | echo_time "account_id is not available from syscfg.db or tr181 param, defaulting to Unknown...">>$CONSOLEFILE |
| 66 | echo "Unknown" |
| 67 | else |
| 68 | echo_time "Checking accountId is alphanumeric and not greater than $KEY_LEN characters...">>$CONSOLEFILE |
| 69 | check_accountid $accountId |
| 70 | fi |
| 71 | |
| 72 | else |
| 73 | echo_time "Checking accountId is alphanumeric and not greater than $KEY_LEN characters...">>$CONSOLEFILE |
| 74 | check_accountid $accountId |
| 75 | fi |
| 76 | } |
| 77 | |