コード例 #1
0
ファイル: useradd.py プロジェクト: FujiMakoto/firefly-irc
def cli(ctx, email, password, group, nick, display_name, force):
    """
    Creates a new user account
    """
    assert isinstance(ctx, Context)

    # Make sure our configuration directory exists
    config_dir = os.path.join(FireflyIRC.CONFIG_DIR, 'config')
    if not os.path.exists(config_dir):
        os.makedirs(config_dir, 0o755)

    # Make sure the user doesn't already exist in our servers configuration
    users_config = FireflyIRC.load_configuration('users')
    users_cfg_path = os.path.join(config_dir, 'users.cfg')
    if email in users_config.sections():
        ctx.log.info('Configuration for %s already exists', email)
        if not force:
            raise click.ClickException('Configuration for {e} already exists'.format(e=email))
        users_config.remove_section(email)

    # Populate users.cfg
    users_config.add_section(email)
    users_config.set(email, 'Password', bcrypt.encrypt(password))
    users_config.set(email, 'Group', group)
    users_config.set(email, 'Nick', nick)
    users_config.set(email, 'DisplayName', display_name)

    # Write to our users configuration file
    with open(users_cfg_path, 'w') as cf:
        users_config.write(cf)

    click.secho('Configuration for user {e} successfully generated'.format(e=email), bold=True)
    click.secho('Users configuration path: {sp}'.format(sp=users_cfg_path), bold=True)
コード例 #2
0
ファイル: serverdel.py プロジェクト: FujiMakoto/firefly-irc
def cli(ctx, host, no_prompt):
    """
    Deletes an existing server from the configuration
    """
    assert isinstance(ctx, Context)

    # Make sure this host actually exists in our configuration
    servers_config = FireflyIRC.load_configuration('servers')
    server_cfg_path = os.path.join(FireflyIRC.CONFIG_DIR, 'config', 'servers.cfg')
    if host not in servers_config.sections():
        ctx.log.error('No configuration for %s exists', host)
        raise click.ClickException('No configuration for {h} exists'.format(h=host))

    # Confirm
    if not no_prompt:
        click.confirm('You are about to delete the IRC configuration files for {hn}\nAre you sure you want to do this?'
                      .format(hn=host), abort=True)

    # Remove the host from servers.cfg
    servers_config.remove_section(host)
    with open(server_cfg_path, 'w') as cf:
        servers_config.write(cf)

    # Remove the server configuration file if it exists
    hostname_fn = '{h}.cfg'.format(h=re.sub('\s', '_', host))
    host_cfg_path = os.path.join(FireflyIRC.CONFIG_DIR, 'config', 'servers', hostname_fn)
    if os.path.exists(host_cfg_path):
        os.remove(host_cfg_path)

    click.secho('{h} configuration files and server setting attributes removed'.format(h=host), bold=True)
コード例 #3
0
ファイル: start.py プロジェクト: FujiMakoto/firefly-irc
def cli(ctx):
    """
    Start Firefly
    """
    # Make sure we don't already have a PID stored
    if not os.path.exists(FireflyIRC.DATA_DIR):
        os.makedirs(FireflyIRC.DATA_DIR)

    pid_file = os.path.join(FireflyIRC.DATA_DIR, 'firefly.pid')
    if os.path.exists(pid_file):
        raise Exception('An instance of Firefly is already running. Even if you are sure this is not the case, please '
                        'run firefly stop and try again.')

    # Load our first server
    servers_config = FireflyIRC.load_configuration('servers')
    servers = []
    hostnames = servers_config.sections()
    for hostname in hostnames:
        if servers_config.getboolean(hostname, 'Enabled'):
            factory = FireflyFactory(Server(hostname, servers_config))
            servers.append(factory)
            reactor.connectTCP(factory.firefly.server.hostname, factory.firefly.server.port, factory)

    # Write our PID file
    with open(pid_file, "w") as f:
        f.write(str(os.getpid()))

    # Run
    try:
        reactor.run()
    except Exception:
        if os.path.exists(pid_file):
            os.remove(pid_file)
        raise

    if os.path.exists(pid_file):
        os.remove(pid_file)
コード例 #4
0
ファイル: userdel.py プロジェクト: FujiMakoto/firefly-irc
def cli(ctx, email, no_prompt):
    """
    Deletes a user account
    """
    assert isinstance(ctx, Context)

    # Make sure this user actually exists in our configuration
    users_config = FireflyIRC.load_configuration('users')
    users_cfg_path = os.path.join(FireflyIRC.CONFIG_DIR, 'config', 'users.cfg')
    if email not in users_config.sections():
        ctx.log.error('No configuration for %s exists', email)
        raise click.ClickException('No such user: {e}'.format(e=email))

    # Confirm
    if not no_prompt:
        click.confirm('You are about to delete the user account {e} ({n})\nAre you sure you want to do this?'
                      .format(e=email, n=users_config.get(email, 'Nick')), abort=True)

    # Remove the host from servers.cfg
    users_config.remove_section(email)
    with open(users_cfg_path, 'w') as cf:
        users_config.write(cf)

    click.secho('Deleted user account {e}'.format(e=email), bold=True)
コード例 #5
0
ファイル: serveradd.py プロジェクト: FujiMakoto/firefly-irc
def cli(ctx, host, port, auto, nick, username, realname, ssl, password, channels, force):
    """
    Generates a new server configuration file
    """
    assert isinstance(ctx, Context)

    # Make sure our configuration directory exists
    config_dir = os.path.join(FireflyIRC.CONFIG_DIR, 'config')
    if not os.path.exists(config_dir):
        os.makedirs(config_dir, 0o755)

    servers_dir = os.path.join(config_dir, 'servers')
    if not os.path.exists(servers_dir):
        os.makedirs(servers_dir, 0o755)

    # Make sure the server doesn't already exist in our servers configuration
    servers_config = FireflyIRC.load_configuration('servers')
    server_cfg_path = os.path.join(config_dir, 'servers.cfg')
    if host in servers_config.sections():
        ctx.log.info('Configuration for %s already exists', host)
        if not force:
            raise click.ClickException('Configuration for {h} already exists'.format(h=host))
        servers_config.remove_section(host)

    # Make sure a configuration file for this server doesn't already exist
    hostname_fn = re.sub('\s', '_', host)
    host_cfg_path = os.path.join(servers_dir, hostname_fn)

    if os.path.exists(host_cfg_path):
        ctx.log.info('Server configuration file %s already exists', hostname_fn)
        if not force:
            raise click.ClickException('Server configuration file {h_fn} already exists'.format(h_fn=host))

    # Populate servers.cfg
    servers_config.add_section(host)
    servers_config.set(host, 'Enabled', True)
    servers_config.set(host, 'Autoconnect', auto)
    servers_config.set(host, 'Nick', nick)
    servers_config.set(host, 'Username', username)
    servers_config.set(host, 'Realname', realname)
    servers_config.set(host, 'Password', password)
    servers_config.set(host, 'Port', port)
    servers_config.set(host, 'SSL', ssl)

    with open(server_cfg_path, 'w') as cf:
        servers_config.write(cf)

    # Create a server configuration file
    channels = [c.strip() for c in channels.split(',')] if channels else []

    host_config = ConfigParser()
    for channel in channels:
        host_config.add_section(channel)
        host_config.set(channel, 'Autojoin', True)
        host_config.set(channel, 'Password', '')

    with open(host_cfg_path, 'w') as cf:
        host_config.write(cf)

    click.secho('Configuration files for {h} successfully generated'.format(h=host), bold=True)
    click.secho('Server configuration path: {sp}'.format(sp=server_cfg_path), bold=True)
    click.secho('Channel configuration path: {cp}'.format(cp=host_cfg_path), bold=True)