def __init__(self, user: discord.Member): self.user = user character = session.query(db.Player)\ .filter(db.Player.user_id == self.user.id)\ .one_or_none() self.sex = character.sex self.level = character.level self.xp = character.xp self.strength = character.strength self.agility = character.agility self.resistance = character.resistance self.endurance = character.endurance self.intelligence = character.intelligence self.perception = character.perception self.luck = character.luck if character is None: player = db.Player() player.user_id = self.user.id player.sex = "male" equipment = db.Player() equipment.user_id = self.user.id session.add(player) session.commit()
def run(self): """ 黑客详细信息 :return: """ if self.method == 'POST': city_data = tt.find(self.src_ip) hacker_city = unicode(city_data[0], 'gb2312').encode('utf-8') hacker_addr = unicode(city_data[1], 'gb2312').encode('utf-8') domain = "http://%s%s" % (self.host, self.uri) s = "时间: %s\n" \ "攻击URL: %s\n" \ "域名: %s\n" \ "攻击ip: %s\n" \ "攻击所在地: %s%s\n" \ "User-Agent: %s\n" \ "状态: POST\n" \ "提交数据: %s\n" \ "详细信息: %s\n" \ "匹配规则: %s\n--------------------------------------\n" % \ (self.src_time, domain, self.host, self.src_ip, hacker_city, hacker_addr, self.user_agent, self.body, self.headers, self.acl) try: hack_db = Hack(src_time=self.src_time, url=domain, hack_city=hacker_city, hack_addr=hacker_addr, method="POST", host=self.host, ip=self.src_ip, acl=str(self.acl), headers=str(self.headers), user_agent=self.user_agent, cookie=self.cookie, post_data=self.body) session.add(hack_db) session.commit() except Exception, e: print e return s
def new(_name, _email, _password): account = Account( name = _name, email = _email, password = _password ) session.add(account) session.commit()
def img_name_in_db(file_name): new_image = Images(img_name=file_name) try: session.add(new_image) session.commit() return True except(IntegrityError, InvalidRequestError): # img_name already exist return False finally: session.close()
def post(self): args = self.reqparse.parse_args() username = args.username now = datetime.now() now = now.strftime("%Y-%m-%d %H:%M:%S") c = Cla(username=username, ctime=now, utime=now) session.add(c) session.commit() return { 'msg': 'ok', 'data': { 'username': username, 'ctime': now, 'utime': now } }
def add(): username = request.form['username'] if username: try: now = datetime.now() now = now.strftime("%Y-%m-%d %H:%M:%S") cls = Classes(username=username, utime=now, ctime=now) session.add(cls) session.commit() except BaseException as e: print("数据库异常", e) return jsonify({'code': 200, 'status': 'no', 'msg': '数据库异常请稍后重试'}) return jsonify({'code': 200, 'status': 'yes', 'msg': '添加成功'}) else: return jsonify({'code': 200, 'status': 'no', 'msg': '参数不正确'})
def createUser(): try: data = request.form for key in getModelKeys(User): if not key in data: raise AssertionError(f'Property {key} is missing') user = User(email=data['email']) user.setPassword(data['password']) session.add(user) session.commit() session.refresh(user) return jsonify(user=JSONEncoder(user)), 201 except AssertionError as err: return jsonify({"message": str(err)}), 400 except Exception as err: print(err) return jsonify({"message": str(err)}), 500
def setup_cli(token_name, token, server_url): '''Setup go cli to work with the go server''' drop_database() create_database() token_name_i = Setting(setting_name='token_name', setting_value=token_name) token_i = Setting(setting_name='token', setting_value=token) token_url_i = Setting(setting_name='url', setting_value=server_url) session.add(token_name_i) session.add(token_i) session.add(token_url_i) session.commit() click.echo('Go CLI successfully setup')
session.commit() except Exception, e: print e return s else: city_data = tt.find(self.src_ip) hacker_city = unicode(city_data[0], 'gb2312').encode('utf-8') hacker_addr = unicode(city_data[1], 'gb2312').encode('utf-8') domain = "http://%s%s" % (self.host, self.uri) s = "时间: %s\n" \ "攻击URL: %s\n" \ "域名: %s\n" \ "攻击ip: %s\n" \ "攻击所在地: %s%s\n" \ "User-Agent: %s\n" \ "状态: GET\n" \ "详细信息: %s\n" \ "匹配规则: %s\n--------------------------------------\n" % \ (self.src_time, domain, self.host, self.src_ip, hacker_city, hacker_addr, self.user_agent, self.headers, self.acl) try: hack_db = Hack(src_time=self.src_time, url=domain, hack_city=hacker_city, hack_addr=hacker_addr, method="GET", host=self.host, ip=self.src_ip, acl=str(self.acl), headers=str(self.headers), user_agent=self.user_agent, cookie=self.cookie) session.add(hack_db) session.commit() except Exception, e: print e return s
hacker_addr = unicode(city_data[1], 'gb2312').encode('utf-8') domain = "http://%s%s" % (self.host, self.uri) s = "时间: %s\n" \ "攻击URL: %s\n" \ "域名: %s\n" \ "攻击ip: %s\n" \ "攻击所在地: %s%s\n" \ "User-Agent: %s\n" \ "状态: GET\n" \ "详细信息: %s\n" \ "匹配规则: %s\n--------------------------------------\n" % \ (self.src_time, domain, self.host, self.src_ip, hacker_city, hacker_addr, self.user_agent, self.headers, self.acl) try: hack_db = Hack(src_time=self.src_time, url=domain, hack_city=hacker_city, hack_addr=hacker_addr, method="GET", host=self.host, ip=self.src_ip, acl=str(self.acl), headers=str(self.headers), user_agent=self.user_agent, cookie=self.cookie) session.add(hack_db) session.commit() except Exception, e: print e return s
def add_project(name, description, deadline): new_project = Project(name=name, description=description, deadline=deadline) session.add(new_project) session.commit()