From d4d7287a0042ee65b5d0fde0f4eb93ff67e7f3c9 Mon Sep 17 00:00:00 2001
From: sk_han <areedd@qq.com>
Date: Wed, 1 Jan 2025 18:11:37 +0800
Subject: [PATCH 1/7] debug

---
 app.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/app.py b/app.py
index 60fe918..ea71598 100644
--- a/app.py
+++ b/app.py
@@ -82,7 +82,4 @@ def is_running_in_docker():
 
 
 if __name__ == '__main__':
-    if is_running_in_docker():
-        app.run(host='0.0.0.0', port=5000, debug=False)
-    else:
-        app.run(debug=False)
+    app.run(host='0.0.0.0', port=5000, debug=False)

From b81b30c960fb08a00cbf17492e2ab1bc5b8fa61e Mon Sep 17 00:00:00 2001
From: sk_han <areedd@qq.com>
Date: Wed, 1 Jan 2025 19:06:25 +0800
Subject: [PATCH 2/7] fix and update

---
 app.py           | 18 +++++-------------
 logo_matching.py |  2 ++
 logo_recog.py    |  4 ++--
 3 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/app.py b/app.py
index ea71598..0bbcd29 100644
--- a/app.py
+++ b/app.py
@@ -34,13 +34,16 @@ def analyze():
         screenshot_path = 'temp_screenshot.png'
         image.save(screenshot_path, format='PNG')
 
+        print("hello")
         # 调用Phishpedia模型进行识别
         phish_category, pred_target, matched_domain, \
             plotvis, siamese_conf, pred_boxes, \
             logo_recog_time, logo_match_time = phishpedia_cls.test_orig_phishpedia(url, screenshot_path, None)
-        
+        print("hello")
+ 
         today = datetime.now().strftime('%Y%m%d')
         log_file_path = os.path.join(log_dir, f'{today}_results.txt')
+        
 
         try:
             with open(log_file_path, "a+", encoding='ISO-8859-1') as f:
@@ -69,17 +72,6 @@ def analyze():
         return jsonify("ERROR"), 500
 
 
-def is_running_in_docker():
-    """检查是否在 Docker 环境中运行"""
-    # 方法1:检查 /.dockerenv 文件是否存在
-    docker_env = os.path.exists('/.dockerenv')
-    # 方法2:检查 cgroup 中是否包含 docker 字符串
-    try:
-        with open('/proc/1/cgroup', 'r') as f:
-            return docker_env or 'docker' in f.read()
-    except (IOError, OSError):  # 明确指定可能的异常类型
-        return docker_env
-
 
 if __name__ == '__main__':
-    app.run(host='0.0.0.0', port=5000, debug=False)
+    app.run(host='0.0.0.0', port=5000, debug=True)
diff --git a/logo_matching.py b/logo_matching.py
index 807f4ed..77590f7 100644
--- a/logo_matching.py
+++ b/logo_matching.py
@@ -111,6 +111,8 @@ def cache_reference_list(model, targetlist_path: str, grayscale=False):
                 except OSError:
                     print(f"Error opening image: {os.path.join(targetlist_path, target, logo_path)}")
                     continue
+    
+    return logo_feat_list, file_name_list
 
 
 @torch.no_grad()
diff --git a/logo_recog.py b/logo_recog.py
index 42e132e..e90577f 100644
--- a/logo_recog.py
+++ b/logo_recog.py
@@ -80,8 +80,8 @@ def vis(img_path, pred_boxes):
     # draw rectangle
     for j, box in enumerate(pred_boxes):
         if j == 0:
-            cv2.rectangle(check, (int(box[0]), int(box[1])), (int(box[2]), int(box[3])), COLORS['0'], 2)
+            cv2.rectangle(check, (int(box[0]), int(box[1])), (int(box[2]), int(box[3])), COLORS[0], 2)
         else:
-            cv2.rectangle(check, (int(box[0]), int(box[1])), (int(box[2]), int(box[3])), COLORS['1'], 2)
+            cv2.rectangle(check, (int(box[0]), int(box[1])), (int(box[2]), int(box[3])), COLORS[1], 2)
 
     return check

From d05b9340a3def567513ed7068b653f234c65ed78 Mon Sep 17 00:00:00 2001
From: sk_han <areedd@qq.com>
Date: Wed, 1 Jan 2025 19:08:31 +0800
Subject: [PATCH 3/7]  fix and update

---
 app.py | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/app.py b/app.py
index 0bbcd29..a636944 100644
--- a/app.py
+++ b/app.py
@@ -34,17 +34,14 @@ def analyze():
         screenshot_path = 'temp_screenshot.png'
         image.save(screenshot_path, format='PNG')
 
-        print("hello")
         # 调用Phishpedia模型进行识别
         phish_category, pred_target, matched_domain, \
             plotvis, siamese_conf, pred_boxes, \
             logo_recog_time, logo_match_time = phishpedia_cls.test_orig_phishpedia(url, screenshot_path, None)
-        print("hello")
  
         today = datetime.now().strftime('%Y%m%d')
         log_file_path = os.path.join(log_dir, f'{today}_results.txt')
         
-
         try:
             with open(log_file_path, "a+", encoding='ISO-8859-1') as f:
                 result_file_write(f, current_dir, url, phish_category, pred_target, matched_domain, siamese_conf,
@@ -72,6 +69,5 @@ def analyze():
         return jsonify("ERROR"), 500
 
 
-
 if __name__ == '__main__':
     app.run(host='0.0.0.0', port=5000, debug=True)

From 5e5bd3012d8ce8318a69d398f93b6833215411e9 Mon Sep 17 00:00:00 2001
From: sk_han <areedd@qq.com>
Date: Wed, 1 Jan 2025 19:10:40 +0800
Subject: [PATCH 4/7] =?UTF-8?q?=E5=85=B3=E9=97=ADflask=20debug=E6=A8=A1?=
 =?UTF-8?q?=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app.py b/app.py
index a636944..bc5760b 100644
--- a/app.py
+++ b/app.py
@@ -70,4 +70,4 @@ def analyze():
 
 
 if __name__ == '__main__':
-    app.run(host='0.0.0.0', port=5000, debug=True)
+    app.run(host='0.0.0.0', port=5000, debug=False)

From 543e26a183283ec3d722e77aaa682e719b12d6e9 Mon Sep 17 00:00:00 2001
From: sk_han <areedd@qq.com>
Date: Wed, 1 Jan 2025 19:47:29 +0800
Subject: [PATCH 5/7] =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E4=BC=98?=
 =?UTF-8?q?=E5=8C=96=EF=BC=8C=E6=B7=BB=E5=8A=A0=E7=A9=BA=E5=80=BC=E5=A4=84?=
 =?UTF-8?q?=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app.py | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/app.py b/app.py
index bc5760b..9794ac7 100644
--- a/app.py
+++ b/app.py
@@ -38,31 +38,39 @@ def analyze():
         phish_category, pred_target, matched_domain, \
             plotvis, siamese_conf, pred_boxes, \
             logo_recog_time, logo_match_time = phishpedia_cls.test_orig_phishpedia(url, screenshot_path, None)
- 
+        
+        # 添加结果处理逻辑
+        result = {
+            "isPhishing": bool(phish_category),
+            "brand": pred_target if pred_target else "unknown",
+            "legitUrl": f"https://{matched_domain[0]}" if matched_domain else "unknown",
+            "confidence": float(siamese_conf) if siamese_conf is not None else 0.0
+        }
+
+        # 记录日志
         today = datetime.now().strftime('%Y%m%d')
         log_file_path = os.path.join(log_dir, f'{today}_results.txt')
         
         try:
             with open(log_file_path, "a+", encoding='ISO-8859-1') as f:
-                result_file_write(f, current_dir, url, phish_category, pred_target, matched_domain, siamese_conf,
-                                  logo_recog_time, logo_match_time)
+                result_file_write(f, current_dir, url, phish_category, pred_target, 
+                                matched_domain if matched_domain else ["unknown"], 
+                                siamese_conf if siamese_conf is not None else 0.0,
+                                logo_recog_time, logo_match_time)
         except UnicodeError:
             with open(log_file_path, "a+", encoding='utf-8') as f:
-                result_file_write(f, current_dir, url, phish_category, pred_target, matched_domain, siamese_conf,
-                                  logo_recog_time, logo_match_time)
-        # 目前返回示例数据
-        result = {
-            "isPhishing": bool(phish_category),
-            "brand": pred_target,
-            "legitUrl": "https://" + matched_domain[0],
-            "confidence": float(siamese_conf)
-        }
+                result_file_write(f, current_dir, url, phish_category, pred_target, 
+                                matched_domain if matched_domain else ["unknown"], 
+                                siamese_conf if siamese_conf is not None else 0.0,
+                                logo_recog_time, logo_match_time)
+
         if os.path.exists(screenshot_path):
             os.remove(screenshot_path)
+            
         return jsonify(result)
     
     except Exception as e:
-        print(e)
+        print(f"Error in analyze: {str(e)}")
         log_error_path = os.path.join(log_dir, 'log_error.txt')
         with open(log_error_path, "a+", encoding='utf-8') as f:
             f.write(f'{datetime.now().strftime("%Y-%m-%d %H:%M:%S")} - {str(e)}\n')

From 4629d04e9c26fcb289bf2773ca52ae25070fd049 Mon Sep 17 00:00:00 2001
From: sk_han <areedd@qq.com>
Date: Wed, 1 Jan 2025 19:52:32 +0800
Subject: [PATCH 6/7] =?UTF-8?q?=E8=A7=A3=E5=86=B3lint=E6=8A=A5=E9=94=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/app.py b/app.py
index 9794ac7..3d51127 100644
--- a/app.py
+++ b/app.py
@@ -53,14 +53,14 @@ def analyze():
         
         try:
             with open(log_file_path, "a+", encoding='ISO-8859-1') as f:
-                result_file_write(f, current_dir, url, phish_category, pred_target, 
-                                matched_domain if matched_domain else ["unknown"], 
+                result_file_write(f, current_dir, url, phish_category, pred_target,
+                                matched_domain if matched_domain else ["unknown"],
                                 siamese_conf if siamese_conf is not None else 0.0,
                                 logo_recog_time, logo_match_time)
         except UnicodeError:
             with open(log_file_path, "a+", encoding='utf-8') as f:
-                result_file_write(f, current_dir, url, phish_category, pred_target, 
-                                matched_domain if matched_domain else ["unknown"], 
+                result_file_write(f, current_dir, url, phish_category, pred_target,
+                                matched_domain if matched_domain else ["unknown"],
                                 siamese_conf if siamese_conf is not None else 0.0,
                                 logo_recog_time, logo_match_time)
 

From b97e6f8ba8bce6d97cc4bd1e922933db83317a23 Mon Sep 17 00:00:00 2001
From: sk_han <areedd@qq.com>
Date: Wed, 1 Jan 2025 19:56:16 +0800
Subject: [PATCH 7/7] =?UTF-8?q?=E8=A7=A3=E5=86=B3lint=E6=8A=A5=E9=94=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app.py | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/app.py b/app.py
index 3d51127..f5f6e98 100644
--- a/app.py
+++ b/app.py
@@ -7,11 +7,9 @@
 import os
 from phishpedia import PhishpediaWrapper, result_file_write
 
-
 app = Flask(__name__)
 CORS(app)
 
-
 # 在创建应用时初始化模型
 with app.app_context():
     current_dir = os.path.dirname(os.path.realpath(__file__))
@@ -27,7 +25,7 @@ def analyze():
         data = request.get_json()
         url = data.get('url')
         screenshot_data = data.get('screenshot')
-        
+
         # 解码Base64图片数据
         image_data = base64.b64decode(screenshot_data.split(',')[1])
         image = Image.open(BytesIO(image_data))
@@ -38,7 +36,7 @@ def analyze():
         phish_category, pred_target, matched_domain, \
             plotvis, siamese_conf, pred_boxes, \
             logo_recog_time, logo_match_time = phishpedia_cls.test_orig_phishpedia(url, screenshot_path, None)
-        
+
         # 添加结果处理逻辑
         result = {
             "isPhishing": bool(phish_category),
@@ -50,25 +48,25 @@ def analyze():
         # 记录日志
         today = datetime.now().strftime('%Y%m%d')
         log_file_path = os.path.join(log_dir, f'{today}_results.txt')
-        
+
         try:
             with open(log_file_path, "a+", encoding='ISO-8859-1') as f:
                 result_file_write(f, current_dir, url, phish_category, pred_target,
-                                matched_domain if matched_domain else ["unknown"],
-                                siamese_conf if siamese_conf is not None else 0.0,
-                                logo_recog_time, logo_match_time)
+                                  matched_domain if matched_domain else ["unknown"],
+                                  siamese_conf if siamese_conf is not None else 0.0,
+                                  logo_recog_time, logo_match_time)
         except UnicodeError:
             with open(log_file_path, "a+", encoding='utf-8') as f:
                 result_file_write(f, current_dir, url, phish_category, pred_target,
-                                matched_domain if matched_domain else ["unknown"],
-                                siamese_conf if siamese_conf is not None else 0.0,
-                                logo_recog_time, logo_match_time)
+                                  matched_domain if matched_domain else ["unknown"],
+                                  siamese_conf if siamese_conf is not None else 0.0,
+                                  logo_recog_time, logo_match_time)
 
         if os.path.exists(screenshot_path):
             os.remove(screenshot_path)
-            
+
         return jsonify(result)
-    
+
     except Exception as e:
         print(f"Error in analyze: {str(e)}")
         log_error_path = os.path.join(log_dir, 'log_error.txt')