-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfix_nginx_auth.sh
More file actions
executable file
·45 lines (37 loc) · 1.21 KB
/
fix_nginx_auth.sh
File metadata and controls
executable file
·45 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
USERNAME=
PASSWORD=
# Check for USERNAME and PASSWORD
if [[ -z "$USERNAME" || -z "$PASSWORD" ]]; then
echo "Set both USERNAME and PASSWORD in the script"
exit
fi
AUTH_B64=$(echo -n "${USERNAME}:${PASSWORD}" | base64 -w 0)
if [[ $EUID -ne 0 ]]; then
echo "Run using sudo or as root"
exit
fi
ORIG=$(cat /etc/nginx/sites-enabled/server.ReverseProxy.conf | grep Authorization)
# Check for existence of Authorization line in nginx config
if [[ -z "$ORIG" ]]; then
echo "The proxy_set_header 'Authorization' was not found in your config."
echo "Have you added it to your Reverse Proxy config in DSM?"
exit
fi
# Output the matches BEFORE the change is made
echo "Before:"
echo -e "$ORIG"
echo
sed -E -i "/^\s*proxy_set_header\s+Authorization\s+/s/(Authorization).*/\1\t\t\"Basic ${AUTH_B64}\";/" /etc/nginx/sites-enabled/server.ReverseProxy.conf
NEW=$(cat /etc/nginx/sites-enabled/server.ReverseProxy.conf | grep Authorization)
# Output the matches AFTER the change is made
echo "After:"
echo -e "$NEW"
echo
# If changes were made, reload nginx configs.
if [[ "${ORIG}" != "${NEW}" ]]; then
echo "Changes made... reloading nginx"
synow3tool --nginx=reload
else
echo "No Changes made... exiting"
fi