-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathredirect.php
62 lines (41 loc) · 1.3 KB
/
redirect.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
<?php
if (empty($_GET['url'])) die();
$url = $_GET['url'];
function siteInList($site, $list) {
if ($site && $list && is_array($list) && count($list) > 0) {
foreach ($list as $item) {
$pattern = '#^' . str_replace('*', '.*', str_replace('.', '\.', trim(mb_strtolower($item)))) . '$#i';
if (preg_match($pattern, $site)) {
return true;
}
}
}
return false;
}
include_once 'sys/boot.php';
$Register = Register::getInstance();
$whitelist = explode(',', $Register['Config']::read('whitelist_sites'));
$blacklist = explode(',', $Register['Config']::read('blacklist_sites'));
$redirect = Config::read('redirect_active');
$delay = Config::read('url_delay');
if (!$delay || $delay < 1) $delay = 10;
$in_white = false;
$in_black = false;
if ($redirect) {
$info = parse_url($url);
if (isset($info['host'])) {
$site = trim(mb_strtolower($info['host']));
$in_white = siteInList($site, $whitelist);
$in_black = (!$in_white) ? siteInList($site, $blacklist) : false;
}
}
if ($in_white) {
header('Refresh: 0; url=' . $url);
die();
} else {
if (!$in_black) {
header('Refresh: ' . $delay . '; url=' . $url);
}
$View = $Register['Viewer'];
echo $View->view('redirect.html', array('url' => $url, 'black' => $in_black, 'template_path' => get_url('/template/' . Config::read('template'))));
}