Ultima attività 1 month ago

Revisione fa786182abc34756a373d30b6cb75a044e4f837e

gistfile1.txt Raw
1function 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]
23PrivateKey = ${private_key}
24Address = ${ip}/32
25DNS = $(config::dns)
26
27[Peer]
28PublicKey = ${server_public_key}
29Endpoint = $(config::endpoint)
30AllowedIPs = ${allowed_ips}
31PersistentKeepalive = 25
32EOF
33
34 chmod 600 "$conf"
35 log::debug "Created client config: ${name} (${ip})"
36}