dnk: tune shm_actions_script.sh
This commit is contained in:
parent
b087228f69
commit
9e41d03b71
@ -1,7 +1,19 @@
|
||||
#!/bin/bash -e
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
EVENT="{{ event_name }}"
|
||||
WG_MANAGER="/etc/wireguard/wg-manager.sh"
|
||||
SESSION_ID="{{ user.gen_session.id }}"
|
||||
|
||||
# We need the --fail-with-body option for curl.
|
||||
# It has been added since curl 7.76.0, but almost all Linux distributions do not support it yet.
|
||||
# If your distribution has an older version of curl, you can use it (just comment CURL_REPO)
|
||||
CURL_REPO="https://github.com/moparisthebest/static-curl/releases/download/v7.86.0/curl-amd64"
|
||||
CURL="/opt/curl/curl-amd64"
|
||||
#CURL="curl"
|
||||
|
||||
echo "EVENT=$EVENT"
|
||||
|
||||
case $EVENT in
|
||||
INIT)
|
||||
@ -16,30 +28,43 @@ case $EVENT in
|
||||
wireguard \
|
||||
wireguard-tools \
|
||||
qrencode \
|
||||
curl
|
||||
wget
|
||||
|
||||
if [[ $CURL_REPO && ! -f $CURL ]]; then
|
||||
mkdir -p /opt/curl
|
||||
cd /opt/curl
|
||||
wget $CURL_REPO
|
||||
chmod 755 $CURL
|
||||
fi
|
||||
|
||||
cd /etc/wireguard
|
||||
curl -s https://danuk.github.io/wg-manager/wg-manager.sh > $WG_MANAGER
|
||||
$CURL -s --fail-with-body https://danuk.github.io/wg-manager/wg-manager.sh > $WG_MANAGER
|
||||
chmod 700 $WG_MANAGER
|
||||
$WG_MANAGER -i -s $SERVER_HOST
|
||||
;;
|
||||
CREATE)
|
||||
SESSION_ID="{{ user.gen_session.id }}"
|
||||
USER_CFG=$($WG_MANAGER -c "{{ us.id }}" -p)
|
||||
|
||||
if [ $? -ne 0]; then
|
||||
echo "ERROR: can't create user"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
curl -s -XPUT \
|
||||
$CURL -s --fail-with-body -XPUT \
|
||||
-H "session-id: $SESSION_ID" \
|
||||
-H "Content-Type: text/plain" \
|
||||
{{ config.api.url }}/shm/v1/storage/manage/vpn \
|
||||
--data-binary $USER_CFG
|
||||
--data-binary @"/etc/wireguard/keys/{{ us.id }}/{{ us.id }}.conf"
|
||||
echo "done"
|
||||
;;
|
||||
ACTIVATE)
|
||||
$WG_MANAGER -u "{{ us.id }}" -U
|
||||
echo "done"
|
||||
;;
|
||||
BLOCK)
|
||||
$WG_MANAGER -u "{{ us.id }}" -L
|
||||
echo "done"
|
||||
;;
|
||||
REMOVE)
|
||||
$WG_MANAGER -c "{{ us.id }}" -d
|
||||
$WG_MANAGER -u "{{ us.id }}" -d
|
||||
$CURL -s --fail-with-body -XDELETE \
|
||||
-H "session-id: $SESSION_ID" \
|
||||
{{ config.api.url }}/shm/v1/storage/manage/vpn
|
||||
echo "done"
|
||||
;;
|
||||
*)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user