#!/usr/bin/env python # ^^^^^^^ PATH TO PYTHON. Not tested on 3.x. import cgi, time, os, sys, smtplib from email.mime.text import MIMEText global debug, dpath # VISONIC ALARM RECEIVER # Put in /scripts/ on your web server running on port 8080 and point your panel to it's IP. # Quick and dirty implementation without needing non-standard libs. Should work out of the box with a standard install of Apache and Python on Windows or *nix # It's not pretty if you want to re-write it and make it nice be my guest. # If you are getting a com error make a file called /scripts/update.php with the following text "status =0&ka_time =480&allow =0&id =119254&" # I take no responsibility for the use of this script in replacement for the official manufacturers software # and make no guarantees about it's compatibility or reliability USE AT YOUR OWN RISK! # Coded by Guyfromhe on ShieldLab ###################### DRYRUNTEST=True #Configuration: paneltime = 0 # 0 - Use server time. 1 - Use panel time sent in timestamp months = ['Zero Padded','January','Febuary','March','April','May','June','July','August','September','October','November','December'] # Month names. First entry will never be used but must be there! debug = 0 # 1 - Enable debug raw data log 0 - Don't log raw data dpath = "/var/visonic" # Path for debug files no trailing slash semail = 1 # 1 - Enable e-mail 0 - log to e-mail file edefault='luca.malgeri@cern.ch' # Default e-mail address when not specified by panel. Blank to just drop messages efrom = 'malgeri.home@gmail.com' # From address subject = "Event detected from Visonic alarm system!" # Subject for e-mail eserver = "smtp.gmail.com" # Outgoing mail server on port 25 (does not support auth or ssl) eport = 587 epasswd = "Tremiti1" # Security: secmode = 0 # 0 - No security 1 - Match Account 2 - Match Serial 3 - Match Both valid_accounts = ['000000',"001234"] # List of valid accounts 'account #','account #', etc valid_serials = ['111111','222222'] # List of valid serial numbers, same format as above ################################################################################################## def email(edefault, efrom, subject, eserver, elist,body): global debug, dpath if elist== "" or elist == "\n": elist = edefault elist = elist.split('\n') for addy in elist: if addy != "": # Create a text/plain message msg = MIMEText(body) msg['Subject'] = subject msg['From'] = efrom msg['To'] = addy s = smtplib.SMTP(eserver,eport) s.ehlo() s.starttls() s.login(efrom,epasswd) s.sendmail(efrom, addy, msg.as_string()) s.close() # s.quit() if debug == 1: q = open("%s/email-debug.txt" % dpath,'a') q.write(efrom +" "+addy +" "+ body+"\n") q.close() if not DRYRUNTEST: # ip = cgi.escape(os.environ["REMOTE_ADDR"]) # get thar IP ip = cgi.escape(os.environ["REMOTE_ADDR"]) # get thar IP else: ip = "192.168.1.110" # generate header print "Content type: text/html\n\n" if not DRYRUNTEST: form = cgi.FieldStorage() # Doesn't actually post a real form, just posts XML data. Work on the full string for ease data = form.value else: data=""" 001234 39 0208018292 2 """ data = data.split('\n') # Initialize the user list userlist = {} elist = "" # Turn all the XML crap into variables. This seems to be pretty standardized/simple format. if debug == 1: z = open('%s/XMLdata.txt' % dpath,'a') for line in data: if debug == 1: z.write(line + "\n") try: if line.find('')[1].split('<')[0] if line.find('')[1].split('<')[0] if line.find('')[1].split('<')[0] if line.find('')[1].split('<')[0])*1.0 if line.find('')[1].split('<')[0] if line.find('')[1].split('<')[0] if line.find('')[1].split('<')[0] if line.find("