-
-
Notifications
You must be signed in to change notification settings - Fork 653
/
adminer.sh
154 lines (122 loc) Β· 4.26 KB
/
adminer.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
# T&M Hansson IT AB Β© - 2024, https://www.hanssonit.se/
true
SCRIPT_NAME="Adminer"
SCRIPT_EXPLAINER="Adminer is a full-featured database management tool written in PHP."
# shellcheck source=lib.sh
source /var/scripts/fetch_lib.sh
# Check for errors + debug code and abort if something isn't right
# 1 = ON
# 0 = OFF
DEBUG=0
debug_mode
# Check if root
root_check
# Check if adminer is already installed
if ! is_this_installed adminer
then
# Ask for installing
install_popup "$SCRIPT_NAME"
else
# Ask for removal or reinstallation
reinstall_remove_menu "$SCRIPT_NAME"
# Removal
check_external_ip # Check that the script can see the external IP (apache fails otherwise)
a2disconf adminer.conf
restart_webserver
rm -f $ADMINER_CONF
rm -rf $ADMINERDIR
check_command apt-get purge adminer -y
restart_webserver
# Show successful uninstall if applicable
removal_popup "$SCRIPT_NAME"
fi
# Check that the script can see the external IP (apache fails otherwise)
check_external_ip
# Check distribution and version
check_distro_version
# Install Apache2
install_if_not apache2
a2enmod headers
a2enmod rewrite
a2enmod ssl
# Install Adminer
apt-get update -q4 & spinner_loading
install_if_not adminer
curl_to_dir "http://www.adminer.org" "latest.php" "$ADMINERDIR"
curl_to_dir "https://raw.githubusercontent.com/Niyko/Hydra-Dark-Theme-for-Adminer/master" "adminer.css" "$ADMINERDIR"
ln -s "$ADMINERDIR"/latest.php "$ADMINERDIR"/adminer.php
# Only add TLS 1.3 on Ubuntu later than 22.04
if version 22.04 "$DISTRO" 24.04.10
then
TLS13="+TLSv1.3"
fi
# Get PHP version for the conf file
check_php
cat << ADMINER_CREATE > "$ADMINER_CONF"
<VirtualHost *:80>
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1:9443 [R=301,L]
</VirtualHost>
Listen 9443
<VirtualHost *:9443>
Header add Strict-Transport-Security: "max-age=15768000;includeSubdomains"
# Intermediate configuration
SSLEngine on
SSLCompression off
SSLProtocol -all +TLSv1.2 $TLS13
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder off
SSLSessionTickets off
ServerSignature off
# Logs
LogLevel warn
CustomLog \${APACHE_LOG_DIR}/access.log combined
ErrorLog \${APACHE_LOG_DIR}/error.log
# This is needed to redirect access on http://$ADDRESS:9443/ to https://$ADDRESS:9443/
ErrorDocument 400 https://$ADDRESS:9443/
### YOUR SERVER ADDRESS ###
# ServerAdmin admin@example.com
# ServerName adminer.example.com
### SETTINGS ###
<FilesMatch "\.php$">
SetHandler "proxy:unix:/run/php/php$PHPVER-fpm.nextcloud.sock|fcgi://localhost"
</FilesMatch>
DocumentRoot $ADMINERDIR
<Directory $ADMINERDIR>
<IfModule mod_dir.c>
DirectoryIndex adminer.php
</IfModule>
AllowOverride None
# Only allow connections from localhost:
Require ip $GATEWAY/24
</Directory>
### LOCATION OF CERT FILES ###
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
ADMINER_CREATE
# Enable config
check_command a2ensite adminer.conf
if ! restart_webserver
then
msg_box "Apache2 could not restart...
The script will exit."
exit 1
else
# Allow local access:
check_command sed -i "s|local all postgres peer|local all postgres md5|g" /etc/postgresql/*/main/pg_hba.conf
restart_webserver
msg_box "Adminer was successfully installed and can be reached here:
https://$ADDRESS:9443
You can download more plugins and get more information here:
https://www.adminer.org
Your PostgreSQL connection information can be found in $NCPATH/config/config.php.
These are the current values:
$(grep dbhost $NCPATH/config/config.php)
$(grep dbuser $NCPATH/config/config.php)
$(grep dbpassword $NCPATH/config/config.php)
$(grep dbname $NCPATH/config/config.php)
In case you try to access Adminer and get 'Forbidden' you need to change the IP in:
$ADMINER_CONF"
fi