Browse Source

Merge pull request #2 from owendelong/master

Support HTTP Authorization -- Required if "Enable Security" is checked
main
Peter Shipley 9 years ago
parent
commit
d247aab0d8
2 changed files with 18 additions and 1 deletions
  1. +12
    -1
      RainEagle/EagleClass.py
  2. +6
    -0
      bin/meter_status.py

+ 12
- 1
RainEagle/EagleClass.py View File

@@ -11,6 +11,7 @@ import time
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import urllib import urllib
import urllib2 import urllib2
import base64
from math import floor from math import floor
from urlparse import urlparse from urlparse import urlparse
import json import json
@@ -142,12 +143,17 @@ class Eagle(object) :
addr address of device addr address of device
port port on device (default 5002) port port on device (default 5002)
getmac connect to device at start up and get macid (default true) 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 timeout TCP socket timeout


Currently there is very little error handling ( if any at all ) Currently there is very little error handling ( if any at all )
""" """
def __init__(self, **kwargs): def __init__(self, **kwargs):


self.username = kwargs.get("username", 0)
self.password = kwargs.get("password", 0)
self.debug = kwargs.get("debug", 0) self.debug = kwargs.get("debug", 0)


if self.debug : if self.debug :
@@ -801,7 +807,12 @@ class Eagle(object) :


url = "http://{0}/cgi-bin/cgi_manager".format(self.addr) 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) response = urllib2.urlopen(req)
the_page = response.read() the_page = response.read()




+ 6
- 0
bin/meter_status.py View File

@@ -35,9 +35,15 @@ def create_parser():


parser.add_argument("-m", "--mac", dest="mac", parser.add_argument("-m", "--mac", dest="mac",
help="Eagle radio mac addrress") help="Eagle radio mac addrress")
parser.add_argument("-s", "--password", dest="password",
help="Password for HTTP Authorization")


parser.add_argument("-t", "--timeout", dest="timeout", parser.add_argument("-t", "--timeout", dest="timeout",
help="Socket timeout") help="Socket timeout")
parser.add_argument("-u", "--username", dest="username",
help="Username for HTTP Authorization")


parser.add_argument("-v", '--version', action='version', parser.add_argument("-v", '--version', action='version',
version="%(prog)s {0}".format(__version__) ) version="%(prog)s {0}".format(__version__) )


Loading…
Cancel
Save