From 5a28d129f5d629f8a0af6a8db714c45173e7b1ed Mon Sep 17 00:00:00 2001 From: lejubila Date: Fri, 9 Jun 2017 01:59:04 +0200 Subject: [PATCH] aggiunto sistema di invio identificativo installazione per uso statistico --- CHANGELOG.md | 1 + conf/piGarden.conf.example | 4 ++++ piGarden.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94170fb..a2175d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ 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 Added the ability to enter an open / close schedule in disabled mode +Add send statistic information to remote server ## 0.3.1 - 13/05/2017 Add experimental support for monostable solenoid valve: diff --git a/conf/piGarden.conf.example b/conf/piGarden.conf.example index b06816a..cc80bdf 100644 --- a/conf/piGarden.conf.example +++ b/conf/piGarden.conf.example @@ -117,3 +117,7 @@ TCPSERVER_PORT="8084" # Utente e password che i clients devono utilizzare per stabilire una connessione tramite socket server TCPSERVER_USER="" TCPSERVER_PWD="" + +# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo +NO_SEND_IDENTIFIER=0 + diff --git a/piGarden.sh b/piGarden.sh index e881595..5048136 100755 --- a/piGarden.sh +++ b/piGarden.sh @@ -1441,6 +1441,34 @@ function lock { } +function send_identifier { + + if [ "$NO_SEND_IDENTIFIER" == "1" ]; then + return + fi + + local FILE_ID="/tmp/pigarden.id" + + if [ -f "$FILE_ID" ]; then + # Se il file è più vecchio di un giorno esce + local max_age_file=86400 + local time_file=`$STAT -c %Y "$FILE_ID"` + local age_file=$((`date +"%s"` - $time_file )) + if [ "$age_file" -lt "$max_age_file" ]; then + return + fi + else + local ID=`ifconfig | $GREP --color=never -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' | head -1 | md5sum | $CUT -d" " -f 1` + if [ -z "$ID" ]; then + return; + fi + echo "$ID" > "$FILE_ID" + fi + + #$CURL https://www.lejubila.net/statistic/usage/piGarden/$ID/$VERSION/$SUB_VERSION/$RELEASE_VERSION > /dev/null + +} + # # Chidue un lock # @@ -1487,6 +1515,7 @@ LAST_WARNING_FILE="$STATUS_DIR/last_worning" LAST_SUCCESS_FILE="$STATUS_DIR/last_success" +# Elimina il file di lock se più vecchio di 11 secondi if [ -f "$LOCK_FILE" ]; then max_age_lock_file=11 time_lock_file=`$STAT -c %Y "$LOCK_FILE"` @@ -1496,6 +1525,7 @@ if [ -f "$LOCK_FILE" ]; then fi fi +send_identifier & case "$1" in init)