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

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

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

	<variables>
        <family name='ninesurvey' icon='ticket'>
            <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_ninesurvey' type='oui/non' description='Activer Ninesurvey'>
				<value>oui</value>
			</variable>

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


            <!-- LDAP -->
            <variable type='string' name='ninesurvey_ldaptemplate' description="Modèle d'annuaire"><value>scribe</value></variable>
            <variable type='string' name='ninesurvey_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='ninesurvey_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='ninesurvey_ldapuid' description="Attribut LDAP uid" mandatory='True'><value>uid</value></variable>
            <variable type='string' name='ninesurvey_ldapfirstname' description="Attribut LDAP firstname" mandatory='True'><value>givenname</value></variable>
            <variable type='string' name='ninesurvey_ldaplastname' description="Attribut LDAP lastname" mandatory='True'><value>sn</value></variable>
            <variable type='string' name='ninesurvey_ldapmail' description="Attribut LDAP email" mandatory='True'><value>mail</value></variable>

            <!-- EMAIL -->
            <variable type='string' name='ninesurvey_noreply' description='Adresse mail utilisé pour le noreply' mandatory='True' />
            <variable type="oui/non" name='ninesurvey_activer_localmail' description="Utiliser le serveur d'envoi de mail local" mandatory='True'>
                <value>oui</value>
            </variable>
            <variable type='string' name='ninesurvey_smtphost' description='Host du serveur SMTP' mandatory='True' />
            <variable type='string' name='ninesurvey_smtpport' description='Port du serveur SMTP' mandatory='True' />
            <variable type='string' name='ninesurvey_smtpuser' description='Compte du serveur SMTP' />
            <variable type='string' name='ninesurvey_smtppwd' description='Mot de passe associé du compte SMTP' />
            <variable type='string' name='ninesurvey_smtpencryption' description='Type Encryptage du serveur SMTP' />
            <variable type='string' name='ninesurvey_smtpauthmode' description='Mode Authentification du serveur SMTP' />
        </family>

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

        <separators>
            <separator name="ninesurvey_ldaptemplate">Paramètres associés à l'Annuaire</separator>
            <separator name="ninesurvey_noreply">Paramètres associés aux Mails</separator>
            <separator name="ninesurvey_db_mode">Paramètres EoleDB associés à Ninesurvey</separator>
        </separators> 
	</variables>

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

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

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

            <target type='variable'>ninesurvey_masteridentity</target>
            <target type='variable'>ninesurvey_urlidentity</target>
            <target type='variable'>ninesurvey_apikeyidentity</target>

            <target type='variable'>ninesurvey_mode_auth</target>
            <target type='variable'>ninesurvey_ldaptemplate</target>

            <target type='variable'>ninesurvey_noreply</target>
            <target type='variable'>ninesurvey_activer_localmail</target>
            <target type='variable'>ninesurvey_smtphost</target>
            <target type='variable'>ninesurvey_smtpport</target>
            <target type='variable'>ninesurvey_smtpuser</target>
            <target type='variable'>ninesurvey_smtppwd</target>
            <target type='variable'>ninesurvey_smtpencryption</target>
            <target type='variable'>ninesurvey_smtpauthmode</target>

            <target type='variable'>ninesurvey_db_mode</target>
            <target type='variable'>ninesurvey_dbserver</target>
            <target type='variable'>ninesurvey_dbport</target>
            <target type='variable'>ninesurvey_allow_hosts</target>
            <target type='variable'>ninesurvey_dbuser</target>
            <target type='variable'>ninesurvey_dbpass</target>

			<target type='filelist'>ninesurvey</target>
            <target type='filelist'>ninesurvey_nginx</target>
			<target type='servicelist'>ninesurvey</target>
		</condition>


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

            <target type='variable'>ninesurvey_urlidentity</target>
            <target type='variable'>ninesurvey_apikeyidentity</target>
        </condition>  

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

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


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

            <target type='variable'>ninesurvey_ldapfiltergroup</target>
            <target type='variable'>ninesurvey_ldapfilteruser</target>
            <target type='variable'>ninesurvey_ldapuid</target>
            <target type='variable'>ninesurvey_ldapfirstname</target>
            <target type='variable'>ninesurvey_ldaplastname</target>
            <target type='variable'>ninesurvey_ldapmail</target>
        </condition>


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

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

            <target type='variable'>ninesurvey_smtphost</target>
            <target type='variable'>ninesurvey_smtpport</target>
            <target type='variable'>ninesurvey_smtpuser</target>
            <target type='variable'>ninesurvey_smtppwd</target>
            <target type='variable'>ninesurvey_smtpencryption</target>
            <target type='variable'>ninesurvey_smtpauthmode</target>
        </condition>


        <!-- AFFICHAGE EN FONCTION DU MODE DE BDD -->
        <condition name='disabled_if_in' source='ninesurvey_db_mode'>
            <param>local</param>
            <target type='variable'>ninesurvey_dbserver</target>
            <target type='variable'>ninesurvey_dbuser</target>
            <target type='variable'>ninesurvey_dbport</target>
            <target type='variable'>ninesurvey_dbpass</target>
        </condition>
        <condition name='disabled_if_in' source='ninesurvey_db_mode'>
            <param>default</param>
            <target type='variable'>ninesurvey_dbserver</target>
            <target type='variable'>ninesurvey_dbuser</target>
            <target type='variable'>ninesurvey_dbport</target>
            <target type='variable'>ninesurvey_dbpass</target>
            <target type='variable'>ninesurvey_allow_hosts</target>
        </condition>


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

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

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

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

	</constraints>

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