ADD os.mkdir(C:Scripte) to create_service.py
This commit is contained in:
@@ -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)
|
||||
# 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)
|
||||
|
||||
Reference in New Issue
Block a user