$tree_lr = $_SESSION["_tree"]; $tree_cp = $_SESSION["_tree"]; $child = getChild($tree_lr, $__level_key); $new_key = null; $error = false; if (@copy($path, $path_tmp) == false) { echo "2###" . _("Failure to update XML File") . " (1)"; exit; } $result = test_conf(); if ($result !== true) { echo "4###" . $result; exit; } $file_to_text = file_get_contents($path, false); $_level_key_name = set_key_name($_level_key_name, $file_to_text); $new_rule['rule'] = $child['tree']; //Tree local_rules.xml $xml_obj = new xml($_level_key_name); $xml_obj->load_file($path); $tree_lr = $xml_obj->xml2array(); foreach ($tree_lr as $k => $v) { if (isset($tree_lr[$k]['group'])) { $__level_key = $tree_lr[$k]['group']['@attributes']['__level_key']; $child = getChild($tree_lr, $__level_key); $keys = array_keys($child['tree']); if (is_numeric($keys[count($keys) - 1])) { $aux_key = $keys[count($keys) - 1] + 1; $new_key = !in_array($aux_key, $keys) ? $aux_key : uniqid(mt_rand("1", mt_getrandmax())); } else { $new_key = uniqid(mt_rand("1", mt_getrandmax()));
function getTree($file) { include_once 'classes/Xml_parser.inc'; include 'conf/_conf.php'; $_SESSION["_current_file"] = $file; $filename = $rules_file . $file; if (file_exists($filename)) { $file_xml = @file_get_contents($filename, false); $_level_key_name = set_key_name($_level_key_name, $file_xml); $_SESSION['_level_key_name'] = $_level_key_name; if ($file_xml == false) { return "2###" . _("Failure to read XML file"); } else { $result = test_conf(); if ($result !== true) { return "3###<div class='errors_ossec'>{$result}</div>"; } $xml_obj = new xml($_level_key_name); $xml_obj->load_file($filename); return $xml_obj->xml2array(); } } else { return "2###" . _("XML file not found"); } }
$error_conf = null; $_SESSION["_current_file"] = $editable_files[0]; if (file_exists($filename)) { $result = test_conf(); if ($result !== true) { $error = true; $link_txt = _("Configuration error in file") . " " . basename($ossec_conf) . " " . _("and/or") . " " . $editable_files[0]; $info_conf = "<span style='font-weight: bold;'>{$link_txt}<a onclick=\"\$('#msg_errors').toggle();\"> [" . _("View errors") . "]</a><br/></span>"; $info_conf .= "<div id='msg_errors'>{$result}</div>"; $error_conf = "<div id='parse_errors' class='oss_error'>{$info_conf}</div>"; } else { $file_xml = @file_get_contents($filename, false); if ($file_xml === false) { $error = true; } else { $_level_key_name = set_key_name($_level_key_name, $file_xml); $_SESSION['_level_key_name'] = $_level_key_name; $xml_obj = new xml($_level_key_name); $xml_obj->load_file($filename); $array_xml = $xml_obj->xml2array(); $tree_json = array2json($array_xml, $filename); $_SESSION['_tree_json'] = $tree_json; $_SESSION['_tree'] = $array_xml; $file_xml = clean_string($file_xml); } } } else { $error = true; } if ($error == true) { $file_xml = '';