2019-04-11 10:05:28 +02:00
|
|
|
<?php
|
|
|
|
|
2019-04-16 16:06:56 +02:00
|
|
|
global $config;
|
|
|
|
|
2019-04-11 10:05:28 +02:00
|
|
|
if (!is_ajax()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once $config['homedir'].'/vendor/autoload.php';
|
|
|
|
|
|
|
|
use Models\VisualConsole\Container as VisualConsole;
|
|
|
|
|
|
|
|
$visualConsoleId = (int) get_parameter('visualConsoleId');
|
|
|
|
$getVisualConsole = (bool) get_parameter('getVisualConsole');
|
|
|
|
$getVisualConsoleItems = (bool) get_parameter('getVisualConsoleItems');
|
2019-06-18 10:13:56 +02:00
|
|
|
$updateVisualConsoleItem = (bool) get_parameter('updateVisualConsoleItem');
|
2019-07-08 17:51:01 +02:00
|
|
|
$getVisualConsoleItem = (bool) get_parameter('getVisualConsoleItem');
|
2019-04-11 10:05:28 +02:00
|
|
|
|
|
|
|
ob_clean();
|
|
|
|
|
2019-07-16 16:27:23 +02:00
|
|
|
// Retrieve the visual console.
|
|
|
|
$visualConsole = VisualConsole::fromDB(['id' => $visualConsoleId]);
|
|
|
|
$visualConsoleData = $visualConsole->toArray();
|
|
|
|
$vcGroupId = $visualConsoleData['groupId'];
|
|
|
|
|
|
|
|
// ACL.
|
|
|
|
$aclRead = check_acl($config['id_user'], $vcGroupId, 'VR');
|
|
|
|
$aclWrite = check_acl($config['id_user'], $vcGroupId, 'VW');
|
|
|
|
$aclManage = check_acl($config['id_user'], $vcGroupId, 'VM');
|
|
|
|
|
|
|
|
if (!$aclRead && !$aclWrite && !$aclManage) {
|
|
|
|
db_pandora_audit(
|
|
|
|
'ACL Violation',
|
|
|
|
'Trying to access visual console without group access'
|
|
|
|
);
|
|
|
|
http_response_code(403);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-11 10:05:28 +02:00
|
|
|
if ($getVisualConsole === true) {
|
2019-07-16 16:27:23 +02:00
|
|
|
echo $visualConsole;
|
|
|
|
return;
|
|
|
|
} else if ($getVisualConsoleItems === true) {
|
|
|
|
// Check groups can access user.
|
|
|
|
$aclUserGroups = [];
|
|
|
|
if (!users_can_manage_group_all('AR')) {
|
|
|
|
$aclUserGroups = array_keys(users_get_groups(false, 'AR'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$vcItems = VisualConsole::getItemsFromDB($visualConsoleId, $aclUserGroups);
|
|
|
|
echo '['.implode($vcItems, ',').']';
|
|
|
|
return;
|
|
|
|
} else if ($getVisualConsoleItem === true
|
|
|
|
|| $updateVisualConsoleItem === true
|
|
|
|
) {
|
|
|
|
$itemId = (int) get_parameter('visualConsoleItemId');
|
|
|
|
|
|
|
|
try {
|
|
|
|
$item = VisualConsole::getItemFromDB($itemId);
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
// Bad params.
|
|
|
|
http_response_code(409);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$itemData = $item->toArray();
|
|
|
|
$itemType = $itemData['type'];
|
|
|
|
$itemAclGroupId = $itemData['aclGroupId'];
|
2019-04-12 13:12:12 +02:00
|
|
|
|
|
|
|
// ACL.
|
2019-07-16 16:27:23 +02:00
|
|
|
$aclRead = check_acl($config['id_user'], $itemAclGroupId, 'VR');
|
|
|
|
$aclWrite = check_acl($config['id_user'], $itemAclGroupId, 'VW');
|
|
|
|
$aclManage = check_acl($config['id_user'], $itemAclGroupId, 'VM');
|
2019-04-12 13:12:12 +02:00
|
|
|
|
|
|
|
if (!$aclRead && !$aclWrite && !$aclManage) {
|
|
|
|
db_pandora_audit(
|
|
|
|
'ACL Violation',
|
|
|
|
'Trying to access visual console without group access'
|
|
|
|
);
|
2019-07-16 16:27:23 +02:00
|
|
|
http_response_code(403);
|
|
|
|
return;
|
2019-04-12 13:12:12 +02:00
|
|
|
}
|
|
|
|
|
2019-07-16 16:27:23 +02:00
|
|
|
// Check also the group Id for the group item.
|
|
|
|
if ($itemType === GROUP_ITEM) {
|
|
|
|
$itemGroupId = $itemData['aclGroupId'];
|
|
|
|
// ACL.
|
|
|
|
$aclRead = check_acl($config['id_user'], $itemGroupId, 'VR');
|
|
|
|
$aclWrite = check_acl($config['id_user'], $itemGroupId, 'VW');
|
|
|
|
$aclManage = check_acl($config['id_user'], $itemGroupId, 'VM');
|
|
|
|
|
|
|
|
if (!$aclRead && !$aclWrite && !$aclManage) {
|
|
|
|
db_pandora_audit(
|
|
|
|
'ACL Violation',
|
|
|
|
'Trying to access visual console without group access'
|
|
|
|
);
|
|
|
|
http_response_code(403);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-07-08 17:51:01 +02:00
|
|
|
|
2019-07-16 16:27:23 +02:00
|
|
|
if ($getVisualConsoleItem === true) {
|
|
|
|
echo $item;
|
|
|
|
return;
|
|
|
|
} else if ($updateVisualConsoleItem === true) {
|
|
|
|
$data = get_parameter('data');
|
|
|
|
$result = $item->save($data);
|
2019-07-08 17:51:01 +02:00
|
|
|
|
2019-07-16 16:27:23 +02:00
|
|
|
echo $item;
|
|
|
|
return;
|
|
|
|
}
|
2019-04-11 10:05:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exit;
|