Helper file and token prep

This commit is contained in:
Elizabeth Cray 2023-10-02 00:23:59 -04:00
parent 937278c8d5
commit 101bfd0d30
4 changed files with 50 additions and 14 deletions

View File

@ -1,20 +1,12 @@
<?php
$config = json_decode(file_get_contents("/var/www/usergen/secret/config.json", true));
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require("/var/www/usergen/secret/oauth.php");
function flog($log_msg) {
$log_filename = "/var/www/html";
$log_file_data = $log_filename.'/log_' . date('d-M-Y') . '.log';
// if you don't add `FILE_APPEND`, the file will be erased each time you add a log
file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
}
require_once("/var/www/usergen/secret/helpers.php");
require_once("/var/www/usergen/secret/oauth.php");
if (isset($_REQUEST["act"])){
// internal functions such as id request
flog("Ret ACT:16 ✨ ".$_REQUEST["act"]." FROM ".$_SERVER["REMOTE_ADDR"]);
switch($_REQUEST["act"]){
case "id":
// return OAUTH app ID
@ -85,6 +77,7 @@ if (isset($_REQUEST["act"])){
}else{
// invalid auth
// TODO: Replace with direct to index logout with error msg
if(isset($_COOKIE["oa_retries"])){
$retries = $_COOKIE["oa_retries"];
if($retries >= 3){

View File

@ -1,7 +1,6 @@
var DEBUG = false;
var isMobile = false;
var USE_ORIGIN = "";
// TODO: Add check for DOMAIN_OVERRIDE
const dbp = (msg) => {
if(DEBUG){
@ -21,7 +20,12 @@ const SwalConfig = {
buttonsStyling: false,
}
const invalidChars = ['/', '\\', '>', '<', ':', '*', '|', '"', '\'', '?', '\0'];
const invalidChars = [
'/', '\\', '>',
'<', ':', '*',
'|', '"', '\'',
'?', '\0'
];
const replaceInvalid = (str) => {
var cache = str;
@ -278,7 +282,9 @@ $(() => {
dbp("Is Mobile 👍🏻");
disableNonDesktopElements();
}
// Auto Retry
// TODO: Replace with redirect to home with logout set if error
var isRetry = false;
if(window.location.pathname.includes("auth")){
var ErrorMsg = document.getElementById("ErrorResult");
@ -289,6 +295,7 @@ $(() => {
beginOauth();
}
}
// Console Welcome
if(!isRetry){
console.log("%cWelcome Hacker!", "color: #ff0000; font-size: 7em; font-style: italic; font-family: 'Times New Roman', Times, serif;");

View File

@ -1,4 +1,18 @@
<!DOCTYPE html>
<!-- TODO: Add popup with error if passed to page -->
<?php
require_once("/var/www/usergen/secret/helpers.php");
if (isset($_REQUEST["act"])){
switch($_REQUEST["act"]){
case "logout":
// Logout
clearCookies();
break;
default:
break;
}
}
?>
<HTML lang="en">
<Head>
<Title>HackersTown Server Access</Title>
@ -35,7 +49,7 @@
</span>
</div>
<div class="row button">
<button id="bttn" class="keyButton" onclick="beginOauth()">Log In</button>
<button id="bttn" class="keyButton" onclick="beginOauth()">Log In With HTown <!-- img src="/Assets/HTown.png" class="emoji"/ --></button>
</div>
<?php require("/var/www/usergen/footer.php"); ?>
</div>

22
secret/helpers.php Normal file
View File

@ -0,0 +1,22 @@
<?php
function clearCookies() {
if(count($_COOKIE) > 0) {
foreach ($_COOKIE as $key => $value) {
setcookie($key, "", time()-3600);
}
}
}
function flog($log_msg) {
$log_filename = "/var/www/html";
$log_file_data = $log_filename.'/log_' . date('d-M-Y') . '.log';
file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
}
function enableDebug(){
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
?>