AJAXMethods);
}
/**
* Generates a JSON error.
*
* @param string $msg Error message.
*
* @return void
*/
public function error($msg)
{
echo json_encode(
['error' => $msg]
);
}
/**
* Minor function to dump json message as ajax response.
*
* @param string $type Type: result || error.
* @param string $msg Message.
* @param boolean $delete Deletion messages.
*
* @return void
*/
private function ajaxMsg($type, $msg, $delete=false)
{
if ($type === 'error') {
$msg_title = ($delete === true) ? 'Failed while removing' : 'Failed while saving';
} else {
$msg_title = ($delete === true) ? 'Successfully deleted' : 'Successfully saved into keystore';
}
echo json_encode(
[ $type => __($msg_title).':
'.$msg ]
);
exit;
}
/**
* Initializes object and validates user access.
*
* @param string $ajax_controller Path of ajaxController, is the 'page'
* variable sent in ajax calls.
*
* @return object
*/
public function __construct($ajax_controller)
{
global $config;
// Check access.
check_login();
if ((bool) check_acl($config['id_user'], 0, 'AR') === false) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access agent deploy wizard'
);
if (is_ajax()) {
echo json_encode(['error' => 'noaccess']);
} else {
include 'general/noaccess.php';
}
exit;
}
$this->ajaxController = $ajax_controller;
return $this;
}
/**
* Prints inputs for modal "Deploy agents".
*
* @return void
*/
public function loadModal()
{
ob_start();
echo '