PageRenderTime 32ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/www/include/options/oreon/generalOpt/general/form.php

https://gitlab.com/florianocomercial/centreon
PHP | 265 lines | 155 code | 41 blank | 69 comment | 21 complexity | a937b3be1b3ac29c47c11002f35e843c MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright 2005-2015 Centreon
  4. * Centreon is developped by : Julien Mathis and Romain Le Merlus under
  5. * GPL Licence 2.0.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU General Public License as published by the Free Software
  9. * Foundation ; either version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  13. * PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, see <http://www.gnu.org/licenses>.
  17. *
  18. * Linking this program statically or dynamically with other modules is making a
  19. * combined work based on this program. Thus, the terms and conditions of the GNU
  20. * General Public License cover the whole combination.
  21. *
  22. * As a special exception, the copyright holders of this program give Centreon
  23. * permission to link this program with independent modules to produce an executable,
  24. * regardless of the license terms of these independent modules, and to copy and
  25. * distribute the resulting executable under terms of Centreon choice, provided that
  26. * Centreon also meet, for each linked independent module, the terms and conditions
  27. * of the license of that module. An independent module is a module which is not
  28. * derived from this program. If you modify this program, you may extend this
  29. * exception to your version of the program, but you are not obliged to do so. If you
  30. * do not wish to do so, delete this exception statement from your version.
  31. *
  32. * For more information : contact@centreon.com
  33. *
  34. */
  35. require_once _CENTREON_PATH_ . "www/class/centreonGMT.class.php";
  36. if (!isset($centreon)) {
  37. exit();
  38. }
  39. $transcoKey = array(
  40. "enable_autologin" => "yes",
  41. "display_autologin_shortcut" => "yes",
  42. "sso_enable" => "yes",
  43. "enable_gmt" => "yes",
  44. "strict_hostParent_poller_management" => "yes"
  45. );
  46. $DBRESULT = $pearDB->query("SELECT * FROM `options`");
  47. while ($opt = $DBRESULT->fetchRow()) {
  48. if (isset($transcoKey[$opt["key"]])) {
  49. $gopt[$opt["key"]][$transcoKey[$opt["key"]]] = myDecode($opt["value"]);
  50. } else {
  51. $gopt[$opt["key"]] = myDecode($opt["value"]);
  52. }
  53. }
  54. /*
  55. * Style
  56. */
  57. $attrsText = array("size"=>"40");
  58. $attrsText2 = array("size"=>"5");
  59. $attrsAdvSelect = null;
  60. /*
  61. * Form begin
  62. */
  63. $form = new HTML_QuickForm('Form', 'post', "?p=".$p);
  64. $form->addElement('header', 'title', _("Modify General Options"));
  65. /*
  66. * information
  67. */
  68. $form->addElement('header', 'oreon', _("Centreon information"));
  69. $form->addElement('text', 'oreon_path', _("Directory"), $attrsText);
  70. $form->addElement('text', 'oreon_web_path', _("Centreon Web Directory"), $attrsText);
  71. $form->addElement('text', 'session_expire', _("Sessions Expiration Time"), $attrsText2);
  72. $limit = array(10 => 10, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 60 => 60, 70 => 70, 80 => 80, 90 => 90, 100 => 100);
  73. $form->addElement('select', 'maxViewMonitoring', _("Limit per page for Monitoring"), $limit);
  74. $form->addElement('text', 'maxGraphPerformances', _("Graph per page for Performances"), $attrsText2);
  75. $form->addElement('text', 'maxViewConfiguration', _("Limit per page (default)"), $attrsText2);
  76. $form->addElement('text', 'AjaxTimeReloadStatistic', _("Refresh Interval for statistics"), $attrsText2);
  77. $form->addElement('text', 'AjaxTimeReloadMonitoring', _("Refresh Interval for monitoring"), $attrsText2);
  78. $form->addElement('text', 'selectPaginationSize', _('Number of elements loaded in select'), $attrsText2);
  79. $CentreonGMT = new CentreonGMT($pearDB);
  80. $GMTList = $CentreonGMT->getGMTList();
  81. $form->addElement('select', 'gmt', _("Timezone"), $GMTList);
  82. $templates = array();
  83. if ($handle = @opendir($oreon->optGen["oreon_path"]."www/Themes/")) {
  84. while ($file = @readdir($handle)) {
  85. if (!is_file($oreon->optGen["oreon_path"]."www/Themes/".$file) && $file != "." && $file != ".." && $file != ".svn") {
  86. $templates[$file] = $file;
  87. }
  88. }
  89. @closedir($handle);
  90. }
  91. $form->addElement('select', 'template', _("Display Template"), $templates);
  92. $global_sort_type = array(
  93. "host_name" => _("Hosts"),
  94. "last_state_change" => _("Duration"),
  95. "service_description" => _("Services"),
  96. "current_state" => _("Status"),
  97. "last_check" => _("Last check"),
  98. "output" => _("Output"),
  99. "criticality_id" => _("Criticality"),
  100. "current_attempt" => _("Attempt"),
  101. );
  102. $sort_type = array( "last_state_change" => _("Duration"),
  103. "host_name" => _("Hosts"),
  104. "service_description" => _("Services"),
  105. "current_state" => _("Status"),
  106. "last_check" => _("Last check"),
  107. "plugin_output" => _("Output"));
  108. $form->addElement('select', 'global_sort_type', _("Sort by "), $global_sort_type);
  109. $global_sort_order = array("ASC" => _("Ascending"), "DESC" => _("Descending"));
  110. $form->addElement('select', 'global_sort_order', _("Order sort "), $global_sort_order);
  111. $form->addElement('select', 'problem_sort_type', _("Sort problems by"), $sort_type);
  112. $sort_order = array("ASC" => _("Ascending"), "DESC" => _("Descending"));
  113. $form->addElement('select', 'problem_sort_order', _("Order sort problems"), $sort_order);
  114. $options1[] = HTML_QuickForm::createElement('checkbox', 'yes', '&nbsp;', '');
  115. $form->addGroup($options1, 'enable_autologin', _("Enable Autologin"), '&nbsp;&nbsp;');
  116. $options2[] = HTML_QuickForm::createElement('checkbox', 'yes', '&nbsp;', '');
  117. $form->addGroup($options2, 'display_autologin_shortcut', _("Display Autologin shortcut"), '&nbsp;&nbsp;');
  118. /*
  119. * SSO
  120. */
  121. $sso_enable[] = HTML_QuickForm::createElement('checkbox', 'yes', '&nbsp;', '', array("onchange" => "javascript:confirm('Are you sure you want to change this parameter ? Please read the help before.')"));
  122. $form->addGroup($sso_enable, 'sso_enable', _("Enable SSO authentication"), '&nbsp;&nbsp;');
  123. $sso_mode = array();
  124. $sso_mode[] = HTML_QuickForm::createElement('radio', 'sso_mode', null, _("SSO only"), '0');
  125. $sso_mode[] = HTML_QuickForm::createElement('radio', 'sso_mode', null, _("Mixed"), '1');
  126. $form->addGroup($sso_mode, 'sso_mode', _("SSO mode"), '&nbsp;');
  127. $form->setDefaults(array('sso_mode'=>'1'));
  128. $form->addElement('text', 'sso_trusted_clients', _('SSO trusted client addresses'), array('size' => 50));
  129. $form->addElement('text', 'sso_blacklist_clients', _('SSO blacklist client addresses'), array('size' => 50));
  130. $form->addElement('text', 'sso_username_pattern', _('SSO pattern matching login'), array('size' => 50));
  131. $form->addElement('text', 'sso_username_replace', _('SSO pattern replace login'), array('size' => 50));
  132. $form->addElement('text', 'sso_header_username', _('SSO login header'), array('size' => 30));
  133. $form->setDefaults(array('sso_header_username'=>'HTTP_AUTH_USER'));
  134. $options3[] = HTML_QuickForm::createElement('checkbox', 'yes', '&nbsp;', '');
  135. $form->addGroup($options3, 'enable_gmt', _("Enable Timezone management"), '&nbsp;&nbsp;');
  136. /*
  137. * Support Email
  138. */
  139. $form->addElement('text', 'centreon_support_email', _("Centreon Support Email"), $attrsText);
  140. /*
  141. * Form Rules
  142. */
  143. function slash($elem = NULL) {
  144. if ($elem) {
  145. return rtrim($elem, "/")."/";
  146. }
  147. }
  148. $form->applyFilter('__ALL__', 'myTrim');
  149. $form->applyFilter('nagios_path', 'slash');
  150. $form->applyFilter('nagios_path_img', 'slash');
  151. $form->applyFilter('nagios_path_plugins', 'slash');
  152. $form->applyFilter('oreon_path', 'slash');
  153. $form->applyFilter('oreon_web_path', 'slash');
  154. $form->applyFilter('debug_path', 'slash');
  155. $form->registerRule('is_valid_path', 'callback', 'is_valid_path');
  156. $form->registerRule('is_readable_path', 'callback', 'is_readable_path');
  157. $form->registerRule('is_executable_binary', 'callback', 'is_executable_binary');
  158. $form->registerRule('is_writable_path', 'callback', 'is_writable_path');
  159. $form->registerRule('is_writable_file', 'callback', 'is_writable_file');
  160. $form->registerRule('is_writable_file_if_exist', 'callback', 'is_writable_file_if_exist');
  161. $form->addRule('oreon_path', _("Can't write in directory"), 'is_valid_path');
  162. $form->addRule('nagios_path_plugins', _("Can't write in directory"), 'is_writable_path');
  163. $form->addRule('nagios_path_img', _("Can't write in directory"), 'is_writable_path');
  164. $form->addRule('nagios_path', _("The directory isn't valid"), 'is_valid_path');
  165. /*
  166. * Smarty template Init
  167. */
  168. $tpl = new Smarty();
  169. $tpl = initSmartyTpl($path.'general/', $tpl);
  170. $form->setDefaults($gopt);
  171. $subC = $form->addElement('submit', 'submitC', _("Save"), array("class" => "btc bt_success"));
  172. $form->addElement('reset', 'reset', _("Reset"), array("class" => "btc bt_default"));
  173. $valid = false;
  174. if ($form->validate()) {
  175. /*
  176. * Update in DB
  177. */
  178. updateGeneralConfigData(1);
  179. /*
  180. * Update in Oreon Object
  181. */
  182. $centreon->initOptGen($pearDB);
  183. $o = NULL;
  184. $valid = true;
  185. $form->freeze();
  186. }
  187. if (!$form->validate() && isset($_POST["gopt_id"])) {
  188. print("<div class='msg' align='center'>"._("Impossible to validate, one or more field is incorrect")."</div>");
  189. }
  190. $form->addElement("button", "change", _("Modify"), array("onClick"=>"javascript:window.location.href='?p=".$p."'", 'class' => 'btc bt_info'));
  191. /*
  192. * Send variable to template
  193. */
  194. $tpl->assign('o', $o);
  195. $tpl->assign("sorting", _("Sorting"));
  196. $tpl->assign("genOpt_max_page_size", _("Maximum page size"));
  197. $tpl->assign("genOpt_expiration_properties", _("Sessions Properties"));
  198. $tpl->assign("time_min", _("minutes"));
  199. $tpl->assign("genOpt_refresh_properties", _("Refresh Properties"));
  200. $tpl->assign("time_sec", _("seconds"));
  201. $tpl->assign("genOpt_global_display", _("Display properties"));
  202. $tpl->assign("genOpt_problem_display", _("Problem display properties"));
  203. $tpl->assign("genOpt_time_zone", _("Time Zone"));
  204. $tpl->assign("genOpt_auth", _("Authentication properties"));
  205. $tpl->assign("support", _("Support Information"));
  206. $tpl->assign('valid', $valid);
  207. /*
  208. * prepare help texts
  209. */
  210. $helptext = "";
  211. include_once("help.php");
  212. foreach ($help as $key => $text) {
  213. $helptext .= '<span style="display:none" id="help:'.$key.'">'.$text.'</span>'."\n";
  214. }
  215. $tpl->assign("helptext", $helptext);
  216. /*
  217. * Apply a template definition
  218. */
  219. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  220. $renderer->setRequiredTemplate('{$label}&nbsp;<font color="red" size="1">*</font>');
  221. $renderer->setErrorTemplate('<font color="red">{$error}</font><br />{$html}');
  222. $form->accept($renderer);
  223. $tpl->assign('form', $renderer->toArray());
  224. $tpl->display("form.ihtml");