aggiunto supporto per autenticazione su socket server

This commit is contained in:
lejubila
2017-05-21 12:42:26 +02:00
parent 6447ec5326
commit 3aad235dda
3 changed files with 22 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
## 0.3.2 - xx/xx/2017 ## 0.4.0 - xx/xx/2017
Add credentials support to socket server (define TCPSERVER_USER and TCPSERVER_PWD in your config file)
Add management lock/unlock for prevent concurrente call to open/close solenoid Add management lock/unlock for prevent concurrente call to open/close solenoid
## 0.3.1 - 13/05/2017 ## 0.3.1 - 13/05/2017

View File

@@ -114,3 +114,6 @@ NOT_IRRIGATE_IF_RAIN_SENSOR=86400
TCPSERVER_IP="127.0.0.1" TCPSERVER_IP="127.0.0.1"
TCPSERVER_PORT="8084" TCPSERVER_PORT="8084"
# Utente e password che i clients devono utilizzare per stabilire una connessione tramite socket server
TCPSERVER_USER=""
TCPSERVER_PWD=""

View File

@@ -1211,6 +1211,21 @@ function socket_server_command {
RUN_FROM_TCPSERVER=1 RUN_FROM_TCPSERVER=1
local line="" local line=""
if [ ! -z "$TCPSERVER_USER" ] && [ ! -z "$TCPSERVER_PWD" ]; then
local user=""
local password=""
read -t 3 user
read -t 3 password
user=$(echo "$user" | $TR -d '[\r\n]')
password=$(echo "$password" | $TR -d '[\r\n]')
if [ "$user" != "$TCPSERVER_USER" ] || [ "$password" != "$TCPSERVER_PWD" ]; then
log_write "socket connection from: $TCPREMOTEIP - Bad socket server credentials - user:$user"
json_error 0 "Bad socket server credentials"
return
fi
fi
read line read line
line=$(echo "$line " | $TR -d '[\r\n]') line=$(echo "$line " | $TR -d '[\r\n]')
arg1=$(echo "$line " | $CUT -d ' ' -f1) arg1=$(echo "$line " | $CUT -d ' ' -f1)
@@ -1432,8 +1447,8 @@ function debug2 {
} }
VERSION=0 VERSION=0
SUB_VERSION=3 SUB_VERSION=4
RELEASE_VERSION=2 RELEASE_VERSION=0
DIR_SCRIPT=`dirname $0` DIR_SCRIPT=`dirname $0`
NAME_SCRIPT=${0##*/} NAME_SCRIPT=${0##*/}