PageRenderTime 32ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/www/include/configuration/configObject/traps-mibs/formMibs.php

https://gitlab.com/florianocomercial/centreon
PHP | 149 lines | 69 code | 19 blank | 61 comment | 6 complexity | fec27bdaf248aa26d847afa3eebcc937 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. if (!isset($centreon))
  36. exit();
  37. /*
  38. * Debug Flag
  39. */
  40. $debug = 0;
  41. $max_characters = 20000;
  42. /*
  43. * Database retrieve information for Manufacturer
  44. */
  45. function myDecodeMib($arg) {
  46. $arg = html_entity_decode($arg, ENT_QUOTES, "UTF-8");
  47. return($arg);
  48. }
  49. /*
  50. * Init Formulary
  51. */
  52. $form = new HTML_QuickForm('Form', 'post', "?p=".$p);
  53. $form->addElement('header', 'title', _("Import SNMP traps from MIB file"));
  54. /*
  55. * Manufacturer information
  56. */
  57. $attrManufacturer= array(
  58. 'datasourceOrigin' => 'ajax',
  59. 'availableDatasetRoute' => './include/common/webServices/rest/internal.php?object=centreon_configuration_manufacturer&action=list',
  60. 'multiple' => false,
  61. 'linkedObject' => 'centreonManufacturer'
  62. );
  63. $attrManufacturer1 = array_merge(
  64. $attrManufacturer,
  65. array('defaultDatasetRoute' => './include/common/webServices/rest/internal.php?object=centreon_configuration_manufacturer&action=defaultValues&target=traps&field=manufacturer_id&id=')
  66. );
  67. $form->addElement('select2', 'mnftr', _("Vendor Name"), array(), $attrManufacturer1);
  68. $form->addElement('file', 'filename', _("File (.mib)"));
  69. /*
  70. * Formulary Rules
  71. */
  72. $form->applyFilter('__ALL__', 'myTrim');
  73. $form->addRule('mnftr', _("Compulsory Name"), 'required');
  74. $form->addRule('filename', _("Compulsory Name"), 'required');
  75. $form->setRequiredNote("<font style='color: red;'>*</font>&nbsp;". _("Required fields"));
  76. /*
  77. * Smarty template Init
  78. */
  79. $tpl = new Smarty();
  80. $tpl = initSmartyTpl($path, $tpl);
  81. $tpl->assign("helpattr", 'TITLE, "'._("Help").'", CLOSEBTN, true, FIX, [this, 0, 5], BGCOLOR, "#ffff99", BORDERCOLOR, "orange", TITLEFONTCOLOR, "black", TITLEBGCOLOR, "orange", CLOSEBTNCOLORS, ["","black", "white", "red"], WIDTH, -300, SHADOW, true, TEXTALIGN, "justify"' );
  82. # prepare help texts
  83. $helptext = "";
  84. include_once("help.php");
  85. foreach ($help as $key => $text) {
  86. $helptext .= '<span style="display:none" id="help:'.$key.'">'.$text.'</span>'."\n";
  87. }
  88. $tpl->assign("helptext", $helptext);
  89. /*
  90. * Just watch a Command information
  91. */
  92. $subA = $form->addElement('submit', 'submit', _("Import"), array("class" => "btc bt_success"));
  93. $form->addElement('header', 'status',_("Status"));
  94. $valid = false;
  95. $msg = NULL;
  96. $stdout = NULL;
  97. if ($form->validate()) {
  98. $ret = $form->getSubmitValues();
  99. $fileObj = $form->getElement('filename');
  100. if ($fileObj->isUploadedFile()) {
  101. /*
  102. * Upload File
  103. */
  104. $values = $fileObj->getValue();
  105. $msg .= str_replace ("\n", "<br />", $stdout);
  106. $msg .= "<br />Moving traps in DataBase...";
  107. if ($debug)
  108. print("@CENTREONTRAPD_BINDIR@/centFillTrapDB -f '".$values["tmp_name"]."' -m ".htmlentities($ret["mnftr"], ENT_QUOTES, "UTF-8")." --severity=info 2>&1");
  109. $stdout = shell_exec("@CENTREONTRAPD_BINDIR@/centFillTrapDB -f '".$values["tmp_name"]."' -m ".htmlentities($ret["mnftr"], ENT_QUOTES, "UTF-8")." --severity=info 2>&1");
  110. unlink($values['tmp_name']);
  111. $msg .= "<br />".str_replace ("\n", "<br />", $stdout);
  112. $msg .= "<br />Generate Traps configuration files from Monitoring Engine configuration form!";
  113. if ($msg) {
  114. if (strlen($msg) > $max_characters) {
  115. $msg = substr($msg, 0, $max_characters)."...".sprintf(_("Message truncated (exceeded %s characters)"), $max_characters);
  116. }
  117. $tpl->assign('msg', $msg);
  118. }
  119. }
  120. $valid = true;
  121. }
  122. /*
  123. * Apply a template definition
  124. */
  125. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  126. $renderer->setRequiredTemplate('{$label}&nbsp;<font color="red" size="1">*</font>');
  127. $renderer->setErrorTemplate('<font color="red">{$error}</font><br />{$html}');
  128. $form->accept($renderer);
  129. $tpl->assign('form', $renderer->toArray());
  130. $tpl->display("formMibs.ihtml");