samba.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <script src="../../script/clipboard.min.js"></script>
  2. <style>
  3. .smbaddr{
  4. cursor:pointer;
  5. color: #5c94cb;
  6. }
  7. .smbaddr:hover{
  8. background-color: rgb(236, 236, 236) !important;
  9. }
  10. </style>
  11. <div class="ui basic yellow message">
  12. <h4 class="ui header">
  13. <i class="yellow folder icon"></i>
  14. <div class="content">
  15. Accessing ArozOS Local Disks using SMB
  16. </div>
  17. </h4>
  18. <p>To access your ArozOS local disk storage using SMB, you can first enable SMB on your account and open the IP address of this host in your File Explorer or Mac Finder (with smb:// prefix)</p>
  19. <small>Samba can only share local disks or partitions. Remote file system mounted into ArozOS cannot be shared by SMB.</small>
  20. </div>
  21. <p>Click "Activate" to enable SMB access to your file system</p>
  22. <button class="ui basic activateSmb button" onclick="activateAccountForThisUser();"><i class="ui green circle check icon"></i> Activate</button>
  23. <button class="ui basic disableSmb disabled button" onclick="disableAccountForThisUser();"><i class="ui red circle times icon"></i> Disable</button>
  24. <table class="ui very basic celled table">
  25. <thead>
  26. <tr>
  27. <th>Share Names</th>
  28. <th>Path</th>
  29. <th>Accessible By</th>
  30. </tr>
  31. </thead>
  32. <tbody id="userShareList">
  33. <tr>
  34. <td colspan="3"><i class="ui red circle times icon"></i> smbd is not enabled on this server</td>
  35. </tr>
  36. </tbody>
  37. </table>
  38. <script>
  39. function initSMBActivationStatusOnThisUser(){
  40. $.get("/system/storage/samba/myshare", function(data){
  41. if (data.error != undefined || !data.SmbdEnabled){
  42. $(".activateSmb").addClass("disabled");
  43. $(".disableSmb").addClass("disabled");
  44. }else{
  45. if (data.UserSmbShareEnabled){
  46. $(".activateSmb").addClass("disabled");
  47. $(".disableSmb").removeClass("disabled");
  48. }else{
  49. $(".activateSmb").removeClass("disabled");
  50. $(".disableSmb").addClass("disabled");
  51. }
  52. //Render the user share list
  53. $("#userShareList").html(``);
  54. data.UserSmbShareList.forEach(smbShare => {
  55. console.log(smbShare);
  56. let visableLogo = "";
  57. if (!smbShare.Browseable){
  58. //This share is hidden from the share tree view
  59. visableLogo = `<i class="eye slash outline icon"></i>`;
  60. }
  61. $("#userShareList").append(`<tr>
  62. <td>${visableLogo} ${smbShare.Name}</td>
  63. <td class="smbaddr" data-clipboard-text="\\\\${window.location.hostname}\\${smbShare.Name}" ><small>\\\\${window.location.hostname}\\${smbShare.Name}</small></td>
  64. <td>${smbShare.ValidUsers.join(", ")}</td>
  65. </tr>`);
  66. });
  67. if (data.UserSmbShareList.length == 0){
  68. $("#userShareList").append(`<tr><td colspan="3"><i class="ui green circle check icon"></i> This account has no shared folder</td></tr>`);
  69. }else{
  70. var clipboard = new ClipboardJS('.smbaddr');
  71. clipboard.on('success', function(e) {
  72. msgbox("Address copied. Paste to File Explorer to open share.")
  73. });
  74. }
  75. }
  76. });
  77. }
  78. initSMBActivationStatusOnThisUser();
  79. function disableAccountForThisUser(){
  80. $.get("/system/storage/samba/deactivate", function(data){
  81. if (data.error != undefined){
  82. msgbox(data.error, false, 6000);
  83. }else{
  84. if (data != false){
  85. msgbox("SMB shares deactivated");
  86. if (typeof(initServiceList) != "undefined"){
  87. initServiceList(function(){
  88. openServerConfig("smbd", undefined, $(".servertype[uuid=\"smbd\"]"));
  89. });
  90. }
  91. }
  92. initSMBActivationStatusOnThisUser();
  93. if (typeof(initShareListTable) != "undefined"){
  94. initShareListTable();
  95. }
  96. }
  97. });
  98. }
  99. //Activate account for user, require password confirmation
  100. function activateAccountForThisUser(){
  101. var apiObject = {
  102. api: "../system/storage/samba/activate",
  103. data: {},
  104. title: `Activate SMB Access`,
  105. desc: `Confirm sharing my account using SMB (Samba)`,
  106. thisuser: true, //This username as default, set to false for entering other user
  107. method: "POST",
  108. success: undefined
  109. }
  110. apiObject = encodeURIComponent(JSON.stringify(apiObject));
  111. parent.newFloatWindow({
  112. url: "SystemAO/security/authreq.html#" + apiObject,
  113. width: 480,
  114. height: 300,
  115. appicon: "SystemAO/security/img/lock.svg",
  116. title: `Activate SMB Access`,
  117. parent: ao_module_windowID,
  118. callback: "handleSMBActivateCallback"
  119. });
  120. }
  121. window.handleSMBActivateCallback = function(data){
  122. if (data.error != undefined){
  123. msgbox(data.error, false, 6000);
  124. }else{
  125. if (data != false){
  126. msgbox("SMB Share activated");
  127. }
  128. initSMBActivationStatusOnThisUser();
  129. //Reload the share table
  130. if (typeof(initShareListTable) != "undefined"){
  131. initShareListTable();
  132. }
  133. //Reload the share endpoint in service list
  134. if (typeof(initServiceList) != "undefined"){
  135. initServiceList(function(){
  136. openServerConfig("smbd", undefined, $(".servertype[uuid=\"smbd\"]"));
  137. });
  138. }
  139. }
  140. }
  141. </script>