summaryrefslogtreecommitdiff
path: root/vless2json.sh
blob: 88f85a1f4a53063fa26f8ffe7cc588e2dae59a20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env dash
# vless to v2ray config converter
# author: touka@nopwd.lol
# version: 0.2

# ============================
# FIRST READ THE SCRIPT!!
echo "FIRST READ THE SCRIPT!!"
exit
# ============================

# -- change it to your needs --

port=2081
protocol='http'

# -----------------------------

set -e

if [ "$#" -ne 1 ]; then
	echo "Usage:
  dash $0 vless.txt > config.json
"
	exit
fi

user=$(trurl -g '{user}' -f $1 )
address=$(trurl -g '{host}' -f $1)
out_port=$(trurl -g '{port}' -f $1)
path=$(trurl -g '{query:path}' -f $1)
security=$(trurl -g '{query:security}' -f $1)
encryption=$(trurl -g '{query:encryption}' -f $1)
host=$(trurl -g '{query:host}' -f $1)
fp=$(trurl -g '{query:fp}' -f $1)
type=$(trurl -g '{query:type}' -f $1)
name=$(trurl -g '{fragment}' -f $1)

if [ -z "$encryption" ]; then
	encryption="none"
fi

echo "
{
  \"log\": {
	\"loglevel\": \"warning\"
  },
  \"inbounds\" : [
    {
      \"listen\" : \"127.0.0.1\",
      \"port\" : $port,
      \"protocol\" : \"$protocol\",
      \"settings\" : {
        \"auth\" : \"noauth\",
        \"udp\" : true
      },
      \"sniffing\" : {
        \"destOverride\" : [
          \"http\",
          \"tls\",
          \"quic\",
          \"fakedns\"
        ],
        \"enabled\" : false,
        \"routeOnly\" : true
      },
      \"tag\" : \"http\"
    }
  ],
  \"outbounds\" : [
    {
      \"protocol\" : \"vless\",
      \"settings\" : {
        \"vnext\" : [
          {
            \"address\" : \"$address\",
            \"port\" : $out_port,
            \"users\" : [
              {
                \"encryption\" : \"$encryption\",
                \"id\" : \"$user\"
              }
            ]
          }
        ]
      },
      \"streamSettings\" : {
        \"network\" : \"$type\",
        \"security\" : \"$security\",
		\"tlsSettings\": {
			\"fingerprint\": \"$fp\",
			\"servername\": \"$host\"
		},
        \"wsSettings\" : {
          \"headers\" : {
            \"Host\" : \"$host\"
          },
          \"path\" : \"$path\"
        }
      },
      \"tag\" : \"proxy\"
    },
    {
      \"protocol\" : \"freedom\",
      \"tag\" : \"direct\"
    },
    {
      \"protocol\" : \"blackhole\",
      \"tag\" : \"block\"
    }
  ]
}
"