Explorar el Código

일부 아이피 관련 수정

Surplus_Up (2DU) hace 6 años
padre
commit
31408f3eeb
Se han modificado 3 ficheros con 21 adiciones y 22 borrados
  1. 6 2
      route/api_topic_sub.py
  2. 6 1
      route/tool/func.py
  3. 9 19
      route/tool/set_mark/tool.py

+ 6 - 2
route/api_topic_sub.py

@@ -37,7 +37,9 @@ def api_topic_sub_2(conn, topic_num):
                     t_data_f = ''
                     b_color = 'toron_color_not'
 
-                curs.execute(db_change("select who from re_admin where what = ? order by time desc limit 1"), ['blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'])
+                curs.execute(db_change("select who from re_admin where what = ? order by time desc limit 1"), [
+                    'blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'
+                ])
                 who_blind = curs.fetchall()
                 if who_blind:
                     ip += ' (' + who_blind[0][0] + ' B)'
@@ -94,7 +96,9 @@ def api_topic_sub_2(conn, topic_num):
                 if i[4] != 'O' or (i[4] == 'O' and admin == 1):
                     t_data_f = i[1]
                 else:
-                    curs.execute(db_change("select who from re_admin where what = ? order by time desc limit 1"), ['blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'])
+                    curs.execute(db_change("select who from re_admin where what = ? order by time desc limit 1"), [
+                        'blind (' + name + ' - ' + sub + '#' + str(i[0]) + ')'
+                    ])
                     who_blind = curs.fetchall()
                     if who_blind:
                         t_data_f = '[[user:' + who_blind[0][0] + ']] block'

+ 6 - 1
route/tool/func.py

@@ -605,7 +605,10 @@ def ip_pas(raw_ip, type_d = 0):
         curs.execute(db_change("select data from other where name = 'ip_view'"))
         data = curs.fetchall()
         if data and data[0][0] != '':
-            ip = re.sub('((?:(?!\.).)+)\.((?:(?!\.).)+)$', '*.*', raw_ip)
+            if re.search('\.', raw_ip):
+                ip = re.sub('\.([^.]*)\.([^.]*)$', '.*.*', raw_ip)
+            else:
+                ip = re.sub(':([^:]*):([^:]*)$', ':*:*', raw_ip)
 
             if not admin_check(1):
                 hide = 1
@@ -621,6 +624,8 @@ def ip_pas(raw_ip, type_d = 0):
 
             if admin_check('all', None, raw_ip) == 1:
                 ip = '<b>' + ip + '</b>'
+        else:
+            ip = raw_ip
 
     if type_d == 0:
         if ban_check(raw_ip) == 1:

+ 9 - 19
route/tool/set_mark/tool.py

@@ -21,25 +21,15 @@ def db_change(data):
     return data
 
 def ip_check(d_type = 0):
-    if d_type == 0:
-        if flask.session and ('state' and 'id') in flask.session:
-            ip = flask.session['id']
-        else:
-            try:
-                ip = flask.request.environ.get('HTTP_X_REAL_IP', flask.request.environ.get('HTTP_X_FORWARDED_FOR', flask.request.remote_addr))
-
-                if ip == '::1' or ip == '127.0.0.1':
-                    ip = flask.request.environ.get('HTTP_X_FORWARDED_FOR', flask.request.remote_addr)
-            except:
-                ip = '-'
-    else:
-        try:
-            ip = flask.request.environ.get('HTTP_X_REAL_IP', flask.request.environ.get('HTTP_X_FORWARDED_FOR', flask.request.remote_addr))
-
-            if ip == '::1' or ip == '127.0.0.1':
-                ip = flask.request.environ.get('HTTP_X_FORWARDED_FOR', flask.request.remote_addr)
-        except:
-            ip = '-'
+    ip = ''
+    if d_type == 0 and (flask.session and ('state' and 'id') in flask.session):
+        ip = flask.session['id']
+    
+    if ip == '':
+        ip = flask.request.environ.get('HTTP_X_REAL_IP', flask.request.environ.get('HTTP_X_FORWARDED_FOR', flask.request.remote_addr))
+
+        if ip == '::1' or ip == '127.0.0.1':
+            ip = flask.request.environ.get('HTTP_X_FORWARDED_FOR', flask.request.remote_addr)
 
     return str(ip)