DevicesView.vue 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. <template>
  2. <div class="page">
  3. <div class="page-header">
  4. <div>
  5. <h1>{{ $t('devices.title') }}</h1>
  6. <p>{{ $t('devices.manage') }}</p>
  7. </div>
  8. </div>
  9. <!-- Device Registration Toggle -->
  10. <div class="registration-banner" :class="{ enabled: autoRegistrationEnabled }">
  11. <div class="registration-content">
  12. <div class="registration-info">
  13. <h2>
  14. <span v-if="autoRegistrationEnabled">🟢 {{ $t('devices.registrationEnabled') }}</span>
  15. <span v-else>🔴 {{ $t('devices.registrationDisabled') }}</span>
  16. </h2>
  17. <p v-if="autoRegistrationEnabled" class="warning">
  18. ⚠️ {{ $t('devices.registrationWarning') }}
  19. <span v-if="registrationTimeLeft > 0">
  20. - {{ $t('devices.autoDisableIn') }} {{ formatTimeLeft(registrationTimeLeft) }}
  21. </span>
  22. </p>
  23. <p v-else>{{ $t('devices.registrationHint') }}</p>
  24. </div>
  25. <div class="registration-toggle">
  26. <label class="toggle-switch-large">
  27. <input
  28. type="checkbox"
  29. :checked="autoRegistrationEnabled"
  30. @change="toggleAutoRegistration"
  31. :disabled="togglingRegistration"
  32. />
  33. <span class="toggle-slider"></span>
  34. <span v-if="togglingRegistration" class="spinner">⏳</span>
  35. </label>
  36. </div>
  37. </div>
  38. </div>
  39. <div class="content">
  40. <!-- Search and Filters -->
  41. <div class="filters-row">
  42. <div class="search-box">
  43. <input
  44. v-model="searchQuery"
  45. type="text"
  46. :placeholder="$t('devices.searchPlaceholder')"
  47. class="search-input"
  48. @input="onSearch"
  49. />
  50. <span v-if="searchQuery" class="search-clear" @click="clearSearch">×</span>
  51. </div>
  52. <label class="filter-checkbox">
  53. <input type="checkbox" v-model="onlineOnly" @change="loadDevices" />
  54. <span>{{ $t('devices.onlineOnly') }}</span>
  55. </label>
  56. <button @click="showDefaultConfigModal" class="btn-primary btn-edit-default">
  57. Edit Default Config
  58. </button>
  59. </div>
  60. <div v-if="loading" class="loading">{{ $t('common.loading') }}</div>
  61. <div v-else-if="error" class="error">{{ error }}</div>
  62. <table v-else-if="devices.length > 0" class="data-table">
  63. <thead>
  64. <tr>
  65. <th @click="sortBy('simple_id')">
  66. {{ $t('devices.simpleId') }}
  67. <span v-if="sortColumn === 'simple_id'">{{ sortDirection === 'asc' ? '↑' : '↓' }}</span>
  68. </th>
  69. <th @click="sortBy('mac_address')">
  70. {{ $t('devices.macAddress') }}
  71. <span v-if="sortColumn === 'mac_address'">{{ sortDirection === 'asc' ? '↑' : '↓' }}</span>
  72. </th>
  73. <th>BLE Enabled</th>
  74. <th>WiFi Enabled</th>
  75. <th @click="sortBy('status')">
  76. {{ $t('common.status') }}
  77. <span v-if="sortColumn === 'status'">{{ sortDirection === 'asc' ? '↑' : '↓' }}</span>
  78. </th>
  79. <th @click="sortBy('last_seen_at')">
  80. {{ $t('devices.lastSeen') }}
  81. <span v-if="sortColumn === 'last_seen_at'">{{ sortDirection === 'asc' ? '↑' : '↓' }}</span>
  82. </th>
  83. <th>{{ $t('common.actions') }}</th>
  84. </tr>
  85. </thead>
  86. <tbody>
  87. <tr v-for="device in sortedDevices" :key="device.id">
  88. <td><strong>#{{ device.simple_id }}</strong></td>
  89. <td><code>{{ device.mac_address }}</code></td>
  90. <td class="text-center">
  91. <label class="toggle-switch-inline">
  92. <input
  93. type="checkbox"
  94. :checked="device.config?.ble?.enabled ?? false"
  95. @click="toggleBLE(device, $event)"
  96. />
  97. <span class="toggle-slider"></span>
  98. </label>
  99. </td>
  100. <td class="text-center">
  101. <label class="toggle-switch-inline">
  102. <input
  103. type="checkbox"
  104. :checked="device.config?.wifi?.monitor_enabled ?? false"
  105. @click="toggleWiFi(device, $event)"
  106. />
  107. <span class="toggle-slider"></span>
  108. </label>
  109. </td>
  110. <td><span class="badge" :class="`status-${device.status}`">{{ $t(`devices.${device.status}`) }}</span></td>
  111. <td>{{ formatRelativeTime(device.last_seen_at) }}</td>
  112. <td>
  113. <button @click="showEditModal(device)" class="btn-icon" title="Edit">✏️</button>
  114. <button
  115. @click="openSSH(device)"
  116. class="btn-icon"
  117. :class="{ loading: tunnelLoading[`${device.id}:ssh`] }"
  118. :disabled="tunnelLoading[`${device.id}:ssh`]"
  119. :title="tunnelLoading[`${device.id}:ssh`] ? 'Connecting...' : 'SSH Terminal'">
  120. <span v-if="tunnelLoading[`${device.id}:ssh`]" class="spinner">⏳</span>
  121. <span v-else>🖥️</span>
  122. </button>
  123. <button
  124. @click="openDashboard(device)"
  125. class="btn-icon"
  126. :class="{ loading: tunnelLoading[`${device.id}:dashboard`] }"
  127. :disabled="tunnelLoading[`${device.id}:dashboard`]"
  128. :title="tunnelLoading[`${device.id}:dashboard`] ? 'Connecting...' : 'Dashboard'">
  129. <span v-if="tunnelLoading[`${device.id}:dashboard`]" class="spinner">⏳</span>
  130. <span v-else>📊</span>
  131. </button>
  132. </td>
  133. </tr>
  134. </tbody>
  135. </table>
  136. <div v-else class="empty">No devices yet</div>
  137. </div>
  138. <!-- Edit Modal -->
  139. <div v-if="modalVisible" class="modal-overlay" @click="closeModal">
  140. <div class="modal modal-wide" @click.stop>
  141. <div class="modal-header">
  142. <h2>Device #{{ editingDevice?.simple_id }} - {{ editingDevice?.mac_address }}</h2>
  143. <button @click="closeModal" class="btn-close">×</button>
  144. </div>
  145. <form @submit.prevent="saveDevice" class="modal-body">
  146. <!-- WiFi Scanner Section -->
  147. <div class="config-section">
  148. <h3>WiFi Scanner</h3>
  149. <div class="toggle-row">
  150. <span>{{ $t('devices.config.wifiScannerEnabled') }}</span>
  151. <label class="toggle-switch">
  152. <input type="checkbox" v-model="config.wifi.monitor_enabled" @change="onWifiMonitorChange" />
  153. <span class="toggle-slider"></span>
  154. </label>
  155. </div>
  156. <div v-if="config.wifi.monitor_enabled" class="toggle-content">
  157. <div class="form-group">
  158. <label>{{ $t('devices.config.wifiBatchInterval') }} (ms)</label>
  159. <input v-model.number="config.wifi.batch_interval_ms" type="number" min="1000" step="1000" />
  160. </div>
  161. <div class="form-group">
  162. <label>{{ $t('devices.config.uploadEndpoint') }}</label>
  163. <input v-model="config.wifi.upload_endpoint" type="text" placeholder="http://custom.example.com:8080/wifi" />
  164. <div class="form-hint">{{ $t('devices.config.uploadEndpointHint') }}</div>
  165. </div>
  166. </div>
  167. </div>
  168. <!-- BLE Section -->
  169. <div class="config-section">
  170. <h3>BLE Scanner</h3>
  171. <div class="toggle-row">
  172. <span>{{ $t('devices.config.bleScannerEnabled') }}</span>
  173. <label class="toggle-switch">
  174. <input type="checkbox" v-model="config.ble.enabled" />
  175. <span class="toggle-slider"></span>
  176. </label>
  177. </div>
  178. <div v-if="config.ble.enabled" class="toggle-content">
  179. <div class="form-group">
  180. <label>{{ $t('devices.config.bleBatchInterval') }} (ms)</label>
  181. <input v-model.number="config.ble.batch_interval_ms" type="number" min="100" step="100" />
  182. </div>
  183. <div class="form-group">
  184. <label>{{ $t('devices.config.uuidFilter') }}</label>
  185. <input v-model="config.ble.uuid_filter_hex" type="text" placeholder="f7826da64fa24e988024bc5b71e0893e" maxlength="32" />
  186. <div class="form-hint">{{ $t('devices.config.uuidFilterHint') }}</div>
  187. </div>
  188. <div class="form-group">
  189. <label>{{ $t('devices.config.uploadEndpoint') }}</label>
  190. <input v-model="config.ble.upload_endpoint" type="text" placeholder="http://custom.example.com:8080/ble" />
  191. <div class="form-hint">{{ $t('devices.config.uploadEndpointHint') }}</div>
  192. </div>
  193. </div>
  194. </div>
  195. <!-- WiFi Client Section -->
  196. <div class="config-section">
  197. <h3>WiFi Client</h3>
  198. <div class="toggle-row">
  199. <span>{{ $t('devices.config.wifiClientEnabled') }}</span>
  200. <label class="toggle-switch">
  201. <input type="checkbox" v-model="config.wifi.client_enabled" @change="onWifiClientChange" />
  202. <span class="toggle-slider"></span>
  203. </label>
  204. </div>
  205. <div v-if="config.wifi.client_enabled" class="toggle-content">
  206. <div class="form-row">
  207. <div class="form-group">
  208. <label>{{ $t('devices.config.wifiSsid') }}</label>
  209. <input v-model="config.wifi.ssid" type="text" />
  210. </div>
  211. <div class="form-group">
  212. <label>{{ $t('devices.config.wifiPassword') }}</label>
  213. <input v-model="config.wifi.psk" type="password" />
  214. </div>
  215. </div>
  216. </div>
  217. </div>
  218. <!-- NTP Section -->
  219. <div class="config-section">
  220. <h3>NTP Servers</h3>
  221. <div class="form-group">
  222. <label>{{ $t('devices.config.ntpServers') }}</label>
  223. <input v-model="ntpServersText" type="text" placeholder="pool.ntp.org, time.google.com" />
  224. <div class="form-hint">{{ $t('devices.config.ntpHint') }}</div>
  225. </div>
  226. </div>
  227. <!-- Other Settings -->
  228. <div class="config-section">
  229. <h3>Other</h3>
  230. <div class="form-group">
  231. <label>Config Polling Timeout (seconds)</label>
  232. <input v-model.number="config.cfg_polling_timeout" type="number" min="5" max="300" step="5" />
  233. <div class="form-hint">How often device fetches config from server (min: 5s, recommended: 30-300s)</div>
  234. </div>
  235. <div class="toggle-row">
  236. <span>{{ $t('devices.config.forceCloud') }}</span>
  237. <label class="toggle-switch">
  238. <input type="checkbox" v-model="config.force_cloud" />
  239. <span class="toggle-slider"></span>
  240. </label>
  241. </div>
  242. <div class="toggle-row">
  243. <span>{{ $t('devices.config.debug') }}</span>
  244. <label class="toggle-switch">
  245. <input type="checkbox" v-model="config.debug" />
  246. <span class="toggle-slider"></span>
  247. </label>
  248. </div>
  249. <div class="toggle-row">
  250. <span>{{ $t('devices.config.dashboardEnabled') }}</span>
  251. <label class="toggle-switch">
  252. <input type="checkbox" v-model="config.dashboard.enabled" />
  253. <span class="toggle-slider"></span>
  254. </label>
  255. </div>
  256. </div>
  257. <div class="modal-footer">
  258. <button type="button" @click="deleteDevice" class="btn-danger btn-delete" :disabled="saving">
  259. Delete Device
  260. </button>
  261. <div style="flex: 1"></div>
  262. <button type="button" @click="closeModal" class="btn-secondary">{{ $t('common.cancel') }}</button>
  263. <button type="submit" :disabled="saving" class="btn-primary">
  264. {{ saving ? $t('common.loading') : $t('common.save') }}
  265. </button>
  266. </div>
  267. </form>
  268. </div>
  269. </div>
  270. <!-- Edit Default Config Modal -->
  271. <div v-if="defaultConfigModalVisible" class="modal-overlay" @click="closeDefaultConfigModal">
  272. <div class="modal modal-wide" @click.stop>
  273. <div class="modal-header">
  274. <h2>Edit Default Device Configuration</h2>
  275. <button @click="closeDefaultConfigModal" class="btn-close">×</button>
  276. </div>
  277. <!-- Tabs -->
  278. <div class="modal-tabs">
  279. <button
  280. @click="defaultConfigTab = 'interactive'"
  281. :class="['tab-button', { active: defaultConfigTab === 'interactive' }]"
  282. >
  283. Interactive
  284. </button>
  285. <button
  286. @click="switchToJsonTab"
  287. :class="['tab-button', { active: defaultConfigTab === 'json' }]"
  288. >
  289. JSON
  290. </button>
  291. </div>
  292. <div class="modal-body">
  293. <p style="margin-bottom: 16px; color: #718096; font-size: 14px;">
  294. This configuration will be copied to all newly registered devices.
  295. Changes do not affect existing devices.
  296. </p>
  297. <!-- Interactive Tab -->
  298. <div v-if="defaultConfigTab === 'interactive'">
  299. <!-- WiFi Scanner Section -->
  300. <div class="config-section">
  301. <h3>WiFi Scanner</h3>
  302. <div class="toggle-row">
  303. <span>WiFi Scanner Enabled</span>
  304. <label class="toggle-switch">
  305. <input type="checkbox" v-model="defaultConfig.wifi.monitor_enabled" @change="onDefaultWifiMonitorChange" />
  306. <span class="toggle-slider"></span>
  307. </label>
  308. </div>
  309. <div v-if="defaultConfig.wifi.monitor_enabled" class="toggle-content">
  310. <div class="form-group">
  311. <label>Batch Interval (ms)</label>
  312. <input v-model.number="defaultConfig.wifi.batch_interval_ms" type="number" min="1000" step="1000" />
  313. </div>
  314. <div class="form-group">
  315. <label>Upload Endpoint (optional)</label>
  316. <input v-model="defaultConfig.wifi.upload_endpoint" type="text" placeholder="http://custom.example.com:8080/wifi" />
  317. <div class="form-hint">Custom upload endpoint URL (leave empty for default)</div>
  318. </div>
  319. </div>
  320. </div>
  321. <!-- BLE Section -->
  322. <div class="config-section">
  323. <h3>BLE Scanner</h3>
  324. <div class="toggle-row">
  325. <span>BLE Scanner Enabled</span>
  326. <label class="toggle-switch">
  327. <input type="checkbox" v-model="defaultConfig.ble.enabled" />
  328. <span class="toggle-slider"></span>
  329. </label>
  330. </div>
  331. <div v-if="defaultConfig.ble.enabled" class="toggle-content">
  332. <div class="form-group">
  333. <label>Batch Interval (ms)</label>
  334. <input v-model.number="defaultConfig.ble.batch_interval_ms" type="number" min="100" step="100" />
  335. </div>
  336. <div class="form-group">
  337. <label>UUID Filter</label>
  338. <input v-model="defaultConfig.ble.uuid_filter_hex" type="text" placeholder="f7826da64fa24e988024bc5b71e0893e" maxlength="32" />
  339. <div class="form-hint">Filter beacons by UUID (32 hex chars, optional)</div>
  340. </div>
  341. <div class="form-group">
  342. <label>Upload Endpoint (optional)</label>
  343. <input v-model="defaultConfig.ble.upload_endpoint" type="text" placeholder="http://custom.example.com:8080/ble" />
  344. <div class="form-hint">Custom upload endpoint URL (leave empty for default)</div>
  345. </div>
  346. </div>
  347. </div>
  348. <!-- WiFi Client Section -->
  349. <div class="config-section">
  350. <h3>WiFi Client</h3>
  351. <div class="toggle-row">
  352. <span>WiFi Client Enabled</span>
  353. <label class="toggle-switch">
  354. <input type="checkbox" v-model="defaultConfig.wifi.client_enabled" @change="onDefaultWifiClientChange" />
  355. <span class="toggle-slider"></span>
  356. </label>
  357. </div>
  358. <div v-if="defaultConfig.wifi.client_enabled" class="toggle-content">
  359. <div class="form-row">
  360. <div class="form-group">
  361. <label>WiFi SSID</label>
  362. <input v-model="defaultConfig.wifi.ssid" type="text" />
  363. </div>
  364. <div class="form-group">
  365. <label>WiFi Password</label>
  366. <input v-model="defaultConfig.wifi.psk" type="password" />
  367. </div>
  368. </div>
  369. </div>
  370. </div>
  371. <!-- NTP Section -->
  372. <div class="config-section">
  373. <h3>NTP Servers</h3>
  374. <div class="form-group">
  375. <label>NTP Servers</label>
  376. <input v-model="defaultNtpServersText" type="text" placeholder="pool.ntp.org, time.google.com" />
  377. <div class="form-hint">Comma-separated list of NTP server addresses</div>
  378. </div>
  379. </div>
  380. <!-- Other Settings -->
  381. <div class="config-section">
  382. <h3>Other</h3>
  383. <div class="form-group">
  384. <label>Config Polling Timeout (seconds)</label>
  385. <input v-model.number="defaultConfig.cfg_polling_timeout" type="number" min="5" max="300" step="5" />
  386. <div class="form-hint">How often device fetches config from server (min: 5s, recommended: 30-300s)</div>
  387. </div>
  388. <div class="toggle-row">
  389. <span>Force Cloud Mode</span>
  390. <label class="toggle-switch">
  391. <input type="checkbox" v-model="defaultConfig.force_cloud" />
  392. <span class="toggle-slider"></span>
  393. </label>
  394. </div>
  395. <div class="toggle-row">
  396. <span>Debug Logging</span>
  397. <label class="toggle-switch">
  398. <input type="checkbox" v-model="defaultConfig.debug" />
  399. <span class="toggle-slider"></span>
  400. </label>
  401. </div>
  402. <div class="toggle-row">
  403. <span>Dashboard Enabled</span>
  404. <label class="toggle-switch">
  405. <input type="checkbox" v-model="defaultConfig.dashboard.enabled" />
  406. <span class="toggle-slider"></span>
  407. </label>
  408. </div>
  409. </div>
  410. </div>
  411. <!-- JSON Tab -->
  412. <div v-if="defaultConfigTab === 'json'">
  413. <div class="form-group">
  414. <label>Configuration (JSON)</label>
  415. <textarea
  416. v-model="defaultConfigJson"
  417. rows="25"
  418. class="config-editor"
  419. @input="validateJson"
  420. ></textarea>
  421. <div v-if="jsonError" class="form-error">{{ jsonError }}</div>
  422. </div>
  423. </div>
  424. </div>
  425. <div class="modal-footer">
  426. <button type="button" @click="closeDefaultConfigModal" class="btn-secondary">Cancel</button>
  427. <button
  428. type="button"
  429. @click="saveDefaultConfig"
  430. :disabled="savingDefaultConfig || (defaultConfigTab === 'json' && !!jsonError)"
  431. class="btn-primary"
  432. >
  433. {{ savingDefaultConfig ? 'Saving...' : 'Save Default Config' }}
  434. </button>
  435. </div>
  436. </div>
  437. </div>
  438. </div>
  439. </template>
  440. <script setup>
  441. import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
  442. import devicesApi from '@/api/devices'
  443. import organizationsApi from '@/api/organizations'
  444. import tunnelsApi from '@/api/tunnels'
  445. import settingsApi from '@/api/settings'
  446. // Auto-registration state
  447. const autoRegistrationEnabled = ref(false)
  448. const togglingRegistration = ref(false)
  449. const registrationTimeLeft = ref(0)
  450. let registrationTimer = null
  451. const devices = ref([])
  452. const organizations = ref([])
  453. const loading = ref(false)
  454. const error = ref(null)
  455. const modalVisible = ref(false)
  456. const editingDevice = ref(null)
  457. const saving = ref(false)
  458. const searchQuery = ref('')
  459. const onlineOnly = ref(false)
  460. const sortColumn = ref('simple_id')
  461. const sortDirection = ref('desc')
  462. const ntpServersText = ref('')
  463. const tunnelLoading = ref({})
  464. const defaultConfigModalVisible = ref(false)
  465. const defaultConfigTab = ref('interactive')
  466. const defaultConfigJson = ref('')
  467. const savingDefaultConfig = ref(false)
  468. const jsonError = ref(null)
  469. const defaultNtpServersText = ref('')
  470. const defaultConfig = ref({
  471. force_cloud: false,
  472. cfg_polling_timeout: 30,
  473. ble: {
  474. enabled: true,
  475. batch_interval_ms: 2500,
  476. uuid_filter_hex: '',
  477. upload_endpoint: ''
  478. },
  479. wifi: {
  480. client_enabled: false,
  481. ssid: '',
  482. psk: '',
  483. monitor_enabled: true,
  484. batch_interval_ms: 10000,
  485. upload_endpoint: ''
  486. },
  487. ssh_tunnel: {
  488. enabled: false,
  489. server: '192.168.5.4',
  490. port: 22,
  491. user: 'tunnel',
  492. remote_port: 0,
  493. keepalive_interval: 30
  494. },
  495. dashboard_tunnel: {
  496. enabled: false,
  497. server: '192.168.5.4',
  498. port: 22,
  499. user: 'tunnel',
  500. remote_port: 0,
  501. keepalive_interval: 30
  502. },
  503. dashboard: {
  504. enabled: true
  505. },
  506. net: {
  507. ntp: {
  508. servers: ['pool.ntp.org', 'time.google.com']
  509. }
  510. },
  511. debug: false
  512. })
  513. let searchDebounceTimer = null
  514. let pollingInterval = null
  515. const config = ref({
  516. force_cloud: false,
  517. cfg_polling_timeout: 30,
  518. ble: {
  519. enabled: true,
  520. batch_interval_ms: 2500,
  521. uuid_filter_hex: '',
  522. upload_endpoint: ''
  523. },
  524. wifi: {
  525. client_enabled: false,
  526. ssid: '',
  527. psk: '',
  528. monitor_enabled: true,
  529. batch_interval_ms: 10000,
  530. upload_endpoint: ''
  531. },
  532. dashboard: {
  533. enabled: true
  534. },
  535. net: {
  536. ntp: {
  537. servers: ['pool.ntp.org', 'time.google.com']
  538. }
  539. },
  540. debug: false
  541. })
  542. const sortedDevices = computed(() => {
  543. let result = [...devices.value]
  544. // Sort
  545. result.sort((a, b) => {
  546. let aVal = a[sortColumn.value]
  547. let bVal = b[sortColumn.value]
  548. // Handle nulls
  549. if (aVal === null || aVal === undefined) return 1
  550. if (bVal === null || bVal === undefined) return -1
  551. // String comparison
  552. if (typeof aVal === 'string') {
  553. aVal = aVal.toLowerCase()
  554. bVal = bVal.toLowerCase()
  555. }
  556. if (aVal < bVal) return sortDirection.value === 'asc' ? -1 : 1
  557. if (aVal > bVal) return sortDirection.value === 'asc' ? 1 : -1
  558. return 0
  559. })
  560. return result
  561. })
  562. function sortBy(column) {
  563. if (sortColumn.value === column) {
  564. sortDirection.value = sortDirection.value === 'asc' ? 'desc' : 'asc'
  565. } else {
  566. sortColumn.value = column
  567. sortDirection.value = 'asc'
  568. }
  569. }
  570. async function loadDevices(silent = false) {
  571. // Only show loading spinner on initial load, not on polling updates
  572. if (!silent) {
  573. loading.value = true
  574. }
  575. error.value = null
  576. try {
  577. const params = {}
  578. if (searchQuery.value && searchQuery.value.length >= 2) {
  579. params.search = searchQuery.value
  580. }
  581. if (onlineOnly.value) {
  582. params.status = 'online'
  583. }
  584. devices.value = await devicesApi.getAllSuperadmin(params)
  585. } catch (err) {
  586. error.value = err.response?.data?.detail || 'Failed to load devices'
  587. } finally {
  588. loading.value = false
  589. }
  590. }
  591. function onSearch() {
  592. // Debounce search - wait 300ms after user stops typing
  593. clearTimeout(searchDebounceTimer)
  594. searchDebounceTimer = setTimeout(() => {
  595. loadDevices()
  596. }, 300)
  597. }
  598. function clearSearch() {
  599. searchQuery.value = ''
  600. loadDevices()
  601. }
  602. async function loadOrganizations() {
  603. try {
  604. organizations.value = await organizationsApi.getAll()
  605. } catch (err) {
  606. console.error('Failed to load organizations:', err)
  607. }
  608. }
  609. function formatDate(dateStr) {
  610. if (!dateStr) return 'Never'
  611. const date = new Date(dateStr)
  612. return date.toLocaleString()
  613. }
  614. function formatRelativeTime(dateStr) {
  615. if (!dateStr) return 'Never'
  616. const now = new Date()
  617. const then = new Date(dateStr)
  618. const diffMs = now - then
  619. const diffMinutes = Math.floor(diffMs / 60000)
  620. if (diffMinutes < 1) {
  621. return 'Just now'
  622. } else if (diffMinutes < 120) {
  623. return `${diffMinutes} min ago`
  624. } else {
  625. const diffHours = Math.floor(diffMinutes / 60)
  626. if (diffHours < 24) {
  627. return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`
  628. } else {
  629. const diffDays = Math.floor(diffHours / 24)
  630. return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`
  631. }
  632. }
  633. }
  634. function showEditModal(device) {
  635. editingDevice.value = device
  636. // Deep copy device config with defaults
  637. config.value = {
  638. force_cloud: device.config?.force_cloud ?? false,
  639. cfg_polling_timeout: device.config?.cfg_polling_timeout ?? 30,
  640. ble: {
  641. enabled: device.config?.ble?.enabled ?? true,
  642. batch_interval_ms: device.config?.ble?.batch_interval_ms ?? 2500,
  643. uuid_filter_hex: device.config?.ble?.uuid_filter_hex ?? '',
  644. upload_endpoint: device.config?.ble?.upload_endpoint ?? ''
  645. },
  646. wifi: {
  647. client_enabled: device.config?.wifi?.client_enabled ?? false,
  648. ssid: device.config?.wifi?.ssid ?? '',
  649. psk: device.config?.wifi?.psk ?? '',
  650. monitor_enabled: device.config?.wifi?.monitor_enabled ?? true,
  651. batch_interval_ms: device.config?.wifi?.batch_interval_ms ?? 10000,
  652. upload_endpoint: device.config?.wifi?.upload_endpoint ?? ''
  653. },
  654. dashboard: {
  655. enabled: device.config?.dashboard?.enabled ?? true
  656. },
  657. net: {
  658. ntp: {
  659. servers: device.config?.net?.ntp?.servers ?? ['pool.ntp.org', 'time.google.com']
  660. }
  661. },
  662. debug: device.config?.debug ?? false
  663. }
  664. // Convert NTP servers array to comma-separated string
  665. ntpServersText.value = config.value.net.ntp.servers.join(', ')
  666. modalVisible.value = true
  667. }
  668. function closeModal() {
  669. modalVisible.value = false
  670. editingDevice.value = null
  671. }
  672. function onWifiClientChange() {
  673. // WiFi client и monitor взаимоисключающие (AIC8800 ограничение)
  674. if (config.value.wifi.client_enabled) {
  675. config.value.wifi.monitor_enabled = false
  676. }
  677. }
  678. function onWifiMonitorChange() {
  679. // WiFi client и monitor взаимоисключающие (AIC8800 ограничение)
  680. if (config.value.wifi.monitor_enabled) {
  681. config.value.wifi.client_enabled = false
  682. }
  683. }
  684. async function saveDevice() {
  685. saving.value = true
  686. try {
  687. // Parse NTP servers from comma-separated string to array
  688. config.value.net.ntp.servers = ntpServersText.value
  689. .split(',')
  690. .map(s => s.trim())
  691. .filter(s => s.length > 0)
  692. await devicesApi.updateSuperadmin(editingDevice.value.id, { config: config.value })
  693. await loadDevices()
  694. closeModal()
  695. } catch (err) {
  696. alert(err.response?.data?.detail || 'Failed to save device')
  697. } finally {
  698. saving.value = false
  699. }
  700. }
  701. async function deleteDevice() {
  702. const deviceName = `#${editingDevice.value.simple_id} (${editingDevice.value.mac_address})`
  703. const confirmed = confirm(
  704. `Are you sure you want to DELETE device ${deviceName}?\n\n` +
  705. `This will permanently remove the device from the system.\n` +
  706. `The device will need to re-register to be used again.\n\n` +
  707. `This action CANNOT be undone!`
  708. )
  709. if (!confirmed) {
  710. return
  711. }
  712. saving.value = true
  713. try {
  714. await devicesApi.deleteSuperadmin(editingDevice.value.id)
  715. await loadDevices()
  716. closeModal()
  717. } catch (err) {
  718. alert(err.response?.data?.detail || 'Failed to delete device')
  719. saving.value = false
  720. }
  721. }
  722. async function openTunnel(device, tunnelType) {
  723. const loadingKey = `${device.id}:${tunnelType}`
  724. tunnelLoading.value[loadingKey] = true
  725. try {
  726. // Step 1: Enable tunnel, get session UUID
  727. const { session_uuid } = await tunnelsApi.enableTunnel(device.id, tunnelType)
  728. // Step 2: Poll for tunnel status
  729. const maxAttempts = 60 // 60 seconds max wait
  730. let attempts = 0
  731. let opened = false // Prevent multiple window.open()
  732. const pollInterval = setInterval(async () => {
  733. attempts++
  734. try {
  735. const status = await tunnelsApi.getSessionStatus(session_uuid)
  736. if (status.status === 'ready' && status.tunnel_url && !opened) {
  737. // Clear polling
  738. clearInterval(pollInterval)
  739. tunnelLoading.value[loadingKey] = false
  740. opened = true
  741. // Open tunnel URL in new tab
  742. window.open(status.tunnel_url, '_blank')
  743. } else if (status.status === 'failed') {
  744. clearInterval(pollInterval)
  745. tunnelLoading.value[loadingKey] = false
  746. alert('Failed to establish tunnel')
  747. } else if (attempts >= maxAttempts) {
  748. clearInterval(pollInterval)
  749. tunnelLoading.value[loadingKey] = false
  750. alert('Tunnel connection timeout')
  751. }
  752. } catch (err) {
  753. clearInterval(pollInterval)
  754. tunnelLoading.value[loadingKey] = false
  755. console.error('Failed to poll tunnel status:', err)
  756. alert('Failed to check tunnel status')
  757. }
  758. }, 1000) // Poll every 1 second
  759. } catch (err) {
  760. tunnelLoading.value[loadingKey] = false
  761. console.error('Failed to enable tunnel:', err)
  762. alert(err.response?.data?.detail || 'Failed to enable tunnel')
  763. }
  764. }
  765. function openSSH(device) {
  766. openTunnel(device, 'ssh')
  767. }
  768. function openDashboard(device) {
  769. openTunnel(device, 'dashboard')
  770. }
  771. async function toggleBLE(device, event) {
  772. event.preventDefault()
  773. const newState = !(device.config?.ble?.enabled ?? false)
  774. const action = newState ? 'enable' : 'disable'
  775. if (!confirm(`Are you sure you want to ${action} BLE scanner for device #${device.simple_id}?`)) {
  776. return
  777. }
  778. try {
  779. const updatedConfig = {
  780. ...device.config,
  781. ble: {
  782. ...(device.config?.ble || {}),
  783. enabled: newState
  784. }
  785. }
  786. await devicesApi.updateSuperadmin(device.id, { config: updatedConfig })
  787. await loadDevices()
  788. } catch (err) {
  789. alert(err.response?.data?.detail || 'Failed to update BLE scanner')
  790. }
  791. }
  792. async function toggleWiFi(device, event) {
  793. event.preventDefault()
  794. const newState = !(device.config?.wifi?.monitor_enabled ?? false)
  795. const action = newState ? 'enable' : 'disable'
  796. if (!confirm(`Are you sure you want to ${action} WiFi scanner for device #${device.simple_id}?`)) {
  797. return
  798. }
  799. try {
  800. const updatedConfig = {
  801. ...device.config,
  802. wifi: {
  803. ...(device.config?.wifi || {}),
  804. monitor_enabled: newState
  805. }
  806. }
  807. await devicesApi.updateSuperadmin(device.id, { config: updatedConfig })
  808. await loadDevices()
  809. } catch (err) {
  810. alert(err.response?.data?.detail || 'Failed to update WiFi scanner')
  811. }
  812. }
  813. async function showDefaultConfigModal() {
  814. try {
  815. const configData = await devicesApi.getDefaultConfig()
  816. // Load into interactive form
  817. defaultConfig.value = {
  818. force_cloud: configData.force_cloud ?? false,
  819. cfg_polling_timeout: configData.cfg_polling_timeout ?? 30,
  820. ble: {
  821. enabled: configData.ble?.enabled ?? true,
  822. batch_interval_ms: configData.ble?.batch_interval_ms ?? 2500,
  823. uuid_filter_hex: configData.ble?.uuid_filter_hex ?? '',
  824. upload_endpoint: configData.ble?.upload_endpoint ?? ''
  825. },
  826. wifi: {
  827. client_enabled: configData.wifi?.client_enabled ?? false,
  828. ssid: configData.wifi?.ssid ?? '',
  829. psk: configData.wifi?.psk ?? '',
  830. monitor_enabled: configData.wifi?.monitor_enabled ?? true,
  831. batch_interval_ms: configData.wifi?.batch_interval_ms ?? 10000,
  832. upload_endpoint: configData.wifi?.upload_endpoint ?? ''
  833. },
  834. ssh_tunnel: configData.ssh_tunnel || {
  835. enabled: false,
  836. server: '192.168.5.4',
  837. port: 22,
  838. user: 'tunnel',
  839. remote_port: 0,
  840. keepalive_interval: 30
  841. },
  842. dashboard_tunnel: configData.dashboard_tunnel || {
  843. enabled: false,
  844. server: '192.168.5.4',
  845. port: 22,
  846. user: 'tunnel',
  847. remote_port: 0,
  848. keepalive_interval: 30
  849. },
  850. dashboard: {
  851. enabled: configData.dashboard?.enabled ?? true
  852. },
  853. net: {
  854. ntp: {
  855. servers: configData.net?.ntp?.servers ?? ['pool.ntp.org', 'time.google.com']
  856. }
  857. },
  858. debug: configData.debug ?? false
  859. }
  860. // Convert NTP servers to text
  861. defaultNtpServersText.value = defaultConfig.value.net.ntp.servers.join(', ')
  862. // Also load into JSON
  863. defaultConfigJson.value = JSON.stringify(configData, null, 2)
  864. jsonError.value = null
  865. defaultConfigTab.value = 'interactive'
  866. defaultConfigModalVisible.value = true
  867. } catch (err) {
  868. alert(err.response?.data?.detail || 'Failed to load default config')
  869. }
  870. }
  871. function closeDefaultConfigModal() {
  872. defaultConfigModalVisible.value = false
  873. defaultConfigTab.value = 'interactive'
  874. defaultConfigJson.value = ''
  875. jsonError.value = null
  876. }
  877. function onDefaultWifiClientChange() {
  878. if (defaultConfig.value.wifi.client_enabled) {
  879. defaultConfig.value.wifi.monitor_enabled = false
  880. }
  881. }
  882. function onDefaultWifiMonitorChange() {
  883. if (defaultConfig.value.wifi.monitor_enabled) {
  884. defaultConfig.value.wifi.client_enabled = false
  885. }
  886. }
  887. function switchToJsonTab() {
  888. // Convert interactive form to JSON before switching
  889. defaultConfig.value.net.ntp.servers = defaultNtpServersText.value
  890. .split(',')
  891. .map(s => s.trim())
  892. .filter(s => s.length > 0)
  893. defaultConfigJson.value = JSON.stringify(defaultConfig.value, null, 2)
  894. defaultConfigTab.value = 'json'
  895. }
  896. function validateJson() {
  897. try {
  898. JSON.parse(defaultConfigJson.value)
  899. jsonError.value = null
  900. } catch (e) {
  901. jsonError.value = `Invalid JSON: ${e.message}`
  902. }
  903. }
  904. async function saveDefaultConfig() {
  905. try {
  906. let configToSave
  907. if (defaultConfigTab.value === 'interactive') {
  908. // Parse NTP servers from text
  909. defaultConfig.value.net.ntp.servers = defaultNtpServersText.value
  910. .split(',')
  911. .map(s => s.trim())
  912. .filter(s => s.length > 0)
  913. configToSave = defaultConfig.value
  914. } else {
  915. // Validate and parse JSON
  916. configToSave = JSON.parse(defaultConfigJson.value)
  917. }
  918. savingDefaultConfig.value = true
  919. await devicesApi.updateDefaultConfig(configToSave)
  920. alert('Default configuration saved successfully!')
  921. closeDefaultConfigModal()
  922. } catch (err) {
  923. if (err instanceof SyntaxError) {
  924. jsonError.value = `Invalid JSON: ${err.message}`
  925. } else {
  926. alert(err.response?.data?.detail || 'Failed to save default config')
  927. }
  928. } finally {
  929. savingDefaultConfig.value = false
  930. }
  931. }
  932. // Auto-registration functions
  933. async function loadAutoRegistrationStatus() {
  934. try {
  935. const status = await settingsApi.getAutoRegistrationStatus()
  936. autoRegistrationEnabled.value = status.enabled
  937. registrationTimeLeft.value = status.time_left || 0
  938. } catch (err) {
  939. console.error('Failed to load registration status:', err)
  940. }
  941. }
  942. async function toggleAutoRegistration() {
  943. togglingRegistration.value = true
  944. try {
  945. const newState = !autoRegistrationEnabled.value
  946. await settingsApi.toggleAutoRegistration(newState)
  947. autoRegistrationEnabled.value = newState
  948. if (newState) {
  949. startRegistrationTimer()
  950. } else {
  951. stopRegistrationTimer()
  952. }
  953. } catch (err) {
  954. console.error('Failed to toggle registration:', err)
  955. // Reload status to sync
  956. await loadAutoRegistrationStatus()
  957. } finally {
  958. togglingRegistration.value = false
  959. }
  960. }
  961. function startRegistrationTimer() {
  962. stopRegistrationTimer()
  963. registrationTimer = setInterval(async () => {
  964. await loadAutoRegistrationStatus()
  965. if (!autoRegistrationEnabled.value) {
  966. stopRegistrationTimer()
  967. }
  968. }, 10000) // Update every 10 seconds
  969. }
  970. function stopRegistrationTimer() {
  971. if (registrationTimer) {
  972. clearInterval(registrationTimer)
  973. registrationTimer = null
  974. }
  975. }
  976. function formatTimeLeft(seconds) {
  977. if (seconds < 60) return `${seconds}s`
  978. if (seconds < 3600) return `${Math.floor(seconds / 60)}m ${seconds % 60}s`
  979. return `${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m`
  980. }
  981. onMounted(() => {
  982. loadDevices()
  983. loadOrganizations()
  984. loadAutoRegistrationStatus()
  985. startRegistrationTimer()
  986. // Real-time polling every 10 seconds (silent to avoid table flickering)
  987. pollingInterval = setInterval(() => {
  988. if (!modalVisible.value) {
  989. loadDevices(true)
  990. }
  991. }, 10000)
  992. })
  993. onBeforeUnmount(() => {
  994. if (pollingInterval) {
  995. clearInterval(pollingInterval)
  996. }
  997. if (searchDebounceTimer) {
  998. clearTimeout(searchDebounceTimer)
  999. }
  1000. stopRegistrationTimer()
  1001. })
  1002. </script>
  1003. <style scoped>
  1004. .page { padding: 32px; }
  1005. .page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 32px; }
  1006. .page-header h1 { font-size: 32px; font-weight: 700; color: #1a202c; margin-bottom: 8px; }
  1007. .page-header p { color: #718096; font-size: 16px; }
  1008. /* Registration Banner */
  1009. .registration-banner {
  1010. background: #fff5f5;
  1011. border: 2px solid #fc8181;
  1012. border-radius: 12px;
  1013. padding: 20px 24px;
  1014. margin-bottom: 24px;
  1015. transition: all 0.3s;
  1016. }
  1017. .registration-banner.enabled {
  1018. background: #f0fff4;
  1019. border-color: #68d391;
  1020. }
  1021. .registration-content {
  1022. display: flex;
  1023. justify-content: space-between;
  1024. align-items: center;
  1025. gap: 24px;
  1026. }
  1027. .registration-info h2 {
  1028. font-size: 20px;
  1029. font-weight: 700;
  1030. margin-bottom: 8px;
  1031. color: #1a202c;
  1032. }
  1033. .registration-info p {
  1034. font-size: 14px;
  1035. color: #718096;
  1036. margin: 0;
  1037. }
  1038. .registration-info .warning {
  1039. color: #c53030;
  1040. font-weight: 500;
  1041. }
  1042. .registration-banner.enabled .warning {
  1043. color: #276749;
  1044. }
  1045. /* Large Toggle Switch (for registration banner) */
  1046. .toggle-switch-large {
  1047. position: relative;
  1048. display: inline-block;
  1049. width: 72px;
  1050. height: 40px;
  1051. flex-shrink: 0;
  1052. }
  1053. .toggle-switch-large input {
  1054. opacity: 0;
  1055. width: 0;
  1056. height: 0;
  1057. position: absolute;
  1058. }
  1059. .toggle-switch-large .toggle-slider {
  1060. position: absolute;
  1061. cursor: pointer;
  1062. top: 0;
  1063. left: 0;
  1064. right: 0;
  1065. bottom: 0;
  1066. background-color: #cbd5e0;
  1067. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  1068. border-radius: 40px;
  1069. box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
  1070. }
  1071. .toggle-switch-large .toggle-slider:before {
  1072. position: absolute;
  1073. content: '';
  1074. height: 32px;
  1075. width: 32px;
  1076. left: 4px;
  1077. top: 4px;
  1078. background-color: white;
  1079. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  1080. border-radius: 50%;
  1081. box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  1082. }
  1083. .toggle-switch-large input:checked + .toggle-slider {
  1084. background-color: #48bb78;
  1085. }
  1086. .toggle-switch-large input:checked + .toggle-slider:before {
  1087. transform: translateX(32px);
  1088. }
  1089. .toggle-switch-large input:focus + .toggle-slider {
  1090. box-shadow: inset 0 2px 4px rgba(0,0,0,0.1), 0 0 0 3px rgba(72, 187, 120, 0.3);
  1091. }
  1092. .toggle-switch-large input:disabled + .toggle-slider {
  1093. opacity: 0.5;
  1094. cursor: not-allowed;
  1095. }
  1096. .toggle-switch-large .spinner {
  1097. position: absolute;
  1098. left: 50%;
  1099. top: 50%;
  1100. transform: translate(-50%, -50%);
  1101. font-size: 18px;
  1102. animation: spin 1s linear infinite;
  1103. z-index: 10;
  1104. }
  1105. .content { background: white; border-radius: 12px; padding: 24px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
  1106. /* Filters Row */
  1107. .filters-row { display: flex; gap: 16px; align-items: center; margin-bottom: 20px; }
  1108. .btn-edit-default { margin-left: auto; }
  1109. .search-box { position: relative; flex: 1; max-width: 400px; }
  1110. .search-input { width: 100%; padding: 10px 40px 10px 14px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 14px; transition: border-color 0.2s; }
  1111. .search-input:focus { outline: none; border-color: #667eea; }
  1112. .search-input::placeholder { color: #a0aec0; }
  1113. .search-clear { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 24px; color: #a0aec0; cursor: pointer; line-height: 1; padding: 0 4px; }
  1114. .search-clear:hover { color: #718096; }
  1115. .filter-checkbox { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; white-space: nowrap; }
  1116. .filter-checkbox input[type="checkbox"] { cursor: pointer; width: 16px; height: 16px; }
  1117. .filter-checkbox span { color: #4a5568; font-size: 14px; }
  1118. .loading, .error, .empty { text-align: center; padding: 40px; color: #718096; }
  1119. .error { color: #e53e3e; }
  1120. .data-table { width: 100%; border-collapse: collapse; }
  1121. .data-table th { text-align: left; padding: 8px 12px; border-bottom: 2px solid #e2e8f0; font-weight: 600; color: #4a5568; font-size: 13px; cursor: pointer; user-select: none; }
  1122. .data-table th:hover { background: #f7fafc; }
  1123. .data-table td { padding: 6px 12px; border-bottom: 1px solid #e2e8f0; color: #1a202c; font-size: 14px; }
  1124. .data-table tbody tr:hover { background: #f7fafc; }
  1125. code { background: #f7fafc; padding: 4px 8px; border-radius: 4px; font-family: monospace; font-size: 13px; }
  1126. .badge { display: inline-block; padding: 4px 12px; border-radius: 12px; font-size: 12px; font-weight: 600; background: #e2e8f0; color: #718096; }
  1127. .badge.status-online { background: #c6f6d5; color: #22543d; }
  1128. .badge.status-offline { background: #e2e8f0; color: #718096; }
  1129. .badge.status-error { background: #fed7d7; color: #742a2a; }
  1130. .btn-icon { padding: 6px 10px; background: none; border: none; cursor: pointer; font-size: 16px; opacity: 0.7; transition: opacity 0.2s; }
  1131. .btn-icon:hover { opacity: 1; background: #f7fafc; border-radius: 4px; }
  1132. .btn-icon:disabled { opacity: 0.5; cursor: not-allowed; }
  1133. .btn-icon:disabled:hover { background: none; }
  1134. .btn-icon.loading .spinner { display: inline-block; animation: spin 1s linear infinite; }
  1135. @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
  1136. .btn-primary { padding: 12px 24px; background: #667eea; color: white; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
  1137. .btn-primary:hover { background: #5568d3; }
  1138. .btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
  1139. .btn-secondary { padding: 12px 24px; background: #e2e8f0; color: #4a5568; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
  1140. .btn-secondary:hover { background: #cbd5e0; }
  1141. .btn-danger { padding: 12px 24px; background: #f56565; color: white; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
  1142. .btn-danger:hover { background: #e53e3e; }
  1143. .modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
  1144. .modal { background: white; border-radius: 12px; width: 90%; max-width: 600px; max-height: 90vh; overflow-y: auto; }
  1145. .modal-sm { max-width: 400px; }
  1146. .modal-wide { max-width: 800px; }
  1147. .modal-header { display: flex; justify-content: space-between; align-items: center; padding: 24px; border-bottom: 1px solid #e2e8f0; }
  1148. .modal-header h2 { font-size: 24px; font-weight: 700; color: #1a202c; }
  1149. .btn-close { width: 32px; height: 32px; border: none; background: none; font-size: 32px; color: #718096; cursor: pointer; line-height: 1; }
  1150. .btn-close:hover { color: #1a202c; }
  1151. .modal-tabs { display: flex; border-bottom: 2px solid #e2e8f0; padding: 0 24px; }
  1152. .tab-button { padding: 12px 24px; background: none; border: none; border-bottom: 3px solid transparent; color: #718096; font-weight: 500; font-size: 14px; cursor: pointer; transition: all 0.2s; margin-bottom: -2px; }
  1153. .tab-button:hover { color: #4a5568; background: #f7fafc; }
  1154. .tab-button.active { color: #667eea; border-bottom-color: #667eea; }
  1155. .modal-body { padding: 16px; }
  1156. .modal-footer { display: flex; justify-content: flex-end; gap: 12px; padding: 16px; border-top: 1px solid #e2e8f0; }
  1157. .btn-delete { margin-right: auto; }
  1158. .form-group { margin-bottom: 12px; }
  1159. .form-group label { display: block; margin-bottom: 4px; font-weight: 500; color: #4a5568; font-size: 13px; }
  1160. .form-group input, .form-group select { width: 100%; padding: 8px 10px; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 13px; transition: border-color 0.2s; }
  1161. .form-group input:focus, .form-group select:focus { outline: none; border-color: #667eea; }
  1162. .form-group input:disabled { background: #f7fafc; color: #718096; }
  1163. .form-hint { margin-top: 4px; font-size: 11px; color: #718096; }
  1164. .config-editor { width: 100%; padding: 12px; border: 1px solid #e2e8f0; border-radius: 6px; font-family: 'Courier New', monospace; font-size: 13px; line-height: 1.5; resize: vertical; transition: border-color 0.2s; }
  1165. .config-editor:focus { outline: none; border-color: #667eea; }
  1166. .form-error { margin-top: 8px; padding: 8px 12px; background: #fed7d7; color: #742a2a; border-radius: 6px; font-size: 13px; }
  1167. /* Config sections */
  1168. .config-section { border: 1px solid #e2e8f0; border-radius: 6px; padding: 12px; margin-bottom: 12px; background: #fafafa; }
  1169. .config-section h3 { margin: 0 0 12px 0; font-size: 14px; font-weight: 600; color: #2d3748; border-bottom: 1px solid #e2e8f0; padding-bottom: 6px; }
  1170. .form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
  1171. /* Toggle row */
  1172. .toggle-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; padding: 8px 0; }
  1173. .toggle-row:last-child { margin-bottom: 0; }
  1174. .toggle-row span { font-size: 13px; font-weight: 500; color: #4a5568; }
  1175. /* Toggle switch */
  1176. .toggle-switch { position: relative; display: inline-block; width: 48px; height: 26px; }
  1177. .toggle-switch input { opacity: 0; width: 0; height: 0; }
  1178. .toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e0; border-radius: 26px; transition: 0.3s; }
  1179. .toggle-slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: 0.3s; }
  1180. .toggle-switch input:checked + .toggle-slider { background-color: #667eea; }
  1181. .toggle-switch input:checked + .toggle-slider:before { transform: translateX(22px); }
  1182. .toggle-switch input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }
  1183. /* Toggle switch inline (for table cells) */
  1184. .toggle-switch-inline { position: relative; display: inline-block; width: 38px; height: 20px; }
  1185. .toggle-switch-inline input { opacity: 0; width: 0; height: 0; }
  1186. .toggle-switch-inline .toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e0; border-radius: 20px; transition: 0.3s; }
  1187. .toggle-switch-inline .toggle-slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: 0.3s; }
  1188. .toggle-switch-inline input:checked + .toggle-slider { background-color: #667eea; }
  1189. .toggle-switch-inline input:checked + .toggle-slider:before { transform: translateX(18px); }
  1190. .toggle-switch-inline input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }
  1191. .text-center { text-align: center; }
  1192. /* Toggle content (expanded section) */
  1193. .toggle-content { padding-left: 0; margin-top: 8px; border-top: 1px solid #e2e8f0; padding-top: 12px; }
  1194. .toggle-content .form-group:last-child { margin-bottom: 0; }
  1195. </style>