Project

General

Profile

Download (2.39 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * auth_func.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2005-2006 Bill Marquette <bill.marquette@gmail.com>
10
 * Copyright (c) 2006 Paul Taylor <paultaylor@winn-dixie.com>.
11
 * Copyright (c) 2008 Shrew Soft Inc
12
 * Copyright (c) 2003-2006 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
/*
29
 * Function put in separate file to avoid processing priv.inc which is cpu intensive
30
 * cmp_page_matches is used by both auth_check.inc and priv.inc which is used by guiconfig.inc
31
 */
32

    
33
function cmp_page_matches($page, & $matches, $fullwc = true) {
34

    
35
	global $g;
36
//	$dbg_matches = implode(",", $matches);
37
//	log_error("debug: checking page {$page} match with {$dbg_matches}");
38

    
39
	if (!is_array($matches)) {
40
		return false;
41
	}
42

    
43
	list($file, $query) = explode('?', $page);
44
	$file = realpath( $g['www_path'] . '/' . ltrim($file, '/'));
45
	if (empty($file)) {
46
		/* File does not exist, or other path shenanigans */
47

    
48
		/* Some tabs are just JS anchors, detect this case. */
49
		if ((substr($page, 0, 1) == "#") &&
50
		    (strpos($page, '.') === false) &&
51
		    (strpos($page, '/') === false) &&
52
		    (strpos($page, '?') === false)) {
53
			return true;
54
		}
55

    
56
		/* Tried to query a path that does not exist */
57
		return false;
58
	}
59
	$page = str_replace($g['www_path'] . '/', '', $file);
60
	$page .= (!empty($query)) ? "?{$query}" : "";
61

    
62
	/* look for a match */
63
	foreach ($matches as $match) {
64

    
65
		/* possibly ignore full wildcard match */
66
		if (!$fullwc && !strcmp($match , "*")) {
67
			continue;
68
		}
69

    
70
		/* compare exact or wildcard match */
71
		$match = str_replace(array(".", "*", "?"), array("\.", ".*", "\?"), $match);
72
		$result = preg_match("@^/{$match}$@", "/{$page}");
73

    
74
		if ($result) {
75
			return true;
76
		}
77
	}
78

    
79
	return false;
80
}
(4-4/61)