diff --git a/.idea/misc.xml b/.idea/misc.xml index 1209e49..857233a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ + + \ No newline at end of file diff --git a/Controller/adcontroller_export.py b/Controller/adcontroller_export.py index 6472b8b..b2574d4 100644 --- a/Controller/adcontroller_export.py +++ b/Controller/adcontroller_export.py @@ -28,13 +28,15 @@ create_service.addservice("REPORTS-AD") def adcontroller (ip,name): command = ["powershell", "-Command", - "Get-ADUser -Filter * -Properties * | Export-Csv -NoTypeInformation -Encoding UTF8 -Path 'users.csv'"] + " Get-ADUser -Filter * -Properties * | Select-Object *, extensionAttribute1, extensionAttribute2 | Export-Csv -NoTypeInformation -Encoding UTF8 -Path 'users.csv'"] subprocess.run(command) # CSV-Datei einlesen und Feldnamen auslesen with open("users.csv", "r", encoding='utf-8-sig') as file: reader = csv.DictReader(file) fieldnames = reader.fieldnames - + # + # unwanted_columns = ["PropertyNames", "AddedProperties","RemovedProperties","ModifiedProperties","PropertyCount"] + # fieldnames = [col for col in fieldnames if col not in unwanted_columns] # Tabelle erstellen, falls sie noch nicht existiert table_name = "Active-Directory-User" create_table_query = f"CREATE TABLE IF NOT EXISTS `{table_name}` (id INT AUTO_INCREMENT PRIMARY KEY, importdate BIGINT(11), " @@ -50,10 +52,10 @@ def adcontroller (ip,name): for row in reader: row = [cell if cell.strip() else "-" for cell in row] unix_time = int(datetime.now().timestamp()) - print(unix_time) row = [unix_time] + row insert_query = f"INSERT INTO `{table_name}` (importdate, `{'`, `'.join(fieldnames)}`) VALUES (%s, {', '.join(['%s'] * len(fieldnames))})" - print(request_post("ad/adduser", {"query": insert_query, 'dbname': name, 'entry': row}).text) + # print(insert_query) + request_post("ad/adduser", {"query": insert_query, 'dbname': name, 'entry': row}) # mysql_connect.add_user(insert_query, name, row) command = ["powershell", "-Command", @@ -123,19 +125,23 @@ def get_local_ip(): service_time = f"23:{str(random.randint(1, 59)).zfill(2)}" ## ADD Random Time -while True: - current_time = datetime.now().strftime("%H:%M") - try: - with open ("log.txt","a") as datei: - datei.writelines(request_get("gettime",{}).text + "\n") - except Exception as e: - with open ("log.txt","a") as datei: - datei.writelines(f"{current_time}No Connection to Server!" + "\n") - if current_time == service_time: - ip = get_local_ip() - database = request_post("info/getdatabase",{"ip":ip}).text.replace('"',"") - adcontroller(ip,database) - with open ("log.txt","a") as datei: - datei.writelines(f"{current_time} - Sleep for {22*3600}" + "\n") - time.sleep(22*3600) - time.sleep(60) \ No newline at end of file +# while True: +# current_time = datetime.now().strftime("%H:%M") +# try: +# with open ("log.txt","a") as datei: +# datei.writelines(request_get("gettime",{}).text + "\n") +# except Exception as e: +# with open ("log.txt","a") as datei: +# datei.writelines(f"{current_time}No Connection to Server!" + "\n") +# if current_time == service_time: +# ip = get_local_ip() +# database = request_post("info/getdatabase",{"ip":ip}).text.replace('"',"") +# adcontroller(ip,database) +# with open ("log.txt","a") as datei: +# datei.writelines(f"{current_time} - Sleep for {22*3600}" + "\n") +# time.sleep(22*3600) +# time.sleep(60) + +ip = get_local_ip() +database = request_post("info/getdatabase",{"ip":ip}).text.replace('"',"") +adcontroller(ip,database) diff --git a/Controller/exchange_export.py b/Controller/exchange_export.py index bd22151..ff4ff6f 100644 --- a/Controller/exchange_export.py +++ b/Controller/exchange_export.py @@ -21,7 +21,7 @@ def request_get(function,variable): def exchange(ip,name): - # exchange_commands = "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn; Get-Mailbox | Select-Object PSComputerName, RunspaceId, PSShowComputerName, Database, UseDatabaseRetentionDefaults, RetainDeletedItemsUntilBackup, IsHierarchyReady, IsHierarchySyncEnabled,RetentionPolicy, ExchangeGuid, AdminDisplayVersion, ExchangeUserAccountControl, IsMailboxEnabled,ProhibitSendQuota, ProhibitSendReceiveQuota, RecoverableItemsQuota, RecoverableItemsWarningQuota,CalendarLoggingQuota, IsResource, IsLinked, IsShared, IsRootPublicFolderMailbox, LinkedMasterAccount, ResetPasswordOnNextLogon,ResourceType, RoomMailboxAccountEnabled, SamAccountName, ServerLegacyDN, UseDatabaseQuotaDefaults,IssueWarningQuota, RulesQuota, UserPrincipalName, RoleAssignmentPolicy, EffectivePublicFolderMailbox, SharingPolicy,ArchiveQuota, ArchiveWarningQuota, DisabledMailboxLocations, CalendarVersionStoreDisabled, AuditEnabled,AuditLogAgeLimit, WhenMailboxCreated, AccountDisabled, Alias, OrganizationalUnit, DisplayName,LegacyExchangeDN, MaxSendSize, MaxReceiveSize, EmailAddressPolicyEnabled, PrimarySmtpAddress,RecipientType, RecipientTypeDetails, WindowsEmailAddress, Identity, IsValid, ExchangeVersion,DistinguishedName, Guid, ObjectCategory, WhenChanged, WhenCreated, WhenChangedUTC, WhenCreatedUTC,OrganizationId, Id, OriginatingServer | Export-Csv -Path 'exuser.csv' -NoTypeInformation -Encoding UTF8" + # exchange_commands = "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn; Get-Mailbox | Select-Object PSComputerName, RunspaceId, PSShowComputerName, Database, UseDatabaseRetentionDefaults, RetainDeletedItemsUntilBackup, IsHierarchyReady, IsHierarchySyncEnabled,RetentionPolicy, ExchangeGuid, AdminDisplayVersion, ExchangeUserAccountControl, IsMailboxEnabled,ProhibitSendQuota, ProhibitSendReceiveQuota, RecoverableItemsQuota, RecoverableItemsWarningQuota,CalendarLoggingQuota, IsResource, IsLinked, IsShared, IsRootPublicFolderMailbox, LinkedMasterAccount, ResetPasswordOnNextLogon,ResourceType, RoomMailboxAccountEnabled, SamAccountName, ServerLegacyDN, UseDatabaseQuotaDefaults,IssueWarningQuota, RulesQuota, UserPrincipalName, RoleAssignmentPolicy, EffectivePublicFolderMailbox, SharingPolicy,ArchiveQuota, ArchiveWarningQuota, DisabledMailboxLocations, CalendarVersionStoreDisabled, AuditEnabled,AuditLogAgeLimit, WhenMailboxCreated, AccountDisabled, Alias, OrganizationalUnit, DisplayName,LegacyExchangeDN, MaxSendSize, MaxReceiveSize, EmailAddressPolicyEnabled, PrimarySmtpAddress,RecipientType, RecipientTypeDetails, WindowsEmailAddress, Identity, IsValid, ExchangeVersion,DistinguishedName, Guid, ObjectCategory, WhenChanged, WhenCreated, WhenChangedUTC, WhenCreatedUTC,OrganizationId, Id, OriginatingServer,CustomAttribute1 | Export-Csv -Path 'exuser.csv' -NoTypeInformation -Encoding UTF8" # # # PowerShell als Subprozess ausführen # process = subprocess.Popen(["powershell", "-Command", exchange_commands], stdout=subprocess.PIPE, shell=True) diff --git a/Controller/zammad.py b/Controller/zammad.py index 81340e2..fa6b876 100644 --- a/Controller/zammad.py +++ b/Controller/zammad.py @@ -29,7 +29,7 @@ def tickets(ip,name): ## Header auslesen headers = [desc[0] for desc in cursor.description] - ## Orga Auslesen + ## Orga Auslesen per API-Server group = f"SELECT id FROM groups WHERE name = '{name.replace('ae','ä').replace('ue','ü').replace('oe','ö').replace('-',' ')}'" cursor.execute(group) query = f"SELECT tickets.*, tag_items.name AS SLA FROM tickets LEFT JOIN tags ON tickets.id = tags.o_id LEFT JOIN tag_items ON tags.tag_item_id = tag_items.id WHERE group_id = {cursor.fetchone()[0]}" diff --git a/dist/REPORTS-AD.exe b/dist/REPORTS-AD.exe index 88bdf80..e016023 100644 Binary files a/dist/REPORTS-AD.exe and b/dist/REPORTS-AD.exe differ diff --git a/main.py b/main.py index d749030..68ac1d9 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -# from Controller import adcontroller_export, exchange_export, rds_export, smtp_export, zammad +from Controller import adcontroller_export, exchange_export, rds_export, smtp_export, zammad import random import subprocess import socket