Recette de migration pour Limesurvey de 1.87 vers 2.05+

Serveur en production (ancienne)

Serveur nouveau : Installation Limesurvey2.05+

Installation des paquets :

aptitude install php5-gd php5-imap

Obtenir le backup (utiliesr addrese IP, pas utilise sondages.auf.org)

cd
# scp root@10.36.1.97:sondages.auf.tgz .
tar -zxf sondages.auf.org.tgz && rm sondages.auf.org_2015-01-28.tar.gz

Préparer les Fichiers de l'application Limesurvey:

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/1218-limesurvey205plus-build150211-tar-gz
tar -zxf 1218-limesurvey205plus-build150211-tar-gz && rm 1218-limesurvey205plus-build150211-tar-gz
## 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/

Modifier templates AUF pour éviter warning dans la migration DB :

for i in upload/templates/auf* ; do
sed -i '/<\/head>/i\{TEMPLATEJS}' $i/startpage.pstpl
done

Configuration Apache http (redirection vers 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

Configuration Apache https

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

Les certificats SSL

cd
mv _.auf.org-cert.pem GandiStandardSSLCA.pem /etc/ssl/certs/
mv _.auf.org-key.pem /etc/ssl/private/
##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

Activation modules et sites Apache:

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

Préparer la Base de données /!\ Changer aufauf pour le vrai mot de passe /!\ :

cd
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'"

Conf limesurvey depuis le navigateur web (dans mon poste du travail):

Permission fichier configuration Limesurvey:

chmod o-rwx /srv/www/sondages.auf.org/application/config/config.php

Il-y-a un bug, un nouveau utilisateur ne pourrais pas utiliser le modèle auf2014, par contre il va utiliser le modèle avec le nom default, voici le workaround: /!\ Ce procédure est une pas bonne pratique, pourrais causer problèmes dan l'avenir /!\

cd /srv/www/sondages.auf.org/templates/
mv default/ default.orig
ln -s ../upload/templates/auf2014/ default

Serveur nouveau : ID AUF pour Limesurvey2.05+

Convertir le nom des utilisateurs anciennes dans la base de données vers prenom.nom@auf.org :

mysql limesurvey -e "UPDATE lime_users SET users_name=email WHERE email LIKE '%@auf.org' AND email !='webmestre@auf.org' AND users_name !='TNSAfrique'"

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
mv patchs/login.php.patch /srv/www/sondages.auf.org/application/views/admin/authentication/
cd /srv/www/sondages.auf.org/application/views/admin/authentication/
patch login.php < login.php.patch && rm login.php.patch

Reference: contenu du fichier login.php.patch

--- login.php.orig      2014-12-29 15:25:36.000000000 -0500
+++ login.php   2015-02-06 10:55:27.556158144 -0500
@@ -2,6 +2,28 @@
     <div class='messagebox ui-corner-all'>
         <div class='header ui-widget-header'><?php echo $summary; ?></div>
         <br />
+<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="/styles/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>
+
+
+
         <ul style='width: 500px; margin-left: auto; margin-right: auto'>
             <?php
             $pluginNames = array_keys($pluginContent);

Hack du plugin webauth pour le logout:

cd
mv patchs/Authwebserver.php.patch /srv/www/sondages.auf.org/application/core/plugins/Authwebserver/
cd /srv/www/sondages.auf.org/application/core/plugins/Authwebserver/
patch Authwebserver.php < Authwebserver.php.patch && rm Authwebserver.php.patch

Reference: contenu du fichier Authwebserver.php.patch

--- Authwebserver.php.orig      2015-02-12 12:31:54.984740145 -0500
+++ Authwebserver.php   2015-02-12 12:30:42.064742670 -0500
@@ -20,7 +20,11 @@
                 'type' => 'checkbox',
                 'label' => 'Check to make default authentication method (This disable Default LimeSurvey authentification by database)',
                 'default' => true,
-                )
+         ),
+       'logout_url' => array(
+               'type' => 'string',
+               'label' => 'Remote auth logout URL (LimeSurvey will redirect to this URL after local logout)',
+       ),
     );

     public function __construct(PluginManager $manager, $id) {
@@ -31,6 +35,7 @@
          */
         $this->subscribe('beforeLogin');
         $this->subscribe('newUserSession');
+       $this->subscribe('afterLogout');
     }

     public function beforeLogin()
@@ -127,5 +132,13 @@

     }

-
+    public function afterLogout()
+    {
+       $logoutURL = $this->get('logout_url');
+        if (!empty($logoutURL))
+       {
+       header("Location: $logoutURL");
+       exit;
+       }
+    }
 }

Configuration du plugin auth web:

Pour la création automatique des utilisateurs:

cd
mv patchs/config.php.patch /srv/www/sondages.auf.org/application/config/
cd /srv/www/sondages.auf.org/application/config/
patch config.php < config.php.patch && rm config.php.patch

Reference: contenu du fichier config.php.patch

--- config.php.orig     2015-02-12 12:54:42.388692801 -0500
+++ config.php  2015-02-12 12:53:11.624695944 -0500
@@ -53,8 +53,9 @@
        // on your webspace.
        // LimeSurvey developers: Set this to 2 to additionally display STRICT PHP error messages and get full access to standard templates
                'debug'=>0,
-               'debugsql'=>0 // Set this to 1 to enanble sql logging, only active when debug = 2
-       )
+               'debugsql'=>0, // Set this to 1 to enanble sql logging, only active when debug = 2
+               'auth_webserver_autocreate_user'=>true,
+       ),
 );
 /* End of file config.php */
-/* Location: ./application/config/config.php */
\ Pas de fin de ligne à la fin du fichier
+/* Location: ./application/config/config.php */

Pour définir le profile des nouveaux utilisateurs :

cd
mv patchs/config-defaults.php.patch /srv/www/sondages.auf.org/application/config/
cd /srv/www/sondages.auf.org/application/config/
patch config-defaults.php < config-defaults.php.patch && rm config-defaults.php.patch

Reference: contenu du fichier config-defaults.php.patch

--- config-defaults.php.orig    2015-02-12 14:04:35.680547616 -0500
+++ config-defaults.php 2015-02-12 14:10:21.276535650 -0500
@@ -197,14 +197,21 @@
 // You can use any external DB in order to fill the profile for the user_name passed as the first parameter
 // A dummy example for the 'hook_get_auth_webserver_profile' function is given below:
 //
-//function hook_get_auth_webserver_profile($user_name)
-//{
-//     return Array(
-//                     'full_name' => '$user_name',
-//                     'email' => "$user_name@localdomain.org",
-//                     'lang' => 'en',
-//                     'htmleditormode' => 'inline');
-//}
+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,
+                        );
+}


 // filterxsshtml

Configuration ID AUF en utilisant https://redmine.auf.org/projects/auth/wiki/MiseEnPlaceSP

cd
mkdir ssl
cd ssl/
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

Installation du mod mellon :

apt-get install libapache2-mod-auth-mellon

Configuration Apache/mod-mellon

cd
mv patchs/sondages.auf.org-ssl.patch /etc/apache2/sites-available/
cd /etc/apache2/sites-available/
patch sondages.auf.org-ssl < sondages.auf.org-ssl.patch && rm sondages.auf.org-ssl.patch

Reference: contenu du fichier sondages.auf.org-ssl.patch

--- sondages.auf.org-ssl.orig   2015-02-12 14:43:04.516467676 -0500
+++ sondages.auf.org-ssl        2015-02-12 14:42:26.348468998 -0500
@@ -33,4 +33,32 @@
         ErrorLog /var/log/apache2/sondages.auf.org-error.log
         LogLevel warn
         CustomLog /var/log/apache2/sondages.auf.org-access.log combined
+    <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>
 </VirtualHost>

Activer le module :

a2enmod auth_mellon
service apache2 restart

Tests à faire :

Verifier le DNS:

LimeSurvey/De187Vers205 (dernière édition le 2015-02-20 21:50:26 par FredyPulido)