Browse Source

구조 개편 및 사문 ACL 추가

2DU 8 years ago
parent
commit
b0db48e88a
2 changed files with 145 additions and 79 deletions
  1. 66 5
      app.py
  2. 79 74
      func.py

+ 66 - 5
app.py

@@ -2032,7 +2032,7 @@ def topic(name = None, sub = None):
         else:
         else:
             num = 1
             num = 1
 
 
-            m = re.search('^사용자:(.+)', name)
+            m = re.search('^사용자:([^/]+)', name)
             if(m):
             if(m):
                 d = m.groups()
                 d = m.groups()
                 curs.execute('insert into alarm (name, data, date) values (?, ?, ?)', [d[0], ip + '님이 <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '">사용자 토론</a>을 시작했습니다.', today])
                 curs.execute('insert into alarm (name, data, date) values (?, ?, ?)', [d[0], ip + '님이 <a href="/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '">사용자 토론</a>을 시작했습니다.', today])
@@ -2647,6 +2647,61 @@ def user_ban(name = None):
             )
             )
         else:
         else:
             return(redirect('/error/3'))
             return(redirect('/error/3'))
+
+@route('/user_acl/<name:path>', method=['POST', 'GET'])
+def acl(name = None):
+    ip = ip_check()
+    if(not ip == name or re.search("(\.|:)", name)):
+        return(redirect('/error/3'))
+    
+    if(request.method == 'POST'):
+        curs.execute("select acl from data where title = ?", ['사용자:' + name])
+        acl_d = curs.fetchall()
+        if(acl_d):
+            if(request.forms.select == 'all'):
+                curs.execute("update data set acl = 'all' where title = ?", ['사용자:' + name])
+            elif(request.forms.select == 'user'):
+                curs.execute("update data set acl = 'user' where title = ?", ['사용자:' + name])
+            else:
+                curs.execute("update data set acl = '' where title = ?", ['사용자:' + name])
+                
+            conn.commit()
+            
+        return(redirect('/w/' + url_pas('사용자:' + name)))
+
+    curs.execute("select acl from data where title = ?", ['사용자:' + name])
+    acl_d = curs.fetchall()
+    if(acl_d):
+        if(acl_d[0][0] == 'all'):
+            now = '모두'
+        elif(acl_d[0][0] == 'user'):
+            now = '로그인'
+        else:
+            now = '일반'
+        
+        return(
+            html_minify(
+                template('index', 
+                    imp = [name, wiki_set(1), wiki_set(3), login_check(), custom_css(), custom_js(), ' (SET)', 0],
+                    data = '<span>현재 ACL : ' + now + '</span> \
+                            <br> \
+                            <br> \
+                            <form method="post"> \
+                                <select name="select"> \
+                                    <option value="all">모두</option> \
+                                    <option value="user">로그인</option> \
+                                    <option value="normal" selected="selected">일반</option> \
+                                </select> \
+                                <br> \
+                                <br> \
+                                <button class="btn btn-primary" type="submit">ACL 변경</button> \
+                            </form>',
+                    menu = [['user', '사용자']]
+                )
+            )
+        )
+    else:
+        return(redirect('/w/' + url_pas(name)))
                 
                 
 @route('/acl/<name:path>', method=['POST', 'GET'])
 @route('/acl/<name:path>', method=['POST', 'GET'])
 def acl(name = None):
 def acl(name = None):
@@ -2673,9 +2728,9 @@ def acl(name = None):
             row = curs.fetchall()
             row = curs.fetchall()
             if(row):
             if(row):
                 if(row[0][0] == 'admin'):
                 if(row[0][0] == 'admin'):
-                    now = '관리자'
+                    now = '관리자'
                 elif(row[0][0] == 'user'):
                 elif(row[0][0] == 'user'):
-                    now = '로그인 이상'
+                    now = '로그인'
                 else:
                 else:
                     now = '일반'
                     now = '일반'
                 
                 
@@ -2688,8 +2743,8 @@ def acl(name = None):
                                     <br> \
                                     <br> \
                                     <form method="post"> \
                                     <form method="post"> \
                                         <select name="select"> \
                                         <select name="select"> \
-                                            <option value="admin" selected="selected">관리자</option> \
-                                            <option value="user">유저 이상</option> \
+                                            <option value="admin" selected="selected">관리자</option> \
+                                            <option value="user">로그인</option> \
                                             <option value="normal">일반</option> \
                                             <option value="normal">일반</option> \
                                         </select> \
                                         </select> \
                                         <br> \
                                         <br> \
@@ -2960,6 +3015,11 @@ def read_view(name = None, num = None, redirect = None):
         if(test and test[0][0] != 'user'):
         if(test and test[0][0] != 'user'):
             acl = ' (관리자)'
             acl = ' (관리자)'
 
 
+        if(rows[0][0] == 'all'):
+            acl += ' (모두)'
+        elif(rows[0][0] == 'user'):
+            acl += ' (로그인)'
+
         curs.execute("select block from ban where block = ?", [g[0]])
         curs.execute("select block from ban where block = ?", [g[0]])
         user = curs.fetchall()
         user = curs.fetchall()
         if(user):
         if(user):
@@ -3200,6 +3260,7 @@ def user_info():
                                                         ' * [[wiki:alarm|알림]]\r\n' + \
                                                         ' * [[wiki:alarm|알림]]\r\n' + \
                                                         ' * [[wiki:change|비밀번호 변경]]\r\n' + \
                                                         ' * [[wiki:change|비밀번호 변경]]\r\n' + \
                                                         ' * [[wiki:count|기여 횟수]]\r\n' + \
                                                         ' * [[wiki:count|기여 횟수]]\r\n' + \
+                                                        ' * [[wiki:user_acl/' + url_pas(raw_ip) + '|사용자 문서 ACL]]\r\n' + \
                                                         ' * [[wiki:custom_css|사용자 CSS]]\r\n' + \
                                                         ' * [[wiki:custom_css|사용자 CSS]]\r\n' + \
                                                         ' * [[wiki:custom_js|사용자 JS]]\r\n', 0, 0, 0),
                                                         ' * [[wiki:custom_js|사용자 JS]]\r\n', 0, 0, 0),
                 menu = 0
                 menu = 0

+ 79 - 74
func.py

@@ -157,96 +157,101 @@ def custom_js():
 
 
 def acl_check(name):
 def acl_check(name):
     ip = ip_check()
     ip = ip_check()
-    m = re.search("^사용자:([^/]*)", name)
-    n = re.search("^파일:(.*)", name)
-    if(m):
-        g = m.groups()
-        if(ip == g[0]):
-            if(re.search("(\.|:)", g[0])):
+    band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
+    if(band):
+        band_it = band.groups()
+    else:
+        band_it = ['Not']
+
+    curs.execute("select block from ban where block = ? and band = 'O'", [band_it[0]])
+    band_d = curs.fetchall()
+
+    curs.execute("select block from ban where block = ?", [ip])
+    ban_d = curs.fetchall()
+    if(band_d or ban_d):
+        return(1)
+
+    acl_c = re.search("^사용자:([^/]*)", name)
+    if(acl_c):
+        acl_n = acl_c.groups()
+        
+        curs.execute("select acl from data where title = ?", [acl_n[0]])
+        acl_d = curs.fetchall()
+        if(acl_d):
+            if(acl_d[0][0] == 'all'):
+                return(0)
+
+            if(acl_d[0][0] == 'user' and not re.search("(\.|:)", acl_n[0])):
+                return(0)
+
+            if(not ip == g[0] or re.search("(\.|:)", acl_n[0])):
                 return(1)
                 return(1)
-            else:
-                curs.execute("select block from ban where block = ?", [ip])
-                rows = curs.fetchall()
-                if(rows):
-                    return(1)
-                else:
-                    return(0)
-        else:
-            return(1)
-    elif(n and admin_check(5, 'edit (' + name + ')') != 1):
+        
+        return(0)
+
+    file_c = re.search("^파일:(.*)", name)
+    if(file_c and admin_check(5, 'edit (' + name + ')') != 1):
         return(1)
         return(1)
+
+    curs.execute("select acl from data where title = ?", [name])
+    acl_d = curs.fetchall()
+    if(not acl_d):
+        return(0)
+
+    curs.execute("select acl from user where id = ?", [ip])
+    user_d = curs.fetchall()
+    if(acl_d[0][0] == 'user' and user_d):
+        return(0)
     else:
     else:
-        b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
-        if(b):
-            results = b.groups()
-            curs.execute("select block from ban where block = ? and band = 'O'", [results[0]])
-            rowss = curs.fetchall()
-            if(rowss):
-                return(1)
+        return(1)
 
 
-        curs.execute("select block from ban where block = ?", [ip])
-        rows = curs.fetchall()
-        if(rows):
-            return(1)
-        else:
-            curs.execute("select acl from data where title = ?", [name])
-            row = curs.fetchall()
-            if(row):
-                curs.execute("select acl from user where id = ?", [ip])
-                rows = curs.fetchall()
-                if(row[0][0] == 'user'):
-                    if(rows):
-                        return(0)
-                    else:
-                        return(1)
-                elif(row[0][0] == 'admin'):
-                    if(rows and admin_check(5, 'edit (' + name + ')') == 1):
-                        return(0)
-                    else:
-                        return(1)
-                else:
-                    return(0)
-            else:
-                return(0)    
+    if(acl_d[0][0] == 'admin' and user_d and admin_check(5, 'edit (' + name + ')') == 1):
+        return(0)
+    else:
+        return(1)
+
+    return(0)
 
 
 def ban_check():
 def ban_check():
     ip = ip_check()
     ip = ip_check()
-    b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
-    if(b):
-        results = b.groups()
-        curs.execute("select block from ban where block = ? and band = 'O'", [results[0]])
-        rowss = curs.fetchall()
-        if(rowss):
-            return(1)
+    band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
+    if(band):
+        band_it = band.groups()
+    else:
+        band_it = ['Not']
+        
+    curs.execute("select block from ban where block = ? and band = 'O'", [band_it[0]])
+    band_d = curs.fetchall()
 
 
     curs.execute("select block from ban where block = ?", [ip])
     curs.execute("select block from ban where block = ?", [ip])
-    rows = curs.fetchall()
-    if(rows):
+    ban_d = curs.fetchall()
+    if(band_d or ban_d):
         return(1)
         return(1)
-    else:
-        return(0)
+    
+    return(0)
         
         
 def topic_check(name, sub):
 def topic_check(name, sub):
     ip = ip_check()
     ip = ip_check()
-    b = re.search("^([0-9](?:[0-9]?[0-9]?)\.[0-9](?:[0-9]?[0-9]?))", ip)
-    if(b):
-        results = b.groups()
-        curs.execute("select block from ban where block = ? and band = 'O'", [results[0]])
-        rowss = curs.fetchall()
-        if(rowss):
-            return(1)
+    band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
+    if(band):
+        band_it = band.groups()
+    else:
+        band_it = ['Not']
+        
+    curs.execute("select block from ban where block = ? and band = 'O'", [band_it[0]])
+    band_d = curs.fetchall()
 
 
     curs.execute("select block from ban where block = ?", [ip])
     curs.execute("select block from ban where block = ?", [ip])
-    rows = curs.fetchall()
-    if(rows):
+    ban_d = curs.fetchall()
+    if(band_d or ban_d):
         return(1)
         return(1)
-    else:
-        curs.execute("select title from stop where title = ? and sub = ?", [name, sub])
-        rows = curs.fetchall()
-        if(rows):
-            return(1)
-        else:
-            return(0)
+
+    curs.execute("select title from stop where title = ? and sub = ?", [name, sub])
+    topic_s = curs.fetchall()
+    if(topic_s):
+        return(1)
+
+    return(0)
 
 
 def rd_plus(title, sub, date):
 def rd_plus(title, sub, date):
     curs.execute("select title from rd where title = ? and sub = ?", [title, sub])
     curs.execute("select title from rd where title = ? and sub = ?", [title, sub])