Issues (4868)

admin/inc/class.admin_denyaccess.inc.php (3 issues)

1
<?php
2
/**
3
 * EGgroupware admin - Deny access
4
 *
5
 * @link http://www.egroupware.org
6
 * @package admin
7
 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
8
 * @version $Id$
9
 */
10
11
use EGroupware\Api;
12
use EGroupware\Api\Framework;
13
14
15
/**
16
 * Deny access to certain parts of admin
17
 */
18
class admin_denyaccess
19
{
20
	var $template;
21
	var $nextmatchs;
22
	var $public_functions = array(
23
		'list_apps'    => True,
24
		'access_form'  => True,
25
		'account_list' => True
26
	);
27
28
	function __construct()
29
	{
30
		$this->account_id = (int)$_GET['account_id'];
0 ignored issues
show
Bug Best Practice introduced by
The property account_id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
		if (!$this->account_id || $GLOBALS['egw']->acl->check('account_access',64,'admin'))
32
		{
33
			$GLOBALS['egw']->redirect_link('/index.php');
34
		}
35
		$this->template = new Framework\Template(Framework\Template::get_dir('admin'));
36
	}
37
38
	function common_header()
39
	{
40
		$GLOBALS['egw_info']['flags']['app_header'] = lang('Admin') . ' - ' . lang('ACL Manager') .
41
			': ' . Api\Accounts::username($this->account_id);
42
		echo $GLOBALS['egw']->framework->header();
43
	}
44
45
	function list_apps()
46
	{
47
		$this->common_header();
48
49
		Api\Hooks::process('acl_manager',array('preferences'));
50
51
		$this->template->set_file(array(
52
			'app_list'   => 'acl_applist.tpl'
53
		));
54
		$this->template->set_block('app_list','list');
55
		$this->template->set_block('app_list','app_row');
56
		$this->template->set_block('app_list','app_row_noicon');
57
		$this->template->set_block('app_list','link_row');
58
		$this->template->set_block('app_list','spacer_row');
59
60
		if (is_array($GLOBALS['acl_manager']))
61
		{
62
			foreach($GLOBALS['acl_manager'] as $app => $locations)
63
			{
64
				$icon = Api\Image::find($app,array('navbar.png',$app.'png','navbar.gif',$app.'.gif'));
65
				$this->template->set_var('icon_backcolor',$GLOBALS['egw_info']['theme']['row_off']);
66
				$this->template->set_var('link_backcolor',$GLOBALS['egw_info']['theme']['row_off']);
67
				$this->template->set_var('app_name',$GLOBALS['egw_info']['apps'][$app]['title']);
68
				$this->template->set_var('app_icon',$icon);
69
70
				if ($icon)
71
				{
72
					$this->template->fp('rows','app_row',True);
73
				}
74
				else
75
				{
76
					$this->template->fp('rows','app_row_noicon',True);
77
				}
78
79
				if (is_array($locations))
80
				{
81
					foreach($locations as $loc => $value)
82
					{
83
						$link_values = array(
84
							'menuaction' => 'admin.admin_denyaccess.access_form',
85
							'location'   => $loc,
86
							'acl_app'    => $app,
87
							'account_id' => $this->account_id
88
						);
89
90
						$this->template->set_var('link_location',$GLOBALS['egw']->link('/index.php',$link_values));
91
						$this->template->set_var('lang_location',lang($value['name']));
92
						$this->template->fp('rows','link_row',True);
93
					}
94
				}
95
96
				$this->template->parse('rows','spacer_row',True);
97
			}
98
		}
99
		$this->template->set_var(array(
100
			'cancel_action' => $GLOBALS['egw']->link('/admin/index.php'),
101
			'lang_cancel'   => lang('Cancel')
102
		));
103
		$this->template->pfp('out','list');
104
		echo $GLOBALS['egw']->framework->footer();
105
	}
106
107
	function access_form()
108
	{
109
		$location = $_GET['location'];
110
111
		// for POST (not GET or cli call via setup_cmd_admin) validate CSRF token
112
		if ($_SERVER['REQUEST_METHOD'] == 'POST')
113
		{
114
			Api\Csrf::validate($_POST['csrf_token'], __FILE__);
115
		}
116
		if ($_POST['submit'] || $_POST['cancel'])
117
		{
118
			if ($_POST['submit'])
119
			{
120
				$total_rights = 0;
121
				if (is_array($_POST['acl_rights']))
122
				{
123
					foreach($_POST['acl_rights'] as $rights)
124
					{
125
						$total_rights += $rights;
126
					}
127
				}
128
				if ($total_rights)
129
				{
130
					$GLOBALS['egw']->acl->add_repository($_GET['acl_app'], $location, $this->account_id, $total_rights);
131
				}
132
				else	// we dont need to save 0 rights (= no restrictions)
133
				{
134
					$GLOBALS['egw']->acl->delete_repository($_GET['acl_app'], $location, $this->account_id);
135
				}
136
			}
137
			$this->list_apps();
138
			return;
139
		}
140
		Api\Hooks::single('acl_manager',$_GET['acl_app']);
141
		$acl_manager = $GLOBALS['acl_manager'][$_GET['acl_app']][$location];
142
143
		$this->common_header();
144
		$this->template->set_file('form','acl_manager_form.tpl');
145
		$this->template->set_var('csrf_token', Api\Csrf::token(__FILE__));
146
147
		$afn = Api\Accounts::username($this->account_id);
148
149
		$this->template->set_var('lang_message',lang('Check items to <b>%1</b> to %2 for %3',lang($acl_manager['name']),$GLOBALS['egw_info']['apps'][$_GET['acl_app']]['title'],$afn));
0 ignored issues
show
The call to lang() has too many arguments starting with lang($acl_manager['name']). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

149
		$this->template->set_var('lang_message',/** @scrutinizer ignore-call */ lang('Check items to <b>%1</b> to %2 for %3',lang($acl_manager['name']),$GLOBALS['egw_info']['apps'][$_GET['acl_app']]['title'],$afn));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
150
		$link_values = array(
151
			'menuaction' => 'admin.admin_denyaccess.access_form',
152
			'acl_app'    => $_GET['acl_app'],
153
			'location'   => urlencode($_GET['location']),
154
			'account_id' => $this->account_id
155
		);
156
157
		$acl    = new Api\Acl($this->account_id);
158
		$acl->read_repository();
159
		$grants = $acl->get_rights($location,$_GET['acl_app']);
160
161
		$this->template->set_var('form_action',$GLOBALS['egw']->link('/index.php',$link_values));
162
163
		foreach($acl_manager['rights'] as $name => $value)
164
		{
165
			$cb .= '<input type="checkbox" name="acl_rights[]" value="'.$value.'"'.($grants & $value ? ' checked' : '').'>&nbsp;'.lang($name)."<br>\n";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $cb seems to be never defined.
Loading history...
166
		}
167
		$this->template->set_var('select_values',$cb);
168
		$this->template->set_var('lang_submit',lang('Save'));
169
		$this->template->set_var('lang_cancel',lang('Cancel'));
170
171
		$this->template->pfp('out','form');
172
		echo $GLOBALS['egw']->framework->footer();
173
	}
174
}
175