Subversion Repositories alarming

Rev

Rev 5 | Rev 8 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line 8... Line 8...
8
import time
8
import time
9
import requests
9
import requests
10
import subprocess
10
import subprocess
11
import config
11
import config
12
import threading
12
import threading
-
 
13
import subprocess as sp
13
 
14
 
14
g_subscribed = []
15
g_subscribed = []
-
 
16
g_bellListenerProc = None
15
 
17
 
16
class S(BaseHTTPRequestHandler):
18
class S(BaseHTTPRequestHandler):
17
    def _output(self, code, content):
19
    def _output(self, code, content):
18
        self.send_response(code)
20
        self.send_response(code)
19
        self.send_header('Content-type', 'text/html')
21
        self.send_header('Content-type', 'text/html')
Line 124... Line 126...
124
                postvars = {}
126
                postvars = {}
125
 
127
 
126
        # ---
128
        # ---
127
 
129
 
128
        global g_subscribed
130
        global g_subscribed
-
 
131
        global g_bellListenerProc
129
 
132
 
130
        if pvget(postvars, "action")[0] == "client_subscribe": # 1.3.6.1.4.1.37476.2.4.1.1
133
        if pvget(postvars, "action")[0] == "client_subscribe": # 1.3.6.1.4.1.37476.2.4.1.1
131
                client_ip      = self.client_address[0]
134
                client_ip      = self.client_address[0]
132
                client_port    = pvget(postvars, "port")[0]
135
                client_port    = pvget(postvars, "port")[0]
133
                client_ttl     = pvget(postvars, "ttl")[0]
136
                client_ttl     = pvget(postvars, "ttl")[0]
Line 182... Line 185...
182
                if found_g == 0:
185
                if found_g == 0:
183
                        print "ALERT {0}, but nobody is listening!".format(server_targets)
186
                        print "ALERT {0}, but nobody is listening!".format(server_targets)
184
 
187
 
185
        if pvget(postvars, "action")[0] == "motion_on": # 1.3.6.1.4.1.37476.2.4.1.100
188
        if pvget(postvars, "action")[0] == "motion_on": # 1.3.6.1.4.1.37476.2.4.1.100
186
                print "Motion start"
189
                print "Motion start"
-
 
190
                if config.enable_motion_detect:
187
                os.system(os.path.dirname(os.path.abspath(__file__)) + "/motion/motion_start_safe")
191
                        os.system(os.path.dirname(os.path.abspath(__file__)) + "/motion/motion_start_safe")
188
 
-
 
-
 
192
                if config.enable_doorbell_listener:
-
 
193
                        g_bellListenerProc = sp.Popen(['python3',os.path.dirname(os.path.abspath(__file__)) + "/doorbell/bell_listener.py"])
189
        if pvget(postvars, "action")[0] == "motion_off": # 1.3.6.1.4.1.37476.2.4.1.101
194
        if pvget(postvars, "action")[0] == "motion_off": # 1.3.6.1.4.1.37476.2.4.1.101
190
                print "Motion stop"
195
                print "Motion stop"
-
 
196
                if config.enable_motion_detect:
191
                os.system(os.path.dirname(os.path.abspath(__file__)) + "/motion/motion_stop_safe")
197
                        os.system(os.path.dirname(os.path.abspath(__file__)) + "/motion/motion_stop_safe")
-
 
198
                if config.enable_doorbell_listener:
-
 
199
                        sp.Popen.terminate(g_bellListenerProc)
192
 
200
 
193
        self._output(200, '')
201
        self._output(200, '')
194
 
202
 
195
def pvget(ary, key):
203
def pvget(ary, key):
196
        if ary.get(key) == None:
204
        if ary.get(key) == None: