Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
  • Loading branch information
NaysKutzu committed Oct 12, 2024
1 parent 7e5a036 commit dd1394a
Show file tree
Hide file tree
Showing 10 changed files with 485 additions and 11 deletions.
48 changes: 48 additions & 0 deletions app/Web/Routes/admin/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of MythicalSystemsFramework.
* Please view the LICENSE file that was distributed with this source code.
*
* (c) MythicalSystems <mythicalsystems.xyz> - All rights reserved
* (c) NaysKutzu <nayskutzu.xyz> - All rights reserved
* (c) Cassian Gherman <nayskutzu.xyz> - All rights reserved
*
* You should have received a copy of the MIT License
* along with this program. If not, see <https://opensource.org/licenses/MIT>.
*/

use MythicalSystemsFramework\User\UserHelper;
use MythicalSystemsFramework\Web\Template\Engine;
use MythicalSystemsFramework\User\UserDataHandler;
use MythicalSystemsFramework\CloudFlare\CloudFlare;
use MythicalSystemsFramework\User\Activity\UserActivity;
use MythicalSystemsFramework\User\Announcement\Announcements;

global $router;

$router->add('/admin/api', function (): void {
global $router, $event, $renderer;
$template = 'admin/api/list.twig';
if (isset($_COOKIE['token']) === false) {
exit(header('location: /auth/login'));
}

$user = new UserHelper($_COOKIE['token'], $renderer);
UserDataHandler::requireAuthorization($renderer, $_COOKIE['token']);
$uuid = UserDataHandler::getSpecificUserData($_COOKIE['token'], 'uuid', false);

if (
!UserDataHandler::hasPermission($_COOKIE['token'], 'mythicalframework.admin.api.view')
|| !UserDataHandler::hasPermission($_COOKIE['token'], 'mythicalframework.admin.api.create')
|| !UserDataHandler::hasPermission($_COOKIE['token'], 'mythicalframework.admin.api.edit')
|| !UserDataHandler::hasPermission($_COOKIE['token'], 'mythicalframework.admin.api.delete')
) {
exit(header('location: /errors/403'));
}

$renderer->addGlobal('page_name', 'API Keys');

Engine::registerAlerts($renderer, $template);
exit($renderer->render($template));
});
95 changes: 95 additions & 0 deletions app/Web/Routes/admin/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

use MythicalSystemsFramework\Api\Api;
use MythicalSystemsFramework\Kernel\Logger;
use MythicalSystemsFramework\Managers\Settings;
use MythicalSystemsFramework\User\UserHelper;
use MythicalSystemsFramework\Web\Template\Engine;
use MythicalSystemsFramework\User\UserDataHandler;

global $router;

$router->add('/admin/settings/(.*)', function ($category): void {
global $router, $event, $renderer;
$template = 'admin/settings/edit.twig';
if (isset($_COOKIE['token']) === false) {
exit(header('location: /auth/login'));
}

$user = new UserHelper($_COOKIE['token'], $renderer);
UserDataHandler::requireAuthorization($renderer, $_COOKIE['token']);

if (
!UserDataHandler::hasPermission($_COOKIE['token'], 'mythicalframework.admin.settings.view') ||
!UserHelper::hasPermission($_COOKIE['token'], 'mythicalframework.admin.settings.edit')
) {
exit(header('location: /errors/403'));
}

$category_list = [
"general",
"mails",
"cloudflare",
"seo",
"custom"
];

if (!in_array($category, $category_list)) {
exit(header('location: /errors/404'));
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
Api::init();

$input = json_decode(file_get_contents('php://input'), true);

if (json_last_error() !== JSON_ERROR_NONE) {
exit(header('location: /errors/400'));
}

if (!isset($input['category'], $input['name'], $input['value'])) {
exit(header('location: /errors/400'));
}

$category = $input['category'];
$name = $input['name'];
$value = $input['value'];

Settings::updateSetting($category, $name, $value, true);
Api::OK("Setting updated successfully.", [
"category" => $category,
"name" => $name,
"value" => $value
]);
} catch (Exception $e) {
Api::InternalServerError("There was an error updating the setting.", null);
}
} else if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$renderer->addGlobal('category_name', $category);
$renderer->addGlobal('page_name', 'Settings');
$timezones = DateTimeZone::listIdentifiers();
$langs = array_filter(scandir(__DIR__ . '/../../../../storage/lang'), function ($file) {
return pathinfo($file, PATHINFO_EXTENSION) === 'yml';
});
$langs = array_map(function ($file) {
return pathinfo($file, PATHINFO_FILENAME);
}, $langs);
$renderer->addGlobal('langs', $langs);
$renderer->addGlobal('timezones', $timezones);

$themes = array_filter(scandir(__DIR__ . '/../../../../storage/themes'), function ($file) {
return is_dir(__DIR__ . '/../../../../storage/themes/' . $file) && $file !== '.' && $file !== '..';
});
$renderer->addGlobal('themes', $themes);

$renderer->addFunction(new Twig\TwigFunction('ucFirst', function (string $word) {
return ucfirst($word);
}));

Engine::registerAlerts($renderer, $template);
exit($renderer->render($template));
} else {
exit(header('location: /dashboard'));
}
});
8 changes: 8 additions & 0 deletions storage/addons/Core/MythicalFramework.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "Core",
"description": "The core plugin for MythicalFramework",
"icon": "https://raw.githubusercontent.com/MythicalLTD/FrameworkBackup24/refs/heads/main/icon.png",
"version": "1.0.1",
"homepage": "https://mythicalsystems.xyz",
"require": [
Expand All @@ -9,6 +10,13 @@
"php-ext=mysqli",
"composer=mythicalsystems/core"
],
"buttons": [
{
"text": "Custom Button",
"url": "https://discord.mythicalsystems.xyz",
"color": "primary"
}
],
"license": "MIT",
"stability": "stable",
"authors": [
Expand Down
6 changes: 5 additions & 1 deletion storage/addons/Core/permissions.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"mythicalframework.admin.languages.edit",

"mythicalframework.admin.settings.view",
"mythicalframework.admin.settings.edit"
"mythicalframework.admin.settings.edit",

"mythicalframework.admin.api.view",
"mythicalframework.admin.api.create",
"mythicalframework.admin.api.delete"

]
57 changes: 53 additions & 4 deletions storage/lang/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,27 @@ Pages:
Actions:
Edit: "Edit"
Delete: "Delete"
Settings:
Edit:
Title: "Edit Settings"
Description: "Here you can edit the settings of the framework."
Fields:
AppName: "App Name: "
AppURL: "App URL: "
AppTimezone: "App Timezone: "
AppLang: "App Language: "
AppTheme: "App Theme: "
AppMirror: "App Mirror: "
Actions:
Save: "Save changes"
Cancel: "Cancel"
Languages:
Editor:
Title: "Language Editor"
Description: "Here you can edit the language files."
Buttons:
Save: "Save changes"
Cancel: "Cancel"

List:
Title: "Languages"
Description: "Here you can see all the framework languages and manage them :)"
Expand All @@ -60,7 +73,6 @@ Pages:
Actions: "Actions"
Actions:
Edit: "Edit"

Logs:
List:
Title: "Logs"
Expand Down Expand Up @@ -120,7 +132,6 @@ Pages:
Enable: "Enable"
Disable: "Disable"
Close: "Close"

Backups:
List:
Title: "Backups"
Expand All @@ -136,6 +147,39 @@ Pages:
Actions:
Restore: "Restore"
Delete: "Delete"
API:
Create:
Title: "Create API Key"
Description: "Enter the name and permission of the api key."
Forms:
Title:
Label: "Name"
Placeholder: "The name of the Api key..."
Content:
Label: "Permissions"
Placeholder: ""
Items:
ReadOnly: "Read Only"
ReadWrite: "Read & Write"
Access:
Label: "Access (% for any ip address)"
Placeholder: "%"
Submit: "Create Key"
Cancel: "Cancel"
List:
Title: "API Keys"
Description: "Here you can manage all the api keys!."
Table:
CreateButton: "Create new api key!"
Head:
Columns:
ID: "ID"
Title: "Title"
Date: "Date"
Actions: "Actions"
Actions:
Edit: "Edit"
Delete: "Delete"
Announcements:
Create:
Title: "Create Announcement"
Expand Down Expand Up @@ -180,6 +224,8 @@ Pages:
Admin:
Name: "Administration Area"
Items:
API:
Title: "API Keys"
Support:
Title: "Support Tickets"
Announcements:
Expand Down Expand Up @@ -618,4 +664,7 @@ Alerts:
Message: "An unknown error occurred. Please try again."
PluginAlreadyExists:
Title: "Plugin Already exists"
Message: "The plugin already exists. Please try again."
Message: "The plugin already exists. Please try again."
NothingChanged:
Title: "Nothing Changed"
Message: "Please modify something in order to apply new values!"
88 changes: 88 additions & 0 deletions storage/themes/v2/admin/api/list.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{% extends 'components/dashboard.twig' %}

{% block head %}{% endblock %}

{% block dashboard %}
<div class="card">
<div class="card-datatable table-responsive pt-0">
<div class="card-header">
<h3 class="card-title">{{ lang('Pages.AdminArea.Pages.API.List.Title') }}</h3>
<p class="card-subtitle text-muted">{{ lang('Pages.AdminArea.Pages.API.List.Description') }}</p>
<br>
<div class="card-options">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#createAnnouncementModal">
{{ lang('Pages.AdminArea.Pages.API.List.Table.CreateButton') }}
</button>
</div>
</div>
<table class="datatables-basic table">
<thead>
<tr>
<th>{{lang('Pages.AdminArea.Pages.API.List.Table.Head.Columns.ID')}}</th>
<th>{{lang('Pages.AdminArea.Pages.API.List.Table.Head.Columns.Title') }}</th>
<th>{{lang('Pages.AdminArea.Pages.API.List.Table.Head.Columns.Date')}}</th>
<th>{{lang('Pages.AdminArea.Pages.API.List.Table.Head.Columns.Actions')}}</th>
</tr>
</thead>
<tbody>
{% for announcement in API %}
<tr>
<td>{{ announcement.id }}</td>
<td>{{ announcement.title }}</td>
<td>{{ announcement.date }}</td>
<td>
<a href="/admin/API/{{ announcement.id }}/edit" class="btn btn-sm btn-primary">{{lang('Pages.AdminArea.Pages.API.List.Table.Head.Actions.Edit') }}</a>
<button onclick="requireConfirmation('/admin/API/{{ announcement.id }}/delete')" class="btn btn-sm btn-danger">{{lang('Pages.AdminArea.Pages.API.List.Table.Head.Actions.Delete')}}</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="modal fade" id="createAnnouncementModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg modal-simple modal-dialog-centered">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<div class="text-center mb-4">
<h4 class="mb-2">{{ lang('Pages.AdminArea.Pages.API.Create.Title') }}</h4>
<p>{{ lang('Pages.AdminArea.Pages.API.Create.Description') }}</p>
</div>
<form action="/admin/api/create" method="POST">
<div class="mb-3">
<label for="apiName" class="form-label">{{ lang('Pages.AdminArea.Pages.API.Create.Forms.Title.Label') }}</label>
<input type="text" class="form-control" id="apiName" name="title" placeholder="{{ lang('Pages.AdminArea.Pages.API.Create.Forms.Title.Placeholder') }}" required>
</div>
<div class="mb-5 col-12">
<label for="apiAccess" class="form-label">{{lang("Pages.AdminArea.Pages.API.Create.Forms.Content.Label")}}</label>
<select id="apiAccess" name="apiAccess" class="select2 form-select form-select-lg">
<option value="rw">{{lang("Pages.AdminArea.Pages.API.Create.Forms.Content.Items.ReadWrite")}}</option>
<option value="r">{{lang("Pages.AdminArea.Pages.API.Create.Forms.Content.Items.ReadOnly")}}</option>
</select>
</div>
<div class="mb-5 col-12">
<label for="apiAccess" class="form-label">{{lang("Pages.AdminArea.Pages.API.Create.Forms.Access.Label")}}</label>


</div>
{% if isTurnStileEnabled == true %}
<center>
<div class="cf-turnstile" data-sitekey="{{setting('cloudflare_turnstile', 'sitekey')}}"></div>
</center>
<br>
{% else %}
<br>
{% endif %}
<div class="text-center">
<button type="submit" class="btn btn-primary">{{ lang('Pages.AdminArea.Pages.API.Create.Forms.Submit') }}</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ lang('Pages.AdminArea.Pages.API.Create.Forms.Cancel') }}</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>{% endblock %}{% block footer %}
{% include 'requirements/datatables.twig' %}
<script>$(document).ready(function() {$('.datatables-basic').DataTable({responsive: true,pageLength: 10,lengthMenu: [5, 10, 25, 50, 75, 100]});});</script>{% endblock %}
2 changes: 1 addition & 1 deletion storage/themes/v2/admin/plugins/list.twig
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</button>
{% if plugin.enabled == "true" %}
{% for button in getButtons(plugin.id) %}
<button onclick="requireConfirmation('/admin/plugins/{{ plugin.id }}{{ button.url }}')" class="btn btn-sm btn-{{ button.color }}">{{ button.text }}</button>
<button onclick="requireConfirmation('{{ button.url }}')" class="btn btn-sm btn-{{ button.color }}">{{ button.text }}</button>
{% endfor %}
<button onclick="requireConfirmation('/admin/plugins/{{ plugin.id }}/disable')" class="btn btn-sm btn-danger">{{ lang('Pages.AdminArea.Pages.Plugins.List.Table.Head.Actions.Disable') }}</button>
{% else %}
Expand Down
Loading

0 comments on commit dd1394a

Please sign in to comment.