| Author |
why does it hang?
|
kevin yeandel
Greenhorn
Joined: May 16, 2012
Posts: 3
|
|
Hi
I spent about 3 hours on this and am going off my head...
I have a jsp setting params then calling another jsp:
test-getobjectunix.jsp
<jsp:forward page="getobjectunix.jsp">
<jsp:param name="command" value=" \". ~/.bash_profile ; echo -e 'dump,c,3d12d68a80000102' | iapi repo -Udmadmin -P\"" />
<jsp:param name="password" value="123456"/>
<jsp:param name="servername" value="example.com"/>
<jsp:param name="noCache" value="0900getobjecttest"/>
<jsp:param name="user" value="dmadmin"/>
</jsp:forward>
getobjectunix.jsp
<%@ page import="java.io.*" %>
<HTML><BODY>
<%
String ret = "C:\\tomcat\\apache-tomcat-7.0.25\\webapps\\mydoc\\logs\\tmp_"+request.getParameter("servername") +request.getParameter("noCache") + ".txt";
Runtime rt=Runtime.getRuntime();
String cmd[]={"cmd.exe","/k","C:\\tomcat\\apache-tomcat-7.0.25\\plink.exe -pw " + request.getParameter("password") + " " + request.getParameter("user") +"@" +request.getParameter("servername")+ " " + request.getParameter("command")};
Process unix_proc=rt.exec(cmd);
%>
<%=ret%>
</BODY></HTML>
What is actually being passed to the command shell is
C:\tomcat\apache-tomcat-7.0.25\plink.exe -pw 123456 dmadmin@example.com ". ~/.bash_profile ; echo -e 'dump,c,3d12d68a80000102' | iapi repo -Udmadmin -P"
If I run that from the command line the contents are displayed as expected. If I call the test-getunixobject.jsp from the browser nothing much happens... is there something very obvious here that I am missing?
Many thanks in advance...
Kevin
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56177
|
|
Welcome to the Ranch!
Why on Earth are you doing processing in a JSP? Especially firing off a separate process?
First step: move the Java code in the second JSP to a servlet where it belongs. Then it'll be a lot easier to diagnose.
Let us know when you've got that done and repost the new code. (Be sure to read UseCodeTags first.)
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
kevin yeandel
Greenhorn
Joined: May 16, 2012
Posts: 3
|
|
It's not a servlet because java isn't my bag and doing it in jsp is easier for someone like me :)
I'll look into putting it into a class.
Apart from debugging.. I would like to know what you mean by "where it belongs"...
Thanks
Kevin
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56177
|
|
Java code in a JSP has been discredited for over 10 years now. It is considered a really poor and lazy practice.
See: http://www.coderanch.com/how-to/java/WhyNotUseScriptlets
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
And while you're moving the Runtime.exec code to a servlet, read When Runtime.exec() won't.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
kevin yeandel
Greenhorn
Joined: May 16, 2012
Posts: 3
|
|
Thank you all for your help.
The problem was that since Tomcat was running as Default User, the remote server challenged for an RSA key - which it wouldn't normally do if Default User had previously logged into the Unix server. So I had to copy the rsa registry keys from
[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY]
to
[HKEY_USERS\.DEFAULT\Software\SimonTatham\PuTTY]
to bypass a challenge.
Unfortunately my Java skills are not exactly my "selling point" but I still had to solve an admin problem in the short term.
In the longer term, can you just advise me:
I had a look at servlet/RequestParamExample code and it seems to be a good starting point for building the class
Could I use my jsp forward to call the class with some params? I'm currently calling the JSP with Adobe FlashBuilder's HTTPService.
Many thanks again
Kevin
|
 |
 |
|
|
subject: why does it hang?
|
|
|