Subversion Repositories slis

Rev

Rev 5499 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?PHP
/*

This script has been written by Philippe Le Brouster
Copyright (C) 2007 Philippe Le Brouster <plb@ac-grenoble.fr>

This script is released under GNU Public Licence (GPL)
http://www.gnu.org/licenses/gpl.html

This script is part of the SLIS Project initiated by
the CARMI-Internet (Academie de Grenoble - France 38).

SLIS : Serveur de communications Linux pour l'Internet Scolaire.
Copyright (C) 1998-2001 Bruno Bzeznik

--------------------------------------------------------------*/


// Slis Update from 2.0.5 to 2.0.5.1

function doUpdate_2_0_5_to_2_0_5_1(){
    global $slim_user,$slim_db;

    if ($slim_user->login == "admin") {
        $retval=1;
        echo ("<br>Updating slim DB from 2.0.5 to 2.0.5.1 ");

        if ($retval) $retval = alter_file_defvalue_key_2_0_5_1();
        if ($retval) $retval = insert_slis41_value_2_0_5_1();
        if ($retval) $retval = insert_slis41_checkversion_2_0_5_1();

        if ($retval) $retval = pg_exec($slim_db,"UPDATE slim_info set value='2.0.5.1' where key='slim_db_version';");

        return $retval;
    }

}

function alter_file_defvalue_key_2_0_5_1() {
    global $slim_db;
    print "<br/> Update index for file_devalue table";

    $result = 1;
    $query  = "BEGIN;";
    $query .= "DROP INDEX file_defvalue_key;";
    $query .= "CREATE INDEX file_defvalue_key ON file_defvalue USING btree (pop_id,\"type\",variable,file);";
    $query .= "COMMIT;";
   
    if ($result) $result = pg_exec($slim_db,$query);

    return $result;
}

function insert_slis41_value_2_0_5_1() {
    global $slim_db;
    print "<br/> Insert the new default values for slis 4.1 configuration generation.";


    $slis41_slis = array(
        'ADSL_PASS' => '%gateway_passwd%',
        'ADSL_TYPE' => 'pppoe',
        'ADSL_USER' => '%gateway_user%',
        'ALLOWED_SMTP' => '194.250.105.1,195.101.206.1,212.208.23.6,212.198.0.221',
        'DMZ_IF' => '1',
        'DMZ_IF_DEV' => 'eth2',
        'DMZ_IF_IP' => '192.168.234.1',
        'DMZ_IF_MASK' => '255.255.255.0',
        'DNS_PRIMARY' => '%dns_primary_ip%',
        'DNS_SECONDARY' => '%dns_secondary_ip%',
        'DOMAIN' => '%slis_name%.ac-grenoble.fr',
        'EXTERNAL_IF_DEV' => 'eth0',
        'EXTERNAL_IF_IP' => '%slis_wan_ip%',
        'EXTERNAL_IF_MASK' => '%slis_wan_netmask%',
        'GATEWAY' => '%slis_gateway%',
        'HOSTNAME' => '%slis_name%',
        'INTERNAL_IF_DEV' => 'eth1',
        'INTERNAL_IF_IP' => '%slis_lan_ip%',
        'INTERNAL_IF_MASK' => '%slis_lan_netmask%',
        'IP_DEBIAN' => '192.168.234.4',
        'IP_DOM0' => '192.168.234.2',
        'IP_LCS' => '192.168.234.6',
        'IP_TUN_SLIS' => '%vtun_tunnel_slis_ip%',
        'IP_TUN_SVR' => '%vtun_tunnel_server_ip%',
        'LDAP_ADMIN_PW' => 'AUTO',
        'LDAP_ADMIN_RDN' => 'admin',
        'LDAP_BASE_DN' => 'ou=%site_code%,ou=ac-grenoble,ou=education,o=gouv,c=fr',
        'LDAP_COMPUTERS_RDN' => 'Computers',
        'LDAP_GROUPS_RDN' => 'Groups',
        'LDAP_MAIL_DOMAIN' => '%slis_name%.ac-grenoble.fr',
        'LDAP_PARKS_RDN' => 'Parcs',
        'LDAP_PEOPLE_RDN' => 'People',
        'LDAP_RIGHTS_RDN' => 'Rights',
        'LDAP_SERVER' => '192.168.234.6',
        'LDAP_TLS' => '1',
        'LDAP_TRASH_RDN' => 'Trash',
        'LOCAL_ADMIN_PW' => '%slis_admin_pass%',
        'LOCAL_PROXY_PORT' => '3128',
        'LOCAL_ZONE_NAME' => 'intranet.local',
        'LOG_FACILITY' => 'local5',
        'MAX_MESSAGE_SIZE' => '2000000',
        'MDA_IP' => '192.168.234.6',
        'MONITOR_ENABLE' => 'true',
        'MONITOR_FREQUENCY' => 'HOURLY',
        'MTA_IP' => '192.168.234.6',
        'NREDIR' => '15',
        'NTP_SERVER' => 'ntp.ac-grenoble.fr',
        'PARENT_ICP_PORT' => '3130',
        'PARENT_PORT' => '3128',
        'PASS' => '\$1\$m9qQQMXn\$qoWTahZHGVwHp3hdSaz5b.',
        'PING_HOST' => '193.54.149.10',
        'PROXY_CACHE' => 'na',
        'PROXYON' => '1',
        'PROXY_TRANS' => '0',
        'REDIR_BASE' => 'http://www.ac-grenoble.fr/redir',
        'RELAY_HOST' => 'smtp.ac-grenoble.fr',
        'ROUTER_TYPE' => '0',
        'ROUTE_TUN_MASK' => '255.255.255.255',
        'ROUTE_TUN_NET' => '193.54.149.10',
        'RSYNC_HOST' => '193.54.149.10',
        'RSYNC_MODULE' => 'slis-update_4.1',
        'SECRET' => '%vtun_secret%',
        'SENDMAILON' => '1',
        'SLIM_HOST' => '195.221.235.245',
        'SLIM_MAX_AGE' => '36000',
        'SLIM_MONITOR_PATH' => 'slim/scripts/monitor/get',
        'SLIM_RETRY_TIME' => '5',
        'SLISMASTER' => 'slismaster@ac-grenoble.fr',
        'SQUID_AUTH' => '0',
        'UPDATE_TIME_WINDOW' => '01-03',
        'USER' => '%vtun_user%',
        'VERSION_NUM' => '4.1',
        'VTUN_RETRIES' => '0',
        'VTUN_SVR_PORT' => '%vtun_server_port%',
        'VTUN_SVR' => '%vtun_server_ip%',
        'VTUN' => '%vtun%'
    );

    $slis41_lcs = array(
        'BROADCAST' => '192.168.234.255',
        'CACHEDIRSIZE' => '100',
        'COUNTRYNAME' => 'FR',
        'DEFAULT_SHELL' => '/bin/true',
        'DNS_PRIMARY' => '192.168.234.1',
        'DNS_SECONDARY' => '192.168.234.1',
        'DOMAIN' => '%slis_name%.ac-grenoble.fr',
        'EXTERNAL_IF_DEV' => 'eth0',
        'GATEWAY' => '192.168.234.1',
        'HOSTNAME' => 'lcs',
        'IPADDR0' =>  '192.168.234.6',
        'LCSMGRPASS' => 'AUTO',
        'LDAP_ADMIN_PW' => 'AUTO',
        'LDAP_ADMIN_RDN' => 'admin',
        'LDAP_BASE_DN' => 'ou=%site_code%,ou=ac-grenoble,ou=education,o=gouv,c=fr',
        'LDAP_COMPUTERS_RDN' => 'Computers',
        'LDAP_GROUPS_RDN' => 'Groups',
        'LDAP_MAIL_DOMAIN' => '%slis_name%.ac-grenoble.fr',
        'LDAP_MASTER_SERVER' => '127.0.0.1',
        'LDAP_PARKS_RDN' => 'Parcs',
        'LDAP_PEOPLE_RDN' => 'People',
        'LDAP_PORT' => '389',
        'LDAP_RID' => '123',
        'LDAP_RIGHTS_RDN' => 'Rights',
        'LDAP_SERVER' => '127.0.0.1',
        'LDAP_TRASH_RDN' => 'Trash',
        'LOCAL_ADMIN_PW' => '%slis_admin_pass%',
        'LOCALITYNAME' => 'Academie de Grenoble',
        'MONITOR_ENABLE' => 'true',
        'MONITOR_FREQUENCY' => 'HOURLY',
        'MTA_IP' => '192.168.234.6',
        'MYSQLPW' => 'AUTO',
        'NETMASK0' => '255.255.255.0',
        'NETWORK' => '192.168.234.0',
        'NTP_SERVER' => '192.168.234.1',
        'ORGANIZATIONALUNITNAME' => '%site_name%',
        'ORGANIZATIONNAME' => 'CARMI',
        'PROVINCENAME' => 'Academie de Grenoble',
        'RELAY_HOST' => 'smtp.ac-grenoble.fr',
        'SLIM_HOST' => '195.221.235.245',
        'SLIM_MAX_AGE' => '36000',
        'SLIM_MONITOR_PATH' => 'slim/scripts/monitor/get',
        'SLIM_RETRY_TIME' => '5',
        'SLISMASTER' => 'slismaster@ac-grenoble.fr',
        'TYPE_GROUPS' => 'posixGroup',
        'UID_POLICY' => '4',
        'URL_MAJMD5' => 'ftp://193.49.66.4/LcsMajMD5-ETCH',
        'URL_MAJMOD' => 'http://linux.crdp.ac-caen.fr/modulesLcsEtchXP/',
        'URL_MAJPLUG' => 'http://linux.crdp.ac-caen.fr/pluginsLcs/',
        'URL_MAJTGZ' => 'ftp://debian.crdp.ac-caen.fr/debian/LcsMaj/LcsMajTGZ-ETCH',
        'VERSION_NUM' => '2.0',
        'VLANSC' => '192.168.234.0/24',
        'SE3_IP' => '172.16.0.11',
        'SE3_DOMAIN' => '%site_code%',
        'SE3_NETBIOS' => 'SRV01'
    );

    /*
     * Retrieve possible values that already exist.
     */

    $query = "SELECT variable FROM file_defvalue WHERE file='slis41_slis.conf' and pop_id='0' and type='' and method='';";
    $result = pg_exec($slim_db, $query);
    if (! $result ) {
        print pg_last_error();
        return false;
    }
    $query = "SELECT variable FROM file_defvalue WHERE file='slis41_lcs.conf' and pop_id='0' and type='' and method='';";
    $result2 = pg_exec($slim_db, $query);
    if (! $result2 ) {
        print pg_last_error();
        return false;
    }

    $arRes = pg_fetch_array($result);
    $arRes2 = pg_fetch_array($result2);

    $arSLIS41Values = array();
    foreach ($arRes as $ar) {
        array_push($arSLIS41Values,$ar[0]);
    }

    $arLCS20Values = array();
    foreach ($arRes2 as $ar) {
        array_push($arLCS20Values, $ar[0]);
    }

    /*
     * Add the new parameters.
     */

    foreach($slis41_slis as $key => $value) {
        if ( ! in_array($key, $arSLIS41Values)) {
            $query = "INSERT INTO file_defvalue VALUES(DEFAULT,'$key','','0','$value','','slis41_slis.conf');";
            pg_exec($slim_db,$query);
        }
    }
   
    foreach($slis41_lcs as $key => $value) {
        if ( ! in_array($key, $arLCS20Values)) {
            $query = "INSERT INTO file_defvalue VALUES(DEFAULT,'$key','','0','$value','','slis41_lcs.conf');";
            pg_exec($slim_db,$query);
        }
    }

    return true;
}

function insert_slis41_checkversion_2_0_5_1() {
    global $slim_db;

    echo "<br/>Add slis4.1, host4.1 & lcs2.0 monitoring versions if needed";

    $vers= array('slis4.1','host4.1','lcs2.0');
    foreach ($vers as $ver) {
        $query = "select count(*) from version_slis where version_name='$ver'";
        $result = pg_exec($slim_db,$query);
        if ( ! $result ) {
            print pg_last_error();
            return false;
        }

        $count = pg_fetch_result($result,0);
        if ( $count == 0 ) {
            $query = "insert into version_slis values ('$ver')";
            $result = pg_exec($slim_db,$query);
        }
    }

    return true;
}