Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feedback #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions add_em_phone/raw_axl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = ''
Expand All @@ -33,25 +33,30 @@ def execute(self, call, args, xml=''):
'xmlns:ns1="http://www.cisco.com/AXL/API/{}">'.format(self.version)
envelope += '<ns0:Header/>'
envelope += '<ns0:Body>'
envelope += '<ns1:{0} sequence="">'.format(call)
envelope += '<ns1:{} sequence="">'.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 += '</ns1:{0}>'.format(call)
envelope += '</ns1:{}>'.format(call)
envelope += '</ns0:Body>'
envelope += '</ns0:Envelope>'

# do the request (disable warnings)
# 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:
Expand All @@ -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))

Expand Down
5 changes: 4 additions & 1 deletion endpoint_monitoring/check_endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand All @@ -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?
Expand Down
13 changes: 6 additions & 7 deletions expressway_upgrade/expressway_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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)

Expand Down
37 changes: 18 additions & 19 deletions password_reset/expressway_password_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()