diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 0000000000..4f84ad5e54 --- /dev/null +++ b/.github/workflows/prettier.yml @@ -0,0 +1,24 @@ +name: prettier +on: + push: + schedule: + - cron: "0 */6 * * *" + workflow_dispatch: +jobs: + prettier: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: prettier + run: | + yarn global add prettier @prettier/plugin-php + cd src + prettier . -w --end-of-line crlf --print-width 10000 --plugin /home/runner/.config/yarn/global/node_modules/@prettier/plugin-php/standalone.js --plugin /home/runner/.config/yarn/global/node_modules/prettier-plugin-tailwindcss/dist/index.mjs + - name: push + run: | + git add -A + git config user.name "GitHub" + git config user.email "noreply@github.com" + git diff-index --quiet HEAD || git commit -sm "prettier" + git push diff --git a/.imgbotconfig b/.imgbotconfig index a31c6d45ea..845d674900 100644 --- a/.imgbotconfig +++ b/.imgbotconfig @@ -1,6 +1,6 @@ { - "schedule": "daily", - "aggressiveCompression": "true", - "compressWiki": "true", - "minKBReduced": 0 + "schedule": "daily", + "aggressiveCompression": "true", + "compressWiki": "true", + "minKBReduced": 0 } diff --git a/renovate.json b/renovate.json index 2427726947..253ae59a33 100644 --- a/renovate.json +++ b/renovate.json @@ -1,8 +1,6 @@ { - "extends": [ - "config:base" - ], - "baseBranches": ["develop", "php"], + "extends": ["config:base"], + "baseBranches": [], "includeForks": true, "automerge": false, "branchPrefix": "renovate-deps-update-", diff --git a/src/.prettierignore b/src/.prettierignore new file mode 100644 index 0000000000..89223433f9 --- /dev/null +++ b/src/.prettierignore @@ -0,0 +1,3 @@ +public/tailwind.css +composer.lock +vendor diff --git a/src/bootstrap-icons.json b/src/bootstrap-icons.json index ee068918fc..21b2b18424 100644 --- a/src/bootstrap-icons.json +++ b/src/bootstrap-icons.json @@ -1,3 +1 @@ -[ - "github" -] +["github", "cloud-download-fill", "cloud-upload-fill"] diff --git a/src/composer.json b/src/composer.json index bdc74b9ca4..3b90ab5273 100644 --- a/src/composer.json +++ b/src/composer.json @@ -1,38 +1,38 @@ { - "name": "zoeyvid/npmplus", - "description": "WebUI for NPMplus, which manages nginx and acme.sh", - "type": "project", - "require": { - "phpmailer/phpmailer": "6.9.1", - "endroid/qr-code": "5.0.9", - "ext-sqlite3": "*" + "name": "zoeyvid/npmplus", + "description": "WebUI for NPMplus, which manages nginx and acme.sh", + "type": "project", + "require": { + "phpmailer/phpmailer": "6.9.1", + "endroid/qr-code": "5.0.9", + "ext-sqlite3": "*" + }, + "license": "AGPL-3.0", + "version": "v0.0.1-alpha", + "authors": [ + { + "name": "Zoey", + "email": "zoey@z0ey.de", + "homepage": "https://z0ey.de" }, - "license": "AGPL-3.0", - "version": "v0.0.1-alpha", - "authors": [ - { - "name": "Zoey", - "email": "zoey@z0ey.de", - "homepage": "https://z0ey.de" - }, - { - "name": "David", - "email": "david@davidcraft.de", - "homepage": "https://davidcraft.de" - }, - { - "name": "ZoeyVid", - "email": "zoeyvid@zvcdn.de", - "homepage": "https://zoeyvid.de" - } - ], - "minimum-stability": "alpha", - "support": { - "email": "zoey@z0ey.de", - "issues": "https://github.com/ZoeyVid/booking/issues", - "forum": "https://github.com/ZoeyVid/booking/discussions", - "wiki": "https://github.com/ZoeyVid/booking", - "source": "https://github.com/ZoeyVid/booking", - "docs": "https://github.com/ZoeyVid/booking" + { + "name": "David", + "email": "david@davidcraft.de", + "homepage": "https://davidcraft.de" + }, + { + "name": "ZoeyVid", + "email": "zoeyvid@zvcdn.de", + "homepage": "https://zoeyvid.de" } + ], + "minimum-stability": "alpha", + "support": { + "email": "zoey@z0ey.de", + "issues": "https://github.com/ZoeyVid/NPMplus/issues", + "forum": "https://github.com/ZoeyVid/NPMplus/discussions", + "wiki": "https://github.com/ZoeyVid/NPMplus", + "source": "https://github.com/ZoeyVid/NPMplus", + "docs": "https://github.com/ZoeyVid/NPMplus" + } } diff --git a/src/functions/auth.php b/src/functions/auth.php index 4abe3f29b7..30b3f0b33a 100644 --- a/src/functions/auth.php +++ b/src/functions/auth.php @@ -1,7 +1,7 @@ 3600)) { + if (!array_key_exists("AUTH_EMAIL", $_SESSION) || empty($_SESSION["AUTH_EMAIL"]) || !array_key_exists("AUTH_PW_HASH", $_SESSION) || empty($_SESSION["AUTH_PW_HASH"]) || !array_key_exists("LOGIN_TIME", $_SESSION) || empty($_SESSION["LOGIN_TIME"]) || time() - $_SESSION["LOGIN_TIME"] > 3600) { return false; } else { require_once __DIR__ . "/database.php"; diff --git a/src/functions/database.php b/src/functions/database.php index cd2c9d0200..384c40c07d 100644 --- a/src/functions/database.php +++ b/src/functions/database.php @@ -1,5 +1,5 @@ querySingle("SELECT value FROM config WHERE key = 'mail_host'"); @@ -31,7 +31,7 @@ function sendMail($to, $subject, $body) : bool } } -function validateEmail($email) : bool +function validateEmail($email): bool { return PHPMailer::validateAddress($email); } diff --git a/src/functions/totp.php b/src/functions/totp.php index e05a160f72..ee1830d43f 100644 --- a/src/functions/totp.php +++ b/src/functions/totp.php @@ -1,21 +1,21 @@ = 8) { - $decoded .= chr(($bitBuffer >> ($bitBufferLength - 8)) & 0xFF); + $decoded .= chr(($bitBuffer >> $bitBufferLength - 8) & 0xff); $bitBufferLength -= 8; } } @@ -25,13 +25,10 @@ function base32decode($base32string): string function truncate($hmac_result): string { - $offset = ord($hmac_result[strlen($hmac_result)-1]) & 0xf; - return substr((ord($hmac_result[$offset]) & 0x7f) << 24 - | (ord($hmac_result[$offset+1]) & 0xff) << 16 - | (ord($hmac_result[$offset+2]) & 0xff) << 8 - | (ord($hmac_result[$offset+3]) & 0xff), -6); + $offset = ord($hmac_result[strlen($hmac_result) - 1]) & 0xf; + return substr(((ord($hmac_result[$offset]) & 0x7f) << 24) | ((ord($hmac_result[$offset + 1]) & 0xff) << 16) | ((ord($hmac_result[$offset + 2]) & 0xff) << 8) | (ord($hmac_result[$offset + 3]) & 0xff), -6); } - $hash = hash_hmac('sha1', pack('J', floor(time() / 30)), base32decode($secret), true); + $hash = hash_hmac("sha1", pack("J", floor(time() / 30)), base32decode($secret), true); return truncate($hash); } diff --git a/src/public/auth/login/index.php b/src/public/auth/login/index.php index 887b3dab73..3e48fdfef0 100644 --- a/src/public/auth/login/index.php +++ b/src/public/auth/login/index.php @@ -3,17 +3,16 @@ $db = db(); if ($db->querySingle("SELECT COUNT(*) FROM auth") === 0) { session_destroy(); - header('Location: /auth/setup', true, 307); - exit; + header("Location: /auth/setup", true, 307); + exit(); } require_once __DIR__ . "/../../../functions/auth.php"; if (isAuthenticated()) { header("Location: /", true, 307); - exit; + exit(); } else { - session_unset(); - ?> + session_unset(); ?>
@@ -31,14 +30,17 @@Note: " . $msg . "
"; } - if (!array_key_exists("email", $_POST) || !array_key_exists("pswd", $_POST)) { - login("none"); - } else { - require_once __DIR__ . "/../../../functions/email.php"; - $_SESSION["LOGIN_TIME"] = time(); - $query = $db->prepare("SELECT * FROM auth WHERE email=:email"); - $query->bindValue(":email", $_POST["email"]); - $queryresult = $query->execute()->fetchArray(); + if (!array_key_exists("email", $_POST) || !array_key_exists("pswd", $_POST)) { + login("none"); + } else { + require_once __DIR__ . "/../../../functions/email.php"; + $_SESSION["LOGIN_TIME"] = time(); + $query = $db->prepare("SELECT * FROM auth WHERE email=:email"); + $query->bindValue(":email", $_POST["email"]); + $queryresult = $query->execute()->fetchArray(); - if (is_array($queryresult) && validateEmail($_POST["email"])) { - if (!password_verify($_POST["pswd"], $queryresult["pswd"])) { - sendMail($_POST["email"], "Failed Login", $_SERVER["REMOTE_ADDR"] . " failed to login into your account."); - login("wpw"); + if (is_array($queryresult) && validateEmail($_POST["email"])) { + if (!password_verify($_POST["pswd"], $queryresult["pswd"])) { + sendMail($_POST["email"], "Failed Login", $_SERVER["REMOTE_ADDR"] . " failed to login into your account."); + login("wpw"); + } else { + if (empty($queryresult["totp"])) { + sendMail($_POST["email"], "New Login", $_SERVER["REMOTE_ADDR"] . " logged into your account"); + $_SESSION["AUTH_PW_HASH"] = hash("sha256", $queryresult["pswd"]); + header("Location: /", true, 307); + exit(); } else { - if (empty($queryresult["totp"])) { - sendMail($_POST["email"], "New Login", $_SERVER["REMOTE_ADDR"] . " logged into your account"); - $_SESSION["AUTH_PW_HASH"] = hash("sha256", $queryresult["pswd"]); - header("Location: /", true, 307); - exit; + if (empty($_POST["totp"])) { + sendMail($_POST["email"], "Failed Login", $_SERVER["REMOTE_ADDR"] . " failed to login into your account."); + login("mtotp"); } else { - if (empty($_POST["totp"])) { - sendMail($_POST["email"], "Failed Login", $_SERVER["REMOTE_ADDR"] . " failed to login into your account."); - login("mtotp"); + require_once __DIR__ . "/../../../functions/totp.php"; + if ($_POST["totp"] === totp($queryresult["totp"])) { + sendMail($_POST["email"], "New Login", $_SERVER["REMOTE_ADDR"] . " logged into your account"); + $_SESSION["AUTH_EMAIL"] = $_POST["email"]; + $_SESSION["AUTH_PW_HASH"] = hash("sha256", $queryresult["pswd"]); + $_SESSION["AUTH_TOTP_HASH"] = hash("sha256", $queryresult["totp"]); + header("Location: /", true, 307); + exit(); } else { - require_once __DIR__ . "/../../../functions/totp.php"; - if ($_POST["totp"] === totp($queryresult["totp"])) { - sendMail($_POST["email"], "New Login", $_SERVER["REMOTE_ADDR"] . " logged into your account"); - $_SESSION["AUTH_EMAIL"] = $_POST["email"]; - $_SESSION["AUTH_PW_HASH"] = hash("sha256", $queryresult["pswd"]); - $_SESSION["AUTH_TOTP_HASH"] = hash("sha256", $queryresult["totp"]); - header("Location: /", true, 307); - exit; - } else { - sendMail($_POST["email"], "Failed Login", $_SERVER["REMOTE_ADDR"] . " failed to login into your account."); - login("wtotp"); - } + sendMail($_POST["email"], "Failed Login", $_SERVER["REMOTE_ADDR"] . " failed to login into your account."); + login("wtotp"); } - } } - } else { - login("adne"); } - } ?> + } else { + login("adne"); + } + } + ?>