-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateILOcredentials.v1.0.py
67 lines (54 loc) · 1.6 KB
/
createILOcredentials.v1.0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Created on May 1 2022
@author: Thomas Beha
"""
from cryptography.fernet import Fernet
import getpass
from lxml import etree
uname = input("Username: ")
password = getpass.getpass()
logfile = input("Logfile: ")
port = input("Connector Port: ")
fname = input("Filename: ")
mintervall = input("Monitoringintervall: ")
keyfile=fname+'.key'
xmlfile=fname+'.xml'
key = Fernet.generate_key()
k1 = key.decode('ASCII')
f = open(keyfile,'w')
f.write(key.decode('ASCII'))
f.close()
f = Fernet(key)
token = f.encrypt(password.encode('ASCII'))
user = f.encrypt(uname.encode('ASCII'))
root = etree.Element("data")
etree.SubElement(root,"username").text=uname
etree.SubElement(root,"user").text=user
etree.SubElement(root,"password").text=token
etree.SubElement(root,"logfile").text=logfile
etree.SubElement(root,"port").text=port
etree.SubElement(root,"monitoringintervall").text=mintervall
print("Enter the ILO IP addresses - stop by entering: 0 as the IP address")
ilo_ip = input("ILO IP Address: ")
while ilo_ip != "0":
etree.SubElement(root,"ILO_ip").text = ilo_ip
ilo_ip = input("ILO IP Address: ")
xmloutput = etree.tostring(root, pretty_print=True)
f = open(xmlfile,'w')
f.write(xmloutput.decode('ASCII'))
f.close()
""" Test the keys """
""" Read keyfile """
f = open(keyfile, 'r')
k2=f.readline()
f.close()
key2=k2.encode('ASCII')
""" Parse XML File """
tree = etree.parse(xmlfile)
u2=(tree.find("user")).text
p2=(tree.find("password")).text
f = Fernet(key2)
user = f.decrypt(u2.encode('ASCII')).decode('ASCII')
password = f.decrypt(p2.encode('ASCII')).decode('ASCII')
print(user,password)