webdav.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. WebDAV Server
  25. <div class="sub header">Access your arozos user root with WebDAV protocols.</div>
  26. </div>
  27. <div class="ui message maconly" style="display:none">
  28. <h4><i class="apple icon"></i> Login Method for MacOS</h4>
  29. <p>If you are using MacOS, you can select "Connect to Network Server", enter the endpoint of the arozos WebDAV service (<span class="protocol"></span>//<span class="hostname"></span>:<span class="port"></span>/webdav/{vroot_name}) and login with your arozos username and password.</p>
  30. </div>
  31. <div class="ui blue message windowonly nontls" style="display:none">
  32. <h4><i class="windows icon"></i> Login Method for Windows (Non SSL / TLS Mode)</h4>
  33. <p>If you are using Windows File Explorer as your WebDAV Client without TLS enabled on arozos server, <b>WebDAV will run in compatibility mode and Basic Auth is not usable. You must authenticate through this Web UI. </b> Please follow the steps below to authenticate your Windows WebDAV Client.</p>
  34. <ol class="ui list">
  35. <li>Mount the WebDAV endpoint in your File Explorer (Endpoint: <span class="protocol"></span>//<span class="hostname"></span>:<span class="port"></span>/webdav/{vroot_name})</li>
  36. <li>Connect with no username and password</li>
  37. <li>You will be directed to a READONLY directory. Refresh this page and see if there is a new client pop up in the "Access Pending Clients" list.</li>
  38. <li>Click "Allow Access" to assign your user storage pool to be accessiable by this Windows WebDAV Client(s). (Sometime more than 1 conncetions will be used by the same File Explorer)</li>
  39. <li>Refresh your file list in File Explorer and your root folder (user:/) should be listed</li>
  40. </ol>
  41. </div>
  42. <div class="ui blue message windowonly tls" style="display:none">
  43. <h4><i class="windows icon"></i> Login Method for Windows (With SSL / TLS MODE)</h4>
  44. <p>If you are using Windows File Explorer as your WebDAV Client, go to "My Computer" and add a network drive with the following endpoint: <span class="protocol"></span>//<span class="hostname"></span>:<span class="port"></span>/webdav/{vroot_name}</p>
  45. </div>
  46. <!-- General Settings -->
  47. <h3>Basic Settings</h3>
  48. <form class="ui form">
  49. <div class="field">
  50. <div class="ui toggle checkbox">
  51. <input type="checkbox" id="serverToggle" tabindex="0" class="hidden" onchange="toggleWebDAVServer(this.checked);">
  52. <label>Enable WebDAV Server</label>
  53. </div>
  54. </div>
  55. </form>
  56. <div id="status" class="ui icon message">
  57. <i class="exchange icon"></i>
  58. <div class="content">
  59. <div class="header">
  60. <span class="onlinestatus">Status: Offline</span>
  61. </div>
  62. <p>Server might take a few seconds to startup / shutdown after switching on and off.</p>
  63. </div>
  64. </div>
  65. <!-- Connection Endpoint List -->
  66. <div class="ui segment">
  67. <p>The following are the endpoints that you can connect via WebDAV with your user account.</p>
  68. <div class="ui list" id="vrootList">
  69. </div>
  70. </div>
  71. <!-- NON TLS Windows Only Mode-->
  72. <div id="nontlsWindowsSettings">
  73. <br>
  74. <h3>Non-TLS Windows Client Connection Settings</h3>
  75. <h4>Access Pending Clients</h4>
  76. <table class="ui very basic collapsing celled table">
  77. <thead>
  78. <tr>
  79. <th>Client IP</th>
  80. <th>Last Request</th>
  81. <th>Connection UUID</th>
  82. <th>Action</th>
  83. </tr>
  84. </thead>
  85. <tbody id="accessPendingClientList">
  86. <tr><td>
  87. <h4 class="ui header">
  88. <div class="content">
  89. 192.168.0.1
  90. </div>
  91. </h4>
  92. </td>
  93. <td>
  94. 1 Jan 1970 08:00:00
  95. </td>
  96. <td>
  97. 5bfba525-00ba-4d00-b8cc-7938fd8a0175
  98. </td>
  99. <td>
  100. <button class="ui tiny primary button">Allow Access</button>
  101. </td>
  102. </tr>
  103. </tbody>
  104. </table>
  105. <div class="ui divider"></div>
  106. <h4>Access Allowed Clients</h4>
  107. <table class="ui very basic collapsing celled table">
  108. <thead>
  109. <tr>
  110. <th>Client IP</th>
  111. <th>Last Request</th>
  112. <th>Connection UUID</th>
  113. <th>Owner</th>
  114. <th>Action</th>
  115. </tr>
  116. </thead>
  117. <tbody id="permittedClientList">
  118. </tbody>
  119. </table>
  120. <div class="ui divider"></div>
  121. <button class="ui blue button" onclick="refreshList();"><i class="refresh icon"></i> Refresh List</button>
  122. <button class="ui button" onclick="clearPendings();"><i class="remove icon"></i> Clear All Pending Request</button>
  123. </div>
  124. <br><br>
  125. </div>
  126. <script>
  127. var isMac = navigator.platform.toUpperCase().indexOf('MAC')>=0;
  128. var isWindows = navigator.platform.indexOf('Win') > -1;
  129. //Initiate UI elements
  130. $(".ui.checkbox").checkbox();
  131. //Generate endpoint list
  132. generateConnectionEndpointList();
  133. function toggleWebDAVServer(value){
  134. if (value == true){
  135. $("#status").addClass("green");
  136. $("#status").find(".onlinestatus").text("Status: Online");
  137. $.get("../../system/network/webdav/status?set=enable", function(data){
  138. initServerStatus();
  139. });
  140. }else{
  141. $("#status").removeClass("green");
  142. $("#status").find(".onlinestatus").text("Status: Offline");
  143. $.get("../../system/network/webdav/status?set=disable", function(data){
  144. initServerStatus();
  145. });
  146. }
  147. }
  148. function generateConnectionEndpointList(){
  149. $.get("../../system/file_system/listRoots", function(data){
  150. if (data.error != undefined){
  151. console.log(data.error);
  152. }else{
  153. $("#vrootList").html("");
  154. var port = (window.location.port);
  155. if (window.location.port == ""){
  156. port = 80;
  157. }
  158. data.forEach(vroot => {
  159. $("#vrootList").append(`<div class="item">
  160. <i class="disk icon"></i>
  161. <div class="content">
  162. <div class="header">${vroot.RootName}</div>
  163. <div class="description">${location.protocol}//${window.location.hostname}:${port}/webdav/${vroot.RootPath.replace(":/","")}</div>
  164. </div>
  165. </div>`);
  166. });
  167. }
  168. });
  169. }
  170. //Check server toggle state
  171. initServerStatus();
  172. function initServerStatus(){
  173. $.get("../../system/network/webdav/status", function(data){
  174. if (data[0] == true){
  175. $("#serverToggle")[0].checked = true;
  176. $("#status").addClass("green");
  177. $("#status").find(".onlinestatus").text("Status: Online");
  178. }else{
  179. $("#serverToggle")[0].checked = false;
  180. $("#status").removeClass("green");
  181. $("#status").find(".onlinestatus").text("Status: Offline");
  182. }
  183. if (data[1] == false){
  184. $("#serverToggle").parent().addClass("disabled");
  185. $("#serverToggle").parent().parent().attr("title","Administrator Only");
  186. }
  187. });
  188. }
  189. //Update tutorial information
  190. $(".hostname").text(window.location.hostname);
  191. $(".port").text(window.location.port);
  192. if (window.location.port == ""){
  193. $(".port").text("80");
  194. }
  195. $(".protocol").text(location.protocol);
  196. if (isMac){
  197. $(".maconly").show();
  198. }else if (isWindows){
  199. $(".windowonly").show();
  200. }
  201. //Check if running in HTTPS mode. If yes, hide this functions
  202. if (location.protocol == 'https:'){
  203. $("#nontlsWindowsSettings").hide();
  204. $(".nontls").hide();
  205. }else{
  206. $(".tls").hide();
  207. }
  208. initAccessPendingList();
  209. initAccessPermittedList();
  210. function initAccessPermittedList(){
  211. $.get("../../system/network/webdav/list?target=loggedin", function(data){
  212. $("#permittedClientList").html("");
  213. data.forEach(client => {
  214. $("#permittedClientList").append(`<tr><td>
  215. <h4 class="ui header">
  216. <div class="content">
  217. ${client.ClientIP}
  218. </div>
  219. </h4>
  220. </td>
  221. <td>
  222. ${timeConverter(client.LastConnectionTimestamp)}
  223. </td>
  224. <td>
  225. ${client.UUID}
  226. </td>
  227. <td>
  228. ${client.Username}
  229. </td>
  230. <td>
  231. <button clientid="${client.UUID}" onclick="removeAllowAccess(this);" class="ui tiny red button">Remove Access</button>
  232. </td>
  233. </tr>`);
  234. });
  235. if (data.length == 0){
  236. $("#permittedClientList").append(`<tr><td colspan="4"><i class="remove icon"></i> NO PERMITTED CLIENT</td></tr>`);
  237. }
  238. })
  239. }
  240. function refreshList(){
  241. initAccessPendingList();
  242. initAccessPermittedList();
  243. }
  244. function initAccessPendingList(){
  245. $.get("../../system/network/webdav/list", function(data){
  246. $("#accessPendingClientList").html("")
  247. data.forEach(client => {
  248. $("#accessPendingClientList").append(`<tr><td>
  249. <h4 class="ui header">
  250. <div class="content">
  251. ${client.ClientIP}
  252. </div>
  253. </h4>
  254. </td>
  255. <td>
  256. ${timeConverter(client.LastConnectionTimestamp)}
  257. </td>
  258. <td>
  259. ${client.UUID}
  260. </td>
  261. <td>
  262. <button clientid="${client.UUID}" onclick="setAllowAccess(this);" class="ui tiny primary button">Allow Access</button>
  263. </td>
  264. </tr>`);
  265. })
  266. if (data.length == 0){
  267. $("#accessPendingClientList").append(`<tr><td colspan="4"><i class="remove icon"></i> NO CLIENTS PENDING</td></tr>`);
  268. }
  269. });
  270. }
  271. function setAllowAccess(object){
  272. var clientUUID = $(object).attr("clientid");
  273. $.ajax({
  274. url: "../../system/network/webdav/edit",
  275. data: {"opr": "set", "uuid": clientUUID},
  276. success: function(data){
  277. initAccessPendingList();
  278. initAccessPermittedList();
  279. }
  280. })
  281. }
  282. function removeAllowAccess(object){
  283. var clientUUID = $(object).attr("clientid");
  284. $.ajax({
  285. url: "../../system/network/webdav/edit",
  286. data: {"opr": "remove", "uuid": clientUUID},
  287. success: function(data){
  288. initAccessPendingList();
  289. initAccessPermittedList();
  290. }
  291. })
  292. }
  293. function clearPendings(){
  294. $.get("../../system/network/webdav/clear", function(data){
  295. //Done. Refresh list
  296. initAccessPendingList();
  297. initAccessPermittedList();
  298. });
  299. }
  300. function timeConverter(UNIX_timestamp){
  301. var a = new Date(UNIX_timestamp * 1000);
  302. var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
  303. var year = a.getFullYear();
  304. var month = months[a.getMonth()];
  305. var date = a.getDate();
  306. var hour = a.getHours();
  307. var min = a.getMinutes();
  308. var sec = a.getSeconds();
  309. var time = date + ' ' + month + ' ' + year + ' ' + (hour + "").padStart(2,"0") + ':' + (min + "").padStart(2,"0") + ':' + (sec + "").padStart(2,"0") ;
  310. return time;
  311. }
  312. </script>
  313. </body>
  314. </html>