mirror of
https://github.com/faicker/wg-config.git
synced 2020-11-18 19:53:49 -08:00
add init server
This commit is contained in:
parent
18d564adcf
commit
c7003084f5
@ -8,17 +8,19 @@ Client config file and qrcode are generated.
|
|||||||
|
|
||||||
### config
|
### config
|
||||||
The wireguard default config directory is /etc/wireguard.
|
The wireguard default config directory is /etc/wireguard.
|
||||||
|
|
||||||
The script config file is wg.def, create and edit it according to wg.def.sample.
|
The script config file is wg.def, create and edit it according to wg.def.sample.
|
||||||
|
|
||||||
You can generate the public key and private key with command `wg genkey | tee prikey | wg pubkey > pubkey`.
|
You can generate the public key and private key with command `wg genkey | tee prikey | wg pubkey > pubkey`.
|
||||||
|
|
||||||
### usage
|
### usage
|
||||||
|
|
||||||
Running as root.
|
Running as root.
|
||||||
|
|
||||||
#### start wireguard
|
#### init wireguard server
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wg-quick up wg0
|
./user.sh -i
|
||||||
```
|
```
|
||||||
|
|
||||||
#### add a user
|
#### add a user
|
||||||
|
35
user.sh
35
user.sh
@ -84,7 +84,7 @@ add_user() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$user $_VPN_IP $public_key" >> ${SAVED_FILE}
|
echo "$user $_VPN_IP $public_key" >> ${SAVED_FILE} && echo "use $user is added. config dir is $userdir"
|
||||||
}
|
}
|
||||||
|
|
||||||
del_user() {
|
del_user() {
|
||||||
@ -105,7 +105,7 @@ del_user() {
|
|||||||
if [[ -n "$ip" ]]; then
|
if [[ -n "$ip" ]]; then
|
||||||
echo "$ip" >> ${AVAILABLE_IP_FILE}
|
echo "$ip" >> ${AVAILABLE_IP_FILE}
|
||||||
fi
|
fi
|
||||||
rm -rf $userdir
|
rm -rf $userdir && echo "use $user is deleted"
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_and_install_server_config_file() {
|
generate_and_install_server_config_file() {
|
||||||
@ -125,7 +125,7 @@ EOF
|
|||||||
\cp -f $WG_TMP_CONF_FILE $WG_CONF_FILE
|
\cp -f $WG_TMP_CONF_FILE $WG_CONF_FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
do_clear() {
|
clear_all() {
|
||||||
local interface=$_INTERFACE
|
local interface=$_INTERFACE
|
||||||
wg-quick down $interface
|
wg-quick down $interface
|
||||||
> $WG_CONF_FILE
|
> $WG_CONF_FILE
|
||||||
@ -148,8 +148,29 @@ do_user() {
|
|||||||
generate_and_install_server_config_file
|
generate_and_install_server_config_file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init_server() {
|
||||||
|
local interface=$_INTERFACE
|
||||||
|
local template_file=${SERVER_TPL_FILE}
|
||||||
|
|
||||||
|
if [[ -s $WG_CONF_FILE ]]; then
|
||||||
|
echo "$WG_CONF_FILE exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
generate_cidr_ip_file_if
|
||||||
|
eval "echo \"$(cat "${template_file}")\"" > $WG_CONF_FILE
|
||||||
|
chmod 600 $WG_CONF_FILE
|
||||||
|
wg-quick up $interface
|
||||||
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: $0 [-a|-d|-c|-g] [username]"
|
echo "usage: $0 [-a|-d|-c|-g|-i] [username]
|
||||||
|
|
||||||
|
-i: init server conf
|
||||||
|
-a: add user
|
||||||
|
-d: del user
|
||||||
|
-c: clear all
|
||||||
|
-g: generate ip file
|
||||||
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
# main
|
# main
|
||||||
@ -161,8 +182,10 @@ fi
|
|||||||
action=$1
|
action=$1
|
||||||
user=$2
|
user=$2
|
||||||
|
|
||||||
if [[ $action == "-c" ]]; then
|
if [[ $action == "-i" ]]; then
|
||||||
do_clear
|
init_server
|
||||||
|
elif [[ $action == "-c" ]]; then
|
||||||
|
clear_all
|
||||||
elif [[ $action == "-g" ]]; then
|
elif [[ $action == "-g" ]]; then
|
||||||
generate_cidr_ip_file_if
|
generate_cidr_ip_file_if
|
||||||
elif [[ ! -z "$user" && ( $action == "-a" || $action == "-d" ) ]]; then
|
elif [[ ! -z "$user" && ( $action == "-a" || $action == "-d" ) ]]; then
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
_INTERFACE=wg0
|
_INTERFACE=wg0
|
||||||
_VPN_NET=192.168.88.0/24
|
_VPN_NET=192.168.88.0/24
|
||||||
_SERVER_PORT=2000
|
_SERVER_PORT=2000
|
||||||
_SERVER_LISTEN=wg.example.com:$_SERVER_PORT
|
_SERVER_LISTEN=wg.example.com:$_SERVER_PORT # client use
|
||||||
_SERVER_PUBLIC_KEY=
|
_SERVER_PUBLIC_KEY=
|
||||||
_SERVER_PRIVATE_KEY=
|
_SERVER_PRIVATE_KEY=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user