]> git.ipfire.org Git - ipfire.org.git/commitdiff
backend: show checksum on thank-you page
authorRico Hoppe <rico.hoppe@ipfire.org>
Sat, 11 May 2024 13:57:33 +0000 (13:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 13 May 2024 09:42:08 +0000 (09:42 +0000)
* this fixes bug 13652
* implemented function to get file by filename
* implemented checksum into thank-you page
* removed checksum from title of download links

Signed-off-by: Rico Hoppe <rico.hoppe@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/releases.py
src/templates/downloads/release.html
src/templates/downloads/thank-you.html
src/web/downloads.py

index bed051d04ce477ecca4e5133fde0a48bb38ca5c2..895c6ca300690dad5f4f9d4ab84fe129195b36ce 100644 (file)
@@ -482,3 +482,9 @@ class Releases(Object):
 
                        with self.db.transaction():
                                release.scan_files(basepath=basepath)
+
+       def get_file_by_filename(self, filename):
+               ret = self.db.get("SELECT * FROM files WHERE filename = %s", filename)
+
+               if ret:
+                       return File(self.backend, None, ret.id, data=ret)
index 0673391489ebb8f4e7b4b6a52d16d92796dc4ed0..9ff42de61099fbd93c6830ccf8a45b18db36b52c 100644 (file)
@@ -34,8 +34,7 @@
                                                                <ul>
                                                                        {% for file in release.get_files_by_arch(arch) %}
                                                                                <li>
-                                                                                       <a class="download-splash" href="{{ file.url }}"
-                                                                                                       title="{{ "%s: %s" % ("SHA256" if file.sha256 else "SHA1", file.sha256 or file.sha1) }}">
+                                                                                       <a class="download-splash" href="{{ file.url }}">
                                                                                                <span class="icon-text">
                                                                                                        <span class="icon">
                                                                                                                <i class="fas fa-download"></i>
@@ -87,7 +86,7 @@
                $("a.download-splash").click(function(e) {
                        e.preventDefault();
 
-                       window.location = "/downloads/thank-you?file=" + this.href;
+                       window.location = "/downloads/thank-you?url=" + this.href;
                });
        </script>
 {% end %}
index 559cc66e72a7a085e44bd36978fcc65ebf9f6379..33da55f9d8b4a7424a37ddd84b97d4108da144e6 100644 (file)
@@ -9,10 +9,17 @@
                                <h1 class="title">
                                        Thank You For Choosing IPFire<span class="has-text-primary">_</span>
                                </h1>
-                               <h4 class="subtitle">{{ _("Your download will begin shortly.") }}</h4>
+                               <h4 class="subtitle">{{ _("Your download will begin shortly") }}</h4>
 
                                <div class="block">
-                                       <p class="download-path"></p>
+                                       <a href="{{ file.url }}">{{ file.url }}</a>
+                               </div>
+
+                               <div class="block">
+                                       <p>
+                                               {{ _("After download, please verify the file has the following %s checksum:") % ("SHA-256" if file.sha256 else "SHA-1") }}
+                                               <span class="is-family-monospace">{{ file.sha256 or file.sha1 }}</span>
+                                       </p>
                                </div>
                        </div>
                </div>
 
 {% block javascript %}
        <script type="text/javascript">
-               $("p.download-path").ready(function() {
-                       const params = new URLSearchParams(window.location.search);
-
-                       var file = params.get("file");
-
-                       // Avoid downloading files from other websites
-                       if (!file.startsWith("https://downloads.ipfire.org/"))
-                               return;
-
-                       $("p.download-path").prepend($("<a>", {
-                               href: encodeURI(file),
-                               text: file
-                       }));
-
-                       setTimeout(function() {
-                               window.location = file
-                       }, "2000");
-               });
+               setTimeout(function() {
+                       window.location = "{{ file.url }}"
+               }, "2000");
        </script>
 {% end %}
index de1c79a18844e6ce82f945f880195753fe612d31..05f95994ebbc5385e329364d058a004597d6b211 100644 (file)
@@ -35,7 +35,20 @@ class ReleaseHandler(base.AnalyticsMixin, base.BaseHandler):
 
 class ThankYouHandler(base.AnalyticsMixin, base.BaseHandler):
        def get(self):
-               self.render("downloads/thank-you.html")
+               url = self.get_argument("url")
+
+               # Send 400 if URL is wrong
+               if not url.startswith("https://downloads.ipfire.org/"):
+                       raise tornado.web.HTTPError(400)
+
+               filename = url.removeprefix("https://downloads.ipfire.org/")
+
+               # Get file by URL
+               file = self.backend.releases.get_file_by_filename(filename)
+               if not file:
+                       raise tornado.web.HTTPError(404)
+
+               self.render("downloads/thank-you.html", file=file)
 
 
 class FileHandler(base.AnalyticsMixin, base.BaseHandler):