class CControllerScriptCreate extends CController {
protected function checkInput() {
'name' => 'required|db scripts.name|not_empty',
'scope' => 'db scripts.scope| in '.implode(',', [ZBX_SCRIPT_SCOPE_ACTION, ZBX_SCRIPT_SCOPE_HOST, ZBX_SCRIPT_SCOPE_EVENT]),
'type' => 'required|db scripts.type|in '.implode(',', [ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT, ZBX_SCRIPT_TYPE_IPMI, ZBX_SCRIPT_TYPE_SSH, ZBX_SCRIPT_TYPE_TELNET, ZBX_SCRIPT_TYPE_WEBHOOK]),
'execute_on' => 'db scripts.execute_on|in '.implode(',', [ZBX_SCRIPT_EXECUTE_ON_AGENT, ZBX_SCRIPT_EXECUTE_ON_SERVER, ZBX_SCRIPT_EXECUTE_ON_PROXY]),
'menu_path' => 'db scripts.menu_path',
'authtype' => 'db scripts.authtype|in '.implode(',', [ITEM_AUTHTYPE_PASSWORD, ITEM_AUTHTYPE_PUBLICKEY]),
'username' => 'db scripts.username',
'password' => 'db scripts.password',
'publickey' => 'db scripts.publickey',
'privatekey' => 'db scripts.privatekey',
'passphrase' => 'db scripts.password',
'port' => 'db scripts.port',
'command' => 'db scripts.command|flags '.P_CRLF,
'commandipmi' => 'db scripts.command|flags '.P_CRLF,
'script' => 'db scripts.command|flags '.P_CRLF,
'timeout' => 'db scripts.timeout|time_unit '.implode(':', [1, SEC_PER_MIN]),
'description' => 'db scripts.description',
'host_access' => 'db scripts.host_access|in '.implode(',', [PERM_READ, PERM_READ_WRITE]),
'groupid' => 'db scripts.groupid',
'usrgrpid' => 'db scripts.usrgrpid',
'confirmation' => 'db scripts.confirmation|not_empty',
'enable_confirmation' => 'in 1',
'form_refresh' => 'int32'
$ret = $this->validateInput($fields);
switch ($this->GetValidationError()) {
case self::VALIDATION_ERROR:
$response = new CControllerResponseRedirect('zabbix.php?action=script.edit');
$response->setFormData($this->getInputAll());
CMessageHelper::setErrorTitle(_('Cannot add script'));
$this->setResponse($response);
case self::VALIDATION_FATAL_ERROR:
$this->setResponse(new CControllerResponseFatal());
protected function checkPermissions() {
return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_SCRIPTS);
protected function doAction() {
$this->getInputs($script, ['name', 'description', 'groupid']);
$script['scope'] = $this->getInput('scope', ZBX_SCRIPT_SCOPE_ACTION);
$script['type'] = $this->getInput('type', ZBX_SCRIPT_TYPE_WEBHOOK);
if ($script['scope'] != ZBX_SCRIPT_SCOPE_ACTION) {
$script['menu_path'] = trimPath($this->getInput('menu_path', ''));
$script['host_access'] = $this->getInput('host_access', PERM_READ);
$script['confirmation'] = $this->getInput('confirmation', '');
$script['usrgrpid'] = $this->getInput('usrgrpid', 0);
switch ($script['type']) {