generated from pavel.muhortov/template-bash
added wg-client-management.conf
This commit is contained in:
parent
decb640e5b
commit
cd2450cf72
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -23,5 +23,4 @@ downloads/
|
||||||
test/
|
test/
|
||||||
tmp/
|
tmp/
|
||||||
var/
|
var/
|
||||||
*.conf
|
|
||||||
*.log
|
*.log
|
19
README.md
19
README.md
|
@ -80,7 +80,8 @@ ____
|
||||||
| 2 |**add\|del**|add or delete client config|**REQUIRED**|
|
| 2 |**add\|del**|add or delete client config|**REQUIRED**|
|
||||||
| 3 |**\<username\>**|client username|**REQUIRED**|
|
| 3 |**\<username\>**|client username|**REQUIRED**|
|
||||||
| 4 |**\<address\>**|client ip address|**REQUIRED**|
|
| 4 |**\<address\>**|client ip address|**REQUIRED**|
|
||||||
| 5 |**[-f]**,**[--force]**|service will restart after add\|del username||
|
| 5 |**\<additional\>**|client description||
|
||||||
|
| 6 |**[-f]**,**[--force]**|service will restart after add\|del username||
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
|
|
||||||
|
@ -107,6 +108,22 @@ sudo chmod +x /etc/wireguard/wg-client-management.sh
|
||||||
sudo mkdir /var/log/wireguard
|
sudo mkdir /var/log/wireguard
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# edit wg-client-management.conf
|
||||||
|
sudo tee /etc/wireguard/wg-client-management.conf > /dev/null <<'EOF'
|
||||||
|
# sendmail configuration
|
||||||
|
from=user@host.zone
|
||||||
|
pass=password
|
||||||
|
dest=user@host.zone
|
||||||
|
smtp=smtp.host.zone
|
||||||
|
port=587
|
||||||
|
# telegram configuration
|
||||||
|
API_KEY=YOURAPIKEY
|
||||||
|
CHAT_ID=-100123456789
|
||||||
|
THRD_ID=123
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# create link
|
# create link
|
||||||
ln -s /etc/wireguard/wg-client-management.sh ./wg
|
ln -s /etc/wireguard/wg-client-management.sh ./wg
|
||||||
|
|
10
wg-client-management.conf
Normal file
10
wg-client-management.conf
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# sendmail configuration
|
||||||
|
from=user@host.zone
|
||||||
|
pass=password
|
||||||
|
dest=user@host.zone
|
||||||
|
smtp=smtp.host.zone
|
||||||
|
port=587
|
||||||
|
# telegram configuration
|
||||||
|
API_KEY=YOURAPIKEY
|
||||||
|
CHAT_ID=-100123456789
|
||||||
|
THRD_ID=123
|
|
@ -59,6 +59,34 @@ execerror() {
|
||||||
execquite 1
|
execquite 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Parsing config file and creating global vars.
|
||||||
|
# Globals:
|
||||||
|
# None
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
getconfig() {
|
||||||
|
logs=/var/log/wireguard/$(basename -s .sh "$(realpath "$0")").log
|
||||||
|
conf="$(dirname "$(realpath "$0")")/$(basename -s .sh "$(realpath "$0")").conf"
|
||||||
|
# wireguard configuration
|
||||||
|
serverpublkey=$(cat /etc/wireguard/pki/server-public.key)
|
||||||
|
servercfgname="/etc/wireguard/${iface_name}.conf"
|
||||||
|
clientpublkey=''
|
||||||
|
clientprivkey=''
|
||||||
|
clientconfdef="/etc/wireguard/client.conf.default"
|
||||||
|
# mail configuration
|
||||||
|
from="$(grep "from=" "${conf}" | cut -d= -f2)"
|
||||||
|
pass="$(grep "pass=" "${conf}" | cut -d= -f2)"
|
||||||
|
dest="$(grep "dest=" "${conf}" | cut -d= -f2)"
|
||||||
|
smtp="$(grep "smtp=" "${conf}" | cut -d= -f2)"
|
||||||
|
port="$(grep "port=" "${conf}" | cut -d= -f2)"
|
||||||
|
# telegram configuration
|
||||||
|
API_KEY=$(grep "API_KEY=" "${conf}" | cut -d= -f2)
|
||||||
|
CHAT_ID=$(grep "CHAT_ID=" "${conf}" | cut -d= -f2)
|
||||||
|
THRD_ID=$(grep "THRD_ID=" "${conf}" | cut -d= -f2)
|
||||||
|
}
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Checking user rights.
|
# Checking user rights.
|
||||||
# Globals:
|
# Globals:
|
||||||
|
@ -88,17 +116,17 @@ startsendmail() {
|
||||||
subj="[WG Settings] $(cat /etc/hostname): ${clientname} client profile"
|
subj="[WG Settings] $(cat /etc/hostname): ${clientname} client profile"
|
||||||
(
|
(
|
||||||
python3 /usr/local/bin/sendmail.py \
|
python3 /usr/local/bin/sendmail.py \
|
||||||
-u "$(grep "from=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
|
-u "${from}" \
|
||||||
-p "$(grep "pass=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
|
-p "${pass}" \
|
||||||
-d "$(grep "dest=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
|
-d "${dest}" \
|
||||||
--smtp "$(grep "smtp=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
|
--smtp "${smtp}" \
|
||||||
--port "$(grep "port=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
|
--port "${port}" \
|
||||||
--stls "True" \
|
--stls "True" \
|
||||||
--subj "${subj}" \
|
--subj "${subj}" \
|
||||||
--text "$(printf "%s\n" "${faqprofile}" | sed 's|`||g')" \
|
--text "$(printf "%s\n" "${faqprofile}" | sed 's|`||g')" \
|
||||||
--file "/etc/wireguard/${clientname}.png,/etc/wireguard/${clientname}.conf"
|
--file "/etc/wireguard/${clientname}.png,/etc/wireguard/${clientname}.conf"
|
||||||
) > /dev/null 2>&1
|
) > /dev/null 2>&1
|
||||||
addtologs "sent mail with subject '${subj}'"
|
addtologs "sent mail with subject '${subj}' to ${dest}"
|
||||||
}
|
}
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
|
@ -257,13 +285,7 @@ fi
|
||||||
#
|
#
|
||||||
|
|
||||||
if checkroot; then
|
if checkroot; then
|
||||||
serverpublkey=$(cat /etc/wireguard/pki/server-public.key)
|
getconfig
|
||||||
servercfgname="/etc/wireguard/${iface_name}.conf"
|
|
||||||
clientpublkey=''
|
|
||||||
clientprivkey=''
|
|
||||||
clientconfdef="/etc/wireguard/client.conf.default"
|
|
||||||
logs=/var/log/wireguard/$(basename -s .sh "$0").log
|
|
||||||
|
|
||||||
if [ "${clienttodo}" == "add" ] && \
|
if [ "${clienttodo}" == "add" ] && \
|
||||||
[ -n "${clientname}" ] && \
|
[ -n "${clientname}" ] && \
|
||||||
grepcidr "0.0.0.0/0" <(echo "${clientaddr}") >/dev/null; then
|
grepcidr "0.0.0.0/0" <(echo "${clientaddr}") >/dev/null; then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user