示例#1
0
    def do_chat_from_mail(self, mail):
        if mail.is_multipart():
            body = None
            for part in mail.walk():
                html = None
                if part.get_content_type() == "text/plain":
                    body = part.get_payload(decode=True)
                    break
                elif part.get_content_type() == "text/html":
                    html = part.get_payload(decode=True)
            if not body:
                body = html
        else:
            body = mail.get_payload()

        text = "Message from %s (%s):\r\n%s" % (\
            mail.get("From", "Unknown Sender"),
            mail.get("Subject", ""),
            body)

        for port in self.emit("get-station-list").keys():
            self._emit("user-send-chat", "CQCQCQ", port, text, False)

        event = main_events.Event(None,
                                  "Mail received from %s and sent via chat" % \
                                      mail.get("From", "Unknown Sender"))
        self._emit("event", event)
示例#2
0
 def __station_status(self, object, sta, stat, msg, port):
     self.mainwindow.tabs["stations"].saw_station(sta, port, stat, msg)
     status = station_status.get_status_msgs()[stat]
     event = main_events.Event(
         None,
         "%s %s %s %s: %s" % (_("Station"), sta, _("is now"), status, msg))
     self.mainwindow.tabs["event"].event(event)
示例#3
0
 def run(self):
     if not self.config.getboolean("state", "connected_inet"):
         self.message("Not connected")
     else:
         mails = []
         try:
             mails = self.fetch_mails()
         except Exception, e:
             self.message("Failed to retrieve messages: %s" % e)
         for mail in mails:
             self.__action(mail)
         if mails:
             event = main_events.Event(None,
                                       "Received %i email(s)" % len(mails))
             self._emit("event", event)
示例#4
0
    def run(self):
        self.message("One-shot thread starting")
        mails = None

        if not self.config.getboolean("state", "connected_inet"):
            result = "Not connected to the Internet"
        else:
            try:
                mails = self.fetch_mails()
            except Exception, e:
                result = "Failed (%s)" % e

            if mails:
                for mail in mails:
                    self.create_form_from_mail(mail)
                event = main_events.Event(_("Received %i messages") % \
                                              len(mails))
                self._emit("event", event)

                result = "Queued %i messages" % len(mails)
            elif mails is not None:
                result = "No messages"
示例#5
0
            def sniff_event(ss, src, dst, msg, port):
                if dosniff:
                    event = main_events.Event(None, "Sniffer: %s" % msg)
                    self.mainwindow.tabs["event"].event(event)

                self.mainwindow.tabs["stations"].saw_station(src, port)
示例#6
0
 def transport_msg(msg):
     _port = name
     event = main_events.Event(None, "%s: %s" % (_port, msg))
     gobject.idle_add(self.mainwindow.tabs["event"].event, event)
示例#7
0
    def start_comms(self, portid):
        spec = self.config.get("ports", portid)
        try:
            enb, port, rate, dosniff, raw, name = spec.split(",")
            enb = (enb == "True")
            dosniff = (dosniff == "True")
            raw = (raw == "True")
        except Exception as e:
            print(f"Failed to parse portspec {spec}:")
            log_exception()
            return

        if not enb:
            if self.sm.has_key(name):
                del self.sm[name]
            return

        print(f"Starting port {portid} ({name})")

        call = self.config.get("user", "callsign")

        if self.__unused_pipes.has_key(port):
            path = self.__unused_pipes[port]
            del self.__unused_pipes[port]
            print(f"Re-using path {path} for port {port}")
        elif port.startswith("tnc-ax25:"):
            print(port)
            tnc, _port, tncport, path = port.split(":")
            path = path.replace(";", ",")
            _port = f"{_port}:{tncport}"
            path = comm.TNCAX25DataPath((_port, int(rate), call, path))
        elif port.startswith("tnc:"):
            _port = port.replace("tnc:", "")
            path = comm.TNCDataPath((_port, int(rate)))
        elif port.startswith("dongle:"):
            path = comm.SocketDataPath(("127.0.0.1", 20003, call, None))
        elif port.startswith("agwpe:"):
            path = comm.AGWDataPath(port, 0.5)
            print(f"Opening AGW: {path}")
        elif ":" in port:
            try:
                (mode, host, sport) = port.split(":")
            except ValueError:
                event = main_events.Event(None,
                                          _("Failed to connect to") + \
                                              " %s: " % port + \
                                              _("Invalid port string"))
                self.mainwindow.tabs["event"].event(event)
                return False

            path = comm.SocketDataPath((host, int(sport), call, rate))
        else:
            path = comm.SerialDataPath((port, int(rate)))

        if self.__pipes.has_key(name):
            raise Exception("Port %s already started!" % name)
        self.__pipes[name] = (port, path)

        def transport_msg(msg):
            _port = name
            event = main_events.Event(None, "%s: %s" % (_port, msg))
            gobject.idle_add(self.mainwindow.tabs["event"].event, event)

        transport_args = {
            "compat": raw,
            "warmup_length": self.config.getint("settings", "warmup_length"),
            "warmup_timeout": self.config.getint("settings", "warmup_timeout"),
            "force_delay": self.config.getint("settings", "force_delay"),
            "msg_fn": transport_msg,
        }

        if not self.sm.has_key(name):
            sm = sessionmgr.SessionManager(path, call, **transport_args)

            chat_session = sm.start_session("chat",
                                            dest="CQCQCQ",
                                            cls=chat.ChatSession)
            self.__connect_object(chat_session, name)

            rpcactions = rpc.RPCActionSet(self.config, name)
            self.__connect_object(rpcactions)

            rpc_session = sm.start_session("rpc",
                                           dest="CQCQCQ",
                                           cls=rpc.RPCSession,
                                           rpcactions=rpcactions)

            def sniff_event(ss, src, dst, msg, port):
                if dosniff:
                    event = main_events.Event(None, "Sniffer: %s" % msg)
                    self.mainwindow.tabs["event"].event(event)

                self.mainwindow.tabs["stations"].saw_station(src, port)

            ss = sm.start_session("Sniffer",
                                  dest="CQCQCQ",
                                  cls=sniff.SniffSession)
            sm.set_sniffer_session(ss._id)
            ss.connect("incoming_frame", sniff_event, name)

            sc = session_coordinator.SessionCoordinator(self.config, sm)
            self.__connect_object(sc, name)

            sm.register_session_cb(sc.session_cb, None)

            self._make_socket_listeners(sc)

            self.sm[name] = sm, sc

            pingdata = self.config.get("settings", "ping_info")
            if pingdata.startswith("!"):

                def pingfn():
                    return ping_exec(pingdata[1:])
            elif pingdata.startswith(">"):

                def pingfn():
                    return ping_file(pingdata[1:])
            elif pingdata:

                def pingfn():
                    return pingdata
            else:
                pingfn = None
            chat_session.set_ping_function(pingfn)

        else:
            sm, sc = self.sm[name]

            sm.set_comm(path, **transport_args)
            sm.set_call(call)

        return True