Merge branch 'master' of alternc.org:alternc

This commit is contained in:
Benjamin Sonntag 2014-03-28 16:05:40 +01:00
commit 537f0fb638
5 changed files with 59 additions and 25 deletions

View File

@ -100,6 +100,9 @@ class m_dom {
return $t; return $t;
} }
/**
* @param string $fqdn
*/
function get_sub_domain_id_and_member_by_name($fqdn) { function get_sub_domain_id_and_member_by_name($fqdn) {
global $db, $err, $cuid; global $db, $err, $cuid;
$err->log("dom", "get_sub_domain_by_name"); $err->log("dom", "get_sub_domain_by_name");
@ -219,6 +222,9 @@ class m_dom {
return $val; return $val;
} }
/**
* @param string $zone
*/
function import_manual_dns_entry($zone, $domain, $detect_redirect = true, $save = false) { function import_manual_dns_entry($zone, $domain, $detect_redirect = true, $save = false) {
global $cuid, $err; global $cuid, $err;
$err->log("dom", "import_manual_dns_entry"); $err->log("dom", "import_manual_dns_entry");
@ -464,6 +470,10 @@ class m_dom {
// Take an URL, and return FALSE is there is no redirection, // Take an URL, and return FALSE is there is no redirection,
// and the target URL if there is one (HTTP CODE 301 & 302) // and the target URL if there is one (HTTP CODE 301 & 302)
// CURL is needed // CURL is needed
/**
* @param string $url
*/
function is_it_a_redirect($url) { function is_it_a_redirect($url) {
try { try {
$params = array('http' => array( $params = array('http' => array(
@ -667,7 +677,6 @@ class m_dom {
* <p>Chaque classe peut définir une fonction add_dom($dom) qui sera * <p>Chaque classe peut définir une fonction add_dom($dom) qui sera
* appellée lors de l'installation d'un nouveau domaine.</p> * appellée lors de l'installation d'un nouveau domaine.</p>
* *
* @param string $dom nom fqdn du domaine é installer
* @param boolean $dns 1 ou 0 pour héberger le DNS du domaine ou pas. * @param boolean $dns 1 ou 0 pour héberger le DNS du domaine ou pas.
* @param boolean $noerase 1 ou 0 pour rendre le domaine inamovible ou non * @param boolean $noerase 1 ou 0 pour rendre le domaine inamovible ou non
* @param boolean $force 1 ou 0, si 1, n'effectue pas les tests de DNS. * @param boolean $force 1 ou 0, si 1, n'effectue pas les tests de DNS.
@ -792,6 +801,9 @@ class m_dom {
return true; return true;
} }
/**
* @param string $domain
*/
function create_default_subdomains($domain, $target_domain = "") { function create_default_subdomains($domain, $target_domain = "") {
global $db, $err; global $db, $err;
$err->log("dom", "create_default_subdomains", $domain); $err->log("dom", "create_default_subdomains", $domain);
@ -1057,6 +1069,7 @@ class m_dom {
* $ref_domaine est le domaine avec lequel on veux comparer les MX * $ref_domaine est le domaine avec lequel on veux comparer les MX
* si $ref_domaine == '', on prend les MX par default * si $ref_domaine == '', on prend les MX par default
* *
* @param string $domaine
*/ */
function checkmx($domaine, $ref_domain = '') { function checkmx($domaine, $ref_domain = '') {
global $L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX; global $L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX;
@ -1180,7 +1193,7 @@ class m_dom {
* Retourne TOUTES les infos d'un sous domaine du compte courant. * Retourne TOUTES les infos d'un sous domaine du compte courant.
* *
* @param integer sub_domain_id id du subdomain * @param integer sub_domain_id id du subdomain
* @return arrray Retourne un tableau associatif contenant les * @return array Retourne un tableau associatif contenant les
* informations du sous-domaine demandé.<pre> * informations du sous-domaine demandé.<pre>
* $r["name"]= nom du sous-domaine (NON-complet) * $r["name"]= nom du sous-domaine (NON-complet)
* $r["dest"]= Destination (url, ip, local ...) * $r["dest"]= Destination (url, ip, local ...)
@ -1218,6 +1231,10 @@ class m_dom {
// get_sub_domain_all // get_sub_domain_all
/**
* @param integer $type
* @param string $value
*/
function check_type_value($type, $value) { function check_type_value($type, $value) {
global $db, $err, $cuid; global $db, $err, $cuid;
@ -1333,10 +1350,8 @@ class m_dom {
* <b>Note : TODO</b> : vérification de concordance de $dest<br /> * <b>Note : TODO</b> : vérification de concordance de $dest<br />
* *
* @param string $dom Domaine dont on souhaite modifier/ajouter un sous domaine * @param string $dom Domaine dont on souhaite modifier/ajouter un sous domaine
* @param string $subk Sous domaine é modifier / créer * @param string $sub Sous domaine é modifier / créer
* @param integer $type Type de sous-domaine (local, ip, url ...) * @param integer $type Type de sous-domaine (local, ip, url ...)
* @param string $action Action : vaut "add" ou "edit" selon que l'on
* Crée (add) ou Modifie (edit) le sous-domaine
* @param string $dest Destination du sous-domaine, dépend de la valeur * @param string $dest Destination du sous-domaine, dépend de la valeur
* de $type (url, ip, dossier...) * de $type (url, ip, dossier...)
* @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
@ -1428,8 +1443,6 @@ class m_dom {
/** /**
* Supprime le sous-domaine demandé * Supprime le sous-domaine demandé
* *
* @param string $dom Domaine dont on souhaite supprimer un sous-domaine
* @param string $sub Sous-domaine que l'on souhaite supprimer
* @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
* *
*/ */
@ -1453,6 +1466,9 @@ class m_dom {
// del_sub_domain // del_sub_domain
/**
* @param integer $dom_id
*/
function set_ttl($dom_id, $ttl) { function set_ttl($dom_id, $ttl) {
global $err; global $err;
$err->log("dom", "set_ttl", "$dom_id / $ttl"); $err->log("dom", "set_ttl", "$dom_id / $ttl");
@ -1479,7 +1495,7 @@ class m_dom {
* TRUE sinon. * TRUE sinon.
* *
*/ */
function edit_domain($dom, $dns, $gesmx, $force = 0, $ttl = 86400) { function edit_domain($dom, $dns, $gesmx, $force = false, $ttl = 86400) {
global $db, $err, $L_MX, $classes, $cuid, $hooks; global $db, $err, $L_MX, $classes, $cuid, $hooks;
$err->log("dom", "edit_domain", $dom . "/" . $dns . "/" . $gesmx); $err->log("dom", "edit_domain", $dom . "/" . $dns . "/" . $gesmx);
// Locked ? // Locked ?
@ -2107,6 +2123,9 @@ order by
return true; return true;
} }
/**
* @param string $dns_action
*/
function set_dns_action($domain, $dns_action) { function set_dns_action($domain, $dns_action) {
global $db; global $db;
$db->query("UPDATE domaines SET dns_action='" . mysql_escape_string($dns_action) . "' WHERE domaine='" . mysql_escape_string($domain) . "'; "); $db->query("UPDATE domaines SET dns_action='" . mysql_escape_string($dns_action) . "' WHERE domaine='" . mysql_escape_string($domain) . "'; ");

View File

@ -11,8 +11,8 @@ Class m_export {
function export_conf(){ function export_conf(){
global $hooks; global $hooks;
$conf=$hooks->invoke('alternc_export_conf'); $config=$hooks->invoke('alternc_export_conf');
return $conf; return $config;
} }
/** le repertoire de base est passé en paramettre puis en construit une arborescence de la forme /** le repertoire de base est passé en paramettre puis en construit une arborescence de la forme

View File

@ -37,6 +37,7 @@ class m_variables {
var $strata_order = array('DEFAULT','GLOBAL','FQDN_CREATOR','FQDN','CREATOR','MEMBER','DOMAIN'); var $strata_order = array('DEFAULT','GLOBAL','FQDN_CREATOR','FQDN','CREATOR','MEMBER','DOMAIN');
var $cache_variable_list = false; var $cache_variable_list = false;
var $replace_array = array(); var $replace_array = array();
var $cache_conf = array();
/** /**
* *
@ -169,7 +170,7 @@ class m_variables {
// Replace needed vars // Replace needed vars
foreach ($variables as $vv => $hh) { foreach ($variables as $vv => $hh) {
if (!isset($hh['value']) || !empty($hh['value'])) { if (!isset($hh['value']) || empty($hh['value'])) {
continue; continue;
} }
$variables[$vv]['value'] = strtr($hh['value'], $this->replace_array ); $variables[$vv]['value'] = strtr($hh['value'], $this->replace_array );
@ -178,22 +179,20 @@ class m_variables {
if ($var && isset($variables[$var])) { if ($var && isset($variables[$var])) {
return $variables[$var]; return $variables[$var];
} else { } else {
return $variables; return $variables;
} }
} }
/** /**
* Initialize the global $conf array if necessary * Initialize the global conf
* *
* @global $conf the global conf array
* @uses variable_init() * @uses variable_init()
* @param boolean $force * @param boolean $force
*/ */
function variable_init_maybe($force=false) { function variable_init_maybe($force=false) {
global $conf; if ($force || empty($this->cache_conf) ) {
if ($force || !isset($conf)) {
$this->cache_variable_list = false; $this->cache_variable_list = false;
$conf = $this->variable_init(); $this->cache_conf = $this->variable_init();
} }
} }
@ -209,19 +208,17 @@ class m_variables {
* and createit_comment value as comment * and createit_comment value as comment
* @return mixed * @return mixed
* The value of the variable. * The value of the variable.
* @global array $conf
* A cache of the configuration.
*/ */
function variable_get($name, $default = null, $createit_comment = null, $type=null) { function variable_get($name, $default = null, $createit_comment = null, $type=null) {
global $conf;
$this->variable_init_maybe(); $this->variable_init_maybe();
if (isset($conf[$name])) { if (isset($this->cache_conf[$name])) {
return $conf[$name]['value']; return $this->cache_conf[$name]['value'];
} elseif (!is_null($createit_comment)) { } elseif (!is_null($createit_comment)) {
$this->variable_update_or_create($name, $default, 'DEFAULT', 'null', 'null', $createit_comment, $type); $this->variable_update_or_create($name, $default, 'DEFAULT', 'null', 'null', $createit_comment, $type);
} }
return $default; return $default;
} }
@ -256,6 +253,7 @@ class m_variables {
$sql="UPDATE variable SET value='".mysql_real_escape_string($var_value)."' WHERE id = ".intval($var_id); $sql="UPDATE variable SET value='".mysql_real_escape_string($var_value)."' WHERE id = ".intval($var_id);
} else { } else {
if ( empty($strata) ) { if ( empty($strata) ) {
$this->variable_init_maybe(true);
$err->raise('variables', _("Err: Missing strata when creating var")); $err->raise('variables', _("Err: Missing strata when creating var"));
return false; return false;
} }
@ -412,7 +410,6 @@ class m_variables {
function variables_list() { function variables_list() {
global $db; global $db;
if ( ! $this->cache_variable_list ) { if ( ! $this->cache_variable_list ) {
$result = $db->query('SELECT * FROM `variable`'); $result = $db->query('SELECT * FROM `variable`');
$arr_var=array(); $arr_var=array();

View File

@ -137,6 +137,7 @@ class DB_system extends DB_Sql {
// Creates database from schema // Creates database from schema
// ********************************************* // *********************************************
echo "*** In progress: importing mysql.sql\n";
$queryList = array( $queryList = array(
"mysql -u $user --password='$password' -e 'DROP DATABASE IF EXISTS $database '", "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' -e 'CREATE DATABASE $database'",
@ -148,6 +149,8 @@ foreach ($queryList as $exec_command) {
throw new \Exception("[!] Mysql exec error : $exec_command \n Error : \n ".print_r($output,true)); throw new \Exception("[!] Mysql exec error : $exec_command \n Error : \n ".print_r($output,true));
} }
} }
echo "*** In progress: mysql.sql imported\n";
$db = new \DB_system($user,$database,$password); $db = new \DB_system($user,$database,$password);
$db->connect(); $db->connect();
$cuid = 0; $cuid = 0;

View File

@ -62,8 +62,7 @@ class m_variablesTest extends AlterncTest
public function testVariable_init_maybe() public function testVariable_init_maybe()
{ {
$this->object->variable_init_maybe(); $this->object->variable_init_maybe();
global $conf; $this->assertTrue( (is_array($this->object->cache_conf) && !empty($this->object->cache_conf)) );
$this->assertTrue(is_array($conf));
} }
/** /**
@ -73,6 +72,22 @@ class m_variablesTest extends AlterncTest
{ {
$result = $this->object->variable_get("phpunit"); $result = $this->object->variable_get("phpunit");
$this->assertStringMatchesFormat("phpunit",$result); $this->assertStringMatchesFormat("phpunit",$result);
/*
// Check old way
$this->object->variable_get('phpunit1', 'toto','plop');
$result = $this->object->variable_get('phpunit1');
$this->assertSame("toto",$result);
// New way
$this->object->variable_get('phpunit2', 'here','comment', array('desc'=>'Want a string','type'=>'string'));
$result = $this->object->variable_get('phpunit2');
$this->assertSame("here",$result);
$this->object->variable_get('phpunit3', array("ns1"=>'ns1.tld',"ip"=>"1.2.3.4"),'comment', array("ns1"=>array('desc'=>'ns name','type'=>'string'),"ip"=>array("desc"=>"here an ip", "type"=>"ip")));
$result = $this->object->variable_get('phpunit2');
$this->assertSame(array('ns1'=>"ns1.tld", "ip"=>"1.2.3.4"),$result);
*/
} }
/** /**