Esempio n. 1
0
 def deactivate(self):
     LoggerGui.debug("FrameTab deactivate called")
     self.status_message["text"] = ""
     self.getting_psk = False
     if self.wpa_supplicant:
         self.wpa_supplicant.stop()
         self.wpa_supplicant = None
Esempio n. 2
0
 def __init__(self):
     """
     Main Gui Entrance
     """
     tkinter.Tk.report_callback_exception = self.throw
     # Main window
     self.destroyed = False
     LoggerGui.info("Initializing GUI")
     self.main_window = tkinter.Tk()
     self.main_window.wm_title("DRC Sim Server")
     icon = tkinter.PhotoImage(data=Resource("image/icon.gif").resource)
     self.main_window.tk.call("wm", "iconphoto", self.main_window, icon)
     self.main_window.protocol("WM_DELETE_WINDOW", self.on_closing)
     self.main_window.resizable(False, False)
     # Notebook
     self.tab_id = None
     self.notebook = Notebook(self.main_window, width=600, height=300)
     self.notebook.grid(column=0, row=0)
     self.notebook.bind("<<NotebookTabChanged>>", self.on_tab_changed)
     # Run Server Frame
     self.frame_run_server = FrameRunServer(self.notebook)
     self.notebook.add(self.frame_run_server, text="Run Server")
     # Get Key Frame
     self.frame_get_key = FrameGetKey(self.notebook)
     self.notebook.add(self.frame_get_key, text="Get Key")
     # Log Frame
     self.frame_log = FrameLog(self.notebook)
     self.notebook.add(self.frame_log, text="Log")
     # About Frame
     self.frame_about = FrameAbout(self.notebook)
     self.notebook.add(self.frame_about, text="About")
Esempio n. 3
0
 def deactivate(self):
     """
     De-initializes the frame.
     :return: None
     """
     LoggerGui.debug("FrameRunServer deactivated")
     self.stop_server()
Esempio n. 4
0
 def get_psk(self, code, interface):
     LoggerGui.debug("Attempting to get PSK")  # Don't log code
     CliMain.create_temp_config_file()
     self.wpa_supplicant = WpaSupplicant()
     self.wpa_supplicant.add_status_change_listener(self.wpa_status_changed)
     self.wpa_supplicant.get_psk(constants.PATH_CONF_CONNECT_TMP, interface,
                                 code)
Esempio n. 5
0
 def activate(self):
     LoggerGui.debug("FrameTab activate called")
     self.getting_psk = False
     self.set_code_text("")
     if not self.wpa_supplicant or not self.wpa_supplicant.get_status():
         self.status_message["text"] = ""
     self.dropdown_wii_u[
         "values"] = InterfaceUtil.get_wiiu_compatible_interfaces()
Esempio n. 6
0
 def throw(*args):
     """
     Throw exceptions from Tkinter
     :param args: arguments
     :return: None
     """
     for arg in args:
         if isinstance(arg, Exception):
             LoggerGui.throw(arg)
Esempio n. 7
0
 def start(self):
     """
     Start the main window loop
     :return:
     """
     LoggerGui.info("Opening GUI")
     self.after()
     self.main_window.mainloop()
     LoggerGui.info("GUI Closed")
Esempio n. 8
0
 def backend_status_changed(self, status):
     """
     Handles backend status changes.
     :param status: status message
     :return: None
     """
     LoggerGui.debug("Backend status changed to %s", status)
     self.label_backend_status.config(text=status)
     if status == DrcSimC.STOPPED:
         self.stop_server()
Esempio n. 9
0
 def on_closing(self):
     """
     Close the main window and current tab
     :return: None
     """
     if self.destroyed:
         return
     self.destroyed = True
     LoggerGui.info("Closing GUI")
     if self.tab_id in self.notebook.children:
         self.notebook.children[self.tab_id].deactivate()
     try:
         self.main_window.destroy()
     except Exception as e:
         LoggerGui.exception(e)
Esempio n. 10
0
 def activate(self):
     """
     Initializes the frame.
     :return: None
     """
     LoggerGui.debug("FrameRunServer activated")
     self.dropdown_wiiu_interface[
         "values"] = InterfaceUtil.get_wiiu_compatible_interfaces()
     self.dropdown_normal_interface[
         "values"] = InterfaceUtil.get_all_interfaces()
     self.dropdown_region["values"] = ["NONE", "NA"]
     self.label_wpa_status["text"] = self.wpa_supplicant.get_status() \
         if self.wpa_supplicant and self.wpa_supplicant.get_status() else WpaSupplicant.DISCONNECTED
     self.label_backend_status["text"] = self.drc_sim_c.get_status() \
         if self.drc_sim_c and self.drc_sim_c.get_status() else DrcSimC.STOPPED
     self.button_start.config(state="normal")
     self.button_stop.config(state="normal")
     self.label_interface_info.config(text="")
Esempio n. 11
0
 def on_tab_changed(self, event):
     """
     Close the previous tab and initialize a new one
     :param event: tab event
     :return: None
     """
     tab_id = self.notebook.select()
     tab_index = self.notebook.index(tab_id)
     tab_name = self.notebook.tab(tab_index, "text")
     LoggerGui.debug("Notebook tab changed to \"%s\" with id %d", tab_name,
                     tab_index)
     self.tab_id = tab_id.split(".")[len(
         tab_id.split(".")) - 1]  # Parse notebook/tab id to only tab id
     if self.notebook.children[self.tab_id].kill_other_tabs():
         for tab in self.notebook.children:
             if tab != self.tab_id:
                 self.notebook.children[tab].deactivate()
     self.notebook.children[self.tab_id].activate()
Esempio n. 12
0
 def button_clicked(self, event):
     if self.getting_psk:
         messagebox.showerror("Running",
                              "A pairing attempt is already im progress.")
         return
     number = str(event.widget.number)
     LoggerGui.debug(
         "A suit button was clicked"
     )  # Don't log numbers as the code can be derived from that
     code = self.entry_pair_code.get()
     code += number
     self.set_code_text(code)
     wii_u_interface = self.dropdown_wii_u.get()
     if not wii_u_interface:
         messagebox.showerror("No Interface",
                              "An interface must be selected.")
         self.activate()
         return
     try:
         InterfaceUtil.get_mac(wii_u_interface)
     except ValueError:
         messagebox.showerror(
             "Interface Error",
             "The selected Interface is no longer available.")
         self.activate()
         return
     if InterfaceUtil.is_managed_by_network_manager(wii_u_interface):
         set_unmanaged = messagebox.askokcancel(
             "Managed Interface",
             "This interface is managed by Network Manager. To use it with DRC Sim it needs "
             "to be set to unmanaged. Network Manager will not be able to control the interface"
             " after this.\nSet %s to unmanaged?" % wii_u_interface)
         if set_unmanaged:
             InterfaceUtil.set_unmanaged_by_network_manager(wii_u_interface)
         else:
             messagebox.showerror(
                 "Managed Interface",
                 "Selected Wii U interface is managed by Network Manager.")
             self.activate()
             return
     if len(code) == 4:
         self.getting_psk = True
         self.set_code_text("")
         self.get_psk(code, wii_u_interface)
Esempio n. 13
0
 def __init__(self, master=None, **kw):
     """
     GUI tab that handles interface and region selection and starting the server.
     :param master: root window
     :param kw: args
     """
     FrameTab.__init__(self, master, **kw)
     self.wii_u_interface = None
     self.normal_interface = None
     self.drc_sim_c = None
     self.wpa_supplicant = None
     LoggerGui.extra("Initializing FrameRunServer")
     # Create Widgets
     self.label_wpa = Label(self, text="Wii U Connection:")
     self.label_backend = Label(self, text="Server Status:")
     self.label_wpa_status = Label(self)
     self.label_backend_status = Label(self)
     self.button_start = Button(self, text="Start")
     self.button_stop = Button(self, text="Stop")
     self.label_wiiu_interface = Label(self, text="Wii U Interface")
     self.label_normal_interface = Label(self, text="Normal Interface")
     self.dropdown_wiiu_interface = Combobox(self, state="readonly")
     self.dropdown_normal_interface = Combobox(self, state="readonly")
     self.label_interface_info = Label(self)
     self.label_region = Label(self, text="Region")
     self.dropdown_region = Combobox(self, state="readonly")
     # Events
     self.button_start.bind("<Button-1>", self.start_server)
     self.button_stop.bind("<Button-1>", self.stop_server)
     # Position widgets
     self.label_wpa.grid(column=0, row=0, sticky="e")
     self.label_backend.grid(column=0, row=1, sticky="e")
     self.label_wpa_status.grid(column=1, row=0, sticky="w")
     self.label_backend_status.grid(column=1, row=1, sticky="w")
     self.label_wiiu_interface.grid(column=0, row=2)
     self.label_normal_interface.grid(column=0, row=3)
     self.dropdown_wiiu_interface.grid(column=1, row=2, columnspan=2)
     self.dropdown_normal_interface.grid(column=1, row=3, columnspan=2)
     self.label_region.grid(column=0, row=4)
     self.dropdown_region.grid(column=1, row=4, columnspan=2)
     self.button_start.grid(column=1, row=5)
     self.button_stop.grid(column=2, row=5)
     self.label_interface_info.grid(column=0, row=6, columnspan=3)
     LoggerGui.extra("Initialized FrameRunServer")
Esempio n. 14
0
 def wpa_status_changed(self, status):
     """
     Handles wpa status changes. Initializes backend server if a connection is made.
     :param status: status message
     :return: None
     """
     LoggerGui.debug("Wpa changed status to %s", status)
     self.label_wpa_status.config(text=status)
     if status == WpaSupplicant.CONNECTED:
         LoggerGui.debug("Routing")
         InterfaceUtil.dhclient(self.wii_u_interface)
         InterfaceUtil.set_metric(self.normal_interface, 0)
         InterfaceUtil.set_metric(self.wii_u_interface, 1)
         LoggerGui.debug("Starting backend")
         self.drc_sim_c = DrcSimC()
         self.drc_sim_c.add_status_change_listener(
             self.backend_status_changed)
         self.drc_sim_c.set_region(self.dropdown_region.get())
         self.drc_sim_c.start()
         self.label_interface_info.config(
             text="Server IP: " +
             InterfaceUtil.get_ip(self.normal_interface) + "\n" +
             os.uname()[1])
     elif status in (WpaSupplicant.DISCONNECTED, WpaSupplicant.TERMINATED):
         self.stop_server()
     elif status == WpaSupplicant.NOT_FOUND:
         self.stop_server()
         messagebox.showerror("Scan Error", "No Wii U found.")
     elif status == WpaSupplicant.FAILED_START:
         self.stop_server()
         messagebox.showerror(
             "Cannot Connect",
             "Failed to start wpa_supplicant_drc. This could mean there is a "
             "configuration error or wpa_supplicant_drc is not installed. "
             "Check %s for details." % constants.PATH_LOG_WPA)
Esempio n. 15
0
 def stop_server(self, event=None):
     """
     Stops active threads.
     :param event: Determines if this is a user initiated stop
     :return: None
     """
     if event:
         LoggerGui.debug("User clicked stop server button")
     LoggerGui.debug("Stop server called")
     if event and (self.label_wpa_status["text"]
                   in (WpaSupplicant.DISCONNECTED, WpaSupplicant.TERMINATED)
                   and self.label_backend_status["text"]
                   == DrcSimC.STOPPED):
         messagebox.showerror("Stop", "Server is not running.")
         return
     if self.drc_sim_c:
         self.drc_sim_c.stop()
         self.drc_sim_c = None
     if self.wpa_supplicant:
         self.wpa_supplicant.stop()
         self.wpa_supplicant = None
     self.activate()
Esempio n. 16
0
 def wpa_status_changed(self, status):
     LoggerGui.debug("Wpa status changed to %s", status)
     if status == WpaSupplicant.NOT_FOUND:
         self.deactivate()
         self.activate()
         messagebox.showerror("Scan", "No Wii U found.")
     elif status == WpaSupplicant.TERMINATED:
         self.deactivate()
         self.activate()
         messagebox.showerror(
             "Auth Fail", "Could not authenticate. Check the entered PIN.")
     elif status == WpaSupplicant.FAILED_START:
         self.deactivate()
         self.activate()
         messagebox.showerror("Error", "An unexpected error occurred.")
     elif status == WpaSupplicant.DISCONNECTED:
         self.deactivate()
         self.activate()
         messagebox.showerror("Auth Saved",
                              "Successfully paired with Wii U.")
     elif status == WpaSupplicant.SCANNING:
         self.status_message["text"] = "Scanning"
     elif status == WpaSupplicant.CONNECTING:
         self.status_message["text"] = "Connecting"
Esempio n. 17
0
 def start_server(self, event=None):
     """
     Try to start wpa_supplicant and connect to a Wii U.
     :param event: Determines if this was a user initiated start.
     :return: None
     """
     if event:
         LoggerGui.debug("User clicked start server button")
     LoggerGui.debug("Start server called")
     if self.label_backend_status["text"] != DrcSimC.STOPPED and \
             (self.label_wpa_status["text"] not in (WpaSupplicant.DISCONNECTED, WpaSupplicant.TERMINATED)):
         messagebox.showerror("Running", "Server is already running")
         return
     if not os.path.exists(constants.PATH_CONF_CONNECT):
         messagebox.showerror(
             "Auth Error",
             "No auth details found. Use the \"Get Key\" tab to pair with a Wii U."
         )
         self.activate()
         return
     self.normal_interface = self.dropdown_normal_interface.get()
     self.wii_u_interface = self.dropdown_wiiu_interface.get()
     if not self.normal_interface or not self.wii_u_interface:
         messagebox.showerror("Interface Error",
                              "Two interfaces need to be selected.")
         self.activate()
         return
     if self.normal_interface == self.wii_u_interface:
         messagebox.showerror(
             "Interface Error",
             "The selected normal and Wii U interfaces must be different.")
         self.activate()
         return
     try:
         InterfaceUtil.get_mac(self.normal_interface)
         InterfaceUtil.get_mac(self.wii_u_interface)
     except ValueError:
         messagebox.showerror(
             "Interface Error",
             "The selected Interface is no longer available.")
         self.activate()
         return
     if InterfaceUtil.is_managed_by_network_manager(self.wii_u_interface):
         set_unmanaged = messagebox.askokcancel(
             "Managed Interface",
             "This interface is managed by Network Manager. To use it with DRC Sim it needs "
             "to be set to unmanaged. Network Manager will not be able to control the interface"
             " after this.\nSet %s to unmanaged?" % self.wii_u_interface)
         if set_unmanaged:
             InterfaceUtil.set_unmanaged_by_network_manager(
                 self.wii_u_interface)
         else:
             messagebox.showerror(
                 "Managed Interface",
                 "Selected Wii U interface is managed by Network Manager.")
             self.activate()
             return
     LoggerGui.debug("Starting wpa supplicant")
     self.wpa_supplicant = WpaSupplicant()
     self.wpa_supplicant.add_status_change_listener(self.wpa_status_changed)
     self.wpa_supplicant.connect(constants.PATH_CONF_CONNECT,
                                 self.wii_u_interface)
     self.label_backend_status.config(text="WAITING")