Untitled
unknown
plain_text
2 years ago
3.8 kB
4
Indexable
import requests
import json
from tkinter import Tk, Label, Button, Entry, StringVar, Text, Scrollbar, W, E, N, S
class App:
def __init__(self, master):
print("Debug: Initializing the App class.")
self.master = master
master.title("ManageEngine MDM API Integration")
master.geometry("500x400")
master.configure(bg='lightgrey')
self.label = Label(master, text="Enter user's email:", bg='lightgrey')
self.label.grid(row=0, column=0, sticky=W)
self.email_entry = Entry(master)
self.email_entry.grid(row=0, column=1, sticky=W + E)
self.search_button = Button(master, text="Search Devices", command=self.search_devices, bg='blue', fg='white')
self.search_button.grid(row=0, column=2, sticky=E)
self.devices_text = Text(master, wrap="none", width=50, height=10)
self.devices_text.grid(row=1, column=0, columnspan=3, sticky=W + E + N + S)
self.scrollb = Scrollbar(master, orient="vertical", command=self.devices_text.yview)
self.scrollb.grid(row=1, column=3, sticky=N + S)
self.devices_text['yscrollcommand'] = self.scrollb.set
self.lock_button = Button(master, text="Lock All Devices", command=self.lock_all_devices, bg='red', fg='white')
self.lock_button.grid(row=2, column=1, sticky=E + W)
def search_devices(self):
print("Debug: search_devices method called.")
email = self.email_entry.get()
print(f"Debug: User entered email - {email}")
headers = {'Authorization': 'b95ce2ea-6b26-436a-9b91-eda13445335d-G3l20Kr'}
params = {'email': email}
print("Debug: Sending GET request.")
response = requests.get('YOUR_API_URL_HERE', headers=headers, params=params)
if response.status_code == 200:
print("Debug: Received 200 OK response.")
try:
devices = response.json()
except json.JSONDecodeError:
print("Debug: Failed to decode JSON. The response might be empty or not in JSON format.")
devices = {}
self.devices_text.delete("1.0", "end")
if devices:
self.devices_text.insert("end", str(devices))
else:
print("Debug: No devices returned.")
self.devices_text.insert("end", "No devices returned.")
elif response.status_code == 401:
print("Debug: Received 401 Unauthorized. Check the Authorization header and credentials.")
else:
print(f"Debug: Received a {response.status_code} response.")
def lock_all_devices(self):
print("Debug: lock_all_devices method called.")
headers = {'Authorization': 'Bearer YOUR_ACCESS_TOKEN'}
device_ids = [] # Assuming device_ids are stored in a list
for device_id in device_ids:
print(f"Debug: Attempting to lock device with ID {device_id}")
params = {'device_id': device_id}
response = requests.post('YOUR_API_URL_HERE', headers=headers, params=params)
if response.status_code == 200:
print(f"Debug: Successfully locked device {device_id}")
elif response.status_code == 401:
print("Debug: Received 401 Unauthorized. Check the Authorization header and credentials.")
else:
print(f"Debug: Failed to lock device {device_id}. Received a {response.status_code} response.")
if __name__ == "__main__":
print("Debug: Starting the application.")
root = Tk()
app = App(root)
print("Debug: Entered main loop.")
root.mainloop()
Editor is loading...