예제 #1
0
파일: Log.py 프로젝트: zhmsg/dms
 def show_log(self, start_time=None, end_time=None, level=None, search_url="", search_account=""):
     run_end = time()
     run_begin = run_end - timedelta(hours=1).total_seconds()
     require = {}
     if start_time is not None and start_time > run_begin:
         run_begin = start_time
         require["start_time"] = start_time
     if end_time is not None and end_time < run_end:
         run_end = end_time
         require["end_time"] = end_time
     where_sql_list = ["log_no>=%s " % long(run_begin * 10000), "log_no<=%s " % long(run_end * 10000)]
     if level is not None:
         if level not in self.log_level:
             return False, "Bad level"
         where_sql_list.append("level = '%s'" % level)
     if search_url is not None and search_url != "":
         search_url = check_sql_character(search_url)
         where_sql_list.append("url like '%s%%'" % search_url)
     if search_account is not None and search_account != "":
         search_account = check_sql_character(search_account)
         where_sql_list.append("account = '%s'" % search_account)
     where_sql = " AND ".join(where_sql_list)
     result, log_records = self._select_log(where_sql)
     if result is False:
         return False, log_records
     return True, {"log_records": log_records, "require": require}
예제 #2
0
파일: APIHelp.py 프로젝트: zhmsg/dms
 def new_api_output(self, api_no, output_examples):
     if len(api_no) != 32:
         return False, "Bad api_no"
     new_result = []
     value_sql = "VALUES "
     for item in output_examples:
         if "desc" not in item or "example" not in item:
             return False, "output example need desc and example"
         output_desc = check_sql_character(item["desc"])[:550]
         output_example = check_sql_character(item["example"])
         if len(output_desc) < 1:
             return False, "Bad output_desc"
         if len(output_example) < 1:
             return False, "Bad output_example"
         output_no = uuid.uuid1().hex
         add_time = datetime.now().strftime(TIME_FORMAT)
         value_sql += "('%s','%s','%s','%s','%s')" % (output_no,api_no, output_desc, output_example, add_time)
         new_result.append({"api_no": api_no, "output_no": output_no, "desc": output_desc,
                            "example": output_example, "add_time": add_time})
     if len(value_sql) < 8:
         return True
     insert_sql = "INSERT INTO %s (output_no,api_no,output_desc,output_example,add_time) %s" \
                  % (self.api_output, value_sql)
     result = self.db.execute(insert_sql)
     if result != 1:
         return False, "sql execute result is %s " % result
     self.set_api_update(api_no)
     return True, new_result
예제 #3
0
파일: Log.py 프로젝트: zhmsg/dms
 def insert_login_server(self, server_ip, server_name, user_ip, user_name, login_time):
     if check_int(server_ip, 1, sys.maxint) is False:
         return False, "Bad server ip"
     if check_int(user_ip, 1, sys.maxint) is False:
         return False, "Bad user ip"
     now_time = int(time())
     if check_int(login_time, now_time - 100, now_time + 100) is False:
         return False, "Bad login time"
     user_name = check_sql_character(user_name)[:50]
     server_name = check_sql_character(server_name)[:20]
     insert_sql = "INSERT INTO %s (server_ip,server_name,user_ip,user_name,login_time) VALUES (%s,'%s',%s,'%s',%s);" \
                  % (self.login_server, server_ip, server_name, user_ip, user_name, login_time)
     self.local_db.execute(insert_sql)
     return True, "success"
예제 #4
0
파일: APIHelp.py 프로젝트: zhmsg/dms
 def new_api_module(self, module_name, module_prefix, module_desc, module_part, module_env):
     module_name = module_name.strip(" ")
     if check_chinese_en(module_name, 1, 35) is False:
         return False, "Bad module_name."
     if check_path(module_prefix, 1, 35) is False:
         return False, "Bad module_prefix"
     if check_int(module_part, max_v=9999) is False:
         return False, "Bad module_part"
     if type(module_env) != list:
         return False, "Bad module_env"
     if len(module_env) not in range(1, 6):
         print(module_env)
         return False, "Bad module_env."
     module_desc = check_sql_character(module_desc)[:240]
     module_env_s = ""
     for env_no in module_env:
         if type(env_no) != int:
             return False, "Bad env_no"
         module_env_s += "%s|" % env_no
     insert_sql = "INSERT INTO %s (module_name,module_prefix,module_desc,module_part,module_env) " \
                  "VALUES ('%s','%s','%s',%s,'%s');" \
                  % (self.api_module, module_name, module_prefix, module_desc, module_part, module_env_s[:-1])
     result = self.db.execute(insert_sql)
     if result != 1:
         return False, "sql execute result is %s " % result
     return True, "success"
예제 #5
0
파일: APIHelp.py 프로젝트: zhmsg/dms
 def new_api_body(self, api_no, body_params):
     if len(api_no) != 32:
         return False, "Bad api_no"
     new_result = []
     value_sql = "VALUES "
     for key, value in body_params.items():
         if check_char_num_underline(key) is False:
             return False, "Bad body param %s" % key
         if "necessary" not in value or "desc" not in value or "type" not in value:
             return False, "Bad body param %s, need necessary type desc" % key
         if value["necessary"] != 0 and value["necessary"] != 1:
             return False, "Bad body param %s, necessary must be 0 or 1" % key
         if check_char(value["type"], 1, 20) is False:
             return False, "Bad body param %s, type must a-z" % key
         param_desc = check_sql_character(value["desc"])[:1000]
         add_time = datetime.now().strftime(TIME_FORMAT)
         value_sql += "('%s','%s',%s,'%s','%s','%s')" \
                      % (api_no, key, value["necessary"], value["type"], param_desc, add_time)
         necessary = True if value["necessary"] == 1 else False
         new_result.append({"api_no": api_no, "necessary": necessary, "param": key, "desc": param_desc,
                            "type": value["type"], "add_time": add_time})
     if len(value_sql) < 8:
         return True
     insert_sql = "INSERT INTO %s (api_no,param,necessary,type,param_desc,add_time) %s " \
                  "ON DUPLICATE KEY UPDATE necessary=VALUES(necessary),param_desc=VALUES(param_desc),type=VALUES(type)" \
                  % (self.api_body, value_sql)
     result = self.db.execute(insert_sql)
     self.set_api_update(api_no)
     return True, new_result
예제 #6
0
파일: Dev.py 프로젝트: zhmsg/dms
 def new_right_action(self, module_no, action_desc, min_role, adder):
     add_time = int(time())
     action_desc = check_sql_character(action_desc)
     insert_sql = "INSERT INTO %s (module_no,action_desc,min_role,adder,add_time) VALUES (%s,'%s','%s','%s',%s)" \
                  % (self.right_action_role, module_no, action_desc, min_role[:1], adder, add_time)
     self.db.execute(insert_sql)
     return True, "success"
예제 #7
0
파일: APIStatus.py 프로젝트: zhmsg/dms
 def _insert_status_code(self, status_code, code_desc, adder):
     code_desc = check_sql_character(code_desc)
     add_time = datetime.now().strftime(TIME_FORMAT)
     insert_sql = "INSERT IGNORE INTO %s (status_code,code_desc,add_time,adder) " \
                  "VALUES (%s,'%s','%s','%s');" % (self.status_code, status_code, code_desc, add_time, adder)
     result = self.db.execute(insert_sql)
     return result
예제 #8
0
파일: APIHelp.py 프로젝트: zhmsg/dms
 def new_send_message(self, send_user, rec_user, content):
     content = check_sql_character(content)
     rec_user_s = ",".join(rec_user)[:500]
     send_time = int(time())
     insert_sql = "INSERT INTO %s (send_user,rec_user,send_time,content) VALUES ('%s','%s',%s,'%s');" \
                  % (self.send_message, send_user, rec_user_s, send_time, content)
     self.db.execute(insert_sql)
     return True, "success"
예제 #9
0
파일: Bug.py 프로젝트: zhmsg/dms
 def new_bug_info(self, bug_title, submitter):
     submit_time = datetime.now().strftime(TIME_FORMAT)
     bug_no = uuid.uuid1().hex
     if len(bug_title) < 5:
         return False, "Bad bug_title"
     bug_title = check_sql_character(bug_title)[:50]
     insert_sql = "INSERT INTO %s (bug_no,bug_title,submitter,submit_time) VALUES ('%s','%s','%s','%s');" \
                  % (self.bug, bug_no, bug_title, submitter, submit_time)
     result = self.db.execute(insert_sql)
     if result != 1:
         return False, "sql execute result is %s " % result
     return True, {"bug_no": bug_no, "bug_title": bug_title, "submitter": submitter, "submit_time": submit_time}
예제 #10
0
파일: APIHelp.py 프로젝트: zhmsg/dms
 def update_api_info(self, api_no, module_no, api_title, api_path, api_method, api_desc):
     if len(api_no) != 32:
         return False, "Bad api_no"
     if type(module_no) != int:
         return False , "Bad module_no"
     if check_path(api_path) is False:
         return False, "Bad api_path"
     if api_path.endswith("/") is False:
         return False, u"api path should end with /"
     if check_http_method(api_method) is False:
         return False, "Bad api_method"
     api_title = check_sql_character(api_title)
     api_desc = check_sql_character(api_desc)
     if len(api_desc) < 1:
         return False, "Bad api_desc"
     # 更新 api_info
     update_time = datetime.now().strftime(TIME_FORMAT)
     update_sql = "UPDATE %s SET module_no=%s,api_title='%s',api_path='%s',api_method='%s',api_desc='%s',update_time='%s' " \
                  "WHERE api_no='%s'; "  \
                  % (self.api_info, module_no, api_title, api_path, api_method, api_desc, update_time, api_no)
     result = self.db.execute(update_sql)
     return True, "success"
예제 #11
0
파일: Bug.py 프로젝트: zhmsg/dms
 def new_bug_example(self, bug_no, example_type, content):
     if len(bug_no) != 32:
         return False, "Bad bug_no"
     add_time = datetime.now().strftime(TIME_FORMAT)
     if len(content) < 5:
         return False, "Bad content"
     content = check_sql_character(content)
     insert_sql = "INSERT INTO %s (bug_no,type,content,add_time) VALUES ('%s','%s','%s','%s');" \
                  % (self.bug_example, bug_no, example_type, content, add_time)
     result = self.db.execute(insert_sql)
     if result != 1:
         return False, "sql execute result is %s " % result
     return True, {"bug_no": bug_no, "example_type": example_type, "content": content, "add_time": add_time}
예제 #12
0
파일: APIHelp.py 프로젝트: zhmsg/dms
 def new_api_info(self, module_no, api_title, api_path, api_method, api_desc):
     if type(module_no) != int:
         return False , "Bad module_no"
     if check_path(api_path) is False:
         return False, "Bad api_path"
     if api_path.endswith("/") is False:
         return False, u"api path should end with /"
     if check_http_method(api_method) is False:
         return False, "Bad api_method"
     api_title = check_sql_character(api_title)
     api_desc = check_sql_character(api_desc)
     if len(api_desc) < 1:
         return False, "Bad api_desc"
     api_no = uuid.uuid1().hex
     # 新建 api_info
     add_time = datetime.now().strftime(TIME_FORMAT)
     insert_sql = "INSERT INTO %s (api_no,module_no,api_title,api_path,api_method,api_desc,add_time,update_time) " \
                  "VALUES('%s',%s,'%s','%s','%s','%s','%s','%s')" \
                  % (self.api_info, api_no, module_no, api_title, api_path, api_method, api_desc, add_time, add_time)
     result = self.db.execute(insert_sql)
     if result != 1:
         return False, "sql execute result is %s " % result
     return True, {"api_no": api_no}
예제 #13
0
파일: APIHelp.py 프로젝트: zhmsg/dms
 def update_api_module(self, module_no, module_name, module_prefix, module_desc, module_part, module_env):
     if check_chinese_en(module_name, 0, 35) is False:
         return False, "Bad module_name."
     if check_path(module_prefix, 0, 35) is False:
         return False, "Bad module_prefix"
     if check_int(module_part, max_v=9999) is False:
         return False, "Bad module_part"
     if type(module_env) != list:
         return False, "Bad module_env"
     if len(module_env) not in range(1, 6):
         print(module_env)
         return False, "Bad module_env."
     module_desc = check_sql_character(module_desc)[:240]
     module_env_s = ""
     for env_no in module_env:
         if type(env_no) != int:
             return False, "Bad env_no"
         module_env_s += "%s|" % env_no
     update_sql = "UPDATE %s SET module_name='%s',module_prefix='%s',module_desc='%s',module_part=%s,module_env='%s' " \
                  "WHERE module_no=%s;"  \
                  % (self.api_module, module_name, module_prefix, module_desc, module_part, module_env_s[:-1], module_no)
     result = self.db.execute(update_sql)
     return True, "success"