. * --------------------------------------------------------------------- */ /** * @since 9.1 */ class APIClient extends CommonDBTM { const DOLOG_DISABLED = 0; const DOLOG_LOGS = 1; const DOLOG_HISTORICAL = 2; static $rightname = 'config'; // From CommonDBTM public $dohistory = true; static $undisclosedFields = [ 'app_token' ]; static function canCreate() { return Session::haveRight(static::$rightname, UPDATE); } static function canPurge() { return Session::haveRight(static::$rightname, UPDATE); } static function getTypeName($nb = 0) { return _n("API client", "API clients", $nb); } function defineTabs($options = []) { $ong = []; $this->addDefaultFormTab($ong) ->addStandardTab('Log', $ong, $options); return $ong; } function rawSearchOptions() { $tab = []; $tab[] = [ 'id' => 'common', 'name' => self::GetTypeName() ]; $tab[] = [ 'id' => '1', 'table' => $this->getTable(), 'field' => 'name', 'name' => __('Name'), 'datatype' => 'itemlink', 'autocomplete' => true, ]; $tab[] = [ 'id' => '2', 'table' => $this->getTable(), 'field' => 'id', 'name' => __('ID'), 'massiveaction' => false, 'datatype' => 'number' ]; $tab[] = [ 'id' => '3', 'table' => $this->getTable(), 'field' => 'is_active', 'name' => __('Active'), 'datatype' => 'bool' ]; $tab[] = [ 'id' => '4', 'table' => $this->getTable(), 'field' => 'dolog_method', 'name' => __('Log connections'), 'datatype' => 'specific' ]; $tab[] = [ 'id' => 'filter', 'name' => __('Filter access') ]; $tab[] = [ 'id' => '5', 'table' => $this->getTable(), 'field' => 'ipv4_range_start', 'name' => __('IPv4 address range')." - ".__("Start"), 'datatype' => 'specific' ]; $tab[] = [ 'id' => '6', 'table' => $this->getTable(), 'field' => 'ipv4_range_end', 'name' => __('IPv4 address range')." - ".__("End"), 'datatype' => 'specific' ]; $tab[] = [ 'id' => '7', 'table' => $this->getTable(), 'field' => 'ipv6', 'name' => __('IPv6 address'), 'datatype' => 'text', 'autocomplete' => true, ]; $tab[] = [ 'id' => '8', 'table' => $this->getTable(), 'field' => 'app_token', 'name' => __('Application token'), 'massiveaction' => false, 'datatype' => 'text', 'autocomplete' => true, ]; return $tab; } static function getSpecificValueToDisplay($field, $values, array $options = []) { switch ($field) { case 'dolog_method' : $methods = self::getLogMethod(); return $methods[$values[$field]]; case 'ipv4_range_start': case 'ipv4_range_end': if (empty($values[$field])) { return ''; } return long2ip((int)$values[$field]); } return parent::getSpecificValueToDisplay($field, $values, $options); } /** * Show form * * @param integer $ID Item ID * @param array $options Options * * @return void */ function showForm ($ID, $options = []) { $this->initForm($ID, $options); $this->showFormHeader($options); echo "