AlternC/install/upgrades/1.1.0.php

62 lines
2.0 KiB
PHP

#!/usr/bin/php
<?php
// We check that mysql php module is loaded
if(!function_exists('mysql_connect')) {
if(!dl("mysql.so"))
exit(1);
}
// we don't check our AlternC session
if(!chdir("/var/alternc/bureau"))
exit(1);
require("/var/alternc/bureau/class/config_nochk.php");
// we go super-admin
$admin->enabled=1;
$db->query("SELECT * FROM sub_domaines WHERE type='webmail'");
if ($db->num_rows()) {
echo "################################################################################\n";
echo "WARNING: You have WEBMAIL domain-types, you need to install alternc-squirrelmail or alternc-roundcube\n";
echo "to be able to use them again. those subdomains will be broken until you do that\n";
echo "Also, a script converts your procmail-builder filters to the new SIEVE protocol.\n";
echo "This script is in /usr/lib/alternc/procmail_to_sieve.php once to migrate\n";
echo "PRESS ENTER TO CONTINUE\n";
echo "################################################################################\n";
$f=fopen("php://stdin","rb");fgets($f,10); fclose($f);
}
//updating db and dbusers tables
$db->query("Alter table dbusers add column password varchar(32);");
$db->query("Alter table dbusers add column enable enum('ACTIVATED','HIDDEN','ADMIN') not NULL default 'ACTIVATED';");
$db->query("Alter table db add column id bigint(20) unsigned NOT NULL AUTO INCREMENT primary key;");
$db->query("select distinct uid,login,pass from db;");
//on insere dans dbusers avec enabled = admin
$query=array();
while($db->next_record()){
$query[]="insert or update into dbusers values('',".$db->f('uid').",'".$db->f('login')."','".$db->f('pass')."',\"ADMIN\");";
}
foreach ($query as $q){
$db->query($q);
}
//Updating mysql.db table to fix the "_" wildcard bug
$db->query("select Db from mysql.db ;");
$query2=array();
while($db->next_record()){
$dbn=preg_replace("/^([A-Za-z0-9]*)_([A-Za-z0-9]*)/","$1\_$2",$db->f('Db'));
$query2[]="update mysql.db set Db=replace(Db,'".$db->f('Db')."','".$dbn."');";
}
foreach ($query2 as $q2){
$db->query($q2);
}
//done ? :)