Exemple #1
0
    def on_dccchat(self, connection: DCCConnection, event: _IRCEvent):
        if len(event.arguments) != 2:
            return

        args = event.arguments[1].split()
        if len(args) == 4:
            try:
                address = ip_numstr_to_quad(args[2])
                port = int(args[3])
            except ValueError:
                return

            nick = event.source.nick
            if not self._is_dcc_connection_request_allowed(address=address,
                                                           nick=nick):
                self.logger.info(
                    f'Refused DCC connection from address={address} nick={nick}'
                )
                connection.disconnect('Unauthorized peer')
                return

            self._post_event(connection,
                             IRCDCCRequestEvent,
                             address=address,
                             port=port,
                             nick=nick)

            self.dcc('chat').connect(address, port)
Exemple #2
0
 def on_dccchat(self, c, e):
     if len(e.arguments) != 2:
         return
     args = e.arguments[1].split()
     if len(args) == 4:
         try:
             address = ip_numstr_to_quad(args[2])
             port = int(args[3])
         except ValueError:
             return
         self.dcc_connect(address, port)
Exemple #3
0
 def on_dccchat(self, c, e):
     if len(e.arguments) != 2:
         return
     args = e.arguments[1].split()
     if len(args) == 4:
         try:
             address = ip_numstr_to_quad(args[2])
             port = int(args[3])
         except ValueError:
             return
         self.dcc_connect(address, port)
Exemple #4
0
    def on_dccchat(self, conn:ServerConnection, event:Event):
        """

        :param conn: ServerConnection
        :param event: Event
        :return:None
        """
        if len(event.arguments) != 2:
            return
        args = event.arguments[1].split()
        if len(args) == 4:
            try:
                address = ip_numstr_to_quad(args[2])
                port = int(args[3])
            except ValueError:
                return
            self.dcc_connect(address, port)
Exemple #5
0
 def on_dccchat(self, connection, event):
     """
     https://github.com/jaraco/irc/blob/1331ba85b5d093f06304d316a03a832959eaf4da/irc/bot.py#L347-L348
     """
     logger.debug(("handler called: on_dccchat...\n"
                   f"connection: {connection}\n"
                   f"event: {event}\n"))
     super(RasaIRCBot, self).on_dccchat(connection, event)
     logger.debug("completed: super on_dccchat...")
     logger.debug("doing RasaIRCBot.on_dccchat...")
     if len(event.arguments) != 2:
         return
     args = event.arguments[1].split()
     if len(args) == 4:
         try:
             address = ip_numstr_to_quad(args[2])
             port = int(args[3])
         except ValueError:
             return
         self.dcc_connect(address, port)
     logger.debug("compelted on_dccchat...")
Exemple #6
0
    def _accept_dcc_file_request(self, connection: DCCConnection,
                                 ctcp_msg: str, nick: str):
        ctcp_msg = [token.strip() for token in ctcp_msg.split(' ') if token]

        filename = ' '.join(ctcp_msg[2:-3])
        address, port, size = ctcp_msg[-3:]

        if not (filename and address and port):
            return

        address = ip_numstr_to_quad(address)
        port = int(port)
        size = int(size)

        if port == 0:
            self.logger.warning(
                'Passive CTCP file transfer is currently not supported')
            return

        self._post_event(connection,
                         IRCDCCFileRequestEvent,
                         address=address,
                         port=port,
                         file=filename,
                         size=size,
                         nick=nick)

        # Accept the file request
        # (if we're here then the peer is whitelisted/not blacklisted)
        self._dcc_recv_procs[(address, port)] = multiprocessing.Process(
            target=self._process_dcc_recv,
            kwargs={
                'connection': connection,
                'address': address,
                'port': port,
                'filename': filename,
                'size': size,
            })

        self._dcc_recv_procs[(address, port)].start()
Exemple #7
0
    def on_ctcp(self, conn: ServerConnection, event: Event):
        """
        The 'ctcp' event indicates that a CTCP message was received.
        The downloader receives a CTCP from the bot to initialize the
        XDCC file transfer.
        Handles DCC ACCEPT and SEND messages. Other DCC messages will result
        in a raised InvalidCTCP exception.
        DCC ACCEPT will only occur when a resume request was sent successfully.
        DCC SEND will occur when the bot offers a file.
        :param conn: The connection
        :param event: The 'ctcp' event
        :return: None
        :raise InvalidCTCPException: In case no valid DCC message was received
        """

        def start_download(append: bool = False):
            """
            Helper method that starts the download of an XDCC pack
            :param append: If set to True, opens the file in append mode
            :return: None
            """
            self.downloading = True
            self.xdcc_timestamp = time.time()
            mode = "ab" if append else "wb"
            self.logger.info("Starting Download (" + mode + ")")
            self.xdcc_file = open(self.pack.get_filepath(), mode)
            self.xdcc_connection = \
                self.dcc_connect(self.peer_address, self.peer_port, "raw")
            self.xdcc_connection.socket.settimeout(5)

        self.logger.info("CTCP Message: " + str(event.arguments))
        if event.arguments[0] == "DCC":
            payload = shlex.split(event.arguments[1])

            if payload[0] == "SEND":

                filename = payload[1]
                self.peer_address = ip_numstr_to_quad(payload[2])
                self.peer_port = int(payload[3])
                self.filesize = int(payload[4])

                self.pack.set_filename(filename)

                if os.path.isfile(self.pack.get_filepath()):

                    position = os.path.getsize(self.pack.get_filepath())

                    if position >= self.filesize:
                        raise AlreadyDownloadedException(self.pack.filename)

                    self.logger.info("Requesting Resume")
                    self.progress = position
                    bot = event.source.split("!")[0]
                    resume_param = "\"" + filename + "\" " + \
                                   str(self.peer_port) + " " + str(position)
                    conn.ctcp("DCC RESUME", bot, resume_param)

                else:
                    start_download()

            elif payload[0] == "ACCEPT":
                start_download(append=True)

            else:
                raise InvalidCTCPException(payload[0])