From 4d19e9d092ed21eec72b9db2ecaf8cfef12d2fa6 Mon Sep 17 00:00:00 2001 From: owendelong Date: Sun, 17 Jan 2016 14:40:11 -0800 Subject: [PATCH 1/2] Update EagleClass.py Added support for Username/Password for HTTP Basic Authorization --- RainEagle/EagleClass.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/RainEagle/EagleClass.py b/RainEagle/EagleClass.py index 8241e88..ab6affb 100644 --- a/RainEagle/EagleClass.py +++ b/RainEagle/EagleClass.py @@ -11,6 +11,7 @@ import time import xml.etree.ElementTree as ET import urllib import urllib2 +import base64 from math import floor from urlparse import urlparse import json @@ -142,12 +143,17 @@ class Eagle(object) : addr address of device port port on device (default 5002) getmac connect to device at start up and get macid (default true) + password Password for HTTP Authentication + username Username for HTTP Authentication timeout TCP socket timeout Currently there is very little error handling ( if any at all ) """ def __init__(self, **kwargs): + self.username = kwargs.get("username", 0) + self.password = kwargs.get("password", 0) + self.debug = kwargs.get("debug", 0) if self.debug : @@ -801,7 +807,12 @@ class Eagle(object) : url = "http://{0}/cgi-bin/cgi_manager".format(self.addr) - req = urllib2.Request(url, commstr) + if self.username is not None : + if self.debug : + print("Authorization string: "+base64.64encode(self.username+":"+self.password)"+\n") + req = urllib2.Request(url, commstr, headers={ "Authorization" : 'Basic'+base64.b64encode(self.username+":"+self.password) }) + else : + req = urllib2.Request(url, commstr) response = urllib2.urlopen(req) the_page = response.read() From a62fb0a6024bb6d17cb247409680eb41943c1516 Mon Sep 17 00:00:00 2001 From: owendelong Date: Sun, 17 Jan 2016 14:43:03 -0800 Subject: [PATCH 2/2] Update meter_status.py Added support for HTTP Authorization --- bin/meter_status.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/meter_status.py b/bin/meter_status.py index c5ab3d4..8e4f55c 100755 --- a/bin/meter_status.py +++ b/bin/meter_status.py @@ -35,9 +35,15 @@ def create_parser(): parser.add_argument("-m", "--mac", dest="mac", help="Eagle radio mac addrress") + + parser.add_argument("-s", "--password", dest="password", + help="Password for HTTP Authorization") parser.add_argument("-t", "--timeout", dest="timeout", help="Socket timeout") + + parser.add_argument("-u", "--username", dest="username", + help="Username for HTTP Authorization") parser.add_argument("-v", '--version', action='version', version="%(prog)s {0}".format(__version__) )