<?php
	
	//--------------------------------------------------------------------------------------------------------
	// initialisation des variables
	//--------------------------------------------------------------------------------------------------------
	$Flag_debug_1 = 1;
	$Flag_debug_1 = 0;

	$code_erreur = 0;
	$NB_users   = 0 ;
	
	//--------------------------------------------------------------------------------------------------------
	// connexion à la base de données
	//--------------------------------------------------------------------------------------------------------
	$mysql_base ='AQCM05_main' ;
	$link = mysqli_connect($mysql_host,$mysql_user,$mysql_password, $mysql_base);
	
	if ( ! $link ) {
		
		$code_erreur = 100;
		
		if ($Flag_debug_1 == 1) {
			echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo '</br>';
			echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; echo '</br>';
		}

		echo "Connexion impossible à la base de donnée MySQL !" . PHP_EOL; echo '</br>';
		exit($code_erreur);
	}

	//--------------------------------------------------------------------------------------------------------
	// recherche des sondes du site demandé
	//--------------------------------------------------------------------------------------------------------
	$query = "
		SELECT aqcm_WG_Server_Address,aqcm_WG_server_AllowedIPs,aqcm_WG_URL,aqcm_WG_ListenPort,aqcm_WG_Keepalive,aqcm_WG_Server_PublicKey,aqcm_WG_Server_PrivateKey 
		FROM AQCM05_WG_SERVER 
		WHERE (idx=1)
		";

	if ($Flag_debug_1 == 1) {
		echo $query . "</br>" ;
	}

	$result_configuration = mysqli_query($link, $query); 
	
	if ( ! $result_configuration ) {
		
		$code_erreur = 11;
		
	} else {
		
		if ( mysqli_num_rows($result_configuration) != 1 ) {	
			$code_erreur = 12;
			
		} else {
			
			if ($row = mysqli_fetch_array($result_configuration, MYSQLI_BOTH)) {

				$aqcm_WG_Server_Address = $row["aqcm_WG_Server_Address"] ;
				$aqcm_WG_server_AllowedIPs = $row["aqcm_WG_server_AllowedIPs"] ;
				$aqcm_WG_URL = $row["aqcm_WG_URL"] ;
				$aqcm_WG_ListenPort = $row["aqcm_WG_ListenPort"] ;
				$aqcm_WG_Keepalive = $row["aqcm_WG_Keepalive"] ;
				$aqcm_WG_Server_PublicKey = $row["aqcm_WG_Server_PublicKey"] ;
				$aqcm_WG_Server_PrivateKey = $row["aqcm_WG_Server_PrivateKey"] ;
				
			}
			else {
				$code_erreur = 13;
			}
		}
	}

	if ($Flag_debug_1 == 1) {
		if ( $code_erreur != 0 ) {
			echo "code erreur = " . strval($code_erreur) . "</br>";
		}
	}

	mysqli_close($link);

?>
