Beispiel #1
0
    def post(self):

        saved = None
        form = NetworkPoolForm(self.request.arguments)
        if form.validate():

            networkpool = {
                'start': form.start.data,
                'end': form.end.data,
                'netmask': form.netmask.data,
                'gateway': form.gateway.data,
                'nameservers': form.nameservers.data,
                'exclude_ips': form.exclude_ips.data,
            }

            nameservers = form.nameservers.data

            if self.nameservers:
                #self.nameservers.value = nameservers
                pass
            else:
                c = LuoYunConfig('nameservers', nameservers)
                self.db2.add(c)

            networkpool = json.dumps([
                networkpool,
            ])
            if self.networkpool:
                self.networkpool.value = networkpool
            else:
                c = LuoYunConfig('networkpool', networkpool)
                self.db2.add(c)

            self.db2.commit()
            from tool.network import set_network_pool
            # set settings.NETWORK_POOL
            set_network_pool(self.db2)
            saved = True
            # TODO: redirect to ?
            url = self.reverse_url('system:networkpool')
            self.redirect(url)

        self.render('system/networkpool_edit.html', form=form, saved=saved)
Beispiel #2
0
    def post(self):

        saved = None
        form = NameserversForm(self)
        if form.validate():

            nameservers = form.nameservers.data

            if self.nameservers:
                self.nameservers.value = nameservers
            else:
                c = LuoYunConfig('nameservers', nameservers)
                self.db2.add(c)

            self.db2.commit()
            saved = True

        self.render('system/nameservers_edit.html', form=form, saved=saved)
Beispiel #3
0
    def post(self):

        saved = None
        form = WelcomeNewUserForm(self)
        if form.validate():

            welcome = json.dumps({
                    'text': form.text.data,
                    'html': YMK.convert(form.text.data) })

            if self.welcome:
                self.welcome.value = welcome
            else:
                c = LuoYunConfig('welcome_new_user', welcome)
                self.db.add(c)

            self.db.commit()
            saved = True

        self.render('system/welcome_new_user_edit.html', form = form, saved = saved)
Beispiel #4
0
    def post(self):

        saved = None
        form = RegistrationProtocolForm(self)
        if form.validate():

            protocol = json.dumps({
                    'text': form.text.data,
                    'html': YMK.convert(form.text.data) })

            if self.protocol:
                self.protocol.value = protocol
            else:
                c = LuoYunConfig('protocol', protocol)
                self.db.add(c)

            self.db.commit()
            saved = True

        self.render('system/registration_protocol_edit.html', form = form, saved = saved)
Beispiel #5
0
    def post(self):

        saved = None
        form = NginxForm(self)
        if form.validate():

            nginx = json.dumps({
                'conf_dir': form.confdir.data,
                'log_dir': form.logdir.data,
                'bin_path': form.binpath.data
            })

            if self.nginx:
                self.nginx.value = nginx
            else:
                c = LuoYunConfig('nginx', nginx)
                self.db2.add(c)

            self.db2.commit()
            saved = True

        self.render('system/nginx_edit.html', form=form, saved=saved)
Beispiel #6
0
    def post(self):

        saved = None
        form = DomainForm(self)
        if form.validate():

            domain = json.dumps({
                'topdomain': form.topdomain.data,
                'prefix': form.prefix.data,
                'suffix': form.suffix.data
            })

            if self.domain:
                self.domain.value = domain
            else:
                c = LuoYunConfig('domain', domain)
                self.db2.add(c)

            self.db2.commit()
            saved = True

        self.render('system/domain_edit.html', form=form, saved=saved)
Beispiel #7
0
def default_value(dbsession):

    # LuoYunConfig
    from app.system.models import LuoYunConfig
    for k, v in settings.luoyun_system_config:
        c = dbsession.query(LuoYunConfig).filter_by(key=k).first()
        if c:
            print '[W] config key exist: %s' % k
        else:
            nc = LuoYunConfig(key=k, value=v)
            dbsession.add(nc)

    # Permission
    from app.account.models import Permission
    for codename, name in settings.default_permission:
        p = dbsession.query(Permission).filter_by(codename=codename).first()
        if p:
            print '[W] permission codename exist: %s' % codename
        else:
            p = Permission(codename=codename, name=name)
            dbsession.add(p)

    # Group
    from app.account.models import Group
    for name in settings.default_group:
        g = dbsession.query(Group).filter_by(name=name).first()
        if g:
            print '[W] group exist: %s' % name
        else:
            # Group created defaultly is locked.
            g = Group(name=name, islocked=True)
            dbsession.add(g)

    # User
    from app.account.models import User
    for username, password in settings.default_user:
        u = dbsession.query(User).filter_by(username=username).first()
        if u:
            print '[W] user exist: %s' % username
        else:
            salt = md5(str(random.random())).hexdigest()[:12]
            hsh = encrypt_password(salt, password)
            enc_password = "******" % (salt, hsh)
            u = User(username=username, password=enc_password)
            dbsession.add(u)
            dbsession.commit()

        if not u.profile:
            from app.account.models import UserProfile
            profile = UserProfile(u, email='%s@localhost' % u.username)
            dbsession.add(profile)

    # User Group
    for groupname, username in settings.default_user_group:
        u = dbsession.query(User).filter_by(username=username).first()
        g = dbsession.query(Group).filter_by(name=groupname).first()
        if u and (g not in u.groups):
            u.groups.append(g)

    # User Permission
    for username, codename in settings.default_user_permission:
        u = dbsession.query(User).filter_by(username=username).first()
        p = dbsession.query(Permission).filter_by(codename=codename).first()
        if p not in u.permissions:
            u.permissions.append(p)

    # Group Permission
    for groupname, codename in settings.default_group_permission:
        g = dbsession.query(Group).filter_by(name=groupname).first()
        p = dbsession.query(Permission).filter_by(codename=codename).first()
        if p not in g.permissions:
            g.permissions.append(p)

    # Appliance Catalog
    from app.appliance.models import ApplianceCatalog
    for name, summary in settings.default_appliance_catalog:
        c = dbsession.query(ApplianceCatalog).filter_by(name=name).first()
        if c:
            print '[W] appliance catalog exist: %s' % name
        else:
            c = ApplianceCatalog(name=name, summary=summary)
            dbsession.add(c)
            dbsession.commit()

    # Wiki Catalog
    from app.wiki.models import WikiCatalog
    for name, summary in settings.default_wiki_catalog:
        c = dbsession.query(WikiCatalog).filter_by(name=name).first()
        if c:
            print '[W] wiki catalog exist: %s' % name
        else:
            c = WikiCatalog(name=name, summary=summary)
            dbsession.add(c)
            dbsession.commit()

    dbsession.commit()