From 3393638f931e03d62f6524bb8ea5f1ff1c7493f9 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Fri, 13 Oct 2023 02:31:50 +0200
Subject: [PATCH] Continued: - added view for recently added instances

---
 daemon.py                  |  9 +++++++++
 templates/views/index.html |  5 +++++
 templates/views/list.html  | 10 +++++++++-
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/daemon.py b/daemon.py
index b16e9e9..f3f246f 100755
--- a/daemon.py
+++ b/daemon.py
@@ -123,6 +123,15 @@ WHERE {mode} = ? \
 ORDER BY domain \
 LIMIT ?", [value, amount]
         )
+    elif mode == "recently":
+        database.cursor.execute(
+            f"SELECT * \
+FROM instances \
+ORDER BY first_seen DESC \
+LIMIT ?", [amount]
+        )
+    else:
+        raise HTTPException(status_code=500, detail=f"mode='{mode}' is unsupported")
 
     domainlist = database.cursor.fetchall()
     return domainlist
diff --git a/templates/views/index.html b/templates/views/index.html
index 4630c10..8660d39 100644
--- a/templates/views/index.html
+++ b/templates/views/index.html
@@ -68,6 +68,11 @@
         <li><a href="scoreboard?mode=obfuscation&amp;amount=10">Obfuscation statistics</a></li>
         <li><a href="scoreboard?mode=block_level&amp;amount=20">Block level statistics</a></li>
     </ul>
+
+    <h2>Recently added:</h2>
+    <ul class="nav">
+        <li><a href="list?mode=recently&amp;value=1&amp;amount=50">50 instances</a></li>
+    </ul>
 {% endblock %}
 {% block footer %}
     <div class="notice">
diff --git a/templates/views/list.html b/templates/views/list.html
index 09b12c0..1f5ff96 100644
--- a/templates/views/list.html
+++ b/templates/views/list.html
@@ -1,6 +1,12 @@
 {% extends "base.html" %}
 
-{% block title %}{% if mode == 'detection_mode' %} - Detection mode {{value}}{% elif mode == 'software' %} - Used software {{value}}{% elif mode == 'command' %} - Command {{value}}{% endif %}{% endblock %}
+{% block title %}
+    {% if mode == 'detection_mode' %} - Detection mode {{value}}
+    {% elif mode == 'software' %} - Used software {{value}}
+    {% elif mode == 'command' %} - Command {{value}}
+    {% elif mode == 'recently' %} - {{amount}} recently added instances
+    {% endif %}
+{% endblock %}
 
 {% block header %}
     {% if mode == 'detection_mode' %}
@@ -11,6 +17,8 @@
         <h1>Instances found by command {{value}}</h1>
     {% elif mode == 'origin' %}
         <h1>Instances originated from {{value}}</h1>
+    {% elif mode == 'recently' %}
+        <h1>{{amount}} recently added instances</h1>
     {% else %}
         <h1 style="color: red">mode={{mode}} not supported</h1>
     {% endif %}
-- 
2.39.5