Esempio n. 1
0
 def POST(self):
     web.header("Content-Type","text/html; charset=utf-8")
     form = forms.nas_add_form()
     if not form.validates(): 
         return render("baseform.html",form=form,title="新增NAS设备",action="/nas/add")    
     else:
         db = get_db()
         if db.query(models.RadNas).filter(models.RadNas.ip_addr == form.d.ip_addr).count()>0:
             return errorpage("Nas %s 已经存在"%form.d.ip_addr)       
         try:
             nas = models.RadNas()
             nas.id = nextid()
             nas.ip_addr = form.d.ip_addr
             nas.name = form.d.name
             nas.auth_secret = form.d.auth_secret
             nas.acct_secret = form.d.acct_secret
             nas.vendor_id = form.d.vendor_id
             nas.time_type = form.d.time_type
             nas.status = form.d.status
             db.add(nas)
             db.commit()
             db.flush()
         except Exception,e:
             db.rollback()
             log.error("add nes error: %s"%str(e))
             return errorpage("新增Nas失败 %s"%str(e))
         raise web.seeother("/nas",absolute=True)
Esempio n. 2
0
File: models.py Progetto: pmn/qi.io
    def __init__(self, id=None, created_by=None):
        record = None
        if id and created_by:
            record = db.get_entry(id, created_by)

        if record:
            self.id = id
            self.created_by = created_by
            self.body = record.get('body')
            self.raw_body = record.get('raw_body')
            self.tags = record.get('tags')
            self.todos = record.get('todos')
            self.keywords = record.get('_keywords')
            self.created_at = record.get('created_at')
            self.updated_by = record.get('updated_by')
            self.updated_at = record.get('updated_at')
        else:
            # Create a new entry
            self.body = ''
            self.raw_body = ''
            self.todos = []
            self.tags = []
            self.keywords = []
            self.created_by = created_by
            self.updated_by = created_by
            self.created_at = datetime.now()
            self.updated_at = datetime.now()

            # ids depend on pre-existing ids
            if id:
                self.id = id
            else:
                current_entry = db.get_current_entry_for_user(created_by)
                if current_entry:
                    self.id = utils.nextid(current_entry.get('id'))
                else:
                    self.id = utils.nextid()
Esempio n. 3
0
    def POST(self, none):
        web.header("Content-Type", "text/html; charset=utf-8")
        form = forms.node_update_form()
        if not form.validates(source=web.input(nas_bind=[])):
            return render("baseform.html",
                          form=form,
                          title="新增节点",
                          action="/node/update/")
        else:
            db = get_db()
            radnode = db.query(models.RadNode).filter(
                models.RadNode.id == form.d.node_id).first()
            if not radnode:
                return errorpage("节点不存在")

            try:
                radnode.id = form.d.node_id
                radnode.name = form.d.node_name
                radnode.desc = form.d.node_desc

                radopr = db.query(models.RadOpr)\
                .filter(models.RadOpr.type==1)\
                .filter(models.RadOpr.node_id == form.d.node_id).first()
                radopr.node_id = radnode.id
                radopr.id = nextid()
                radopr.type = 1
                radopr.name = form.d.opr_name
                radopr.ip_addr = form.d.opr_ip
                radopr.password = encrypt(form.d.opr_passwd)
                radopr.status = 0

                #修改nas绑定
                for nasnode in db.query(models.RadNasNode).filter(
                        models.RadNasNode.node_id == radnode.id):
                    db.delete(nasnode)

                for ip in form.d.nas_bind:
                    radnasnode = models.RadNasNode()
                    radnasnode.node_id = radnode.id
                    radnasnode.ip_addr = ip
                    db.add(radnasnode)

                db.commit()
                db.flush()
            except Exception, e:
                db.rollback()
                log.error("update node error: %s" % str(e))
                return errorpage("节点修改失败 %s" % str(e))
            raise web.seeother("/node", absolute=True)
Esempio n. 4
0
 def POST(self):
     web.header("Content-Type", "text/html; charset=utf-8")
     form = forms.user_add_form()
     if not form.validates():
         form.group_id.args = getGroupIds(form.d.node_id)
         return render("baseform.html",
                       form=form,
                       title="新增用户",
                       action="/user/add")
     else:
         db = get_db()
         if db.query(models.RadUser)\
              .filter(models.RadUser.user_name == form.d.user_name)\
              .count()>0:
             return errorpage("帐号重复")
         try:
             user = models.RadUser()
             user.id = nextid()
             user.node_id = form.d.node_id
             user.group_id = form.d.group_id
             user.user_name = form.d.user_name
             user.user_cname = form.d.user_cname
             user.password = encrypt(form.d.password)
             user.product_id = form.d.product_id
             user.status = form.d.status
             user.auth_begin_date = form.d.auth_begin_date
             user.auth_end_date = form.d.auth_end_date
             user.user_control = form.d.user_control
             user.concur_number = form.d.concur_number
             user.user_vlan = form.d.user_vlan
             user.user_mac = form.d.user_mac
             user.ip_addr = form.d.ip_addr
             user.install_address = form.d.install_address
             user.balance = 0
             user.time_length = 0
             user.basic_fee = 0
             user.create_time = currtime()
             db.add(user)
             db.commit()
             db.flush()
         except Exception, e:
             db.rollback()
             log.error("add user error: %s" % str(e))
             return errorpage("新增用户失败 %s" % str(e))
         raise web.seeother("/user", absolute=True)
Esempio n. 5
0
    def POST(self):
        web.header("Content-Type","text/html; charset=utf-8")
        form = forms.node_add_form()
       
        if not form.validates(source=web.input(nas_bind=[])): 
            return render("baseform.html",form=form,title="新增节点",action="/node/add")   
        else:
            db = get_db()
            if db.query(models.RadNode).filter(models.RadNode.id == form.d.node_id).count()>0:
                return errorpage("节点编号重复")
            try:
                radnode = models.RadNode()
                radnode.id = form.d.node_id
                radnode.name = form.d.node_name
                radnode.desc = form.d.node_desc

                radopr = models.RadOpr()
                radopr.node_id = radnode.id
                radopr.id = nextid()
                radopr.type = 1
                radopr.name = form.d.opr_name
                radopr.ip_addr = form.d.opr_ip
                radopr.password = encrypt(form.d.opr_passwd)
                radopr.status = 0

                db.add(radnode)
                db.add(radopr)


                #新增nas绑定
                for ip in form.d.nas_bind:
                    radnasnode = models.RadNasNode()
                    radnasnode.node_id = radnode.id
                    radnasnode.ip_addr = ip
                    db.add(radnasnode) 

                db.commit()
                db.flush()
            except Exception,e:
                db.rollback()
                log.error("add node error: %s"%str(e))
                return errorpage("节点新增失败 %s"%str(e))

            raise web.seeother("/node",absolute=True)
Esempio n. 6
0
 def POST(self):
     web.header("Content-Type","text/html; charset=utf-8")
     form = forms.user_add_form()
     if not form.validates(): 
         form.group_id.args = getGroupIds(form.d.node_id)
         return render("baseform.html",form=form,title="新增用户",action="/user/add")    
     else:
         db = get_db()
         if db.query(models.RadUser)\
              .filter(models.RadUser.user_name == form.d.user_name)\
              .count()>0:
             return errorpage("帐号重复")       
         try:
             user = models.RadUser()
             user.id = nextid()
             user.node_id = form.d.node_id
             user.group_id = form.d.group_id
             user.user_name = form.d.user_name
             user.user_cname = form.d.user_cname
             user.password = encrypt(form.d.password)
             user.product_id = form.d.product_id
             user.status = form.d.status
             user.auth_begin_date = form.d.auth_begin_date
             user.auth_end_date = form.d.auth_end_date
             user.user_control = form.d.user_control
             user.concur_number = form.d.concur_number
             user.user_vlan = form.d.user_vlan
             user.user_mac = form.d.user_mac
             user.ip_addr = form.d.ip_addr
             user.install_address = form.d.install_address
             user.balance = 0
             user.time_length = 0
             user.basic_fee = 0
             user.create_time = currtime()
             db.add(user)
             db.commit()
             db.flush()
         except Exception,e:
             db.rollback()
             log.error("add user error: %s"%str(e))
             return errorpage("新增用户失败 %s"%str(e))
         raise web.seeother("/user",absolute=True)