embed.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. package static
  2. // IndexHTML is the embedded admin panel HTML
  3. var IndexHTML = `<!DOCTYPE html>
  4. <html lang="zh-CN">
  5. <head>
  6. <meta charset="UTF-8">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>FTP Server 管理面板</title>
  9. <style>
  10. * { margin: 0; padding: 0; box-sizing: border-box; }
  11. body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f0f2f5; color: #333; }
  12. /* Login Page */
  13. .login-container { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
  14. .login-card { background: white; border-radius: 12px; padding: 40px; width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
  15. .login-card h1 { text-align: center; margin-bottom: 30px; color: #333; font-size: 24px; }
  16. .login-card h1 .icon { font-size: 48px; display: block; margin-bottom: 10px; }
  17. .form-group { margin-bottom: 20px; }
  18. .form-group label { display: block; margin-bottom: 6px; font-weight: 600; color: #555; font-size: 14px; }
  19. .form-group input { width: 100%; padding: 12px 16px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; transition: border-color 0.3s; }
  20. .form-group input:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,0.1); }
  21. .btn { padding: 12px 24px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; transition: all 0.3s; }
  22. .btn-primary { background: linear-gradient(135deg, #667eea, #764ba2); color: white; width: 100%; }
  23. .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 15px rgba(102,126,234,0.4); }
  24. .btn-danger { background: #dc3545; color: white; }
  25. .btn-danger:hover { background: #c82333; }
  26. .btn-success { background: #28a745; color: white; }
  27. .btn-success:hover { background: #218838; }
  28. .btn-sm { padding: 6px 14px; font-size: 12px; }
  29. .error-msg { color: #dc3545; text-align: center; margin-top: 12px; font-size: 14px; min-height: 20px; }
  30. /* Dashboard */
  31. .app-container { display: none; }
  32. .header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 16px 30px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
  33. .header h1 { font-size: 20px; font-weight: 600; }
  34. .header .user-info { display: flex; align-items: center; gap: 16px; }
  35. .header .user-info span { font-size: 14px; opacity: 0.9; }
  36. .sidebar { position: fixed; left: 0; top: 60px; bottom: 0; width: 220px; background: #fff; box-shadow: 2px 0 10px rgba(0,0,0,0.05); padding-top: 20px; }
  37. .sidebar a { display: block; padding: 14px 24px; color: #666; text-decoration: none; font-size: 14px; transition: all 0.3s; border-left: 3px solid transparent; }
  38. .sidebar a:hover, .sidebar a.active { background: #f8f9ff; color: #667eea; border-left-color: #667eea; }
  39. .main-content { margin-left: 220px; padding: 30px; margin-top: 60px; }
  40. .stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-bottom: 30px; }
  41. .stat-card { background: white; border-radius: 12px; padding: 24px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
  42. .stat-card .label { color: #888; font-size: 13px; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
  43. .stat-card .value { font-size: 28px; font-weight: 700; color: #333; }
  44. .stat-card .value.purple { color: #667eea; }
  45. .stat-card .value.green { color: #28a745; }
  46. .stat-card .value.blue { color: #007bff; }
  47. .card { background: white; border-radius: 12px; padding: 24px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); margin-bottom: 20px; }
  48. .card h2 { font-size: 18px; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid #eee; color: #333; }
  49. .card h3 { font-size: 15px; margin-bottom: 16px; color: #555; }
  50. table { width: 100%; border-collapse: collapse; }
  51. th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid #f0f0f0; font-size: 14px; }
  52. th { background: #fafafa; font-weight: 600; color: #555; }
  53. tr:hover { background: #f8f9ff; }
  54. .badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
  55. .badge-success { background: #e8f5e9; color: #28a745; }
  56. .badge-secondary { background: #f5f5f5; color: #888; }
  57. .section { display: none; }
  58. .section.active { display: block; }
  59. .config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  60. .config-grid .form-group input, .config-grid .form-group select { width: 100%; padding: 10px 14px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px; }
  61. .config-grid .form-group input:focus { outline: none; border-color: #667eea; }
  62. .modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1000; justify-content: center; align-items: center; }
  63. .modal-overlay.show { display: flex; }
  64. .modal { background: white; border-radius: 12px; padding: 30px; width: 480px; max-width: 90%; }
  65. .modal h2 { margin-bottom: 24px; }
  66. .modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
  67. .toast { position: fixed; top: 80px; right: 30px; padding: 14px 24px; border-radius: 8px; color: white; font-size: 14px; font-weight: 500; z-index: 2000; animation: slideIn 0.3s ease; }
  68. .toast-success { background: #28a745; }
  69. .toast-error { background: #dc3545; }
  70. @keyframes slideIn { from { transform: translateX(100px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
  71. .actions-cell { display: flex; gap: 8px; }
  72. </style>
  73. </head>
  74. <body>
  75. <!-- Login Page -->
  76. <div class="login-container" id="loginPage">
  77. <div class="login-card">
  78. <h1><span class="icon">&#128193;</span>FTP Server 管理面板</h1>
  79. <div class="form-group">
  80. <label>用户名</label>
  81. <input type="text" id="loginUser" placeholder="请输入管理员用户名" value="admin">
  82. </div>
  83. <div class="form-group">
  84. <label>密码</label>
  85. <input type="password" id="loginPass" placeholder="请输入密码" value="">
  86. </div>
  87. <button class="btn btn-primary" onclick="doLogin()">登 录</button>
  88. <div class="error-msg" id="loginError"></div>
  89. </div>
  90. </div>
  91. <!-- Dashboard -->
  92. <div class="app-container" id="appContainer">
  93. <div class="header">
  94. <h1>&#128193; FTP Server 管理面板</h1>
  95. <div class="user-info">
  96. <span id="welcomeText">欢迎, Admin</span>
  97. <button class="btn btn-sm btn-danger" onclick="doLogout()">退出登录</button>
  98. </div>
  99. </div>
  100. <div class="sidebar">
  101. <a href="#" class="active" onclick="showSection('dashboard', this)">&#128202; 仪表盘</a>
  102. <a href="#" onclick="showSection('users', this)">&#128100; 用户管理</a>
  103. <a href="#" onclick="showSection('settings', this)">&#9881; 系统设置</a>
  104. </div>
  105. <div class="main-content">
  106. <!-- Dashboard Section -->
  107. <div class="section active" id="section-dashboard">
  108. <div class="stats-grid">
  109. <div class="stat-card">
  110. <div class="label">服务状态</div>
  111. <div class="value green">运行中</div>
  112. </div>
  113. <div class="stat-card">
  114. <div class="label">FTP 端口</div>
  115. <div class="value purple" id="statFtpPort">-</div>
  116. </div>
  117. <div class="stat-card">
  118. <div class="label">Web 端口</div>
  119. <div class="value blue" id="statWebPort">-</div>
  120. </div>
  121. <div class="stat-card">
  122. <div class="label">FTP 用户数</div>
  123. <div class="value" id="statUserCount">-</div>
  124. </div>
  125. </div>
  126. <div class="card">
  127. <h2>服务器信息</h2>
  128. <table>
  129. <tr><td style="width:200px;font-weight:600;">FTP 根目录</td><td id="infoRootDir">-</td></tr>
  130. <tr><td style="font-weight:600;">被动模式端口范围</td><td id="infoPassiveRange">-</td></tr>
  131. <tr><td style="font-weight:600;">管理面板地址</td><td id="infoWebAddr">-</td></tr>
  132. </table>
  133. </div>
  134. </div>
  135. <!-- Users Section -->
  136. <div class="section" id="section-users">
  137. <div class="card">
  138. <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:20px;">
  139. <h2 style="margin:0;border:none;padding:0;">FTP 用户管理</h2>
  140. <button class="btn btn-primary" style="width:auto;background:linear-gradient(135deg,#667eea,#764ba2);" onclick="showAddUserModal()">+ 添加用户</button>
  141. </div>
  142. <table>
  143. <thead>
  144. <tr><th>用户名</th><th>主目录</th><th>写入权限</th><th>操作</th></tr>
  145. </thead>
  146. <tbody id="userTableBody">
  147. </tbody>
  148. </table>
  149. </div>
  150. </div>
  151. <!-- Settings Section -->
  152. <div class="section" id="section-settings">
  153. <div class="card">
  154. <h2>FTP 服务设置</h2>
  155. <div class="config-grid">
  156. <div class="form-group">
  157. <label>FTP 监听地址</label>
  158. <input type="text" id="cfgFtpHost">
  159. </div>
  160. <div class="form-group">
  161. <label>FTP 端口</label>
  162. <input type="number" id="cfgFtpPort">
  163. </div>
  164. <div class="form-group">
  165. <label>被动模式起始端口</label>
  166. <input type="number" id="cfgPassiveMin">
  167. </div>
  168. <div class="form-group">
  169. <label>被动模式结束端口</label>
  170. <input type="number" id="cfgPassiveMax">
  171. </div>
  172. <div class="form-group">
  173. <label>FTP 根目录</label>
  174. <input type="text" id="cfgRootDir">
  175. </div>
  176. </div>
  177. </div>
  178. <div class="card">
  179. <h2>Web 管理面板设置</h2>
  180. <div class="config-grid">
  181. <div class="form-group">
  182. <label>Web 监听地址</label>
  183. <input type="text" id="cfgWebHost">
  184. </div>
  185. <div class="form-group">
  186. <label>Web 端口</label>
  187. <input type="number" id="cfgWebPort">
  188. </div>
  189. </div>
  190. </div>
  191. <div class="card">
  192. <h2>管理员密码</h2>
  193. <div class="config-grid">
  194. <div class="form-group">
  195. <label>新密码</label>
  196. <input type="password" id="cfgAdminPass" placeholder="输入新密码">
  197. </div>
  198. <div class="form-group">
  199. <label>确认密码</label>
  200. <input type="password" id="cfgAdminPassConfirm" placeholder="再次输入新密码">
  201. </div>
  202. </div>
  203. </div>
  204. <button class="btn btn-primary" style="width:auto;padding:12px 40px;" onclick="saveSettings()">保存设置</button>
  205. </div>
  206. </div>
  207. </div>
  208. <!-- Add/Edit User Modal -->
  209. <div class="modal-overlay" id="userModal">
  210. <div class="modal">
  211. <h2 id="userModalTitle">添加 FTP 用户</h2>
  212. <input type="hidden" id="editUserName">
  213. <div class="form-group">
  214. <label>用户名</label>
  215. <input type="text" id="modalUsername" placeholder="输入用户名">
  216. </div>
  217. <div class="form-group">
  218. <label>密码</label>
  219. <input type="password" id="modalPassword" placeholder="输入密码">
  220. </div>
  221. <div class="form-group">
  222. <label>主目录</label>
  223. <input type="text" id="modalHomeDir" placeholder="例如: ./ftp_root/user1">
  224. </div>
  225. <div class="form-group">
  226. <label><input type="checkbox" id="modalWrite" checked> 允许写入</label>
  227. </div>
  228. <div class="modal-actions">
  229. <button class="btn" style="background:#eee;" onclick="closeUserModal()">取消</button>
  230. <button class="btn btn-primary" style="width:auto;" onclick="saveUser()">保存</button>
  231. </div>
  232. </div>
  233. </div>
  234. <script>
  235. let authToken = localStorage.getItem('ftp_admin_token') || '';
  236. // Check auth on load
  237. window.onload = function() {
  238. if (authToken) {
  239. checkAuth();
  240. }
  241. };
  242. function checkAuth() {
  243. fetch('/api/status', {
  244. headers: { 'Authorization': 'Bearer ' + authToken }
  245. }).then(r => {
  246. if (r.ok) {
  247. showDashboard();
  248. } else {
  249. showLogin();
  250. }
  251. }).catch(() => showLogin());
  252. }
  253. function showLogin() {
  254. document.getElementById('loginPage').style.display = 'flex';
  255. document.getElementById('appContainer').style.display = 'none';
  256. }
  257. function showDashboard() {
  258. document.getElementById('loginPage').style.display = 'none';
  259. document.getElementById('appContainer').style.display = 'block';
  260. loadStatus();
  261. loadUsers();
  262. loadConfig();
  263. }
  264. function doLogin() {
  265. const username = document.getElementById('loginUser').value;
  266. const password = document.getElementById('loginPass').value;
  267. const errorEl = document.getElementById('loginError');
  268. if (!username || !password) {
  269. errorEl.textContent = '请输入用户名和密码';
  270. return;
  271. }
  272. fetch('/api/login', {
  273. method: 'POST',
  274. headers: { 'Content-Type': 'application/json' },
  275. body: JSON.stringify({ username, password })
  276. }).then(r => r.json()).then(data => {
  277. if (data.token) {
  278. authToken = data.token;
  279. localStorage.setItem('ftp_admin_token', authToken);
  280. showDashboard();
  281. } else {
  282. errorEl.textContent = data.error || '登录失败';
  283. }
  284. }).catch(() => {
  285. errorEl.textContent = '网络错误';
  286. });
  287. }
  288. function doLogout() {
  289. fetch('/api/logout', {
  290. headers: { 'Authorization': 'Bearer ' + authToken }
  291. }).finally(() => {
  292. authToken = '';
  293. localStorage.removeItem('ftp_admin_token');
  294. showLogin();
  295. });
  296. }
  297. function loadStatus() {
  298. fetch('/api/status', {
  299. headers: { 'Authorization': 'Bearer ' + authToken }
  300. }).then(r => r.json()).then(data => {
  301. document.getElementById('statFtpPort').textContent = data.ftpPort;
  302. document.getElementById('statWebPort').textContent = data.webPort;
  303. document.getElementById('statUserCount').textContent = data.userCount;
  304. document.getElementById('infoRootDir').textContent = data.rootDir;
  305. });
  306. }
  307. function loadConfig() {
  308. fetch('/api/config', {
  309. headers: { 'Authorization': 'Bearer ' + authToken }
  310. }).then(r => r.json()).then(data => {
  311. document.getElementById('cfgFtpHost').value = data.ftp.host;
  312. document.getElementById('cfgFtpPort').value = data.ftp.port;
  313. document.getElementById('cfgPassiveMin').value = data.ftp.passivePortMin;
  314. document.getElementById('cfgPassiveMax').value = data.ftp.passivePortMax;
  315. document.getElementById('cfgRootDir').value = data.ftp.rootDir;
  316. document.getElementById('cfgWebHost').value = data.web.host;
  317. document.getElementById('cfgWebPort').value = data.web.port;
  318. document.getElementById('infoPassiveRange').textContent = data.ftp.passivePortMin + ' - ' + data.ftp.passivePortMax;
  319. document.getElementById('infoWebAddr').textContent = 'http://' + data.web.host + ':' + data.web.port;
  320. });
  321. }
  322. function loadUsers() {
  323. fetch('/api/users', {
  324. headers: { 'Authorization': 'Bearer ' + authToken }
  325. }).then(r => r.json()).then(users => {
  326. const tbody = document.getElementById('userTableBody');
  327. tbody.innerHTML = '';
  328. if (users && users.length > 0) {
  329. users.forEach(u => {
  330. const tr = document.createElement('tr');
  331. const writeBadge = u.write ? '<span class="badge badge-success">可写</span>' : '<span class="badge badge-secondary">只读</span>';
  332. tr.innerHTML =
  333. '<td>' + u.username + '</td>' +
  334. '<td>' + u.homeDir + '</td>' +
  335. '<td>' + writeBadge + '</td>' +
  336. '<td class="actions-cell">' +
  337. '<button class="btn btn-sm" style="background:#667eea;color:white;" onclick="editUser(\'' + u.username + '\', \'' + u.homeDir + '\', ' + u.write + ')">编辑</button>' +
  338. '<button class="btn btn-sm btn-danger" onclick="deleteUser(\'' + u.username + '\')">删除</button>' +
  339. '</td>';
  340. tbody.appendChild(tr);
  341. });
  342. } else {
  343. tbody.innerHTML = '<tr><td colspan="4" style="text-align:center;color:#888;">暂无用户</td></tr>';
  344. }
  345. });
  346. }
  347. function showSection(name, el) {
  348. document.querySelectorAll('.section').forEach(s => s.classList.remove('active'));
  349. document.getElementById('section-' + name).classList.add('active');
  350. document.querySelectorAll('.sidebar a').forEach(a => a.classList.remove('active'));
  351. el.classList.add('active');
  352. if (name === 'dashboard') { loadStatus(); loadConfig(); }
  353. if (name === 'users') { loadUsers(); }
  354. if (name === 'settings') { loadConfig(); }
  355. }
  356. function showAddUserModal() {
  357. document.getElementById('userModalTitle').textContent = '添加 FTP 用户';
  358. document.getElementById('editUserName').value = '';
  359. document.getElementById('modalUsername').value = '';
  360. document.getElementById('modalUsername').disabled = false;
  361. document.getElementById('modalPassword').value = '';
  362. document.getElementById('modalHomeDir').value = '';
  363. document.getElementById('modalWrite').checked = true;
  364. document.getElementById('userModal').classList.add('show');
  365. }
  366. function editUser(username, homeDir, write) {
  367. document.getElementById('userModalTitle').textContent = '编辑 FTP 用户';
  368. document.getElementById('editUserName').value = username;
  369. document.getElementById('modalUsername').value = username;
  370. document.getElementById('modalUsername').disabled = true;
  371. document.getElementById('modalPassword').value = '';
  372. document.getElementById('modalPassword').placeholder = '留空则不修改密码';
  373. document.getElementById('modalHomeDir').value = homeDir;
  374. document.getElementById('modalWrite').checked = write;
  375. document.getElementById('userModal').classList.add('show');
  376. }
  377. function closeUserModal() {
  378. document.getElementById('userModal').classList.remove('show');
  379. document.getElementById('modalPassword').placeholder = '输入密码';
  380. }
  381. function saveUser() {
  382. const editUser = document.getElementById('editUserName').value;
  383. const username = document.getElementById('modalUsername').value;
  384. const password = document.getElementById('modalPassword').value;
  385. const homeDir = document.getElementById('modalHomeDir').value;
  386. const write = document.getElementById('modalWrite').checked;
  387. if (!username) { showToast('请输入用户名', 'error'); return; }
  388. if (editUser) {
  389. // Update existing user
  390. const user = { username, homeDir, write };
  391. if (password) user.password = password;
  392. else {
  393. // Keep existing password - send a flag
  394. user.keepPassword = true;
  395. }
  396. fetch('/api/users/update', {
  397. method: 'POST',
  398. headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + authToken },
  399. body: JSON.stringify({ username: editUser, user })
  400. }).then(r => r.json()).then(data => {
  401. if (data.status === 'ok') {
  402. showToast('用户已更新');
  403. loadUsers();
  404. closeUserModal();
  405. } else {
  406. showToast(data.error || '更新失败', 'error');
  407. }
  408. });
  409. } else {
  410. // Add new user
  411. if (!password) { showToast('请输入密码', 'error'); return; }
  412. fetch('/api/users/add', {
  413. method: 'POST',
  414. headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + authToken },
  415. body: JSON.stringify({ username, password, homeDir, write })
  416. }).then(r => r.json()).then(data => {
  417. if (data.status === 'ok') {
  418. showToast('用户已添加');
  419. loadUsers();
  420. closeUserModal();
  421. } else {
  422. showToast(data.error || '添加失败', 'error');
  423. }
  424. });
  425. }
  426. }
  427. function deleteUser(username) {
  428. if (!confirm('确定要删除用户 "' + username + '" 吗?')) return;
  429. fetch('/api/users/delete', {
  430. method: 'POST',
  431. headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + authToken },
  432. body: JSON.stringify({ username })
  433. }).then(r => r.json()).then(data => {
  434. if (data.status === 'ok') {
  435. showToast('用户已删除');
  436. loadUsers();
  437. } else {
  438. showToast(data.error || '删除失败', 'error');
  439. }
  440. });
  441. }
  442. function saveSettings() {
  443. const adminPass = document.getElementById('cfgAdminPass').value;
  444. const adminPassConfirm = document.getElementById('cfgAdminPassConfirm').value;
  445. if (adminPass && adminPass !== adminPassConfirm) {
  446. showToast('两次密码输入不一致', 'error');
  447. return;
  448. }
  449. const update = {
  450. ftp: {
  451. host: document.getElementById('cfgFtpHost').value,
  452. port: parseInt(document.getElementById('cfgFtpPort').value),
  453. passivePortMin: parseInt(document.getElementById('cfgPassiveMin').value),
  454. passivePortMax: parseInt(document.getElementById('cfgPassiveMax').value),
  455. rootDir: document.getElementById('cfgRootDir').value
  456. },
  457. web: {
  458. host: document.getElementById('cfgWebHost').value,
  459. port: parseInt(document.getElementById('cfgWebPort').value)
  460. }
  461. };
  462. if (adminPass) {
  463. update.adminPassword = adminPass;
  464. }
  465. fetch('/api/config/update', {
  466. method: 'POST',
  467. headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + authToken },
  468. body: JSON.stringify(update)
  469. }).then(r => r.json()).then(data => {
  470. if (data.status === 'ok') {
  471. showToast('设置已保存,部分设置需重启服务生效');
  472. document.getElementById('cfgAdminPass').value = '';
  473. document.getElementById('cfgAdminPassConfirm').value = '';
  474. loadConfig();
  475. loadStatus();
  476. } else {
  477. showToast(data.error || '保存失败', 'error');
  478. }
  479. });
  480. }
  481. function showToast(msg, type) {
  482. const toast = document.createElement('div');
  483. toast.className = 'toast ' + (type === 'error' ? 'toast-error' : 'toast-success');
  484. toast.textContent = msg;
  485. document.body.appendChild(toast);
  486. setTimeout(() => toast.remove(), 3000);
  487. }
  488. // Handle Enter key on login
  489. document.getElementById('loginPass').addEventListener('keypress', function(e) {
  490. if (e.key === 'Enter') doLogin();
  491. });
  492. </script>
  493. </body>
  494. </html>
  495. `