services.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. <script src="../../script/clipboard.min.js"></script>
  11. <style>
  12. .hidden{
  13. display:none;
  14. }
  15. .disabled{
  16. opacity: 0.5;
  17. pointer-events: none;
  18. }
  19. .detailBtn{
  20. position: absolute;
  21. right: 0.4em;
  22. top: calc(30% + 0.5em);
  23. }
  24. .servertype.active .detailBtn{
  25. pointer-events: none;
  26. opacity: 0.3;
  27. }
  28. .servertype:hover{
  29. opacity: 0.7;
  30. }
  31. .servertype.active{
  32. background-color: #f7f7f7 !important;
  33. border-right: 3px solid #6bc2ec !important;
  34. }
  35. .clickable{
  36. cursor: pointer;
  37. }
  38. .fileservice{
  39. margin-bottom: 1em;
  40. }
  41. .serviceConnEndpoints{
  42. margin-top: 0 !important;
  43. display: inline-block;
  44. vertical-align:top;
  45. }
  46. .ui.toggle.checkbox input[type=checkbox]:checked~label::before,
  47. .ui.toggle.checkbox input[type=checkbox]:checked:focus~label::before {
  48. background: #8cd493 !important;
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <br>
  54. <div class="ui container">
  55. <div class="ui header">
  56. <div class="content">
  57. Network File Transfer Servers
  58. <div class="sub header">Manage the exported file server interface for ArozOS Virtual File System</div>
  59. </div>
  60. </div>
  61. <br>
  62. <div class="ui stackable grid">
  63. <div class="six wide column" style="border-right: 1px solid #e0e0e0;">
  64. <div id="serviceList"></div>
  65. <div class="ui divider"></div>
  66. <!--
  67. <div style="width: 100%;" align="center">
  68. <button title="Start All Services" onclick="" class="circular basic green large ui icon button">
  69. <i class="green play icon"></i>
  70. </button>
  71. <button title="Stop All Services" onclick="" class="circular basic red large ui icon button">
  72. <i class="red stop icon"></i>
  73. </button>
  74. </div>
  75. -->
  76. </div>
  77. <div class="ten wide column">
  78. <div id="serviceInstruction"></div>
  79. <div class="ui divider"></div>
  80. <div id="serviceSettings"></div>
  81. </div>
  82. </div>
  83. <br><br>
  84. </div>
  85. <script>
  86. var isAdmin = false;
  87. var fileServerServices = [];
  88. function isAdminCheck(){
  89. $.get("../../system/desktop/user?noicon=true", function(data){
  90. isAdmin = data.IsAdmin;
  91. initServiceList();
  92. });
  93. }
  94. isAdminCheck();
  95. function initServiceList(){
  96. $("#serviceList").html("");
  97. $.get("../../system/network/server/list", function(data){
  98. console.log(data);
  99. fileServerServices = data;
  100. data.forEach(server => {
  101. console.log(server);
  102. let checkboxDefaultState = "";
  103. let messageDefaultColor = "";
  104. if (server.Enabled){
  105. checkboxDefaultState = "checked";
  106. messageDefaultColor = "green";
  107. }
  108. $("#serviceList").append(`<div class="fileservice">
  109. <div class="ui clickable servertype top attached segment" uuid="${server.ID}" onclick="openServerConfig('${server.ID}', event, this);">
  110. <h4 class="ui header">
  111. <img src="../../${server.IconPath}">
  112. <div class="content">
  113. ${server.Name}
  114. <div class="sub header">
  115. ${server.Desc}
  116. </div>
  117. </div>
  118. </h4>
  119. <a title="Details" onclick="openServerConfig('${server.ID}', event, this.parent);" class="detailBtn">
  120. <i class="grey angle right icon"></i>
  121. </a>
  122. </div>
  123. <div class="ui bottom attached ${messageDefaultColor} mini message">
  124. <div class="ui toggle mini checkbox enableState" fserv="${server.ID}" onclick="handleServiceStateChange(this, event);">
  125. <input type="checkbox" ${checkboxDefaultState} onchange="updateCheckboxBackground(this, event);">
  126. <label></label>
  127. </div>
  128. <p fserv="${server.ID}" class="serviceConnEndpoints"></p>
  129. </div>`);
  130. });
  131. if (data.length > 0){
  132. openServerConfig(data[0].ID);
  133. $($(".servertype")[0]).addClass("active");
  134. }
  135. //Get a list of endpoints that is dedicated for this file server
  136. $.get("../../system/network/server/endpoints", function(data){
  137. for (let [id, endpoints] of Object.entries(data)){
  138. console.log(id, endpoints)
  139. //Get the target connection display for this endpoint
  140. $(".serviceConnEndpoints").each(function(){
  141. if ($(this).attr("fserv") == id){
  142. //This is the one. Render the endpoints on it
  143. let endpointHTML = "";
  144. endpoints.forEach(ep => {
  145. var portName = ":" + ep.Port;
  146. if (ep.Port == 0){
  147. //Do not define port. Hence do not show it
  148. portName = "";
  149. }
  150. let connURL = ep.ProtocolName + window.location.hostname + portName + ep.Subpath;
  151. endpointHTML += `<i class="ui grey caret right icon"></i> <a class="clip" data-clipboard-text="${connURL}" style="cursor:pointer;" conn="${connURL}">${connURL}</a><br>`
  152. });
  153. $(this).html(endpointHTML);
  154. }
  155. });
  156. var clipboard = new ClipboardJS('.clip');
  157. clipboard.on('success', function(e) {
  158. //console.info('Action:', e.action);
  159. //console.info('Text:', e.text);
  160. console.info('Trigger:', e.trigger);
  161. let targetElement = e.trigger;
  162. $(targetElement).html(`<i class="ui green checkmark icon"></i> Copied`);
  163. setTimeout(function(){
  164. let originalURL = $(targetElement).attr("conn");
  165. $(targetElement).html(originalURL);
  166. }, 3000);
  167. e.clearSelection();
  168. });
  169. //Activate all checkbox
  170. $(".ui.checkbox").checkbox();
  171. if (!isAdmin){
  172. //This user not admin. Disable all checkbox
  173. $(".ui.checkbox").addClass("disabled");
  174. }
  175. updateAllServiceState();
  176. }
  177. });
  178. });
  179. }
  180. function updateAllServiceState(){
  181. $.get("../../system/network/server/status", function(data){
  182. $(".enableState").each(function(){
  183. var fservid = $(this).attr("fserv");
  184. var enableState = data[fservid];
  185. if (enableState){
  186. $(this).checkbox("set checked");
  187. }else{
  188. $(this).checkbox("set unchecked");
  189. }
  190. });
  191. });
  192. }
  193. function handleServiceStateChange(object, event){
  194. event.preventDefault();
  195. let targetElement = object;
  196. setTimeout(function(){
  197. //This delay is to make sure the checkbox event is executed first
  198. //Before the state is checked
  199. let isChecked = $(targetElement).checkbox("is checked");
  200. let isCheckedString = isChecked?"true":"false";
  201. let serviceId = $(targetElement).attr("fserv");
  202. $.ajax({
  203. url: "../../system/network/server/toggle",
  204. method: "POST",
  205. data: {id: serviceId, enable: isCheckedString},
  206. success: function(){
  207. updateAllServiceState();
  208. }
  209. })
  210. }, 100);
  211. }
  212. function getServiceById(serviceid){
  213. for (var i =0; i < fileServerServices.length; i++){
  214. if (fileServerServices[i].ID == serviceid){
  215. return fileServerServices[i];
  216. }
  217. }
  218. }
  219. function openServerConfig(serviceid, evt=undefined, object=undefined){
  220. if (evt != undefined){
  221. evt.preventDefault();
  222. }
  223. $(".servertype.active").removeClass("active");
  224. $(object).addClass("active");
  225. let targetService = getServiceById(serviceid);
  226. let targetServiceConfigPage = targetService.ConfigPage;
  227. if (targetServiceConfigPage == "" || targetServiceConfigPage == undefined){
  228. $("#serviceSettings").html(`No Configuration Avabile`);
  229. }else{
  230. $("#serviceInstruction").load("../../" + targetService.ConnInstrPage);
  231. if (isAdmin){
  232. $("#serviceSettings").load("../../" + targetService.ConfigPage);
  233. }else{
  234. $("#serviceSettings").load("../disk/instr/noaccess.html");
  235. }
  236. }
  237. }
  238. function updateCheckboxBackground(object, event){
  239. let message = $(object).parent().parent();
  240. if (object.checked){
  241. $(message).addClass("green");
  242. }else{
  243. $(message).removeClass("green");
  244. }
  245. }
  246. </script>
  247. </body>
  248. </html>