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

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

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

	<variables>
        <family name='nineboard' icon='edit'>
            <variable name="ninegate_test_ninegate" type="oui/non" hidden='True' exists='False'><value>non</value></variable>
            <variable name="activer_etherpad" type="oui/non" description="Activer Etherpad" hidden='True' exists='False'><value>non</value></variable>
            <variable name="activer_ethercalc" type="oui/non" description="Activer Ethercalc" 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_nineboard' type='oui/non' description='Activer Nineboard'>
				<value>oui</value>
			</variable>

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


            <!-- LDAP -->
            <variable type='string' name='nineboard_ldaptemplate' description="Modèle d'annuaire"><value>scribe</value></variable>
            <variable type='string' name='nineboard_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='nineboard_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='nineboard_ldapuid' description="Attribut LDAP uid" mandatory='True'><value>uid</value></variable>
            <variable type='string' name='nineboard_ldapfirstname' description="Attribut LDAP firstname" mandatory='True'><value>givenname</value></variable>
            <variable type='string' name='nineboard_ldaplastname' description="Attribut LDAP lastname" mandatory='True'><value>sn</value></variable>
            <variable type='string' name='nineboard_ldapmail' description="Attribut LDAP email" mandatory='True'><value>mail</value></variable>

            <!-- ETHERPAD -->
            <variable type="oui/non" name='nineboard_activate_etherpad' description='Activer Etherpad'  mandatory='True'>
                <value>non</value>
            </variable>
            <variable type='string' name='nineboard_etherpad_url' description='URL complète de votre Etherpad'  mandatory='True' />
            <variable type='string' name='nineboard_etherpad_key' description='Fichier API Key de votre Etherpad'  mandatory='True' />

            <!-- ETHERCALC -->
            <variable type="oui/non" name='nineboard_activate_ethercalc' description='Activer Ethercalc'  mandatory='True'>
                <value>non</value>
            </variable>
            <variable type='string' name='nineboard_ethercalc_url' description='URL complète de votre Ethercalc'  mandatory='True' />
            
            <!-- EMAIL -->
            <variable type='string' name='nineboard_noreply' description='Adresse mail utilisé pour le noreply' mandatory='True' />
            <variable type="oui/non" name='nineboard_activer_localmail' description="Utiliser le serveur d'envoi de mail local" mandatory='True'>
                <value>oui</value>
            </variable>
            <variable type='string' name='nineboard_smtphost' description='Host du serveur SMTP' mandatory='True' />
            <variable type='string' name='nineboard_smtpport' description='Port du serveur SMTP' mandatory='True' />
            <variable type='string' name='nineboard_smtpuser' description='Compte du serveur SMTP' mandatory='True' />
            <variable type='string' name='nineboard_smtppwd' description='Mot de passe associé du compte SMTP' mandatory='True' />
            <variable type='string' name='nineboard_smtpencryption' description='Type Encryptage du serveur SMTP' mandatory='True' />
            <variable type='string' name='nineboard_smtpauthmode' description='Mode Authentification du serveur SMTP' mandatory='True' />
        </family>

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

        <separators>
            <separator name="nineboard_ldaptemplate">Paramètres associés à l'Annuaire</separator>
            <separator name="nineboard_noreply">Paramètres associés aux Mails</separator>
            <separator name="nineboard_db_mode">Paramètres EoleDB associés à Nineboard</separator>
        </separators> 
	</variables>

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

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

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

            <target type='variable'>nineboard_masteridentity</target>
            <target type='variable'>nineboard_urlidentity</target>
            <target type='variable'>nineboard_apikeyidentity</target>

            <target type='variable'>nineboard_mode_auth</target>
            <target type='variable'>nineboard_ldaptemplate</target>

            <target type='variable'>nineboard_activate_etherpad</target>
            <target type='variable'>nineboard_activate_ethercalc</target>

            <target type='variable'>nineboard_noreply</target>
            <target type='variable'>nineboard_activer_localmail</target>
            <target type='variable'>nineboard_smtphost</target>
            <target type='variable'>nineboard_smtpport</target>
            <target type='variable'>nineboard_smtpuser</target>
            <target type='variable'>nineboard_smtppwd</target>
            <target type='variable'>nineboard_smtpencryption</target>
            <target type='variable'>nineboard_smtpauthmode</target>

            <target type='variable'>nineboard_db_mode</target>
            <target type='variable'>nineboard_dbserver</target>
            <target type='variable'>nineboard_dbport</target>
            <target type='variable'>nineboard_allow_hosts</target>
            <target type='variable'>nineboard_dbuser</target>
            <target type='variable'>nineboard_dbpass</target>

			<target type='filelist'>nineboard</target>
            <target type='filelist'>nineboard_nginx</target>
			<target type='servicelist'>nineboard</target>
		</condition>


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

            <target type='variable'>nineboard_urlidentity</target>
            <target type='variable'>nineboard_apikeyidentity</target>
        </condition>  

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

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

        <!-- AFFICHAGE EN FONCTION D'ETHERPAD -->
        <fill name='calc_multi_condition' target='nineboard_activate_etherpad'>
            <param>oui</param>
            <param type='eole' name='condition_1' hidden='False'>activer_etherpad</param>
            <param name='match'>oui</param>
            <param name='mismatch'>non</param>
            <param name='default_mismatch'>non</param>
        </fill>

        <condition name='hidden_if_in' source='nineboard_activate_etherpad'>
            <param>non</param>

            <target type='variable'>nineboard_etherpad_url</target>
            <target type='variable'>nineboard_etherpad_key</target>
        </condition>   

        <fill name='calc_multi_condition' target='nineboard_etherpad_url'>
            <param>oui</param>
            <param type='eole' name='condition_1' hidden='False'>activer_etherpad</param>
            <param name='match'>/etherpad/</param>
            <param name='default_mismatch'>None</param>
        </fill>

        <fill name='calc_multi_condition' target='nineboard_etherpad_key'>
            <param>oui</param>
            <param type='eole' name='condition_1' hidden='False'>activer_etherpad</param>
            <param name='match'>/usr/share/eole/nodejs/etherpad/APIKEY.txt</param>
            <param name='default_mismatch'>/root/.etherpad</param>
        </fill>

        <!-- AFFICHAGE EN FONCTION D'ETHERCALC -->
        <fill name='calc_multi_condition' target='nineboard_activate_ethercalc'>
            <param>oui</param>
            <param type='eole' name='condition_1' hidden='False'>activer_ethercalc</param>
            <param name='match'>oui</param>
            <param name='mismatch'>non</param>
            <param name='default_mismatch'>non</param>
        </fill>

        <condition name='hidden_if_in' source='nineboard_activate_ethercalc'>
            <param>non</param>

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

        <fill name='calc_multi_condition' target='nineboard_ethercalc_url'>
            <param>oui</param>
            <param type='eole' name='condition_1' hidden='False'>activer_ethercalc</param>
            <param name='match'>/ethercalc/</param>
            <param name='default_mismatch'>None</param>
        </fill>

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

            <target type='variable'>nineboard_ldapfiltergroup</target>
            <target type='variable'>nineboard_ldapfilteruser</target>
            <target type='variable'>nineboard_ldapuid</target>
            <target type='variable'>nineboard_ldapfirstname</target>
            <target type='variable'>nineboard_ldaplastname</target>
            <target type='variable'>nineboard_ldapmail</target>
        </condition>


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

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

            <target type='variable'>nineboard_smtphost</target>
            <target type='variable'>nineboard_smtpport</target>
            <target type='variable'>nineboard_smtpuser</target>
            <target type='variable'>nineboard_smtppwd</target>
            <target type='variable'>nineboard_smtpencryption</target>
            <target type='variable'>nineboard_smtpauthmode</target>
        </condition>


        <!-- AFFICHAGE EN FONCTION DU MODE DE BDD -->
        <condition name='disabled_if_in' source='nineboard_db_mode'>
            <param>local</param>
            <target type='variable'>nineboard_dbserver</target>
            <target type='variable'>nineboard_dbuser</target>
            <target type='variable'>nineboard_dbport</target>
            <target type='variable'>nineboard_dbpass</target>
        </condition>
        <condition name='disabled_if_in' source='nineboard_db_mode'>
            <param>default</param>
            <target type='variable'>nineboard_dbserver</target>
            <target type='variable'>nineboard_dbuser</target>
            <target type='variable'>nineboard_dbport</target>
            <target type='variable'>nineboard_dbpass</target>
            <target type='variable'>nineboard_allow_hosts</target>
        </condition>


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

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

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

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

	</constraints>

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