Example #1
0
def updateUserById(user_id):
    try:
        if not user_id.isdigit(): raise ValueError('Id must be integer')
        user_id = int(user_id)
        if user_id < 1: raise ValueError('Id must be bigger than 0')

        user = session.query(User).get(user_id)
        if user is None: return jsonify({"message": 'Not found'}), 404

        data = request.form
        for key in getModelKeys(User):
            if key is 'password' and key in data: user.setPassword(data[key])
            else:
                if key in data: user.__setattr__(key, data[key])

        session.commit()
        session.refresh(user)

        return jsonify(user=JSONEncoder(user)), 200

    except ValueError as err:
        return jsonify({"message": str(err)}), 400

    except AssertionError as err:
        return jsonify({"message": str(err)}), 400

    except Exception as err:
        print(err)
        return jsonify({"message": str(err)}), 500
Example #2
0
    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()
Example #3
0
    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
Example #4
0
	def new(_name, _email, _password):
		account = Account(
			name = _name,
			email = _email,
			password = _password
		)
		session.add(account)
		session.commit()
Example #5
0
def dels():
    c = session.query(Classes).filter(Classes.id).first()
    try:
        session.delete(c)
        session.commit()
    except:
        return jsonify({'code':200,'status':'no','msg':'数据库异常,请重试'})
    return jsonify({'code':200,'status':'yes','msg':'提交成功'})
def delete_image(img):
    try:
        file_path = os.getcwd() + '/database/images/' + img.img_name + '.jpeg'
        session.delete(img)
        session.commit()
        session.close()
        os.remove(file_path)
    except:
        return {'message': 'Something went wrong'}, 500
Example #7
0
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()
Example #8
0
 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
         }
     }
Example #9
0
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')
Example #10
0
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': '参数不正确'})
Example #11
0
def deleteUserById(user_id):
    try:
        if not user_id.isdigit(): raise ValueError('Id must be integer')
        user_id = int(user_id)
        if user_id < 1: raise ValueError('Id must be bigger than 0')

        user = session.query(User).get(user_id)
        if user is None: return jsonify({"message": 'Not found'}), 404

        session.query(User).filter(User.id == user_id).delete()
        session.commit()
        return jsonify(user=JSONEncoder(user)), 200

    except ValueError as err:
        return jsonify({"message": str(err)}), 400

    except Exception as err:
        print(err)
        return jsonify({"message": str(err)}), 500
Example #12
0
    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
Example #13
0
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
Example #14
0
                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
Example #15
0
            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
Example #16
0
 def add_project(name, description, deadline):
     new_project = Project(name=name,
                           description=description,
                           deadline=deadline)
     session.add(new_project)
     session.commit()