grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Config class **/ class Config extends CommonDBTM { // From CommonGLPI protected $displaylist = false; // From CommonDBTM public $auto_message_on_action = false; public $showdebug = true; static $rightname = 'config'; static function getTypeName($nb=0) { return __('Setup'); } /** * @see CommonGLPI::getMenuContent() * * @since version 0.85 **/ static function getMenuContent() { global $CFG_GLPI; $menu = array(); if (static::canView()) { $menu['title'] = _x('setup', 'General'); $menu['page'] = '/front/config.form.php'; $menu['options']['apiclient']['title'] = APIClient::getTypeName(Session::getPluralNumber()); $menu['options']['apiclient']['page'] = '/front/config.form.php?forcetab=Config$8'; $menu['options']['apiclient']['links']['search'] = '/front/config.form.php?forcetab=Config$8'; $menu['options']['apiclient']['links']['add'] = '/front/apiclient.form.php'; } if (count($menu)) { return $menu; } return false; } static function canCreate() { return false; } function defineTabs($options=array()) { $ong = array(); $this->addStandardTab(__CLASS__, $ong, $options); return $ong; } /** * Prepare input datas for updating the item * * @see CommonDBTM::prepareInputForUpdate() * * @param $input array of datas used to update the item * * @return the modified $input array **/ function prepareInputForUpdate($input) { global $CFG_GLPI; // Update only an item if (isset($input['context'])) { return $input; } // Process configuration for plugins if (!empty($input['config_context'])) { $config_context = $input['config_context']; unset($input['id']); unset($input['_glpi_csrf_token']); unset($input['update']); unset($input['config_context']); if ((!empty($input['config_class'])) && (class_exists($input['config_class'])) && (method_exists ($input['config_class'], 'configUpdate'))) { $config_method = $input['config_class'].'::configUpdate'; unset($input['config_class']); $input = call_user_func($config_method, $input); } $this->setConfigurationValues($config_context, $input); return false; } if (isset($input['allow_search_view']) && !$input['allow_search_view']) { // Global search need "view" $input['allow_search_global'] = 0; } if (isset($input["smtp_passwd"])) { if (empty($input["smtp_passwd"])) { unset($input["smtp_passwd"]); } else { $input["smtp_passwd"] = Toolbox::encrypt(stripslashes($input["smtp_passwd"]), GLPIKEY); } } if (isset($input["_blank_smtp_passwd"]) && $input["_blank_smtp_passwd"]) { $input['smtp_passwd'] = ''; } if (isset($input["proxy_passwd"])) { if (empty($input["proxy_passwd"])) { unset($input["proxy_passwd"]); } else { $input["proxy_passwd"] = Toolbox::encrypt(stripslashes($input["proxy_passwd"]), GLPIKEY); } } if (isset($input["_blank_proxy_passwd"]) && $input["_blank_proxy_passwd"]) { $input['proxy_passwd'] = ''; } // Manage DB Slave process if (isset($input['_dbslave_status'])) { $already_active = DBConnection::isDBSlaveActive(); if ($input['_dbslave_status']) { DBConnection::changeCronTaskStatus(true); if (!$already_active) { // Activate Slave from the "system" tab DBConnection::createDBSlaveConfig(); } else if (isset($input["_dbreplicate_dbhost"])) { // Change parameter from the "replicate" tab DBConnection::saveDBSlaveConf($input["_dbreplicate_dbhost"], $input["_dbreplicate_dbuser"], $input["_dbreplicate_dbpassword"], $input["_dbreplicate_dbdefault"]); } } if (!$input['_dbslave_status'] && $already_active) { DBConnection::deleteDBSlaveConfig(); DBConnection::changeCronTaskStatus(false); } } // Matrix for Impact / Urgence / Priority if (isset($input['_matrix'])) { $tab = array(); for ($urgency=1 ; $urgency<=5 ; $urgency++) { for ($impact=1 ; $impact<=5 ; $impact++) { $priority = $input["_matrix_${urgency}_${impact}"]; $tab[$urgency][$impact] = $priority; } } $input['priority_matrix'] = exportArrayToDB($tab); $input['urgency_mask'] = 0; $input['impact_mask'] = 0; for ($i=1 ; $i<=5 ; $i++) { if ($input["_urgency_${i}"]) { $input['urgency_mask'] += (1<<$i); } if ($input["_impact_${i}"]) { $input['impact_mask'] += (1<<$i); } } } // lock mechanism update if (isset( $input['lock_use_lock_item'])) { $input['lock_item_list'] = exportArrayToDB((isset($input['lock_item_list']) ? $input['lock_item_list'] : array())); } // Beware : with new management system, we must update each value unset($input['id']); unset($input['_glpi_csrf_token']); unset($input['update']); // Add skipMaintenance if maintenance mode update if (isset($input['maintenance_mode']) && $input['maintenance_mode']) { $_SESSION['glpiskipMaintenance'] = 1; $url = $CFG_GLPI['root_doc']."/index.php?skipMaintenance=1"; Session::addMessageAfterRedirect(sprintf(__('Maintenance mode activated. Backdoor using: %s'), "$url"), false, WARNING); } $this->setConfigurationValues('core', $input); return false; } static public function unsetUndisclosedFields(&$fields) { if (isset($fields['context']) && isset($fields['name'])) { if ($fields['context'] == 'core' && in_array($fields['name'], array('proxy_passwd', 'smtp_passwd'))) { unset($fields['value']); } } } /** * Print the config form for display * * @return Nothing (display) **/ function showFormDisplay() { global $CFG_GLPI; if (!self::canView()) { return false; } $canedit = Session::haveRight(self::$rightname, UPDATE); if ($canedit) { echo "
"; } echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; // echo ""; // echo ""; // echo ""; // echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if ($canedit) { echo ""; echo ""; } echo "
" . __('General setup') . "
" . __('URL of the application') . ""; echo "
" . __('Text in the login box') . ""; echo ""; echo "
" . __('Allow FAQ anonymous access') . ""; Dropdown::showYesNo("use_public_faq", $CFG_GLPI["use_public_faq"]); echo "" . __('Simplified interface help link') . "
" . __('Default search results limit (page)').""; Dropdown::showNumber("list_limit_max", array('value' => $CFG_GLPI["list_limit_max"], 'min' => 5, 'max' => 200, 'step' => 5)); echo "" . __('Standard interface help link') . "
" . __('Default characters limit (summary text boxes)') . ""; Dropdown::showNumber('cut', array('value' => $CFG_GLPI["cut"], 'min' => 50, 'max' => 500, 'step' => 50)); echo "" . __('Default url length limit') . ""; Dropdown::showNumber('url_maxlength', array('value' => $CFG_GLPI["url_maxlength"], 'min' => 20, 'max' => 80, 'step' => 5)); echo "
" .__('Default decimals limit') . ""; Dropdown::showNumber("decimal_number", array('value' => $CFG_GLPI["decimal_number"], 'min' => 1, 'max' => 4)); echo "" . __('Default chart format').""; Dropdown::showFromArray("default_graphtype", array('png' => 'PNG', 'svg' => 'SVG'), array('value' => $CFG_GLPI["default_graphtype"])); echo "
" . __("Translation of dropdowns") . ""; Dropdown::showYesNo("translate_dropdowns", $CFG_GLPI["translate_dropdowns"]); echo "" . __("Knowledge base translation") . ""; Dropdown::showYesNo("translate_kb", $CFG_GLPI["translate_kb"]); echo "
".__('Dynamic display'). "
". __('Page size for dropdown (paging using scroll)'). ""; Dropdown::showNumber('dropdown_max', array('value' => $CFG_GLPI["dropdown_max"], 'min' => 1, 'max' => 200)); echo "" . __('Autocompletion of text fields') . ""; Dropdown::showYesNo("use_ajax_autocompletion", $CFG_GLPI["use_ajax_autocompletion"]); echo "
". __("Don't show search engine in dropdowns if the number of items is less than"). ""; Dropdown::showNumber('ajax_limit_count', array('value' => $CFG_GLPI["ajax_limit_count"], 'min' => 1, 'max' => 200, 'step' => 1, 'toadd' => array(0 => __('Never')))); // echo "".__('Buffer time for dynamic search in dropdowns').""; // Dropdown::showNumber('ajax_buffertime_load', // array('value' => $CFG_GLPI["ajax_buffertime_load"], // 'min' => 100, // 'max' => 5000, // 'step' => 100, // 'unit' => 'millisecond')); echo "
" . __('Autocompletion of text fields') . ""; // Dropdown::showYesNo("use_ajax_autocompletion", $CFG_GLPI["use_ajax_autocompletion"]); // echo "". __('Character to force the full display of dropdowns (wildcard)').""; // echo "
".__('Search engine')."
" . __('Items seen') . ""; $values = array(0 => __('No'), 1 => sprintf(__('%1$s (%2$s)'), __('Yes'), __('last criterion')), 2 => sprintf(__('%1$s (%2$s)'), __('Yes'), __('default criterion'))); Dropdown::showFromArray('allow_search_view', $values, array('value' => $CFG_GLPI['allow_search_view'])); echo "". __('Global search').""; if ($CFG_GLPI['allow_search_view']) { Dropdown::showYesNo('allow_search_global', $CFG_GLPI['allow_search_global']); } else { echo Dropdown::getYesNo(0); } echo "
" . __('All') . ""; $values = array(0 => __('No'), 1 => sprintf(__('%1$s (%2$s)'), __('Yes'), __('last criterion'))); Dropdown::showFromArray('allow_search_all', $values, array('value' => $CFG_GLPI['allow_search_all'])); echo "
".__('Item locks')."
" . __('Use locks') . ""; Dropdown::showYesNo("lock_use_lock_item", $CFG_GLPI["lock_use_lock_item"]); echo "". __('Profile to be used when locking items').""; if ($CFG_GLPI["lock_use_lock_item"]) { Profile::dropdown(array('name' => 'lock_lockprofile_id', 'display_emptychoice' => true, 'value' => $CFG_GLPI['lock_lockprofile_id'])); } else { echo dropdown::getDropdownName( Profile::getTable(), $CFG_GLPI['lock_lockprofile_id']) ; } echo "
" . __('List of items to lock') . ""; Dropdown::showFromArray('lock_item_list', ObjectLock::getLockableObjects(), array('values' => $CFG_GLPI['lock_item_list'], 'width' => '100%', 'multiple' => true, 'readonly' => !$CFG_GLPI["lock_use_lock_item"])); echo "
"; echo ""; echo "
"; Html::closeForm(); } /** * Print the config form for restrictions * * @return Nothing (display) **/ function showFormInventory() { global $DB, $CFG_GLPI; if (!self::canView()) { return false; } $canedit = Config::canUpdate(); if ($canedit) { echo ""; } echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
" . __('Assets') . "
". __('Enable the financial and administrative information by default').""; Dropdown::ShowYesNo('auto_create_infocoms', $CFG_GLPI["auto_create_infocoms"]); echo " " . __('Restrict monitor management') . ""; $this->dropdownGlobalManagement ("monitors_management_restrict", $CFG_GLPI["monitors_management_restrict"]); echo "
" . __('Software category deleted by the dictionary rules') . ""; SoftwareCategory::dropdown(array('value' => $CFG_GLPI["softwarecategories_id_ondelete"], 'name' => "softwarecategories_id_ondelete")); echo " " . __('Restrict device management') . ""; $this->dropdownGlobalManagement ("peripherals_management_restrict", $CFG_GLPI["peripherals_management_restrict"]); echo "
" .__('Beginning of fiscal year') . ""; Html::showDateField("date_tax", array('value' => $CFG_GLPI["date_tax"], 'maybeempty' => false, 'canedit' => true, 'min' => '', 'max' => '', 'showyear' => false)); echo " " . __('Restrict phone management') . ""; $this->dropdownGlobalManagement ("phones_management_restrict", $CFG_GLPI["phones_management_restrict"]); echo "
" . __('Automatic fields (marked by *)') . ""; $tab = array(0 => __('Global'), 1 => __('By entity')); Dropdown::showFromArray('use_autoname_by_entity', $tab, array('value' => $CFG_GLPI["use_autoname_by_entity"])); echo " " . __('Restrict printer management') . ""; $this->dropdownGlobalManagement("printers_management_restrict", $CFG_GLPI["printers_management_restrict"]); echo "
"; if (Session::haveRightsOr("transfer", array(CREATE, UPDATE)) && Session::isMultiEntitiesMode()) { echo "
"; echo ""; echo ""; echo ""; echo "
" . __('Automatic transfer of computers') . "
" . __('Template for the automatic transfer of computers in another entity') . ""; Transfer::dropdown(array('value' => $CFG_GLPI["transfers_id_auto"], 'name' => "transfers_id_auto", 'emptylabel' => __('No automatic transfer'))); echo "
"; } echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $fields = array("contact", "user", "group", "location"); echo ""; echo ""; $values[0] = __('Do not copy'); $values[1] = __('Copy'); foreach ($fields as $field) { echo ""; } echo ""; echo ""; echo ""; $values[0] = __('Do not delete'); $values[1] = __('Clear'); foreach ($fields as $field) { echo ""; } echo ""; if ($canedit) { echo ""; echo ""; } echo "
".__('Automatically update of the elements related to the computers'); echo "".__('Unit management')."
 " . __('Alternate username') . "" . __('User') . "" . __('Group') . "" . __('Location') . "" . __('Status') . "
" . __('When connecting or updating') . ""; $fieldname = "is_".$field."_autoupdate"; Dropdown::showFromArray($fieldname, $values, array('value' => $CFG_GLPI[$fieldname])); echo ""; State::dropdownBehaviour("state_autoupdate_mode", __('Copy computer status'), $CFG_GLPI["state_autoupdate_mode"]); echo "
" . __('When disconnecting') . ""; $fieldname = "is_".$field."_autoclean"; Dropdown::showFromArray($fieldname, $values, array('value' => $CFG_GLPI[$fieldname])); echo ""; State::dropdownBehaviour("state_autoclean_mode", __('Clear status'), $CFG_GLPI["state_autoclean_mode"]); echo "
"; echo ""; echo "
"; Html::closeForm(); } /** * Print the config form for restrictions * * @return Nothing (display) **/ function showFormAuthentication() { global $DB, $CFG_GLPI; if (!Config::canUpdate()) { return false; } echo ""; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
" . __('Authentication') . "
". __('Automatically add users from an external authentication source'). ""; Dropdown::showYesNo("is_users_auto_add", $CFG_GLPI["is_users_auto_add"]); echo "". __('Add a user without accreditation from a LDAP directory'). ""; Dropdown::showYesNo("use_noright_users_add", $CFG_GLPI["use_noright_users_add"]); echo "
" . __('Action when a user is deleted from the LDAP directory') . ""; AuthLDap::dropdownUserDeletedActions($CFG_GLPI["user_deleted_ldap"]); echo " " . __('GLPI server time zone') . ""; Dropdown::showGMT("time_offset", $CFG_GLPI["time_offset"]); echo "
"; echo ""; echo "
"; Html::closeForm(); } /** * Print the config form for slave DB * * @return Nothing (display) **/ function showFormDBSlave() { global $DB, $CFG_GLPI, $DBslave; if (!Config::canUpdate()) { return false; } echo ""; echo "
"; echo ""; echo ""; $active = DBConnection::isDBSlaveActive(); echo ""; $DBslave = DBConnection::getDBSlaveConf(); if (is_array($DBslave->dbhost)) { $host = implode(' ', $DBslave->dbhost); } else { $host = $DBslave->dbhost; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if ($DBslave->connected && !$DB->isSlave()) { echo ""; } echo ""; echo "
" . _n('SQL replica', 'SQL replicas', Session::getPluralNumber()) . "
" . __('SQL server (MariaDB or MySQL)') . "" . __('Database') . ""; echo "
" . __('SQL user') . "" . __('SQL password') . ""; echo "
" . __('Use the slave for the search engine') . ""; $values = array(0 => __('Never'), 1 => __('If synced (all changes)'), 2 => __('If synced (current user changes)'), 3 => __('If synced or read-only account'), 4 => __('Always')); Dropdown::showFromArray('use_slave_for_search', $values, array('value' => $CFG_GLPI["use_slave_for_search"])); echo " 
"; DBConnection::showAllReplicateDelay(); echo "
"; echo ""; echo "
"; Html::closeForm(); } /** * Print the config form for External API * * @since 9.1 * @return Nothing (display) **/ function showFormAPI() { global $DB, $CFG_GLPI; if (!self::canView()) { return false; } echo "
"; $canedit = Config::canUpdate(); if ($canedit) { echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if ($CFG_GLPI["enable_api"]) { echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
" . __('API') . "
" . __('URL of the API') . "
" . __("Enable Rest API") . ""; Dropdown::showYesNo("enable_api", $CFG_GLPI["enable_api"]); echo ""; $inline_doc_api = trim($CFG_GLPI['url_base_api'], '/')."/"; echo "".__("API inline Documentation").""; echo "
" . __('Authentication') . "
"; echo __("Enable login with credentials")." "; Html::showToolTip(__("Allow to login to api and get a session token with user credentials")); echo ""; Dropdown::showYesNo("enable_api_login_credentials", $CFG_GLPI["enable_api_login_credentials"]); echo ""; echo __("Enable login with external token")." "; Html::showToolTip(__("Allow to login to api and get a session token with user external token. See Remote access key in user Settings tab ")); echo ""; Dropdown::showYesNo("enable_api_login_external_token", $CFG_GLPI["enable_api_login_external_token"]); echo "
"; echo ""; echo "


"; echo "
"; Html::closeForm(); echo ""; echo ""; echo "
"; echo "
"; $buttons["apiclient.form.php"] = __('Add API client'); $title = ""; Html::displayTitle("", self::getTypeName(Session::getPluralNumber()), "", $buttons); Search::show("APIClient"); echo "
"; } /** * Print the config form for connections * * @return Nothing (display) **/ function showFormHelpdesk() { global $DB, $CFG_GLPI; if (!self::canView()) { return false; } $canedit = Config::canUpdate(); if ($canedit) { echo ""; } echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
" . __('Assistance') . "
" . __('Step for the hours (minutes)') . ""; Dropdown::showNumber('time_step', array('value' => $CFG_GLPI["time_step"], 'min' => 30, 'max' => 60, 'step' => 30, 'toadd' => array(1 => 1, 5 => 5, 10 => 10, 15 => 15, 20 => 20))); echo "" .__('Limit of the schedules for planning') . ""; Dropdown::showHours('planning_begin', array('value' => $CFG_GLPI["planning_begin"])); echo " -> "; Dropdown::showHours('planning_end', array('value' => $CFG_GLPI["planning_end"])); echo "
".__('Default file size limit imported by the mails receiver').""; MailCollector::showMaxFilesize('default_mailcollector_filesize_max', $CFG_GLPI["default_mailcollector_filesize_max"]); echo "" . __('Use rich text for helpdesk') . ""; $id = 'alert'.mt_rand(); $param['on_change'] = '$("#'.$id.'").html(""); if ($(this).val() == 0) { $("#'.$id.'").html("
'.__('You will lose the formatting of your data').'"); }'; Dropdown::showYesNo("use_rich_text", $CFG_GLPI["use_rich_text"], -1, $param); echo ""; echo "
" . __('Default heading when adding a document to a ticket') . ""; DocumentCategory::dropdown(array('value' => $CFG_GLPI["documentcategories_id_forticket"], 'name' => "documentcategories_id_forticket")); echo "" . __('By default, a software may be linked to a ticket') . ""; Dropdown::showYesNo("default_software_helpdesk_visible", $CFG_GLPI["default_software_helpdesk_visible"]); echo "
" . __('Keep tickets when purging hardware in the inventory') . ""; Dropdown::showYesNo("keep_tickets_on_delete", $CFG_GLPI["keep_tickets_on_delete"]); echo "".__('Show personnal information in new ticket form (simplified interface)'); echo ""; Dropdown::showYesNo('use_check_pref', $CFG_GLPI['use_check_pref']); echo "
" .__('Allow anonymous ticket creation (helpdesk.receiver)') . ""; Dropdown::showYesNo("use_anonymous_helpdesk", $CFG_GLPI["use_anonymous_helpdesk"]); echo "" . __('Allow anonymous followups (receiver)') . ""; Dropdown::showYesNo("use_anonymous_followups", $CFG_GLPI["use_anonymous_followups"]); echo "
"; echo ""; echo ""; echo ""; echo ""; for ($impact=5 ; $impact>=1 ; $impact--) { echo ""; } echo ""; echo ""; echo ""; for ($impact=5 ; $impact>=1 ; $impact--) { echo ""; } echo ""; for ($urgency=5 ; $urgency>=1 ; $urgency--) { echo ""; echo ""; echo ""; for ($impact=5 ; $impact>=1 ; $impact--) { $pri = round(($urgency+$impact)/2); if (isset($CFG_GLPI['priority_matrix'][$urgency][$impact])) { $pri = $CFG_GLPI['priority_matrix'][$urgency][$impact]; } if ($isurgency[$urgency] && $isimpact[$impact]) { $bgcolor=$_SESSION["glpipriority_$pri"]; echo ""; } else { echo ""; } } echo "\n"; } if ($canedit) { echo ""; echo ""; } echo "
" . __('Matrix of calculus for priority'); echo "
".__('Impact')."".Ticket::getImpactName($impact).'
'; if ($impact==3) { $isimpact[3] = 1; echo ""; } else { $isimpact[$impact] = (($CFG_GLPI['impact_mask']&(1<<$impact)) >0); Dropdown::showYesNo("_impact_${impact}", $isimpact[$impact]); } echo "
".__('Urgency')." 
".Ticket::getUrgencyName($urgency)." "; if ($urgency==3) { $isurgency[3] = 1; echo ""; } else { $isurgency[$urgency] = (($CFG_GLPI['urgency_mask']&(1<<$urgency)) >0); Dropdown::showYesNo("_urgency_${urgency}", $isurgency[$urgency]); } echo ""; Ticket::dropdownPriority(array('value' => $pri, 'name' => "_matrix_${urgency}_${impact}")); echo "
"; echo ""; echo "
"; Html::closeForm(); } /** * Print the config form for default user prefs * * @param $data array containing datas * (CFG_GLPI for global config / glpi_users fields for user prefs) * * @return Nothing (display) **/ function showFormUserPrefs($data=array()) { global $DB, $CFG_GLPI; $oncentral = ($_SESSION["glpiactiveprofile"]["interface"]=="central"); $userpref = false; $url = Toolbox::getItemTypeFormURL(__CLASS__); $canedit = Config::canUpdate(); if (array_key_exists('last_login',$data)) { $userpref = true; if ($data["id"] === Session::getLoginUserID()) { $url = $CFG_GLPI['root_doc']."/front/preference.php"; } else { $url = $CFG_GLPI['root_doc']."/front/user.form.php"; } } if($canedit || $userpref) { echo ""; } // Only set id for user prefs if ($userpref) { echo ""; } echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $values = array(0 => '1 234.56', 1 => '1,234.56', 2 => '1 234,56', 3 => '1234.56', 4 => '1234,56'); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if ($oncentral) { echo ""; } else { echo ""; } if (!$userpref || ($CFG_GLPI['show_count_on_tabs'] != -1)) { echo ""; } else { echo ""; } echo ""; echo ""; if ($oncentral) { echo ""; } else { echo ""; } echo ""; echo ""; echo ""; echo ""; if ($oncentral) { echo ""; } else { echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if ($oncentral) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } // Only for user if (array_key_exists('personal_token', $data)) { echo ""; echo ""; } echo ""; echo "". ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "". ""; echo ""; echo ""; echo ""; if ($oncentral && $CFG_GLPI["lock_use_lock_item"]) { echo ""; echo ""; echo ""; } if ($canedit || $userpref) { echo ""; echo ""; } echo "
" . __('Personalization') . "
" . ($userpref?__('Language'):__('Default language')) . ""; if (Config::canUpdate() || !GLPI_DEMO_MODE) { Dropdown::showLanguages("language", array('value' => $data["language"])); } else { echo " "; } echo "" . __('Date format') .""; $date_formats = array(0 => __('YYYY-MM-DD'), 1 => __('DD-MM-YYYY'), 2 => __('MM-DD-YYYY')); Dropdown::showFromArray('date_format', $date_formats, array('value' => $data["date_format"])); echo "
".__('Display order of surnames firstnames').""; $values = array(User::REALNAME_BEFORE => __('Surname, First name'), User::FIRSTNAME_BEFORE => __('First name, Surname')); Dropdown::showFromArray('names_format', $values, array('value' => $data["names_format"])); echo "" .__('Number format') . ""; Dropdown::showFromArray('number_format', $values, array('value' => $data["number_format"])); echo "
" . __('Results to display by page').""; // Limit using global config $value = (($data['list_limit'] < $CFG_GLPI['list_limit_max']) ? $data['list_limit'] : $CFG_GLPI['list_limit_max']); Dropdown::showNumber('list_limit', array('value' => $value, 'min' => 5, 'max' => $CFG_GLPI['list_limit_max'], 'step' => 5)); echo "".__('Go to created item after creation').""; Dropdown::showYesNo("backcreated", $data["backcreated"]); echo "
" . __('Display the complete name in tree dropdowns') . ""; Dropdown::showYesNo('use_flat_dropdowntree', $data["use_flat_dropdowntree"]); echo " ".__('Display counts in tabs').""; $values = array(0 => __('No'), 1 => __('Yes')); if (!$userpref) { $values[-1] = __('Never'); } Dropdown::showFromArray('show_count_on_tabs', $values, array('value' => $data["show_count_on_tabs"])); echo " 
" . __('Show GLPI ID') . ""; Dropdown::showYesNo("is_ids_visible", $data["is_ids_visible"]); echo "" . __('Keep devices when purging an item') . ""; Dropdown::showYesNo('keep_devices_when_purging_item', $data['keep_devices_when_purging_item']); echo "
" . __('Notifications for my changes') . ""; Dropdown::showYesNo("notification_to_myself", $data["notification_to_myself"]); echo "".__('Results to display on home page').""; Dropdown::showNumber('display_count_on_home', array('value' => $data['display_count_on_home'], 'min' => 0, 'max' => 30)); echo " 
" . __('PDF export font') . ""; Dropdown::showFromArray("pdffont", GLPIPDF::getFontList(), array('value' => $data["pdffont"], 'width' => 200)); echo "".__('CSV delimiter').""; $values = array(';' => ';', ',' => ','); Dropdown::showFromArray('csv_delimiter', $values, array('value' => $data["csv_delimiter"])); echo "
" . __("Color palette") . ""; $themes_files = scandir(GLPI_ROOT."/css/palettes/"); echo ""; echo "" . __('Layout').""; $layout_options = array('lefttab' => __("Tabs on left"), 'classic' => __("Classic view"), 'vsplit' => __("Vertical split")); echo ""; echo "
".__('Enable high contrast').""; Dropdown::showYesNo('highcontrast_css', $data['highcontrast_css']); echo ""; echo "
".__('Assistance')."
".__('Private followups by default').""; Dropdown::showYesNo("followup_private", $data["followup_private"]); echo "". __('Show new tickets on the home page') . ""; if (Session::haveRightsOr("ticket", array(Ticket::READMY, Ticket::READALL, Ticket::READASSIGN))) { Dropdown::showYesNo("show_jobs_at_login", $data["show_jobs_at_login"]); } else { echo Dropdown::getYesNo(0); } echo "
" . __('Private tasks by default') . ""; Dropdown::showYesNo("task_private", $data["task_private"]); echo " " . __('Request sources by default') . ""; RequestType::dropdown(array('value' => $data["default_requesttypes_id"], 'name' => "default_requesttypes_id", 'condition' => 'is_active = 1 AND is_ticketheader = 1')); echo "
" . __('Tasks state by default') . ""; Planning::dropdownState("task_state", $data["task_state"]); echo "" . __('Automatically refresh the list of tickets (minutes)') . ""; Dropdown::showNumber('refresh_ticket_list', array('value' => $data["refresh_ticket_list"], 'min' => 1, 'max' => 30, 'step' => 1, 'toadd' => array(0 => __('Never')))); echo "
".__('Pre-select me as a technician when creating a ticket'). ""; if (!$userpref || Session::haveRight('ticket', Ticket::OWN)) { Dropdown::showYesNo("set_default_tech", $data["set_default_tech"]); } else { echo Dropdown::getYesNo(0); } echo "" . __('Pre-select me as a requester when creating a ticket') . ""; if (!$userpref || Session::haveRight('ticket', CREATE)) { Dropdown::showYesNo("set_default_requester", $data["set_default_requester"]); } else { echo Dropdown::getYesNo(0); } echo "
" . __('Priority colors') . ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
1 "; Html::showColorField('priority_1', array('value' => $data["priority_1"])); echo "2 "; Html::showColorField('priority_2', array('value' => $data["priority_2"])); echo "3 "; Html::showColorField('priority_3', array('value' => $data["priority_3"])); echo "4 "; Html::showColorField('priority_4', array('value' => $data["priority_4"])); echo "5 "; Html::showColorField('priority_5', array('value' => $data["priority_5"])); echo "6 "; Html::showColorField('priority_6', array('value' => $data["priority_6"])); echo "
"; echo "
".__('Enable ticket timeline').""; Dropdown::showYesNo('ticket_timeline', $data['ticket_timeline']); echo "" . __('Keep tabs replaced by the ticket timeline').""; Dropdown::showYesNo('ticket_timeline_keep_replaced_tabs', $data['ticket_timeline_keep_replaced_tabs']); echo "
". __('Remote access key') ."
"; if (!empty($data["personal_token"])) { //TRANS: %s is the generation date echo "
".sprintf(__('generated on %s'), Html::convDateTime($data["personal_token_date"])); } echo "
"; echo $data["personal_token"]; echo ""; echo " ".__('Regenerate'); echo "
".__('Due date progression')."
".__('OK state color').""; Html::showColorField('duedateok_color', array('value' => $data["duedateok_color"])); echo " 
".__('Warning state color').""; Html::showColorField('duedatewarning_color', array('value' => $data["duedatewarning_color"])); echo "".__('Warning state threshold').""; Dropdown::showNumber("duedatewarning_less", array('value' => $data['duedatewarning_less'])); $elements = array('%' => '%', 'hours' => _n('Hour', 'Hours', Session::getPluralNumber()), 'days' => _n('Day', 'Days', Session::getPluralNumber())); echo " "; Dropdown::showFromArray("duedatewarning_unit", $elements, array('value' => $data['duedatewarning_unit'])); echo "
".__('Critical state color').""; Html::showColorField('duedatecritical_color', array('value' => $data["duedatecritical_color"])); echo "".__('Critical state threshold').""; Dropdown::showNumber("duedatecritical_less", array('value' => $data['duedatecritical_less'])); echo " "; $elements = array('%' => '%', 'hours' => _n('Hour', 'Hours', Session::getPluralNumber()), 'days' => _n('Day', 'Days', Session::getPluralNumber())); Dropdown::showFromArray("duedatecritical_unit", $elements, array('value' => $data['duedatecritical_unit'])); echo "
".__('Item locks')."
" . __('Auto-lock Mode') . ""; Dropdown::showYesNo("lock_autolock_mode", $data["lock_autolock_mode"]); echo "". __('Direct Notification (requester for unlock will be the notification sender)'). ""; Dropdown::showYesNo("lock_directunlock_notification", $data["lock_directunlock_notification"]); echo "
"; echo ""; echo "
"; Html::closeForm(); } /** * Display security checks on password * * @param $field string id of the field containing password to check (default 'password') * * @since version 0.84 **/ static function displayPasswordSecurityChecks($field='password') { global $CFG_GLPI; printf(__('%1$s: %2$s'), __('Password minimum length'), "".$CFG_GLPI['password_min_length']. ""); echo "'; if (count($needs)) { echo "
"; printf(__('%1$s: %2$s'), __('Password must contains'), implode(', ',$needs)); } } /** * Validate password based on security rules * * @since version 0.84 * * @param $password string password to validate * @param $display boolean display errors messages? (true by default) * * @return boolean is password valid? **/ static function validatePassword($password, $display=true) { global $CFG_GLPI; $ok = true; if ($CFG_GLPI["use_password_security"]) { if (Toolbox::strlen($password) < $CFG_GLPI['password_min_length']) { $ok = false; if ($display) { Session::addMessageAfterRedirect(__('Password too short!'), false, ERROR); } } if ($CFG_GLPI["password_need_number"] && !preg_match("/[0-9]+/", $password)) { $ok = false; if ($display) { Session::addMessageAfterRedirect(__('Password must include at least a digit!'), false, ERROR); } } if ($CFG_GLPI["password_need_letter"] && !preg_match("/[a-z]+/", $password)) { $ok = false; if ($display) { Session::addMessageAfterRedirect(__('Password must include at least a lowercase letter!'), false, ERROR); } } if ($CFG_GLPI["password_need_caps"] && !preg_match("/[A-Z]+/", $password)) { $ok = false; if ($display) { Session::addMessageAfterRedirect(__('Password must include at least a uppercase letter!'), false, ERROR); } } if ($CFG_GLPI["password_need_symbol"] && !preg_match("/\W+/", $password)) { $ok = false; if ($display) { Session::addMessageAfterRedirect(__('Password must include at least a symbol!'), false, ERROR); } } } return $ok; } /** * Display a report about system performance * - opcode cache (opcache) * - user data cache (apcu / apcu-bc) * * @since 9.1 **/ function showPerformanceInformations() { global $CFG_GLPI; if (!Config::canUpdate()) { return false; } echo "
"; echo ""; echo ""; $ext = 'Zend OPcache'; if (extension_loaded($ext) && ($info = opcache_get_status(false))) { echo ""; // echo ""; // Memory $used = $info['memory_usage']['used_memory']; $free = $info['memory_usage']['free_memory']; $rate = round(100.0 * $used / ($used + $free)); $max = Toolbox::getSize($used + $free); $used = Toolbox::getSize($used); echo ""; // Hits $hits = $info['opcache_statistics']['hits']; $miss = $info['opcache_statistics']['misses']; $max = $hits+$miss; $rate = round($info['opcache_statistics']['opcache_hit_rate']); echo ""; // Restart (1 seems ok, can happen) $max = $info['opcache_statistics']['oom_restarts']; echo ""; if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { echo "\n"; } } else { echo ""; } echo ""; $ext = (PHP_MAJOR_VERSION < 7 ? 'APCu' : 'apcu-bc'); if (function_exists('apc_fetch') && ini_get('apc.enabled')) { echo ""; $info = apc_sma_info(true); $stat = apc_cache_info('user', true); // echo ""; // Memory $max = $info['num_seg'] * $info['seg_size']; $free = $info['avail_mem']; $used = $max - $free; $rate = round(100.0 * $used / $max); $max = Toolbox::getSize($used + $free); $used = Toolbox::getSize($used); echo ""; // Hits $hits = $stat['num_hits']; $miss = $stat['num_misses']; $max = $hits+$miss; $rate = round(100 * $hits / ($hits + $miss)); echo ""; if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { echo "\n"; } } else { echo ""; } echo "
" . __('PHP opcode cache') . "
" . sprintf(__('The "%s" extension is installed'), $ext) . " " . phpversion($ext) . " $ext
".print_r($info, true)."
" . __('Memory') . " " . sprintf(__('%1$s / %2$s'), $used, $max) . ""; Html::displayProgressBar('100', $rate, array('simple' => true, 'forcepadding' => false)); echo " 5 && $rate < 75 ? 'ok_min.png' : 'ko_min.png') . "' alt='$ext'>
" . __('Hits rate') . " " . sprintf(__('%1$s / %2$s'), $hits, $max) . ""; Html::displayProgressBar('100', $rate, array('simple' => true, 'forcepadding' => false)); echo " 90 ? 'ok_min.png' : 'ko_min.png') . "' alt='$ext'>
" . __('Out of memory restart') . " $max"; echo "$ext
"; echo ""; _e('Reset'); echo "
" . sprintf(__('Installing and enabling the "%s" extension may improve GLPI performance'), $ext) . " $ext
" . __('User data cache') . "
" . sprintf(__('The "%s" extension is installed'), $ext) . " " . phpversion('apc') . " $ext
Info:".print_r($info, true)."Stat:".print_r($stat, true)."
" . __('Memory') . " " . sprintf(__('%1$s / %2$s'), $used, $max) . ""; Html::displayProgressBar('100', $rate, array('simple' => true, 'forcepadding' => false)); echo " 5 && $rate < 50 ? 'ok_min.png' : 'ko_min.png') . "' alt='$ext'>
" . __('Hits rate') . " " . sprintf(__('%1$s / %2$s'), $hits, $max) . ""; Html::displayProgressBar('100', $rate, array('simple' => true, 'forcepadding' => false)); echo " 90 ? 'ok_min.png' : 'ko_min.png') . "' alt='$ext'>
"; echo ""; _e('Reset'); echo "
" . sprintf(__('Installing the "%s" extension may improve GLPI performance'), $ext) . " $ext
\n"; } /** * Display a HTML report about systeme information / configuration **/ function showSystemInformations() { global $DB, $CFG_GLPI; if (!Config::canUpdate()) { return false; } echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; //TRANS: Proxy port echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; //TRANS: Proxy port echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
" . __('General setup') . "
" . __('Log Level') . ""; $values[1] = __('1- Critical (login error only)'); $values[2] = __('2- Severe (not used)'); $values[3] = __('3- Important (successful logins)'); $values[4] = __('4- Notices (add, delete, tracking)'); $values[5] = __('5- Complete (all)'); Dropdown::showFromArray('event_loglevel', $values, array('value' => $CFG_GLPI["event_loglevel"])); echo "".__('Maximal number of automatic actions (run by CLI)').""; Dropdown::showNumber('cron_limit', array('value' => $CFG_GLPI["cron_limit"], 'min' => 1, 'max' => 30)); echo "
" . __('Logs in files (SQL, email, automatic action...)') . ""; Dropdown::showYesNo("use_log_in_files", $CFG_GLPI["use_log_in_files"]); echo " " . _n('SQL replica', 'SQL replicas', 1) . ""; $active = DBConnection::isDBSlaveActive(); Dropdown::showYesNo("_dbslave_status", $active); echo "
".__('Password security policy'); echo "
" . __('Password security policy validation') . ""; Dropdown::showYesNo("use_password_security", $CFG_GLPI["use_password_security"]); echo "" . __('Password minimum length') . ""; Dropdown::showNumber('password_min_length', array('value' => $CFG_GLPI["password_min_length"], 'min' => 4, 'max' => 30)); echo "
" . __('Password need digit') . ""; Dropdown::showYesNo("password_need_number", $CFG_GLPI["password_need_number"]); echo "" . __('Password need lowercase character') . ""; Dropdown::showYesNo("password_need_letter", $CFG_GLPI["password_need_letter"]); echo "
" . __('Password need uppercase character') . ""; Dropdown::showYesNo("password_need_caps", $CFG_GLPI["password_need_caps"]); echo "" . __('Password need symbol') . ""; Dropdown::showYesNo("password_need_symbol", $CFG_GLPI["password_need_symbol"]); echo "
".__('Maintenance mode'); echo "
" . __('Maintenance mode') . ""; Dropdown::showYesNo("maintenance_mode", $CFG_GLPI["maintenance_mode"]); echo "" . __('Maintenance text') . ""; echo ""; echo "
".__('Proxy configuration for upgrade check'); echo "
" . __('Server') . "" . __('Port') . "
" . __('Login') . "" . __('Password') . ""; echo "
".__('Clear'); echo "
"; echo ""; echo "
"; Html::closeForm(); $width = 128; echo ""; echo ""; $oldlang = $_SESSION['glpilanguage']; // Keep this, for some function call which still use translation (ex showAllReplicateDelay) Session::loadLanguage('en_GB'); // No need to translate, this part always display in english (for copy/paste to forum) // Try to compute a better version for .git if (is_dir(GLPI_ROOT."/.git")) { $dir = getcwd(); chdir(GLPI_ROOT); $returnCode = 1; $result = @exec('git describe --tags 2>&1', $output, $returnCode); chdir($dir); $ver = ($returnCode ? $CFG_GLPI['version'].'-git' : $result); } else { $ver = $CFG_GLPI['version']; } echo ""; echo "\n"; echo ""; self::showLibrariesInformation(); foreach ($CFG_GLPI["systeminformations_types"] as $type) { $tmp = new $type(); $tmp->showSystemInformations($width); } Session::loadLanguage($oldlang); echo ""; echo "\n"; echo "
". __('Information about system installation and configuration')."
[code]\n \n";
      echo "GLPI $ver (" . $CFG_GLPI['root_doc']." => " . GLPI_ROOT . ")\n";
      echo "\n
Server
\n \n";
      echo wordwrap("Operating system: ".php_uname()."\n", $width, "\n\t");
      $exts = get_loaded_extensions();
      sort($exts);
      echo wordwrap("PHP ".phpversion().' '.php_sapi_name()." (".implode(', ',$exts).")\n",
                    $width, "\n\t");
      $msg = "Setup: ";

      foreach (array('max_execution_time', 'memory_limit', 'post_max_size', 'safe_mode',
                     'session.save_handler', 'upload_max_filesize') as $key) {
         $msg .= $key.'="'.ini_get($key).'" ';
      }
      echo wordwrap($msg."\n", $width, "\n\t");

      $msg = 'Software: ';
      if (isset($_SERVER["SERVER_SOFTWARE"])) {
         $msg .= $_SERVER["SERVER_SOFTWARE"];
      }
      if (isset($_SERVER["SERVER_SIGNATURE"])) {
         $msg .= ' ('.Html::clean($_SERVER["SERVER_SIGNATURE"]).')';
      }
      echo wordwrap($msg."\n", $width, "\n\t");

      if (isset($_SERVER["HTTP_USER_AGENT"])) {
         echo "\t" . $_SERVER["HTTP_USER_AGENT"] . "\n";
      }

      foreach ($DB->getInfo() as $key => $val) {
         echo "$key: $val\n\t";
      }
      echo "\n";

      self::checkWriteAccessToDirs(true);
      toolbox::checkSELinux(true);

      echo "\n
[/code]\n
". __('To copy/paste in your support request')."
\n"; } /** * @since version 0.90 * * @return string **/ static function getSQLMode() { global $DB; $query = "SELECT @@GLOBAL.sql_mode;"; $results = $DB->query($query); if ($DB->numrows($results) > 0) { return $DB->results($result, 0); } return ''; } /** * Retrieve full directory of a lib * @param $libstring object, class or function * @return string the path or false * * @since version 9.1 */ static function getLibraryDir($libstring) { if (is_object($libstring)) { return realpath(dirname((new ReflectionObject($libstring))->getFileName())); } elseif (class_exists($libstring)) { return realpath(dirname((new ReflectionClass($libstring))->getFileName())); } elseif (function_exists($libstring)) { // Internal function have no file name $path = (new ReflectionFunction($libstring))->getFileName(); return ($path ? realpath(dirname($path)) : false); } return false; } /** * show Libraries information in system information * * @since version 0.84 **/ static function showLibrariesInformation() { // No gettext echo "Libraries\n"; echo "
\n \n";

      include_once(GLPI_HTMLAWED);
      $pm = new PHPMailer();
      $sp = new SimplePie();

      $deps = [[ 'name'    => 'htmLawed',
                 'version' => hl_version() ,
                 'check'   => 'hl_version' ],
               [ 'name'    => 'phpCas',
                 'version' => phpCAS::getVersion() ,
                 'check'   => 'phpCAS' ],
               [ 'name'    => 'PHPMailer',
                 'version' => $pm->Version ,
                 'check'   => 'PHPMailer' ],
               [ 'name'    => 'Zend Framework',
                 'check'   => 'Zend\\Loader\\StandardAutoloader' ],
               [ 'name'    => 'zetacomponents/graph',
                 'check'   => 'ezcGraph' ],
               [ 'name'    => 'SimplePie',
                 'version' => SIMPLEPIE_VERSION,
                 'check'   => $sp ],
               [ 'name'    => 'TCPDF',
                 'version' => TCPDF_STATIC::getTCPDFVersion(),
                 'check'   => 'TCPDF' ],
               [ 'name'    => 'ircmaxell/password-compat',
                 'check'   => 'password_hash' ],
               [ 'name'    => 'ramsey/array_column',
                 'check'   => 'array_column' ],
               [ 'name'    => 'michelf/php-markdown',
                 'check'   => 'Michelf\\Markdown' ],
               [ 'name'    => 'true/punycode',
                 'check'   => 'TrueBV\\Punycode' ],
               [ 'name'    => 'iacaml/autolink',
                 'check'   => 'autolink' ],
               [ 'name'    => 'sabre/vobject',
                 'check'   => 'Sabre\\VObject\\Component' ],
      ];

      foreach ($deps as $dep) {
         $path = self::getLibraryDir($dep['check']);
         if ($path) {
            echo "{$dep['name']} ";
            if (isset($dep['version'])) {
               echo "version {$dep['version']} ";
            }
            echo "in ($path)\n";
         }
      }

      echo "\n
"; } /** * Dropdown for global management config * * @param $name select name * @param $value default value **/ static function dropdownGlobalManagement($name, $value) { $choices[0] = __('Yes - Restrict to unit management for manual add'); $choices[1] = __('Yes - Restrict to global management for manual add'); $choices[2] = __('No'); Dropdown::showFromArray($name,$choices,array('value'=>$value)); } /** * Get language in GLPI associated with the value coming from LDAP * Value can be, for example : English, en_EN or en * * @param $lang : the value coming from LDAP * * @return the locale's php page in GLPI or '' is no language associated with the value **/ static function getLanguage($lang) { global $CFG_GLPI; // Search in order : ID or extjs dico or tinymce dico / native lang / english name // / extjs dico / tinymce dico // ID or extjs dico or tinymce dico foreach ($CFG_GLPI["languages"] as $ID => $language) { if ((strcasecmp($lang,$ID) == 0) || (strcasecmp($lang,$language[2]) == 0) || (strcasecmp($lang,$language[3]) == 0)) { return $ID; } } // native lang foreach ($CFG_GLPI["languages"] as $ID => $language) { if (strcasecmp($lang,$language[0]) == 0) { return $ID; } } // english lang name foreach ($CFG_GLPI["languages"] as $ID => $language) { if (strcasecmp($lang,$language[4]) == 0) { return $ID; } } return ""; } static function detectRootDoc() { global $CFG_GLPI; if (!isset($CFG_GLPI["root_doc"])) { if (!isset($_SERVER['REQUEST_URI']) ) { $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF']; } $currentdir = getcwd(); chdir(GLPI_ROOT); $glpidir = str_replace(str_replace('\\', '/',getcwd()), "", str_replace('\\', '/',$currentdir)); chdir($currentdir); $globaldir = Html::cleanParametersURL($_SERVER['REQUEST_URI']); $globaldir = preg_replace("/\/[0-9a-zA-Z\.\-\_]+\.php/","",$globaldir); // api exception if (strpos($globaldir, 'api/') !== false) { $globaldir = preg_replace("/(.*\/)api\/.*/", "$1", $globaldir); } $CFG_GLPI["root_doc"] = str_replace($glpidir,"",$globaldir); $CFG_GLPI["root_doc"] = preg_replace("/\/$/","",$CFG_GLPI["root_doc"]); // urldecode for space redirect to encoded URL : change entity $CFG_GLPI["root_doc"] = urldecode($CFG_GLPI["root_doc"]); } } /** * Display debug information for dbslave **/ function showDebug() { $options['diff'] = 0; $options['name'] = ''; NotificationEvent::debugEvent(new DBConnection(), $options); } /** * Display field unicity criterias form **/ function showFormFieldUnicity() { global $CFG_GLPI; $unicity = new FieldUnicity(); $unicity->showForm(1, -1); } /** * @see CommonGLPI::getTabNameForItem() **/ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { switch ($item->getType()) { case 'Preference' : return __('Personalization'); case 'User' : if (User::canUpdate() && $item->currentUserHaveMoreRightThan($item->getID())) { return __('Settings'); } break; case __CLASS__ : $tabs[1] = __('General setup'); // Display $tabs[2] = __('Default values'); // Prefs $tabs[3] = __('Assets'); $tabs[4] = __('Assistance'); if (Config::canUpdate()) { $tabs[5] = __('System'); $tabs[7] = __('Performance'); $tabs[8] = __('API'); } if (DBConnection::isDBSlaveActive() && Config::canUpdate()) { $tabs[6] = _n('SQL replica', 'SQL replicas', Session::getPluralNumber()); // Slave } return $tabs; } return ''; } /** * @param $item CommonGLPI object * @param $tabnum (default 1) * @param $withtemplate (default 0) **/ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { global $CFG_GLPI; if ($item->getType() == 'Preference') { $config = new self(); $user = new User(); if ($user->getFromDB(Session::getLoginUserID())) { $user->computePreferences(); $config->showFormUserPrefs($user->fields); } } else if ($item->getType() == 'User') { $config = new self(); $item->computePreferences(); $config->showFormUserPrefs($item->fields); } else if ($item->getType() == __CLASS__) { switch ($tabnum) { case 1 : $item->showFormDisplay(); break; case 2 : $item->showFormUserPrefs($CFG_GLPI); break; case 3 : $item->showFormInventory(); break; case 4 : $item->showFormHelpdesk(); break; case 5 : $item->showSystemInformations(); break; case 6 : $item->showFormDBSlave(); break; case 7 : $item->showPerformanceInformations(); break; case 8 : $item->showFormAPI(); break; } } return true; } /** * Check Write Access to needed directories * * @param $fordebug boolean display for debug (no html, no gettext required) (false by default) * * @return 2 : creation error 1 : delete error 0: OK **/ static function checkWriteAccessToDirs($fordebug=false) { global $CFG_GLPI; $dir_to_check = array(GLPI_CONFIG_DIR => __('Checking write permissions for setting files'), GLPI_DOC_DIR => __('Checking write permissions for document files'), GLPI_DUMP_DIR => __('Checking write permissions for dump files'), GLPI_SESSION_DIR => __('Checking write permissions for session files'), GLPI_CRON_DIR => __('Checking write permissions for automatic actions files'), GLPI_GRAPH_DIR => __('Checking write permissions for graphic files'), GLPI_LOCK_DIR => __('Checking write permissions for lock files'), GLPI_PLUGIN_DOC_DIR => __('Checking write permissions for plugins document files'), GLPI_TMP_DIR => __('Checking write permissions for temporary files'), GLPI_RSS_DIR => __('Checking write permissions for rss files'), GLPI_UPLOAD_DIR => __('Checking write permissions for upload files'), GLPI_PICTURE_DIR => __('Checking write permissions for pictures files')); $error = 0; foreach ($dir_to_check as $dir => $message) { if (!$fordebug) { echo "".$message.""; } $tmperror = Toolbox::testWriteAccessToDirectory($dir); $errors = array(4 => __('The directory could not be created.'), 3 => __('The directory was created but could not be removed.'), 2 => __('The file could not be created.'), 1 => __("The file was created but can't be deleted.")); if ($tmperror > 0) { if ($fordebug) { echo " ". sprintf(__('Check permissions to the directory: %s'), $dir). " ".$errors[$tmperror]."\n"; } else { echo "

". $errors[$tmperror]."

". sprintf(__('Check permissions to the directory: %s'), $dir). "'"; } $error = 2; } else { if ($fordebug) { echo "\"".__s('OK').$dir : OK\n"; } else { echo "\"".". ""; } } } // Only write test for GLPI_LOG as SElinux prevent removing log file. if (!$fordebug) { echo "". __('Checking write permissions for log files').""; } if (error_log("Test\n", 3, GLPI_LOG_DIR."/php-errors.log")) { if ($fordebug) { echo "\"".__s('OK')."\"". GLPI_LOG_DIR." : OK\n"; } else { echo "\""."; } } else { if ($fordebug) { echo "". sprintf(__('Check permissions to the directory: %s'), GLPI_LOG_DIR)."\n"; } else { echo "". "

".__('The file could not be created.')."

". sprintf(__('Check permissions to the directory: %s'), GLPI_LOG_DIR).""; } $error = 1; } $oldhand = set_error_handler(function($errno, $errmsg, $filename, $linenum, $vars){return true;}); $oldlevel = error_reporting(0); /* TODO: could be improved, only default vhost checked */ if ($fic = fopen('http://localhost'.$CFG_GLPI['root_doc'].'/index.php', 'r')) { fclose($fic); if (!$fordebug) { echo "". __('Web access to files directory is protected').""; } if ($fic = fopen('http://localhost'.$CFG_GLPI['root_doc'].'/files/_log/php-errors.log', 'r')) { fclose($fic); if ($fordebug) { echo "". __('Web access to the files directory, should not be allowed')."\n". __('Check the .htaccess file and the web server configuration.')."\n"; } else { echo "". "

".__('Web access to the files directory, should not be allowed')."
". __('Check the .htaccess file and the web server configuration.')."

"; } $error = 1; } else { if ($fordebug) { echo "\"".". __s('Web access to files directory is protected')." : OK\n"; } else { echo "\""."; } } } error_reporting($oldlevel); set_error_handler($oldhand); return $error; } /** * Get current DB version (compatible with all version of GLPI) * * @since version 0.85 * * @return DB version **/ static function getCurrentDBVersion() { global $DB; if (!TableExists('glpi_configs')) { $query = "SELECT `version` FROM `glpi_config` WHERE `id` = '1'"; } else if (FieldExists('glpi_configs', 'version')) { $query = "SELECT `version` FROM `glpi_configs` WHERE `id` = '1'"; } else { $query = "SELECT `value` as version FROM `glpi_configs` WHERE 'context' = 'core' AND 'name' = 'version'"; } $result = $DB->query($query); $config = $DB->fetch_assoc($result); return trim($config['version']); } /** * Get config values * * @since version 0.85 * * @param $context string context to get values (default for glpi is core) * @param $names array of config names to get * * @return array of config values **/ static function getConfigurationValues($context, array $names=array()) { global $DB; if (count($names) == 0) { $query = "SELECT * FROM `glpi_configs` WHERE `context` = '$context'"; } else { $query = "SELECT * FROM `glpi_configs` WHERE `context` = '$context' AND `name` IN ('".implode("', '", $names)."')"; } $result = array(); foreach ($DB->request($query) as $line) { $result[$line['name']] = $line['value']; } return $result; } /** * Set config values : create or update entry * * @since version 0.85 * * @param $context string context to get values (default for glpi is core) * @param $values array of config names to set * * @return array of config values **/ static function setConfigurationValues($context, array $values=array()) { $config = new self(); foreach ($values as $name => $value) { if ($config->getFromDBByQuery("WHERE `context` = '$context' AND `name` = '$name'")) { $input = array('id' => $config->getID(), 'context' => $context, 'value' => $value); $config->update($input); } else { $input = array('context' => $context, 'name' => $name, 'value' => $value); $config->add($input); } } } /** * Delete config entries * * @since version 0.85 * * @param $context string context to get values (default for glpi is core) * @param $values array of config names to delete * * @return array of config values **/ static function deleteConfigurationValues($context, array $values= array()) { $config = new self(); foreach ($values as $value) { if ($config->getFromDBByQuery("WHERE `context` = '$context' AND `name` = '$value'")) { $config->delete(array('id' => $config->getID())); } } } /** * @since version 0.85 * * @see commonDBTM::getRights() **/ function getRights($interface='central') { $values = parent::getRights(); unset($values[CREATE], $values[DELETE], $values[PURGE]); return $values; } }