Chore: Bump version to v1.1.0 and implement automated release system

This commit is contained in:
dyzulk
2026-01-17 13:01:05 +07:00
parent 64609a5821
commit 5b0b6de2dc
69 changed files with 3157 additions and 2375 deletions

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Middleware;
class AuthMiddleware implements MiddlewareInterface {
public function handle($request, \Closure $next) {
// Assume session is started in index.php
if (!isset($_SESSION['user_id'])) {
header('Location: /login');
exit;
}
return $next($request);
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Middleware;
use App\Core\Database;
class CorsMiddleware implements MiddlewareInterface {
public function handle($request, \Closure $next) {
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
// Always allow if no origin (e.g. server-to-server or same-origin strict)
// Check generic logic: if valid origin, try to match DB
if (!empty($origin)) {
$db = Database::getInstance();
$stmt = $db->query("SELECT * FROM api_cors WHERE origin = ? OR origin = '*' LIMIT 1", [$origin]);
$rule = $stmt->fetch();
if ($rule) {
header("Access-Control-Allow-Origin: " . ($rule['origin'] === '*' ? '*' : $origin));
$methods = json_decode($rule['methods'], true) ?: ['GET', 'POST'];
header("Access-Control-Allow-Methods: " . implode(', ', $methods));
$headers = json_decode($rule['headers'], true) ?: ['*'];
header("Access-Control-Allow-Headers: " . implode(', ', $headers));
header("Access-Control-Max-Age: " . ($rule['max_age'] ?? 3600));
// Handle preflight requests
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}
}
}
return $next($request);
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace App\Middleware;
interface MiddlewareInterface {
public function handle($request, \Closure $next);
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Middleware;
use App\Models\Config;
class RouterCheckMiddleware implements MiddlewareInterface {
public function handle($request, \Closure $next) {
// We need to extract the session from the URI
// Pattern: /{session}/...
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$scriptName = dirname($_SERVER['SCRIPT_NAME']);
if (strpos($path, $scriptName) === 0) {
$path = substr($path, strlen($scriptName));
}
$path = '/' . trim($path, '/');
// Regex to grab first segment
if (preg_match('#^/([^/]+)#', $path, $matches)) {
$session = $matches[1];
// Exclude system routes that might mimic this pattern if any (like 'settings')
// But 'settings' is usually top level.
// If the user name their router "settings", it would conflict anyway.
// Let's assume standard routing structure.
if ($session === 'login' || $session === 'logout' || $session === 'settings' || $session === 'install' || $session === 'api') {
return $next($request);
}
$configModel = new Config();
if ($session !== 'demo' && !$configModel->getSession($session)) {
// Router NOT FOUND
\App\Helpers\ErrorHelper::show(404, 'errors.router_not_found_title', 'errors.router_not_found_desc');
}
}
return $next($request);
}
}