protected function doAction() { foreach (CJs::decodeJson($this->getInput('grid')) as $col => $column) { foreach ($column as $row => $widgetName) { $widgetName = str_replace('_widget', '', $widgetName); CProfile::update('web.dashboard.widget.' . $widgetName . '.col', $col, PROFILE_TYPE_INT); CProfile::update('web.dashboard.widget.' . $widgetName . '.row', $row, PROFILE_TYPE_INT); } } $data = ['main_block' => '']; $response = new CControllerResponseData($data); $this->setResponse($response); }
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ require_once dirname(__FILE__) . '/include/func.inc.php'; require_once dirname(__FILE__) . '/include/classes/class.chttp_request.php'; $allowed_content = array('application/json-rpc' => 'json-rpc', 'application/json' => 'json-rpc', 'application/jsonrequest' => 'json-rpc'); $http_request = new CHTTP_request(); $content_type = $http_request->header('Content-Type'); $content_type = explode(';', $content_type); $content_type = $content_type[0]; if (!isset($allowed_content[$content_type])) { header('HTTP/1.0 412 Precondition Failed'); exit; } require_once dirname(__FILE__) . '/include/classes/core/Z.php'; header('Content-Type: application/json'); $data = $http_request->body(); try { Z::getInstance()->run(ZBase::EXEC_MODE_API); $jsonRpc = new CJSONrpc($data); echo $jsonRpc->execute(); } catch (Exception $e) { // decode input json request to get request's id $jsonData = CJs::decodeJson($data); $response = array('jsonrpc' => '2.0', 'error' => array('code' => 1, 'message' => $e->getMessage()), 'id' => isset($jsonData['id']) ? $jsonData['id'] : null); echo CJs::encodeJson($response); }
$dashconf['severity'] = zbx_empty($severity) ? null : explode(';', $severity); $dashconf['severity'] = zbx_toHash($dashconf['severity']); $config = select_config(); $dashconf['extAck'] = $config['event_ack_enable'] ? CProfile::get('web.dashconf.events.extAck', 0) : 0; } /* * Actions */ if (isset($_REQUEST['favobj'])) { $_REQUEST['pmasterid'] = get_request('pmasterid', 'mainpage'); if ($_REQUEST['favobj'] == 'hat') { if ($_REQUEST['favaction'] == 'flop') { $widgetName = substr($_REQUEST['favref'], 4); CProfile::update('web.dashboard.widget.' . $widgetName . '.state', $_REQUEST['favstate'], PROFILE_TYPE_INT); } elseif (getRequest('favaction') == 'sort') { $favdata = CJs::decodeJson(getRequest('favdata')); foreach ($favdata as $col => $column) { foreach ($column as $row => $widgetName) { $widgetName = substr($widgetName, 4, -7); CProfile::update('web.dashboard.widget.' . $widgetName . '.col', $col, PROFILE_TYPE_INT); CProfile::update('web.dashboard.widget.' . $widgetName . '.row', $row, PROFILE_TYPE_INT); } } } elseif ($_REQUEST['favaction'] == 'refresh') { switch ($_REQUEST['favref']) { case 'hat_syssum': $syssum = make_system_status($dashconf); $syssum->show(); break; case 'hat_hoststat': $hoststat = make_hoststat_summary($dashconf);
/** * Executes a given JSON request and returns the result. Returns false if an error has occurred. * * @param array $params * * @return mixed the output of the script if it has been executed successfully or false otherwise */ protected function request(array $params) { // connect to the server if (!$this->connect()) { return false; } // set timeout stream_set_timeout($this->socket, $this->timeout); // send the command if (fwrite($this->socket, CJs::encodeJson($params)) === false) { $this->error = _s('Cannot send command, check connection with Zabbix server "%1$s".', $this->host); return false; } // read the response $readBytesLimit = $this->totalBytesLimit && $this->totalBytesLimit < $this->readBytesLimit ? $this->totalBytesLimit : $this->readBytesLimit; $response = ''; $now = time(); $i = 0; while (!feof($this->socket)) { $i++; if (time() - $now >= $this->timeout) { $this->error = _s('Connection timeout of %1$s seconds exceeded when connecting to Zabbix server "%2$s".', $this->timeout, $this->host); return false; } elseif ($this->totalBytesLimit && $i * $readBytesLimit >= $this->totalBytesLimit) { $this->error = _s('Size of the response received from Zabbix server "%1$s" exceeds the allowed size of %2$s bytes. This value can be increased in the ZBX_SOCKET_BYTES_LIMIT constant in include/defines.inc.php.', $this->host, $this->totalBytesLimit); return false; } if (($out = fread($this->socket, $readBytesLimit)) !== false) { $response .= $out; } else { $this->error = _s('Cannot read the response, check connection with the Zabbix server "%1$s".', $this->host); return false; } } fclose($this->socket); // check if the response is empty if (!strlen($response)) { $this->error = _s('Empty response received from Zabbix server "%1$s".', $this->host); return false; } $response = CJs::decodeJson($response); if (!$response || !$this->validateResponse($response)) { $this->error = _s('Incorrect response received from Zabbix server "%1$s".', $this->host); return false; } // request executed successfully if ($response['response'] == self::RESPONSE_SUCCESS) { return $response['data']; } else { $this->error = $response['info']; return false; } }
private function validateField($field, $rules) { if (false === ($rules = $this->validationRuleParser->parse($rules))) { $this->addError(true, $this->validationRuleParser->getError()); return false; } $fatal = array_key_exists('fatal', $rules); foreach ($rules as $rule => $params) { switch ($rule) { /* * 'fatal' => true */ case 'fatal': // nothing to do break; /* * 'not_empty' => true */ /* * 'not_empty' => true */ case 'not_empty': if (array_key_exists($field, $this->input) && $this->input[$field] === '') { $this->addError($fatal, _s('Incorrect value for field "%1$s": %2$s.', $field, _('cannot be empty'))); return false; } break; case 'json': if (array_key_exists($field, $this->input)) { if (!is_string($this->input[$field]) || !CJs::decodeJson($this->input[$field])) { $this->addError($fatal, _s('Incorrect value "%1$s" for "%2$s" field.', $this->input[$field], $field)); return false; } } break; /* * 'in' => array(<values) */ /* * 'in' => array(<values) */ case 'in': if (array_key_exists($field, $this->input)) { if (!is_string($this->input[$field]) || !in_array($this->input[$field], $params)) { $this->addError($fatal, _s('Incorrect value "%1$s" for "%2$s" field.', $this->input[$field], $field)); return false; } } break; case 'int32': if (array_key_exists($field, $this->input)) { if (!is_string($this->input[$field]) || !$this->is_int32($this->input[$field])) { $this->addError($fatal, _s('Incorrect value "%1$s" for "%2$s" field.', $this->input[$field], $field)); return false; } } break; case 'id': if (array_key_exists($field, $this->input)) { if (!is_string($this->input[$field]) || !$this->is_id($this->input[$field])) { $this->addError($fatal, _s('Incorrect value "%1$s" for "%2$s" field.', $this->input[$field], $field)); return false; } } break; /* * 'array_id' => true */ /* * 'array_id' => true */ case 'array_id': if (array_key_exists($field, $this->input)) { if (!is_array($this->input[$field]) || !$this->is_array_id($this->input[$field])) { $this->addError($fatal, _s('Incorrect value "%1$s" for "%2$s" field.', $this->input[$field], $field)); return false; } } break; /* * 'array_db' => array( * 'table' => <table_name>, * 'field' => <field_name> * ) */ /* * 'array_db' => array( * 'table' => <table_name>, * 'field' => <field_name> * ) */ case 'array': if (array_key_exists($field, $this->input) && !is_array($this->input[$field])) { $this->addError($fatal, _s('Incorrect value "%1$s" for "%2$s" field.', $this->input[$field], $field)); return false; } break; /* * 'array_db' => array( * 'table' => <table_name>, * 'field' => <field_name> * ) */ /* * 'array_db' => array( * 'table' => <table_name>, * 'field' => <field_name> * ) */ case 'array_db': if (array_key_exists($field, $this->input)) { if (!is_array($this->input[$field]) || !$this->is_array_db($this->input[$field], $params['table'], $params['field'])) { $this->addError($fatal, _s('Incorrect value "%1$s" for "%2$s" field.', $this->input[$field], $field)); return false; } } break; /* * 'db' => array( * 'table' => <table_name>, * 'field' => <field_name> * ) */ /* * 'db' => array( * 'table' => <table_name>, * 'field' => <field_name> * ) */ case 'db': if (array_key_exists($field, $this->input)) { if (!$this->is_db($this->input[$field], $params['table'], $params['field'])) { $this->addError($fatal, _s('Incorrect value "%1$s" for "%2$s" field.', $this->input[$field], $field)); return false; } } break; /* * 'required' => true */ /* * 'required' => true */ case 'required': if (!array_key_exists($field, $this->input)) { $this->addError($fatal, _s('Field "%1$s" is mandatory.', $field)); return false; } break; /* * 'string' => true */ /* * 'string' => true */ case 'string': if (array_key_exists($field, $this->input) && !is_string($this->input[$field])) { $this->addError($fatal, _s('Incorrect value for field "%1$s": %2$s.', $field, _('a character string is expected'))); return false; } break; default: // the message can be not translated because it is an internal error $this->addError($fatal, 'Invalid validation rule "' . $rule . '".'); return false; } } return true; }
if (in_array($widgetName, $widgets)) { // refresh rate if (hasRequest('widgetRefreshRate')) { $widgetRefreshRate = getRequest('widgetRefreshRate'); CProfile::update('web.dashboard.widget.' . $widgetName . '.rf_rate', $widgetRefreshRate, PROFILE_TYPE_INT); echo 'PMasters["dashboard"].dolls["' . $widgetName . '"].frequency(' . CJs::encodeJson($widgetRefreshRate) . ');' . "\n" . 'PMasters["dashboard"].dolls["' . $widgetName . '"].restartDoll();'; } // widget state if (hasRequest('widgetState')) { CProfile::update('web.dashboard.widget.' . $widgetName . '.state', getRequest('widgetState'), PROFILE_TYPE_INT); } } } // sort if (hasRequest('widgetSort')) { foreach (CJs::decodeJson(getRequest('widgetSort')) as $col => $column) { foreach ($column as $row => $widgetName) { $widgetName = str_replace('_widget', '', $widgetName); CProfile::update('web.dashboard.widget.' . $widgetName . '.col', $col, PROFILE_TYPE_INT); CProfile::update('web.dashboard.widget.' . $widgetName . '.row', $row, PROFILE_TYPE_INT); } } } // favourites if (hasRequest('favobj') && hasRequest('favaction')) { $favouriteObject = getRequest('favobj'); $favouriteAction = getRequest('favaction'); $favouriteId = getRequest('favid'); $result = true; DBstart(); switch ($favouriteObject) {