ADD os.mkdir(C:Scripte) to create_service.py

main
Sebastian Serfling 2023-10-17 14:10:07 +02:00
parent d7d0060e07
commit 26aab46c59
6 changed files with 32 additions and 23 deletions

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.9 (server-info) (2)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (server-info) (2)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (server-info) (2)" project-jdk-type="Python SDK" />
</project> </project>

View File

@ -28,13 +28,15 @@ create_service.addservice("REPORTS-AD")
def adcontroller (ip,name): def adcontroller (ip,name):
command = ["powershell", "-Command", 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) subprocess.run(command)
# CSV-Datei einlesen und Feldnamen auslesen # CSV-Datei einlesen und Feldnamen auslesen
with open("users.csv", "r", encoding='utf-8-sig') as file: with open("users.csv", "r", encoding='utf-8-sig') as file:
reader = csv.DictReader(file) reader = csv.DictReader(file)
fieldnames = reader.fieldnames 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 # Tabelle erstellen, falls sie noch nicht existiert
table_name = "Active-Directory-User" 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), " 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: for row in reader:
row = [cell if cell.strip() else "-" for cell in row] row = [cell if cell.strip() else "-" for cell in row]
unix_time = int(datetime.now().timestamp()) unix_time = int(datetime.now().timestamp())
print(unix_time)
row = [unix_time] + row row = [unix_time] + row
insert_query = f"INSERT INTO `{table_name}` (importdate, `{'`, `'.join(fieldnames)}`) VALUES (%s, {', '.join(['%s'] * len(fieldnames))})" 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) # mysql_connect.add_user(insert_query, name, row)
command = ["powershell", "-Command", 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 service_time = f"23:{str(random.randint(1, 59)).zfill(2)}" ## ADD Random Time
while True: # while True:
current_time = datetime.now().strftime("%H:%M") # current_time = datetime.now().strftime("%H:%M")
try: # try:
with open ("log.txt","a") as datei: # with open ("log.txt","a") as datei:
datei.writelines(request_get("gettime",{}).text + "\n") # datei.writelines(request_get("gettime",{}).text + "\n")
except Exception as e: # except Exception as e:
with open ("log.txt","a") as datei: # with open ("log.txt","a") as datei:
datei.writelines(f"{current_time}No Connection to Server!" + "\n") # datei.writelines(f"{current_time}No Connection to Server!" + "\n")
if current_time == service_time: # if current_time == service_time:
ip = get_local_ip() # ip = get_local_ip()
database = request_post("info/getdatabase",{"ip":ip}).text.replace('"',"") # database = request_post("info/getdatabase",{"ip":ip}).text.replace('"',"")
adcontroller(ip,database) # adcontroller(ip,database)
with open ("log.txt","a") as datei: # with open ("log.txt","a") as datei:
datei.writelines(f"{current_time} - Sleep for {22*3600}" + "\n") # datei.writelines(f"{current_time} - Sleep for {22*3600}" + "\n")
time.sleep(22*3600) # time.sleep(22*3600)
time.sleep(60) # time.sleep(60)
ip = get_local_ip()
database = request_post("info/getdatabase",{"ip":ip}).text.replace('"',"")
adcontroller(ip,database)

View File

@ -21,7 +21,7 @@ def request_get(function,variable):
def exchange(ip,name): 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 # # PowerShell als Subprozess ausführen
# process = subprocess.Popen(["powershell", "-Command", exchange_commands], stdout=subprocess.PIPE, shell=True) # process = subprocess.Popen(["powershell", "-Command", exchange_commands], stdout=subprocess.PIPE, shell=True)

View File

@ -29,7 +29,7 @@ def tickets(ip,name):
## Header auslesen ## Header auslesen
headers = [desc[0] for desc in cursor.description] 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('-',' ')}'" group = f"SELECT id FROM groups WHERE name = '{name.replace('ae','ä').replace('ue','ü').replace('oe','ö').replace('-',' ')}'"
cursor.execute(group) 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]}" 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]}"

BIN
dist/REPORTS-AD.exe vendored

Binary file not shown.

View File

@ -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 random
import subprocess import subprocess
import socket import socket