gistfile1.txt
· 759 B · Text
Originalformat
function peers::create_client_config() {
local name="$1"
local type="$2"
local ip="$3"
local allowed_ips="${4:-$(config::allowed_ips_for "split")}"
local conf
conf="$(ctx::clients)/${name}.conf"
if [[ -f "$conf" ]]; then
log::wg_warning "Client config already exists: ${name}"
return 1
fi
local private_key
private_key=$(keys::private "$name")
local server_public_key
server_public_key=$(config::server_public_key)
cat > "$conf" <<EOF
[Interface]
PrivateKey = ${private_key}
Address = ${ip}/32
DNS = $(config::dns)
[Peer]
PublicKey = ${server_public_key}
Endpoint = $(config::endpoint)
AllowedIPs = ${allowed_ips}
PersistentKeepalive = 25
EOF
chmod 600 "$conf"
log::debug "Created client config: ${name} (${ip})"
}
| 1 | function peers::create_client_config() { |
| 2 | local name="$1" |
| 3 | local type="$2" |
| 4 | local ip="$3" |
| 5 | local allowed_ips="${4:-$(config::allowed_ips_for "split")}" |
| 6 | |
| 7 | local conf |
| 8 | conf="$(ctx::clients)/${name}.conf" |
| 9 | |
| 10 | if [[ -f "$conf" ]]; then |
| 11 | log::wg_warning "Client config already exists: ${name}" |
| 12 | return 1 |
| 13 | fi |
| 14 | |
| 15 | local private_key |
| 16 | private_key=$(keys::private "$name") |
| 17 | |
| 18 | local server_public_key |
| 19 | server_public_key=$(config::server_public_key) |
| 20 | |
| 21 | cat > "$conf" <<EOF |
| 22 | [Interface] |
| 23 | PrivateKey = ${private_key} |
| 24 | Address = ${ip}/32 |
| 25 | DNS = $(config::dns) |
| 26 | |
| 27 | [Peer] |
| 28 | PublicKey = ${server_public_key} |
| 29 | Endpoint = $(config::endpoint) |
| 30 | AllowedIPs = ${allowed_ips} |
| 31 | PersistentKeepalive = 25 |
| 32 | EOF |
| 33 | |
| 34 | chmod 600 "$conf" |
| 35 | log::debug "Created client config: ${name} (${ip})" |
| 36 | } |