ADD os.mkdir(C:Scripte) to create_service.py
parent
d7d0060e07
commit
26aab46c59
|
|
@ -1,4 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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" />
|
||||
</project>
|
||||
|
|
@ -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:
|
||||
# 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)
|
||||
with open ("log.txt","a") as datei:
|
||||
datei.writelines(f"{current_time} - Sleep for {22*3600}" + "\n")
|
||||
time.sleep(22*3600)
|
||||
time.sleep(60)
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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]}"
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue