Issues (296)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

lib/helper/AdminInterface.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace DigitalWand\AdminHelper\Helper;
4
5
/**
6
 * Базовый класс для описания админского интерфейса.
7
 * Включает в себя методы описывающие элементы управления, названия столбцов, типы полей и т.д.
8
 *
9
 * Есть 2 метода которые обязательно должны быть описаны в реализуемых классах:
10
 *
11
 * getFields()  - должен возвращать массив со списком табов и описанием полей для каждого таба
12
 * getHelpers() - должен возваращать массив со списком классов хелперов, также может включать
13
 * описание настроек элементов управления для хелпера.
14
 *
15
 * Для того что бы модуль мог корректна работать необходима регистрация классов унаследованных от AdminInterface.
16
 * Это можно сделтаь в include.php другого модуля(не рекомендуется) или AdminInterface зарегистрируется
17
 * автоматически если при генерации ссылок на страницы админского интерфейса использовался статический
18
 * метод getLink из соответствующего хелпера (ListHelper для списка элементов и EditHelper для страницы редактирования)
19
 *
20
 * При использовании разделов необходимо уведомить AdminInterface элементов и AdminInterface разделов о существовании
21
 * друг друга, что бы каждый из них регистрировал другого в момент собственной регистрации. Для этого достаточно указать полное
22
 * имя класса в методе getDependencies(), это нужно сделать как для AdminInterface элементов так и для AdminInterface разделов.
23
 *
24
 * @author Nik Samokhvalov <[email protected]>
25
 * @author Artem Yarygin <[email protected]>
26
 */
27
abstract class AdminInterface
28
{
29
	/**
30
	 * Список зарегистрированных интерфейсов
31
	 * @var string
32
	 */
33
	public static $registeredInterfaces = array();
34
35
	/**
36
	 * Описание интерфейса админки: списка табов и полей. Метод должен вернуть массив вида:
37
	 *
38
	 * ```
39
	 * array(
40
	 *    'TAB_1' => array(
41
	 *        'NAME' => Loc::getMessage('VENDOR_MODULE_ENTITY_TAB_1_NAME'),
42
	 *        'FIELDS' => array(
43
	 *            'FIELD_1' => array(
44
	 *                'WIDGET' => new StringWidget(),
45
	 *                'TITLE' => Loc::getMessage('VENDOR_MODULE_ENTITY_FIELD_1_TITLE'),
46
	 *                ...
47
	 *            ),
48
	 *            'FIELD_2' => array(
49
	 *                'WIDGET' => new NumberWidget(),
50
	 *                'TITLE' => Loc::getMessage('VENDOR_MODULE_ENTITY_FIELD_2_TITLE'),
51
	 *                ...
52
	 *            ),
53
	 *            ...
54
	 *        )
55
	 *    ),
56
	 *    'TAB_2' => array(
57
	 *        'NAME' => Loc::getMessage('VENDOR_MODULE_ENTITY_TAB_2_NAME'),
58
	 *        'FIELDS' => array(
59
	 *            'FIELD_3' => array(
60
	 *                'WIDGET' => new DateTimeWidget(),
61
	 *                'TITLE' => Loc::getMessage('VENDOR_MODULE_ENTITY_FIELD_3_TITLE'),
62
	 *                ...
63
	 *            ),
64
	 *            'FIELD_4' => array(
65
	 *                'WIDGET' => new UserWidget(),
66
	 *                'TITLE' => Loc::getMessage('VENDOR_MODULE_ENTITY_FIELD_4_TITLE'),
67
	 *                ...
68
	 *            ),
69
	 *            ...
70
	 *        )
71
	 *    ),
72
	 *  ...
73
	 * )
74
	 * ```
75
	 *
76
	 * Где TAB_1..2 - символьные коды табов, FIELD_1..4 - название столбцов в таблице сущности. TITLE для поля задавать
77
	 * не обязательно, в этому случае он будет запрашиваться из модели.
78
	 *
79
	 * Более подробную информацию о формате описания настроек виджетов см. в классе HelperWidget.
80
	 *
81
	 * @see DigitalWand\AdminHelper\Widget\HelperWidget
82
	 *
83
	 * @return array[]
84
	 */
85
	abstract public function fields();
86
87
	/**
88
	 * Список классов хелперов с настройками. Метод должен вернуть массив вида:
89
	 *
90
	 * ```
91
	 * array(
92
	 *    '\Vendor\Module\Entity\AdminInterface\EntityListHelper' => array(
93
	 *        'BUTTONS' => array(
94
	 *            'RETURN_TO_LIST' => array('TEXT' => Loc::getMessage('VENDOR_MODULE_ENTITY_RETURN_TO_LIST')),
95
	 *            'ADD_ELEMENT' => array('TEXT' => Loc::getMessage('VENDOR_MODULE_ENTITY_ADD_ELEMENT'),
96
	 *            ...
97
	 *        )
98
	 *    ),
99
	 *    '\Vendor\Module\Entity\AdminInterface\EntityEditHelper' => array(
100
	 *        'BUTTONS' => array(
101
	 *            'LIST_CREATE_NEW' => array('TEXT' => Loc::getMessage('VENDOR_MODULE_ENTITY_LIST_CREATE_NEW')),
102
	 *            'LIST_CREATE_NEW_SECTION' => array('TEXT' => Loc::getMessage('VENDOR_MODULE_ENTITY_LIST_CREATE_NEW_SECTION'),
103
	 *            ...
104
	 *        )
105
	 *    )
106
	 * )
107
	 * ```
108
	 *
109
	 * или
110
	 *
111
	 * ```
112
	 * array(
113
	 *    '\Vendor\Module\Entity\AdminInterface\EntityListHelper',
114
	 *    '\Vendor\Module\Entity\AdminInterface\EntityEditHelper'
115
	 * )
116
	 * ```
117
	 *
118
	 * Где:
119
	 * <ul>
120
	 * <li> `Vendor\Module\Entity\AdminInterface` - namespace до реализованных классов AdminHelper.
121
	 * <li> `BUTTONS` - ключ для массива с описанием элементов управления (подробнее в методе getButton()
122
	 *          класса AdminBaseHelper).
123
	 * <li> `LIST_CREATE_NEW`, `LIST_CREATE_NEW_SECTION`, `RETURN_TO_LIST`, `ADD_ELEMENT` - символьные код элементов
124
	 *          управления.
125
	 * <li> `EntityListHelper` и `EntityEditHelper` - реализованные классы хелперов.
126
	 *
127
	 * Оба формата могут сочетаться друг с другом.
128
	 *
129
	 * @see \DigitalWand\AdminHelper\Helper\AdminBaseHelper::getButton()
130
	 *
131
	 * @return string[]
132
	 */
133
	abstract public function helpers();
134
135
	/**
136
	 * Список зависимых админских интерфейсов, которые будут зарегистрированы при регистраци админского интерфейса,
137
	 * например, админские интерфейсы разделов.
138
	 *
139
	 * @return string[]
140
	 */
141
	public function dependencies()
142
	{
143
		return array();
144
	}
145
146
	/**
147
	 * Регистрируем поля, табы и кнопки.
148
	 */
149
	public function registerData()
150
	{
151
		$fieldsAndTabs = array('FIELDS' => array(), 'TABS' => array());
152
		$tabsWithFields = $this->fields();
153
154
		// приводим массив хелперов к формату класс => настройки
155
		$helpers = array();
156
157
		foreach ($this->helpers() as $key => $value) {
158
			if (is_array($value)) {
159
				$helpers[$key] = $value;
160
			}
161
			else {
162
				$helpers[$value] = array();
163
			}
164
		}
165
166
		$helperClasses = array_keys($helpers);
167
		/**
168
		 * @var \Bitrix\Main\Entity\DataManager
169
		 */
170
		$model = $helperClasses[0]::getModel();
0 ignored issues
show
The method getModel cannot be called on $helperClasses[0] (of type integer|string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
171
		foreach ($tabsWithFields as $tabCode => $tab) {
172
			$fieldsAndTabs['TABS'][$tabCode] = $tab['NAME'];
173
174
			foreach ($tab['FIELDS'] as $fieldCode => $field) {
175
				if (empty($field['TITLE']) && $model) {
176
					$field['TITLE'] = $model::getEntity()->getField($fieldCode)->getTitle();
177
				}
178
179
				$field['TAB'] = $tabCode;
180
				$fieldsAndTabs['FIELDS'][$fieldCode] = $field;
181
			}
182
		}
183
184
		AdminBaseHelper::setInterfaceSettings($fieldsAndTabs, $helpers, $helperClasses[0]::getModule());
0 ignored issues
show
The method getModule cannot be called on $helperClasses[0] (of type integer|string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
185
186
		foreach ($helperClasses as $helperClass) {
187
			/**
188
			 * @var AdminBaseHelper $helperClass
189
			 */
190
			$helperClass::setInterfaceClass(get_called_class());
191
		}
192
	}
193
194
	/**
195
	 * Регистрация интерфейса и его зависимостей.
196
	 */
197
	public static function register()
198
	{
199
		if (!in_array(get_called_class(), static::$registeredInterfaces)) {
200
			static::$registeredInterfaces[] = get_called_class();
201
202
			$adminInterface = new static();
203
			$adminInterface->registerData();
204
205
			foreach ($adminInterface->dependencies() as $adminInterfaceClass) {
206
				$adminInterfaceClass::register();
207
			}
208
		}
209
	}
210
}