REFACTORING: code formatting of the panel + braces on if/while/for + fixe some missing or too many Globals in functions
This commit is contained in:
parent
3e42567048
commit
d3ab589e56
|
@ -7,7 +7,6 @@ if (!$admin->enabled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once("head.php");
|
include_once("head.php");
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<h3><?php __("Manage defaults domains type"); ?></h3>
|
<h3><?php __("Manage defaults domains type"); ?></h3>
|
||||||
<hr id="topbar" />
|
<hr id="topbar" />
|
||||||
|
@ -46,32 +45,31 @@ $tab=$dom->lst_default_subdomains();
|
||||||
<form method="post" action="adm_doms_def_type.php" name="main" id="main">
|
<form method="post" action="adm_doms_def_type.php" name="main" id="main">
|
||||||
<table class="tlist">
|
<table class="tlist">
|
||||||
<tr><th> </th><th><?php __("Sub"); ?></th><th><?php __("Type"); ?></th><th><?php __("settings"); ?></th><th><?php __("Concerned"); ?></th><th><?php __("Activation"); ?></th></tr>
|
<tr><th> </th><th><?php __("Sub"); ?></th><th><?php __("Type"); ?></th><th><?php __("settings"); ?></th><th><?php __("Concerned"); ?></th><th><?php __("Activation"); ?></th></tr>
|
||||||
<?php
|
<?php for ($i = 0; $i < count($tab) + 1; $i++) { ?>
|
||||||
for($i=0;$i<count($tab)+1;$i++) {?>
|
|
||||||
<tr class="lst">
|
<tr class="lst">
|
||||||
<td>
|
<td>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
@$val = $tab[$i];
|
@$val = $tab[$i];
|
||||||
if (isset($tab[$i])) {
|
if (isset($tab[$i])) {
|
||||||
echo "<input type='hidden' name='domup[$i][id]' value='" . $val['id'] . "' />";
|
echo "<input type='hidden' name='domup[$i][id]' value='" . $val['id'] . "' />";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<div class="ina delete"><a href='dom_defdel.php?id=<?php echo $val['id']; ?>' type=''><?php __("Delete"); ?></a></div>
|
<div class="ina delete"><a href="dom_defdel.php?id=<?php echo $val['id']; ?>"><?php __("Delete"); ?></a></div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td><input type='text' size="16" name='domup[<?php echo $i; ?>][sub]' value="<?php echo $val['sub']; ?>"/></td>
|
<td><input type='text' size="16" name='domup[<?php echo $i; ?>][sub]' value="<?php echo $val['sub']; ?>"/></td>
|
||||||
<?php $type=array("VHOST","URL","WEBMAIL","");
|
<?php
|
||||||
if(in_array($val['domain_type'],$type)){?>
|
$type = array("VHOST", "URL", "WEBMAIL", "");
|
||||||
|
if (in_array($val['domain_type'], $type)) {
|
||||||
|
?>
|
||||||
<td><select name='domup[<?php echo $i; ?>][domain_type]'>
|
<td><select name='domup[<?php echo $i; ?>][domain_type]'>
|
||||||
<option value='VHOST' <?php if ($val['domain_type'] == 'VHOST') echo "selected=\"selected\""; ?> >VHOST</option>
|
<option value='VHOST' <?php if ($val['domain_type'] == 'VHOST') echo "selected=\"selected\""; ?> >VHOST</option>
|
||||||
<option value='URL' <?php if ($val['domain_type'] == 'URL') echo "selected=\"selected\""; ?> >URL</option>
|
<option value='URL' <?php if ($val['domain_type'] == 'URL') echo "selected=\"selected\""; ?> >URL</option>
|
||||||
<option value='WEBMAIL' <?php if ($val['domain_type'] == 'WEBMAIL') echo "selected=\"selected\""; ?> >WEBMAIL</option>
|
<option value='WEBMAIL' <?php if ($val['domain_type'] == 'WEBMAIL') echo "selected=\"selected\""; ?> >WEBMAIL</option>
|
||||||
</select>
|
</select>
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
<td><input type ='text' width="100px" style="width:100px" name='domup[<?php echo $i; ?>][domain_type]' value='<?php echo $val['domain_type']?>' ></td>
|
<td><input type="text" style="width:100px" name="domup[<?php echo $i; ?>][domain_type]" value="<?php echo $val['domain_type'] ?>" ></td>
|
||||||
<? }?>
|
<?php } ?>
|
||||||
</td>
|
|
||||||
<td><input type ='text' name='domup[<?php echo $i; ?>][domain_type_parameter]' value='<?php echo $val['domain_type_parameter'] ?>' /></td>
|
<td><input type ='text' name='domup[<?php echo $i; ?>][domain_type_parameter]' value='<?php echo $val['domain_type_parameter'] ?>' /></td>
|
||||||
<td><select name='domup[<?php echo $i; ?>][concerned]'>
|
<td><select name='domup[<?php echo $i; ?>][concerned]'>
|
||||||
<option value='MAIN' <?php if ($val['concerned'] == 'MAIN') echo "selected=\"selected\""; ?> >MAIN</option>
|
<option value='MAIN' <?php if ($val['concerned'] == 'MAIN') echo "selected=\"selected\""; ?> >MAIN</option>
|
||||||
|
@ -89,5 +87,5 @@ for($i=0;$i<count($tab)+1;$i++) {?>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
<?php
|
<?php include_once("foot.php");
|
||||||
include_once("foot.php"); ?>
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
$Id: m_authip.php
|
$Id: m_authip.php
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
Original Author of file: Fufroma
|
Original Author of file: Fufroma
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe de gestion des IP authorisée
|
* Classe de gestion des IP authorisée
|
||||||
* @group alternc
|
* @group alternc
|
||||||
|
@ -33,7 +35,9 @@ class m_authip {
|
||||||
*/
|
*/
|
||||||
function list_ip_whitelist() {
|
function list_ip_whitelist() {
|
||||||
global $mem;
|
global $mem;
|
||||||
if (!$mem->checkRight()) return false;
|
if (!$mem->checkRight()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return $this->list_ip(true);
|
return $this->list_ip(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,13 +85,10 @@ class m_authip {
|
||||||
} else {
|
} else {
|
||||||
$r[$db->f('id')]['ip_human'] = $db->f('ip') . "/" . $db->f('subnet');
|
$r[$db->f('id')]['ip_human'] = $db->f('ip') . "/" . $db->f('subnet');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supprime une IP des IP de l'utilisateur
|
* Supprime une IP des IP de l'utilisateur
|
||||||
* et supprime les droits attaché en cascade
|
* et supprime les droits attaché en cascade
|
||||||
|
@ -150,7 +151,8 @@ class m_authip {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
if ( $this->is_in_subnet($ip, $db->f('ip'), $db->f('subnet') ) ) return true;
|
if ($this->is_in_subnet($ip, $db->f('ip'), $db->f('subnet')))
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +170,9 @@ class m_authip {
|
||||||
$ip = inet_pton($ip);
|
$ip = inet_pton($ip);
|
||||||
$sub = pow(2, $sub);
|
$sub = pow(2, $sub);
|
||||||
|
|
||||||
if ( $o >= $ip && $o <= ($ip+$sub) ) return true;
|
if ($o >= $ip && $o <= ($ip + $sub)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +183,9 @@ class m_authip {
|
||||||
*/
|
*/
|
||||||
function ip_save_whitelist($id, $ipsub, $infos) {
|
function ip_save_whitelist($id, $ipsub, $infos) {
|
||||||
global $mem;
|
global $mem;
|
||||||
if (!$mem->checkRight()) return false;
|
if (!$mem->checkRight()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return $this->ip_save($id, $ipsub, $infos, 0);
|
return $this->ip_save($id, $ipsub, $infos, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,12 +232,17 @@ class m_authip {
|
||||||
if (isset($tmp[1])) {
|
if (isset($tmp[1])) {
|
||||||
$subnet = intval($tmp[1]);
|
$subnet = intval($tmp[1]);
|
||||||
} else {
|
} else {
|
||||||
if ( checkip($ip) ) $subnet=32;
|
if (checkip($ip)) {
|
||||||
else $subnet=128;
|
$subnet = 32;
|
||||||
|
} else {
|
||||||
|
$subnet = 128;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// An IPv4 can't have subnet > 32
|
// An IPv4 can't have subnet > 32
|
||||||
if (checkip($ip) && $subnet > 32 ) $subnet=32;
|
if (checkip($ip) && $subnet > 32) {
|
||||||
|
$subnet = 32;
|
||||||
|
}
|
||||||
|
|
||||||
if ($id) { // Update
|
if ($id) { // Update
|
||||||
$list_affected = $this->list_affected($id);
|
$list_affected = $this->list_affected($id);
|
||||||
|
@ -270,7 +281,6 @@ class m_authip {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Analyse les classes et récupéres les informations
|
* Analyse les classes et récupéres les informations
|
||||||
* des classes voulant de la restriction IP
|
* des classes voulant de la restriction IP
|
||||||
|
@ -349,7 +359,6 @@ class m_authip {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appel les hooks demandé avec en parametres les
|
* Appel les hooks demandé avec en parametres les
|
||||||
* affectationt ip<=>ressource dont l'id est en parametre
|
* affectationt ip<=>ressource dont l'id est en parametre
|
||||||
|
@ -409,6 +418,6 @@ class m_authip {
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
}; /* Classe m_authip */
|
}
|
||||||
|
|
||||||
?>
|
/* Classe m_authip */
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -91,8 +92,6 @@ class m_bro {
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifie un dossier relatif au dossier de l'utilisateur courant
|
* Verifie un dossier relatif au dossier de l'utilisateur courant
|
||||||
*
|
*
|
||||||
|
@ -138,10 +137,10 @@ class m_bro {
|
||||||
}
|
}
|
||||||
if (substr($dir, -1) == "/") {
|
if (substr($dir, -1) == "/") {
|
||||||
return substr($dir, 0, strlen($dir) - 1);
|
return substr($dir, 0, strlen($dir) - 1);
|
||||||
} else
|
} else {
|
||||||
return $dir;
|
return $dir;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne le chemin complet vers la racine du repertoire de l'utilisateur.
|
* Retourne le chemin complet vers la racine du repertoire de l'utilisateur.
|
||||||
|
@ -155,7 +154,6 @@ class m_bro {
|
||||||
return getuserpath();
|
return getuserpath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne le chemin complet vers la racine du repertoire de l'utilisateur.
|
* Retourne le chemin complet vers la racine du repertoire de l'utilisateur.
|
||||||
* Returns the complete path to the root of the user's directory.
|
* Returns the complete path to the root of the user's directory.
|
||||||
|
@ -179,7 +177,6 @@ class m_bro {
|
||||||
return $this->get_user_root($member['login']);
|
return $this->get_user_root($member['login']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne un tableau contenant la liste des fichiers du dossier courant
|
* Retourne un tableau contenant la liste des fichiers du dossier courant
|
||||||
*
|
*
|
||||||
|
@ -222,7 +219,6 @@ class m_bro {
|
||||||
return $c;
|
return $c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne un tableau contenant les prfrences de l'utilisateur courant
|
* Retourne un tableau contenant les prfrences de l'utilisateur courant
|
||||||
*
|
*
|
||||||
|
@ -244,7 +240,6 @@ class m_bro {
|
||||||
return $db->Record;
|
return $db->Record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Modifie les prfrences de l'utilisateur courant.
|
Modifie les prfrences de l'utilisateur courant.
|
||||||
*
|
*
|
||||||
|
@ -280,7 +275,6 @@ class m_bro {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne le nom du fichier icone associ au fichier donc le nom est $file
|
* Retourne le nom du fichier icone associ au fichier donc le nom est $file
|
||||||
* <b>Note</b>: Les fichiers icones sont mis en cache sur la page courante.
|
* <b>Note</b>: Les fichiers icones sont mis en cache sur la page courante.
|
||||||
|
@ -295,10 +289,11 @@ class m_bro {
|
||||||
return "file.png";
|
return "file.png";
|
||||||
}
|
}
|
||||||
$t = explode(".", $file);
|
$t = explode(".", $file);
|
||||||
if (!is_array($t))
|
if (!is_array($t)) {
|
||||||
$ext = $t;
|
$ext = $t;
|
||||||
else
|
} else {
|
||||||
$ext = $t[count($t) - 1];
|
$ext = $t[count($t) - 1];
|
||||||
|
}
|
||||||
// Now seek the extension
|
// Now seek the extension
|
||||||
if (!isset($bro_icon[$ext]) || !$bro_icon[$ext]) {
|
if (!isset($bro_icon[$ext]) || !$bro_icon[$ext]) {
|
||||||
return "file.png";
|
return "file.png";
|
||||||
|
@ -307,7 +302,6 @@ class m_bro {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne le type mime associé au fichier donc le nom est $file
|
* Retourne le type mime associé au fichier donc le nom est $file
|
||||||
* <b>Note</b>: Les types mimes sont mis en cache sur la page courante.
|
* <b>Note</b>: Les types mimes sont mis en cache sur la page courante.
|
||||||
|
@ -323,10 +317,11 @@ class m_bro {
|
||||||
return "File";
|
return "File";
|
||||||
}
|
}
|
||||||
$t = explode(".", $file);
|
$t = explode(".", $file);
|
||||||
if (!is_array($t))
|
if (!is_array($t)) {
|
||||||
$ext = $t;
|
$ext = $t;
|
||||||
else
|
} else {
|
||||||
$ext = $t[count($t) - 1];
|
$ext = $t[count($t) - 1];
|
||||||
|
}
|
||||||
// Now seek the extension
|
// Now seek the extension
|
||||||
if (empty($bro_type[$ext])) {
|
if (empty($bro_type[$ext])) {
|
||||||
return "File";
|
return "File";
|
||||||
|
@ -335,7 +330,6 @@ class m_bro {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne la taille du fichier $file
|
* Retourne la taille du fichier $file
|
||||||
* si $file est un dossier, retourne la taille de ce dossier et de tous
|
* si $file est un dossier, retourne la taille de ce dossier et de tous
|
||||||
|
@ -358,7 +352,6 @@ class m_bro {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the size of a directory, by adding all it's files sizes
|
* Returns the size of a directory, by adding all it's files sizes
|
||||||
*
|
*
|
||||||
|
@ -368,7 +361,7 @@ class m_bro {
|
||||||
function dirsize($dir) {
|
function dirsize($dir) {
|
||||||
$totalsize = 0;
|
$totalsize = 0;
|
||||||
|
|
||||||
if ($handle=opendir($dir)) {
|
if (($handle = opendir($dir))) {
|
||||||
while (false !== ($file = readdir($handle))) {
|
while (false !== ($file = readdir($handle))) {
|
||||||
$nextpath = $dir . '/' . $file;
|
$nextpath = $dir . '/' . $file;
|
||||||
|
|
||||||
|
@ -385,7 +378,6 @@ class m_bro {
|
||||||
return $totalsize;
|
return $totalsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crée le dossier $file dans le dossier (parent) $dir
|
* Crée le dossier $file dans le dossier (parent) $dir
|
||||||
*
|
*
|
||||||
|
@ -414,7 +406,6 @@ class m_bro {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crée un fichier vide dans un dossier
|
* Crée un fichier vide dans un dossier
|
||||||
*
|
*
|
||||||
|
@ -443,7 +434,6 @@ class m_bro {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Efface les fichiers du tableau $file_list dans le dossier $R
|
* Efface les fichiers du tableau $file_list dans le dossier $R
|
||||||
*
|
*
|
||||||
|
@ -454,7 +444,7 @@ class m_bro {
|
||||||
* @return boolean TRUE si les fichiers ont t effacs, FALSE si une erreur s'est produite.
|
* @return boolean TRUE si les fichiers ont t effacs, FALSE si une erreur s'est produite.
|
||||||
*/
|
*/
|
||||||
function DeleteFile($file_list, $R) {
|
function DeleteFile($file_list, $R) {
|
||||||
global $err, $mem;
|
global $err;
|
||||||
$root = realpath(getuserpath());
|
$root = realpath(getuserpath());
|
||||||
$absolute = $this->convertabsolute($R, false);
|
$absolute = $this->convertabsolute($R, false);
|
||||||
if (!$absolute && strpos($root, $absolute) === 0 && strlen($absolute) > (strlen($root) + 1)) {
|
if (!$absolute && strpos($root, $absolute) === 0 && strlen($absolute) > (strlen($root) + 1)) {
|
||||||
|
@ -470,7 +460,6 @@ class m_bro {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renomme les fichier de $old du dossier $R en $new
|
* Renomme les fichier de $old du dossier $R en $new
|
||||||
*
|
*
|
||||||
|
@ -504,7 +493,6 @@ class m_bro {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Déplace les fichier de $d du dossier $old vers $new
|
* Déplace les fichier de $d du dossier $old vers $new
|
||||||
*
|
*
|
||||||
|
@ -538,20 +526,20 @@ class m_bro {
|
||||||
for ($i = 0; $i < count($d); $i++) {
|
for ($i = 0; $i < count($d); $i++) {
|
||||||
$d[$i] = ssla($d[$i]); // strip slashes if needed
|
$d[$i] = ssla($d[$i]); // strip slashes if needed
|
||||||
if (!strpos($d[$i], "/") && file_exists($old . "/" . $d[$i]) && !file_exists($new . "/" . $d[$i])) {
|
if (!strpos($d[$i], "/") && file_exists($old . "/" . $d[$i]) && !file_exists($new . "/" . $d[$i])) {
|
||||||
if (!rename($old."/".$d[$i],$new."/".$d[$i]))
|
if (!rename($old . "/" . $d[$i], $new . "/" . $d[$i])) {
|
||||||
$err->raise("bro", "error renaming $old/$d[$i] -> $new/$d[$i]");
|
$err->raise("bro", "error renaming $old/$d[$i] -> $new/$d[$i]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change les droits d'acces aux fichier de $d du dossier $R en $p
|
* Change les droits d'acces aux fichier de $d du dossier $R en $p
|
||||||
*
|
*
|
||||||
* @global m_err $err
|
|
||||||
* @global m_action $action
|
|
||||||
* @param string $R Dossier dans lequel se trouve les fichiers renommer.
|
* @param string $R Dossier dans lequel se trouve les fichiers renommer.
|
||||||
|
* @param string $d list of files whose permission must be changed
|
||||||
|
* @param string $perm the permission to change
|
||||||
* @param boolean $verbose Shall we 'echo' what we did ?
|
* @param boolean $verbose Shall we 'echo' what we did ?
|
||||||
* @return boolean TRUE Si les fichiers ont t renomms, FALSE si une erreur s'est produite.
|
* @return boolean TRUE Si les fichiers ont t renomms, FALSE si une erreur s'est produite.
|
||||||
*/
|
*/
|
||||||
|
@ -584,7 +572,6 @@ class m_bro {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recoit un champ file upload (Global) et le stocke dans le dossier $R
|
* Recoit un champ file upload (Global) et le stocke dans le dossier $R
|
||||||
* Le champ file-upload originel doit s'appeler "userfile" et doit
|
* Le champ file-upload originel doit s'appeler "userfile" et doit
|
||||||
|
@ -641,7 +628,6 @@ class m_bro {
|
||||||
return $absolute . "/" . $_FILES['userfile']['name'];
|
return $absolute . "/" . $_FILES['userfile']['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract an archive by using GNU and non-GNU tools
|
* Extract an archive by using GNU and non-GNU tools
|
||||||
*
|
*
|
||||||
|
@ -655,7 +641,7 @@ class m_bro {
|
||||||
* @return integer|null != 0 on error
|
* @return integer|null != 0 on error
|
||||||
*/
|
*/
|
||||||
function ExtractFile($file, $dest = null) {
|
function ExtractFile($file, $dest = null) {
|
||||||
global $err,$cuid,$mem,$action;
|
global $err, $action;
|
||||||
$file = $this->convertabsolute($file, false);
|
$file = $this->convertabsolute($file, false);
|
||||||
if (is_null($dest)) {
|
if (is_null($dest)) {
|
||||||
$dest = dirname($file);
|
$dest = dirname($file);
|
||||||
|
@ -671,6 +657,7 @@ class m_bro {
|
||||||
// TODO new version of tar supports `tar xf ...` so there is no
|
// TODO new version of tar supports `tar xf ...` so there is no
|
||||||
// need to specify the compression format
|
// need to specify the compression format
|
||||||
echo "<p>" . _("Uncompressing through TAR") . "</p><pre style=\"overflow: scroll; height: 200px\">";
|
echo "<p>" . _("Uncompressing through TAR") . "</p><pre style=\"overflow: scroll; height: 200px\">";
|
||||||
|
$ret = 0;
|
||||||
passthru("tar -xf " . escapeshellarg($file) . " -C " . escapeshellarg($dest) . " 2>&1", $ret);
|
passthru("tar -xf " . escapeshellarg($file) . " -C " . escapeshellarg($dest) . " 2>&1", $ret);
|
||||||
}
|
}
|
||||||
if (substr($lfile, -4) == ".zip") {
|
if (substr($lfile, -4) == ".zip") {
|
||||||
|
@ -687,12 +674,11 @@ class m_bro {
|
||||||
if ($ret) {
|
if ($ret) {
|
||||||
$err->raise("bro", _("I cannot find a way to extract the file %s, it is an unsupported compressed format"), $file);
|
$err->raise("bro", _("I cannot find a way to extract the file %s, it is an unsupported compressed format"), $file);
|
||||||
}
|
}
|
||||||
// fix the perms of the extracted archive TODO: does it work???
|
// fix the perms of the extracted archive TODO: does it work??? | note: it was using a wrong variable name !
|
||||||
$action->fix_dir($dest_to_fix);
|
$action->fix_dir($dest);
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy many files from point A to point B
|
* Copy many files from point A to point B
|
||||||
*
|
*
|
||||||
|
@ -727,7 +713,6 @@ class m_bro {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy a source to a destination by either copying recursively a
|
* Copy a source to a destination by either copying recursively a
|
||||||
* directory or by downloading a file with a URL (only http:// is
|
* directory or by downloading a file with a URL (only http:// is
|
||||||
|
@ -750,7 +735,6 @@ class m_bro {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Affiche le chemin et les liens de la racine au dossier $path
|
* Affiche le chemin et les liens de la racine au dossier $path
|
||||||
* Affiche autant de liens HTML (anchor) que le chemin $path contient de
|
* Affiche autant de liens HTML (anchor) que le chemin $path contient de
|
||||||
|
@ -765,7 +749,9 @@ class m_bro {
|
||||||
function PathList($path, $action, $justparent = false) {
|
function PathList($path, $action, $justparent = false) {
|
||||||
$path = $this->convertabsolute($path, true);
|
$path = $this->convertabsolute($path, true);
|
||||||
$a = explode("/", $path);
|
$a = explode("/", $path);
|
||||||
if (!is_array($a)) $a=array($a);
|
if (!is_array($a)) {
|
||||||
|
$a = array($a);
|
||||||
|
}
|
||||||
$c = '';
|
$c = '';
|
||||||
$R = '';
|
$R = '';
|
||||||
if ($justparent) {
|
if ($justparent) {
|
||||||
|
@ -780,7 +766,6 @@ class m_bro {
|
||||||
return $c;
|
return $c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Affiche le contenu d'un fichier pour un champ VALUE de textarea
|
* Affiche le contenu d'un fichier pour un champ VALUE de textarea
|
||||||
*
|
*
|
||||||
|
@ -811,8 +796,6 @@ class m_bro {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne une url de navigation pour le fichier $name du dossier $dir
|
* Retourne une url de navigation pour le fichier $name du dossier $dir
|
||||||
* Les url sont mises en caches. Il se peut qu'aucune url n'existe, ou que
|
* Les url sont mises en caches. Il se peut qu'aucune url n'existe, ou que
|
||||||
|
@ -831,13 +814,19 @@ class m_bro {
|
||||||
function viewurl($dir, $name) {
|
function viewurl($dir, $name) {
|
||||||
global $db, $cuid;
|
global $db, $cuid;
|
||||||
// Is it in cache ?
|
// Is it in cache ?
|
||||||
if (substr($dir,0,1) == "/") $dir=substr($dir,1);
|
if (substr($dir, 0, 1) == "/") {
|
||||||
if (substr($dir,-1) == "/") $dir=substr($dir,0,-1);
|
$dir = substr($dir, 1);
|
||||||
|
}
|
||||||
|
if (substr($dir, -1) == "/") {
|
||||||
|
$dir = substr($dir, 0, -1);
|
||||||
|
}
|
||||||
$dir = str_replace("%2F", "/", urlencode($dir));
|
$dir = str_replace("%2F", "/", urlencode($dir));
|
||||||
$name = urlencode($name);
|
$name = urlencode($name);
|
||||||
if (!@$this->cacheurl["d" . $dir]) {
|
if (!@$this->cacheurl["d" . $dir]) {
|
||||||
// On parcours $dir en remontant les /
|
// On parcours $dir en remontant les /
|
||||||
$end=""; $beg=$dir; $tofind=true;
|
$end = "";
|
||||||
|
$beg = $dir;
|
||||||
|
$tofind = true;
|
||||||
while ($tofind) {
|
while ($tofind) {
|
||||||
$db->query("SELECT sub,domaine FROM sub_domaines WHERE compte='$cuid'
|
$db->query("SELECT sub,domaine FROM sub_domaines WHERE compte='$cuid'
|
||||||
AND type=0 AND (valeur='/$beg/' or valeur='/$beg');");
|
AND type=0 AND (valeur='/$beg/' or valeur='/$beg');");
|
||||||
|
@ -876,7 +865,7 @@ class m_bro {
|
||||||
* @return null|boolean
|
* @return null|boolean
|
||||||
*/
|
*/
|
||||||
function can_edit($dir, $name) {
|
function can_edit($dir, $name) {
|
||||||
global $mem,$err;
|
global $err;
|
||||||
$absolute = "$dir/$name";
|
$absolute = "$dir/$name";
|
||||||
$absolute = $this->convertabsolute($absolute, false);
|
$absolute = $this->convertabsolute($absolute, false);
|
||||||
if (!$absolute) {
|
if (!$absolute) {
|
||||||
|
@ -892,7 +881,6 @@ class m_bro {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a HTML snippet representing an extraction function only if the mimetype of $name is supported
|
* Return a HTML snippet representing an extraction function only if the mimetype of $name is supported
|
||||||
*
|
*
|
||||||
|
@ -900,7 +888,7 @@ class m_bro {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function is_extractable($name) {
|
function is_extractable($name) {
|
||||||
if ($parts=explode(".", $name)) {
|
if (($parts = explode(".", $name))) {
|
||||||
$ext = array_pop($parts);
|
$ext = array_pop($parts);
|
||||||
switch ($ext) {
|
switch ($ext) {
|
||||||
case "gz":
|
case "gz":
|
||||||
|
@ -931,10 +919,12 @@ class m_bro {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function is_sqlfile($name) {
|
function is_sqlfile($name) {
|
||||||
if ($parts=explode(".", $name)) {
|
if (($parts = explode(".", $name))) {
|
||||||
$ext = array_pop($parts);
|
$ext = array_pop($parts);
|
||||||
$ext2 = array_pop($parts) . '.' . $ext;
|
$ext2 = array_pop($parts) . '.' . $ext;
|
||||||
if ( $ext == 'sql' or $ext2 == 'sql.gz') return true;
|
if ($ext == 'sql' or $ext2 == 'sql.gz') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -954,7 +944,6 @@ class m_bro {
|
||||||
$this->content_send($dir, $file);
|
$this->content_send($dir, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Echoes the content of the file $file located in directory $R
|
* Echoes the content of the file $file located in directory $R
|
||||||
*
|
*
|
||||||
|
@ -977,7 +966,6 @@ class m_bro {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sauve le fichier $file dans le dossier $R avec pour contenu $texte
|
* Sauve le fichier $file dans le dossier $R avec pour contenu $texte
|
||||||
* le contenu est issu d'un textarea, et ne DOIT PAS contenir de \ ajouts
|
* le contenu est issu d'un textarea, et ne DOIT PAS contenir de \ ajouts
|
||||||
|
@ -1007,7 +995,6 @@ class m_bro {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Echo d'un flux .tar.Z contenant tout le contenu du dossier $dir
|
* Echo d'un flux .tar.Z contenant tout le contenu du dossier $dir
|
||||||
*
|
*
|
||||||
|
@ -1025,7 +1012,6 @@ class m_bro {
|
||||||
passthru("/bin/tar -cZ -C " . getuserpath() . "/" . $mem->user["login"] . "/ $d");
|
passthru("/bin/tar -cZ -C " . getuserpath() . "/" . $mem->user["login"] . "/ $d");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Echo d'un flux .tgz contenant tout le contenu du dossier $dir
|
* Echo d'un flux .tgz contenant tout le contenu du dossier $dir
|
||||||
*
|
*
|
||||||
|
@ -1043,7 +1029,6 @@ class m_bro {
|
||||||
passthru("/bin/tar -cz -C " . getuserpath() . "/ $d");
|
passthru("/bin/tar -cz -C " . getuserpath() . "/ $d");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Echo d'un flux .tar.bz2 contenant tout le contenu du dossier $dir
|
* Echo d'un flux .tar.bz2 contenant tout le contenu du dossier $dir
|
||||||
*
|
*
|
||||||
|
@ -1061,8 +1046,6 @@ class m_bro {
|
||||||
passthru("/bin/tar -cj -C " . getuserpath() . "/ $d");
|
passthru("/bin/tar -cj -C " . getuserpath() . "/ $d");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Echo d'un flux .ZIP contenant tout le contenu du dossier $dir
|
* Echo d'un flux .ZIP contenant tout le contenu du dossier $dir
|
||||||
*
|
*
|
||||||
|
@ -1080,7 +1063,6 @@ class m_bro {
|
||||||
passthru("/usr/bin/zip -r - $d");
|
passthru("/usr/bin/zip -r - $d");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fonction de tri perso utilis par filelist.
|
* Fonction de tri perso utilis par filelist.
|
||||||
*
|
*
|
||||||
|
@ -1090,12 +1072,15 @@ class m_bro {
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function _sort_filelist_name($a, $b) {
|
function _sort_filelist_name($a, $b) {
|
||||||
if ($a["type"] && !$b["type"]) return 1;
|
if ($a["type"] && !$b["type"]) {
|
||||||
if ($b["type"] && !$a["type"]) return -1;
|
return 1;
|
||||||
|
}
|
||||||
|
if ($b["type"] && !$a["type"]) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return $a["name"] > $b["name"];
|
return $a["name"] > $b["name"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Efface $file et tous ses sous-dossiers s'il s'agit d'un dossier
|
* Efface $file et tous ses sous-dossiers s'il s'agit d'un dossier
|
||||||
* A UTILISER AVEC PRECAUTION !!!
|
* A UTILISER AVEC PRECAUTION !!!
|
||||||
|
@ -1122,7 +1107,6 @@ class m_bro {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function d'exportation de configuration appelé par la classe m_export via un hooks
|
* Function d'exportation de configuration appelé par la classe m_export via un hooks
|
||||||
* Produit en sorti un tableau formatté ( pour le moment) en HTML
|
* Produit en sorti un tableau formatté ( pour le moment) en HTML
|
||||||
|
@ -1132,7 +1116,7 @@ class m_bro {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function alternc_export_conf() {
|
function alternc_export_conf() {
|
||||||
global $db,$err;
|
global $err;
|
||||||
$err->log("bro", "export_conf");
|
$err->log("bro", "export_conf");
|
||||||
$str = "<table border=\"1\"><caption> Browser </caption>\n";
|
$str = "<table border=\"1\"><caption> Browser </caption>\n";
|
||||||
$str.=" <browser>\n";
|
$str.=" <browser>\n";
|
||||||
|
@ -1150,7 +1134,6 @@ class m_bro {
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function d'exportation des données appelé par la classe m_export via un hooks
|
* Function d'exportation des données appelé par la classe m_export via un hooks
|
||||||
*
|
*
|
||||||
|
@ -1174,12 +1157,12 @@ class m_bro {
|
||||||
} else {
|
} else {
|
||||||
$err->log("bro", "export_data_failed");
|
$err->log("bro", "export_data_failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMaxAllowedUploadSize() {
|
function getMaxAllowedUploadSize() {
|
||||||
return min(ini_get('post_max_size'), ini_get('upload_max_filesize'));
|
return min(ini_get('post_max_size'), ini_get('upload_max_filesize'));
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* Class Browser */
|
}
|
||||||
|
|
||||||
|
/* Class Browser */
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -32,9 +33,11 @@ class m_cron {
|
||||||
const DEFAULT_CAFILE = "/etc/ssl/certs/ca-certificates.crt";
|
const DEFAULT_CAFILE = "/etc/ssl/certs/ca-certificates.crt";
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Constructor
|
/** Constructor
|
||||||
*/
|
*/
|
||||||
function m_cron() {
|
function m_cron() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function schedule() {
|
function schedule() {
|
||||||
|
@ -45,8 +48,8 @@ class m_cron {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** List the crontab for the current user.
|
/** List the crontab for the current user.
|
||||||
* @return array an hash for each crontab.
|
* @return array an hash for each crontab.
|
||||||
*/
|
*/
|
||||||
|
@ -81,6 +84,7 @@ class m_cron {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** update the crontab
|
/** update the crontab
|
||||||
* @param $arr array the crontab information, including its ID
|
* @param $arr array the crontab information, including its ID
|
||||||
* @return boolean TRUE if the crontab has been edited
|
* @return boolean TRUE if the crontab has been edited
|
||||||
|
@ -88,8 +92,12 @@ class m_cron {
|
||||||
function update($arr) {
|
function update($arr) {
|
||||||
$ok = true;
|
$ok = true;
|
||||||
foreach ($arr as $a) {
|
foreach ($arr as $a) {
|
||||||
if (! isset($a['id'])) $a['id']=null;
|
if (!isset($a['id'])) {
|
||||||
if (empty($a['url']) && is_null($a['id'])) continue;
|
$a['id'] = null;
|
||||||
|
}
|
||||||
|
if (empty($a['url']) && is_null($a['id'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!$this->_update_one($a['url'], $a['user'], $a['password'], $a['email'], $a['schedule'], $a['id'])) {
|
if (!$this->_update_one($a['url'], $a['user'], $a['password'], $a['email'], $a['schedule'], $a['id'])) {
|
||||||
$ok = false;
|
$ok = false;
|
||||||
}
|
}
|
||||||
|
@ -97,8 +105,8 @@ class m_cron {
|
||||||
return $ok;
|
return $ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** delete a crontab
|
/** delete a crontab
|
||||||
* @param $id the id of the crontab to delete
|
* @param $id the id of the crontab to delete
|
||||||
* @return boolean TRUE if the crontab has been deleted
|
* @return boolean TRUE if the crontab has been deleted
|
||||||
|
@ -109,8 +117,8 @@ class m_cron {
|
||||||
return $db->query("DELETE FROM cron WHERE id=" . intval($id) . " AND uid=$cuid LIMIT 1;");
|
return $db->query("DELETE FROM cron WHERE id=" . intval($id) . " AND uid=$cuid LIMIT 1;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** update a crontab,
|
/** update a crontab,
|
||||||
* @return boolean TRUE if the crontab has been edited
|
* @return boolean TRUE if the crontab has been edited
|
||||||
*/
|
*/
|
||||||
|
@ -129,7 +137,9 @@ class m_cron {
|
||||||
}
|
}
|
||||||
$url = urlencode($url);
|
$url = urlencode($url);
|
||||||
$user = urlencode($user);
|
$user = urlencode($user);
|
||||||
if (empty($user)) $password='';
|
if (empty($user)) {
|
||||||
|
$password = '';
|
||||||
|
}
|
||||||
$password = urlencode($password);
|
$password = urlencode($password);
|
||||||
|
|
||||||
//@todo remove checkmail cf functions.php
|
//@todo remove checkmail cf functions.php
|
||||||
|
@ -138,7 +148,9 @@ class m_cron {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$email = urlencode($email);
|
$email = urlencode($email);
|
||||||
if (! $this->valid_schedule($schedule)) return false;
|
if (!$this->valid_schedule($schedule)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_null($id)) { // if a new insert, quotacheck
|
if (is_null($id)) { // if a new insert, quotacheck
|
||||||
$q = $quota->getquota("cron");
|
$q = $quota->getquota("cron");
|
||||||
|
@ -160,23 +172,28 @@ class m_cron {
|
||||||
return $db->query("$query");
|
return $db->query("$query");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** validate a crontab schedule
|
/** validate a crontab schedule
|
||||||
* @param $s array schedule paramters
|
* @param $s array schedule paramters
|
||||||
* @return boolean TRUE if the schedule is valid
|
* @return boolean TRUE if the schedule is valid
|
||||||
*/
|
*/
|
||||||
function valid_schedule($s) {
|
function valid_schedule($s) {
|
||||||
$s2 = intval($s);
|
$s2 = intval($s);
|
||||||
if ($s2 != $s) return false;
|
if ($s2 != $s) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$r = false;
|
$r = false;
|
||||||
foreach ($this->schedule() as $cs) {
|
foreach ($this->schedule() as $cs) {
|
||||||
if ($cs['unit'] == $s) return true;
|
if ($cs['unit'] == $s) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** hook for quota computation
|
/** hook for quota computation
|
||||||
*/
|
*/
|
||||||
function hook_quota_get() {
|
function hook_quota_get() {
|
||||||
|
@ -191,6 +208,7 @@ class m_cron {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the required crontab of AlternC users
|
* Execute the required crontab of AlternC users
|
||||||
* this function EXIT at the end.
|
* this function EXIT at the end.
|
||||||
|
@ -198,13 +216,17 @@ class m_cron {
|
||||||
function execute_cron() {
|
function execute_cron() {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
if (!isset($GLOBALS["DEBUG"])) $GLOBALS["DEBUG"]=false;
|
if (!isset($GLOBALS["DEBUG"])) {
|
||||||
|
$GLOBALS["DEBUG"] = false;
|
||||||
|
}
|
||||||
$db->query("SELECT id, url, email, schedule, user, password FROM cron WHERE next_execution <= NOW();");
|
$db->query("SELECT id, url, email, schedule, user, password FROM cron WHERE next_execution <= NOW();");
|
||||||
$urllist = array();
|
$urllist = array();
|
||||||
|
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$db->Record["url"]=urldecode($db->Record["url"]); $db->Record["user"]=urldecode($db->Record["user"]);
|
$db->Record["url"] = urldecode($db->Record["url"]);
|
||||||
$db->Record["email"]=urldecode($db->Record["email"]); $db->Record["password"]=urldecode($db->Record["password"]);
|
$db->Record["user"] = urldecode($db->Record["user"]);
|
||||||
|
$db->Record["email"] = urldecode($db->Record["email"]);
|
||||||
|
$db->Record["password"] = urldecode($db->Record["password"]);
|
||||||
|
|
||||||
// we support only http or https schemes:
|
// we support only http or https schemes:
|
||||||
if (substr($db->Record["url"], 0, 7) == "http://" || substr($db->Record["url"], 0, 8) == "https://") {
|
if (substr($db->Record["url"], 0, 7) == "http://" || substr($db->Record["url"], 0, 8) == "https://") {
|
||||||
|
@ -217,7 +239,8 @@ class m_cron {
|
||||||
$u["login"] = $db->Record["user"];
|
$u["login"] = $db->Record["user"];
|
||||||
$u["password"] = $db->Record["password"];
|
$u["password"] = $db->Record["password"];
|
||||||
}
|
}
|
||||||
if ($GLOBALS["DEBUG"]) echo "Will run cron :\n".print_r($u,true)."\n";
|
if ($GLOBALS["DEBUG"])
|
||||||
|
echo "Will run cron :\n" . print_r($u, true) . "\n";
|
||||||
$urllist[] = $u;
|
$urllist[] = $u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,16 +253,17 @@ class m_cron {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback function called by rolling_curl when a cron resulr has been received
|
* Callback function called by rolling_curl when a cron resulr has been received
|
||||||
* schedule it for next run and send the mail if needed
|
* schedule it for next run and send the mail if needed
|
||||||
*/
|
*/
|
||||||
function cron_callback($url, $content, $curl) {
|
function cron_callback($url, $content, $curl) {
|
||||||
global $db, $L_FQDN;
|
global $db, $L_FQDN;
|
||||||
if (empty($url["id"])) return; // not normal...
|
if (empty($url["id"])) {
|
||||||
|
return; // not normal...
|
||||||
|
}
|
||||||
$id = intval($url["id"]);
|
$id = intval($url["id"]);
|
||||||
|
|
||||||
if ($curl["http_code"] == 200) {
|
if ($curl["http_code"] == 200) {
|
||||||
|
@ -256,9 +280,8 @@ class m_cron {
|
||||||
$db->query("UPDATE cron SET next_execution=FROM_UNIXTIME( UNIX_TIMESTAMP(NOW()) + schedule * 60) WHERE id=$id");
|
$db->query("UPDATE cron SET next_execution=FROM_UNIXTIME( UNIX_TIMESTAMP(NOW()) + schedule * 60) WHERE id=$id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch parallel (using MAX_SOCKETS sockets maximum) retrieval
|
* Launch parallel (using MAX_SOCKETS sockets maximum) retrieval
|
||||||
* of URL using CURL
|
* of URL using CURL
|
||||||
|
@ -273,12 +296,12 @@ class m_cron {
|
||||||
*/
|
*/
|
||||||
function rolling_curl($urls, $callback, $custom_options = null) {
|
function rolling_curl($urls, $callback, $custom_options = null) {
|
||||||
// make sure the rolling window isn't greater than the # of urls
|
// make sure the rolling window isn't greater than the # of urls
|
||||||
if (!isset($GLOBALS["DEBUG"])) $GLOBALS["DEBUG"]=false;
|
if (!isset($GLOBALS["DEBUG"]))
|
||||||
|
$GLOBALS["DEBUG"] = false;
|
||||||
$rolling_window = m_cron::MAX_SOCKETS;
|
$rolling_window = m_cron::MAX_SOCKETS;
|
||||||
$rolling_window = (count($urls) < $rolling_window) ? count($urls) : $rolling_window;
|
$rolling_window = (count($urls) < $rolling_window) ? count($urls) : $rolling_window;
|
||||||
|
|
||||||
$master = curl_multi_init();
|
$master = curl_multi_init();
|
||||||
$curl_arr = array();
|
|
||||||
|
|
||||||
// add additional curl options here
|
// add additional curl options here
|
||||||
$std_options = array(CURLOPT_RETURNTRANSFER => true,
|
$std_options = array(CURLOPT_RETURNTRANSFER => true,
|
||||||
|
@ -288,37 +311,49 @@ class m_cron {
|
||||||
CURLOPT_USERAGENT => "AlternC (Cron Daemon)",
|
CURLOPT_USERAGENT => "AlternC (Cron Daemon)",
|
||||||
CURLOPT_MAXREDIRS => 0);
|
CURLOPT_MAXREDIRS => 0);
|
||||||
|
|
||||||
if ($GLOBALS["DEBUG"]) $std_options[CURLOPT_VERBOSE]=true;
|
if ($GLOBALS["DEBUG"]) {
|
||||||
|
$std_options[CURLOPT_VERBOSE] = true;
|
||||||
|
}
|
||||||
$options = ($custom_options) ? ($std_options + $custom_options) : $std_options;
|
$options = ($custom_options) ? ($std_options + $custom_options) : $std_options;
|
||||||
|
|
||||||
// start the first batch of requests
|
// start the first batch of requests
|
||||||
for ($i = 0; $i < $rolling_window; $i++) {
|
for ($i = 0; $i < $rolling_window; $i++) {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
$options[CURLOPT_URL] = $urls[$i]["url"];
|
$options[CURLOPT_URL] = $urls[$i]["url"];
|
||||||
if ($GLOBALS["DEBUG"]) echo "URL: ".$urls[$i]["url"]."\n";
|
if ($GLOBALS["DEBUG"]) {
|
||||||
|
echo "URL: " . $urls[$i]["url"] . "\n";
|
||||||
|
}
|
||||||
curl_setopt_array($ch, $options);
|
curl_setopt_array($ch, $options);
|
||||||
// Handle custom cafile for some https url
|
// Handle custom cafile for some https url
|
||||||
if (strtolower(substr($options[CURLOPT_URL], 0, 5)) == "https") {
|
if (strtolower(substr($options[CURLOPT_URL], 0, 5)) == "https") {
|
||||||
curl_setopt($ch, CURLOPT_CAINFO, m_cron::DEFAULT_CAFILE);
|
curl_setopt($ch, CURLOPT_CAINFO, m_cron::DEFAULT_CAFILE);
|
||||||
if ($GLOBALS["DEBUG"]) echo "cainfo set to DEFAULT\n";
|
if ($GLOBALS["DEBUG"]) {
|
||||||
|
echo "cainfo set to DEFAULT\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isset($urls[$i]["login"]) && isset($urls[$i]["password"])) { // set basic http authentication
|
if (isset($urls[$i]["login"]) && isset($urls[$i]["password"])) { // set basic http authentication
|
||||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||||
curl_setopt($ch, CURLOPT_USERPWD, $urls[$i]["login"] . ":" . $urls[$i]["password"]);
|
curl_setopt($ch, CURLOPT_USERPWD, $urls[$i]["login"] . ":" . $urls[$i]["password"]);
|
||||||
if ($GLOBALS["DEBUG"]) echo "set basic auth\n";
|
if ($GLOBALS["DEBUG"]) {
|
||||||
|
echo "set basic auth\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
curl_multi_add_handle($master, $ch);
|
curl_multi_add_handle($master, $ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
while (($execrun = curl_multi_exec($master, $running)) == CURLM_CALL_MULTI_PERFORM);
|
while (($execrun = curl_multi_exec($master, $running)) == CURLM_CALL_MULTI_PERFORM);
|
||||||
if($execrun != CURLM_OK)
|
if ($execrun != CURLM_OK) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
// a request was just completed -- find out which one
|
// a request was just completed -- find out which one
|
||||||
while ($done = curl_multi_info_read($master)) {
|
while ($done = curl_multi_info_read($master)) {
|
||||||
$info = curl_getinfo($done['handle']);
|
$info = curl_getinfo($done['handle']);
|
||||||
// TODO : since ssl_verify_result is buggy, if we have [header_size] => 0 && [request_size] => 0 && [http_code] => 0, AND https, we can pretend the SSL certificate is buggy.
|
// TODO : since ssl_verify_result is buggy, if we have [header_size] => 0 && [request_size] => 0 && [http_code] => 0, AND https, we can pretend the SSL certificate is buggy.
|
||||||
if ($GLOBALS["DEBUG"]) { echo "Info for ".$done['handle']." \n"; print_r($info); }
|
if ($GLOBALS["DEBUG"]) {
|
||||||
|
echo "Info for " . $done['handle'] . " \n";
|
||||||
|
print_r($info);
|
||||||
|
}
|
||||||
if ($info['http_code'] == 200) {
|
if ($info['http_code'] == 200) {
|
||||||
$output = curl_multi_getcontent($done['handle']);
|
$output = curl_multi_getcontent($done['handle']);
|
||||||
} else {
|
} else {
|
||||||
|
@ -342,12 +377,16 @@ class m_cron {
|
||||||
curl_setopt_array($ch, $options);
|
curl_setopt_array($ch, $options);
|
||||||
if (strtolower(substr($options[CURLOPT_URL], 0, 5)) == "https") {
|
if (strtolower(substr($options[CURLOPT_URL], 0, 5)) == "https") {
|
||||||
curl_setopt($ch, CURLOPT_CAINFO, m_cron::DEFAULT_CAFILE);
|
curl_setopt($ch, CURLOPT_CAINFO, m_cron::DEFAULT_CAFILE);
|
||||||
if ($GLOBALS["DEBUG"]) echo "cainfo set to DEFAULT\n";
|
if ($GLOBALS["DEBUG"]) {
|
||||||
|
echo "cainfo set to DEFAULT\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isset($urls[$i]["login"]) && isset($urls[$i]["password"])) { // set basic http authentication
|
if (isset($urls[$i]["login"]) && isset($urls[$i]["password"])) { // set basic http authentication
|
||||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||||
curl_setopt($ch, CURLOPT_USERPWD, urlencode($urls[$i]["login"]) . ":" . urlencode($urls[$i]["password"]));
|
curl_setopt($ch, CURLOPT_USERPWD, urlencode($urls[$i]["login"]) . ":" . urlencode($urls[$i]["password"]));
|
||||||
if ($GLOBALS["DEBUG"]) echo "set basic auth\n";
|
if ($GLOBALS["DEBUG"]) {
|
||||||
|
echo "set basic auth\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
curl_multi_add_handle($master, $ch);
|
curl_multi_add_handle($master, $ch);
|
||||||
}
|
}
|
||||||
|
@ -360,5 +399,6 @@ class m_cron {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} /* Class cron */
|
/* Class cron */
|
||||||
|
|
|
@ -1,41 +1,28 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class m_crypto
|
class m_crypto {
|
||||||
{
|
|
||||||
function encrypt($sValue, $sSecretKey)
|
function encrypt($sValue, $sSecretKey) {
|
||||||
{
|
|
||||||
return rtrim(
|
return rtrim(
|
||||||
base64_encode(
|
base64_encode(
|
||||||
mcrypt_encrypt(
|
mcrypt_encrypt(
|
||||||
MCRYPT_RIJNDAEL_256,
|
MCRYPT_RIJNDAEL_256, $sSecretKey, $sValue, MCRYPT_MODE_ECB, mcrypt_create_iv(
|
||||||
$sSecretKey, $sValue,
|
|
||||||
MCRYPT_MODE_ECB,
|
|
||||||
mcrypt_create_iv(
|
|
||||||
mcrypt_get_iv_size(
|
mcrypt_get_iv_size(
|
||||||
MCRYPT_RIJNDAEL_256,
|
MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB
|
||||||
MCRYPT_MODE_ECB
|
), MCRYPT_RAND
|
||||||
),
|
|
||||||
MCRYPT_RAND
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
), "\0"
|
), "\0"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function decrypt($sValue, $sSecretKey)
|
function decrypt($sValue, $sSecretKey) {
|
||||||
{
|
|
||||||
return rtrim(
|
return rtrim(
|
||||||
mcrypt_decrypt(
|
mcrypt_decrypt(
|
||||||
MCRYPT_RIJNDAEL_256,
|
MCRYPT_RIJNDAEL_256, $sSecretKey, base64_decode($sValue), MCRYPT_MODE_ECB, mcrypt_create_iv(
|
||||||
$sSecretKey,
|
|
||||||
base64_decode($sValue),
|
|
||||||
MCRYPT_MODE_ECB,
|
|
||||||
mcrypt_create_iv(
|
|
||||||
mcrypt_get_iv_size(
|
mcrypt_get_iv_size(
|
||||||
MCRYPT_RIJNDAEL_256,
|
MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB
|
||||||
MCRYPT_MODE_ECB
|
), MCRYPT_RAND
|
||||||
),
|
|
||||||
MCRYPT_RAND
|
|
||||||
)
|
)
|
||||||
), "\0"
|
), "\0"
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
LICENSE
|
LICENSE
|
||||||
|
|
||||||
|
@ -18,12 +19,14 @@
|
||||||
Purpose of file: Manage hook system.
|
Purpose of file: Manage hook system.
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manage debug.
|
* This class manage debug.
|
||||||
*
|
*
|
||||||
* @copyright AlternC-Team 2002-2005 http://alternc.org/
|
* @copyright AlternC-Team 2002-2005 http://alternc.org/
|
||||||
*/
|
*/
|
||||||
class m_debug_alternc {
|
class m_debug_alternc {
|
||||||
|
|
||||||
var $infos = "";
|
var $infos = "";
|
||||||
var $status = false;
|
var $status = false;
|
||||||
var $nb_sql_query = 0;
|
var $nb_sql_query = 0;
|
||||||
|
@ -31,6 +34,7 @@ class m_debug_alternc {
|
||||||
var $generation_started = null;
|
var $generation_started = null;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Constructor
|
/** Constructor
|
||||||
*/
|
*/
|
||||||
function m_debug_alternc() {
|
function m_debug_alternc() {
|
||||||
|
@ -62,8 +66,12 @@ class m_debug_alternc {
|
||||||
|
|
||||||
function dump() {
|
function dump() {
|
||||||
global $cuid;
|
global $cuid;
|
||||||
if ( $cuid!=2000 ) return false;
|
if ($cuid != 2000) {
|
||||||
if ( ! $this->status ) return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (!$this->status) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$generation_time = (microtime(true) - $this->generation_started) * 1000;
|
$generation_time = (microtime(true) - $this->generation_started) * 1000;
|
||||||
|
|
||||||
|
@ -89,6 +97,6 @@ class m_debug_alternc {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* Class debug_alternc */
|
}
|
||||||
|
|
||||||
?>
|
/* Class debug_alternc */
|
||||||
|
|
|
@ -105,16 +105,16 @@ class m_dom {
|
||||||
* @param string $fqdn
|
* @param string $fqdn
|
||||||
*/
|
*/
|
||||||
public static function get_sub_domain_id_and_member_by_name($fqdn) {
|
public static function get_sub_domain_id_and_member_by_name($fqdn) {
|
||||||
global $db, $err, $cuid;
|
global $db, $err;
|
||||||
$err->log("dom", "get_sub_domain_by_name");
|
$err->log("dom", "get_sub_domain_by_name");
|
||||||
$fqdn = mysql_real_escape_string($fqdn);
|
$fqdn = mysql_real_escape_string($fqdn);
|
||||||
$db->query("select sd.* from sub_domaines sd where if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) = '$fqdn';");
|
$db->query("select sd.* from sub_domaines sd where if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) = '$fqdn';");
|
||||||
if (!$db->next_record())
|
if (!$db->next_record()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return array('sub_id' => intval($db->f('id')), 'member_id' => intval($db->f('compte')));
|
return array('sub_id' => intval($db->f('id')), 'member_id' => intval($db->f('compte')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function hook_menu() {
|
function hook_menu() {
|
||||||
global $quota;
|
global $quota;
|
||||||
$obj = array(
|
$obj = array(
|
||||||
|
@ -126,8 +126,7 @@ class m_dom {
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($quota->cancreate("dom")) {
|
if ($quota->cancreate("dom")) {
|
||||||
$obj['links'][] =
|
$obj['links'][] = array(
|
||||||
array(
|
|
||||||
'ico' => 'images/new.png',
|
'ico' => 'images/new.png',
|
||||||
'txt' => _("Add a domain"),
|
'txt' => _("Add a domain"),
|
||||||
'url' => "dom_add.php",
|
'url' => "dom_add.php",
|
||||||
|
@ -135,8 +134,7 @@ class m_dom {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->enum_domains() as $d) {
|
foreach ($this->enum_domains() as $d) {
|
||||||
$obj['links'][] =
|
$obj['links'][] = array(
|
||||||
array(
|
|
||||||
'txt' => htmlentities($d),
|
'txt' => htmlentities($d),
|
||||||
'url' => "dom_edit.php?domain=" . urlencode($d),
|
'url' => "dom_edit.php?domain=" . urlencode($d),
|
||||||
);
|
);
|
||||||
|
@ -186,7 +184,7 @@ class m_dom {
|
||||||
* @param integer $type
|
* @param integer $type
|
||||||
*/
|
*/
|
||||||
function domains_type_target_values($type = null) {
|
function domains_type_target_values($type = null) {
|
||||||
global $db, $err, $cuid;
|
global $db, $err;
|
||||||
$err->log("dom", "domains_type_target_values");
|
$err->log("dom", "domains_type_target_values");
|
||||||
if (is_null($type)) {
|
if (is_null($type)) {
|
||||||
$db->query("desc domaines_type;");
|
$db->query("desc domaines_type;");
|
||||||
|
@ -202,8 +200,9 @@ class m_dom {
|
||||||
return $r;
|
return $r;
|
||||||
} else {
|
} else {
|
||||||
$db->query("select target from domaines_type where name='$type';");
|
$db->query("select target from domaines_type where name='$type';");
|
||||||
if (!$db->next_record())
|
if (!$db->next_record()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return $db->f('target');
|
return $db->f('target');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,8 +219,9 @@ class m_dom {
|
||||||
$val = array();
|
$val = array();
|
||||||
foreach (explode("\n", $zone) as $z) {
|
foreach (explode("\n", $zone) as $z) {
|
||||||
$z = trim($z);
|
$z = trim($z);
|
||||||
if (empty($z))
|
if (empty($z)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
$val[] = $this->import_manual_dns_entry($z, $domain, $detect_redirect, $save);
|
$val[] = $this->import_manual_dns_entry($z, $domain, $detect_redirect, $save);
|
||||||
}
|
}
|
||||||
return $val;
|
return $val;
|
||||||
|
@ -231,11 +231,12 @@ class m_dom {
|
||||||
* @param string $zone
|
* @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 $err;
|
||||||
$err->log("dom", "import_manual_dns_entry");
|
$err->log("dom", "import_manual_dns_entry");
|
||||||
$zone = trim($zone);
|
$zone = trim($zone);
|
||||||
if (empty($zone))
|
if (empty($zone)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$domain = trim($domain);
|
$domain = trim($domain);
|
||||||
if (empty($domain)) {
|
if (empty($domain)) {
|
||||||
|
@ -409,7 +410,6 @@ class m_dom {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function import_manual_dns_entry_doit($entry) {
|
private function import_manual_dns_entry_doit($entry) {
|
||||||
global $err;
|
|
||||||
$entry['did_it'] = 0;
|
$entry['did_it'] = 0;
|
||||||
if ($entry['status'] == 'err') {
|
if ($entry['status'] == 'err') {
|
||||||
return $entry;
|
return $entry;
|
||||||
|
@ -417,14 +417,14 @@ class m_dom {
|
||||||
|
|
||||||
$val = $entry['entry_new'];
|
$val = $entry['entry_new'];
|
||||||
|
|
||||||
if (empty($val['type']))
|
if (empty($val['type'])) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch ($val['type']) {
|
switch ($val['type']) {
|
||||||
case "set_ttl":
|
case "set_ttl":
|
||||||
$entry['did_it'] = $this->set_ttl($this->get_domain_byname($val['domain']), $val['value']);
|
$entry['did_it'] = $this->set_ttl($this->get_domain_byname($val['domain']), $val['value']);
|
||||||
return $entry;
|
return $entry;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it is an unknown domains type
|
// If it is an unknown domains type
|
||||||
|
@ -435,8 +435,9 @@ class m_dom {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the subdomain is @, we want an empty subdomain
|
// If the subdomain is @, we want an empty subdomain
|
||||||
if ($val['sub'] == '@')
|
if ($val['sub'] == '@') {
|
||||||
$val['sub'] = '';
|
$val['sub'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
$this->lock();
|
$this->lock();
|
||||||
$entry['did_it'] = $this->set_sub_domain($val['domain'], $val['sub'], $val['type'], $val['value']);
|
$entry['did_it'] = $this->set_sub_domain($val['domain'], $val['sub'], $val['type'], $val['value']);
|
||||||
|
@ -492,7 +493,6 @@ class m_dom {
|
||||||
|
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new Exception("Could not read data from {$url}");
|
throw new Exception("Could not read data from {$url}");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (strstr($http_response_header[0], '301') || strstr($http_response_header[0], '302')) {
|
if (strstr($http_response_header[0], '301') || strstr($http_response_header[0], '302')) {
|
||||||
// This is a redirection
|
// This is a redirection
|
||||||
|
@ -528,7 +528,7 @@ class m_dom {
|
||||||
}
|
}
|
||||||
|
|
||||||
function domains_type_get($name) {
|
function domains_type_get($name) {
|
||||||
global $db, $err, $cuid;
|
global $db;
|
||||||
$name = mysql_real_escape_string($name);
|
$name = mysql_real_escape_string($name);
|
||||||
$db->query("select * from domaines_type where name='$name' ;");
|
$db->query("select * from domaines_type where name='$name' ;");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
|
@ -536,14 +536,14 @@ class m_dom {
|
||||||
}
|
}
|
||||||
|
|
||||||
function domains_type_del($name) {
|
function domains_type_del($name) {
|
||||||
global $db, $err, $cuid;
|
global $db;
|
||||||
$name = mysql_real_escape_string($name);
|
$name = mysql_real_escape_string($name);
|
||||||
$db->query("delete domaines_type where name='$name';");
|
$db->query("delete domaines_type where name='$name';");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function domains_type_update($name, $description, $target, $entry, $compatibility, $enable, $only_dns, $need_dns, $advanced, $create_tmpdir, $create_targetdir) {
|
function domains_type_update($name, $description, $target, $entry, $compatibility, $enable, $only_dns, $need_dns, $advanced, $create_tmpdir, $create_targetdir) {
|
||||||
global $err, $cuid, $db;
|
global $err, $db;
|
||||||
// The name MUST contain only letter and digits, it's an identifier after all ...
|
// The name MUST contain only letter and digits, it's an identifier after all ...
|
||||||
if (!preg_match("#^[a-z0-9]+$#", $name)) {
|
if (!preg_match("#^[a-z0-9]+$#", $name)) {
|
||||||
$err->raise("dom", _("The name MUST contain only letter and digits"));
|
$err->raise("dom", _("The name MUST contain only letter and digits"));
|
||||||
|
@ -565,12 +565,13 @@ class m_dom {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sub_domain_change_status($sub_id, $status) {
|
function sub_domain_change_status($sub_id, $status) {
|
||||||
global $db, $err, $cuid;
|
global $db, $err;
|
||||||
$err->log("dom", "sub_domain_change_status");
|
$err->log("dom", "sub_domain_change_status");
|
||||||
$sub_id = intval($sub_id);
|
$sub_id = intval($sub_id);
|
||||||
$status = strtoupper($status);
|
$status = strtoupper($status);
|
||||||
if (!in_array($status, array('ENABLE', 'DISABLE')))
|
if (!in_array($status, array('ENABLE', 'DISABLE'))) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$jh = $this->get_sub_domain_all($sub_id);
|
$jh = $this->get_sub_domain_all($sub_id);
|
||||||
if ($status == 'ENABLE') { // check compatibility with existing sub_domains
|
if ($status == 'ENABLE') { // check compatibility with existing sub_domains
|
||||||
|
@ -618,9 +619,7 @@ class m_dom {
|
||||||
$dom = strtolower($dom);
|
$dom = strtolower($dom);
|
||||||
$db->query("UPDATE sub_domaines SET web_action='UPDATE' WHERE domaine='$dom';");
|
$db->query("UPDATE sub_domaines SET web_action='UPDATE' WHERE domaine='$dom';");
|
||||||
$this->set_dns_action($dom, 'UPDATE');
|
$this->set_dns_action($dom, 'UPDATE');
|
||||||
|
|
||||||
# TODO : some work with domain sensitive classes
|
# TODO : some work with domain sensitive classes
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,7 +637,7 @@ class m_dom {
|
||||||
* @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
|
* @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
|
||||||
*/
|
*/
|
||||||
function del_domain($dom) {
|
function del_domain($dom) {
|
||||||
global $db, $err, $classes, $cuid, $hooks;
|
global $db, $err, $hooks;
|
||||||
$err->log("dom", "del_domain", $dom);
|
$err->log("dom", "del_domain", $dom);
|
||||||
$dom = strtolower($dom);
|
$dom = strtolower($dom);
|
||||||
|
|
||||||
|
@ -689,7 +688,7 @@ class m_dom {
|
||||||
$ @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
|
$ @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
|
||||||
*/
|
*/
|
||||||
function add_domain($domain, $dns, $noerase = false, $force = false, $isslave = false, $slavedom = "") {
|
function add_domain($domain, $dns, $noerase = false, $force = false, $isslave = false, $slavedom = "") {
|
||||||
global $db, $err, $quota, $classes, $L_MX, $L_FQDN, $tld, $cuid, $bro, $hooks;
|
global $db, $err, $quota, $L_FQDN, $tld, $cuid, $hooks;
|
||||||
$err->log("dom", "add_domain", $domain);
|
$err->log("dom", "add_domain", $domain);
|
||||||
|
|
||||||
// Locked ?
|
// Locked ?
|
||||||
|
@ -740,14 +739,15 @@ class m_dom {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dns)
|
if ($dns) {
|
||||||
$dns = "1";
|
$dns = "1";
|
||||||
else
|
} else {
|
||||||
$dns = "0";
|
$dns = "0";
|
||||||
|
}
|
||||||
// mode 5 : force DNS to NO.
|
// mode 5 : force DNS to NO.
|
||||||
if ($tld[$v] == 5)
|
if ($tld[$v] == 5) {
|
||||||
$dns = 0;
|
$dns = 0;
|
||||||
|
}
|
||||||
// It must be a real domain (no subdomain)
|
// It must be a real domain (no subdomain)
|
||||||
if (!$dns) {
|
if (!$dns) {
|
||||||
$v = checkhostallow_nodns($domain);
|
$v = checkhostallow_nodns($domain);
|
||||||
|
@ -762,14 +762,16 @@ class m_dom {
|
||||||
$err->raise("dom", _("Your domain quota is over, you cannot create more domain names"));
|
$err->raise("dom", _("Your domain quota is over, you cannot create more domain names"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($noerase)
|
if ($noerase) {
|
||||||
$noerase = "1";
|
$noerase = "1";
|
||||||
else
|
} else {
|
||||||
$noerase = "0";
|
$noerase = "0";
|
||||||
if ($dns)
|
}
|
||||||
|
if ($dns) {
|
||||||
$gesmx = "1";
|
$gesmx = "1";
|
||||||
else
|
} else {
|
||||||
$gesmx = "0"; // do not host mx by default if not hosting the DNS
|
$gesmx = "0"; // do not host mx by default if not hosting the DNS
|
||||||
|
}
|
||||||
$db->query("INSERT INTO domaines (compte,domaine,gesdns,gesmx,noerase,dns_action) VALUES ('$cuid','$domain','$dns','$gesmx','$noerase','UPDATE');");
|
$db->query("INSERT INTO domaines (compte,domaine,gesdns,gesmx,noerase,dns_action) VALUES ('$cuid','$domain','$dns','$gesmx','$noerase','UPDATE');");
|
||||||
if (!($id = $db->lastid())) {
|
if (!($id = $db->lastid())) {
|
||||||
$err->raise("dom", _("An unexpected error occured when creating the domain"));
|
$err->raise("dom", _("An unexpected error occured when creating the domain"));
|
||||||
|
@ -798,8 +800,9 @@ class m_dom {
|
||||||
}
|
}
|
||||||
// New Hooks:
|
// New Hooks:
|
||||||
$hooks->invoke("hook_dom_add_domain", array($id));
|
$hooks->invoke("hook_dom_add_domain", array($id));
|
||||||
if ($gesmx)
|
if ($gesmx) {
|
||||||
$hooks->invoke("hook_dom_add_mx_domain", array($id));
|
$hooks->invoke("hook_dom_add_mx_domain", array($id));
|
||||||
|
}
|
||||||
if ($isslave) {
|
if ($isslave) {
|
||||||
$hooks->invoke("hook_dom_add_slave_domain", array($id, $slavedom));
|
$hooks->invoke("hook_dom_add_slave_domain", array($id, $slavedom));
|
||||||
}
|
}
|
||||||
|
@ -834,13 +837,11 @@ class m_dom {
|
||||||
* @param string $domain
|
* @param string $domain
|
||||||
*/
|
*/
|
||||||
function domdefaultdir($domain) {
|
function domdefaultdir($domain) {
|
||||||
global $bro, $cuid;
|
|
||||||
$dest_root = $bro->get_userid_root($cuid);
|
|
||||||
# return $dest_root."/www/".$this->domshort($domain);
|
|
||||||
return "/www/" . $this->domshort($domain);
|
return "/www/" . $this->domshort($domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dump_axfr($domain, $ns = 'localhost') {
|
function dump_axfr($domain, $ns = 'localhost') {
|
||||||
|
$axfr = array();
|
||||||
exec('/usr/bin/dig AXFR "' . escapeshellcmd($domain) . '" @"' . escapeshellcmd($ns) . '"', $axfr);
|
exec('/usr/bin/dig AXFR "' . escapeshellcmd($domain) . '" @"' . escapeshellcmd($ns) . '"', $axfr);
|
||||||
return $axfr;
|
return $axfr;
|
||||||
}
|
}
|
||||||
|
@ -869,12 +870,14 @@ class m_dom {
|
||||||
$err->log("dom", "update_default_subdomains");
|
$err->log("dom", "update_default_subdomains");
|
||||||
$ok = true;
|
$ok = true;
|
||||||
foreach ($arr as $a) {
|
foreach ($arr as $a) {
|
||||||
if (!isset($a['id']))
|
if (!isset($a['id'])) {
|
||||||
$a['id'] = null;
|
$a['id'] = null;
|
||||||
|
}
|
||||||
if (!empty($a['sub']) || !empty($a['domain_type_parameter'])) {
|
if (!empty($a['sub']) || !empty($a['domain_type_parameter'])) {
|
||||||
|
|
||||||
if (!isset($a['enabled']))
|
if (!isset($a['enabled'])) {
|
||||||
$a['enabled'] = 0;
|
$a['enabled'] = 0;
|
||||||
|
}
|
||||||
if (!$this->update_one_default($a['domain_type'], $a['sub'], $a['domain_type_parameter'], $a['concerned'], $a['enabled'], $a['id'])) {
|
if (!$this->update_one_default($a['domain_type'], $a['sub'], $a['domain_type_parameter'], $a['concerned'], $a['enabled'], $a['id'])) {
|
||||||
$ok = false;
|
$ok = false;
|
||||||
}
|
}
|
||||||
|
@ -887,10 +890,11 @@ class m_dom {
|
||||||
global $db, $err;
|
global $db, $err;
|
||||||
$err->log("dom", "update_one_default");
|
$err->log("dom", "update_one_default");
|
||||||
|
|
||||||
if ($id == null)
|
if ($id == null) {
|
||||||
$db->query("INSERT INTO default_subdomains values ('','" . addslashes($sub) . "','" . addslashes($domain_type) . "','" . addslashes($domain_type_parameter) . "','" . addslashes($concerned) . "','" . addslashes($enabled) . "');");
|
$db->query("INSERT INTO default_subdomains values ('','" . addslashes($sub) . "','" . addslashes($domain_type) . "','" . addslashes($domain_type_parameter) . "','" . addslashes($concerned) . "','" . addslashes($enabled) . "');");
|
||||||
else
|
} else {
|
||||||
$db->query("UPDATE default_subdomains set sub='" . addslashes($sub) . "', domain_type='" . addslashes($domain_type) . "',domain_type_parameter='" . addslashes($domain_type_parameter) . "',concerned='" . addslashes($concerned) . "',enabled='" . addslashes($enabled) . "' where id=" . addslashes($id) . ";");
|
$db->query("UPDATE default_subdomains set sub='" . addslashes($sub) . "', domain_type='" . addslashes($domain_type) . "',domain_type_parameter='" . addslashes($domain_type_parameter) . "',concerned='" . addslashes($concerned) . "',enabled='" . addslashes($enabled) . "' where id=" . addslashes($id) . ";");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
//update
|
//update
|
||||||
}
|
}
|
||||||
|
@ -924,7 +928,7 @@ class m_dom {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function whois($domain) {
|
function whois($domain) {
|
||||||
global $db, $err;
|
global $err;
|
||||||
$err->log("dom", "whois", $domain);
|
$err->log("dom", "whois", $domain);
|
||||||
// pour ajouter un nouveau TLD, utiliser le code ci-dessous.
|
// pour ajouter un nouveau TLD, utiliser le code ci-dessous.
|
||||||
// echo "whois : $domain<br />";
|
// echo "whois : $domain<br />";
|
||||||
|
@ -978,16 +982,19 @@ class m_dom {
|
||||||
if (preg_match("#Name Server:#", $ligne)) {
|
if (preg_match("#Name Server:#", $ligne)) {
|
||||||
$found = true;
|
$found = true;
|
||||||
$tmp = strtolower(str_replace(chr(10), "", str_replace(chr(13), "", str_replace(" ", "", str_replace("Name Server:", "", $ligne)))));
|
$tmp = strtolower(str_replace(chr(10), "", str_replace(chr(13), "", str_replace(" ", "", str_replace("Name Server:", "", $ligne)))));
|
||||||
if ($tmp)
|
if ($tmp) {
|
||||||
$serveurList[] = $tmp;
|
$serveurList[] = $tmp;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "cx":
|
case "cx":
|
||||||
$ligne = str_replace(chr(10), "", str_replace(chr(13), "", str_replace(" ", "", $ligne)));
|
$ligne = str_replace(chr(10), "", str_replace(chr(13), "", str_replace(" ", "", $ligne)));
|
||||||
if ($ligne == "" && $state == 1)
|
if ($ligne == "" && $state == 1) {
|
||||||
$state = 2;
|
$state = 2;
|
||||||
if ($state == 1)
|
}
|
||||||
|
if ($state == 1) {
|
||||||
$serveurList[] = strtolower($ligne);
|
$serveurList[] = strtolower($ligne);
|
||||||
|
}
|
||||||
if ($ligne == "Nameservers:" && $state == 0) {
|
if ($ligne == "Nameservers:" && $state == 0) {
|
||||||
$state = 1;
|
$state = 1;
|
||||||
$found = true;
|
$found = true;
|
||||||
|
@ -996,10 +1003,12 @@ class m_dom {
|
||||||
case "eu":
|
case "eu":
|
||||||
case "be":
|
case "be":
|
||||||
$ligne = preg_replace("/^ *([^ ]*) \(.*\)$/", "\\1", trim($ligne));
|
$ligne = preg_replace("/^ *([^ ]*) \(.*\)$/", "\\1", trim($ligne));
|
||||||
if ($found)
|
if ($found) {
|
||||||
$tmp = trim($ligne);
|
$tmp = trim($ligne);
|
||||||
if ($tmp)
|
}
|
||||||
|
if ($tmp) {
|
||||||
$serveurList[] = $tmp;
|
$serveurList[] = $tmp;
|
||||||
|
}
|
||||||
if ($ligne == "Nameservers:") {
|
if ($ligne == "Nameservers:") {
|
||||||
$state = 1;
|
$state = 1;
|
||||||
$found = true;
|
$found = true;
|
||||||
|
@ -1011,26 +1020,29 @@ class m_dom {
|
||||||
// weird regexp (trailing garbage after name server), but I could not make it work otherwise
|
// weird regexp (trailing garbage after name server), but I could not make it work otherwise
|
||||||
$tmp = strtolower(preg_replace('/Name Server: ([^ ]+)\..$/', "\\1", $ligne));
|
$tmp = strtolower(preg_replace('/Name Server: ([^ ]+)\..$/', "\\1", $ligne));
|
||||||
$tmp = preg_replace('/[^-_a-z0-9\.]/', '', $tmp);
|
$tmp = preg_replace('/[^-_a-z0-9\.]/', '', $tmp);
|
||||||
if ($tmp)
|
if ($tmp) {
|
||||||
$serveurList[] = $tmp;
|
$serveurList[] = $tmp;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "it":
|
case "it":
|
||||||
if (preg_match("#nserver:#", $ligne)) {
|
if (preg_match("#nserver:#", $ligne)) {
|
||||||
$found = true;
|
$found = true;
|
||||||
$tmp = strtolower(preg_replace("/nserver:\s*[^ ]*\s*([^\s]*)$/", "\\1", $ligne));
|
$tmp = strtolower(preg_replace("/nserver:\s*[^ ]*\s*([^\s]*)$/", "\\1", $ligne));
|
||||||
if ($tmp)
|
if ($tmp) {
|
||||||
$serveurList[] = $tmp;
|
$serveurList[] = $tmp;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "fr":
|
case "fr":
|
||||||
case "re":
|
case "re":
|
||||||
if (preg_match("#nserver:#", $ligne)) {
|
if (preg_match("#nserver:#", $ligne)) {
|
||||||
$found = true;
|
$found = true;
|
||||||
$tmp = strtolower(preg_replace("#nserver:\s*([^\s]*)\s*.*$#", "\\1", $ligne));
|
$tmp = strtolower(preg_replace("#nserver:\s*([^\s]*)\s*.*$#", "\\1", $ligne));
|
||||||
if ($tmp)
|
if ($tmp) {
|
||||||
$serveurList[] = $tmp;
|
$serveurList[] = $tmp;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "ca":
|
case "ca":
|
||||||
case "ws";
|
case "ws";
|
||||||
|
@ -1082,6 +1094,8 @@ class m_dom {
|
||||||
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;
|
||||||
|
|
||||||
|
$ref_mx = array();
|
||||||
|
$mxhosts = array();
|
||||||
if (!empty($ref_domain)) {
|
if (!empty($ref_domain)) {
|
||||||
getmxrr($ref_domain, $ref_mx);
|
getmxrr($ref_domain, $ref_mx);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1114,9 +1128,6 @@ class m_dom {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//checkmx
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1245,7 +1256,7 @@ class m_dom {
|
||||||
* @param string $value
|
* @param string $value
|
||||||
*/
|
*/
|
||||||
function check_type_value($type, $value) {
|
function check_type_value($type, $value) {
|
||||||
global $db, $err, $cuid;
|
global $err;
|
||||||
|
|
||||||
// check the type we can have in domaines_type.target
|
// check the type we can have in domaines_type.target
|
||||||
switch ($this->domains_type_target_values($type)) {
|
switch ($this->domains_type_target_values($type)) {
|
||||||
|
@ -1273,7 +1284,6 @@ class m_dom {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
|
||||||
case 'IP':
|
case 'IP':
|
||||||
if (checkip($value)) {
|
if (checkip($value)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1309,14 +1319,10 @@ class m_dom {
|
||||||
default:
|
default:
|
||||||
$err->raise("dom", _("Invalid domain type selected, please check"));
|
$err->raise("dom", _("Invalid domain type selected, please check"));
|
||||||
return false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//check_type_value
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1328,13 +1334,14 @@ class m_dom {
|
||||||
* @return boolean tell you if the subdomain can be installed there
|
* @return boolean tell you if the subdomain can be installed there
|
||||||
*/
|
*/
|
||||||
function can_create_subdomain($dom, $sub, $type, $sub_domain_id = 'null') {
|
function can_create_subdomain($dom, $sub, $type, $sub_domain_id = 'null') {
|
||||||
global $db, $err, $cuid;
|
global $db, $err;
|
||||||
$err->log("dom", "can_create_subdomain", $dom . "/" . $sub);
|
$err->log("dom", "can_create_subdomain", $dom . "/" . $sub);
|
||||||
|
|
||||||
// Get the compatibility list for this domain type
|
// Get the compatibility list for this domain type
|
||||||
$db->query("select upper(compatibility) as compatibility from domaines_type where upper(name)=upper('$type');");
|
$db->query("select upper(compatibility) as compatibility from domaines_type where upper(name)=upper('$type');");
|
||||||
if (!$db->next_record())
|
if (!$db->next_record()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
$compatibility_lst = explode(",", $db->f('compatibility'));
|
$compatibility_lst = explode(",", $db->f('compatibility'));
|
||||||
|
|
||||||
// Get the list of type of subdomains already here who have the same name
|
// Get the list of type of subdomains already here who have the same name
|
||||||
|
@ -1342,9 +1349,10 @@ class m_dom {
|
||||||
#$db->query("select * from sub_domaines where sub='$sub' and domaine='$dom';");
|
#$db->query("select * from sub_domaines where sub='$sub' and domaine='$dom';");
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
// And if there is a domain with a incompatible type, return false
|
// And if there is a domain with a incompatible type, return false
|
||||||
if (!in_array(strtoupper($db->f('type')), $compatibility_lst))
|
if (!in_array(strtoupper($db->f('type')), $compatibility_lst)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// All is right, go ! Create ur domain !
|
// All is right, go ! Create ur domain !
|
||||||
return true;
|
return true;
|
||||||
|
@ -1393,7 +1401,7 @@ class m_dom {
|
||||||
}
|
}
|
||||||
|
|
||||||
// On a épuré $dir des problémes eventuels ... On est en DESSOUS du dossier de l'utilisateur.
|
// On a épuré $dir des problémes eventuels ... On est en DESSOUS du dossier de l'utilisateur.
|
||||||
if ($t = checkfqdn($dom)) {
|
if (($t = checkfqdn($dom))) {
|
||||||
$err->raise("dom", _("The domain name is syntaxically incorrect"));
|
$err->raise("dom", _("The domain name is syntaxically incorrect"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1415,7 +1423,7 @@ class m_dom {
|
||||||
|
|
||||||
// Create TMP dir and TARGET dir if needed by the domains_type
|
// Create TMP dir and TARGET dir if needed by the domains_type
|
||||||
$dest_root = $bro->get_userid_root($cuid);
|
$dest_root = $bro->get_userid_root($cuid);
|
||||||
$domshort = $this->domshort($dom, $sub);
|
//$domshort = $this->domshort($dom, $sub);
|
||||||
$db->query("select create_tmpdir, create_targetdir from domaines_type where name = '$type';");
|
$db->query("select create_tmpdir, create_targetdir from domaines_type where name = '$type';");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
if ($db->f('create_tmpdir')) {
|
if ($db->f('create_tmpdir')) {
|
||||||
|
@ -1444,9 +1452,6 @@ class m_dom {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set_sub_domain
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1456,7 +1461,7 @@ class m_dom {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function del_sub_domain($sub_domain_id) {
|
function del_sub_domain($sub_domain_id) {
|
||||||
global $db, $err, $cuid;
|
global $db, $err;
|
||||||
$err->log("dom", "del_sub_domain", $sub_domain_id);
|
$err->log("dom", "del_sub_domain", $sub_domain_id);
|
||||||
// Locked ?
|
// Locked ?
|
||||||
if (!$this->islocked) {
|
if (!$this->islocked) {
|
||||||
|
@ -1473,8 +1478,6 @@ class m_dom {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// del_sub_domain
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param integer $dom_id
|
* @param integer $dom_id
|
||||||
*/
|
*/
|
||||||
|
@ -1505,7 +1508,7 @@ class m_dom {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function edit_domain($dom, $dns, $gesmx, $force = false, $ttl = 86400) {
|
function edit_domain($dom, $dns, $gesmx, $force = false, $ttl = 86400) {
|
||||||
global $db, $err, $L_MX, $classes, $cuid, $hooks;
|
global $db, $err, $hooks;
|
||||||
$err->log("dom", "edit_domain", $dom . "/" . $dns . "/" . $gesmx);
|
$err->log("dom", "edit_domain", $dom . "/" . $dns . "/" . $gesmx);
|
||||||
// Locked ?
|
// Locked ?
|
||||||
if (!$this->islocked && !$force) {
|
if (!$this->islocked && !$force) {
|
||||||
|
@ -1544,8 +1547,9 @@ class m_dom {
|
||||||
$err->raise("dom", _("The domain name %s does not exist"), $dom);
|
$err->raise("dom", _("The domain name %s does not exist"), $dom);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($dns != "1")
|
if ($dns != "1") {
|
||||||
$dns = "0";
|
$dns = "0";
|
||||||
|
}
|
||||||
// On vérifie que des modifications ont bien eu lieu :)
|
// On vérifie que des modifications ont bien eu lieu :)
|
||||||
if ($r["dns"] == $dns && $r["mail"] == $gesmx && $r["zonettl"] == $ttl) {
|
if ($r["dns"] == $dns && $r["mail"] == $gesmx && $r["zonettl"] == $ttl) {
|
||||||
$err->raise("dom", _("No change has been requested..."));
|
$err->raise("dom", _("No change has been requested..."));
|
||||||
|
@ -1579,14 +1583,10 @@ class m_dom {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// edit_domain
|
|
||||||
|
|
||||||
|
|
||||||
/* * ************************* */
|
/* * ************************* */
|
||||||
/* Slave dns ip managment */
|
/* Slave dns ip managment */
|
||||||
/* * ************************* */
|
/* * ************************* */
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Return the list of ip addresses and classes that are allowed access to domain list
|
/** Return the list of ip addresses and classes that are allowed access to domain list
|
||||||
|
@ -1616,8 +1616,9 @@ class m_dom {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$class = intval($class);
|
$class = intval($class);
|
||||||
if ($class < 8 || $class > 32)
|
if ($class < 8 || $class > 32) {
|
||||||
$class = 32;
|
$class = 32;
|
||||||
|
}
|
||||||
$db->query("SELECT * FROM slaveip WHERE ip='$ip' AND class='$class';");
|
$db->query("SELECT * FROM slaveip WHERE ip='$ip' AND class='$class';");
|
||||||
if ($db->next_record()) {
|
if ($db->next_record()) {
|
||||||
$err->raise("err", _("The requested domain is forbidden in this server, please contact the administrator"));
|
$err->raise("err", _("The requested domain is forbidden in this server, please contact the administrator"));
|
||||||
|
@ -1652,7 +1653,7 @@ class m_dom {
|
||||||
/** Check for a slave account
|
/** Check for a slave account
|
||||||
*/
|
*/
|
||||||
function check_slave_account($login, $pass) {
|
function check_slave_account($login, $pass) {
|
||||||
global $db, $err;
|
global $db;
|
||||||
$db->query("SELECT * FROM slaveaccount WHERE login='$login' AND pass='$pass';");
|
$db->query("SELECT * FROM slaveaccount WHERE login='$login' AND pass='$pass';");
|
||||||
if ($db->next_record()) {
|
if ($db->next_record()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1665,7 +1666,7 @@ class m_dom {
|
||||||
/** Out (echo) the complete hosted domain list :
|
/** Out (echo) the complete hosted domain list :
|
||||||
*/
|
*/
|
||||||
function echo_domain_list($integrity = false) {
|
function echo_domain_list($integrity = false) {
|
||||||
global $db, $err;
|
global $db;
|
||||||
$db->query("SELECT domaine FROM domaines WHERE gesdns=1 ORDER BY domaine");
|
$db->query("SELECT domaine FROM domaines WHERE gesdns=1 ORDER BY domaine");
|
||||||
$tt = "";
|
$tt = "";
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
|
@ -1684,7 +1685,7 @@ class m_dom {
|
||||||
/** Returns the complete hosted domain list :
|
/** Returns the complete hosted domain list :
|
||||||
*/
|
*/
|
||||||
function get_domain_list($uid = -1) {
|
function get_domain_list($uid = -1) {
|
||||||
global $db, $err;
|
global $db;
|
||||||
$uid = intval($uid);
|
$uid = intval($uid);
|
||||||
$res = array();
|
$res = array();
|
||||||
$sql = "";
|
$sql = "";
|
||||||
|
@ -1703,7 +1704,7 @@ class m_dom {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function get_domain_all_summary() {
|
function get_domain_all_summary() {
|
||||||
global $db, $err;
|
global $db;
|
||||||
$res = array();
|
$res = array();
|
||||||
$db->query("SELECT domaine, gesdns, gesmx, dns_action, zonettl FROM domaines ORDER BY domaine");
|
$db->query("SELECT domaine, gesdns, gesmx, dns_action, zonettl FROM domaines ORDER BY domaine");
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
|
@ -1770,7 +1771,7 @@ class m_dom {
|
||||||
/** Count all domains, for all users
|
/** Count all domains, for all users
|
||||||
*/
|
*/
|
||||||
function count_domains_all() {
|
function count_domains_all() {
|
||||||
global $db, $err, $cuid;
|
global $db;
|
||||||
$db->query("SELECT COUNT(*) AS count FROM domaines;");
|
$db->query("SELECT COUNT(*) AS count FROM domaines;");
|
||||||
if ($db->next_record()) {
|
if ($db->next_record()) {
|
||||||
return $db->f('count');
|
return $db->f('count');
|
||||||
|
@ -1784,14 +1785,15 @@ class m_dom {
|
||||||
/** Return the list of allowed slave accounts
|
/** Return the list of allowed slave accounts
|
||||||
*/
|
*/
|
||||||
function enum_slave_account() {
|
function enum_slave_account() {
|
||||||
global $db, $err;
|
global $db;
|
||||||
$db->query("SELECT * FROM slaveaccount;");
|
$db->query("SELECT * FROM slaveaccount;");
|
||||||
$res = array();
|
$res = array();
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$res[] = $db->Record;
|
$res[] = $db->Record;
|
||||||
}
|
}
|
||||||
if (!count($res))
|
if (!count($res)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1831,7 +1833,7 @@ class m_dom {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function lock() {
|
function lock() {
|
||||||
global $db, $err;
|
global $err;
|
||||||
$err->log("dom", "lock");
|
$err->log("dom", "lock");
|
||||||
if ($this->islocked) {
|
if ($this->islocked) {
|
||||||
$err->raise("dom", _("--- Program error --- Lock already obtained!"));
|
$err->raise("dom", _("--- Program error --- Lock already obtained!"));
|
||||||
|
@ -1850,7 +1852,7 @@ class m_dom {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function unlock() {
|
function unlock() {
|
||||||
global $db, $err;
|
global $err;
|
||||||
$err->log("dom", "unlock");
|
$err->log("dom", "unlock");
|
||||||
if (!$this->islocked) {
|
if (!$this->islocked) {
|
||||||
$err->raise("dom", _("--- Program error --- No lock on the domains!"));
|
$err->raise("dom", _("--- Program error --- No lock on the domains!"));
|
||||||
|
@ -1914,7 +1916,7 @@ class m_dom {
|
||||||
* No parameters needed
|
* No parameters needed
|
||||||
* */
|
* */
|
||||||
function alternc_export_conf() {
|
function alternc_export_conf() {
|
||||||
global $db, $err;
|
global $err;
|
||||||
$err->log("dom", "export");
|
$err->log("dom", "export");
|
||||||
$this->enum_domains();
|
$this->enum_domains();
|
||||||
$str = "";
|
$str = "";
|
||||||
|
@ -1975,6 +1977,7 @@ class m_dom {
|
||||||
if ($only_apache) {
|
if ($only_apache) {
|
||||||
$params.=" and dt.only_dns is false ";
|
$params.=" and dt.only_dns is false ";
|
||||||
}
|
}
|
||||||
|
|
||||||
// BUG BUG BUG FIXME
|
// BUG BUG BUG FIXME
|
||||||
// Suppression de comptes -> membres existe pas -> domaines a supprimer ne sont pas lister
|
// Suppression de comptes -> membres existe pas -> domaines a supprimer ne sont pas lister
|
||||||
$db->query("
|
$db->query("
|
||||||
|
@ -2017,8 +2020,9 @@ order by
|
||||||
global $dom;
|
global $dom;
|
||||||
$d = array();
|
$d = array();
|
||||||
foreach ($dom->domains_type_lst() as $k => $v) {
|
foreach ($dom->domains_type_lst() as $k => $v) {
|
||||||
if ($v['only_dns'] == true)
|
if ($v['only_dns'] == true) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
if (!$j = file_get_contents(ALTERNC_APACHE2_GEN_TMPL_DIR . '/' . strtolower($k) . '.conf')) {
|
if (!$j = file_get_contents(ALTERNC_APACHE2_GEN_TMPL_DIR . '/' . strtolower($k) . '.conf')) {
|
||||||
die("Error: missing file for $k");
|
die("Error: missing file for $k");
|
||||||
}
|
}
|
||||||
|
@ -2030,9 +2034,9 @@ order by
|
||||||
|
|
||||||
// Launch old fashionned hooks as there was in AlternC 1.0
|
// Launch old fashionned hooks as there was in AlternC 1.0
|
||||||
function generate_conf_oldhook($action, $lst_sub, $sub_obj = null) {
|
function generate_conf_oldhook($action, $lst_sub, $sub_obj = null) {
|
||||||
if (is_null($sub_obj))
|
if (is_null($sub_obj)) {
|
||||||
$sub_obj = $this->generation_parameters(null, false);
|
$sub_obj = $this->generation_parameters(null, false);
|
||||||
|
}
|
||||||
if (!isset($lst_sub[strtoupper($action)]) || empty($lst_sub[strtoupper($action)])) {
|
if (!isset($lst_sub[strtoupper($action)]) || empty($lst_sub[strtoupper($action)])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2173,7 +2177,9 @@ order by
|
||||||
// by subdomain
|
// by subdomain
|
||||||
$tmp = array();
|
$tmp = array();
|
||||||
foreach ($da['sub'] as $sub) {
|
foreach ($da['sub'] as $sub) {
|
||||||
if ($sub['web_action']!='OK') continue;
|
if ($sub['web_action'] != 'OK') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!$sub['only_dns']) {
|
if (!$sub['only_dns']) {
|
||||||
if (!isset($tmp[$sub['fqdn']])) {
|
if (!isset($tmp[$sub['fqdn']])) {
|
||||||
$tmp[$sub['fqdn']] = 0;
|
$tmp[$sub['fqdn']] = 0;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$Id: m_err.php,v 1.4 2004/05/19 14:23:06 benjamin Exp $
|
$Id: m_err.php,v 1.4 2004/05/19 14:23:06 benjamin Exp $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
Original Author of file: Benjamin Sonntag, Franck Missoum
|
Original Author of file: Benjamin Sonntag, Franck Missoum
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe de gestion des erreurs apparaissant lors d'appels API.
|
* Classe de gestion des erreurs apparaissant lors d'appels API.
|
||||||
*
|
*
|
||||||
|
@ -133,10 +135,10 @@ class m_err {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function log($clsid, $function, $param = "") {
|
function log($clsid, $function, $param = "") {
|
||||||
global $mem,$cuid;
|
global $mem;
|
||||||
return @file_put_contents($this->logfile, date("d/m/Y H:i:s") . " - " . get_remote_ip() . " - CALL - " . $mem->user["login"] . " - $clsid - $function - $param\n", FILE_APPEND);
|
return @file_put_contents($this->logfile, date("d/m/Y H:i:s") . " - " . get_remote_ip() . " - CALL - " . $mem->user["login"] . " - $clsid - $function - $param\n", FILE_APPEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
}; /* Classe m_err */
|
}
|
||||||
|
|
||||||
?>
|
/* Classe m_err */
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Constructor
|
/** Constructor
|
||||||
Classe d'export de compte Alternc.
|
Classe d'export de compte Alternc.
|
||||||
Cette classe ce contente d'invoquer les fonctions d'exportation de configuration et de données d'un compte,
|
Cette classe ce contente d'invoquer les fonctions d'exportation de configuration et de données d'un compte,
|
||||||
presentes dans les classes concernées.
|
presentes dans les classes concernées.
|
||||||
*/
|
*/
|
||||||
Class m_export {
|
Class m_export {
|
||||||
|
|
||||||
function m_export() {
|
function m_export() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function export_conf() {
|
function export_conf() {
|
||||||
|
@ -25,5 +29,7 @@ Class m_export {
|
||||||
$hooks->invoke('alternc_export_data', Array($dir));
|
$hooks->invoke('alternc_export_data', Array($dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
}// export Class end
|
}
|
||||||
|
|
||||||
|
// export Class end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -24,13 +25,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe de gestion des comptes FTP de l'hébergé.
|
* FTP account management class
|
||||||
*/
|
*/
|
||||||
class m_ftp {
|
class m_ftp {
|
||||||
|
|
||||||
|
|
||||||
var $srv_name;
|
var $srv_name;
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructeur
|
* Constructeur
|
||||||
*/
|
*/
|
||||||
|
@ -39,8 +41,8 @@ class m_ftp {
|
||||||
$this->srv_name = variable_get('ftp_human_name', $L_FQDN, 'Human name for FTP server', array('desc' => 'Name', 'type' => 'string'));
|
$this->srv_name = variable_get('ftp_human_name', $L_FQDN, 'Human name for FTP server', array('desc' => 'Name', 'type' => 'string'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Password kind used in this class (hook for admin class)
|
* Password kind used in this class (hook for admin class)
|
||||||
*/
|
*/
|
||||||
|
@ -61,8 +63,7 @@ class m_ftp {
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($quota->cancreate("ftp")) {
|
if ($quota->cancreate("ftp")) {
|
||||||
$obj['links'][] =
|
$obj['links'][] = array(
|
||||||
array (
|
|
||||||
'ico' => 'images/new.png',
|
'ico' => 'images/new.png',
|
||||||
'txt' => _("Create a new ftp account"),
|
'txt' => _("Create a new ftp account"),
|
||||||
'url' => "ftp_edit.php?create=1",
|
'url' => "ftp_edit.php?create=1",
|
||||||
|
@ -71,8 +72,7 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($q['u'] > 0) { // if there are some FTP accounts
|
if ($q['u'] > 0) { // if there are some FTP accounts
|
||||||
$obj['links'][] =
|
$obj['links'][] = array(
|
||||||
array (
|
|
||||||
'txt' => _("FTP accounts list"),
|
'txt' => _("FTP accounts list"),
|
||||||
'url' => "ftp_list.php"
|
'url' => "ftp_list.php"
|
||||||
);
|
);
|
||||||
|
@ -90,7 +90,9 @@ class m_ftp {
|
||||||
$c['values'] = Array();
|
$c['values'] = Array();
|
||||||
|
|
||||||
$tt = $this->get_list();
|
$tt = $this->get_list();
|
||||||
if (empty($tt) || !is_array($tt)) return $c;
|
if (empty($tt) || !is_array($tt)) {
|
||||||
|
return $c;
|
||||||
|
}
|
||||||
foreach ($this->get_list() as $v) {
|
foreach ($this->get_list() as $v) {
|
||||||
$c['values'][$v['id']] = $v['login'];
|
$c['values'][$v['id']] = $v['login'];
|
||||||
}
|
}
|
||||||
|
@ -106,8 +108,11 @@ class m_ftp {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($status == null) {
|
if ($status == null) {
|
||||||
if ($jj[0]['enabled'] == true ) { $status=0;}
|
if ($jj[0]['enabled'] == true) {
|
||||||
else { $status=1; }
|
$status = 0;
|
||||||
|
} else {
|
||||||
|
$status = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Be sure what is in $status, in case of it was a parameter
|
// Be sure what is in $status, in case of it was a parameter
|
||||||
|
@ -121,18 +126,18 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Retourne la liste des comptes FTP du compte hébergé
|
|
||||||
* Retourne la liste des comptes FTP sous forme de tableau indexé de
|
/** Retourne la liste des comptes FTP du compte h<EFBFBD>berg<EFBFBD>
|
||||||
|
* Retourne la liste des comptes FTP sous forme de tableau index<EFBFBD> de
|
||||||
* tableaus associatifs comme suit :
|
* tableaus associatifs comme suit :
|
||||||
* $a["id"]= ID du compte ftp
|
* $a["id"]= ID du compte ftp
|
||||||
* $a["login"]= Nom de login du compte
|
* $a["login"]= Nom de login du compte
|
||||||
* $a["dir"]= Dossier relatif à la racine du compte de l'utilisateur
|
* $a["dir"]= Dossier relatif <EFBFBD> la racine du compte de l'utilisateur
|
||||||
* @return array Retourne le tableau des comptes
|
* @return array Retourne le tableau des comptes
|
||||||
*/
|
*/
|
||||||
function get_list() {
|
function get_list() {
|
||||||
global $db,$err,$cuid, $bro;
|
global $db, $err, $cuid;
|
||||||
$err->log("ftp", "get_list");
|
$err->log("ftp", "get_list");
|
||||||
$r = array();
|
$r = array();
|
||||||
$db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid='$cuid' ORDER BY name;");
|
$db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid='$cuid' ORDER BY name;");
|
||||||
|
@ -154,9 +159,10 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Retourne les détails d'un compte FTP (voir get_list)
|
|
||||||
* Le tableau est celui du compte d'id spécifié
|
/** Retourne les details d'un compte FTP (voir get_list)
|
||||||
* @param integer $id Numéro du compte dont on souhaite obtenir les détails
|
* Le tableau est celui du compte d'id specifie
|
||||||
|
* @param integer $id Numero du compte dont on souhaite obtenir les d<EFBFBD>tails
|
||||||
* @return array Tableau associatif contenant les infos du comptes ftp
|
* @return array Tableau associatif contenant les infos du comptes ftp
|
||||||
*/
|
*/
|
||||||
function get_ftp_details($id) {
|
function get_ftp_details($id) {
|
||||||
|
@ -168,6 +174,7 @@ class m_ftp {
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
|
|
||||||
$regexp = "/^" . preg_quote(getuserpath(), "/") . "\/(.*)$/";
|
$regexp = "/^" . preg_quote(getuserpath(), "/") . "\/(.*)$/";
|
||||||
|
$match = array();
|
||||||
preg_match($regexp, $db->f("homedir"), $match);
|
preg_match($regexp, $db->f("homedir"), $match);
|
||||||
|
|
||||||
$lg = explode("_", $db->f("name"));
|
$lg = explode("_", $db->f("name"));
|
||||||
|
@ -190,6 +197,7 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Retourne la liste des prefixes utilisables par le compte courant
|
/** Retourne la liste des prefixes utilisables par le compte courant
|
||||||
* @return array tableau contenant la liste des prefixes (domaines + login)
|
* @return array tableau contenant la liste des prefixes (domaines + login)
|
||||||
* du compte actuel.
|
* du compte actuel.
|
||||||
|
@ -232,33 +240,39 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Affiche (ECHO) la liste des prefixes disponibles sous forme de champs d'option
|
/** Affiche (ECHO) la liste des prefixes disponibles sous forme de champs d'option
|
||||||
* Les champs sont affichés sous la forme <option>prefixe</option>...
|
* Les champs sont affich<EFBFBD>s sous la forme <option>prefixe</option>...
|
||||||
* La valeur $current se voit affublée de la balise SELECTED.
|
* La valeur $current se voit affubl<EFBFBD>e de la balise SELECTED.
|
||||||
* @param string $current Prefixe sélectionné par défaut
|
* @param string $current Prefixe s<EFBFBD>lectionn<EFBFBD> par d<EFBFBD>faut
|
||||||
* @return boolean TRUE.
|
* @return boolean TRUE.
|
||||||
*/
|
*/
|
||||||
function select_prefix_list($current) {
|
function select_prefix_list($current) {
|
||||||
$r = $this->prefix_list();
|
$r = $this->prefix_list();
|
||||||
reset($r);
|
reset($r);
|
||||||
while (list($key, $val) = each($r)) {
|
while (list($key, $val) = each($r)) {
|
||||||
if ($current==$val) $c=" selected=\"selected\""; else $c="";
|
if ($current == $val) {
|
||||||
|
$c = " selected=\"selected\"";
|
||||||
|
} else {
|
||||||
|
$c = "";
|
||||||
|
}
|
||||||
echo "<option$c>$val</option>";
|
echo "<option$c>$val</option>";
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Modifie les paramètres du comptes FTP $id.
|
|
||||||
* @param integer $id Numéro du compte dont on veut modifier les paramètres
|
/** Modifie les param<EFBFBD>tres du comptes FTP $id.
|
||||||
|
* @param integer $id Num<EFBFBD>ro du compte dont on veut modifier les param<EFBFBD>tres
|
||||||
* @param string $prefixe Prefixe du compte FTP
|
* @param string $prefixe Prefixe du compte FTP
|
||||||
* @param string $login login ajouté au préfixe ($prefixe_$login)
|
* @param string $login login ajout<EFBFBD> au pr<EFBFBD>fixe ($prefixe_$login)
|
||||||
* @param string $pass mot de passe
|
* @param string $pass mot de passe
|
||||||
* @param string $dir Répertoire racine du compte
|
* @param string $dir R<EFBFBD>pertoire racine du compte
|
||||||
* @return boolean TRUE si le compte a été modifié, FALSE si une erreur est survenue.
|
* @return boolean TRUE si le compte a <EFBFBD>t<EFBFBD> modifi<EFBFBD>, FALSE si une erreur est survenue.
|
||||||
*/
|
*/
|
||||||
function put_ftp_details($id, $prefixe, $login, $pass, $dir) {
|
function put_ftp_details($id, $prefixe, $login, $pass, $dir) {
|
||||||
global $mem,$db,$err,$bro,$cuid,$admin;
|
global $db, $err, $bro, $cuid, $admin;
|
||||||
$err->log("ftp", "put_ftp_details", $id);
|
$err->log("ftp", "put_ftp_details", $id);
|
||||||
$db->query("SELECT count(*) AS cnt FROM ftpusers WHERE id='$id' and uid='$cuid';");
|
$db->query("SELECT count(*) AS cnt FROM ftpusers WHERE id='$id' and uid='$cuid';");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
|
@ -277,8 +291,12 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
|
|
||||||
$full_login = $prefixe;
|
$full_login = $prefixe;
|
||||||
if ($login) $full_login.="_".$login;
|
if ($login) {
|
||||||
if (! $this->check_login($full_login) ) return false;
|
$full_login.="_" . $login;
|
||||||
|
}
|
||||||
|
if (!$this->check_login($full_login)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE id!='$id' AND name='$full_login';");
|
$db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE id!='$id' AND name='$full_login';");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
if ($db->f("cnt")) {
|
if ($db->f("cnt")) {
|
||||||
|
@ -309,11 +327,11 @@ class m_ftp {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Efface le compte ftp spécifié.
|
|
||||||
* @param integer $id Numéro du compte FTP à supprimer.
|
/** Efface le compte ftp specifie
|
||||||
* @return boolean TRUE si le compte a été effacé, FALSE sinon.
|
* @param integer $id Numero du compte FTP a supprimer.
|
||||||
|
* @return boolean TRUE si le compte a ete efface, FALSE sinon.
|
||||||
*/
|
*/
|
||||||
function delete_ftp($id) {
|
function delete_ftp($id) {
|
||||||
global $db, $err, $cuid;
|
global $db, $err, $cuid;
|
||||||
|
@ -330,16 +348,17 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Crée un nouveau compte FTP.
|
|
||||||
|
/** Cree un nouveau compte FTP.
|
||||||
* @param string $prefixe Prefixe au login
|
* @param string $prefixe Prefixe au login
|
||||||
* @param string $login Login ftp (login=prefixe_login)
|
* @param string $login Login ftp (login=prefixe_login)
|
||||||
* @param string $pass Mot de passe FTP
|
* @param string $pass Mot de passe FTP
|
||||||
* @param string $dir Répertoire racine du compte relatif à la racine du membre
|
* @param string $dir Repertoire racine du compte relatif à la racine du membre
|
||||||
* @return boolean TRUE si le compte a été créé, FALSE sinon.
|
* @return boolean TRUE si le compte a ete cree, FALSE sinon.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function add_ftp($prefixe, $login, $pass, $dir) {
|
function add_ftp($prefixe, $login, $pass, $dir) {
|
||||||
global $mem,$db,$err,$quota,$bro,$cuid,$admin;
|
global $db, $err, $quota, $bro, $cuid, $admin;
|
||||||
$err->log("ftp", "add_ftp", $prefixe . "_" . $login);
|
$err->log("ftp", "add_ftp", $prefixe . "_" . $login);
|
||||||
$dir = $bro->convertabsolute($dir);
|
$dir = $bro->convertabsolute($dir);
|
||||||
if (substr($dir, 0, 1) == "/") {
|
if (substr($dir, 0, 1) == "/") {
|
||||||
|
@ -355,8 +374,12 @@ class m_ftp {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$full_login = $prefixe;
|
$full_login = $prefixe;
|
||||||
if ($login) $full_login.="_".$login;
|
if ($login) {
|
||||||
if ( !$this->check_login($full_login) ) return false;
|
$full_login.="_" . $login;
|
||||||
|
}
|
||||||
|
if (!$this->check_login($full_login)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$db->query("SELECT count(*) AS cnt FROM ftpusers WHERE name='" . $full_login . "'");
|
$db->query("SELECT count(*) AS cnt FROM ftpusers WHERE name='" . $full_login . "'");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
if ($db->f("cnt")) {
|
if ($db->f("cnt")) {
|
||||||
|
@ -392,14 +415,17 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Retourne TRUE si $dir possède un compte FTP
|
|
||||||
* @param string $dir Dossier à tester, relatif à la racine du compte courant
|
/** Retourne TRUE si $dir possee un compte FTP
|
||||||
* @return boolean retourne TRUE si $dir à un compte FTP, FALSE sinon.
|
* @param string $dir Dossier a tester, relatif a la racine du compte courant
|
||||||
|
* @return boolean retourne TRUE si $dir a un compte FTP, FALSE sinon.
|
||||||
*/
|
*/
|
||||||
function is_ftp($dir) {
|
function is_ftp($dir) {
|
||||||
global $mem,$db,$err;
|
global $db, $err;
|
||||||
$err->log("ftp", "is_ftp", $dir);
|
$err->log("ftp", "is_ftp", $dir);
|
||||||
if (substr($dir,0,1)=="/") $dir=substr($dir,1);
|
if (substr($dir, 0, 1) == "/") {
|
||||||
|
$dir = substr($dir, 1);
|
||||||
|
}
|
||||||
$db->query("SELECT id FROM ftpusers WHERE homedir='" . getuserpath() . "/$dir';");
|
$db->query("SELECT id FROM ftpusers WHERE homedir='" . getuserpath() . "/$dir';");
|
||||||
if ($db->num_rows()) {
|
if ($db->num_rows()) {
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
|
@ -410,8 +436,9 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Fonction appellée par domains quand un domaine est supprimé pour le membre
|
|
||||||
* @param string $dom Domaine à détruire.
|
/** Fonction appellee par domains quand un domaine est supprime pour le membre
|
||||||
|
* @param string $dom Domaine à detruire.
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function alternc_del_domain($dom) {
|
function alternc_del_domain($dom) {
|
||||||
|
@ -422,7 +449,8 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Fonction appellée par membres quand un membre est effacé.
|
|
||||||
|
/** Fonction appellee par membres quand un membre est efface
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function alternc_del_member() {
|
function alternc_del_member() {
|
||||||
|
@ -433,6 +461,7 @@ class m_ftp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the used quota for the $name service for the current user.
|
* Returns the used quota for the $name service for the current user.
|
||||||
* @param $name string name of the quota
|
* @param $name string name of the quota
|
||||||
|
@ -450,8 +479,8 @@ class m_ftp {
|
||||||
return $q;
|
return $q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exporte toutes les informations ftp du compte AlternC
|
* Exporte toutes les informations ftp du compte AlternC
|
||||||
* @access private
|
* @access private
|
||||||
|
@ -471,8 +500,8 @@ class m_ftp {
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** hook function called by AlternC-upnp to know which open
|
/** hook function called by AlternC-upnp to know which open
|
||||||
* tcp or udp ports this class requires or suggests
|
* tcp or udp ports this class requires or suggests
|
||||||
* @return array a key => value list of port protocol name mandatory values
|
* @return array a key => value list of port protocol name mandatory values
|
||||||
|
@ -484,5 +513,6 @@ class m_ftp {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* Class m_ftp */
|
}
|
||||||
|
|
||||||
|
/* Class m_ftp */
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -29,15 +30,17 @@
|
||||||
* @copyright AlternC-Team 2002-2005 http://alternc.org/
|
* @copyright AlternC-Team 2002-2005 http://alternc.org/
|
||||||
*/
|
*/
|
||||||
class m_hooks {
|
class m_hooks {
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Constructor
|
/** Constructor
|
||||||
* hooks([$mid]) Constructeur de la classe hooks, ne fait rien pour le moment
|
* hooks([$mid]) Constructeur de la classe hooks, ne fait rien pour le moment
|
||||||
*/
|
*/
|
||||||
function m_hooks() {
|
function m_hooks() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* invoke() permet de lancer une fonction donné en parametre dans toute les classes
|
* invoke() permet de lancer une fonction donné en parametre dans toute les classes
|
||||||
* connues de alternc, avec les parametres donnés.
|
* connues de alternc, avec les parametres donnés.
|
||||||
|
@ -77,6 +80,7 @@ class m_hooks {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* invoke each executable script of the directory (or the specified script)
|
* invoke each executable script of the directory (or the specified script)
|
||||||
* @param string $scripts a script or a directory
|
* @param string $scripts a script or a directory
|
||||||
|
@ -115,5 +119,7 @@ class m_hooks {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* Class hooks */
|
}
|
||||||
|
|
||||||
|
/* Class hooks */
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$Id: m_hta.php,v 1.5 2004/11/29 17:15:37 anonymous Exp $
|
$Id: m_hta.php,v 1.5 2004/11/29 17:15:37 anonymous Exp $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
@ -39,13 +40,12 @@
|
||||||
*/
|
*/
|
||||||
class m_hta {
|
class m_hta {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
function m_webaccess() {
|
function m_webaccess() {
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Password kind used in this class (hook for admin class)
|
* Password kind used in this class (hook for admin class)
|
||||||
|
@ -71,7 +71,6 @@ class m_hta {
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a protected folder (.htaccess et .htpasswd)
|
* Create a protected folder (.htaccess et .htpasswd)
|
||||||
* @param string $dir Folder to protect (relative to user root)
|
* @param string $dir Folder to protect (relative to user root)
|
||||||
|
@ -84,7 +83,7 @@ class m_hta {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function CreateDir($dir) {
|
function CreateDir($dir) {
|
||||||
global $mem,$bro,$err;
|
global $bro, $err;
|
||||||
$err->log("hta", "createdir", $dir);
|
$err->log("hta", "createdir", $dir);
|
||||||
$absolute = $bro->convertabsolute($dir, 0);
|
$absolute = $bro->convertabsolute($dir, 0);
|
||||||
if (!$absolute) {
|
if (!$absolute) {
|
||||||
|
@ -119,7 +118,6 @@ class m_hta {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of all user folder currently protected by a .htpasswd file
|
* Returns the list of all user folder currently protected by a .htpasswd file
|
||||||
*
|
*
|
||||||
|
@ -141,6 +139,7 @@ class m_hta {
|
||||||
|
|
||||||
$r = array();
|
$r = array();
|
||||||
for ($i = 0; $i < count($sortie); $i++) {
|
for ($i = 0; $i < count($sortie); $i++) {
|
||||||
|
$matches = array();
|
||||||
preg_match($pattern, $sortie[$i], $matches);
|
preg_match($pattern, $sortie[$i], $matches);
|
||||||
$tmpm = isset($matches[1]) ? '/' . $matches[1] : '';
|
$tmpm = isset($matches[1]) ? '/' . $matches[1] : '';
|
||||||
$r[$i] = $tmpm . "/";
|
$r[$i] = $tmpm . "/";
|
||||||
|
@ -167,7 +166,6 @@ class m_hta {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of login for a protected folder.
|
* Returns the list of login for a protected folder.
|
||||||
*
|
*
|
||||||
|
@ -184,7 +182,8 @@ class m_hta {
|
||||||
/* if (!_reading_htaccess($absolute)) {
|
/* if (!_reading_htaccess($absolute)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*/ }
|
*/
|
||||||
|
}
|
||||||
$file = @fopen("$absolute/.htpasswd", "r");
|
$file = @fopen("$absolute/.htpasswd", "r");
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$res = array();
|
$res = array();
|
||||||
|
@ -204,7 +203,6 @@ class m_hta {
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unprotect a folder
|
* Unprotect a folder
|
||||||
*
|
*
|
||||||
|
@ -216,7 +214,7 @@ class m_hta {
|
||||||
* @return boolean TRUE if the folder has been unprotected, or FALSE if an error occurred
|
* @return boolean TRUE if the folder has been unprotected, or FALSE if an error occurred
|
||||||
*/
|
*/
|
||||||
function DelDir($dir, $skip = false) {
|
function DelDir($dir, $skip = false) {
|
||||||
global $mem,$bro,$err;
|
global $bro, $err;
|
||||||
$err->log("hta", "deldir", $dir);
|
$err->log("hta", "deldir", $dir);
|
||||||
$dir = $bro->convertabsolute($dir, $skip);
|
$dir = $bro->convertabsolute($dir, $skip);
|
||||||
if (!$dir) {
|
if (!$dir) {
|
||||||
|
@ -258,8 +256,7 @@ class m_hta {
|
||||||
$htpasswd_file = "$dir/.htpasswd";
|
$htpasswd_file = "$dir/.htpasswd";
|
||||||
if (!is_writable($htpasswd_file)) {
|
if (!is_writable($htpasswd_file)) {
|
||||||
$err->raise("hta", printf(_("I cannot read the file '%s'"), $htpasswd_file));
|
$err->raise("hta", printf(_("I cannot read the file '%s'"), $htpasswd_file));
|
||||||
}
|
} else if (!unlink($htpasswd_file)) {
|
||||||
else if ( ! unlink($htpasswd_file)) {
|
|
||||||
$err->raise("hta", printf(_("I cannot delete the file '%s/.htpasswd'"), $dir));
|
$err->raise("hta", printf(_("I cannot delete the file '%s/.htpasswd'"), $dir));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -267,7 +264,6 @@ class m_hta {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a user to a protected folder
|
* Add a user to a protected folder
|
||||||
*
|
*
|
||||||
|
@ -333,9 +329,6 @@ class m_hta {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* Delete a user from a protected folder.
|
* Delete a user from a protected folder.
|
||||||
*
|
*
|
||||||
|
@ -377,24 +370,13 @@ class m_hta {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Change the password of a user in a protected folder
|
||||||
* @param string $user The users whose password should be changed
|
* @param string $user The users whose password should be changed
|
||||||
* @param string $newpass The new password of this user
|
* @param string $newpass The new password of this user
|
||||||
* @param string $dir The folder, relative to user root, in which we will change a password
|
* @param string $dir The folder, relative to user root, in which we will change a password
|
||||||
* @return boolean TRUE if the password has been changed, or FALSE if an error occurred
|
* @return boolean TRUE if the password has been changed, or FALSE if an error occurred
|
||||||
*/
|
*/
|
||||||
/**
|
|
||||||
* Change the password of a user in a protected folder
|
|
||||||
*
|
|
||||||
* @global m_bro $bro
|
|
||||||
* @global m_err $err
|
|
||||||
* @global m_admin $admin
|
|
||||||
* @param string $user
|
|
||||||
* @param string $newpass
|
|
||||||
* @param string $dir
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
function change_pass($user, $newpass, $dir) {
|
function change_pass($user, $newpass, $dir) {
|
||||||
global $bro, $err, $admin;
|
global $bro, $err, $admin;
|
||||||
$err->log("hta", "change_pass", $user . "/" . $dir);
|
$err->log("hta", "change_pass", $user . "/" . $dir);
|
||||||
|
@ -433,7 +415,6 @@ class m_hta {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that a .htaccess file is valid (for authentication)
|
* Check that a .htaccess file is valid (for authentication)
|
||||||
*
|
*
|
||||||
|
@ -477,6 +458,6 @@ class m_hta {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* CLASS m_hta */
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* CLASS m_hta */
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -29,6 +30,7 @@
|
||||||
class m_log {
|
class m_log {
|
||||||
|
|
||||||
function m_log() {
|
function m_log() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function list_logs_directory($dir) {
|
function list_logs_directory($dir) {
|
||||||
|
@ -46,8 +48,7 @@ class m_log {
|
||||||
}
|
}
|
||||||
usort($c, "m_log::compare_logtime");
|
usort($c, "m_log::compare_logtime");
|
||||||
return $c;
|
return $c;
|
||||||
|
}
|
||||||
}//list_logs
|
|
||||||
|
|
||||||
// Used by list_logs_directory to sort
|
// Used by list_logs_directory to sort
|
||||||
private function compare_logname($a, $b) {
|
private function compare_logname($a, $b) {
|
||||||
|
@ -59,7 +60,6 @@ class m_log {
|
||||||
return $b['mtime'] - $a['mtime'];
|
return $b['mtime'] - $a['mtime'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function hook_menu() {
|
function hook_menu() {
|
||||||
$obj = array(
|
$obj = array(
|
||||||
'title' => _("Logs"),
|
'title' => _("Logs"),
|
||||||
|
@ -79,7 +79,6 @@ class m_log {
|
||||||
$c[$dir] = $this->list_logs_directory($val);
|
$c[$dir] = $this->list_logs_directory($val);
|
||||||
}
|
}
|
||||||
return $c;
|
return $c;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_logs_directory() {
|
function get_logs_directory() {
|
||||||
|
@ -95,7 +94,7 @@ class m_log {
|
||||||
}
|
}
|
||||||
|
|
||||||
function download_link($file) {
|
function download_link($file) {
|
||||||
global $err,$mem;
|
global $err;
|
||||||
$err->log("log", "download_link");
|
$err->log("log", "download_link");
|
||||||
header("Content-Disposition: attachment; filename=" . $file . "");
|
header("Content-Disposition: attachment; filename=" . $file . "");
|
||||||
header("Content-Type: application/force-download");
|
header("Content-Type: application/force-download");
|
||||||
|
@ -107,16 +106,19 @@ class m_log {
|
||||||
}
|
}
|
||||||
|
|
||||||
function tail($file, $lines = 20) {
|
function tail($file, $lines = 20) {
|
||||||
global $err,$mem;
|
global $err;
|
||||||
$err->log("log", "tail");
|
$err->log("log", "tail");
|
||||||
$lines=intval($lines); if ($lines<=0) $lines=20;
|
$lines = intval($lines);
|
||||||
|
if ($lines <= 0) {
|
||||||
|
$lines = 20;
|
||||||
|
}
|
||||||
$f = $this->get_logs_directory();
|
$f = $this->get_logs_directory();
|
||||||
$ff = $f['dir'] . "/" . basename($file);
|
$ff = $f['dir'] . "/" . basename($file);
|
||||||
unset($out);
|
$out=array();
|
||||||
exec("tail -" . $lines . " " . escapeshellarg($ff), $out);
|
exec("tail -" . $lines . " " . escapeshellarg($ff), $out);
|
||||||
return implode("\n", $out);
|
return implode("\n", $out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // end class
|
// end class
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,11 @@
|
||||||
|
|
||||||
include_once(dirname(__FILE__) . '/vm.class.php');
|
include_once(dirname(__FILE__) . '/vm.class.php');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage AlternC's virtual machine start/stop using our own inetd-based protocol.
|
* Manage AlternC's virtual machine start/stop using our own inetd-based protocol.
|
||||||
*/
|
*/
|
||||||
class m_lxc implements vm {
|
class m_lxc implements vm {
|
||||||
|
|
||||||
|
|
||||||
public $IP;
|
public $IP;
|
||||||
public $KEY;
|
public $KEY;
|
||||||
public $PORT;
|
public $PORT;
|
||||||
|
@ -40,7 +38,6 @@ class m_lxc implements vm {
|
||||||
public $TIMEOUT = 5;
|
public $TIMEOUT = 5;
|
||||||
public $error = array();
|
public $error = array();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor, initialize the class informations from AlternC's variables
|
* Constructor, initialize the class informations from AlternC's variables
|
||||||
*/
|
*/
|
||||||
|
@ -51,12 +48,12 @@ class m_lxc implements vm {
|
||||||
$this->maxtime = variable_get('lxc_maxtime', '4', "How many hours do we allow to have a server before shutting it down", array('desc' => 'Max time', 'type' => 'integer'));
|
$this->maxtime = variable_get('lxc_maxtime', '4', "How many hours do we allow to have a server before shutting it down", array('desc' => 'Max time', 'type' => 'integer'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HOOK: add the "Console Access" to AlternC's main menu
|
* HOOK: add the "Console Access" to AlternC's main menu
|
||||||
*/
|
*/
|
||||||
function hook_menu() {
|
function hook_menu() {
|
||||||
if ( empty($this->IP)) return ; // No menu if no server
|
if (empty($this->IP))
|
||||||
|
return; // No menu if no server
|
||||||
|
|
||||||
$obj = array(
|
$obj = array(
|
||||||
'title' => _("Console access"),
|
'title' => _("Console access"),
|
||||||
|
@ -68,7 +65,6 @@ class m_lxc implements vm {
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HOOK: remove VM history for AlternC account
|
* HOOK: remove VM history for AlternC account
|
||||||
*/
|
*/
|
||||||
|
@ -79,7 +75,6 @@ class m_lxc implements vm {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to a remote VM manager instance
|
* Send a message to a remote VM manager instance
|
||||||
* $params are the parameters to send as serialized data
|
* $params are the parameters to send as serialized data
|
||||||
|
@ -100,9 +95,10 @@ class m_lxc implements vm {
|
||||||
// MySQL Host for this user ?
|
// MySQL Host for this user ?
|
||||||
$moreparams = $hooks->invoke("lxc_params", array($params));
|
$moreparams = $hooks->invoke("lxc_params", array($params));
|
||||||
foreach ($moreparams as $p) {
|
foreach ($moreparams as $p) {
|
||||||
foreach($p as $k=>$v)
|
foreach ($p as $k => $v) {
|
||||||
$params[$k] = $v;
|
$params[$k] = $v;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$msg = serialize($params);
|
$msg = serialize($params);
|
||||||
if (fwrite($fp, $msg . "\n") < 0) {
|
if (fwrite($fp, $msg . "\n") < 0) {
|
||||||
|
@ -122,7 +118,6 @@ class m_lxc implements vm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* START a Virtual Machine on the remote VM manager
|
* START a Virtual Machine on the remote VM manager
|
||||||
* for user $login having hashed password $pass and uid $uid
|
* for user $login having hashed password $pass and uid $uid
|
||||||
|
@ -163,35 +158,35 @@ class m_lxc implements vm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getvm($login = FALSE) {
|
public function getvm($login = FALSE) {
|
||||||
global $db, $mem, $cuid;
|
global $mem;
|
||||||
|
|
||||||
$login = $login ? $login : $mem->user['login'];
|
$login = $login ? $login : $mem->user['login'];
|
||||||
$msgg = array('action' => 'get', 'login' => $login);
|
$msgg = array('action' => 'get', 'login' => $login);
|
||||||
$res = $this->sendMessage($msgg);
|
$res = $this->sendMessage($msgg);
|
||||||
if (!$res) return FALSE;
|
if (!$res) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
return unserialize($res);
|
return unserialize($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop the currently running VM
|
* Stop the currently running VM
|
||||||
*/
|
*/
|
||||||
public function stop() {
|
public function stop() {
|
||||||
global $db, $mem;
|
|
||||||
$vm = $this->getvm();
|
$vm = $this->getvm();
|
||||||
if ($vm === FALSE)
|
if ($vm === FALSE) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
if ($this->sendMessage(array('action' => 'stop', 'vm' => $vm['vm'])) === FALSE)
|
if ($this->sendMessage(array('action' => 'stop', 'vm' => $vm['vm'])) === FALSE) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// class m_lxc
|
||||||
} // class m_lxc
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -34,38 +35,35 @@
|
||||||
* This class is also defining a few hooks, search ->invoke in the code.
|
* This class is also defining a few hooks, search ->invoke in the code.
|
||||||
*/
|
*/
|
||||||
class m_mail {
|
class m_mail {
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** domain list for this account
|
/** domain list for this account
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $domains;
|
var $domains;
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** If an email has those chars, 'not nice in shell env' ;)
|
/** If an email has those chars, 'not nice in shell env' ;)
|
||||||
* we don't store the email in $mail/u/{user}_domain, but in $mail/_/{address_id}_domain
|
* we don't store the email in $mail/u/{user}_domain, but in $mail/_/{address_id}_domain
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $specialchars = array('"', "'", '\\', '/');
|
var $specialchars = array('"', "'", '\\', '/');
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** If an email has those chars, we will ONLY allow RECIPIENTS, NOT POP/IMAP for DOVECOT !
|
/** If an email has those chars, we will ONLY allow RECIPIENTS, NOT POP/IMAP for DOVECOT !
|
||||||
* Since Dovecot doesn't allow those characters
|
* Since Dovecot doesn't allow those characters
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $forbiddenchars = array('"', "'", '\\', '/', '?', '!', '*', '$', '|', '#', '+');
|
var $forbiddenchars = array('"', "'", '\\', '/', '?', '!', '*', '$', '|', '#', '+');
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Number of results for a pager display
|
/** Number of results for a pager display
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $total;
|
var $total;
|
||||||
|
|
||||||
|
|
||||||
// Human server name for help
|
// Human server name for help
|
||||||
var $srv_submission;
|
var $srv_submission;
|
||||||
var $srv_smtp;
|
var $srv_smtp;
|
||||||
|
@ -74,10 +72,11 @@ class m_mail {
|
||||||
var $srv_imaps;
|
var $srv_imaps;
|
||||||
var $srv_pop3;
|
var $srv_pop3;
|
||||||
var $srv_pop3s;
|
var $srv_pop3s;
|
||||||
|
|
||||||
var $cache_domain_mail_size = array();
|
var $cache_domain_mail_size = array();
|
||||||
var $enum_domains = array();
|
var $enum_domains = array();
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructeur
|
* Constructeur
|
||||||
*/
|
*/
|
||||||
|
@ -102,8 +101,7 @@ class m_mail {
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($this->enum_domains() as $d) {
|
foreach ($this->enum_domains() as $d) {
|
||||||
$obj['links'][] =
|
$obj['links'][] = array(
|
||||||
array (
|
|
||||||
'txt' => htmlentities($d["domaine"]) . ' ' . htmlentities("(" . $d["nb_mail"] . ")"),
|
'txt' => htmlentities($d["domaine"]) . ' ' . htmlentities("(" . $d["nb_mail"] . ")"),
|
||||||
'url' => "mail_list.php?domain_id=" . urlencode($d['id']),
|
'url' => "mail_list.php?domain_id=" . urlencode($d['id']),
|
||||||
);
|
);
|
||||||
|
@ -121,7 +119,9 @@ class m_mail {
|
||||||
$this->cache_domain_mail_size[$dd] = $db->f('sum');
|
$this->cache_domain_mail_size[$dd] = $db->f('sum');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( isset( $this->cache_domain_mail_size[$domain]) ) return $this->cache_domain_mail_size[$domain];
|
if (isset($this->cache_domain_mail_size[$domain])) {
|
||||||
|
return $this->cache_domain_mail_size[$domain];
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,9 @@ class m_mail {
|
||||||
*/
|
*/
|
||||||
function catchall_del($domain_id) {
|
function catchall_del($domain_id) {
|
||||||
$catch = $this->catchall_getinfos($domain_id);
|
$catch = $this->catchall_getinfos($domain_id);
|
||||||
if (empty($catch['mail_id'])) return false;
|
if (empty($catch['mail_id'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return $this->delete($catch['mail_id']);
|
return $this->delete($catch['mail_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +174,6 @@ class m_mail {
|
||||||
*/
|
*/
|
||||||
function catchall_set($domain_id, $target) {
|
function catchall_set($domain_id, $target) {
|
||||||
global $err;
|
global $err;
|
||||||
// target :
|
|
||||||
$target = rtrim($target);
|
$target = rtrim($target);
|
||||||
if (substr_count($target, '@') == 0) { // Pas de @
|
if (substr_count($target, '@') == 0) { // Pas de @
|
||||||
$target = '@' . $target;
|
$target = '@' . $target;
|
||||||
|
@ -191,8 +192,8 @@ class m_mail {
|
||||||
return $this->create_alias($domain_id, '', $target, "catchall", true);
|
return $this->create_alias($domain_id, '', $target, "catchall", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** get_quota (hook for quota class), returns the number of used
|
/** get_quota (hook for quota class), returns the number of used
|
||||||
* service for a quota-bound service
|
* service for a quota-bound service
|
||||||
* @param $name string the named quota we want
|
* @param $name string the named quota we want
|
||||||
|
@ -210,8 +211,8 @@ class m_mail {
|
||||||
return $q;
|
return $q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Password policy kind used in this class (hook for admin class)
|
/** Password policy kind used in this class (hook for admin class)
|
||||||
* @return array an array of policykey => "policy name (for humans)"
|
* @return array an array of policykey => "policy name (for humans)"
|
||||||
*/
|
*/
|
||||||
|
@ -219,15 +220,17 @@ class m_mail {
|
||||||
return array("pop" => _("Email account password"));
|
return array("pop" => _("Email account password"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Returns the list of mail-hosting domains for a user
|
/** Returns the list of mail-hosting domains for a user
|
||||||
* @return array indexed array of hosted domains
|
* @return array indexed array of hosted domains
|
||||||
*/
|
*/
|
||||||
function enum_domains($uid = -1) {
|
function enum_domains($uid = -1) {
|
||||||
global $db, $err, $cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("mail", "enum_domains");
|
$err->log("mail", "enum_domains");
|
||||||
if ($uid == -1) { $uid = $cuid; }
|
if ($uid == -1) {
|
||||||
|
$uid = $cuid;
|
||||||
|
}
|
||||||
$db->query("
|
$db->query("
|
||||||
SELECT
|
SELECT
|
||||||
d.id,
|
d.id,
|
||||||
|
@ -251,8 +254,8 @@ ORDER BY
|
||||||
return $this->enum_domains;
|
return $this->enum_domains;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** available: tells if an email address can be installed in the server
|
/** available: tells if an email address can be installed in the server
|
||||||
* check the domain part (is it mine too), the syntax, and the availability.
|
* check the domain part (is it mine too), the syntax, and the availability.
|
||||||
* @param $mail string email to check
|
* @param $mail string email to check
|
||||||
|
@ -280,7 +283,6 @@ ORDER BY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/* function used to list every mail address hosted on a domain.
|
/* function used to list every mail address hosted on a domain.
|
||||||
* @param $dom_id integer the domain id.
|
* @param $dom_id integer the domain id.
|
||||||
|
@ -289,19 +291,28 @@ ORDER BY
|
||||||
* @param $count integer return no more than THAT much emails. -1 for ALL. Offset is ignored then.
|
* @param $count integer return no more than THAT much emails. -1 for ALL. Offset is ignored then.
|
||||||
* @result an array of each mail hosted under the domain.
|
* @result an array of each mail hosted under the domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function enum_domain_mails($dom_id = null, $search = "", $offset = 0, $count = 30, $show_systemmails = false) {
|
function enum_domain_mails($dom_id = null, $search = "", $offset = 0, $count = 30, $show_systemmails = false) {
|
||||||
global $db,$err,$cuid,$hooks;
|
global $db, $err, $hooks;
|
||||||
$err->log("mail", "enum_domains_mail");
|
$err->log("mail", "enum_domains_mail");
|
||||||
|
|
||||||
$search = trim($search);
|
$search = trim($search);
|
||||||
|
|
||||||
$where = "a.domain_id=$dom_id";
|
$where = "a.domain_id=$dom_id";
|
||||||
if ($search) $where.=" AND (a.address LIKE '%".addslashes($search)."%' OR r.recipients LIKE '%".addslashes($search)."%')";
|
if ($search) {
|
||||||
if (!$show_systemmails) $where.=" AND type='' ";
|
$where.=" AND (a.address LIKE '%" . addslashes($search) . "%' OR r.recipients LIKE '%" . addslashes($search) . "%')";
|
||||||
|
}
|
||||||
|
if (!$show_systemmails) {
|
||||||
|
$where.=" AND type='' ";
|
||||||
|
}
|
||||||
$db->query("SELECT count(a.id) AS total FROM address a LEFT JOIN recipient r ON r.address_id=a.id WHERE $where;");
|
$db->query("SELECT count(a.id) AS total FROM address a LEFT JOIN recipient r ON r.address_id=a.id WHERE $where;");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$this->total = $db->f("total");
|
$this->total = $db->f("total");
|
||||||
if ($count!=-1) $limit="LIMIT $offset,$count"; else $limit="";
|
if ($count != -1) {
|
||||||
|
$limit = "LIMIT $offset,$count";
|
||||||
|
} else {
|
||||||
|
$limit = "";
|
||||||
|
}
|
||||||
$db->query("SELECT a.id, a.address, a.password, a.`enabled`, a.mail_action, d.domaine AS domain, m.quota, m.quota*1024*1024 AS quotabytes, m.bytes AS used, NOT ISNULL(m.id) AS islocal, a.type, r.recipients, m.lastlogin, a.domain_id
|
$db->query("SELECT a.id, a.address, a.password, a.`enabled`, a.mail_action, d.domaine AS domain, m.quota, m.quota*1024*1024 AS quotabytes, m.bytes AS used, NOT ISNULL(m.id) AS islocal, a.type, r.recipients, m.lastlogin, a.domain_id
|
||||||
FROM (address a LEFT JOIN mailbox m ON m.address_id=a.id) LEFT JOIN recipient r ON r.address_id=a.id, domaines d
|
FROM (address a LEFT JOIN mailbox m ON m.address_id=a.id) LEFT JOIN recipient r ON r.address_id=a.id, domaines d
|
||||||
WHERE $where AND d.id=a.domain_id $limit ;");
|
WHERE $where AND d.id=a.domain_id $limit ;");
|
||||||
|
@ -322,13 +333,14 @@ ORDER BY
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function hook_mail_get_details($detail) {
|
function hook_mail_get_details($detail) {
|
||||||
if ($detail['type']=='catchall') return _(sprintf("Special mail address for catch-all. <a href='mail_manage_catchall.php?domain_id=%s'>Click here to manage it.</a>",$detail['domain_id']));
|
if ($detail['type'] == 'catchall') {
|
||||||
|
return _(sprintf("Special mail address for catch-all. <a href='mail_manage_catchall.php?domain_id=%s'>Click here to manage it.</a>", $detail['domain_id']));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Function used to insert a new mail into the db
|
/** Function used to insert a new mail into the db
|
||||||
* should be used by the web interface, not by third-party programs.
|
* should be used by the web interface, not by third-party programs.
|
||||||
*
|
*
|
||||||
|
@ -342,7 +354,7 @@ ORDER BY
|
||||||
* or false if an error occured ($err is filled accordingly)
|
* or false if an error occured ($err is filled accordingly)
|
||||||
*/
|
*/
|
||||||
function create($dom_id, $mail, $type = "", $dontcheck = false) {
|
function create($dom_id, $mail, $type = "", $dontcheck = false) {
|
||||||
global $err,$db,$cuid,$quota,$dom,$hooks;
|
global $err, $db, $quota, $dom, $hooks;
|
||||||
$err->log("mail", "create", $mail);
|
$err->log("mail", "create", $mail);
|
||||||
|
|
||||||
// Validate the domain id
|
// Validate the domain id
|
||||||
|
@ -383,14 +395,14 @@ ORDER BY
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** function used to get every information we can on a mail
|
/** function used to get every information we can on a mail
|
||||||
* @param $mail_id integer
|
* @param $mail_id integer
|
||||||
* @return array a hashtable with all the informations for that email
|
* @return array a hashtable with all the informations for that email
|
||||||
*/
|
*/
|
||||||
function get_details($mail_id) {
|
function get_details($mail_id) {
|
||||||
global $db, $err, $cuid, $hooks;
|
global $db, $err, $hooks;
|
||||||
$err->log("mail", "get_details");
|
$err->log("mail", "get_details");
|
||||||
|
|
||||||
$mail_id = intval($mail_id);
|
$mail_id = intval($mail_id);
|
||||||
|
@ -401,7 +413,9 @@ ORDER BY
|
||||||
|
|
||||||
// We fetch all the informations for that email: these will fill the hastable :
|
// We fetch all the informations for that email: these will fill the hastable :
|
||||||
$db->query("SELECT a.id, a.address, a.password, a.enabled, d.domaine AS domain, m.path, m.quota, m.quota*1024*1024 AS quotabytes, m.bytes AS used, NOT ISNULL(m.id) AS islocal, a.type, r.recipients, m.lastlogin, a.mail_action, m.mail_action AS mailbox_action FROM (address a LEFT JOIN mailbox m ON m.address_id=a.id) LEFT JOIN recipient r ON r.address_id=a.id, domaines d WHERE a.id=" . $mail_id . " AND d.id=a.domain_id;");
|
$db->query("SELECT a.id, a.address, a.password, a.enabled, d.domaine AS domain, m.path, m.quota, m.quota*1024*1024 AS quotabytes, m.bytes AS used, NOT ISNULL(m.id) AS islocal, a.type, r.recipients, m.lastlogin, a.mail_action, m.mail_action AS mailbox_action FROM (address a LEFT JOIN mailbox m ON m.address_id=a.id) LEFT JOIN recipient r ON r.address_id=a.id, domaines d WHERE a.id=" . $mail_id . " AND d.id=a.domain_id;");
|
||||||
if (! $db->next_record()) return false;
|
if (!$db->next_record()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$details = $db->Record;
|
$details = $db->Record;
|
||||||
// if necessary, fill the typedata with data from hooks ...
|
// if necessary, fill the typedata with data from hooks ...
|
||||||
if ($details["type"]) {
|
if ($details["type"]) {
|
||||||
|
@ -411,10 +425,10 @@ ORDER BY
|
||||||
return $details;
|
return $details;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private $isitmy_cache = array();
|
private $isitmy_cache = array();
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Check if an email is mine ...
|
/** Check if an email is mine ...
|
||||||
*
|
*
|
||||||
* @param $mail_id integer the number of the email to check
|
* @param $mail_id integer the number of the email to check
|
||||||
|
@ -425,8 +439,9 @@ ORDER BY
|
||||||
global $err, $db, $cuid;
|
global $err, $db, $cuid;
|
||||||
$mail_id = intval($mail_id);
|
$mail_id = intval($mail_id);
|
||||||
// cache it (may be called more than one time in the same page).
|
// cache it (may be called more than one time in the same page).
|
||||||
if (isset($this->isitmy_cache[$mail_id])) return $this->isitmy_cache[$mail_id];
|
if (isset($this->isitmy_cache[$mail_id])) {
|
||||||
|
return $this->isitmy_cache[$mail_id];
|
||||||
|
}
|
||||||
$db->query("SELECT concat(a.address,'@',d.domaine) AS email FROM address a, domaines d WHERE d.id=a.domain_id AND a.id=$mail_id AND d.compte=$cuid;");
|
$db->query("SELECT concat(a.address,'@',d.domaine) AS email FROM address a, domaines d WHERE d.id=a.domain_id AND a.id=$mail_id AND d.compte=$cuid;");
|
||||||
if ($db->next_record()) {
|
if ($db->next_record()) {
|
||||||
return $this->isitmy_cache[$mail_id] = $db->f("email");
|
return $this->isitmy_cache[$mail_id] = $db->f("email");
|
||||||
|
@ -436,8 +451,8 @@ ORDER BY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Hook called when the DOMAIN class will delete a domain.
|
/** Hook called when the DOMAIN class will delete a domain.
|
||||||
*
|
*
|
||||||
* @param $dom integer the number of the email to delete
|
* @param $dom integer the number of the email to delete
|
||||||
|
@ -463,7 +478,7 @@ ORDER BY
|
||||||
|
|
||||||
// return the alternc account's ID of the mail_id
|
// return the alternc account's ID of the mail_id
|
||||||
function get_account_by_mail_id($mail_id) {
|
function get_account_by_mail_id($mail_id) {
|
||||||
global $db,$err;
|
global $db;
|
||||||
$db->query("select compte as uid from domaines d, address a where a.domain_id = d.id and a.id = $mail_id");
|
$db->query("select compte as uid from domaines d, address a where a.domain_id = d.id and a.id = $mail_id");
|
||||||
if (!$db->next_record()) {
|
if (!$db->next_record()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -471,8 +486,8 @@ ORDER BY
|
||||||
return $db->f('uid');
|
return $db->f('uid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Function used to delete a mail from the db
|
/** Function used to delete a mail from the db
|
||||||
* should be used by the web interface, not by third-party programs.
|
* should be used by the web interface, not by third-party programs.
|
||||||
*
|
*
|
||||||
|
@ -481,7 +496,7 @@ ORDER BY
|
||||||
* or false if an error occured ($err is filled accordingly)
|
* or false if an error occured ($err is filled accordingly)
|
||||||
*/
|
*/
|
||||||
function delete($mail_id) {
|
function delete($mail_id) {
|
||||||
global $err,$db,$cuid,$quota,$dom,$hooks;
|
global $err, $db, $hooks;
|
||||||
$err->log("mail", "delete");
|
$err->log("mail", "delete");
|
||||||
|
|
||||||
$mail_id = intval($mail_id);
|
$mail_id = intval($mail_id);
|
||||||
|
@ -525,8 +540,8 @@ ORDER BY
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Function used to undelete a pending deletion mail from the db
|
/** Function used to undelete a pending deletion mail from the db
|
||||||
* should be used by the web interface, not by third-party programs.
|
* should be used by the web interface, not by third-party programs.
|
||||||
*
|
*
|
||||||
|
@ -535,7 +550,7 @@ ORDER BY
|
||||||
* or false if an error occured ($err is filled accordingly)
|
* or false if an error occured ($err is filled accordingly)
|
||||||
*/
|
*/
|
||||||
function undelete($mail_id) {
|
function undelete($mail_id) {
|
||||||
global $err,$db,$cuid,$quota,$dom,$hooks;
|
global $err, $db;
|
||||||
$err->log("mail", "undelete");
|
$err->log("mail", "undelete");
|
||||||
|
|
||||||
$mail_id = intval($mail_id);
|
$mail_id = intval($mail_id);
|
||||||
|
@ -577,8 +592,8 @@ ORDER BY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** set the password of an email address.
|
/** set the password of an email address.
|
||||||
* @param $mail_id integer email ID
|
* @param $mail_id integer email ID
|
||||||
* @param $pass string the new password.
|
* @param $pass string the new password.
|
||||||
|
@ -588,14 +603,20 @@ ORDER BY
|
||||||
global $db, $err, $admin;
|
global $db, $err, $admin;
|
||||||
$err->log("mail", "setpasswd");
|
$err->log("mail", "setpasswd");
|
||||||
|
|
||||||
if (!($email=$this->is_it_my_mail($mail_id))) return false;
|
if (!($email = $this->is_it_my_mail($mail_id))) {
|
||||||
if (!$admin->checkPolicy("pop",$email,$pass)) return false;
|
return false;
|
||||||
if (!$db->query("UPDATE address SET password='"._md5cr($pass)."' where id=$mail_id;")) return false;
|
}
|
||||||
|
if (!$admin->checkPolicy("pop", $email, $pass)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!$db->query("UPDATE address SET password='" . _md5cr($pass) . "' where id=$mail_id;")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Enables an email address.
|
/** Enables an email address.
|
||||||
* @param $mail_id integer Email ID
|
* @param $mail_id integer Email ID
|
||||||
* @return boolean true if the email has been enabled.
|
* @return boolean true if the email has been enabled.
|
||||||
|
@ -603,13 +624,17 @@ ORDER BY
|
||||||
function enable($mail_id) {
|
function enable($mail_id) {
|
||||||
global $db, $err;
|
global $db, $err;
|
||||||
$err->log("mail", "enable");
|
$err->log("mail", "enable");
|
||||||
if (!($email=$this->is_it_my_mail($mail_id))) return false;
|
if (!($email = $this->is_it_my_mail($mail_id))) {
|
||||||
if (!$db->query("UPDATE address SET `enabled`=1 where id=$mail_id;")) return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (!$db->query("UPDATE address SET `enabled`=1 where id=$mail_id;")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Disables an email address.
|
/** Disables an email address.
|
||||||
* @param $mail_id integer Email ID
|
* @param $mail_id integer Email ID
|
||||||
* @return boolean true if the email has been enabled.
|
* @return boolean true if the email has been enabled.
|
||||||
|
@ -617,13 +642,17 @@ ORDER BY
|
||||||
function disable($mail_id) {
|
function disable($mail_id) {
|
||||||
global $db, $err;
|
global $db, $err;
|
||||||
$err->log("mail", "disable");
|
$err->log("mail", "disable");
|
||||||
if (!($email=$this->is_it_my_mail($mail_id))) return false;
|
if (!($email = $this->is_it_my_mail($mail_id))) {
|
||||||
if (!$db->query("UPDATE address SET `enabled`=0 where id=$mail_id;")) return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (!$db->query("UPDATE address SET `enabled`=0 where id=$mail_id;")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Function used to update an email settings
|
/** Function used to update an email settings
|
||||||
* should be used by the web interface, not by third-party programs.
|
* should be used by the web interface, not by third-party programs.
|
||||||
*
|
*
|
||||||
|
@ -635,7 +664,7 @@ ORDER BY
|
||||||
* or false if an error occured ($err is filled accordingly)
|
* or false if an error occured ($err is filled accordingly)
|
||||||
*/
|
*/
|
||||||
function set_details($mail_id, $islocal, $quotamb, $recipients, $delivery = "dovecot", $dontcheck = false) {
|
function set_details($mail_id, $islocal, $quotamb, $recipients, $delivery = "dovecot", $dontcheck = false) {
|
||||||
global $err,$db,$cuid,$quota,$dom,$hooks;
|
global $err, $db;
|
||||||
$delivery = mysql_real_escape_string($delivery);
|
$delivery = mysql_real_escape_string($delivery);
|
||||||
$err->log("mail", "set_details");
|
$err->log("mail", "set_details");
|
||||||
if (!($me = $this->get_details($mail_id))) {
|
if (!($me = $this->get_details($mail_id))) {
|
||||||
|
@ -655,7 +684,6 @@ ORDER BY
|
||||||
if (strpos($me["address"], $str) !== false) {
|
if (strpos($me["address"], $str) !== false) {
|
||||||
$err->raise("mail", _("There is forbidden characters in your email address. You can't make it a POP/IMAP account, you can only use it as redirection to other emails"));
|
$err->raise("mail", _("There is forbidden characters in your email address. You can't make it a POP/IMAP account, you can only use it as redirection to other emails"));
|
||||||
return false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($this->specialchars as $str) {
|
foreach ($this->specialchars as $str) {
|
||||||
|
@ -696,14 +724,14 @@ ORDER BY
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** A wrapper used by mailman class to create it's needed addresses
|
/** A wrapper used by mailman class to create it's needed addresses
|
||||||
* @ param : $dom_id , the domain id associated to a given address
|
* @ param : $dom_id , the domain id associated to a given address
|
||||||
* @ param : $m , the left part of the mail address being created
|
* @ param : $m , the left part of the mail address being created
|
||||||
* @ param : $delivery , the delivery used to deliver the mail
|
* @ param : $delivery , the delivery used to deliver the mail
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function add_wrapper($dom_id, $m, $delivery) {
|
function add_wrapper($dom_id, $m, $delivery) {
|
||||||
global $err,$db,$mail;
|
global $err, $mail;
|
||||||
$err->log("mail", "add_wrapper", "creating $delivery $m address");
|
$err->log("mail", "add_wrapper", "creating $delivery $m address");
|
||||||
|
|
||||||
$mail_id = $mail->create($dom_id, $m, $delivery);
|
$mail_id = $mail->create($dom_id, $m, $delivery);
|
||||||
|
@ -712,6 +740,7 @@ ORDER BY
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** A function used to create an alias for a specific address
|
/** A function used to create an alias for a specific address
|
||||||
* @ param : $dom_id , the domain sql identifier
|
* @ param : $dom_id , the domain sql identifier
|
||||||
* @ param : $m , the alias we want to create
|
* @ param : $m , the alias we want to create
|
||||||
|
@ -722,35 +751,37 @@ ORDER BY
|
||||||
* @param string $dom_id
|
* @param string $dom_id
|
||||||
*/
|
*/
|
||||||
function create_alias($dom_id, $m, $alias, $type = "", $dontcheck = false) {
|
function create_alias($dom_id, $m, $alias, $type = "", $dontcheck = false) {
|
||||||
global $err,$db,$mail;
|
global $err, $mail;
|
||||||
$err->log("mail", "create_alias", "creating $m alias for $alias type $type");
|
$err->log("mail", "create_alias", "creating $m alias for $alias type $type");
|
||||||
|
|
||||||
$mail_id = $mail->create($dom_id, $m, $type, $dontcheck);
|
$mail_id = $mail->create($dom_id, $m, $type, $dontcheck);
|
||||||
if (!$mail_id) return false;
|
if (!$mail_id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$this->set_details($mail_id, 0, 0, $alias, "dovecot", $dontcheck);
|
$this->set_details($mail_id, 0, 0, $alias, "dovecot", $dontcheck);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** A wrapper used by mailman class to create it's needed addresses
|
/** A wrapper used by mailman class to create it's needed addresses
|
||||||
* @ param : $mail_id , the mysql id of the mail address we want to delete
|
* @ param : $mail_id , the mysql id of the mail address we want to delete
|
||||||
* of the email for the current acccount.
|
* of the email for the current acccount.
|
||||||
*/
|
*/
|
||||||
function del_wrapper($mail_id) {
|
function del_wrapper($mail_id) {
|
||||||
global $err,$db;
|
global $err;
|
||||||
$err->log("mail", "del_wrapper");
|
$err->log("mail", "del_wrapper");
|
||||||
$this->delete($mail_id);
|
$this->delete($mail_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Export the mail information of an account
|
/** Export the mail information of an account
|
||||||
* @return: str, string containing the complete configuration
|
* @return: str, string containing the complete configuration
|
||||||
* of the email for the current acccount.
|
* of the email for the current acccount.
|
||||||
*/
|
*/
|
||||||
function alternc_export_conf() {
|
function alternc_export_conf() {
|
||||||
global $db,$err,$mail_localbox;
|
global $err;
|
||||||
$err->log("mail", "export");
|
$err->log("mail", "export");
|
||||||
$domain = $this->enum_domains();
|
$domain = $this->enum_domains();
|
||||||
$str = "<mail>\n";
|
$str = "<mail>\n";
|
||||||
|
@ -784,24 +815,27 @@ ORDER BY
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the list of allowed slave accounts (secondary-mx)
|
* Return the list of allowed slave accounts (secondary-mx)
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function enum_slave_account() {
|
function enum_slave_account() {
|
||||||
global $db,$err;
|
global $db;
|
||||||
$db->query("SELECT login,pass FROM mxaccount;");
|
$db->query("SELECT login,pass FROM mxaccount;");
|
||||||
$res = array();
|
$res = array();
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$res[] = $db->Record;
|
$res[] = $db->Record;
|
||||||
}
|
}
|
||||||
if (!count($res)) return false;
|
if (!count($res)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for a slave account (secondary mx)
|
* Check for a slave account (secondary mx)
|
||||||
* @param string $login the login to check
|
* @param string $login the login to check
|
||||||
|
@ -809,7 +843,7 @@ ORDER BY
|
||||||
* @return boolean TRUE if the password is correct, or FALSE if an error occurred.
|
* @return boolean TRUE if the password is correct, or FALSE if an error occurred.
|
||||||
*/
|
*/
|
||||||
function check_slave_account($login, $pass) {
|
function check_slave_account($login, $pass) {
|
||||||
global $db,$err;
|
global $db;
|
||||||
$login = mysql_real_escape_string($login);
|
$login = mysql_real_escape_string($login);
|
||||||
$pass = mysql_real_escape_string($pass);
|
$pass = mysql_real_escape_string($pass);
|
||||||
$db->query("SELECT * FROM mxaccount WHERE login='$login' AND pass='$pass';");
|
$db->query("SELECT * FROM mxaccount WHERE login='$login' AND pass='$pass';");
|
||||||
|
@ -819,12 +853,12 @@ ORDER BY
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Out (echo) the complete hosted domain list :
|
/** Out (echo) the complete hosted domain list :
|
||||||
*/
|
*/
|
||||||
function echo_domain_list($format = null) {
|
function echo_domain_list($format = null) {
|
||||||
global $db,$err;
|
global $db;
|
||||||
$db->query("SELECT domaine FROM domaines WHERE gesmx=1 ORDER BY domaine");
|
$db->query("SELECT domaine FROM domaines WHERE gesmx=1 ORDER BY domaine");
|
||||||
$lst = array();
|
$lst = array();
|
||||||
$tt = "";
|
$tt = "";
|
||||||
|
@ -839,16 +873,16 @@ ORDER BY
|
||||||
switch ($format) {
|
switch ($format) {
|
||||||
case "json":
|
case "json":
|
||||||
return json_encode($obj);
|
return json_encode($obj);
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
foreach ($lst as $l) { echo $l."\n"; }
|
foreach ($lst as $l) {
|
||||||
|
echo $l . "\n";
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
|
||||||
} // switch
|
} // switch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a slave account that will be allowed to access the mxdomain list
|
* Add a slave account that will be allowed to access the mxdomain list
|
||||||
* @param string $login the login to add
|
* @param string $login the login to add
|
||||||
|
@ -868,20 +902,21 @@ ORDER BY
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a slave account
|
* Remove a slave account
|
||||||
* @param string $login the login to delete
|
* @param string $login the login to delete
|
||||||
*/
|
*/
|
||||||
function del_slave_account($login) {
|
function del_slave_account($login) {
|
||||||
global $db,$err;
|
global $db;
|
||||||
$login = mysql_real_escape_string($login);
|
$login = mysql_real_escape_string($login);
|
||||||
$db->query("DELETE FROM mxaccount WHERE login='$login'");
|
$db->query("DELETE FROM mxaccount WHERE login='$login'");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** hook function called by AlternC when a domain is created for
|
/** hook function called by AlternC when a domain is created for
|
||||||
* the current user account using the SLAVE DOMAIN feature
|
* the current user account using the SLAVE DOMAIN feature
|
||||||
* This function create a CATCHALL to the master domain
|
* This function create a CATCHALL to the master domain
|
||||||
|
@ -897,6 +932,7 @@ ORDER BY
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** hook function called by AlternC when a domain is created for
|
/** hook function called by AlternC when a domain is created for
|
||||||
* the current user account
|
* the current user account
|
||||||
* This function create a postmaster mail which is an alias to LOGIN @ FQDN
|
* This function create a postmaster mail which is an alias to LOGIN @ FQDN
|
||||||
|
@ -905,7 +941,7 @@ ORDER BY
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function hook_dom_add_mx_domain($domain_id) {
|
function hook_dom_add_mx_domain($domain_id) {
|
||||||
global $err, $mem, $L_FQDN,$db;
|
global $err, $mem, $db;
|
||||||
$err->log("mail", "hook_dom_add_mx_domain", $domain_id);
|
$err->log("mail", "hook_dom_add_mx_domain", $domain_id);
|
||||||
|
|
||||||
$db->query("SELECT value FROM variable where name='mailname_bounce';");
|
$db->query("SELECT value FROM variable where name='mailname_bounce';");
|
||||||
|
@ -927,8 +963,8 @@ ORDER BY
|
||||||
return $this->create_alias($domain_id, 'postmaster', $mem->user['login'] . '@' . $mailname);
|
return $this->create_alias($domain_id, 'postmaster', $mem->user['login'] . '@' . $mailname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** hook function called by variables when a variable is changed
|
/** hook function called by variables when a variable is changed
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
|
@ -953,21 +989,26 @@ ORDER BY
|
||||||
$this->set_dns_dmarc($db->Record["domaine"], $new, $old, $db->Record["compte"], $db->Record["login"]);
|
$this->set_dns_dmarc($db->Record["domaine"], $new, $old, $db->Record["compte"], $db->Record["login"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Set or UPDATE the DNS record for the domain $dom(str) to be $spf
|
/** Set or UPDATE the DNS record for the domain $dom(str) to be $spf
|
||||||
* account's login is current and if not it's $login.
|
* account's login is current and if not it's $login.
|
||||||
* don't change spf if current value is not $old
|
* don't change spf if current value is not $old
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function set_dns_spf($domain, $spf, $previous = -1, $uid = -1, $login = -1) {
|
function set_dns_spf($domain, $spf, $previous = -1, $uid = -1, $login = -1) {
|
||||||
global $db, $cuid, $dom, $mem;
|
global $db, $cuid, $mem;
|
||||||
// defaults
|
// defaults
|
||||||
if ($uid===-1) $uid=intval($cuid); else $uid=intval($uid);
|
if ($uid === -1) {
|
||||||
if ($login===-1) $login=$mem->user["login"];
|
$uid = intval($cuid);
|
||||||
|
} else {
|
||||||
|
$uid = intval($uid);
|
||||||
|
}
|
||||||
|
if ($login === -1) {
|
||||||
|
$login = $mem->user["login"];
|
||||||
|
}
|
||||||
// Search for the record in sub_domaines table
|
// Search for the record in sub_domaines table
|
||||||
$db->query("SELECT * FROM sub_domaines WHERE compte=$uid AND domaine='" . addslashes($domain) . "' AND sub='' AND type='txt' AND valeur LIKE 'v=spf1 %' AND web_action!='DELETE';");
|
$db->query("SELECT * FROM sub_domaines WHERE compte=$uid AND domaine='" . addslashes($domain) . "' AND sub='' AND type='txt' AND valeur LIKE 'v=spf1 %' AND web_action!='DELETE';");
|
||||||
if ($db->next_record()) {
|
if ($db->next_record()) {
|
||||||
|
@ -980,19 +1021,24 @@ ORDER BY
|
||||||
$db->query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine='" . addslashes($domain) . "';");
|
$db->query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine='" . addslashes($domain) . "';");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Set or UPDATE the DNS record for the domain $dom(str) to be $dmarc
|
/** Set or UPDATE the DNS record for the domain $dom(str) to be $dmarc
|
||||||
* account's login is current and if not it's $login.
|
* account's login is current and if not it's $login.
|
||||||
* don't change dmarc if current value is not $old
|
* don't change dmarc if current value is not $old
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function set_dns_dmarc($domain, $dmarc, $previous = -1, $uid = -1, $login = -1) {
|
function set_dns_dmarc($domain, $dmarc, $previous = -1, $uid = -1, $login = -1) {
|
||||||
global $db, $cuid, $dom, $mem, $L_FQDN;
|
global $db, $cuid, $mem, $L_FQDN;
|
||||||
// defaults
|
// defaults
|
||||||
if ($uid===-1) $uid=intval($cuid); else $uid=intval($uid);
|
if ($uid === -1) {
|
||||||
if ($login===-1) $login=$mem->user["login"];
|
$uid = intval($cuid);
|
||||||
|
} else {
|
||||||
|
$uid = intval($uid);
|
||||||
|
}
|
||||||
|
if ($login === -1) {
|
||||||
|
$login = $mem->user["login"];
|
||||||
|
}
|
||||||
$dmarc = str_replace("%%ADMINMAIL%%", "admin@" . $L_FQDN, $dmarc);
|
$dmarc = str_replace("%%ADMINMAIL%%", "admin@" . $L_FQDN, $dmarc);
|
||||||
$dmarc = str_replace("%%USERMAIL%%", $login . "@" . $L_FQDN, $dmarc);
|
$dmarc = str_replace("%%USERMAIL%%", $login . "@" . $L_FQDN, $dmarc);
|
||||||
|
|
||||||
|
@ -1008,10 +1054,8 @@ ORDER BY
|
||||||
$db->query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine='" . addslashes($domain) . "';");
|
$db->query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine='" . addslashes($domain) . "';");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** hook function called by AlternC-upnp to know which open
|
/** hook function called by AlternC-upnp to know which open
|
||||||
* tcp or udp ports this class requires or suggests
|
* tcp or udp ports this class requires or suggests
|
||||||
* @return array a key => value list of port protocol name mandatory values
|
* @return array a key => value list of port protocol name mandatory values
|
||||||
|
@ -1029,8 +1073,6 @@ ORDER BY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Class m_mail */
|
||||||
} /* Class m_mail */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$Id: m_mem.php,v 1.19 2006/01/12 08:04:43 anarcat Exp $
|
$Id: m_mem.php,v 1.19 2006/01/12 08:04:43 anarcat Exp $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
@ -21,6 +22,7 @@
|
||||||
member parameters
|
member parameters
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manage user sessions in the web desktop.
|
* This class manage user sessions in the web desktop.
|
||||||
*
|
*
|
||||||
|
@ -37,20 +39,24 @@ class m_mem {
|
||||||
* Ce tableau est utilisable globalement par toutes les classes filles.
|
* Ce tableau est utilisable globalement par toutes les classes filles.
|
||||||
*/
|
*/
|
||||||
var $user;
|
var $user;
|
||||||
|
|
||||||
/** Tableau contenant les champs de la table "local" du membre courant
|
/** Tableau contenant les champs de la table "local" du membre courant
|
||||||
* Ce tableau est utilisable globalement par toutes les classes filles.
|
* Ce tableau est utilisable globalement par toutes les classes filles.
|
||||||
* Note : les champs de "local" sont spécifiques à l'hébergeur.
|
* Note : les champs de "local" sont specifiques a l'hebergeur.
|
||||||
*/
|
*/
|
||||||
var $local;
|
var $local;
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructeur
|
* Constructeur
|
||||||
*/
|
*/
|
||||||
function m_mem() {
|
function m_mem() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Password kind used in this class (hook for admin class)
|
* Password kind used in this class (hook for admin class)
|
||||||
*/
|
*/
|
||||||
|
@ -70,6 +76,7 @@ class m_mem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Check that the current user is an admnistrator.
|
/** Check that the current user is an admnistrator.
|
||||||
* @return boolean TRUE if we are super user, or FALSE if we are not.
|
* @return boolean TRUE if we are super user, or FALSE if we are not.
|
||||||
*/
|
*/
|
||||||
|
@ -78,6 +85,7 @@ class m_mem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Start a session in the web desktop. Check username and password.
|
/** Start a session in the web desktop. Check username and password.
|
||||||
* <b>Note : </b>If the user entered a bas password, the failure will be logged
|
* <b>Note : </b>If the user entered a bas password, the failure will be logged
|
||||||
* and told to the corresponding user on next successfull login.
|
* and told to the corresponding user on next successfull login.
|
||||||
|
@ -86,7 +94,7 @@ class m_mem {
|
||||||
* @return boolean TRUE if the user has been successfully connected, or FALSE if an error occured.
|
* @return boolean TRUE if the user has been successfully connected, or FALSE if an error occured.
|
||||||
*/
|
*/
|
||||||
function login($username, $password, $restrictip = 0, $authip_token = false) {
|
function login($username, $password, $restrictip = 0, $authip_token = false) {
|
||||||
global $db,$err,$cuid,$authip,$admin;
|
global $db, $err, $cuid, $authip;
|
||||||
$err->log("mem", "login", $username);
|
$err->log("mem", "login", $username);
|
||||||
// $username=addslashes($username);
|
// $username=addslashes($username);
|
||||||
// $password=addslashes($password);
|
// $password=addslashes($password);
|
||||||
|
@ -115,11 +123,15 @@ class m_mem {
|
||||||
|
|
||||||
// AuthIP
|
// AuthIP
|
||||||
$allowed_ip = false;
|
$allowed_ip = false;
|
||||||
if ( $authip_token ) $allowed_ip = $this->authip_tokencheck($authip_token);
|
if ($authip_token) {
|
||||||
|
$allowed_ip = $this->authip_tokencheck($authip_token);
|
||||||
|
}
|
||||||
|
|
||||||
$aga = $authip->get_allowed('panel');
|
$aga = $authip->get_allowed('panel');
|
||||||
foreach ($aga as $k => $v) {
|
foreach ($aga as $k => $v) {
|
||||||
if ( $authip->is_in_subnet(get_remote_ip(), $v['ip'], $v['subnet']) ) $allowed=true ;
|
if ($authip->is_in_subnet(get_remote_ip(), $v['ip'], $v['subnet'])) {
|
||||||
|
$allowed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error if there is rules, the IP is not allowed and it's not in the whitelisted IP
|
// Error if there is rules, the IP is not allowed and it's not in the whitelisted IP
|
||||||
|
@ -131,11 +143,15 @@ class m_mem {
|
||||||
|
|
||||||
if ($restrictip) {
|
if ($restrictip) {
|
||||||
$ip = "'" . get_remote_ip() . "'";
|
$ip = "'" . get_remote_ip() . "'";
|
||||||
} else $ip="''";
|
} else {
|
||||||
|
$ip = "''";
|
||||||
|
}
|
||||||
/* Close sessions that are more than 2 days old. */
|
/* Close sessions that are more than 2 days old. */
|
||||||
$db->query("DELETE FROM sessions WHERE DATE_ADD(ts,INTERVAL 2 DAY)<NOW();");
|
$db->query("DELETE FROM sessions WHERE DATE_ADD(ts,INTERVAL 2 DAY)<NOW();");
|
||||||
/* Delete old impersonation */
|
/* Delete old impersonation */
|
||||||
if ( isset($_COOKIE["oldid"]) ) setcookie('oldid','',0,'/');
|
if (isset($_COOKIE["oldid"])) {
|
||||||
|
setcookie('oldid', '', 0, '/');
|
||||||
|
}
|
||||||
/* Open the session : */
|
/* Open the session : */
|
||||||
$sess = md5(uniqid(mt_rand()));
|
$sess = md5(uniqid(mt_rand()));
|
||||||
$_REQUEST["session"] = $sess;
|
$_REQUEST["session"] = $sess;
|
||||||
|
@ -152,6 +168,7 @@ class m_mem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Start a session as another user from an administrator account.
|
/** Start a session as another user from an administrator account.
|
||||||
* This function is not the same as su. setid connect the current user in the destination
|
* This function is not the same as su. setid connect the current user in the destination
|
||||||
* account (for good), and su allow any user to become another account for some commands only.
|
* account (for good), and su allow any user to become another account for some commands only.
|
||||||
|
@ -191,12 +208,15 @@ class m_mem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Suite à la connexion de l'utilisateur, réinitialise ses paramètres de dernière connexion
|
|
||||||
|
/** Suite <EFBFBD> la connexion de l'utilisateur, r<EFBFBD>initialise ses param<EFBFBD>tres de derni<EFBFBD>re connexion
|
||||||
*/
|
*/
|
||||||
function resetlast() {
|
function resetlast() {
|
||||||
global $db, $cuid;
|
global $db, $cuid;
|
||||||
$ip = addslashes(getenv("REMOTE_HOST"));
|
$ip = addslashes(getenv("REMOTE_HOST"));
|
||||||
if (!$ip) $ip=addslashes(get_remote_ip());
|
if (!$ip) {
|
||||||
|
$ip = addslashes(get_remote_ip());
|
||||||
|
}
|
||||||
$db->query("UPDATE membres SET lastlogin=NOW(), lastfail=0, lastip='$ip' WHERE uid='$cuid';");
|
$db->query("UPDATE membres SET lastlogin=NOW(), lastfail=0, lastip='$ip' WHERE uid='$cuid';");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +225,9 @@ class m_mem {
|
||||||
$db->query("select pass from membres where uid='$cuid';");
|
$db->query("select pass from membres where uid='$cuid';");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$i = intval(time() / 3600);
|
$i = intval(time() / 3600);
|
||||||
if ($bis) ++$i;
|
if ($bis) {
|
||||||
|
++$i;
|
||||||
|
}
|
||||||
return md5("$i--" . $db->f('pass'));
|
return md5("$i--" . $db->f('pass'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,11 +235,10 @@ class m_mem {
|
||||||
* @param boolean $t
|
* @param boolean $t
|
||||||
*/
|
*/
|
||||||
function authip_tokencheck($t) {
|
function authip_tokencheck($t) {
|
||||||
if ($t==$this->authip_token() || $t==$this->authip_token(true) ) return true;
|
return ($t == $this->authip_token() || $t == $this->authip_token(true));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Faut finir de l'implémenter :) * /
|
/* Faut finir de l'implementer :) * /
|
||||||
function authip_class() {
|
function authip_class() {
|
||||||
global $cuid;
|
global $cuid;
|
||||||
$c = Array();
|
$c = Array();
|
||||||
|
@ -230,17 +251,18 @@ class m_mem {
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Vérifie que la session courante est correcte (cookie ok et ip valide).
|
|
||||||
* Si besoin, et si réception des champs username & password, crée une nouvelle
|
/** Verifie que la session courante est correcte (cookie ok et ip valide).
|
||||||
* session pour l'utilisateur annoncé.
|
* Si besoin, et si reception des champs username & password, cree une nouvelle
|
||||||
* Cette fonction doit être appellée à chaque page devant être authentifiée.
|
* session pour l'utilisateur annonce.
|
||||||
* et AVANT d'émettre des données. (un cookie peut être envoyé)
|
* Cette fonction doit etre appellee a chaque page devant etre authentifiee.
|
||||||
|
* et AVANT d'emettre des donnees. (un cookie peut etre envoye)
|
||||||
* @global string $session Le cookie de session eventuel
|
* @global string $session Le cookie de session eventuel
|
||||||
* @global string $username/password le login/pass de l'utilisateur
|
* @global string $username/password le login/pass de l'utilisateur
|
||||||
* @return boolean TRUE si la session est correcte, FALSE sinon.
|
* @return boolean TRUE si la session est correcte, FALSE sinon.
|
||||||
*/
|
*/
|
||||||
function checkid() {
|
function checkid() {
|
||||||
global $db,$err,$cuid,$restrictip,$authip;
|
global $db, $err, $cuid;
|
||||||
if (isset($_REQUEST["username"])) {
|
if (isset($_REQUEST["username"])) {
|
||||||
if (empty($_REQUEST['password'])) {
|
if (empty($_REQUEST['password'])) {
|
||||||
$err->raise("mem", _("Missing password"));
|
$err->raise("mem", _("Missing password"));
|
||||||
|
@ -289,14 +311,16 @@ class m_mem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Change l'identité d'un utilisateur temporairement.
|
|
||||||
* @global string $uid Utilisateur dont on prends l'identité
|
/** Change l'identite d'un utilisateur temporairement.
|
||||||
|
* @global string $uid Utilisateur dont on prends l'identite
|
||||||
* @return TRUE si la session est correcte, FALSE sinon.
|
* @return TRUE si la session est correcte, FALSE sinon.
|
||||||
*/
|
*/
|
||||||
function su($uid) {
|
function su($uid) {
|
||||||
global $cuid, $db, $err, $mysql;
|
global $cuid, $db, $err, $mysql;
|
||||||
if (!$this->olduid)
|
if (!$this->olduid) {
|
||||||
$this->olduid = $cuid;
|
$this->olduid = $cuid;
|
||||||
|
}
|
||||||
$db->query("select * from membres where uid='$uid';");
|
$db->query("select * from membres where uid='$uid';");
|
||||||
if ($db->num_rows() == 0) {
|
if ($db->num_rows() == 0) {
|
||||||
$err->raise("mem", _("User or password incorrect"));
|
$err->raise("mem", _("User or password incorrect"));
|
||||||
|
@ -312,13 +336,15 @@ class m_mem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Retourne a l'identite d'origine de l'utilisateur apres su.
|
/** Retourne a l'identite d'origine de l'utilisateur apres su.
|
||||||
* @return boolean TRUE si la session est correcte, FALSE sinon.
|
* @return boolean TRUE si la session est correcte, FALSE sinon.
|
||||||
*/
|
*/
|
||||||
function unsu() {
|
function unsu() {
|
||||||
global $cuid,$mysql;
|
global $mysql;
|
||||||
if (!$this->olduid)
|
if (!$this->olduid) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
$this->su($this->olduid);
|
$this->su($this->olduid);
|
||||||
$this->olduid = 0;
|
$this->olduid = 0;
|
||||||
// And recreate the $db->dbus
|
// And recreate the $db->dbus
|
||||||
|
@ -326,13 +352,13 @@ class m_mem {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Termine une session du bureau virtuel (logout)
|
/** Termine une session du bureau virtuel (logout)
|
||||||
* @return boolean TRUE si la session a bien été détruite, FALSE sinon.
|
* @return boolean TRUE si la session a bien ete detruite, FALSE sinon.
|
||||||
*/
|
*/
|
||||||
function del_session() {
|
function del_session() {
|
||||||
global $db,$user,$err,$cuid,$classes,$hooks;
|
global $db, $user, $err, $cuid, $hooks;
|
||||||
$_COOKIE["session"] = addslashes(isset($_COOKIE["session"]) ? $_COOKIE["session"] : '');
|
$_COOKIE["session"] = addslashes(isset($_COOKIE["session"]) ? $_COOKIE["session"] : '');
|
||||||
setcookie("session", "", 0, "/");
|
setcookie("session", "", 0, "/");
|
||||||
setcookie("oldid", "", 0, "/");
|
setcookie("oldid", "", 0, "/");
|
||||||
|
@ -375,11 +401,12 @@ class m_mem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Change le mot de passe de l'utilisateur courant.
|
/** Change le mot de passe de l'utilisateur courant.
|
||||||
* @param string $oldpass Ancien mot de passe.
|
* @param string $oldpass Ancien mot de passe.
|
||||||
* @param string $newpass Nouveau mot de passe
|
* @param string $newpass Nouveau mot de passe
|
||||||
* @param string $newpass2 Nouveau mot de passe (à nouveau)
|
* @param string $newpass2 Nouveau mot de passe (a nouveau)
|
||||||
* @return boolean TRUE si le mot de passe a été changé, FALSE sinon.
|
* @return boolean TRUE si le mot de passe a ete change, FALSE sinon.
|
||||||
*/
|
*/
|
||||||
function passwd($oldpass, $newpass, $newpass2) {
|
function passwd($oldpass, $newpass, $newpass2) {
|
||||||
global $db, $err, $cuid, $admin;
|
global $db, $err, $cuid, $admin;
|
||||||
|
@ -412,9 +439,10 @@ class m_mem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Change les préférences administrateur d'un compte
|
|
||||||
|
/** Change les preferences administrateur d'un compte
|
||||||
* @param integer $admlist Mode de visualisation des membres (0=large 1=courte)
|
* @param integer $admlist Mode de visualisation des membres (0=large 1=courte)
|
||||||
* @return boolean TRUE si les préférences ont été changées, FALSE sinon.
|
* @return boolean TRUE si les preferences ont ete changees, FALSE sinon.
|
||||||
*/
|
*/
|
||||||
function adminpref($admlist) {
|
function adminpref($admlist) {
|
||||||
global $db, $err, $cuid;
|
global $db, $err, $cuid;
|
||||||
|
@ -429,11 +457,12 @@ class m_mem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Envoie en mail le mot de passe d'un compte.
|
/** Envoie en mail le mot de passe d'un compte.
|
||||||
* <b>Note : </b>On ne peut demander le mot de passe qu'une seule fois par jour.
|
* <b>Note : </b>On ne peut demander le mot de passe qu'une seule fois par jour.
|
||||||
* TODO : Translate this mail into the localization program.
|
* TODO : Translate this mail into the localization program.
|
||||||
* TODO : Check this function's !
|
* TODO : Check this function's !
|
||||||
* @return boolean TRUE si le mot de passe a été envoyé avec succès, FALSE sinon.
|
* @return boolean TRUE si le mot de passe a ete envoye avec succes, FALSE sinon.
|
||||||
*/
|
*/
|
||||||
function send_pass($login) {
|
function send_pass($login) {
|
||||||
global $err, $db, $L_HOSTING, $L_FQDN;
|
global $err, $db, $L_HOSTING, $L_FQDN;
|
||||||
|
@ -473,10 +502,11 @@ Cordially.
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Change le mail d'un membre (première etape, envoi du CookiE)
|
|
||||||
|
/** Change le mail d'un membre (premiere etape, envoi du CookiE)
|
||||||
* TODO : insert this mail string into the localization system
|
* TODO : insert this mail string into the localization system
|
||||||
* @param string $newmail Nouveau mail souhaité pour le membre.
|
* @param string $newmail Nouveau mail souhaite pour le membre.
|
||||||
* @return string le cookie si le mail a bien été envoyé, FALSE sinon
|
* @return string le cookie si le mail a bien ete envoye, FALSE sinon
|
||||||
*/
|
*/
|
||||||
function ChangeMail1($newmail) {
|
function ChangeMail1($newmail) {
|
||||||
global $err, $db, $L_HOSTING, $L_FQDN, $cuid;
|
global $err, $db, $L_HOSTING, $L_FQDN, $cuid;
|
||||||
|
@ -488,9 +518,9 @@ Cordially.
|
||||||
}
|
}
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
|
|
||||||
// un cookie de 20 caractères pour le mail
|
// un cookie de 20 caract<63>res pour le mail
|
||||||
$COOKIE = substr(md5(uniqid(rand(), true)), 0, 20);
|
$COOKIE = substr(md5(uniqid(rand(), true)), 0, 20);
|
||||||
// et de 6 pour la clé à entrer. ca me semble suffisant...
|
// et de 6 pour la cl<63> <20> entrer. ca me semble suffisant...
|
||||||
$KEY = substr(md5(uniqid(rand(), true)), 0, 6);
|
$KEY = substr(md5(uniqid(rand(), true)), 0, 6);
|
||||||
$link = "https://$L_FQDN/mem_cm.php?usr=$cuid&cookie=$COOKIE";
|
$link = "https://$L_FQDN/mem_cm.php?usr=$cuid&cookie=$COOKIE";
|
||||||
$txt = sprintf(_("Hello,
|
$txt = sprintf(_("Hello,
|
||||||
|
@ -513,7 +543,7 @@ again, please contact your server's administrator.
|
||||||
Cordially.
|
Cordially.
|
||||||
"), $db->f("login"), $L_HOSTING, $link);
|
"), $db->f("login"), $L_HOSTING, $link);
|
||||||
mail($newmail, "Email modification request on $L_HOSTING", $txt, "From: postmaster@$L_FQDN\nReply-to: postmaster@$L_FQDN");
|
mail($newmail, "Email modification request on $L_HOSTING", $txt, "From: postmaster@$L_FQDN\nReply-to: postmaster@$L_FQDN");
|
||||||
// Supprime les demandes précédentes de ce compte !
|
// Supprime les demandes pr<70>c<EFBFBD>dentes de ce compte !
|
||||||
$db->query("DELETE FROM chgmail WHERE uid='$cuid';");
|
$db->query("DELETE FROM chgmail WHERE uid='$cuid';");
|
||||||
$db->query("INSERT INTO chgmail (cookie,ckey,uid,mail,ts) VALUES ('$COOKIE','$KEY','$cuid','$newmail'," . time() . ");");
|
$db->query("INSERT INTO chgmail (cookie,ckey,uid,mail,ts) VALUES ('$COOKIE','$KEY','$cuid','$newmail'," . time() . ");");
|
||||||
// Supprime les cookies de la veille :)
|
// Supprime les cookies de la veille :)
|
||||||
|
@ -523,14 +553,15 @@ Cordially.
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Change le mail d'un membre (seconde etape, CookiE+clé = application)
|
|
||||||
* @param string $COOKIE Cookie envoyé par mail
|
/** Change le mail d'un membre (seconde etape, CookiE+cle = application)
|
||||||
* @param string $KEY clé affichée à l'écran
|
* @param string $COOKIE Cookie envoye par mail
|
||||||
* @param integer $uid Utilisateur concerné (on est hors session)
|
* @param string $KEY cle affichee a l'ecran
|
||||||
* @return boolean TRUE si le mail a bien été modifié, FALSE sinon
|
* @param integer $uid Utilisateur concerne (on est hors session)
|
||||||
|
* @return boolean TRUE si le mail a bien ete modifie, FALSE sinon
|
||||||
*/
|
*/
|
||||||
function ChangeMail2($COOKIE, $KEY, $uid) {
|
function ChangeMail2($COOKIE, $KEY, $uid) {
|
||||||
global $err,$db,$L_HOSTING,$L_FQDN;
|
global $err, $db;
|
||||||
$err->log("mem", "changemail2", $uid);
|
$err->log("mem", "changemail2", $uid);
|
||||||
$db->query("SELECT * FROM chgmail WHERE cookie='$COOKIE' and ckey='$KEY' and uid='$uid';");
|
$db->query("SELECT * FROM chgmail WHERE cookie='$COOKIE' and ckey='$KEY' and uid='$uid';");
|
||||||
if (!$db->num_rows()) {
|
if (!$db->num_rows()) {
|
||||||
|
@ -539,7 +570,7 @@ Cordially.
|
||||||
}
|
}
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
|
|
||||||
// met à jour le compte :
|
// met a jour le compte :
|
||||||
$db->query("UPDATE membres SET mail='" . $db->f("mail") . "' WHERE uid='$uid';");
|
$db->query("UPDATE membres SET mail='" . $db->f("mail") . "' WHERE uid='$uid';");
|
||||||
|
|
||||||
$db->query("DELETE FROM chgmail WHERE uid='$uid';");
|
$db->query("DELETE FROM chgmail WHERE uid='$uid';");
|
||||||
|
@ -550,7 +581,8 @@ Cordially.
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Modifie le paramètre d'aide en ligne (1/0)
|
|
||||||
|
/** Modifie le parametre d'aide en ligne (1/0)
|
||||||
* @param integer $show Faut-il (1) ou non (0) afficher l'aide en ligne
|
* @param integer $show Faut-il (1) ou non (0) afficher l'aide en ligne
|
||||||
*/
|
*/
|
||||||
function set_help_param($show) {
|
function set_help_param($show) {
|
||||||
|
@ -560,26 +592,26 @@ Cordially.
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Dit si l'aide en ligne est demandée
|
|
||||||
* @return boolean TRUE si l'aide en ligne est demandée, FALSE sinon.
|
/** Dit si l'aide en ligne est demandee
|
||||||
|
* @return boolean TRUE si l'aide en ligne est demandee, FALSE sinon.
|
||||||
*/
|
*/
|
||||||
function get_help_param() {
|
function get_help_param() {
|
||||||
return $this->user["show_help"];
|
return $this->user["show_help"];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Affiche (echo) l'aide contextuelle
|
/** Affiche (echo) l'aide contextuelle
|
||||||
* @param integer $file Numéro de fichier d'aide à afficher.
|
* @param integer $file Numero de fichier d'aide a afficher.
|
||||||
* @return boolean TRUE si l'aide contextuelle a été trouvée, FALSE sinon
|
* @return boolean TRUE si l'aide contextuelle a ete trouvee, FALSE sinon
|
||||||
*/
|
*/
|
||||||
function show_help($file, $force = false) {
|
function show_help($file, $force = false) {
|
||||||
global $err;
|
|
||||||
if ($this->user["show_help"] || $force) {
|
if ($this->user["show_help"] || $force) {
|
||||||
$hlp = _("hlp_$file");
|
$hlp = _("hlp_$file");
|
||||||
if ($hlp != "hlp_$file") {
|
if ($hlp != "hlp_$file") {
|
||||||
$hlp = preg_replace(
|
$hlp = preg_replace(
|
||||||
"#HELPID_([0-9]*)#",
|
"#HELPID_([0-9]*)#", "<a href=\"javascript:help(\\1);\"><img src=\"/aide/help.png\" width=\"17\" height=\"17\" style=\"vertical-align: middle;\" alt=\"" . _("Help") . "\" /></a>", $hlp);
|
||||||
"<a href=\"javascript:help(\\1);\"><img src=\"/aide/help.png\" width=\"17\" height=\"17\" style=\"vertical-align: middle;\" alt=\""._("Help")."\" /></a>",$hlp);
|
|
||||||
echo "<p class=\"hlp\">" . $hlp . "</p>";
|
echo "<p class=\"hlp\">" . $hlp . "</p>";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -597,14 +629,16 @@ Cordially.
|
||||||
$err->log("dom", "get_creator_by_uid");
|
$err->log("dom", "get_creator_by_uid");
|
||||||
$uid = mysql_real_escape_string(intval($uid));
|
$uid = mysql_real_escape_string(intval($uid));
|
||||||
$db->query("select creator from membres where uid = '$uid';");
|
$db->query("select creator from membres where uid = '$uid';");
|
||||||
if (! $db->next_record()) return false;
|
if (!$db->next_record()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return intval($db->f('creator'));
|
return intval($db->f('creator'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exports all the personnal user related information for an account.
|
* Exports all the personal user related information for an account.
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function alternc_export_conf() {
|
function alternc_export_conf() {
|
||||||
|
@ -628,7 +662,9 @@ Cordially.
|
||||||
|
|
||||||
function session_tempo_params_get($v) {
|
function session_tempo_params_get($v) {
|
||||||
global $uid;
|
global $uid;
|
||||||
if (empty($_COOKIE['session'])) return false;
|
if (empty($_COOKIE['session'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$sid = $_COOKIE['session'];
|
$sid = $_COOKIE['session'];
|
||||||
if (empty($_SESSION[$sid . '-' . $uid])) { // si pas de session de params tempo
|
if (empty($_SESSION[$sid . '-' . $uid])) { // si pas de session de params tempo
|
||||||
return false;
|
return false;
|
||||||
|
@ -643,7 +679,9 @@ Cordially.
|
||||||
|
|
||||||
function session_tempo_params_set($k, $v, $ecrase = false) {
|
function session_tempo_params_set($k, $v, $ecrase = false) {
|
||||||
global $uid;
|
global $uid;
|
||||||
if (empty($_COOKIE['session'])) return false;
|
if (empty($_COOKIE['session'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$sid = $_COOKIE['session'];
|
$sid = $_COOKIE['session'];
|
||||||
$p = Array();
|
$p = Array();
|
||||||
if (!empty($_SESSION[$sid . '-' . $uid])) {
|
if (!empty($_SESSION[$sid . '-' . $uid])) {
|
||||||
|
@ -658,6 +696,6 @@ Cordially.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* Classe Membre */
|
}
|
||||||
|
|
||||||
?>
|
/* Classe Membre */
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -29,12 +30,13 @@
|
||||||
* @copyright AlternC-Team 2002-2005 http://alternc.org/
|
* @copyright AlternC-Team 2002-2005 http://alternc.org/
|
||||||
*/
|
*/
|
||||||
class m_menu {
|
class m_menu {
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Constructor
|
/** Constructor
|
||||||
* menu([$mid]) Constructeur de la classe menu, ne fait rien pour le moment
|
* menu([$mid]) Constructeur de la classe menu, ne fait rien pour le moment
|
||||||
*/
|
*/
|
||||||
function m_menu() {
|
function m_menu() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getmenu() {
|
function getmenu() {
|
||||||
|
@ -42,7 +44,6 @@ class m_menu {
|
||||||
|
|
||||||
// Force rebuilding quota, in case of add or edit of the quota and cache not up-to-date
|
// Force rebuilding quota, in case of add or edit of the quota and cache not up-to-date
|
||||||
$mesq = $quota->getquota("", true); // rebuild quota
|
$mesq = $quota->getquota("", true); // rebuild quota
|
||||||
|
|
||||||
// Get menu objects
|
// Get menu objects
|
||||||
$lsto = $hooks->invoke('hook_menu');
|
$lsto = $hooks->invoke('hook_menu');
|
||||||
|
|
||||||
|
@ -71,12 +72,18 @@ class m_menu {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Be sure that the default visibility is true
|
// Be sure that the default visibility is true
|
||||||
if (! isset($lst[$k]['visibility'])) $lst[$k]['visibility'] = true;
|
if (!isset($lst[$k]['visibility'])) {
|
||||||
|
$lst[$k]['visibility'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the user's specific visibility option
|
// Set the user's specific visibility option
|
||||||
if (isset($mop["menu-$k"])) {
|
if (isset($mop["menu-$k"])) {
|
||||||
if ($mop["menu-$k"] == "hidden") $lst[$k]['visibility'] = false;
|
if ($mop["menu-$k"] == "hidden") {
|
||||||
if ($mop["menu-$k"] == "visible") $lst[$k]['visibility'] = true;
|
$lst[$k]['visibility'] = false;
|
||||||
|
}
|
||||||
|
if ($mop["menu-$k"] == "visible") {
|
||||||
|
$lst[$k]['visibility'] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($mesq[$k])) { // if there are some quota for this class
|
if (isset($mesq[$k])) { // if there are some quota for this class
|
||||||
|
@ -89,13 +96,11 @@ class m_menu {
|
||||||
// Set the quota in the menu object
|
// Set the quota in the menu object
|
||||||
$lst[$k]['quota_used'] = $mesq[$k]['u'];
|
$lst[$k]['quota_used'] = $mesq[$k]['u'];
|
||||||
$lst[$k]['quota_total'] = $mesq[$k]['t'];
|
$lst[$k]['quota_total'] = $mesq[$k]['t'];
|
||||||
|
|
||||||
} // end if there are some quota for this class
|
} // end if there are some quota for this class
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $lst;
|
return $lst;
|
||||||
} //getmenu
|
}
|
||||||
|
|
||||||
function order_menu($a, $b) {
|
function order_menu($a, $b) {
|
||||||
// Use to order the menu with a usort
|
// Use to order the menu with a usort
|
||||||
|
@ -106,8 +111,7 @@ class m_menu {
|
||||||
// Here some needed menu who don't have a class
|
// Here some needed menu who don't have a class
|
||||||
global $help_baseurl, $lang_translation, $locales;
|
global $help_baseurl, $lang_translation, $locales;
|
||||||
|
|
||||||
$m =
|
$m = array(
|
||||||
array(
|
|
||||||
'home' =>
|
'home' =>
|
||||||
array(
|
array(
|
||||||
'title' => _("Home / Information"),
|
'title' => _("Home / Information"),
|
||||||
|
@ -144,32 +148,8 @@ class m_menu {
|
||||||
$m['lang']['links'][] = array('txt' => (isset($lang_translation[$l])) ? $lang_translation[$l] : $l, 'url' => "/login.php?setlang=$l");
|
$m['lang']['links'][] = array('txt' => (isset($lang_translation[$l])) ? $lang_translation[$l] : $l, 'url' => "/login.php?setlang=$l");
|
||||||
}
|
}
|
||||||
return $m;
|
return $m;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/* Class menu */
|
||||||
|
|
||||||
<div class="menu-box">
|
|
||||||
<a href="javascript:menu_toggle('menu-lang');">
|
|
||||||
<div class="menu-title">
|
|
||||||
<img src="/images/lang.png" alt="<?php __("Languages"); ?>" /> <?php __("Languages"); ?>
|
|
||||||
<img src="/images/menu_moins.png" alt="" style="float:right;" id="menu-lang-img"/>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<div class="menu-content" id="menu-lang">
|
|
||||||
<ul>
|
|
||||||
<?php foreach($locales as $l) { ?>
|
|
||||||
<li><a href="/login.php?setlang=<?php echo $l; ?>" target="_top"><?php if (isset($lang_translation[$l])) echo $lang_translation[$l]; else echo $l; ?></a></li>
|
|
||||||
<?php } ?>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
} //system_menu
|
|
||||||
|
|
||||||
} /* Class menu */
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$Id: m_mysql.php,v 1.35 2005/12/18 09:51:32 benjamin Exp $
|
$Id: m_mysql.php,v 1.35 2005/12/18 09:51:32 benjamin Exp $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
@ -27,14 +28,15 @@
|
||||||
Purpose of file: Manage mysql database for users.
|
Purpose of file: Manage mysql database for users.
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MySQL user database management for AlternC.
|
* MySQL user database management for AlternC.
|
||||||
* This class manage user's databases in MySQL, and user's MySQL accounts.
|
* This class manage user's databases in MySQL, and user's MySQL accounts.
|
||||||
*
|
*
|
||||||
* @copyright AlternC-Team 2002-2005 http://alternc.org/
|
* @copyright AlternC-Team 2002-2005 http://alternc.org/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DB_users extends DB_Sql {
|
class DB_users extends DB_Sql {
|
||||||
|
|
||||||
var $Host, $HumanHostname, $User, $Password, $Client;
|
var $Host, $HumanHostname, $User, $Password, $Client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,11 +74,12 @@ class DB_users extends DB_Sql {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class m_mysql {
|
class m_mysql {
|
||||||
|
|
||||||
var $dbus;
|
var $dbus;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Constructor
|
/** Constructor
|
||||||
* m_mysql([$mid]) Constructeur de la classe m_mysql, initialise le membre concerne
|
* m_mysql([$mid]) Constructeur de la classe m_mysql, initialise le membre concerne
|
||||||
*/
|
*/
|
||||||
|
@ -114,19 +117,16 @@ class m_mysql {
|
||||||
'links' => array(),
|
'links' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$obj['links'][] =
|
$obj['links'][] = array(
|
||||||
array (
|
|
||||||
'txt' => _("Databases"),
|
'txt' => _("Databases"),
|
||||||
'url' => "sql_list.php",
|
'url' => "sql_list.php",
|
||||||
);
|
);
|
||||||
$obj['links'][] =
|
$obj['links'][] = array(
|
||||||
array (
|
|
||||||
'txt' => _("MySQL Users"),
|
'txt' => _("MySQL Users"),
|
||||||
'url' => "sql_users_list.php",
|
'url' => "sql_users_list.php",
|
||||||
);
|
);
|
||||||
if ($q["u"] > 0) {
|
if ($q["u"] > 0) {
|
||||||
$obj['links'][] =
|
$obj['links'][] = array(
|
||||||
array (
|
|
||||||
'txt' => _("PhpMyAdmin"),
|
'txt' => _("PhpMyAdmin"),
|
||||||
'url' => "sql_pma_sso.php",
|
'url' => "sql_pma_sso.php",
|
||||||
'target' => '_blank',
|
'target' => '_blank',
|
||||||
|
@ -135,9 +135,8 @@ class m_mysql {
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Password kind used in this class (hook for admin class)
|
* Password kind used in this class (hook for admin class)
|
||||||
*/
|
*/
|
||||||
|
@ -146,6 +145,7 @@ class m_mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Get the list of the database for the current user.
|
/** Get the list of the database for the current user.
|
||||||
* @return array returns an associative array as follow : <br>
|
* @return array returns an associative array as follow : <br>
|
||||||
* "db" => database name "bck" => backup mode for this db
|
* "db" => database name "bck" => backup mode for this db
|
||||||
|
@ -166,6 +166,7 @@ class m_mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Get the login and password of the special user able to connect to phpmyadmin
|
/** Get the login and password of the special user able to connect to phpmyadmin
|
||||||
* @return array returns an associative array with login and password
|
* @return array returns an associative array with login and password
|
||||||
* Returns FALSE if error
|
* Returns FALSE if error
|
||||||
|
@ -187,8 +188,8 @@ class m_mysql {
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Returns the details of a user's database.
|
/** Returns the details of a user's database.
|
||||||
* $dbn is the name of the database (after the _) or nothing for the database "$user"
|
* $dbn is the name of the database (after the _) or nothing for the database "$user"
|
||||||
* @return string returns an associative array as follow :
|
* @return string returns an associative array as follow :
|
||||||
|
@ -202,7 +203,7 @@ class m_mysql {
|
||||||
* Returns FALSE if the user has no database of if the database does not exist.
|
* Returns FALSE if the user has no database of if the database does not exist.
|
||||||
*/
|
*/
|
||||||
function get_mysql_details($dbn) {
|
function get_mysql_details($dbn) {
|
||||||
global $db,$err,$bro,$mem,$cuid;
|
global $db, $err, $cuid;
|
||||||
$root = getuserpath();
|
$root = getuserpath();
|
||||||
$err->log("mysql", "get_mysql_details");
|
$err->log("mysql", "get_mysql_details");
|
||||||
$pos = strpos($dbn, '_');
|
$pos = strpos($dbn, '_');
|
||||||
|
@ -224,21 +225,15 @@ class m_mysql {
|
||||||
return array("enabled" => true, "login" => $db->f("login"), "db" => $db->f("db"), "name" => $dbn, "bck" => $db->f("bck_mode"), "dir" => substr($db->f("bck_dir"), strlen($root)), "size" => $size, "pass" => $db->f("pass"), "history" => $db->f("bck_history"), "gzip" => $db->f("bck_gzip"));
|
return array("enabled" => true, "login" => $db->f("login"), "db" => $db->f("db"), "name" => $dbn, "bck" => $db->f("bck_mode"), "dir" => substr($db->f("bck_dir"), strlen($root)), "size" => $size, "pass" => $db->f("pass"), "history" => $db->f("bck_history"), "gzip" => $db->f("bck_gzip"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_get_param($dbname){
|
|
||||||
global $db,$err,$cuid;
|
|
||||||
$db->query("SELECT ");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Create a new database for the current user.
|
/** Create a new database for the current user.
|
||||||
* @param $dbn string Database name ($user_$dbn is the mysql db name)
|
* @param $dbn string Database name ($user_$dbn is the mysql db name)
|
||||||
* @return boolean if the database $user_$db has been successfully created, or FALSE if
|
* @return boolean if the database $user_$db has been successfully created, or FALSE if
|
||||||
* an error occured, such as over quota user.
|
* an error occured, such as over quota user.
|
||||||
*/
|
*/
|
||||||
function add_db($dbn) {
|
function add_db($dbn) {
|
||||||
global $db,$err,$quota,$mem,$cuid,$admin;
|
global $db, $err, $quota, $cuid;
|
||||||
$err->log("mysql", "add_db", $dbn);
|
$err->log("mysql", "add_db", $dbn);
|
||||||
$password_user = "";
|
$password_user = "";
|
||||||
if (!$quota->cancreate("mysql")) {
|
if (!$quota->cancreate("mysql")) {
|
||||||
|
@ -262,7 +257,6 @@ class m_mysql {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (strlen($dbname) > 64) {
|
if (strlen($dbname) > 64) {
|
||||||
$err->raise("mysql", _("Database name cannot exceed 64 characters"));
|
$err->raise("mysql", _("Database name cannot exceed 64 characters"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -277,6 +271,7 @@ class m_mysql {
|
||||||
if (!$db->num_rows()) {
|
if (!$db->num_rows()) {
|
||||||
$password_user = create_pass(8);
|
$password_user = create_pass(8);
|
||||||
if (!$this->add_user($dbn, $password_user, $password_user)) {
|
if (!$this->add_user($dbn, $password_user, $password_user)) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,15 +306,15 @@ class m_mysql {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Delete a database for the current user.
|
/** Delete a database for the current user.
|
||||||
* @param $dbn string Name of the database to delete. The db name is $user_$dbn
|
* @param $dbn string Name of the database to delete. The db name is $user_$dbn
|
||||||
* @return boolean if the database $user_$db has been successfully deleted, or FALSE if
|
* @return boolean if the database $user_$db has been successfully deleted, or FALSE if
|
||||||
* an error occured, such as db does not exist.
|
* an error occured, such as db does not exist.
|
||||||
*/
|
*/
|
||||||
function del_db($dbn) {
|
function del_db($dbn) {
|
||||||
global $db,$err,$mem,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("mysql", "del_db", $dbn);
|
$err->log("mysql", "del_db", $dbn);
|
||||||
$dbname = addslashes($dbn);
|
$dbname = addslashes($dbn);
|
||||||
$db->query("SELECT uid FROM db WHERE db='$dbname';");
|
$db->query("SELECT uid FROM db WHERE db='$dbname';");
|
||||||
|
@ -346,12 +341,10 @@ class m_mysql {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Set the backup parameters for the database $db
|
/** Set the backup parameters for the database $db
|
||||||
* @param $db string database name
|
* @param $dbn string database name
|
||||||
* @param $bck_mode integer Backup mode (0 = none 1 = daily 2 = weekly)
|
* @param $bck_mode integer Backup mode (0 = none 1 = daily 2 = weekly)
|
||||||
* @param $bck_history integer How many backup should we keep ?
|
* @param $bck_history integer How many backup should we keep ?
|
||||||
* @param $bck_gzip boolean shall we compress the backup ?
|
* @param $bck_gzip boolean shall we compress the backup ?
|
||||||
|
@ -359,7 +352,7 @@ class m_mysql {
|
||||||
* @return boolean true if the backup parameters has been successfully changed, false if not.
|
* @return boolean true if the backup parameters has been successfully changed, false if not.
|
||||||
*/
|
*/
|
||||||
function put_mysql_backup($dbn, $bck_mode, $bck_history, $bck_gzip, $bck_dir) {
|
function put_mysql_backup($dbn, $bck_mode, $bck_history, $bck_gzip, $bck_dir) {
|
||||||
global $db,$err,$mem,$bro,$cuid;
|
global $db, $err, $bro, $cuid;
|
||||||
$err->log("mysql", "put_mysql_backup");
|
$err->log("mysql", "put_mysql_backup");
|
||||||
|
|
||||||
if (!variable_get('sql_allow_users_backups')) {
|
if (!variable_get('sql_allow_users_backups')) {
|
||||||
|
@ -387,12 +380,14 @@ class m_mysql {
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$bck_mode = intval($bck_mode);
|
$bck_mode = intval($bck_mode);
|
||||||
$bck_history = intval($bck_history);
|
$bck_history = intval($bck_history);
|
||||||
if ($bck_gzip)
|
if ($bck_gzip) {
|
||||||
$bck_gzip = "1";
|
$bck_gzip = "1";
|
||||||
else
|
} else {
|
||||||
$bck_gzip = "0";
|
$bck_gzip = "0";
|
||||||
if (!$bck_mode)
|
}
|
||||||
|
if (!$bck_mode) {
|
||||||
$bck_mode = "0";
|
$bck_mode = "0";
|
||||||
|
}
|
||||||
if (!$bck_history) {
|
if (!$bck_history) {
|
||||||
$err->raise("mysql", _("You have to choose how many backups you want to keep"));
|
$err->raise("mysql", _("You have to choose how many backups you want to keep"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -405,14 +400,14 @@ class m_mysql {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Change the password of the user in MySQL
|
/** Change the password of the user in MySQL
|
||||||
* @param $password string new password (cleartext)
|
* @param $password string new password (cleartext)
|
||||||
* @return boolean TRUE if the password has been successfully changed, FALSE else.
|
* @return boolean TRUE if the password has been successfully changed, FALSE else.
|
||||||
*/
|
*/
|
||||||
function put_mysql_details($password) {
|
function put_mysql_details($password) {
|
||||||
global $db,$err,$mem,$cuid,$admin;
|
global $db, $err, $cuid, $admin;
|
||||||
$err->log("mysql", "put_mysql_details");
|
$err->log("mysql", "put_mysql_details");
|
||||||
$db->query("SELECT * FROM db WHERE uid='$cuid';");
|
$db->query("SELECT * FROM db WHERE uid='$cuid';");
|
||||||
if (!$db->num_rows()) {
|
if (!$db->num_rows()) {
|
||||||
|
@ -484,8 +479,9 @@ class m_mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Protect database name if not wildcard
|
# Protect database name if not wildcard
|
||||||
if ($base != '*' ) $base = "`".$base."`" ;
|
if ($base != '*') {
|
||||||
|
$base = "`" . $base . "`";
|
||||||
|
}
|
||||||
$grant = "grant " . $rights . " on " . $base . "." . $table . " to '" . $user . "'@'" . $this->dbus->Client . "'";
|
$grant = "grant " . $rights . " on " . $base . "." . $table . " to '" . $user . "'@'" . $this->dbus->Client . "'";
|
||||||
|
|
||||||
if ($pass) {
|
if ($pass) {
|
||||||
|
@ -498,11 +494,10 @@ class m_mysql {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Restore a sql database.
|
/** Restore a sql database.
|
||||||
* @param $file string The filename, relative to the user root dir, which contains a sql dump
|
* @param $file string The filename, relative to the user root dir, which contains a sql dump
|
||||||
* @param $stdout boolean shall-we dump the error to stdout ?
|
* @param $stdout boolean shall-we dump the error to stdout ?
|
||||||
|
@ -510,7 +505,7 @@ class m_mysql {
|
||||||
* @return boolean TRUE if the database has been restored, or FALSE if an error occurred
|
* @return boolean TRUE if the database has been restored, or FALSE if an error occurred
|
||||||
*/
|
*/
|
||||||
function restore($file, $stdout, $id) {
|
function restore($file, $stdout, $id) {
|
||||||
global $err,$bro,$mem,$L_MYSQL_HOST,$db;
|
global $err, $bro;
|
||||||
if (empty($file)) {
|
if (empty($file)) {
|
||||||
$err->raise("mysql", _("No file specified"));
|
$err->raise("mysql", _("No file specified"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -537,6 +532,7 @@ class m_mysql {
|
||||||
$exe .= " 2>&1";
|
$exe .= " 2>&1";
|
||||||
|
|
||||||
echo "<code><pre>";
|
echo "<code><pre>";
|
||||||
|
$ret = 0;
|
||||||
if ($stdout) {
|
if ($stdout) {
|
||||||
passthru($exe, $ret);
|
passthru($exe, $ret);
|
||||||
} else {
|
} else {
|
||||||
|
@ -550,32 +546,34 @@ class m_mysql {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Get the size of a database
|
/** Get the size of a database
|
||||||
* @param $dbname name of the database
|
* @param $dbname name of the database
|
||||||
* @return integer database size
|
* @return integer database size
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function get_db_size($dbname) {
|
function get_db_size($dbname) {
|
||||||
global $db,$err;
|
global $db;
|
||||||
|
|
||||||
$this->dbus->query("SHOW TABLE STATUS FROM `$dbname`;");
|
$this->dbus->query("SHOW TABLE STATUS FROM `$dbname`;");
|
||||||
$size = 0;
|
$size = 0;
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$size += $db->f('Data_length') + $db->f('Index_length');
|
$size += $db->f('Data_length') + $db->f('Index_length');
|
||||||
if ( $db->f('Engine') != 'InnoDB') $size += $db->f('Data_free');
|
if ($db->f('Engine') != 'InnoDB') {
|
||||||
|
$size += $db->f('Data_free');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $size;
|
return $size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of database users of an account
|
* Returns the list of database users of an account
|
||||||
* */
|
* */
|
||||||
function get_userslist($all = null) {
|
function get_userslist($all = null) {
|
||||||
global $db,$err,$bro,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("mysql", "get_userslist");
|
$err->log("mysql", "get_userslist");
|
||||||
$c = array();
|
$c = array();
|
||||||
if (!$all) {
|
if (!$all) {
|
||||||
|
@ -597,7 +595,7 @@ class m_mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_defaultsparam($dbn) {
|
function get_defaultsparam($dbn) {
|
||||||
global $db,$err,$bro,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("mysql", "getdefaults");
|
$err->log("mysql", "getdefaults");
|
||||||
|
|
||||||
$dbu = $dbn;
|
$dbu = $dbn;
|
||||||
|
@ -680,11 +678,10 @@ class m_mysql {
|
||||||
$r['user'] = $db->f('name');
|
$r['user'] = $db->f('name');
|
||||||
$r['password'] = $db->f('password');
|
$r['password'] = $db->f('password');
|
||||||
return $r;
|
return $r;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new user in MySQL rights tables
|
* Create a new user in MySQL rights tables
|
||||||
* @param $usern the username (we will add _[alternc-account] to it)
|
* @param $usern the username (we will add _[alternc-account] to it)
|
||||||
|
@ -693,7 +690,7 @@ class m_mysql {
|
||||||
* @return boolean if the user has been created in MySQL or FALSE if an error occurred
|
* @return boolean if the user has been created in MySQL or FALSE if an error occurred
|
||||||
* */
|
* */
|
||||||
function add_user($usern, $password, $passconf) {
|
function add_user($usern, $password, $passconf) {
|
||||||
global $db,$err,$quota,$mem,$cuid,$admin;
|
global $db, $err, $mem, $cuid, $admin;
|
||||||
$err->log("mysql", "add_user", $usern);
|
$err->log("mysql", "add_user", $usern);
|
||||||
|
|
||||||
$usern = trim($usern);
|
$usern = trim($usern);
|
||||||
|
@ -718,7 +715,6 @@ class m_mysql {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// We check the length of the COMPLETE username, not only the part after _
|
// We check the length of the COMPLETE username, not only the part after _
|
||||||
if (strlen($user) > 16) {
|
if (strlen($user) > 16) {
|
||||||
$err->raise("mysql", _("MySQL username cannot exceed 16 characters"));
|
$err->raise("mysql", _("MySQL username cannot exceed 16 characters"));
|
||||||
|
@ -749,6 +745,7 @@ class m_mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change a user's MySQL password
|
* Change a user's MySQL password
|
||||||
* @param $usern the username
|
* @param $usern the username
|
||||||
|
@ -757,7 +754,7 @@ class m_mysql {
|
||||||
* @return boolean if the password has been changed in MySQL or FALSE if an error occurred
|
* @return boolean if the password has been changed in MySQL or FALSE if an error occurred
|
||||||
* */
|
* */
|
||||||
function change_user_password($usern, $password, $passconf) {
|
function change_user_password($usern, $password, $passconf) {
|
||||||
global $db,$err,$quota,$mem,$cuid,$admin;
|
global $db, $err, $cuid, $admin;
|
||||||
$err->log("mysql", "change_user_pass", $usern);
|
$err->log("mysql", "change_user_pass", $usern);
|
||||||
|
|
||||||
$usern = trim($usern);
|
$usern = trim($usern);
|
||||||
|
@ -779,9 +776,8 @@ class m_mysql {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a user in MySQL rights tables
|
* Delete a user in MySQL rights tables
|
||||||
* @param $user the username (we will add "[alternc-account]_" to it) to delete
|
* @param $user the username (we will add "[alternc-account]_" to it) to delete
|
||||||
|
@ -789,7 +785,7 @@ class m_mysql {
|
||||||
* @return boolean if the user has been deleted in MySQL or FALSE if an error occurred
|
* @return boolean if the user has been deleted in MySQL or FALSE if an error occurred
|
||||||
* */
|
* */
|
||||||
function del_user($user, $all = null) {
|
function del_user($user, $all = null) {
|
||||||
global $db,$err,$mem,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("mysql", "del_user", $user);
|
$err->log("mysql", "del_user", $user);
|
||||||
if (!preg_match("#^[0-9a-z]#", $user)) {
|
if (!preg_match("#^[0-9a-z]#", $user)) {
|
||||||
$err->raise("mysql", _("The username can contain only letters and numbers"));
|
$err->raise("mysql", _("The username can contain only letters and numbers"));
|
||||||
|
@ -818,16 +814,15 @@ class m_mysql {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the list of the database rights of user $user
|
* Return the list of the database rights of user $user
|
||||||
* @param $user the username
|
* @param $user the username
|
||||||
* @return array An array of database name and rights
|
* @return array An array of database name and rights
|
||||||
* */
|
* */
|
||||||
|
|
||||||
function get_user_dblist($user) {
|
function get_user_dblist($user) {
|
||||||
global $db,$err,$mem,$cuid;
|
global $db, $err;
|
||||||
|
|
||||||
$this->dbus->query("SELECT * FROM mysql.user WHERE User='" . $user . "' AND Host='" . $this->dbus->Client . "';");
|
$this->dbus->query("SELECT * FROM mysql.user WHERE User='" . $user . "' AND Host='" . $this->dbus->Client . "';");
|
||||||
if (!$this->dbus->next_record()) {
|
if (!$this->dbus->next_record()) {
|
||||||
|
@ -858,14 +853,13 @@ class m_mysql {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$r[] = array("db" => $tab['db'], "select" => "N", "insert" => "N", "update" => "N", "delete" => "N", "create" => "N", "drop" => "N", "references" => "N", "index" => "N", "alter" => "N", "create_tmp" => "N", "lock" => "N", "create_view" => "N", "show_view" => "N", "create_routine" => "N", "alter_routine" => "N", "execute" => "N", "event" => "N", "trigger" => "N");
|
$r[] = array("db" => $tab['db'], "select" => "N", "insert" => "N", "update" => "N", "delete" => "N", "create" => "N", "drop" => "N", "references" => "N", "index" => "N", "alter" => "N", "create_tmp" => "N", "lock" => "N", "create_view" => "N", "show_view" => "N", "create_routine" => "N", "alter_routine" => "N", "execute" => "N", "event" => "N", "trigger" => "N");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the access rights of user $user to database $dbn to be rights $rights
|
* Set the access rights of user $user to database $dbn to be rights $rights
|
||||||
* @param $user the username to give rights to
|
* @param $user the username to give rights to
|
||||||
|
@ -875,13 +869,13 @@ class m_mysql {
|
||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
function set_user_rights($user, $dbn, $rights) {
|
function set_user_rights($user, $dbn, $rights) {
|
||||||
global $mem,$err,$db;
|
global $err;
|
||||||
$err->log("mysql", "set_user_rights");
|
$err->log("mysql", "set_user_rights");
|
||||||
|
|
||||||
$usern = addslashes($user);
|
$usern = addslashes($user);
|
||||||
$dbname = addslashes($dbn);
|
$dbname = addslashes($dbn);
|
||||||
$dbname = str_replace('_', '\_', $dbname);
|
$dbname = str_replace('_', '\_', $dbname);
|
||||||
// On génère les droits en fonction du tableau de droits
|
// On genere les droits en fonction du tableau de droits
|
||||||
$strrights = "";
|
$strrights = "";
|
||||||
for ($i = 0; $i < count($rights); $i++) {
|
for ($i = 0; $i < count($rights); $i++) {
|
||||||
switch ($rights[$i]) {
|
switch ($rights[$i]) {
|
||||||
|
@ -944,8 +938,9 @@ class m_mysql {
|
||||||
|
|
||||||
// We reset all user rights on this DB :
|
// We reset all user rights on this DB :
|
||||||
$this->dbus->query("SELECT * FROM mysql.db WHERE User = '$usern' AND Db = '$dbname';");
|
$this->dbus->query("SELECT * FROM mysql.db WHERE User = '$usern' AND Db = '$dbname';");
|
||||||
if($this->dbus->num_rows())
|
if ($this->dbus->num_rows()) {
|
||||||
$this->dbus->query("REVOKE ALL PRIVILEGES ON `$dbname`.* FROM '$usern'@'" . $this->dbus->Client . "';");
|
$this->dbus->query("REVOKE ALL PRIVILEGES ON `$dbname`.* FROM '$usern'@'" . $this->dbus->Client . "';");
|
||||||
|
}
|
||||||
if ($strrights) {
|
if ($strrights) {
|
||||||
$strrights = substr($strrights, 0, strlen($strrights) - 1);
|
$strrights = substr($strrights, 0, strlen($strrights) - 1);
|
||||||
$this->grant($dbname, $usern, $strrights);
|
$this->grant($dbname, $usern, $strrights);
|
||||||
|
@ -956,16 +951,12 @@ class m_mysql {
|
||||||
|
|
||||||
function available_sql_rights() {
|
function available_sql_rights() {
|
||||||
return Array('select', 'insert', 'update', 'delete', 'create', 'drop', 'references', 'index', 'alter', 'create_tmp', 'lock', 'create_view', 'show_view', 'create_routine', 'alter_routine', 'execute', 'event', 'trigger');
|
return Array('select', 'insert', 'update', 'delete', 'create', 'drop', 'references', 'index', 'alter', 'create_tmp', 'lock', 'create_view', 'show_view', 'create_routine', 'alter_routine', 'execute', 'event', 'trigger');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Hook function called by the lxc class to set mysql_host and port
|
/** Hook function called by the lxc class to set mysql_host and port
|
||||||
* parameters
|
* parameters
|
||||||
* @param $name string name of the quota
|
|
||||||
* @return integer the number of service used or false if an error occured
|
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function hook_lxc_params($params) {
|
function hook_lxc_params($params) {
|
||||||
|
@ -979,8 +970,8 @@ class m_mysql {
|
||||||
return $p;
|
return $p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Hook function called by the quota class to compute user used quota
|
/** Hook function called by the quota class to compute user used quota
|
||||||
* Returns the used quota for the $name service for the current user.
|
* Returns the used quota for the $name service for the current user.
|
||||||
* @param $name string name of the quota
|
* @param $name string name of the quota
|
||||||
|
@ -988,7 +979,7 @@ class m_mysql {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function hook_quota_get() {
|
function hook_quota_get() {
|
||||||
global $err,$db,$cuid;
|
global $err;
|
||||||
$err->log("mysql", "alternc_get_quota");
|
$err->log("mysql", "alternc_get_quota");
|
||||||
$q = Array("name" => "mysql", "description" => _("MySQL Databases"), "used" => 0);
|
$q = Array("name" => "mysql", "description" => _("MySQL Databases"), "used" => 0);
|
||||||
$c = $this->get_dblist();
|
$c = $this->get_dblist();
|
||||||
|
@ -999,6 +990,7 @@ class m_mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Hook function called when a user is created.
|
/** Hook function called when a user is created.
|
||||||
* AlternC's standard function that create a member
|
* AlternC's standard function that create a member
|
||||||
* @access private
|
* @access private
|
||||||
|
@ -1022,16 +1014,14 @@ class m_mysql {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Hook function called when a user is deleted.
|
/** Hook function called when a user is deleted.
|
||||||
* AlternC's standard function that delete a member
|
* AlternC's standard function that delete a member
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function alternc_del_member() {
|
function alternc_del_member() {
|
||||||
global $db,$err,$cuid;
|
global $err;
|
||||||
$err->log("mysql", "alternc_del_member");
|
$err->log("mysql", "alternc_del_member");
|
||||||
$c = $this->get_dblist();
|
$c = $this->get_dblist();
|
||||||
if (is_array($c)) {
|
if (is_array($c)) {
|
||||||
|
@ -1048,8 +1038,8 @@ class m_mysql {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Hook function called when a user is logged out.
|
/** Hook function called when a user is logged out.
|
||||||
* We just remove the cookie created in admin/sql_admin.php
|
* We just remove the cookie created in admin/sql_admin.php
|
||||||
a @access private
|
a @access private
|
||||||
|
@ -1060,8 +1050,8 @@ class m_mysql {
|
||||||
$_SESSION['PMA_single_signon_host'] = '';
|
$_SESSION['PMA_single_signon_host'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exporte all the mysql information of an account
|
* Exporte all the mysql information of an account
|
||||||
* @access private
|
* @access private
|
||||||
|
@ -1094,13 +1084,14 @@ class m_mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exporte all the mysql databases a of give account to $dir directory
|
* Exporte all the mysql databases a of give account to $dir directory
|
||||||
* @access private
|
* @access private
|
||||||
* EXPERIMENTAL 'sid' function ;)
|
* EXPERIMENTAL 'sid' function ;)
|
||||||
*/
|
*/
|
||||||
function alternc_export_data($dir) {
|
function alternc_export_data($dir) {
|
||||||
global $db, $err, $cuid,$mem;
|
global $db, $err, $cuid;
|
||||||
$err->log("mysql", "export_data");
|
$err->log("mysql", "export_data");
|
||||||
$db->query("SELECT db.login, db.pass, db.db, dbusers.name FROM db,dbusers WHERE db.uid='$cuid' AND dbusers.uid=db.uid;");
|
$db->query("SELECT db.login, db.pass, db.db, dbusers.name FROM db,dbusers WHERE db.uid='$cuid' AND dbusers.uid=db.uid;");
|
||||||
$dir.="sql/";
|
$dir.="sql/";
|
||||||
|
@ -1117,6 +1108,7 @@ class m_mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the size of each databases in a SQL Host given in parameter
|
* Return the size of each databases in a SQL Host given in parameter
|
||||||
* @param $db_name the human name of the host
|
* @param $db_name the human name of the host
|
||||||
|
@ -1127,7 +1119,7 @@ class m_mysql {
|
||||||
* @return an array associating the name of the databases to their sizes : array(dbname=>size)
|
* @return an array associating the name of the databases to their sizes : array(dbname=>size)
|
||||||
*/
|
*/
|
||||||
function get_dbus_size($db_name, $db_host, $db_login, $db_password, $db_client) {
|
function get_dbus_size($db_name, $db_host, $db_login, $db_password, $db_client) {
|
||||||
global $db,$err;
|
global $err;
|
||||||
$err->log("mysql", "get_dbus_size", $db_host);
|
$err->log("mysql", "get_dbus_size", $db_host);
|
||||||
|
|
||||||
# We create the object with empty parameters
|
# We create the object with empty parameters
|
||||||
|
@ -1153,6 +1145,6 @@ class m_mysql {
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* Class m_mysql */
|
}
|
||||||
|
|
||||||
?>
|
/* Class m_mysql */
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -38,13 +39,12 @@
|
||||||
class m_quota {
|
class m_quota {
|
||||||
|
|
||||||
var $disk = Array(); /* disk resource for which we will manage quotas */
|
var $disk = Array(); /* disk resource for which we will manage quotas */
|
||||||
|
|
||||||
var $disk_quota_enable;
|
var $disk_quota_enable;
|
||||||
var $quotas;
|
var $quotas;
|
||||||
var $clquota; // Which class manage which quota.
|
var $clquota; // Which class manage which quota.
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -53,7 +53,6 @@ class m_quota {
|
||||||
if ($this->disk_quota_enable) {
|
if ($this->disk_quota_enable) {
|
||||||
$this->disk = Array("web" => "web");
|
$this->disk = Array("web" => "web");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function dummy_for_translation() {
|
private function dummy_for_translation() {
|
||||||
|
@ -73,7 +72,9 @@ class m_quota {
|
||||||
$q = $this->getquota();
|
$q = $this->getquota();
|
||||||
|
|
||||||
foreach (array('web', 'bw_web') as $key) {
|
foreach (array('web', 'bw_web') as $key) {
|
||||||
if ( ! isset($q[$key]["u"]) || empty($q[$key]["t"])) continue;
|
if (!isset($q[$key]["u"]) || empty($q[$key]["t"])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$usage_percent = (int) ($q[$key]["u"] / $q[$key]["t"] * 100);
|
$usage_percent = (int) ($q[$key]["u"] / $q[$key]["t"] * 100);
|
||||||
$obj['links'][] = array('txt' => _("quota_" . $key) . " " . sprintf(_("%s%% of %s"), $usage_percent, format_size($q[$key]["t"] * 1024)), 'url' => ($key == 'bw_web' ? 'stats_show_per_month.php' : 'quota_show.php'));
|
$obj['links'][] = array('txt' => _("quota_" . $key) . " " . sprintf(_("%s%% of %s"), $usage_percent, format_size($q[$key]["t"] * 1024)), 'url' => ($key == 'bw_web' ? 'stats_show_per_month.php' : 'quota_show.php'));
|
||||||
$obj['links'][] = array('txt' => 'progressbar', 'total' => $q[$key]["t"], 'used' => $q[$key]["u"]);
|
$obj['links'][] = array('txt' => 'progressbar', 'total' => $q[$key]["t"], 'used' => $q[$key]["u"]);
|
||||||
|
@ -83,6 +84,7 @@ class m_quota {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Check if a user can use a ressource.
|
/** Check if a user can use a ressource.
|
||||||
* @param string $ressource the ressource name (a named quota)
|
* @param string $ressource the ressource name (a named quota)
|
||||||
* @Return TRUE if the user can create a ressource (= is there any quota left ?)
|
* @Return TRUE if the user can create a ressource (= is there any quota left ?)
|
||||||
|
@ -93,13 +95,12 @@ class m_quota {
|
||||||
return $t["u"] < $t["t"];
|
return $t["u"] < $t["t"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** List the quota-managed services in the server
|
/** List the quota-managed services in the server
|
||||||
* @Return array the quota names and description (translated)
|
* @Return array the quota names and description (translated)
|
||||||
*/
|
*/
|
||||||
function qlist() {
|
function qlist() {
|
||||||
global $classes,$hooks;
|
|
||||||
$qlist = array();
|
$qlist = array();
|
||||||
reset($this->disk);
|
reset($this->disk);
|
||||||
while (list($key, $val) = each($this->disk)) {
|
while (list($key, $val) = each($this->disk)) {
|
||||||
|
@ -114,7 +115,6 @@ class m_quota {
|
||||||
return $qlist;
|
return $qlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronise the quotas of the users with the quota of the
|
* Synchronise the quotas of the users with the quota of the
|
||||||
* user's profile.
|
* user's profile.
|
||||||
|
@ -126,7 +126,9 @@ class m_quota {
|
||||||
global $db, $err;
|
global $db, $err;
|
||||||
$err->log("quota", "synchronise_user_profile");
|
$err->log("quota", "synchronise_user_profile");
|
||||||
$q = "insert into quotas select m.uid as uid, d.quota as name, d.value as total from membres m, defquotas d left join quotas q on q.name=d.quota where m.type=d.type ON DUPLICATE KEY UPDATE total = greatest(d.value, quotas.total);";
|
$q = "insert into quotas select m.uid as uid, d.quota as name, d.value as total from membres m, defquotas d left join quotas q on q.name=d.quota where m.type=d.type ON DUPLICATE KEY UPDATE total = greatest(d.value, quotas.total);";
|
||||||
if (!$db->query($q)) return false;
|
if (!$db->query($q)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +137,7 @@ class m_quota {
|
||||||
* when a new quota appear
|
* when a new quota appear
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function create_missing_quota_profile() {
|
function create_missing_quota_profile() {
|
||||||
global $db, $quota, $err;
|
global $db, $quota, $err;
|
||||||
$err->log("quota", "create_missing_quota_profile");
|
$err->log("quota", "create_missing_quota_profile");
|
||||||
|
@ -149,6 +152,7 @@ class m_quota {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Return a ressource usage (u) and total quota (t)
|
/** Return a ressource usage (u) and total quota (t)
|
||||||
* @param string $ressource ressource to get quota of
|
* @param string $ressource ressource to get quota of
|
||||||
* @Return array the quota used and total for this ressource (or for all ressource if unspecified)
|
* @Return array the quota used and total for this ressource (or for all ressource if unspecified)
|
||||||
|
@ -179,10 +183,7 @@ class m_quota {
|
||||||
while (list($key, $val) = each($this->disk)) {
|
while (list($key, $val) = each($this->disk)) {
|
||||||
$a = array();
|
$a = array();
|
||||||
if (
|
if (
|
||||||
isset($disk_cached[$val])
|
isset($disk_cached[$val]) && !empty($disk_cached[$val]) && $disk_cached[$val]['uid'] == $cuid && $disk_cached[$val]['timestamp'] > ( time() - (90) ) // Cache, en seconde
|
||||||
&& !empty($disk_cached[$val])
|
|
||||||
&& $disk_cached[$val]['uid'] == $cuid
|
|
||||||
&& $disk_cached[$val]['timestamp'] > ( time() - (90) ) // Cache, en seconde
|
|
||||||
) {
|
) {
|
||||||
// If there is a cached value
|
// If there is a cached value
|
||||||
$a = $disk_cached[$val];
|
$a = $disk_cached[$val];
|
||||||
|
@ -218,8 +219,8 @@ class m_quota {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Set the quota for a user (and for a ressource)
|
/** Set the quota for a user (and for a ressource)
|
||||||
* @param string $ressource ressource to set quota of
|
* @param string $ressource ressource to set quota of
|
||||||
* @param integer size of the quota (available or used)
|
* @param integer size of the quota (available or used)
|
||||||
|
@ -227,11 +228,14 @@ class m_quota {
|
||||||
function setquota($ressource, $size) {
|
function setquota($ressource, $size) {
|
||||||
global $err, $db, $cuid;
|
global $err, $db, $cuid;
|
||||||
$err->log("quota", "setquota", $ressource . "/" . $size);
|
$err->log("quota", "setquota", $ressource . "/" . $size);
|
||||||
if (floatval($size)==0) $size="0";
|
if (floatval($size) == 0) {
|
||||||
|
$size = "0";
|
||||||
|
}
|
||||||
if (isset($this->disk[$ressource])) {
|
if (isset($this->disk[$ressource])) {
|
||||||
// It's a disk resource, update it with shell command
|
// It's a disk resource, update it with shell command
|
||||||
exec("sudo /usr/lib/alternc/quota_edit " . intval($cuid) . " " . intval($size) . " &> /dev/null &");
|
exec("sudo /usr/lib/alternc/quota_edit " . intval($cuid) . " " . intval($size) . " &> /dev/null &");
|
||||||
// Now we check that the value has been written properly :
|
// Now we check that the value has been written properly :
|
||||||
|
$a = array();
|
||||||
exec("sudo /usr/lib/alternc/quota_get " . intval($cuid) . " &> /dev/null &", $a);
|
exec("sudo /usr/lib/alternc/quota_get " . intval($cuid) . " &> /dev/null &", $a);
|
||||||
if (!isset($a[1]) || $size != $a[1]) {
|
if (!isset($a[1]) || $size != $a[1]) {
|
||||||
$err->raise("quota", _("Error writing the quota entry!"));
|
$err->raise("quota", _("Error writing the quota entry!"));
|
||||||
|
@ -248,8 +252,8 @@ class m_quota {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erase all quota information about the user.
|
* Erase all quota information about the user.
|
||||||
*/
|
*/
|
||||||
|
@ -260,8 +264,8 @@ class m_quota {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Get the default quotas as an associative array
|
/** Get the default quotas as an associative array
|
||||||
* @return array the array of the default quotas
|
* @return array the array of the default quotas
|
||||||
*/
|
*/
|
||||||
|
@ -270,9 +274,9 @@ class m_quota {
|
||||||
$c = array();
|
$c = array();
|
||||||
|
|
||||||
$db->query("SELECT type,quota FROM defquotas WHERE type='default'");
|
$db->query("SELECT type,quota FROM defquotas WHERE type='default'");
|
||||||
if(!$db->next_record())
|
if (!$db->next_record()) {
|
||||||
$this->addtype('default');
|
$this->addtype('default');
|
||||||
|
}
|
||||||
$db->query("SELECT value,quota,type FROM defquotas ORDER BY type,quota");
|
$db->query("SELECT value,quota,type FROM defquotas ORDER BY type,quota");
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$type = $db->f("type");
|
$type = $db->f("type");
|
||||||
|
@ -281,8 +285,8 @@ class m_quota {
|
||||||
return $c;
|
return $c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Set the default quotas
|
/** Set the default quotas
|
||||||
* @param array associative array of quota (key=>val)
|
* @param array associative array of quota (key=>val)
|
||||||
*/
|
*/
|
||||||
|
@ -293,16 +297,17 @@ class m_quota {
|
||||||
foreach ($newq as $type => $quotas) {
|
foreach ($newq as $type => $quotas) {
|
||||||
foreach ($quotas as $qname => $value) {
|
foreach ($quotas as $qname => $value) {
|
||||||
if (array_key_exists($qname, $qlist)) {
|
if (array_key_exists($qname, $qlist)) {
|
||||||
if(!$db->query("REPLACE INTO defquotas (value,quota,type) VALUES ($value,'$qname','$type');"))
|
if (!$db->query("REPLACE INTO defquotas (value,quota,type) VALUES ($value,'$qname','$type');")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Add an account type for quotas
|
/** Add an account type for quotas
|
||||||
* @param string $type account type to be added
|
* @param string $type account type to be added
|
||||||
* @return boolean true if all went ok
|
* @return boolean true if all went ok
|
||||||
|
@ -310,22 +315,24 @@ class m_quota {
|
||||||
function addtype($type) {
|
function addtype($type) {
|
||||||
global $db, $err;
|
global $db, $err;
|
||||||
$qlist = $this->qlist();
|
$qlist = $this->qlist();
|
||||||
if(empty($type)) return false;
|
if (empty($type)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$type = strtolower($type);
|
$type = strtolower($type);
|
||||||
if (!preg_match("#^[a-z0-9]*$#", $type)) {
|
if (!preg_match("#^[a-z0-9]*$#", $type)) {
|
||||||
$err->raise("quota", "Type can only contains characters a-z and 0-9");
|
$err->raise("quota", "Type can only contains characters a-z and 0-9");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
while (list($key, $val) = each($qlist)) {
|
while (list($key, $val) = each($qlist)) {
|
||||||
if(!$db->query("INSERT IGNORE INTO defquotas (quota,type) VALUES('$key', '$type');")
|
if (!$db->query("INSERT IGNORE INTO defquotas (quota,type) VALUES('$key', '$type');") || $db->affected_rows() == 0) {
|
||||||
|| $db->affected_rows() == 0)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** List for quotas
|
/** List for quotas
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
@ -339,8 +346,8 @@ class m_quota {
|
||||||
return $t;
|
return $t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Delete an account type for quotas
|
/** Delete an account type for quotas
|
||||||
* @param string $type account type to be deleted
|
* @param string $type account type to be deleted
|
||||||
* @return boolean true if all went ok
|
* @return boolean true if all went ok
|
||||||
|
@ -356,8 +363,8 @@ class m_quota {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Create default quotas entries for a new user.
|
/** Create default quotas entries for a new user.
|
||||||
* The user we are talking about is in the global $cuid.
|
* The user we are talking about is in the global $cuid.
|
||||||
*/
|
*/
|
||||||
|
@ -368,9 +375,9 @@ class m_quota {
|
||||||
reset($ql);
|
reset($ql);
|
||||||
|
|
||||||
$db->query("SELECT type,quota FROM defquotas WHERE type='default'");
|
$db->query("SELECT type,quota FROM defquotas WHERE type='default'");
|
||||||
if(!$db->next_record())
|
if (!$db->next_record()) {
|
||||||
$this->addtype('default');
|
$this->addtype('default');
|
||||||
|
}
|
||||||
$db->query("SELECT type FROM membres WHERE uid='$cuid'");
|
$db->query("SELECT type FROM membres WHERE uid='$cuid'");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$t = $db->f("type");
|
$t = $db->f("type");
|
||||||
|
@ -383,8 +390,8 @@ class m_quota {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Return a quota value with its unit (when it is a space quota)
|
/** Return a quota value with its unit (when it is a space quota)
|
||||||
* in MB, GB, TB ...
|
* in MB, GB, TB ...
|
||||||
* @param string $type The quota type
|
* @param string $type The quota type
|
||||||
|
@ -402,10 +409,10 @@ class m_quota {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* get size_xx function (filled by spoolsize.php) */
|
/* get size_xx function (filled by spoolsize.php) */
|
||||||
|
|
||||||
function _get_sum_sql($sql) {
|
function _get_sum_sql($sql) {
|
||||||
global $db,$err,$cuid;
|
global $db;
|
||||||
$db->query($sql);
|
$db->query($sql);
|
||||||
if ($db->num_rows() == 0) {
|
if ($db->num_rows() == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -417,7 +424,7 @@ class m_quota {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _get_count_sql($sql) {
|
function _get_count_sql($sql) {
|
||||||
global $db,$err,$cuid;
|
global $db;
|
||||||
$db->query($sql);
|
$db->query($sql);
|
||||||
if ($db->num_rows() == 0) {
|
if ($db->num_rows() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -429,7 +436,7 @@ class m_quota {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _get_size_and_record_sql($sql) {
|
function _get_size_and_record_sql($sql) {
|
||||||
global $db,$err,$cuid;
|
global $db;
|
||||||
$db->query($sql);
|
$db->query($sql);
|
||||||
if ($db->num_rows() == 0) {
|
if ($db->num_rows() == 0) {
|
||||||
return array();
|
return array();
|
||||||
|
@ -443,97 +450,116 @@ class m_quota {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sum of websites sizes from all users */
|
/* sum of websites sizes from all users */
|
||||||
|
|
||||||
function get_size_web_sum_all() {
|
function get_size_web_sum_all() {
|
||||||
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_web;");
|
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_web;");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sum of websites sizes from one user */
|
/* sum of websites sizes from one user */
|
||||||
|
|
||||||
function get_size_web_sum_user($u) {
|
function get_size_web_sum_user($u) {
|
||||||
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_web WHERE uid='$u';");
|
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_web WHERE uid='$u';");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sum of mailbox sizes from all domains */
|
/* sum of mailbox sizes from all domains */
|
||||||
|
|
||||||
function get_size_mail_sum_all() {
|
function get_size_mail_sum_all() {
|
||||||
return $this->_get_sum_sql("SELECT SUM(bytes) AS sum FROM mailbox;");
|
return $this->_get_sum_sql("SELECT SUM(bytes) AS sum FROM mailbox;");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sum of mailbox sizes for one domain */
|
/* sum of mailbox sizes for one domain */
|
||||||
|
|
||||||
function get_size_mail_sum_domain($dom) {
|
function get_size_mail_sum_domain($dom) {
|
||||||
global $mail;
|
global $mail;
|
||||||
return $mail->get_total_size_for_domain($dom);
|
return $mail->get_total_size_for_domain($dom);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count of mailbox sizes from all domains */
|
/* count of mailbox sizes from all domains */
|
||||||
|
|
||||||
function get_size_mail_count_all() {
|
function get_size_mail_count_all() {
|
||||||
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM mailbox;");
|
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM mailbox;");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count of mailbox for one domain */
|
/* count of mailbox for one domain */
|
||||||
|
|
||||||
function get_size_mail_count_domain($dom) {
|
function get_size_mail_count_domain($dom) {
|
||||||
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_view WHERE user LIKE '%@{$dom}'");
|
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_view WHERE user LIKE '%@{$dom}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get list of mailbox alias and size for one domain */
|
/* get list of mailbox alias and size for one domain */
|
||||||
|
|
||||||
function get_size_mail_details_domain($dom) {
|
function get_size_mail_details_domain($dom) {
|
||||||
return $this->_get_size_and_record_sql("SELECT user as alias,quota_dovecot as size FROM dovecot_view WHERE user LIKE '%@{$dom}' ORDER BY alias;");
|
return $this->_get_size_and_record_sql("SELECT user as alias,quota_dovecot as size FROM dovecot_view WHERE user LIKE '%@{$dom}' ORDER BY alias;");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sum of mailman lists sizes from all domains */
|
/* sum of mailman lists sizes from all domains */
|
||||||
|
|
||||||
function get_size_mailman_sum_all() {
|
function get_size_mailman_sum_all() {
|
||||||
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman;");
|
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman;");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sum of mailman lists sizes for one domain */
|
/* sum of mailman lists sizes for one domain */
|
||||||
|
|
||||||
function get_size_mailman_sum_domain($dom) {
|
function get_size_mailman_sum_domain($dom) {
|
||||||
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE list LIKE '%@{$dom}'");
|
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE list LIKE '%@{$dom}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sum of mailman lists for one user */
|
/* sum of mailman lists for one user */
|
||||||
|
|
||||||
function get_size_mailman_sum_user($u) {
|
function get_size_mailman_sum_user($u) {
|
||||||
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE uid = '{$u}'");
|
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE uid = '{$u}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count of mailman lists sizes from all domains */
|
/* count of mailman lists sizes from all domains */
|
||||||
|
|
||||||
function get_size_mailman_count_all() {
|
function get_size_mailman_count_all() {
|
||||||
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mailman;");
|
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mailman;");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count of mailman lists for one user */
|
/* count of mailman lists for one user */
|
||||||
|
|
||||||
function get_size_mailman_count_user($u) {
|
function get_size_mailman_count_user($u) {
|
||||||
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mailman WHERE uid = '{$u}'");
|
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mailman WHERE uid = '{$u}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get list of mailman list and size for one user */
|
/* get list of mailman list and size for one user */
|
||||||
|
|
||||||
function get_size_mailman_details_user($u) {
|
function get_size_mailman_details_user($u) {
|
||||||
return $this->_get_size_and_record_sql("SELECT s.size,CONCAT(m.list,'@',m.domain) as list FROM size_mailman s LEFT JOIN mailman m ON s.list=m.name WHERE s.uid='{$u}' ORDER BY s.list ASC");
|
return $this->_get_size_and_record_sql("SELECT s.size,CONCAT(m.list,'@',m.domain) as list FROM size_mailman s LEFT JOIN mailman m ON s.list=m.name WHERE s.uid='{$u}' ORDER BY s.list ASC");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sum of databases sizes from all users */
|
/* sum of databases sizes from all users */
|
||||||
|
|
||||||
function get_size_db_sum_all() {
|
function get_size_db_sum_all() {
|
||||||
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_db;");
|
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_db;");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sum of databases sizes for one user */
|
/* sum of databases sizes for one user */
|
||||||
|
|
||||||
function get_size_db_sum_user($u) {
|
function get_size_db_sum_user($u) {
|
||||||
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
|
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count of databases from all users */
|
/* count of databases from all users */
|
||||||
|
|
||||||
function get_size_db_count_all() {
|
function get_size_db_count_all() {
|
||||||
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_db;");
|
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_db;");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count of databases for one user */
|
/* count of databases for one user */
|
||||||
|
|
||||||
function get_size_db_count_user($u) {
|
function get_size_db_count_user($u) {
|
||||||
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
|
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get list of databases name and size for one user */
|
/* get list of databases name and size for one user */
|
||||||
|
|
||||||
function get_size_db_details_user($u) {
|
function get_size_db_details_user($u) {
|
||||||
return $this->_get_size_and_record_sql("SELECT db,size FROM size_db WHERE db='{$u}' OR db LIKE '{$u}\_%';");
|
return $this->_get_size_and_record_sql("SELECT db,size FROM size_db WHERE db='{$u}' OR db LIKE '{$u}\_%';");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return appropriate value and unit of a size given in Bytes (e.g. 1024 Bytes -> return 1 KB) */
|
/* Return appropriate value and unit of a size given in Bytes (e.g. 1024 Bytes -> return 1 KB) */
|
||||||
|
|
||||||
function get_size_unit($size) {
|
function get_size_unit($size) {
|
||||||
$units = array(1073741824 => _("GB"), 1048576 => _("MB"), 1024 => _("KB"), 0 => _("B"));
|
$units = array(1073741824 => _("GB"), 1048576 => _("MB"), 1024 => _("KB"), 0 => _("B"));
|
||||||
foreach ($units as $value => $unit) {
|
foreach ($units as $value => $unit) {
|
||||||
|
@ -565,10 +591,10 @@ class m_quota {
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ==== Hook functions ==== */
|
/* ==== Hook functions ==== */
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Hook function call when a user is deleted
|
/** Hook function call when a user is deleted
|
||||||
* AlternC's standard function called when a user is deleted
|
* AlternC's standard function called when a user is deleted
|
||||||
* globals $cuid is the appropriate user
|
* globals $cuid is the appropriate user
|
||||||
|
@ -577,8 +603,8 @@ class m_quota {
|
||||||
$this->delquotas();
|
$this->delquotas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Hook function called when a user is created
|
/** Hook function called when a user is created
|
||||||
* This function initialize the user's quotas.
|
* This function initialize the user's quotas.
|
||||||
* globals $cuid is the appropriate user
|
* globals $cuid is the appropriate user
|
||||||
|
@ -590,14 +616,14 @@ class m_quota {
|
||||||
$this->getquota('', true); // actualise quota
|
$this->getquota('', true); // actualise quota
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Exports all the quota related information for an account.
|
/** Exports all the quota related information for an account.
|
||||||
* @access private
|
* @access private
|
||||||
* EXPERIMENTAL function ;)
|
* EXPERIMENTAL function ;)
|
||||||
*/
|
*/
|
||||||
function alternc_export_conf() {
|
function alternc_export_conf() {
|
||||||
global $db,$err;
|
global $err;
|
||||||
$err->log("quota", "export");
|
$err->log("quota", "export");
|
||||||
$str = " <quota>";
|
$str = " <quota>";
|
||||||
|
|
||||||
|
@ -612,6 +638,7 @@ class m_quota {
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} /* Class m_quota */
|
/* Class m_quota */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue