Project

General

Profile

Download (2.02 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-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
		return false;
46
	}
47
	$page = str_replace($g['www_path'] . '/', '', $file);
48
	$page .= (!empty($query)) ? "?{$query}" : "";
49

    
50
	/* look for a match */
51
	foreach ($matches as $match) {
52

    
53
		/* possibly ignore full wildcard match */
54
		if (!$fullwc && !strcmp($match , "*")) {
55
			continue;
56
		}
57

    
58
		/* compare exact or wildcard match */
59
		$match = str_replace(array(".", "*", "?"), array("\.", ".*", "\?"), $match);
60
		$result = preg_match("@^/{$match}$@", "/{$page}");
61

    
62
		if ($result) {
63
			return true;
64
		}
65
	}
66

    
67
	return false;
68
}
(4-4/60)