class GroupForm(forms.Form): """ グループの入力チェック """ group_name_errors = { 'required': 'MOSJA23011', 'max_length': 'MOSJA23012', } summary_errors = { 'max_length': 'MOSJA23013', } group_name = forms.CharField(max_length=64, error_messages=group_name_errors) summary = forms.CharField(max_length=4000, required=False, error_messages=summary_errors) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.emo_chk = UnicodeCheck() def clean_group_name(self): group_name = self.cleaned_data['group_name'] if len(self.emo_chk.is_emotion(group_name)): self.add_error('group_name', 'MOSJA23037') return group_name def clean_summary(self): summary = self.cleaned_data['summary'] if len(self.emo_chk.is_emotion(summary)): self.add_error('summary', 'MOSJA23038') return summary
class DataObjectSerializer(serializers.ModelSerializer): CONDITIONAL_NAME_LENGTH = 32 EMO_CHK = UnicodeCheck() symbol_repatter = '[\u0021-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u007E\uFF01-\uFF0F\uFF1A-\uFF20\uFF3B-\uFF40\uFF5B-\uFF5E]' class Meta: model = DataObject fields = ( 'conditional_name', 'conditional_expression_id', 'last_update_user', 'last_update_timestamp', ) def validate_conditional_name(self, conditional_name): conditional_name_len = len(conditional_name) #未入力チェック if conditional_name_len <= 0: raise serializers.ValidationError("条件名 未入力") #文字数チェック if conditional_name_len > self.CONDITIONAL_NAME_LENGTH: raise serializers.ValidationError( "条件名 入力文字数不正 conditional_name=%s, req_len=%s, valid_len=%s" % (conditional_name, conditional_name_len, self.CONDITIONAL_NAME_LENGTH)) # 絵文字チェック value_list = self.EMO_CHK.is_emotion(conditional_name) if len(value_list) > 0: raise serializers.ValidationError("条件名 入力文字不正") # 記号チェック re_obj = re.search(self.symbol_repatter, conditional_name) if re_obj: raise serializers.ValidationError("条件名 入力文字不正") return conditional_name
class RuleTypeSerializer(serializers.ModelSerializer): GENERATION_MIN = 1 GENERATION_MAX = 10 RULE_TYPE_NAME_LENGTH = 64 SUMMARY_LENGTH = 4000 RULE_TABLE_NAEM_LENGTH = 64 RULE_TABLE_NAME_PATTERN = '^[a-zA-Z0-9]+$' MAIL_ADDRESS_LENGTH = 512 EMO_CHK = UnicodeCheck() NOTIFY_TYPES = ['0', '1', '2', '3'] class Meta: model = RuleType fields = ( 'rule_type_id', 'rule_type_name', 'summary', 'rule_table_name', 'generation_limit', 'group_id', 'artifact_id', 'container_id_prefix_staging', 'container_id_prefix_product', 'current_container_id_staging', 'current_container_id_product', 'unknown_event_notification', 'mail_address', 'last_update_timestamp', 'last_update_user', ) def validate_generation_limit(self, generation_limit): if generation_limit < self.GENERATION_MIN or generation_limit > self.GENERATION_MAX: raise serializers.ValidationError("不正な世代管理数 generation_limit=%s" % (generation_limit)) return generation_limit def validate_rule_type_name(self, rule_type_name): rule_type_name_len = len(rule_type_name) # 未入力チェック if rule_type_name_len <= 0: raise serializers.ValidationError("ルール種別名称未入力", "rule_type_name") # 文字数チェック if rule_type_name_len > self.RULE_TYPE_NAME_LENGTH: raise serializers.ValidationError( "ルール種別名称 入力文字数不正 rule_type_name=%s, req_len=%s, valid_len=%s" % (rule_type_name, rule_type_name_len, self.RULE_TYPE_NAME_LENGTH), "rule_type_name") # 絵文字チェック value_list = self.EMO_CHK.is_emotion(rule_type_name) if len(value_list) > 0: raise serializers.ValidationError("ルール種別名称 入力文字不正", "rule_type_name") return rule_type_name def validate_summary(self, summary): # 文字数チェック summary_len = len(summary) if summary_len > self.SUMMARY_LENGTH: raise serializers.ValidationError( "概要 入力文字数不正 summary=%s, req_len=%s, valid_len=%s" % (summary, summary_len, self.SUMMARY_LENGTH), "summary") value_list = self.EMO_CHK.is_emotion(summary) if len(value_list) > 0: raise serializers.ValidationError("概要 入力文字不正", "summary") return summary def validate_rule_table_name(self, rule_table_name): rule_table_name_len = len(rule_table_name) # 未入力チェック if rule_table_name_len <= 0: raise serializers.ValidationError("RuleTable名未入力", "rule_table_name") # 文字数チェック if rule_table_name_len > self.RULE_TABLE_NAEM_LENGTH: raise serializers.ValidationError( "RuleTable名 入力文字数不正 rule_table_name=%s, req_len=%s, valid_len=%s" % (rule_table_name, rule_table_name_len, self.RULE_TABLE_NAEM_LENGTH), "rule_table_name") # 半角英数字チェック re_obj = re.match(self.RULE_TABLE_NAME_PATTERN, rule_table_name) if re_obj is None: raise serializers.ValidationError( "RuleTable名 入力文字不正 rule_table_name=%s" % (rule_table_name), "rule_table_name") # 絵文字チェック value_list = self.EMO_CHK.is_emotion(rule_table_name) if len(value_list) > 0: raise serializers.ValidationError("RuleTable名 入力文字不正", "rule_table_name") return rule_table_name def validate_mail_address(self, mail_address): mail_address_len = len(mail_address) # 文字数チェック if (mail_address_len) > self.MAIL_ADDRESS_LENGTH: raise serializers.ValidationError( "メールアドレス 入力文字数不正 mail_address=%s, req_len=%s, valid_len=%s" % (mail_address, mail_address_len, self.MAIL_ADDRESS_LENGTH), "mail_address") # 絵文字チェック value_list = self.EMO_CHK.is_emotion(mail_address) if len(value_list) > 0: raise serializers.ValidationError("メールアドレス 入力文字不正", "mail_address") # メールアドレスの形式チェック if not is_addresses(mail_address): raise serializers.ValidationError("メールアドレス 形式不正", "mail_address") return mail_address def validate_unknown_event_notification(self, unknown_event_notification): """ 通知種別チェック """ if unknown_event_notification not in self.NOTIFY_TYPES: raise serializers.ValidationError("未知事象通知設定が不正", "unknown_event_notification") return unknown_event_notification
def _validate(self, rq, error_msg, request): """ [概要] 入力チェック [引数] rq: dict リクエストされた入力データ error_msg: dict [戻り値] """ logger.logic_log('LOSI00001', 'data: %s, error_msg:%s' % (rq, error_msg)) error_flag = False emo_chk = UnicodeCheck() emo_flag = False emo_flag_ita_disp_name = False emo_flag_hostname = False if len(rq['mail_disp_name']) == 0: error_flag = True error_msg['mail_disp_name'] += get_message( 'MOSJA27201', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07001', 'mail_disp_name', request=request) if len(rq['mail_disp_name']) > 64: error_flag = True error_msg['mail_disp_name'] += get_message( 'MOSJA27202', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07002', 'mail_disp_name', 64, rq['mail_disp_name'], request=request) # 絵文字チェック value_list = emo_chk.is_emotion(rq['mail_disp_name']) if len(value_list) > 0: error_flag = True emo_flag = True error_msg['mail_disp_name'] += get_message( 'MOSJA27216', request.user.get_lang_mode(), showMsgId=False) + '\n' if len(rq['protocol']) == 0: error_flag = True error_msg['protocol'] += get_message( 'MOSJA27212', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07001', 'protocol', request=request) if len(rq['protocol']) > 64: error_flag = True error_msg['protocol'] += get_message( 'MOSJA27213', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07002', 'protocol', 64, rq['protocol'], request=request) if len(rq['smtp_server']) == 0: error_flag = True error_msg['smtp_server'] += get_message( 'MOSJA27203', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07001', 'smtp_server', request=request) if len(rq['smtp_server']) > 128: error_flag = True error_msg['smtp_server'] += get_message( 'MOSJA27204', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07002', 'smtp_server', 64, rq['smtp_server'], request=request) # 絵文字チェック value_list = emo_chk.is_emotion(rq['smtp_server']) if len(value_list) > 0: error_flag = True error_msg['smtp_server'] += get_message( 'MOSJA27217', request.user.get_lang_mode(), showMsgId=False) + '\n' if len(rq['port']) == 0: error_flag = True error_msg['port'] += get_message( 'MOSJA27205', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07001', 'port', request=request) try: tmp_port = int(rq['port']) if 0 > tmp_port or tmp_port > 65535: error_flag = True error_msg['port'] += get_message( 'MOSJA27206', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07003', 'port', rq['port'], request=request) except ValueError: error_flag = True error_msg['port'] += get_message( 'MOSJA27206', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07003', 'port', rq['port'], request=request) if len(rq['user']) > 64: error_flag = True error_msg['user'] += get_message( 'MOSJA27207', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07002', 'user', 64, rq['user'], request=request) # 絵文字チェック value_list = emo_chk.is_emotion(rq['user']) if len(value_list) > 0: error_flag = True error_msg['user'] += get_message('MOSJA27218', request.user.get_lang_mode(), showMsgId=False) + '\n' if len(rq['password']) > 64: error_flag = True error_msg['password'] += get_message( 'MOSJA27208', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07002', 'password', 64, rq['password'], request=request) # 絵文字チェック value_list = emo_chk.is_emotion(rq['password']) if len(value_list) > 0: error_flag = True error_msg['password'] += get_message('MOSJA27219', request.user.get_lang_mode(), showMsgId=False) + '\n' if not emo_flag: duplication = MailDriver.objects.filter( mail_disp_name=rq['mail_disp_name']) if len(duplication) == 1 and int( rq['mail_driver_id']) != duplication[0].mail_driver_id: error_flag = True error_msg['mail_disp_name'] += get_message( 'MOSJA27209', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07004', 'mail_disp_name', rq['mail_disp_name'], request=request) if error_flag == False: # 疎通確認 resp_code = -1 try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: resp_code = sock.connect_ex( (rq['smtp_server'], int(rq['port']))) # host名名前解決が必要/etc/hostsとか sock.close() except Exception as e: pass if resp_code != 0: error_flag = True #todo 仮でこのエラーは名前に入れている error_msg['mail_disp_name'] += get_message( 'MOSJA27215', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07005', rq['smtp_server'], rq['port'], request=request) return error_flag
def modify(self, json_str, request): """ [メソッド概要] グループのDB更新処理 """ logger.logic_log('LOSI00001', 'None', request=request) error_flag = False error_msg = { 'mail_disp_name': '', 'protocol': '', 'smtp_server': '', 'port': '', 'user': '', 'password': '', } now = datetime.datetime.now(pytz.timezone('UTC')) emo_chk = UnicodeCheck() # 成功時データ response = { "status": "success", } try: rq = json_str['json_str'] ope = int(rq['ope']) #削除以外の場合の入力チェック if ope != defs.DABASE_OPECODE.OPE_DELETE: error_flag = self._validate(rq, error_msg, request) if error_flag: raise UserWarning('validation error.') # パスワードを暗号化 空なら空文字 cipher = AESCipher(settings.AES_KEY) if ope == defs.DABASE_OPECODE.OPE_UPDATE: encrypted_password = cipher.encrypt( rq['password']) if rq['password'] else '' driver_info_mod = MailDriver.objects.get( mail_driver_id=rq['mail_driver_id']) driver_info_mod.mail_disp_name = rq['mail_disp_name'] driver_info_mod.protocol = rq['protocol'] driver_info_mod.smtp_server = rq['smtp_server'] driver_info_mod.port = rq['port'] driver_info_mod.user = rq['user'] driver_info_mod.password = encrypted_password driver_info_mod.last_update_user = request.user.user_name driver_info_mod.last_update_timestamp = now driver_info_mod.save(force_update=True) elif ope == defs.DABASE_OPECODE.OPE_DELETE: MailDriver.objects.filter(pk=rq['mail_driver_id']).delete() elif ope == defs.DABASE_OPECODE.OPE_INSERT: encrypted_password = cipher.encrypt( rq['password']) if rq['password'] else '' driver_info_reg = MailDriver( mail_disp_name=rq['mail_disp_name'], protocol=rq['protocol'], smtp_server=rq['smtp_server'], port=rq['port'], user=rq['user'], password=encrypted_password, last_update_user=request.user.user_name, last_update_timestamp=now).save(force_insert=True) except MailDriver.DoesNotExist: logger.logic_log('LOSM07006', "mail_driver_id", mail_driver_id, request=request) except Exception as e: logger.logic_log('LOSI00005', traceback.format_exc(), request=request) response = { 'status': 'failure', 'error_msg': error_msg, # エラー詳細(エラーアイコンで出す) } logger.logic_log('LOSI00002', 'response=%s' % response, request=request) return response
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.emo_chk = UnicodeCheck()
class RuleTypeForm(forms.Form): rule_type_name_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA11003', } summary_errors = { 'max_length': 'MOSJA11004', } rule_table_name_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA11005', } rule_type_name = forms.CharField( label="ルール種別名称", max_length=64, error_messages=rule_type_name_errors) #unique summary = forms.CharField(label="概要", max_length=4000, required=False, error_messages=summary_errors) rule_table_name = forms.CharField( label="RuleTable名", max_length=64, error_messages=rule_table_name_errors) #unique required_css_class = 'tooltip-input validation-input' error_css_class = 'tooltip-input validation-input' def __init__(self, pk, *args, **kwargs): super().__init__(*args, **kwargs) self.pk = pk self.emo_chk = UnicodeCheck() def clean_rule_type_name(self): d = self.cleaned_data['rule_type_name'] # 絵文字チェック if len(self.emo_chk.is_emotion(d)): self.add_error('rule_type_name', 'MOSJA11040') # 重複チェック duplication = RuleType.objects.filter(rule_type_name=d) if len(duplication) and duplication[0].disuse_flag == '0': # 使用中のルール種別と重複 self.add_error('rule_type_name', 'MOSJA11043') elif len(duplication) and duplication[0].disuse_flag == '1': # 削除済みのものと重複 self.add_error('rule_type_name', 'MOSJA11044') return d def clean_summary(self): d = self.cleaned_data['summary'] # 絵文字チェック if len(self.emo_chk.is_emotion(d)): self.add_error('summary', 'MOSJA11041') return d def clean_rule_table_name(self): d = self.cleaned_data['rule_table_name'] # 絵文字チェック if len(self.emo_chk.is_emotion(d)): self.add_error('rule_table_name', 'MOSJA11042') # 半角英数字チェック re_obj = re.match('^[a-zA-Z0-9]+$', d) if re_obj == None: self.add_error('rule_table_name', 'MOSJA00240') # 重複チェック duplication = RuleType.objects.filter(rule_table_name=d) if len(duplication) and duplication[0].disuse_flag == '0': # 使用中のルール種別と重複 self.add_error('rule_table_name', 'MOSJA11045') elif len(duplication) and duplication[0].disuse_flag == '1': # 削除済みのものと重複 self.add_error('rule_table_name', 'MOSJA11046') return d
class SystemSerializer(serializers.ModelSerializer): LOG_STORAGE_PERIOD_MIN = 1 LOG_STORAGE_PERIOD_MAX = 7 SESSION_TIMEOUT_MIN = 1 SESSION_TIMEOUT_MAX = 60 PASSWORD_LIFETIME_MIN = 0 PASSWORD_LIFETIME_MAX = 180 PASS_ERROR_THRESHOLD_MIN = 0 PASS_ERROR_THRESHOLD_MAX = 10 ACCOUNT_LOCK_PERIOD_MIN = 1 ACCOUNT_LOCK_PERIOD_MAX = 120 PASSWORD_GENERATION_MIN = 0 PASSWORD_GENERATION_MAX = 5 PASSWORD_INITTIME_MIN = 0 PASSWORD_INITTIME_MAX = 72 ACCOUNT_LOCK_MAX_TIMES_MIN = 0 ACCOUNT_LOCK_MAX_TIMES_MAX = 10 DISUSEFLAG_LIST = ['0', '1', ] TARGET_GROUP_LIST_MAX = 30 IPADDR_LOGIN_RETRY_MIN = 0 IPADDR_LOGIN_RETRY_MAX = 1000 EMO_CHK = UnicodeCheck() EMAIL_PATTERN = r'^([\w!#$%&\'*+\-\/=?^`{|}~]+(\.[\w!#$%&\'*+\-\/=?^`{|}~]+)*|"([\w!#$%&\'*+\-\/=?^`{|}~. ()<>\[\]:;@,]|\\[\\"])+")@(([a-zA-Z\d\-]+\.)+[a-zA-Z]+|\[(\d{1,3}(\.\d{1,3}){3}|IPv6:[\da-fA-F]{0,4}(:[\da-fA-F]{0,4}){1,5}(:\d{1,3}(\.\d{1,3}){3}|(:[\da-fA-F]{0,4}){0,2}))\])$' HOUR_PATTERN = r'([0-2]?[0-9])' class Meta: model = System fields = ( 'item_id', 'config_name', 'category', 'config_id', 'value', 'maintenance_flag' ) def validate(self, data): if not data['maintenance_flag']: return data if data['category'] not in defs.SYSTEM_SETTINGS.CATEGORY_LIST: raise serializers.ValidationError("不明なカテゴリー categ=%s" % (data['category'])) if data['category'] == 'LOG_STORAGE_PERIOD': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(ログ保存日数) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(ログ保存日数) val=%s" % (data['value'])) val_tmp = int(data['value']) if val_tmp < self.LOG_STORAGE_PERIOD_MIN or val_tmp > self.LOG_STORAGE_PERIOD_MAX: raise serializers.ValidationError("無効なログ保存日数 val=%s" % (val_tmp)) if data['category'] == 'SESSION_TIMEOUT': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(セッションタイムアウト値) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(セッションタイムアウト値) val=%s" % (data['value'])) val_tmp = int(data['value']) if val_tmp < self.SESSION_TIMEOUT_MIN or val_tmp > self.SESSION_TIMEOUT_MAX: raise serializers.ValidationError("無効なセッションタイムアウト値 val=%s" % (val_tmp)) if data['category'] == 'PASSWORD': if data['config_id'] == 'Pass_Valid_Period': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(パスワード有効期間) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(パスワード有効期間) val=%s" % (data['value'])) val_tmp = int(data['value']) if val_tmp < self.PASSWORD_LIFETIME_MIN or val_tmp > self.PASSWORD_LIFETIME_MAX: raise serializers.ValidationError("無効なパスワード有効期間 val=%s" % (val_tmp)) if len(data['value']) > 1 and data['value'][0] == '0': raise serializers.ValidationError("無効なパスワード有効期間 val=%s" % (data['value'])) if data['config_id'] == 'Pass_generate_manage': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(同一パスワード設定不可世代数) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(同一パスワード設定不可世代数) val=%s" % (data['value'])) val_tmp = int(data['value']) if val_tmp < self.PASSWORD_GENERATION_MIN or val_tmp > self.PASSWORD_GENERATION_MAX: raise serializers.ValidationError("無効な同一パスワード設定不可世代数 val=%s" % (val_tmp)) if data['config_id'] == 'PASS_ERROR_THRESHOLD': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(パスワード誤り閾値) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(パスワード誤り閾値) val=%s" % (data['value'])) val_tmp = int(data['value']) if val_tmp < self.PASS_ERROR_THRESHOLD_MIN or val_tmp > self.PASS_ERROR_THRESHOLD_MAX: raise serializers.ValidationError("無効なパスワード誤り閾値 val=%s" % (val_tmp)) if len(data['value']) > 1 and data['value'][0] == '0': raise serializers.ValidationError("無効なパスワード誤り閾値 val=%s" % (data['value'])) if data['config_id'] == 'ACCOUNT_LOCK_PERIOD': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(アカウントロック継続期間) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(アカウントロック継続期間) val=%s" % (data['value'])) val_tmp = int(data['value']) if val_tmp < self.ACCOUNT_LOCK_PERIOD_MIN or val_tmp > self.ACCOUNT_LOCK_PERIOD_MAX: raise serializers.ValidationError("無効なアカウントロック継続期間 val=%s" % (val_tmp)) if len(data['value']) > 1 and data['value'][0] == '0': raise serializers.ValidationError("無効なアカウントロック継続期間 val=%s" % (data['value'])) if data['config_id'] == 'INITIAL_PASS_VALID_PERIOD': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(初期パスワード有効期間) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(初期パスワード有効期間) val=%s" % (data['value'])) val_tmp = int(data['value']) if val_tmp < self.PASSWORD_INITTIME_MIN or val_tmp > self.PASSWORD_INITTIME_MAX: raise serializers.ValidationError("無効な初期パスワード有効期間 val=%s" % (val_tmp)) if data['config_id'] == 'ACCOUNT_LOCK_MAX_TIMES': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(アカウントロック上限回数) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(アカウントロック上限回数) val=%s" % (data['value'])) val_tmp = int(data['value']) if val_tmp < self.ACCOUNT_LOCK_MAX_TIMES_MIN or val_tmp > self.ACCOUNT_LOCK_MAX_TIMES_MAX: raise serializers.ValidationError("無効なアカウントロック上限回数 val=%s" % (val_tmp)) if data['config_id'] == 'NOTIFICATION_DESTINATION_TYPE': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(メール通知種別) type=%s, val=%s" % (type(data['value']), data['value'])) if not (data['value'] in ('0','1','2')): raise serializers.ValidationError("予期せぬ型(メール通知種別) type=%s, val=%s" % (type(data['value']), data['value'])) # ログインID形式チェック if data['config_id'] == 'NOTIFICATION_DESTINATION': if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(メール通知先ログインID) type=%s, val=%s" % (type(data['value']), data['value'])) # 絵文字チェック value_list = self.EMO_CHK.is_emotion(data['value']) if len(value_list) > 0: raise serializers.ValidationError("メール通知先ログインIDに使用できない文字が含まれています。") # 同一IP連続ログイン試行上限チェック if data['config_id'] == 'IPADDR_LOGIN_RETRY_MAX': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(同一IPアドレス連続ログイン試行上限) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(同一IPアドレス連続ログイン試行上限) val=%s" % (data['value'])) val_tmp = int(data['value']) if val_tmp < self.IPADDR_LOGIN_RETRY_MIN or val_tmp > self.IPADDR_LOGIN_RETRY_MAX: raise serializers.ValidationError("無効な同一IPアドレス連続ログイン試行上限 val=%s" % (val_tmp)) if data['category'] == 'ACTIVE_DIRECTORY': if data['config_id'] == 'ADCOLLABORATION': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(Active Directory連携値) type=%s, val=%s" % (type(data['value']), data['value'])) if data['value'] not in self.DISUSEFLAG_LIST: raise serializers.ValidationError("無効なActive Directory連携値 val=%s" % (data['value'])) if data['config_id'] == 'ADMINISTRATOR_USER': value_len = len(data['value']) if value_len < 1: raise serializers.ValidationError("管理者ユーザは必須項目です") # 絵文字チェック value_list = self.EMO_CHK.is_emotion(data['value']) if len(value_list) > 0: raise serializers.ValidationError("管理者ユーザに使用できない文字が含まれています。") if data['config_id'] == 'ADMINISTRATOR_PW': value_len = len(data['value']) if value_len < 1: raise serializers.ValidationError("管理者パスワードは必須項目です") # 絵文字チェック value_list = self.EMO_CHK.is_emotion(data['value']) if len(value_list) > 0: raise serializers.ValidationError("管理者パスワードに使用できない文字が含まれています。") if data['config_id'] == 'ACCESS_POINT': value_len = len(data['value']) if value_len < 1: raise serializers.ValidationError("接続先は必須項目です") # 絵文字チェック value_list = self.EMO_CHK.is_emotion(data['value']) if len(value_list) > 0: raise serializers.ValidationError("接続先に使用できない文字が含まれています。") if data['config_id'] == 'CONNECTION_TIMEOUT': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(接続タイムアウト値) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(接続タイムアウト値) val=%s" % (data['value'])) if data['config_id'] == 'READ_TIMEOUT': if isinstance(data['value'], int): data['value'] = str(data['value']) if not isinstance(data['value'], str): raise serializers.ValidationError("予期せぬ型(読み取りタイムアウト値) type=%s, val=%s" % (type(data['value']), data['value'])) if not data['value'].isdigit(): raise serializers.ValidationError("数値以外の値(読み取りタイムアウト値) val=%s" % (data['value'])) if data['config_id'] == 'AUTHSERVER_SEARCH_CHAR': value_len = len(data['value']) if value_len < 1: raise serializers.ValidationError("認証サーバ検索文字は必須項目です") # 絵文字チェック value_list = self.EMO_CHK.is_emotion(data['value']) if len(value_list) > 0: raise serializers.ValidationError("認証サーバ検索文字に使用できない文字が含まれています。") if data['config_id'] == 'TARGET_GROUP_LIST': targetlist = {} value_len = len(data['value']) if value_len < 1: raise serializers.ValidationError("対象グループリストは必須項目です") value_list = data['value'] if isinstance(value_list, str): try: value_list = ast.literal_eval(value_list) except Exception as e: raise serializers.ValidationError("対象グループリストの値が不正です val=%s" % (data['value'])) if not isinstance(value_list, list): raise serializers.ValidationError("対象グループリストの値が不正です val=%s" % (data['value'])) if len(value_list) <= 0: raise serializers.ValidationError("対象グループリストは必須項目です") if len(value_list) > self.TARGET_GROUP_LIST_MAX: raise serializers.ValidationError("対象グループリストは %s 件までです" % (self.TARGET_GROUP_LIST_MAX)) for i,val in enumerate(value_list): if not isinstance(val, dict): raise serializers.ValidationError("対象グループリストの値が不正です val=%s" % (val)) for k, v in val.items(): if not k: targetlist[ i * 2 ] = "対象グループリストの値が不正です val=%s" % (val) continue else: # 絵文字チェック value_list = self.EMO_CHK.is_emotion(k) if len(value_list) > 0: targetlist[ i * 2 ] = "対象グループリストの値に使用できない文字が含まれています。" continue if not v: targetlist[ i * 2 + 1 ] = "対象グループリストの値が不正です val=%s" % (val) continue else: # 絵文字チェック value_list = self.EMO_CHK.is_emotion(v) if len(value_list) > 0: targetlist[ i * 2 + 1] = "対象グループリストの値に使用できない文字が含まれています。" continue if len(targetlist) > 0: raise serializers.ValidationError(targetlist) if data['config_id'] == 'AD_LINKAGE_TIMER': value_len = len(data['value']) values = data['value'].split(',') # 未入力チェック if not value_len: raise serializers.ValidationError("必須項目が入力されていません。入力してください。") # 00~23 チェック for x in values: if re.match(self.HOUR_PATTERN, x) is None: raise serializers.ValidationError("00から23の数値を入力してください。") return data
def modify_mailaddr(request): """ [メソッド概要] メールアドレス変更処理 """ msg = {} error_msg = {} result = 'success' now = datetime.datetime.now(pytz.timezone('UTC')) mail_pass = request.POST.get('password', '') mail_addr = request.POST.get('mail', '') uid = request.user.user_id login_id = request.user.login_id emo_chk = UnicodeCheck() logger.logic_log('LOSI00001', mail_pass, mail_addr, request=request) if uid == '': error_msg = get_message('MOSJA32009', request.user.get_lang_mode()) logger.user_log('LOSM17000') return HttpResponseServerError(error_msg) try: # パスワードチェック error_msg = _check_password(request, mail_pass, uid) # 値チェック if mail_addr == request.user.mail_address: error_msg['txtMailAddr'] = get_message( 'MOSJA31008', request.user.get_lang_mode()) logger.user_log('LOSI10001', login_id, mail_addr, request=request) logger.logic_log('LOSM10000', request=request) # バリデーションチェック dot_string = r'[\w!#$%&\'*+\-\/=?^`{|}~]+(\.[\w!#$%&\'*+\-\/=?^`{|}~]+)*' quoted_string = r'"([\w!#$%&\'*+\-\/=?^`{|}~. ()<>\[\]:;@,]|\\[\\"])+"' domain = r'([a-zA-Z\d\-]+\.)+[a-zA-Z]+' ip_v4 = r'(\d{1,3}(\.\d{1,3}){3}' ip_v6 = r'IPv6:[\da-fA-F]{0,4}(:[\da-fA-F]{0,4}){1,5}(:\d{1,3}(\.\d{1,3}){3}|(:[\da-fA-F]{0,4}){0,2}))' mail_ip_addr = r'\[' + ip_v4 + r'|' + ip_v6 + r'\]' mail_pattern = r'^(' + dot_string + r'|' + quoted_string + \ r')@(' + domain + r'|' + mail_ip_addr + r')$' if len(mail_addr) <= 0: error_msg['txtMailAddr'] = get_message( 'MOSJA31004', request.user.get_lang_mode()) logger.user_log('LOSI10002', request=request) logger.logic_log('LOSM10000', request=request) elif len(mail_addr) > 256: error_msg['txtMailAddr'] = get_message( 'MOSJA31005', request.user.get_lang_mode()) logger.user_log('LOSI10003', request=request) logger.logic_log('LOSM10000', request=request) # 絵文字チェック value_list = emo_chk.is_emotion(mail_addr) if len(value_list) > 0: error_msg['txtMailAddr'] = get_message( 'MOSJA31018', request.user.get_lang_mode()) logger.user_log('LOSI10011', request=request) logger.logic_log('LOSM10000', request=request) elif not re.match(mail_pattern, mail_addr): error_msg['txtMailAddr'] = get_message( 'MOSJA31006', request.user.get_lang_mode()) logger.user_log('LOSI10004', request=request) logger.logic_log('LOSM10000', request=request) # 機密情報URL生成 req_protcol = request.scheme req_host = request.get_host() modify_url = reverse('web_app:user:user_determ_mailaddr') hash_login = OaseCommon.oase_hash(login_id) hash_maddr = OaseCommon.oase_hash(mail_addr) modify_url = '%s://%s%s?arg=%s&tok=%s' % ( req_protcol, req_host, modify_url, hash_login, hash_maddr) # 重複チェック error_msg = _check_duplication(request, error_msg, mail_addr, now, login_id) # DB保存 hour_expire = int( System.objects.get(config_id='MAILADDR_URL_VALID_PERIOD').value) url_expire = now + datetime.timedelta(hours=hour_expire) rcnt = MailAddressModify.objects.filter( login_id=login_id, login_id__contains=login_id).count() if rcnt > 0: MailAddressModify.objects.filter( login_id=login_id, login_id__contains=login_id).update( mail_address=mail_addr, mail_address_hash=hash_maddr, url_expire=url_expire, last_update_timestamp=now, last_update_user=request.user.user_name) else: MailAddressModify(login_id=login_id, mail_address=mail_addr, mail_address_hash=hash_maddr, url_expire=url_expire, last_update_timestamp=now, last_update_user=request.user.user_name).save( force_insert=True) if len(error_msg) == 0: # 署名用URL生成 req_protcol = request.scheme req_host = request.get_host() login_url = reverse('web_app:top:login') inquiry_url = reverse('web_app:top:inquiry') login_url = '%s://%s%s' % (req_protcol, req_host, login_url) inquiry_url = '%s://%s%s' % (req_protcol, req_host, inquiry_url) # メール送信 obj_smtp = OASEMailSMTP(request=request) obj_mail = OASEMailModifyMailAddressNotify(mail_addr, request.user.user_name, hour_expire, modify_url, inquiry_url, login_url) send_result = obj_smtp.send_mail(obj_mail) if send_result: error_msg['system'] = get_message(send_result, request.user.get_lang_mode()) logger.user_log('LOSI10006', request=request) logger.logic_log('LOSM10000', request=request) except Exception as e: logger.logic_log('LOSI00005', traceback.format_exc(), request=request) error_msg['system'] = get_message('MOSJA31014', request.user.get_lang_mode()) if len(error_msg) > 0: result = 'failure' else: msg['system'] = get_message('MOSJA31017', request.user.get_lang_mode()) data = { 'status': result, 'msg': msg, 'error_msg': error_msg, } respdata = json.dumps(data) logger.logic_log('LOSI00002', result, request=request) return HttpResponse(respdata, content_type="application/json")
def _validate(self, rq, error_msg, request, mode): """ [概要] 入力チェック [引数] rq: dict リクエストされた入力データ error_msg: dict [戻り値] """ logger.logic_log('LOSI00001', 'data: %s, error_msg:%s' % (rq, error_msg)) error_flag = False emo_chk = UnicodeCheck() emo_flag_zabbix_disp_name = False emo_flag_hostname = False rule_type_id_error_flag = False lang = request.user.get_lang_mode() # zabbix_disp_name未入力チェック if len(rq['zabbix_disp_name']) == 0: error_flag = True error_msg['zabbix_disp_name'] += get_message('MOSJA26102', lang) + '\n' logger.user_log('LOSM07001', 'zabbix_disp_name', request=request) # zabbix_disp_name長さチェック if len(rq['zabbix_disp_name']) > 64: error_flag = True error_msg['zabbix_disp_name'] += get_message('MOSJA26103', lang) + '\n' logger.user_log('LOSM07002', 'zabbix_disp_name', 64, rq['zabbix_disp_name'], request=request) # zabbix_disp_name絵文字使用チェック value_list = emo_chk.is_emotion(rq['zabbix_disp_name']) if len(value_list) > 0: error_flag = True emo_flag_zabbix_disp_name = True error_msg['zabbix_disp_name'] += get_message('MOSJA26104', lang) + '\n' logger.user_log('LOSM07008', rq['zabbix_disp_name'], request=request) # protocol未入力チェック if len(rq['protocol']) == 0: error_flag = True error_msg['protocol'] += get_message('MOSJA26105', lang) + '\n' logger.user_log('LOSM07001', 'protocol', request=request) # protocol長さチェック if len(rq['protocol']) > 64: error_flag = True error_msg['protocol'] += get_message('MOSJA26106', lang) + '\n' logger.user_log('LOSM07002', 'protocol', 64, rq['protocol'], request=request) # hostname未入力チェック if len(rq['hostname']) == 0: error_flag = True error_msg['hostname'] += get_message('MOSJA26107', lang) + '\n' logger.user_log('LOSM07001', 'hostname', request=request) # hostname長さチェック if len(rq['hostname']) > 128: error_flag = True error_msg['hostname'] += get_message('MOSJA26108', lang) + '\n' logger.user_log('LOSM07002', 'hostname', 128, rq['hostname'], request=request) # hostname絵文字使用チェック value_list = emo_chk.is_emotion(rq['hostname']) if len(value_list) > 0: error_flag = True emo_flag_hostname = True error_msg['hostname'] += get_message('MOSJA26109', lang) + '\n' logger.user_log('LOSM07008', rq['hostname'], request=request) # port未入力チェック if len(rq['port']) == 0: error_flag = True error_msg['port'] += get_message('MOSJA26110', lang) + '\n' logger.user_log('LOSM07001', 'port', request=request) # port長さチェック try: tmp_port = int(rq['port']) if 0 > tmp_port or tmp_port > 65535: error_flag = True error_msg['port'] += get_message('MOSJA26111', lang) + '\n' logger.user_log('LOSM07003', 'port', rq['port'], request=request) except ValueError: error_flag = True error_msg['port'] += get_message('MOSJA26111', lang) + '\n' logger.user_log('LOSM07003', 'port', rq['port'], request=request) # username未入力チェック if len(rq['username']) == 0: error_flag = True error_msg['username'] += get_message('MOSJA26112', lang) + '\n' logger.user_log('LOSM07001', 'username', request=request) # username長さチェック if len(rq['username']) > 64: error_flag = True error_msg['username'] += get_message('MOSJA26113', lang) + '\n' logger.user_log('LOSM07002', 'username', 64, rq['username'], request=request) # username絵文字使用チェック value_list = emo_chk.is_emotion(rq['username']) if len(value_list) > 0: error_flag = True error_msg['username'] += get_message('MOSJA26114', lang) + '\n' logger.user_log('LOSM07008', rq['username'], request=request) # password未入力チェック if len(rq['password']) == 0: error_flag = True error_msg['password'] += get_message('MOSJA26115', lang) + '\n' logger.user_log('LOSM07001', 'password', request=request) # password長さチェック # 追加の場合 if rq['zabbix_adapter_id'] == '0': if len(rq['password']) > 64: error_flag = True error_msg['password'] += get_message('MOSJA26116', lang) + '\n' logger.user_log('LOSM07002', 'password', 64, rq['password'], request=request) # password絵文字使用チェック value_list = emo_chk.is_emotion(rq['password']) if len(value_list) > 0: error_flag = True error_msg['password'] += get_message('MOSJA26117', lang) + '\n' logger.user_log('LOSM07008', rq['password'], request=request) # 変更の場合 else: old_password = ZabbixAdapter.objects.get( zabbix_adapter_id=rq['zabbix_adapter_id']).password # パスワード復号 cipher = AESCipher(settings.AES_KEY) old_password_dec = cipher.decrypt(old_password) if old_password != rq['password']: if len(rq['password']) > 64: error_flag = True error_msg['password'] += get_message('MOSJA26116', lang) + '\n' logger.user_log('LOSM07002', 'password', 64, rq['password'], request=request) # password絵文字使用チェック value_list = emo_chk.is_emotion(rq['password']) if len(value_list) > 0: error_flag = True error_msg['password'] += get_message('MOSJA26117', lang) + '\n' logger.user_log('LOSM07008', rq['password'], request=request) # rule_type_id未入力チェック if len(rq['rule_type_id']) == 0: error_flag = True rule_type_id_error_flag = True error_msg['rule_type_id'] += get_message('MOSJA26118', lang) + '\n' logger.user_log('LOSM07001', 'rule_type_id', request=request) # rule_type_id存在チェック else: check_rule_id = RuleType.objects.filter( rule_type_id=rq['rule_type_id']) if len(check_rule_id) < 1: error_flag = True rule_type_id_error_flag = True error_msg['rule_type_id'] += get_message('MOSJA26119', lang) + '\n' logger.user_log('LOSM07001', 'rule_type_id', request=request) if not rule_type_id_error_flag: # 突合情報存在チェック # 条件名の数を取得 do_list = DataObject.objects.filter( rule_type_id=rq['rule_type_id']).values_list('data_object_id', flat=True) # Zabbix項目チェック for data_object_id, zabbix_response_key in rq['match_list'].items( ): id_name = 'zabbix-' + data_object_id error_msg.setdefault(id_name, '') # 条件名とZabbix項目の数があっているかチェック if len(do_list) != len(rq['match_list'].keys()): error_flag = True error_msg[id_name] += get_message( 'MOSJA26121', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07007', len(do_list), len(rq['match_list'].items()), request=request) if len(zabbix_response_key) == 0: error_flag = True error_msg[id_name] += get_message('MOSJA26122', lang) + '\n' logger.user_log('LOSM07001', 'zabbix_response_key', request=request) if len(zabbix_response_key) > 32: error_flag = True error_msg[id_name] += get_message('MOSJA26128', lang) + '\n' logger.user_log('LOSM07002', 'zabbix_response_key', 32, zabbix_response_key, request=request) # Zabbix項目絵文字使用チェック value_list = emo_chk.is_emotion(zabbix_response_key) if len(value_list) > 0: error_flag = True error_msg[id_name] += get_message('MOSJA26123', lang) + '\n' logger.user_log('LOSM07008', rq['zabbix_disp_name'], request=request) # 使用可能名チェック if zabbix_response_key not in ZABBIX_ITEMS: error_flag = True error_msg[id_name] += get_message('MOSJA26147', lang) + '\n' logger.user_log('LOSM07009', rq['zabbix_disp_name'], request=request) # zabbix_disp_name重複チェック if not emo_flag_zabbix_disp_name: duplication = ZabbixAdapter.objects.filter( zabbix_disp_name=rq['zabbix_disp_name']) if len(duplication) == 1 and int( rq['zabbix_adapter_id'] ) != duplication[0].zabbix_adapter_id: error_flag = True error_msg['zabbix_disp_name'] += get_message( 'MOSJA26124', lang) + '\n' logger.user_log('LOSM07004', 'zabbix_disp_name', rq['zabbix_disp_name'], request=request) # hostname重複チェック if not emo_flag_hostname: duplication = ZabbixAdapter.objects.filter( hostname=rq['hostname'], rule_type_id=rq['rule_type_id']) # ホスト名重複かつルール種別名が同一の場合 if len(duplication) == 1 and int( rq['zabbix_adapter_id'] ) != duplication[0].zabbix_adapter_id: error_flag = True error_msg['hostname'] += get_message( 'MOSJA26125', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07004', 'hostname', rq['hostname'], request=request) # 疎通確認 if not error_flag: resp_code = -1 try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: resp_code = sock.connect_ex( (rq['hostname'], int(rq['port']))) # host名名前解決が必要/etc/hostsとか sock.close() except: pass if resp_code != 0: error_flag = True error_msg['hostname'] += get_message('MOSJA26126', lang) + '\n' logger.user_log('LOSM07005', rq['hostname'], rq['port'], request=request) logger.logic_log('LOSI00002', 'return: %s' % error_flag) return error_flag
def _validate(json_str, group_ids_diff=[], request=None): """ [メソッド概要] 入力チェック [引数] request :logger.logic_logでuserId sessionIDを表示するために使用する [戻り値] error_flag error_msg_user_name error_msg_login_id error_msg_mail error_msg_user_group """ error_flag = False error_msg_user_name = {} error_msg_login_id = {} error_msg_mail = {} error_msg_user_group = {} chk_login = [] chk_mail = [] loginID_pattern = r'^[a-zA-Z0-9.@_\-]+$' mail_pattern = r'^([\w!#$%&\'*+\-\/=?^`{|}~]+(\.[\w!#$%&\'*+\-\/=?^`{|}~]+)*|"([\w!#$%&\'*+\-\/=?^`{|}~. ()<>\[\]:;@,]|\\[\\"])+")@(([a-zA-Z\d\-]+\.)+[a-zA-Z]+|\[(\d{1,3}(\.\d{1,3}){3}|IPv6:[\da-fA-F]{0,4}(:[\da-fA-F]{0,4}){1,5}(:\d{1,3}(\.\d{1,3}){3}|(:[\da-fA-F]{0,4}){0,2}))\])$' emo_chk = UnicodeCheck() logger.logic_log('LOSI00001', 'json_str: %s' % json_str, request=request) # jsonの形式チェック if {'insertInfo','updateInfo','delInfo'} != set(list(json_str.keys())): logger.user_log('LOSM05002', request=request) raise TypeError( 'json_strの形式不正') loginID_repatter = re.compile(loginID_pattern) mail_repatter = re.compile(mail_pattern) for k,v in json_str.items(): for rq in v: # 削除の場合は飛ばす if k == 'delInfo': continue error_msg_user_name[rq['row_id']] = '' error_msg_login_id[rq['row_id']] = '' error_msg_mail[rq['row_id']] = '' error_msg_user_group[rq['row_id']] = '' if 'user_name' in rq and len(rq['user_name']) == 0: error_msg_user_name[rq['row_id']] += get_message('MOSJA24005', request.user.get_lang_mode()) + '\n' if 'login_id' in rq and len(rq['login_id']) == 0: error_msg_login_id[rq['row_id']] += get_message('MOSJA24006', request.user.get_lang_mode()) + '\n' if 'mail' in rq and len(rq['mail']) == 0: error_msg_mail[rq['row_id']] += get_message('MOSJA24007', request.user.get_lang_mode()) + '\n' if k == 'insertInfo': if 'add_group_id' not in rq: error_msg_user_group[rq['row_id']] += get_message('MOSJA24008', request.user.get_lang_mode()) + '\n' if 'add_group_id' in rq: for gid in rq['add_group_id']: if len(gid) == 0: error_msg_user_group[rq['row_id']] += get_message('MOSJA24008', request.user.get_lang_mode()) + '\n' break gid = int(gid) if gid in group_ids_diff: error_msg_user_group[rq['row_id']] += get_message('MOSJA24016', request.user.get_lang_mode()) + '\n' break if 'del_group_id' in rq: for gid in rq['del_group_id']: gid = int(gid) if gid in group_ids_diff: error_msg_user_group[rq['row_id']] += get_message('MOSJA24019', request.user.get_lang_mode()) + '\n' break if 'user_name' in rq and len(rq['user_name']) > 64: error_msg_user_name[rq['row_id']] += get_message('MOSJA24011', request.user.get_lang_mode()) + '\n' if 'login_id' in rq and len(rq['login_id']) > 32: error_msg_login_id[rq['row_id']] += get_message('MOSJA24012', request.user.get_lang_mode()) + '\n' if 'mail' in rq and len(rq['mail']) > 256: error_msg_mail[rq['row_id']] += get_message('MOSJA24013', request.user.get_lang_mode()) + '\n' if chk_login.count(rq['login_id']) > 0: error_msg_login_id[rq['row_id']] += get_message('MOSJA24017', request.user.get_lang_mode()) + '\n' # user_name絵文字チェック value_list = emo_chk.is_emotion(rq['user_name']) if len(value_list) > 0: error_msg_user_name[rq['row_id']] += get_message('MOSJA24022', request.user.get_lang_mode(), strConName='ユーザ名') + '\n' # login_id絵文字チェック value_list = emo_chk.is_emotion(rq['login_id']) if len(value_list) > 0: error_msg_login_id[rq['row_id']] += get_message('MOSJA24022', request.user.get_lang_mode(), strConName='ログインID') + '\n' # mail絵文字チェック value_list = emo_chk.is_emotion(rq['mail']) if len(value_list) > 0: error_msg_mail[rq['row_id']] += get_message('MOSJA24022', request.user.get_lang_mode(), strConName='メールアドレス') + '\n' else: duplication = User.objects.filter(login_id=rq['login_id'], login_id__contains=rq['login_id'], sso_id=0) if len(duplication) == 1 and int(rq['user_id']) != duplication[0].user_id: error_msg_login_id[rq['row_id']] += get_message('MOSJA24017', request.user.get_lang_mode()) + '\n' if chk_mail.count(rq['mail']) > 0: error_msg_mail[rq['row_id']] += get_message('MOSJA24018', request.user.get_lang_mode()) + '\n' else: duplication = User.objects.filter(mail_address=rq['mail'], sso_id=0) if len(duplication) == 1 and int(rq['user_id']) != duplication[0].user_id: error_msg_mail[rq['row_id']] += get_message('MOSJA24018', request.user.get_lang_mode()) + '\n' if 'login_id' in rq and len(rq['login_id']) != 0: re_obj = loginID_repatter.match(rq['login_id']) if not re_obj: error_msg_login_id[rq['row_id']] += get_message('MOSJA24021', request.user.get_lang_mode()) + '\n' if 'mail' in rq and len(rq['mail']) != 0: re_obj = mail_repatter.match(rq['mail']) if not re_obj: error_msg_mail[rq['row_id']] += get_message('MOSJA24014', request.user.get_lang_mode()) + '\n' if len(error_msg_user_name[rq['row_id']]) > 0: error_flag = True elif len(error_msg_login_id[rq['row_id']]) > 0: error_flag = True elif len(error_msg_mail[rq['row_id']]) > 0: error_flag = True elif len(error_msg_user_group[rq['row_id']]) > 0: error_flag = True chk_login.append(rq['login_id']) chk_mail.append(rq['mail']) logger.logic_log('LOSI00002', 'error_flag: %s' % error_flag, request=request) return error_flag, error_msg_user_name, error_msg_login_id, error_msg_mail, error_msg_user_group
class RuleTypeForm(forms.Form): rule_type_name_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA11003', } summary_errors = { 'max_length': 'MOSJA11004', } rule_table_name_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA11005', } mail_address_errors = { 'max_length': 'MOSJA11054', } rule_type_name = forms.CharField( label="ルール種別名称", max_length=64, error_messages=rule_type_name_errors) #unique summary = forms.CharField(label="概要", max_length=4000, required=False, error_messages=summary_errors) rule_table_name = forms.CharField( label="RuleTable名", max_length=64, error_messages=rule_table_name_errors) #unique mail_address = forms.CharField(label="通知先メールアドレス", max_length=512, required=False, error_messages=mail_address_errors) unknown_event_notification = forms.CharField(label="未知事象通知設定", max_length=1) required_css_class = 'tooltip-input validation-input' error_css_class = 'tooltip-input validation-input' def __init__(self, pk, *args, **kwargs): super().__init__(*args, **kwargs) self.pk = pk self.emo_chk = UnicodeCheck() def clean_rule_type_name(self): d = self.cleaned_data['rule_type_name'] # 絵文字チェック if len(self.emo_chk.is_emotion(d)): self.add_error('rule_type_name', 'MOSJA11040') # 重複チェック duplication = RuleType.objects.filter(rule_type_name=d) if len(duplication) and duplication[0].disuse_flag == '0': # 使用中のルール種別と重複 self.add_error('rule_type_name', 'MOSJA11043') elif len(duplication) and duplication[0].disuse_flag == '1': # 削除済みのものと重複 self.add_error('rule_type_name', 'MOSJA11044') return d def clean_summary(self): d = self.cleaned_data['summary'] # 絵文字チェック if len(self.emo_chk.is_emotion(d)): self.add_error('summary', 'MOSJA11041') return d def clean_rule_table_name(self): d = self.cleaned_data['rule_table_name'] # 絵文字チェック if len(self.emo_chk.is_emotion(d)): self.add_error('rule_table_name', 'MOSJA11042') # 半角英数字チェック re_obj = re.match('^[a-zA-Z0-9]+$', d) if re_obj == None: self.add_error('rule_table_name', 'MOSJA00240') # 重複チェック duplication = RuleType.objects.filter(rule_table_name=d) if len(duplication) and duplication[0].disuse_flag == '0': # 使用中のルール種別と重複 self.add_error('rule_table_name', 'MOSJA11045') elif len(duplication) and duplication[0].disuse_flag == '1': # 削除済みのものと重複 self.add_error('rule_table_name', 'MOSJA11046') return d def clean_mail_address(self): """ メールアドレスチェック """ mail_address = self.cleaned_data['mail_address'] # 絵文字チェック if len(self.emo_chk.is_emotion(mail_address)): self.add_error('mail_address', 'MOSJA11055') # メールアドレスの形式チェック if not is_addresses(mail_address): self.add_error('mail_address', 'MOSJA11056') return mail_address def clean_unknown_event_notification(self): """ 通知種別チェック """ notify_type = self.cleaned_data['unknown_event_notification'] if notify_type not in ['0', '1', '2', '3']: self.add_error('unknown_event_notification', 'MOSJA11059') return notify_type
class RuleTypeSerializer(serializers.ModelSerializer): GENERATION_MIN = 1 GENERATION_MAX = 10 RULE_TYPE_NAME_LENGTH = 64 SUMMARY_LENGTH = 4000 RULE_TABLE_NAEM_LENGTH = 64 RULE_TABLE_NAME_PATTERN = '^[a-zA-Z0-9]+$' EMO_CHK = UnicodeCheck() class Meta: model = RuleType fields = ( 'rule_type_id', 'rule_type_name', 'summary', 'rule_table_name', 'generation_limit', 'group_id', 'artifact_id', 'container_id_prefix_staging', 'container_id_prefix_product', 'current_container_id_staging', 'current_container_id_product', 'last_update_timestamp', 'last_update_user', ) def validate_generation_limit(self, generation_limit): if generation_limit < self.GENERATION_MIN or generation_limit > self.GENERATION_MAX: raise serializers.ValidationError("不正な世代管理数 generation_limit=%s" % (generation_limit)) return generation_limit def validate_rule_type_name(self, rule_type_name): rule_type_name_len = len(rule_type_name) # 未入力チェック if rule_type_name_len <= 0: raise serializers.ValidationError("ルール種別名称未入力", "rule_type_name") # 文字数チェック if rule_type_name_len > self.RULE_TYPE_NAME_LENGTH: raise serializers.ValidationError( "ルール種別名称 入力文字数不正 rule_type_name=%s, req_len=%s, valid_len=%s" % (rule_type_name, rule_type_name_len, self.RULE_TYPE_NAME_LENGTH), "rule_type_name") # 絵文字チェック value_list = self.EMO_CHK.is_emotion(rule_type_name) if len(value_list) > 0: raise serializers.ValidationError("ルール種別名称 入力文字不正", "rule_type_name") return rule_type_name def validate_summary(self, summary): # 文字数チェック summary_len = len(summary) if summary_len > self.SUMMARY_LENGTH: raise serializers.ValidationError( "概要 入力文字数不正 summary=%s, req_len=%s, valid_len=%s" % (summary, summary_len, self.SUMMARY_LENGTH), "summary") value_list = self.EMO_CHK.is_emotion(summary) if len(value_list) > 0: raise serializers.ValidationError("概要 入力文字不正", "summary") return summary def validate_rule_table_name(self, rule_table_name): rule_table_name_len = len(rule_table_name) # 未入力チェック if rule_table_name_len <= 0: raise serializers.ValidationError("RuleTable名未入力", "rule_table_name") # 文字数チェック if rule_table_name_len > self.RULE_TABLE_NAEM_LENGTH: raise serializers.ValidationError( "RuleTable名 入力文字数不正 rule_table_name=%s, req_len=%s, valid_len=%s" % (rule_table_name, rule_table_name_len, self.RULE_TABLE_NAEM_LENGTH), "rule_table_name") # 半角英数字チェック re_obj = re.match(self.RULE_TABLE_NAME_PATTERN, rule_table_name) if re_obj is None: raise serializers.ValidationError( "RuleTable名 入力文字不正 rule_table_name=%s" % (rule_table_name), "rule_table_name") # 絵文字チェック value_list = self.EMO_CHK.is_emotion(rule_table_name) if len(value_list) > 0: raise serializers.ValidationError("RuleTable名 入力文字不正", "rule_table_name") return rule_table_name
def _validate(self, rq, error_msg, request): """ [概要] 入力チェック [引数] rq: dict リクエストされた入力データ error_msg: dict [戻り値] """ logger.logic_log('LOSI00001', 'data: %s, error_msg:%s' % (rq, error_msg)) error_flag = False emo_chk = UnicodeCheck() emo_flag_ita_disp_name = False emo_flag_hostname = False if len(rq['ita_disp_name']) == 0: error_flag = True error_msg['ita_disp_name'] += get_message( 'MOSJA27101', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07001', 'ita_disp_name', request=request) if len(rq['ita_disp_name']) > 64: error_flag = True error_msg['ita_disp_name'] += get_message( 'MOSJA27102', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07002', 'ita_disp_name', 64, rq['ita_disp_name'], request=request) # 絵文字チェック value_list = emo_chk.is_emotion(rq['ita_disp_name']) if len(value_list) > 0: error_flag = True emo_flag_ita_disp_name = True error_msg['ita_disp_name'] += get_message( 'MOSJA27120', request.user.get_lang_mode(), showMsgId=False) + '\n' if len(rq['protocol']) == 0: error_flag = True error_msg['protocol'] += get_message( 'MOSJA27115', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07001', 'protocol', request=request) if len(rq['protocol']) > 64: error_flag = True error_msg['protocol'] += get_message( 'MOSJA27116', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07002', 'protocol', 64, rq['protocol'], request=request) if len(rq['hostname']) == 0: error_flag = True error_msg['hostname'] += get_message( 'MOSJA27103', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07001', 'hostname', request=request) if len(rq['hostname']) > 128: error_flag = True error_msg['hostname'] += get_message( 'MOSJA27104', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07002', 'hostname', 128, rq['hostname'], request=request) # 絵文字チェック value_list = emo_chk.is_emotion(rq['hostname']) if len(value_list) > 0: error_flag = True emo_flag_hostname = True error_msg['hostname'] += get_message('MOSJA27121', request.user.get_lang_mode(), showMsgId=False) + '\n' if len(rq['port']) == 0: error_flag = True error_msg['port'] += get_message( 'MOSJA27105', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07001', 'port', request=request) try: tmp_port = int(rq['port']) if 0 > tmp_port or tmp_port > 65535: error_flag = True error_msg['port'] += get_message( 'MOSJA27106', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07003', 'port', rq['port'], request=request) except ValueError: error_flag = True error_msg['port'] += get_message( 'MOSJA27106', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07003', 'port', rq['port'], request=request) if len(rq['username']) == 0: error_flag = True error_msg['username'] += get_message( 'MOSJA27107', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07001', 'username', request=request) if len(rq['username']) > 64: error_flag = True error_msg['username'] += get_message( 'MOSJA27108', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07002', 'username', 64, rq['username'], request=request) # 絵文字チェック value_list = emo_chk.is_emotion(rq['username']) if len(value_list) > 0: error_flag = True error_msg['username'] += get_message('MOSJA27122', request.user.get_lang_mode(), showMsgId=False) + '\n' if len(rq['password']) == 0: error_flag = True error_msg['password'] += get_message( 'MOSJA27109', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07001', 'password', request=request) driver_info_old = ItaDriver.objects.filter( ita_driver_id=rq['ita_driver_id']) if len(driver_info_old ) > 0 and driver_info_old[0].password != rq['password']: if len(rq['password']) > 64: error_flag = True error_msg['password'] += get_message( 'MOSJA27110', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07002', 'password', 64, rq['password'], request=request) # 絵文字チェック value_list = emo_chk.is_emotion(rq['password']) if len(value_list) > 0: error_flag = True error_msg['password'] += get_message( 'MOSJA27123', request.user.get_lang_mode(), showMsgId=False) + '\n' if not emo_flag_ita_disp_name: duplication = ItaDriver.objects.filter( ita_disp_name=rq['ita_disp_name']) if len(duplication) == 1 and int( rq['ita_driver_id']) != duplication[0].ita_driver_id: error_flag = True error_msg['ita_disp_name'] += get_message( 'MOSJA27111', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07004', 'ita_disp_name', rq['ita_disp_name'], request=request) if not emo_flag_hostname: duplication = ItaDriver.objects.filter(hostname=rq['hostname']) if len(duplication) == 1 and int( rq['ita_driver_id']) != duplication[0].ita_driver_id: error_flag = True error_msg['hostname'] += get_message( 'MOSJA27112', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07004', 'hostname', rq['hostname'], request=request) # 疎通確認 if not error_flag: resp_code = -1 try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: resp_code = sock.connect_ex( (rq['hostname'], int(rq['port']))) # host名名前解決が必要/etc/hostsとか sock.close() except: pass if resp_code != 0: error_flag = True error_msg['ita_disp_name'] += get_message( 'MOSJA27119', request.user.get_lang_mode()) + '\n' logger.user_log('LOSM07005', rq['hostname'], rq['port'], request=request) logger.logic_log('LOSI00002', 'return: %s' % error_flag) return error_flag
class SsoInfoForm(forms.Form): provider_name_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA28036', } auth_type_errors = { 'required': 'MOSJA00003', } logo_errors = { 'max_length': 'MOSJA28037', } visible_flag_errors = { 'required': 'MOSJA00003', } clientid_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA28038', } clientsecret_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA28039', } authorizationuri_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA28040', } accesstokenuri_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA28041', } resourceowneruri_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA28042', } scope_errors = { 'max_length': 'MOSJA28043', } id_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA28044', } name_errors = { 'required': 'MOSJA00003', 'max_length': 'MOSJA28045', } email_errors = { 'max_length': 'MOSJA28046', } imageurl_errors = { 'max_length': 'MOSJA28047', } proxy_errors = { 'max_length': 'MOSJA28048', } provider_name = forms.CharField(label="プロバイダー名", max_length=128, error_messages=provider_name_errors) logo = forms.CharField(label="ロゴ", max_length=64, required=False, error_messages=logo_errors) clientid = forms.CharField(label="clientid", max_length=256, error_messages=clientid_errors) clientsecret = forms.CharField(label="clientsecret", max_length=256, error_messages=clientsecret_errors) authorizationuri = forms.CharField(label="authorizationuri", max_length=256, error_messages=authorizationuri_errors) accesstokenuri = forms.CharField(label="accesstokenuri", max_length=256, error_messages=accesstokenuri_errors) resourceowneruri = forms.CharField(label="resourceowneruri", max_length=256, error_messages=resourceowneruri_errors) scope = forms.CharField(label="scope", max_length=256, required=False, error_messages=scope_errors) id = forms.CharField(label="id", max_length=256, error_messages=id_errors) name = forms.CharField(label="name", max_length=256, error_messages=name_errors) email = forms.CharField(label="email", max_length=256, required=False, error_messages=email_errors) imageurl = forms.CharField(label="imageurl", max_length=256, required=False, error_messages=imageurl_errors) proxy = forms.CharField(label="proxy", max_length=256, required=False, error_messages=proxy_errors) required_css_class = 'tooltip-input validation-input' error_css_class = 'tooltip-input validation-input' def __init__(self, pk, *args, **kwargs): super().__init__(*args, **kwargs) self.pk = pk self.emo_chk = UnicodeCheck() def clean_provider_name(self): """ プロバイダー名チェック """ provider_name = self.cleaned_data['provider_name'] # 絵文字チェック if len(self.emo_chk.is_emotion(provider_name)): self.add_error('provider_name', 'MOSJA28049') return provider_name def clean_auth_type(self): """ 認証方式チェック """ auth_type = self.cleaned_data['auth_type'] if auth_type not in ['0']: self.add_error('auth_type', 'MOSJA28051') return auth_type def clean_logo(self): """ logoチェック """ logo = self.cleaned_data['logo'] # 絵文字チェック if len(self.emo_chk.is_emotion(logo)): self.add_error('logo', 'MOSJA28052') return logo def clean_visible_flag(self): """ 表示フラグチェック """ visible_flag = self.cleaned_data['visible_flag'] if visible_flag not in ['0', '1']: self.add_error('visible_flag', 'MOSJA28054') return visible_flag def clean_clientid(self): """ clientidチェック """ clientid = self.cleaned_data['clientid'] # 絵文字チェック if len(self.emo_chk.is_emotion(clientid)): self.add_error('clientid', 'MOSJA28055') return clientid def clean_clientsecret(self): """ clientsecretチェック """ clientsecret = self.cleaned_data['clientsecret'] # 絵文字チェック if len(self.emo_chk.is_emotion(clientsecret)): self.add_error('clientsecret', 'MOSJA28056') return clientsecret def clean_authorizationuri(self): """ authorizationuriチェック """ authorizationuri = self.cleaned_data['authorizationuri'] # 絵文字チェック if len(self.emo_chk.is_emotion(authorizationuri)): self.add_error('authorizationuri', 'MOSJA28057') return authorizationuri def clean_accesstokenuri(self): """ accesstokenuriチェック """ accesstokenuri = self.cleaned_data['accesstokenuri'] # 絵文字チェック if len(self.emo_chk.is_emotion(accesstokenuri)): self.add_error('accesstokenuri', 'MOSJA28058') return accesstokenuri def clean_resourceowneruri(self): """ resourceowneruriチェック """ resourceowneruri = self.cleaned_data['resourceowneruri'] # 絵文字チェック if len(self.emo_chk.is_emotion(resourceowneruri)): self.add_error('resourceowneruri', 'MOSJA28059') return resourceowneruri def clean_scope(self): """ scopeチェック """ scope = self.cleaned_data['scope'] # 絵文字チェック if len(self.emo_chk.is_emotion(scope)): self.add_error('scope', 'MOSJA28060') return scope def clean_id(self): """ idチェック """ id = self.cleaned_data['id'] # 絵文字チェック if len(self.emo_chk.is_emotion(id)): self.add_error('id', 'MOSJA28061') return id def clean_name(self): """ nameチェック """ name = self.cleaned_data['name'] # 絵文字チェック if len(self.emo_chk.is_emotion(name)): self.add_error('name', 'MOSJA28062') return name def clean_email(self): """ emailチェック """ email = self.cleaned_data['email'] # 絵文字チェック if len(self.emo_chk.is_emotion(email)): self.add_error('email', 'MOSJA28063') return email def clean_imageurl(self): """ imageurlチェック """ imageurl = self.cleaned_data['imageurl'] # 絵文字チェック if len(self.emo_chk.is_emotion(imageurl)): self.add_error('imageurl', 'MOSJA28064') return imageurl def clean_proxy(self): """ proxyチェック """ proxy = self.cleaned_data['proxy'] # 絵文字チェック if len(self.emo_chk.is_emotion(proxy)): self.add_error('proxy', 'MOSJA28065') return proxy
class MailTemplateForm(forms.Form): """ メールテンプレートの入力確認 データは自動的にstripされる """ mail_template_name_errors = { 'required': 'MOSJA25004', 'max_length': 'MOSJA25007', } subject_errors = { 'required': 'MOSJA25005', 'max_length': 'MOSJA25008', } content_errors = { 'required': 'MOSJA25006', 'max_length': 'MOSJA25009', } destination_errors = { 'max_length': 'MOSJA25010', } cc_errors = { 'max_length': 'MOSJA25011', } bcc_errors = { 'max_length': 'MOSJA25012', } pk = forms.IntegerField(required=False) mail_template_name = forms.CharField( max_length=64, error_messages=mail_template_name_errors) subject = forms.CharField(max_length=128, error_messages=subject_errors) content = forms.CharField(max_length=512, error_messages=content_errors) destination = forms.CharField(max_length=512, required=False, error_messages=destination_errors) cc = forms.CharField(max_length=512, required=False, error_messages=cc_errors) bcc = forms.CharField(max_length=200, required=False, error_messages=bcc_errors) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.emo_chk = UnicodeCheck() def clean_mail_template_name(self): """ メールテンプレートチェック """ mtn = self.cleaned_data['mail_template_name'] if len(self.emo_chk.is_emotion(mtn)): self.add_error('mail_template_name', 'MOSJA25020') return mtn def clean_subject(self): """ 題名チェック """ subject = self.cleaned_data['subject'] if len(self.emo_chk.is_emotion(subject)): self.add_error('subject', 'MOSJA25021') return subject def clean_content(self): """ 本文チェック """ content = self.cleaned_data['content'] if len(self.emo_chk.is_emotion(content)): self.add_error('content', 'MOSJA25022') return content def clean_destination(self): """ 宛先チェック """ destination = self.cleaned_data['destination'] if len(self.emo_chk.is_emotion(destination)): self.add_error('destination', 'MOSJA25023') # 複数メールアドレスの形式チェック if not is_addresses(destination): self.add_error('destination', 'MOSJA25014') return destination def clean_cc(self): """ CCチェック """ cc = self.cleaned_data['cc'] if len(self.emo_chk.is_emotion(cc)): self.add_error('cc', 'MOSJA25024') # 複数メールアドレスの形式チェック if not is_addresses(cc): self.add_error('cc', 'MOSJA25015') return cc def clean_bcc(self): """ BCCチェック """ bcc = self.cleaned_data['bcc'] if len(self.emo_chk.is_emotion(bcc)): self.add_error('bcc', 'MOSJA25025') # 複数メールアドレスの形式チェック if not is_addresses(bcc): self.add_error('bcc', 'MOSJA25016') return bcc def clean(self): """ 重複チェック """ mtn = self.cleaned_data.get('mail_template_name') pk = self.cleaned_data.get('pk') # 更新時の重複チェック if pk is None: duplication = MailTemplate.objects.filter(mail_template_name=mtn) if len(duplication): self.add_error('mail_template_name', 'MOSJA25013') # 新規追加時の重複チェック else: duplication = MailTemplate.objects.filter( mail_template_name=mtn).exclude(pk=pk) if len(duplication): self.add_error('mail_template_name', 'MOSJA25013') return self.cleaned_data