autologin.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <html>
  2. <head>
  3. <title>Auto Login Mode</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  6. <link rel="stylesheet" href="../../script/semantic/semantic.css">
  7. <script type="application/javascript" src="../../script/jquery.min.js"></script>
  8. <script type="application/javascript" src="../../script/clipboard.min.js"></script>
  9. <script type="application/javascript" src="../../script/semantic/semantic.js"></script>
  10. <style>
  11. /* Tooltip container */
  12. .tooltip {
  13. position: relative;
  14. display: inline-block;
  15. border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
  16. }
  17. /* Tooltip text */
  18. .tooltip .tooltiptext {
  19. visibility: hidden;
  20. width: 120px;
  21. background-color: #555;
  22. color: #fff;
  23. text-align: center;
  24. padding: 5px 0;
  25. border-radius: 6px;
  26. /* Position the tooltip text */
  27. position: absolute;
  28. z-index: 1;
  29. bottom: 125%;
  30. left: 50%;
  31. margin-left: -60px;
  32. /* Fade in tooltip */
  33. opacity: 0;
  34. transition: opacity 0.3s;
  35. }
  36. /* Tooltip arrow */
  37. .tooltip .tooltiptext::after {
  38. content: "";
  39. position: absolute;
  40. top: 100%;
  41. left: 50%;
  42. margin-left: -5px;
  43. border-width: 5px;
  44. border-style: solid;
  45. border-color: #555 transparent transparent transparent;
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <div class="ui container">
  51. <div class="ui basic segment">
  52. <div class="ui header">
  53. <i class="tv icon"></i>
  54. <div class="content">
  55. Auto Login Mode
  56. <div class="sub header">Allow automatic bot login and interface module displaying</div>
  57. </div>
  58. </div>
  59. <p>This function allows a given user to login automatically using a given token and display its interface module. Although this is design for billboard purpose, you can also use this function for other purposes like web service demo and more.<br>
  60. <span style="font-weight: bold; color: red;">Please treat the token of your account as your password</span></p>
  61. </div>
  62. <div class="ui divider"></div>
  63. <div class="ui form">
  64. <div class="field">
  65. <label>Select User Account</label>
  66. <div class="ui selection fluid dropdown" autocomplete="false">
  67. <input type="hidden" name="username" onchange="updateUserInfo(this.value);" autocomplete="false">
  68. <i class="dropdown icon"></i>
  69. <div class="default text">Select User Account</div>
  70. <div id="userlist" class="menu">
  71. </div>
  72. </div>
  73. </div>
  74. <div id="adminwarning" class="ui yellow segment" style="display:none">
  75. <i class="info circle icon"></i> We do not recommend enabling auto login on Administrator accounts due to security issues. Click <a href="../vendor/public/autoLoginForAdmin.html" target="_blank">HERE</a> to learn more.
  76. </div>
  77. <button id="ntb" onclick="newToken(event);" class="ui green disabled button" type="submit">New Token</button>
  78. <button onclick="refreshTokenList();" class="ui blue button"><i class="refresh icon"></i>Refresh List</button>
  79. <div class="ui green segment" style="display:none;">
  80. <h4>Token Created: </h4>
  81. <p id="newTokenDisplay"></p>
  82. </div>
  83. </div>
  84. <div class="ui divider"></div>
  85. <div class="ui bottom attached segment">
  86. <h4>Selected User's Tokens</h4>
  87. <div id="tokenlist" class="ui list">
  88. <p>Please select a target user</p>
  89. </div>
  90. </div>
  91. <br><br>
  92. </div>
  93. <script>
  94. var currentSelectedUsername = "";
  95. var tokenAccessPath = location.protocol + "//" + window.location.host + "/api/auth/login?token=";
  96. $(document).ready(function(){
  97. loadUserList();
  98. });
  99. function updateUserInfo(userinfo){
  100. userinfo = JSON.parse(decodeURIComponent(userinfo));
  101. if (userinfo[3] == true){
  102. $("#adminwarning").slideDown("fast");
  103. }else{
  104. $("#adminwarning").slideUp("fast");
  105. }
  106. updateTokenList(userinfo[0]);
  107. $("#ntb").removeClass("disabled");
  108. currentSelectedUsername = userinfo[0];
  109. $("#newTokenDisplay").parent().hide();
  110. }
  111. function refreshTokenList(){
  112. updateTokenList(currentSelectedUsername);
  113. }
  114. function newToken(){
  115. event.preventDefault();
  116. if (currentSelectedUsername == ""){
  117. return
  118. }
  119. $.get("../../system/autologin/create?username=" + currentSelectedUsername, function(newToken){
  120. if (newToken.error !== undefined){
  121. $("#newTokenDisplay").text(newToken.error);
  122. $("#newTokenDisplay").parent().removeclass("green").addClass("red");
  123. }else{
  124. $("#newTokenDisplay").text(newToken);
  125. $("#newTokenDisplay").parent().addClass("green").removeclass("red");
  126. }
  127. });
  128. setTimeout(function(){
  129. updateTokenList(currentSelectedUsername);
  130. }, 1000);
  131. $("#newTokenDisplay").parent().show();
  132. }
  133. function updateTokenList(username){
  134. $("#tokenlist").html("");
  135. $.get("../../system/autologin/list?username=" + username, function(data){
  136. data.forEach(token => {
  137. $("#tokenlist").append(`
  138. <div class="item">
  139. <i class="key icon"></i>
  140. <div class="content" style="font-family: monospace;">
  141. ${token} <a style="margin-left: 12px; font-family: Arial;" token="${token}" class="copyURL tooltip">
  142. <i class="copy icon"></i> Copy URL to Clipboard
  143. <span class="tooltiptext"><i class="checkmark icon"></i> Copied</span>
  144. </a>
  145. <a style="margin-left: 12px; color: red; font-family: Arial;" token="${token}" onclick="deleteToken(this);">
  146. <i class="remove icon"></i> Delete
  147. </a>
  148. </div>
  149. </div>`);
  150. });
  151. if (data.length == 0){
  152. $("#tokenlist").append(`
  153. <div class="item">
  154. <i class="question icon"></i>
  155. <div class="content" style="font-family: monospace;">
  156. No Token Found
  157. </div>
  158. </div>`);
  159. }
  160. });
  161. }
  162. new ClipboardJS('.copyURL', {
  163. text: function(trigger) {
  164. var token = $(trigger).attr("token");
  165. var url = tokenAccessPath + token;
  166. console.log( $(trigger).find(".tooltiptext"));
  167. $(trigger).find(".tooltiptext").css({
  168. "visibility": "visible",
  169. "opacity": 1,
  170. });
  171. setTimeout(function(){
  172. $(trigger).find(".tooltiptext").css({
  173. "visibility": "hidden",
  174. "opacity": 0,
  175. });
  176. }, 3000);
  177. return url;
  178. }
  179. });
  180. function deleteToken(object){
  181. if (confirm("This token will be removed permanently. Confirm?")){
  182. var token = $(object).attr("token");
  183. $.get("../../system/autologin/delete?token=" + token, function(data){
  184. updateTokenList(currentSelectedUsername);
  185. });
  186. }
  187. }
  188. function loadUserList(){
  189. $("#userlist").html("");
  190. $.get("../../system/users/list", function(data){
  191. if (data.error !== undefined){
  192. alert(data.error);
  193. }else{
  194. for (var i = 0; i < data.length; i++){
  195. let userinfo = data[i];
  196. $("#userlist").append(`<div class="item" data-value="${encodeURIComponent(JSON.stringify(userinfo))}" isadmin="${userinfo[3]}">${userinfo[0]}</div>`);
  197. }
  198. }
  199. $("#userlist").parent().dropdown();
  200. });
  201. }
  202. </script>
  203. </body>
  204. </html>