def __init__(self, connection, get_login=False): # Every new property should be defind here with the corresponding method of Properties.properties.gather_physical_information prop = Properties() prop.gather_physical_information(connection) self.hostname = prop.get_hostname() self.disks = prop.get_disks() self.cpu = prop.get_cpu_usage() self.memory = prop.get_memory_usage() self.virtualization = None login = Logon(self.hostname, 4624) try: if get_login: self.login_info = { "most_login": None, "login_info": login.get_logged_users() } login.close_log() most_login = { "amount_logins": 0, "name": "None", "last_login": None } for user in self.login_info["login_info"]: if user["name"] == "liberton": continue if int(user["amount_logins"]) > int( most_login["amount_logins"]): most_login = user self.login_info["most_login"] = most_login except Exception as e: print(e) self.login_info = None
def test_logon(self): logon = Logon(login='******', password='******') encoded_logon = self.marshaller.encode_logon(logon=logon) message_type, body, _ = self.marshaller.decode_header(encoded_logon) decoded_logon = self.marshaller.decode_logon(body) self.assertEqual(message_type, MessageTypes.Logon.value) self.assertEqual(logon.__dict__, decoded_logon.__dict__)
def test_logon(instrument_identifier, marshaller): logon = Logon(login=random_string(length=5), password=random_string(length=5)) encoded_logon = marshaller.encode_logon(logon=logon) message_type, body, _ = marshaller.decode_header(encoded_logon) decoded_logon = marshaller.decode_logon(body) assert message_type == MessageTypes.Logon.value assert logon.__dict__ == decoded_logon.__dict__
def decode_logon(self, encoded_logon): tokens = list(filter(None, encoded_logon.split(self.separator))) logon = Logon(login=tokens[0], password=tokens[1]) return logon
def on_connect(self): logon = Logon(self.login, self.password) encoded_logon = self.marshaller.encode_logon(logon) self.output_message_stacks[self.server_socket].append(encoded_logon)
def decode_logon(self, encoded_logon): logon_message = logon_pb2.Logon() logon_message.ParseFromString(encoded_logon) logon = Logon(login=logon_message.login, password=logon_message.password) return logon