Commit | Line | Data |
---|---|---|
c495c100 P |
1 | <?php |
2 | ||
3 | /***************************************************************************\ | |
4 | * SPIP, Systeme de publication pour l'internet * | |
5 | * * | |
6 | * Copyright (c) 2001-2007 * | |
7 | * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * | |
8 | * * | |
9 | * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * | |
10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * | |
11 | \***************************************************************************/ | |
12 | ||
13 | if (!defined("_ECRIRE_INC_VERSION")) return; // securiser | |
14 | ||
15 | if (defined("_TEST_DIRS")) return; | |
16 | define("_TEST_DIRS", "1"); | |
17 | ||
18 | include_spip('inc/minipres'); | |
19 | include_spip('inc/lang'); | |
20 | utiliser_langue_visiteur(); | |
21 | ||
22 | // | |
23 | // Tente d'ecrire | |
24 | // | |
25 | // http://doc.spip.org/@test_ecrire | |
26 | function test_ecrire($my_dir) { | |
27 | static $chmod = 0; | |
28 | ||
29 | $ok = false; | |
30 | $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; | |
31 | $self = basename($script); | |
32 | $uid = @fileowner('.'); | |
33 | $uid2 = @fileowner($self); | |
34 | $gid = @filegroup('.'); | |
35 | $gid2 = @filegroup($self); | |
36 | $perms = @fileperms($self); | |
37 | ||
38 | // Comparer l'appartenance d'un fichier cree par PHP | |
39 | // avec celle du script et du repertoire courant | |
40 | if(!$chmod) { | |
41 | @rmdir('test'); | |
42 | @unlink('test'); // effacer au cas ou | |
43 | @touch('test'); | |
44 | if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) | |
45 | $chmod = 0700; | |
46 | else if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) | |
47 | $chmod = 0770; | |
48 | else | |
49 | $chmod = 0777; | |
50 | // Appliquer de plus les droits d'acces du script | |
51 | if ($perms > 0) { | |
52 | $perms = ($perms & 0777) | (($perms & 0444) >> 2); | |
53 | $chmod |= $perms; | |
54 | } | |
55 | @unlink('test'); | |
56 | } | |
57 | // Verifier que les valeurs sont correctes | |
58 | $f = @fopen($my_dir.'test.php', 'w'); | |
59 | if ($f) { | |
60 | @fputs($f, '<'.'?php $ok = true; ?'.'>'); | |
61 | @fclose($f); | |
62 | @chmod($my_dir.'test.php', $chmod); | |
63 | include($my_dir.'test.php'); | |
64 | } | |
65 | @unlink($my_dir.'test.php'); | |
66 | return $ok?$chmod:false; | |
67 | } | |
68 | ||
69 | // | |
70 | // tester les droits en ecriture sur les repertoires | |
71 | // rajouter celui passer dans l'url ou celui du source (a l'installation) | |
72 | // | |
73 | ||
74 | // http://doc.spip.org/@action_test_dirs_dist | |
75 | function action_test_dirs_dist() | |
76 | { | |
77 | global $test_dir, $test_dirs; | |
78 | $chmod = 0; | |
79 | ||
80 | if ($test_dir) { | |
81 | if (!ereg("/$", $test_dir)) $test_dir .= '/'; | |
82 | if (!in_array($test_dir, $test_dirs)) $test_dirs[] = $test_dir; | |
83 | } | |
84 | else { | |
85 | if (!_FILE_CONNECT) | |
86 | $test_dirs[] = dirname(_FILE_CONNECT_INS).'/'; | |
87 | } | |
88 | ||
89 | $bad_dirs = array(); | |
90 | $absent_dirs = array();; | |
91 | ||
92 | while (list(, $my_dir) = each($test_dirs)) { | |
93 | $test = test_ecrire($my_dir); | |
94 | if (!test_ecrire($my_dir)) { | |
95 | if (@file_exists($my_dir)) { | |
96 | $bad_dirs[] = "<li>".$my_dir."</li>"; | |
97 | } else | |
98 | $absent_dirs[] = "<li>".$my_dir."</li>"; | |
99 | } | |
100 | $chmod = max($chmod, $test); | |
101 | } | |
102 | ||
103 | if ($bad_dirs OR $absent_dirs) { | |
104 | ||
105 | if (!_FILE_CONNECT) { | |
106 | $titre = _T('dirs_preliminaire'); | |
107 | $continuer = ' '._T('dirs_commencer') . '.'; | |
108 | } else | |
109 | $titre = _T('dirs_probleme_droits'); | |
110 | ||
111 | ||
112 | $res = "<div align='right'>". menu_langues('var_lang_ecrire')."</div>\n"; | |
113 | ||
114 | if ($bad_dirs) { | |
115 | $res .= | |
116 | _T('dirs_repertoires_suivants', | |
117 | array('bad_dirs' => join(" ", $bad_dirs))) . | |
118 | "<b>". _T('login_recharger')."</b>."; | |
119 | } | |
120 | ||
121 | if ($absent_dirs) { | |
122 | $res .= | |
123 | _T('dirs_repertoires_absents', | |
124 | array('bad_dirs' => join(" ", $absent_dirs))) . | |
125 | "<b>". _T('login_recharger')."</b>."; | |
126 | } | |
127 | ||
128 | $res = "<p>" . $continuer . $res . aide ("install0") . "</p>" . | |
129 | "<form action='" . generer_url_action('test_dirs') . "'>" . | |
130 | "<input type='hidden' name='action' value='test_dirs' />" . | |
131 | (!$test_dir ? "" : | |
132 | "<input type='hidden' name='test_dir' value='$test_dir' />") . | |
133 | "<div align='right'><input type='submit' class='fondl' value='". | |
134 | _T('login_recharger')."' /></div>" . | |
135 | "</form>"; | |
136 | echo minipres($titre, $res); | |
137 | ||
138 | } else { | |
139 | if (!_FILE_CONNECT) | |
140 | header("Location: " . generer_url_ecrire("install", "etape=1&chmod=".$chmod, true)); | |
141 | else | |
142 | header("Location: " . _DIR_RESTREINT_ABS); | |
143 | } | |
144 | } | |
145 | ?> |