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 "core/servercontroller.h"
|
||||
#include "core/scripts_registry.h"
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
V2RayConfigurator::V2RayConfigurator(std::shared_ptr<Settings> settings, std::shared_ptr<ServerController> serverController,
|
||||
|
|
@ -29,42 +30,13 @@ QString V2RayConfigurator::genV2RayConfig(const ServerCredentials &credentials,
|
|||
return "";
|
||||
}
|
||||
|
||||
QJsonObject config;
|
||||
|
||||
QJsonObject inboundsSocks;
|
||||
inboundsSocks.insert("protocol", "socks");
|
||||
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;
|
||||
inbounds.push_back(inboundsSocks);
|
||||
config.insert("inbounds", inbounds);
|
||||
|
||||
|
||||
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(),
|
||||
QString v2RayClientConfig = m_serverController->replaceVars(amnezia::scriptData(ProtocolScriptType::v2ray_client_template, container),
|
||||
m_serverController->genVarsForScript(credentials, container, containerConfig));
|
||||
|
||||
// qDebug().noquote() << textCfg;
|
||||
return textCfg;
|
||||
v2RayClientConfig.replace("$V2RAY_VMESS_CLIENT_UUID", v2rayVmessClientUuid);
|
||||
v2RayClientConfig = m_serverController->replaceVars(v2RayClientConfig,
|
||||
m_serverController->genVarsForScript(credentials, container, containerConfig));
|
||||
|
||||
return v2RayClientConfig;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ QString amnezia::scriptName(ProtocolScriptType type)
|
|||
case ProtocolScriptType::container_startup: return QLatin1String("start.sh");
|
||||
case ProtocolScriptType::openvpn_template: return QLatin1String("template.ovpn");
|
||||
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,
|
||||
container_startup,
|
||||
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) }});
|
||||
|
||||
// V2Ray vars
|
||||
vars.append({{"$V2RAY_SERVER_PORT", v2RayConfig.value(config_key::port).toString(protocols::v2ray::defaultLocalPort) }});
|
||||
vars.append({{"$V2RAY_LOCAL_PORT", v2RayConfig.value(config_key::local_port).toString(protocols::v2ray::defaultServerPort) }});
|
||||
vars.append({{"$V2RAY_VMESS_PORT", v2RayConfig.value(config_key::port).toString(protocols::v2ray::defaultServerPort) }});
|
||||
vars.append({{"$V2RAY_SOCKS_LOCAL_PORT", v2RayConfig.value(config_key::local_port).toString(protocols::v2ray::defaultLocalPort) }});
|
||||
|
||||
// IPsec vars
|
||||
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/start.sh</file>
|
||||
<file>server_scripts/openvpn_v2ray_vmess/template.ovpn</file>
|
||||
<file>server_scripts/openvpn_v2ray_vmess/template_v2ray_client.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
|||
|
|
@ -26,23 +26,23 @@ $OPENVPN_TLS_AUTH
|
|||
$OPENVPN_ADDITIONAL_SERVER_CONFIG
|
||||
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.
|
||||
# UUID is 32 hexadecimal digits /([0-9a-f]-?){32}/ (128 bit value).
|
||||
|
||||
mkdir -p /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
|
||||
|
||||
cat < /opt/amnezia/v2ray/v2ray-server.json <<EOF
|
||||
cat > /opt/amnezia/v2ray/v2ray-server.json <<EOF
|
||||
{
|
||||
"log": {
|
||||
"loglevel": "None"
|
||||
},
|
||||
"inbounds": [
|
||||
{
|
||||
"port": $V2RAY_SERVER_PORT,
|
||||
"port": $V2RAY_VMESS_PORT,
|
||||
"protocol": "vmess",
|
||||
"settings": {
|
||||
"clients": [
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ sudo docker run -d \
|
|||
--log-driver none \
|
||||
--restart always \
|
||||
--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
|
||||
|
||||
sudo docker network connect amnezia-dns-net $CONTAINER_NAME
|
||||
|
|
|
|||
|
|
@ -26,6 +26,6 @@ killall -KILL openvpn
|
|||
|
||||
# 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/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
|
||||
|
|
|
|||
|
|
@ -1,21 +1,31 @@
|
|||
{
|
||||
"inbounds": [{
|
||||
"port": $V2RAY_SOCKS_LOCAL_PORT,
|
||||
"inbounds": [
|
||||
{
|
||||
"listen": "127.0.0.1",
|
||||
"port": $V2RAY_SOCKS_LOCAL_PORT,
|
||||
"protocol": "socks",
|
||||
"settings": {
|
||||
"auth": "noauth",
|
||||
"udp": false
|
||||
"udp": true
|
||||
}
|
||||
}],
|
||||
"outbounds": [{
|
||||
}
|
||||
],
|
||||
"outbounds": [
|
||||
{
|
||||
"protocol": "vmess",
|
||||
"settings": {
|
||||
"vnext": [{
|
||||
"vnext": [
|
||||
{
|
||||
"address": "$REMOTE_HOST",
|
||||
"port": $V2RAY_VMESS_PORT,
|
||||
"users": [{ "id": "$V2RAY_VMESS_CLIENT_UUID" }]
|
||||
}]
|
||||
"users": [
|
||||
{
|
||||
"id": "$V2RAY_VMESS_CLIENT_UUID"
|
||||
}
|
||||
}]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue