Example #1
0
def provision_site(user, site_type, site_name, template_id=""):
    # create site entry
    site = models.Site(user.id, site_type, site_name)
    site.last_accessed = datetime.now()
    models.Session.add(site)
    models.Session.flush()

    # create host
    hostname = "%s.%s" % (site_name, PLOUD.domain)
    host = models.Host(site.id, hostname.lower())
    models.Session.add(host)
    addVirtualHosts((str(hostname),), "plone41")
    POLICIES[user.type].changeHostsPolicy((hostname,), site_name)

    # Create the database.
    conn = ploud_config.CLIENTS_POOL.getconn()
    try:
        tmpl.create_site(conn, site.id, template_id=template_id, type=site_type)
    except NameError:
        tmpl.create_site(conn, site.id, type=site_type)
    conn.commit()
    ploud_config.CLIENTS_POOL.putconn(conn)
    transaction.commit()

    # change owner of new site
    if PLOUD.maintence is not None:
        PLOUD.maintence.execute(hostname, "ploud-fix-owner")

    return site
Example #2
0
def provision_site(user, site_type, site_name, template_id='', language='en'):
    # create site entry
    site = models.Site(user.id, site_type, site_name)
    site.last_accessed = datetime.now()
    Session = ptah.get_session()
    Session.add(site)
    Session.flush()

    # create host
    PLOUD = ptah.get_settings('ploud')

    hostname = '%s.%s'%(site_name, PLOUD['domain'])
    host = models.Host(site.id, hostname.lower())
    Session.add(host)
    addVirtualHosts((str(hostname),), 'plone41')
    POLICIES[user.type].changeHostsPolicy((hostname,), site_name)

    FE = ptah.get_settings('frontend')
    if FE['devmode']:
        transaction.commit()
        return site

    # Create the database.
    conn = ploud_config.CLIENTS_POOL.getconn()
    try:
        tmpl.create_site(conn, site.id, template_id=template_id, type=site_type)
    except NameError:
        tmpl.create_site(conn, site.id, type=site_type)
    conn.commit()
    ploud_config.CLIENTS_POOL.putconn(conn)
    transaction.commit()

    # change owner of new site
    if maintenance.maintence is not None:
        maintenance.maintence.execute(hostname, 'ploud-fix-owner,%s' % language)

    return site
Example #3
0
def addvhost(self):
    if not pol.vhosts:
        view.addMessage(
            request,
            "Virtual host is not available for your type "
            "of membership.")
        
        raise HTTPFound(location=urlmsg)

    hostname = request.str_GET['vhost'].strip().lower()
    if hostname.endswith('.%s'%PLOUD.domain):
        view.addMessage(
            request, "%s domain is not allowed."%PLOUD.domain)
        raise HTTPFound(location=urlmsg)

    conn = ploud_config.PLOUD_POOL.getconn()
    cursor = conn.cursor()

    cursor.execute(
        "SELECT host FROM vhost WHERE id = %s", (site.id,))
    sites = [row[0] for row in cursor.fetchall()]
    if sites:
        cursor.execute(
            "DELETE FROM vhost WHERE id = %s", (site.id,))
        removeVirtualHosts(sites)
            
    cursor.execute("INSERT INTO vhost(id, host) VALUES(%s, %s)",
                   (site_id, hostname))
    addVirtualHosts((hostname,), 'plone41')
    pol.changeHostsPolicy((hostname,), site_name)

    cursor.close()
    conn.commit()
    ploud_config.PLOUD_POOL.getconn(conn)
    view.addMessage(request, "Site now has new hostname.")
    raise HTTPFound(location=urlmsg)
Example #4
0
def addVirtualHost(site, hostname):
    host = Host(site.id, hostname.lower())
    Session.add(host)
    addVirtualHosts((str(hostname),), 'plone41')
Example #5
0
def addVirtualHost(site, hostname):
    host = Host(site.id, hostname.lower())
    ptah.get_session().add(host)
    addVirtualHosts((str(hostname),), 'plone41')
Example #6
0
    def update(self):
        request = self.request

        site = request.params.get('site')
        site = ptah.get_session().query(Site).filter_by(id=site).first()
        if site is None:
            return HTTPFound(location="/dashboard.html?message=Can't find site.")

        self.site = site

        self.host = ''
        for host in site.hosts:
            self.host = host.host
            break

        principal = authenticated_userid(request)
        user = User.getByURI(principal)
        if site.user_id != user.id:
            return HTTPFound(location="/dashboard.html?message=Can't find site.")

        pol = POLICIES[user.type]

        if not pol.vhosts:
            url = '/dashboard.html?message='
            url += 'Virtual hosting is not available for your type of '
            url += 'membership.'
            return HTTPFound(location=url)

        if 'form-change' not in request.POST:
            return

        hostname = request.POST.get('hostname','').strip().lower()
        PLOUD = ptah.get_settings('ploud', self.request.registry)
        if hostname.endswith('.%s'%PLOUD['domain']) and \
                hostname != '%s.%s'%(site.site_name, PLOUD['domain']):
            self.message = "%s domain is not allowed."%PLOUD['domain']
            return

        if hostname == self.host:
            return HTTPFound(location='/dashboard.html?message=Site now has new hostname.')


        conn = ploud_config.PLOUD_POOL.getconn()
        cursor = conn.cursor()

        cursor.execute(
            "SELECT host FROM vhost WHERE id = %s", (site.id,))
        sites = [row[0] for row in cursor.fetchall()]
        if sites:
            cursor.execute(
                "DELETE FROM vhost WHERE id = %s", (site.id,))
            removeVirtualHosts(sites)

        cursor.execute("INSERT INTO vhost(id, host) VALUES(%s, %s)",
                       (site.id, hostname))
        addVirtualHosts((str(hostname),), 'plone41')
        pol.changeHostsPolicy((hostname,), site.site_name)

        cursor.close()
        conn.commit()
        ploud_config.PLOUD_POOL.getconn(conn)

        return HTTPFound(location='/dashboard.html?message=Site now has new hostname.')