<?php
/* 
 * Module d'encryptage de la config pour envoyer à l'admin du broker
 * 19/05/2011 RR
 */

$rootPath = dirname(__FILE__) . '/../../webservices';
if (isset($_GET['ip']) && !empty($_GET['ip']) && isset($_GET['idclient']) && !empty($_GET['idclient']) && isset($_GET['typeconfig']) && !empty($_GET['typeconfig'])) {
    $ini_path = '';
    switch ($_GET['typeconfig']) {
        case 'general' :
            if (file_exists($rootPath . '/client/config/' .$_GET['idclient'].'/config.ini')) $ini_path = $rootPath . '/client/config/' .$_GET['idclient'].'/config.ini';
            elseif (file_exists($rootPath . '/client/config/config.ini')) $ini_path = $rootPath . '/client/config/config.ini';
            elseif (file_exists($rootPath . '/client/config/config_orig.ini')) $ini_path = $rootPath . '/client/config/config_orig.ini';
            break;
        case 'monitoring' :
            if (file_exists($rootPath . '/monitoring/config.ini')) $ini_path = $rootPath . '/monitoring/config.ini';
            elseif (file_exists($rootPath . '/monitoring/config_orig.ini')) $ini_path = $rootPath . '/monitoring/config_orig.ini';
            break;
    }
    if (!empty($ini_path)) {
        $content = file_get_contents($ini_path);
        $key = (strlen($_GET['ip']) < 11 ? $_GET['ip'] : substr($_GET['ip'], -11)).date('Ymd').'OPAC2'; //Taille max de la clé : 24
        $iv = '12345678';
        $cipher = mcrypt_module_open(MCRYPT_3DES,'','cbc','');
        mcrypt_generic_init($cipher, $key, $iv);
        $encrypted = mcrypt_generic($cipher, $content);
        $encrypted = base64_encode($encrypted);
        mcrypt_generic_deinit($cipher);
        echo $encrypted;
    }
    else return null;
}
?>