Siteβ―Builder
Editing:
admin-protected.js
writable 0666
// admin-protect.js (function() { // ====== CONFIGURE HERE ====== const PASSPHRASE = 'open'; // Change this for production! const COOKIE_DURATION = 60*60*24*30; // 30 days in seconds const LOCAL_KEY_NAME = 'adm_cookieName'; const LOCAL_KEY_VALUE = 'adm_cookieValue'; // ====== Helper functions ====== function randName(len=8) { const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; let res = ''; for(let i=0; i<len; ++i) res += chars[Math.floor(Math.random()*chars.length)]; return res; } function setCookie(name, value, maxage) { document.cookie = name + "=" + value + "; path=/; max-age=" + maxage; } function getCookie(name) { const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); return match ? match[2] : null; } // ====== Main logic ====== let cookieName = localStorage.getItem(LOCAL_KEY_NAME); let cookieValue = localStorage.getItem(LOCAL_KEY_VALUE); let ok = false; if (cookieName && cookieValue && getCookie(cookieName) === cookieValue) { ok = true; } function hideBody() { document.documentElement.style.display = "none"; } function showBody() { document.documentElement.style.display = ""; } if (!ok) { hideBody(); let tries = 0; function askPass() { let entered = prompt("Enter admin passphrase to access this page:"); if (entered === PASSPHRASE) { let newName = "adm_" + randName(7) + Date.now(); let newValue = randName(20) + Date.now(); setCookie(newName, newValue, COOKIE_DURATION); localStorage.setItem(LOCAL_KEY_NAME, newName); localStorage.setItem(LOCAL_KEY_VALUE, newValue); showBody(); location.reload(); } else { tries++; if(tries < 5) askPass(); else { document.body.innerHTML = "<h2 style='color:red;text-align:center;margin-top:5em'>Access Denied</h2>"; showBody(); } } } document.addEventListener("DOMContentLoaded", askPass); } })();
Save changes
Create folder
writable 0777
Create
Cancel