コード例 #1
0
ファイル: dashboard.py プロジェクト: nerdfiles/ploud-prod
def remove(request):
    site = request.POST.get('site_id')
    site = Session.query(Site).filter_by(id = site).first()
    if site is None:
        raise HTTPFound(location="/dashboard.html?message=Can't find site.")
        
    principal = authenticated_userid(request)
    user = User.getByURI(principal)
    if site.user_id != user.id:
        raise HTTPFound(location="/dashboard.html?message=Can't find site.")

    pol = POLICIES[user.type]
    if user.removes >= pol.removes:
        raise HTTPFound(
            location="/dashboard.html?message=You are not allowed to remove site.")

    conn = ploud_config.PLOUD_POOL.getconn()
    cursor = conn.cursor()
    pol.removeSite(site.id, cursor)
    site.removed = True

    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)

    site.site_name = 'site_for_removing_%s'%site.id

    user.removes += 1
    cursor.close()
    conn.commit()
    ploud_config.PLOUD_POOL.putconn(conn)

    raise HTTPFound(location="/dashboard.html?message=Site has been removed.")
コード例 #2
0
ファイル: dashboard.py プロジェクト: nerdfiles/ploud-prod
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)
コード例 #3
0
ファイル: hostname.py プロジェクト: enfold/ploud.frontend
    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.')