def redirectDbAdmin(db_id): if len(db_id) == 0: flash('[db_id]パラメータを入れてください') return render_template('error/404.html') # データベースオブジェクトを取得する current_db = app.lib.cms_lib.session.get_current_db(db_id) # グローバル変数に設定する app.lib.cms_lib.session.current_db = current_db if current_db is None: flash('[db_id:{}]情報を取得できません'.format(db_id)) return render_template('error/404.html') StrUtil.print_debug("db_adm_login_required. cur_db.db_id=[{}]".format( str(current_db.db_id))) if current_user.is_active: session['last_login_user_id'] = current_user.get_id() return set_cookie( StrUtil.get_safe_config(current_app, 'CMS_DB_SYS_COOKIE'), current_user.tuid, url_for('db_adm_index', db_id=db_id)) form = LoginForm() # ログイン情報を保持する last_login_user_id = StrUtil.get_safe_edit_mode('last_login_user_id', session) user_id = request.args.get('user_id') or last_login_user_id if user_id: form.user_id.data = user_id return render_template('cms_admin/login.html', form=form, db_id=db_id, db_name=current_db.db_name, systemVersion="Developer Version 1.00")
def admin_main_init(db_id, request): db_name = "" information_message = "" # ナビゲーションリンク navi_arr_ref = [] navi_arr_ref.append('Main Menu') navi_arr_ref.append(url_for('db_adm_index', db_id=db_id)) if app.lib.cms_lib.session.current_db: db_name = app.lib.cms_lib.session.current_db.db_name information_message = app.lib.cms_lib.session.current_db.information_message StrUtil.print_debug( 'main_db_admin_init. db_name:{0} information_message:{1}'.format( db_name, information_message)) cmsObjectType = CmsObjectType() objTypeList = cmsObjectType.getObjectTypeList(db_id) return render_template('cms_db_admin/main.html', title='ログインメイン', navi_bar_html=HtmlUtil.print_navi_bar(navi_arr_ref), db_id=db_id, db_name=db_name, current_user=current_user, objectTypeList=objTypeList, appVer=current_app.config['APP_VER'])
def view_pdf(file_id): params = {} params['file_id'] = file_id params = file_service.decompress_file(params) if params['df'] != '': downloadDirPath = current_app.config['DOWNLOAD_DIR_PATH'] pdf_file_path = params['df'].replace(downloadDirPath, '/view_pdf') StrUtil.print_debug("file_path:{}".format(pdf_file_path)) return render_template('view_pdf.html', pdf_full_path=pdf_file_path)
def doDbAdminLogin(db_id, form): if len(db_id) == 0: flash('[db_id]パラメータを入れてください') return render_template('error/404.html') # データベースオブジェクトを取得する current_db = app.lib.cms_lib.session.get_current_db(db_id) # グローバル変数に設定する app.lib.cms_lib.session.current_db = current_db if current_db is None: flash('[db_id:{}]情報を取得できません'.format(db_id)) return render_template('error/404.html') StrUtil.print_debug("db_adm_login_required. cur_db.db_id=[{}]".format( str(current_db.db_id))) # リダイレクトURLを取得する next_url = _get_next_url() if form.validate_on_submit(): user = User.query.filter_by(tuid=form.user_id.data).first() if user is None or not PkgUserAuth.check_passwd_for_cms( form.user_id.data, form.password.data): # エラーログを記録する pkgCmsErrLog = PkgCmsErrLog() pkgCmsErrLog.saveErrLog('LOGIN_ERROR', str(form.user_id.data), str(current_db.db_id), '') db.session.commit() flash('invalid user_id or password') return redirect( url_for('db_adm_login', db_id=db_id, user_id=form.user_id.data, next_url=next_url)) login_user(user, False) session['last_login_user_id'] = form.user_id.data return set_cookie( StrUtil.get_safe_config(current_app, 'CMS_DB_SYS_COOKIE'), current_user.tuid, url_for('db_adm_index', db_id=db_id)) # ログイン情報を保持する last_login_user_id = StrUtil.get_safe_edit_mode('last_login_user_id', session) user_id = request.args.get('user_id') or last_login_user_id if user_id: form.user_id.data = user_id return render_template('cms_db_admin/login.html', form=form, db_id=db_id, db_name=current_db.db_name, next_url=next_url, systemVersion="Developer Version 1.00")
def file_pdf(file_id): params = {} params['file_id'] = file_id params['disp_mode'] = request.args.get('disp_mode') params = file_service.decompress_file(params) if params['df'] is not None and params['df'] != '': downloadDirPath = current_app.config['DOWNLOAD_DIR_PATH'] pdf_file_path = params['df'].replace(downloadDirPath, '/file_pdf') StrUtil.print_debug("file_path:{}".format(pdf_file_path)) return render_template('view_pdf.html', pdf_full_path=pdf_file_path) else: return render_template('error/fileNotFound.html')
def _get_ymd(date_str, fmt, date_hash): if fmt == 'YYYY-MM-DD' or fmt == 'YYYY/MM/DD': match = re.search('^(\d+)[\-\/](\d+)[\-\/](\d+)$', date_str) if not match: return 1 date_hash['yyyy'] = match.group(1) date_hash['mm'] = match.group(2) date_hash['dd'] = match.group(3) elif fmt == 'YY/MM/DD': match = re.search('^(\d{1,2})[\-\/](\d{1,2})[\-\/](\d{1,2})$', date_str) if not match: return 1 if int(match.group(3)) > 50: date_hash['yyyy'] = 1900 + int(match.group(1)) else: date_hash['yyyy'] = 2000 + int(match.group(1)) date_hash['mm'] = match.group(2) date_hash['dd'] = match.group(3) elif fmt == 'DD/Mon/YY' or fmt == 'DD-Mon-YY': match = re.search('^(\d+)[\-\/](\w+)[\-\/](\d+)$', date_str) if not match: return 1 if int(match.group(3)) > 50: date_hash['yyyy'] = 1900 + int(match.group(3)) else: date_hash['yyyy'] = 2000 + int(match.group(3)) date_hash['mm'] = ArrUtil.search_array(DateUtil.MoYs, match.group(2)) + 1 date_hash['dd'] = match.group(1) if int(date_hash['mm']) <= 0: return 1 elif fmt == 'DD/Mon/YYYY' or fmt == 'DD-Mon-YYYY': match = re.search('^(\d+)[\-\/](\w+)[\-\/](\d+)$', date_str) if not match: return 1 date_hash['yyyy'] = int(match.group(3)) date_hash['mm'] = ArrUtil.search_array(DateUtil.MoYs, match.group(2)) + 1 date_hash['dd'] = match.group(1) if int(date_hash['mm']) <= 0: return 1 else: StrUtil.print_debug("Invalid date format({})".format(fmt)) sys.exit(1) return 0
def wrapper(*args, **kwargs): logout_user() StrUtil.print_debug('db_adm_login_required. func=[{}]'.format( func.__name__)) db_id = app.lib.cms_lib.session.get_db_id() if not db_id: flash('[db_id]パラメータが必要です') return redirect(url_for('login')) # データベースオブジェクトを取得する current_db = app.lib.cms_lib.session.get_current_db(db_id) # グローバル変数に設定する app.lib.cms_lib.session.current_db = current_db # db情報チェック if not current_db: flash('[db_id:{}]情報を取得できません'.format(db_id)) return redirect(url_for('db_adm_login', db_id=db_id)) StrUtil.print_debug( 'db_adm_login_required. cur_db.db_id=[{}]'.format( str(current_db.db_id))) session_id = app.lib.cms_lib.session.get_session_id( StrUtil.get_safe_config(current_app, 'CMS_DB_SYS_COOKIE')) if session_id: StrUtil.print_debug( 'db_adm_login_required. session_cookie_name:{0} session_id:{1}' .format('DB_ADMIN_SESSION_COOKIE', session_id)) cst = CmsSessionTable.get_db_adm_session_info(session_id) if cst is None: flash('invalid user_id or password') return redirect(url_for('db_adm_login')) # 取得したユーザIDでユーザ情報を取得する user = User.query.filter_by(tuid=cst.user_id).first() if user is None: flash('invalid user_id or password') return redirect(url_for('db_adm_login')) # DB管理者権限チェック pkgCmsSecurity = PkgCmsSecurity() if not pkgCmsSecurity.isDbAdminUser(db_id, user.tuid): flash('利用権限がありません') return redirect( UserAuth._get_redirect_url( url_for('db_adm_login', db_id=current_db.db_id))) login_user(user, False) else: StrUtil.print_debug('login_required. no session id got.') return redirect( UserAuth._get_redirect_url( url_for('db_adm_login', db_id=current_db.db_id))) return func(*args, **kwargs)
def set_cookie(session_cookie_name, tuid, redirectUrl): random_str = '{0}{1}'.format(StrUtil.make_random_str(25), str(CreateSeq.getSessionIdSeq()).zfill(9)) StrUtil.print_debug('random_str:{}'.format(str(random_str))) cst = CmsSessionTable(session_cookie_name, random_str, tuid) db.session.add(cst) db.session.commit() if request.method == 'GET': next_url = request.args.get('next_url') else: next_url = request.form['next_url'] if not next_url: next_url = redirectUrl else: next_url = urllib.parse.unquote(next_url) StrUtil.print_debug('next_url:{}'.format(str(next_url))) response = make_response(redirect(next_url)) response.set_cookie(session_cookie_name, random_str) return response
def wrapper(*args, **kwargs): logout_user() StrUtil.print_debug('adm_login_required. func=[{}]'.format( str(func.__name__))) session_id = app.lib.cms_lib.session.get_session_id( StrUtil.get_safe_config(current_app, 'CMS_SYS_COOKIE')) if session_id: StrUtil.print_debug( 'login_required. session_cookie_name:{0} session_id:{1}'. format('ADMIN_SESSION_COOKIE', session_id)) cst = CmsSessionTable.get_adm_session_info(session_id) if cst is None: flash('invalid user_id or password') return redirect(url_for('adm_login')) # 取得したユーザIDでユーザ情報を取得する user = User.query.filter_by(tuid=cst.user_id).first() if user is None: flash('invalid user_id or password') return redirect(url_for('adm_login')) # 管理者権限チェック pkgCmsSecurity = PkgCmsSecurity() if not pkgCmsSecurity.isAdminUser(user.tuid): flash('利用権限がありません') return redirect( UserAuth._get_redirect_url(url_for('adm_login'))) login_user(user, False) else: StrUtil.print_debug('login_required. no session id got.') return redirect( UserAuth._get_redirect_url(url_for('adm_login'))) return func(*args, **kwargs)
'created_by', 'created_at', ] input_value = [ '1', 'ああああああああああああああああああああああああああああああああああああああああ', 'test body', '10.24', '1', 'z02039n0', '2020-02-18', ] db_field = [ 'ID', 'TITLE', 'BODY', 'AMOUNT', 'ORDER_BY', 'CREATED_BY', 'CREATED_AT', ] col_prop = {'cname': cname, 'input_value': input_value, 'db_field': db_field} param_prop = { 'err_msgs': [], 'table_name': 'PYTHON_TEST001', 'col_prop': col_prop } DbUtil.check_input_form_data_by_db(param_prop) StrUtil.print_debug(list(param_prop['err_msgs']))
def save_privs_dept(func, request): if len(func) == 0: return render_template('error/404.html') res, msg = {}, "OK" form = PrivsDeptForm() err_msgs = [] isSaveError = False db_id = request.form["db_id"] if func == Const.UPDATE_PRIVS_DEPT: old_div_cd = request.form["old_div_cd"] old_dept_cd = request.form["old_dept_cd"] old_emp_type_cd = request.form["old_emp_type_cd"] old_working_type_cd = request.form["old_working_type_cd"] old_privs_type = request.form["old_privs_type"] corp_cd = request.form["corp_cd"] div_cd = request.form["div_cd"] dept_cd = request.form["dept_cd"] emp_type_cd = request.form["emp_type_cd"] working_type_cd = request.form["working_type_cd"] privs_type = request.form["privs_type"] cmsDbPrivsDept = CmsDbPrivsDept() cmsDbCodeMaster = CmsDbCodeMaster() OPERATION_NOTE = "CORP_CD={}, DIV_CD={}, DEPT_CD={}, EMP_TYPE_CD={}, WORKING_TYPE_ID={}, PRIVS_TYPE={}" # 保存処理(新規、編集) if func == Const.ADD_PRIVS_DEPT or func == Const.UPDATE_PRIVS_DEPT: if func == Const.ADD_PRIVS_DEPT: isCorpCdExist = cmsDbCodeMaster.checkCorpCdExist(corp_cd) if not isCorpCdExist: err_msgs.append( Const.DATA_NOT_EXIST_ERR_MSG.replace("%s", "Corp Cd")) isSaveError = True privsDept = cmsDbPrivsDept.getPrivsDept(db_id, corp_cd, div_cd, dept_cd, emp_type_cd, working_type_cd, privs_type) if privsDept and privsDept.corp_cd == corp_cd: err_msgs.append(Const.DATA_EXIST_ERR_MSG) isSaveError = True else: privsDept = cmsDbPrivsDept.getPrivsDept(db_id, corp_cd, div_cd, dept_cd, emp_type_cd, working_type_cd, privs_type) # 登録しようとするデータが存在すれば(自分自身以外)、更新できないよう if privsDept and \ (privsDept.div_cd != old_div_cd or privsDept.dept_cd != old_dept_cd or privsDept.emp_type_cd != old_emp_type_cd or privsDept.working_type_cd != old_working_type_cd): err_msgs.append(Const.DATA_EXIST_ERR_MSG) isSaveError = True if not isSaveError: # 入力チェックする cname = [ "Corp Cd", "Div Cd", "Dept Cd", "Emp Type", "Working Type", "Privs Type", ] input_value = [ corp_cd, div_cd, dept_cd, emp_type_cd, working_type_cd, privs_type, ] db_field = [ "MANAGEMENT_CORP_CD", "DIV_CD", "DEPT_CD", "EMP_TYPE_CD", "WORKING_TYPE_CD", "PRIVS_TYPE", ] col_prop = { 'cname': cname, 'input_value': input_value, 'db_field': db_field } param_prop = { 'err_msgs': [], 'table_name': 'CMS_DB_PRIVS_DEPT', 'form': form, 'col_prop': col_prop } DbUtil.check_input_form_data_by_db(param_prop) if len(param_prop['err_msgs']) > 0: err_msgs = param_prop['err_msgs'] isSaveError = True if request.method == 'POST' and not isSaveError: if form.validate_on_submit() == False: StrUtil.print_debug("validate error.") else: try: if func == Const.ADD_PRIVS_DEPT: addPrivsDept = CmsDbPrivsDept(db_id, corp_cd, div_cd, dept_cd, emp_type_cd, working_type_cd, privs_type) cmsDbPrivsDept.addPrivsDept(addPrivsDept, current_user.get_id()) # Privs Dept登録を記録する pkgCmsLog = PkgCmsLog() pkgCmsLog.saveOperationLog( current_user.get_id(), db_id, operation_cd=Const.OPERATION_CD_ADD_PRIVS_DEPT, object_id=None, object_type=None, note=OPERATION_NOTE.format(corp_cd, div_cd, dept_cd, emp_type_cd, working_type_cd, privs_type)) db.session.commit() else: cmsDbPrivsDept.uptPrivsDept( db_id, corp_cd, div_cd, dept_cd, emp_type_cd, working_type_cd, old_div_cd, old_dept_cd, old_emp_type_cd, old_working_type_cd, old_privs_type, current_user.get_id()) # Privs Dept変更を記録する pkgCmsLog = PkgCmsLog() pkgCmsLog.saveOperationLog( current_user.tuid, db_id, operation_cd=Const.OPERATION_CD_UPDATE_PRIVS_DEPT, object_id=None, object_type=None, note=OPERATION_NOTE.format(corp_cd, div_cd, dept_cd, emp_type_cd, working_type_cd, privs_type)) db.session.commit() except Exception as e: db.session.rollback() tb = sys.exc_info()[2] StrUtil.print_error( "Database save failed. error_msg:{}".format( str(e.with_traceback(tb)))) err_msgs.append('Database save failed.') # 削除処理 elif func == Const.DELETE_PRIVS_DEPT: try: cmsDbPrivsDept.delPrivsDept(db_id, corp_cd, div_cd, dept_cd, emp_type_cd, working_type_cd, privs_type, current_user.get_id()) # Privs Dept削除を記録する pkgCmsLog = PkgCmsLog() pkgCmsLog.saveOperationLog( current_user.tuid, db_id, operation_cd=Const.OPERATION_CD_DELETE_PRIVS_DEPT, object_id=None, object_type=None, note=OPERATION_NOTE.format(corp_cd, div_cd, dept_cd, emp_type_cd, working_type_cd, privs_type)) db.session.commit() except Exception as e: db.session.rollback() tb = sys.exc_info()[2] StrUtil.print_error("Database save failed. error_msg:{}".format( str(e.with_traceback(tb)))) err_msgs.append('Database delete failed.') res = {**res, **{"err_msgs": err_msgs}} return Response(json.dumps(res))
def save_privs_user(func, request): if len(func) == 0: return render_template('error/404.html') res, msg = {}, "OK" form = PrivsUserForm() err_msgs = [] isSaveError = False db_id = request.form["db_id"] if func == Const.UPDATE_PRIVS_USER: old_corp_cd = request.form["old_corp_cd"] old_dept_cd = request.form["old_dept_cd"] old_privs_type = request.form["old_privs_type"] corp_cd = request.form["corp_cd"] dept_cd = request.form["dept_cd"] tuid = request.form["user_id"] privs_type = request.form["privs_type"] cmsDbPrivsUser = CmsDbPrivsUser() # 保存処理(新規、編集) if func == Const.ADD_PRIVS_USER or func == Const.UPDATE_PRIVS_USER: if func == Const.ADD_PRIVS_USER: privsUser = cmsDbPrivsUser.getPrivsUser(db_id, corp_cd, dept_cd, tuid, privs_type) if privsUser and privsUser.tuid == tuid: err_msgs.append(Const.DATA_EXIST_ERR_MSG) isSaveError = True user_info = User.getUserInfo(tuid) if not user_info: err_msgs.append(Const.USER_ID_NOT_EXIST_ERR_MSG) isSaveError = True else: privsUser = cmsDbPrivsUser.getPrivsUser(db_id, corp_cd, dept_cd, tuid, privs_type) # 登録しようとするデータが存在すれば(自分自身以外)、更新できないよう if privsUser and \ (privsUser.corp_cd != old_corp_cd or privsUser.dept_cd != old_dept_cd): err_msgs.append(Const.DATA_EXIST_ERR_MSG) isSaveError = True if not isSaveError: # 入力チェックする cname = [ "Corp Cd", "Department", "User Id", "Privs Type", ] input_value = [ corp_cd, dept_cd, tuid, privs_type, ] db_field = [ "MANAGEMENT_CORP_CD", "DEPT_CD", "TUID", "PRIVS_TYPE", ] col_prop = { 'cname': cname, 'input_value': input_value, 'db_field': db_field } param_prop = { 'err_msgs': [], 'table_name': 'CMS_DB_PRIVS_USER', 'form': form, 'col_prop': col_prop } DbUtil.check_input_form_data_by_db(param_prop) if len(param_prop['err_msgs']) > 0: err_msgs = param_prop['err_msgs'] isSaveError = True if request.method == 'POST' and not isSaveError: # form = DatabaseForm(request.form) if form.validate_on_submit() == False: StrUtil.print_debug("validate error.") else: try: if func == Const.ADD_PRIVS_USER: addPrivsUser = CmsDbPrivsUser(db_id, corp_cd, dept_cd, tuid, privs_type) cmsDbPrivsUser.addPrivsUser(addPrivsUser, tuid) # Privs User登録を記録する pkgCmsLog = PkgCmsLog() pkgCmsLog.saveOperationLog( current_user.tuid, db_id, operation_cd=Const.OPERATION_CD_ADD_PRIVS_USER, object_id=None, object_type=None, note=tuid) db.session.commit() else: uptPrivsUser = cmsDbPrivsUser.uptPrivsUser( db_id, old_corp_cd, old_dept_cd, tuid, old_privs_type, corp_cd, dept_cd, privs_type, current_user.get_id()) # Privs User変更を記録する pkgCmsLog = PkgCmsLog() pkgCmsLog.saveOperationLog( current_user.tuid, db_id, operation_cd=Const.OPERATION_CD_UPDATE_PRIVS_USER, object_id=None, object_type=None, note=tuid) db.session.commit() except Exception as e: db.session.rollback() tb = sys.exc_info()[2] StrUtil.print_error( "Database save failed. error_msg:{}".format( str(e.with_traceback(tb)))) err_msgs.append('Database save failed.') # 削除処理 elif func == Const.DELETE_PRIVS_USER: try: cmsDbPrivsUser.delPrivsUser(db_id, corp_cd, dept_cd, tuid, privs_type, current_user.get_id()) # Privs User削除を記録する pkgCmsLog = PkgCmsLog() pkgCmsLog.saveOperationLog( current_user.tuid, db_id, operation_cd=Const.OPERATION_CD_DELETE_PRIVS_USER, object_id=None, object_type=None, note=tuid) db.session.commit() except Exception as e: db.session.rollback() tb = sys.exc_info()[2] StrUtil.print_error("Database save failed. error_msg:{}".format( str(e.with_traceback(tb)))) err_msgs.append('Database delete failed.') res = {**res, **{"err_msgs": err_msgs}} return Response(json.dumps(res))
def optimize_ctx(self, app): try: # データベースオブジェクトを取得する db_list = CmsDb.getCmsDbList() if db_list is None: return False row_num = str(StrUtil.get_safe_config(app, 'CTX_MAX_OBJECT_CNT')) for db_info in db_list: StrUtil.print_debug("optimize_ctx db_id=[{}] begin.".format( str(db_info.db_id))) cms_object = CmsObject() for object_info in cms_object.getCtxObjectList( db_info.db_id, row_num): cmsCtxData = CmsCtxData() # cms_ctx_dataからレコード削除 (updateされた場合の対応) cmsCtxData.delCmsCtxData(object_info.object_id, db_info.db_id) # タイトルテキスト 例:<#IDX_TEXT_001#> : <#IDX_TEXT_002#> ctx_title_rst = { 'CTX_TITLE': '', 'CTX_TEXT': '', 'CTX_ERROR_FLG': 0, 'CTX_ERROR_LOG': '' } cms_object.getCtxTitle(object_info.object_type_id, object_info.object_id, None, object_info.ctx_title_format, ctx_title_rst) # cms_ctx_dataに登録する情報を設定する cmsCtxData.db_id = db_info.db_id cmsCtxData.object_id = object_info.object_id cmsCtxData.object_updated_at = object_info.updated_at cmsCtxData.ctx_title = ctx_title_rst['CTX_TITLE'] cmsCtxData.ctx_text = ctx_title_rst['CTX_TEXT'] cmsCtxData.ctx_error_log = ctx_title_rst['CTX_ERROR_LOG'] cmsCtxData.data_type = Const.DATA_TYPE_OBJECT url = Const.URL_FORMAT.format( str(StrUtil.get_safe_config( app, 'CMS_SYS_URL')).strip('/') + '/property', 'func={}&db_id={}&id={}&object_id={}'.format( 'show_property', db_info.db_id, object_info.parent_folder_id, object_info.object_id)) cmsCtxData.ctx_url = url cmsCtxData.ctx_error_flg = ctx_title_rst['CTX_ERROR_FLG'] # cms_ctx_dataに登録する cmsCtxData.addCmsCtxData(cmsCtxData) # INDEXに登録したら、 cms_object.ctx_indexed_flg=1にする cms_object.ctxUpdObject(object_info.object_id, 1) # cms_object_property, cms_file_typeからINDEX対象の属性やファイルを特定 cms_file = CmsFile() for file_info in cms_file.get_ctx_file_list( object_info.object_id): if not ctx_allowed_file(file_info.file_name): continue cmsCtxData = CmsCtxData() # ctx_text = ctx_text_format.format(ctx_text, # file_info.file_name + ":" # + os.path.join(file_info.dir_name, # file_info.c_file_name)) StrUtil.print_debug( 'ctx_file file_info=[file_name={}; file_path={}]'. format( file_info.file_name, os.path.join(file_info.dir_name, file_info.c_file_name))) # CTX_TITLE_FOTMATの取得 cmsFileType = CmsFileType() fileTypeInfo = cmsFileType.getFileTypeInfo( file_info.file_type_id) # タイトルテキスト 例:<#IDX_TEXT_001#> : <#IDX_TEXT_002#> (<#FILE_NAME#>) ctx_title_rst = { 'CTX_TITLE': '', 'CTX_TEXT': '', 'CTX_ERROR_FLG': 0, 'CTX_ERROR_LOG': '' } cms_object.getCtxTitle(object_info.object_type_id, object_info.object_id, file_info.file_id, fileTypeInfo.ctx_title_format, ctx_title_rst) ctx_text_rst = { 'CTX_TEXT': '', 'CTX_ERROR_FLG·': 0, 'CTX_ERROR_LOG': '' } CtxUtil._get_ctx_text(app, file_info, ctx_text_rst) # URL url = '' # テキスト ctx_text = Const.CONTACT_FORMAT.format( ctx_title_rst['CTX_TEXT'], ctx_text_rst['CTX_TEXT']) # エラーメッセージ ctx_error_log = ctx_title_rst['CTX_ERROR_LOG'] if len(ctx_error_log) != 0: ctx_error_log += '\n' ctx_error_log += ctx_text_rst['CTX_ERROR_LOG'] # cms_ctx_dataに登録する情報を設定する cmsCtxData.db_id = db_info.db_id cmsCtxData.object_id = object_info.object_id cmsCtxData.object_updated_at = object_info.updated_at cmsCtxData.ctx_title = ctx_title_rst['CTX_TITLE'] cmsCtxData.ctx_text = ctx_text cmsCtxData.ctx_error_log = StrUtil.truncate( ctx_error_log, 4000) cmsCtxData.data_type = Const.DATA_TYPE_FILE if ctx_text_rst['CTX_ERROR_FLG'] == 0: url = Const.URL_FORMAT.format( str(StrUtil.get_safe_config( app, 'CMS_SYS_URL')).strip('/') + '/download_file', 'db_id={}&file_id={}'.format( db_info.db_id, file_info.file_id)) cmsCtxData.ctx_url = url cmsCtxData.ctx_error_flg = ctx_text_rst[ 'CTX_ERROR_FLG'] # cms_ctx_dataに登録する cmsCtxData.addCmsCtxData(cmsCtxData) cms_file = CmsFile(object_info.object_id) # INDEXに登録したら、 cms_file.ctx_indexed_flg=1にする cms_file.setCtxIndexedFlg(file_info.file_id, 1) # DBごと処理後にtmpフォルダを空にする CtxUtil._tmp_file_remove(app) StrUtil.print_debug('optimize_ctx db_id=[{}] end.'.format( str(db_info.db_id))) db.session.commit() except Exception as e: db.session.rollback() tb = sys.exc_info()[2] StrUtil.print_error('optimize_ctx error_msg:{}'.format( str(e.with_traceback(tb)))) CtxUtil._tmp_file_remove(app)
def main_init(db_id, request): if len(db_id) == 0: return render_template('error/404.html') db_name = "" information_message = "" # TODO result_cnt result_cnt = 0 if app.lib.cms_lib.session.current_db: db_name = app.lib.cms_lib.session.current_db.db_name information_message = app.lib.cms_lib.session.current_db.information_message StrUtil.print_debug( 'main_init. db_name:{0} information_message:{1}'.format( db_name, information_message)) db_id = app.lib.cms_lib.session.current_db.db_id cmsSecurity = PkgCmsSecurity() is_db_editable = cmsSecurity.isDbEditable(db_id, current_user.get_id()) # タブ情報を取得 viewType = request.args.get('view_type') cmsTreeViewSetting = CmsTreeViewSetting() tabList = cmsTreeViewSetting.getTreeViewSettingList(db_id) if viewType is None or len(viewType) <= 0: treeSetting = cmsTreeViewSetting.getTreeViewSettingList(db_id).first() viewType = treeSetting.view_type treeOpenFlg = treeSetting.tree_open_flg else: treeSetting = cmsTreeViewSetting.getTreeViewSetting(db_id, viewType) treeOpenFlg = treeSetting.tree_open_flg jtree_store = '' selected_node_id = '' if request.method == 'GET': jtree_store = request.args.get('jtree_store') or '' selected_node_id = request.args.get('selected_node_id') or '' # 通常検索機能 searchSetting = CmsSearchSetting().getSearchSettingByDbId(db_id) # 画面表示用CSS STYLEを取得 colorSettingDic = CmsStyleMaster().getStyleSettings( db_id, Const.STYLE_TYPE_COLOR) return render_template( 'main.html', title=db_name, view_type=viewType, tree_open_flg=treeOpenFlg, db_id=db_id, db_name=db_name, information_message=information_message, result_cnt=result_cnt, current_user=current_user, jtree_store=jtree_store, selected_node_id=selected_node_id, is_edit_mode=StrUtil.get_safe_edit_mode( str(db_id) + '_is_edit_mode', session), is_db_editable=is_db_editable, tabList=tabList, searchSetting=searchSetting, colorSettingDic=colorSettingDic, appVer=current_app.config['APP_VER'], is_db_admin_user=isDbAdminUser(str(db_id), str(current_user.get_id())), )
def createCsvFile(self, writer): StrUtil.print_debug('createCsvFile')
def doLogin(db_id, form): if len(db_id) == 0: flash('[db_id]パラメータを入れてください') return render_template('error/404.html') # データベースオブジェクトを取得する current_db = app.lib.cms_lib.session.get_current_db(db_id) # グローバル変数に設定する app.lib.cms_lib.session.current_db = current_db if current_db is None: flash('[db_id:{}]情報を取得できません'.format(db_id)) return render_template('error/404.html') StrUtil.print_debug("login_required. cur_db.db_id=[{}]".format( str(current_db.db_id))) # リダイレクトURLを取得する next_url = _get_next_url() if form.validate_on_submit(): user = User.query.filter_by(tuid=form.user_id.data).first() if user is None or not PkgUserAuth.check_passwd_for_cms( form.user_id.data, form.password.data): # エラーログを記録する pkgCmsErrLog = PkgCmsErrLog() pkgCmsErrLog.saveErrLog('LOGIN_ERROR', str(form.user_id.data), str(current_db.db_id), '') db.session.commit() flash('invalid user_id or password') return redirect( url_for('login', db_id=db_id, user_id=form.user_id.data, next_url=next_url)) login_user(user, False) session['last_login_user_id'] = form.user_id.data session[str(db_id) + '_is_edit_mode'] = False # ログインログを記録する pkgCmsLog = PkgCmsLog() pkgCmsLog.saveOperationLog(form.user_id.data, db_id, operation_cd=Const.OPERATION_CD_LOGIN, object_type='DB', note=current_db.db_name) db.session.commit() return set_cookie(current_db.session_cookie_name, current_user.tuid, url_for('index', db_id=db_id)) # ログイン情報を保持する last_login_user_id = StrUtil.get_safe_edit_mode('last_login_user_id', session) user_id = request.args.get('user_id') or last_login_user_id if user_id: form.user_id.data = user_id user_name = '' if current_user.is_active: user_name = current_user.get_user_name() return render_template( 'login.html', title=current_db.db_name + '-ログイン画面', systemVersion="Developer Version 1.00", form=form, db_id=db_id, next_url=next_url, db_name=current_db.db_name, user_name=user_name, loginMessage=current_db.login_message, )
def wrapper(*args, **kwargs): logout_user() StrUtil.print_debug('login_required. func=[{}]'.format( str(func.__name__))) db_id = app.lib.cms_lib.session.get_db_id() if not db_id: flash('[db_id]パラメータが必要です') return redirect(url_for('login')) # データベースオブジェクトを取得する current_db = app.lib.cms_lib.session.get_current_db(db_id) # グローバル変数に設定する app.lib.cms_lib.session.current_db = current_db if not current_db: flash('[db_id:{}]情報を取得できません'.format(db_id)) return redirect(url_for('login', db_id=db_id)) StrUtil.print_debug('login_required. cur_db.db_id=[{}]'.format( str(current_db.db_id))) session_id = app.lib.cms_lib.session.get_session_id( current_db.session_cookie_name) if session_id: StrUtil.print_debug( 'login_required. session_cookie_name:{0} session_id:{1}'. format(current_db.session_cookie_name, session_id)) # セッションテーブルからユーザIDを取得する(有効期限:一週間) cst = CmsSessionTable.get_session_info( current_db.session_cookie_name, session_id) if cst is None: flash('invalid user_id or password') return redirect(url_for('login', db_id=db_id)) # 取得したユーザIDでユーザ情報を取得する user = User.query.filter_by(tuid=cst.user_id).first() if user is None: flash('invalid user_id or password') return redirect(url_for('login', db_id=db_id)) # アクセス権限チェック pkgIpAddrUtil = PkgIpAddrUtil() id_addr = StrUtil.get_ip_addr() if not id_addr or not pkgIpAddrUtil.isDbIpAddrVisible( db_id, id_addr): # ログ出力 DBの参照権限なし PkgCmsErrLog().saveErrLog(Const.IP_ADDRESS_ERROR, user.tuid, str(current_db.db_id)) db.session.commit() flash('利用権限がありません') return redirect(url_for('login', db_id=db_id)) # 参照権限チェック pkgCmsSecurity = PkgCmsSecurity() if not pkgCmsSecurity.isDbVisible(db_id, user.tuid): # ログ出力 DBの参照権限なし PkgCmsErrLog().saveErrLog(Const.DB_PRIVS_ERROR, user.tuid, str(current_db.db_id)) db.session.commit() flash('このDBを参照する権限がありません') return redirect(url_for('login', db_id=db_id)) StrUtil.print_debug('login_required. user_id=[{}]'.format( str(current_db.db_id))) login_user(user, False) session['db_id'] = db_id else: StrUtil.print_debug('login_required. no session id got.') return redirect( UserAuth._get_redirect_url( url_for('login', db_id=current_db.db_id))) return func(*args, **kwargs)
# coding:utf-8 import os import sys from app.lib.cms_lib.date_util import DateUtil from app.lib.cms_lib.num_util import NumUtil from app.lib.cms_lib.str_util import StrUtil sys.path.append('/home03/cms/flask/cms/') os.environ['NLS_LANG'] = 'JAPANESE_JAPAN.AL32UTF8' from app import create_app app = create_app() app.app_context().push() # 日付チェック rst = DateUtil.check_date_format('2020/02/18', 'YYYY/MM/DD') StrUtil.print_debug(rst) # 日付チェック rst = NumUtil.is_number_data('aa') StrUtil.print_debug(rst) rst = NumUtil.is_integer_data('10.22') StrUtil.print_debug(rst) num_prop = {'sign_ref': '', 'i_ref': '', 'f_ref': ''} rst = NumUtil.split_number('10.22', num_prop) StrUtil.print_debug(rst) rst = StrUtil.truncate('ああああああああああああああああああああああああああああああああああああああああああ', 20) StrUtil.print_debug(rst)