diff --git a/add_em_phone/raw_axl.py b/add_em_phone/raw_axl.py index 3b24e41..c179623 100644 --- a/add_em_phone/raw_axl.py +++ b/add_em_phone/raw_axl.py @@ -13,7 +13,7 @@ class AxlException(Exception): class RawAxl: - def __init__(self, username, password, server=None, version="10.5"): + def __init__(self, username, password, server, version="10.5"): # setup username and password self.username = username self.password = password @@ -23,7 +23,7 @@ def __init__(self, username, password, server=None, version="10.5"): def setCluster(self, newCluster): self.server = newCluster - + def execute(self, call, args, xml=''): # clear some stuff self.response_xml = '' @@ -33,16 +33,18 @@ def execute(self, call, args, xml=''): 'xmlns:ns1="http://www.cisco.com/AXL/API/{}">'.format(self.version) envelope += '' envelope += '' - envelope += ''.format(call) + envelope += ''.format(call) # arguments from dict to xml if not xml == '': envelope += xml else: - envelope += str(dicttoxml.dicttoxml(args, attr_type=False, root=False).decode("UTF-8")) + envelope += str( + dicttoxml.dicttoxml(args, attr_type=False, + root=False).decode("UTF-8")) # closing tags - envelope += ''.format(call) + envelope += ''.format(call) envelope += '' envelope += '' @@ -50,8 +52,11 @@ def execute(self, call, args, xml=''): # requests.packages.urllib3.disable_warnings(InsecureRequestWarning) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) url = 'https://{}:8443/axl/'.format(self.server) - r = requests.post(url, data=envelope, - auth=HTTPBasicAuth(self.username, self.password), verify=False) + r = requests.post( + url, + data=envelope, + auth=HTTPBasicAuth(self.username, self.password), + verify=False) # if not 200, throw exception if r.status_code == 200 or r.status_code == 500: @@ -64,35 +69,29 @@ def execute(self, call, args, xml=''): r_dict = xmltodict.parse(r.text, process_namespaces=True) body = r_dict['{}:Envelope'.format(ns0)]['{}:Body'.format(ns0)] - if '{0}:{1}Response'.format(ns1, call).format(call) in body: - return body['{0}:{1}Response'.format(ns1, call)] + if '{}:{}Response'.format(ns1, call) in body: + return body['{}:{}Response'.format(ns1, call)] elif '{}:Fault'.format(ns0) in body: # clean it up a bit + '''NOT SURE IF WE NEED THIS? CONVERTS OBJECT TO STRING.. BACK TO OBJECT. ONLY TO PRINT''' exceptionBody = {'fault': body['{}:Fault'.format(ns0)]} raise AxlException(json.loads(json.dumps(exceptionBody))) - else: - return body + return body - elif r.status_code != 200: - # not ok, the axl call didn't make it trough for some reason - raise AxlException('Http Status {}'.format(r.status_code)) + # not ok, the axl call didn't make it trough for some reason + raise AxlException('Http Status {}'.format(r.status_code)) if __name__ == '__main__': axl = RawAxl(*sys.argv[1:]) # print('Testcase 1:') - # response = axl.execute('executeSQLQuery', {'sql': "select * from enduser where userid like '{}%'".format(sys.argv[1])}) - # print(response) - # print(json.dumps(response, sort_keys=True, indent=4)) - - # print('Testcase 2:') # response2 = axl.execute('getPhone', {'name': "SEPxxxxxxxxxxxx"}) # print(response2) # print(json.dumps(response2, sort_keys=True, indent=4)) # print(axl.response_xml) - # print('Testcase 3:') + # print('Testcase 2:') # response3 = axl.execute('addPhone', {'phone': response2['return']['phone']}) # print(json.dumps(response3, sort_keys=True, indent=4)) diff --git a/endpoint_monitoring/check_endpoints.php b/endpoint_monitoring/check_endpoints.php index eb279cb..5e3ca90 100644 --- a/endpoint_monitoring/check_endpoints.php +++ b/endpoint_monitoring/check_endpoints.php @@ -12,6 +12,7 @@ $server = readline('server to connect to (AXL must be running): '); $username = readline('username with AXL permissions: '); // A bit of trickery for hiding passwords, this will only work on UX like systems +'''PASSWORD WILL BE LOGGED HERE AS PLAIN TEXT, DO WE WANT THIS?''' echo "Password: "; system('stty -echo'); $password = trim(fgets(STDIN)); @@ -84,7 +85,7 @@ curl_setopt($_ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($_ch, CURLOPT_HEADER, 0); curl_setopt($_ch, CURLOPT_VERBOSE, 0); - + '''WE SHOULD REMOVE THIS''' // Todo: parse the below to just find out if there's an issue or not $_rep = curl_exec($_ch); //var_dump($_rep); @@ -97,10 +98,12 @@ print("Touchpanel not found\n"); $issues[] = $device->devicename; } + '''LOGIC ERROR?''' if( ! isset($_ch) ) curl_close($_ch); } +'''SHOULD REMOVE THESE COMMENTS''' // Create ticket for issues // Not sure how far we can go here, obviously we won't create anything // Todo: add some pseudo code? Or go with the SNow code we have? diff --git a/expressway_upgrade/expressway_upgrade.py b/expressway_upgrade/expressway_upgrade.py index b7d2dbd..8113f13 100644 --- a/expressway_upgrade/expressway_upgrade.py +++ b/expressway_upgrade/expressway_upgrade.py @@ -5,7 +5,6 @@ import time import getpass - def do_backup(server, password): cmd = 'sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} "echo random_key | /sbin/backup.sh"'.format(password, server) exitcode, data = subprocess.getstatusoutput(cmd) @@ -20,8 +19,9 @@ def do_install(server, image, password): exitcode, data = subprocess.getstatusoutput(cmd) if exitcode: return False - else: - time.sleep(20) + + '''EXPLANATION ON WHAT SLEEP IS FOR AND WHY 20 WAS CHOSEN''' + time.sleep(20) cmd = 'sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} "ls -l /tmp/install*"'.format(password, server) while time.time() - starttime < waittime: @@ -38,10 +38,8 @@ def do_install(server, image, password): def tshell_reboot(server, password): cmd = 'sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} "echo xCommand Boot | tshell"'.format(password, server) exitcode, data = subprocess.getstatusoutput(cmd) - if exitcode or 'OK' not in data: - return False - return True - + '''COLLAPSED THIS LINE, NEEDS TESTING''' + return exitcode or 'OK' in data if __name__ == '__main__': # get hostname and root password @@ -61,6 +59,7 @@ def tshell_reboot(server, password): image_filename = input('filename: ') print("starting to copy image, this may take a while ...") + '''INCONSISTENT DIRECTORY LOOKUP AS TO ADD_EM_PHONE''' res = do_install(host, 'images/' + image_filename, root_pass) print(res) diff --git a/password_reset/expressway_password_reset.py b/password_reset/expressway_password_reset.py index 5114c02..8b478cb 100644 --- a/password_reset/expressway_password_reset.py +++ b/password_reset/expressway_password_reset.py @@ -20,25 +20,24 @@ exit(1) # Initialise SSH login, make sure to auto accept new keys -ssh = paramiko.SSHClient() -ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # don't do this in production -try: - ssh.connect(host, username="root", password=root_pass, timeout=5, look_for_keys=False) -except Exception as message: - print('Could not login to host {}: {}'.format(host, str(message))) - exit(1) +with paramiko.SSHClient() as ssh: + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # don't do this in production + try: + ssh.connect(host, username="root", password=root_pass, timeout=5, look_for_keys=False) + except Exception as message: + print('Could not login to host {}: {}'.format(host, str(message))) + raise -# we're logged in, change password -stdin, stdout, stderr = ssh.exec_command('passwd {}'.format(user)) -stdin.write(new_pass+"\n") -stdin.flush() -stdin.write(new_pass+"\n") -stdin.flush() -exit_status = stdout.channel.recv_exit_status() + # we're logged in, change password + stdin, stdout, stderr = ssh.exec_command('passwd {}'.format(user)) + stdin.write(new_pass+"\n") + stdin.flush() + stdin.write(new_pass+"\n") + stdin.flush() + exit_status = stdout.channel.recv_exit_status() -if exit_status == 0: - print('password changed successfully for {}'.format(user)) -else: - print('issue while trying to change password for {}'.format(user)) + if exit_status == 0: + print('password changed successfully for {}'.format(user)) + else: + print('issue while trying to change password for {}'.format(user)) -ssh.close()