Example #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()
Example #2
0
def cli(ctx, dname):
    """
    Disable installations 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

    sites = domain.sites
    for site in sites:
        if site.enabled:
            click.secho('Disabling site {sn}'.format(sn=site.name), bold=True)
            site.disable()

    # 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()
Example #3
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()
Example #4
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)
Example #5
0
def delete_single(site, domain, delete_code=False, no_prompt=False):
    """
    Delete a single site
    @type   site:           Site
    @type   domain:         Domain
    @type   delete_code:    bool
    @type   no_prompt:      bool
    """
    click.secho('Deleting installation "{sn}" hosted on the domain {dn}'.format(sn=site.name, dn=domain.name),
                fg='yellow', bold=True)
    if not no_prompt:
        if delete_code:
            warn_text = click.style('WARNING! THIS WILL PERMANENTLY DELETE THIS SITE AND ALL OF THE ASSOCIATED '
                                    'PROJECT CODE FILES!\nTHIS MEANS ALL DATA FILES, INCLUDING ANY CREATED CUSTOM '
                                    'APPLICATIONS AND PLUGINS WILL BE PERMANENTLY AND IRREVOCABLY ERASED!',
                                    fg='red', bold=True)
            click.echo(warn_text)
            prompt_text = click.style('In order to continue, please re-input the site name', fg='white', bold=True)
            prompt = click.prompt(prompt_text)

            # If our prompt doesn't match, abort
            if prompt != site.name:
                click.secho('Site name did not match, site will not be deleted. Aborting.', fg='red', bold=True)
                raise click.Abort('Site name prompt did not match')

        else:
            prompt_text = click.style('Are you sure you want to delete this site entry? Your project files will '
                                      'still be preserved.', fg='white', bold=True)
            click.confirm(prompt_text, abort=True)

    site.delete()

    if delete_code:
        _remove_code(site)

    # If this is the only site left in the domain, remove the domain now as well
    domain_sites = [ds for ds in domain.sites if ds.id != site.id]
    if not len(domain_sites):
        Session.delete(domain)

    Session.commit()
    click.secho('{sn} removed'.format(sn=site.name), fg='yellow', bold=True)

    # Restart Nginx
    FNULL = open(os.devnull, 'w')
    subprocess.check_call(['service', 'nginx', 'restart'], stdout=FNULL, stderr=subprocess.STDOUT)
Example #6
0
def delete_all(domain, delete_code=False, no_prompt=False):
    """
    Delete all sites under a domain
    @type   domain:         Domain
    @type   delete_code:    bool
    @type   no_prompt:      bool
    """
    click.secho('All of the following installations hosted on the domain {dn} will be deleted:'
                .format(dn=domain.name), fg='yellow', bold=True)

    sites = domain.sites
    for site in sites:
        click.secho('{sn} ({v})'.format(sn=site.name, v=site.version), fg='red', bold=True)
    click.secho('------', fg='white', bold=True)
    click.echo()

    if not no_prompt:
        if delete_code:
            warn_text = click.style('WARNING! THIS WILL PERMANENTLY DELETE ALL OF THE ABOVE SITES AND ALL OF THEIR '
                                    'PROJECT CODE FILES!\nTHIS MEANS ALL DATA FILES, INCLUDING ANY CREATED CUSTOM '
                                    'APPLICATIONS AND PLUGINS, WILL BE PERMANENTLY AND IRREVOCABLY ERASED!',
                                    fg='red', bold=True)
            click.echo(warn_text)
            prompt_text = click.style('In order to continue, please re-input the domain name', fg='white', bold=True)
            prompt = click.prompt(prompt_text)

            # If our prompt doesn't match, abort
            if prompt != domain.name:
                click.secho('Domain name did not match, domain will not be deleted. Aborting.', fg='red', bold=True)
                raise click.Abort('Domain name prompt did not match')

        else:
            prompt_text = click.style('Are you sure you want to delete this domain and all its associated sites? '
                                      'Your project files will still be preserved.', fg='white', bold=True)
            click.confirm(prompt_text, abort=True)

    for site in sites:
        Session.delete(site)
        if delete_code:
            _remove_code(site)
        click.secho('{sn} removed'.format(sn=site.name), fg='yellow', bold=True)

    Session.delete(domain)
    Session.commit()

    # Restart Nginx
    FNULL = open(os.devnull, 'w')
    subprocess.check_call(['service', 'nginx', 'restart'], stdout=FNULL, stderr=subprocess.STDOUT)
Example #7
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))
Example #8
0
def cli(ctx, dname):
    """
    Disable installations 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

    sites = domain.sites
    for site in sites:
        if site.enabled:
            click.secho('Disabling site {sn}'.format(sn=site.name), bold=True)
            site.disable()

    # 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()
Example #9
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)
    )
Example #10
0
def delete_single(site, domain, delete_code=False, no_prompt=False):
    """
    Delete a single site
    @type   site:           Site
    @type   domain:         Domain
    @type   delete_code:    bool
    @type   no_prompt:      bool
    """
    click.secho(
        'Deleting installation "{sn}" hosted on the domain {dn}'.format(
            sn=site.name, dn=domain.name),
        fg='yellow',
        bold=True)
    if not no_prompt:
        if delete_code:
            warn_text = click.style(
                'WARNING! THIS WILL PERMANENTLY DELETE THIS SITE AND ALL OF THE ASSOCIATED '
                'PROJECT CODE FILES!\nTHIS MEANS ALL DATA FILES, INCLUDING ANY CREATED CUSTOM '
                'APPLICATIONS AND PLUGINS WILL BE PERMANENTLY AND IRREVOCABLY ERASED!',
                fg='red',
                bold=True)
            click.echo(warn_text)
            prompt_text = click.style(
                'In order to continue, please re-input the site name',
                fg='white',
                bold=True)
            prompt = click.prompt(prompt_text)

            # If our prompt doesn't match, abort
            if prompt != site.name:
                click.secho(
                    'Site name did not match, site will not be deleted. Aborting.',
                    fg='red',
                    bold=True)
                raise click.Abort('Site name prompt did not match')

        else:
            prompt_text = click.style(
                'Are you sure you want to delete this site entry? Your project files will '
                'still be preserved.',
                fg='white',
                bold=True)
            click.confirm(prompt_text, abort=True)

    site.delete()

    if delete_code:
        _remove_code(site)

    # If this is the only site left in the domain, remove the domain now as well
    domain_sites = [ds for ds in domain.sites if ds.id != site.id]
    if not len(domain_sites):
        Session.delete(domain)

    Session.commit()
    click.secho('{sn} removed'.format(sn=site.name), fg='yellow', bold=True)

    # Restart Nginx
    FNULL = open(os.devnull, 'w')
    subprocess.check_call(['service', 'nginx', 'restart'],
                          stdout=FNULL,
                          stderr=subprocess.STDOUT)
Example #11
0
def delete_all(domain, delete_code=False, no_prompt=False):
    """
    Delete all sites under a domain
    @type   domain:         Domain
    @type   delete_code:    bool
    @type   no_prompt:      bool
    """
    click.secho(
        'All of the following installations hosted on the domain {dn} will be deleted:'
        .format(dn=domain.name),
        fg='yellow',
        bold=True)

    sites = domain.sites
    for site in sites:
        click.secho('{sn} ({v})'.format(sn=site.name, v=site.version),
                    fg='red',
                    bold=True)
    click.secho('------', fg='white', bold=True)
    click.echo()

    if not no_prompt:
        if delete_code:
            warn_text = click.style(
                'WARNING! THIS WILL PERMANENTLY DELETE ALL OF THE ABOVE SITES AND ALL OF THEIR '
                'PROJECT CODE FILES!\nTHIS MEANS ALL DATA FILES, INCLUDING ANY CREATED CUSTOM '
                'APPLICATIONS AND PLUGINS, WILL BE PERMANENTLY AND IRREVOCABLY ERASED!',
                fg='red',
                bold=True)
            click.echo(warn_text)
            prompt_text = click.style(
                'In order to continue, please re-input the domain name',
                fg='white',
                bold=True)
            prompt = click.prompt(prompt_text)

            # If our prompt doesn't match, abort
            if prompt != domain.name:
                click.secho(
                    'Domain name did not match, domain will not be deleted. Aborting.',
                    fg='red',
                    bold=True)
                raise click.Abort('Domain name prompt did not match')

        else:
            prompt_text = click.style(
                'Are you sure you want to delete this domain and all its associated sites? '
                'Your project files will still be preserved.',
                fg='white',
                bold=True)
            click.confirm(prompt_text, abort=True)

    for site in sites:
        Session.delete(site)
        if delete_code:
            _remove_code(site)
        click.secho('{sn} removed'.format(sn=site.name),
                    fg='yellow',
                    bold=True)

    Session.delete(domain)
    Session.commit()

    # Restart Nginx
    FNULL = open(os.devnull, 'w')
    subprocess.check_call(['service', 'nginx', 'restart'],
                          stdout=FNULL,
                          stderr=subprocess.STDOUT)
Example #12
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)