Skip to content

Commit

Permalink
Generate client configs
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-asriyan committed Dec 25, 2024
1 parent 9eb562e commit d462bb5
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 19 deletions.
14 changes: 1 addition & 13 deletions roles/users-configs/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,9 @@
dest: "{{ users_configs_static_root_local }}/robots.txt"

- name: Render configs
template:
src: config.j2
dest: "{{ users_configs_static_root_local }}/{{ item.key }}"
with_items: "{{ users_configs_users | dict2items }}"
loop_control:
index_var: loop_index
vars:
users_configs_user_uuid: "{{ item.key }}"
users_configs_default_server: "{{ users_configs_servers[users_configs_default_server_uuid] }}"
users_configs_default_server_uuid: "{{ item.value.preferred_server_uuid if 'preferred_server_uuid' in item.value else (users_configs_servers | dict2items)[loop_index % (users_configs_servers | length)].key }}"

- name: Render redirect configs
template:
src: redirect.json.j2
dest: "{{ users_configs_static_root_local }}/{{ item.key }}.json"
with_items: "{{ users_configs_users | dict2items }}"
vars:
users_configs_user_uuid: "{{ item.key }}"
include_tasks: render_users_configs.yml
25 changes: 25 additions & 0 deletions roles/users-configs/tasks/render_users_configs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

- name: Create user's directory
file:
path: "{{ users_configs_static_root_local }}/{{ users_configs_user_uuid }}"
state: directory

- name: Render hiddify config
template:
src: hiddify.j2
dest: "{{ users_configs_static_root_local }}/{{ users_configs_user_uuid }}/{{ user_configs_hiddify_filename }}"

- name: Render hiddify config (index.html for backward compatibility)
template:
src: hiddify.j2
dest: "{{ users_configs_static_root_local }}/{{ users_configs_user_uuid }}/index.html"

- name: Render client configs
template:
src: client-xray-config.json.j2
dest: "{{ users_configs_static_root_local }}/{{ users_configs_user_uuid }}/{{ user_configs_client_xray_config_filename }}"

- name: Render urls map
template:
src: urls-map.json.j2
dest: "{{ users_configs_static_root_local }}/{{ users_configs_user_uuid }}/{{ users_configs_urls_map_filename }}"
120 changes: 120 additions & 0 deletions roles/users-configs/templates/client-xray-config.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"inbounds": [
{
"tag": "inbound",
"listen": "0.0.0.0",
"port": 1080,
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": false
},
"streamSettings": {
"network": "raw",
"security": "none"
}
}
],
"outbounds": [
{% for server_item in users_configs_servers | dict2items %}
{% set users_configs_server_uuid = server_item.key %}
{% set users_configs_server = server_item.value %}
{% set server_index = loop.index %}

{% for sni, fingerprint in users_configs_server.supported_snis | product(users_configs_server.fingerprints) %}
{
"protocol": "vless",
"sendThrough": "0.0.0.0",
"settings": {
"vnext": [
{
"address": "{{ users_configs_server.host }}",
"port": {{ users_configs_server.port }},
"users": [
{
"id": "{{ users_configs_user_uuid }}",
"encryption": "none",
"flow": "{{ users_configs_server.flow }}",
"level": 0
}
]
}
]
},
"tag": "outbound-vless-{{ server_index }}-{{ loop.index }}-{{ users_configs_server.name | urlencode }}",
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"fingerprint": "{{ fingerprint }}",
"serverName": "{{ sni }}",
"publicKey": "{{ users_configs_server.public_key }}",
"spiderX": "/&",
"shortId": ""
}
}
},
{% endfor %}
{% endfor %}
{
"tag": "outbound-freedom",
"protocol": "freedom"
}
],
"routing": {
"domainStrategy": "AsIs",
"domainMatcher": "hybrid",
"rules": [
{
"inboundTag": [
"inbound"
],
"outboundTag": "outbound-freedom",
"domain": [
"geosite:category-ru",
"geosite:microsoft"
]
},
{
"inboundTag": [
"inbound"
],
"outboundTag": "outbound-freedom",
"ip": [
"geoip:private",
"geoip:ru"
]
},
{
"inboundTag": [
"inbound"
],
"balancerTag": "balancer"
}
],
"balancers": [
{
"tag": "balancer",
"selector": [
"outbound-vless"
],
"strategy": {
"type": "leastLoad",
"settings": {}
}
}
]
},
"burstObservatory": {
"subjectSelector":[
"outbound"
],
"pingConfig": {
"destination": "https://connectivitycheck.gstatic.com/generate_204",
"connectivity": "",
"interval": "1h",
"sampling": 3,
"timeout": "30s"
}
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions roles/users-configs/templates/index.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
const hash = window.location.hash;
if (hash) {
const url= "/" + hash.slice(1) + ".json";
const url= "/" + hash.slice(1) + "/{{ users_configs_urls_map_filename }}";
fetch(url)
.then(response => response.json())
.then(data => {
const redirectUrl = data["{{ instruction_url_field_name }}"];
const redirectUrl = data["{{ user_configs_instruction_url_field_name }}"];
if (redirectUrl) {
redirect(redirectUrl);
} else {
Expand Down
3 changes: 0 additions & 3 deletions roles/users-configs/templates/redirect.json.j2

This file was deleted.

7 changes: 7 additions & 0 deletions roles/users-configs/templates/urls-map.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
{% set instruction_url = '/' + users_configs_instruction_filename + '#' + users_configs_user_uuid %}
"{{ user_configs_instruction_url_field_name }}": "{{ instruction_url }}",
"instruction_url": "{{ instruction_url }}",
"xray_client_config_url": "/{{ users_configs_user_uuid }}/{{ user_configs_client_xray_config_filename }}",
"hiddify_url": "/{{ users_configs_user_uuid }}/{{ user_configs_hiddify_filename }}"
}
6 changes: 5 additions & 1 deletion roles/users-configs/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
instruction_url_field_name: admin_login_url
user_configs_instruction_url_field_name: admin_login_url

user_configs_frontend_html_url: https://github.com/ed-asriyan/xray-server-frontend/releases/latest/download/index.html

users_configs_urls_map_filename: urls-map.json
user_configs_hiddify_filename: hiddify
user_configs_client_xray_config_filename: client-xray-config.json

0 comments on commit d462bb5

Please sign in to comment.