Project

General

Profile

Download (2.43 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-2024 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
require_once('globals.inc');
29

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

    
35
function cmp_page_matches($page, & $matches, $fullwc = true) {
36

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

    
41
	if (!is_array($matches)) {
42
		return false;
43
	}
44

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

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

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

    
64
	/* look for a match */
65
	foreach ($matches as $match) {
66

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

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

    
76
		if ($result) {
77
			return true;
78
		}
79
	}
80

    
81
	return false;
82
}
(4-4/61)