diff --git a/tools/ngcp-api.inc b/tools/ngcp-api.inc index 4e2ec83d90..2752bf6c81 100644 --- a/tools/ngcp-api.inc +++ b/tools/ngcp-api.inc @@ -4,6 +4,7 @@ set -e importcreds () { local CREDS=$1 + local PERMS=${2:-0600} if [ -z "${CREDS}" ]; then echo "Error: missing mandatory file name to read" >&2 @@ -20,11 +21,11 @@ importcreds () { fi echo "${CREDS} present, checking perms" - if stat "${CREDS}" | grep -q 'Access: (0600' 1>/dev/null ; then + if stat "${CREDS}" | grep -q "Access: (${PERMS}" 1>/dev/null ; then echo "${CREDS} permissions ok" . "${CREDS}" else - echo "Error: ${CREDS} must have permissions 600" >&2 + echo "Error: ${CREDS} must have permissions ${PERMS}" >&2 exit 1 fi } diff --git a/tools_bin/ngcp-api-delete b/tools_bin/ngcp-api-delete index 3ff09731bd..3934f3fac1 100755 --- a/tools_bin/ngcp-api-delete +++ b/tools_bin/ngcp-api-delete @@ -1,6 +1,7 @@ #!/bin/bash CURL="/usr/bin/curl" -CREDS="${HOME}/.ngcp-api" +SYSCREDS="/etc/default/ngcp-api" +USERCREDS="${HOME}/.ngcp-api" TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc" usage () { @@ -19,9 +20,16 @@ EOF if [ -z "${APIUSER}" ]; then if [ -f "${TOOLS}" ]; then source "${TOOLS}" - importcreds "${CREDS}" - else - APIUSER="administrator:administrator" + + importcreds "${USERCREDS}" 0600 + if [ -z "${APIUSER}" ]; then + importcreds "${SYSCREDS}" 0440 + APIUSER="${AUTH_SYSTEM_LOGIN}:${AUTH_SYSTEM_PASSWORD}" + fi + fi + if [ -z "${APIUSER}" ]; then + echo "Error: no authentication credentials found" >&2 + exit 1 fi fi diff --git a/tools_bin/ngcp-api-get b/tools_bin/ngcp-api-get index 0c94dd7799..27fa83fd2a 100755 --- a/tools_bin/ngcp-api-get +++ b/tools_bin/ngcp-api-get @@ -1,6 +1,7 @@ #!/bin/bash CURL="/usr/bin/curl" -CREDS="${HOME}/.ngcp-api" +SYSCREDS="/etc/default/ngcp-api" +USERCREDS="${HOME}/.ngcp-api" TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc" usage () { @@ -19,9 +20,16 @@ EOF if [ -z "${APIUSER}" ]; then if [ -f "${TOOLS}" ]; then source "${TOOLS}" - importcreds "${CREDS}" - else - APIUSER="administrator:administrator" + + importcreds "${USERCREDS}" 0600 + if [ -z "${APIUSER}" ]; then + importcreds "${SYSCREDS}" 0440 + APIUSER="${AUTH_SYSTEM_LOGIN}:${AUTH_SYSTEM_PASSWORD}" + fi + fi + if [ -z "${APIUSER}" ]; then + echo "Error: no authentication credentials found" >&2 + exit 1 fi fi diff --git a/tools_bin/ngcp-api-patch b/tools_bin/ngcp-api-patch index e2565e5287..05739575ab 100755 --- a/tools_bin/ngcp-api-patch +++ b/tools_bin/ngcp-api-patch @@ -1,6 +1,7 @@ #!/bin/bash CURL="/usr/bin/curl" -CREDS="${HOME}/.ngcp-api" +SYSCREDS="/etc/default/ngcp-api" +USERCREDS="${HOME}/.ngcp-api" TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc" usage () { @@ -21,9 +22,16 @@ EOF if [ -z "${APIUSER}" ]; then if [ -f "${TOOLS}" ]; then source "${TOOLS}" - importcreds "${CREDS}" - else - APIUSER="administrator:administrator" + + importcreds "${USERCREDS}" 0600 + if [ -z "${APIUSER}" ]; then + importcreds "${SYSCREDS}" 0440 + APIUSER="${AUTH_SYSTEM_LOGIN}:${AUTH_SYSTEM_PASSWORD}" + fi + fi + if [ -z "${APIUSER}" ]; then + echo "Error: no authentication credentials found" >&2 + exit 1 fi fi INPUT=(-T -) diff --git a/tools_bin/ngcp-api-post b/tools_bin/ngcp-api-post index 552361bdb9..1d46c5b6de 100755 --- a/tools_bin/ngcp-api-post +++ b/tools_bin/ngcp-api-post @@ -1,6 +1,7 @@ #!/bin/bash CURL="/usr/bin/curl" -CREDS="${HOME}/.ngcp-api" +SYSCREDS="/etc/default/ngcp-api" +USERCREDS="${HOME}/.ngcp-api" TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc" usage () { @@ -20,9 +21,16 @@ EOF if [ -z "${APIUSER}" ]; then if [ -f "${TOOLS}" ]; then source "${TOOLS}" - importcreds "${CREDS}" - else - APIUSER="administrator:administrator" + + importcreds "${USERCREDS}" 0600 + if [ -z "${APIUSER}" ]; then + importcreds "${SYSCREDS}" 0440 + APIUSER="${AUTH_SYSTEM_LOGIN}:${AUTH_SYSTEM_PASSWORD}" + fi + fi + if [ -z "${APIUSER}" ]; then + echo "Error: no authentication credentials found" >&2 + exit 1 fi fi INPUT=(-T -) diff --git a/tools_bin/ngcp-api-put b/tools_bin/ngcp-api-put index 6b2c5e4b40..01060f1297 100755 --- a/tools_bin/ngcp-api-put +++ b/tools_bin/ngcp-api-put @@ -1,6 +1,7 @@ #!/bin/bash CURL="/usr/bin/curl" -CREDS="${HOME}/.ngcp-api" +SYSCREDS="/etc/default/ngcp-api" +USERCREDS="${HOME}/.ngcp-api" TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc" usage () { @@ -20,9 +21,16 @@ EOF if [ -z "${APIUSER}" ]; then if [ -f "${TOOLS}" ]; then source "${TOOLS}" - importcreds "${CREDS}" - else - APIUSER="administrator:administrator" + + importcreds "${USERCREDS}" 0600 + if [ -z "${APIUSER}" ]; then + importcreds "${SYSCREDS}" 0440 + APIUSER="${AUTH_SYSTEM_LOGIN}:${AUTH_SYSTEM_PASSWORD}" + fi + fi + if [ -z "${APIUSER}" ]; then + echo "Error: no authentication credentials found" >&2 + exit 1 fi fi INPUT=(-T -)