Page 1 sur 2

Sécurité domoticz

Publié : 09 juin 2017, 14:32
par espagne1988
Bonjour,

Je dispose d'un script qui me permet de compter l'énergie produite par les panneaux photovoltaïque.

Mon script fonctionne correctement cependant je désire un peu protéger mon système contre les intrusion.
Actuellement, je n'ai pas de sécurité sur domoticz

Image

Lorsque j'entre un identifiant et mdp dans les paramètres, mon script ne fonctionne plus, je n'ai plus aucun comptage.

Code : Tout sélectionner

#!/usr/bin/env python
 
#imports
import time
import RPi.GPIO as GPIO
import json
import urllib2
import threading

#Config serveur domoticz
domoticzserver="192.168.14.110:8080"
domoticzusername="monusername"
domoticzpassword="mon mdp"
domoticzpasscode="mon mdp"

#vars
GET_URL = 'http://localhost:8080/json.htm?type=devices&rid=%d'
SET_URL = 'http://localhost:8080/json.htm?type=command&param=udevice&idx=%d&svalue=%d'
ELEC_DELTA = 0
ELEC_IDX = 6
ELEC_GPIO = 22
ELEC_COUNTER_LOCK = threading.Lock()
 
def gpio_intr(pin):
 
    if pin == ELEC_GPIO:
        global ELEC_DELTA
        with ELEC_COUNTER_LOCK:
            ELEC_DELTA += 1
        print 'Electricity counter tick: %d' % ELEC_DELTA
        print time.strftime('%d/%m/%y %H:%M:%S',time.localtime())
 
def main():
    global ELEC_DELTA
 
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(ELEC_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.add_event_detect(ELEC_GPIO, GPIO.RISING, callback=gpio_intr, bouncetime=100)
 
    while True:
        time.sleep(5)
 
        ELEC_DELTA_POST = ELEC_DELTA
 
        if ELEC_DELTA_POST != 0:
         
            try:
                res = json.load(urllib2.urlopen(SET_URL % (ELEC_IDX, ELEC_DELTA_POST)))
                if res['status'] != 'OK':
                    raise Exception('Domoticz json error')
                with ELEC_COUNTER_LOCK:
                    ELEC_DELTA -= ELEC_DELTA_POST
            except Exception as e:
                print e
 
    #    print 'Elec delta %d' % (ELEC_DELTA_POST)
 
 
 
if __name__=="__main__":
    main()
Concernant la ligne domoticzserver="192.168.14.110:8080", j'ai essayé plusieurs possibilités mais aucune n'a fonctionné
domoticzserver="localhost:8080"
domoticzserver="http://192.168.14.110:8080"
domoticzserver="http://localhost:8080"

Pouvez-vous m'aiguiller pour résoudre mon problème?

Merci d'avance

Re: Sécurité domoticz

Publié : 09 juin 2017, 18:25
par Invité
Hello,

si ton script s'exécute depuis la même machine ou est installé domoticz ajoute dans réseaux locaux 127.0.0.0 (ou 127.0.0.1 j'ai un trou de mémoire ). Cela permet à tout les script qui ce connecte à domoticz depuis la même machine à ne pas avoir d'identifiants à entrer ;-)

Envoyé de mon A0001 en utilisant Tapatalk

Re: Sécurité domoticz

Publié : 09 juin 2017, 18:25
par djksage
Hello,

si ton script s'exécute depuis la même machine ou est installé domoticz ajoute dans réseaux locaux 127.0.0.0 (ou 127.0.0.1 j'ai un trou de mémoire ). Cela permet à tout les script qui ce connecte à domoticz depuis la même machine à ne pas avoir d'identifiants à entrer ;-)

Envoyé de mon A0001 en utilisant Tapatalk

Re: Sécurité domoticz

Publié : 09 juin 2017, 20:32
par Chrominator
127.0.0.1 - C'est le l'ip loopback, l'adresse virtuelle de toute interface réseau.
Mets dans ton script

Code : Tout sélectionner

domoticzserver="127.0.0.1:8080"
et ça marchera quand tu auras spécifié dans "réseaux locaux" 127.0.0.1

Tu pourras aussi ajouter ;192.168.14.* au même endroit (dans réseaux locaux, le point-virgule sépare les différents segments), ça t'évitera de taper ton user/mot de passe lorsque tu te connectera de chez toi (pour peu que l'adresse ip de tes autres ordinateurs commence par 192.168.14)

Re: Sécurité domoticz

Publié : 12 juin 2017, 18:40
par espagne1988
Bonjour,

Merci pour vos réponses j'ai modifié les paramètres comme vous me l'avez stipulé mais cela ne compte toujours pas :evil:

Mon script se trouve dans un répertoire de domoticz "pi@raspberry:~/domoticz
J'ai rajouté dans les réseaux locaux 127.0.0.*;192.168.14.*;127.0.0.1
Effectivement en local je n'ai pas besoin d'encoder de mot de passe et depuis l'extérieur oui.
Mais mon compteur ne s'incrémente plus lorsque je mets un user et mdp

Code : Tout sélectionner

#!/usr/bin/env python

#imports
import time
import RPi.GPIO as GPIO
import json
import urllib2
import threading

# Settings for the domoticz server
domoticzserver="127.0.0.1:8080"
omoticzusername = "monusername"
domoticzpassword = "monmdp"
domoticzpasscode = "monmdp"

#vars
GET_URL = 'http://localhost:8080/json.htm?type=devices&rid=%d'
SET_URL = 'http://localhost:8080/json.htm?type=command&param=udevice&idx=%d&svalue=%d'
ELEC_DELTA = 0
ELEC_IDX = 6
ELEC_GPIO = 22
ELEC_COUNTER_LOCK = threading.Lock()

def gpio_intr(pin):

    if pin == ELEC_GPIO:
        global ELEC_DELTA
        with ELEC_COUNTER_LOCK:
            ELEC_DELTA += 1
        print 'Electricity counter tick: %d' % ELEC_DELTA
        print time.strftime('%d/%m/%y %H:%M:%S',time.localtime())

def main():
    global ELEC_DELTA

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(ELEC_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.add_event_detect(ELEC_GPIO, GPIO.RISING, callback=gpio_intr, bouncetime=100)

    while True:
        time.sleep(5)

        ELEC_DELTA_POST = ELEC_DELTA

        if ELEC_DELTA_POST != 0:
                    try:
                res = json.load(urllib2.urlopen(SET_URL % (ELEC_IDX, ELEC_DELTA_POST)))
                if res['status'] != 'OK':
                    raise Exception('Domoticz json error')
                with ELEC_COUNTER_LOCK:
                    ELEC_DELTA -= ELEC_DELTA_POST
            except Exception as e:
                print e

    #    print 'Elec delta %d' % (ELEC_DELTA_POST)



if __name__=="__main__":
    main()      
Voici un screen des modifs
Image

Ce me prend la tête car dans les logs je vois des connexion de Singapour, Chine, Suisse, Etats-unis

Merci de votre aide

Re: Sécurité domoticz

Publié : 17 juin 2017, 11:13
par espagne1988
Personne pour m'aider ??

Re: Sécurité domoticz

Publié : 04 juil. 2017, 15:34
par espagne1988
Up

Re: Sécurité domoticz

Publié : 04 juil. 2017, 15:40
par vil1driver
Salut,

Authentification : basic auth

Et pourquoi ne retrouve-t-on pas ceci ailleurs dans ton code ?

Code : Tout sélectionner

# Settings for the domoticz server
domoticzserver="127.0.0.1:8080"
omoticzusername = "monusername"
domoticzpassword = "monmdp"
domoticzpasscode = "monmdp"
Si ton script ne s'identifie pas, ça ne risque pas de fonctionner

Sinon oui le plus simple reste d'ajouter une exception à la demande d'identification.. Étonnant que cela ne fonctionne pas..

Re: Sécurité domoticz

Publié : 05 juil. 2017, 07:28
par higgins91
essaye ma config d'url:
https://easydomoticz.com/forum/viewtopi ... 347#p38193

cela fonctionne en python chez moi!

Re: Sécurité domoticz

Publié : 06 juil. 2017, 18:58
par espagne1988
vil1driver a écrit :Salut,

Authentification : basic auth

Et pourquoi ne retrouve-t-on pas ceci ailleurs dans ton code ?

Code : Tout sélectionner

# Settings for the domoticz server
domoticzserver="127.0.0.1:8080"
domoticzusername = "monusername"
domoticzpassword = "monmdp"
domoticzpasscode = "monmdp"
Si ton script ne s'identifie pas, ça ne risque pas de fonctionner

Sinon oui le plus simple reste d'ajouter une exception à la demande d'identification.. Étonnant que cela ne fonctionne pas..
Je ne comprends pas la question.

J'ai intégré cette partie dans mon script juste après mes imports.
J'ai également mis une exeption d'identification mais mon compteur ne s'incrémente pas...

J'ai essayé la méthode de @higgins91 mais cela ne va pas non plus.

Cela me prend vraiment la tête :twisted: