forked from danopia/php-ircd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
67 lines (53 loc) · 1.67 KB
/
index.php
File metadata and controls
67 lines (53 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* PHP-IRCd - An IRC server in PHP
*
* Originally written by Daniel Danopia (2008)
* Modernized 2025
*/
// Check if executed as CLI or via web server
$isCliMode = (php_sapi_name() === 'cli');
// Initialize autoloader
require_once __DIR__ . '/vendor/autoload.php';
use PhpIrcd\Core\Config;
use PhpIrcd\Core\Server;
use PhpIrcd\Utils\Logger;
// Set error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Set timezone
date_default_timezone_set('UTC');
// Load configuration
$configPath = __DIR__ . '/config.php';
if (!file_exists($configPath)) {
die("Configuration file not found: {$configPath}\n");
}
$config = require $configPath;
// Initialize logger
$logger = new Logger($config['log_level'] ?? 'info');
// Create and start server
$server = new Server($config, false);
$server->start();
if (!$isCliMode) {
// Einfache API-Router-Logik
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
$requestMethod = $_SERVER['REQUEST_METHOD'] ?? 'GET';
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
if ($requestMethod === 'OPTIONS') {
http_response_code(204);
exit;
}
if (strpos($requestUri, '/api/') === 0) {
$apiPath = substr($requestUri, 5); // nach /api/
require_once __DIR__ . '/src/Web/api_router.php';
handle_api_request($apiPath, $requestMethod, $server, $config);
exit;
} else {
// No web interface available anymore
header('Content-Type: text/plain');
echo "PHP-IRCd: Web interface removed. Please use the API at /api/.";
exit;
}
}