A
Anonymous

Challenge Card - Copy this React, Tailwind Component to your project

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CTF Challenges</title> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <!-- Include Font Awesome for the download icon --> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet"> <style> /* Theme Styles */ body { font-family: 'Poppins', sans-serif; background-color: #1e1e2f; color: #ffffff; } .container { margin-top: 50px; } h1 { color: #f8f9fa; font-weight: bold; text-align: center; margin-bottom: 30px; } h3 { color: #ffdd57; font-weight: bold; } .card { background-color: #2b2b3d; border: 1px solid #44475a; border-radius: 8px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); margin-bottom: 20px; transition: transform 0.3s ease, box-shadow 0.3s ease; } .card:hover { transform: translateY(-5px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); } .card-body { padding: 20px; } .card-title { font-size: 1.5rem; font-weight: bold; color: #f1fa8c; margin-bottom: 15px; display: flex; justify-content: space-between; align-items: center; } .card-title .badge { background-color: #50fa7b; } .card-title .download-icon { font-size: 1.2rem; color: #ff79c6; cursor: pointer; margin-left: 15px; } .card-text { font-size: 1rem; color: #f8f9fa; line-height: 1.6; margin-bottom: 15px; } .btn-primary { background-color: #6272a4; color: white; border: none; font-weight: bold; padding: 10px 20px; transition: background-color 0.3s, transform 0.3s ease; border-radius: 4px; } .btn-primary:hover { background-color: #44475a; transform: scale(1.05); } .btn-secondary { background-color: #44475a; color: white; border: none; font-weight: bold; padding: 8px 18px; transition: background-color 0.3s, transform 0.3s ease; border-radius: 4px; } .btn-secondary:hover { background-color: #6272a4; transform: scale(1.05); } .url { font-size: 1.1rem; color: #50fa7b; font-weight: bold; background-color: #1e1e2f; border: 1px solid #44475a; padding: 8px 10px; border-radius: 4px; display: inline-block; } .url:hover { color: #ff79c6; } .hint { color: #bd93f9; font-style: italic; } /* Status Section */ #status { margin-top: 20px; font-size: 1.1rem; color: #f8f9fa; } </style> </head> <body> <div class="container"> <h1 class="mt-5">CTF Challenges</h1> {% for category, category_challenges in categories.items() %} <div class="mt-4"> <h3>{{ category }}</h3> <div class="row"> {% for challenge in category_challenges %} <div class="col-md-12"> <div class="card"> <div class="card-body"> <h5 class="card-title"> {{ challenge.title }} <span class="badge badge-info">{{ challenge.difficulty }}</span> {% if challenge.attachment %} <a href="{{ url_for('download', filename=challenge.attachment[0]) }}" title="Download"> <i class="fas fa-download"></i> </a> {% endif %} </h5> <p class="card-text">{{ challenge.description | safe }}</p> {% if challenge.hint %} <div class="hint"> <strong>Hint:</strong> {{ challenge.hint }} </div> {% endif %} {% if challenge.docker_image %} <div class="challenge-info"> <button class="btn btn-primary start-challenge" data-docker-image="{{ challenge.docker_image }}" data-ports="{{ challenge.expose_ports|tojson }}"> Start Challenge </button> <div class="challenge-url" style="display:none;"> <a class="url" href="" target="_blank"></a> <button class="btn btn-secondary terminate-instance">Terminate Instance</button> </div> </div> {% endif %} </div> </div> </div> {% endfor %} </div> </div> {% endfor %} <div id="status"></div> </div> <script> $(document).ready(function () { // Start Challenge button logic $(".start-challenge").click(function () { let challengeCard = $(this).closest('.card'); // Get the current challenge card let dockerImage = $(this).data("docker-image"); let ports = $(this).data("ports"); // AJAX to start the Docker container $.ajax({ url: "/start-docker", type: "POST", contentType: "application/json", data: JSON.stringify({ docker_image: dockerImage, expose_ports: ports }), success: function (response) { if (response.container_id) { // Store container ID in the card for future reference challengeCard.data("container-id", response.container_id); // Hide the Start button and show Challenge URL & Terminate button challengeCard.find('.start-challenge').hide(); challengeCard.find('.challenge-url').show(); // Show the dynamically generated URL with IP and Port let challengeurl = response.ip + ":" + response.assigned_ports[Object.keys(response.assigned_ports)[0]]; challengeCard.find('.url') .text(challengeurl) .attr("href", "http://" + challengeurl); } else { $("#status").html("Challenge started, but no container ID was returned."); } }, error: function (xhr, status, error) { console.log("Error status: " + status); console.log("Error message: " + error); if (xhr.responseJSON) { let errorMsg = xhr.responseJSON.error || "An unknown error occurred"; $("#status").html("Error: " + errorMsg); } else { $("#status").html("Error: " + xhr.statusText || "An unknown error occurred"); } } }); }); // Terminate Challenge button logic $(".terminate-instance").click(function () { let challengeCard = $(this).closest('.card'); let containerId = challengeCard.data("container-id"); // Get the container ID from the card data // AJAX to terminate the Docker container $.ajax({ url: "/terminate-docker", type: "POST", contentType: "application/json", data: JSON.stringify({ container_id: containerId }), success: function (response) { if (response.status === "terminated") { // Hide the terminate button and display a success message challengeCard.find('.terminate-instance').hide(); challengeCard.find('.challenge-url').hide(); challengeCard.find('.start-challenge').show(); $("#status").html("Challenge terminated successfully."); } else if (response.success) { // Handle other success cases challengeCard.find('.challenge-url').hide(); challengeCard.find('.start-challenge').show(); $("#status").html("Challenge terminated successfully."); } else { $("#status").html("Failed to terminate the challenge."); } }, error: function (xhr, status, error) { console.log("Error status: " + status); console.log("Error message: " + error); if (xhr.responseJSON) { let errorMsg = xhr.responseJSON.error || "An unknown error occurred"; $("#status").html("Error: " + errorMsg); } else { $("#status").html("Error: " + xhr.statusText || "An unknown error occurred"); } } }); }); }); </script> </body> </html> can make it just look so much still beautiful?

Prompt

About

ChallengeCard - A sleek, interactive card for CTF challenges featuring Docker integration, download options, and hints, built with Rea. Get code instantly!

Share

Last updated 1 month ago