X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fecrire%2Finc%2Facces.php;fp=www%2Fecrire%2Finc%2Facces.php;h=29fee841c623c456db41fd0faaa95dbb86c24834;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c diff --git a/www/ecrire/inc/acces.php b/www/ecrire/inc/acces.php new file mode 100644 index 0000000..29fee84 --- /dev/null +++ b/www/ecrire/inc/acces.php @@ -0,0 +1,262 @@ + $low_sec), "id_auteur = $id_auteur"); + } + } + return $low_sec; +} + +// Inclure les arguments significatifs pour le hachage +// cas particulier du statut pour compatibilite ancien rss/suivi_revisions + +function param_low_sec($op, $args=array(), $lang='', $mime='rss') +{ + $a = $b = ''; + foreach ($args as $val => $var) + if ($var) { + if ($val<>'statut') $a .= ':' . $val.'-'.$var; + $b .= $val.'='.$var . '&'; + } + $a = substr($a,1); + $id = intval(@$GLOBALS['connect_id_auteur']); + return $b + . "op=" + . $op + . "&id=" + . $id + . "&cle=" + . afficher_low_sec($id, "$mime $op $a") + . (!$a ? '' : "&args=$a") + . (!$lang ? '' : "&lang=$lang"); +} + +// http://doc.spip.org/@afficher_low_sec +function afficher_low_sec ($id_auteur, $action='') { + return substr(md5($action.low_sec($id_auteur)),0,8); +} + +// http://doc.spip.org/@verifier_low_sec +function verifier_low_sec ($id_auteur, $cle, $action='') { + return ($cle == afficher_low_sec($id_auteur, $action)); +} + +// http://doc.spip.org/@effacer_low_sec +function effacer_low_sec($id_auteur) { + if (!$id_auteur = intval($id_auteur)) return; // jamais trop prudent ;) + sql_updateq("spip_auteurs", array("low_sec" => ''), "id_auteur = $id_auteur"); +} + +// http://doc.spip.org/@initialiser_sel +function initialiser_sel() { + global $htsalt; + if (CRYPT_MD5) $htsalt = '$1$'.creer_pass_aleatoire(); + else return ""; +} + +// Cette fonction ne sert qu'a la connexion en mode http_auth.non LDAP +// Son role est de creer le fichier htpasswd +// Voir le plugin "acces restreint" +// http://doc.spip.org/@ecrire_acces +function ecrire_acces() { + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; + + // Cette variable de configuration peut etre posee par un plugin + // par exemple acces_restreint ; + // si .htaccess existe, outrepasser spip_meta + if (($GLOBALS['meta']['creer_htpasswd'] != 'oui') + AND !@file_exists($htaccess)) { + spip_unlink($htpasswd); + spip_unlink($htpasswd."-admin"); + return; + } + + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre + # de devenir redacteur le cas echeant (auth http)... a nettoyer + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) + + if (spip_connect_ldap()) return; + $p1 = ''; // login:htpass pour tous + $p2 = ''; // login:htpass pour les admins + $s = sql_select("login, htpass, statut", "spip_auteurs", sql_in("statut", array('1comite','0minirezo','nouveau'))); + while ($t = sql_fetch($s)) { + if (strlen($t['login']) AND strlen($t['htpass'])) { + $p1 .= $t['login'].':'.$t['htpass']."\n"; + if ($t['statut'] == '0minirezo') + $p2 .= $t['login'].':'.$t['htpass']."\n"; + } + } + if ($p1) { + ecrire_fichier($htpasswd, $p1); + ecrire_fichier($htpasswd.'-admin', $p2); + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); + } +} + + +// http://doc.spip.org/@generer_htpass +function generer_htpass($pass) { + global $htsalt; + if (function_exists('crypt')) + return crypt($pass, $htsalt); +} + +// +// Installe ou verifie un .htaccess, y compris sa prise en compte par Apache +// +// http://doc.spip.org/@verifier_htaccess +function verifier_htaccess($rep, $force=false) { + $htaccess = rtrim($rep,"/") . "/" . _ACCESS_FILE_NAME; + if (((@file_exists($htaccess)) OR defined('_TEST_DIRS')) AND !$force) + return true; + if ($_SERVER['SERVER_ADMIN'] == 'www@nexenservices.com') + return nexen($rep); + if ($ht = @fopen($htaccess, "w")) { + fputs($ht, "deny from all\n"); + fclose($ht); + @chmod($htaccess, _SPIP_CHMOD & 0666); + $t = rtrim($rep,"/") . "/.ok"; + if ($ht = @fopen($t, "w")) { + @fclose($ht); + include_spip('inc/distant'); + $t = substr($t,strlen(_DIR_RACINE)); + $t = url_de_base() . $t; + $ht = recuperer_lapage($t, false, 'HEAD', 0); + // htaccess inoperant si on a recupere des entetes HTTP + // (ignorer la reussite si connexion par fopen) + $ht = !(isset($ht[0]) AND $ht[0]); + } + } + spip_log("Creation de $htaccess " . ($ht ? " reussie" : " manquee")); + return $ht; +} + +function nexen($rep) +{ + echo "IMPORTANT : "; + echo "Votre hébergeur est Nexen Services.
"; + echo "La protection du répertoire $rep/ doit se faire + par l'intermédiaire de "; + echo "l'espace webmestres."; + echo "Veuillez créer manuellement la protection pour + ce répertoire (un couple login/mot de passe est + nécessaire).
"; + return false; +} + + +// http://doc.spip.org/@gerer_htaccess +function gerer_htaccess() { + // Cette variable de configuration peut etre posee par un plugin + // par exemple acces_restreint + $f = ($GLOBALS['meta']['creer_htaccess'] === 'oui'); + $dirs = sql_allfetsel('extension', 'spip_types_documents'); + $dirs[] = array('extension' => 'distant'); + foreach($dirs as $e) { + if (is_dir($dir = _DIR_IMG . $e['extension'])) { + if ($f) + verifier_htaccess($dir); + else spip_unlink($dir . '/' . _ACCESS_FILE_NAME); + } + } + return $GLOBALS['meta']['creer_htaccess']; +} + +initialiser_sel(); + +?>