priv.inc 3.1 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1 2
<?php

3 4 5
/*
	Copyright (C) 2008 Shrew Soft Inc
	Copyright (C) 2007-2008 Scott Ullrich <sullrich@gmail.com>
Ad Schellevis's avatar
Ad Schellevis committed
6
        Copyright (C) 2005-2006 Bill Marquette <bill.marquette@gmail.com>
7 8
        Copyright (C) 2006 Paul Taylor <paultaylor@winn-dixie.com>
        Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>
Ad Schellevis's avatar
Ad Schellevis committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
        All rights reserved.

        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:

        1. Redistributions of source code must retain the above copyright notice,
           this list of conditions and the following disclaimer.

        2. Redistributions in binary form must reproduce the above copyright
           notice, this list of conditions and the following disclaimer in the
           documentation and/or other materials provided with the distribution.

        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        POSSIBILITY OF SUCH DAMAGE.
*/
32 33 34 35
require_once("script/load_phalcon.php");
global $priv_list;
$acl = new OPNsense\Core\ACL();
$priv_list = $acl->getLegacyPrivList();
Ad Schellevis's avatar
Ad Schellevis committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56


function cmp_page_matches($page, & $matches, $fullwc = true) {
	if (!is_array($matches))
		return false;

	/* skip any leading fwdslash */
	$test = strpos($page, "/");
	if ($test !== false && $test == 0)
		$page = substr($page, 1);

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

		/* possibly ignore full wildcard match */
		if (!$fullwc && !strcmp($match ,"*"))
			continue;

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

Ad Schellevis's avatar
Ad Schellevis committed
58 59 60 61 62 63 64 65
		if ($result)
			return true;
	}

	return false;
}


66 67
function isAllowed($username, $page)
{
Ad Schellevis's avatar
Ad Schellevis committed
68 69
	global $_SESSION;

70
	if (!isset($username)) {
Ad Schellevis's avatar
Ad Schellevis committed
71
		return false;
72
	}
Ad Schellevis's avatar
Ad Schellevis committed
73

74
	/* root access check */
Ad Schellevis's avatar
Ad Schellevis committed
75
	$user = getUserEntry($username);
76 77 78
	if (isset($user)) {
		if (isset($user['uid'])) {
			if ($user['uid'] == 0) {
Ad Schellevis's avatar
Ad Schellevis committed
79
				return true;
80 81 82
			}
		}
	}
Ad Schellevis's avatar
Ad Schellevis committed
83 84

	/* user privelege access check */
85
	if (cmp_page_matches($page, $_SESSION['page-match'])) {
Ad Schellevis's avatar
Ad Schellevis committed
86
		return true;
87
	}
Ad Schellevis's avatar
Ad Schellevis committed
88 89 90 91

	return false;
}

92 93
function isAllowedPage($page)
{
94
	if (!isset($_SESSION['Username'])) {
Ad Schellevis's avatar
Ad Schellevis committed
95
		return false;
96
	}
Ad Schellevis's avatar
Ad Schellevis committed
97

98
	/* root access check */
99
	$user = getUserEntry($_SESSION['Username']);
100 101 102
	if (isset($user)) {
		if (isset($user['uid'])) {
			if ($user['uid'] == 0) {
Ad Schellevis's avatar
Ad Schellevis committed
103
				return true;
104 105 106
			}
		}
	}
Ad Schellevis's avatar
Ad Schellevis committed
107 108 109 110 111

	/* user privelege access check */
	return cmp_page_matches($page, $_SESSION['page-match']);
}

112

113
?>