Răsfoiți Sursa

정규식 차단 추가 및 차단 알고리즘 개편

Surplus_Up (2DU) 7 ani în urmă
părinte
comite
a4f27d90c3
9 a modificat fișierele cu 208 adăugiri și 104 ștergeri
  1. 2 1
      app.py
  2. 8 1
      language/en-US.json
  3. 8 1
      language/ko-KR.json
  4. 41 19
      route/block_log.py
  5. 1 2
      route/manager.py
  6. 2 5
      route/plus_inter.py
  7. 85 46
      route/tool/func.py
  8. 57 25
      route/user_ban.py
  9. 4 4
      views/neo_yousoro/css/main.css

+ 2 - 1
app.py

@@ -8,7 +8,7 @@ for i_data in os.listdir("route"):
 
         exec("from route." + f_src + " import *")
 
-r_ver = 'v3.1.0-master-06'
+r_ver = 'v3.1.0-master-07'
 c_ver = '400001'
 s_ver = '2'
 
@@ -491,6 +491,7 @@ def check_key(tool = 'check_pass_key'):
 def logout():
     return logout_2(conn)
     
+@app.route('/ban', methods=['POST', 'GET'])
 @app.route('/ban/<name>', methods=['POST', 'GET'])
 def user_ban(name = None):
     return user_ban_2(conn, name)         

+ 8 - 1
language/en-US.json

@@ -82,6 +82,9 @@
         "explanation" : "Explanation",
         "default" : "Default",
         "lastest" : "Lastest",
+        "type" : "Type",
+        "in_progress" : "In progress",
+        "start" : "Start",
         "_comment_1.1_" : "Time",
             "second" : "Second(s)",
             "hour" : "Hour(s)",
@@ -155,6 +158,8 @@
         "check_key" : "Check Authentication Key",
         "reset_user_ok" : "Check Success",
         "name_or_ip_or_regex" : "ID or IP or Regex",
+        "ban_period" : "Period to block",
+        "not_sure" : "Not sure",
         "_comment_2.1_" : "Filter",
             "_comment_2.1.1_" : "List",
                 "interwiki_list" : "Interwiki(s) list",
@@ -236,6 +241,7 @@
         "user_head_warring" : "User[s] <head> will deleted if you close the browser or sign-in",
         "no_login_warring" : "Non-login status. IP is logged when working with non-login.",
         "user_reset_sign" : "Your account information has changed like this.",
+        "ban_explanation" : "If the blockout period is not set, it is an indefinite block.",
         "_comment_3.1_" : "Error",
             "update_error" : "Auto update is not support.",
             "inter_error" : "Internal error.",
@@ -259,5 +265,6 @@
             "edit_filter_error" : "Censored by edit filter.",
             "file_name_error" : "Only alphabet, hangul, space, underscore, and minus signs are allowed for file names.",
             "topic_long_error" : "The discussion name must not exceed 256 characters.",
-            "email_error" : "No one has this email."
+            "email_error" : "No one has this email.",
+            "regex_error" : "There is an error in the regular expression."
 }

+ 8 - 1
language/ko-KR.json

@@ -82,6 +82,9 @@
         "explanation" : "설명",
         "default" : "기본값",
         "lastest" : "최신",
+        "type" : "유형",
+        "in_progress" : "진행중",
+        "start" : "시작",
         "_comment_1.1_" : "시간",
             "second" : "초",
             "hour" : "시간",
@@ -155,6 +158,8 @@
         "check_key" : "인증키 검사",
         "reset_user_ok" : "검사 성공",
         "name_or_ip_or_regex" : "ID or IP or 정규식",
+        "ban_period" : "차단 기간",
+        "not_sure" : "확실하지 않음",
         "_comment_2.1_" : "필터",
             "_comment_2.1.1_" : "목록",
                 "interwiki_list" : "인터위키 목록",
@@ -236,6 +241,7 @@
         "user_head_warring" : "비로그인시 브라우저를 닫거나 로그인시 사용자의 <head>는 삭제됩니다.",
         "no_login_warring" : "비로그인 상태입니다. 편집시 지금 접속한 IP 명의로 기록됩니다.",
         "user_reset_sign" : "사용자의 계정 정보가 다음과 같이 변경 되었습니다.",
+        "ban_explanation" : "차단 기간이 정해지지 않으면 무기한 차단 입니다.",
         "_comment_3.1_" : "오류",
             "update_error" : "자동 업데이트가 지원되지 않습니다.",
             "inter_error" : "내부 오류.",
@@ -259,5 +265,6 @@
             "edit_filter_error" : "편집 필터에 의해 금지된 단어가 사용되었습니다.",
             "file_name_error" : "파일 이름에는 알파벳, 한글, 공백, 밑줄 과 빼기 기호만 사용할 수 있습니다.",
             "topic_long_error" : "토론 이름이 256자를 넘지 않아야 합니다.",
-            "email_error" : "이런 이메일을 가진 사용자가 없습니다."
+            "email_error" : "이런 이메일을 가진 사용자가 없습니다.",
+            "regex_error" : "정규표현식에 오류가 있습니다."
 }

+ 41 - 19
route/block_log.py

@@ -20,28 +20,37 @@ def block_log_2(conn, name, tool):
     '''
     
     data_list = ''
+
+    curs.execute("delete from ban where (end < ? and end like '2%')", [get_time()])
+    conn.commit()
     
-    if not name:
-        div = '''
-            <a href="/manager/11">(''' + load_lang('blocked') + ''')</a> <a href="/manager/12">(''' + load_lang('admin') + ''')</a>
-            <hr class=\"main_hr\">
-        ''' + div
-        
-        sub = 0
-        menu = 0
-        
-        curs.execute("select why, block, blocker, end, today from rb order by today desc limit ?, '50'", [str(sql_num)])
+    if not name:        
+        if flask.request.args.get('type', '') == 'ongoing':
+            sub = ' (' + load_lang('in_progress') + ')'
+            menu = [['block_log', load_lang('normal')]]
+
+            curs.execute("select why, block, '', end, '', band from ban where ((end > ? and end like '2%') or end = '') order by end desc limit ?, '50'", [get_time(), str(sql_num)])
+        else:
+            sub = 0
+            menu = 0
+
+            div = '''
+                <a href="/manager/11">(''' + load_lang('blocked') + ''')</a> <a href="/manager/12">(''' + load_lang('admin') + ''')</a> <a href="?type=ongoing">(''' + load_lang('in_progress') + ''')</a>
+                <hr class=\"main_hr\">
+            ''' + div
+            
+            curs.execute("select why, block, blocker, end, today, band from rb order by today desc limit ?, '50'", [str(sql_num)])
     else:
         menu = [['block_log', load_lang('normal')]]
         
         if tool == 'block_user':
             sub = ' (' + load_lang('blocked') + ')'
             
-            curs.execute("select why, block, blocker, end, today from rb where block = ? order by today desc limit ?, '50'", [name, str(sql_num)])
+            curs.execute("select why, block, blocker, end, today, band from rb where block = ? order by today desc limit ?, '50'", [name, str(sql_num)])
         else:
             sub = ' (' + load_lang('admin') + ')'
             
-            curs.execute("select why, block, blocker, end, today from rb where blocker = ? order by today desc limit ?, '50'", [name, str(sql_num)])
+            curs.execute("select why, block, blocker, end, today, band from rb where blocker = ? order by today desc limit ?, '50'", [name, str(sql_num)])
 
     if data_list == '':
         data_list = curs.fetchall()
@@ -51,25 +60,38 @@ def block_log_2(conn, name, tool):
         if why == '':
             why = '<br>'
         
-        band = re.search("^([0-9]{1,3}\.[0-9]{1,3})$", data[1])
-        if band:
+        if data[5] == 'O':
             ip = data[1] + ' (' + load_lang('range') + ')'
+        elif data[5] == 'regex':
+            ip = data[1] + ' (' + load_lang('regex') + ')'
         else:
             ip = ip_pas(data[1])
 
-        if data[3] != '':
+        if data[3] == '':
+            end = load_lang('limitless')
+        elif data[3] == 'release':
+            end = load_lang('release')
+        else:
             end = data[3]
+
+        if data[2] == '':
+            admin = ''
+        else:
+            admin = ip_pas(data[2])
+
+        if data[4] == '':
+            start = ''
         else:
-            end = load_lang('limitless') + ''
+            start = load_lang('start') + ' : ' + data[4]
             
         div += '''
             <tr>
                 <td>''' + ip + '''</td>
-                <td>''' + ip_pas(data[2]) + '''</td>
+                <td>''' + admin + '''</td>
                 <td>
-                    start : ''' + data[4] + '''
+                    ''' + start + '''
                     <br>
-                    end : ''' + end + '''
+                    ''' + load_lang('end') + ' : ' + end + '''
                 </td>
             </tr>
             <tr>

+ 1 - 2
route/manager.py

@@ -6,7 +6,6 @@ def manager_2(conn, num):
     title_list = {
         0 : [load_lang('document_name'), 'acl'], 
         1 : [0, 'check'], 
-        2 : [0, 'ban'], 
         3 : [0, 'admin'], 
         4 : [0, 'record'], 
         5 : [0, 'topic_record'], 
@@ -27,7 +26,7 @@ def manager_2(conn, num):
                     <h2>''' + load_lang('admin') + '''</h2>
                     <ul>
                         <li><a href="/manager/3">''' + load_lang('check_user') + '''</a></li>
-                        <li><a href="/manager/4">''' + load_lang('ban') + '''</a></li>
+                        <li><a href="/ban">''' + load_lang('ban') + '''</a></li>
                         <li><a href="/manager/5">''' + load_lang('authorize') + '''</a></li>
                         <li><a href="/edit_filter">''' + load_lang('edit_filter_list') + '''</a></li>
                         <li><a href="/give_log">''' + load_lang('admin_group_list') + '''</a></li>

+ 2 - 5
route/plus_inter.py

@@ -19,16 +19,13 @@ def plus_inter_2(conn, tools, name):
             try:
                 re.compile(flask.request.form.get('content', 'test'))
 
-                i = 0
-            except:
-                i = 1
-
-            if i == 0:
                 curs.execute("select name from filter where name = ?", [name])
                 if curs.fetchall():
                     curs.execute("update filter set regex = ?, sub = ? where name = ?", [flask.request.form.get('content', 'test'), end, name])
                 else:
                     curs.execute("insert into filter (name, regex, sub) values (?, ?, ?)", [name, flask.request.form.get('content', 'test'), end])
+            except:
+                return re_error('/error/23')                
         else:
             if tools == 'plus_name_filter':
                 admin_check(None, 'name_filter edit')

+ 85 - 46
route/tool/func.py

@@ -828,20 +828,38 @@ def ban_check(ip = None, tool = None):
         band_it = band.groups()[0]
     else:
         band_it = '-'
+
+    curs.execute("delete from ban where (end < ? and end like '2%')", [get_time()])
+    conn.commit()
+
+    curs.execute("select login, block from ban where ((end > ? and end like '2%') or end = '') and band = 'regex'", [get_time()])
+    regex_d = curs.fetchall()
+    for test_r in regex_d:
+        g_regex = re.compile(test_r[1])
+        if g_regex.search(ip):
+            if tool and tool == 'login':
+                if test_r[0] != 'O':
+                    return 1
+            else:
+                return 1
     
-    curs.execute("select end, login from ban where block = ?", [band_it])
+    curs.execute("select login from ban where ((end > ? and end like '2%') or end = '') and block = ? and band = 'O'", [get_time(), band_it])
     band_d = curs.fetchall()
-    
-    curs.execute("select end, login from ban where block = ?", [ip])
+    if band_d:
+        if tool and tool == 'login':
+            if data[0][0] != 'O':
+                return 1
+        else:
+            return 1
+
+    curs.execute("select login from ban where ((end > ? and end like '2%') or end = '') and block = ? and band = ''", [get_time(), ip])
     ban_d = curs.fetchall()
-    
-    data = band_d or ban_d
-    if data and (data[0][0] == '' or data[0][0] > get_time()):
-        if tool and tool == 'login':                    
-            if data[0][1] == 'O':
-                return 0
-                
-        return 1
+    if ban_d:
+        if tool and tool == 'login':
+            if data[0][0] != 'O':
+                return 1
+        else:
+            return 1
 
     return 0
         
@@ -901,25 +919,30 @@ def topic_check(name, sub):
 
     return 0
 
-def ban_insert(name, end, why, login, blocker):
+def ban_insert(name, end, why, login, blocker, type_d = None):
     now_time = get_time()
 
-    if re.search("^([0-9]{1,3}\.[0-9]{1,3})$", name):
-        band = 'O'
+    if type_d:
+        band = type_d
     else:
-        band = ''
+        if re.search("^([0-9]{1,3}\.[0-9]{1,3})$", name):
+            band = 'O'
+        else:
+            band = ''
 
-    curs.execute("select block from ban where block = ?", [name])
+    curs.execute("delete from ban where (end < ? and end like '2%')", [get_time()])
+
+    curs.execute("select block from ban where ((end > ? and end like '2%') or end = '') and block = ? and band = ?", [name, band])
     if curs.fetchall():
         curs.execute("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, ?)", [
             name, 
-            load_lang('release', 1),
+            'release',
             now_time, 
             blocker, 
             '', 
             band
         ])
-        curs.execute("delete from ban where block = ?", [name])
+        curs.execute("delete from ban where block = ? and band = ?", [name, band])
     else:
         if login != '':
             login = 'O'
@@ -1018,35 +1041,49 @@ def re_error(data):
         end = '<li>' + load_lang('why') + ' : ' + load_lang('authority_error') + '</li>'
 
         if ban_check() == 1:
-            curs.execute("select end, why from ban where block = ?", [ip])
-            end_data = curs.fetchall()
-            if not end_data:
-                match = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
-                if match:
-                    curs.execute("select end, why from ban where block = ?", [match.groups()[0]])
-                    end_data = curs.fetchall()
-            
-            if end_data:
-                end = '<li>' + load_lang('state') + ' : ' + load_lang('ban') + '</li><li>'
-
-                if end_data[0][0]:
-                    now = int(re.sub('(\-| |:)', '', get_time()))
-                    day = int(re.sub('(\-| |:)', '', end_data[0][0]))
-                    
-                    if now >= day:
-                        curs.execute("delete from ban where block = ?", [ip])
-                        conn.commit()
+            end = '<li>' + load_lang('state') + ' : ' + load_lang('ban') + '</li>'
+            ok_sign = 1
 
-                        end += '<script>location.reload();</script>'
-                    else:
-                        end += 'end : ' + end_data[0][0]
-                else:
-                    end += load_lang('limitless')
-                
-                end += '</li>'
-
-                if end_data[0][1] != '':
-                    end += '<li>' + load_lang('why') + ' : ' + end_data[0][1] + '</li>'
+            band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
+            if band:
+                band_it = band.groups()[0]
+            else:
+                band_it = '-'
+
+            curs.execute("delete from ban where (end < ? and end like '2%')", [get_time()])
+            conn.commit()
+
+            curs.execute("select login, block, end from ban where ((end > ? and end like '2%') or end = '') and band = 'regex'", [get_time()])
+            regex_d = curs.fetchall()
+            for test_r in regex_d:
+                g_regex = re.compile(test_r[1])
+                if g_regex.search(ip):
+                    end += '<li>' + load_lang('type') + ' : regex ban</li>'
+                    end += '<li>' + load_lang('end') + ' : ' + test_r[2] + '</li>'
+                    if test_r[0] != 'O':
+                        end += '<li>' + load_lang('login_able') + ' (' + load_lang('not_sure') + ')</li>'
+
+                    end += '<hr class=\"main_hr\">'
+            
+            curs.execute("select login, end from ban where ((end > ? and end like '2%') or end = '') and block = ?", [get_time(), band_it])
+            band_d = curs.fetchall()
+            if band_d:
+                end += '<li>' + load_lang('type') + ' : band ban</li>'
+                end += '<li>' + load_lang('end') + ' : ' + band_d[0][1] + '</li>'
+                if data[0][0] != 'O':
+                    end += '<li>' + load_lang('login_able') + ' (' + load_lang('not_sure') + ')</li>'
+
+                end += '<hr class=\"main_hr\">'
+
+            curs.execute("select login, end from ban where ((end > ? and end like '2%') or end = '') and block = ?", [get_time(), ip])
+            ban_d = curs.fetchall()
+            if ban_d:
+                end += '<li>' + load_lang('type') + ' : ban</li>'
+                end += '<li>' + load_lang('end') + ' : ' + ban_d[0][1] + '</li>'
+                if data[0][0] != 'O':
+                    end += '<li>' + load_lang('login_able') + ' (' + load_lang('not_sure') + ')</li>'
+
+                end += '<hr class=\"main_hr\">'
 
         return easy_minify(flask.render_template(skin_check(), 
             imp = [load_lang('error'), wiki_set(1), custom(), other2([0, 0])],
@@ -1097,6 +1134,8 @@ def re_error(data):
                 data = load_lang('edit_filter_error')
             elif num == 22:
                 data = load_lang('file_name_error')
+            elif num == 23:
+                data = load_lang('regex_error')
             else:
                 data = '???'
 

+ 57 - 25
route/user_ban.py

@@ -3,7 +3,7 @@ from .tool.func import *
 def user_ban_2(conn, name):
     curs = conn.cursor()
 
-    if ip_or_user(name) == 0:
+    if name and ip_or_user(name) == 0:
         curs.execute("select acl from user where id = ?", [name])
         user = curs.fetchall()
         if not user:
@@ -17,17 +17,34 @@ def user_ban_2(conn, name):
         return re_error('/ban')
                 
     if flask.request.method == 'POST':
-        if admin_check(1, 'ban (' + name + ')') != 1:
+        name = name if name else flask.request.form.get('name', 'test')
+
+        if admin_check(1, 'ban' + ((' (' + name + ')') if name else '')) != 1:
             return re_error('/error/3')
 
-        if flask.request.form.get('limitless', '') == '':
-            end = flask.request.form.get('second', '0')
+        end = flask.request.form.get('second', '0')
+        end = end if end else '0'
+
+        if flask.request.form.get('regex', None):
+            type_d = 'regex'
+
+            try:
+                re.compile(name)
+            except:
+                return re_error('/error/23')
         else:
-            end = '0'
+            type_d = None
 
-        ban_insert(name, end, flask.request.form.get('why', ''), flask.request.form.get('login', ''), ip_check())
+        ban_insert(
+            name, 
+            end, 
+            flask.request.form.get('why', ''), 
+            flask.request.form.get('login', ''), 
+            ip_check(),
+            type_d
+        )
 
-        return redirect('/ban/' + url_pas(name))     
+        return redirect('/block_log')     
     else:
         if admin_check(1) != 1:
             return re_error('/error/3')
@@ -51,32 +68,47 @@ def user_ban_2(conn, name):
             else:
                 data += '</ul><hr class=\"main_hr\">'
         else:
-            if re.search("^([0-9]{1,3}\.[0-9]{1,3})$", name):
-                now = load_lang('band_ban')
+            if name:
+                if name and re.search("^([0-9]{1,3}\.[0-9]{1,3})$", name):
+                    b_now = load_lang('band_ban')
+                else:
+                    b_now = load_lang('ban')
+
+                now = ' (' + b_now + ')'
+                    
+                if name and ip_or_user(name) == 1:
+                    plus = '<input type="checkbox" name="login"> ' + load_lang('login_able') + '<hr class=\"main_hr\">'
+                else:
+                    plus = ''
+
+                name += '<hr class=\"main_hr\">'
+                regex = ''
             else:
-                now = load_lang('ban')
-                
-            if ip_or_user(name) == 1:
+                name = '<input placeholder="' + load_lang('name_or_ip_or_regex') + '" name="name" type="text"><hr class=\"main_hr\">'
+                regex = '<input type="checkbox" name="regex"> ' + load_lang('regex') + '<hr class=\"main_hr\">'
                 plus = '<input type="checkbox" name="login"> ' + load_lang('login_able') + '<hr class=\"main_hr\">'
-            else:
-                plus = ''
+                now = 0
+                b_now = load_lang('ban')
 
-            data =  '''
-                <input placeholder="''' + load_lang('second') + '''" name="second" type="text">
-                <hr class=\"main_hr\">
-                <input type="checkbox" name="limitless"> ''' + load_lang('limitless') + '''
+            data = name + '''
+                <input placeholder="''' + load_lang('ban_period') + ''' (''' + load_lang('second') + ''')" name="second" type="text">
                 <hr class=\"main_hr\">
+                ''' + regex + '''
                 <input placeholder="''' + load_lang('why') + '''" name="why" type="text">
                 <hr class=\"main_hr\">
             ''' + plus
 
         return easy_minify(flask.render_template(skin_check(), 
-            imp = [name, wiki_set(), custom(), other2([' (' + now + ')', 0])],
-            data =  '''
-                    <form method="post">
-                        ''' + data + '''
-                        <button type="submit">''' + now + '''</button>
-                    </form>
-                    ''',
+            imp = [load_lang('ban'), wiki_set(), custom(), other2([now, 0])],
+            data = '''
+                <form method="post">
+                    ''' + data + '''
+                    <button type="submit">''' + b_now + '''</button>
+                </form>
+                <h2>''' + load_lang('explanation') + '''</h2>
+                <ul>
+                    <li>''' + load_lang('ban_explanation') + '''</li>
+                </ul>
+            ''',
             menu = [['manager', load_lang('return')]]
         ))   

+ 4 - 4
views/neo_yousoro/css/main.css

@@ -339,14 +339,14 @@ input {
 #go_toc {
     display: inline-block;
     padding: 10px;
-    border-left: 2px solid gainsboro;
+    border-left: 2px solid skyblue;
     width: 25px;
 }
 
 #go_top {
     display: inline-block;
     padding: 10px;
-    border-right: 2px solid gainsboro;
+    border-right: 2px solid skyblue;
     width: 25px;
 }
 
@@ -362,8 +362,8 @@ input {
     position: fixed;
     bottom: 0;
     right: 0;
-    border: 2px solid gainsboro;
-    background: skyblue;
+    border: 2px solid skyblue;
+    background: white;
     text-align: center;
 }