vmess.jsont 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. {{if assertExists . "root_!kind" | not}} Unknown environment {{end}}
  2. {{ $protocol_name := tryGet . "root_!link_protocol" "root_!json_type_!unquoted"}}
  3. {{if assertValueIsOneOf $protocol_name "vmess" | not}} This template will only handle vmess link {{end}}
  4. {{ $server_address := tryGet . "root_!link_host_!base64_!json_add" "root_!json_server"}}
  5. {{ $server_uuid := tryGet . "root_!link_host_!base64_!json_id" "root_!json_uuid"}}
  6. {{ $server_port := tryGet . "root_!link_host_!base64_!json_port_!unquoted" "root_!link_host_!base64_!json_port" "root_!json_port_!unquoted" "root_!json_port"}}
  7. {{ $transport_type := tryGet . "root_!link_host_!base64_!json_net_!unquoted" "root_!json_network_!unquoted" "<default>"}}
  8. {{ $transport_type = $transport_type | unalias "tcp" ""}}
  9. {{ $name_annotation := tryGet . "root_!link_host_!base64_!json_ps_!unquoted" "root_!json_name_!unquoted" "<default>"}}
  10. {{if assertValueIsOneOf $transport_type "tcp" "kcp" "ws" "h2" "quic" "grpc"| not }}
  11. unknown transport type {{end}}
  12. {{$transport_grpc_service_name := ""}}
  13. {{ if $transport_type | eq "grpc"}}
  14. {{ $transport_grpc_service_name = tryGet . "root_!link_host_!base64_!json_path" "<default>"}}
  15. {{end}}
  16. {{$transport_ws_path := ""}}
  17. {{ if $transport_type | eq "ws"}}
  18. {{ $transport_ws_path = tryGet . "root_!link_host_!base64_!json_path" "root_!json_ws-opts_!json_path" "<default>"}}
  19. {{end}}
  20. {{ $security_type := tryGet . "root_!link_host_!base64_!json_tls_!unquoted" "root_!json_tls" "<default>"}}
  21. {{ $security_type = $security_type | unalias "none" "" "false" "0"}}
  22. {{if assertValueIsOneOf $security_type "tls" "utls" "none"| not }}
  23. unknown security type {{end}}
  24. {{ $security_tlsmmon_sni := tryGet . "root_!link_host_!base64_!json_sni" "<default>"}}
  25. {{ $security_tlsmmon_sni = $security_tlsmmon_sni | unalias $server_address ""}}
  26. {
  27. "protocol": "vmess",
  28. "settings":{
  29. "address":{{$server_address}},
  30. "port":{{$server_port}},
  31. "uuid":{{$server_uuid}}
  32. },
  33. "streamSettings":{
  34. "transport":{{$transport_type|jsonEncode}},
  35. "security":{{$security_type|jsonEncode}},
  36. "transportSettings":{
  37. {{ if $transport_type | eq "grpc"}}
  38. "serviceName":{{$transport_grpc_service_name}}
  39. {{end}}
  40. {{ if $transport_type | eq "ws"}}
  41. "path":{{$transport_ws_path}}
  42. {{end}}
  43. },
  44. "securitySettings":{
  45. {{ if $security_type | eq "tls"}}
  46. "serverName":{{$security_tlsmmon_sni}}
  47. {{end}}
  48. }
  49. },
  50. "metadata":{
  51. "TagName": {{print $name_annotation "_" $server_address | jsonEncode}}
  52. }
  53. }