]> git.ipfire.org Git - pbs.git/commitdiff
images: Add modal with all checksums
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Feb 2025 17:08:42 +0000 (17:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Feb 2025 17:08:42 +0000 (17:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/images.py
src/templates/images/macros.html

index 6833dea0b5498fc6bbb08ed318791aa5b71d359a..526c1e112d3e9d2e66962d73a51f8524f74c1469 100644 (file)
@@ -19,6 +19,7 @@
 ###############################################################################
 
 import logging
+import os.path
 
 import sqlalchemy
 from sqlalchemy import Column, ForeignKey
@@ -90,6 +91,12 @@ class Image(database.Base, database.BackendMixin, database.SoftDeleteMixin):
 
        path = Column(Text, nullable=False)
 
+       # Filename
+
+       @property
+       def filename(self):
+               return os.path.basename(self.path)
+
        # Link
 
        @property
@@ -103,6 +110,25 @@ class Image(database.Base, database.BackendMixin, database.SoftDeleteMixin):
 
        size = Column(BigInteger, nullable=False)
 
+       # Checksums
+
+       @property
+       def checksums(self):
+               """
+                       A dictionary with all available checksums
+               """
+               checksums = {
+                       "sha3-512"   : self.checksum_sha3_512,
+                       "sha3-256"   : self.checksum_sha3_256,
+                       "blake2b512" : self.checksum_blake2b512,
+                       "blake2s256" : self.checksum_blake2s256,
+                       "sha2-512"   : self.checksum_sha2_512,
+                       "sha2-256"   : self.checksum_sha2_256,
+               }
+
+               # Filter out any empty checksums
+               return { algo : checksums[algo] for algo in checksums if checksums[algo] }
+
        # Checksum SHA3-512
 
        checksum_sha3_512 = Column(LargeBinary, nullable=False)
index 14bfe5c19d664b3df351a561d48a1d98390ef333..27b11a4b9d5fe635725292795d25ab70dce9bc1c 100644 (file)
                                                                                </a>
                                                                        </small>
                                                                </div>
+
+                                                               {# Checksums Link #}
+                                                               <div class="level-item">
+                                                                       <small>
+                                                                               <a href="#" class="modal-toggle" data-target="image-{{ image.type }}-{{ image.arch }}">
+                                                                                       <span class="icon-text">
+                                                                                               <span class="icon">
+                                                                                                       <i class="fa-solid fa-hashtag"></i>
+                                                                                               </span>
+                                                                                       </span>
+                                                                               </a>
+                                                                       </small>
+                                                               </div>
                                                        </nav>
                                                </div>
+
+                                               {# Modal with the checksums #}
+                                               <div class="modal" id="image-{{ image.type }}-{{ image.arch }}">
+                                                       <div class="modal-background"></div>
+                                                               <div class="modal-content">
+                                                                       <section class="modal-card-body">
+                                                                               <div class="content">
+                                                                                       <h4 class="title is-4">
+                                                                                               {{ _("Checksums for %s") % image.filename }}
+                                                                                       </h4>
+
+                                                                                       <p>
+                                                                                               {{ _("To ensure your downloaded file is complete and unmodified, "
+                                                                                                       "use the checksums below to verify its integrity. "
+                                                                                                       "Compare the checksum of your downloaded file with the one "
+                                                                                                       "listed here. If they match, your file is intact.") }}
+                                                                                       </p>
+
+                                                                                       <ul>
+                                                                                               {% for algo, checksum in image.checksums.items() %}
+                                                                                                       <li>
+                                                                                                               <strong>
+                                                                                                                       {% if algo == "sha3-512" %}
+                                                                                                                               {{ _("SHA3-512" )}}
+                                                                                                                       {% elif algo == "sha3-256" %}
+                                                                                                                               {{ _("SHA3-256") }}
+                                                                                                                       {% elif algo == "blake2b512" %}
+                                                                                                                               {{ _("BLAKE2b512") }}
+                                                                                                                       {% elif algo == "blake2b256" %}
+                                                                                                                               {{ _("BLAKE2s256") }}
+                                                                                                                       {% elif algo == "sha2-512" %}
+                                                                                                                               {{ _("SHA2-512") }}
+                                                                                                                       {% elif algo == "sha2-256" %}
+                                                                                                                               {{ _("SHA2-256") }}
+                                                                                                                       {% else %}
+                                                                                                                               {{ algo }}
+                                                                                                                       {% endif %}
+                                                                                                               </strong>
+
+                                                                                                               <br>
+
+                                                                                                               <code>
+                                                                                                                       {{ checksum.hex() }}
+                                                                                                               </code>
+                                                                                                       </li>
+                                                                                               {% endfor %}
+                                                                                       </li>
+                                                                               </div>
+                                                                   </section>
+                                                               </div>
+
+                                                               {# Close Button #}
+                                                               <button class="modal-close is-large" aria-label="close"></button>
+                                               </div>
                                        {% endfor %}
                                </div>
                        </div>