def post(self): ip_address=self.request.remote_ip self.set_header("Content-Type","application/json") data=data_operation.ByteToJson(self.request.body) try: username = data['username'] len15=len(username) if len15>15: raise RuntimeError('testError') password = data['password'] log_data =json.dumps({"username":username,"password":password}) ret1= yield User.data_usr.login_byusername(self,username,password) #print(ret1) Dictret=ret1.__dict__ data1=yield permiss.permiss_data.PermissSelect(self,Dictret["rolename"]) Dictret["permiss"]=json.loads(data1) self.set_status(200,'OK') self.write(json.dumps({"status_code":200,"data":Dictret})) yield session.Session.DitCheck(self,username) str1= yield session.Session.DitInsert(self,username) self.set_secure_cookie('str',str1) #print(session.NameDit) yield Logconfig.Write_Sys_Log(self,username,'用户登录','用户登录',ip_address,log_data,200) Web_log.info('User %s was login by %s.'%(username,str1)) #self.redirect("/nw/index.html#/users/welcome") except : yield Logconfig.Write_Sys_Log(self,username,'用户登录','登录错误',ip_address,json.dumps(data),4012) self.set_status(200,'用户名或密码错误') self.write(json.dumps({"status_code":4012}))
def post(self): self.set_header("Content-Type","application/json") ip_address=self.request.remote_ip data=data_operation.ByteToJson(self.request.body) try: username = data["username"] try: password=data["password"] except: password='' name = data["name"] email = data["email"] department=data["department"] phone_num=data["phone_num"] try: description=data["description"] except: description='' rolename=data["rolename"] #print(password) if (username==''or name==''or email==''or department==''or phone_num==''or rolename==''): raise RuntimeError('testError') user_data=User.data_usr(username,name,email,department,phone_num,description,rolename,password) if(yield User.data_usr.UserUpdate(self,user_data)): self.set_status(201,"修改成功") self.write(json.dumps("Update OK")) yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','修改用户',ip_address,json.dumps(data),200) else: yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','修改用户',ip_address,json.dumps(data)+'\nusername is wrong',400) self.write(json.dumps({"status_code":422,"res":"username is wrong"})) except : yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','修改用户',ip_address,json.dumps(data)+'\n data wrong',400) self.set_status(400,"参数不全或格式错误") self.write(json.dumps("data wrong"))
def post(self): ip_address=self.request.remote_ip self.set_header("Content-Type","application/json") data=data_operation.ByteToJson(self.request.body) res=Rule.rulegroup_write(data) if(res==True): if len(data["rule"]) != 0: re=Action_to_rule.action_to_rulegroup(data["ingroupname"],data["outgroupname"],data["rulegroupname"]) else: re=Action_to_rule.default_action(data["ingroupname"],data["outgroupname"]) re_sync = yield Rule.rule_sync(self) if re==True and re_sync==True: yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则组',ip_address,json.dumps(data),200) self.set_status(200,'OK') self.write(json.dumps("RuleGroup insert ok")) else: yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则组',ip_address,json.dumps(data)+'\nfailed Action_to_rule',400) self.write(json.dumps({"status_code":400,"res":"Action_to_rule"})) self.set_status(400,'XX') elif Rule.Chongfu==0: yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则组',ip_address,json.dumps(data)+'\nfailed rule_group_write',400) self.write(json.dumps({"status_code":400,"res":"rule_group_write"})) self.set_status(400,'XX') else: yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则组',ip_address,json.dumps(data)+'\nfailed rule_group_write',400) self.write(json.dumps({"status_code":4002,"res":"rule_group_write"})) self.set_status(4002,'XX')
def post(self): self.set_header("Content-Type","application/json") ip_address=self.request.remote_ip #print(self.request.body) data=data_operation.ByteToJson(self.request.body) username = data["username"] password = data["password"] name = data["name"] email = data["email"] department=data["department"] phone_num=data["phone_num"] try: description=data["description"] except: description='' rolename=data["rolename"] if (username==''or password==''or name==''or email==''or department==''or phone_num==''or rolename==''): self.set_status(400,'参数不全或格式错误') self.write(json.dumps({"status_code":400,"res":"data wrong"})) yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','添加用户',ip_address,json.dumps(data)+"\ndata wrong",400) return False user_data=User.data_usr(username,name,email,department,phone_num,description,rolename,password) if(yield User.data_usr.UserInsert(self,user_data)): self.set_status(201,'创建成功') self.write(json.dumps({"status_code":200,"res":"Insert OK"})) yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','添加用户',ip_address,json.dumps(data),200) else: yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','添加用户',ip_address,json.dumps(data)+"\nusername exsit",422) self.set_status(422,'创建不成功,username已存在') self.write(json.dumps({"status_code":422,"res":"create is wrong"}))
def post(self): self.set_header("Content-Type", "application/json") data = data_operation.ByteToJson(self.request.body) if data['real_time'] == 0: data1 = statistic.get_statistic_data(data['otype'], data) else: data1 = statistic.get_real_time_data(data['otype'], data) self.set_status(200, 'success') self.write(json.dumps(data1))
def post(self): ip_address=self.request.remote_ip self.set_header("Content-Type","application/json") data=data_operation.ByteToJson(self.request.body) rolename = data["rolename"] if(yield permiss.permiss_data.RoleDelete(self,rolename)): Web_log.info("User %s was deleting role:%s"%(self.username,data["rolename"])) yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','删除角色',ip_address,json.dumps(data),200) self.set_status(201,'ok') self.write(json.dumps('OK')) else: self.set_status(400,'data wrong') self.write(json.dumps({"status_code":400,"res":"data is wrong"}))
def post(self): ip_address=self.request.remote_ip self.set_header("Content-Type","application/json") try: data=data_operation.ByteToJson(self.request.body) data_permission=permiss.permiss_decode(data['permissions']) data1=yield permiss.permiss_data.PermissInsert(self,data_permission) Web_log.info("User %s was updating %s 's permission:"%(self.username,data["rolename"])) yield permiss.permiss_data.PermissUpdate(self,data["rolename"],data1,data["description"]) yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','更新角色',ip_address,json.dumps(data),200) self.set_status(200,'ok') self.write(json.dumps('OK')) except: yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','更新角色',ip_address,json.dumps(data)+"\ndata is wrong",400) self.set_status(400,'data wrong') self.write(json.dumps({"status_code":400,"res":"data is wrong"}))
def post(self): ip_address=self.request.remote_ip data=data_operation.ByteToJson(self.request.body) self.set_header("Content-Type","application/json") try: username = data["username"] if (username==''): raise RuntimeError('testError') elif(yield User.data_usr.UserDelete(self,username)): yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','删除用户',ip_address,json.dumps(data),200) self.write(json.dumps("OK")) else: yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','删除用户',ip_address,json.dumps(data),400) self.set_status(400,"参数错误") self.write(json.dumps({"status_code":400,"res":"data is wrong"})) except : yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','删除用户',ip_address,json.dumps(data),400) self.set_status(400,"参数不全或格式错误") self.write(json.dumps({"status_code":400,"res":"data is wrong"}))
def post(self): self.set_header("Content-Type","application/json") try: cookie_str=data_operation.ByteToStr(self.get_secure_cookie("str")) except: cookie_str='' username='******' #权限验证 if cookie_str : username=yield session.Session.DitGet(self,cookie_str) permiss_value=yield permiss.permiss_data.PermissTest(self,username,'policy_read') if (Open_permiss or permiss_value): data=data_operation.ByteToJson(self.request.body) #print(data) Rulelist=Rule.rulegroup_select(data["rulegroupname"]) RuleData=json.dumps(Rulelist) self.write(RuleData) else: self.write(json.dumps('no permissions')) self.write(json.dumps({"status_code":401}))
def post(self): ip_address=self.request.remote_ip self.set_header("Content-Type","application/json") data=data_operation.ByteToJson(self.request.body) res_data=Rule.rule_write(data) res=res_data['data'] if (len(data["rule"]) == len(res) and res!=[]): for i in res: re=Action_to_rule.action_to_rule(i,'','','',data['rulegroupname']) #print(i,re) Rule.rule_des_update(data) re_sync = yield Rule.rule_sync(self) if re_sync: yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则',ip_address,json.dumps(data),200) self.set_status(200,'OK') self.write(json.dumps("Rule insert ok")) else: yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则',ip_address,json.dumps(data),400) self.set_status(400,'OK') self.write(json.dumps("sync failed")) elif (res==[] and len(data["rule"]) == len(res)): yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则组',ip_address,json.dumps(data)+'\nrule_write failed',400) Rule.rule_des_update(data) self.write(json.dumps('no update: rule_write')) self.set_status(200,'XX') elif res_data['message']=='re' and res==[]: yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则组',ip_address,json.dumps(data)+'\nRule insert failed',402) self.set_status(4002,'fail') self.write(json.dumps("Rule insert failed")) elif res_data['message']=='re' : Rule.only_delete_rule(res) yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则组',ip_address,json.dumps(data)+'\nRule insert failed',402) self.set_status(4002,'fail') self.write(json.dumps("Rule insert failed")) elif res==[] : yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则组',ip_address,json.dumps(data)+'\nRule insert failed',400) self.set_status(4001,'fail') self.write(json.dumps("Rule insert failed")) else: Rule.only_delete_rule(res) yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','添加规则组',ip_address,json.dumps(data)+'\nRule insert failed',400) self.set_status(4001,'fail') self.write(json.dumps("Rule insert failed"))
def post(self): ip_address = self.request.remote_ip self.set_header("Content-Type", "application/json") data = data_operation.ByteToJson(self.request.body) res = databasetime.PatchSystemTime(data['time']) if res == True: con = sqlite3.connect(database_default.interface_db) c = con.cursor() c.execute("Delete from in_out_day") con.commit() con.close() self.write(json.dumps({"status_code": 200, "message": "successd"})) self.set_status(200, '') yield Logconfig.Write_Sys_Log(self, self.username, '系统配置', '时间配置', ip_address, '', 200) else: yield Logconfig.Write_Sys_Log(self, self.username, '系统配置', '时间配置', ip_address, 'reset failed', 400) self.write(json.dumps({"status_code": 400, "res": "reset failed"})) self.set_status(400, '')
def post(self): ip_address=self.request.remote_ip data=data_operation.ByteToJson(self.request.body) self.set_header("Content-Type","application/json") if "ruleid" in data: log_name='规则' data1=data["rulegroupname"] data2=data["ruleid"] res=Rule.rule_delete(data1,data2) else: log_name='规则组' data1=data["rulegroupname"] res=Rule.rulegroup_delete(data1) re_sync = yield Rule.rule_sync(self) if(res==True and re_sync==True): yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','删除'+log_name,ip_address,json.dumps(data),200) self.write(json.dumps('OK')) self.set_status(200,'ok') else: yield Logconfig.Write_Sys_Log(self,self.username,'转发策略','删除'+log_name,ip_address,json.dumps(data)+'\nnot existed',400) self.write(json.dumps({"status_code":400,"res":"Rulegroup is not existed"})) self.set_status(400,'not existed')
def post(self): ip_address=self.request.remote_ip self.set_header("Content-Type","application/json") data=data_operation.ByteToJson(self.request.body) data['permissions']=permiss.permiss_decode(data['permissions']) data1=yield permiss.permiss_data.PermissInsert(self,data['permissions']) #print(data) rolename = data['rolename'] try: description=data['description'] except: description='' try : if(yield permiss.permiss_data.RoleInsert(self,rolename,data1,description)): yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','添加角色',ip_address,json.dumps(data),200) self.write(json.dumps({"status_code":200,"res":"ok"})) else: yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','添加角色',ip_address,json.dumps(data)+'\nrolename is exsited',400) self.write(json.dumps({"status_code":400,"res":"rolename is exsited"})) except : yield Logconfig.Write_Sys_Log(self,self.username,'用户管理','添加角色',ip_address,json.dumps(data),401) self.set_status(401,'no') self.write(json.dumps({"status_code":401}))