You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
7.1 KiB

#!/usr/bin/env bash
set -eu
#set -x
DESC="Test apache2 (serveur:bigboss et client:tiny)"
HELP="
Bigboss et tiny doivent avoir été configurés par baseConfig.
ATTENTION, les fichiers suivants sont modifiés :
- /etc/apache2/apache2.conf
- /etc/apache2/sites-available/000-default.conf
Une copie est faite avec l'extension .vdn
"
repairApache2Base() {
echo "Lancement du serveur"
vdn-ssh root@bigboss "
echo 'ServerName bigboss' >> /etc/apache2/apache2.conf
systemctl enable apache2
systemctl stop apache2
systemctl start apache2
sleep 1
"
}
repairApache2Root() {
echo
echo "Modification de la racine du serveur Web"
vdn-ssh root@bigboss "
conf=/etc/apache2/sites-available/000-default.conf
[ ! -e \$conf ] && cp \$conf \${conf}.vdn
root=/home/httpd/html
[ ! -d \$root ] && mkdir -p \$root
#cat \$conf | sed -e 's|/var/www/html|'\$root'|g' \
# > /tmp/default
cat <<-EOF > \$conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /home/httpd/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog \\\${APACHE_LOG_DIR}/error.log
CustomLog \\\${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with \"a2disconf\".
#Include conf-available/serve-cgi-bin.conf
ScriptAlias \"/cgi-bin/\" \"/home/httpd/cgi-bin/\"
<Directory /home/httpd/html>
Options Indexes FollowSymLinks
AllowOverride None
Allow from all
Require all granted
</Directory>
<Directory \"/home/httpd/cgi-bin/\">
Options +ExecCGI
Require all granted
</Directory>
</VirtualHost>
EOF
#mv /tmp/default \$conf
cat <<-EOF > \$root/index.html
<html>
<body>
ok
</body>
</html>
EOF
systemctl reload apache2
sleep 1
"
vdn-ssh root@bigboss "
conf=/etc/apache2/sites-available/000-default.conf
root=/home/httpd/html/
cat \$conf | \
sed -e '/<Directory \/home\/httpd/,/<\/Directory>/d' \
> /tmp/default
cat /tmp/default | grep -v '</VirtualHost>' > \$conf
cat <<-EOF >> \$conf
<Directory \"/home/httpd/html/\">
Options Indexes FollowSymlinks Multiviews
AllowOverride None
Order allow,deny
allow from all
Require all granted
</Directory>
</VirtualHost>
EOF
sleep 1
systemctl reload apache2
sleep 1
"
}
repairApache2CGI() {
echo
echo "Création d'un script CGI"
vdn-ssh root@bigboss "
[ ! -d /home/httpd/cgi-bin ] && mkdir -p /home/httpd/cgi-bin
cat <<-EOF > /home/httpd/cgi-bin/test-cgi
#!/bin/bash
# Header
echo 'Content-type: text/html'
# Fin de l'header
echo
# Contenu à afficher dans le navigateur
echo '<html><body>'
echo 'Bonjour : nous sommes le :\`date\`'
echo '</body></html>'
EOF
chmod 755 /home/httpd/cgi-bin/test-cgi
cat /etc/apache2/sites-available/000-default.conf | \
sed -re 's,/usr/lib/cgi-bin/,/home/httpd/cgi-bin/,' \
> /tmp/defaut
mv /tmp/defaut /etc/apache2/sites-available/000-default.conf
a2enmod cgid
systemctl restart apache2
sleep 1
"
}
repairApache2Php() {
echo
echo "Création d'une page PHP"
vdn-ssh root@bigboss "
[ ! -d /home/http/html ] && mkdir -p /home/httpd/html
cat <<-EOF > /home/httpd/html/index.php
<html>
<head><title>Exemple</title></head>
<body>
Nous sommes le <?php echo date('d/m/Y'); ?>, il est <?php echo date('G:i:s'); ?>.
</body>
</html>
EOF
"
}
repairApache2Home() {
echo
echo "Page Web personnelle (userdir)"
vdn-ssh root@bigboss "
[ ! -d /home ] && { echo 'Need toto user !' >&2; exit 1; }
[ ! -d /home/toto/public_html ] && mkdir /home/toto/public_html
cat <<-EOF > /home/toto/public_html/index.html
<html><body>Page perso.</body></html>
EOF
chown -R toto: /home/toto/public_html
a2enmod userdir
systemctl restart apache2
sleep 1
"
}
repairApache2HtaccessToto() {
echo
echo "Protection de toto@bigboss:~toto/secret"
vdn-ssh root@bigboss "
[ ! -d /home/toto/public_html/secret ] && {
mkdir -p /home/toto/public_html/secret
chown -R toto: /home/toto/public_html
chmod 700 /home/toto/public_html/secret
}
cat <<-EOF > /home/toto/public_html/secret/.htaccess
AuthType Basic
AuthUserFile /home/toto/public_html/secret/users
#AuthGroupFile /dev/null
AuthName \"Accès privé\"
<limit GET>
require user titi
</limit>
EOF
echo \"<html><body>Prive</body></html>\" > \
/home/toto/public_html/secret/index.html
(
cd /home/toto/public_html/secret/
htpasswd -b -c users titi iut
)
chown -R toto: /home/toto/public_html
"
}
repairApache2Htaccess() {
echo
echo "Protection par mot de passe"
vdn-ssh root@bigboss "
[ ! -d /home/httpd/html/prive ] && mkdir /home/httpd/html/prive
cat <<-EOF > /home/httpd/html/prive/.htaccess
AuthType Basic
AuthUserFile /etc/apache2/users
#AuthGroupFile /dev/null
AuthName \"Accès privé\"
<limit GET>
require user toto
</limit>
EOF
echo \"<html><body>Prive</body></html>\" > \
/home/httpd/html/prive/index.html
(
cd /etc/apache2
htpasswd -b -c users toto iut
htpasswd -b users prof iut
)
"
vdn-ssh root@bigboss "
conf=/etc/apache2/sites-available/000-default.conf
cat \$conf | \
sed -e '/<Directory \/home\/httpd/,/<\/Directory>/d' \
> /tmp/default
cat /tmp/default | grep -v '</VirtualHost>' > \$conf
cat <<-EOF >> \$conf
<Directory \"/home/httpd/html/\">
Options Indexes FollowSymlinks Multiviews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
EOF
systemctl reload apache2
sleep 1
"
}
run() {
setErrorHandler
echoStart
requireSshGuests bigboss tiny
repairApache2Base
#repairApache2Root
#repairApache2CGI
#repairApache2Php
repairApache2Home
#repairApache2Htaccess
repairApache2HtaccessToto
unsetErrorHandler
}