Subversion Repositories Applications.papyrus

Rev

Rev 91 | Rev 100 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
68 jpm 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | Copyright (c) 2002, Hendrik Mans <hendrik@mans.de>                                                   |
9
// | Copyright 2002, 2003 David DELON                                                                     |
10
// | Copyright 2002 Patrick PAUL                                                                          |
11
// | Copyright  2003  Jean-Pascal MILCENT                                                                 |
12
// | All rights reserved.                                                                                 |
13
// | Redistribution and use in source and binary forms, with or without                                   |
14
// | modification, are permitted provided that the following conditions                                   |
15
// | are met:                                                                                             |
16
// | 1. Redistributions of source code must retain the above copyright                                    |
17
// | notice, this list of conditions and the following disclaimer.                                        |
18
// | 2. Redistributions in binary form must reproduce the above copyright                                 |
19
// | notice, this list of conditions and the following disclaimer in the                                  |
20
// | documentation and/or other materials provided with the distribution.                                 |
21
// | 3. The name of the author may not be used to endorse or promote products                             |
22
// | derived from this software without specific prior written permission.                                |
23
// |                                                                                                      |
24
// | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR                                 |
25
// | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES                            |
26
// | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.                              |
27
// | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,                                     |
28
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT                             |
29
// | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,                            |
30
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY                                |
31
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT                                  |
32
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF                             |
33
// | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                    |
34
// +------------------------------------------------------------------------------------------------------+
97 jpm 35
// CVS : $Id: instal_fichier.inc.php,v 1.6 2004-10-22 17:39:14 jpm Exp $
68 jpm 36
/**
69 jpm 37
* Page de création des fichiers nécessaire à l'installation de Papyrus.
68 jpm 38
*
39
* Page permettant de créer le fichier de configuration de Papyrus.
40
*
41
*@package Installateur
42
//Auteur original :
43
*@author        Hendrik MANS <hendrik@mans.de>
44
//Autres auteurs :
45
*@author        David DELON
46
*@author        Patrick PAUL
47
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
48
*@copyright     Tela-Botanica 2000-2004
97 jpm 49
*@version       $Revision: 1.6 $ $Date: 2004-10-22 17:39:14 $
68 jpm 50
// +------------------------------------------------------------------------------------------------------+
51
**/
52
 
53
// +------------------------------------------------------------------------------------------------------+
54
// |                                            ENTÊTE du PROGRAMME                                       |
55
// +------------------------------------------------------------------------------------------------------+
91 jpm 56
// Numéro de l'étape d'installation :
57
$num_etape = 3;
58
 
59
// Initialisation du tableau contenant les valeurs de configuration de la base de données
60
$tableau = array(   'PAP_FTP_SERVEUR' => '', 'PAP_FTP_PORT' => '', 'PAP_FTP_UTILISATEUR' => '',
61
                    'PAP_FTP_MOT_DE_PASSE' => '', 'PAP_FTP_RACINE' => '');
62
foreach ($tableau as $cle => $val) {
63
    if (!empty($_POST['fichier'][$cle])) {
64
        $fichier[$cle] = $_POST['fichier'][$cle];
65
    } else if (defined($cle)) {
66
        $fichier[$cle] = constant($cle);
67
    } else {
68
        $fichier[$cle] = '';
69
    }
70
}
71
 
68 jpm 72
// Récupération des paramêtres de configuration du formulaire précédent
91 jpm 73
if (isset($_POST['pref_serial'])) {
74
    $pref = unserialize(stripslashes($_POST['pref_serial']));
68 jpm 75
}
91 jpm 76
if (isset($_POST['bdd'])) {
77
    $bdd = $_POST['bdd'];
78
} else if (isset($_POST['bdd_serial'])) {
79
    $bdd = unserialize(stripslashes($_POST['bdd_serial']));
80
}
76 jpm 81
 
68 jpm 82
// +------------------------------------------------------------------------------------------------------+
83
// |                                          CORPS du PROGRAMME                                          |
84
// +------------------------------------------------------------------------------------------------------+
91 jpm 85
// Affichage d'informations...
86
$sortie .= '<p><strong>Etape n°'.$num_etape.' sur '.INSTAL_NBRE_ETAPE.'.</strong></p>'."\n";
87
 
88
// Correction éventuelle des informations saisies par l'utilisateur
97 jpm 89
if (preg_match('/^(?:\/|\\)(.*)$/', $fichier['PAP_FTP_RACINE']) == 1) {
91 jpm 90
    // le chemin FTP ne doit pas commencer par un slash, nous le supprimons
97 jpm 91
    $fichier['PAP_FTP_RACINE'] = GEN_SEP.$fichier['PAP_FTP_RACINE'];
68 jpm 92
}
93
 
91 jpm 94
// Nous vérifions si nous sommes en phase de test du formulaire de config de l'écriture de fichier
95
$erreur = 0;
96
$sortie_verif = '';
97
if ($_GET['installation'] == 'verif_fichier') {
98
    // Test de la configuration du FTP
99
    $sortie_verif .= '    <h2>Test de la connexion FTP</h2>'."\n";
100
    $erreur = testerConfig($sortie_verif, 'Test connexion FTP ...', $ftp = @ftp_connect($fichier['PAP_FTP_SERVEUR'], $fichier['PAP_FTP_PORT']), '', 1, $erreur);
101
    $erreur = testerConfig($sortie_verif, 'Test identification sur le serveur FTP ...', @ftp_login($ftp, $fichier['PAP_FTP_UTILISATEUR'],
102
                            $fichier['PAP_FTP_MOT_DE_PASSE']), 'Les paramêtres FTP saisies ne permettent pas l\'identification !', 1, $erreur);
103
    $sortie_verif .= '<br />'."\n";
104
 
105
    $configCode = "<?php\n// pap_config.inc.php construit le ".strftime("%c")."\n// ne changez pas la version de Papyrus manuellement!\n\n";
106
    $entries[] = 'define(\''.INSTAL_VERSION_NOUVELLE_NOM.'\',\''.INSTAL_VERSION_NOUVELLE.'\');'."\n";
107
    foreach ($bdd as $cle => $val) {
108
        $entries[] = 'define(\''.$cle.'\',\''.$val.'\');'."\n";
109
    }
110
    $entries[] = "define('PAP_DSN', 'mysql://'.PAP_BDD_UTILISATEUR.':'.PAP_BDD_MOT_DE_PASSE.'@'.PAP_BDD_SERVEUR.'/'.PAP_BDD_NOM);"."\n";
111
    foreach ($fichier as $cle => $val) {
112
        $entries[] = 'define(\''.$cle.'\',\''.$val.'\');'."\n";
113
    }
114
    foreach ($pref as $cle => $val) {
115
        // Nous récupérons uniquement les constantes à stocker dans le fichier de config (leur nom commence par PAP_)
116
        if (preg_match('/^PAP_/', $cle)) {
117
            $entries[] = 'define(\''.$cle.'\',\''.$val.'\');'."\n";
118
        }
119
    }
120
    $configCode .= implode("\n", $entries)."\n\n?>";
121
 
122
    // Tentative d'écriture du fichier de config
123
    $sortie_verif .= '    <h2>Ecriture des fichiers sur le serveur par FTP</h2>'."\n";
97 jpm 124
    $chemin_fpt_absolu = $fichier['PAP_FTP_RACINE'].INSTAL_CHEMIN_CONFIG;
91 jpm 125
    $url_ftp =  'ftp://'.$fichier['PAP_FTP_UTILISATEUR'].':'.$fichier['PAP_FTP_MOT_DE_PASSE'].
126
                '@'.$fichier['PAP_FTP_SERVEUR'].$chemin_fpt_absolu;
127
    $fp = @fopen($url_ftp, 'w');
128
    $txt_ecriture_conf = '&Eacute;criture sur le serveur de <tt>'.$chemin_fpt_absolu.'</tt>...';
129
    $txt_ecriture_conf_erreur = '<p><span class="failed">AVERTISSEMENT:</span> Le fichier de configuration <tt>'.$chemin_fpt_absolu.
68 jpm 130
                '</tt> n\'a pu &ecirc;tre cr&eacute;&eacute;. Veuillez vous assurez que votre serveur a les droits '.
131
                'd\'acc&egrave;s en &eacute;criture pour ce fichier. Si pour une raison quelconque vous ne pouvez pas '.
132
                'faire &ccedil;a vous devez copier les informations suivantes dans un fichier et les transf&eacute;rer '.
133
                'au moyen d\'un logiciel de transfert de fichier (ftp) sur le serveur dans un fichier '.
91 jpm 134
                '<tt>pap_config.inc.php</tt> directement dans le r&eacute;pertoire <tt>configuration</tt> du répertoire '.
68 jpm 135
                '<tt>papyrus</tt> de Papyrus. Une fois que vous aurez fait cela, votre site Papyrus devrait fonctionner '.
91 jpm 136
                'correctement.</p>';
137
    $txt_ecriture_conf_erreur .= '<div id="fichier_config">'."\n";
138
    $txt_ecriture_conf_erreur .= '<xmp>'.$configCode.'</xmp>'."\n";
139
    $txt_ecriture_conf_erreur .= '</div>'."\n";
140
    $erreur = testerConfig($sortie_verif, $txt_ecriture_conf, $fp, $txt_ecriture_conf_erreur, 1, $erreur);
68 jpm 141
}
142
 
91 jpm 143
// Gestion de l'affichage
144
if ($erreur == 0 && empty($sortie_verif)) {
145
    // Premier appel du fichier...
146
    $sortie .= creerFormulaire($fichier);
147
    $sortie .= '<li><input type="hidden" name="pref_serial" value="'.htmlentities(serialize($pref)).'" /></li>'."\n";
148
    $sortie .= '<li><input type="hidden" name="bdd_serial" value="'.htmlentities(serialize($bdd)).'" /></li>'."\n";
149
    $sortie .= '<li><input type="submit" value="Tester" /></li>'."\n";
150
    $sortie .= '      </ul>'."\n";
151
    $sortie .= '    </form>';
152
} else if ($erreur == 2 && !empty($sortie_verif)) {
153
    // Vérification du fichier avec interuption...
154
    $sortie .= creerFormulaire($fichier);
155
    $sortie .= '<li><input type="hidden" name="pref_serial" value="'.htmlentities(serialize($pref)).'" /></li>'."\n";
156
    $sortie .= '<li><input type="hidden" name="bdd_serial" value="'.htmlentities(serialize($bdd)).'" /></li>'."\n";
157
    $sortie .= '<li><input type="submit" value="Tester à nouveau" /></li>'."\n";
158
    $sortie .= '      </ul>'."\n";
159
    $sortie .= '    </form>';
160
    $sortie .= $sortie_verif;
161
} else if (($erreur == 0 || $erreur == 1) && !empty($sortie_verif)) {
162
    // Vérification du fichier sans interuption... passage à l'étape suivante
163
    $sortie .= creerFormulaire($fichier, true);
164
    $sortie .= '      </ul>'."\n";
165
    $sortie .= '    </form>';
166
    $sortie .= $sortie_verif;
167
    // Ecriture du fichier...
168
    fwrite($fp, $configCode);
169
    fclose($fp);
170
    $sortie .= '    <p>Voila c\'est termin&eacute; ! Vous pouvez <a href="'.donnerUrlCourante().'">retourner sur votre site '.
171
                'Papyrus</a>. Il est conseill&eacute; de retirer l\'acc&egrave;s en &eacute;criture au fichier '.
172
                '<tt>pap_config.inc.php</tt>. Ceci peut &ecirc;tre une faille dans la s&eacute;curit&eacute;.</p>'."\n";
173
}
174
 
68 jpm 175
// +------------------------------------------------------------------------------------------------------+
91 jpm 176
// |                                            LISTE DES FONCTIONS                                       |
177
// +------------------------------------------------------------------------------------------------------+
178
 
179
// Création du formulaire de configuration de la base de donneés
180
function creerFormulaire($fichier, $bln_lecture = false) {
181
    $disabled = '';
182
    if ($bln_lecture) {
183
        $disabled = ' disabled="disabled" ';
184
    }
185
    $sortie_form .= '    <form action="'.donnerUrlCourante().'?installation=verif_fichier" method="post">';
186
    $sortie_form .= '      <ul>'."\n";
187
    $sortie_form .=  '<li><h2>Configuration du FTP et des chemins d\'accès</h2></li>'."\n";
188
    $sortie_form .=  '<li>'."\n".
189
                '<label for="ftp_serveur">Nom du serveur FTP :</label>'.
190
                '<input id="ftp_serveur"'.$disabled.'type="text" size="30" name="fichier[PAP_FTP_SERVEUR]" value="'.$fichier['PAP_FTP_SERVEUR'].'" />'.
191
                '</li>'."\n";
192
    $sortie_form .=  '<li>'."\n".
193
                '<label for="ftp_port">N° du port d\'accès au serveur FTP :</label>'.
194
                '<input id="ftp_port"'.$disabled.'type="text" size="20" name="fichier[PAP_FTP_PORT]" value="'.$fichier['PAP_FTP_PORT'].'" />'.
195
                '</li>'."\n";
196
    $sortie_form .=  '<li>'."\n".
197
                '<label for="ftp_utilisateur">Nom d\'utilisateur pour le serveur FTP :</label>'.
198
                '<input id="ftp_utilisateur"'.$disabled.'type="text" size="20" name="fichier[PAP_FTP_UTILISATEUR]" value="'.$fichier['PAP_FTP_UTILISATEUR'].'" />'.
199
                '</li>'."\n";
200
    $sortie_form .=  '<li>'."\n".
201
                '<label for="ftp_mot_de_passe">Mot de passe de l\'utilisateur pour le serveur FTP :</label>'.
202
                '<input id="ftp_mot_de_passe"'.$disabled.'type="password" size="20" name="fichier[PAP_FTP_MOT_DE_PASSE]" value="'.$fichier['PAP_FTP_MOT_DE_PASSE'].'" />'.
203
                '</li>'."\n";
204
    $sortie_form .=  '<li>Lorsque vous vous connecter par FTP sur le serveur où vous avez déposé les fichiers de Papyrus, le '.
205
                'dossier le plus haut auquel vous pouvez accéder dans l\'arborescence est la racine. Il vous faut donc '.
206
                'indiquez dans le champ ci-dessous le chemin depuis cette racine jusqu\'au dossier contenant le fichier '.
207
                '<tt>papyrus.php</tt>. Exemple : <i>www/</i><br /> Notes : Le chemin doit commmencer directement par le nom'.
208
                ' du premier dossier et se terminer par un slash (/) ou un anti-slash (\\) suivant le système d\''.
209
                'exploitation de votre serveur.</li>'."\n";
210
    $sortie_form .=  '<li>'."\n".
211
                '<label for="ftp_racine">Racine dépôt FTP :</label>'.
212
                '<input id="ftp_racine"'.$disabled.'type="text" size="60" name="fichier[PAP_FTP_RACINE]" value="'.$fichier['PAP_FTP_RACINE'].'" />'.
213
                '</li>'."\n";
214
    return $sortie_form;
215
}
216
 
217
// +------------------------------------------------------------------------------------------------------+
68 jpm 218
// |                                            PIED du PROGRAMME                                         |
219
// +------------------------------------------------------------------------------------------------------+
220
 
221
 
222
/* +--Fin du code ----------------------------------------------------------------------------------------+
223
*
224
* $Log: not supported by cvs2svn $
97 jpm 225
* Revision 1.5  2004/10/22 17:23:04  jpm
226
* Simplification del'installation de Papyrus.
227
*
91 jpm 228
* Revision 1.4  2004/10/19 17:01:12  jpm
229
* Correction bogues.
230
*
80 jpm 231
* Revision 1.3  2004/10/19 15:59:18  jpm
232
* Ajout de la gestion des valeurs propre à Papyrus à insérer dans la base de données.
233
* Ajout des constantes FTP.
234
*
76 jpm 235
* Revision 1.2  2004/10/18 09:12:09  jpm
236
* Changement de nom d'un fichier.
237
*
69 jpm 238
* Revision 1.1  2004/10/18 09:11:05  jpm
239
* Changement de nom du fichier.
240
*
68 jpm 241
* Revision 1.1  2004/10/15 18:28:59  jpm
242
* Début appli installateur de Papyrus.
243
*
244
*
245
* +-- Fin du code ----------------------------------------------------------------------------------------+
246
*/
247
?>