blob: 44ca3cd7ad920a8f1f97a691efec9c772c184c4d [file] [log] [blame]
developer15a43312022-04-12 11:23:23 +08001#!/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
22if [ -f /etc/os-release ] || [ -f /etc/device.properties ]; then
23 LOG_FOLDER="/rdklogs"
24else
25 LOG_FOLDER="/var/tmp"
26fi
27
28KEY_LEN="32"
29CONSOLEFILE="$LOG_FOLDER/logs/Consolelog.txt.0"
30
31echo_time()
32{
33 echo "`date +"%y%m%d-%T.%6N"` getAccountId() called from: $0 - $1"
34}
35
36
37check_accountid()
38{
39accountId="$1"
40accountIdlen="$(echo ${#accountId})"
41checkisalnum=`echo $accountId | grep -E '^[-_0-9a-zA-Z]*$'`
42
43if [ "$accountIdlen" -lt "$KEY_LEN" ] && [[ "$checkisalnum" != "" ]] && [[ "$accountId" != "*['!'@'#'"$"%^&*()+]*" ]]; then
44 echo_time "accountId is valid and value retrieved from tr181/webpa param..." >>$CONSOLEFILE
45 echo "$accountId"
46else
47 echo_time "accountId is invalid as contains specail characters or larger than max $KEY_LEN characters..." >>$CONSOLEFILE
48 echo "Unknown"
49fi
50
51}
52
53# Function to get account_id
54getAccountId()
55{
56
57#Get AccountID set in the system via syscfg get command
58accountId=`syscfg get AccountID`
59
60#Try "dmcli" to retrieve accountId if "sysconf" returned null. It's a fallback check.
61if [ "$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
72else
73 echo_time "Checking accountId is alphanumeric and not greater than $KEY_LEN characters...">>$CONSOLEFILE
74 check_accountid $accountId
75fi
76}
77