]>
git.p6c8.net - jirafeau.git/blob - install.php
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 define ( 'JIRAFEAU_ROOT' , dirname ( __FILE__
) . '/' );
24 define ( 'JIRAFEAU_CFG' , JIRAFEAU_ROOT
. 'lib/config.local.php' );
25 define ( 'JIRAFEAU_VAR_RAND_LENGTH' , 15 );
27 require ( JIRAFEAU_ROOT
. 'lib/config.php' );
29 function jirafeau_quoted ( $str ) {
30 return QUOTE
. str_replace ( QUOTE
, " \' " , $str ) . QUOTE
;
33 function jirafeau_export_cfg ( $cfg ) {
34 $handle = fopen ( JIRAFEAU_CFG
, 'w' );
35 fwrite ( $handle , '<?php' . NL
);
36 fwrite ( $handle , '/* ' . _ ( 'This file was generated by the install process. You can edit it. Please see config.php to understand the configuration items.' ) . ' */' . NL
);
37 foreach ( $cfg as $key => $item ) {
38 fwrite ( $handle , ' $cfg [' . jirafeau_quoted ( $key ) . '] = ' );
40 fwrite ( $handle , ( $item ?
'true' : 'false' ));
41 } else if ( is_string ( $item )) {
42 fwrite ( $handle , jirafeau_quoted ( $item ));
44 fwrite ( $handle , 'null' );
46 fwrite ( $handle , ';' . NL
);
48 fwrite ( $handle , '?>' ); // no newline at the end of the file to be able to send headers
52 function jirafeau_mkdir ( $path ) {
53 if (! file_exists ( $path )) {
54 if (! @mkdir
( $path , 0755 )) {
62 * Returns true whether the path is writable or we manage to make it
63 * so, which essentially is the same thing.
64 * @param $path is the file or directory to be tested.
65 * @return true if $path is writable.
67 function jirafeau_is_writable ( $path ) {
68 return is_writable ( $path ) || @chmod
( $path , 0777 ); // "@" gets rid of error messages.
71 function jirafeau_check_var_dir ( $path ) {
72 $mkdir_str1 = _ ( 'The following directory could not be created:' );
73 $mkdir_str2 = _ ( 'You should create this directory by hand.' );
74 $write_str1 = _ ( 'The following directory is not writable:' );
75 $write_str2 = _ ( 'You should give the write right to the web server on this directory.' );
76 $solution_str = _ ( 'Here is a solution:' );
78 if (! jirafeau_mkdir ( $path )) {
81 'why' => $mkdir_str1 . '<br /><code>' . $path . '</code><br />' . $solution_str . '<br />' . $mkdir_str2
85 if (! jirafeau_is_writable ( $path )) {
88 'why' => $write_str1 . '<br /><code>' . $path . '</code><br />' . $solution_str . '<br />' . $write_str2
92 foreach ( array ( 'files' , 'links' , 'trash' ) as $subdir ) {
93 $subpath = $path . $subdir ;
95 if (! jirafeau_mkdir ( $subpath )) {
98 'why' => $mkdir_str1 . '<br /><code>' . $subpath . '</code><br />' . $solution_str . '<br />' . $mkdir_str2
102 if (! jirafeau_is_writable ( $subpath )) {
105 'why' => $write_str1 . '<br /><code>' . $subpath . '</code><br />' . $solution_str . '<br />' . $write_str2
111 return array ( 'has_error' => false , 'why' => '' );
114 function jirafeau_add_ending_slash ( $path ) {
115 return $path . (( substr ( $path , - 1 ) == '/' ) ?
'' : '/' );
118 if (! file_exists ( JIRAFEAU_CFG
)) {
119 // we try to create an empty one
120 if (! @touch
( JIRAFEAU_CFG
)) {
121 require ( JIRAFEAU_ROOT
. 'lib/template/header.php' );
122 echo '<div class="error"><p>' . _ ( 'The local configuration file could not be created. Create a <code>lib/config.local.php</code> file and give the write right to the web server (preferred solution), or give the write right to the web server on the <code>lib</code> directory.' ) . '</p></div>' ;
123 require ( JIRAFEAU_ROOT
. 'lib/template/footer.php' );
128 if (! is_writable ( JIRAFEAU_CFG
) && ! @chmod
( JIRAFEAU_CFG
, '0666' )) {
129 require ( JIRAFEAU_ROOT
. 'lib/template/header.php' );
130 echo '<div class="error"><p>' . _ ( 'The local configuration is not writable by the web server. Give the write right to the web server on the <code>lib/config.local.php</code> file.' ) . '</p></div>' ;
131 require ( JIRAFEAU_ROOT
. 'lib/template/footer.php' );
135 if ( isset ( $_POST [ 'step' ]) && isset ( $_POST [ 'next' ])) {
136 switch ( $_POST [ 'step' ]) {
138 $cfg [ 'lang' ] = $_POST [ 'lang' ];
139 jirafeau_export_cfg ( $cfg );
143 $cfg [ 'web_root' ] = jirafeau_add_ending_slash ( $_POST [ 'web_root' ]);
144 $cfg [ 'var_root' ] = jirafeau_add_ending_slash ( $_POST [ 'var_root' ]);
145 jirafeau_export_cfg ( $cfg );
154 require ( JIRAFEAU_ROOT
. 'lib/settings.php' );
155 require ( JIRAFEAU_ROOT
. 'lib/template/header.php' );
158 if ( isset ( $_POST [ 'next' ])) {
159 $current = $_POST [ 'step' ] +
1 ;
160 } else if ( isset ( $_POST [ 'previous' ])) {
161 $current = $_POST [ 'step' ] - 1 ;
162 } else if ( isset ( $_POST [ 'retry' ])) {
163 $current = $_POST [ 'step' ];
169 < h2
>< ?php
printf ( _ ( 'Installation of Jirafeau - step %d out of %d ' ), 3 , 3 ); ?
></ h2
>
171 < form action
= "<?php echo basename(__FILE__); ?>" method
= "post" >
172 < input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION; ?>" />
173 < input type
= "hidden" name
= "step" value
= "3" />
175 < legend
>< ?php
echo _ ( 'Finalisation' ); ?
></ legend
>
178 < td
class = "info" colspan
= "2" >< ?php
echo _ ( 'Jirafeau is setting the website according to the configuration you provided.' ); ?
></ td
>
181 < td
class = "nav previous" >< input type
= "submit" name
= "previous" value
= "<?php echo _('Previous step'); ?>" /></ td
>
190 $err = jirafeau_check_var_dir ( $cfg [ 'var_root' ]);
191 if ( $err [ 'has_error' ]) {
192 echo '<div class="error"><p>' . $err [ 'why' ] . '<br />' . NL
;
194 < form action
= "<?php echo basename(__FILE__); ?>" method
= "post" >
195 < input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION; ?>" />
196 < input type
= "hidden" name
= "step" value
= "3" />
197 < input type
= "submit" name
= "retry" value
= "<?php echo _('Retry this step'); ?>" />
202 echo '<div class="message"><p>' . _ ( 'Your website is now fully operational:' ) . '<br /><a href="' . $cfg [ 'web_root' ] . '">' . $cfg [ 'web_root' ] . '</a></p></div>' ;
208 < h2
>< ?php
printf ( _ ( 'Installation of Jirafeau - step %d out of %d ' ), 2 , 3 ); ?
></ h2
>
210 < form action
= "<?php echo basename(__FILE__); ?>" method
= "post" >
211 < input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION; ?>" />
212 < input type
= "hidden" name
= "step" value
= "2" />
214 < legend
>< ?php
echo _ ( 'Information' ); ?
></ legend
>
217 < td
class = "info" colspan
= "2" >< ?php
echo _ ( 'The base address of Jirafeau is the first part of the URL, until (and including) the last slash. For example: "http://www.example.com/". Do not forget the ending slash!' ); ?
></ td
>
220 < td
class = "label" >< label
for = "input_web_root" >< ?php
echo _ ( 'Base address:' ); ?
></ label
></ td
>
221 < td
class = "field" >< input type
= "text" name
= "web_root" id
= "input_web_root" value
= "<?php
222 echo (empty( $cfg ['web_root']) ?
223 'http://' . $_SERVER ['HTTP_HOST'] . str_replace(basename(__FILE__), '', $_SERVER ['REQUEST_URI']) :
225 ?>" size
= "40" /></ td
>
228 < td
class = "info" colspan
= "2" >< ?php
echo _ ( 'The data directory is where your files and information about your files will be stored. You should put it outside your web site, or at least restrict the access of this directory. Do not forget the ending slash!' ); ?
></ td
>
231 < td
class = "label" >< label
for = "input_var_root" >< ?php
echo _ ( 'Data directory:' ); ?
></ label
></ td
>
232 < td
class = "field" >< input type
= "text" name
= "var_root" id
= "input_var_root" value
= "<?php
233 if(empty( $cfg ['var_root'])) {
234 $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
235 $len_alphanum = strlen( $alphanum );
237 for( $i = 0; $i < JIRAFEAU_VAR_RAND_LENGTH; $i ++) {
238 $var .= substr( $alphanum , mt_rand(0, $len_alphanum - 1), 1);
240 echo JIRAFEAU_ROOT . $var . '/';
242 echo $cfg ['var_root'];
244 ?>" size
= "40" /></ td
>
248 < input type
= "submit" class = "navright" name
= "next" value
= "<?php echo _('Next step'); ?>" />
249 < input type
= "submit" class = "navleft" name
= "previous" value
= "<?php echo _('Previous step'); ?>" />
263 'fr_FR.UTF-8' => 'Français'
266 < h2
>< ?php
printf ( _ ( 'Installation of Jirafeau - step %d out of %d ' ), 1 , 3 ); ?
></ h2
>
268 < form action
= "<?php echo basename(__FILE__); ?>" method
= "post" >
269 < input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION; ?>" />
270 < input type
= "hidden" name
= "step" value
= "1" />
272 < legend
>< ?php
echo _ ( 'Language' ); ?
></ legend
>
275 < td
class = "info" colspan
= "2" >< ?php
echo _ ( 'The installation of Jirafeau is internationalised, so you can have it in your own language if the translation is available.' ); ?
></ td
>
278 < td
class = "label" >< label
for = "select_lang" >< ?php
echo _ ( 'Choose your language:' ); ?
></ label
></ td
>
280 < select name
= "lang" id
= "select_lang" >
282 foreach ( $languages as $key => $item ) {
283 echo '<option value="' . $key . '"' . ( $key == $cfg [ 'lang' ] ?
' selected="selected"' : '' ) . '>' . $item . '</option>' . NL
;
291 < td
class = "nav next" >< input type
= "submit" name
= "next" value
= "<?php echo _('Next step'); ?>" /></ td
>
302 require ( JIRAFEAU_ROOT
. 'lib/template/footer.php' );
309 verify if they are present and if the are writable
patrick-canterino.de