2014-03-12 17:43:26 +00:00
|
|
|
<?php
|
2014-03-19 09:15:54 +00:00
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
//
|
|
|
|
// Alternc bootstrapping
|
|
|
|
// bureau/class/config.php file is -not- test friendly
|
|
|
|
// @todo streamline test and prod
|
|
|
|
//
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
// Autoloading
|
|
|
|
// ***********
|
|
|
|
$pathList = array_merge( array("."),explode(PATH_SEPARATOR,get_include_path()));
|
2014-03-12 17:43:26 +00:00
|
|
|
set_include_path(implode(PATH_SEPARATOR, $pathList));
|
|
|
|
require_once('AutoLoader.php');
|
|
|
|
AutoLoader::registerDirectory('lib');
|
|
|
|
AutoLoader::registerDirectory('../bureau/class');
|
|
|
|
AutoLoader::registerDirectory('.');
|
|
|
|
|
2014-03-22 14:39:37 +00:00
|
|
|
define('ALTERNC_PANEL',realpath(__DIR__."/../bureau"));; // Custom
|
|
|
|
define('PHPUNIT_DATASETS_PATH',realpath(__DIR__."/tests/_datasets"));
|
2014-03-19 09:15:54 +00:00
|
|
|
require_once ALTERNC_PANEL."/class/db_mysql.php";
|
|
|
|
require_once ALTERNC_PANEL."/class/functions.php";
|
|
|
|
|
|
|
|
|
|
|
|
// General variables setup
|
|
|
|
// *********************
|
|
|
|
if(is_readable('local.sh')){
|
2014-03-26 13:31:06 +00:00
|
|
|
$configFile = file_get_contents('local.sh';
|
2014-03-21 14:04:09 +00:00
|
|
|
} else if(is_readable('local.sh_generic')){
|
2014-03-26 13:31:06 +00:00
|
|
|
$configFile = file_get_contents('local.sh_generic');
|
2014-03-19 09:15:54 +00:00
|
|
|
} else {
|
|
|
|
throw new Exception("You must provide a local.sh file", 1 );
|
|
|
|
}
|
|
|
|
$configFile = explode("\n",$configFile);
|
|
|
|
$compat = array('DEFAULT_MX' => 'MX',
|
|
|
|
'MYSQL_USER' => 'MYSQL_LOGIN',
|
|
|
|
'MYSQL_PASS' => 'MYSQL_PWD',
|
|
|
|
'NS1_HOSTNAME' => 'NS1',
|
|
|
|
'NS2_HOSTNAME' => 'NS2'
|
|
|
|
);
|
|
|
|
foreach ($configFile as $line) {
|
|
|
|
if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $matches)) {
|
2014-03-21 14:04:09 +00:00
|
|
|
//$GLOBALS['L_'.$matches[1]] = $matches[2];
|
|
|
|
eval('$L_'.$matches[1].' = $matches[2];'); # Ugly, but work with phpunit...
|
2014-03-19 09:15:54 +00:00
|
|
|
if (isset($compat[$matches[1]])) {
|
|
|
|
$GLOBALS['L_'.$compat[$matches[1]]] = $matches[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Constants and globals
|
|
|
|
// ********************
|
|
|
|
|
2014-03-21 14:04:09 +00:00
|
|
|
// Define constants from vars of local.sh
|
|
|
|
define('ALTERNC_MAIL', "$L_ALTERNC_MAIL");
|
|
|
|
define('ALTERNC_HTML', "$L_ALTERNC_HTML");
|
|
|
|
define('ALTERNC_LOGS', "$L_ALTERNC_LOGS");
|
2014-03-19 09:15:54 +00:00
|
|
|
if(isset($L_ALTERNC_LOGS_ARCHIVE)){
|
|
|
|
define('ALTERNC_LOGS_ARCHIVE', "$L_ALTERNC_LOGS_ARCHIVE");
|
|
|
|
}
|
|
|
|
define('ALTERNC_LOCALES', ALTERNC_PANEL."/locales");
|
|
|
|
define('ALTERNC_LOCK_JOBS', '/var/run/alternc/jobs-lock');
|
|
|
|
define('ALTERNC_LOCK_PANEL', '/var/lib/alternc/panel/nologin.lock');
|
|
|
|
define('ALTERNC_APACHE2_GEN_TMPL_DIR', '/etc/alternc/templates/apache2/');
|
|
|
|
define('ALTERNC_VHOST_DIR', "/var/lib/alternc/apache-vhost/");
|
|
|
|
define('ALTERNC_VHOST_FILE', ALTERNC_VHOST_DIR."vhosts_all.conf");
|
|
|
|
define('ALTERNC_VHOST_MANUALCONF', ALTERNC_VHOST_DIR."manual/");
|
2014-03-22 14:39:37 +00:00
|
|
|
define("THROW_EXCEPTIONS", TRUE);
|
2014-03-19 09:15:54 +00:00
|
|
|
$root = ALTERNC_PANEL."/";
|
|
|
|
|
2014-03-21 14:04:09 +00:00
|
|
|
// Create test directory
|
|
|
|
foreach (array(ALTERNC_MAIL, ALTERNC_HTML, ALTERNC_LOGS) as $crdir ) {
|
|
|
|
if (! is_dir($crdir)) {
|
|
|
|
mkdir($crdir, 0777, true);
|
|
|
|
}
|
|
|
|
}
|
2014-03-19 09:15:54 +00:00
|
|
|
|
|
|
|
// Database variables setup
|
|
|
|
// ***********************
|
2014-03-21 09:31:41 +00:00
|
|
|
// Default values
|
|
|
|
$database = "alternc_test";
|
|
|
|
$user = "root";
|
|
|
|
$password = "";
|
|
|
|
// Local override
|
2014-03-19 09:15:54 +00:00
|
|
|
if ( is_readable("my.cnf") ) {
|
2014-03-21 09:31:41 +00:00
|
|
|
$mysqlConfigFile = file("my.cnf");
|
2014-03-21 14:04:09 +00:00
|
|
|
} else if(is_readable('my.cnf_generic')){
|
|
|
|
$mysqlConfigFile = file('my.cnf_generic');
|
2014-03-26 13:31:06 +00:00
|
|
|
} else {
|
|
|
|
throw new Exception("You must provide a my.cnf file", 1 );
|
|
|
|
}
|
2014-03-21 14:04:09 +00:00
|
|
|
|
2014-03-22 14:59:45 +00:00
|
|
|
foreach ($mysqlConfigFile as $line) {
|
|
|
|
if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $matches)) {
|
|
|
|
switch ($matches[1]) {
|
|
|
|
case "user":
|
|
|
|
$user = $matches[2];
|
|
|
|
break;
|
|
|
|
case "password":
|
|
|
|
$password = $matches[2];
|
|
|
|
break;
|
|
|
|
case "database":
|
|
|
|
$database = $matches[2];
|
|
|
|
break;
|
2014-03-19 09:15:54 +00:00
|
|
|
}
|
2014-03-22 14:59:45 +00:00
|
|
|
}
|
|
|
|
if (preg_match('/^#alternc_var ([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $matches)) {
|
|
|
|
$$matches[1] = $matches[2];
|
|
|
|
}
|
|
|
|
}
|
2014-03-19 09:15:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for MySQL management in the bureau
|
|
|
|
*
|
|
|
|
* This class heriting from the db class of the phplib manages
|
|
|
|
* the connection to the MySQL database.
|
|
|
|
*/
|
|
|
|
class DB_system extends DB_Sql {
|
|
|
|
var $Host,$Database,$User,$Password;
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
function DB_system($user,$database,$password) {
|
|
|
|
global $L_MYSQL_HOST,$L_MYSQL_DATABASE,$L_MYSQL_LOGIN,$L_MYSQL_PWD;
|
|
|
|
$this->Host = "127.0.0.1";
|
|
|
|
$this->Database = $database;
|
|
|
|
$this->User = $user;
|
|
|
|
$this->Password = $password;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Creates database from schema
|
|
|
|
// *********************************************
|
|
|
|
|
|
|
|
$queryList = array(
|
|
|
|
"mysql -u $user --password='$password' -e 'DROP DATABASE IF EXISTS $database '",
|
|
|
|
"mysql -u $user --password='$password' -e 'CREATE DATABASE $database'",
|
|
|
|
"mysql -u $user --password='$password' $database < ".__DIR__."/../install/mysql.sql"
|
|
|
|
);
|
|
|
|
foreach ($queryList as $exec_command) {
|
|
|
|
exec($exec_command,$output,$return_var);
|
|
|
|
if( $return_var){
|
|
|
|
throw new \Exception("[!] Mysql exec error : $exec_command \n Error : \n ".print_r($output,1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$db = new \DB_system($user,$database,$password);
|
2014-03-22 14:39:37 +00:00
|
|
|
$db->connect();
|
2014-03-19 09:15:54 +00:00
|
|
|
$cuid = 0;
|
|
|
|
$variables = new \m_variables();
|
|
|
|
$mem = new \m_mem();
|
|
|
|
$err = new \m_err();
|
|
|
|
$authip = new \m_authip();
|
|
|
|
$hooks = new \m_hooks();
|
|
|
|
|