1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.smartlab.ssh;
24
25 import java.io.IOException;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionMapping;
30 import net.smartlab.web.ActionException;
31 import net.smartlab.web.BusinessException;
32 import net.smartlab.web.DynaAction;
33
34
35
36
37
38 public class ShellAction extends DynaAction {
39
40
41
42
43 public final static String SESSION_KEY = "net.smartlab.web.shell";
44
45
46
47
48
49
50
51
52
53
54
55
56 public String login(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping)
57 throws ActionException {
58 logger.info("login() - start");
59 Shell shell = new Shell();
60 super.valorize(form, shell, null);
61 try {
62 shell.open();
63 request.getSession().setAttribute(ShellAction.SESSION_KEY, shell);
64 logger.info("Connection established to " + shell);
65 return "success";
66 } catch (BusinessException be) {
67 logger.warn("Connection failed to " + shell);
68 return "error";
69 } catch (IOException ioe) {
70 throw new ActionException(ioe.getMessage(), ioe.getCause());
71 }
72 }
73
74
75
76
77
78
79
80
81
82
83 public String logout(ActionForm form, HttpServletRequest request, HttpServletResponse response,
84 ActionMapping mapping) throws ActionException {
85 logger.info("logout() - start");
86 Shell shell = (Shell)request.getSession().getAttribute(ShellAction.SESSION_KEY);
87 if (shell != null) {
88 shell.close();
89 request.getSession().removeAttribute(ShellAction.SESSION_KEY);
90 }
91 return "success";
92 }
93 }