Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Addosn
  • Loading branch information
NaysKutzu committed Oct 4, 2024
1 parent 790db1a commit 5fdf0d1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
49 changes: 49 additions & 0 deletions app/Web/Routes/admin/addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,55 @@

global $router;

$router->add('/admin/plugins/upload', function (): void {
global $router, $event, $renderer;
$template = 'admin/plugins/upload.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.plugins.install')
) {
exit(header('location: /errors/403'));
}

$renderer->addGlobal('page_name', 'Upload Plugin');
Engine::registerAlerts($renderer, $template);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_FILES['pluginFile']) && $_FILES['pluginFile']['error'] === UPLOAD_ERR_OK) {
$fileTmpPath = $_FILES['pluginFile']['tmp_name'];
$fileName = $_FILES['pluginFile']['name'];
$fileSize = $_FILES['pluginFile']['size'];
$fileType = $_FILES['pluginFile']['type'];
$fileNameCmps = explode(".", $fileName);
$fileExtension = strtolower(end($fileNameCmps));

if ($fileExtension === 'mfa') {
// Process the file upload (e.g., move to the desired directory)
$uploadFileDir = '/path/to/upload/directory/';
$dest_path = $uploadFileDir . $fileName;

if (move_uploaded_file($fileTmpPath, $dest_path)) {
exit(header('location: /admin/plugins?s=ok'));
} else {
exit(header('location: /admin/plugins?s=error'));
}
} else {
$renderer->addGlobal('error', 'Invalid file type. Only .mfa files are allowed.');
}
} else {
$renderer->addGlobal('error', 'There was an error with the file upload.');
}
}

exit($renderer->render($template));
});

$router->add('/admin/plugins', function (): void {
global $router, $event, $renderer;
$template = 'admin/plugins/list.twig';
Expand Down
2 changes: 2 additions & 0 deletions storage/lang/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ Alerts:
Message: "You have successfully verified two factor authentication."

Error:
Plugins:

Social:
CannotLikeYourSelf:
Title: "Cannot Like Yourself"
Expand Down
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 @@ -30,7 +30,7 @@
<form action="/admin/plugins/upload" method="post" enctype="multipart/form-data">
<div class="mb-3">
<label for="pluginFile" class="form-label">{{ lang('Pages.AdminArea.Pages.Plugins.List.UploadModal.FileLabel') }}</label>
<input type="file" class="form-control" id="pluginFile" name="pluginFile" required>
<input type="file" class="form-control" id="pluginFile" name="pluginFile" accept=".mfa" required>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">{{ lang('Pages.AdminArea.Pages.Plugins.List.UploadModal.Submit') }}</button>
Expand Down

0 comments on commit 5fdf0d1

Please sign in to comment.