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

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

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

	<variables>
        <family name='nineschool' icon='eye-open'>
            <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_nineschool' type='oui/non' description='Activer Nineschool'>
				<value>oui</value>
			</variable>

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


            <!-- LDAP -->
            <variable type='string' name='nineschool_ldaptemplate' description="Modèle d'annuaire"><value>scribe</value></variable>
            <variable type='string' name='nineschool_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='nineschool_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='nineschool_ldapuid' description="Attribut LDAP uid" mandatory='True'><value>uid</value></variable>
            <variable type='string' name='nineschool_ldapfirstname' description="Attribut LDAP firstname" mandatory='True'><value>givenname</value></variable>
            <variable type='string' name='nineschool_ldaplastname' description="Attribut LDAP lastname" mandatory='True'><value>sn</value></variable>
            <variable type='string' name='nineschool_ldapmail' description="Attribut LDAP email" mandatory='True'><value>mail</value></variable>

            <!-- EMAIL -->
            <variable type='string' name='nineschool_noreply' description='Adresse mail utilisé pour le noreply' mandatory='True' />
            <variable type="oui/non" name='nineschool_activer_localmail' description="Utiliser le serveur d'envoi de mail local" mandatory='True'>
                <value>oui</value>
            </variable>
            <variable type='string' name='nineschool_smtphost' description='Host du serveur SMTP' mandatory='True' />
            <variable type='string' name='nineschool_smtpport' description='Port du serveur SMTP' mandatory='True' />
            <variable type='string' name='nineschool_smtpuser' description='Compte du serveur SMTP' mandatory='True' />
            <variable type='string' name='nineschool_smtppwd' description='Mot de passe associé du compte SMTP' mandatory='True' />
            <variable type='string' name='nineschool_smtpencryption' description='Type Encryptage du serveur SMTP' mandatory='True' />
            <variable type='string' name='nineschool_smtpauthmode' description='Mode Authentification du serveur SMTP' mandatory='True' />
        </family>

        <family name='EoleDB' icon='database' mode='expert'>
            <!-- BDD -->
            <variable type='string' name='nineschool_db_mode' description='Serveur de bases de données à utiliser' mode='expert'/>
            <variable type='string' name='nineschool_dbserver' description='Adresse du serveur de base de données' mode='expert'/>
            <variable type='number' name='nineschool_dbport' description="Port d'écoute du serveur de base de données" mode='expert'/>
            <variable type='string' name='nineschool_allow_hosts' description="Hôtes autorisés à utiliser la base de données" multi='True' mode='expert'/>
            <variable type='string' name='nineschool_dbuser' description='Utilisateur du serveur de base de données' mode='expert'/>
            <variable type='string' name='nineschool_dbpass' description='Fichier de mot de passe du serveur' mode='expert'/>
        </family>

        <separators>
            <separator name="nineschool_ldaptemplate">Paramètres associés à l'Annuaire</separator>
            <separator name="nineschool_noreply">Paramètres associés aux Mails</separator>
            <separator name="nineschool_db_mode">Paramètres EoleDB associés à Nineschool</separator>
        </separators> 
	</variables>

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

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

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

            <target type='variable'>nineschool_masteridentity</target>
            <target type='variable'>nineschool_urlidentity</target>
            <target type='variable'>nineschool_apikeyidentity</target>

            <target type='variable'>nineschool_mode_auth</target>
            <target type='variable'>nineschool_ldaptemplate</target>

            <target type='variable'>nineschool_noreply</target>
            <target type='variable'>nineschool_activer_localmail</target>
            <target type='variable'>nineschool_smtphost</target>
            <target type='variable'>nineschool_smtpport</target>
            <target type='variable'>nineschool_smtpuser</target>
            <target type='variable'>nineschool_smtppwd</target>
            <target type='variable'>nineschool_smtpencryption</target>
            <target type='variable'>nineschool_smtpauthmode</target>

            <target type='variable'>nineschool_db_mode</target>
            <target type='variable'>nineschool_dbserver</target>
            <target type='variable'>nineschool_dbport</target>
            <target type='variable'>nineschool_allow_hosts</target>
            <target type='variable'>nineschool_dbuser</target>
            <target type='variable'>nineschool_dbpass</target>

			<target type='filelist'>nineschool</target>
            <target type='filelist'>nineschool_nginx</target>
			<target type='servicelist'>nineschool</target>
		</condition>


        <!-- AFFICHAGE EN FONCTION DE NINEGATE -->
        <fill name='calc_multi_condition' target='nineschool_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='nineschool_masteridentity'>
            <param>LDAP</param>

            <target type='variable'>nineschool_urlidentity</target>
            <target type='variable'>nineschool_apikeyidentity</target>
        </condition>  

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

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


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

            <target type='variable'>nineschool_ldapfiltergroup</target>
            <target type='variable'>nineschool_ldapfilteruser</target>
            <target type='variable'>nineschool_ldapuid</target>
            <target type='variable'>nineschool_ldapfirstname</target>
            <target type='variable'>nineschool_ldaplastname</target>
            <target type='variable'>nineschool_ldapmail</target>
        </condition>


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

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

            <target type='variable'>nineschool_smtphost</target>
            <target type='variable'>nineschool_smtpport</target>
            <target type='variable'>nineschool_smtpuser</target>
            <target type='variable'>nineschool_smtppwd</target>
            <target type='variable'>nineschool_smtpencryption</target>
            <target type='variable'>nineschool_smtpauthmode</target>
        </condition>


        <!-- AFFICHAGE EN FONCTION DU MODE DE BDD -->
        <condition name='disabled_if_in' source='nineschool_db_mode'>
            <param>local</param>
            <target type='variable'>nineschool_dbserver</target>
            <target type='variable'>nineschool_dbuser</target>
            <target type='variable'>nineschool_dbport</target>
            <target type='variable'>nineschool_dbpass</target>
        </condition>
        <condition name='disabled_if_in' source='nineschool_db_mode'>
            <param>default</param>
            <target type='variable'>nineschool_dbserver</target>
            <target type='variable'>nineschool_dbuser</target>
            <target type='variable'>nineschool_dbport</target>
            <target type='variable'>nineschool_dbpass</target>
            <target type='variable'>nineschool_allow_hosts</target>
        </condition>


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

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

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

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

	</constraints>

	<help>
		<variable name='activer_nineschool'>Skelete application Nine</variable>
	</help>
</creole>
