Serveur en production (ancienne)

Serveur nouveau

#####################################################################################
## Migration du limesurvey de 1.87 vers 2.05+
#####################################################################################

aptitude install php5-gd php5-imap

## obtenir le backup (utiliesr addrese IP, pas utilise sondages.auf.org)
cd
## //ATENTION: adresse IP:
# scp root@10.36.1.97:sondages.auf.org_2015-01-28.tar.gz .   
## //ATENTION: adresse nom fichier tgz:
tar -zxf sondages.auf.org_2015-01-28.tar.gz && rm sondages.auf.org_2015-01-28.tar.gz
## rm apache.conf   //enlever

mysql -e "create database limesurvey"
mysql limesurvey < sondages_auf_org.mysql && rm sondages_auf_org.mysql
mysql -e "grant all privileges on limesurvey.* to 'limesurvey'@'localhost' identified by 'aufauf'"

mkdir -p /srv/www/
mv sondages.auf.org /srv/www/sondages.auf.org.old
cd /srv/www/
wget https://www.limesurvey.org/en/stable-release/finish/25-latest-stable-release/1213-limesurvey205plus-build141229-tar-gz
tar -zxf 1213-limesurvey205plus-build141229-tar-gz && rm 1213-limesurvey205plus-build141229-tar-gz
mv limesurvey/ sondages.auf.org
cp -a sondages.auf.org.old/templates/auf* sondages.auf.org/upload/templates/
cp -a sondages.auf.org.old/upload/* sondages.auf.org/upload/
rm -fr sondages.auf.org.old

chown -hR root: sondages.auf.org
cd sondages.auf.org
chgrp -hR www-data tmp/ upload/ application/config/
chmod -R g+w  tmp/ upload/ application/config/

## "update" des templates pour "utilisrer" TEMPLATEJS (eviter warning dans la migration DB)
for i in upload/templates/auf* ; do
sed -i '/<\/head>/i\{TEMPLATEJS}' $i/startpage.pstpl
done


#################################################
## Conf d'apache, (redirect to https)
#################################################
cat <<EOT>> /etc/apache2/sites-available/sondages.auf.org
<VirtualHost *:80>
             ServerName sondages.auf.org
        ServerAdmin technique@ca.auf.org
        Redirect permanent / https://sondages.auf.org/
</VirtualHost>
EOT

#################################################
## Conf d'apache, (redirect to https)
#################################################
scp root@10.36.1.97:/etc/ssl/certs/_.auf.org-cert.pem /etc/ssl/certs/_.auf.org-cert.pem
scp root@10.36.1.97:/etc/ssl/private/_.auf.org-key.pem /etc/ssl/private/_.auf.org-key.pem
scp root@10.36.1.97:/etc/ssl/certs/GandiStandardSSLCA.pem /etc/ssl/certs/GandiStandardSSLCA.pem

cat <<EOT>> /etc/apache2/sites-available/sondages.auf.org-ssl
<VirtualHost *:443>
        ServerName sondages.auf.org
        ServerAdmin technique@ca.auf.org

        SSLEngine on
        SSLCertificateFile    /etc/ssl/certs/_.auf.org-cert.pem
        SSLCertificateKeyFile /etc/ssl/private/_.auf.org-key.pem
        SSLCACertificateFile  /etc/ssl/certs/GandiStandardSSLCA.pem
        SSLVerifyClient None

        DocumentRoot /srv/www/sondages.auf.org
        <Directory /srv/www/sondages.auf.org>
                Options FollowSymLinks MultiViews
                AllowOverride All
                Order Allow,Deny
                Allow From All

                AddDefaultCharset utf-8
                php_value default_charset utf-8

                RewriteEngine On
                ## DONT TOUCH ANYTHING ##
                # Only with survey code : http://server.fr/123456
                RewriteRule ^([0-9]+)/*$ index.php?sid=$1 [L,QSA]
                # Survey code + Lang + Token : http://server.fr/123456/lang-fr/tk-sdlfkjozeiru
                RewriteRule ^([0-9]+)/lang-([^/]*)/*$ index.php?sid=$1&lang=$2 [L,QSA]
                # Survey code + Token : http://server.fr/123456/tk-sdlfkjozeiru
                RewriteRule ^([0-9]+)/lang-([^/]*)/tk-([^/]*)/*$ index.php?sid=$1&lang=$2&token=$3 [L,QSA]
                # Survey code + Token : http://server.fr/123456/tk-sdlfkjozeiru
                RewriteRule ^([0-9]+)/tk-([^/]*)/*$ index.php?sid=$1&token=$2 [L,QSA]
        </Directory>

        ErrorLog /var/log/apache2/sondages.auf.org-error.log
        LogLevel warn
        CustomLog /var/log/apache2/sondages.auf.org-access.log combined
</VirtualHost>
EOT

a2enmod rewrite ssl
a2ensite sondages.auf.org sondages.auf.org-ssl
service apache2 restart

## Conf limesurvey depuis le navigateur web:
## Verifier /etc/hosts dans mon poste du travail
## sudo nscd -i hosts
# http://sondages.auf.org/admin
# Welcome: Français, start installation
# Paramètres de la base de données
# * Utilisateur de la base de données: limesurvey
# * Mot de passe de la base de données: aufauf   /!\ Utiliser le vrait!
# * Nom de la base de données: limesurvey

## Il faut l'ajouter après la conf initial
chmod o-rwx application/config/config.php

#####################################################################################
## Conf limesurvey pour supporter ID
#####################################################################################

## changement du nom utilisateurs vers @auf.org pour ceux dans la DB:
mysql> UPDATE lime_users SET users_name=email WHERE email LIKE '%@auf.org' AND email !='webmestre@auf.org' AND email !='frantz.fongang@auf.org';
## ATENION les comptes: TNSAfrique, TNSavoirs + informer tous les utilisateurs!

#####################################################################################
## Hack du plugin pour le logout:
#####################################################################################
## Alternative scp:
# scp root@10.36.1.88:/srv/www/sondages.auf.org/application/core/plugins/Authwebserver/Authwebserver.php

# diff /srv/www/sondages.auf.org/application/core/plugins/Authwebserver/Authwebserver.php Authwebserver.php
23,27c23
<          ),
<          'logout_url' => array(
<                       'type' => 'string',
<                              'label' => 'Remote auth logout URL (LimeSurvey will redirect to this URL after local logout)',
<                              ),
---
>                 )
38d33
<       $this->subscribe('afterLogout');
135,143c130
<     public function afterLogout()
<     {
<     $logoutURL = $this->get('logout_url');
<         if (!empty($logoutURL))
<         {
<         header("Location: $logoutURL");
<         exit;
<         }
<     }
---
>

#####################################################################################
## Hack Bouton login ID AUF
#####################################################################################
cd /srv/www/sondages.auf.org/styles
wget https://nuage.auf.org/themes/auf/core/img/idauf_bouton.png
wget https://nuage.auf.org/themes/auf/core/img/idauf_bouton_survol.png
cd /srv/www/sondages.auf.org/application/views/admin/authentication
## Optional au diff:
# scp root@10.36.1.97:/srv/www/sondages.auf.org/application/views/admin/authentication/login.php .
diff login.php*
5,26d4
< <form id="id_auf">
<
< <p style="display: inline-block;
<     margin-right: 20px;
<     vertical-align: middle;
<     text-align: right"> <strong>Usagers de l'AUF&nbsp;:</strong>
< </p>
<
< <p style="display: inline-block;
<     vertical-align: middle;
<     text-align: right">
<
< <a href="https://sondages.auf.org/mellon/login?ReturnTo=/admin/" onmouseover="document.idauf_bouton.src='/styles/idauf_bouton_survol.png';" onmouseout="document.idauf_bouton.src='/styles/idauf_bouton.png';"><img id="idauf_bouton" src="/s\
tyles/idauf_bouton.png" height="32" width="200"></a>
<
< </p>
< </form>
<
<
< <p align="left"><strong>Pour les usagers qui n'ont pas d'adresse @auf.org,</strong><br>utilisez le formulaire de connexion suivant&nbsp;:</p>
<
<

## Plugin auth web  https://sondages.auf.org/index.php/plugins
# Webserver [active]
## Conf du plugin:
# Strip domain part ... []
# Key to use for username ... [REMOTE_USER]
# Check to make default authentication method ... []
# Logout url: https://sondages.auf.org/mellon/logout?ReturnTo=https://sondages.auf.org/index.php/admin/authentication/sa/logout/

## /srv/www/sondages.auf.org/application/config/config.php
                'debugsql'=>0, // Set this to 1 to enanble sql logging, only active when debug = 2
                'auth_webserver_autocreate_user'=>true,
        ),

## /srv/www/sondages.auf.org/application/config/config-defaults.php
function hook_get_auth_webserver_profile($user_name)
{
      return Array(
                        'full_name' => getenv("MELLON_gn")." ".getenv("MELLON_sn"),
                        'email' => getenv("MELLON_mail"),
                        'lang' => 'fr',
                        'create_survey' => 1,
                        'create_user' => 0,
                        'delete_user' => 0,
                        'superadmin' => 0,
                        'configurator' =>0,
                        'manage_template' => 0,
                        'manage_label' => 0,
                        );
}

#####################################################################################
## Conf ID (doc reference): https://redmine.auf.org/projects/auth/wiki/MiseEnPlaceSP
#####################################################################################
cd
openssl req -new -x509 -keyout key.pem -out cert.pem -nodes -days 3650 -newkey rsa:2048 -subj "/CN=sondages.auf.org"
chmod 0600 key.pem
chmod 0644 cert.pem
chown root:root key.pem cert.pem
mv key.pem /etc/ssl/private/saml-sondages.auf.org-key.pem
mv cert.pem /etc/ssl/certs/saml-sondages.auf.org-cert.pem
wget --no-check-certificate https://id.auf.org/idp/saml2/metadata -O- | tee -a /etc/ssl/saml-id.auf.org-metadata.xml

##### pour le test copier depuis la machine du test:
# rm /etc/ssl/private/saml-sondages.auf.org-key.pem
# rm /etc/ssl/certs/saml-sondages.auf.org-cert.pem
# rm /etc/ssl/saml-id.auf.org-metadata.xml
# scp root@10.36.1.97:/etc/ssl/private/saml-sondages.auf.org-key.pem /etc/ssl/private/saml-sondages.auf.org-key.pem
# scp root@10.36.1.97:/etc/ssl/certs/saml-sondages.auf.org-cert.pem /etc/ssl/certs/saml-sondages.auf.org-cert.pem
# scp root@10.36.1.97:/etc/ssl/saml-id.auf.org-metadata.xml /etc/ssl/saml-id.auf.org-metadata.xml

apt-get install libapache2-mod-auth-mellon

#########ConfApache (ajouter dessus </VirtualHost>) /etc/apache2/sites-available/sondages.auf.org-ssl
    <Location />
        AuthType "Mellon"
        # si on veut imposer l'authentification avant d'accéder au site (100% privé)
        #MellonEnable "auth"
        # si on veut laisser le site web déclencher l'authentification (public + privé)
        MellonEnable "info"

        # les méta-données
                MellonDefaultLoginPath "/"
        MellonOrganizationName "sondages.auf.org"
        MellonOrganizationDisplayName "fr" "Sondages AUF"
        MellonOrganizationURL "http://www.auf.org"
        MellonSPPrivateKeyFile /etc/ssl/private/saml-sondages.auf.org-key.pem
        MellonSPCertFile /etc/ssl/certs/saml-sondages.auf.org-cert.pem
        MellonIdPMetadataFile /etc/ssl/saml-id.auf.org-metadata.xml

        # les conditions d'accès
        MellonUser "mail"
        MellonCond "mail" "^[^@]*@auf\.org$" [REG]
        #MellonCond "mail" "jean-christophe.andre@auf.org" [OR]
        #MellonCond "mail" "moussa.nombre@auf.org"
        #MellonCond "eduPersonAffiliation" "employee"
    </Location>

    <Location /mellon/>
        AuthType "Mellon"
        MellonEnable "info"
    </Location>
########End ConfApache

a2enmod auth_mellon
service apache2 restart

## Login et logout SAML
### alternative:
## scp root@10.36.1.97: /srv/www/sondages.auf.org/application/views/admin/authentication/login.php /tmp/login.php
## cp -a /srv/www/sondages.auf.org/application/views/admin/authentication/login.php /srv/www/sondages.auf.org/application/views/admin/authentication/login.php.orig
## cat /tmp/login.php > /srv/www/sondages.auf.org/application/views/admin/authentication/login.php
# /srv/www/sondages.auf.org/application/views/admin/authentication/login.php
diff /srv/www/sondages.auf.org/application/views/admin/authentication/login.php*
5,26d4
< <form id="id_auf">
<
< <p style="display: inline-block;
<     margin-right: 20px;
<     vertical-align: middle;
<     text-align: right"> <strong>Usagers de l'AUF&nbsp;:</strong>
< </p>
<
< <p style="display: inline-block;
<     vertical-align: middle;
<     text-align: right">
<
< <a href="https://sondages.auf.org/mellon/login?ReturnTo=/admin/" onmouseover="document.idauf_bouton.src='/styles/idauf_bouton_survol.png';" onmouseout="document.idauf_bouton.src='/styles/idauf_bouton.png';"><img id="idauf_bouton" src="/s\
tyles/idauf_bouton.png" height="32" width="200"></a>
<
< </p>
< </form>
<
<
< <p align="left"><strong>Pour les usagers qui n'ont pas d'adresse @auf.org,</strong><br>utilisez le formulaire de connexion suivant&nbsp;:</p>
<
<
<

## Tests:
* Login standard user
* login ID
* Creation du sondage avec utilisateur ID
 * Verifier s'il est possible de choisir le template
 * Verifier le template2014

## penser en theme avec le nom "default"
## bug: le vrait default c'et celui avec le nom default, pas celui choisi dans la configuration.