-
Notifications
You must be signed in to change notification settings - Fork 46
/
serve.php
86 lines (73 loc) · 3.38 KB
/
serve.php
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
*
* @package Kleeja
* @copyright (c) 2007 Kleeja.net
* @license ./docs/license.txt
*
*/
/**
* We are in serve.php file, useful for exceptions
*/
define('IN_SERVE', true);
/**
* Defaults rewrite rules
*/
$rules = [
'^index.html$' => ['file' => 'index.php'],
'^download([0-9]*).html$' => ['file' => 'do.php', 'args' => 'id=$1'],
'^downloadf-(.*)-([a-zA-Z0-9_-]*).html$' => ['file' => 'do.php', 'args' =>'filename=$1&x=$2'],
'^down-([0-9]*).html$' => ['file' => 'do.php', 'args' => 'down=$1'],
'^downf-(.*)-([a-zA-Z0-9_-]*).html$' => ['file' => 'do.php', 'args' => 'downf=$1&x=$2'],
'^downex-([0-9]*).html$' => ['file' => 'do.php', 'args' => 'down=$1'],
'^downexf-(.*)-([a-zA-Z0-9_-]*).html$' => ['file' =>'do.php', 'args' => 'downexf=$1&x=$2'],
'^thumb([0-9]*).html$' => ['file' => 'do.php', 'args' => 'thmb=$1'],
'^imagef-(.*)-([a-zA-Z0-9_-]*).html$' => ['file' =>'do.php', 'args' => 'imgf=$1&x=$2'],
'^thumbf-(.*)-([a-zA-Z0-9_-]*).html$' => ['file' => 'do.php', 'args' => 'thmbf=$1&x=$2'],
'^image([0-9]*).html$' => ['file' => 'do.php', 'args' => 'img=$1'],
'^del([a-zA-Z0-9_-]*).html$' => ['file' => 'go.php', 'args' => 'go=del&cd=$1'],
'^(call|guide|rules|stats|report).html$' => ['file' =>'go.php', 'args' => 'go=$1'],
'^report[_-]([0-9]*).html$' => ['file' => 'go.php', 'args' => 'go=report&id=$1'],
'^(filecp|profile|fileuser|register|login|logout).html$' => ['file' => 'ucp.php', 'args' => 'go=$1'],
'^fileuser[_-]([0-9]+).html$' => ['file' => 'ucp.php', 'args' => 'go=fileuser&id=$1'],
'^fileuser[_-]([0-9]+)-([0-9]+).html$' => ['file' => 'ucp.php', 'args' => 'go=fileuser&id=$1&page=$2'],
// #for future plugins
'^go-(.*).html$' => ['file' => 'go.php', 'args' => 'go=$1'],
];
if (file_exists('plugins_rules.php'))
{
$plugins_rules = include_once 'plugins_rules.php';
$rules = array_merge($rules, $plugins_rules);
}
$base_folder = str_replace('/serve.php', '', parse_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], PHP_URL_PATH));
$request_uri = preg_replace('/^'. preg_quote($base_folder, '/') . '\//', '', strtok($_SERVER['REQUEST_URI'], '?'));
foreach ($rules as $rule_regex => $rule_result)
{
if (preg_match("/{$rule_regex}/", $request_uri, $matches))
{
if (! empty($rule_result['args']))
{
parse_str($rule_result['args'], $args);
foreach ($args as $arg_key => $arg_value)
{
if (preg_match('/^\$/', $arg_value))
{
$match_number = ltrim($arg_value, '$');
if (isset($matches[$match_number]))
{
$_GET[$arg_key] = $matches[$match_number];
}
}
else
{
$_GET[$arg_key] = $arg_value;
}
}
}
include $rule_result['file'];
exit;
}
}
//fallback
define('SERVE_FALLBACK', true);
include 'go.php';