Beispiel #1
0
def main():
    global verbose, f, db, co, ldap, auth, start

    parser = argparse.ArgumentParser()
    parser.add_argument('-v', "--verbose", action="count", default=0)
    parser.add_argument('-m', "--mail-file")
    parser.add_argument('-s', "--spread", default=ldapconf('MAIL', 'spread', None))
    parser.add_argument('-i', "--ignore-size", dest="max_change", action="store_const", const=100)
    parser.add_argument('-a', "--no-auth-data", dest="auth", action="store_false", default=True)
    args = parser.parse_args()

    verbose = args.verbose
    auth = args.auth

    db = Factory.get('Database')()
    co = Factory.get('Constants')(db)

    start = now()
    curr = now()

    if verbose:
        logger.debug("Loading the EmailLDAP module...")
    ldap = Factory.get('EmailLDAP')(db)
    if verbose:
        logger.debug("  done in %d sec." % (now() - curr))

    spread = args.spread
    if spread is not None:
        spread = map_spreads(spread, int)

    f = ldif_outfile('MAIL', args.mail_file, max_change=args.max_change)
    get_data(spread)
    end_ldif_outfile('MAIL', f)
Beispiel #2
0
    def setup(self):
        self.zone = self.opts.zone and self.co.DnsZone(self.opts.zone)
        self.spreads = PosixData()
        for name in ('user', 'filegroup', 'netgroup', 'host_netgroup'):
            spread = getattr(self.opts, name + '_spread')
            spread = spread and spread.split(',')
            setattr(self.spreads, name, map_spreads(spread) or None)

        if self.opts.ldif: self.setup_ldif()
        if self.opts.passwd: self.setup_passwd()
        if self.opts.filegroup: self.setup_filegroup()
        if self.opts.netgroup_spread: self.setup_netgroup()
        if self.opts.zone: self.setup_host_netgroup()
Beispiel #3
0
    def setup(self):
        self.zone = self.opts.zone and self.co.DnsZone(self.opts.zone)
        self.spreads = PosixData()
        for name in ('user', 'filegroup', 'netgroup', 'host_netgroup'):
            spread = getattr(self.opts, name + '_spread')
            spread = spread and spread.split(',')
            setattr(self.spreads, name, map_spreads(spread) or None)

        if self.opts.ldif:          self.setup_ldif()
        if self.opts.passwd:        self.setup_passwd()
        if self.opts.filegroup:     self.setup_filegroup()
        if self.opts.netgroup_spread: self.setup_netgroup()
        if self.opts.zone:            self.setup_host_netgroup()
Beispiel #4
0
def main():
    global verbose, f, db, co, ldap, auth, start

    parser = argparse.ArgumentParser()
    parser.add_argument('-v', "--verbose", action="count", default=0)
    parser.add_argument('-m', "--mail-file")
    parser.add_argument('-s',
                        "--spread",
                        default=ldapconf('MAIL', 'spread', None))
    parser.add_argument('-i',
                        "--ignore-size",
                        dest="max_change",
                        action="store_const",
                        const=100)
    parser.add_argument('-a',
                        "--no-auth-data",
                        dest="auth",
                        action="store_false",
                        default=True)
    args = parser.parse_args()

    verbose = args.verbose
    auth = args.auth

    db = Factory.get('Database')()
    co = Factory.get('Constants')(db)

    start = now()
    curr = now()

    if verbose:
        logger.debug("Loading the EmailLDAP module...")
    ldap = Factory.get('EmailLDAP')(db)
    if verbose:
        logger.debug("  done in %d sec." % (now() - curr))

    spread = args.spread
    if spread is not None:
        spread = map_spreads(spread, int)

    f = ldif_outfile('MAIL', args.mail_file, max_change=args.max_change)
    get_data(spread)
    end_ldif_outfile('MAIL', f)
Beispiel #5
0
def main(inargs=None):
    parser = argparse.ArgumentParser(description='Generate a mail-db.ldif', )
    parser.add_argument(
        '-v',
        "--verbose",
        action="count",
        default=0,
        help=('Show some statistics while running. '
              'Repeat the option for more verbosity.'),
    )
    parser.add_argument(
        '-m',
        "--mail-file",
        help='Specify file to write to.',
    )
    parser.add_argument(
        '-s',
        "--spread",
        default=ldapconf('MAIL', 'spread', None),
        help='Targets printed found in spread.',
    )
    parser.add_argument(
        '-i',
        "--ignore-size",
        dest="max_change",
        action="store_const",
        const=100,
        help='Use file class instead of SimilarSizeWriter.',
    )
    parser.add_argument(
        '-a',
        "--no-auth-data",
        dest="auth",
        action="store_false",
        default=True,
        help="Don't populate userPassword.",
    )
    Cerebrum.logutils.options.install_subparser(parser)

    args = parser.parse_args(inargs)
    Cerebrum.logutils.autoconf('cronjob', args)

    logger.info('Start %s', parser.prog)
    logger.debug('args: %s', repr(args))

    db = Factory.get('Database')()

    start = now()

    with log_time('loading the EmailLDAP module'):
        ldap = Factory.get('EmailLDAP')(db)

    spread = args.spread
    if spread is not None:
        spread = map_spreads(spread, int)

    # Configure auth
    if args.auth:
        auth_attr = ldapconf('MAIL', 'auth_attr', None)
        user_password = AuthExporter.make_exporter(db,
                                                   auth_attr['userPassword'])
    else:
        user_password = None

    outfile = ldif_outfile('MAIL', args.mail_file, max_change=args.max_change)
    logger.debug('writing data to %s', repr(outfile))

    with log_time('fetching data', level=logging.INFO):
        get_data(db, ldap, getattr(user_password, 'cache', None), spread)

    with log_time('generating ldif', level=logging.INFO):
        write_ldif(db, ldap, user_password, outfile, verbose=args.verbose)

    end_ldif_outfile('MAIL', outfile)

    logger.info("Total time: %ds" % (now() - start))
    logger.info('Done %s', parser.prog)