<?xml version="1.0" encoding="utf-8"?>
<creole>
    <files>
        <file filelist='janus' name='/etc/eole/eole-db.d/janus-db.yml' rm='True' mkdir='True'/>
        <file filelist='janus_nginx' name='/etc/nginx/web.d/janus.conf' source='janus-nginx.conf' rm='True' mkdir='True' />   
    </files>

	<containers>
        <container name='web'>
            <package>janus-apps</package>
           
			<!-- service de configuration apache -->
			<service method="apache" servicelist="janus">janus</service>

			<!-- template -->
			<file filelist='janus' name='/etc/apache2/sites-available/janus' source='janus-apache.conf' />
			<file filelist='janus' name='/var/www/html/janus/.env.local' source='janus-env.local' rm='True'/>
            <file filelist='janus' name='/etc/cron.d/janus' source='janus.cron' rm='True'/>
		</container>
	</containers>

	<variables>
        <family name='janus' icon='male'>
            <variable name="ninegate_test_ninegate" type="oui/non" hidden='True' exists='False'><value>non</value></variable>
            <variable name="activer_revprox" type="oui/non" description="Activer le reverse proxy Nginx" hidden='True' exists='False'><value>non</value></variable>

			<variable name='activer_janus' type='oui/non' description='Activer Janus'>
				<value>oui</value>
			</variable>

            <variable type='string' name='janus_mode_auth' description="Mode Authentification" mandatory='True'><value>CAS</value></variable>
            <variable type='string' name='janus_masteridentity' description="Maître de l'Identité" mandatory='True'><value>Ninegate</value></variable>
            <variable type='string' name='janus_urlidentity' description="URL complète de l'Identité" mandatory='True'><value>/ninegate</value></variable>
            <variable type='string' name='janus_apikeyidentity' description="API Key de l'Identité" mandatory='True'><value>APIKeyNinegate</value></variable>


            <!-- LDAP -->
            <variable type='string' name='janus_ldaptemplate' description="Modèle d'annuaire"><value>scribe</value></variable>
            <variable type='string' name='janus_ldapfiltergroup' description="Filtre LDAP des groupes (bien mettre votre filtre entre parenthèses)" mandatory='True'><value>(&amp;(ObjectClass=posixGroup)(cn=*))</value></variable>
            <variable type='string' name='janus_ldapfilteruser' description="Filtre LDAP des utilisateurs (bien mettre votre filtre entre parenthèses)" mandatory='True'><value>(&amp;(ObjectClass=person)(uid=*))</value></variable>
            <variable type='string' name='janus_ldapuid' description="Attribut LDAP uid" mandatory='True'><value>uid</value></variable>
            <variable type='string' name='janus_ldapfirstname' description="Attribut LDAP firstname" mandatory='True'><value>givenname</value></variable>
            <variable type='string' name='janus_ldaplastname' description="Attribut LDAP lastname" mandatory='True'><value>sn</value></variable>
            <variable type='string' name='janus_ldapmail' description="Attribut LDAP email" mandatory='True'><value>mail</value></variable>

            <!-- EMAIL -->
            <variable type='string' name='janus_noreply' description='Adresse mail utilisé pour le noreply' mandatory='True' />
            <variable type="oui/non" name='janus_activer_localmail' description="Utiliser le serveur d'envoi de mail local" mandatory='True'>
                <value>oui</value>
            </variable>
            <variable type='string' name='janus_smtphost' description='Host du serveur SMTP' mandatory='True' />
            <variable type='string' name='janus_smtpport' description='Port du serveur SMTP' mandatory='True' />
            <variable type='string' name='janus_smtpuser' description='Compte du serveur SMTP' mandatory='True' />
            <variable type='string' name='janus_smtppwd' description='Mot de passe associé du compte SMTP' mandatory='True' />
            <variable type='string' name='janus_smtpencryption' description='Type Encryptage du serveur SMTP' mandatory='True' />
            <variable type='string' name='janus_smtpauthmode' description='Mode Authentification du serveur SMTP' mandatory='True' />
        </family>

        <family name='EoleDB' icon='database' mode='expert'>
            <variable type='string' name='janus_db_mode' description='Serveur de bases de données à utiliser' mode='expert'/>
            <variable type='string' name='janus_dbserver' description='Adresse du serveur de base de données' mode='expert'/>
            <variable type='number' name='janus_dbport' description="Port d'écoute du serveur de base de données" mode='expert'/>
            <variable type='string' name='janus_allow_hosts' description="Hôtes autorisés à utiliser la base de données" multi='True' mode='expert'/>
            <variable type='string' name='janus_dbuser' description='Utilisateur du serveur de base de données' mode='expert'/>
            <variable type='string' name='janus_dbpass' description='Fichier de mot de passe du serveur' mode='expert'/>
        </family>

        <separators>
            <separator name="janus_ldaptemplate">Paramètres associés à l'Annuaire</separator>
            <separator name="janus_noreply">Paramètres associés aux Mails</separator>
            <separator name="janus_db_mode">Paramètres EoleDB associés à Janus</separator>
        </separators> 
	</variables>

	<constraints>
        <!-- AFFICHAGE EN FONCTION DE APACHE -->
        <condition name='hidden_if_in' source='activer_apache'>
            <param>non</param>
            <target type='filelist'>janus</target>
            <target type='filelist'>janus_nginx</target>
            <target type='servicelist'>janus</target>
        </condition>

        <!-- AFFICHAGE EN FONCTION DE REVERSE PROXY -->
        <condition name='hidden_if_in' source='activer_revprox'>
            <param>non</param>
            <target type='filelist'>janus_nginx</target>
        </condition>

        <!-- AFFICHAGE EN FONCTION DE janus -->
		<condition name='hidden_if_in' source='activer_janus'>
			<param>non</param>

            <target type='variable'>janus_masteridentity</target>
            <target type='variable'>janus_urlidentity</target>
            <target type='variable'>janus_apikeyidentity</target>

            <target type='variable'>janus_mode_auth</target>
            <target type='variable'>janus_ldaptemplate</target>

            <target type='variable'>janus_noreply</target>
            <target type='variable'>janus_activer_localmail</target>
            <target type='variable'>janus_smtphost</target>
            <target type='variable'>janus_smtpport</target>
            <target type='variable'>janus_smtpuser</target>
            <target type='variable'>janus_smtppwd</target>
            <target type='variable'>janus_smtpencryption</target>
            <target type='variable'>janus_smtpauthmode</target>

            <target type='variable'>janus_db_mode</target>
            <target type='variable'>janus_dbserver</target>
            <target type='variable'>janus_dbport</target>
            <target type='variable'>janus_allow_hosts</target>
            <target type='variable'>janus_dbuser</target>
            <target type='variable'>janus_dbpass</target>

			<target type='filelist'>janus</target>
            <target type='filelist'>janus_nginx</target>
			<target type='servicelist'>janus</target>
		</condition>


        <!-- AFFICHAGE EN FONCTION DE NINEGATE -->
        <fill name='calc_multi_condition' target='janus_masteridentity'>
            <param>oui</param>

            <param type='eole' name='condition_1' hidden='False'>ninegate_test_ninegate</param>
            <param name='match'>Ninegate</param>
            <param name='mismatch'>LDAP</param>
            <param name='default_mismatch'>LDAP</param>
        </fill>


        <!-- AFFICHAGE EN FONCTION DU MASTERIDENTITY -->
        <condition name='hidden_if_in' source='janus_masteridentity'>
            <param>LDAP</param>

            <target type='variable'>janus_urlidentity</target>
            <target type='variable'>janus_apikeyidentity</target>
        </condition>  

        <condition name='hidden_if_in' source='janus_masteridentity'>
            <param>Ninegate</param>

            <target type='variable'>janus_ldaptemplate</target>
        </condition>


        <!-- AFFICHAGE EN FONCTION DU LDAP -->
        <condition name='hidden_if_in' source='janus_ldaptemplate'>
            <param>scribe</param>

            <target type='variable'>janus_ldapfiltergroup</target>
            <target type='variable'>janus_ldapfilteruser</target>
            <target type='variable'>janus_ldapuid</target>
            <target type='variable'>janus_ldapfirstname</target>
            <target type='variable'>janus_ldaplastname</target>
            <target type='variable'>janus_ldapmail</target>
        </condition>


        <!-- AFFICHAGE EN FONCTION DU MAIL -->
        <fill name='concat' target='janus_noreply'>
            <param>noreply@</param>
            <param type='eole'>domaine_messagerie_etab</param>
        </fill>

        <condition name='hidden_if_in' source='janus_activer_localmail'>
            <param>oui</param>

            <target type='variable'>janus_smtphost</target>
            <target type='variable'>janus_smtpport</target>
            <target type='variable'>janus_smtpuser</target>
            <target type='variable'>janus_smtppwd</target>
            <target type='variable'>janus_smtpencryption</target>
            <target type='variable'>janus_smtpauthmode</target>
        </condition>


        <!-- AFFICHAGE EN FONCTION DU MODE DE BDD -->
        <condition name='disabled_if_in' source='janus_db_mode'>
            <param>local</param>
            <target type='variable'>janus_dbserver</target>
            <target type='variable'>janus_dbuser</target>
            <target type='variable'>janus_dbport</target>
            <target type='variable'>janus_dbpass</target>
        </condition>
        <condition name='disabled_if_in' source='janus_db_mode'>
            <param>default</param>
            <target type='variable'>janus_dbserver</target>
            <target type='variable'>janus_dbuser</target>
            <target type='variable'>janus_dbport</target>
            <target type='variable'>janus_dbpass</target>
            <target type='variable'>janus_allow_hosts</target>
        </condition>


        <!-- VALID EMUN DES DIFFRENTES COMBO -->
        <check name='valid_enum' target='janus_masteridentity'>
            <param>['LDAP','Ninegate']</param>
        </check>

        <check name='valid_enum' target='janus_mode_auth'>
            <param>['CAS', 'LDAP', 'SQL']</param>
        </check>
        
        <check name='valid_enum' target='janus_ldaptemplate'>
            <param>['scribe','open']</param>
        </check>

        <check name='valid_enum' target='janus_smtpencryption'>
            <param>['tls', 'ssl', 'null']</param>
        </check>
        <check name='valid_enum' target='janus_smtpauthmode'>
            <param>['plain', 'login', 'cram-md5', 'null']</param>
        </check>

        <check name='valid_enum' target='janus_db_mode'>
            <param>['default', 'externe', 'local']</param>
        </check>    
	</constraints>
</creole>
