<?php
/*
Copyright (C) 2007 Mercier Benjamin

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
*/
/*
[ERREUR 1] => Le serveur web du domaine ne repond pas correctement.
[ERREUR 2] => Le domaine n'a pu etre mis a jour sur le panel.
[ERREUR 3] => La mise en suppression du domaine n'a pu etre mis a jour sur le panel
*/

// Annulation de la connexion MySql locale :
$ConnexionLocale = "non";

// Inclusion du core
require ('/var/www/daemon/system/core.php');


$ListDomaine = $ConnexionPanel->Select ("*", "domaine", "Status='2'", "", "", "", "");
if ( $ListDomaine != FALSE )
	{
	$CountDomaine = count($ListDomaine);
	echo "\nDomaine(s) a controler : ".$CountDomaine."\n";
	
	for ($i=0; $i < $CountDomaine; $i++)
		{
		echo "Domaine de ".$ListDomaine[$i]["Utilisateur"]." : ".$ListDomaine[$i]["Adresse"];
		
		if ( gethostbyname($ListDomaine[$i]["Adresse"]) == gethostbyname($ServeurFichier) )
			{
		
			$CodeSource = @file_get_contents("http://".$ListDomaine[$i]["Adresse"]);
			if ( $CodeSource != FALSE )
				{
				if ( preg_match("#pub-3624271267101348#sUi", $CodeSource) )
					{
					if ( $ListDomaine[$i]["Bridage"] == "Oui" )
						{
						$MajDomaine = $ConnexionPanel->Update("domaine", array("Bridage", "Regeneration"), array("Non", "Oui"), "Adresse='".$ListDomaine[$i]["Adresse"]."'");
						if ( $MajDomaine != FALSE )
							{
							echo "\t\t\t[OK]\n";
							}
						else
							{
							echo "\t\t\t[ERREUR 2]\n";
							}
						}
					else	
						{
						echo "\t\t\t[OK]\n";
						}
					}	
				else
					{
					if ( $ListDomaine[$i]["Bridage"] == "Non" )
						{
						$MajDomaine = $ConnexionPanel->Update("domaine", array("Bridage", "Regeneration"), array("Oui", "Oui"), "Adresse='".$ListDomaine[$i]["Adresse"]."'");
						if ( $MajDomaine != FALSE )
							{
							echo "\t\t\t[OK]\n";
							}
						else
							{
							echo "\t\t\t[ERREUR 4]\n";
							}
						}
					else
						{
						echo "\t\t\t[OK]\n";
						}
					}			
				}
			else
				{
				echo "\t\t\t[ERREUR 1]\n";
				}
			}
		else
			{
			$MajDomaine = $ConnexionPanel->Update("domaine", "Status", "3", "Adresse='".$ListDomaine[$i]["Adresse"]."'");
			if ( $MajDomaine != FALSE )
				{
				echo "\t\t\t[OK]\n";
				}
			else
				{
				echo "\t\t\t[ERREUR 3]\n";
				}
			}
		}
	}
else
	{
	echo "Aucun domaine a controler (bug ?)\n";
	}

?>