Source Code Cross Referenced for SshShellServlet.java in  » Net » ssh-web-proxy » com » ericdaugherty » sshwebproxy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » ssh web proxy » com.ericdaugherty.sshwebproxy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * $Source: /cvsroot/sshwebproxy/src/java/com/ericdaugherty/sshwebproxy/SshShellServlet.java,v $
003:         * $Revision: 1.2 $
004:         * $Author: edaugherty $
005:         * $Date: 2003/11/23 00:18:10 $
006:         ******************************************************************************
007:         * Copyright (c) 2003, Eric Daugherty (http://www.ericdaugherty.com)
008:         * All rights reserved.
009:         *
010:         * Redistribution and use in source and binary forms, with or without
011:         * modification, are permitted provided that the following conditions are met:
012:         *
013:         *     * Redistributions of source code must retain the above copyright notice,
014:         *       this list of conditions and the following disclaimer.
015:         *     * Redistributions in binary form must reproduce the above copyright
016:         *       notice, this list of conditions and the following disclaimer in the
017:         *       documentation and/or other materials provided with the distribution.
018:         *     * Neither the name of the Eric Daugherty nor the names of its
019:         *       contributors may be used to endorse or promote products derived
020:         *       from this software without specific prior written permission.
021:         *
022:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
023:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
024:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
025:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
026:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
027:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
028:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
029:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
030:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
031:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
032:         * THE POSSIBILITY OF SUCH DAMAGE.
033:         * *****************************************************************************
034:         * For current versions and more information, please visit:
035:         * http://www.ericdaugherty.com/dev/sshwebproxy
036:         *
037:         * or contact the author at:
038:         * web@ericdaugherty.com
039:         *****************************************************************************/package com.ericdaugherty.sshwebproxy;
040:
041:        import org.apache.commons.logging.Log;
042:        import org.apache.commons.logging.LogFactory;
043:
044:        import javax.servlet.http.HttpServletRequest;
045:        import javax.servlet.http.HttpServletResponse;
046:        import javax.servlet.http.HttpServlet;
047:        import javax.servlet.ServletException;
048:        import java.io.IOException;
049:
050:        /**
051:         * Handles interaction between the ShellChannel and the UI.
052:         *
053:         * @author Eric Daugherty
054:         */
055:        public class SshShellServlet extends HttpServlet implements 
056:                SshConstants {
057:
058:            //***************************************************************
059:            // Variables
060:            //***************************************************************
061:
062:            /** Logger */
063:            private static final Log log = LogFactory
064:                    .getLog(SshShellServlet.class);
065:
066:            //***************************************************************
067:            // HTTPServlet Methods
068:            //***************************************************************
069:
070:            protected void doGet(HttpServletRequest request,
071:                    HttpServletResponse response) throws ServletException,
072:                    IOException {
073:                log.warn("doGet called, but is not implemented.");
074:                response.sendRedirect(PAGE_HOME);
075:            }
076:
077:            /**
078:             * Handles requests from the SHH client JSP page.  All requests from
079:             * that page should be via POST.
080:             *
081:             * @param request
082:             * @param response
083:             * @throws ServletException
084:             * @throws IOException
085:             */
086:            protected void doPost(HttpServletRequest request,
087:                    HttpServletResponse response) throws ServletException,
088:                    IOException {
089:
090:                // Validate login.
091:                SshSession sshSession = new SshSession(request);
092:                if (!sshSession.isValid()) {
093:                    response.sendRedirect(SshConstants.PAGE_LOGIN);
094:                    return;
095:                }
096:
097:                String action = request.getParameter(PARAMETER_ACTION);
098:
099:                // Verify we received an action to perform.
100:                if (action == null || action.trim().length() == 0) {
101:                    log
102:                            .warn("POST Request received without an action parameter.");
103:                    response.sendRedirect(PAGE_HOME);
104:                }
105:
106:                action = action.trim();
107:                if (ACTION_WRITE.equals(action)) {
108:                    if (request.getParameter("write") != null) {
109:                        write(request, response, false);
110:                    } else if (request.getParameter("writeline") != null) {
111:                        write(request, response, true);
112:                    } else {
113:                        log
114:                                .warn("Invalid write request recieved.  Request does not contain write or writeline parameter.");
115:                        response.sendRedirect(PAGE_HOME);
116:                    }
117:                } else {
118:                    log
119:                            .warn("POST Request received with an invalid action parameter: "
120:                                    + action);
121:                    response.sendRedirect(PAGE_HOME);
122:                }
123:            }
124:
125:            //***************************************************************
126:            // Private Action Handlers
127:            //***************************************************************
128:
129:            /**
130:             * Write data to a channel.
131:             * @param request
132:             * @param response
133:             * @param sendNewLine
134:             * @throws IOException
135:             */
136:            private void write(HttpServletRequest request,
137:                    HttpServletResponse response, boolean sendNewLine)
138:                    throws IOException {
139:                log.debug("Write request received.");
140:
141:                SshSession session = new SshSession(request);
142:                String connectionInfo = request.getParameter("connection");
143:                String channelId = request.getParameter("channel");
144:                boolean valid = false;
145:
146:                // Get the Channel and write to it.
147:                SshConnection sshConnection = session
148:                        .getSshConnection(connectionInfo);
149:                ShellChannel shellChannel = null;
150:                if (sshConnection != null) {
151:                    shellChannel = sshConnection.getShellChannel(channelId);
152:                    if (shellChannel != null) {
153:                        String data = request.getParameter("data");
154:                        shellChannel.write(data, sendNewLine);
155:                        valid = true;
156:                    }
157:                }
158:
159:                // Redirect to the result page.
160:                if (valid) {
161:                    response.sendRedirect(shellChannel.getPage());
162:                    if (log.isDebugEnabled())
163:                        log.debug("Successful Write to " + connectionInfo + " "
164:                                + channelId);
165:                } else {
166:                    log.info("Write request to invalid channel.");
167:                    session.setErrorMessage("Invalid connection or channel.");
168:                    response.sendRedirect(PAGE_HOME);
169:                }
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.