From 9989797ecd50074ea8006613ce4b03e3b38f0e89 Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 6 Apr 2022 21:52:16 +0200 Subject: Admin panel done --- admin/callback/index.php | 60 ++++++++++++++++++ admin/contact/index.php | 118 +++++++++++++++++++++++++++++++++++ admin/index.php | 45 ++++++++++++++ admin/login/index.php | 4 ++ admin/pluralkit/index.php | 50 +++++++++++++++ admin/projects/index.php | 155 ++++++++++++++++++++++++++++++++++++++++++++++ admin/users/index.php | 75 ++++++++++++++++++++++ 7 files changed, 507 insertions(+) create mode 100644 admin/callback/index.php create mode 100644 admin/contact/index.php create mode 100644 admin/index.php create mode 100644 admin/login/index.php create mode 100644 admin/pluralkit/index.php create mode 100644 admin/projects/index.php create mode 100644 admin/users/index.php (limited to 'admin') diff --git a/admin/callback/index.php b/admin/callback/index.php new file mode 100644 index 0000000..7aaed70 --- /dev/null +++ b/admin/callback/index.php @@ -0,0 +1,60 @@ + json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/github.json"), true)["id"], + 'client_secret' => json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/github.json"), true)["secret"], + 'code' => $_GET['code'] +); + +$post_data = json_encode($data); + +$crl = curl_init('https://github.com/login/oauth/access_token'); +curl_setopt($crl, CURLOPT_RETURNTRANSFER, true); +curl_setopt($crl, CURLINFO_HEADER_OUT, true); +curl_setopt($crl, CURLOPT_POST, true); +curl_setopt($crl, CURLOPT_POSTFIELDS, $post_data); + +curl_setopt($crl, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + "Accept: application/json" +)); + +$result = curl_exec($crl); + +if ($result === false) { + throw new ErrorException("GitHub OAuth Flow interrupted", 214, E_ERROR); +} + +curl_close($crl); + +$data = json_decode($result, true); +$crl = curl_init('https://api.github.com/user'); +curl_setopt($crl, CURLOPT_RETURNTRANSFER, true); +curl_setopt($crl, CURLINFO_HEADER_OUT, true); +curl_setopt($crl, CURLOPT_POST, false); + +curl_setopt($crl, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + "Accept: application/json", + "Authorization: token " . $data["access_token"], + "User-Agent: ProjectCloudsdale-Admin/0.0.0 (contact@minteck.org)" +)); + +$result = curl_exec($crl); +$ndata = json_decode($result, true); + +if (!in_array($ndata["login"], json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/admins.json"), true))) { + header("Location: /"); + die(); +} + +if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/tokens")) mkdir($_SERVER['DOCUMENT_ROOT'] . "/data/tokens"); +file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/tokens/" . $data["access_token"], $ndata["login"]); +setcookie("pcdAdminToken", $data["access_token"], 0, "/"); + +header("Location: /admin"); +die(); diff --git a/admin/contact/index.php b/admin/contact/index.php new file mode 100644 index 0000000..3310762 --- /dev/null +++ b/admin/contact/index.php @@ -0,0 +1,118 @@ + + $_GET["add-project"], + "link" => $_GET["add-project-src"], + "icon" => "about:blank" + ]; + file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/data/contact.json", json_encode($projects, JSON_PRETTY_PRINT)); + header("Location: /admin/contact"); + die(); + } + + if (isset($_GET["delete-project"])) { + if (isset($projects[(int)$_GET["delete-project"]])) { + unset($projects[(int)$_GET["delete-project"]]); + file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/data/contact.json", json_encode($projects, JSON_PRETTY_PRINT)); + header("Location: /admin/contact"); + die(); + } + } + + if (isset($_GET["edit-project"]) && isset($_GET["edit-project-name"]) && isset($_GET["edit-project-source"]) && isset($_GET["edit-project-icon"])) { + if (isset($projects[(int)$_GET["edit-project"]])) { + $projects[(int)$_GET["edit-project"]]["name"] = $_GET["edit-project-name"]; + $projects[(int)$_GET["edit-project"]]["link"] = $_GET["edit-project-source"]; + $projects[(int)$_GET["edit-project"]]["icon"] = $_GET["edit-project-icon"]; + file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/data/contact.json", json_encode($projects, JSON_PRETTY_PRINT)); + header("Location: /admin/contact"); + die(); + } + } +} + +?> + + +
+
+ + +

Edit ()

+ +
+

+ Social Network Name:
+ "> +

+

+ Link:
+ "> +

+

+ Icon URL (can be relative):
+ "> +

+ + "> + +
+ + +

Contact Info Management

+

Contact info added to this list is publicly shown on the website's Contact page and will lead users to containg you.

+ + +
+ + + + +
+ + + + \ No newline at end of file diff --git a/admin/index.php b/admin/index.php new file mode 100644 index 0000000..0b03f35 --- /dev/null +++ b/admin/index.php @@ -0,0 +1,45 @@ + + + +
+
+

Welcome back !

+
+ +
+
+
+
+

PluralKit

+

Configure PluralKit system ID.

+ Manage +
+
+
+
+
+
+

Projects

+

Add, edit, delete or showcase projects.

+ Manage +
+
+
+
+
+
+

Contact Info

+

Add, edit or delete contact information.

+ Manage +
+
+
+
+
+ +

This website is managed by $item): ?> (you) and , , edit...

+ +

powered by Pawer Technologies

+
+ + \ No newline at end of file diff --git a/admin/login/index.php b/admin/login/index.php new file mode 100644 index 0000000..41c4298 --- /dev/null +++ b/admin/login/index.php @@ -0,0 +1,4 @@ + + $_GET['system-id'] + ], JSON_PRETTY_PRINT)); + header("Location: /admin/pluralkit"); + die(); + } +} + +?> + + +
+
+

PluralKit Configuration

+ +

Current System: + " id="system-icon"> () + + Not found, please make sure the ID is entered correctly +

+
+ + + +
+
+ + + + \ No newline at end of file diff --git a/admin/projects/index.php b/admin/projects/index.php new file mode 100644 index 0000000..78e2b04 --- /dev/null +++ b/admin/projects/index.php @@ -0,0 +1,155 @@ + + $_GET["add-project"], + "description" => $_GET["add-project"], + "icon" => "about:blank", + "source" => $_GET["add-project-src"], + "showcase" => false + ]; + file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/data/projects.json", json_encode($projects, JSON_PRETTY_PRINT)); + header("Location: /admin/projects"); + die(); + } + + if (isset($_GET["delete-project"])) { + if (isset($projects[(int)$_GET["delete-project"]])) { + unset($projects[(int)$_GET["delete-project"]]); + file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/data/projects.json", json_encode($projects, JSON_PRETTY_PRINT)); + header("Location: /admin/projects"); + die(); + } + } + + if (isset($_GET["edit-project"]) && isset($_GET["edit-project-name"]) && isset($_GET["edit-project-source"]) && isset($_GET["edit-project-icon"]) && isset($_GET["edit-project-description"])) { + if (isset($projects[(int)$_GET["edit-project"]])) { + $projects[(int)$_GET["edit-project"]]["name"] = $_GET["edit-project-name"]; + $projects[(int)$_GET["edit-project"]]["description"] = $_GET["edit-project-description"]; + $projects[(int)$_GET["edit-project"]]["icon"] = $_GET["edit-project-icon"]; + file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/data/projects.json", json_encode($projects, JSON_PRETTY_PRINT)); + header("Location: /admin/projects"); + die(); + } + } +} + +?> + + +
+
+ + +

Edit ()

+ +
+

+ Project Name:
+ "> +

+

+ Project VCS Repository:
+ "> +

+

+ Icon URL (can be relative):
+ "> +

+

+ Project Description (can contain HTML tags):
+ +

+ + "> + +
+ + +

Projects Management

+

Projects added to this list are publicly shown on the website's Projects page and (for select projects) on the homepage.

+ + +
+ + + + +
+ + + + \ No newline at end of file diff --git a/admin/users/index.php b/admin/users/index.php new file mode 100644 index 0000000..1bc81d2 --- /dev/null +++ b/admin/users/index.php @@ -0,0 +1,75 @@ + + + + +
+
+

Administrators Management

+

Administrators added to this list are able to login to this admin panel using their GitHub account. Make sure you trust the person before giving them administrative permissions.

+ + +
+ + + +
+ + \ No newline at end of file -- cgit