#! /local/web/.local/bin/python3 import urllib.request import urllib.parse import xml.etree.ElementTree as ET import cgitb theurl = 'https:///tipsapi/config/read/Endpoint' username = '' password = '' xml_string = ''' ''' cgitb.enable() # Enable Traceback via HTML passman = urllib.request.HTTPPasswordMgrWithDefaultRealm() # this creates a password manager passman.add_password(None, theurl, username, password) # Because with have put None at the start it will always # use this username/password combination for urls # for which 'theurl' is a super-urllib authhandler = urllib.request.HTTPBasicAuthHandler(passman) # create the authhandler opener = urllib.request.build_opener(authhandler) urllib.request.install_opener(opener) # All calls to urllib.urlopen will now use our handler # Make sure not to include the protocol in the URL, or # HTTPPasswordMgrWithDefaultRealm will be very confused. # You must (of course) use it when fetching the page though. data = xml_string.encode('utf-8') # Encode string as bytes req = urllib.request.Request(theurl, data) req.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8") # Create request pagehandle = urllib.request.urlopen(req) # Submit request and return results # authentication automatically handled for username namespace ='{http://www.avendasys.com/tipsapiDefs/1.0}' root = ET.fromstring(pagehandle.read().decode('utf-8')) # Decode bytes to String and parse XML # Send HTTP Headers print("Content-Type: text/html") print() # Start HTML print("") print("") print("") print("") print("ITS : NEG : Clearpass Disabled Clients") print("") print("") print("

Clearpass Disabled Clients

") print("") print("") print("") print("") print("") for elem in root.findall("{0}Endpoints/{0}Endpoint".format(namespace)): print("") mac_address = elem.get('macAddress') for end_point_tag in elem.findall('{0}EndpointTags'.format(namespace)): if end_point_tag.get('tagName') == 'Disabled By': disabled_by = end_point_tag.get('tagValue') if end_point_tag.get('tagName') == 'Disabled Reason': disabled_reason = end_point_tag.get('tagValue') pretty_mac = ':'.join(mac_address[i:i+2] for i in range(0,12,2)) (dummy, IRDBTicket, disabled_reason) = disabled_reason.split(':') print("") print("") print("
Client MAC Address:Disabled by:IRDB Ticket #Disabled Reason:
", pretty_mac, "", disabled_by, "", IRDBTicket, "", disabled_reason, "
") print("") print("")