-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
485 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.