forked from sergejey/majordomo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnf.php
140 lines (118 loc) · 6.28 KB
/
nf.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/*
* @version 0.1 (auto-set)
*/
/**
* 404-error handler
*
* @package MajorDoMo
* @author Serge Dzheigalo <[email protected]> http://smartliving.ru/
*/
list($usec, $sec) = explode(" ",microtime());
$script_started_time = ((float)$usec + (float)$sec);
if (!preg_match('/\/$/', $_SERVER["REQUEST_URI"]))
$file = basename($_SERVER["REQUEST_URI"]);
$ext = strtolower(substr($file, -3));
if ($ext == 'jpg' || $ext == 'gif' || $ext == 'css')
{
header("HTTP/1.0: 404 Page not found\n");
exit;
}
if (preg_match("/\?(.*?)$/", $_SERVER["REQUEST_URI"], $matches))
$redir_qry = $matches[1];
$file = preg_replace("/\.htm.*$/","", $file);
if ($file != '')
$fake_doc = $file;
include_once("./config.php");
// use this array for URL conversion rules
$requests = array(
"/^\/panel\/script\/(\d+)\.html/is" => '?(panel:{action=scripts})&md=scripts&view_mode=edit_scripts&id=\1',
"/^\/panel\/command\/(\d+)\.html/is" => '?(panel:{action=commands})&md=commands&view_mode=edit_commands&id=\1',
"/^\/panel\/xray\.html/is" => '?(panel:{action=xray})&md=xray',
"/^\/panel\/linkedobject.html/is" => '?(panel:{action=linkedobject})',
"/^\/panel\/popup\/(.+?).html/is" => '?(panel:{action=\1})&print=1',
"/^\/panel\/class\/(\d+)\.html/is" => '?(panel:{action=classes})&md=classes&view_mode=edit_classes&id=\1',
"/^\/panel\/class\/(\d+)\/properties\.html/is"=> '?(panel:{action=classes})&md=classes&view_mode=edit_classes&id=\1&tab=properties',
"/^\/panel\/class\/(\d+)\/methods\.html/is"=> '?(panel:{action=classes})&md=classes&view_mode=edit_classes&id=\1&tab=methods',
"/^\/panel\/class\/(\d+)\/methods\/(\d+)\.html/is"=> '?(panel:{action=classes}classes:{view_mode=edit_classes, tab=methods, id=\1, instance=adm})&md=methods&view_mode=edit_methods&id=\2',
"/^\/panel\/class\/(\d+)\/object\/(\d+)\.html/is"=> '?(panel:{action=classes}classes:{view_mode=edit_classes, tab=objects, id=\1, instance=adm})&md=objects&view_mode=edit_objects&id=\2',
"/^\/panel\/class\/(\d+)\/object\/(\d+)\\/methods\.html/is"=> '?(panel:{action=classes}classes:{view_mode=edit_classes, tab=objects, id=\1, instance=adm})&md=objects&view_mode=edit_objects&id=\2&tab=methods',
"/^\/panel\/class\/(\d+)\/object\/(\d+)\\/methods\/(\d+)\.html/is"=> '?(panel:{action=classes}classes:{view_mode=edit_classes, tab=objects, id=\1, instance=adm})&md=objects&view_mode=edit_objects&id=\2&tab=methods&overwrite=1&method_id=\3',
"/^\/panel\/class\/(\d+)\/object\/(\d+)\\/methods\/(\d+)\.html/is"=> '?(panel:{action=classes}classes:{view_mode=edit_classes, tab=objects, id=\1, instance=adm})&md=objects&view_mode=edit_objects&id=\2&tab=methods&overwrite=1&method_id=\3',
"/^\/panel\/class\/(\d+)\/object\/(\d+)\\/properties\.html/is"=> '?(panel:{action=classes}classes:{view_mode=edit_classes, tab=objects, id=\1, instance=adm})&md=objects&view_mode=edit_objects&id=\2&tab=properties',
"/^\/panel\/scene\/(\d+)\/elements\/(\d+)\\/state(\d+)\.html/is"=> '?(panel:{action=scenes})&md=scenes&view_mode=edit_scenes&id=\1&tab=elements&view_mode2=edit_elements&element_id=\2&state_id=\3',
"/^\/panel\/zwave\/(\d+)\.html/is" => '?(panel:{action=zwave})&md=zwave&&view_mode=edit_zwave_devices&id=\1',
"/^\/panel\/app_gpstrack\/action_(\d+)\.html/is"=> '?(panel:{action=app_gpstrack})&md=app_gpstrack&data_source=gpsactions&view_mode=edit_gpsactions&id=\1',
"/^\/panel\/pattern\/(\d+)\.html/is" => '?(panel:{action=patterns})&md=patterns&view_mode=edit_patterns&id=\1',
"/^\/menu\.html/is" => '?(application:{action=menu})',
"/^\/pages\.html/is" => '?(application:{action=pages})',
"/^\/menu\/(\d+?)\.html/is" => '?(application:{action=menu, parent_item=\1})',
"/^\/popup\/(shoutbox)\.html/is" => '?(application:{action=\1, popup=1, app_action=1})',
"/^\/module\/(.+?)\.html/is" => '?(application:{action=\1, popup=1, app_action=1})',
"/^\/apps\/(.+?)\.html/is" => '?(application:{action=apps, popup=1, app_action=\1})',
"/^\/apps\.html/is" => '?(application:{action=apps, popup=1})',
"/^\/popup\/(.+?)\/(.+?)\.html/is" => '?(application:{action=\1, popup=1})',
"/^\/popup\/(.+?)\.html/is" => '?(application:{action=\1, popup=1})',
"/^\/ajax\/(.+?)\.html/is" => '?(application:{action=\1, ajax=1})',
"/^\/page\/(\d+?)\.html/is" => '?(application:{action=layouts, popup=1}layouts:{view_mode=view_layouts, id=\1})',
"/^\/getnextevent\.html/is" => '?(application:{action=events})',
"/^\/getlatestnote\.html/is" => '?(application:{action=getlatestnote})',
"/^\/getlatestmp3\.html/is" => '?(application:{action=getlatestmp3})',
"/^\/design_sample\.html/is" => '?(application:{action=design_sample})',
"/^\/docs\/(\d+)\.html/is" => '?(application:{action=docs, doc_id=\1})',
"/^\/([\w-]+)\.html/is" => '?(application:{action=docs, doc_name=\1})'
);
$found=0;
foreach($requests as $key => $value)
{
if (!$found && preg_match($key, $_SERVER["REQUEST_URI"], $matches))
{
$link = $value;
$matchesCount = count($matches);
for ($i = 1; $i < $matchesCount; $i++)
{
$link = str_replace("\\$i", $matches[$i], $link);
}
$link = preg_replace('/\\\\(\d+?)/is', '', $link);
$found = 1;
}
}
if (preg_match('/^moved:(.+)/is', $link, $matches))
{
Header("HTTP/1.1 301 Moved Permanently");
header("Location:" . $matches[1]);
exit;
}
include_once("./config.php");
include_once("./lib/loader.php");
if ($link != '')
{
$mdl = new module();
$param_str = $mdl->parseLinks("<a href=\"$link\">");
if (preg_match("/<a href=\".+?\?pd=(.*?)&(.+)\">/", $param_str, $matches))
{
$pd = $matches[1];
$other = $matches[2];
$tmp = explode('&', $other);
foreach ($tmp as $pair)
{
$tmp2 = explode('=', $pair);
$_GET[$tmp2[0]] = $tmp2[1];
${$tmp2[0]} = $tmp2[1];
}
}
elseif (preg_match("/<a href=\".+?\?pd=(.*?)\">/", $param_str, $matches))
{
$pd = $matches[1];
}
}
else
{
header("HTTP/1.0 404 Not Found");
echo "The page cannot be found. Please use <a href='/'>this link</a> to continue browsing.";
exit;
}
if (preg_match('/^\/panel\//is', $_SERVER['REQUEST_URI']))
include_once("admin.php");
else
include_once("index.php");