commit 5f64caf6bcbc645c57cf2f561c042837cd282db3 Author: mctaylors Date: Thu Jun 6 22:39:59 2024 +0500 Initial commit Signed-off-by: mctaylors diff --git a/activate/index.html b/activate/index.html new file mode 100644 index 0000000..7865332 --- /dev/null +++ b/activate/index.html @@ -0,0 +1,33 @@ + + + + + CensoredManager - Activate + + + +
+
+ + + +
+
+
+
+ + Balance: - + + CensoredManager
+ home - source code +
+
+ + + + + \ No newline at end of file diff --git a/assets/css/styles.css b/assets/css/styles.css new file mode 100644 index 0000000..ece6ed0 --- /dev/null +++ b/assets/css/styles.css @@ -0,0 +1,18 @@ +:root { +} + +.highlighted { + font-weight: bold; +} + +.right { + float: right; +} + +.footer { + font-style: italic; +} + +.display { + font-size: 24px; +} \ No newline at end of file diff --git a/assets/js/activate.js b/assets/js/activate.js new file mode 100644 index 0000000..891222e --- /dev/null +++ b/assets/js/activate.js @@ -0,0 +1,22 @@ +const token = docCookies.getItem("token"); +const notificationElement = document.getElementById("notification"); +const balanceElement = document.getElementById("balance"); + +window.addEventListener("load", async function () { + balanceElement.innerText = await getBalance(token); +}); + +document.getElementById("activate-form").addEventListener("submit", async (e) => { + e.preventDefault(); + const id = document.getElementById("id").value; + const infoResult = await chequeInfo(id); + const activateResult = await activateCheque(token, id); + if (activateResult !== undefined) { + notificationElement.innerText = `+${infoResult['amount']} coins`; + notificationElement.style.color = "green"; + balanceElement.innerText = activateResult; + } else { + notificationElement.innerText = "Incorrect ID!"; + notificationElement.style.color = "red"; + } +}); \ No newline at end of file diff --git a/assets/js/auth.js b/assets/js/auth.js new file mode 100644 index 0000000..9f8a9e4 --- /dev/null +++ b/assets/js/auth.js @@ -0,0 +1,22 @@ +const notificationElement = document.getElementById("notification"); +const apiProviderElement = document.getElementById("api-provider"); + +window.addEventListener("load", function () { + apiProviderElement.href = `https://${api_provider}`; + apiProviderElement.innerText = api_provider; + if (docCookies.hasItem('token')) { + document.getElementById('form').innerHTML = 'Already logged in! '; + } +}); + +document.getElementById("token-form").addEventListener("submit", async (e) => { + e.preventDefault(); + const token = document.getElementById("token").value; + if (await getId(token).then(value => value['status'])) { + docCookies.setItem("token", document.getElementById("token").value); + window.location = "/"; + } else { + notificationElement.innerText = "Incorrect token!"; + notificationElement.style.color = "red"; + } +}); \ No newline at end of file diff --git a/assets/js/cookie.js b/assets/js/cookie.js new file mode 100644 index 0000000..1875ce8 --- /dev/null +++ b/assets/js/cookie.js @@ -0,0 +1,48 @@ +/*\ +|*| +|*| :: cookies.js :: +|*| +|*| A complete cookies reader/writer framework with full unicode support. +|*| +|*| https://developer.mozilla.org/en-US/docs/DOM/document.cookie +|*| +|*| Syntaxes: +|*| +|*| * docCookies.setItem(name, value[, end[, path[, domain[, secure[, samesite]]]]]) +|*| * docCookies.getItem(name) +|*| * docCookies.removeItem(name[, path]) +|*| * docCookies.hasItem(name) +|*| +\*/ + +const docCookies = { + getItem: function (sKey) { + if (!sKey || !this.hasItem(sKey)) { return null; } + return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-.+*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1")); + }, + setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure, sSameSite) { + if (!sKey || /^(?:expires|max-age|path|domain|secure|samesite)$/i.test(sKey)) { return; } + let sExpires = ""; + if (vEnd) { + switch (vEnd.constructor) { + case Number: + sExpires = vEnd === Infinity ? "; expires=Tue, 19 Jan 2038 03:14:07 UTC" : "; max-age=" + vEnd; + break; + case String: + sExpires = "; expires=" + vEnd; + break; + case Date: + sExpires = "; expires=" + vEnd.toUTCString(); + break; + } + } + document.cookie = escape(sKey) + "=" + escape(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "; path=/") + (bSecure ? "; secure" : "") + (sSameSite ? "; samesite=" + sSameSite : "; samesite=strict"); + }, + removeItem: function (sKey, sPath) { + if (!sKey || !this.hasItem(sKey)) { return; } + document.cookie = escape(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sPath ? "; path=" + sPath : ""); + }, + hasItem: function (sKey) { + return (new RegExp("(?:^|;\\s*)" + escape(sKey).replace(/[\-.+*]/g, "\\$&") + "\\s*\\=")).test(document.cookie); + } +}; \ No newline at end of file diff --git a/assets/js/create.js b/assets/js/create.js new file mode 100644 index 0000000..91b995e --- /dev/null +++ b/assets/js/create.js @@ -0,0 +1,43 @@ +const token = docCookies.getItem("token"); +const notificationElement = document.getElementById("notification"); +const balanceElement = document.getElementById("balance"); +let balance; + +window.addEventListener("load", async function () { + refreshBalance(await getBalance(token)); +}); + +function refreshBalance(from) { + balance = from; + balanceElement.innerText = balance; +} + +document.getElementById("create-form").addEventListener("submit", async (e) => { + e.preventDefault(); + const act = parseInt(document.getElementById("act").value); + if (act <= 0) { + notificationElement.innerText = "Activation amount cannot be lower than 0!"; + notificationElement.style.color = "red"; + return; + } + const amount = parseInt(document.getElementById("amount").value); + const bottleneck = Math.floor(balance / act); + if (amount <= 0 || amount > bottleneck) { + notificationElement.innerText = `Incorrect coin amount. (1-${bottleneck} allowed)`; + notificationElement.style.color = "red"; + return; + } + + const createResult = await createCheque(token, amount, act); + if (createResult['status']) { + notificationElement.innerHTML = `Cheque has been created. + + `; + notificationElement.style.color = "green"; + refreshBalance(createResult['balance']); + } else { + notificationElement.innerText = "Incorrect ID!"; + notificationElement.style.color = "red"; + } +}); \ No newline at end of file diff --git a/assets/js/delete.js b/assets/js/delete.js new file mode 100644 index 0000000..7c57cf8 --- /dev/null +++ b/assets/js/delete.js @@ -0,0 +1,28 @@ +const token = docCookies.getItem("token"); +const notificationElement = document.getElementById("notification"); +const balanceElement = document.getElementById("balance"); + +window.addEventListener("load", async function () { + balanceElement.innerText = await getBalance(token); +}); + +document.getElementById("delete-form").addEventListener("submit", async (e) => { + e.preventDefault(); + const id = document.getElementById("id").value; + const infoResult = await chequeInfo(id); + if (infoResult !== undefined) { + const coinsLeft = infoResult['amount'] * infoResult['count']; + const deleteResult = await deleteCheque(token, id); + if (deleteResult !== undefined) { + notificationElement.innerText = `+${coinsLeft} coins`; + notificationElement.style.color = "green"; + balanceElement.innerText = deleteResult; + } else { + notificationElement.innerText = "You do not own this cheque."; + notificationElement.style.color = "red"; + } + } else { + notificationElement.innerText = "Incorrect ID!"; + notificationElement.style.color = "red"; + } +}); \ No newline at end of file diff --git a/assets/js/index.js b/assets/js/index.js new file mode 100644 index 0000000..a0ac0b4 --- /dev/null +++ b/assets/js/index.js @@ -0,0 +1,15 @@ +const token = docCookies.getItem("token"); +const amountElement = document.getElementById("amount"); +const listElement = document.getElementById("list"); +const userElement = document.getElementById("user"); + +window.addEventListener("load", async function () { + userElement.innerText = docCookies.getItem("token").substring(0, 4) + "**"; + listElement.href = `https://${api_provider}/get_cheques?token=${token}`; + amountElement.innerText = await getBalance(token); +}); + +function logout() { + docCookies.removeItem("token"); + window.location = "/auth/"; +} \ No newline at end of file diff --git a/assets/js/shared.js b/assets/js/shared.js new file mode 100644 index 0000000..b75bd39 --- /dev/null +++ b/assets/js/shared.js @@ -0,0 +1,42 @@ +window.addEventListener("load", async function () { + if (!docCookies.hasItem("token") && window.location.pathname !== "/auth/") { + window.location = "/auth/"; + } +}); + +const api_provider = 'api.example.com'; +const telegram_bot = 'example_bot'; + +async function getId(token) { + return await fetch(`https://${api_provider}/get_id?token=${token}`) + .then(response => response.json()); +} + +async function getBalance(token) { + return await fetch(`https://${api_provider}/get_balance?token=${token}`) + .then(response => response.json()) + .then(value => value['balance']); +} + +async function createCheque(token, amount, act) { + return await fetch(`https://${api_provider}/create_cheque?token=${token}&amount=${amount}&act=${act}`) + .then(response => response.json()); +} + +async function deleteCheque(token, id) { + return await fetch(`https://${api_provider}/delete_cheque?token=${token}&id=${id}`) + .then(response => response.json()) + .then(value => value['balance']); +} + +async function activateCheque(token, id) { + return await fetch(`https://${api_provider}/activate_cheque?token=${token}&id=${id}`) + .then(response => response.json()) + .then(value => value['balance']); +} + +async function chequeInfo(id) { + return await fetch(`https://${api_provider}/cheque_info?id=${id}`) + .then(response => response.json()) + .then(value => value['info']); +} \ No newline at end of file diff --git a/auth/index.html b/auth/index.html new file mode 100644 index 0000000..cd2ef20 --- /dev/null +++ b/auth/index.html @@ -0,0 +1,31 @@ + + + + + CensoredManager - Auth + + + +
+
+ + + +
+
+
+
+ + CensoredManager
+ home - source code +
+
+ + + + + \ No newline at end of file diff --git a/create/index.html b/create/index.html new file mode 100644 index 0000000..849d878 --- /dev/null +++ b/create/index.html @@ -0,0 +1,34 @@ + + + + + CensoredManager - Create + + + +
+
+ + + +
+
+
+
+ + Balance: - + + CensoredManager
+ home - source code +
+
+ + + + + \ No newline at end of file diff --git a/delete/index.html b/delete/index.html new file mode 100644 index 0000000..544c5b5 --- /dev/null +++ b/delete/index.html @@ -0,0 +1,33 @@ + + + + + CensoredManager - Delete + + + +
+
+ + + +
+
+
+
+ + Balance: - + + CensoredManager
+ home - source code +
+
+ + + + + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..3635dd1 --- /dev/null +++ b/index.html @@ -0,0 +1,31 @@ + + + + + CensoredManager + + + +
+ Logged in as + +
+
+ - coins +
+
+
+ + + + + + CensoredManager
+ home - source code +
+
+ + + + + \ No newline at end of file