auth.blade.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. @extends('admin.table_layouts')
  2. @section('content')
  3. <div class="page-content container-fluid">
  4. <x-admin.table-panel :title="trans('admin.menu.node.auth')" :theads="[
  5. trans('model.node.id'),
  6. trans('model.common.type'),
  7. trans('model.node.name'),
  8. trans('model.node.domain'),
  9. trans('model.node_auth.key'),
  10. trans('model.node_auth.secret'),
  11. trans('common.action'),
  12. ]" :count="trans('admin.node.auth.counts', ['num' => $authorizations->total()])" :pagination="$authorizations->links()" :delete-config="['url' => route('admin.node.auth.destroy', 'PLACEHOLDER'), 'attribute' => trans('model.node_auth.attribute'), 'nameColumn' => 2]">
  13. @can('admin.node.auth.store')
  14. <x-slot:actions>
  15. <button class="btn btn-primary" onclick="addAuth()">
  16. <i class="icon wb-plus" aria-hidden="true"></i> {{ trans('common.add') }}
  17. </button>
  18. </x-slot:actions>
  19. @endcan
  20. <x-slot:tbody>
  21. @foreach ($authorizations as $auth)
  22. <tr>
  23. <td> {{ $auth->node_id }} </td>
  24. <td> {{ $auth->node->type_label }} </td>
  25. <td> {{ Str::limit($auth->node->name, 20) }} </td>
  26. <td> {{ $auth->node->host }} </td>
  27. <td><span class="badge badge-lg badge-info"> {{ $auth->key }} </span></td>
  28. <td><span class="badge badge-lg badge-info"> {{ $auth->secret }} </span></td>
  29. <td>
  30. <div class="btn-group">
  31. <button class="btn btn-primary" onclick="showDeployModal({{ $auth->node->id }}, '{{ $auth->node->type_label }}')">
  32. <i class="icon wb-code" aria-hidden="true"></i> {{ trans('admin.node.auth.deploy.attribute') }}
  33. </button>
  34. @can('admin.node.auth.update')
  35. <button class="btn btn-danger" onclick="refreshAuth('{{ $auth->id }}')">
  36. <i class="icon wb-reload" aria-hidden="true"></i> {{ trans('admin.node.auth.reset_auth') }}
  37. </button>
  38. @endcan
  39. @can('admin.node.auth.destroy')
  40. <button class="btn btn-primary" data-action="delete">
  41. <i class="icon wb-trash" aria-hidden="true"></i> {{ trans('common.delete') }}
  42. </button>
  43. @endcan
  44. </div>
  45. </td>
  46. </tr>
  47. @endforeach
  48. </x-slot:tbody>
  49. </x-admin.table-panel>
  50. </div>
  51. <!-- 部署教程模态框模板 -->
  52. <x-ui.modal id="deployModal" tabindex="-1" size="simple" position="center" :keyboard="false" focus="input:first">
  53. <x-slot:title>
  54. <span id="deployModalTitle"></span>
  55. </x-slot:title>
  56. <div id="deployModalBody">
  57. <div class="text-center" id="loadingSpinner" style="display: none;">
  58. <i class="icon wb-loop icon-spin"></i> {{ trans('common.loading') }}
  59. </div>
  60. <div id="deployContent"></div>
  61. </div>
  62. </x-ui.modal>
  63. @endsection
  64. @push('javascript')
  65. <script>
  66. // 生成授权KEY
  67. @can('admin.node.auth.store')
  68. function addAuth() {
  69. showConfirm({
  70. title: '{{ trans('admin.hint') }}',
  71. text: '{{ trans('admin.node.auth.generating_all') }}',
  72. icon: 'info',
  73. onConfirm: function() {
  74. ajaxPost('{{ route('admin.node.auth.store') }}');
  75. }
  76. });
  77. }
  78. @endcan
  79. @can('admin.node.auth.update')
  80. // 重置授权认证KEY
  81. function refreshAuth(id) {
  82. showConfirm({
  83. title: '{{ trans('admin.hint') }}',
  84. text: '{{ trans('admin.confirm.continues') }}',
  85. icon: 'info',
  86. onConfirm: function() {
  87. ajaxPut(jsRoute('{{ route('admin.node.auth.update', 'PLACEHOLDER') }}', id));
  88. }
  89. });
  90. }
  91. @endcan
  92. // 显示部署教程模态框
  93. function showDeployModal(nodeId, typeLabel) {
  94. // 设置模态框标题
  95. $('#deployModalTitle').text(jsRoute('{{ trans('admin.node.auth.deploy.title', ['type_label' => 'PLACEHOLDER']) }}', typeLabel));
  96. // 显示加载动画
  97. $('#loadingSpinner').show();
  98. $('#deployContent').html('');
  99. // 从后端获取部署配置
  100. $.ajax({
  101. url: jsRoute('{{ route('admin.node.deployment', 'PLACEHOLDER') }}', nodeId),
  102. type: 'GET',
  103. success: function(response) {
  104. if (response.status) {
  105. renderDeploymentConfig(response.data);
  106. } else {
  107. $('#deployContent').html('<div class="alert alert-danger">{{ trans('common.error') }}</div>');
  108. }
  109. },
  110. error: function() {
  111. $('#deployContent').html('<div class="alert alert-danger">{{ trans('common.error') }}</div>');
  112. },
  113. complete: function() {
  114. $('#loadingSpinner').hide();
  115. }
  116. });
  117. $('#deployModal').modal('show');
  118. }
  119. // 渲染部署配置
  120. function renderDeploymentConfig(config) {
  121. let content = '';
  122. if (config.requires_host) {
  123. content = `<h3>{!! trans('admin.node.auth.deploy.trojan_hint', ['url' => '${config.edit_url}']) !!}</h3>`;
  124. } else {
  125. config.forEach(script => {
  126. content += `
  127. <div class="alert alert-info text-break">
  128. <div class="text-center red-700 mb-5">${script.name}</div>
  129. ${formatCommand(script?.commands?.install)}
  130. ${script.commands ? `<div class="text-center red-700 mb-5">{{ trans('admin.node.auth.deploy.command') }}</div>${renderCommands(script.commands)}`: ''}
  131. </div>
  132. `;
  133. });
  134. }
  135. $('#deployContent').html(content);
  136. }
  137. // 动态渲染命令列表
  138. function renderCommands(commands) {
  139. let commandsHtml = '';
  140. const commandLabels = {
  141. update: '{{ trans('admin.node.auth.deploy.update') }}',
  142. uninstall: '{{ trans('admin.node.auth.deploy.uninstall') }}',
  143. start: '{{ trans('admin.node.auth.deploy.start') }}',
  144. stop: '{{ trans('admin.node.auth.deploy.stop') }}',
  145. restart: '{{ trans('admin.node.auth.deploy.restart') }}',
  146. status: '{{ trans('admin.node.auth.deploy.status') }}',
  147. recent_logs: '{{ trans('admin.node.auth.deploy.recent_logs') }}',
  148. real_time_logs: '{{ trans('admin.node.auth.deploy.real_time_logs') }}'
  149. };
  150. for (const [command, value] of Object.entries(commands)) {
  151. if (commandLabels[command] && value) {
  152. commandsHtml += `${commandLabels[command]}: ${value}<br>`;
  153. }
  154. }
  155. return commandsHtml;
  156. }
  157. // 格式化命令显示
  158. function formatCommand(command) {
  159. if (!command) {
  160. return ''
  161. }
  162. // 使用 <pre> 标签保持原始格式
  163. return `<pre class="p-0 border-0">${command}</pre>`;
  164. }
  165. </script>
  166. @endpush