feat(remnawave): declarative panel on core-net and SelfSteal node on ger-nod-02
ansible-core-mon / deploy (push) Successful in 25s
ansible-core-secrets / deploy (push) Canceled after 0s
ansible-ger-nod-02 / deploy (push) Canceled after 0s
ansible-opnsense / deploy (push) Canceled after 0s
ansible-rus-central / deploy (push) Canceled after 0s
ansible-core-net / deploy (push) Failing after 26s
ansible-core-mon / deploy (push) Successful in 25s
ansible-core-secrets / deploy (push) Canceled after 0s
ansible-ger-nod-02 / deploy (push) Canceled after 0s
ansible-opnsense / deploy (push) Canceled after 0s
ansible-rus-central / deploy (push) Canceled after 0s
ansible-core-net / deploy (push) Failing after 26s
Add Remnawave panel+subscription behind Traefik (rw/sub.gunihome.ru), API bootstrap into Infisical, and ger-nod-02 node with Cloudflare DNS-01 SelfSteal (yali.gunis.top). Leaves remna.gunihome.ru on Golova untouched. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a0ec829eee
commit
8caaddc779
25 files changed
+1401
-5
No files matched your search
@@ -0,0 +1,279 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
API_BASE="https://${RW_PANEL_DOMAIN}/api"
|
||||
CURL=(curl -fsSk --resolve "${RW_PANEL_DOMAIN}:443:127.0.0.1")
|
||||
AUTH_HDR=()
|
||||
|
||||
admin_created=0
|
||||
token_updated=0
|
||||
profile_created=0
|
||||
node_created=0
|
||||
host_created=0
|
||||
node_secret=""
|
||||
active_token="${RW_API_TOKEN:-}"
|
||||
|
||||
api() {
|
||||
local method="$1"; shift
|
||||
local path="$1"; shift
|
||||
if [ "${#AUTH_HDR[@]}" -gt 0 ]; then
|
||||
"${CURL[@]}" -X "$method" "${AUTH_HDR[@]}" -H "Content-Type: application/json" "${API_BASE}${path}" "$@"
|
||||
else
|
||||
"${CURL[@]}" -X "$method" -H "Content-Type: application/json" "${API_BASE}${path}" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
json_first() {
|
||||
jq -r "$1" 2>/dev/null || true
|
||||
}
|
||||
|
||||
status_json=$("${CURL[@]}" "${API_BASE}/auth/status")
|
||||
is_login=$(printf '%s' "${status_json}" | jq -r '.response.isLoginAllowed // .isLoginAllowed // false')
|
||||
is_register=$(printf '%s' "${status_json}" | jq -r '.response.isRegisterAllowed // .isRegisterAllowed // false')
|
||||
|
||||
if [ "${is_register}" = "true" ]; then
|
||||
reg_payload=$(jq -n --arg u "$RW_ADMIN_USER" --arg p "$RW_ADMIN_PASS" '{username: $u, password: $p}')
|
||||
api POST /auth/register -d "${reg_payload}" >/dev/null
|
||||
admin_created=1
|
||||
is_login=true
|
||||
fi
|
||||
|
||||
login_ok=0
|
||||
if [ -n "${active_token}" ]; then
|
||||
code=$("${CURL[@]}" -o /dev/null -w '%{http_code}' \
|
||||
-H "Authorization: Bearer ${active_token}" "${API_BASE}/nodes/" || true)
|
||||
if [ "${code}" = "200" ]; then
|
||||
login_ok=1
|
||||
AUTH_HDR=(-H "Authorization: Bearer ${active_token}")
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${login_ok}" -eq 0 ]; then
|
||||
login_payload=$(jq -n --arg u "$RW_ADMIN_USER" --arg p "$RW_ADMIN_PASS" '{username: $u, password: $p}')
|
||||
login_resp=$(api POST /auth/login -d "${login_payload}")
|
||||
access=$(printf '%s' "${login_resp}" | jq -r '.response.accessToken // .accessToken // empty')
|
||||
if [ -z "${access}" ]; then
|
||||
echo "Не удалось войти в панель Remnawave" >&2
|
||||
printf '%s\n' "${login_resp}" >&2
|
||||
exit 1
|
||||
fi
|
||||
AUTH_HDR=(-H "Authorization: Bearer ${access}")
|
||||
|
||||
tokens_json=$(api GET /tokens/ || echo '{"response":[]}')
|
||||
old_uuid=$(printf '%s' "${tokens_json}" | jq -r --arg n "$RW_TOKEN_NAME" '
|
||||
(.response // .)
|
||||
| if type=="array" then . elif .tokens then .tokens else [] end
|
||||
| map(select(.tokenName == $n or .name == $n))
|
||||
| .[0].uuid // empty')
|
||||
if [ -n "${old_uuid}" ]; then
|
||||
api DELETE "/tokens/${old_uuid}" >/dev/null || true
|
||||
fi
|
||||
|
||||
token_payload=$(jq -n --arg n "$RW_TOKEN_NAME" '{tokenName: $n}')
|
||||
token_resp=$(api POST /tokens/ -d "${token_payload}")
|
||||
active_token=$(printf '%s' "${token_resp}" | jq -r '
|
||||
.response.token // .response.apiToken // .token // .apiToken // empty')
|
||||
if [ -z "${active_token}" ]; then
|
||||
echo "Не удалось создать API-токен" >&2
|
||||
printf '%s\n' "${token_resp}" >&2
|
||||
exit 1
|
||||
fi
|
||||
AUTH_HDR=(-H "Authorization: Bearer ${active_token}")
|
||||
token_updated=1
|
||||
fi
|
||||
|
||||
profiles_json=$(api GET /config-profiles/)
|
||||
profile_uuid=$(printf '%s' "${profiles_json}" | jq -r --arg n "$RW_PROFILE_NAME" '
|
||||
(.response.configProfiles // .response // [])
|
||||
| map(select(.name == $n)) | .[0].uuid // empty')
|
||||
pub=""
|
||||
|
||||
if [ -z "${profile_uuid}" ]; then
|
||||
key_resp=$(api GET /system/tools/x25519/generate 2>/dev/null || api GET /keygen/ 2>/dev/null || echo '{}')
|
||||
priv=$(printf '%s' "${key_resp}" | jq -r '
|
||||
.response.privateKey // .response.privKey // .privateKey // .privKey // empty')
|
||||
pub=$(printf '%s' "${key_resp}" | jq -r '
|
||||
.response.publicKey // .response.pubKey // .publicKey // .pubKey // empty')
|
||||
if [ -z "${priv}" ]; then
|
||||
echo "Не удалось сгенерировать X25519 ключи Reality" >&2
|
||||
printf '%s\n' "${key_resp}" >&2
|
||||
exit 1
|
||||
fi
|
||||
short_id=$(openssl rand -hex 8)
|
||||
profile_config=$(sed \
|
||||
-e "s|__REALITY_PRIVATE_KEY__|${priv}|g" \
|
||||
-e "s|__REALITY_SHORT_ID__|${short_id}|g" \
|
||||
"$RW_PROFILE_FILE")
|
||||
create_profile=$(jq -n --arg n "$RW_PROFILE_NAME" --argjson c "${profile_config}" '{name: $n, config: $c}')
|
||||
profile_resp=$(api POST /config-profiles/ -d "${create_profile}")
|
||||
profile_uuid=$(printf '%s' "${profile_resp}" | jq -r '.response.uuid // .uuid // empty')
|
||||
if [ -z "${profile_uuid}" ]; then
|
||||
echo "Не удалось создать config profile" >&2
|
||||
printf '%s\n' "${profile_resp}" >&2
|
||||
exit 1
|
||||
fi
|
||||
profile_created=1
|
||||
fi
|
||||
|
||||
profile_full=$(api GET "/config-profiles/${profile_uuid}")
|
||||
inbound_uuid=$(printf '%s' "${profile_full}" | jq -r --arg t "$RW_INBOUND_TAG" '
|
||||
(.response.inbounds // .inbounds // [])
|
||||
| map(select(.tag == $t)) | .[0].uuid // empty')
|
||||
if [ -z "${inbound_uuid}" ]; then
|
||||
inbounds_json=$(api GET "/config-profiles/${profile_uuid}/inbounds" 2>/dev/null || echo '{}')
|
||||
inbound_uuid=$(printf '%s' "${inbounds_json}" | jq -r --arg t "$RW_INBOUND_TAG" '
|
||||
(.response // .)
|
||||
| if type=="array" then . else (.inbounds // []) end
|
||||
| map(select(.tag == $t)) | .[0].uuid // empty')
|
||||
fi
|
||||
if [ -z "${inbound_uuid}" ]; then
|
||||
echo "Не найден inbound ${RW_INBOUND_TAG} в профиле ${profile_uuid}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
nodes_json=$(api GET /nodes/)
|
||||
node_uuid=$(printf '%s' "${nodes_json}" | jq -r --arg n "$RW_NODE_NAME" '
|
||||
(.response // []) | map(select(.name == $n)) | .[0].uuid // empty')
|
||||
node_secret="${RW_NODE_SECRET:-}"
|
||||
|
||||
if [ -z "${node_uuid}" ]; then
|
||||
node_payload=$(jq -n \
|
||||
--arg name "$RW_NODE_NAME" \
|
||||
--arg addr "$RW_NODE_ADDR" \
|
||||
--argjson port "$RW_NODE_PORT" \
|
||||
--arg cc "$RW_NODE_CC" \
|
||||
--arg pu "$profile_uuid" \
|
||||
--arg iu "$inbound_uuid" \
|
||||
'{
|
||||
name: $name,
|
||||
address: $addr,
|
||||
port: $port,
|
||||
countryCode: $cc,
|
||||
configProfile: {
|
||||
activeConfigProfileUuid: $pu,
|
||||
activeInbounds: [$iu]
|
||||
}
|
||||
}')
|
||||
node_resp=$(api POST /nodes/ -d "${node_payload}" 2>/dev/null || true)
|
||||
node_uuid=$(printf '%s' "${node_resp}" | jq -r '.response.uuid // .uuid // empty')
|
||||
node_secret=$(printf '%s' "${node_resp}" | jq -r '
|
||||
.response.secretKey // .response.SECRET_KEY // .secretKey // .SECRET_KEY // empty')
|
||||
|
||||
if [ -z "${node_uuid}" ]; then
|
||||
node_payload=$(jq -n \
|
||||
--arg name "$RW_NODE_NAME" \
|
||||
--arg addr "$RW_NODE_ADDR" \
|
||||
--argjson port "$RW_NODE_PORT" \
|
||||
--arg cc "$RW_NODE_CC" \
|
||||
'{name: $name, address: $addr, port: $port, countryCode: $cc}')
|
||||
node_resp=$(api POST /nodes/ -d "${node_payload}")
|
||||
node_uuid=$(printf '%s' "${node_resp}" | jq -r '.response.uuid // .uuid // empty')
|
||||
node_secret=$(printf '%s' "${node_resp}" | jq -r '
|
||||
.response.secretKey // .response.SECRET_KEY // .secretKey // .SECRET_KEY // empty')
|
||||
fi
|
||||
|
||||
if [ -z "${node_uuid}" ]; then
|
||||
echo "Не удалось создать ноду" >&2
|
||||
printf '%s\n' "${node_resp}" >&2
|
||||
exit 1
|
||||
fi
|
||||
node_created=1
|
||||
fi
|
||||
|
||||
node_update=$(jq -n \
|
||||
--arg u "$node_uuid" \
|
||||
--arg pu "$profile_uuid" \
|
||||
--arg iu "$inbound_uuid" \
|
||||
'{
|
||||
uuid: $u,
|
||||
configProfile: {
|
||||
activeConfigProfileUuid: $pu,
|
||||
activeInbounds: [$iu]
|
||||
}
|
||||
}')
|
||||
api PATCH /nodes/ -d "${node_update}" >/dev/null 2>&1 \
|
||||
|| api PUT /nodes/ -d "${node_update}" >/dev/null 2>&1 \
|
||||
|| true
|
||||
|
||||
if [ -z "${node_secret}" ] && [ "${node_created}" -eq 1 ]; then
|
||||
node_full=$(api GET "/nodes/${node_uuid}")
|
||||
node_secret=$(printf '%s' "${node_full}" | jq -r '
|
||||
.response.secretKey // .response.SECRET_KEY // .secretKey // empty')
|
||||
fi
|
||||
|
||||
hosts_json=$(api GET /hosts/)
|
||||
host_uuid=$(printf '%s' "${hosts_json}" | jq -r --arg a "$RW_SELFSTEAL" '
|
||||
(.response // []) | map(select(.address == $a)) | .[0].uuid // empty')
|
||||
|
||||
if [ -z "${host_uuid}" ]; then
|
||||
host_payload=$(jq -n \
|
||||
--arg remark "$RW_HOST_REMARK" \
|
||||
--arg addr "$RW_SELFSTEAL" \
|
||||
--arg path "$RW_XHTTP_PATH" \
|
||||
--arg sni "$RW_SELFSTEAL" \
|
||||
--arg host "$RW_SELFSTEAL" \
|
||||
--arg pu "$profile_uuid" \
|
||||
--arg iu "$inbound_uuid" \
|
||||
--arg nu "$node_uuid" \
|
||||
'{
|
||||
remark: $remark,
|
||||
address: $addr,
|
||||
port: 443,
|
||||
path: $path,
|
||||
sni: $sni,
|
||||
host: $host,
|
||||
fingerprint: "chrome",
|
||||
isDisabled: false,
|
||||
securityLayer: "DEFAULT",
|
||||
alpn: "h2",
|
||||
xHttpExtraParams: {
|
||||
xmux: {
|
||||
maxConcurrency: "16-32",
|
||||
hMaxRequestTimes: "600-900",
|
||||
hMaxReusableSecs: "1800-3000"
|
||||
},
|
||||
noSSEHeader: true,
|
||||
xPaddingBytes: "100-1000"
|
||||
},
|
||||
inbound: {
|
||||
configProfileUuid: $pu,
|
||||
configProfileInboundUuid: $iu
|
||||
},
|
||||
nodes: [$nu]
|
||||
}')
|
||||
host_resp=$(api POST /hosts/ -d "${host_payload}")
|
||||
host_uuid=$(printf '%s' "${host_resp}" | jq -r '.response.uuid // .uuid // empty')
|
||||
if [ -z "${host_uuid}" ]; then
|
||||
echo "Не удалось создать host" >&2
|
||||
printf '%s\n' "${host_resp}" >&2
|
||||
exit 1
|
||||
fi
|
||||
host_created=1
|
||||
fi
|
||||
|
||||
jq -n \
|
||||
--arg api_token "${active_token}" \
|
||||
--arg node_secret "${node_secret}" \
|
||||
--arg profile_uuid "${profile_uuid}" \
|
||||
--arg node_uuid "${node_uuid}" \
|
||||
--arg host_uuid "${host_uuid}" \
|
||||
--arg reality_pub "${pub}" \
|
||||
--argjson admin_created "${admin_created}" \
|
||||
--argjson token_updated "${token_updated}" \
|
||||
--argjson profile_created "${profile_created}" \
|
||||
--argjson node_created "${node_created}" \
|
||||
--argjson host_created "${host_created}" \
|
||||
'{
|
||||
api_token: $api_token,
|
||||
node_secret: $node_secret,
|
||||
profile_uuid: $profile_uuid,
|
||||
node_uuid: $node_uuid,
|
||||
host_uuid: $host_uuid,
|
||||
reality_public_key: $reality_pub,
|
||||
admin_created: ($admin_created == 1),
|
||||
token_updated: ($token_updated == 1),
|
||||
profile_created: ($profile_created == 1),
|
||||
node_created: ($node_created == 1),
|
||||
host_created: ($host_created == 1),
|
||||
changed: (($admin_created + $token_updated + $profile_created + $node_created + $host_created) > 0)
|
||||
}'
|
||||
Reference in new issue
Block a user