first Upload
commit
f9662c488e
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
|
|
@ -0,0 +1,2 @@
|
||||||
|
import os
|
||||||
|
os.system(f"docker exec -u www-data app-server /bin/bash -c 'php occ files:scan --path=karstenstoecker/files/Stines\ GmbH/1.\ Verwaltung/4.\ Verträge/2.\ Zulieferer\ -\ Dienstleister/MS\ -\ SPLA/Insight/Reports/'")
|
||||||
|
|
@ -0,0 +1,362 @@
|
||||||
|
import csv
|
||||||
|
import os
|
||||||
|
import mysql.connector
|
||||||
|
import pandas as pd
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
import openpyxl
|
||||||
|
import calendar
|
||||||
|
import http.client, urllib
|
||||||
|
# from reportlab.lib.pagesizes import letter
|
||||||
|
# from reportlab.pdfgen import canvas
|
||||||
|
from openpyxl.styles import Alignment, Font
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
date = datetime.now() - timedelta(1)
|
||||||
|
month = datetime.now().strftime("%m")
|
||||||
|
year = datetime.now().strftime("%Y")
|
||||||
|
start_date_00 = date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
start_date_23 = start_date_00.replace(hour=23, minute=59, second=59, microsecond=0)
|
||||||
|
start_date_str = start_date_00.strftime("01.%m")
|
||||||
|
last_date_str = start_date_00.strftime(f"{calendar.monthrange(int(year),int(month))[1]}.%m")
|
||||||
|
|
||||||
|
mydb = mysql.connector.connect(
|
||||||
|
host="172.17.1.21",
|
||||||
|
port="3306",
|
||||||
|
user="root",
|
||||||
|
password="N53yBCswuawzBzS445VNAhWVMs3N59Gb9szEsrzXRBzarDqpdETpQeyt5v5CGe",
|
||||||
|
database="Stines-GmbH",
|
||||||
|
auth_plugin='mysql_native_password',
|
||||||
|
)
|
||||||
|
mydb.connect()
|
||||||
|
cursor = mydb.cursor()
|
||||||
|
|
||||||
|
cursor.execute("SELECT Datenbank FROM Kunden GROUP by Datenbank")
|
||||||
|
kunden = cursor.fetchall()
|
||||||
|
|
||||||
|
main_path = fr"/docker/app_data/data/karstenstoecker/files/Stines GmbH/1. Verwaltung/4. Verträge/2. Zulieferer - Dienstleister/MS - SPLA/Insight/Reports/{year}"
|
||||||
|
for i in kunden:
|
||||||
|
kunde = i[0].replace("-"," ").replace("ae","ä")
|
||||||
|
if os.path.exists(fr"{main_path}/{i}/{start_date_str} - {last_date_str}/RAW"):
|
||||||
|
next
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
os.mkdir(fr"{main_path}/{kunde}")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
try:
|
||||||
|
os.mkdir(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
try:
|
||||||
|
os.mkdir(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
# RAW EXPORT
|
||||||
|
## AD - User Export START ##
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Active-Directory-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
cursor.execute(f'SELECT * FROM `{i[0]}`.`Active-Directory-User` where importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()}')
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
## AD - User Export ENDE ##
|
||||||
|
## SERVER - Export START ##
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
# print(f"SELECT Kundennummer,Name,`Server-Name`,`IP-Adresse`,CreateDate,`Windows-Key`,CPU,RAM,Speicher,Prozessor FROM `Stines-GmbH`.`Kunden-Server` where Name='{i[0]}' AND `Windows-Key` IS NOT NULL")
|
||||||
|
cursor.execute(f"SELECT Kundennummer,Name,`Server-Name`,`IP-Adresse`,CreateDate,`Windows-Key`,CPU,RAM,Speicher,Prozessor FROM `Stines-GmbH`.`Kunden-Server` where Name='{i[0]}' AND `Windows-Key` IS NOT NULL")
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
## SERVER - Export ENDE ##
|
||||||
|
## RDS - User Export START ##
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
try:
|
||||||
|
cursor.execute(f"SELECT id FROM `{i[0]}`.`Exchange-User` LIMIT 1")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
table_exists = cursor.fetchone() is not None
|
||||||
|
if table_exists:
|
||||||
|
cursor.execute(f'SELECT db1.importdate as "time",db1.CreateTimeStamp,db1.SamAccountName,db1.DisplayName, db1.EmailAddress, db1.extensionAttribute1 AS "RDS Deaktviert am", db1.extensionAttribute2 AS "Exchange Deaktviert am", db1.Description,db1.Deleted,db1.LastLogonDate,db1.City FROM `{i[0]}`.`Active-Directory-User` db1 INNER JOIN `{i[0]}`.`Active-Directory-RDS-User` db2 ON db1.SamAccountName = db2.SamAccountName WHERE db1.importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND db2.SamAccountName NOT LIKE "%test%" AND db2.SamAccountName NOT LIKE "%admin%"')
|
||||||
|
else:
|
||||||
|
cursor.execute(f'SELECT db1.importdate as "time",db1.CreateTimeStamp,db1.SamAccountName,db1.DisplayName, db1.EmailAddress, db1.extensionAttribute1 AS "RDS Deaktviert am", db1.Description,db1.Deleted,db1.LastLogonDate,db1.City FROM `{i[0]}`.`Active-Directory-User` db1 INNER JOIN `{i[0]}`.`Active-Directory-RDS-User` db2 ON db1.SamAccountName = db2.SamAccountName WHERE db1.importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND db2.SamAccountName NOT LIKE "%test%" AND db2.SamAccountName NOT LIKE "%admin%"')
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
if table_exists:
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
cursor.execute(f'SELECT importdate as "time",SamAccountName,WindowsEmailAddress,CustomAttribute2 as "Description",WhenCreated FROM `{i[0]}`.`Exchange-User` WHERE RecipientTypeDetails = "UserMailbox" AND importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND SamAccountName NOT LIKE "%test%" AND SamAccountName NOT LIKE "%admin%" AND SamAccountName NOT LIKE "%journal%" ')
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
## RDS - User Export ENDE ##
|
||||||
|
## RAW EXPORT ENDE ##
|
||||||
|
## CREATE Excel Sheet from csv Export ##
|
||||||
|
## EXPORT to AD- User Excel-Sheet ##
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_User_Export Stand({last_date_str}).xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
||||||
|
worksheet.auto_filter.ref = "A1:J1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
## EXPORT to AD- User Excel-Sheet ##
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
# df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Server_Export Stand({last_date_str}).xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
||||||
|
worksheet.auto_filter.ref = "A1:J1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
if table_exists:
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Mailbox_Export Stand({last_date_str}).xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
||||||
|
worksheet.auto_filter.ref = "A1:E1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
|
||||||
|
## CREATE Worksheet first Page
|
||||||
|
try:
|
||||||
|
os.remove(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
|
|
||||||
|
workbook = openpyxl.Workbook()
|
||||||
|
worksheet = workbook.active
|
||||||
|
worksheet.title = "Übersicht"
|
||||||
|
font = Font(size=20)
|
||||||
|
|
||||||
|
font_small = Font(size=16)
|
||||||
|
|
||||||
|
|
||||||
|
worksheet.merge_cells('C5:G6')
|
||||||
|
worksheet.merge_cells('C7:G7')
|
||||||
|
worksheet.merge_cells('C8:E8')
|
||||||
|
worksheet.merge_cells('C10:E10')
|
||||||
|
worksheet.merge_cells('C12:E12')
|
||||||
|
worksheet.merge_cells('C14:E14')
|
||||||
|
|
||||||
|
worksheet['C5'] = "Übersicht"
|
||||||
|
worksheet['C5'].font = font
|
||||||
|
|
||||||
|
worksheet['C7'] = f"{start_date_str} - {last_date_str}"
|
||||||
|
worksheet['C7'].font = font_small
|
||||||
|
|
||||||
|
worksheet['C10'] = "RDS-User"
|
||||||
|
worksheet['C10'].font = font_small
|
||||||
|
worksheet['G10'] = "=COUNTIF('RDS - User'!G2:G50;\"-\")"
|
||||||
|
|
||||||
|
if table_exists:
|
||||||
|
worksheet['C12'] = "Exchange-User"
|
||||||
|
worksheet['C12'].font = font_small
|
||||||
|
worksheet['G12'] = "=COUNTIF('Exchange - User'!D2:D50;\"<>\"&\"*Exchange - Deaktiviert*\")+1"
|
||||||
|
else:
|
||||||
|
next
|
||||||
|
|
||||||
|
worksheet['C14'] = "Server-Cores"
|
||||||
|
worksheet['C14'].font = font_small
|
||||||
|
worksheet['G14'] = "=COUNTIF('Server'!J2:J50)*8/2"
|
||||||
|
|
||||||
|
workbook.save(excel_datei)
|
||||||
|
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'RDS - User')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'RDS - User']
|
||||||
|
worksheet.auto_filter.ref = "A1:J1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
|
||||||
|
if table_exists:
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'Exchange - User')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'Exchange - User']
|
||||||
|
worksheet.auto_filter.ref = "A1:E1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
# df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'Server')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'Server']
|
||||||
|
worksheet.auto_filter.ref = "A1:J1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
# # os.mkdir("")
|
||||||
|
# #
|
||||||
|
# # print(table_exists)
|
||||||
|
# #
|
||||||
|
# # c = canvas.Canvas(fr"{i}/{start_date_str} - {last_date_str}/PDF_Export Stand({last_date_str}).pdf", pagesize=letter)
|
||||||
|
# # # Hier können Sie IhrenCode zum Hinzufügen von Daten zur PDF einfügen
|
||||||
|
# # c.setFont("Helvetica", 10)
|
||||||
|
# # c.drawString(50, 750, f"Create Date - {datetime.now().strftime("%d-%M-%Y")}")
|
||||||
|
# # c.drawImage("Firmen-Logo.png", x=450, y=730, width=150, height=40)
|
||||||
|
# # c.setFont("Helvetica", 12)
|
||||||
|
# # c.drawString(100, 680, "REPORT der RDP / Exchange User der Firma bla")
|
||||||
|
# #
|
||||||
|
# # k = 10
|
||||||
|
# # n = 650
|
||||||
|
# # x = 100
|
||||||
|
# # t = 0
|
||||||
|
# # if n < 50:
|
||||||
|
# # if t == 1:
|
||||||
|
# # x = 400
|
||||||
|
# # n = 650
|
||||||
|
# # print(x)
|
||||||
|
# # print("insede")
|
||||||
|
# # else:
|
||||||
|
# # x = 250
|
||||||
|
# # n = 650
|
||||||
|
# # t += 1
|
||||||
|
# # c.setFont("Helvetica", 8)
|
||||||
|
# # c.drawString(x, n, f"Zeitraum: {i}")
|
||||||
|
# # c.drawString(x, n - 10, f"Aktive RDS-User: {i}")
|
||||||
|
# # c.drawString(x, n - 20, f"Deaktivierte RDS-User: {i}")
|
||||||
|
# # if table_exists:
|
||||||
|
# # c.drawString(x, n - 30, f"Aktive EX-User: {i}")
|
||||||
|
# # c.drawString(x, n - 40, f"Deaktivierte EX-User: {i}")
|
||||||
|
# # n = n - 60
|
||||||
|
# # c.save()
|
||||||
|
# # subprocess.Popen(["start", "output.pdf"], shell=True)
|
||||||
|
cursor.close()
|
||||||
|
mydb.close()
|
||||||
|
os.system(f'chmod 777 -R "/docker/app_data/data/karstenstoecker/files/Stines GmbH/1. Verwaltung/4. Verträge/2. Zulieferer - Dienstleister/MS - SPLA/Insight/Reports/{year}"')
|
||||||
|
os.system(f"/bin/bash -c 'docker exec -u www-data app-server /bin/bash -c 'php occ files:scan --path=karstenstoecker/files/Stines\ GmbH/1.\ Verwaltung/4.\ Verträge/2.\ Zulieferer\ -\ Dienstleister/MS\ -\ SPLA/Insight/Reports/''")
|
||||||
|
|
||||||
|
## SEND Pushover ##
|
||||||
|
conn = http.client.HTTPSConnection("api.pushover.net:443")
|
||||||
|
conn.request("POST", "/1/messages.json",
|
||||||
|
urllib.parse.urlencode({
|
||||||
|
"token": "avzcexyjeu7y71pcskwshyx8ytmq8i",
|
||||||
|
"user": "uo2sf2pmrtjvt8auu786fviabimimr",
|
||||||
|
"message": "Reporting was running!",
|
||||||
|
}), { "Content-type": "application/x-www-form-urlencoded" })
|
||||||
|
conn.getresponse()
|
||||||
|
|
||||||
|
|
@ -0,0 +1,229 @@
|
||||||
|
import csv
|
||||||
|
import os
|
||||||
|
import mysql.connector
|
||||||
|
import pandas as pd
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
import openpyxl
|
||||||
|
# from reportlab.lib.pagesizes import letter
|
||||||
|
# from reportlab.pdfgen import canvas
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
mydb = mysql.connector.connect(
|
||||||
|
host="172.17.1.21",
|
||||||
|
port="3306",
|
||||||
|
user="root",
|
||||||
|
password="N53yBCswuawzBzS445VNAhWVMs3N59Gb9szEsrzXRBzarDqpdETpQeyt5v5CGe",
|
||||||
|
database="Stines-GmbH",
|
||||||
|
auth_plugin='mysql_native_password',
|
||||||
|
)
|
||||||
|
mydb.connect()
|
||||||
|
cursor = mydb.cursor()
|
||||||
|
|
||||||
|
lastdate_month=29
|
||||||
|
month=2
|
||||||
|
|
||||||
|
for k in range(0,lastdate_month):
|
||||||
|
heute = datetime.now()
|
||||||
|
start_date = datetime(2024, month, 1).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
start_date_00 = start_date + timedelta(days=k)
|
||||||
|
start_date_23 = start_date_00.replace(hour=23, minute=59, second=59, microsecond=0)
|
||||||
|
last_date = datetime(2024, month, lastdate_month)
|
||||||
|
year = last_date.strftime("%Y")
|
||||||
|
|
||||||
|
cursor.execute("SELECT Datenbank FROM Kunden GROUP by Datenbank")
|
||||||
|
kunden = cursor.fetchall()
|
||||||
|
start_date_str = start_date.strftime("%d.%m")
|
||||||
|
last_date_str = last_date.strftime("%d.%m")
|
||||||
|
|
||||||
|
main_path = fr"/docker/app_data/data/karstenstoecker/files/Stines GmbH/1. Verwaltung/4. Verträge/2. Zulieferer - Dienstleister/Microsoft Service Provider License Agreement/Insight Technology Solutions GmbH/Reports/{year}"
|
||||||
|
|
||||||
|
for i in kunden:
|
||||||
|
kunde = i[0].replace("-"," ").replace("ae","ä")
|
||||||
|
if os.path.exists(fr"{main_path}/{i}/{start_date_str} - {last_date_str}/RAW"):
|
||||||
|
next
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
os.mkdir(fr"{main_path}/{kunde}")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
try:
|
||||||
|
os.mkdir(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
try:
|
||||||
|
os.mkdir(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
# RAW EXPORT
|
||||||
|
## AD - User Export START ##
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Active-Directory-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
cursor.execute(f'SELECT * FROM `{i[0]}`.`Active-Directory-User` where importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()}')
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
|
||||||
|
## AD - User Export ENDE ##
|
||||||
|
## SERVER - Export START ##
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
# print(f"SELECT Kundennummer,Name,`Server-Name`,`IP-Adresse`,CreateDate,`Windows-Key`,CPU,RAM,Speicher,Prozessor FROM `Stines-GmbH`.`Kunden-Server` where Name='{i[0]}' AND `Windows-Key` IS NOT NULL")
|
||||||
|
cursor.execute(f"SELECT Kundennummer,Name,`Server-Name`,`IP-Adresse`,CreateDate,`Windows-Key`,CPU,RAM,Speicher,Prozessor FROM `Stines-GmbH`.`Kunden-Server` where Name='{i[0]}' AND `Windows-Key` IS NOT NULL")
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
## SERVER - Export ENDE ##
|
||||||
|
## RDS - User Export START ##
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
try:
|
||||||
|
cursor.execute(f"SELECT id FROM `{i[0]}`.`Exchange-User` LIMIT 1")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
table_exists = cursor.fetchone() is not None
|
||||||
|
if table_exists:
|
||||||
|
cursor.execute(f'SELECT db1.importdate as "time",db1.CreateTimeStamp,db1.SamAccountName,db1.DisplayName, db1.EmailAddress, db1.extensionAttribute1 AS "RDS Deaktviert am", db1.extensionAttribute2 AS "Exchange Deaktviert am", db1.Description,db1.Deleted,db1.LastLogonDate,db1.City FROM `{i[0]}`.`Active-Directory-User` db1 INNER JOIN `{i[0]}`.`Active-Directory-RDS-User` db2 ON db1.SamAccountName = db2.SamAccountName WHERE db1.importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND db2.SamAccountName NOT LIKE "%test%" AND db2.SamAccountName NOT LIKE "%admin%"')
|
||||||
|
else:
|
||||||
|
cursor.execute(f'SELECT db1.importdate as "time",db1.CreateTimeStamp,db1.SamAccountName,db1.DisplayName, db1.EmailAddress, db1.extensionAttribute1 AS "RDS Deaktviert am", db1.Description,db1.Deleted,db1.LastLogonDate,db1.City FROM `{i[0]}`.`Active-Directory-User` db1 INNER JOIN `{i[0]}`.`Active-Directory-RDS-User` db2 ON db1.SamAccountName = db2.SamAccountName WHERE db1.importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND db2.SamAccountName NOT LIKE "%test%" AND db2.SamAccountName NOT LIKE "%admin%"')
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
if table_exists:
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
cursor.execute(f'SELECT importdate as "time",SamAccountName,WindowsEmailAddress,CustomAttribute2 as "Description",WhenCreated FROM `{i[0]}`.`Exchange-User` WHERE RecipientTypeDetails = "UserMailbox" AND importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND SamAccountName NOT LIKE "%test%" AND SamAccountName NOT LIKE "%admin%" AND SamAccountName NOT LIKE "%journal%" ')
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
## RDS - User Export ENDE ##
|
||||||
|
## RAW EXPORT ENDE ##
|
||||||
|
## CREATE Excel Sheet from csv Export ##
|
||||||
|
## EXPORT to AD- User Excel-Sheet ##
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_User_Export Stand({last_date_str}).xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
||||||
|
|
||||||
|
worksheet.auto_filter.ref = "A1:J1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
|
||||||
|
## EXPORT to AD- User Excel-Sheet ##
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
# df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Server_Export Stand({last_date_str}).xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
||||||
|
|
||||||
|
worksheet.auto_filter.ref = "A1:J1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
|
||||||
|
if table_exists:
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Mailbox_Export Stand({last_date_str}).xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
||||||
|
|
||||||
|
worksheet.auto_filter.ref = "A1:E1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
|
||||||
|
# os.mkdir("")
|
||||||
|
#
|
||||||
|
# print(table_exists)
|
||||||
|
#
|
||||||
|
# c = canvas.Canvas(fr"{i}/{start_date_str} - {last_date_str}/PDF_Export Stand({last_date_str}).pdf", pagesize=letter)
|
||||||
|
# # Hier können Sie IhrenCode zum Hinzufügen von Daten zur PDF einfügen
|
||||||
|
# c.setFont("Helvetica", 10)
|
||||||
|
# c.drawString(50, 750, f"Create Date - {datetime.now().strftime("%d-%M-%Y")}")
|
||||||
|
# c.drawImage("Firmen-Logo.png", x=450, y=730, width=150, height=40)
|
||||||
|
# c.setFont("Helvetica", 12)
|
||||||
|
# c.drawString(100, 680, "REPORT der RDP / Exchange User der Firma bla")
|
||||||
|
#
|
||||||
|
# k = 10
|
||||||
|
# n = 650
|
||||||
|
# x = 100
|
||||||
|
# t = 0
|
||||||
|
# if n < 50:
|
||||||
|
# if t == 1:
|
||||||
|
# x = 400
|
||||||
|
# n = 650
|
||||||
|
# print(x)
|
||||||
|
# print("insede")
|
||||||
|
# else:
|
||||||
|
# x = 250
|
||||||
|
# n = 650
|
||||||
|
# t += 1
|
||||||
|
# c.setFont("Helvetica", 8)
|
||||||
|
# c.drawString(x, n, f"Zeitraum: {i}")
|
||||||
|
# c.drawString(x, n - 10, f"Aktive RDS-User: {i}")
|
||||||
|
# c.drawString(x, n - 20, f"Deaktivierte RDS-User: {i}")
|
||||||
|
# if table_exists:
|
||||||
|
# c.drawString(x, n - 30, f"Aktive EX-User: {i}")
|
||||||
|
# c.drawString(x, n - 40, f"Deaktivierte EX-User: {i}")
|
||||||
|
# n = n - 60
|
||||||
|
# c.save()
|
||||||
|
# subprocess.Popen(["start", "output.pdf"], shell=True)
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
mydb.close()
|
||||||
|
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
import openpyxl
|
||||||
|
from reportlab.pdfgen import canvas
|
||||||
|
from reportlab.pdfbase import pdfmetrics
|
||||||
|
from reportlab.pdfbase.pdfmetrics import stringWidth
|
||||||
|
from reportlab.pdfbase.ttfonts import TTFont
|
||||||
|
import os
|
||||||
|
from PyPDF2 import PdfFileReader, PdfFileMerger
|
||||||
|
|
||||||
|
pdfmetrics.registerFont(TTFont('Arial', 'Arial.ttf'))
|
||||||
|
wb = openpyxl.load_workbook('Excel_Export Stand(31.08).xlsx')
|
||||||
|
sheet = wb.get_sheet_by_name("01-08")
|
||||||
|
|
||||||
|
# print(sheet.cell(2,2).value)
|
||||||
|
|
||||||
|
page_width = 2156
|
||||||
|
page_height = 3050
|
||||||
|
start = 200
|
||||||
|
start_2 = 700
|
||||||
|
spread = 80
|
||||||
|
categories = ["Roll Number: ", "Name: ", "Gender: ", "Age: ", "Board: ", "City: ", "Email: "]
|
||||||
|
|
||||||
|
university = "NED University Of Engineering And Technology"
|
||||||
|
|
||||||
|
|
||||||
|
def create_data():
|
||||||
|
for i in range(2, 14):
|
||||||
|
std_id = sheet.cell(row=i, column=1).value
|
||||||
|
std_name = sheet.cell(row=i, column=2).value
|
||||||
|
std_gender = sheet.cell(row=i, column=3).value
|
||||||
|
std_age = sheet.cell(row=i, column=4).value
|
||||||
|
std_board = sheet.cell(row=i, column=5).value
|
||||||
|
std_city = sheet.cell(row=i, column=6).value
|
||||||
|
std_email = sheet.cell(row=i, column=8).value
|
||||||
|
|
||||||
|
data = [std_id, std_name, std_gender, std_age, std_board, std_city, std_email]
|
||||||
|
|
||||||
|
c = canvas.Canvas(str(std_name) + '.pdf')
|
||||||
|
c.setPageSize((page_width, page_height))
|
||||||
|
c.setFont('Arial', 80)
|
||||||
|
text_width = stringWidth(university, 'Arial', 80)
|
||||||
|
c.drawString((page_width - text_width) / 2, 2900, university)
|
||||||
|
|
||||||
|
y = 2500
|
||||||
|
|
||||||
|
for x in range(0, 7):
|
||||||
|
c.setFont('Arial', 40)
|
||||||
|
c.drawString(start, y, categories[x])
|
||||||
|
c.drawString(start_2, y, str(data[x]))
|
||||||
|
y -= spread
|
||||||
|
|
||||||
|
c.save()
|
||||||
|
|
||||||
|
|
||||||
|
def merge_data():
|
||||||
|
files_dir = 'pytopdf'
|
||||||
|
pdf_files = [f for f in os.listdir(files_dir) if f.endswith('.pdf')]
|
||||||
|
merger = PdfFileMerger()
|
||||||
|
for filename in pdf_files:
|
||||||
|
merger.append(PdfFileReader(os.path.join(files_dir, filename, 'rb')))
|
||||||
|
merger.write(os.path.join(files_dir, 'merged_data.pdf'))
|
||||||
|
|
||||||
|
|
||||||
|
create_data()
|
||||||
|
merge_data()
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,10 @@
|
||||||
|
import http.client, urllib
|
||||||
|
|
||||||
|
conn = http.client.HTTPSConnection("api.pushover.net:443")
|
||||||
|
conn.request("POST", "/1/messages.json",
|
||||||
|
urllib.parse.urlencode({
|
||||||
|
"token": "avzcexyjeu7y71pcskwshyx8ytmq8i",
|
||||||
|
"user": "uo2sf2pmrtjvt8auu786fviabimimr",
|
||||||
|
"message": "Reporting was running!",
|
||||||
|
}), { "Content-type": "application/x-www-form-urlencoded" })
|
||||||
|
conn.getresponse()
|
||||||
Loading…
Reference in New Issue