aX0en
Профессор
- Регистрация
- 5 Авг 2009
- Сообщения
- 102
- Реакции
- 44
- Автор темы
- #1
прошу помочь, есть скрипт нужно переделать чтобы никаких преобразований он не делал над доменами, которые я ему скармливаю.
Как думаю этот кусок отвечает за это.
Вот полный скрипт:
Как думаю этот кусок отвечает за это.
PHP:
$siteName = '';
if(!$SelectSiteName) {
if($pwPingJenah) {
@preg_match('/<title>(.+?)<\/title>/',@file_get_contents("http://$siteDomen/"),$output);
$siteName = @$output[1];
}
@preg_match("/^(http:\/\/)?([^\/]+)/i",@$lineDomens[0],$ph);
$siteDomen = @$ph[2];
}
if($SelectSiteName) {
@list($domen,$siteName) = explode("|",@$lineDomens[0]);
@preg_match("/^(http:\/\/)?([^\/]+)/i",@$domen,$ph);
$siteDomen = @$ph[2];
}
Вот полный скрипт:
PHP:
<?php
set_time_limit(0);
function displayLog($log = '') {
echo $log;
flush();
unset($log);
}
function __file_put_contents($file,$vall,$sel = 0) {
$log = '';
if($fp = fopen($file,"a")) {
flock($fp,LOCK_EX);
ftruncate($fp,0);
fseek($fp,0);
if(@fputs($fp,$vall)) {
if($sel)
displayLog("<li class=\"file\">Файл [<a href=\"{$file}\" target=\"_blank\">{$file}</a>] [OK]</li>");
} else {
if($sel)
displayLog("<li class=\"file\">Файл [<b>{$file}</b>] [NO]</li>");
}
fflush($fp);
flock($fp,LOCK_UN);
fclose($fp);
}
return $log;
}
function addStrFile($file = '',$str = '') {
$fp = fopen($file,"a");
flock($fp,LOCK_EX);
fputs($fp,$str."\r\n");
fflush($fp);
flock($fp,LOCK_UN);
fclose($fp);
$data = file($file);
$data = array_unique($data);
$count_data = sizeof($data);
$newdata = array();
for($i = 0; $i < $count_data; $i++) {
$data[$i] = trim($data[$i]);
if(empty($data[$i]))
continue;
$newdata[] = $data[$i]."\r\n";
}
$count_newdata = count($newdata);
$fp = fopen($file,"a");
flock($fp,LOCK_EX);
ftruncate($fp,0);
fseek($fp,0);
for($j = 0; $j < $count_newdata; $j++) {
fputs($fp,$newdata[$j]);
}
fflush($fp);
flock($fp,LOCK_UN);
fclose($fp);
}
function ping($url,$blogname,$blogurl) {
$blogurl = str_replace("&","&",$blogurl);
$blogname = trim(iconv("windows-1251","utf-8",$blogname));
$xml_send = '<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>weblogUpdates.ping</methodName>
<params>
<param>
<value>'.$blogname.'</value>
</param>
<param>
<value>'.$blogurl.'</value>
</param>
</params>
</methodCall>';
$context = stream_context_create(array('http' => array('method' => "POST",
'header' => "Content-type: text/xml\r\n"."Content-length: ".strlen($xml_send),
'content' => $xml_send)));
$response = @file_get_contents($url,true,$context);
if(!$response) {
print "Внутренняя ошибка сервера при отправке запроса\n";
}
strpos($response,'<value>Thanks for the ping.</value>')?$return = true:$return = false;
return $return;
}
function delStrFile($file = '',$num_str = 0) {
if(!is_file($file) and !is_readable($file))
return;
$data = file($file);
$count_data = sizeof($data);
unset($data[$num_str]);
$fp = fopen($file,"a");
flock($fp,LOCK_EX);
ftruncate($fp,0);
fseek($fp,0);
for($j = 0; $j < $count_data; $j++) {
fputs($fp,"$data[$j]");
}
fflush($fp);
flock($fp,LOCK_UN);
fclose($fp);
}
function creatFileFtp($creatFile = '',$creatFileFtp = '',$vall = '') {
global $domen;
global $conn_id;
global $ftp_path;
if($conn_id == false)
return false;
$tempDir = "temp";
$tempFile = "{$tempDir}/{$creatFile}";
__file_put_contents($tempFile,$vall,0);
if(@ftp_put($conn_id,$ftp_path.$creatFileFtp,$tempFile,FTP_ASCII)) {
displayLog("<li class=\"file\">Файл [<a href=\"http://{$domen}/{$creatFileFtp}\" target=\"_blank\">{$creatFileFtp}</a>] [OK]</li>");
$result = true;
} else {
displayLog("<div class=\"file\">Файл [<b>{$file}</b>] [NO]</div>");
$result = false;
}
@unlink($tempFile);
return $result;
}
function connectFtp($login = '',$password = '',$host = '',$ftp_path = '') {
$result = '';
$result_connect = false;
if($conn_id = @ftp_connect($host)) {
displayLog("<div>Сервер {$host} найден</div>");
if(@ftp_login($conn_id,$login,$password)) {
displayLog("<div>Успешно залогинились как <b>{$login}</b></div>");
if(!ftp_pasv($conn_id,true))
ftp_pasv($conn_id,false);
$result_connect = true;
} else {
displayLog("<div>Неудачная авторизация</div>");
ftp_quit($conn_id);
$result_connect = false;
}
} else {
displayLog("<div>Сервер {$host} не найден!</div>");
if($conn_id)
ftp_quit($conn_id);
$result_connect = false;
}
$result->conn_id = $conn_id;
$result->result_connect = $result_connect;
;
return $result;
}
echo <<< HTML
<html>
<head></head>
<body>
HTML;
$SCRIPT_NAME = isset($_SERVER["SCRIPT_NAME"])?@$_SERVER["SCRIPT_NAME"]:"";
$fileDoments = "data/domens.txt";
$lineDomens = array_map("trim",@file($fileDoments));
if(isset($_GET['jenahping'])) {
if(count($lineDomens) < 1)
die("Список доменов пуст. Прогонять нечего!");
if(is_file("data/config.php") and is_readable("data/config.php"))
require ("data/config.php");
$siteName = '';
if(!$SelectSiteName) {
if($pwPingJenah) {
@preg_match('/<title>(.+?)<\/title>/',@file_get_contents("http://$siteDomen/"),$output);
$siteName = @$output[1];
}
@preg_match("/^(http:\/\/)?([^\/]+)/i",@$lineDomens[0],$ph);
$siteDomen = @$ph[2];
}
if($SelectSiteName) {
@list($domen,$siteName) = explode("|",@$lineDomens[0]);
@preg_match("/^(http:\/\/)?([^\/]+)/i",@$domen,$ph);
$siteDomen = @$ph[2];
}
if($pwPingJenah) {
if($fp = @fopen("data/jenahBase.txt","r")) {
if(!function_exists('curl_setopt'))
die("Этот скрипт требует поддержку Curl, текущий сервер его не поддерживает! :(");
$ch = curl_init();
displayLog("<h3>Прогоняем домен <a href=\"http://{$siteDomen}/\" target=\"_blank\">{$siteDomen}</a> по базе дженах</h3>");
displayLog("<ol>");
for($i = 0; $line = trim(fgets($fp,10000)); $i++) {
if(empty($line))
continue;
if(!@preg_match("/^http:\/\//i",$line))
continue;
$url = str_replace("[domen]",$siteDomen,$line);
@ curl_setopt($ch,CURLOPT_URL,$url);
@curl_setopt($ch,CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
@ curl_setopt($ch,CURLOPT_TIMEOUT,60);
@ curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
@curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
@curl_setopt($ch,CURLOPT_REFERER,'http://www.google.com/');
$AskApache_result = curl_exec($ch);
if(!@preg_match("/$domen/",$AskApache_result)) {
displayLog("<li>страница URL не оставляет нашу ссылку, домен .. пропускаем !</li>");
continue;
}
if(@preg_match("!http://http://{$siteDomen}/!",$AskApache_result)) {
addStrFile("data/result_ok_url.txt",str_replace("http://{$siteDomen}/",
"[domen]",$url)."\r\n");
} else {
addStrFile("data/result_ok_url.txt",str_replace($siteDomen,"[domen]",$url)."\r\n");
}
curl_setopt($ch,CURLOPT_URL,'http://pingomatic.com/ping/?title='.urlencode($siteName).
'&blogurl='.urlencode($url).
'&&rssurl=http%3A%2F%2F&chk_weblogscom=on&chk_blogs=on&chk_feedburner=on&chk_syndic8=on&chk_newsgator=on&chk_myyahoo=on&chk_pubsubcom=on&chk_blogdigger=on&chk_blogstreet=on&chk_moreover=on&chk_weblogalot=on&chk_icerocket=on&chk_newsisfree=on&chk_topicexchange=on&chk_google=on&chk_tailrank=on&chk_postrank=on&chk_skygrid=on&chk_collecta=on&chk_superfeedr=on&chk_audioweblogs=on&chk_rubhub=on&chk_geourl=on&chk_a2b=on&chk_blogshares=on');
$AskApache_result = curl_exec($ch);
if(@preg_match('/Pinging complete!/',$AskApache_result)) {
displayLog("<li><a href=\"".$url."\" target=\"_blank\">{$url}</a> - Pinged!</li>");
} else {
displayLog("<li><a href=\"{$url}\" target=\"_blank\">{$url}</a> <b>Pinging Failed!</b></li>");
}
ob_flush();
}
fclose($fp);
displayLog("</ol>");
displayLog("<h3>Готово! Прогнали сайт <a href=\"http;//{$siteDomen}/\" target=\"_blank\">{$siteDomen}</a> по базе дженах</h3>");
if(!$PwGenIndex)
delStrFile($fileDoments);
}
$SleepTime = mt_rand(10,30);
displayLog("<div class=\"time\">Засыпаем на {$SleepTime} сек</div>");
sleep($SleepTime);
}
die("<meta http-equiv=\"Refresh\" content=\"0;URL={$SCRIPT_NAME}?genindex\" />");
} elseif(isset($_GET['genindex'])) {
if(is_file("data/config.php") and is_readable("data/config.php"))
require ("data/config.php");
if(!$PwGenIndex) {
if(!$pwPingJenah)
die("Определи задачу! Пинг базы дженах и генерация индексаторов отключены.");
die("<meta http-equiv=\"Refresh\" content=\"0;URL={$SCRIPT_NAME}?jenahping\" />");
}
$siteName = '';
if(!$SelectSiteName) {
@preg_match("/^(http:\/\/)?([^\/]+)/i",@$lineDomens[0],$ph);
$siteDomen = @$ph[2];
}
if($SelectSiteName) {
@list($domen,$siteName) = explode("|",@$lineDomens[0]);
@preg_match("/^(http:\/\/)?([^\/]+)/i",@$domen,$ph);
$siteDomen = @$ph[2];
}
$fileProject = "data/project.txt";
$fileBadProject = "data/bad_project.txt";
$n = 1;
$n = isset($_GET['n'])?trim(@$_GET['n']):1;
if($countGenIndexs < $n) {
delStrFile("data/domens.txt");
die("<meta http-equiv=\"Refresh\" content=\"0;URL={$SCRIPT_NAME}?jenahping\" />");
}
if(!is_file($fileProject) and (!is_readable($fileProject))) {
echo ("Файл project.txt не найден в папке data! Генерацию индексаторов пропускаем!<br>");
flush();
} else {
$linesProject = @file($fileProject);
$countProject = count($linesProject);
if($countProject < 1) {
echo ("Файл с проектами пуст!<br>");
$SleepTime = mt_rand(10,30);
displayLog("<div class=\"time\">Засыпаем на {$SleepTime} сек</div>");
sleep($SleepTime);
die("<meta http-equiv=\"Refresh\" content=\"0;URL={$SCRIPT_NAME}?jenahping\" />");
} else {
flush();
list($domen,$login,$password,$host,$ftp_path) = array_map("trim",explode("|",$linesProject[0]));
if(empty($ftp_path))
$ftp_path = '/';
if(!empty($domen) or !empty($login) or !empty($password) or !empty($host)) {
$h = 0;
do {
$h++;
if($h > 10) {
addStrFile($fileBadProject,$linesProject[0]);
delStrFile($fileProject);
$n++;
die("<meta http-equiv=\"Refresh\" content=\"0;URL={$SCRIPT_NAME}?genindex&n={$n}\" />");
}
displayLog("<h3>Авторизация на FTP сервере</h3>");
$resultFtp = @connectFtp($login,$password,$host,$ftp_path);
$conn_id = @$resultFtp->conn_id;
$result_connect = @$resultFtp->result_connect;
if((!$conn_id) || (!$result_connect)) {
if($h < 10) {
$ftpSleepTime = mt_rand(10,30);
displayLog("<div class=\"time\">$h) Засыпаем на {$ftpSleepTime} сек</div>");
sleep($ftpSleepTime);
}
}
} while((!$conn_id) || (!$result_connect));
$jenahResultLinks = "data/result_ok_url.txt";
$jenahLines = @file($jenahResultLinks);
$countLinksJenah = count($jenahLines);
$countPage = ceil($countLinksJenah / 200);
displayLog("<h3>Генерируем индексатор <a href=\"http://{$domen}/\" target=\"_blank\">{$domen}</a></h3><br>");
displayLog("<ol>");
for($q1 = 0; $q1 <= $countPage; $q1++) {
$linkblok = '<table><tr><td valign=\"top\">';
$pagination = '';
if($q1 == 0) {
$q = 1;
} else
$q = $q1;
if($q > $countPage)
$q = $countPage;
for($pg = 0; $pg < $countPage; $pg++) {
$numPage = ($pg + 1);
if($numPage == $q) {
$pagination .= "$numPage ";
} else {
$pagination .= "[<a href=\"page_{$numPage}.html\">{$numPage}</a>] ";
}
}
$countLinks = ceil($countLinksJenah / $countPage);
$in = ($countLinks * $q) - $countLinks;
$end = $in + $countLinks;
$urls = array();
for($i = $in; $i < $end; $i++) {
$urls[] = $jenahLines[$i];
}
shuffle($urls);
for($i = 0; $i < count($urls); $i++) {
if(isset($urls[$i])) {
$url = $urls[$i];
$url = str_replace("[domen]",$siteDomen,$url);
@preg_match("/^(http:\/\/)?([^\/]+)/i",$url,$ph);
$domenJenah = @$ph[2];
if($i % 35 < 1) {
$linkblok .= "</td><td valign=\"top\">";
}
if($i % 2 == 0) {
$linkblok .= "<div class=\"zebra1\"><a href=\"$url\" target=\"_blank\">{$domenJenah}</a></div>";
} else {
$linkblok .= "<div class=\"zebra2\"><a href=\"$url\" target=\"_blank\">{$domenJenah}</a></div>";
}
}
}
$linkblok .= '<td></tr></table>';
$from = array();
$to = array();
$from[] = "[LINKBLOK]";
$to[] = $linkblok;
$from[] = "[PAGINATION]";
$to[] = "Страницы: $pagination";
$from[] = "[DOMEN]";
$to[] = $domen;
$from[] = "[NUMPAGE]";
$to[] = $q;
$from[] = "[YEAR]";
$date_time_array = getdate(time());
$to[] = $date_time_array[year];
$html = str_replace($from,$to,file_get_contents("template/indexator.shablon.html"));
if($q1 == 0) {
$filePage = "index.html";
} else {
$filePage = "page_{$q}.html";
}
if(!creatFileFtp($filePage,$filePage,$html)) {
$h = 0;
do {
$h++;
if($h > 10) {
addStrFile($fileBadProject,$linesProject[0]);
$n++;
$SleepTime = mt_rand(10,30);
displayLog("<div class=\"time\">$h) Засыпаем на {$SleepTime} сек</div>");
sleep($SleepTime);
die("<meta http-equiv=\"Refresh\" content=\"0;URL={$SCRIPT_NAME}?genindex&n={$n}\" />");
}
displayLog("<h3>Сбой! $h) Попытка авторизироваться на сервере</h3>");
$resultFtp = @connectFtp($login,$password,$host,$ftp_path);
$conn_id = @$resultFtp->conn_id;
$result_connect = @$resultFtp->result_connect;
creatFileFtp($filePage,$filePage,$html);
if((!$conn_id) || (!$result_connect)) {
if($h < 10) {
$ftpSleepTime = mt_rand(10,30);
displayLog("<div class=\"time\">$h) Засыпаем на {$ftpSleepTime} сек</div>");
sleep($ftpSleepTime);
}
}
} while((!$conn_id) || (!$result_connect));
} else {
if($PwPingIndex) {
if(ping("http://ping.blogs.yandex.ru/RPC2","http://{$domen}/{$filePage}",
"http://{$domen}/{$filePage}")) {
displayLog("<div>пинг в http://ping.blogs.yandex.ru/RPC2 [OK]</div>");
} else {
displayLog("<div>пинг в http://ping.blogs.yandex.ru/RPC2 [NO]</div>");
}
if(ping("http://blogsearch.google.ru/ping/RPC2","http://{$domen}/{$filePage}",
"http://{$domen}/{$filePage}")) {
displayLog("<div>пинг в http://blogsearch.google.ru/ping/RPC2 [OK]</div>");
} else {
displayLog("<div>пинг в http://blogsearch.google.ru/ping/RPC2 [NO]</div>");
}
}
}
}
displayLog("</ol>");
ftp_close($conn_id);
displayLog("<h3>Индексатор <a href=\"http://{$domen}/\" target=\"_blank\">{$domen}</a> залит</h3>Отключились от сервера<br>");
delStrFile($fileProject);
$n++;
$SleepTime = mt_rand(10,30);
displayLog("<div class=\"time\">Засыпаем на {$SleepTime} сек</div>");
sleep($SleepTime);
die("<meta http-equiv=\"Refresh\" content=\"0;URL={$SCRIPT_NAME}?genindex&n={$n}\" />");
}
}
}
} elseif(isset($_GET['update'])) {
$ref = isset($_SERVER['HTTP_REFERER'])?@$_SERVER['HTTP_REFERER']:$SCRIPT_NAME;
die("<meta http-equiv=\"Refresh\" content=\"0;URL={$ref}\" />");
} else {
$countDomens = 0;
$countProject = 0;
$countGenIndexs = 0;
$countJenah = 0;
$SelectSiteName = 0;
$linesJenah = array();
$linesProject = array();
if(is_file("data/config.php") and is_readable("data/config.php"))
require ("data/config.php");
if(isset($_POST['cmd']) and $_POST['cmd'] == 'save') {
$postJenahList = @$_POST['jenahList'];
$postDomenList = @$_POST['domenList'];
$postProjectList = @$_POST['projectList'];
$postPwPingJenah = @$_POST['pwPingJenah'];
$postPwGenIndex = @$_POST['pwGenIndex'];
$postPwPingIndex = @$_POST['pwPingIndex'];
$postСountGenIndex = @$_POST['countGenIndex'];
$postSelectSiteName = @$_POST['selectSiteName'];
$configShablon = "<?php\r\n";
$configShablon .= "// пинговать урлы дженах\r\n";
$configShablon .= "\$pwPingJenah=\"$postPwPingJenah\";\r\n";
$configShablon .= "// генерить индексаторы\r\n";
$configShablon .= "\$PwGenIndex=\"$postPwGenIndex\";\r\n";
$configShablon .= "// пинговать индексаторы в яндекс и гугл\r\n";
$configShablon .= "\$PwPingIndex=\"$postPwPingIndex\";\r\n";
$configShablon .= "// число индексаторов для каждого домена\r\n";
$configShablon .= "\$countGenIndexs=\"$postСountGenIndex\";\r\n";
$configShablon .= "// 0 - Парсить заголовок c с домена; 1 - свои ключи (формат списка доменов: domen|ключевик))\r\n";
$configShablon .= "\$SelectSiteName=\"$postSelectSiteName\";\r\n";
__file_put_contents("data/config.php",$configShablon,0);
__file_put_contents("data/domens.txt",$postDomenList,0);
__file_put_contents("data/jenahBase.txt",$postJenahList,0);
__file_put_contents("data/project.txt",$postProjectList,0);
die("<meta http-equiv=\"Refresh\" content=\"0;URL={$SCRIPT_NAME}?update\" />");
}
if(is_file("data/jenahBase.txt") and is_readable("data/jenahBase.txt")) {
$linesJenah = @file("data/jenahBase.txt");
$countJenah = count($linesJenah);
}
if(is_file("data/domens.txt") and is_readable("data/domens.txt")) {
$linesDomens = @file("data/domens.txt");
$countDomens = count($linesDomens);
}
if(is_file("data/project.txt") and is_readable("data/project.txt")) {
$linesProject = @file("data/project.txt");
$countProject = count($linesProject);
}
$from = array();
$to = array();
$from[] = "[COUNT_JENAH]";
$to[] = $countJenah;
$from[] = "[OUT_JENAH]";
$to[] = @implode("",$linesJenah);
$from[] = "[COUNT_DOMENS]";
$to[] = $countDomens;
$from[] = "[OUT_DOMENS]";
$to[] = @implode("",$linesDomens);
$from[] = "[COUNT_GEN_INDEX]";
$to[] = $countGenIndexs;
$from[] = "[COUNT_PROJECT]";
$to[] = $countProject;
$from[] = "[OUT_PROJECT]";
$to[] = @implode("",$linesProject);
$from[] = "[COUNT_GEN_INDEX]";
$to[] = $countGenIndexs;
$from[] = "[pw_gen_index]";
$to[] = ($PwGenIndex)?"checked=\"checked\"":'';
$from[] = "[pw_ping_index]";
$to[] = ($PwPingIndex)?"checked=\"checked\"":'';
$from[] = "[pw_ping_jenah]";
$to[] = ($pwPingJenah)?"checked=\"checked\"":'';
$from[] = "[selectSiteName2]";
$to[] = ($SelectSiteName)?"checked=\"checked\"":'';
$from[] = "[selectSiteName1]";
$to[] = ($selectSiteName)?"":"checked=\"checked\"";
$from[] = "[SCRIPT_NAME]";
$to[] = $SCRIPT_NAME;
$from[] = "[YEAR]";
$date_time_array = getdate(time());
$to[] = $date_time_array[year];
echo str_replace($from,$to,@file_get_contents("template/admin.shablon.html"));
}
echo <<< HTML
</body>
</html>
HTML;
?>