$data['status'] = 'error'; $data['data'] = _('Error! XML file not updated (1)'); echo json_encode($data); } else { $xml = new Xml_parser($lk_name); $output = $xml->array2xml($tree); $output = Ossec_utilities::formatOutput($output, $lk_name); $output = utf8_decode($output); try { Ossec::set_rule_file($sensor_id, $file, $output); $tree = Ossec::get_tree($sensor_id, $file); $tree_json = Ossec_utilities::array2json($tree, $file); $_SESSION['_tree_json'] = $tree_json; $_SESSION['_tree'] = $tree; } catch (Exception $e) { $data['status'] = 'error'; $data['data'] = $e->getMessage(); } } } if ($data['status'] == 'error') { //Restore copy @copy($path_tmp, $rule_file); $_SESSION['_tree'] = $tree_cp; $_SESSION['_tree_json'] = Ossec_utilities::array2json($tree_cp, $file); } else { $data['status'] = 'success'; $data['data'] = _('XML file update successfully') . '###' . base64_encode($tree_json); echo json_encode($data); } @unlink($path_tmp);
exit; } if (!Ossec::is_editable($file)) { $data['status'] = 'error'; $data['data'] = _('Error! File not editable'); echo json_encode($data); exit; } $_SESSION['_current_file'] = $file; $lk_name = $_SESSION['lk_name']; $new_xml_data = html_entity_decode(base64_decode($new_xml_data), ENT_QUOTES, 'UTF-8'); $xml_obj = new Xml_parser($lk_name); $xml_obj->load_string($new_xml_data); if ($xml_obj->errors['status'] == FALSE) { $data['status'] = 'error'; $data['data'] = "<div id='parse_errors'>\n <span style='font-weight: bold;'>" . _('Data in XML file with wrong format') . " <a onclick=\"\$('#msg_errors').toggle();\"> [" . _('View errors') . "]</a></span>\n <br/><div id='msg_errors'>" . implode('', $xml_obj->errors['msg']) . "</div>\n </div>"; } else { try { Ossec::set_rule_file($sensor_id, $file, $new_xml_data); $array_xml = $xml_obj->xml2array(); $tree_json = Ossec_utilities::array2json($array_xml, $file); $_SESSION['_tree_json'] = $tree_json; $_SESSION['_tree'] = $array_xml; $data['data'] = _("{$file} updated successfully") . '###' . base64_encode($tree_json); } catch (Exception $e) { $data['status'] = 'error'; $data['data'] = $e->getMessage(); } } echo json_encode($data); exit;
ossim_valid($file, OSS_ALPHA, OSS_SCORE, OSS_DOT, 'illegal:' . _('File')); if (!ossim_error()) { $db = new ossim_db(); $conn = $db->connect(); if (!Ossec_utilities::is_sensor_allowed($conn, $sensor_id)) { ossim_set_error(_('Error! Sensor not allowed')); } $db->close(); } if (ossim_error()) { $data['status'] = 'error'; $data['data'] = _('We found the followings errors:') . "<div style='padding-left: 15px; text-align:left;'>" . ossim_get_error_clean() . '</div>'; echo json_encode($data); exit; } //Set current file $_SESSION['_current_file'] = $file; $_SESSION['lk_name'] = Ossec::get_key_name($file); try { $tree = Ossec::get_tree($sensor_id, $file); $tree_json = Ossec_utilities::array2json($tree, $file); $_SESSION['_tree_json'] = $tree_json; $_SESSION['_tree'] = $tree; $data['status'] = 'success'; $data['data'] = _('Click on a branch to display a node') . '###' . base64_encode($tree_json); } catch (Exception $e) { $data['status'] = 'error'; $data['data'] = $e->getMessage(); } echo json_encode($data); exit;