예제 #1
0
def cli(ctx, dname, site):
    """
    Enable the <site> under the specified <domain>
    """
    assert isinstance(ctx, Context)

    dname = domain_parse(dname).hostname
    domain = Session.query(Domain).filter(Domain.name == dname).first()
    if not domain:
        click.secho('No such domain: {dn}'.format(dn=dname),
                    fg='red',
                    bold=True,
                    err=True)
        return

    site_name = site
    site = Site.get(domain, site_name)
    if not site:
        click.secho('No such site: {site}'.format(site=site_name),
                    fg='red',
                    bold=True,
                    err=True)
        return

    p = Echo('Constructing paths and configuration files...')
    site.enable()
    p.done()

    # Restart Nginx
    p = Echo('Restarting web server...')
    FNULL = open(os.devnull, 'w')
    subprocess.check_call(['service', 'nginx', 'restart'],
                          stdout=FNULL,
                          stderr=subprocess.STDOUT)
    p.done()
예제 #2
0
def cli(ctx, dname, site):
    """
    Enable the <site> under the specified <domain>
    """
    assert isinstance(ctx, Context)

    dname = domain_parse(dname).hostname
    domain = Session.query(Domain).filter(Domain.name == dname).first()
    if not domain:
        click.secho('No such domain: {dn}'.format(dn=dname), fg='red', bold=True, err=True)
        return

    site_name = site
    site = Site.get(domain, site_name)
    if not site:
        click.secho('No such site: {site}'.format(site=site_name), fg='red', bold=True, err=True)
        return

    p = Echo('Constructing paths and configuration files...')
    site.enable()
    p.done()

    # Restart Nginx
    p = Echo('Restarting web server...')
    FNULL = open(os.devnull, 'w')
    subprocess.check_call(['service', 'nginx', 'restart'], stdout=FNULL, stderr=subprocess.STDOUT)
    p.done()
예제 #3
0
def cli(ctx, dname, site):
    """
    List all domains if no <domain> is provided. If <domain> is provided but <site> is not, lists all sites
    hosted under <domain>. If both <domain> and <site> are provided, lists information on the specified site.
    """
    assert isinstance(ctx, Context)

    if dname:
        dname = domain_parse(dname).hostname
        domain = Session.query(Domain).filter(Domain.name == dname).first()

        # No such domain
        if not domain:
            click.secho("No such domain: {dn}".format(dn=dname), fg="red", bold=True, err=True)
            return

    if site:
        site_name = site
        site = Site.get(domain, site)
        if not site:
            click.secho("No such site: {site}".format(site=site_name), fg="red", bold=True, err=True)
            return

        click.secho("Name: {n}".format(n=site.name), bold=True)
        click.secho("Domain: {dn}".format(dn=site.domain.name), bold=True)
        click.secho("Version: {v}".format(v=site.version), bold=True)
        click.secho("License Key: {lk}".format(lk=site.license_key), bold=True)
        click.secho("Status: {s}".format(s=styled_status(site.enabled)), bold=True)
        click.secho("IN_DEV: {id}".format(id=styled_status(site.in_dev)), bold=True)
        click.secho("SSL: {s}".format(s=styled_status(site.ssl)), bold=True)
        click.secho("SPDY: {s}".format(s=styled_status(site.spdy)), bold=True)
        click.secho("GZIP: {g}".format(g=styled_status(site.gzip)), bold=True)
        return

    # Print sites
    if dname:
        # Get sites
        sites = Site.all(domain)
        if not sites:
            click.secho("No sites active under domain: {dn}".format(dn=dname), fg="red", bold=True, err=True)
            return

        # Display site data
        for site in sites:
            prefix = "[DEV] " if site.in_dev else ""
            fg = "green" if site.enabled else "white"
            click.secho("{pre}{name} ({ver})".format(pre=prefix, name=site.name, ver=site.version), fg=fg, bold=True)

        return

    # Print domains
    domains = Domain.all()
    for domain in domains:
        # Extra domains
        extras = ""
        if domain.extras:
            extras = " ({dnames})".format(dnames=str(domain.extras).replace(",", ", "))

        click.secho("{dname}{extras}".format(dname=domain.name, extras=extras), bold=True)
예제 #4
0
def cli(ctx, dname, site):
    """
    Launches a MySQL CLI session for the database of the specified IPS installation.
    """
    assert isinstance(ctx, Context)
    log = logging.getLogger('ipsv.mysql')

    dname = domain_parse(dname).hostname
    domain = Session.query(Domain).filter(Domain.name == dname).first()

    # No such domain
    if not domain:
        click.secho('No such domain: {dn}'.format(dn=dname),
                    fg='red',
                    bold=True,
                    err=True)
        return

    site_name = site
    site = Site.get(domain, site_name)

    # No such site
    if not site:
        click.secho('No such site: {site}'.format(site=site_name),
                    fg='red',
                    bold=True,
                    err=True)
        return

    # Connect to the MySQL database and exit
    log.info('Connecting to MySQL database: {db}'.format(db=site.db_name))
    log.debug('MySQL host: {host}'.format(host=site.db_host))
    log.debug('MySQL username: {user}'.format(user=site.db_user))
    log.debug('MySQL password: {pwd}'.format(pwd=site.db_pass))

    os.execl('/usr/bin/mysql', '/usr/bin/mysql',
             '--database={db}'.format(db=site.db_name),
             '--user={user}'.format(user=site.db_user),
             '--password={pwd}'.format(pwd=site.db_pass))
예제 #5
0
def cli(ctx, dname, site):
    """
    Launches a MySQL CLI session for the database of the specified IPS installation.
    """
    assert isinstance(ctx, Context)
    log = logging.getLogger('ipsv.mysql')

    dname = domain_parse(dname).hostname
    domain = Session.query(Domain).filter(Domain.name == dname).first()

    # No such domain
    if not domain:
        click.secho('No such domain: {dn}'.format(dn=dname), fg='red', bold=True, err=True)
        return

    site_name = site
    site = Site.get(domain, site_name)

    # No such site
    if not site:
        click.secho('No such site: {site}'.format(site=site_name), fg='red', bold=True, err=True)
        return

    # Connect to the MySQL database and exit
    log.info('Connecting to MySQL database: {db}'.format(db=site.db_name))
    log.debug('MySQL host: {host}'.format(host=site.db_host))
    log.debug('MySQL username: {user}'.format(user=site.db_user))
    log.debug('MySQL password: {pwd}'.format(pwd=site.db_pass))

    os.execl(
        '/usr/bin/mysql',
        '/usr/bin/mysql',
        '--database={db}'.format(db=site.db_name),
        '--user={user}'.format(user=site.db_user),
        '--password={pwd}'.format(pwd=site.db_pass)
    )
예제 #6
0
def cli(ctx, dname, site):
    """
    List all domains if no <domain> is provided. If <domain> is provided but <site> is not, lists all sites
    hosted under <domain>. If both <domain> and <site> are provided, lists information on the specified site.
    """
    assert isinstance(ctx, Context)

    if dname:
        dname = domain_parse(dname).hostname
        domain = Session.query(Domain).filter(Domain.name == dname).first()

        # No such domain
        if not domain:
            click.secho('No such domain: {dn}'.format(dn=dname), fg='red', bold=True, err=True)
            return

    if site:
        site_name = site
        site = Site.get(domain, site)
        if not site:
            click.secho('No such site: {site}'.format(site=site_name), fg='red', bold=True, err=True)
            return

        click.secho('Name: {n}'.format(n=site.name), bold=True)
        click.secho('Domain: {dn}'.format(dn=site.domain.name), bold=True)
        click.secho('Version: {v}'.format(v=site.version), bold=True)
        click.secho('License Key: {lk}'.format(lk=site.license_key), bold=True)
        click.secho('Status: {s}'.format(s=styled_status(site.enabled)), bold=True)
        click.secho('IN_DEV: {id}'.format(id=styled_status(site.in_dev)), bold=True)
        click.secho('SSL: {s}'.format(s=styled_status(site.ssl)), bold=True)
        click.secho('SPDY: {s}'.format(s=styled_status(site.spdy)), bold=True)
        click.secho('GZIP: {g}'.format(g=styled_status(site.gzip)), bold=True)
        click.secho('MySQL Database: {db}'.format(db=site.db_name), bold=True)
        click.secho('MySQL User: {u}'.format(u=site.db_user), bold=True)
        click.secho('MySQL Password: {u}'.format(u=site.db_pass), bold=True)
        return

    # Print sites
    if dname:
        # Get sites
        sites = Site.all(domain)
        if not sites:
            click.secho('No sites active under domain: {dn}'.format(dn=dname), fg='red', bold=True, err=True)
            return

        # Display site data
        for site in sites:
            prefix = '[DEV] ' if site.in_dev else ''
            fg = 'green' if site.enabled else 'white'
            click.secho('{pre}{name} ({ver})'.format(pre=prefix, name=site.name, ver=site.version), fg=fg, bold=True)

        return

    # Print domains
    domains = Domain.all()
    for domain in domains:
        # Extra domains
        extras = ''
        if domain.extras:
            extras = ' ({dnames})'.format(dnames=str(domain.extras).replace(',', ', '))

        click.secho('{dname}{extras}'.format(dname=domain.name, extras=extras), bold=True)