コード例 #1
0
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
コード例 #2
0
    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
コード例 #3
0
ファイル: rule_type_form.py プロジェクト: yuya0arai/oase
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
コード例 #4
0
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
コード例 #5
0
ファイル: personal_config.py プロジェクト: yuya0arai/oase
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")
コード例 #6
0
    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
コード例 #7
0
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
コード例 #8
0
ファイル: action_ITA.py プロジェクト: yuya0arai/oase
    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
コード例 #9
0
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
コード例 #10
0
ファイル: mail_form.py プロジェクト: m-kawata-git/oase-filter
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