/gui/tools/filemanager/modules/advanced_ftpserver/advanced_ftpserver.inc.php

https://github.com/BenBE/ispCP · PHP · 257 lines · 73 code · 79 blank · 105 comment · 28 complexity · 211d2e7133d7fde364f3fa17d70f1bc0 MD5 · raw file

  1. <?php
  2. // -------------------------------------------------------------------------------
  3. // | net2ftp: a web based FTP client |
  4. // | Copyright (c) 2003-2009 by David Gartner |
  5. // | |
  6. // | This program is free software; you can redistribute it and/or |
  7. // | modify it under the terms of the GNU General Public License |
  8. // | as published by the Free Software Foundation; either version 2 |
  9. // | of the License, or (at your option) any later version. |
  10. // | |
  11. // -------------------------------------------------------------------------------
  12. // **************************************************************************************
  13. // **************************************************************************************
  14. // ** **
  15. // ** **
  16. function net2ftp_module_sendHttpHeaders() {
  17. // --------------
  18. // This function sends HTTP headers
  19. // --------------
  20. // global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
  21. } // end net2ftp_sendHttpHeaders
  22. // ** **
  23. // ** **
  24. // **************************************************************************************
  25. // **************************************************************************************
  26. // **************************************************************************************
  27. // **************************************************************************************
  28. // ** **
  29. // ** **
  30. function net2ftp_module_printJavascript() {
  31. // --------------
  32. // This function prints Javascript code and includes
  33. // --------------
  34. // global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
  35. // Code
  36. // echo "<script type=\"text/javascript\"><!--\n";
  37. // echo "//--></script>\n";
  38. // Include
  39. // echo "<script type=\"text/javascript\" src=\"". $net2ftp_globals["application_rootdir_url"] . "/modules/login/login.js\"></script>\n";
  40. } // end net2ftp_printJavascript
  41. // ** **
  42. // ** **
  43. // **************************************************************************************
  44. // **************************************************************************************
  45. // **************************************************************************************
  46. // **************************************************************************************
  47. // ** **
  48. // ** **
  49. function net2ftp_module_printCss() {
  50. // --------------
  51. // This function prints CSS code and includes
  52. // --------------
  53. global $net2ftp_settings, $net2ftp_globals;
  54. // Include
  55. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"". $net2ftp_globals["application_rootdir_url"] . "/skins/" . $net2ftp_globals["skin"] . "/css/main.css.php?ltr=" . __("ltr") . "&amp;image_url=" . urlEncode2($net2ftp_globals["image_url"]) . "\" />\n";
  56. } // end net2ftp_printCssInclude
  57. // ** **
  58. // ** **
  59. // **************************************************************************************
  60. // **************************************************************************************
  61. // **************************************************************************************
  62. // **************************************************************************************
  63. // ** **
  64. // ** **
  65. function net2ftp_module_printBodyOnload() {
  66. // --------------
  67. // This function prints the <body onload="" actions
  68. // --------------
  69. // global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
  70. // echo "";
  71. } // end net2ftp_printBodyOnload
  72. // ** **
  73. // ** **
  74. // **************************************************************************************
  75. // **************************************************************************************
  76. // **************************************************************************************
  77. // **************************************************************************************
  78. // ** **
  79. // ** **
  80. function net2ftp_module_printBody() {
  81. // --------------
  82. // This function prints the login screen
  83. // --------------
  84. // -------------------------------------------------------------------------
  85. // Global variables
  86. // -------------------------------------------------------------------------
  87. global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output;
  88. if (isset($_POST["troubleshoot_ftpserver"]) == true) { $troubleshoot_ftpserver = validateFtpserver($_POST["troubleshoot_ftpserver"]); }
  89. else { $troubleshoot_ftpserver = ""; }
  90. if (isset($_POST["troubleshoot_ftpserverport"]) == true) { $troubleshoot_ftpserverport = validateFtpserverport($_POST["troubleshoot_ftpserverport"]); }
  91. else { $troubleshoot_ftpserverport = ""; }
  92. if (isset($_POST["troubleshoot_username"]) == true) { $troubleshoot_username = validateUsername($_POST["troubleshoot_username"]); }
  93. else { $troubleshoot_username = ""; }
  94. if (isset($_POST["troubleshoot_password"]) == true) { $troubleshoot_password = validatePassword($_POST["troubleshoot_password"]); }
  95. else { $troubleshoot_password = ""; }
  96. if (isset($_POST["troubleshoot_directory"]) == true) { $troubleshoot_directory = validateDirectory($_POST["troubleshoot_directory"]); }
  97. else { $troubleshoot_directory = "/"; }
  98. if (isset($_POST["troubleshoot_passivemode"]) == true) { $troubleshoot_passivemode = validatePassivemode($_POST["troubleshoot_passivemode"]); }
  99. else { $troubleshoot_passivemode = ""; }
  100. $troubleshoot_ftpserver_html = htmlEncode2($troubleshoot_ftpserver);
  101. $troubleshoot_ftpserverport_html = htmlEncode2($troubleshoot_ftpserverport);
  102. $troubleshoot_username_html = htmlEncode2($troubleshoot_username);
  103. $troubleshoot_directory_html = htmlEncode2($troubleshoot_directory);
  104. $troubleshoot_passivemode_html = htmlEncode2($troubleshoot_passivemode);
  105. // -------------------------------------------------------------------------
  106. // Variables for all screens
  107. // -------------------------------------------------------------------------
  108. // Title
  109. $title = __("Troubleshoot an FTP server");
  110. // Form name
  111. $formname = "AdvancedForm";
  112. // -------------------------------------------------------------------------
  113. // Variables for screen 1
  114. // -------------------------------------------------------------------------
  115. if ($net2ftp_globals["screen"] == 1) {
  116. // Next screen
  117. $nextscreen = 2;
  118. // Back and forward buttons
  119. $back_onclick = "document.forms['" . $formname . "'].state.value='advanced';document.forms['" . $formname . "'].screen.value='1';document.forms['" . $formname . "'].submit();";
  120. $forward_onclick = "document.forms['" . $formname . "'].submit();";
  121. } // end if
  122. // -------------------------------------------------------------------------
  123. // Variables for screen 2
  124. // -------------------------------------------------------------------------
  125. elseif ($net2ftp_globals["screen"] == 2) {
  126. // Back and forward buttons
  127. $back_onclick = "document.forms['" . $formname . "'].state.value='advanced_ftpserver'; document.forms['" . $formname . "'].submit();";
  128. // Initial checks
  129. if ($troubleshoot_passivemode != "yes") { $troubleshoot_passivemode = "no"; }
  130. // Connect
  131. setStatus(1, 10, __("Connecting to the FTP server"));
  132. $conn_id = ftp_connect("$troubleshoot_ftpserver", $troubleshoot_ftpserverport);
  133. // Login with username and password
  134. setStatus(2, 10, __("Logging into the FTP server"));
  135. $ftp_login_result = ftp_login($conn_id, $troubleshoot_username, $troubleshoot_password);
  136. // Passive mode
  137. if ($troubleshoot_passivemode == "yes") {
  138. setStatus(3, 10, __("Setting the passive mode"));
  139. $ftp_pasv_result = ftp_pasv($conn_id, TRUE);
  140. }
  141. else {
  142. $ftp_pasv_result = true;
  143. }
  144. // Get the FTP system type
  145. setStatus(4, 10, __("Getting the FTP system type"));
  146. $ftp_systype_result = ftp_systype($conn_id);
  147. // Change the directory
  148. setStatus(5, 10, __("Changing the directory"));
  149. $ftp_chdir_result = ftp_chdir($conn_id, $troubleshoot_directory);
  150. // Get the current directory from the FTP server
  151. setStatus(6, 10, __("Getting the current directory"));
  152. $ftp_pwd_result = ftp_pwd($conn_id);
  153. // Try to get a raw list
  154. setStatus(7, 10, __("Getting the list of directories and files"));
  155. $ftp_rawlist_result = ftp_rawlist($conn_id, "-a");
  156. if (sizeof($ftp_rawlist_result) <= 1) {
  157. $ftp_rawlist_result = ftp_rawlist($conn_id, "");
  158. }
  159. // Parse the list
  160. setStatus(8, 10, __("Parsing the list of directories and files"));
  161. for($i=0; $i<sizeof($ftp_rawlist_result); $i++) {
  162. $parsedlist[$i] = ftp_scanline($troubleshoot_directory, $ftp_rawlist_result[$i]);
  163. } // end for
  164. // Quiting; ftp_quit doesn't return a value
  165. setStatus(9, 10, __("Logging out of the FTP server"));
  166. ftp_quit($conn_id);
  167. } // end if
  168. // -------------------------------------------------------------------------
  169. // Print the output
  170. // -------------------------------------------------------------------------
  171. setStatus(10, 10, __("Printing the result"));
  172. require_once($net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php");
  173. } // End net2ftp_printBody
  174. // ** **
  175. // ** **
  176. // **************************************************************************************
  177. // **************************************************************************************
  178. ?>