def getDpsk(nbi_password, nbi_url, client_mac, wlan): # Create XML string to retrieve the newly created DPSK for the user xml_request = xmlcommon.createXmlFetchDpsk(nbi_password, client_mac, wlan) # Send the request to the ZD and capture response. The response is in XML format xml_response = xmlcommon.sendXmlString(xml_request, nbi_url) # Check response success = False if not xml_response: print "Content-type: text/html \n\n" print "Retrieve DPSK failed: No response from ZoneDirector" else: response_code = xmlcommon.checkXmlResponse(xml_response) # Lookup the code returned to see if it indicates successful authentication success = xmlcommon.statusCodeLookup(response_code, "dpsk") if not success: return False passphrase = xmlcommon.getXmlAttribute(xml_response, "dpsk", "passphrase") expiration = xmlcommon.getXmlAttribute(xml_response, "dpsk", "expiration") return passphrase, expiration
def downloadProv2server(nbi_password, nbi_url, client_ip, client_mac, username, wlan, expiration, key_length, vlan): # Generate the XML request xml_request, ext = xmlcommon.createXmlFetchProv( nbi_password, nbi_url, client_ip, client_mac, username, wlan, expiration, key_length, vlan ) # Send the request to the ZD and capture response. The response is in XML format xml_response = xmlcommon.sendXmlString(xml_request, nbi_url) # The response can be a binary stream or an XML file with a return code # File download location is hard-coded here to /downloads tmpdt = strftime("%Y%m%d-%H%M%S", gmtime()) file_loc = "replace_file_location/prov-%s.%s" % (tmpdt, ext) file = "prov-%s.%s" % (tmpdt, ext) # This should be changed to match the root directory for your web files server_loc = "/var/www/" # Parse the response msgData = xmlcommon.getXmlTagData(xml_response, "response-code") if msgData: print "Content-type: text/html \n\n" print "get prov failed with code %s" % msgData file_loc = file_loc.replace(".exe", ".xml") server_loc += file_loc writeProv2serverFile(xml_response, server_loc) # Construct the full HTTP URL for prov.exe server = os.environ["SERVER_NAME"] prov_url = "http://" + server + file_loc return prov_url
def authenticateUser(nbi_password,nbi_url,client_ip,client_mac,username,password): # Create the XML authentication request xml_request = xmlcommon.createXmlAuthReq(nbi_password,client_ip,client_mac,username,password) # Send the XML authentication request to the ZD and capture response. The response is in XML format xml_response = xmlcommon.sendXmlString(xml_request,nbi_url) # Check response success = '' if not xml_response: print "Content-type: text/html \n\n" print "Authentication request failed: No response from ZoneDirector." return else: response_code = xmlcommon.checkXmlResponse(xml_response) # Lookup the code returned to see if it indicates successful authentication success = xmlcommon.statusCodeLookup(response_code, "auth") return success
def createDpsk( nbi_password, nbi_url, client_ip, client_mac, username, password, expiration, key_length, wlan, vlan, restricted ): # Create XML string to generate a DPSK for the user xml_request = xmlcommon.createXmlDpskReq( nbi_password, client_ip, client_mac, username, password, expiration, key_length, wlan, vlan, restricted ) # Send the request to the ZD and capture response. The response is in XML format xml_response = xmlcommon.sendXmlString(xml_request, nbi_url) # Check response success = False if not xml_response: print "Content-type: text/html \n\n" print "DPSK generation failed: No response from ZoneDirector" else: response_code = xmlcommon.checkXmlResponse(xml_response) # Lookup the code returned to see if it indicates successful authentication success = xmlcommon.statusCodeLookup(response_code, "dpsk") return success