403Webshell
Server IP : 104.21.21.239  /  Your IP : 216.73.216.11
Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5
System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/banners/public_html/bway/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/banners/public_html/bway/includepoll.js
/**
 * includepoll.js
 *
 * Usage in HTML:
 *   <script src="https://cloud.broadwayworld.com/includepoll.js?pollid=1"></script>
 *   <script src="https://cloud.broadwayworld.com/includepoll.js?pollid=2"></script>
 *
 * This script will:
 *  - Use `document.currentScript` to get its own <script> element,
 *    extracting `pollid` from that script's URL.
 *  - Check if a cookie indicates the user has voted on this pollid.
 *  - If not voted, it loads the poll from `includepoll.cfm` and shows the form inline.
 *  - If already voted, it shows the results (percentages only).
 *  - When a user votes, sets a cookie for 7 days and then shows results.
 */

(function () {
  // Define the base URL for all requests
  var BASE_URL = "https://cloud.broadwayworld.com/";

  // Attempt to get the <script> element for this invocation via currentScript
  var scriptEl = document.currentScript;
  if (!scriptEl) {
    console.warn("[includepoll.js] Could not find currentScript; this may not work in older browsers.");
    return; // In older browsers without a fallback, we bail or use alternative logic
  }

  // Extract the pollid from the script's query parameters
  var scriptSrc = new URL(scriptEl.src, window.location.origin);
  var pollid = scriptSrc.searchParams.get("pollid");
  if (!pollid) {
    console.warn("[includepoll.js] No pollid provided!");
    return;
  }

  // Check if user has already voted (cookie "poll_{pollid}=voted")
  var hasVoted = (document.cookie.indexOf("poll_" + pollid + "=voted") !== -1);

  // Create the container for the poll right after this script tag
  var pollContainer = document.createElement("div");
  pollContainer.id = "poll-container-" + pollid;
  pollContainer.style.border = "1px solid #ccc";
  pollContainer.style.padding = "10px";
  pollContainer.style.margin = "10px 0";

  // Insert pollContainer inline, right after <script>
  if (scriptEl.parentNode) {
    scriptEl.parentNode.insertBefore(pollContainer, scriptEl.nextSibling);
  } else {
    // Fallback: if for some reason there's no parent, append to body
    document.body.appendChild(pollContainer);
  }

  /**
   * loadPoll()
   * Fetches poll data. Shows results if user has voted, otherwise shows form.
   */
  function loadPoll() {
    fetch(BASE_URL + "includepoll.cfm?action=getPoll&pollid=" + pollid)
      .then(function (response) {
        return response.json();
      })
      .then(function (data) {
        if (!data.success) {
          pollContainer.innerHTML = "<p>Poll not found.</p>";
          return;
        }
        if (hasVoted) {
          renderPollResults(data.poll);
        } else {
          renderPollForm(data.poll);
        }
      })
      .catch(function (error) {
        console.error("[includepoll.js] Error loading poll:", error);
        pollContainer.innerHTML = "<p>Error loading poll.</p>";
      });
  }

  /**
   * renderPollForm(poll)
   * Builds and displays a radio form for poll answers.
   */
  function renderPollForm(poll) {
    var html = "<h3 style='font-size:20px;font-weight:700;'>" + escapeHtml(poll.question) + "</h3>";
    html += '<form id="pollForm-' + pollid + '">';

    // Up to 6 answers
    for (var i = 1; i <= 6; i++) {
      var answerText = poll["answer" + i];
      if (answerText) {
        html +=
          "<p>" +
          "<label>" +
          '<input type="radio" name="answer" value="' +
          i +
          '"> ' +
          escapeHtml(answerText) +
          "</label>" +
          "</p>";
      }
    }

    html += '<p><button type="submit" class="btn register-btn">Vote</button></p>';
    html += "</form>";

    pollContainer.innerHTML = html;

    var pollForm = document.getElementById("pollForm-" + pollid);
    if (pollForm) {
      pollForm.addEventListener("submit", function (evt) {
        evt.preventDefault();
        var selected = pollForm.querySelector('input[name="answer"]:checked');
        if (!selected) {
          alert("Please select an answer.");
          return;
        }
        submitVote(selected.value);
      });
    }
  }

  /**
   * submitVote(answerNum)
   * Submits the user's choice, sets the cookie, and shows results.
   */
  function submitVote(answerNum) {
    fetch(BASE_URL + "includepoll.cfm?action=submitVote&pollid=" + pollid + "&answer=" + answerNum)
      .then(function (response) {
        return response.json();
      })
      .then(function (data) {
        if (!data.success) {
          pollContainer.innerHTML = "<p>Error recording vote.</p>";
          return;
        }
        // Troubleshooting: uncomment to inspect API response after vote
        // console.log("[includepoll.js] After vote, poll data:", data.poll);
        // Set a 7-day cookie
        setVoteCookie(pollid);
        hasVoted = true;

        // Show results
        renderPollResults(data.poll);
      })
      .catch(function (error) {
        console.error("[includepoll.js] Error submitting vote:", error);
        pollContainer.innerHTML = "<p>Error submitting vote.</p>";
      });
  }

  /**
   * renderPollResults(poll)
   * Shows poll results in percentages only.
   */
  function renderPollResults(poll) {
    var totalVotes = 0;
    var answerCounts = [];

    for (var i = 1; i <= 6; i++) {
      if (poll["answer" + i]) {
        var raw = poll["answer" + i + "_clicks"];
        var count = parseInt(raw === undefined || raw === null ? "0" : String(raw), 10);
        if (isNaN(count)) count = 0;
        answerCounts[i] = count;
        totalVotes += count;
      }
    }

    var html = "<h3 style='font-size:20px;font-weight:700;'>" + escapeHtml(poll.question) + "</h3>";
    html += "<p>Thanks for your vote! Here are the results:</p>";
    html += "<ul>";

    for (var j = 1; j <= 6; j++) {
      var ansText = poll["answer" + j];
      if (ansText) {
        var count = answerCounts[j] || 0;
        var pct = totalVotes > 0 ? ((count / totalVotes) * 100).toFixed(1) : 0;
        html += "<li>" + escapeHtml(ansText) + " - " + pct + "%</li>";
      }
    }
    html += "</ul>";

    pollContainer.innerHTML = html;
  }

  /**
   * setVoteCookie(pid)
   * Creates a cookie poll_{pid}=voted for 7 days.
   */
  function setVoteCookie(pid) {
    var cookieName = "poll_" + pid;
    var d = new Date();
    d.setTime(d.getTime() + 7 * 24 * 60 * 60 * 1000);
    var expires = "expires=" + d.toUTCString();
    document.cookie = cookieName + "=voted; " + expires + "; path=/";
  }

  /**
   * escapeHtml(str)
   * Basic HTML escaping to prevent injection.
   */
  function escapeHtml(str) {
    if (!str) return "";
    return str
      .replace(/&/g, "&amp;")
      .replace(/</g, "&lt;")
      .replace(/>/g, "&gt;")
      .replace(/"/g, "&quot;");
  }

  // Finally, load the poll
  loadPoll();
})();

Youez - 2016 - github.com/yon3zu
LinuXploit