| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | Oreon is developped with GPL Licence 2.0 : |
|---|
| 4 | http://www.gnu.org/licenses/gpl.txt |
|---|
| 5 | Developped by : Julien Mathis - Romain Le Merlus |
|---|
| 6 | |
|---|
| 7 | Adapted to Pear library by Merethis company, under direction of Cedrick Facon, Romain Le Merlus, Julien Mathis |
|---|
| 8 | |
|---|
| 9 | The Software is provided to you AS IS and WITH ALL FAULTS. |
|---|
| 10 | OREON makes no representation and gives no warranty whatsoever, |
|---|
| 11 | whether express or implied, and without limitation, with regard to the quality, |
|---|
| 12 | safety, contents, performance, merchantability, non-infringement or suitability for |
|---|
| 13 | any particular or intended purpose of the Software found on the OREON web site. |
|---|
| 14 | In no event will OREON be liable for any direct, indirect, punitive, special, |
|---|
| 15 | incidental or consequential damages however they may arise and even if OREON has |
|---|
| 16 | been previously advised of the possibility of such damages. |
|---|
| 17 | |
|---|
| 18 | For information : contact@oreon-project.org |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | if (!isset($oreon)) |
|---|
| 22 | exit(); |
|---|
| 23 | |
|---|
| 24 | # pagination |
|---|
| 25 | # set limit & num |
|---|
| 26 | $DBRESULT =& $pearDB->query("SELECT maxViewMonitoring FROM general_opt LIMIT 1"); |
|---|
| 27 | if (PEAR::isError($DBRESULT)) |
|---|
| 28 | print "Mysql Error : ".$DBRESULT->getMessage(); |
|---|
| 29 | $gopt = array_map("myDecode", $DBRESULT->fetchRow()); |
|---|
| 30 | |
|---|
| 31 | # pagination |
|---|
| 32 | include("./include/common/autoNumLimit.php"); |
|---|
| 33 | |
|---|
| 34 | isset ($_GET["num"]) ? $num = $_GET["num"] : $num = 0; |
|---|
| 35 | |
|---|
| 36 | isset($_GET["nopt_id"]) ? $nG = $_GET["nopt_id"] : $nG = NULL; |
|---|
| 37 | isset($_POST["nopt_id"]) ? $nP = $_POST["nopt_id"] : $nP = NULL; |
|---|
| 38 | $nG ? $nopt_id = $nG : $nopt_id = $nP; |
|---|
| 39 | |
|---|
| 40 | #Pear library |
|---|
| 41 | require_once "HTML/QuickForm.php"; |
|---|
| 42 | require_once 'HTML/QuickForm/advmultiselect.php'; |
|---|
| 43 | require_once 'HTML/QuickForm/Renderer/ArraySmarty.php'; |
|---|
| 44 | |
|---|
| 45 | #Path to the configuration dir |
|---|
| 46 | global $path; |
|---|
| 47 | $path = "./modules/NmapXmlImport/"; |
|---|
| 48 | |
|---|
| 49 | #PHP functions |
|---|
| 50 | require_once $path."DB-Func.php"; |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | # |
|---|
| 55 | ## Database retrieve information for LCA |
|---|
| 56 | # |
|---|
| 57 | $nopt = getNmapXmlImportOpt(); |
|---|
| 58 | |
|---|
| 59 | $hTpls = array(); |
|---|
| 60 | $hTpls = getHostTemplates(); |
|---|
| 61 | |
|---|
| 62 | $NmapOs = array(); |
|---|
| 63 | //$NmapOs = getNmapOs(); |
|---|
| 64 | |
|---|
| 65 | # |
|---|
| 66 | ## Database retrieve information for differents elements list we need on the page |
|---|
| 67 | # |
|---|
| 68 | # |
|---|
| 69 | # End of "database-retrieved" information |
|---|
| 70 | ########################################################## |
|---|
| 71 | |
|---|
| 72 | $req = "SELECT * FROM nmap_xml_import_os ORDER BY os_name ASC "; |
|---|
| 73 | $DBRESULT =& $pearDB->query($req); |
|---|
| 74 | if (PEAR::isError($DBRESULT)) |
|---|
| 75 | print ($DBRESULT->getMessage()); |
|---|
| 76 | |
|---|
| 77 | $rows = $DBRESULT->numrows(); |
|---|
| 78 | |
|---|
| 79 | include("./include/common/checkPagination.php"); |
|---|
| 80 | if(($num * $limit) > $rows) |
|---|
| 81 | $num = round($rows / $limit) - 1; |
|---|
| 82 | $lstart = $num * $limit; |
|---|
| 83 | |
|---|
| 84 | if ($lstart <= 0) |
|---|
| 85 | $lstart = 0; |
|---|
| 86 | |
|---|
| 87 | $req = $req . " LIMIT $lstart,$limit"; |
|---|
| 88 | $DBRESULT =& $pearDB->query($req); |
|---|
| 89 | if (PEAR::isError($DBRESULT)) |
|---|
| 90 | print ($DBRESULT->getMessage()); |
|---|
| 91 | |
|---|
| 92 | for($i = 0; $DBRESULT->numRows() && $DBRESULT->fetchInto($elem);$i++){ |
|---|
| 93 | $NmapOs[$i] = array_map("myDecode", $elem); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | ########################################################## |
|---|
| 97 | # Var information to format the element |
|---|
| 98 | # |
|---|
| 99 | |
|---|
| 100 | $attrsText = array("size"=>"50"); |
|---|
| 101 | $attrsText2 = array("size"=>"20"); |
|---|
| 102 | $attrsText3 = array("size"=>"10"); |
|---|
| 103 | $attrsAdvSelect = null; |
|---|
| 104 | # |
|---|
| 105 | ## Form begin |
|---|
| 106 | # |
|---|
| 107 | $form = new HTML_QuickForm('Form', 'post', "?p=".$p); |
|---|
| 108 | $form->addElement('header', 'title', $lang["nmap_xml_importOpt_change"]); |
|---|
| 109 | |
|---|
| 110 | $form->addElement('header', 'nmap_xml_importOpt', $lang["nmap_xml_importOpt"]); |
|---|
| 111 | //$form->addElement('text', 'default_template', $lang["nmap_xml_importOpt_default_template"], $attrsText ); |
|---|
| 112 | |
|---|
| 113 | $form->addElement('select', 'default_template' , $lang["nmap_xml_importOpt_default_template"], $hTpls); |
|---|
| 114 | //$template_select_list->setSelected($tmpConf["host_template_model_htm_id"]); |
|---|
| 115 | |
|---|
| 116 | foreach ($NmapOs as $os) { |
|---|
| 117 | |
|---|
| 118 | $selectedElements =& $form->addElement('checkbox', 'os['. $os['os_id'] .'][use_default_template]'); |
|---|
| 119 | if ($os['use_default_template'] == "1" ) |
|---|
| 120 | $selectedElements->setChecked(true); |
|---|
| 121 | |
|---|
| 122 | $template_select_list =& $form->addElement('select', 'os['. $os['os_id'] .'][host_template_model_htm]' , '', $hTpls); |
|---|
| 123 | if ($os['use_default_template'] == "1") |
|---|
| 124 | $template_select_list->setSelected($nopt['default_template']); |
|---|
| 125 | else |
|---|
| 126 | $template_select_list->setSelected($os["os_template"]); |
|---|
| 127 | |
|---|
| 128 | $hidden_os =&$form->addElement('hidden', 'os['. $os['os_id'] .'][os_id]' ,$os['os_id'] ); |
|---|
| 129 | |
|---|
| 130 | $osArr[] = array( |
|---|
| 131 | "RowMenu_os_hidden"=>$hidden_os->toHtml(), |
|---|
| 132 | "RowMenu_select"=>$selectedElements->toHtml(), |
|---|
| 133 | "RowMenu_osname"=>$os["os_name"], |
|---|
| 134 | "RowMenu_use_default_template"=>$os["use_default_template"], |
|---|
| 135 | "RowMenu_template_select"=>$template_select_list->toHtml() |
|---|
| 136 | ); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | # Header title for same name - Ajust pattern lenght with (0, 4) param |
|---|
| 141 | $pattern = NULL; |
|---|
| 142 | for ($i = 0; $i < count($osArr); $i++) { |
|---|
| 143 | # Searching for a pattern wich n+1 elem |
|---|
| 144 | if (isset($osArr[$i+1]["RowMenu_osname"]) && stristr($osArr[$i+1]["RowMenu_osname"], substr($osArr[$i]["RowMenu_osname"], 0, 4)) && !$pattern) { |
|---|
| 145 | for ($j = 0; isset($osArr[$i]["RowMenu_osname"][$j]) && $j <= 4 ; $j++) { |
|---|
| 146 | if (isset($osArr[$i+1]["RowMenu_osname"][$j]) && $osArr[$i+1]["RowMenu_osname"][$j] == $osArr[$i]["RowMenu_osname"][$j]) |
|---|
| 147 | ; |
|---|
| 148 | else |
|---|
| 149 | break; |
|---|
| 150 | } |
|---|
| 151 | $pattern = substr($osArr[$i]["RowMenu_osname"], 0, $j); |
|---|
| 152 | } |
|---|
| 153 | if ( isset($osArr[$i]["RowMenu_osname"]) && (stristr($osArr[$i]["RowMenu_osname"], $pattern))) |
|---|
| 154 | $osArr[$i]["pattern"] = $pattern; |
|---|
| 155 | else { |
|---|
| 156 | $osArr[$i]["pattern"] = NULL; |
|---|
| 157 | $pattern = NULL; |
|---|
| 158 | if (isset($osArr[$i+1]["RowMenu_osname"]) && stristr($osArr[$i+1]["RowMenu_osname"], substr($osArr[$i]["RowMenu_osname"], 0, 4)) && !$pattern) { |
|---|
| 159 | for ($j = 0; isset($osArr[$i]["RowMenu_osname"][$j]) && $j <= 4 ; $j++) { |
|---|
| 160 | if (isset($osArr[$i+1]["RowMenu_osname"][$j]) && $osArr[$i+1]["RowMenu_osname"][$j] == $osArr[$i]["RowMenu_osname"][$j]) |
|---|
| 161 | ; |
|---|
| 162 | else |
|---|
| 163 | break; |
|---|
| 164 | } |
|---|
| 165 | $pattern = substr($osArr[$i]["RowMenu_osname"], 0, $j); |
|---|
| 166 | $osArr[$i]["pattern"] = $pattern; |
|---|
| 167 | } |
|---|
| 168 | } |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | $form->addElement('hidden', 'nopt_id'); |
|---|
| 172 | $redirect =& $form->addElement('hidden', 'o'); |
|---|
| 173 | $redirect->setValue($o); |
|---|
| 174 | |
|---|
| 175 | # |
|---|
| 176 | ## Form Rules |
|---|
| 177 | # |
|---|
| 178 | function slash($elem = NULL) { |
|---|
| 179 | if ($elem) |
|---|
| 180 | return rtrim($elem, "/")."/"; |
|---|
| 181 | } |
|---|
| 182 | $form->applyFilter('_ALL_', 'trim'); |
|---|
| 183 | |
|---|
| 184 | # |
|---|
| 185 | ##End of form definition |
|---|
| 186 | # |
|---|
| 187 | |
|---|
| 188 | # Smarty template Init |
|---|
| 189 | $tpl = new Smarty(); |
|---|
| 190 | $tpl = initSmartyTpl($path, $tpl); |
|---|
| 191 | |
|---|
| 192 | $form->setDefaults($nopt); |
|---|
| 193 | |
|---|
| 194 | $subC =& $form->addElement('submit', 'submitC', $lang["save"]); |
|---|
| 195 | $DBRESULT =& $form->addElement('reset', 'reset', $lang["reset"]); |
|---|
| 196 | |
|---|
| 197 | $valid = false; |
|---|
| 198 | if ($form->validate()) { |
|---|
| 199 | |
|---|
| 200 | # Update in DB |
|---|
| 201 | updateNmapXmlImportOptConfigData($form->getSubmitValue("nopt_id")); |
|---|
| 202 | |
|---|
| 203 | if (isset($_POST['os']) && ($_POST['os'] != NULL)) { |
|---|
| 204 | foreach ($_POST['os'] as $os) { |
|---|
| 205 | updateOsConfigData($os['os_id']); |
|---|
| 206 | } |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | # Update in Oreon Object |
|---|
| 210 | |
|---|
| 211 | $NmapOs = NULL; |
|---|
| 212 | $NmapOs = getNmapOs(); |
|---|
| 213 | $osArr = NULL; |
|---|
| 214 | $osArr = array(); |
|---|
| 215 | foreach ($NmapOs as $os) { |
|---|
| 216 | |
|---|
| 217 | $selectedElements =& $form->addElement('checkbox', "select[".$os['os_id']."]"); |
|---|
| 218 | if ($os['use_default_template'] == "1" ) |
|---|
| 219 | $selectedElements->setChecked(true); |
|---|
| 220 | |
|---|
| 221 | $template_select_list =& $form->addElement('select', 'os['. $os['os_id'] .'][host_template_model_htm]' , '', $hTpls); |
|---|
| 222 | |
|---|
| 223 | if ($os['use_default_template'] == "1") |
|---|
| 224 | $template_select_list->setSelected($nopt['default_template']); |
|---|
| 225 | else |
|---|
| 226 | $template_select_list->setSelected($os["os_template"]); |
|---|
| 227 | |
|---|
| 228 | $hidden_os = &$form->addElement('hidden', 'os['. $os['os_id'] .'][os_id]' ,$os['os_id'] ); |
|---|
| 229 | |
|---|
| 230 | $osArr[] = array( |
|---|
| 231 | "RowMenu_os_hidden"=>$hidden_os->toHtml(), |
|---|
| 232 | "RowMenu_select"=>$selectedElements->toHtml(), |
|---|
| 233 | "RowMenu_osname"=>$os["os_name"], |
|---|
| 234 | "RowMenu_use_default_template"=>$os["use_default_template"], |
|---|
| 235 | "RowMenu_template_select"=>$template_select_list->toHtml() |
|---|
| 236 | ); |
|---|
| 237 | } |
|---|
| 238 | $o = "w"; |
|---|
| 239 | $valid = true; |
|---|
| 240 | $form->freeze(); |
|---|
| 241 | |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | if (!$form->validate() && isset($_POST["nopt_id"])) { |
|---|
| 245 | print("<div class='msg' align='center'>".$lang["quickFormError"]."</div>"); |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | $form->addElement("button", "change", $lang['modify'], array("onClick"=>"javascript:window.location.href='?p=".$p."&o=nmapxmlimport'")); |
|---|
| 249 | |
|---|
| 250 | # |
|---|
| 251 | ##Apply a template definition |
|---|
| 252 | # |
|---|
| 253 | |
|---|
| 254 | $renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl); |
|---|
| 255 | $renderer->setRequiredTemplate('{$label} <font color="red" size="1">*</font>'); |
|---|
| 256 | $renderer->setErrorTemplate('<font color="red">{$error}</font><br />{$html}'); |
|---|
| 257 | $form->accept($renderer); |
|---|
| 258 | $tpl->assign("osArr", $osArr); |
|---|
| 259 | |
|---|
| 260 | $tpl->assign("headerMenu_use_default_template", $lang["xh_header_use_default_template"] ); |
|---|
| 261 | $tpl->assign("headerMenu_nmap_template", $lang["xh_header_nmap_template"]); |
|---|
| 262 | $tpl->assign("headerMenu_nmap_os", $lang["xh_header_nmap_os"]); |
|---|
| 263 | $tpl->assign('limit', $limit); |
|---|
| 264 | |
|---|
| 265 | $tpl->assign('form', $renderer->toArray()); |
|---|
| 266 | $tpl->assign('o', $o); |
|---|
| 267 | $tpl->assign('valid', $valid); |
|---|
| 268 | $tpl->display("formNmapXmlImport.ihtml"); |
|---|
| 269 | ?> |
|---|