ftp.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. </div>
  43. <div class="ui basic message maconly" style="display:none;">
  44. <h4 class="ui header">
  45. <i class="apple icon"></i>
  46. <div class="content">
  47. FTP Server Endpoint
  48. <div class="sub header">ftp://<span class="hostname"></span>:<span class="port"></span></div>
  49. </div>
  50. </h4>
  51. <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>
  52. </div>
  53. <div class="ui form">
  54. <div class="field">
  55. <div class="ui toggle checkbox">
  56. <input id="enabled" type="checkbox" name="enable" onchange="toggleFTPServer(this.checked);">
  57. <label>Enable FTP Server</label>
  58. </div>
  59. </div>
  60. <div class="field">
  61. <div class="ui toggle checkbox">
  62. <input id="useUPNP" type="checkbox" name="upnp" onchange="toggleUPNP(this.checked);">
  63. <label>Enable UPnP on FTP Server Port</label>
  64. <small>Aka Auto Port Forwarding. Disable this option if you are connecting within Local Area Network</small>
  65. </div>
  66. </div>
  67. <div class="field">
  68. <label>Listening Port</label>
  69. <div class="ui labeled input">
  70. <input id="listeningPort" type="number" placeholder="21" min="21" onchange="updateFTPPort(this.value)">
  71. </div>
  72. </div>
  73. <div class="field">
  74. <label>Enable FTP access to the following user groups: </label>
  75. <select id="grouplist" name="groups" multiple="" class="ui fluid dropdown">
  76. <option value="">User Groups</option>
  77. </select>
  78. <small><a href="../vendor/public/ftpForAdmin.html" target="_blank">Why enable FTP on administrator account is not a good idea?</a></small>
  79. </div>
  80. <div class="field">
  81. <button onclick="updateGroupAccess();" class="ui secondary right floated button">Update Access Policy</button>
  82. </div>
  83. <br><br>
  84. <div class="ui divider"></div>
  85. <h4>Advance Options</h4>
  86. <div class="ui message">
  87. <h4><i class="info circle icon"></i>FTP Usage under UPnP Mode</h4>
  88. <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>
  89. </div>
  90. <br>
  91. <div class="field">
  92. <div class="ui toggle checkbox">
  93. <input id="passiveMode" type="checkbox" name="passivemode" onchange="handlePassiveModeChange(this.checked);">
  94. <label>Force Passive Mode</label>
  95. <small>Enable this option if your server is hosted behind a NAT router, require manual port forwarding in router.</small>
  96. </div>
  97. </div>
  98. <div class="field">
  99. <label>Passive Mode Public IP Address</label>
  100. <div class="ui labeled input">
  101. <input id="publicip" type="text">
  102. </div>
  103. <small>The public IP address of your NAT router. Currently only support IP address.</small>
  104. </div>
  105. <div class="field">
  106. <button onclick="updatePublicIPSetting();" class="ui secondary right floated button">Update Public IP Setting</button>
  107. </div>
  108. </div>
  109. <br><br>
  110. </div>
  111. <script>
  112. var serverAllowUPNP = false;
  113. var isMac = navigator.platform.indexOf('Mac') > -1;
  114. var isWindows = navigator.platform.indexOf('Win') > -1;
  115. if (isMac){
  116. $(".maconly").show();
  117. }else if (isWindows){
  118. $(".windowsonly").show();
  119. }
  120. $(document).ready(function(){
  121. //Load usergroups
  122. $.get("../../system/permission/listgroup", function(data){
  123. if (data.error !== undefined){
  124. console.log(data.error);
  125. }else{
  126. data.forEach(group => {
  127. $("#grouplist").append(` <option value="${group}">${group}</option>`);
  128. });
  129. }
  130. $(".ui.dropdown").dropdown();
  131. //Init server status
  132. initFTPServerStatus();
  133. });
  134. });
  135. function initFTPServerStatus(){
  136. //Load current system status
  137. $.get("../../system/storage/ftp/status", function(data){
  138. if (data.error !== undefined){
  139. console.log(data.error);
  140. }else{
  141. if (data.Enabled == true){
  142. $("#enabled")[0].checked = true;
  143. $("#useUPNP").parent().removeClass("disabled");
  144. }else{
  145. $("#listeningPort").parent().addClass("disabled");
  146. $("#useUPNP").parent().addClass("disabled");
  147. }
  148. $("#listeningPort").val(data.Port);
  149. $(".port").text(data.Port);
  150. if (data.AllowUPNP == false){
  151. $("#useUPNP").parent().addClass("disabled");
  152. serverAllowUPNP = false;
  153. }else{
  154. $("#useUPNP").parent().removeClass("disabled");
  155. serverAllowUPNP = true;
  156. }
  157. if (data.FTPUpnpEnabled == true){
  158. $("#useUPNP")[0].checked = true;
  159. //Disable the chnage of force passive mode and public ip address
  160. $("#passiveMode")[0].checked = true;
  161. $("#passiveMode").parent().addClass("disabled");
  162. $("#publicip").val(data.PublicAddr);
  163. $("#publicip").parent().addClass("disabled");
  164. }else{
  165. $("#useUPNP")[0].checked = false;
  166. //Restore to non UPnP passive mode setting
  167. $("#passiveMode")[0].checked = data.PassiveMode;
  168. $("#passiveMode").parent().removeClass("disabled");
  169. $("#publicip").val(data.PublicAddr);
  170. $("#publicip").parent().removeClass("disabled");
  171. }
  172. if (data.UserGroups !== undefined){
  173. $('#grouplist').dropdown('set selected', data.UserGroups);
  174. }
  175. if (data.PassiveMode){
  176. $("#passiveMode")[0].checked = true;
  177. }else{
  178. $("#passiveMode")[0].checked = false;
  179. }
  180. if (data.PublicAddr != ""){
  181. $("#publicip").val(data.PublicAddr);
  182. }else{
  183. $("#publicip").val("");
  184. }
  185. }
  186. //Update tutorial information
  187. $(".hostname").text(window.location.hostname);
  188. });
  189. }
  190. function toggleFTPServer(enabled){
  191. if (enabled == true){
  192. $.get("../../system/storage/ftp/start", function(data){
  193. if (data.error != undefined){
  194. showError(data.error);
  195. }else{
  196. showOK();
  197. if (serverAllowUPNP){
  198. $("#useUPNP").parent().removeClass("disabled");
  199. }
  200. $("#listeningPort").parent().removeClass("disabled");
  201. }
  202. });
  203. }else{
  204. $.get("../../system/storage/ftp/stop", function(data){
  205. if (data.error != undefined){
  206. showError(data.error);
  207. }else{
  208. showOK();
  209. $("#useUPNP").parent().addClass("disabled");
  210. $("#listeningPort").parent().addClass("disabled");
  211. }
  212. });
  213. }
  214. }
  215. function toggleUPNP(enabled){
  216. if (enabled){
  217. $.get("../../system/storage/ftp/upnp?enable=true", function(data){
  218. if (data.error != undefined){
  219. showError(data.error);
  220. }else{
  221. setTimeout(function(){
  222. handleUpnpStateCheck(true);
  223. }, 1000);
  224. }
  225. });
  226. }else{
  227. $.get("../../system/storage/ftp/upnp?enable=false", function(data){
  228. if (data.error != undefined){
  229. showError(data.error);
  230. }else{
  231. setTimeout(function(){
  232. handleUpnpStateCheck(false);
  233. }, 1000);
  234. }
  235. });
  236. }
  237. }
  238. function handleUpnpStateCheck(expectedUPnPState){
  239. console.log("Checking UPNP Enabling State")
  240. $.get("../../system/storage/ftp/status",function(data){
  241. if (data.FTPUpnpEnabled == expectedUPnPState){
  242. //OK
  243. showOK();
  244. }else{
  245. //Show error
  246. showError("UPnP Port Forward Request Failed");
  247. $("#useUPNP")[0].checked = false;
  248. }
  249. initFTPServerStatus();
  250. });
  251. }
  252. function updateGroupAccess(){
  253. var groups = $("#grouplist").dropdown("get value");
  254. groups = JSON.stringify(groups)
  255. $.ajax({
  256. url: "../../system/storage/ftp/updateGroups",
  257. method: "POST",
  258. data: {"groups": groups},
  259. success: function(data){
  260. if (data.error != undefined){
  261. showError(data.error);
  262. }else{
  263. showOK();
  264. }
  265. }
  266. })
  267. }
  268. function updatePublicIPSetting(){
  269. var newip = $("#publicip").val();
  270. $.ajax({
  271. url: "../../system/storage/ftp/passivemode",
  272. data: {set: "ip", "ip": newip},
  273. success: function(data){
  274. if (data.error != undefined){
  275. showError(data.error);
  276. }else{
  277. showOK();
  278. }
  279. }
  280. })
  281. }
  282. function handlePassiveModeChange(value){
  283. $.ajax({
  284. url: "../../system/storage/ftp/passivemode",
  285. data: {set: "mode", "passive": value},
  286. success: function(data){
  287. if (data.error != undefined){
  288. showError(data.error);
  289. }else{
  290. showOK();
  291. }
  292. initFTPServerStatus();
  293. }
  294. })
  295. }
  296. function updateFTPPort(portNumber){
  297. if (portNumber < 21){
  298. showError("Port number must be > 21")
  299. return
  300. }
  301. $.ajax({
  302. url: "../../system/storage/ftp/setPort",
  303. data: {port: portNumber},
  304. success: function(data){
  305. if (data.error !== undefined){
  306. showError(data.error);
  307. }else{
  308. showOK();
  309. }
  310. }
  311. })
  312. }
  313. function showOK(){
  314. $("#ok").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  315. }
  316. function showError(msg){
  317. $("#error").find(".msg").text(msg);
  318. $("#error").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  319. }
  320. //Update examples
  321. $(".thisAddr").text(window.location.hostname.replace('www.',''));
  322. </script>
  323. </body>
  324. </html>