mirror of
https://github.com/YunoHost-Apps/spip_ynh.git
synced 2024-09-03 20:25:59 +02:00
146 lines
4.1 KiB
PHP
146 lines
4.1 KiB
PHP
|
<?php
|
||
|
|
||
|
/***************************************************************************\
|
||
|
* SPIP, Systeme de publication pour l'internet *
|
||
|
* *
|
||
|
* Copyright (c) 2001-2014 *
|
||
|
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
|
||
|
* *
|
||
|
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
|
||
|
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
|
||
|
\***************************************************************************/
|
||
|
|
||
|
if (!defined('_ECRIRE_INC_VERSION')) return;
|
||
|
|
||
|
if (defined('_TEST_DIRS')) return;
|
||
|
define('_TEST_DIRS', "1");
|
||
|
|
||
|
include_spip('inc/minipres');
|
||
|
utiliser_langue_visiteur();
|
||
|
|
||
|
//
|
||
|
// Tente d'ecrire
|
||
|
//
|
||
|
// http://doc.spip.org/@test_ecrire
|
||
|
function test_ecrire($my_dir) {
|
||
|
static $chmod = 0;
|
||
|
|
||
|
$ok = false;
|
||
|
$script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF'];
|
||
|
$self = basename($script);
|
||
|
$uid = @fileowner('.');
|
||
|
$uid2 = @fileowner($self);
|
||
|
$gid = @filegroup('.');
|
||
|
$gid2 = @filegroup($self);
|
||
|
$perms = @fileperms($self);
|
||
|
|
||
|
// Comparer l'appartenance d'un fichier cree par PHP
|
||
|
// avec celle du script et du repertoire courant
|
||
|
if(!$chmod) {
|
||
|
@rmdir('test');
|
||
|
spip_unlink('test'); // effacer au cas ou
|
||
|
@touch('test');
|
||
|
if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid)
|
||
|
$chmod = 0700;
|
||
|
else if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid)
|
||
|
$chmod = 0770;
|
||
|
else
|
||
|
$chmod = 0777;
|
||
|
// Appliquer de plus les droits d'acces du script
|
||
|
if ($perms > 0) {
|
||
|
$perms = ($perms & 0777) | (($perms & 0444) >> 2);
|
||
|
$chmod |= $perms;
|
||
|
}
|
||
|
spip_unlink('test');
|
||
|
}
|
||
|
// Verifier que les valeurs sont correctes
|
||
|
$f = @fopen($my_dir.'test.php', 'w');
|
||
|
if ($f) {
|
||
|
@fputs($f, '<'.'?php $ok = true; ?'.'>');
|
||
|
@fclose($f);
|
||
|
@chmod($my_dir.'test.php', $chmod);
|
||
|
include($my_dir.'test.php');
|
||
|
}
|
||
|
spip_unlink($my_dir.'test.php');
|
||
|
return $ok?$chmod:false;
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// tester les droits en ecriture sur les repertoires
|
||
|
// rajouter celui passe dans l'url ou celui du source (a l'installation)
|
||
|
//
|
||
|
|
||
|
// http://doc.spip.org/@install_etape_chmod_dist
|
||
|
function install_etape_chmod_dist()
|
||
|
{
|
||
|
global $test_dirs;
|
||
|
$test_dir = _request('test_dir');
|
||
|
$chmod = 0;
|
||
|
|
||
|
if ($test_dir) {
|
||
|
if (substr($test_dir,-1)!=='/') $test_dir .= '/';
|
||
|
if (!in_array($test_dir, $test_dirs)) $test_dirs[] = _DIR_RACINE . $test_dir;
|
||
|
} else {
|
||
|
if (!_FILE_CONNECT) {
|
||
|
$test_dirs[] = _DIR_CONNECT;
|
||
|
$test_dirs[] = _DIR_CHMOD;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$bad_dirs = array();
|
||
|
$absent_dirs = array();;
|
||
|
|
||
|
while (list(, $my_dir) = each($test_dirs)) {
|
||
|
$test = test_ecrire($my_dir);
|
||
|
if (!$test) {
|
||
|
$m = preg_replace(',^' . _DIR_RACINE . ',', '',$my_dir);
|
||
|
if (@file_exists($my_dir)) {
|
||
|
$bad_dirs["<li>".$m."</li>"] = 1;
|
||
|
} else
|
||
|
$absent_dirs["<li>".$m."</li>"] = 1;
|
||
|
} else $chmod = max($chmod, $test);
|
||
|
}
|
||
|
|
||
|
if ($bad_dirs OR $absent_dirs) {
|
||
|
|
||
|
if (!_FILE_CONNECT) {
|
||
|
$titre = _T('dirs_preliminaire');
|
||
|
$continuer = ' '._T('dirs_commencer') . '.';
|
||
|
} else
|
||
|
$titre = _T('dirs_probleme_droits');
|
||
|
|
||
|
|
||
|
$res = "<div align='right'>". menu_langues('var_lang_ecrire')."</div>\n";
|
||
|
|
||
|
if ($bad_dirs) {
|
||
|
$res .=
|
||
|
_T('dirs_repertoires_suivants',
|
||
|
array('bad_dirs' => join("\n", array_keys($bad_dirs)))) .
|
||
|
"<b>". _T('login_recharger')."</b>.";
|
||
|
}
|
||
|
|
||
|
if ($absent_dirs) {
|
||
|
$res .=
|
||
|
_T('dirs_repertoires_absents',
|
||
|
array('bad_dirs' => join("\n", array_keys($absent_dirs)))) .
|
||
|
"<b>". _T('login_recharger')."</b>.";
|
||
|
}
|
||
|
$res = "<p>" . $continuer . $res . aide ("install0", true) . "</p>";
|
||
|
|
||
|
$t = _T('login_recharger');
|
||
|
$t = (!$test_dir ? "" :
|
||
|
"<input type='hidden' name='test_dir' value='$test_dir' />")
|
||
|
. "<input type='hidden' name='etape' value='chmod' />"
|
||
|
. "<div style='text-align: right'><input type='submit' value='$t' /></div>";
|
||
|
|
||
|
echo minipres($titre, $res . generer_form_ecrire('install', $t));
|
||
|
|
||
|
} else {
|
||
|
$deja = (_FILE_CONNECT AND analyse_fichier_connection(_FILE_CONNECT));
|
||
|
if (!$deja)
|
||
|
redirige_url_ecrire("install", "etape=1&chmod=".$chmod);
|
||
|
else redirige_url_ecrire();
|
||
|
}
|
||
|
}
|
||
|
?>
|