rikkix / v2gen

A powerful cross-platform CLI client for V2Ray subscription. 跨平台V2Ray命令行订阅管理客户端
MIT License
143 stars 29 forks source link

Some further requirments. #4

Closed hongyi-zhao closed 5 years ago

hongyi-zhao commented 5 years ago

Hi,

Thanks a lot for your reply. Now I want to have following feather with v2gen:

1- Setting the inbounds ports for specific protocols using as argument of v2gen. So that it can be used in for-loop for setting multiple config files.

2- Only generate the inbounds and outbound parts of the config.

Could you please add these functions into v2gen?

rikkix commented 5 years ago

If just use v2gen.ini, the v2gen config will be hard to edit. It will be sovled in next version, by allowing user to use their own v2ray config template.

rikkix commented 5 years ago

If just use v2gen.ini, the v2gen config will be hard to edit. It will be sovled in next version, by allowing user to use their own v2ray config template.

In the latest version, use --tpl v2rayconfig.tpl to do that

hongyi-zhao commented 5 years ago

Failed to test this function, see my following steps:

Firstly, I use the v2rayconfig.tpl which has the following content:

$ cat v2rayconfig.tpl 
{
    "inbounds": [
        {
            "port": 8888,
            "protocol": "socks"
        }
    ],
    "outbound": {
        "protocol": "vmess",
        "settings": {
            "vnext": [
                {
                    "address": "",
                    "port": "",
                    "users": [
                        {
                            "id": "",
                            "alterId": "",
                            "security": "aes-256-gcm"
                        }
                    ]
                }
            ]
        },
        "streamSettings": {
            "network": "",
            "security": "",
            "tlsSettings": null,
            "kcpSettings": null,
            "wsSettings": null,
            "httpSettings": null,
            "quicSettings": null
        }
    }
}

Then I do the test as follows:

$ ./v2gen -tpl ./v2rayconfig.tpl -vmess vmess://eyJhZGQiOiI0NS4zMi44NC4xMzQiLCJhaWQiOiIxIiwiaG9zdCI6IiIsImlkIjoiOTM2NzAxYmUtNmJkNS0yMjc5LWRmZTAtZjBjNTUzMDczNzExIiwibmV0IjoidGNwIiwicGF0aCI6IiIsInBvcnQiOjM5MDAzLCJwcyI6IlNTUlRPT0wuQ09NIiwidGxzIjoiIiwidHlwZSI6Im5vbmUiLCJ2IjoiMiJ9 -p "" -silent
{
    "inbounds": [
        {
            "port": 8888,
            "protocol": "socks"
        }
    ],
    "outbound": {
        "protocol": "vmess",
        "settings": {
            "vnext": [
                {
                    "address": "",
                    "port": "",
                    "users": [
                        {
                            "id": "",
                            "alterId": "",
                            "security": "aes-256-gcm"
                        }
                    ]
                }
            ]
        },
        "streamSettings": {
            "network": "",
            "security": "",
            "tlsSettings": null,
            "kcpSettings": null,
            "wsSettings": null,
            "httpSettings": null,
            "quicSettings": null
        }
    }
}

As you can see, the corresponding field value don't feed the tpl file. Any hints?

rikkix commented 5 years ago

It should be like

{
  "log": {
    "loglevel": "{{loglevel}}"
  },
  "inbounds": [
    {
      "port": {{socksPort}},
      "protocol": "socks",
      "settings": {
        "udp": {{udp}}
      }
    },
    {
      "port": {{httpPort}},
      "protocol": "http",
      "settings": {
        "udp": {{udp}}
      }
    }
  ],
  "outbound": {
    "protocol": "vmess",
    "settings": {
      "vnext": [
        {
          "address": "{{address}}",
          "port": {{serverPort}},
          "users": [
            {
              "id": "{{uuid}}",
              "alterId": {{aid}},
              "security": "{{security}}"
            }
          ]
        }
      ]
    },
    "streamSettings": {
      "network": "{{network}}",
      "security": "{{streamSecurity}}",
      "tlsSettings": {{tls}},
      "kcpSettings": {{kcp}},
      "wsSettings": {{ws}},
      "httpSettings": {{http}},
      "quicSettings": {{quic}}
    },
    "mux": {
      "enabled": {{mux}},
      "concurrency": {{concurrency}}
    }
  },
  "dns": {
    "servers": [
      "{{dns1}}",
      "{{dns2}}",
      "localhost"
    ]
  },
  "outboundDetour": [
    {
      "protocol": "freedom",
      "settings": {},
      "tag": "direct"
    }
  ],
    "routing": {
        "strategy": "rules",
            "settings": {
            "domainStrategy": "IPIfNonMatch",
                "rules": [{{china_sites}}
                    {
                    "type": "field",
                    "outboundTag": "direct",
                    "ip": [{{china_ip}}
                        "geoip:private"
                    ]
                }
            ]
        }
    }
}

It will replace {{foo}} with bar in v2gen config, with the line foo bar in v2gen config.

uuid aid address serverPort depend on the vmess://xxxx uri

hongyi-zhao commented 5 years ago

Are these variables' name are defined by you or from the specification of v2ray?

rikkix commented 5 years ago

Both. You can use your own variable names too.