#!/usr/bin/perl

#use Net::SCP::Expect;
# perl -MCPAN -e 'install "Net::SCP::Expect"'
require "/root/zoozle/new-bots-fr/functions.pl";


while(1){

#	system("perl /root/zoozle/new-bots/emule-newsbot/EmuleNewsCrawler.pl");
#	system("perl /root/zoozle/new-bots/torrent-newsbot/TorrentNewsCrawler.pl");	# torrent.newsbot.pl
	
	# resette datum
	system("python /root/zoozle/new-bots-fr/updatedate.py");

	system("perl /root/zoozle/new-bots-fr/TorrentCrawlerFR.pl");	# torrent.newsbot.pl
	
	# newsarchive cachen
	system("perl /root/zoozle/caching/NewsarchiveCachePage.pl");

	&CACHE();
	# &ftp_upload();	
	# &swarm_files();

	# sitemaps für heute erstellen
	system("perl /root/zoozle/sitemaps/SitemapToday.pl");

	# sitemaps aus den suchkeywords der user bilden 
	system("perl /root/zoozle/sitemaps/SitemapKeywordsToday.pl");
		
	system("date");	
	sleep 30200;

};


sub CACHE(){

	my $timeout	= "300";
	my $ua		= "Mozilla/5.0 (Windows; U; Windows NT 5.0; de-DE; rv:1.6) Gecko/20040206 Firefox/1.0.1";

	my %CACHING = (
		"/server/wwwroot/index.html" => "http://www.zoozle.biz/index.php",
	#	"/server/en.wwwroot/index.html" => "http://en.zoozle.net/index.php",
	#	"/server/de.wwwroot/index.html" => "http://de.zoozle.net/index.php",

	#	"/server/apache2/htdocs/de/index.html" => "http://85.214.90.176/de/index_de.php",
	#	"/server/apache2/htdocs/org/index.html" => "http://85.214.90.176/org/index_org.php",
	#	"/server/apache2/htdocs/devu/index.html" => "http://85.214.90.176/devu/index_devu.php"
	);

	while( my ( $path, $url ) = each(%CACHING) ){
		my $page = &http_get($url, $timeout, $ua, );
		print "Generate Cache for $url\n";
		
		if ( length($page) >= 1000 ) {
		
			unlink $page;
			open(WH,">$path");
				print WH $page;
			close WH;

		}; # if ( length($page) >= 1000 ) {

	}; # while( my ( $path, $url ) = each(%CACHING) ){

	return 1;

}; # sub CACHE(){}




####################################
######## too old & obsolate functions
####################################



sub ftp_upload(){

	use Net::FTP;
	use LWP::Simple;

	my $StoreURLAs	= "/root/zoozle/bots/index.html";
	my $GetFromURL	= "http://www.zoozle.net/zoozle.org/index_org.php";
	my $doc			= get($GetFromURL);

	open(WH,">$StoreURLAs");
	print WH $doc;
	close WH;

	my $FTP = Net::FTP->new("zoozle.org", Debug => 1) or warn "zoozle.org: $@";

	$FTP->login("u36432067","dvyGd8bn") or warn "Cannot login ", $FTP->message;
	$FTP->cwd("/") or warn "Cannot change working directory ", $FTP->message;
	$FTP->put($StoreURLAs, "index.html"); 
	$FTP->quit;

	unlink $StoreURLAs;

	my $StoreURLAs	= "/root/zoozle/bots/index.html";
	my $GetFromURL	= "http://www.zoozle.net/p2pworld.org/p2pworld.php";
	my $doc			= get($GetFromURL);

	open(WH,">$StoreURLAs");
	print WH $doc;
	close WH;

	my $FTP = Net::FTP->new("p2pworld.org", Debug => 1) or warn "p2pworld.org: $@";

	$FTP->login("v130366","a6z7dnwn") or warn "Cannot login ", $FTP->message;
	$FTP->cwd("/") or warn "Cannot change working directory ", $FTP->message;
	$FTP->put($StoreURLAs, "index.html"); 
	$FTP->quit;

	my $StoreURLAs	= "/root/zoozle/bots/index.html";
	my $GetFromURL	= "http://www.zoozle.net/bittorrent-search-engines.com/index_bts.php";
	my $doc			= get($GetFromURL);

	open(WH,">$StoreURLAs");
	print WH $doc;
	close WH;

	my $FTP = Net::FTP->new("bittorrent-search-engines.com", Debug => 1) or die "zoozle.org: $@";

	$FTP->login("u41545054","qCacFNsE") or die "Cannot login ", $FTP->message;
	$FTP->cwd("/") or die "Cannot change working directory ", $FTP->message;
	$FTP->put($StoreURLAs, "index.html"); 
	$FTP->quit;

	print "Done - FTP Upload\n";

}; # sub ftp_upload(){



sub swarm_files(){

	my %ConfigHash =(
		"1"	=> my $CfG1 = { 
				"HOST"	=> "85.214.66.15",	# fishwarez
				"USER"	=> "root",
				"PASS"	=> "######################!1962",
				"PATH"	=> "/root/zoozle/updates/"
				},
		#	"2"	=> my $CfG2 = { 
		#			"HOST"	=> "HOSTIP",
		#			"USER"	=> "USERNAME",
		#			"PASS"	=> "PASSWORD",
		#			"PATH"	=> "/root/.mutella"	 # wo soll es gespeichert werden
		#			}, 
	);

	# von A nach B kopieren
	while ( my ($key, $value) = each(%ConfigHash) ) {

		my $RemoteUserName	= $value->{ 'USER' };
		my $RemotePassword	= $value->{ 'PASS' };
		my $RemoteHostname	= $value->{ 'HOST' };
		my $RemoteStorePath	= $value->{ 'PATH' };

		# print "SCP: $RemoteUserName $RemotePassword $RemoteHostname $RemoteStorePath\n";

		my $SCP = Net::SCP::Expect->new(
			host		=> "$RemoteHostname",
			user		=> "$RemoteUserName",
			password	=> "$RemotePassword" );

		$SCP->auto_yes(1);
		
		eval {
			$SCP->scp("/root/zoozle/bots/emule_news.txt","$RemoteUserName\@$RemoteHostname:$RemoteStorePath");
			$SCP->scp("/root/zoozle/bots/torrent_news.txt","$RemoteUserName\@$RemoteHostname:$RemoteStorePath");
			undef $SCP;
		};

	}; # while (my ($key, $value) = each(%ConfigHash) ) {}
	
	$now_string = localtime;
	print "$now_string: I swarmed the files to slaves\n";

}; # sub swarm_files(){
