<?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. 
*/

// Librairie contenant l'ajout de domaine

if ( VerifPOST("Adresse", "#^[a-z0-9.-]+\.[a-z]+$#", 5, 120) == "ChaineValide" )
	{
	if ( VerifPOST("Adresse", "#kelio\.org#", 5, 120) == "ChaineValide")
		{
		$_SESSION['Resultat'] = "Vous ne pouvez pas utiliser Kelio dans vos domaines !!!";
		$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
		Redirect ('resultat.html');
		}
	else
		{
		if ( (VerifPOST("Racine", "#^/[.a-z0-9/_-]+/$#", 1, 120) == "ChaineValide") or 
			 (VerifPOST("Racine", "#^/$#", 1, 120) == "ChaineValide") )
			{
			if ( (VerifPOST("BaseDir", "#^/[.a-z0-9/_-]+/$#", 1, 120) == "ChaineValide") or 
				 (VerifPOST("BaseDir", "#^/$#", 1, 120) == "ChaineValide") )
				{
				if ( (VerifPOST("Commentaire", "#^[a-z0-9 ]+$#i", 1, 50) == "ChaineValide") or 
					 (VerifPOST("Commentaire", "#^[a-z0-9]+$#i", 1, 50) == "ChaineVide") )
					{
					if ( VerifPOST("Listage", "#^Oui|Non$#", 3, 3) == "ChaineValide" )
						{
						if ( (VerifPOST("mysqldefault_host", "#^[a-z0-9.-]+\.[a-z]+$#", 5, 50) == "ChaineValide") or 
							 (VerifPOST("mysqldefault_host", "#^[a-z0-9.-]+\.[a-z]+$#", 5, 50) == "ChaineVide") )
							{
							if ( (VerifPOST("mysqldefault_user", "#^[a-z0-9_]+$#", 3, 16) == "ChaineValide") or 
								 (VerifPOST("mysqldefault_user", "#^[a-z0-9_]+$#", 3, 16) == "ChaineVide") )
								{
								if ( (VerifPOST("mysqldefault_password", "#^[a-z0-9]+$#", 3, 16) == "ChaineValide") or 
								     (VerifPOST("mysqldefault_password", "#^[a-z0-9]+$#", 3, 16) == "ChaineVide") )
									{
									if ( (VerifPOST("temporaire", "#^/[a-z0-9/_-]+/$#", 1, 120) == "ChaineValide") or 
										 (VerifPOST("temporaire", "#^/[a-z0-9/_-]+/$#", 1, 120) == "ChaineVide") )
										{
										if ( (VerifPOST("sessions", "#^/[a-z0-9/_-]+/$#", 1, 120) == "ChaineValide") or 
										     (VerifPOST("sessions", "#^/[a-z0-9/_-]+/$#", 1, 120) == "ChaineVide") )
											{
											if ( VerifPOST("allow_url_fopen", "#^Oui|Non$#", 3, 3) == "ChaineValide" )
												{
												if ( VerifPOST("allow_url_include", "#^Oui|Non$#", 3, 3) == "ChaineValide" )
													{
													if ( VerifPOST("display_errors", "#^Oui|Non$#", 3, 3) == "ChaineValide" )
														{
														if ( VerifPOST("short_open_tag", "#^Oui|Non$#", 3, 3) == "ChaineValide" )
															{
															if ( VerifPOST("sessionauto_start", "#^Oui|Non$#", 3, 3) == "ChaineValide" )
																{
																if ( VerifPOST("magic_quotes_gpc", "#^Oui|Non$#", 3, 3) == "ChaineValide" )
																	{
																	if ( VerifPOST("register_globals", "#^Oui|Non$#", 3, 3) == "ChaineValide" )
																		{
																		$DetecteServeur = $MySql->Select ("*", "utilisateur", "Utilisateur='".$_SESSION['Utilisateur']."'", "", "", "", "");
																		$VerificatinIP = gethostbyname ($_POST['Adresse']);
																		if ( $VerificatinIP == gethostbyname($DetecteServeur[0]["ServeurFichier"]) )
																			{
																			$VerificationExistance = $MySql->Select ("*", "domaine", "Adresse='".$_POST["Adresse"]."'", "", "", "", "");
																			if ( $VerificationExistance == FALSE )
																				{
																					$ListTable = $MySql->Select ("*", "domaine", "Utilisateur='".$_SESSION['Utilisateur']."'", "", "", "", "");
																					$CountEnregistrement = count ($ListTable);
																					if ( ($CountEnregistrement >= $_SESSION['Offre']['Domaine']) and ($_SESSION['Offre']['Domaine'] != '-1') ) {
																						$_SESSION['Resultat'] = "Désolé, votre offre ne vous permet pas d'ajouter plus de domaine(s).";
																						$_SESSION['Lien'] = "Page-Domaine-SuppressionDomaineExterne.html";
																						Redirect ('resultat.html');
																					}	else {																				
																						$Conteneur = "Utilisateur, Adresse, OpenBasedir, Racine, Status, Listage, Commentaire, DateDeCreation, MysqlDefaultHost, MysqlDefaultUser, MysqlDefaultPassword, tmp, sessions, Allow_url_fopen, Allow_url_include, Session_auto_start, Magic_quotes_gpc, Register_globals, DisplayErrors, Short_Open_Tag";
																						$Contenu = "'".$_SESSION['Utilisateur']."', '".$_POST['Adresse']."', '".$_POST['BaseDir']."', '".$_POST['Racine']."', '1', '".$_POST['Listage']."', '".$_POST['Commentaire']."', '".time()."', '".$_POST['mysqldefault_host']."', '".$_POST['mysqldefault_user']."', '".$_POST['mysqldefault_password']."', '".$_POST['temporaire']."', '".$_POST['sessions']."', '".$_POST['allow_url_fopen']."', '".$_POST['allow_url_include']."', '".$_POST['sessionauto_start']."', '".$_POST['magic_quotes_gpc']."', '".$_POST['register_globals']."', '".$_POST['display_errors']."', '".$_POST['short_open_tag']."'";
																				
																						$MySql->Insert($Conteneur, $Contenu, 'domaine');
																						Redirect ('Page-Domaine-Recapitulatif.html');	
																					}
																				}
																			else
																				{
																				$_SESSION['Resultat'] = "Le domaine existe deja sur un des serveurs";
																				$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
																				Redirect ('resultat.html');
																				}
																			}
																		else
																			{
																			$_SESSION['Resultat'] = "Le domaine ne pointe pas sur le serveur";
																			$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
																			Redirect ('resultat.html');
																			}
																		} // Fin de la verif register_globals
																	else
																		{
																		$_SESSION['Resultat'] = "L'option php 'register_globals' est incorrecte.";
																		$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
																		Redirect ('resultat.html');
																		}
																	} // Fin de la verif magic_quotes_gpc
																else
																	{
																	$_SESSION['Resultat'] = "L'option php 'magic_quotes_gpc' est incorrecte.";
																	$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
																	Redirect ('resultat.html');
																	}
																} // Fin de la verif sessionauto_start
															else
																{
																$_SESSION['Resultat'] = "L'option php 'session.auto_start' est incorrecte.";
																$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
																Redirect ('resultat.html');
																}
															} // Fin de la verif short_open_tag
														else
															{
															$_SESSION['Resultat'] = "L'option php 'short_open_tag' est incorrecte.";
															$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
															Redirect ('resultat.html');
															}
														} // Fin de la verif display_errors
													else
														{
														$_SESSION['Resultat'] = "L'option php 'display_errors' est incorrecte.";
														$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
														Redirect ('resultat.html');
														}
													} // Fin de la verif allow_url_include
												else
													{
													$_SESSION['Resultat'] = "L'option php 'allow_url_include' est incorrecte.";
													$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
													Redirect ('resultat.html');
													}
												} // Fin de la verif du allow_url_fopen
											else
												{
												$_SESSION['Resultat'] = "L'option php 'allow_url_fopen' est incorrecte.";
												$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
												Redirect ('resultat.html');
												}
											} // Fin de la verif du dossier sessions
										else
											{
											$_SESSION['Resultat'] = "Le dossier sessions est invalide. (il doit commencer et finir par /)";
											$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
											Redirect ('resultat.html');
											}
										} // Fin de la verif du dossier temporaire
									else
										{
										$_SESSION['Resultat'] = "Le dossier temporaire est invalide. (il doit commencer et finir par /)";
										$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
										Redirect ('resultat.html');
										}
									} // Fin de la verif sql pass
								else
									{
									$_SESSION['Resultat'] = "Le mot de passe pour la base de données mysql est invalide.";
									$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
									Redirect ('resultat.html');
									}
								} // Fin de la verif sql user
							else
								{
								$_SESSION['Resultat'] = "L'utilisateur pour la base de données mysql est invalide.";
								$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
								Redirect ('resultat.html');
								}
							} // Fin de la verif sql adresse							
						else
							{
							$_SESSION['Resultat'] = "L'adresse du serveur mysql est invalide.";
							$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
							Redirect ('resultat.html');
							}
						}
					else
						{
						$_SESSION['Resultat'] = "Le listage est incorrect.";
						$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
						Redirect ('resultat.html');
						}
					}
				else
					{
					$_SESSION['Resultat'] = "Le commentaire est incorrect.";
					$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
					Redirect ('resultat.html');
					}
				}
			else
				{
				$_SESSION['Resultat'] = "Le BaseDir est incorrect (il doit commencer et finir par /)";
				$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
				Redirect ('resultat.html');
				}
			}
		else
			{
			$_SESSION['Resultat'] = "La racine est incorrecte (il doit commencer et finir par /)";
			$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
			Redirect ('resultat.html');
			}
		}
	}
else
	{
	$_SESSION['Resultat'] = "L'adresse est incorrecte";
	$_SESSION['Lien'] = "Page-Domaine-AjoutDomaineExterne.html";
	Redirect ('resultat.html');
	}





?>
