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 }}"
|
EVENT="{{ event_name }}"
|
||||||
WG_MANAGER="/etc/wireguard/wg-manager.sh"
|
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
|
case $EVENT in
|
||||||
INIT)
|
INIT)
|
||||||
@ -16,30 +28,43 @@ case $EVENT in
|
|||||||
wireguard \
|
wireguard \
|
||||||
wireguard-tools \
|
wireguard-tools \
|
||||||
qrencode \
|
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
|
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
|
chmod 700 $WG_MANAGER
|
||||||
$WG_MANAGER -i -s $SERVER_HOST
|
$WG_MANAGER -i -s $SERVER_HOST
|
||||||
;;
|
;;
|
||||||
CREATE)
|
CREATE)
|
||||||
SESSION_ID="{{ user.gen_session.id }}"
|
|
||||||
USER_CFG=$($WG_MANAGER -c "{{ us.id }}" -p)
|
USER_CFG=$($WG_MANAGER -c "{{ us.id }}" -p)
|
||||||
|
|
||||||
if [ $? -ne 0]; then
|
$CURL -s --fail-with-body -XPUT \
|
||||||
echo "ERROR: can't create user"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
curl -s -XPUT \
|
|
||||||
-H "session-id: $SESSION_ID" \
|
-H "session-id: $SESSION_ID" \
|
||||||
-H "Content-Type: text/plain" \
|
-H "Content-Type: text/plain" \
|
||||||
{{ config.api.url }}/shm/v1/storage/manage/vpn \
|
{{ 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"
|
echo "done"
|
||||||
;;
|
;;
|
||||||
REMOVE)
|
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"
|
echo "done"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user