Example #1
0
    def edit_pkt(self, src, name, ctx):
        pkt = fidonet.PacketFactory(src)

        if self.opts.origin:
            pkt.origAddr = fidonet.Address(self.opts.origin)
            self.log.debug('set origAddr = %s' % pkt.origAddr)
        if self.opts.destination:
            pkt.destAddr = fidonet.Address(self.opts.destination)
            self.log.debug('set destAddr = %s' % pkt.destAddr)
        if self.opts.time:
            t = time.strptime(self.opts.time, '%Y-%m-%d %H:%M:%S')
            pkt.time = t
            self.log.debug('set time = %s' %
                           time.strftime('%Y-%m-%d %H:%M:%S', t))
        if self.opts.capword:
            pkt.capWord = int(self.opts.capword)
            self.log.debug('set capword = %d' % pkt.capWord)

        if name == '<stdin>':
            pkt.write(sys.stdout)
        else:
            src.seek(0)
            pkt.write(src)
            src.close()

        self.log.info('wrote edits to %s' % name)
Example #2
0
    def __unpack__(self):
        logging.debug('parsing a message')

        self['parsed_body'] = MessageBodyParser.unpack(self['body'])

        if 'INTL' in self.parsed_body.klines:
            intlDest, intlOrig = self.parsed_body.klines['INTL'][0].split()
            self.destAddr = fidonet.Address(intlDest)
            self.origAddr = fidonet.Address(intlOrig)

        # Make sure we have origZone/destZone keys, because we need these
        # for a diskmessage (and for various sorts of address manipulation)
        if not 'origZone' in self:
            self['origZone'] = 0
        if not 'destZone' in self:
            self['destZone'] = 0

        # Extract point information from control lines.
        if self.get('origPoint', 0) == 0:
            logging.debug('looking for FMPT')
            if 'FMPT' in self.parsed_body.klines:
                self['origPoint'] = self.parsed_body.klines['FMPT'][0]
                logging.debug('set origPoint = %(origPoint)s' % self)
            else:
                self['origPoint'] = 0
        if self.get('destPoint', 0) == 0:
            logging.debug('looking for TOPT')
            if 'TOPT' in self.parsed_body.klines:
                self['destPoint'] = self.parsed_body.klines['TOPT'][0]
                logging.debug('set destPoint = %(destPoint)s' % self)
            else:
                self['destPoint'] = 0
Example #3
0
    def handle_args(self, args):
        if self.opts.nodelist is None:
            nodelist = self.get_data_path('fidonet', 'nodelist')
            self.opts.nodelist = '%s.idx' % nodelist
            self.log.debug('using nodelist = %s' % self.opts.nodelist)

        if self.opts.routes is None:
            self.opts.routes = self.get_cfg_path('fidonet', 'routes')

        self.log.info('using nodelist %s' % self.opts.nodelist)
        if self.opts.routes:
            self.log.info('using routes from %s' % self.opts.routes)

        nl = Nodelist('sqlite:///%s' % self.opts.nodelist)
        nl.setup()
        session = nl.broker()

        router = Router(nl, self.opts.routes)

        nodes = session.query(Node).join('flags')

        if self.opts.output:
            sys.stdout = open(self.opts.output, 'w')

        for node in nodes:
            addr = fidonet.Address(node.address)
            rspec = router[addr]

            if not self.opts.quiet:
                print '# %s -> %s [%s]' % (addr, rspec[0], ' '.join(
                    [str(x) for x in rspec[1]]))
            print '%s\t%s:%s' % (addr.rfc, self.opts.transport, rspec[0].rfc)
Example #4
0
    def index_one_nodelist(self, session, nodelist):
        addr = fidonet.Address()
        hubs = []
        host = None

        self.log.info('indexing %s' % nodelist)

        for line in open(nodelist):
            if line.startswith(';'):
                continue

            node = fidonet.nodelist.Node()
            node.from_nodelist(line, addr)

            if node.node is None:
                continue

            if node.kw == 'hub':
                hubs.append(node)

            session.add(node)

        self.log.debug('committing changes')
        session.commit()

        self.log.debug('updating hub information')
        for hub in hubs:
            session.execute(
                Node.__table__.update(
                    and_(Node.net == hub.net, Node.node != hub.node,
                         Node.node != 0), dict(hub_id=hub.id)))

        self.log.debug('committing changes')
        session.commit()
Example #5
0
    def edit_msg(self, src, name, ctx):
        msg = fidonet.MessageFactory(src)

        if self.opts.to_name:
            self.log.debug('setting to = %s' % self.opts.to_name)
            msg.toUsername = self.opts.to_name
        if self.opts.from_name:
            self.log.debug('setting from = %s' % self.opts.from_name)
            msg.fromUsername = self.opts.from_name
        if self.opts.origin:
            addr = fidonet.Address(self.opts.origin)
            self.log.debug('setting origin = %s' % addr)
            msg.origAddr = addr
        if self.opts.destination:
            addr = fidonet.Address(self.opts.destination)
            self.log.debug('setting destination = %s' % addr)
            msg.destAddr = addr
        if self.opts.subject:
            self.log.debug('setting subject = %s' % self.opts.subject)
            msg.subject = self.opts.subject
        if self.opts.time:
            msg.dateTime = self.opts.time
            self.log.debug('set dateTime = %s' % msg.dateTime)

        for f in self.opts.flag:
            if f.startswith('!'):
                msg.attributeWord[f[1:]] = False
            else:
                msg.attributeWord[f] = True

        if self.opts.area:
            msg.body.area = self.opts.area

        for k in self.opts.kludge:
            k_name, k_val = k.split(' ', 1)
            msg.body.klines[k_name] = msg.body.klines.get(k_name, []) + [k_val]

        if self.opts.debug:
            import pprint
            pprint.pprint(msg, stream=sys.stderr)

        if name == '<stdin>':
            msg.write(sys.stdout)
        else:
            src.seek(0)
            msg.write(src)
            src.close()
Example #6
0
    def handle_args(self, args):
        outb = self.get('binkd', 'outbound')
        if outb is None:
            outb = '.'

        for addr in args:
            addr = fidonet.Address(addr)
            self.log.info('creating poll for %s.' % addr)
            poll = os.path.join(outb, '%s.%slo' % (addr.hex, self.opts.mode))
            self.log.debug('poll file = %s' % poll)
            open(poll, 'w').close()
Example #7
0
    def route(self, addr):
        addr = fidonet.Address(addr)
        host = fidonet.Address(addr, node=0)
        session = self.nodelist.broker()

        node = session.query(Node).filter(Node.address == addr.ftn).first()
        logging.debug('found node = %s' % node)

        rspec = self.lookup_route(addr, node)

        action = rspec[0]
        logging.debug('route spec gives action = %s' % repr(action))
        if action == 'direct':
            # no nodelists lookups required for direct routing.
            return (addr, rspec)
        elif action == 'route-to':
            # ...or for route-to, either.
            return (fidonet.Address(rspec[1]), rspec)

        # We could make this more efficient using the hub_id field
        # in the index, but then it wouldn't work for unknown nodes.
        hub = session.query(Node)\
                .filter(Node.zone==addr.zone)\
                .filter(Node.net==addr.net)\
                .filter(Node.kw=='hub').first()

        logging.debug('hub for %s = %s' % (addr, hub))
        logging.debug('host for %s = %s' % (addr, host))

        if action == 'no-route':
            if node is None or node.kw in ['pvt', 'hold']:
                if hub:
                    return (fidonet.Address(hub.address), rspec)
                else:
                    return (host, rspec)
            else:
                return (fidonet.Address(node.address), rspec)
        elif action == 'hub-route':
            if hub:
                return (fidonet.Address(hub.address), rspec)
            else:
                return (host, rspec)
        elif action == 'host-route':
            return (host, rspec)
        elif action == 'zone-route':
            zonegate = fidonet.Address(addr, net=addr.zone, node=0)
            return (zonegate, rspec)

        return (None, None)
Example #8
0
    def handle_args(self, args):
        if self.opts.nodelist is None:
            nodelist = list(self.get_data_paths('fidonet', 'nodelist'))[0]
            if not nodelist:
                self.log.error('unable to locate a nodelist index')
                sys.exit(1)

            self.opts.nodelist = '%s.idx' % nodelist
        if self.opts.routes is None:
            self.opts.routes = self.get_cfg_path('fidonet', 'routes')

        self.log.info('using nodelist %s' % self.opts.nodelist)
        if self.opts.routes:
            self.log.info('using routes from %s' % self.opts.routes)

        nl = Nodelist('sqlite:///%s' % self.opts.nodelist)
        nl.setup()
        router = Router(nl, self.opts.routes)

        for addr in args:
            addr = fidonet.Address(addr)
            rspec = router[addr]
            print addr, 'via', rspec[0], 'using', rspec[1]
Example #9
0
    def handle_args(self, args):
        if self.opts.zone is None:
            try:
                myaddr = fidonet.Address(self.cfg.get('fidonet', 'address'))
                self.opts.zone = myaddr.zone
            except:
                pass
        if args:
            src = open(args.pop(0))
        else:
            src = bitstring.ConstBitStream(bytes=sys.stdin.read())

        ftnmsg = fidonet.MessageFactory(src)
        rfcmsg = email.message.Message()

        origAddr = ftnmsg.origAddr
        destAddr = ftnmsg.destAddr

        origAddr.zone = self.opts.zone
        destAddr.zone = self.opts.zone

        rfcmsg['From'] = '@'.join(
            [ftnmsg.fromUsername.replace(' ', '_'), origAddr.rfc])
        rfcmsg['To'] = '@'.join(
            [ftnmsg.toUsername.replace(' ', '_'), destAddr.rfc])
        rfcmsg['Subject'] = ftnmsg.subject

        if ftnmsg.body.area is not None:
            rfcmsg['Newsgroups'] = ftnmsg.body.area

        for k in ftnmsg.body['klines'].keys():
            for v in ftnmsg.body['klines'][k]:
                rfcmsg['X-FTN-Kludge'] = '%s %s' % (k, v)

        rfcmsg.set_payload(ftnmsg.body.text)

        print rfcmsg.as_string()
Example #10
0
 def cmd_route_to(self, args):
     target = fidonet.Address(args.pop(0))
     return (('route-to', target), args)