selectXmlNodeOperation.jsp
6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/templetecheck/filecheck/CheckUserIsSysadmin.jsp" %>
<%@ page import="java.util.*,java.io.*,org.dom4j.io.*" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="org.dom4j.*" %>
<%@ page import="weaver.templetecheck.*"%>
<%@ page import="weaver.general.GCONST"%>
<%@ page import="weaver.security.file.FileType" %>
<%@ page import="weaver.hrm.*,weaver.general.*" %>
<%
response.setHeader("cache-control", "no-cache");
response.setHeader("pragma", "no-cache");
response.setHeader("expires", "Mon 1 Jan 1990 00:00:00 GMT");
User user = HrmUserVarify.getUser(request,response);
if(user == null) return ;
String from = request.getParameter("from");
ConfigBakUtil fileBakUtil = new ConfigBakUtil();
FileUtil fileUtil = new FileUtil();
if("updateConfig".equals(from)){
String nodeid = request.getParameter("nodeid");
String tabtype = request.getParameter("tabtype");
String content = "";
String ruleid = request.getParameter("ruleid");
String path = request.getParameter("path");
if(!"".equals(tabtype)&&!"".equals(ruleid)) {
CheckUtil checkutil = new CheckUtil();
List<Map<String,String>> rulemap = checkutil.getRuleById(tabtype, ruleid,"","");
if(rulemap.size() > 0) {
Map<String,String> map = rulemap.get(0);
content = map.get("replacecontent");
content = content.replaceAll("<","<");
content = content.replaceAll(">",">");
content = content.replaceAll(""","\"");
content = content.replaceAll("'","'");
content = content.replaceAll(" "," ");
content = content.replaceAll("\\\\r|\\\\n","");
}
}else{
String detailid = request.getParameter("detailid");
RecordSet rs = new RecordSet();
String sql = "select a.attrvalue,b.filepath from configXmlFile a,configFileManager b where a.configfileid = b.id and a.id="+detailid+" and a.attrvalue is not null order by b.filepath";
rs.execute(sql);
if(rs.next()) {
content = rs.getString("attrvalue");
path = rs.getString("filepath");
}
}
if(!"".equals(tabtype)&&!"".equals(ruleid)) {
} else {
path = GCONST.getRootPath() + path;//配置文件信息维护检测配置,地址存放的是相对路径,需要添加项目路径
}
ArrayList<String> types = new ArrayList<String>();
types.add(".xml");
types.add(".jsp");
types.add(".js");
types.add(".html");
types.add(".css");
types.add(".properties");
types.add(".java");
if(!FileType.validateFileExt(path,types)) {
out.print("{\"status\":\"no\"}");
return;
}
//备份即将修改的文件
String targetPath = fileBakUtil.getBakRootPath()+path;
String sourcePath = GCONST.getRootPath() + path;
fileBakUtil.copyFile(sourcePath, targetPath);
selectXmlNodeUtil xml2ArrayList = new selectXmlNodeUtil(path);
String res = xml2ArrayList.addNode(nodeid,content);
out.print(res);
}
if("autoChangeXmlNodeConfig".equals(from)){
String detailid = Util.null2String(request.getParameter("detailid"));
String operate = Util.null2String(request.getParameter("operate"));
String path = "";//文件路径
String content = "";//配置内容
String xpath = "";//配置路径
FileOutputStream fw = null;
XMLWriter writer = null;
ReadXml readXml = new ReadXml();
try{
RecordSet rs = new RecordSet();
String sql = "select a.attrvalue,a.xpath,b.filepath from configXmlFile a,configFileManager b where a.configfileid = b.id and a.id="+detailid+" and a.attrvalue is not null order by b.filepath";
// String sql = "select a.attrvalue,b.filepath from configXmlFile a,configFileManager b where a.configfileid = b.id and a.issystem = '1' and a.id="+detailid+" and a.attrvalue is not null "+(rs.getDBType().equals("oracle")?"":" and a.attrvalue <>'' ")+" order by b.filepath";
rs.execute(sql);
if(rs.next()) {
content = rs.getString("attrvalue");
path = rs.getString("filepath");
xpath = rs.getString("xpath").replace("'","\'");
}else{
out.print("{\"status\":\"no\"}") ;
return;
}
selectXmlNodeUtil util = new selectXmlNodeUtil(GCONST.getRootPath() +path);
Document doc = null;
File file = null;
try {
if(doc == null) {
doc = readXml.read(GCONST.getRootPath() + path);
}
} catch (Exception e) {
e.printStackTrace();
}
//备份即将修改的文件
String targetPath = fileBakUtil.getBakRootPath()+path;
String sourcePath = GCONST.getRootPath() + path;
fileBakUtil.copyFile(sourcePath, targetPath);
String handleResult="";
// content = content.replaceAll("\r|\n","").replaceAll(">\\s+",">").replaceAll("\\s+<","<").replaceAll("\\s\\s+"," ");
content = util.changeStr2(content);
if(operate.equals("2")){
handleResult = util.deleteConfig(content,GCONST.getRootPath() + path,xpath);
} else{
handleResult = util.autoConfig(xpath,doc,content);
if(doc != null) {
//替换空命名空间
doc = util.transformDocument(doc);
fw = new FileOutputStream(fileUtil.getPath(GCONST.getRootPath() +path));
OutputFormat format = OutputFormat.createPrettyPrint();
String fileEncoding = readXml.getFileEncode().equals("")?"UTF-8":readXml.getFileEncode();
format.setEncoding(fileEncoding);
format.setIndent(true);
format.setIndent(" ");
writer = new XMLWriter(fw,format);
writer.write(doc);
}
}
if("ok".equals(handleResult)){
out.print("{\"status\":\"ok\"}") ;
}else{
out.print("{\"status\":\"no\"}");
}
return ;
} catch(Exception e) {
e.printStackTrace();
out.print("{\"status\":\"no\"}") ;
return;
} finally {
if(writer != null) {
writer.flush();
}
if(fw != null){
fw.flush();
}
if(writer != null) {
writer.close();
}
if(fw != null) {
fw.close();
}
}
}
if("needRestart".equals(from)){
String detailid = Util.null2String(request.getParameter("detailid"));
if(detailid==null){
out.print("{\"status\":\"no\",\"msg\":\"无法获取记录的id\"}");
return;
}
if(detailid.endsWith(",")){
detailid = detailid.substring(0,detailid.length()-1);
}
boolean needRestart = false;
RecordSet rs = new RecordSet();
String sql1 = "select b.filename from configXmlFile a left join configFileManager b on a.configfileid = b.id where a.id in ("+detailid+")";
rs.execute(sql1);
while(rs.next()){
if(Util.null2String(rs.getString("filename")).toLowerCase().endsWith("web.xml")){
needRestart = true;
break;
}
}
if(needRestart){
out.print("{\"status\":\"ok\"}");
return;
}else{
out.print("{\"status\":\"no\"}");
return;
}
}
%>