diff --git a/Makefile b/Makefile index 6918796..aec6481 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ update: check ## Обновить бинарник, перекатить кон export: check ## Только перевыпустить URL и QR (без изменений на сервере) $(ANSIBLE) playbook.yml --tags export $(ANSIBLE_OPTS) -index: check ## Пересобрать output/index.html из локальных server-info.yml и открыть в браузере +index: check ## Пересобрать HTML серверов + output/index.html и открыть в браузере $(ANSIBLE) playbook-index.yml $(VAULT_ARGS) \ $(if $(EXTRA_VARS),--extra-vars "$(EXTRA_VARS)",) diff --git a/README.md b/README.md index 70e99cc..205616b 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ make install # → output/index.html откроется в браузере | `make install` | Установка masquerade + экспорт URL/QR/HTML | | `make update` | Обновить бинарник и конфиг; экспорт только для новых/изменённых пользователей | | `make export` | Только экспорт (URL, QR, HTML) без изменений на сервере | -| `make index` | Пересобрать `output/index.html` (вкладки серверов + статистика) и открыть в браузере | +| `make index` | Пересобрать HTML всех серверов + общий `output/index.html` и открыть в браузере | | `make uninstall` | Полное удаление с VPS + `output//` + пересборка `output/index.html` | | `make vault-init` | Создать `.vault_pass`, включить `vault_password_file` в `ansible.cfg` | | `make vault-encrypt` | Зашифровать `vault.yml` | diff --git a/playbook-index.yml b/playbook-index.yml index 351966a..ddd3d19 100644 --- a/playbook-index.yml +++ b/playbook-index.yml @@ -1,11 +1,11 @@ --- -- name: Rebuild global output index from local exports +- name: Rebuild HTML catalogs from local exports hosts: localhost connection: local gather_facts: true become: false tasks: - - name: Generate output/index.html and open in browser + - name: Regenerate server pages and global index.html ansible.builtin.include_role: name: hysteria2 - tasks_from: export_global.yml + tasks_from: export_rebuild_local.yml diff --git a/playbook.yml b/playbook.yml index 890e0f7..a860adc 100644 --- a/playbook.yml +++ b/playbook.yml @@ -5,14 +5,14 @@ roles: - hysteria2 -- name: Build global output index +- name: Build HTML catalogs from local exports hosts: localhost connection: local gather_facts: true become: false tags: [install, update, export] tasks: - - name: Generate global index.html and open in browser + - name: Regenerate server pages and global index.html ansible.builtin.include_role: name: hysteria2 - tasks_from: export_global.yml + tasks_from: export_rebuild_local.yml diff --git a/roles/hysteria2/tasks/export_rebuild_local.yml b/roles/hysteria2/tasks/export_rebuild_local.yml new file mode 100644 index 0000000..634b74c --- /dev/null +++ b/roles/hysteria2/tasks/export_rebuild_local.yml @@ -0,0 +1,41 @@ +--- +# Пересборка HTML-страниц серверов и общего index из локальных server-info.yml (без SSH) +- name: Find server-info.yml in output directories + ansible.builtin.find: + paths: "{{ hysteria2_output_dir }}" + patterns: server-info.yml + recurse: true + register: _hysteria2_local_server_info_files + become: false + +- name: Load local server-info.yml files + ansible.builtin.slurp: + src: "{{ item.path }}" + loop: "{{ _hysteria2_local_server_info_files.files | default([]) }}" + register: _hysteria2_local_server_info_raw + when: _hysteria2_local_server_info_files.matched | default(0) | int > 0 + become: false + +- name: Rebuild per-server index.html from local export data + ansible.builtin.template: + src: export/index.html.j2 + dest: "{{ _server_dir }}/index.html" + mode: "0644" + loop: "{{ _hysteria2_local_server_info_raw.results | default([]) }}" + when: not item.skipped | default(false) + loop_control: + label: "{{ _info.server | default('unknown') }}" + vars: + _info: "{{ item.content | b64decode | from_yaml }}" + _server_dir: "{{ item.item.path | dirname }}" + hysteria2_output_name: "{{ _info.server }}" + hysteria2_domain: "{{ _info.domain }}" + hysteria2_listen_port: "{{ _info.port }}" + hysteria2_export_users: "{{ _info.users }}" + hysteria2_obfs_password: "{{ _info.obfs_password | default('') }}" + hysteria2_mode: "{{ _info.mode | default('') }}" + generated_at: "{{ now(utc=false, fmt='%Y-%m-%d %H:%M:%S') }}" + become: false + +- name: Rebuild global output index + ansible.builtin.import_tasks: export_global.yml diff --git a/roles/hysteria2/templates/export/index.html.j2 b/roles/hysteria2/templates/export/index.html.j2 index ebe81e0..96aa3e9 100644 --- a/roles/hysteria2/templates/export/index.html.j2 +++ b/roles/hysteria2/templates/export/index.html.j2 @@ -7,73 +7,116 @@ -
-
-

Hysteria2

-

- Сервер: {{ hysteria2_output_name }}
- Домен: {{ hysteria2_domain }}:{{ hysteria2_listen_port }} -

+
+

{{ hysteria2_output_name | e }}

+

+ {{ hysteria2_domain | e }}:{{ hysteria2_listen_port }} +

+
{{ hysteria2_export_users | length }} {{ 'пользователь' if hysteria2_export_users | length == 1 else 'пользователей' }} -
+{% if (hysteria2_mode | default('')) == 'salamander' or (hysteria2_obfs_password | default('') | length > 0) %} + Salamander +{% endif %} +
+ + +
+ ← Общий каталог +
+ +
+{% if hysteria2_obfs_password | default('') | length > 0 %} +
+ +
+ + +
+
+{% endif %}
{% for user in hysteria2_export_users %} - {% endfor %}
+
- - - +
Скопировано!