diff --git a/0.3/autoblog.php b/0.3/autoblog.php index 255fe81..fac6dba 100755 --- a/0.3/autoblog.php +++ b/0.3/autoblog.php @@ -697,6 +697,8 @@ echo '
+

PROJET AUTOBLOG ~ '. $head_title .'

+

'.escape($config->site_title).'

'; if (!empty($config->site_description)) diff --git a/0.3/config.php b/0.3/config.php index 512abad..dc0b60e 100755 --- a/0.3/config.php +++ b/0.3/config.php @@ -47,15 +47,28 @@ function __($str) } } -// Autoriser la création d'autoblogs ? -$allow_new_autoblogs=TRUE; +define( 'ALLOW_NEW_AUTOBLOGS', TRUE ); +// If you set ALLOW_NEW_AUTOBLOGS to FALSE, the following options do not matter. +// Generic RSS +define( 'ALLOW_NEW_AUTOBLOGS_BY_LINKS', TRUE ); +// Twitter, Identica, Statusnet, Shaarli +define( 'ALLOW_NEW_AUTOBLOGS_BY_SOCIAL', TRUE ); +// Bookmark button +define( 'ALLOW_NEW_AUTOBLOGS_BY_BUTTON', TRUE ); +// OPML file +define( 'ALLOW_NEW_AUTOBLOGS_BY_OPML', TRUE ); + +define( 'ALLOW_FULL_UPDATE', TRUE ); + // Logo à utiliser -$logo="./icon-logo.svg"; +//$logo="./icon-logo.svg"; +$logo = ''; // Marquez ici votre propre message qui apparaîtra en bas de page. // exemple : -// $HTML_footer="
Love data
Data is essential
Data must flow
Data must be used
Data is neither good nor bad
There is no illegal data
Data is free
Data can not be owned
No man, machine or system shall interrupt the flow of data
Locking data is a crime against datanity"; -$HTML_footer=""; +//$HTML_footer="
Love data
Data is essential
Data must flow
Data must be used
Data is neither good nor bad
There is no illegal data
Data is free
Data can not be owned
No man, machine or system shall interrupt the flow of data
Locking data is a crime against datanity"; +$HTML_footer='D\'après les premières versions de SebSauvage et Bohwaz.'; +$head_title = "Arthur HOARO"; ?> diff --git a/0.3/functions.php b/0.3/functions.php new file mode 100755 index 0000000..65ef795 --- /dev/null +++ b/0.3/functions.php @@ -0,0 +1,100 @@ +'. $sitename .' existe déjà.'; + return $error; + } + + if ( mkdir('./'. $foldername, 0755, false) ) { + $fp = fopen('./'. $foldername .'/index.php', 'w+'); + if( !fwrite($fp, "") ) + $error[] = "Impossible d'écrire le fichier index.php"; + fclose($fp); + + $fp = fopen('./'. $foldername .'/vvb.ini', 'w+'); + if( !fwrite($fp, '[VroumVroumBlogConfig] +SITE_TYPE="'. $type .'" +SITE_TITLE="'. $sitename .'" +SITE_DESCRIPTION="Site original : '. $sitename .'" +SITE_URL="'. $siteurl .'" +FEED_URL="'. $rssurl .'" +ARTICLES_PER_PAGE="5" +UPDATE_INTERVAL="'. getInterval( $type ) .'" +UPDATE_TIMEOUT="30"') ) + $error[] = "Impossible d'écrire le fichier vvb.ini"; + fclose($fp); + } + else + $error[] = "Impossible de créer le répertoire."; + + return $error; +} + +function getInterval( $type ) { + switch( $type ) { + case 'microblog': + return 300; + case 'shaarli': + return 1800; + default: + return 3600; + } +} + +function updateType($siteurl) { + if( strpos($siteurl, 'twitter.com') !== FALSE ) { + return array('type' => 'microblog', 'name' => 'twitter'); + } + elseif ( strpos( $siteurl, 'identi.ca') !== FALSE ) { + return array('type' => 'microblog', 'name' => 'identica'); + } + elseif( strpos( $siteurl, 'shaarli' ) !== FALSE ) { + return array('type' => 'shaarli', 'name' => 'shaarli'); + } + else + return array('type' => 'generic', 'name' => ''); +} +?> \ No newline at end of file diff --git a/0.3/index.php b/0.3/index.php index ba2fa56..718a603 100755 --- a/0.3/index.php +++ b/0.3/index.php @@ -1,8 +1,11 @@ loadXML($data) or die('xml malformé'); $title = $dom->getElementsByTagName('title'); return $title->item(0)->nodeValue; - } +} -function get_link_from_feed($url) - { - // get site link from feed - $data = file_get_contents("$url"); +function get_link_from_feed($url) { + return get_link_from_datafeed(file_get_contents($url)); +} + +function get_link_from_datafeed($data) { $xml = simplexml_load_string($data); // quick feed check + // ATOM feed && RSS 1.0 /RDF && RSS 2.0 if (!isset($xml->entry) && !isset($xml->item) && !isset($xml->channel->item)) - { die('le flux n\'a pas une syntaxe valide'); } + die('le flux n\'a pas une syntaxe valide'); + + $check = substr($data, 0, 5); + if($check !== 'channel->link; - if($channel['link'] === NULL) - { - $dom = new DOMDocument; - $dom->loadXML($data) or die('xml malformé'); - $link = $dom->getElementsByTagName('uri'); - return $link->item(0)->nodeValue; - } - else - { - return $channel['link']; - } + if($channel['link'] === NULL) { + $dom = new DOMDocument; + $dom->loadXML($data) or die('xml malformé'); + $link = $dom->getElementsByTagName('uri'); + return $link->item(0)->nodeValue; } + else { + return $channel['link']; + } +} function serverUrl() { @@ -65,197 +78,173 @@ function serverUrl() return 'http'.($https?'s':'').'://'.$_SERVER["SERVER_NAME"].$serverport; } -function NoProtocolSiteURL($url) - { - $siteurlnoprototypes = array("http://", "https://"); - $siteurlnoproto = str_replace($siteurlnoprototypes, "", $url); - return $siteurlnoproto; - } - -function DetectRedirect($url) -{ -$response = get_headers($url, 1); -if(!empty($response['Location'])) - { - $response2 = get_headers($response['Location'], 1); - if(!empty($response2['Location'])) - {die('too much redirection');} - else { return $response['Location']; } - } -else - { - return $url; - } +function objectCmp($a, $b) { + return strcasecmp ($a->site_title, $b->site_title); } +/** + * SVG + **/ if (isset($_GET['check'])) { -$randomtime=rand(86400, 259200); /* intervalle de mise à jour: de 1 à 3 jours (pour éviter que le statut de tous les autoblogs soit rafraichi en bloc et bouffe le CPU) */ -$expire=time() -$randomtime ; + //echo "1"; + header('Content-type: image/svg+xml'); + $randomtime=rand(86400, 259200); /* intervalle de mise à jour: de 1 à 3 jours (pour éviter que le statut de tous les autoblogs soit rafraichi en bloc et bouffe le CPU) */ + $expire=time() -$randomtime ; -/* SVG minimalistes */ -$svg_vert='OK'; -$svg_jaune='mv'; -$svg_rouge='err'; -$svg_twitter=''; -$svg_identica=''; -$svg_statusnet=''; + /* SVG minimalistes */ + $svg_vert='OK'; + $svg_jaune='mv'; + $svg_rouge='err'; + $svg_twitter=''; + $svg_identica=''; + $svg_statusnet=''; - $errorlog="./".$_GET['check']."/error.log"; + $errorlog="./".escape( $_GET['check'] ) ."/error.log"; if(file_exists($errorlog) && filemtime($errorlog) < $expire) { unlink($errorlog); } /* errorlog périmé ? Suppression. */ if(file_exists($errorlog)) /* errorlog existe encore ? se contenter de lire sa taille pour avoir le statut */ - { - header('Content-type: image/svg+xml'); + { if(filesize($errorlog) == "0") {die($svg_vert);} else if(filesize($errorlog) == "1") {die($svg_jaune);} else {die($svg_rouge);} - } + } else /* ..sinon, lancer la procédure de contrôle */ - { - $ini = parse_ini_file("./".$_GET['check']."/vvb.ini") or die; - header('Content-type: image/svg+xml'); - if(strpos(strtolower($ini[SITE_TITLE]), 'twitter') !== FALSE) { die($svg_twitter); } /* Twitter */ - if(strpos(strtolower($ini[SITE_TITLE]), 'identica') !== FALSE) { die($svg_identica); } /* Identica */ - if(strpos(strtolower($ini[SITE_TYPE]), 'microblog') !== FALSE) { die($svg_statusnet); } /* Statusnet */ - $headers = get_headers("$ini[FEED_URL]"); + { + $ini = parse_ini_file("./". escape( $_GET['check'] ) ."/vvb.ini") or die; + + if(strpos(strtolower($ini['SITE_TITLE']), 'twitter') !== FALSE) { die($svg_twitter); } /* Twitter */ + if(strpos(strtolower($ini['SITE_TITLE']), 'identica') !== FALSE) { die($svg_identica); } /* Identica */ + if(strpos(strtolower($ini['SITE_TYPE']), 'microblog') !== FALSE) { die($svg_statusnet); } /* Statusnet */ + + $headers = get_headers($ini['FEED_URL']); if(empty($headers)) { file_put_contents($errorlog, '..'); die($svg_rouge); } /* le flux est indisponible (typiquement: erreur DNS ou possible censure) - à vérifier */ $code=explode(" ", $headers[0]); if($code[1] == "200") { file_put_contents($errorlog, ''); die($svg_vert);} /* code retour 200: flux disponible */ else {file_put_contents($errorlog, '.'); die($svg_jaune);} /* autre code retour: un truc a changé (redirection, changement de CMS, .. bref vvb.ini doit être corrigé) */ - } + } } -if (isset($_GET['export'])) -// autoblog exporting -{ -header('Content-Type: application/json'); -$directory = "./"; -$subdirs = glob($directory . "*"); -foreach($subdirs as $unit) - { - if(is_dir($unit)) - { +/** + * Simple and Full Export + **/ +if (isset($_GET['export']) || isset($_GET['feedexport'])) { + header('Content-Type: application/json'); + $directory = "./"; + $subdirs = glob($directory . "*"); + + foreach($subdirs as $unit) { + if(is_dir($unit)) { $unit=substr($unit, 2); $ini = parse_ini_file($unit.'/vvb.ini'); $config = new stdClass; - foreach ($ini as $key=>$value) - { + + foreach ($ini as $key=>$value) { $key = strtolower($key); $config->$key = $value; - } + } unset($ini); - $type=$config->site_type; - $title=$config->site_title; - $url=$config->site_url; - $feed=$config->feed_url; - $reponse[$unit] = array("SITE_TYPE"=>"$type", "SITE_TITLE"=>"$title", "SITE_URL"=>"$url", "FEED_URL"=>"$feed"); - } - } - echo json_encode( array( "meta"=> array("xsaf-version"=>XSAF_VERSION,"xsaf-db_transfer"=>"true","xsaf-media_transfer"=>"true"), + + $feed=$config->feed_url; + + if( isset($_GET['export']) ) { + $type=$config->site_type; + $title=$config->site_title; + $url=$config->site_url; + $reponse[$unit] = array("SITE_TYPE"=>"$type", "SITE_TITLE"=>"$title", "SITE_URL"=>"$url", "FEED_URL"=>"$feed"); + } + // export feed only + else + $reponse=$reponse.";$feed"; + } + } + if( isset($_GET['export']) ) + echo json_encode( array( "meta"=> array("xsaf-version"=>XSAF_VERSION,"xsaf-db_transfer"=>"true","xsaf-media_transfer"=>"true"), "autoblogs"=>$reponse)); -die; -} - -if (isset($_GET['feedexport'])) -// autoblog exporting -feed only -{ -header('Content-Type: application/json'); -$directory = "./"; -$reponse=""; -$subdirs = glob($directory . "*"); -foreach($subdirs as $unit) - { - if(is_dir($unit)) - { - $unit=substr($unit, 2); - $ini = parse_ini_file($unit.'/vvb.ini'); - $config = new stdClass; - foreach ($ini as $key=>$value) - { - $key = strtolower($key); - $config->$key = $value; - } - unset($ini); - $feed=$config->feed_url; - $reponse=$reponse.";$feed"; - } - } -$reponse=substr($reponse, 1); -echo json_encode(explode(';', $reponse)); -die; + else + echo json_encode(explode(';', substr($reponse, 1))); + die; } +/** + * Site map + **/ if (isset($_GET['sitemap'])) // url-list sitemap { -header('Content-Type: text/plain'); -$directory = "./"; -$subdirs = glob($directory . "*"); -foreach($subdirs as $unit) - { - if(is_dir($unit)) - { + header('Content-Type: text/plain'); + $directory = "./"; + $subdirs = glob($directory . "*"); + + foreach($subdirs as $unit) { + if(is_dir($unit)) { $unit=substr($unit, 2); $proto=$_SERVER['HTTPS']?"https://":"http://"; echo $proto.$_SERVER['SERVER_NAME'].substr($_SERVER['PHP_SELF'], 0, -9)."$unit/"."\n"; - } - } -die; + } + } + die; } -function escape($str) -{ - return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false); +/** + * Update ALL autblogs (except .disabled) + * This action can be very slow and consume CPU if you have a lot of autoblogs + **/ +if( isset($_GET['updateAll']) && ALLOW_FULL_UPDATE) { + + $expire = time() - 84600 ; // 23h30 en secondes + $lockfile = ".updatealllock"; + if (file_exists($lockfile) && filemtime($lockfile) > $expire) { + echo "too early"; + die; + } + else { + if( file_exists($lockfile) ) + unlink($lockfile); + + if( file_put_contents($lockfile, date(DATE_RFC822)) ===FALSE) { + echo "Merci d'ajouter des droits d'écriture sur le fichier."; + die; + } + } + + $directory = "./"; + $subdirs = glob($directory . "*"); + foreach($subdirs as $unit) { + if(is_dir($unit)) { + if( !file_exists(ROOT_DIR . '/' . $unit . '/.disabled')) { + file_get_contents(serverUrl() . substr($_SERVER['PHP_SELF'], 0, -9) . $unit . '/index.php'); + } + } + } } -$form = '

-
'; +$form = '
+
+
+ +
'; -if(!empty($_GET['via_button']) && !empty($_GET['rssurl']) && $_GET['number'] === '17' && $allow_new_autoblogs == TRUE) +/** + * ADD BY BOOKMARK BUTTON + **/ +if(!empty($_GET['via_button']) && !empty($_GET['rssurl']) && $_GET['number'] === '17' && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_BUTTON ) { - if(isset($_GET['add']) && $_GET['add'] === '1' && !empty($_GET['siteurl']) && !empty($_GET['sitename'])) - { + if(isset($_GET['add']) && $_GET['add'] === '1' && !empty($_GET['siteurl']) && !empty($_GET['sitename'])) { $rssurl = DetectRedirect(escape($_GET['rssurl'])); $siteurl = escape($_GET['siteurl']); - $sitetype = 'generic'; - $foldername = sha1(NoProtocolSiteURL($siteurl)); - if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');} - $sitename = escape($_GET['sitename']); - if(file_exists($foldername) || file_exists($foldername2)) { die('Erreur: l\'autoblog existe déjà.'); } - if ( mkdir('./'. $foldername, 0755, false) ) { - $fp = fopen('./'. $foldername .'/index.php', 'w+'); - if( !fwrite($fp, "") ) - {die("Impossible d'écrire le fichier index.php");} - fclose($fp); - $fp = fopen('./'. $foldername .'/vvb.ini', 'w+'); - if( !fwrite($fp, '[VroumVroumBlogConfig] -SITE_TYPE="'. $sitetype .'" -SITE_TITLE="'. $sitename .'" -SITE_DESCRIPTION="source: '. $sitename .'" -SITE_URL="'. $siteurl .'" -FEED_URL="'. $rssurl .'" -ARTICLES_PER_PAGE="5" -UPDATE_INTERVAL="3600" -UPDATE_TIMEOUT="30"') ) - {die("Impossible d'écrire le fichier vvb.ini");} - fclose($fp); - {die('autoblog crée avec succès.afficher l\'autoblog');} + $sitename = escape($_GET['sitename']); + + $error = createAutoblog($sitetype, $sitename, $siteurl, $rssurl, $error); + if( empty($error)) + $success[] = 'AutoMicroblog ajouté avec succès.'; + } -else - {die("Impossible de créer le répertoire.");} - - } - else - { - // checking procedure - $sitetype = $_GET['sitetype']; - $rssurl = DetectRedirect($_GET['rssurl']); - $siteurl = get_link_from_feed($rssurl); - $foldername = sha1(NoProtocolSiteURL($siteurl)); - if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');} - $sitename = get_title_from_feed($rssurl); - $sitedomain1 = preg_split('/\//', $siteurl, 0);$sitedomain2=$sitedomain1[2];$sitedomain3=explode(".", $sitedomain2);$sitedomain3=array_reverse($sitedomain3);$sitedomain = $sitedomain3[1].'.'.$sitedomain3[0]; - if(file_exists($foldername) || file_exists($foldername2)) { die('Erreur: l\'autoblog existe déjà.'); } + else { + $rssurl = DetectRedirect(escape($_GET['rssurl'])); + $datafeed = file_get_contents($rssurl); + $siteurl = get_link_from_datafeed($datafeed); + $sitename = get_title_from_datafeed($datafeed); + $form = 'Merci de vérifier les informations suivantes, corrigez si nécessaire.
@@ -267,122 +256,132 @@ else echo $form; die; } } -$error = array(); -$infos = array(); -if(!empty($_POST['socialaccount']) && !empty($_POST['socialinstance']) && $allow_new_autoblogs == TRUE) -{ -$socialaccount = strtolower(escape($_POST['socialaccount'])); - if(escape($_POST['socialinstance']) === 'twitter') { $socialinstance = 'twitter'; } - if(escape($_POST['socialinstance']) === 'identica') { $socialinstance = 'identica'; } - if(escape($_POST['socialinstance']) === 'statusnet') { $socialinstance = 'statusnet'; } - if(escape($_POST['socialinstance']) === 'shaarli') { $socialinstance = 'shaarli'; } - if($socialinstance === 'twitter') { $sitetype = 'microblog'; $update_interval='300'; $siteurl = "http://twitter.com/$socialaccount"; $rssurl = "http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=$socialaccount"; } - if($socialinstance === 'identica') { $sitetype = 'microblog'; $update_interval='300'; $siteurl = "http://identi.ca/$socialaccount"; $rssurl = "http://identi.ca/api/statuses/user_timeline/$socialaccount.rss"; } - if($socialinstance === 'statusnet' && !empty($_POST['statusneturl'])) { $sitetype = 'microblog'; $update_interval='300'; $siteurl=NoProtocolSiteURL(escape($_POST['statusneturl'])); if(substr($siteurl, -1) == '/'){ $siteurl = substr($siteurl, 0, -1); } $rssurl = DetectRedirect("http://".$siteurl."/api/statuses/user_timeline/$socialaccount.rss"); $siteurl = DetectRedirect("http://".$siteurl."/$socialaccount"); } - if($socialinstance === 'shaarli' && !empty($_POST['shaarliurl'])) { $sitetype = 'shaarli'; $update_interval='1800'; $siteurl = NoProtocolSiteURL(escape($_POST['shaarliurl'])); if(substr($siteurl, -1) == '/'){ $siteurl = substr($siteurl, 0, -1); } $siteurl = DetectRedirect("http://".$siteurl."/"); $rssurl = $siteurl."?do=rss";$socialaccount = get_title_from_feed($rssurl); } - $foldername = sha1(NoProtocolSiteURL($siteurl));if(file_exists($foldername)) { die('Erreur: l\'autoblog existe déjà.'); } - $rssurl=DetectRedirect($rssurl); $headers = get_headers($rssurl, 1); - if (strpos($headers[0], '200') == FALSE) {$error[] = "Flux inaccessible (compte inexistant ?)";} else { } -if( empty($error) ) { - if( !preg_match('#\.\.|/#', $foldername) ) { - if ( mkdir('./'. $foldername, 0755, false) ) { - $fp = fopen('./'. $foldername .'/index.php', 'w+'); - if( !fwrite($fp, "") ) - $error[] = "Impossible d'écrire le fichier index.php"; - fclose($fp); - $fp = fopen('./'. $foldername .'/vvb.ini', 'w+'); - if( !fwrite($fp, '[VroumVroumBlogConfig] -SITE_TYPE="'.$sitetype.'" -SITE_TITLE="'.$socialinstance.'-'.$socialaccount.'" -SITE_DESCRIPTION="source: '. $socialaccount .'" -SITE_URL="'. $siteurl .'" -FEED_URL="'. $rssurl .'" -ARTICLES_PER_PAGE="20" -UPDATE_INTERVAL="'.$update_interval.'" -UPDATE_TIMEOUT="30"') ) - $error[] = "Impossible d'écrire le fichier vvb.ini"; - fclose($fp); - $infos[] = 'AutoMicroblog ajouté avec succès.'; - } - else - $error[] = "Impossible de créer le répertoire."; - } - else - $error[] = "Nom de site invalide."; - } +/** + * ADD BY SOCIAL / SHAARLI + **/ +if(!empty($_POST['socialaccount']) && !empty($_POST['socialinstance']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_SOCIAL) +{ + $socialaccount = strtolower(escape($_POST['socialaccount'])); + $socialinstance = strtolower(escape($_POST['socialinstance'])); + + if($socialinstance === 'twitter') { + $sitetype = 'microblog'; + $siteurl = "http://twitter.com/$socialaccount"; + $rssurl = "http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=$socialaccount"; + } + elseif($socialinstance === 'identica') { + $sitetype = 'microblog'; + $siteurl = "http://identi.ca/$socialaccount"; + $rssurl = "http://identi.ca/api/statuses/user_timeline/$socialaccount.rss"; + } + elseif($socialinstance === 'statusnet' && !empty($_POST['statusneturl'])) { + $sitetype = 'microblog'; + $siteurl= NoProtocolSiteURL(escape($_POST['statusneturl'])); + $rssurl = DetectRedirect("http://".$siteurl."/api/statuses/user_timeline/$socialaccount.rss"); + $siteurl = DetectRedirect("http://".$siteurl."/$socialaccount"); + } + elseif($socialinstance === 'shaarli' && !empty($_POST['shaarliurl'])) { + $sitetype = 'shaarli'; + $siteurl = NoProtocolSiteURL(escape($_POST['shaarliurl'])); + $siteurl = DetectRedirect("http://".$siteurl."/"); + $rssurl = $siteurl."?do=rss"; + $socialaccount = get_title_from_feed($rssurl); + } + + $headers = get_headers($rssurl, 1); + if (strpos($headers[0], '200') == FALSE) { + $error[] = "Flux inaccessible (compte inexistant ?)"; + } + if( empty($error) ) { + $error = createAutoblog($sitetype, ucfirst($socialinstance) .' - '. $socialaccount, $siteurl, $rssurl, $error); + if( empty($error)) + $success[] = 'AutoMicroblog ajouté avec succès.'; + } } -if( !empty($_POST) && empty($_POST['socialinstance']) && $allow_new_autoblogs == TRUE) { +/** + * ADD BY GENERIC LINK + **/ +if( !empty($_POST['generic']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_LINK) { if(empty($_POST['rssurl'])) {$error[] = "Veuillez entrer l'adresse du flux.";} if(empty($_POST['number'])) - {$error[] = "Le chiffre. Écrivez le chiffre.";} + {$error[] = "Vous êtes un bot ?";} if($_POST['number'] !== '17') - {$error[] = "C'est pas le bon chiffre.";} + {$error[] = "C'est pas le bon nombre.";} - if(empty($error)) - { + if(empty($error)) { $rssurl = DetectRedirect(escape($_POST['rssurl'])); - if(!empty($_POST['siteurl'])) - { - // check done, writing out - $siteurl = escape($_POST['siteurl']); - $foldername = sha1(NoProtocolSiteURL($siteurl));$sitename = get_title_from_feed($rssurl); - if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');} - $sitedomain1 = preg_split('/\//', $siteurl, 0);$sitedomain2=$sitedomain1[2];$sitedomain3=explode(".", $sitedomain2);$sitedomain3=array_reverse($sitedomain3);$sitedomain = $sitedomain3[1].'.'.$sitedomain3[0]; - if(file_exists($foldername) || file_exists($foldername2)) { die('Erreur: l\'autoblog existe déjà.'); } - if ( mkdir('./'. $foldername, 0755, false) ) { - $fp = fopen('./'. $foldername .'/index.php', 'w+'); - if( !fwrite($fp, "") ) - $error[] = "Impossible d'écrire le fichier index.php"; - fclose($fp); - $fp = fopen('./'. $foldername .'/vvb.ini', 'w+'); - if( !fwrite($fp, '[VroumVroumBlogConfig] -SITE_TYPE="generic" -SITE_TITLE="'. $sitename .'" -SITE_DESCRIPTION="source: '. $sitename .'" -SITE_URL="'. $siteurl .'" -FEED_URL="'. $rssurl .'" -ARTICLES_PER_PAGE="5" -UPDATE_INTERVAL="3600" -UPDATE_TIMEOUT="30"') ) - $error[] = "Impossible d'écrire le fichier vvb.ini"; - fclose($fp); - $infos[] = 'autoblog crée avec succès.afficher l\'autoblog'; - } - else - $error[] = "Impossible de créer le répertoire."; - - } - else - { - // checking procedure - $rssurl = DetectRedirect($rssurl); - $sitetype = 'generic'; - $siteurl = get_link_from_feed($rssurl); - $foldername = sha1(NoProtocolSiteURL($siteurl)); + if(!empty($_POST['siteurl'])) { + $siteurl = escape($_POST['siteurl']); $sitename = get_title_from_feed($rssurl); - if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');} - $sitedomain1 = preg_split('/\//', $siteurl, 0);$sitedomain2=$sitedomain1[2];$sitedomain3=explode(".", $sitedomain2);$sitedomain3=array_reverse($sitedomain3);$sitedomain = $sitedomain3[1].'.'.$sitedomain3[0]; - if(file_exists($foldername) || file_exists($foldername2)) { die('Erreur: l\'autoblog existe déjà.'); } - $form = 'Merci de vérifier les informations suivantes, corrigez si nécessaire.
-
-
-
-
-
'; - } - } + $error = createAutoblog('generic', $sitename, $siteurl, $rssurl, $error); + + if( empty($error)) + $success[] = 'autoblog crée avec succès.afficher l\'autoblog'; + } + else { + // checking procedure + $rssurl = DetectRedirect($rssurl); + $datafeed = file_get_contents($rssurl); + $sitetype = 'generic'; + $siteurl = get_link_from_datafeed($datafeed); + $foldername = urlToFolder($siteurl); + $sitename = get_title_from_datafeed($datafeed); + + if(file_exists($foldername)) { + $error[] = 'Erreur: l\'autoblog existe déjà.'; + } + else { + $form = 'Merci de vérifier les informations suivantes, corrigez si nécessaire.
+
+
+
+
+
+
'; + } + } + } } + +/** + * ADD BY OPML + **/ +if( !empty($_POST['opml']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML) { + if (is_uploaded_file($_FILES['file']['tmp_name'])) { + $opml = null; + if( ($opml = simplexml_load_file( $_FILES['file']['tmp_name'])) !== false ) { + foreach( $opml->body->outline as $outline ) { + if ( !empty( $outline['title'] ) && !empty( $outline['xmlUrl']) && !empty( $outline['htmlUrl'] )) { + $siteurl = escape($outline['htmlUrl']); + $rssurl = DetectRedirect(escape( $outline['xmlUrl'])); + $sitename = escape( $outline['title'] ); + + $error = createAutoblog( 'generic', $sitename, $siteurl, $rssurl, $error ); + if( empty ( $error )) + $success[] = 'Autoblog "'. $sitename .'" crée avec succès. → afficher l\'autoblog.'; + } + } + } + else + $error[] = "Impossible de lire le contenu du fichier OPML."; + unlink($_FILES['file']['tmp_name']); + } else { + $error[] = "Le fichier n'a pas été envoyé."; + } + +} + ?> - Le Projet Autoblog + Projet Autoblog | <?php echo $head_title; ?> - + -

LE PROJET AUTOBLOG

+

PROJET AUTOBLOG |

+
- - Note
- Voici une liste d'autoblogs hébergés sur (plus d'infos sur le projet).

- Autres fermes
- → Rechercher

- -
Ajouter un compte social

-
-
- Twitter
- Identica
-
- -

-
Ajouter un Shaarli

-
- -
- -

-
Ajouter un site web
-Erreur(s) :

    '; - foreach ( $error AS $value ) { - echo '
  • '. $value .'
  • '; - } - echo '
'; -} -if( !empty( $infos )) { - echo '

Info(s) :

    '; - foreach ( $infos AS $value ) { - echo '
  • '. $value .'
  • '; - } - echo '
'; -} -?> -Si vous souhaitez que héberge un autoblog d'un site,
remplissez le formulaire suivant:

- -

Pour ajouter facillement un autoblog d'un site web, glissez ce bouton dans votre barre de marque-pages => ";var%20popup=window.open("","Add%20autoblog",'height=180,width=670');popup.document.writeln('');popup.document.write('Url%20feed%20%20:%20
');var%20feed_links=new%20Array();var%20links=document.getElementsByTagName('link');if(links.length>0){for(var%20i=0;i'+links[i].title+"%20(%20"+links[i].href+"%20)
");}}}popup.document.writeln("");popup.document.writeln("");popup.document.writeln("
");popup.document.writeln("");})();">Projet Autoblog
- -
-
-

Autoblogs hébergés

- -$value) - { - $key = strtolower($key); - $config->$key = $value; - } - $autoblogs[$unit] = ' -
- -
config | '.escape($config->site_type).' source: '.escape($config->site_url).'
-
'; - unset($ini); - } - } -} -if(!empty($autoblogs)){ - sort($autoblogs, SORT_STRING); - foreach ($autoblogs as $autoblog) { - echo $autoblog; - } -} -?> -
-".count($autoblogs)." autoblogs hébergés"; ?> -
-Propulsé par Projet Autoblog 0.3 de Mitsu et Oros (Domaine Public) -".$HTML_footer; } ?> - - - + + +

Présentation

+ +

+ La Projet Autoblog a pour objectif de répliquer les articles d'un blog ou d'un site site web. + Si l'article source est supprimé, et même si le site d'origine disparaît, les articles restent lisibles sur l'autoblog. + L'objectif premier de ce projet est de lutter contre la censure et toute sorte de pression... +

+

+ Voici une liste d'autoblogs hébergés sur + (plus d'infos sur le projet). +

+
+ + +
+ +

Ajouter un autoblog

+ + Message'. (count($error) ? 's' : '') .' :

'; + } + ?> + + +
+

Ajouter un site web

+

+ Si vous souhaitez que héberge un autoblog d'un site,
+ remplissez le formulaire suivant: +

+ + +
+ +
+

Ajouter un compte social

+ +
+
+ Twitter
+ Identica
+ +
+ + +
+
+ +
+

Ajouter un Shaarli

+ +
+ +
+ +
+
+ +
+

Ajout par fichier OPML

+ +
+ +
+ +
+
+ + +

Marque page

+

Pour ajouter facilement un autoblog d'un site web, glissez ce bouton dans votre barre de marque-pages → + ";var%20popup=window.open("","Add%20autoblog",'height=180,width=670');popup.document.writeln('');popup.document.write('Url%20feed%20%20:%20
');var%20feed_links=new%20Array();var%20links=document.getElementsByTagName('link');if(links.length>0){for(var%20i=0;i'+links[i].title+"%20(%20"+links[i].href+"%20)
");}}}popup.document.writeln("");popup.document.writeln("");popup.document.writeln("
");popup.document.writeln("");})();"> + Projet Autoblog +
+ +

+ + +
+

Autoblogs hébergés

+

+ Autres fermes + → Rechercher +

+ +
export JSON
+ + $value) + { + $key = strtolower($key); + $config->$key = $value; + } + $autoblogs[$unit] = $config; + unset($ini); + } + } + } + } + + uasort($autoblogs, "objectCmp"); + $autoblogs_display = ''; + + if(!empty($autoblogs)){ + foreach ($autoblogs as $key => $autoblog) { + $autoblogs_display .= '
+ +
config | '.escape($autoblog->site_type).' source: '.escape($autoblog->site_url).'
+
'; + } + } + + echo $autoblogs_display; + ?> + +
+ + ".count($autoblogs)." autoblogs hébergés

"; ?> +
+ Propulsé par Projet Autoblog 0.3 de Mitsu, Oros et Arthur Hoaro (Domaine Public) + ".$HTML_footer; } ?> + + + \ No newline at end of file diff --git a/0.3/xsaf3.php b/0.3/xsaf3.php index 327b9dd..6b00428 100755 --- a/0.3/xsaf3.php +++ b/0.3/xsaf3.php @@ -3,33 +3,35 @@ define('DEBUG', true); define('XSAF_VERSION', 3); define('AUTOBLOG_FILE_NAME', 'autoblog.php'); +define('ALLOW_REMOTE_DB_DL', false); +define('ALLOW_REMOTE_MEDIA_DL', false); +define('EXEC_TIME', 5); +define( 'ALLOW_XSAF', TRUE ); header("HTTP/1.0 403 Forbidden"); /* Uncivilized method to prevent bot indexing, huh :) */ header('X-Robots-Tag: noindex'); /* more civilized method, but bots may not all take into account */ -header('Content-type: text/plain'); -$expire = time() -7200 ; $lockfile = ".xsaflock"; /* defaut delay: 7200 (2 hours) */ +//header('Content-type: text/plain'); -if (file_exists($lockfile)) { - if (filemtime($lockfile) > $expire) { +$expire = time() -7200 ; +$lockfile = ".xsaflock"; /* defaut delay: 7200 (2 hours) */ + +if (file_exists($lockfile) && filemtime($lockfile) > $expire) { echo "too early"; die; - }else{ - unlink($lockfile); - if( file_put_contents($lockfile, '') ===FALSE) { - echo "Merci d'ajouter des droits d'écriture sur le dossier."; - die; - } - } -}else{ - if( file_put_contents($lockfile, '') ===FALSE) { - echo "Merci d'ajouter des droits d'écriture sur le dossier."; +} +else { + if( file_exists($lockfile) ) + unlink($lockfile); + + if( file_put_contents($lockfile, date(DATE_RFC822)) ===FALSE) { + echo "Merci d'ajouter des droits d'écriture sur le dossier."; die; } -} +} define('ROOT_DIR', __DIR__); -function escape($str) { - return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false); +if(file_exists("functions.php")){ + include "functions.php"; } function serverUrl() { @@ -38,18 +40,16 @@ function serverUrl() { return 'http'.($https?'s':'').'://'.$_SERVER["SERVER_NAME"].$serverport; } -function NoProtocolSiteURL($url) { - $siteurlnoprototypes = array("http://", "https://"); - $siteurlnoproto = str_replace($siteurlnoprototypes, "", $url); - return $siteurlnoproto; -} - libxml_use_internal_errors(true); + // $max_exec_time = temps max d'exécution en seconde function xsafimport($xsafremote, $max_exec_time) { - echo "\n*Traitement $xsafremote en maximum $max_exec_time secondes"; + if( DEBUG ) + echo "\n*Traitement $xsafremote en maximum $max_exec_time secondes"; + $max_exec_time+=time()-1; // -1 car l'import prend environ 1 seconde -/* détection de ferme autoblog */ + + /* détection de ferme autoblog */ $json_import = file_get_contents($xsafremote); if(!empty($json_import)) { $to_update=array(); @@ -61,143 +61,127 @@ function xsafimport($xsafremote, $max_exec_time) { } return false; } - if($json_import['meta']['xsaf-db_transfer'] != "true") {$get_remote_db="0";} else {$get_remote_db="1";} - if($json_import['meta']['xsaf-media_transfer'] != "true") {$get_remote_media="0";} else {$get_remote_media="1";} + + $get_remote_db = ($json_import['meta']['xsaf-db_transfer'] == "true") ? true : false; + $get_remote_media = ($json_import['meta']['xsaf-media_transfer'] == "true") ? true : false; + if(!empty($json_import['autoblogs'])) { foreach ($json_import['autoblogs'] as $value) { - $infos=""; + if(count($value)==4 && !empty($value['SITE_TYPE']) && !empty($value['SITE_TITLE']) && !empty($value['SITE_URL']) && !empty($value['FEED_URL'])) { - $sitetype = $value['SITE_TYPE']; - $sitename = $value['SITE_TITLE']; + $sitetype = escape($value['SITE_TYPE']); + $sitename = escape($value['SITE_TITLE']); $siteurl = escape($value['SITE_URL']); + // Do not use DetectRedirect because it's slow and it has been used when the feed was added + //$rssurl = DetectRedirect(escape($value['FEED_URL'])); $rssurl = escape($value['FEED_URL']); - if($sitetype == 'shaarli') { $articles_per_page = "20"; $update_interval = "1800"; $update_timeout = "30"; } - else if($sitetype == 'microblog') { $articles_per_page = "20"; $update_interval = "300"; $update_timeout = "30"; } - else { $articles_per_page = "5"; $update_interval = "3600"; $update_timeout = "30"; } -// $foldername = $sitename;$foldername2 = $sitename; - $foldername = sha1(NoProtocolSiteURL($siteurl)); - if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');} - - if(!file_exists($foldername) && !file_exists($foldername2)) { - if ( mkdir('./'. $foldername, 0755, false) ) { - $fp = fopen('./'. $foldername .'/index.php', 'w+'); - - $response = get_headers($rssurl, 1); // check for redirections - if(!empty($response['Location'])) { - $result="false"; - }else{ - $xml = simplexml_load_file($rssurl); // quick feed check - - if($xml === FALSE){ - $result="false"; - }elseif (isset($xml->entry)) { // ATOM feed. - $result="true"; - }elseif (isset($xml->item)) { // RSS 1.0 /RDF - $result="true"; - }elseif (isset($xml->channel->item)) { // RSS 2.0 - $result="true"; - }else{ - $result="false"; - } - } - - /* autoblog */ - if($result!=="false") { - if( !fwrite($fp, "") ) { - $infos = "\nImpossible d'écrire le fichier index.php dans ".$foldername; - fclose($fp); - }else{ - fclose($fp); - $fp = fopen('./'. $foldername .'/vvb.ini', 'w+'); - if( !fwrite($fp, <<entry) && !isset($xml->item) && !isset($xml->channel->item)) ? false : true; */ + $result = true; + + /* autoblog */ + if( $result === true ) { + $foldername = urlToFolder($siteurl); + + $errors = createAutoblog($sitetype, $sitename, $siteurl, $rssurl); + foreach( $errors AS $value) { + if( DEBUG ) + echo '

'. $value .'

'; + } + if( empty($errors) && DEBUG ) { + echo '

autoblog '. $sitename .' crée avec succès (DL DB : '. var_dump($get_remote_db) .' - DL media : '. var_dump($get_remote_media) .') : '. $foldername .'

'; + if( !ALLOW_REMOTE_DB_DL && !ALLOW_REMOTE_MEDIA_DL ) + echo ''; + } + + /* ============================================================================================================================================================================== */ + /* récupération de la DB distante */ + if($get_remote_db == true && ALLOW_REMOTE_DB_DL ) { + $remote_db = str_replace("?export", $foldername."/articles.db", $xsafremote); + copy($remote_db, './'. $foldername .'/articles.db'); + } + + if($get_remote_media == true && ALLOW_REMOTE_MEDIA_DL ) { + $remote_media=str_replace("?export", $foldername."/?media", $xsafremote); + $json_media_import = file_get_contents($remote_media); + if(!empty($json_media_import)) + { + mkdir('./'.$foldername.'/media/'); + $json_media_import = json_decode($json_media_import, true); + $media_path=$json_media_import['url']; + if(!empty($json_media_import['files'])) { + foreach ($json_media_import['files'] as $value) { + copy($media_path.$value, './'.$foldername.'/media/'.$value); + } + } + } + } + + /* ============================================================================================================================================================================== */ + //TODO : tester si articles.db est une DB valide + //$to_update[] = serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog + } + + if( DEBUG ) + echo '

time : '.($max_exec_time - time()) .'

'; + if(time() >= $max_exec_time) { + if( DEBUG ) + echo "

Time out !

"; + break; } } + } + else { + if( DEBUG ) + echo "Format JSON incorrect."; + return false; } - /* ============================================================================================================================================================================== */ - - //TODO : tester si articles.db est une DB valide - - $infos = "\nautoblog crée avec succès (DB:$get_remote_db media:$get_remote_media) : $foldername"; - $to_update[]=serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog - } - } - } else { - $infos = "\n$rssurl -> flux invalide"; unlink("./$foldername/index.php"); rmdir($foldername); - } - /* end of file writing */ - }else { - $infos = "\nImpossible de créer le répertoire ".$foldername; - } - } else { - /*$infos = "\nFin d'itération ou Le répertoire ".$foldername." existe déjà ($sitename;$siteurl;$rssurl)";*/ - } - if(DEBUG){ - echo $infos; - } - } - echo "\n time : ".(time() - $max_exec_time); - if(time() >= $max_exec_time){ - break; - } - } - } - /*if(!empty($to_update)){ - if(DEBUG){ - echo "\nupdate of autoblogs ..."; - } - // because it's could be very long, we finish by updating new autoblogs - foreach ($to_update as $url) { - get_headers($url); - } - if(DEBUG){ - echo "done\n\n"; - } - }*/ } - return; + return; } - -/* And now, the XSAF links to be imported, with maximal execusion time for import in second ! */ -xsafimport('https://raw.github.com/mitsukarenai/xsaf-bootstrap/master/3.json', 5); -//xsafimport('https://www.ecirtam.net/autoblogs/?export', 5); -//xsafimport('https://autoblog.suumitsu.eu/?export', 5); + +/* And now, the XSAF links to be imported, with maximal execusion time for import in second ! + You should add only trusted sources. */ +$autoblog_farm = array( + 'https://raw.github.com/mitsukarenai/xsaf-bootstrap/master/3.json', + 'https://www.ecirtam.net/autoblogs/?export', + 'https://autoblog.suumitsu.eu/?export', +); +if( DEBUG ) echo ''; +if( ALLOW_XSAF ) { + foreach( $autoblog_farm AS $value ) { + if( !empty($value) ) + xsafimport($value, EXEC_TIME); + } +} +elseif( DEBUG ) + echo "

XSAF désactivé. Positionnez la variable ALLOW_XSAF à TRUE dans le fichier xsaf3.php pour l'activer.

"; if(DEBUG) { - echo "\n\nXSAF import finished\n\n"; + echo "

XSAF import finished

"; } -die; -?> +if( DEBUG ) echo ''; +?> \ No newline at end of file