ftp.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!--
  5. <meta name="mobile-web-app-capable" content="yes">
  6. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  7. <meta charset="UTF-8">
  8. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  9. <script src="../../script/jquery.min.js"></script>
  10. <script src="../../script/semantic/semantic.min.js"></script>
  11. -->
  12. <style>
  13. .hidden{
  14. display:none;
  15. }
  16. .disabled{
  17. opacity: 0.5;
  18. pointer-events: none;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="ui form">
  24. <!--
  25. <div class="field">
  26. <div class="ui toggle checkbox">
  27. <input id="enabled" type="checkbox" name="enable" onchange="toggleFTPServer(this.checked);">
  28. <label>Enable FTP Server</label>
  29. </div>
  30. </div>
  31. -->
  32. <div class="field">
  33. <div class="ui toggle checkbox">
  34. <input id="useUPNP" type="checkbox" name="upnp" onchange="toggleUPNP(this.checked);">
  35. <label>Enable UPnP on FTP Server Port</label>
  36. <small>Aka Auto Port Forwarding. Disable this option if you are connecting within Local Area Network</small>
  37. </div>
  38. </div>
  39. <div class="field">
  40. <label>Listening Port</label>
  41. <div class="ui labeled input">
  42. <input id="listeningPort" type="number" placeholder="21" min="21" onchange="updateFTPPort(this.value)">
  43. </div>
  44. </div>
  45. <div class="field">
  46. <label>Enable FTP access to the following user groups: </label>
  47. <select id="grouplist" name="groups" multiple="" class="ui fluid dropdown">
  48. <option value="">User Groups</option>
  49. </select>
  50. <small><a href="../vendor/public/ftpForAdmin.html" target="_blank">Why enable FTP on administrator account is not a good idea?</a></small>
  51. </div>
  52. <div class="field">
  53. <button onclick="updateGroupAccess();" class="ui secondary right floated button">Update Access Policy</button>
  54. </div>
  55. <br><br>
  56. <div id="ok" class="ui secondary inverted green segment" style="display:none;">
  57. <i class="checkmark icon"></i> Setting Applied
  58. </div>
  59. <div id="error" class="ui secondary inverted red segment" style="display:none;">
  60. <i class="remove icon"></i> <span class="msg">Something went wrong</span>
  61. </div>
  62. <div class="ui divider"></div>
  63. <h4>Advance Options</h4>
  64. <br>
  65. <div class="field">
  66. <div class="ui toggle checkbox">
  67. <input id="passiveMode" type="checkbox" name="passivemode" onchange="handlePassiveModeChange(this.checked);">
  68. <label>Force Passive Mode</label>
  69. <small>Required under UPnP mode. Optional in default mode with manual port forwarding in gateway router</small>
  70. </div>
  71. </div>
  72. <div class="field">
  73. <label>Passive Mode Public IP Address</label>
  74. <div class="ui labeled input">
  75. <input id="publicip" type="text">
  76. </div>
  77. <small>The public IP address of your NAT router. Currently only support IP address.</small>
  78. </div>
  79. <div class="field">
  80. <button onclick="updatePublicIPSetting();" class="ui secondary right floated button">Update Public IP Setting</button>
  81. </div>
  82. </div>
  83. <br><br>
  84. <script>
  85. var serverAllowUPNP = false;
  86. var isMac = navigator.platform.indexOf('Mac') > -1;
  87. var isWindows = navigator.platform.indexOf('Win') > -1;
  88. if (isMac){
  89. $(".maconly").show();
  90. }else if (isWindows){
  91. $(".windowsonly").show();
  92. }
  93. $(document).ready(function(){
  94. //Load usergroups
  95. $.get("../../system/permission/listgroup", function(data){
  96. if (data.error !== undefined){
  97. console.log(data.error);
  98. }else{
  99. data.forEach(group => {
  100. $("#grouplist").append(` <option value="${group}">${group}</option>`);
  101. });
  102. }
  103. $(".ui.dropdown").dropdown();
  104. //Init server status
  105. //Update done by service.html
  106. initFTPServerStatus();
  107. });
  108. });
  109. function initFTPServerStatus(){
  110. //Load current system status
  111. $.get("../../system/storage/ftp/status", function(data){
  112. if (data.error !== undefined){
  113. console.log(data.error);
  114. }else{
  115. if (data.Enabled == true){
  116. //$("#enabled")[0].checked = true;
  117. $("#useUPNP").parent().removeClass("disabled");
  118. }else{
  119. $("#listeningPort").parent().addClass("disabled");
  120. $("#useUPNP").parent().addClass("disabled");
  121. }
  122. $("#listeningPort").val(data.Port);
  123. $(".port").text(data.Port);
  124. if (data.AllowUPNP == false){
  125. $("#useUPNP").parent().addClass("disabled");
  126. serverAllowUPNP = false;
  127. }else{
  128. $("#useUPNP").parent().removeClass("disabled");
  129. serverAllowUPNP = true;
  130. }
  131. if (data.FTPUpnpEnabled == true){
  132. $("#useUPNP")[0].checked = true;
  133. //Disable the chnage of force passive mode and public ip address
  134. $("#passiveMode")[0].checked = true;
  135. $("#passiveMode").parent().addClass("disabled");
  136. $("#publicip").val(data.PublicAddr);
  137. $("#publicip").parent().addClass("disabled");
  138. }else{
  139. $("#useUPNP")[0].checked = false;
  140. //Restore to non UPnP passive mode setting
  141. $("#passiveMode")[0].checked = data.PassiveMode;
  142. $("#passiveMode").parent().removeClass("disabled");
  143. $("#publicip").val(data.PublicAddr);
  144. $("#publicip").parent().removeClass("disabled");
  145. }
  146. if (data.UserGroups !== undefined){
  147. $('#grouplist').dropdown('set selected', data.UserGroups);
  148. }
  149. if (data.PassiveMode){
  150. $("#passiveMode")[0].checked = true;
  151. }else{
  152. $("#passiveMode")[0].checked = false;
  153. }
  154. if (data.PublicAddr != ""){
  155. $("#publicip").val(data.PublicAddr);
  156. }else{
  157. $("#publicip").val("");
  158. }
  159. }
  160. //Update tutorial information
  161. $(".hostname").text(window.location.hostname);
  162. });
  163. }
  164. function toggleFTPServer(enabled){
  165. if (enabled == true){
  166. $.get("../../system/storage/ftp/start", function(data){
  167. if (data.error != undefined){
  168. showError(data.error);
  169. }else{
  170. showOK();
  171. if (serverAllowUPNP){
  172. $("#useUPNP").parent().removeClass("disabled");
  173. }
  174. $("#listeningPort").parent().removeClass("disabled");
  175. }
  176. });
  177. }else{
  178. $.get("../../system/storage/ftp/stop", function(data){
  179. if (data.error != undefined){
  180. showError(data.error);
  181. }else{
  182. showOK();
  183. $("#useUPNP").parent().addClass("disabled");
  184. $("#listeningPort").parent().addClass("disabled");
  185. }
  186. });
  187. }
  188. }
  189. function toggleUPNP(enabled){
  190. if (enabled){
  191. $.get("../../system/storage/ftp/upnp?enable=true", function(data){
  192. if (data.error != undefined){
  193. showError(data.error);
  194. }else{
  195. setTimeout(function(){
  196. handleUpnpStateCheck(true);
  197. }, 1000);
  198. }
  199. });
  200. }else{
  201. $.get("../../system/storage/ftp/upnp?enable=false", function(data){
  202. if (data.error != undefined){
  203. showError(data.error);
  204. }else{
  205. setTimeout(function(){
  206. handleUpnpStateCheck(false);
  207. }, 1000);
  208. }
  209. });
  210. }
  211. }
  212. function handleUpnpStateCheck(expectedUPnPState){
  213. console.log("Checking UPNP Enabling State")
  214. $.get("../../system/storage/ftp/status",function(data){
  215. if (data.FTPUpnpEnabled == expectedUPnPState){
  216. //OK
  217. showOK();
  218. }else{
  219. //Show error
  220. showError("UPnP Port Forward Request Failed");
  221. $("#useUPNP")[0].checked = false;
  222. }
  223. initFTPServerStatus();
  224. });
  225. }
  226. function updateGroupAccess(){
  227. var groups = $("#grouplist").dropdown("get value");
  228. groups = JSON.stringify(groups)
  229. $.ajax({
  230. url: "../../system/storage/ftp/updateGroups",
  231. method: "POST",
  232. data: {"groups": groups},
  233. success: function(data){
  234. if (data.error != undefined){
  235. showError(data.error);
  236. }else{
  237. showOK();
  238. }
  239. }
  240. })
  241. }
  242. function updatePublicIPSetting(){
  243. var newip = $("#publicip").val();
  244. $.ajax({
  245. url: "../../system/storage/ftp/passivemode",
  246. data: {set: "ip", "ip": newip},
  247. success: function(data){
  248. if (data.error != undefined){
  249. showError(data.error);
  250. }else{
  251. showOK();
  252. }
  253. }
  254. })
  255. }
  256. function handlePassiveModeChange(value){
  257. $.ajax({
  258. url: "../../system/storage/ftp/passivemode",
  259. data: {set: "mode", "passive": value},
  260. success: function(data){
  261. if (data.error != undefined){
  262. showError(data.error);
  263. }else{
  264. showOK();
  265. }
  266. initFTPServerStatus();
  267. }
  268. })
  269. }
  270. function updateFTPPort(portNumber){
  271. if (portNumber < 21){
  272. showError("Port number must be > 21")
  273. return
  274. }
  275. $.ajax({
  276. url: "../../system/storage/ftp/setPort",
  277. data: {port: portNumber},
  278. success: function(data){
  279. if (data.error !== undefined){
  280. showError(data.error);
  281. }else{
  282. showOK();
  283. }
  284. }
  285. })
  286. }
  287. function showOK(){
  288. $("#ok").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  289. }
  290. function showError(msg){
  291. $("#error").find(".msg").text(msg);
  292. $("#error").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  293. }
  294. </script>
  295. </body>
  296. </html>