예제 #1
0
def _getWhiteListData(filters, request=None):
    """
    [メソッド概要]
      データ抽出処理
    [引数]
      request :logger.logic_logでuserId sessionIDを表示するために使用する
    [戻り値]
      ip_list
    """

    logger.logic_log('LOSI00001', 'filters: %s' % filters, request=request)

    # リスト表示用
    where_info = {}
    Common.convert_filters(filters, where_info)

    # フィルタ情報によるデータ抽出
    white = WhiteListIPAddress.objects.filter(**where_info)

    # 抽出結果を画面表示用に整形
    white_list = []
    for w in white:
        white_list_info = {
            'white_list_id': w.white_list_id,
            'ipaddr': w.ipaddr,
            'upd_user': w.last_update_user,
            'updated': w.last_update_timestamp,
        }
        white_list.append(white_list_info)

    logger.logic_log('LOSI00002',
                     'white_list: %s' % len(white_list),
                     request=request)

    return white_list
예제 #2
0
파일: group.py 프로젝트: y-koyama-git/oase
def _select(filters={}):
    """
    [メソッド概要]
      グループのデータ取得
    """
    logger.logic_log('LOSI00001', 'filters: %s' % (filters))

    # グループ情報取得
    where_info = {}
    WebCommon.convert_filters(filters, where_info)
    group = Group.objects.filter(**where_info)
    group = group.filter(group_id__gte=1).order_by('group_id')

    # グループ情報作成
    group_list = []
    for g in group:
        group_info_dic = {}
        group_info_dic['group_id'] = g.group_id
        group_info_dic['group_name'] = g.group_name
        group_info_dic['summary'] = g.summary
        group_info_dic['last_timestamp'] = g.last_update_timestamp
        group_info_dic['last_update_user'] = g.last_update_user

        group_info_dic['summary_outline'] = ''
        hasBreakLine = True if len(g.summary.splitlines()) > 2 else False
        max_str_length = 20  # セル幅と相談
        if hasBreakLine:
            group_info_dic['summary_outline'] = g.summary.splitlines(
            )[0][:max_str_length]
        elif len(g.summary) > max_str_length:
            group_info_dic['summary_outline'] = g.summary[:max_str_length]

        group_list.append(group_info_dic)

    return group_list
예제 #3
0
def _select(filters={}):
    """
    [メソッド概要]
      グループのデータ取得
    """

    logger.logic_log('LOSI00001', 'filters: %s' % (filters))

    where_info = {}

    Common.convert_filters(filters, where_info)
    mail_list = MailTemplate.objects.filter(**where_info)

    logger.logic_log('LOSI00002', 'mail_list: %s' % mail_list)

    return mail_list
예제 #4
0
def _getBlackListData(filters, request=None):
    """
    [メソッド概要]
      データ更新処理
    [引数]
      request :logger.logic_logでuserId sessionIDを表示するために使用する
    [戻り値]
      ip_list
    """

    logger.logic_log('LOSI00001', 'filters: %s' % filters, request=request)

    # リスト表示用
    where_info = {
        'release_timestamp': None
    }
    Common.convert_filters(filters, where_info)

    # フィルタ情報によるデータ抽出
    black = BlackListIPAddress.objects.filter(**where_info)

    # 抽出結果を画面表示用に整形
    black_list = []
    for b in black:
        black_list_info = {
            'black_list_id': b.black_list_id,
            'ipaddr': b.ipaddr,
            'release_timestamp': b.release_timestamp,
            'manual_reg_flag': b.manual_reg_flag,
            'upd_user': b.last_update_user,
            'updated': b.last_update_timestamp,
        }
        black_list.append(black_list_info)

    logger.logic_log('LOSI00002', 'black_list: %s' %
                     len(black_list), request=request)

    return black_list
예제 #5
0
    def _send_user_locked_mail(self, login_id, request):
        """
        [概要]
        メール通知種別に応じてメールを送信する
        [引数]
        login_id : int ログインid
        """
        mail_list = WebCommon.get_mail_notification_list()
        smtp = OASEMailSMTP()
        # 署名用URL生成
        req_protcol = request.scheme
        req_host = request.get_host()
        locked_url = reverse('web_app:user:locked_user')
        login_url = reverse('web_app:top:login')
        inquiry_url = reverse('web_app:top:inquiry')
        locked_url = '%s://%s%s' % (req_protcol, req_host, locked_url)
        login_url = '%s://%s%s' % (req_protcol, req_host, login_url)
        inquiry_url = '%s://%s%s' % (req_protcol, req_host, inquiry_url)

        for m in mail_list:
            user_mail = OASEMailUserLocked(m, login_id, locked_url,
                                           inquiry_url, login_url)
            _ = smtp.send_mail(user_mail)
예제 #6
0
def _getUserData(filters, edit=False, request=None):
    """
    [メソッド概要]
      データ更新処理
    [引数]
      edit : bool 編集モードか否か デフォルトは一覧モード
      request :logger.logic_logでuserId sessionIDを表示するために使用する
    [戻り値]
      user_list
    """

    logger.logic_log('LOSI00001', 'filters: %s' % filters, request=request)

    # リスト表示用 編集モードと一覧モードでフィルタを分ける
    where_info = {'pk__gt':1, 'disuse_flag':'0'} if edit else {'pk__gt':0, 'disuse_flag':'0'}
    where_group_info = {}

    WebCommon.convert_filters(filters, where_info)
    search_info =  _get_search_info(where_info)

    # グループのフィルタ情報をwhere_infoから抽出
    if 'group_name__contains' in where_info:
        where_group_info['group_name__contains'] = where_info.pop('group_name__contains')
    if 'group_name__in' in where_info:
        where_group_info['group_name__in'] = where_info.pop('group_name__in')


    # フィルタ情報によるデータ抽出
    user = User.objects.filter(**where_info)

    if len(where_group_info):
        ug_list  = []
        gid_list = Group.objects.filter(**where_group_info).values_list('group_id', flat=True)
        if len(gid_list) > 0:
            ug_list = list(UserGroup.objects.filter(group_id__in=gid_list).values_list('user_id', flat=True).distinct())

        if len(ug_list) > 0:
            user = user.filter(pk__in=ug_list)

        else:
            logger.user_log('LOSM05006', 'Group: %s' % where_info['Group'], request=request)
            logger.logic_log('LOSI00002', 'None', request=request)
            return []


    # 抽出結果を画面表示用に整形
    user_list = []
    for u in user:
        group_id_list, group_name_list = u.get_group_info()
        user_info = {
            'user_id'  : u.user_id,
            'user_name': u.user_name,
            'login_id' : u.login_id,
            'mail'     : u.mail_address,
            'sso_id'   : u.sso_id,
            'group_id' : group_id_list,
            'upd_user': u.last_update_user,
            'updated'  : u.last_update_timestamp,
            'group_name' : group_name_list,
            'upd_user_name' : u.last_update_user,
        }
        user_list.append(user_info)

    logger.logic_log('LOSI00002', 'user_list: %s' % len(user_list), request=request)

    return user_list, search_info
예제 #7
0
def _ipaddr_login_log(request, ipaddr, login_id, flg, now):
    """
    [メソッド概要]
      ログインの成否によりログインログを操作する
    [引数]
      ipaddr   : ログイン元IPアドレス
      login_id : 入力ログインID
      flg      : ログイン成否 True=成功、False=失敗
      now      : ログイン試行日時
    """

    if not now:
        now = datetime.datetime.now(pytz.timezone('UTC'))

    try:
        with transaction.atomic():
            # ログイン成功IPアドレスを削除
            if flg:
                LoginLogIPAddress.objects.filter(ipaddr=ipaddr).delete()

            # ログイン失敗時はログインログに登録
            else:
                save_login_id = login_id[:32]

                # ログインログを保存
                LoginLogIPAddress(
                    ipaddr=ipaddr,
                    login_id=save_login_id,
                    last_update_timestamp=now,
                ).save(force_insert=True)

                # 連続失敗回数の規定値を取得
                threshold = 0
                try:
                    threshold = int(
                        System.objects.get(
                            config_id='IPADDR_LOGIN_RETRY_MAX').value)
                except Exception as e:
                    pass

                if threshold > 0:

                    # 連続失敗回数が規定数に達したら、ブラックリストに登録
                    rcnt = LoginLogIPAddress.objects.filter(
                        ipaddr=ipaddr).count()
                    # ブラックリストに登録済かつ有効のIPを検索
                    recent_record = list(
                        BlackListIPAddress.objects.filter(ipaddr=ipaddr).
                        order_by('black_list_id').reverse()[:1])

                    auto_blacklist = 0
                    if len(recent_record) > 0:
                        if recent_record[0].release_timestamp == None:
                            auto_blacklist = 1

                    logger.logic_log('LOSI13005', ipaddr, rcnt, threshold,
                                     auto_blacklist)

                    if rcnt >= threshold and auto_blacklist < 1:
                        BlackListIPAddress(
                            ipaddr=ipaddr,
                            release_timestamp=None,
                            last_update_timestamp=now,
                            last_update_user='',
                            manual_reg_flag=False).save(force_insert=True)

                        # ブラックリスト登録時、連続失敗回数をリセットする
                        LoginLogIPAddress.objects.filter(
                            ipaddr=ipaddr).delete()

                        # URL生成
                        req_protcol = request.scheme
                        req_host = request.get_host()
                        url = reverse('web_app:user:black_list')
                        url = '%s://%s%s' % (req_protcol, req_host, url)
                        # 署名用URL生成
                        login_url = reverse('web_app:top:login')
                        contact_url = reverse('web_app:top:inquiry')
                        login_url = '%s://%s%s' % (req_protcol, req_host,
                                                   login_url)
                        contact_url = '%s://%s%s' % (req_protcol, req_host,
                                                     contact_url)

                        # メール通知
                        mail_list = Common.get_mail_notification_list()
                        smtp = OASEMailSMTP()
                        for m in mail_list:
                            user_mail = OASEMailAddBlackList(
                                m, ipaddr, url, contact_url, login_url)
                            _ = smtp.send_mail(user_mail)

    except Exception as e:
        logger.system_log('LOSM13015', ipaddr, login_id, flg,
                          traceback.format_exc())