Skip to content

Commit

Permalink
add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoey2936 committed Jun 1, 2024
1 parent cd3cafe commit dad032d
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 115 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
git diff-index --quiet HEAD || git commit -sm "prettier"
git push
8 changes: 4 additions & 4 deletions .imgbotconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schedule": "daily",
"aggressiveCompression": "true",
"compressWiki": "true",
"minKBReduced": 0
"schedule": "daily",
"aggressiveCompression": "true",
"compressWiki": "true",
"minKBReduced": 0
}
6 changes: 2 additions & 4 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": [
"config:base"
],
"baseBranches": ["develop", "php"],
"extends": ["config:base"],
"baseBranches": [],
"includeForks": true,
"automerge": false,
"branchPrefix": "renovate-deps-update-",
Expand Down
3 changes: 3 additions & 0 deletions src/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public/tailwind.css
composer.lock
vendor
4 changes: 1 addition & 3 deletions src/bootstrap-icons.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[
"github"
]
["github", "cloud-download-fill", "cloud-upload-fill"]
68 changes: 34 additions & 34 deletions src/composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"homepage": "https://z0ey.de"
},
"license": "AGPL-3.0",
"version": "v0.0.1-alpha",
"authors": [
{
"name": "Zoey",
"email": "[email protected]",
"homepage": "https://z0ey.de"
},
{
"name": "David",
"email": "[email protected]",
"homepage": "https://davidcraft.de"
},
{
"name": "ZoeyVid",
"email": "[email protected]",
"homepage": "https://zoeyvid.de"
}
],
"minimum-stability": "alpha",
"support": {
"email": "[email protected]",
"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": "[email protected]",
"homepage": "https://davidcraft.de"
},
{
"name": "ZoeyVid",
"email": "[email protected]",
"homepage": "https://zoeyvid.de"
}
],
"minimum-stability": "alpha",
"support": {
"email": "[email protected]",
"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"
}
}
2 changes: 1 addition & 1 deletion src/functions/auth.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
function isAuthenticated(): bool
{
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)) {
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";
Expand Down
2 changes: 1 addition & 1 deletion src/functions/database.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
function db() : SQLite3
function db(): SQLite3
{
require_once __DIR__ . "/../config.php";
$db = new SQLite3(data_path() . "/npmplus.sqlite");
Expand Down
4 changes: 2 additions & 2 deletions src/functions/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once __DIR__ . "/../functions/database.php";
use PHPMailer\PHPMailer\PHPMailer;

function sendMail($to, $subject, $body) : bool
function sendMail($to, $subject, $body): bool
{
$db = db();
$mail_host = $db->querySingle("SELECT value FROM config WHERE key = 'mail_host'");
Expand Down Expand Up @@ -31,7 +31,7 @@ function sendMail($to, $subject, $body) : bool
}
}

function validateEmail($email) : bool
function validateEmail($email): bool
{
return PHPMailer::validateAddress($email);
}
19 changes: 8 additions & 11 deletions src/functions/totp.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php
function totp($secret) : string
function totp($secret): string
{
function base32decode($base32string): string
{
$base32string = preg_replace('/[^A-Z2-7]/', '', strtoupper($base32string));
$base32string = preg_replace("/[^A-Z2-7]/", "", strtoupper($base32string));

$decoded = '';
$decoded = "";
$bitBuffer = 0;
$bitBufferLength = 0;

foreach (str_split($base32string) as $char) {
$pentet = strpos('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', $char);
$pentet = strpos("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", $char);
$bitBuffer = ($bitBuffer << 5) + $pentet;
$bitBufferLength += 5;

if ($bitBufferLength >= 8) {
$decoded .= chr(($bitBuffer >> ($bitBufferLength - 8)) & 0xFF);
$decoded .= chr(($bitBuffer >> $bitBufferLength - 8) & 0xff);
$bitBufferLength -= 8;
}
}
Expand All @@ -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);
}
93 changes: 48 additions & 45 deletions src/public/auth/login/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -31,14 +30,17 @@

<body>
<div class="text-center">
<?php function login($msg): void
{ ?>
<?php
function login($msg): void
{
?>
<h1>Login</h1>
<form method="post">
<label for="email">E-Mail: </label><input type="email" name="email" id="email" maxlength="255" required><br>
<label for="pswd">Passwort: </label><input type="password" name="pswd" id="pswd" maxlength="255" required><br>
<label for="totp">TOTP: </label><input type="text" name="totp" id="totp" maxlength="6"><br>
<!--<div class="h-captcha" data-sitekey="<?php //echo $hcaptcha_key; ?>"></div>-->
<!--<div class="h-captcha" data-sitekey="<?php //echo $hcaptcha_key;
?>"></div>-->
<input type="submit" value="Login" onClick="this.hidden=true;">
<b></b>
</form>
Expand All @@ -52,50 +54,51 @@
};
echo "<p><strong>Note: " . $msg . "</strong></p>";
}
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");
}
}
?>
</div>
</body>
<?php } ?>
<?php
} ?>
2 changes: 1 addition & 1 deletion src/public/auth/logout/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
session_destroy();
header("Location: /auth/login", true, 307);
exit;
exit();
8 changes: 5 additions & 3 deletions src/public/auth/setup/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
$db = db();
if ($db->querySingle("SELECT COUNT(*) FROM auth") !== 0) {
header("Location: /", true, 307);
exit;
} else { ?>
exit();
} else {
?>
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -18,4 +19,5 @@
<link rel="stylesheet" href="/tailwind.css">
<link rel="icon" type="image/webp" href="/favicon.webp">
</head>
<?php }
<?php
}
3 changes: 3 additions & 0 deletions src/public/bootstrap-icons/cloud-download-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/public/bootstrap-icons/cloud-upload-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/public/index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
require_once __DIR__ . '/../require/session.php';
require_once __DIR__ . "/../require/session.php";
phpinfo();
8 changes: 4 additions & 4 deletions src/require/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
$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()) {
session_destroy();
header('Location: /auth/login', true, 307);
exit;
header("Location: /auth/login", true, 307);
exit();
}
Loading

0 comments on commit dad032d

Please sign in to comment.