Merge branch 'userOptions' into kt-dev

Conflicts:
	.gitignore
This commit is contained in:
Knah Tsaeb 2014-08-29 16:01:52 +02:00
commit 6185cbeeaf
4 changed files with 244 additions and 237 deletions

1
.gitignore vendored
View file

@ -220,3 +220,4 @@ mypersonaldata/public/
mypersonaldata/zipversions/ mypersonaldata/zipversions/
!mypersonaldata/zipversions/index.html !mypersonaldata/zipversions/index.html
pass.php pass.php
user_config.php

View file

@ -1,185 +1,185 @@
<?php <?php
/** /**
* @author bronco@warriordudimanche.com / www.warriordudimanche.net * @author bronco@warriordudimanche.com / www.warriordudimanche.net
* @copyright open source and free to adapt (keep me aware !) * @copyright open source and free to adapt (keep me aware !)
* @version 2.0 * @version 2.0
* *
* Verrouille l'accès à une page * Verrouille l'accès à une page
* Il suffit d'inclure ce fichier pour bloquer l'accès * Il suffit d'inclure ce fichier pour bloquer l'accès
* il gère seul l'expiration de session, la connexion, * il gère seul l'expiration de session, la connexion,
* la déconnexion. * la déconnexion.
* *
* Améliorations eventuelles: * Améliorations eventuelles:
* ajouter compteur de tentatives sur ban id. * ajouter compteur de tentatives sur ban id.
* ajouter la sécurisation du $_POST (en cas d'usage d'une base de donnees) * ajouter la sécurisation du $_POST (en cas d'usage d'une base de donnees)
* *
*/ */
session_start(); session_start();
// ------------------------------------------------------------------
// configuration
// ------------------------------------------------------------------
$auto_restrict['error_msg']='Erreur - impossible de se connecter.';// utilisé si on ne veut pas rediriger
$auto_restrict['cookie_name']='sonarrss';// nom du cookie
$auto_restrict['encryption_key']='abcdef';// clé pour le cryptage de la chaine de vérification
$auto_restrict['session_expiration_delay']=120;//minutes
//$auto_restrict['login']='bronco'; // caractères alphanum + _ et .
$auto_restrict['redirect_error']='index.php?public';// si précisé, pas de message d'erreur
// ---------------------------------------------------------------------------------
// sécurisation du passe: procédure astucieuse de JérômeJ (http://www.olissea.com/)
@include('pass.php');
if(!isset($auto_restrict['pass'])){
if(isset($_POST['pass'])&&isset($_POST['login'])&&$_POST['pass']!=''&&$_POST['login']!=''){ # Création du fichier pass.php
$salt = md5(uniqid('', true));
file_put_contents('pass.php', '<?php $auto_restrict["login"]="'.$_POST['login'].'";$auto_restrict["salt"] = '.var_export($salt,true).'; $auto_restrict["pass"] = '.var_export(hash('sha512', $salt.$_POST['pass']),true).'; ?>');
include('login_form.php');exit();
}
else{ # On affiche un formulaire invitant à rentrer le mdp puis on exit le script
include('login_form.php');exit();
}
}
// ---------------------------------------------------------------------------------
// ------------------------------------------------------------------
// ------------------------------------------------------------------ // configuration
// ------------------------------------------------------------------
// ------------------------------------------------------------------ $auto_restrict['error_msg']='Erreur - impossible de se connecter.';// utilisé si on ne veut pas rediriger
// gestion de post pour demande de connexion $auto_restrict['cookie_name']='sonarrss';// nom du cookie
// si un utilisateur tente de se loguer, on gère ici $auto_restrict['encryption_key']='abcdef';// clé pour le cryptage de la chaine de vérification
// ------------------------------------------------------------------ $auto_restrict['session_expiration_delay']=120;//minutes
if (isset($_POST['login'])&&isset($_POST['pass'])){ //$auto_restrict['login']='bronco'; // caractères alphanum + _ et .
log_user($_POST['login'],$_POST['pass']); $auto_restrict['redirect_error']='index.php?public';// si précisé, pas de message d'erreur
if (isset($_POST['cookie'])){setcookie($auto_restrict['cookie_name'],sha1($_SERVER['HTTP_USER_AGENT']),time()+31104000);}//un an
header('location: index.php');
}
// ------------------------------------------------------------------
// si pas de demande de connexion on verifie les vars de session
// et la duree d'inactivité de la session
// si probleme,on include un form de login.
// ------------------------------------------------------------------
if (!is_ok()){session_destroy();header('location: index.php?public');exit();}
// ------------------------------------------------------------------ // ---------------------------------------------------------------------------------
// demande de deco via la variable get 'deconnexion' // sécurisation du passe: procédure astucieuse de JérômeJ (http://www.olissea.com/)
// ------------------------------------------------------------------ @include('pass.php');
if (isset($_GET['deconnexion'])){log_user($_POST['login'],$_POST['pass']);} if(!isset($auto_restrict['pass'])){
// ------------------------------------------------------------------ if(isset($_POST['pass'])&&isset($_POST['login'])&&$_POST['pass']!=''&&$_POST['login']!=''){ # Création du fichier pass.php
//header('location: index.php?public'); $salt = md5(uniqid('', true));
file_put_contents('pass.php', '<?php $auto_restrict["login"]="'.$_POST['login'].'";$auto_restrict["salt"] = '.var_export($salt,true).'; $auto_restrict["pass"] = '.var_export(hash('sha512', $salt.$_POST['pass']),true).'; ?>');
include('login_form.php');exit();
}
else{ # On affiche un formulaire invitant à rentrer le mdp puis on exit le script
// ------------------------------------------------------------------ include('login_form.php');exit();
// fonctions de cryptage }
// récupérées sur http://www.info-3000.com/phpmysql/cryptagedecryptage.php }
// ------------------------------------------------------------------ // ---------------------------------------------------------------------------------
function GenerationCle($Texte,$CleDEncryptage)
{
$CleDEncryptage = md5($CleDEncryptage); // ------------------------------------------------------------------
$Compteur=0;
$VariableTemp = ""; // ------------------------------------------------------------------
for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++) // gestion de post pour demande de connexion
{ // si un utilisateur tente de se loguer, on gère ici
if ($Compteur==strlen($CleDEncryptage)) // ------------------------------------------------------------------
$Compteur=0; if (isset($_POST['login'])&&isset($_POST['pass'])){
$VariableTemp.= substr($Texte,$Ctr,1) ^ substr($CleDEncryptage,$Compteur,1); log_user($_POST['login'],$_POST['pass']);
$Compteur++; if (isset($_POST['cookie'])){setcookie($auto_restrict['cookie_name'],sha1($_SERVER['HTTP_USER_AGENT']),time()+31104000);}//un an
} header('location: index.php');
return $VariableTemp; }
}
function Crypte($Texte,$Cle) // ------------------------------------------------------------------
{ // si pas de demande de connexion on verifie les vars de session
srand((double)microtime()*1000000); // et la duree d'inactivité de la session
$CleDEncryptage = md5(rand(0,32000) ); // si probleme,on include un form de login.
$Compteur=0; // ------------------------------------------------------------------
$VariableTemp = ""; if (!is_ok()){session_destroy();header('location: index.php?public');exit();}
for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++)
{ // ------------------------------------------------------------------
if ($Compteur==strlen($CleDEncryptage)) // demande de deco via la variable get 'deconnexion'
$Compteur=0; // ------------------------------------------------------------------
$VariableTemp.= substr($CleDEncryptage,$Compteur,1).(substr($Texte,$Ctr,1) ^ substr($CleDEncryptage,$Compteur,1) ); if (isset($_GET['deconnexion'])){log_user($_POST['login'],$_POST['pass']);}
$Compteur++; // ------------------------------------------------------------------
} //header('location: index.php?public');
return base64_encode(GenerationCle($VariableTemp,$Cle) );
}
function Decrypte($Texte,$Cle)
{
$Texte = GenerationCle(base64_decode($Texte),$Cle); // ------------------------------------------------------------------
$VariableTemp = ""; // fonctions de cryptage
for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++) // récupérées sur http://www.info-3000.com/phpmysql/cryptagedecryptage.php
{ // ------------------------------------------------------------------
$md5 = substr($Texte,$Ctr,1); function GenerationCle($Texte,$CleDEncryptage)
$Ctr++; {
$VariableTemp.= (substr($Texte,$Ctr,1) ^ $md5); $CleDEncryptage = md5($CleDEncryptage);
} $Compteur=0;
return $VariableTemp; $VariableTemp = "";
} for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++)
{
if ($Compteur==strlen($CleDEncryptage))
$Compteur=0;
$VariableTemp.= substr($Texte,$Ctr,1) ^ substr($CleDEncryptage,$Compteur,1);
$Compteur++;
}
return $VariableTemp;
}
function Crypte($Texte,$Cle)
{
srand((double)microtime()*1000000);
$CleDEncryptage = md5(rand(0,32000) );
$Compteur=0;
$VariableTemp = "";
for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++)
{
if ($Compteur==strlen($CleDEncryptage))
$Compteur=0;
$VariableTemp.= substr($CleDEncryptage,$Compteur,1).(substr($Texte,$Ctr,1) ^ substr($CleDEncryptage,$Compteur,1) );
$Compteur++;
}
return base64_encode(GenerationCle($VariableTemp,$Cle) );
}
function Decrypte($Texte,$Cle)
{
$Texte = GenerationCle(base64_decode($Texte),$Cle);
$VariableTemp = "";
for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++)
{
$md5 = substr($Texte,$Ctr,1);
$Ctr++;
$VariableTemp.= (substr($Texte,$Ctr,1) ^ $md5);
}
return $VariableTemp;
}
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
function id_user(){ function id_user(){
// retourne une chaine identifiant l'utilisateur que l'on comparera par la suite // retourne une chaine identifiant l'utilisateur que l'on comparera par la suite
// cette chaine cryptée contient les variables utiles sérialisées // cette chaine cryptée contient les variables utiles sérialisées
$id=array(); $id=array();
$id['REMOTE_ADDR']=$_SERVER['REMOTE_ADDR']; $id['REMOTE_ADDR']=$_SERVER['REMOTE_ADDR'];
$id['HTTP_USER_AGENT']=$_SERVER['HTTP_USER_AGENT']; $id['HTTP_USER_AGENT']=$_SERVER['HTTP_USER_AGENT'];
$id['session_id']=session_id(); $id['session_id']=session_id();
$id=serialize($id); $id=serialize($id);
return $id; return $id;
} }
function is_ok(){
// vérifie et compare les variables de session
// en cas de problème on sort/redirige en détruisant la session
global $auto_restrict;
$expired=false;
if (isset($_COOKIE[$auto_restrict['cookie_name']])&&$_COOKIE[$auto_restrict['cookie_name']]==sha1($_SERVER['HTTP_USER_AGENT'])){return true;}
if (!isset($_SESSION['id_user'])){return false;}
if ($_SESSION['expire']<time()){$expired=true;}
$sid=Decrypte($_SESSION['id_user'],$auto_restrict['encryption_key']);
$id=id_user();
if ($sid!=$id || $expired==true){// problème
return false;
}else{ // tout va bien
//on redonne un délai à la session
$_SESSION['expire']=time()+(60*$auto_restrict['session_expiration_delay']);
return true;
}
}
function log_user($login_donne,$pass_donne){
//cree les variables de session
global $auto_restrict;
if ($auto_restrict['login']==$login_donne && $auto_restrict['pass']==hash('sha512', $auto_restrict["salt"].$pass_donne)){
$_SESSION['id_user']=Crypte(id_user(),$auto_restrict['encryption_key']);
$_SESSION['login']=$auto_restrict['login'];
$_SESSION['expire']=time()+(60*$auto_restrict['session_expiration_delay']);
return true;
}else{
exit_redirect();
return false;
}
}
function redirect_to($page){header('Location: '.$page); } function is_ok(){
function exit_redirect(){ // vérifie et compare les variables de session
global $auto_restrict; // en cas de problème on sort/redirige en détruisant la session
@session_unset(); global $auto_restrict;
@session_destroy(); $expired=false;
setcookie($auto_restrict['cookie_name'],'',time()+1); if (isset($_COOKIE[$auto_restrict['cookie_name']])&&$_COOKIE[$auto_restrict['cookie_name']]==sha1($_SERVER['HTTP_USER_AGENT'])){return true;}
if ($auto_restrict['redirect_error']&&$auto_restrict['redirect_error']!=''){//tester sans la deuxième condition if (!isset($_SESSION['id_user'])){return false;}
redirect_to($auto_restrict['redirect_error']); if ($_SESSION['expire']<time()){$expired=true;}
}else{exit($auto_restrict['error_msg']);} $sid=Decrypte($_SESSION['id_user'],$auto_restrict['encryption_key']);
} $id=id_user();
if ($sid!=$id || $expired==true){// problème
return false;
}else{ // tout va bien
//on redonne un délai à la session
$_SESSION['expire']=time()+(60*$auto_restrict['session_expiration_delay']);
return true;
}
}
function log_user($login_donne,$pass_donne){
//cree les variables de session
global $auto_restrict;
if ($auto_restrict['login']==$login_donne && $auto_restrict['pass']==hash('sha512', $auto_restrict["salt"].$pass_donne)){
$_SESSION['id_user']=Crypte(id_user(),$auto_restrict['encryption_key']);
$_SESSION['login']=$auto_restrict['login'];
$_SESSION['expire']=time()+(60*$auto_restrict['session_expiration_delay']);
return true;
}else{
exit_redirect();
return false;
}
}
function redirect_to($page){header('Location: '.$page); }
function exit_redirect(){
global $auto_restrict;
@session_unset();
@session_destroy();
setcookie($auto_restrict['cookie_name'],'',time()+1);
if ($auto_restrict['redirect_error']&&$auto_restrict['redirect_error']!=''){//tester sans la deuxième condition
redirect_to($auto_restrict['redirect_error']);
}else{exit($auto_restrict['error_msg']);}
}
?> ?>

View file

@ -3,10 +3,10 @@
* @author bronco@warriordudimanche.com * @author bronco@warriordudimanche.com
* @copyright open source and free to adapt (keep me aware !) * @copyright open source and free to adapt (keep me aware !)
* @version 0.1 * @version 0.1
* auto_form.php is a little script to auto create a form and * auto_form.php is a little script to auto create a form and
* its content only with an array. * its content only with an array.
* It can create text inputs radiobuttons, select lists, passwords inputs. * It can create text inputs radiobuttons, select lists, passwords inputs.
* All the generated form's elements can be reached by classes * All the generated form's elements can be reached by classes
* and ids with css or jquery. * and ids with css or jquery.
* *
* It's possible to configure auto_form to add some features * It's possible to configure auto_form to add some features
@ -23,7 +23,7 @@ $config=array(
'use_a_radiobutton_choice'=>'choice one',// current value: other values are defined below 'use_a_radiobutton_choice'=>'choice one',// current value: other values are defined below
'my_password'=>'password', 'my_password'=>'password',
'confirm_password'=>'', 'confirm_password'=>'',
);*/ );*/
//then render_form($config); //then render_form($config);
@ -31,7 +31,7 @@ $config=array(
/* ##################################################################### /* #####################################################################
# auto_form config # # auto_form config #
##################################################################### #####################################################################
*/ */
// here are the basic parameters // here are the basic parameters
@ -68,7 +68,7 @@ function render_form($var){
if ($autoform_config['form_class']){$class=' class="'.$autoform_config['form_class'].'" ';} if ($autoform_config['form_class']){$class=' class="'.$autoform_config['form_class'].'" ';}
if ($autoform_config['enctype']){$enctype=' enctype="'.$autoform_config['enctype'].'" ';} if ($autoform_config['enctype']){$enctype=' enctype="'.$autoform_config['enctype'].'" ';}
if (isset($autoform_config['reset_button_label'])){$reset="<input type='reset' value='".$autoform_config['reset_button_label'].'"/>';} if (isset($autoform_config['reset_button_label'])){$reset="<input type='reset' value='".$autoform_config['reset_button_label'].'"/>';}
echo '<form name="'.$autoform_config['form_name']."\" $id $class $enctype method=\"".$autoform_config['method']."\" action=\"".$autoform_config['action']."\">\n "; echo '<form name="'.$autoform_config['form_name']."\" $id $class $enctype method=\"".$autoform_config['method']."\" action=\"".$autoform_config['action']."\">\n ";
foreach($var as $key=>$value){ foreach($var as $key=>$value){
$all_keys.=$key.' | '; $all_keys.=$key.' | ';
@ -77,7 +77,7 @@ function render_form($var){
$idclasname="name='$key' id='$key' class='$key'"; $idclasname="name='$key' id='$key' class='$key'";
// //
echo '<li>'; echo '<li>';
if (is_bool($value)){ if (is_bool($value)){
// oh, a checkbox ! // oh, a checkbox !
if ($value==true){$checked=' checked ';}else{$checked='';} if ($value==true){$checked=' checked ';}else{$checked='';}
echo $label; echo $label;
@ -89,7 +89,7 @@ function render_form($var){
// lists of choices // lists of choices
if (isset($autoform_config[$key]['type'])&&$autoform_config[$key]['type']=='radio'){ if (isset($autoform_config[$key]['type'])&&$autoform_config[$key]['type']=='radio'){
unset($autoform_config[$key]['type']); unset($autoform_config[$key]['type']);
// oh, a radiobutton list ! // oh, a radiobutton list !
echo $txt.'<br/>'; echo $txt.'<br/>';
echo "<ul>\n"; echo "<ul>\n";
@ -98,11 +98,11 @@ function render_form($var){
echo "<li><label for='$choice$key'> $choice </label><input name='$key' type='radio' value='$choice' $checked id='$choice$key'/></li>\n"; echo "<li><label for='$choice$key'> $choice </label><input name='$key' type='radio' value='$choice' $checked id='$choice$key'/></li>\n";
} }
echo "</ul>\n"; echo "</ul>\n";
}else{ }else{
// oh, a select input ! // oh, a select input !
echo $label; echo $label;
echo "<select $idclasname text='$value'>\n"; echo "<select $idclasname text='$value'>\n";
foreach ($autoform_config[$key] as $choice){ foreach ($autoform_config[$key] as $choice){
if ($choice==$value){$checked='selected';}else{$checked='';} if ($choice==$value){$checked='selected';}else{$checked='';}
echo "<option $checked value='$choice'>$choice</option>\n"; echo "<option $checked value='$choice'>$choice</option>\n";
@ -112,15 +112,15 @@ function render_form($var){
}else if (isset($autoform_config[$key]) && $autoform_config[$key]=='pass'){ }else if (isset($autoform_config[$key]) && $autoform_config[$key]=='pass'){
//oh, a password input ! //oh, a password input !
echo $label; echo $label;
echo "<input type='password' $idclasname value='$value' />\n"; echo "<input type='password' $idclasname value='$value' />\n";
}else{ }else{
// ok, so that's a text input... // ok, so that's a text input...
echo $label; echo $label;
if ($autoform_config['use_placeholder']){$placeholder=" placeholder='$txt'";}else{$placeholder='';} if ($autoform_config['use_placeholder']){$placeholder=" placeholder='$txt'";}else{$placeholder='';}
echo "<input type='text' $idclasname value='$value' $placeholder/>\n"; echo "<input type='text' $idclasname value='$value' $placeholder/>\n";
} }
} }
echo "</li>\n"; echo "</li>\n";
} }
@ -129,13 +129,16 @@ function render_form($var){
} }
include('auto_restrict.php'); include('auto_restrict.php');
include('config.php'); include('config.php');
if(file_exists('user_config.php')){
include('user_config.php');
}
unset($GLOBAL['private_data_folder']); unset($GLOBAL['private_data_folder']);
unset($GLOBAL['public_data_folder']); unset($GLOBAL['public_data_folder']);
$GLOBAL['default_data_folder']=basename($GLOBAL['default_data_folder']); $GLOBAL['default_data_folder']=basename($GLOBAL['default_data_folder']);
$message=''; $message='';
if ($_POST){ if ($_POST){
$auto_form['filename']='config.php'; $auto_form['filename']='user_config.php';
$auto_form['filecontent']="<?php \n /* The configuration generated with auto_form*/\n\n"; $auto_form['filecontent']="<?php \n /* The configuration generated with auto_form*/\n\n";
$auto_form['variable_name']='$GLOBAL'; $auto_form['variable_name']='$GLOBAL';
$all_keys=explode(' | ',$_POST['all_keys']); $all_keys=explode(' | ',$_POST['all_keys']);
@ -150,7 +153,7 @@ if ($_POST){
}else{// not bool }else{// not bool
$auto_form['filecontent'].=$auto_form['variable_name']."['$key']='".$postdata[$key]."';\n"; $auto_form['filecontent'].=$auto_form['variable_name']."['$key']='".$postdata[$key]."';\n";
} }
} }
$auto_form['filecontent'].="\n?>"; $auto_form['filecontent'].="\n?>";
@ -164,9 +167,9 @@ if ($_POST){
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8" /></head> <meta charset="utf-8" /></head>
<title>Configuration</title> <title>Configuration</title>
<link rel="stylesheet" type="text/css" href="design/<?php echo $GLOBAL['skin']; ?>/style.css"/> <link rel="stylesheet" type="text/css" href="design/<?php echo $GLOBAL['skin']; ?>/style.css"/>
<link rel="shortcut icon" type="/image/png" href="design/<?php echo $GLOBAL['skin']; ?>/favicon2.png"> <link rel="shortcut icon" type="/image/png" href="design/<?php echo $GLOBAL['skin']; ?>/favicon2.png">
<!--[if IE]><script> document.createElement("article");document.createElement("aside");document.createElement("section");document.createElement("footer");</script> <![endif]--> <!--[if IE]><script> document.createElement("article");document.createElement("aside");document.createElement("section");document.createElement("footer");</script> <![endif]-->
@ -178,7 +181,7 @@ if ($_POST){
</nav> </nav>
</header> </header>
<aside> <aside>
<?php <?php
render_form($GLOBAL); render_form($GLOBAL);
?> ?>
</aside> </aside>

View file

@ -3,18 +3,18 @@
/* (webpage retriever by Timo Van Neerden; http://lehollandaisvolant.net/contact December 2012) /* (webpage retriever by Timo Van Neerden; http://lehollandaisvolant.net/contact December 2012)
* last updated : December, 10th, 2012 * last updated : December, 10th, 2012
* *
* This piece of software is under the WTF Public Licence. * This piece of software is under the WTF Public Licence.
* Everyone is permitted to copy and distribute verbatim or modified * Everyone is permitted to copy and distribute verbatim or modified
* copies of this program, under the following terms of the WFTPL : * copies of this program, under the following terms of the WFTPL :
* *
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
* *
* 0. You just DO WHAT THE FUCK YOU WANT TO. * 0. You just DO WHAT THE FUCK YOU WANT TO.
* *
*/ */
/* all the enhancements (logo, css, session lock, bookmarklet, tags, rss feed, api) are from Bronco (www.warriordudimanche.net) /* all the enhancements (logo, css, session lock, bookmarklet, tags, rss feed, api) are from Bronco (www.warriordudimanche.net)
* and are based on the same licence ;) * and are based on the same licence ;)
* thanks a lot to Timo for his great job on this app ;) */ * thanks a lot to Timo for his great job on this app ;) */
@ -35,6 +35,9 @@ if (isset($_GET['tag'])){$search_tags=strip_tags($_GET['tag']);}else{$search_tag
// CONFIGURABLE OPTIONS // CONFIGURABLE OPTIONS
// adapter la configuration dans le fichier config.php // adapter la configuration dans le fichier config.php
include('config.php'); include('config.php');
if(file_exists('user_config.php')){
include('user_config.php');
}
$GLOBAL['version']='2.2'; $GLOBAL['version']='2.2';
$GLOBAL['respawn_url']=returncurrenturl(); $GLOBAL['respawn_url']=returncurrenturl();
@ -299,7 +302,7 @@ if (!$GLOBAL['public']){ // private
$matches_url = array_merge($matches_url2, $matches_url); $matches_url = array_merge($matches_url2, $matches_url);
// pour chaque URL/URI // pour chaque URL/URI
foreach ($matches_url as $j => $valuej) { foreach ($matches_url as $j => $valuej) {
@ -378,11 +381,11 @@ if (!$GLOBAL['public']){ // private
$info .= 'TITLE="'.$title.'"'."\n"; $info .= 'TITLE="'.$title.'"'."\n";
$info .= 'DATE="'.time().'"'."\n"; $info .= 'DATE="'.time().'"'."\n";
file_put_contents($GLOBAL['target_folder'].'/'.'index.ini', $info); file_put_contents($GLOBAL['target_folder'].'/'.'index.ini', $info);
/*$GLOBAL['done']['d'] = 'ajout'; /*$GLOBAL['done']['d'] = 'ajout';
$GLOBAL['done']['lien'] = $GLOBAL['target_folder'].'/'; */ $GLOBAL['done']['lien'] = $GLOBAL['target_folder'].'/'; */
} }
}//die; }//die;
@ -394,7 +397,7 @@ if (!$GLOBAL['public']){ // private
$id=idfrompath($_GET['suppr']); $id=idfrompath($_GET['suppr']);
$status=statuspath($_GET['suppr']); $status=statuspath($_GET['suppr']);
if (isset($GLOBAL['tag_array'][$status][$id])){deltags($GLOBAL['tag_array'][$status][$id],$_GET['suppr'],$id,$status);} if (isset($GLOBAL['tag_array'][$status][$id])){deltags($GLOBAL['tag_array'][$status][$id],$_GET['suppr'],$id,$status);}
// suppr page // suppr page
$sousliste = scandir($_GET['suppr']); // listage des dossiers de data. $sousliste = scandir($_GET['suppr']); // listage des dossiers de data.
$nb_sousfichier = count($sousliste); $nb_sousfichier = count($sousliste);
@ -405,11 +408,11 @@ if (!$GLOBAL['public']){ // private
} }
// then the folder itself. // then the folder itself.
if (TRUE === rmdir($_GET['suppr'])) { if (TRUE === rmdir($_GET['suppr'])) {
$GLOBAL['done']['d'] = 'remove'; $GLOBAL['done']['d'] = 'remove';
} }
} }
header("location: index.php"); header("location: index.php");
} }
@ -444,7 +447,7 @@ if (!$GLOBAL['public']){ // private
if (isset($_GET['privateget'])&&is_dir($GLOBAL['private_data_folder'].'/'.$_GET['privateget'])){$target=$GLOBAL['private_data_folder'].'/'.$_GET['privateget'];} if (isset($_GET['privateget'])&&is_dir($GLOBAL['private_data_folder'].'/'.$_GET['privateget'])){$target=$GLOBAL['private_data_folder'].'/'.$_GET['privateget'];}
if (isset($_GET['zipprivate'])) { if (isset($_GET['zipprivate'])) {
$ini_file = $GLOBAL['private_data_folder'].'/'.$_GET['zipprivate'].'/index.ini'; $ini_file = $GLOBAL['private_data_folder'].'/'.$_GET['zipprivate'].'/index.ini';
if(is_file($ini_file)){$info=parse_ini_file($ini_file);}else{$info['TITLE']='';} if(is_file($ini_file)){$info=parse_ini_file($ini_file);}else{$info['TITLE']='';}
$origin_folder_path=$GLOBAL['private_data_folder'].'/'.$_GET['zipprivate']; $origin_folder_path=$GLOBAL['private_data_folder'].'/'.$_GET['zipprivate'];
@ -453,31 +456,31 @@ if (!$GLOBAL['public']){ // private
$zip_completepath=$GLOBAL['data_folder'].'/zipversions/'.$zip_filename; $zip_completepath=$GLOBAL['data_folder'].'/zipversions/'.$zip_filename;
if (is_file($zip_completepath)){header("location: $zip_completepath");exit();}// il existe déjà, on envoie if (is_file($zip_completepath)){header("location: $zip_completepath");exit();}// il existe déjà, on envoie
if (is_dir($origin_folder_path)){// sinon on crée le zip si le dossier existe if (is_dir($origin_folder_path)){// sinon on crée le zip si le dossier existe
include 'zip.php'; include 'zip.php';
rename ($origin_folder_path,$zip_foldername); // on le déplace pour éviter de voir la structure de dossiers apparaître dans le zip rename ($origin_folder_path,$zip_foldername); // on le déplace pour éviter de voir la structure de dossiers apparaître dans le zip
zip($zip_filename,$zip_foldername,$GLOBAL['data_folder'].'/zipversions/'); zip($zip_filename,$zip_foldername,$GLOBAL['data_folder'].'/zipversions/');
rename ($zip_foldername,$origin_folder_path); // on le remet à sa place rename ($zip_foldername,$origin_folder_path); // on le remet à sa place
header('location: '.$GLOBAL['data_folder'].'/zipversions/'.$zip_filename); header('location: '.$GLOBAL['data_folder'].'/zipversions/'.$zip_filename);
} }
} }
if (isset($_GET['rename'])&&isset($_GET['to'])&&isset($_GET['file'])) { if (isset($_GET['rename'])&&isset($_GET['to'])&&isset($_GET['file'])) {
if (is_file($_GET['file'].'/index.ini')){ if (is_file($_GET['file'].'/index.ini')){
$ini=parse_ini_file($_GET['file'].'/index.ini'); $ini=parse_ini_file($_GET['file'].'/index.ini');
$old=strip_tags(urldecode($_GET['rename'])); $old=strip_tags(urldecode($_GET['rename']));
$new=strip_tags(urldecode($_GET['to'])); $new=strip_tags(urldecode($_GET['to']));
$newini='URL="'.$ini['URL'].'"'."\n".'TITLE="'.$new.'"'."\n".'DATE="'.$ini['DATE'].'"'; $newini='URL="'.$ini['URL'].'"'."\n".'TITLE="'.$new.'"'."\n".'DATE="'.$ini['DATE'].'"';
file_put_contents($_GET['file'].'/index.ini',$newini); file_put_contents($_GET['file'].'/index.ini',$newini);
} }
} }
if (isset($_GET['settag'])&&isset($_GET['file'])) { if (isset($_GET['settag'])&&isset($_GET['file'])) {
if (is_file($GLOBAL['data_folder'].'/tags.txt')){$GLOBAL['tag_array']=unstore($GLOBAL['data_folder'].'/tags.txt');}else{$GLOBAL['tag_array']=array();} if (is_file($GLOBAL['data_folder'].'/tags.txt')){$GLOBAL['tag_array']=unstore($GLOBAL['data_folder'].'/tags.txt');}else{$GLOBAL['tag_array']=array();}
if (isset($_GET['ispublic'])){$type='public';}else{$type='private';} if (isset($_GET['ispublic'])){$type='public';}else{$type='private';}
$GLOBAL['tag_array'][$type][$_GET['file']]=strip_tags($_GET['settag']); $GLOBAL['tag_array'][$type][$_GET['file']]=strip_tags($_GET['settag']);
store($GLOBAL['data_folder'].'/tags.txt',$GLOBAL['tag_array']); store($GLOBAL['data_folder'].'/tags.txt',$GLOBAL['tag_array']);
} }
}else{ // public get }else{ // public get
//download public zip version //download public zip version
if (isset($_GET['zippublic'])) { if (isset($_GET['zippublic'])) {
$ini_file = $GLOBAL['public_data_folder'].'/'.$_GET['zippublic'].'/index.ini'; $ini_file = $GLOBAL['public_data_folder'].'/'.$_GET['zippublic'].'/index.ini';
@ -488,9 +491,9 @@ if (!$GLOBAL['public']){ // private
$zip_completepath=$GLOBAL['data_folder'].'/zipversions/'.$zip_filename; $zip_completepath=$GLOBAL['data_folder'].'/zipversions/'.$zip_filename;
if (is_file($zip_completepath)){header("location: $zip_completepath");exit();}// il existe déjà, on envoie if (is_file($zip_completepath)){header("location: $zip_completepath");exit();}// il existe déjà, on envoie
if (is_dir($origin_folder_path)){// sinon on crée le zip si le dossier existe if (is_dir($origin_folder_path)){// sinon on crée le zip si le dossier existe
include 'zip.php'; include 'zip.php';
rename ($origin_folder_path,$zip_foldername); // on le déplace pour éviter de voir la structure de dossiers apparaître dans le zip rename ($origin_folder_path,$zip_foldername); // on le déplace pour éviter de voir la structure de dossiers apparaître dans le zip
zip($zip_filename,$zip_foldername,$GLOBAL['data_folder'].'/zipversions/'); zip($zip_filename,$zip_foldername,$GLOBAL['data_folder'].'/zipversions/');
rename ($zip_foldername,$origin_folder_path); // on le remet à sa place rename ($zip_foldername,$origin_folder_path); // on le remet à sa place
header('location: '.$GLOBAL['data_folder'].'/zipversions/'.$zip_filename); header('location: '.$GLOBAL['data_folder'].'/zipversions/'.$zip_filename);
} }
@ -508,8 +511,8 @@ if (!$GLOBAL['public']){ // private
) )
); );
foreach ($items as $key=>$item){ foreach ($items as $key=>$item){
if ($item!='index.html'){ if ($item!='index.html'){
if (is_dir($GLOBAL['public_data_folder'].'/'.$item)){ if (is_dir($GLOBAL['public_data_folder'].'/'.$item)){
if (is_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini')){ if (is_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini')){
$infos=parse_ini_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini'); $infos=parse_ini_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini');
date_default_timezone_set('Europe/Paris'); date_default_timezone_set('Europe/Paris');
@ -531,10 +534,10 @@ if (!$GLOBAL['public']){ // private
} }
if (isset($_GET['api'])){ if (isset($_GET['api'])){
$content=array(); $content=array();
$items=search('public',$search_tags); $items=search('public',$search_tags);
foreach ($items as $key=>$item){ foreach ($items as $key=>$item){
if ($item!='index.html'){ if ($item!='index.html'){
if (is_dir($GLOBAL['public_data_folder'].'/'.$item)){ if (is_dir($GLOBAL['public_data_folder'].'/'.$item)){
if (is_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini')){ if (is_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini')){
$infos=parse_ini_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini'); $infos=parse_ini_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini');
date_default_timezone_set('Europe/Paris'); date_default_timezone_set('Europe/Paris');
@ -572,7 +575,7 @@ function url_parts() {
} }
// //
// Gets external file by URL. // Gets external file by URL.
// Make a stream context (better). // Make a stream context (better).
// //
@ -813,7 +816,7 @@ if ($GLOBAL['done']['d'] !== FALSE) {
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<?php <?php
if (!empty($_GET['publicget'])){ if (!empty($_GET['publicget'])){
$id=strip_tags($_GET['publicget']); $id=strip_tags($_GET['publicget']);
$temp=parse_ini_file($GLOBAL['public_data_folder'].'/'.$id.'/index.ini'); $temp=parse_ini_file($GLOBAL['public_data_folder'].'/'.$id.'/index.ini');
@ -825,16 +828,16 @@ if ($GLOBAL['done']['d'] !== FALSE) {
else{$page_title='Respawn';} else{$page_title='Respawn';}
?> ?>
<meta charset="utf-8" /></head> <meta charset="utf-8" /></head>
<title><?php echo $page_title; ?></title> <title><?php echo $page_title; ?></title>
<link rel="stylesheet" type="text/css" href="<?php echo $GLOBAL['css_folder']; ?>/style.css"/> <link rel="stylesheet" type="text/css" href="<?php echo $GLOBAL['css_folder']; ?>/style.css"/>
<?php link2favicon($target);?> <?php link2favicon($target);?>
<!--[if IE]><script> document.createElement("article");document.createElement("aside");document.createElement("section");document.createElement("footer");</script> <![endif]--> <!--[if IE]><script> document.createElement("article");document.createElement("aside");document.createElement("section");document.createElement("footer");</script> <![endif]-->
</head> </head>
<body <?php echo $bodyclass;?>> <body <?php echo $bodyclass;?>>
<header><a href="<?php echo $GLOBAL['respawn_url'].$publicarg; ?>"><img src="<?php echo $GLOBAL['css_folder']; ?>/logo2.png"/></a> <header><a href="<?php echo $GLOBAL['respawn_url'].$publicarg; ?>"><img src="<?php echo $GLOBAL['css_folder']; ?>/logo2.png"/></a>
<nav id="orpx_nav-bar"> <nav id="orpx_nav-bar">
<?php <?php
if (!$GLOBAL['public']){ if (!$GLOBAL['public']){
echo "\t".'<form method="get" action="'.$_SERVER['PHP_SELF'].'" >'."\n"; echo "\t".'<form method="get" action="'.$_SERVER['PHP_SELF'].'" >'."\n";
@ -846,7 +849,7 @@ if ($GLOBAL['done']['d'] !== FALSE) {
if (!empty($target)){echo $page_title.' <a class="zip" href="?zippublic='.strip_tags($_GET['publicget']).'" title="Get ZIP version"></a>';}else{echo $GLOBAL['message'];} if (!empty($target)){echo $page_title.' <a class="zip" href="?zippublic='.strip_tags($_GET['publicget']).'" title="Get ZIP version"></a>';}else{echo $GLOBAL['message'];}
echo '</p>'; echo '</p>';
} }
echo '<div class="tag_cloud">'; echo '<div class="tag_cloud">';
tagcloud(); tagcloud();
echo '</div>'; echo '</div>';
@ -925,8 +928,8 @@ if ($GLOBAL['done']['d'] !== FALSE) {
// PRIVATE PAGES ------------------------------------------------------------------------------------------ // PRIVATE PAGES ------------------------------------------------------------------------------------------
if (!$GLOBAL['public']){ if (!$GLOBAL['public']){
echo '<div class="private" style="'.$column_width.'">'."\n"; echo '<div class="private" style="'.$column_width.'">'."\n";
$liste_pages = search('private',$search_tags); $liste_pages = search('private',$search_tags);
if ( ($nb = count($liste_pages)) != 0 ) { if ( ($nb = count($liste_pages)) != 0 ) {
@ -951,17 +954,17 @@ if ($GLOBAL['done']['d'] !== FALSE) {
} }
$tags=$taglinks=''; $tags=$taglinks='';
if (isset($GLOBAL['tag_array']['private'][$liste_pages[$i]])){$tags=$GLOBAL['tag_array']['private'][$liste_pages[$i]];$taglinks=tag2links($GLOBAL['tag_array']['private'][$liste_pages[$i]]);} if (isset($GLOBAL['tag_array']['private'][$liste_pages[$i]])){$tags=$GLOBAL['tag_array']['private'][$liste_pages[$i]];$taglinks=tag2links($GLOBAL['tag_array']['private'][$liste_pages[$i]]);}
echo "\t".' echo "\t".'
<li> <li>
<a class="icon suppr" onclick="return window.confirm(\'Sure to remove?\')" href="?suppr='.$GLOBAL['private_data_folder'].'/'.$liste_pages[$i].'" title="suppr">X</a> <a class="icon suppr" onclick="return window.confirm(\'Sure to remove?\')" href="?suppr='.$GLOBAL['private_data_folder'].'/'.$liste_pages[$i].'" title="suppr">X</a>
<a class="title" href="?privateget='.$liste_pages[$i].'" title="'.$titre.'('.$date.')"><img src="'.$favicon.'"/>'.$titre.'</a> <a class="title" href="?privateget='.$liste_pages[$i].'" title="'.$titre.'('.$date.')"><img src="'.$favicon.'"/>'.$titre.'</a>
<p class="infos">'.$taglinks.'</p> <p class="infos">'.$taglinks.'</p>
<p class="tools"> <p class="tools">
<a class="icon rename" onclick="rename(\''.$GLOBAL['public_data_folder'].'/'.$liste_pages[$i].'\',\''.$titre.'\',this)" href="#" title="rename">R</a> <a class="icon rename" onclick="rename(\''.$GLOBAL['public_data_folder'].'/'.$liste_pages[$i].'\',\''.$titre.'\',this)" href="#" title="rename">R</a>
<a class="icon tagme" onclick="tag(\'\',\''.$liste_pages[$i].'\',\''.$tags.'\',this)" href="#" title="edit tags">T</a> <a class="icon tagme" onclick="tag(\'\',\''.$liste_pages[$i].'\',\''.$tags.'\',this)" href="#" title="edit tags">T</a>
<a class="icon zip" href="?zipprivate='.$liste_pages[$i].'" title="Download zip version">Z</a> <a class="icon zip" href="?zipprivate='.$liste_pages[$i].'" title="Download zip version">Z</a>
<a class="icon origine" href="'.$url.'" title="origin">&#10150;</a> <a class="icon origine" href="'.$url.'" title="origin">&#10150;</a>
<a href="?topublic='.$liste_pages[$i].'" class="topublic" title="Change to public">&#9664;</a> <a href="?topublic='.$liste_pages[$i].'" class="topublic" title="Change to public">&#9664;</a>
</p> </p>
</li>'."\n"; </li>'."\n";
@ -974,11 +977,11 @@ if ($GLOBAL['done']['d'] !== FALSE) {
} }
?> ?>
</aside> </aside>
<footer> <footer>
<a title='from TiMo' href='http://lehollandaisvolant.net/index.php?mode=links&id=20121211195941'>Respawn</a> (bronco edition v<?php echo $GLOBAL['version'];?>) - <a href='?public'>Public page link</a> - <a title='from TiMo' href='http://lehollandaisvolant.net/index.php?mode=links&id=20121211195941'>Respawn</a> (bronco edition v<?php echo $GLOBAL['version'];?>) - <a href='?public'>Public page link</a> -
<a href="?rss<?php if ($search_tags!='') {echo '&tag='.$search_tags; }?>"> RSS </a> - <a href="?rss<?php if ($search_tags!='') {echo '&tag='.$search_tags; }?>"> RSS </a> -
<?php if (!$GLOBAL['public']){echo $bookmarklet;} ?> - <?php if (!$GLOBAL['public']){echo $bookmarklet;} ?> -
<?php if (!$GLOBAL['public']){echo '<a href="config_page.php">Config</a>';} ?> - <?php if (!$GLOBAL['public']){echo '<a href="config_page.php">Config</a>';} ?> -
<?php if (!$GLOBAL['public']){echo '<a href="?discotime">Disconnect</a>';}else{echo '<a href="login_form.php">Admin</a>';}?> <?php if (!$GLOBAL['public']){echo '<a href="?discotime">Disconnect</a>';}else{echo '<a href="login_form.php">Admin</a>';}?>
</footer> </footer>
@ -987,14 +990,14 @@ if ($GLOBAL['done']['d'] !== FALSE) {
newname= prompt('Rename this page:',oldname); newname= prompt('Rename this page:',oldname);
if (newname && newname!=oldname){ if (newname && newname!=oldname){
obj.setAttribute('href',"<?php echo $GLOBAL['respawn_url']; ?>?rename="+encodeURIComponent(oldname)+"&to="+encodeURIComponent(newname)+"&file="+file); obj.setAttribute('href',"<?php echo $GLOBAL['respawn_url']; ?>?rename="+encodeURIComponent(oldname)+"&to="+encodeURIComponent(newname)+"&file="+file);
}else{} }else{}
} }
function tag(ispublic,file,oldtags,obj){ function tag(ispublic,file,oldtags,obj){
newtags= prompt('Tags for this page:',oldtags); newtags= prompt('Tags for this page:',oldtags);
if (newtags && newtags!=oldtags){ if (newtags && newtags!=oldtags){
obj.setAttribute('href',"<?php echo $GLOBAL['respawn_url']; ?>?settag="+encodeURIComponent(newtags)+"&file="+file+ispublic); obj.setAttribute('href',"<?php echo $GLOBAL['respawn_url']; ?>?settag="+encodeURIComponent(newtags)+"&file="+file+ispublic);
}else{} }else{}
} }
</script> </script>