changed v2ray client config generation
This commit is contained in:
parent
6a903792ab
commit
68830021d6
9 changed files with 49 additions and 64 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
|
||||||
#include "core/servercontroller.h"
|
#include "core/servercontroller.h"
|
||||||
|
#include "core/scripts_registry.h"
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
|
|
||||||
V2RayConfigurator::V2RayConfigurator(std::shared_ptr<Settings> settings, std::shared_ptr<ServerController> serverController,
|
V2RayConfigurator::V2RayConfigurator(std::shared_ptr<Settings> settings, std::shared_ptr<ServerController> serverController,
|
||||||
|
|
@ -29,42 +30,13 @@ QString V2RayConfigurator::genV2RayConfig(const ServerCredentials &credentials,
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject config;
|
|
||||||
|
|
||||||
QJsonObject inboundsSocks;
|
QString v2RayClientConfig = m_serverController->replaceVars(amnezia::scriptData(ProtocolScriptType::v2ray_client_template, container),
|
||||||
inboundsSocks.insert("protocol", "socks");
|
m_serverController->genVarsForScript(credentials, container, containerConfig));
|
||||||
inboundsSocks.insert("listen", "127.0.0.1");
|
|
||||||
inboundsSocks.insert("port", 1080); //todo
|
|
||||||
QJsonObject socksSettings;
|
|
||||||
socksSettings.insert("auth", "noauth");
|
|
||||||
socksSettings.insert("udp", true);
|
|
||||||
inboundsSocks.insert("settings", socksSettings);
|
|
||||||
|
|
||||||
QJsonArray inbounds;
|
v2RayClientConfig.replace("$V2RAY_VMESS_CLIENT_UUID", v2rayVmessClientUuid);
|
||||||
inbounds.push_back(inboundsSocks);
|
v2RayClientConfig = m_serverController->replaceVars(v2RayClientConfig,
|
||||||
config.insert("inbounds", inbounds);
|
m_serverController->genVarsForScript(credentials, container, containerConfig));
|
||||||
|
|
||||||
|
return v2RayClientConfig;
|
||||||
QJsonObject outboundsVmess;
|
|
||||||
outboundsVmess.insert("protocol", "vmess");
|
|
||||||
QJsonObject vmessSettings;
|
|
||||||
QJsonObject vnext;
|
|
||||||
vnext.insert("address", credentials.hostName);
|
|
||||||
vnext.insert("port", 10086); //todo
|
|
||||||
QJsonObject users;
|
|
||||||
users.insert("id", v2rayVmessClientUuid);
|
|
||||||
vnext.insert("users", QJsonArray({users}));
|
|
||||||
vmessSettings.insert("vnext", QJsonArray({vnext}));
|
|
||||||
outboundsVmess.insert("settings", vmessSettings);
|
|
||||||
|
|
||||||
QJsonArray outbounds;
|
|
||||||
outbounds.push_back(outboundsVmess);
|
|
||||||
config.insert("outbounds", outbounds);
|
|
||||||
|
|
||||||
|
|
||||||
QString textCfg = m_serverController->replaceVars(QJsonDocument(config).toJson(),
|
|
||||||
m_serverController->genVarsForScript(credentials, container, containerConfig));
|
|
||||||
|
|
||||||
// qDebug().noquote() << textCfg;
|
|
||||||
return textCfg;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ QString amnezia::scriptName(ProtocolScriptType type)
|
||||||
case ProtocolScriptType::container_startup: return QLatin1String("start.sh");
|
case ProtocolScriptType::container_startup: return QLatin1String("start.sh");
|
||||||
case ProtocolScriptType::openvpn_template: return QLatin1String("template.ovpn");
|
case ProtocolScriptType::openvpn_template: return QLatin1String("template.ovpn");
|
||||||
case ProtocolScriptType::wireguard_template: return QLatin1String("template.conf");
|
case ProtocolScriptType::wireguard_template: return QLatin1String("template.conf");
|
||||||
|
case ProtocolScriptType::v2ray_client_template: return QLatin1String("template_v2ray_client.json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ enum ProtocolScriptType {
|
||||||
configure_container,
|
configure_container,
|
||||||
container_startup,
|
container_startup,
|
||||||
openvpn_template,
|
openvpn_template,
|
||||||
wireguard_template
|
wireguard_template,
|
||||||
|
v2ray_client_template
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -720,8 +720,8 @@ ServerController::Vars ServerController::genVarsForScript(const ServerCredential
|
||||||
vars.append({{"$WIREGUARD_SERVER_PORT", wireguarConfig.value(config_key::port).toString(protocols::wireguard::defaultPort) }});
|
vars.append({{"$WIREGUARD_SERVER_PORT", wireguarConfig.value(config_key::port).toString(protocols::wireguard::defaultPort) }});
|
||||||
|
|
||||||
// V2Ray vars
|
// V2Ray vars
|
||||||
vars.append({{"$V2RAY_SERVER_PORT", v2RayConfig.value(config_key::port).toString(protocols::v2ray::defaultLocalPort) }});
|
vars.append({{"$V2RAY_VMESS_PORT", v2RayConfig.value(config_key::port).toString(protocols::v2ray::defaultServerPort) }});
|
||||||
vars.append({{"$V2RAY_LOCAL_PORT", v2RayConfig.value(config_key::local_port).toString(protocols::v2ray::defaultServerPort) }});
|
vars.append({{"$V2RAY_SOCKS_LOCAL_PORT", v2RayConfig.value(config_key::local_port).toString(protocols::v2ray::defaultLocalPort) }});
|
||||||
|
|
||||||
// IPsec vars
|
// IPsec vars
|
||||||
vars.append({{"$IPSEC_VPN_L2TP_NET", "192.168.42.0/24"}});
|
vars.append({{"$IPSEC_VPN_L2TP_NET", "192.168.42.0/24"}});
|
||||||
|
|
|
||||||
|
|
@ -170,5 +170,6 @@
|
||||||
<file>server_scripts/openvpn_v2ray_vmess/run_container.sh</file>
|
<file>server_scripts/openvpn_v2ray_vmess/run_container.sh</file>
|
||||||
<file>server_scripts/openvpn_v2ray_vmess/start.sh</file>
|
<file>server_scripts/openvpn_v2ray_vmess/start.sh</file>
|
||||||
<file>server_scripts/openvpn_v2ray_vmess/template.ovpn</file>
|
<file>server_scripts/openvpn_v2ray_vmess/template.ovpn</file>
|
||||||
|
<file>server_scripts/openvpn_v2ray_vmess/template_v2ray_client.json</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
||||||
|
|
@ -26,23 +26,23 @@ $OPENVPN_TLS_AUTH
|
||||||
$OPENVPN_ADDITIONAL_SERVER_CONFIG
|
$OPENVPN_ADDITIONAL_SERVER_CONFIG
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# V2RAY_SERVER_PORT port for v2ray listening, for example 10086.
|
# V2RAY_VMESS_PORT port for v2ray listening, for example 10086.
|
||||||
# V2RAY_VMESS_CLIENT_UUID client's id and secret as UUID.
|
# V2RAY_VMESS_CLIENT_UUID client's id and secret as UUID.
|
||||||
# UUID is 32 hexadecimal digits /([0-9a-f]-?){32}/ (128 bit value).
|
# UUID is 32 hexadecimal digits /([0-9a-f]-?){32}/ (128 bit value).
|
||||||
|
|
||||||
mkdir -p /opt/amnezia/v2ray
|
mkdir -p /opt/amnezia/v2ray
|
||||||
cd /opt/amnezia/v2ray
|
cd /opt/amnezia/v2ray
|
||||||
V2RAY_VMESS_CLIENT_UUID="b831381d-6324-4d53-ad4f-8cda48b30811" # $(openssl rand -base64 32 | tr "=" "A" | tr "+" "A" | tr "/" "A")
|
V2RAY_VMESS_CLIENT_UUID=$(cat /proc/sys/kernel/random/uuid)
|
||||||
echo $V2RAY_VMESS_CLIENT_UUID > /opt/amnezia/v2ray/v2ray.key
|
echo $V2RAY_VMESS_CLIENT_UUID > /opt/amnezia/v2ray/v2ray.key
|
||||||
|
|
||||||
cat < /opt/amnezia/v2ray/v2ray-server.json <<EOF
|
cat > /opt/amnezia/v2ray/v2ray-server.json <<EOF
|
||||||
{
|
{
|
||||||
"log": {
|
"log": {
|
||||||
"loglevel": "None"
|
"loglevel": "None"
|
||||||
},
|
},
|
||||||
"inbounds": [
|
"inbounds": [
|
||||||
{
|
{
|
||||||
"port": $V2RAY_SERVER_PORT,
|
"port": $V2RAY_VMESS_PORT,
|
||||||
"protocol": "vmess",
|
"protocol": "vmess",
|
||||||
"settings": {
|
"settings": {
|
||||||
"clients": [
|
"clients": [
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ sudo docker run -d \
|
||||||
--log-driver none \
|
--log-driver none \
|
||||||
--restart always \
|
--restart always \
|
||||||
--cap-add=NET_ADMIN \
|
--cap-add=NET_ADMIN \
|
||||||
-p $V2RAY_SERVER_PORT:$V2RAY_SERVER_PORT/tcp \
|
-p $V2RAY_VMESS_PORT:$V2RAY_VMESS_PORT/tcp \
|
||||||
--name $CONTAINER_NAME $CONTAINER_NAME
|
--name $CONTAINER_NAME $CONTAINER_NAME
|
||||||
|
|
||||||
sudo docker network connect amnezia-dns-net $CONTAINER_NAME
|
sudo docker network connect amnezia-dns-net $CONTAINER_NAME
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,6 @@ killall -KILL openvpn
|
||||||
|
|
||||||
# start daemons if configured
|
# start daemons if configured
|
||||||
if [ -f /opt/amnezia/openvpn/ca.crt ]; then (openvpn --config /opt/amnezia/openvpn/server.conf --daemon); fi
|
if [ -f /opt/amnezia/openvpn/ca.crt ]; then (openvpn --config /opt/amnezia/openvpn/server.conf --daemon); fi
|
||||||
if [ -f /opt/amnezia/v2ray/v2ray-server.json ]; then (v2ray - c /opt/amnezia/v2ray/v2ray-server.json &)
|
if [ -f /opt/amnezia/v2ray/v2ray-server.json ]; then (v2ray -config /opt/amnezia/v2ray/v2ray-server.json &); fi
|
||||||
|
|
||||||
tail -f /dev/null
|
tail -f /dev/null
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,31 @@
|
||||||
{
|
{
|
||||||
"inbounds": [{
|
"inbounds": [
|
||||||
"port": $V2RAY_SOCKS_LOCAL_PORT,
|
{
|
||||||
"listen": "127.0.0.1",
|
"listen": "127.0.0.1",
|
||||||
"protocol": "socks",
|
"port": $V2RAY_SOCKS_LOCAL_PORT,
|
||||||
"settings": {
|
"protocol": "socks",
|
||||||
"auth": "noauth",
|
"settings": {
|
||||||
"udp": false
|
"auth": "noauth",
|
||||||
}
|
"udp": true
|
||||||
}],
|
}
|
||||||
"outbounds": [{
|
}
|
||||||
"protocol": "vmess",
|
],
|
||||||
"settings": {
|
"outbounds": [
|
||||||
"vnext": [{
|
{
|
||||||
"address": "$REMOTE_HOST",
|
"protocol": "vmess",
|
||||||
"port": $V2RAY_VMESS_PORT,
|
"settings": {
|
||||||
"users": [{ "id": "$V2RAY_VMESS_CLIENT_UUID" }]
|
"vnext": [
|
||||||
}]
|
{
|
||||||
}
|
"address": "$REMOTE_HOST",
|
||||||
}]
|
"port": $V2RAY_VMESS_PORT,
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"id": "$V2RAY_VMESS_CLIENT_UUID"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue