summaryrefslogtreecommitdiffstats
path: root/userSubGenerate
blob: 4e0d842a570e41b46ba151f41d7c633ad4d00f6f (plain)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/zsh
#
# Ein Skript, das fuer jede Splinenutzerin eine
# Subdomain <user>[.userpage].spline[.inf.fu-berlin].de
# anlegt.
# 2003-04-09 [stb]
# 2003-05-25 [yann] Anpassung um Logfiles und cgi-bin
# 2005-11-15 [stb] Anpassung an neues Serverlayout
# 2005-11-16 [yann] Ergaenzung ohne "userpage"
#

PHP_VER="7.4"

exec 3>&1

if [[ "$1" != "--debug" ]]
then
  exec >/dev/null
fi

SPLINEUSERS=$(ldapsearch -LLL -x -b "ou=People,dc=spline,dc=inf,dc=fu-berlin,dc=de" uid | grep "^uid" | cut -d" " -f2 | sort)
TMPFILEDNS=$(mktemp /tmp/userSubGenerate-dns.XXXXXX)
TMPFILEAPACHEVHOSTS=$(mktemp /tmp/userSubGenerate-apache-vhosts.XXXXXX)
TMPFILEAPACHEGLOBAL=$(mktemp /tmp/userSubGenerate-apache-global.XXXXXX)
TMPFILEPHP=$(mktemp /tmp/userSubGenerate-php-fpm.XXXXXX)

cat <<EOF > $TMPFILEDNS
; Diese Datei wird automatisch generiert!
; Eintragungen von Hand sind sinnlos!
;
; Siehe plonk:/usr/local/bin/userSubGenerate
;
;
; Fuer jede Nutzerin bei spline gibt es eine Subdomain
; <user>[.userpage].spline[.inf.fu-berlin].de, die dann vom
; Apache auf ~<user> aufgeloest wird.

EOF

cat <<EOF > $TMPFILEAPACHEVHOSTS
# Diese Datei wird automatisch generiert!
# Eintragungen von Hand sind sinnlos!
#
# Siehe plonk:/usr/local/bin/userSubGenerate
#
# Fuer jede Nutzerin bei spline gibt es eine Subdomain
# <user>[.userpage].spline[.inf.fu-berlin].de, die vom
# Apache auf ~<user> aufgeloest wird.

EOF

cat <<EOF > $TMPFILEAPACHEGLOBAL
# Diese Datei wird automatisch generiert!
# Eintragungen von Hand sind sinnlos!
#
# Siehe plonk:/usr/local/bin/userSubGenerate
#
#
# Für jeden User gibt es hier spezifische Einstellungen,
# die wir im vhost und im /~user/ brauchen.

DirectoryIndex index.html index.htm index.php

EOF

cat <<EOF > $TMPFILEPHP
; Diese Datei wird automatisch generiert!
; Eintragungen von Hand sind sinnlos!
;
; Siehe plonk:/usr/local/bin/userSubGenerate
;
;
; Hier wird ein php-pool fuer jeden user generiert.

EOF

echo "Generiere $TMPFILEDNS, $TMPFILEAPACHEVHOSTS, $TMPFILEAPACHEGLOBAL und $TMPFILEPHP..." >&3

for SPLINEUID in $(echo $SPLINEUSERS)
do
  echo $SPLINEUID
  FULLNAME=$(ldapsearch -LLL -x -b "dc=spline,dc=inf,dc=fu-berlin,dc=de" "(uid=$SPLINEUID)" cn | grep "^cn" | cut -d" " -f2-)


  cat <<EOF >> $TMPFILEDNS
; $SPLINEUID.userpage.spline[.inf.fu-berlin].de fuer $FULLNAME
$SPLINEUID.userpage	IN	CNAME	userpage.spline.inf.fu-berlin.de.
www.$SPLINEUID.userpage	IN	CNAME	userpage.spline.inf.fu-berlin.de.
$SPLINEUID	IN	CNAME	userpage.spline.inf.fu-berlin.de.
www.$SPLINEUID	IN	CNAME	userpage.spline.inf.fu-berlin.de.

EOF

  if [ -d /var/users/$SPLINEUID/public_html ]; then

    cat <<EOF >> $TMPFILEAPACHEGLOBAL
# php fuer $SPLINEUID ($FULLNAME)
<Proxy "unix:/run/php/php$PHP_VER-fpm-$SPLINEUID.sock|fcgi://php-fpm-$SPLINEUID">
    ProxySet disablereuse=off
</Proxy>

<Directory /home/$SPLINEUID/public_html/webroot>
    AddHandler proxy:fcgi://php-fpm-$SPLINEUID .php .php3 .php4 .php5

    AllowOverride All
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require all granted
</Directory>

<Directory /home/$SPLINEUID/public_html/cgi-bin>
    Options +ExecCGI
    Require all granted
</Directory>


EOF

    cat <<EOF >> $TMPFILEAPACHEVHOSTS
# http://$SPLINEUID.userpage.spline[.inf.fu-berlin].de fuer $FULLNAME
<VirtualHost *:80>
    ServerAlias $SPLINEUID.userpage.spline.inf.fu-berlin.de
    ServerAlias $SPLINEUID.userpage.spline.de
    ServerAlias $SPLINEUID.spline.de
    ServerAlias $SPLINEUID.spline.inf.fu-berlin.de
    ServerAlias www.$SPLINEUID.userpage.spline.inf.fu-berlin.de
    ServerAlias www.$SPLINEUID.userpage.spline.de
    ServerAlias www.$SPLINEUID.spline.de
    ServerAlias www.$SPLINEUID.spline.inf.fu-berlin.de
    ErrorLog /home/$SPLINEUID/public_html/logs/error.log
    CustomLog /home/$SPLINEUID/public_html/logs/access.log combined
    DocumentRoot /home/$SPLINEUID/public_html/webroot

    SuexecUserGroup $SPLINEUID users

    <Location "/php-status">
        SetHandler proxy:fcgi://php-fpm-$SPLINEUID
    </Location>
</VirtualHost>

<VirtualHost *:443>
    ServerAlias $SPLINEUID.userpage.spline.inf.fu-berlin.de
    ServerAlias $SPLINEUID.userpage.spline.de
    ErrorLog /home/$SPLINEUID/public_html/logs/error.log
    CustomLog /home/$SPLINEUID/public_html/logs/access.log combined
    DocumentRoot /home/$SPLINEUID/public_html/webroot

    SuexecUserGroup $SPLINEUID users

    <Location "/php-status">
        SetHandler proxy:fcgi://php-fpm-$SPLINEUID
    </Location>
</VirtualHost>

EOF

    cat <<EOF >> $TMPFILEPHP
[$SPLINEUID]
user = \$pool
group = nogroup
listen = /run/php/php$PHP_VER-fpm-\$pool.sock

listen.owner = www-data
listen.group = nogroup
listen.mode = 0600

pm = ondemand
pm.max_children = 25
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 50
pm.process_idle_timeout = 10s

pm.status_path = /php-status
catch_workers_output = yes

security.limit_extensions = .php .php3 .php4 .php5
request_terminate_timeout = 300s

EOF

  fi # -d /var/users/$SPLINEUID/public_html
done

echo "Kopiere $TMPFILEPHP nach userpage:/etc/php/$PHP_VER/fpm/pool.d/users.conf..." >&3
scp $TMPFILEPHP www-data@userpage.spline.inf.fu-berlin.de:/etc/php/$PHP_VER/fpm/pool.d/users.conf

echo "Starte den php-fpm auf userpage neu." >&3
ssh www-data@userpage.spline.inf.fu-berlin.de sudo /etc/init.d/php$PHP_VER-fpm reload

echo "Kopiere $TMPFILEAPACHEVHOSTS nach userpage:/etc/apache2/user-site.d/user-vhosts.conf ..." >&3
scp $TMPFILEAPACHEVHOSTS www-data@userpage.spline.inf.fu-berlin.de:/etc/apache2/user-site.d/user-vhosts.conf

echo "Kopiere $TMPFILEAPACHEGLOBAL nach userpage:/etc/apache2/user-site.d/globals.conf ..." >&3
scp $TMPFILEAPACHEGLOBAL www-data@userpage.spline.inf.fu-berlin.de:/etc/apache2/user-site.d/globals.conf

echo "Starte den Apache auf userpage neu." >&3
ssh www-data@userpage.spline.inf.fu-berlin.de sudo /etc/init.d/apache2 reload

echo "Kopiere $TMPFILEDNS nach beep:/etc/bind/dns-sources/common.userpage" >&3
scp $TMPFILEDNS root@vm-dnsintern.spline.inf.fu-berlin.de:/etc/bind/generated/common.userpage

echo "Erstelle die DNS-Eintraege neu" >&3
ssh root@vm-dnsintern.spline.inf.fu-berlin.de /usr/bin/make -C /root/dns/zones install || echo "Fehler beim Erstellen der neuen DNS-Eintraege." >&3

# cleanup
rm $TMPFILEPHP
rm $TMPFILEAPACHEVHOSTS
rm $TMPFILEAPACHEGLOBAL
rm $TMPFILEDNS