From 5fd9fa480f302902328b81f912dd67ce378284f8 Mon Sep 17 00:00:00 2001 From: citizenz7 Date: Thu, 20 Apr 2017 18:50:55 +0200 Subject: V.1.4.6 --- Html/includes/.htaccess | 1 + Html/includes/BDecode.php | 172 +++++++++++++++++++ Html/includes/BEncode.php | 94 +++++++++++ Html/includes/ariane.php | 32 ++++ Html/includes/config.php | 138 +++++++++++++++ Html/includes/footer.php | 40 +++++ Html/includes/functions.php | 385 ++++++++++++++++++++++++++++++++++++++++++ Html/includes/header-logo.php | 14 ++ Html/includes/header.php | 158 +++++++++++++++++ Html/includes/nav.php | 10 ++ 10 files changed, 1044 insertions(+) create mode 100644 Html/includes/.htaccess create mode 100644 Html/includes/BDecode.php create mode 100644 Html/includes/BEncode.php create mode 100644 Html/includes/ariane.php create mode 100644 Html/includes/config.php create mode 100644 Html/includes/footer.php create mode 100644 Html/includes/functions.php create mode 100644 Html/includes/header-logo.php create mode 100644 Html/includes/header.php create mode 100644 Html/includes/nav.php (limited to 'Html/includes') diff --git a/Html/includes/.htaccess b/Html/includes/.htaccess new file mode 100644 index 0000000..5a928f6 --- /dev/null +++ b/Html/includes/.htaccess @@ -0,0 +1 @@ +Options -Indexes diff --git a/Html/includes/BDecode.php b/Html/includes/BDecode.php new file mode 100644 index 0000000..fbf12bc --- /dev/null +++ b/Html/includes/BDecode.php @@ -0,0 +1,172 @@ += '0' && $wholefile[$offset] <= '9') { + $ret[0] *= 10; + //Added 2005.02.21 - VisiGod + //Changing the type of variable from integer to double to prevent a numeric overflow + settype($ret[0],'double'); + //Added 2005.02.21 - VisiGod + $ret[0] += ord($wholefile[$offset]) - ord('0'); + $offset++; + } else if ($wholefile[$offset] == 'e' || $wholefile[$offset] == ':') { + // Tolerate : or e because this is a multiuse function + $ret[1] = $offset+1; + if ($negative) { + if ($ret[0] == 0) + return array(false); + $ret[0] = - $ret[0]; + } + return $ret; + } else return array(false); + } + } + + function decodeEntry($wholefile, $offset=0) { + if ($wholefile[$offset] == 'd') + return $this->decodeDict($wholefile, $offset); + if ($wholefile[$offset] == 'l') + return $this->decodelist($wholefile, $offset); + if ($wholefile[$offset] == 'i') + return $this->numberdecode($wholefile, ++$offset); + // String value: decode number, then grab substring + + $info = $this->numberdecode($wholefile, $offset); + + if ($info[0] === false) + return array(false); + $ret[0] = substr($wholefile, $info[1], $info[0]); + $ret[1] = $info[1]+strlen($ret[0]); + + + return $ret; + } + + function decodeList($wholefile, $offset) { + if ($wholefile[$offset] != 'l') + return array(false); + $offset++; + $ret = array(); + for ($i=0;;$i++) { + if ($wholefile[$offset] == 'e') + break; + $value = $this->decodeEntry($wholefile, $offset); + if ($value[0] === false) + return array(false); + $ret[$i] = $value[0]; + $offset = $value[1]; + } + // The empty list is an empty array. Seems fine. + return array(0=>$ret, 1=>++$offset); + } + + // Tries to construct an array + function decodeDict($wholefile, $offset=0) { + if ($wholefile[$offset] == 'l') + return $this->decodeList($wholefile, $offset); + if ($wholefile[$offset] != 'd') + return false; + $ret=array(); + $offset++; + for (;;) { + if ($wholefile[$offset] == 'e') { + $offset++; + break; + } + $left = $this->decodeEntry($wholefile, $offset); + if ($left[0]===false) { + die("stop...".$left[1]); + return false; + } + + $offset = $left[1]; + if ($wholefile[$offset] == 'd') { + // Recurse + $value = $this->decodedict($wholefile, $offset); + if ($value[0]) { + $ret[addslashes($left[0])] = $value[0]; + $offset= $value[1]; + } + continue; + } + if ($wholefile[$offset] == 'l') { + $value = $this->decodeList($wholefile, $offset); + if (!$value[0] && is_bool($value[0])) + return false; + $ret[addslashes($left[0])] = $value[0]; + $offset = $value[1]; + continue; + } + $value = $this->decodeEntry($wholefile, $offset); + if ($value[0] === false) + return false; + $ret[addslashes($left[0])] = $value[0]; + $offset = $value[1]; + + } + + return array(0=>(empty($ret)?true:$ret), 1=>$offset); + } +} // End of class declaration. + +// Use this function. eg: BDecode("d8:announce44:http://www. ... e"); +function BDecode($wholefile) { + $decoder = new BDecode; + $return = $decoder->decodeEntry($wholefile); + return $return[0]; +} +?> \ No newline at end of file diff --git a/Html/includes/BEncode.php b/Html/includes/BEncode.php new file mode 100644 index 0000000..b0876e7 --- /dev/null +++ b/Html/includes/BEncode.php @@ -0,0 +1,94 @@ + $dummy) + $keys[$i++] = stripslashes($key); + sort($keys); + for ($i=0; isset($keys[$i]); $i++) + $return[addslashes($keys[$i])] = $array[addslashes($keys[$i])]; + return $return; + } + + // Encodes strings, integers and empty dictionaries. + // $unstrip is set to true when decoding dictionary keys + function encodeEntry($entry, &$fd, $unstrip = false) { + if (is_bool($entry)) { + $fd .= 'de'; + return; + } + if (is_int($entry) || is_float($entry)) { + $fd .= 'i'.$entry.'e'; + return; + } + if ($unstrip) + $myentry = stripslashes($entry); + else + $myentry = $entry; + $length = strlen($myentry); + $fd .= $length.':'.$myentry; + } + + // Encodes lists + function encodeList($array, &$fd) { + $fd .= 'l'; + // The empty list is defined as array(); + if (empty($array)) { + $fd .= 'e'; + return; + } + for ($i = 0; isset($array[$i]); $i++) + $this->decideEncode($array[$i], $fd); + $fd .= 'e'; + } + + // Passes lists and dictionaries accordingly, and has encodeEntry handle + // the strings and integers. + function decideEncode($unknown, &$fd) { + if (is_array($unknown)) { + if (isset($unknown[0]) || empty($unknown)) + return $this->encodeList($unknown, $fd); + else + return $this->encodeDict($unknown, $fd); + } + $this->encodeEntry($unknown, $fd); + } + + // Encodes dictionaries + function encodeDict($array, &$fd) { + $fd .= 'd'; + if (is_bool($array)) { + $fd .= 'e'; + return; + } + // NEED TO SORT! + $newarray = $this->makeSorted($array); + foreach($newarray as $left => $right) { + $this->encodeEntry($left, $fd, true); + $this->decideEncode($right, $fd); + } + $fd .= 'e'; + } +} // End of class declaration. + +// Use this function in your own code. +function BEncode($array) { + $string = ''; + $encoder = new BEncode; + $encoder->decideEncode($array, $string); + return $string; +} +?> \ No newline at end of file diff --git a/Html/includes/ariane.php b/Html/includes/ariane.php new file mode 100644 index 0000000..d63374a --- /dev/null +++ b/Html/includes/ariane.php @@ -0,0 +1,32 @@ +'; + + echo 'Accueil'; + + for($i=1; $i"; + } + else { + $prChunks[0]=$dChunks[$i] . ' ›› '; + } + echo '">'; + echo str_replace("_" , " " , $prChunks[0]); + } + +echo '

'; +?> diff --git a/Html/includes/config.php b/Html/includes/config.php new file mode 100644 index 0000000..64e7f00 --- /dev/null +++ b/Html/includes/config.php @@ -0,0 +1,138 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} +catch(PDOException $e) { + //show error + echo '

'.$e->getMessage().'

'; + exit; +} + +//PARAMETRES DU SITE----------------------------------------------------------------- +define('WEBPATH','/var/www/freetorrent.fr/web'); // Path of your website files +define('SITENAME','freetorrent'); +define('SITENAMELONG','freetorrent.fr'); +define('SITESLOGAN','Freetorrent : Bittorrent au service du Libre'); +define('SITEDESCRIPTION','freetorrent.fr rassemble des OS libres (Systèmes d\'exploitation) et les propose au téléchargement par l\'intermédiaire du protocole Bittorrent.'); +define('SITEURL','http://www.freetorrent.fr'); +define('SITEMAIL','contact@freetorrent.fr'); +define('SITEOWNORNAME',''); // author's name +define('SITEOWNORADDRESS',''); // author's real address ... +define('SITEDISQUS',''); // DISQUS comments if enabled +define('ANNOUNCEPORT',''); // PORT FOR XBTT +define('SITEVERSION','1.4.6'); +define('SITEDATE','24/12/16'); +define('COPYDATE','2016-2017'); +define('CHARSET','UTF-8'); + + +define('NBTORRENTS','15'); // Number of torrents in torrents list + +// Deconnexion auto au bout de 10 minutes +if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) { + if (isset($_SESSION['time'])) { + if ($_SESSION['time'] + 600 > time()) { + $_SESSION['time'] = time(); + } + else { + header ('Location: '.SITEURL.'/admin/logout.php'); + } + } + else { + $_SESSION['time'] = time(); + } +} + + +// Announce +$ANNOUNCEURL = SITEURL.':'.ANNOUNCEPORT.'/announce'; + +// Répertoire des images +$REP_IMAGES = '/var/www/freetorrent.fr/web/images/'; + +// Edito - Page d'accueil +$EDITO = ' +

Bienvenue sur '.SITEURL.' !

+

'.SITENAMELONG.' rassemble des projets sous licences libres et licences de libre diffusion et les propose au téléchargement par l\'intermédiaire du protocole Bittorrent.
+Il est complémentaire de certains gros projets officiels qui possèdent déjà leurs services Bittorrent et s\'adresse tout particulièrement aux projets plus modestes qui recherchent un moyen simple de partager librement leurs travaux.
+Si vous voulez nous apporter un peu d\'aide, merci de nous contacter par l\'intermédiaire du formulaire de contact.
+Le téléchargement (leech) est libre et ne nécessite aucune création de compte. Néanmoins, vous devrez créer un compte membre afin d\'uploader des torrents. +

+'; + +//Paramètres pour le fichier torrent (upload.php) +define('MAX_FILE_SIZE', 1048576); // Taille maxi en octets du fichier .torrent +$WIDTH_MAX = 500; // Largeur max de l'image en pixels +$HEIGHT_MAX = 500; // Hauteur max de l'image en pixels +$REP_TORRENTS = '/var/www/freetorrent.fr/web/torrents/'; // Répertoire des fichiers .torrents + +//Paramètres pour l'icone de présentation du torrent (index.php, edit-post.php, ...) +$WIDTH_MAX_ICON = 150; //largeur maxi de l'icone de présentation dut orrent +$HEIGHT_MAX_ICON = 150; //Hauteur maxi de l'icone de présentation du torrent +$MAX_SIZE_ICON = 30725; // Taille max en octet de l'icone de présentation du torrent (30 Ko) +$REP_IMAGES_TORRENTS = '/var/www/freetorrent.fr/web/images/imgtorrents/'; +$WEB_IMAGES_TORRENTS = 'images/imgtorrents/'; + +//Paramètres pour l'avatar membre (profile.php, edit-profil.php, ...) +$MAX_SIZE_AVATAR = 51200; // Taille max en octets du fichier (50 Ko) +$WIDTH_MAX_AVATAR = 200; // Largeur max de l'image en pixels +$HEIGHT_MAX_AVATAR = 200; // Hauteur max de l'image en pixels +$EXTENSIONS_VALIDES = array( 'jpg' , 'png' ); //extensions d'images valides +$REP_IMAGES_AVATARS = '/var/www/freetorrent.fr/web/images/avatars/'; // Répertoires des images avatar des membres + + +// ----------------------------------------------------------------------------------- +// CLASSES +// ----------------------------------------------------------------------------------- + +//load classes as needed +function __autoload($class) { + + $class = strtolower($class); + + //if call from within assets adjust the path + $classpath = 'classes/class.'.$class . '.php'; + if ( file_exists($classpath)) { + require_once $classpath; + } + + //if call from within admin adjust the path + $classpath = '../classes/class.'.$class . '.php'; + if ( file_exists($classpath)) { + require_once $classpath; + } + + //if call from within admin adjust the path + $classpath = '../../classes/class.'.$class . '.php'; + if ( file_exists($classpath)) { + require_once $classpath; + } + +} + +require_once(WEBPATH.'/classes/phpmailer/mail.php'); + +$user = new User($db); + +// On inclut le fichier de fonctions +// et les fichiers d'encodage et de décodage des torrents +require_once('functions.php'); +require_once('BDecode.php'); +require_once('BEncode.php'); + +?> diff --git a/Html/includes/footer.php b/Html/includes/footer.php new file mode 100644 index 0000000..1d1c808 --- /dev/null +++ b/Html/includes/footer.php @@ -0,0 +1,40 @@ +
+
+
+ +
+ + diff --git a/Html/includes/functions.php b/Html/includes/functions.php new file mode 100644 index 0000000..a46978e --- /dev/null +++ b/Html/includes/functions.php @@ -0,0 +1,385 @@ + 0) + return "$weeks semaine" . ($weeks > 1 ? "s" : ""); + if ($days > 0) + return "$days jour" . ($days > 1 ? "s" : ""); + if ($hours > 0) + return "$hours heure" . ($hours > 1 ? "s" : ""); + if ($mins > 0) + return "$mins min" . ($mins > 1 ? "s" : ""); + return "< 1 min"; +} + + +function buildTreeArray($files) +{ + $ret = array(); + + foreach ($files as $k => $v) + { + $filename=$v['filename']; + + $parts = preg_split('/\//', $filename, -1, PREG_SPLIT_NO_EMPTY); + $leaf = array_pop($parts); + + // build parent structure + $parent = &$ret; + foreach ($parts as $part) + { + $parent = &$parent[$part]; + } + + if (empty($parent[$leaf])) + { + $v['filename']=$leaf; + $parent[$leaf] = $v; + } + } + + return $ret; +} + + +function outputTree($files, $indent=1) +{ + //echo "$v) + { + $entry=isset($v['filename']) ? $v['filename'] : $k; + $size=$v['size']; + + if($indent==0) + { + // root + $is_folder=true; + } + elseif(is_array($v) && (!array_key_exists('filename',$v) && !array_key_exists('size',$v))) + { + // normal node + $is_folder=true; + } + else + { + // leaf node, i.e. a file + $is_folder=false; + } + + if($is_folder) + { + // we could output a folder icon here + } + else + { + // we could output an appropriate icon + // based on file extension here + $ext=pathinfo($entry,PATHINFO_EXTENSION); + } + + // echo ""; + + if(is_array($v) && $is_folder) + { + outputTree($v, ($indent+1)); + } + } + + //echo "
"; + echo $entry; // output folder name or filename + + if(!$is_folder) + { + // if it’s not a folder, show file size + echo " (".makesize($size).")"; + } + + //echo "
"; +} + + +function unesc($x) { + if (get_magic_quotes_gpc()) + return stripslashes($x); + return $x; +} + +/* +function benc($str) //bencoding +{ + if (is_string($str)) { //string + return strlen($str) . ':' . $str; + } + + if (is_numeric($str)) { //integer + return 'i' . $str . 'e'; + } + + if (is_array($str)) { + $ret_str = ''; //the return string + + $k = key($str); //we check the 1st key, if the key is 0 then is a list if not a dictionary + foreach($str as $var => $val) { + if ($k) { //is dictionary + $ret_str .= benc($var); //bencode the var + } + $ret_str .= benc($val); //we recursivly bencode the contents + } + + if ($k) { //is dictionary + return 'd' . $ret_str . 'e'; + } + + return 'l' . $ret_str . 'e'; + } +} + +function bdec_file($f, $ms) +{ + $fp = fopen($f, "rb"); + if (!$fp) + return; + $e = fread($fp, $ms); + fclose($fp); + return bdec($e); +} + +function bdec($str, &$_len = 0) //bdecoding +{ + $type = substr($str, 0, 1); + + if (is_numeric($type)) { + $type = 's'; + } + + switch ($type) { + case 'i': //integer + $p = strpos($str, 'e'); + $_len = $p + 1; //lenght of bencoded data + return intval(substr($str, 1, $p - 1)); + break; + + case 's': //string + $p = strpos($str, ':'); + $len = substr($str, 0, $p); + $_len = $len + $p + 1; //lenght of bencoded data + return substr($str, $p + 1, $len); + break; + + case 'l': //list + $l = 1; + $ret_array = array(); + while (substr($str, $l, 1) != 'e') { + $ret_array[] = bdec(substr($str, $l), $len); + $l += $len; + } + $_len = $l + 1; //lenght of bencoded data + return $ret_array; + break; + + case 'd': //dictionary + $l = 1; + $ret_array = array(); + while (substr($str, $l, 1) != 'e') { + $var = bdec(substr($str, $l), $len); + $l += $len; + + $ret_array[$var] = bdec(substr($str, $l), $len); + $l += $len; + } + $_len = $l + 1; //lenght of bencoded data + return $ret_array; + break; + } +} +*/ + + +function date_fr($format, $timestamp=false) { + if ( !$timestamp ) $date_en = date($format); + else $date_en = date($format,$timestamp); + + $texte_en = array( + "Monday", "Tuesday", "Wednesday", "Thursday", + "Friday", "Saturday", "Sunday", "January", + "February", "March", "April", "May", + "June", "July", "August", "September", + "October", "November", "December" + ); + $texte_fr = array( + "lundi", "mardi", "mercredi", "jeudi", + "vendredi", "samedi", "dimanche", "janvier", + "février", "mars", "avril", "mai", + "juin", "juillet", "août", "septembre", + "octobre", "novembre", "décembre" + ); + $date_fr = str_replace($texte_en, $texte_fr, $date_en); + + $texte_en = array( + "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", + "Aug", "Sep", "Oct", "Nov", "Dec" + ); + $texte_fr = array( + "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim", + "Jan", "Fév", "Mar", "Avr", "Mai", "Jui", + "Jui", "Aoû", "Sep", "Oct", "Nov", "Déc" + ); + $date_fr = str_replace($texte_en, $texte_fr, $date_fr); + + return $date_fr; +} + + +// --------------------------------------------------------------------- +// Générer un mot de passe aléatoire +// --------------------------------------------------------------------- +function fct_passwd( $chrs = "") +{ + if( $chrs == "" ) $chrs = 10; + $chaine = ""; + + $list = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghkmnpqrstuvwxyz!=$"; + mt_srand((double)microtime()*1000000); + $newstring=""; + + while( strlen( $newstring )< $chrs ) { + $newstring .= $list[mt_rand(0, strlen($list)-1)]; + } + return $newstring; + } + + +function get_extension($nom) { + $nom = explode(".", $nom); + $nb = count($nom); + return strtolower($nom[$nb-1]); +} + + +define('REPLACE_FLAGS', ENT_COMPAT | ENT_XHTML); + +function html($string) { + return htmlspecialchars($string, REPLACE_FLAGS, CHARSET); +} + + +function bbcode($input){ + $input = strip_tags($input); + $input = html($input); + + $search = array( + '/\[b\](.*?)\[\/b\]/is', + '/\[i\](.*?)\[\/i\]/is', + '/\[u\](.*?)\[\/u\]/is', + '/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/is', + '/\[url=(.*?)\](.*?)\[\/url\]/is', + '/\[color=(.*?)\](.*?)\[\/color\]/is', + '/\[size=(.*?)\](.*?)\[\/size\]/is', + '/\[code\](.*?)\[\/code\]/is', + '/\[quote\](.*?)\[\/quote\]/is', + '/\[center\](.*?)\[\/center\]/is', + '/\[right\](.*?)\[\/right\]/is', + '/\[justify\](.*?)\[\/justify\]/is' + ); + + $replace = array( + '$1', + '$1', + '$1', + '', + '$1', + '$2', + '$2', + '$1', + '
$1
', + '

$1

', + '

$1

', + '

$1

' + ); + + return preg_replace($search,$replace,$input); +} + + +function write_log($message, $db) { + + /* + // Check database connection + if(($db instanceof PDO) == false) { + return array(status => false, message => 'ERREUR : connexion MySQL non valide'); + } + */ + + // Check message + if($message == '') { + return array(status => false, message => 'Message vide'); + } + + // Get IP address + if( ($remote_addr = $_SERVER['REMOTE_ADDR']) == '') { + $remote_addr = "Adresse IP inconnue"; + } + + // Get requested script + if( ($request_uri = $_SERVER['REQUEST_URI']) == '') { + $request_uri = "Adresse inconnue"; + } + + // Mysql + $sql = "INSERT INTO blog_logs (remote_addr, request_uri, message) VALUES('$remote_addr', '$request_uri','$message')"; + + // Execute query and save data + $result = $db->query($sql); + if($result) { + return array(status => true, message => 'ok'); + } + else { + return array(status => false, message => 'ERREUR : écriture impossible dans la base de données.'); + } +} +?> diff --git a/Html/includes/header-logo.php b/Html/includes/header-logo.php new file mode 100644 index 0000000..0857700 --- /dev/null +++ b/Html/includes/header-logo.php @@ -0,0 +1,14 @@ + diff --git a/Html/includes/header.php b/Html/includes/header.php new file mode 100644 index 0000000..1f53595 --- /dev/null +++ b/Html/includes/header.php @@ -0,0 +1,158 @@ + + + + + <?php + if(isset($pagetitle)) { + echo SITENAMELONG .' - '. $pagetitle; + } + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Html/includes/nav.php b/Html/includes/nav.php new file mode 100644 index 0000000..d671c14 --- /dev/null +++ b/Html/includes/nav.php @@ -0,0 +1,10 @@ + -- cgit v1.2.1