Skip to content

Commit

Permalink
feat: обновление совместимости, улучшение проверки маршрутизации
Browse files Browse the repository at this point in the history
Совместимость с DLE 17 и MySQL версии 5.7.
Улучшена проверка маршрутизации путем проверки запрещенных маршрутов
и обеспечения существования запрашиваемого маршрута перед его подключением.
Добавлен парсинг тела запроса и middleware для маршрутизации в API.
Удалены неиспользуемые импорты в файле маршрутов post.
  • Loading branch information
Gokujo committed Jan 7, 2025
1 parent 961db86 commit 74590ab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
[![GitHub forks](https://img.shields.io/github/forks/Gokujo/dle_api.svg?style=flat-square)](https://github.com/Gokujo/dle_api/network)
[![GitHub license](https://img.shields.io/github/license/Gokujo/dle_api.svg?style=flat-square)](https://github.com/Gokujo/dle_api/blob/master/LICENSE)

![DLE-16.x](https://img.shields.io/badge/DLE-16.x-green.svg?style=flat-square)
![MySQL-5.5.6](https://img.shields.io/badge/MySQL-5.5.6-red.svg?style=flat-square)
![DLE-17.3](https://img.shields.io/badge/DLE-17.3-green.svg?style=flat-square)
![MySQL-5.7](https://img.shields.io/badge/MySQL-5.5.6-red.svg?style=flat-square)
![PHP-8.3](https://img.shields.io/badge/PHP-8.3-red.svg?style=flat-square)

![Версия_релиза](https://img.shields.io/github/manifest-json/v/Gokujo/dle_api?filename=manifest.json&style=flat-square)
![Версия_релиза](https://img.shields.io/badge/Version-BETA-orange.svg?style=flat-square)

# DLE API
Модификация для админпанели и глобальные функции для моих разработок
Совместимость проверенна на DLE-версиях 16.х. Для корректной работы требуется минимальная версия MySQL 5.5.6 или MariaDB 10.0, поскольку используются Foreign Key, которые требуют наличие InnoDB.
Совместимость проверенна на DLE-версиях 17.3. Для корректной работы требуется минимальная версия MySQL 5.5.6 или MariaDB 10.0, поскольку используются Foreign Key, которые требуют наличие InnoDB.

Для установки достаточно скачать [релиз](https://github.com/Gokujo/dle_api/releases/latest).
Документация к API находится на сервере [POSTMAN](https://documenter.getpostman.com/view/7856564/2s93CLsZ6p). На данный момент она не полная и пополняется медленно, но верно.
Expand Down
3 changes: 3 additions & 0 deletions upload/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@

$app->setBasePath('/api/v1');

$app->addBodyParsingMiddleware();
$app->addRoutingMiddleware();

// Middleware для обработки ошибок
$app->addErrorMiddleware(
$container->get('settings')['displayErrorDetails'],
Expand Down
26 changes: 19 additions & 7 deletions upload/api/routes/_router.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@
die("Hacking attempt!");
}

$routePath = API_DIR . '/routes';
$routeFiles = glob($routePath . '/*.php');
$routePath = API_DIR . '/routes';
$forbiddenFiles = ['_router.php', '_sample.php', '.', '..'];
$routeFiles = array_diff(scandir($routePath), $forbiddenFiles);

$route_path = str_replace([$_SERVER['REQUEST_SCHEME'] . '://', $_SERVER['SERVER_NAME'], 'api', 'v1', '/'], '', $_SERVER['REDIRECT_URL']);
$forbidden = ['_router.php', '_sample.php'];
// Проверяем соответствие URL-адреса маршруту
if (!preg_match('#/api/v1/([^/]+)/#', $_SERVER['REDIRECT_URL'], $matches)) {
die('Некорректный рутинг!');
}

$routeFileName = "{$matches[1]}.php";

if(in_array("{$route_path}.php", $forbidden)) die('Данный рутинг запрещён!');
if(!in_array("{$routePath}/{$route_path}.php", $routeFiles)) die('Данного рутинга не существует!');
// Проверяем запрещённые или отсутствующие маршруты
if (in_array($routeFileName, $forbiddenFiles, true)) {
die('Данный рутинг запрещён!');
}

if (!in_array($routeFileName, $routeFiles, true)) {
die('Данного рутинга не существует!');
}

include_once DLEPlugins::Check("{$routePath}/{$route_path}.php");
// Подключаем файл маршрута с проверкой через DLEPlugins
include_once DLEPlugins::Check("{$routePath}/{$routeFileName}");

4 changes: 0 additions & 4 deletions upload/api/routes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
}

use Slim\Routing\RouteCollectorProxy;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

$api_name = "post";
$possibleData = [
Expand Down

0 comments on commit 74590ab

Please sign in to comment.