示例#1
0
    def add_outgoing_paths(self, id, paths):
        reqauth = self.config.get("settings", "require_auth") == "True"
        trustlocal = self.config.get("settings", "trust_local") == "True"
        gps_okay_ports = self.config.get("tweaks", "allow_gps").split(",")
        print("Repeater id is %s" % id)
        self.repeater = Repeater(id, reqauth, trustlocal, gps_okay_ports)
        for dev, param in paths:
            to = 0
            if dev.startswith("net:"):
                try:
                    net, host, port = dev.split(":", 2)
                    port = int(port)
                except Exception, e:
                    print("Invalid net string: %s (%s)" % (dev, e))
                    continue

                print("Socket %s %i (%s)" % (host, port, param))

                if param:
                    path = comm.SocketDataPath((host, port, id, param))
                else:
                    path = comm.SocketDataPath((host, port))
            elif dev.startswith("tnc:"):
                try:
                    tnc, port, device = dev.split(":", 2)
                    device = int(device)
                except Exception, e:
                    print("Invalid tnc string: %s (%s)" % (dev, e))
                    continue
示例#2
0
    def add_outgoing_paths(self, id, paths):
        reqauth = self.config.get("settings", "require_auth") == "True"
        trustlocal = self.config.get("settings", "trust_local") == "True"
        gps_okay_ports = self.config.get("tweaks", "allow_gps").split(",")
        printlog("Repeater  : Repeater id is %s" % id)
        self.repeater = Repeater(id, reqauth, trustlocal, gps_okay_ports)
        for dev, param in paths:
            to = 0
            if dev.startswith("net:"):
                try:
                    net, host, port = dev.split(":", 2)
                    port = int(port)
                except Exception as e:
                    printlog(("Invalid net string: %s (%s)" % (dev, e)))
                    continue

                printlog("Repeater  : Socket %s %i (%s)" % (host, port, param))

                if param:
                    path = comm.SocketDataPath((host, port, id, param))
                else:
                    path = comm.SocketDataPath((host, port))
            elif dev.startswith("tnc:"):
                try:
                    tnc, port, device = dev.split(":", 2)
                    device = int(device)
                except Exception as e:
                    printlog("Repeater  : Invalid tnc string: %s (%s)" %
                             (dev, e))
                    continue
                printlog("Repeater  : TNC %s %i" %
                         (dev.replace("tnc:", ""), int(param)))
                path = comm.TNCDataPath((dev.replace("tnc:", ""), int(param)))
            else:
                printlog("Repeater  : Serial: %s %i" % (dev, int(param)))
                path = comm.SerialDataPath((dev, int(param)))
                to = 3

            path.connect()
            tport = transport.Transporter(path, warmup_timout=to, name=dev)
            self.repeater.add_new_transport(tport)
示例#3
0
    def accept_new(self):
        if not self.socket:
            return

        try:
            (csocket, addr) = self.socket.accept()
        except:
            return

        printlog("Repeater  : Accepted new client %s:%i" % addr)

        path = comm.SocketDataPath(csocket)
        tport = transport.Transporter(path,
                                      authfn=self.auth_user,
                                      warmup_timeout=0)
        self.add_new_transport(tport)
示例#4
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