<?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'/>
    </files>

    <containers>
        <container name='web'>
            <package>nineboard-apps</package>

            <file filelist='nineboard' name='/etc/apache2/sites-available/nineboard' source='nineboard-apache.conf' rm="True"/>
            <file filelist="nineboard" name="/var/www/html/nineboard/app/config/parameters.yml" source="nineboard-parameters.yml" rm="True"/>
            <file filelist="nineboard" name="/var/www/html/nineboard/app/config/template.yml" source="nineboard-template.yml" rm="True"/>
            <file filelist="nineboard" name="/var/www/html/nineboard/scripts/nineboard-postservice-00.sh" source="nineboard-postservice-00.sh" rm="True" mode="700" />
            <file filelist="nineboard" name="/var/www/html/nineboard/src/Cadoles/CoreBundle/Command/data/core-init-01.sql" source="nineboard-init-01.sql" rm="True"/>
            <file filelist='nineboard' name='/etc/cron.d/nineboard' source='nineboard.cron' rm='True'/>

            <service method='apache' servicelist='nineboard'>nineboard</service>

            <service_access service='nineboard_websocket'>
                <port port_type="SymLinkOption">nineboard_websocket_portexterne</port>
            </service_access>

        </container>
    </containers>

    <variables>
        <family name='nineboard'>
            <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>

            <!-- BASIQUE -->
            <variable type='oui/non' name='activer_nineboard' description='Activer Nineboard'><value>oui</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>
            <variable type='string' name='nineboard_mode_auth' description="Mode Authentification" mandatory='True'><value>CAS</value></variable>
            <variable type='string' name='nineboard_api_key' description="Clé d'accès API" mandatory='True'><value>APIKeyNineboard</value></variable>
            <variable type='string' name='nineboard_ldaptemplate' description="Modèle d'annuaire"><value>scribe</value></variable>

            <variable type='string' name='nineboard_websocket_url' description='Host du serveur Websocket'  mandatory='True' />
            <variable type='string' name='nineboard_websocket_portexterne' description='Port de commuinication externe du serveur Websocket'  mandatory='True' >
                <value>5565</value>
            </variable>
            <variable type='string' name='nineboard_websocket_portinterne' description='Port de commuinication interne du serveur Websocket'  mandatory='True'>
                <value>5566</value>
            </variable>

            <!-- MODULE CRON -->
            <variable type="oui/non" name='nineboard_activate_cron' description='Activer le module CRON'  mandatory='True'>
                <value>oui</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' />
            <variable type='string' name='nineboard_smtpport' description='Port du serveur SMTP' />
            <variable type='string' name='nineboard_smtpuser' description='Compte du serveur SMTP' />
            <variable type='string' name='nineboard_smtppwd' description='Fichier contenant le mot de passe associé du compte SMTP' />
            <variable type='string' name='nineboard_smtpencryption' description='Type Encryptage du serveur SMTP' />
            <variable type='string' name='nineboard_smtpauthmode' description='Mode Authentification du serveur SMTP' />

            <!-- EOLEDB -->
            <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_websocket_url">Paramètres associés au Serveur WEBSOCKET</separator>
            <separator name="nineboard_activate_cron">Paramètres associés aux modules à activer</separator>
            <separator name="nineboard_noreply">Paramètres associés aux Mails</separator>
            <separator name="nineboard_db_mode">Paramètres associés à la Base de Données</separator>
        </separators> 
    </variables>

    <constraints>
        <condition name='hidden_if_in' source='activer_apache'>
            <param>non</param>
            <target type='variable'>activer_nineboard</target>
        </condition>

        <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_api_key</target>
            <target type='variable'>nineboard_ldaptemplate</target>

            <target type='variable'>nineboard_websocket_url</target>
            <target type='variable'>nineboard_websocket_portexterne</target>
            <target type='variable'>nineboard_websocket_portinterne</target>

            <target type='variable'>nineboard_activate_cron</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='servicelist'>nineboard</target>
        </condition>

        <fill name='calc_multi_condition' target='nineboard_websocket_url'>
            <param>oui</param>
            <param type='eole' name='condition_1' hidden='False'>activer_apache</param>
            <param type='eole' name='match' hidden='False'>web_url</param>
            <param name='default_mismatch'>None</param>
        </fill>

        <!-- 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 DU MAIL -->
        <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 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 MODE DE BDD -->
        <condition name='hidden_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='hidden_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>

        <!-- CONCAT -->
        <fill name='concat' target='nineboard_noreply'>
            <param>noreply@</param>
            <param type='eole'>domaine_messagerie_etab</param>
        </fill>

        <!-- 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', 'SAML', 'LDAP']</param>
        </check>
        
        <check name='valid_enum' target='nineboard_ldaptemplate'>
            <param>['scribe']</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>
    </help>
</creole>
