1
|
<?php
|
2
|
/*
|
3
|
* auth_func.inc
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2019 Rubicon Communications, LLC (Netgate)
|
7
|
* Copyright (c) 2005-2006 Bill Marquette <bill.marquette@gmail.com>
|
8
|
* Copyright (c) 2006 Paul Taylor <paultaylor@winn-dixie.com>.
|
9
|
* Copyright (c) 2008 Shrew Soft Inc
|
10
|
* Copyright (c) 2003-2006 Manuel Kasper <mk@neon1.net>.
|
11
|
* All rights reserved.
|
12
|
*
|
13
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
14
|
* you may not use this file except in compliance with the License.
|
15
|
* You may obtain a copy of the License at
|
16
|
*
|
17
|
* http://www.apache.org/licenses/LICENSE-2.0
|
18
|
*
|
19
|
* Unless required by applicable law or agreed to in writing, software
|
20
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
21
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
22
|
* See the License for the specific language governing permissions and
|
23
|
* limitations under the License.
|
24
|
*/
|
25
|
|
26
|
/*
|
27
|
* Function put in seperate file to avoid processing priv.inc which is cpu intensive
|
28
|
* cmp_page_matches is used by both auth_check.inc and priv.inc which is used by guiconfig.inc
|
29
|
*/
|
30
|
|
31
|
function cmp_page_matches($page, & $matches, $fullwc = true) {
|
32
|
|
33
|
global $g;
|
34
|
// $dbg_matches = implode(",", $matches);
|
35
|
// log_error("debug: checking page {$page} match with {$dbg_matches}");
|
36
|
|
37
|
if (!is_array($matches)) {
|
38
|
return false;
|
39
|
}
|
40
|
|
41
|
list($file, $query) = explode('?', $page);
|
42
|
$file = realpath( $g['www_path'] . '/' . ltrim($file, '/'));
|
43
|
if (empty($file)) {
|
44
|
/* File does not exist, or other path shenanigans */
|
45
|
|
46
|
/* Some tabs are just JS anchors, detect this case. */
|
47
|
if ((substr($page, 0, 1) == "#") &&
|
48
|
(strpos($page, '.') === false) &&
|
49
|
(strpos($page, '/') === false) &&
|
50
|
(strpos($page, '?') === false)) {
|
51
|
return true;
|
52
|
}
|
53
|
|
54
|
/* Tried to query a path that does not exist */
|
55
|
return false;
|
56
|
}
|
57
|
$page = str_replace($g['www_path'] . '/', '', $file);
|
58
|
$page .= (!empty($query)) ? "?{$query}" : "";
|
59
|
|
60
|
/* look for a match */
|
61
|
foreach ($matches as $match) {
|
62
|
|
63
|
/* possibly ignore full wildcard match */
|
64
|
if (!$fullwc && !strcmp($match , "*")) {
|
65
|
continue;
|
66
|
}
|
67
|
|
68
|
/* compare exact or wildcard match */
|
69
|
$match = str_replace(array(".", "*", "?"), array("\.", ".*", "\?"), $match);
|
70
|
$result = preg_match("@^/{$match}$@", "/{$page}");
|
71
|
|
72
|
if ($result) {
|
73
|
return true;
|
74
|
}
|
75
|
}
|
76
|
|
77
|
return false;
|
78
|
}
|