def add_admin(self, username, password, role=0, nick=None, email=None): if not self._user_check(username): raise DatabaseError("username already exists") if username and password: try: salt = token_hex()[8:16] item = mongo[self.table].insert_one({ "username": username, "salt": salt, "password": self.hash_md5(password, salt), "role": role, "token": self.generate_token(), "nick": nick if nick else username, "email": email if email else "*****@*****.**", "date": int(time.time()) }) return item except Exception as e: logger.error("admin insert failed: {} {}".format(username, e)) return False else: logger.error("admin insert failed: invalid data") return False
def add(self, taskid, poc, task_name, poc_name, status, target, app, result=""): if taskid and poc and task_name and poc_name and status and target and app: inserted_id = mongo[self.table].insert_one({ "taskid": taskid, "poc": poc, "task_name": task_name, "poc_name": poc_name, "status": status, "target": target, "app": app, "result": result, "date": self.localtime, }).inserted_id return str(inserted_id) else: logger.warning("pocsuite scan result insert failed: invalid data") raise DatabaseError("invalid data")
def add(self, name, target, poc, thread, frequency): if name and target and poc and thread: inserted_id = mongo[self.table].insert_one({ "name": name.strip(), "target": target, "poc": poc, "thread": thread, "frequency": int(frequency), "date": self.localtime, "end_date": 0, "status": "Waiting", "vul_count": 0, }).inserted_id return str(inserted_id) else: raise DatabaseError("invalid data")
def get_user_info_by_token(self, token): if self.token_check(token): return mongo[self.table].find_one({"token": token}, { "username": 1, "nick": 1, "email": 1 }) else: raise DatabaseError("the access token is invalid")
def add(self, ip, referrer, data): if ip and data and referrer: inserted_id = mongo[self.table].insert_one({ "ip": ip.strip(), "data": data, "referrer": referrer, "date": int(time.time()) }).inserted_id return str(inserted_id) else: logger.warning("http request log insert failed: invalid data") raise DatabaseError("invalid data")
def add(self, domain, title, url, server, project, company_name, taskid, port=None, ip=None, icp=None): if domain: insert_id = mongo[self.table].insert_one({ "taskid": str(taskid), "domain": domain.strip(), "url": url, "ip": str(ip), "title": str(title), "server": str(server), "date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "project": str(project), "company_name": str(company_name), "port": str(port), "icp": str(icp) }).inserted_id print(insert_id) return str(insert_id) else: logger.warning('入库error') raise DatabaseError("invalid data")
def add(self, name, poc_content, filename, app=None, vulntype=None, desc=None, author=None): if name and poc_content: inserted_id = mongo[self.table].insert_one({ "name": name.strip(), "poc_content": poc_content, "app": app, "vulntype": vulntype, "filename": filename, "date": self.localtime, "desc": desc, "author": author }).inserted_id return str(inserted_id) else: raise DatabaseError("upload data error!")
def passwd_check(self, username, password): item = mongo[self.table].find_one({"username": username}) if item: if item['password'] == self.hash_md5(password, item['salt']): return True raise DatabaseError("username or password is incorrect")