From eee958a134415d1c15e02a006f4f067aebe0023a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C5=9Eahin?= Date: Tue, 6 Dec 2016 11:51:25 +0300 Subject: [PATCH] registration and login messages extended --- debian/control | 2 +- opt/ahenk/base/messaging/messaging.py | 7 ++ opt/ahenk/base/registration/registration.py | 12 ++- opt/ahenk/base/system/system.py | 90 ++++++++++++++++++--- 4 files changed, 98 insertions(+), 13 deletions(-) diff --git a/debian/control b/debian/control index 77fc88f..48845c9 100644 --- a/debian/control +++ b/debian/control @@ -8,5 +8,5 @@ Homepage: http://www.liderahenk.org.tr Package: ahenk Architecture: any -Depends: bash, python3 (>= 3), cython, libidn11, libidn11-dev, python3-dev, python3-pip, python3-watchdog, libffi-dev, libssl-dev, python3-paramiko, python3-cpuinfo, python3-psutil (>= 4), libpam-script, python3-sleekxmpp, dmidecode, python3-easygui, notify-osd +Depends: bash, python3 (>= 3), cython, libidn11, libidn11-dev, python3-dev, python3-pip, python3-watchdog, libffi-dev, libssl-dev, python3-paramiko, python3-cpuinfo, python3-psutil (>= 4), libpam-script, python3-sleekxmpp, dmidecode, python3-easygui, notify-osd, read-edid Description: Lider Ahenk is an open source project which provides solutions to manage, monitor and audit unlimited number of different systems and users on a network. diff --git a/opt/ahenk/base/messaging/messaging.py b/opt/ahenk/base/messaging/messaging.py index 94456fb..86c7ced 100644 --- a/opt/ahenk/base/messaging/messaging.py +++ b/opt/ahenk/base/messaging/messaging.py @@ -70,6 +70,13 @@ class Messaging(object): data['username'] = username data['ipAddresses'] = str(System.Hardware.Network.ip_addresses()).replace('[', '').replace(']', '') data['timestamp'] = Util.timestamp() + + data['hardware.monitors'] = str(System.Hardware.monitors()), + data['hardware.screens'] = str(System.Hardware.screens()), + data['hardware.usbDevices'] = str(System.Hardware.usb_devices()), + data['hardware.printers'] = str(System.Hardware.printers()), + data['hardware.systemDefinitions'] = str(System.Hardware.system_definitions()), + json_data = json.dumps(data) self.logger.debug('Login message was created') return json_data diff --git a/opt/ahenk/base/registration/registration.py b/opt/ahenk/base/registration/registration.py index 296fa17..e30bd9d 100644 --- a/opt/ahenk/base/registration/registration.py +++ b/opt/ahenk/base/registration/registration.py @@ -125,10 +125,16 @@ class Registration: 'hardware.disk.used': System.Hardware.Disk.used(), 'hardware.disk.free': System.Hardware.Disk.free(), 'hardware.disk.partitions': str(parts), + 'hardware.monitors': str(System.Hardware.monitors()), + 'hardware.screens': str(System.Hardware.screens()), + 'hardware.usbDevices': str(System.Hardware.usb_devices()), + 'hardware.printers': str(System.Hardware.printers()), + 'hardware.systemDefinitions': str(System.Hardware.system_definitions()), 'hardware.memory.total': System.Hardware.Memory.total(), - 'hardware.network.ipAddresses': System.Hardware.Network.ip_addresses(), - 'sessions.userNames': System.Sessions.user_name(), - 'bios.releaseDate': System.BIOS.release_date()[1].replace('\n', '') if System.BIOS.release_date()[0] == 0 else 'n/a', + 'hardware.network.ipAddresses': str(System.Hardware.Network.ip_addresses()), + 'sessions.userNames': str(System.Sessions.user_name()), + 'bios.releaseDate': System.BIOS.release_date()[1].replace('\n', '') if System.BIOS.release_date()[ + 0] == 0 else 'n/a', 'bios.version': System.BIOS.version()[1].replace('\n', '') if System.BIOS.version()[0] == 0 else 'n/a', 'bios.vendor': System.BIOS.vendor()[1].replace('\n', '') if System.BIOS.vendor()[0] == 0 else 'n/a', 'hardware.baseboard.manufacturer': System.Hardware.BaseBoard.manufacturer()[1].replace('\n', '') if diff --git a/opt/ahenk/base/system/system.py b/opt/ahenk/base/system/system.py index 775ad98..652bc1d 100644 --- a/opt/ahenk/base/system/system.py +++ b/opt/ahenk/base/system/system.py @@ -2,18 +2,21 @@ # -*- coding: utf-8 -*- # Author: Volkan Şahin -import platform -import psutil -import cpuinfo -import re -import os import configparser -import socket import fcntl +import glob +import os +import platform +import re +import socket import struct from uuid import getnode as get_mac -from base.util.util import Util + +import cpuinfo +import psutil + from base.scope import Scope +from base.util.util import Util class System: @@ -472,6 +475,77 @@ class System: return arr + @staticmethod + def screen_info_json_obj(info): + label_list = [ + # 'Identifier', + 'ModelName', 'VendorName', 'Monitor Manufactured', 'DisplaySize', + # 'Gamma', + # 'Horizsync', + # 'VertRefresh' + ] + data = dict() + + for line in info.splitlines(): + line = line.strip().replace('"', '') + intersection = list(set(line.split(' ')).intersection(label_list)) + if len(intersection) > 0: + data[str(intersection[0])] = line.split(intersection[0])[1].strip() + + return data + + @staticmethod + def monitors(): + edid_list = glob.glob('/sys/class/drm/*/edid') + + monitor_list = list() + for edid in edid_list: + result_code, p_out, p_err = Util.execute('parse-edid < {0}'.format(edid)) + + if result_code == 0: + monitor_list.append(System.Hardware.screen_info_json_obj(p_out)) + + return monitor_list + + @staticmethod + def screens(): + result_code, p_out, p_err = Util.execute('xrandr') + arr = [] + if result_code == 0: + for line in p_out.splitlines(): + if len(list(set(line.split(' ')).intersection(['connected']))) > 0: + arr.append(line) + return arr + + @staticmethod + def usb_devices(): + result_code, p_out, p_err = Util.execute('lsusb') + arr = [] + if result_code == 0: + for line in p_out.splitlines(): + if ':' in line and 'Device 001' not in line.split(':')[0]: + arr.append(line) + return arr + + @staticmethod + def printers(): + result_code, p_out, p_err = Util.execute('lpstat -a') + arr = None + if result_code == 0: + arr = p_out.splitlines() + return arr + + @staticmethod + def system_definitions(): + result_code, p_out, p_err = Util.execute('dmidecode -t system') + arr = [] + if result_code == 0: + for line in p_out.splitlines(): + line = line.strip() + if len(list(set(line.split(' ')).intersection(['Manufacturer:', 'Product']))) > 0: + arr.append(line) + return arr + @staticmethod def machine_type(): config = configparser.ConfigParser() @@ -479,7 +553,6 @@ class System: config.read(System.Ahenk.config_path()) return config.get('MACHINE', 'type') - @staticmethod def interfaces_details(): return psutil.net_if_addrs() @@ -543,4 +616,3 @@ class System: @staticmethod def model(): return cpuinfo.get_cpu_info()['model'] -