ftp.html 14 KB

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