Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.3 kB
1
Indexable
Never
import requests
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('https://apis.m3.maas360.com/user-apis/user/1.0/search/30055783?authType=1&domain=%40momentumsolar.co%20m&includeAllUsers=0&includeCustomAttributes=0&match=0&pageNumber=1&pageSize=50', headers=headers, params=params)

        if response.status_code == 200:
            print("Debug: Received 200 OK response.")
            devices = response.json()
            self.devices_text.delete("1.0", "end")
            self.devices_text.insert("end", str(devices))
        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('https://api.manageengine.com/mdm/devices/lock', headers=headers, params=params)

            if response.status_code == 200:
                print(f"Debug: Successfully locked device {device_id}")
            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()