Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.5 kB
2
Indexable
Never
import requests
from tkinter import Tk, Label, Button, Entry, StringVar, Text, Scrollbar, W, E, N, S
class App:
    def __init__(self, master):
        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):
        email = self.email_entry.get()
        headers = {'Authorization': 'b95ce2ea-6b26-436a-9b91-eda13445335d-G3l20Kr'}
        params = {'email': email}
        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:
            devices = response.json()
            self.devices_text.delete("1.0", "end")
            self.devices_text.insert("end", str(devices))

    def lock_all_devices(self):
        headers = {'Authorization': 'Bearer YOUR_ACCESS_TOKEN'}

        # Assuming device_ids are stored in a list
        device_ids = []

        for device_id in device_ids:
            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"Locked device {device_id}")


if __name__ == "__main__":
    root = Tk()
    app = App(root)
    root.mainloop()