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"); $xml = simplexml_load_string($data); // quick feed check if (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";} if($result == "false") { 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']; } } function serverUrl() { $https = (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS'])=='on')) || $_SERVER["SERVER_PORT"]=='443'; // HTTPS detection. $serverport = ($_SERVER["SERVER_PORT"]=='80' || ($https && $_SERVER["SERVER_PORT"]=='443') ? '' : ':'.$_SERVER["SERVER_PORT"]); 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; } } 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 ; /* SVG minimalistes */ $svg_vert=''; $svg_jaune=''; $svg_rouge=''; $svg_twitter=''; $svg_identica=''; $svg_statusnet=''; if(strpos($_GET['check'], 'twitter') !== FALSE) { header('Content-type: image/svg+xml');die($svg_twitter); } if(strpos($_GET['check'], 'identica') !== FALSE) { header('Content-type: image/svg+xml');die($svg_identica); } if(strpos($_GET['check'], 'statusnet') !== FALSE) { header('Content-type: image/svg+xml');die($svg_statusnet); } $errorlog="./".$_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'); $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)) { $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); $title=$config->site_title; $url=$config->site_url; $feed=$config->feed_url; $reponse[$unit] = array("$title", "$url", "$feed"); } } echo json_encode($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; } if (isset($_GET['sitemap'])) // url-list sitemap { 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; } function escape($str) { return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false); } $form = '
'; if(!empty($_GET['via_button']) && !empty($_GET['rssurl']) && $_GET['number'] === '17') { if(isset($_GET['add']) && $_GET['add'] === '1' && !empty($_GET['siteurl']) && !empty($_GET['sitename'])) { $rssurl = DetectRedirect(escape($_GET['rssurl'])); $siteurl = escape($_GET['siteurl']); $foldername = sha1(NoProtocolSiteURL($siteurl)); if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');} $sitename = escape($_GET['sitename']); $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, "") ) {die("Impossible d'écrire le fichier index.php");} fclose($fp); $fp = fopen('./'. $foldername .'/vvb.ini', 'w+'); if( !fwrite($fp, '[VroumVroumBlogConfig] SITE_TITLE="'. $sitename .'" SITE_DESCRIPTION="Ce site n\'est pas le site officiel de '. $sitename .'