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
|
@ -4,90 +4,88 @@ require_once("../class/config.php");
|
||||||
if (!$admin->enabled) {
|
if (!$admin->enabled) {
|
||||||
__("This page is restricted to authorized staff");
|
__("This page is restricted to authorized staff");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
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" />
|
<p><?php __("If you don't know what this page is about, don't touch anything, and read AlternC documentation about domain types"); ?></p>
|
||||||
<p><?php __("If you don't know what this page is about, don't touch anything, and read AlternC documentation about domain types"); ?></p>
|
<p><?php __("The Type column contains a type of available VirtualHost config on The server."); ?></p>
|
||||||
<p><?php __("The Type column contains a type of available VirtualHost config on The server."); ?></p>
|
<p><?php __("The Setting column contains the variables to be expanded in the defaults configuration. Available values are: "); ?></p>
|
||||||
<p><?php __("The Setting column contains the variables to be expanded in the defaults configuration. Available values are: "); ?></p>
|
<ul>
|
||||||
<ul>
|
|
||||||
<li><?php __("%%DOMAIN%% : the Domain name"); ?></li>
|
<li><?php __("%%DOMAIN%% : the Domain name"); ?></li>
|
||||||
<li><?php __("%%TARGETDOM%%: The destination domain"); ?></li>
|
<li><?php __("%%TARGETDOM%%: The destination domain"); ?></li>
|
||||||
<li><?php __("%%SUB%% : The subdomain name"); ?></li>
|
<li><?php __("%%SUB%% : The subdomain name"); ?></li>
|
||||||
<li><?php __("%%DOMAINDIR%%: the domain directory on the file system"); ?></li>
|
<li><?php __("%%DOMAINDIR%%: the domain directory on the file system"); ?></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<?php
|
<?php
|
||||||
if (isset($error) && $error) {
|
if (isset($error) && $error) {
|
||||||
echo "<p class=\"alert alert-danger\">$error</p>";
|
echo "<p class=\"alert alert-danger\">$error</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$fields = array (
|
$fields = array(
|
||||||
"domup" => array ("post", "array", ""),
|
"domup" => array("post", "array", ""),
|
||||||
);
|
);
|
||||||
getFields($fields);
|
getFields($fields);
|
||||||
|
|
||||||
if (!empty($domup)) {
|
if (!empty($domup)) {
|
||||||
if (!$dom->update_default_subdomains($domup) ) {
|
if (!$dom->update_default_subdomains($domup)) {
|
||||||
$error=_("There was an error during the record.");
|
$error = _("There was an error during the record.");
|
||||||
} else {
|
} else {
|
||||||
$error=_("Save done.");
|
$error = _("Save done.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$tab=$dom->lst_default_subdomains();
|
$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>
|
||||||
<option value='SLAVE' <?php if($val['concerned']=='SLAVE') echo "selected=\"selected\""; ?> >SLAVE</option>
|
<option value='SLAVE' <?php if ($val['concerned'] == 'SLAVE') echo "selected=\"selected\""; ?> >SLAVE</option>
|
||||||
<option value='BOTH' <?php if($val['concerned']=='BOTH') echo "selected=\"selected\""; ?> >BOTH</option>
|
<option value='BOTH' <?php if ($val['concerned'] == 'BOTH') echo "selected=\"selected\""; ?> >BOTH</option>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td><input type="checkbox" name="domup[<?php echo $i; ?>][enabled]" value="1" <?php if ($val['enabled']==1) echo "checked=\"checked\""; ?> /></td>
|
<td><input type="checkbox" name="domup[<?php echo $i; ?>][enabled]" value="1" <?php if ($val['enabled'] == 1) echo "checked=\"checked\""; ?> /></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan='6'><p><input type="submit" class="inb" name="submit" value="<?php __("Save"); ?>" /></p></td>
|
<td colspan='6'><p><input type="submit" class="inb" name="submit" value="<?php __("Save"); ?>" /></p></td>
|
||||||
</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
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
@ -18,11 +19,12 @@
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
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
|
||||||
**/
|
* */
|
||||||
class m_authip {
|
class m_authip {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +51,7 @@ class m_authip {
|
||||||
'ico' => 'images/ip.png',
|
'ico' => 'images/ip.png',
|
||||||
'link' => 'ip_main.php',
|
'link' => 'ip_main.php',
|
||||||
'pos' => 120,
|
'pos' => 120,
|
||||||
) ;
|
);
|
||||||
|
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
@ -62,11 +66,11 @@ class m_authip {
|
||||||
* @param boolean $whitelist
|
* @param boolean $whitelist
|
||||||
* @return array Retourne un tableau indexé des ip de l'utilisateur
|
* @return array Retourne un tableau indexé des ip de l'utilisateur
|
||||||
*/
|
*/
|
||||||
function list_ip($whitelist=false) {
|
function list_ip($whitelist = false) {
|
||||||
global $db, $mem;
|
global $db, $mem;
|
||||||
|
|
||||||
if ($whitelist && $mem->checkRight() ) {
|
if ($whitelist && $mem->checkRight()) {
|
||||||
$cuid=0;
|
$cuid = 0;
|
||||||
} else {
|
} else {
|
||||||
global $cuid;
|
global $cuid;
|
||||||
}
|
}
|
||||||
|
@ -74,20 +78,17 @@ class m_authip {
|
||||||
$r = array();
|
$r = array();
|
||||||
$db->query("SELECT * FROM authorised_ip WHERE uid='$cuid' order by ip,subnet;");
|
$db->query("SELECT * FROM authorised_ip WHERE uid='$cuid' order by ip,subnet;");
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$r[$db->f('id')]=$db->Record;
|
$r[$db->f('id')] = $db->Record;
|
||||||
if ( (checkip($db->f('ip')) && $db->f('subnet') == 32) ||
|
if ((checkip($db->f('ip')) && $db->f('subnet') == 32) ||
|
||||||
(checkipv6($db->f('ip')) && $db->f('subnet') == 128) ) {
|
(checkipv6($db->f('ip')) && $db->f('subnet') == 128)) {
|
||||||
$r[$db->f('id')]['ip_human']=$db->f('ip');
|
$r[$db->f('id')]['ip_human'] = $db->f('ip');
|
||||||
} 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
|
||||||
|
@ -102,14 +103,14 @@ class m_authip {
|
||||||
*/
|
*/
|
||||||
function ip_delete($id) {
|
function ip_delete($id) {
|
||||||
global $db, $cuid;
|
global $db, $cuid;
|
||||||
$id=intval($id);
|
$id = intval($id);
|
||||||
|
|
||||||
$db->query("SELECT id FROM authorised_ip_affected where authorised_ip_id ='$id';");
|
$db->query("SELECT id FROM authorised_ip_affected where authorised_ip_id ='$id';");
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$this->ip_affected_delete($db->f('id'));
|
$this->ip_affected_delete($db->f('id'));
|
||||||
}
|
}
|
||||||
if (! $db->query("delete from authorised_ip where id='$id' and ( uid='$cuid' or uid=0) limit 1;") ) {
|
if (!$db->query("delete from authorised_ip where id='$id' and ( uid='$cuid' or uid=0) limit 1;")) {
|
||||||
echo "query failed: ".$db->Error;
|
echo "query failed: " . $db->Error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -126,13 +127,13 @@ class m_authip {
|
||||||
*/
|
*/
|
||||||
function get_allowed($s) {
|
function get_allowed($s) {
|
||||||
global $db, $cuid;
|
global $db, $cuid;
|
||||||
if (! $db->query("select ai.ip, ai.subnet, ai.infos, aia.parameters from authorised_ip ai, authorised_ip_affected aia where aia.protocol='$s' and aia.authorised_ip_id = ai.id and ai.uid='$cuid';") ) {
|
if (!$db->query("select ai.ip, ai.subnet, ai.infos, aia.parameters from authorised_ip ai, authorised_ip_affected aia where aia.protocol='$s' and aia.authorised_ip_id = ai.id and ai.uid='$cuid';")) {
|
||||||
echo "query failed: ".$db->Error;
|
echo "query failed: " . $db->Error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$r=Array();
|
$r = Array();
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$r[]=Array("ip"=>$db->f("ip"), "subnet"=>$db->f("subnet"), "infos"=>$db->f("infos"), "parameters"=>$db->f("parameters"));
|
$r[] = Array("ip" => $db->f("ip"), "subnet" => $db->f("subnet"), "infos" => $db->f("infos"), "parameters" => $db->f("parameters"));
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
@ -145,12 +146,13 @@ class m_authip {
|
||||||
*/
|
*/
|
||||||
function is_wl($ip) {
|
function is_wl($ip) {
|
||||||
global $db;
|
global $db;
|
||||||
if (! $db->query("select ai.ip, ai.subnet from authorised_ip ai where ai.uid='0';") ) {
|
if (!$db->query("select ai.ip, ai.subnet from authorised_ip ai where ai.uid='0';")) {
|
||||||
echo "query failed: ".$db->Error;
|
echo "query failed: " . $db->Error;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,56 +204,61 @@ class m_authip {
|
||||||
* @return boolean Retourne FALSE si erreur, sinon TRUE
|
* @return boolean Retourne FALSE si erreur, sinon TRUE
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function ip_save($id, $ipsub, $infos, $uid=null) {
|
function ip_save($id, $ipsub, $infos, $uid = null) {
|
||||||
global $db, $mem;
|
global $db, $mem;
|
||||||
|
|
||||||
// If we ask for uid=0, we have to check to be super-user
|
// If we ask for uid=0, we have to check to be super-user
|
||||||
// else, juste use global cuid;
|
// else, juste use global cuid;
|
||||||
if ($uid === 0 && $mem->checkRight() ) {
|
if ($uid === 0 && $mem->checkRight()) {
|
||||||
$cuid=0;
|
$cuid = 0;
|
||||||
} else {
|
} else {
|
||||||
global $cuid;
|
global $cuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
$id=intval($id);
|
$id = intval($id);
|
||||||
$infos=mysql_real_escape_string($infos);
|
$infos = mysql_real_escape_string($infos);
|
||||||
|
|
||||||
// Extract subnet from ipsub
|
// Extract subnet from ipsub
|
||||||
$tmp=explode('/',$ipsub);
|
$tmp = explode('/', $ipsub);
|
||||||
$ip=$tmp[0];
|
$ip = $tmp[0];
|
||||||
|
|
||||||
// Error if $ip not an IP
|
// Error if $ip not an IP
|
||||||
if ( ! checkip($ip) && ! checkipv6($ip) ) {
|
if (!checkip($ip) && !checkipv6($ip)) {
|
||||||
echo "Failed : not an IP address";
|
echo "Failed : not an IP address";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the subnet, if not defined, give a /32 or a /128
|
// Check the subnet, if not defined, give a /32 or a /128
|
||||||
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);
|
||||||
foreach($list_affected as $k => $v) {
|
foreach ($list_affected as $k => $v) {
|
||||||
$this->call_hooks("authip_on_delete", $k );
|
$this->call_hooks("authip_on_delete", $k);
|
||||||
}
|
}
|
||||||
if (! $db->query("update authorised_ip set ip='$ip', subnet='$subnet', infos='$infos' where id='$id' and uid='$cuid' ;") ) {
|
if (!$db->query("update authorised_ip set ip='$ip', subnet='$subnet', infos='$infos' where id='$id' and uid='$cuid' ;")) {
|
||||||
echo "query failed: ".$db->Error;
|
echo "query failed: " . $db->Error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
foreach($list_affected as $k => $v) {
|
foreach ($list_affected as $k => $v) {
|
||||||
$this->call_hooks("authip_on_create", $k );
|
$this->call_hooks("authip_on_create", $k);
|
||||||
}
|
}
|
||||||
} else { // Insert
|
} else { // Insert
|
||||||
if (! $db->query("insert into authorised_ip (uid, ip, subnet, infos) values ('$cuid', '$ip', '$subnet', '$infos' );") ) {
|
if (!$db->query("insert into authorised_ip (uid, ip, subnet, infos) values ('$cuid', '$ip', '$subnet', '$infos' );")) {
|
||||||
echo "query failed: ".$db->Error;
|
echo "query failed: " . $db->Error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +273,7 @@ class m_authip {
|
||||||
* @return boolean Retourne TRUE
|
* @return boolean Retourne TRUE
|
||||||
*/
|
*/
|
||||||
function alternc_del_member() {
|
function alternc_del_member() {
|
||||||
global $cuid,$db;
|
global $cuid, $db;
|
||||||
$db->query("SELECT id FROM authorised_ip WHERE uid ='$cuid';");
|
$db->query("SELECT id FROM authorised_ip WHERE uid ='$cuid';");
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$this->ip_delete($db->f('id'));
|
$this->ip_delete($db->f('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
|
||||||
|
@ -284,7 +294,7 @@ class m_authip {
|
||||||
// Je rajoute la class DANS l'objet parce que
|
// Je rajoute la class DANS l'objet parce que
|
||||||
// ca m'interesse
|
// ca m'interesse
|
||||||
foreach ($authclass as $k => $v) {
|
foreach ($authclass as $k => $v) {
|
||||||
$authclass[$k]['class']=$k;
|
$authclass[$k]['class'] = $k;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $authclass;
|
return $authclass;
|
||||||
|
@ -302,26 +312,26 @@ class m_authip {
|
||||||
* @param int $id $id présent si c'est une édition
|
* @param int $id $id présent si c'est une édition
|
||||||
* @return boolean Retourne FALSE si erreur, sinon TRUE
|
* @return boolean Retourne FALSE si erreur, sinon TRUE
|
||||||
*/
|
*/
|
||||||
function ip_affected_save($authorised_ip_id, $protocol, $parameters, $id=null) {
|
function ip_affected_save($authorised_ip_id, $protocol, $parameters, $id = null) {
|
||||||
global $db;
|
global $db;
|
||||||
$authorised_ip_id=intval($authorised_ip_id);
|
$authorised_ip_id = intval($authorised_ip_id);
|
||||||
$protocol=mysql_real_escape_string($protocol);
|
$protocol = mysql_real_escape_string($protocol);
|
||||||
$parameters=mysql_real_escape_string($parameters);
|
$parameters = mysql_real_escape_string($parameters);
|
||||||
|
|
||||||
if ($id) {
|
if ($id) {
|
||||||
$id=intval($id);
|
$id = intval($id);
|
||||||
$this->call_hooks("authip_on_delete", $id );
|
$this->call_hooks("authip_on_delete", $id);
|
||||||
if (! $db->query("update authorised_ip_affected set authorised_ip_id='$authorised_ip_id', protocol='$protocol', parameters='$parameters' where id ='$id' limit 1;") ) {
|
if (!$db->query("update authorised_ip_affected set authorised_ip_id='$authorised_ip_id', protocol='$protocol', parameters='$parameters' where id ='$id' limit 1;")) {
|
||||||
echo "query failed: ".$db->Error;
|
echo "query failed: " . $db->Error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->call_hooks("authip_on_create", $id );
|
$this->call_hooks("authip_on_create", $id);
|
||||||
} else {
|
} else {
|
||||||
if (! $db->query("insert into authorised_ip_affected (authorised_ip_id, protocol, parameters) values ('$authorised_ip_id', '$protocol', '$parameters');") ) {
|
if (!$db->query("insert into authorised_ip_affected (authorised_ip_id, protocol, parameters) values ('$authorised_ip_id', '$protocol', '$parameters');")) {
|
||||||
echo "query failed: ".$db->Error;
|
echo "query failed: " . $db->Error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->call_hooks("authip_on_create", mysql_insert_id() );
|
$this->call_hooks("authip_on_create", mysql_insert_id());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -337,19 +347,18 @@ class m_authip {
|
||||||
*/
|
*/
|
||||||
function ip_affected_delete($id) {
|
function ip_affected_delete($id) {
|
||||||
global $db;
|
global $db;
|
||||||
$id=intval($id);
|
$id = intval($id);
|
||||||
|
|
||||||
// Call hooks
|
// Call hooks
|
||||||
$this->call_hooks("authip_on_delete", $id );
|
$this->call_hooks("authip_on_delete", $id);
|
||||||
|
|
||||||
if (! $db->query("delete from authorised_ip_affected where id='$id' limit 1;") ) {
|
if (!$db->query("delete from authorised_ip_affected where id='$id' limit 1;")) {
|
||||||
echo "query failed: ".$db->Error;
|
echo "query failed: " . $db->Error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
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
|
||||||
|
@ -361,11 +370,11 @@ class m_authip {
|
||||||
* @return boolean Retourne TRUE
|
* @return boolean Retourne TRUE
|
||||||
*/
|
*/
|
||||||
function call_hooks($function, $affectation_id) {
|
function call_hooks($function, $affectation_id) {
|
||||||
global $hooks,$err;
|
global $hooks, $err;
|
||||||
|
|
||||||
// On récure l'objet dont on parle
|
// On récure l'objet dont on parle
|
||||||
$d = $this->list_affected();
|
$d = $this->list_affected();
|
||||||
if (! isset($d[$affectation_id] )) {
|
if (!isset($d[$affectation_id])) {
|
||||||
$err->raise('authip', _("Object not available"));
|
$err->raise('authip', _("Object not available"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -374,14 +383,14 @@ class m_authip {
|
||||||
|
|
||||||
// On en déduis la classe qui le concerne
|
// On en déduis la classe qui le concerne
|
||||||
$e = $this->get_auth_class();
|
$e = $this->get_auth_class();
|
||||||
if (! isset($e[$affectation['protocol']])) {
|
if (!isset($e[$affectation['protocol']])) {
|
||||||
$err->raise('authip', sprintf(_("Can't identified class for the protocole %s"), $affectation['protocol']));
|
$err->raise('authip', sprintf(_("Can't identified class for the protocole %s"), $affectation['protocol']));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$c = $e[$affectation['protocol']]['class'];
|
$c = $e[$affectation['protocol']]['class'];
|
||||||
|
|
||||||
// On appelle le hooks de cette classe
|
// On appelle le hooks de cette classe
|
||||||
$hooks->invoke($function, Array($affectation), Array($c) );
|
$hooks->invoke($function, Array($affectation), Array($c));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -394,21 +403,21 @@ class m_authip {
|
||||||
* @param int $ip_id
|
* @param int $ip_id
|
||||||
* @return array Retourne un tableau de valeurs
|
* @return array Retourne un tableau de valeurs
|
||||||
*/
|
*/
|
||||||
function list_affected($ip_id=null) {
|
function list_affected($ip_id = null) {
|
||||||
global $db, $cuid;
|
global $db, $cuid;
|
||||||
|
|
||||||
$r = array();
|
$r = array();
|
||||||
if ( is_null($ip_id) ) {
|
if (is_null($ip_id)) {
|
||||||
$db->query("select aia.* from authorised_ip_affected aia, authorised_ip ai where ai.uid='$cuid' and aia.authorised_ip_id = ai.id order by protocol, parameters;");
|
$db->query("select aia.* from authorised_ip_affected aia, authorised_ip ai where ai.uid='$cuid' and aia.authorised_ip_id = ai.id order by protocol, parameters;");
|
||||||
} else {
|
} else {
|
||||||
$db->query("select aia.* from authorised_ip_affected aia, authorised_ip ai where ai.uid='$cuid' and aia.authorised_ip_id = '".intval($ip_id)."' order by protocol, parameters;");
|
$db->query("select aia.* from authorised_ip_affected aia, authorised_ip ai where ai.uid='$cuid' and aia.authorised_ip_id = '" . intval($ip_id) . "' order by protocol, parameters;");
|
||||||
}
|
}
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$r[$db->f('id')]=$db->Record;
|
$r[$db->f('id')] = $db->Record;
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
}; /* Classe m_authip */
|
}
|
||||||
|
|
||||||
?>
|
/* Classe m_authip */
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -21,50 +22,52 @@
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Purpose of file: Manage hook system.
|
Purpose of file: Manage hook system.
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manage web-cron tasks
|
* This class manage web-cron tasks
|
||||||
*/
|
*/
|
||||||
class m_cron {
|
class m_cron {
|
||||||
|
|
||||||
const MAX_SOCKETS=8;
|
const MAX_SOCKETS = 8;
|
||||||
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() {
|
||||||
return Array(
|
return Array(
|
||||||
Array('unit'=>1440, 'name'=>_("Daily")),
|
Array('unit' => 1440, 'name' => _("Daily")),
|
||||||
Array('unit'=>60, 'name'=>_("Hour")),
|
Array('unit' => 60, 'name' => _("Hour")),
|
||||||
Array('unit'=>30, 'name'=>_("Half Hour")),
|
Array('unit' => 30, 'name' => _("Half Hour")),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/** 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.
|
||||||
*/
|
*/
|
||||||
function lst_cron() {
|
function lst_cron() {
|
||||||
global $cuid,$db,$err;
|
global $cuid, $db, $err;
|
||||||
$err->log("cron","lst_cron");
|
$err->log("cron", "lst_cron");
|
||||||
$db->query("SELECT * FROM cron WHERE uid = $cuid ORDER BY url;");
|
$db->query("SELECT * FROM cron WHERE uid = $cuid ORDER BY url;");
|
||||||
$r=Array();
|
$r = Array();
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$tmp=Array();
|
$tmp = Array();
|
||||||
$tmp['id']=$db->f('id');
|
$tmp['id'] = $db->f('id');
|
||||||
$tmp['url']=urldecode($db->f('url'));
|
$tmp['url'] = urldecode($db->f('url'));
|
||||||
$tmp['user']=urldecode($db->f('user'));
|
$tmp['user'] = urldecode($db->f('user'));
|
||||||
$tmp['password']=urldecode($db->f('password'));
|
$tmp['password'] = urldecode($db->f('password'));
|
||||||
$tmp['schedule']=$db->f('schedule');
|
$tmp['schedule'] = $db->f('schedule');
|
||||||
$tmp['email']=urldecode($db->f('email'));
|
$tmp['email'] = urldecode($db->f('email'));
|
||||||
$tmp['next_execution']=$db->f('next_execution');
|
$tmp['next_execution'] = $db->f('next_execution');
|
||||||
$r[]=$tmp;
|
$r[] = $tmp;
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
@ -75,84 +78,93 @@ class m_cron {
|
||||||
'ico' => 'images/schedule.png',
|
'ico' => 'images/schedule.png',
|
||||||
'link' => 'cron.php',
|
'link' => 'cron.php',
|
||||||
'pos' => 90,
|
'pos' => 90,
|
||||||
) ;
|
);
|
||||||
|
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** 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
|
||||||
*/
|
*/
|
||||||
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 (! $this->_update_one($a['url'], $a['user'], $a['password'], $a['email'], $a['schedule'], $a['id']) ) {
|
}
|
||||||
$ok=false;
|
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'])) {
|
||||||
|
$ok = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
||||||
*/
|
*/
|
||||||
function delete_one($id) {
|
function delete_one($id) {
|
||||||
global $db,$err,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("cron","delete_one");
|
$err->log("cron", "delete_one");
|
||||||
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
|
||||||
*/
|
*/
|
||||||
private function _update_one($url, $user, $password, $email, $schedule, $id=null) {
|
private function _update_one($url, $user, $password, $email, $schedule, $id = null) {
|
||||||
global $db,$err,$quota,$cuid;
|
global $db, $err, $quota, $cuid;
|
||||||
$err->log("cron","update_one");
|
$err->log("cron", "update_one");
|
||||||
|
|
||||||
if (empty($url) && !is_null($id)) {
|
if (empty($url) && !is_null($id)) {
|
||||||
return $this->delete_one($id);
|
return $this->delete_one($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(filter_var($url,FILTER_VALIDATE_URL)===false){
|
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
|
||||||
$err->raise("cron",_("URL not valid"));
|
$err->raise("cron", _("URL not valid"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$url=urlencode($url);
|
$url = urlencode($url);
|
||||||
$user=urlencode($user);
|
$user = urlencode($user);
|
||||||
if (empty($user)) $password='';
|
if (empty($user)) {
|
||||||
$password=urlencode($password);
|
$password = '';
|
||||||
|
}
|
||||||
|
$password = urlencode($password);
|
||||||
|
|
||||||
//@todo remove checkmail cf functions.php
|
//@todo remove checkmail cf functions.php
|
||||||
if (!empty($email) && ! checkmail($email) == 0 ){
|
if (!empty($email) && !checkmail($email) == 0) {
|
||||||
$err->raise("cron",_("Email address is not valid"));
|
$err->raise("cron", _("Email address is not valid"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$email = urlencode($email);
|
||||||
|
if (!$this->valid_schedule($schedule)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$email=urlencode($email);
|
|
||||||
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");
|
||||||
if ( $q["u"] >= $q["t"] ) {
|
if ($q["u"] >= $q["t"]) {
|
||||||
$err->raise("cron",_("You quota of cron entries is over. You cannot create more cron entries"));
|
$err->raise("cron", _("You quota of cron entries is over. You cannot create more cron entries"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else { // if not a new insert, check the $cuid
|
} else { // if not a new insert, check the $cuid
|
||||||
$db->query("SELECT uid FROM cron WHERE id = $id;");
|
$db->query("SELECT uid FROM cron WHERE id = $id;");
|
||||||
if (! $db->next_record()) {
|
if (!$db->next_record()) {
|
||||||
return "false";
|
return "false";
|
||||||
} // return false if pb
|
} // return false if pb
|
||||||
if ( $db->f('uid') != $cuid ) {
|
if ($db->f('uid') != $cuid) {
|
||||||
$err->raise("cron",_("Identity problem"));
|
$err->raise("cron", _("Identity problem"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,37 +172,43 @@ 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) {
|
||||||
$r=false;
|
return false;
|
||||||
foreach ($this->schedule() as $cs ) {
|
}
|
||||||
if ($cs['unit'] == $s) return true;
|
$r = false;
|
||||||
|
foreach ($this->schedule() as $cs) {
|
||||||
|
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() {
|
||||||
global $cuid,$db,$err;
|
global $cuid, $db, $err;
|
||||||
$err->log("cron","alternc_get_quota");
|
$err->log("cron", "alternc_get_quota");
|
||||||
$q=Array("name"=>"cron", "description"=>_("Scheduled tasks"), "used"=>0);
|
$q = Array("name" => "cron", "description" => _("Scheduled tasks"), "used" => 0);
|
||||||
$db->query("select count(*) as cnt from cron where uid = $cuid;");
|
$db->query("select count(*) as cnt from cron where uid = $cuid;");
|
||||||
if ($db->next_record()) {
|
if ($db->next_record()) {
|
||||||
$q['used']=$db->f('cnt');
|
$q['used'] = $db->f('cnt');
|
||||||
}
|
}
|
||||||
return $q;
|
return $q;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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,27 +216,32 @@ 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://") {
|
||||||
$u=array(
|
$u = array(
|
||||||
"url" => $db->Record["url"],
|
"url" => $db->Record["url"],
|
||||||
"id" => $db->Record["id"], "email" =>$db->Record["email"],
|
"id" => $db->Record["id"], "email" => $db->Record["email"],
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($db->Record["user"] && $db->Record["password"]) {
|
if ($db->Record["user"] && $db->Record["password"]) {
|
||||||
$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"])
|
||||||
$urllist[]=$u;
|
echo "Will run cron :\n" . print_r($u, true) . "\n";
|
||||||
|
$urllist[] = $u;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($urllist)) { // nothing to do :
|
if (empty($urllist)) { // nothing to do :
|
||||||
|
@ -226,39 +249,39 @@ class m_cron {
|
||||||
}
|
}
|
||||||
|
|
||||||
// cron_callback($url, $content, $curlobj) will be called at the end of each http call.
|
// cron_callback($url, $content, $curlobj) will be called at the end of each http call.
|
||||||
$this->rolling_curl($urllist, array("m_cron","cron_callback"));
|
$this->rolling_curl($urllist, array("m_cron", "cron_callback"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
/**
|
||||||
* 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"])) {
|
||||||
$id=intval($url["id"]);
|
return; // not normal...
|
||||||
|
}
|
||||||
|
$id = intval($url["id"]);
|
||||||
|
|
||||||
if ($curl["http_code"]==200) {
|
if ($curl["http_code"] == 200) {
|
||||||
$ok=true;
|
$ok = true;
|
||||||
} else {
|
} else {
|
||||||
$ok=false;
|
$ok = false;
|
||||||
}
|
}
|
||||||
if (isset($url["email"]) && $url["email"] && $content) {
|
if (isset($url["email"]) && $url["email"] && $content) {
|
||||||
if (!mail($url["email"],"AlternC Cron #$id - Report ".date("r"),"Please find below the stdout content produced by your cron task.\n------------------------------------------------------------\n\n".$content,"From: postmaster@$L_FQDN")) {
|
if (!mail($url["email"], "AlternC Cron #$id - Report " . date("r"), "Please find below the stdout content produced by your cron task.\n------------------------------------------------------------\n\n" . $content, "From: postmaster@$L_FQDN")) {
|
||||||
echo "Error sending mail for cron #$id to address '".$url["email"]."'\n";
|
echo "Error sending mail for cron #$id to address '" . $url["email"] . "'\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// now schedule it for next run:
|
// now schedule it for next run:
|
||||||
$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,66 +311,82 @@ 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"]) {
|
||||||
curl_setopt_array($ch,$options);
|
echo "URL: " . $urls[$i]["url"] . "\n";
|
||||||
|
}
|
||||||
|
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 {
|
||||||
// request failed. add error handling.
|
// request failed. add error handling.
|
||||||
$output="";
|
$output = "";
|
||||||
}
|
}
|
||||||
// request terminated. process output using the callback function.
|
// request terminated. process output using the callback function.
|
||||||
// Pass the url array to the callback, so we need to search it
|
// Pass the url array to the callback, so we need to search it
|
||||||
foreach($urls as $url) {
|
foreach ($urls as $url) {
|
||||||
if ($url["url"]==$info["url"]) {
|
if ($url["url"] == $info["url"]) {
|
||||||
call_user_func($callback,$url,$output,$info);
|
call_user_func($callback, $url, $output, $info);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is more: start a new request
|
// If there is more: start a new request
|
||||||
// (it's important to do this before removing the old one)
|
// (it's important to do this before removing the old one)
|
||||||
if ($i<count($urls)) {
|
if ($i < count($urls)) {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
$options[CURLOPT_URL] = $urls[$i++]; // increment i
|
$options[CURLOPT_URL] = $urls[$i++]; // increment i
|
||||||
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
|
||||||
|
|
||||||
|
@ -17,41 +18,44 @@
|
||||||
Original Author of file: Camille Lafitte
|
Original Author of file: Camille Lafitte
|
||||||
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 $status=false;
|
|
||||||
var $nb_sql_query=0;
|
|
||||||
var $tps_sql_query=0;
|
|
||||||
var $generation_started=null;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
var $infos = "";
|
||||||
|
var $status = false;
|
||||||
|
var $nb_sql_query = 0;
|
||||||
|
var $tps_sql_query = 0;
|
||||||
|
var $generation_started = null;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Constructor
|
/** Constructor
|
||||||
*/
|
*/
|
||||||
function m_debug_alternc() {
|
function m_debug_alternc() {
|
||||||
if ( isset($_COOKIE['alternc_debugme']) && $_COOKIE['alternc_debugme'] ) {
|
if (isset($_COOKIE['alternc_debugme']) && $_COOKIE['alternc_debugme']) {
|
||||||
$this->status=true;
|
$this->status = true;
|
||||||
ini_set('display_errors', '1');
|
ini_set('display_errors', '1');
|
||||||
}
|
}
|
||||||
$this->nb_sql_query=0;
|
$this->nb_sql_query = 0;
|
||||||
$this->tps_sql_query=0;
|
$this->tps_sql_query = 0;
|
||||||
$this->generation_started=microtime(true);
|
$this->generation_started = microtime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function activate() {
|
function activate() {
|
||||||
setcookie('alternc_debugme','1', time()+3600); // expire in 1 hour
|
setcookie('alternc_debugme', '1', time() + 3600); // expire in 1 hour
|
||||||
$this->status="";
|
$this->status = "";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function desactivate() {
|
function desactivate() {
|
||||||
setcookie('alternc_debugme','0');
|
setcookie('alternc_debugme', '0');
|
||||||
$this->status=false;
|
$this->status = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -71,7 +79,7 @@ class m_debug_alternc {
|
||||||
echo "<pre>";
|
echo "<pre>";
|
||||||
echo "+++ BEGIN Debug Mode+++\n";
|
echo "+++ BEGIN Debug Mode+++\n";
|
||||||
echo "Total generation time : $generation_time ms\n";
|
echo "Total generation time : $generation_time ms\n";
|
||||||
print_r("\n--- Total SQL Query : ".$this->nb_sql_query." req / ".$this->tps_sql_query." ms ---\n");
|
print_r("\n--- Total SQL Query : " . $this->nb_sql_query . " req / " . $this->tps_sql_query . " ms ---\n");
|
||||||
print_r($this->infos);
|
print_r($this->infos);
|
||||||
echo "\n\n--- GET ---\n";
|
echo "\n\n--- GET ---\n";
|
||||||
print_r($_GET);
|
print_r($_GET);
|
||||||
|
@ -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,10 +1916,10 @@ 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 = "";
|
||||||
foreach ($this->domains as $d) {
|
foreach ($this->domains as $d) {
|
||||||
$str.= " <domaines>\n";
|
$str.= " <domaines>\n";
|
||||||
$str.=" <nom>" . $d . "</nom>\n";
|
$str.=" <nom>" . $d . "</nom>\n";
|
||||||
|
@ -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,12 +2177,14 @@ 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;
|
||||||
}
|
}
|
||||||
$tmp[$sub['fqdn']]++;
|
$tmp[$sub['fqdn']] ++;
|
||||||
if ($tmp[$sub['fqdn']] >= 2) {
|
if ($tmp[$sub['fqdn']] >= 2) {
|
||||||
$errors[$sub['fqdn']] = sprintf(_("Problem on %s: there is more than 1 web configuration going to be generated for this sub-domain."), $sub['fqdn']);
|
$errors[$sub['fqdn']] = sprintf(_("Problem on %s: there is more than 1 web configuration going to be generated for this sub-domain."), $sub['fqdn']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
@ -18,34 +19,35 @@
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
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.
|
||||||
*
|
*
|
||||||
* <p>Cette classe gère les erreurs qui peuvent apparaitre lors d'appels
|
* <p>Cette classe gère les erreurs qui peuvent apparaitre lors d'appels
|
||||||
* à l'API d'AlternC. Ces erreurs sont stockées sous la forme de 2 nombres
|
* à l'API d'AlternC. Ces erreurs sont stockées sous la forme de 2 nombres
|
||||||
* (Classe ID et Numéro d'erreur) ainsi qu'un texte facultatif associé.
|
* (Classe ID et Numéro d'erreur) ainsi qu'un texte facultatif associé.
|
||||||
* Des textes d'erreurs localisés sont aussi disponibles.</p>
|
* Des textes d'erreurs localisés sont aussi disponibles.</p>
|
||||||
* <p>Cette classe se charge aussi d'insérer les appels à l'API d'AlternC
|
* <p>Cette classe se charge aussi d'insérer les appels à l'API d'AlternC
|
||||||
* dans les logs du système dans /var/log/alternc/bureau.log
|
* dans les logs du système dans /var/log/alternc/bureau.log
|
||||||
* </p>
|
* </p>
|
||||||
* Copyleft {@link http://alternc.net/ AlternC Team}
|
* Copyleft {@link http://alternc.net/ AlternC Team}
|
||||||
*
|
*
|
||||||
* @copyright AlternC-Team 2002-11-01 http://alternc.net/
|
* @copyright AlternC-Team 2002-11-01 http://alternc.net/
|
||||||
*/
|
*/
|
||||||
class m_err {
|
class m_err {
|
||||||
|
|
||||||
/** Numero de classe d'erreur actuelle */
|
/** Numero de classe d'erreur actuelle */
|
||||||
var $clsid=0;
|
var $clsid = 0;
|
||||||
|
|
||||||
/** Dernière erreur enregistrée par la classe */
|
/** Dernière erreur enregistrée par la classe */
|
||||||
var $error=0;
|
var $error = 0;
|
||||||
|
|
||||||
/** Paramètre chaine eventuellement associé à la dernière erreur */
|
/** Paramètre chaine eventuellement associé à la dernière erreur */
|
||||||
var $param="";
|
var $param = "";
|
||||||
|
|
||||||
/** Emplacement du fichier de logs d'AlternC */
|
/** Emplacement du fichier de logs d'AlternC */
|
||||||
var $logfile="/var/log/alternc/bureau.log";
|
var $logfile = "/var/log/alternc/bureau.log";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Leve une erreur, signale celle-ci dans les logs et stocke le code erreur
|
* Leve une erreur, signale celle-ci dans les logs et stocke le code erreur
|
||||||
|
@ -61,19 +63,19 @@ class m_err {
|
||||||
* @return boolean TRUE si l'erreur est connue, FALSE sinon.
|
* @return boolean TRUE si l'erreur est connue, FALSE sinon.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function raise($clsid,$error,$param="") {
|
function raise($clsid, $error, $param = "") {
|
||||||
/* Leve une exception. Si elle existe, sinon, stocke un message d'erreur sur erreur ...*/
|
/* Leve une exception. Si elle existe, sinon, stocke un message d'erreur sur erreur ... */
|
||||||
if (_("err_".$clsid."_".$error)!="err_".$clsid."_".$error || is_string($error)) {
|
if (_("err_" . $clsid . "_" . $error) != "err_" . $clsid . "_" . $error || is_string($error)) {
|
||||||
$this->clsid=$clsid;
|
$this->clsid = $clsid;
|
||||||
$this->error=$error;
|
$this->error = $error;
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$this->param=array_slice($args, 2);
|
$this->param = array_slice($args, 2);
|
||||||
$this->logerr();
|
$this->logerr();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$this->clsid="err";
|
$this->clsid = "err";
|
||||||
$this->error=1;
|
$this->error = 1;
|
||||||
$this->param="Error # $error in Class $clsid, Value is $param. (sorry, no text for this error in your language at the moment)";
|
$this->param = "Error # $error in Class $clsid, Value is $param. (sorry, no text for this error in your language at the moment)";
|
||||||
$this->logerr();
|
$this->logerr();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -92,10 +94,10 @@ class m_err {
|
||||||
function errstr() {
|
function errstr() {
|
||||||
if (is_string($this->error)) {
|
if (is_string($this->error)) {
|
||||||
// new way of handling errors: message directly in the class
|
// new way of handling errors: message directly in the class
|
||||||
$str = $this->error."\n";
|
$str = $this->error . "\n";
|
||||||
} else {
|
} else {
|
||||||
// old way: message in the locales files (ugly)
|
// old way: message in the locales files (ugly)
|
||||||
$str = _("err_".$this->clsid."_".$this->error)."\n";
|
$str = _("err_" . $this->clsid . "_" . $this->error) . "\n";
|
||||||
}
|
}
|
||||||
$args = $this->param;
|
$args = $this->param;
|
||||||
if (is_array($args)) {
|
if (is_array($args)) {
|
||||||
|
@ -117,7 +119,7 @@ class m_err {
|
||||||
*/
|
*/
|
||||||
function logerr() {
|
function logerr() {
|
||||||
global $mem;
|
global $mem;
|
||||||
@file_put_contents($this->logfile, date("d/m/Y H:i:s")." - ERROR - ".$mem->user["login"]." - ".$this->errstr(), FILE_APPEND );
|
@file_put_contents($this->logfile, date("d/m/Y H:i:s") . " - ERROR - " . $mem->user["login"] . " - " . $this->errstr(), FILE_APPEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,11 +134,11 @@ class m_err {
|
||||||
* @return boolean TRUE si le log a été ajouté, FALSE sinon
|
* @return boolean TRUE si le log a été ajouté, FALSE sinon
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
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,29 +1,35 @@
|
||||||
<?php
|
<?php
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/** Constructor
|
/* --------------------------------------------------------------------------- */
|
||||||
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,
|
/** Constructor
|
||||||
presentes dans les classes concernées.
|
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,
|
||||||
|
presentes dans les classes concernées.
|
||||||
*/
|
*/
|
||||||
Class m_export {
|
Class m_export {
|
||||||
|
|
||||||
function m_export() {
|
function m_export() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function export_conf(){
|
function export_conf() {
|
||||||
global $hooks;
|
global $hooks;
|
||||||
$config=$hooks->invoke('alternc_export_conf');
|
$config = $hooks->invoke('alternc_export_conf');
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** le repertoire de base est passé en paramettre puis en construit une arborescence de la forme
|
/** le repertoire de base est passé en paramettre puis en construit une arborescence de la forme
|
||||||
<dir>/<user>/<timestamp/ qui contiendra les dossier de dump html et sql
|
<dir>/<user>/<timestamp/ qui contiendra les dossier de dump html et sql
|
||||||
*/
|
*/
|
||||||
function export_data($dir){
|
function export_data($dir) {
|
||||||
global $hooks, $mem;
|
global $hooks, $mem;
|
||||||
|
|
||||||
|
|
||||||
$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
|
||||||
|
@ -21,31 +22,32 @@
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Purpose of file: Manage FTP accounts
|
Purpose of file: Manage FTP accounts
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
function m_ftp() {
|
function m_ftp() {
|
||||||
global $L_FQDN;
|
global $L_FQDN;
|
||||||
$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)
|
||||||
*/
|
*/
|
||||||
function alternc_password_policy() {
|
function alternc_password_policy() {
|
||||||
return array("ftp"=>"FTP accounts");
|
return array("ftp" => "FTP accounts");
|
||||||
}
|
}
|
||||||
|
|
||||||
function hook_menu() {
|
function hook_menu() {
|
||||||
|
@ -58,11 +60,10 @@ class m_ftp {
|
||||||
'link' => 'toggle',
|
'link' => 'toggle',
|
||||||
'pos' => 60,
|
'pos' => 60,
|
||||||
'links' => array(),
|
'links' => array(),
|
||||||
) ;
|
);
|
||||||
|
|
||||||
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",
|
||||||
|
@ -70,9 +71,8 @@ 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"
|
||||||
);
|
);
|
||||||
|
@ -85,122 +85,130 @@ class m_ftp {
|
||||||
// in authip for more informations
|
// in authip for more informations
|
||||||
function authip_class() {
|
function authip_class() {
|
||||||
$c = Array();
|
$c = Array();
|
||||||
$c['name']="FTP";
|
$c['name'] = "FTP";
|
||||||
$c['protocol']="ftp";
|
$c['protocol'] = "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)) {
|
||||||
foreach ($this->get_list() as $v ) {
|
return $c;
|
||||||
$c['values'][$v['id']]=$v['login'];
|
}
|
||||||
|
foreach ($this->get_list() as $v) {
|
||||||
|
$c['values'][$v['id']] = $v['login'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $c;
|
return $c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch enabled status of an account
|
// Switch enabled status of an account
|
||||||
function switch_enabled($id,$status=null) {
|
function switch_enabled($id, $status = null) {
|
||||||
global $cuid, $db, $err;
|
global $cuid, $db, $err;
|
||||||
if (! $jj = $this->get_ftp_details($id)) {
|
if (!$jj = $this->get_ftp_details($id)) {
|
||||||
$err->raise('ftp', _("This account do not exist or is not of this account"));
|
$err->raise('ftp', _("This account do not exist or is not of this account"));
|
||||||
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
|
||||||
$status = ($status?'true':'false');
|
$status = ($status ? 'true' : 'false');
|
||||||
|
|
||||||
if ( ! $db->query("UPDATE ftpusers SET enabled = $status WHERE uid = '$cuid' AND id = '$id' ;") ) {
|
if (!$db->query("UPDATE ftpusers SET enabled = $status WHERE uid = '$cuid' AND id = '$id' ;")) {
|
||||||
$err->raise('ftp', _("Error during update"));
|
$err->raise('ftp', _("Error during update"));
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true ;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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;");
|
||||||
if ($db->num_rows()) {
|
if ($db->num_rows()) {
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$r[]=array(
|
$r[] = array(
|
||||||
"id"=>$db->f("id"),
|
"id" => $db->f("id"),
|
||||||
"login"=>$db->f("name"),
|
"login" => $db->f("name"),
|
||||||
"enabled"=>$db->f("enabled"),
|
"enabled" => $db->f("enabled"),
|
||||||
//"dir"=>$match[1]
|
//"dir"=>$match[1]
|
||||||
"dir"=>$db->f("homedir")
|
"dir" => $db->f("homedir")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
} else {
|
} else {
|
||||||
$err->raise("ftp",_("No FTP account found"));
|
$err->raise("ftp", _("No FTP account found"));
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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) {
|
||||||
global $db,$err,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("ftp","get_ftp_details",$id);
|
$err->log("ftp", "get_ftp_details", $id);
|
||||||
$r=array();
|
$r = array();
|
||||||
$db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid='$cuid' AND id='$id';");
|
$db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid='$cuid' AND id='$id';");
|
||||||
if ($db->num_rows()) {
|
if ($db->num_rows()) {
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
|
|
||||||
$regexp="/^".preg_quote(getuserpath(),"/")."\/(.*)$/";
|
$regexp = "/^" . preg_quote(getuserpath(), "/") . "\/(.*)$/";
|
||||||
preg_match($regexp, $db->f("homedir"),$match);
|
$match = array();
|
||||||
|
preg_match($regexp, $db->f("homedir"), $match);
|
||||||
|
|
||||||
$lg=explode("_",$db->f("name"));
|
$lg = explode("_", $db->f("name"));
|
||||||
if ((!is_array($lg)) || (count($lg)!=2)) {
|
if ((!is_array($lg)) || (count($lg) != 2)) {
|
||||||
$lg[0]=$db->f("name");
|
$lg[0] = $db->f("name");
|
||||||
$lg[1]="";
|
$lg[1] = "";
|
||||||
}
|
}
|
||||||
$r[]=array(
|
$r[] = array(
|
||||||
"id"=>$db->f("id"),
|
"id" => $db->f("id"),
|
||||||
"prefixe"=> $lg[0],
|
"prefixe" => $lg[0],
|
||||||
"login"=>$lg[1],
|
"login" => $lg[1],
|
||||||
"dir"=>$match[1],
|
"dir" => $match[1],
|
||||||
"enabled"=>$db->f("enabled")
|
"enabled" => $db->f("enabled")
|
||||||
);
|
);
|
||||||
return $r;
|
return $r;
|
||||||
} else {
|
} else {
|
||||||
$err->raise("ftp",_("This FTP account does not exist"));
|
$err->raise("ftp", _("This FTP account does not exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** 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.
|
||||||
*/
|
*/
|
||||||
function prefix_list() {
|
function prefix_list() {
|
||||||
global $db,$mem,$cuid;
|
global $db, $mem, $cuid;
|
||||||
$r=array();
|
$r = array();
|
||||||
$r[]=$mem->user["login"];
|
$r[] = $mem->user["login"];
|
||||||
$db->query("SELECT domaine FROM domaines WHERE compte='$cuid' ORDER BY domaine;");
|
$db->query("SELECT domaine FROM domaines WHERE compte='$cuid' ORDER BY domaine;");
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$r[]=$db->f("domaine");
|
$r[] = $db->f("domaine");
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
@ -215,16 +223,16 @@ class m_ftp {
|
||||||
|
|
||||||
// special chars and the max numbers of them allowed
|
// special chars and the max numbers of them allowed
|
||||||
// to be able to give a specific error
|
// to be able to give a specific error
|
||||||
$vv = array('_'=>'1', ' '=>0);
|
$vv = array('_' => '1', ' ' => 0);
|
||||||
foreach ($vv as $k=>$n) {
|
foreach ($vv as $k => $n) {
|
||||||
if (substr_count($l, $k) > $n ) { // if there is more than $n $k
|
if (substr_count($l, $k) > $n) { // if there is more than $n $k
|
||||||
$err->raise('ftp', sprintf(_("FTP login is incorrect: too many '%s'"), $k));
|
$err->raise('ftp', sprintf(_("FTP login is incorrect: too many '%s'"), $k));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicitly look for only allowed chars
|
// Explicitly look for only allowed chars
|
||||||
if ( ! preg_match("/^[A-Za-z0-9]+[A-Za-z0-9_\.\-]*$/", $l) ) {
|
if (!preg_match("/^[A-Za-z0-9]+[A-Za-z0-9_\.\-]*$/", $l)) {
|
||||||
$err->raise('ftp', _("FTP login is incorrect"));
|
$err->raise('ftp', _("FTP login is incorrect"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -232,97 +240,107 @@ 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();
|
||||||
if (!$db->f("cnt")) {
|
if (!$db->f("cnt")) {
|
||||||
$err->raise("ftp",_("This FTP account does not exist"));
|
$err->raise("ftp", _("This FTP account does not exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$dir=$bro->convertabsolute($dir);
|
$dir = $bro->convertabsolute($dir);
|
||||||
if (substr($dir,0,1)=="/") {
|
if (substr($dir, 0, 1) == "/") {
|
||||||
$dir=substr($dir,1);
|
$dir = substr($dir, 1);
|
||||||
}
|
}
|
||||||
$r=$this->prefix_list();
|
$r = $this->prefix_list();
|
||||||
if (!in_array($prefixe,$r)) {
|
if (!in_array($prefixe, $r)) {
|
||||||
$err->raise("ftp",_("The chosen prefix is not allowed"));
|
$err->raise("ftp", _("The chosen prefix is not allowed"));
|
||||||
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 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")) {
|
||||||
$err->raise("ftp",_("This FTP account already exists"));
|
$err->raise("ftp", _("This FTP account already exists"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$absolute=getuserpath()."/$dir";
|
$absolute = getuserpath() . "/$dir";
|
||||||
if (!file_exists($absolute)) {
|
if (!file_exists($absolute)) {
|
||||||
system("/bin/mkdir -p $absolute");
|
system("/bin/mkdir -p $absolute");
|
||||||
}
|
}
|
||||||
if (!is_dir($absolute)) {
|
if (!is_dir($absolute)) {
|
||||||
$err->raise("ftp",_("The directory cannot be created"));
|
$err->raise("ftp", _("The directory cannot be created"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (trim($pass)) {
|
if (trim($pass)) {
|
||||||
|
|
||||||
// Check this password against the password policy using common API :
|
// Check this password against the password policy using common API :
|
||||||
if (is_callable(array($admin,"checkPolicy"))) {
|
if (is_callable(array($admin, "checkPolicy"))) {
|
||||||
if (!$admin->checkPolicy("ftp",$full_login,$pass)) {
|
if (!$admin->checkPolicy("ftp", $full_login, $pass)) {
|
||||||
return false; // The error has been raised by checkPolicy()
|
return false; // The error has been raised by checkPolicy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$encrypted_password = _md5cr($pass,strrev(microtime(true)));
|
$encrypted_password = _md5cr($pass, strrev(microtime(true)));
|
||||||
$db->query("UPDATE ftpusers SET name='".$full_login."', password='', encrypted_password='$encrypted_password', homedir='$absolute', uid='$cuid' WHERE id='$id';");
|
$db->query("UPDATE ftpusers SET name='" . $full_login . "', password='', encrypted_password='$encrypted_password', homedir='$absolute', uid='$cuid' WHERE id='$id';");
|
||||||
} else {
|
} else {
|
||||||
$db->query("UPDATE ftpusers SET name='".$full_login."', homedir='$absolute', uid='$cuid' WHERE id='$id';");
|
$db->query("UPDATE ftpusers SET name='" . $full_login . "', homedir='$absolute', uid='$cuid' WHERE id='$id';");
|
||||||
}
|
}
|
||||||
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;
|
||||||
$err->log("ftp","delete_ftp",$id);
|
$err->log("ftp", "delete_ftp", $id);
|
||||||
$db->query("SELECT name FROM ftpusers WHERE id='$id' and uid='$cuid';");
|
$db->query("SELECT name FROM ftpusers WHERE id='$id' and uid='$cuid';");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$name=$db->f("name");
|
$name = $db->f("name");
|
||||||
if (!$name) {
|
if (!$name) {
|
||||||
$err->raise("ftp",_("This FTP account does not exist"));
|
$err->raise("ftp", _("This FTP account does not exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db->query("DELETE FROM ftpusers WHERE id='$id'");
|
$db->query("DELETE FROM ftpusers WHERE id='$id'");
|
||||||
|
@ -330,77 +348,85 @@ 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) == "/") {
|
||||||
$dir=substr($dir,1);
|
$dir = substr($dir, 1);
|
||||||
}
|
}
|
||||||
$r=$this->prefix_list();
|
$r = $this->prefix_list();
|
||||||
if (empty($pass)) {
|
if (empty($pass)) {
|
||||||
$err->raise("ftp",_("Password can't be empty"));
|
$err->raise("ftp", _("Password can't be empty"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!in_array($prefixe,$r) || $prefixe=="") {
|
if (!in_array($prefixe, $r) || $prefixe == "") {
|
||||||
$err->raise("ftp",_("The chosen prefix is not allowed"));
|
$err->raise("ftp", _("The chosen prefix is not allowed"));
|
||||||
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;
|
||||||
$db->query("SELECT count(*) AS cnt FROM ftpusers WHERE name='".$full_login."'");
|
}
|
||||||
|
if (!$this->check_login($full_login)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$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")) {
|
||||||
$err->raise("ftp",_("This FTP account already exists"));
|
$err->raise("ftp", _("This FTP account already exists"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db->query("SELECT login FROM membres WHERE uid='$cuid';");
|
$db->query("SELECT login FROM membres WHERE uid='$cuid';");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$absolute=getuserpath()."/$dir";
|
$absolute = getuserpath() . "/$dir";
|
||||||
if (!file_exists($absolute)) {
|
if (!file_exists($absolute)) {
|
||||||
system("/bin/mkdir -p $absolute"); // FIXME replace with action
|
system("/bin/mkdir -p $absolute"); // FIXME replace with action
|
||||||
}
|
}
|
||||||
if (!is_dir($absolute)) {
|
if (!is_dir($absolute)) {
|
||||||
$err->raise("ftp",_("The directory cannot be created"));
|
$err->raise("ftp", _("The directory cannot be created"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check this password against the password policy using common API :
|
// Check this password against the password policy using common API :
|
||||||
if (is_callable(array($admin,"checkPolicy"))) {
|
if (is_callable(array($admin, "checkPolicy"))) {
|
||||||
if (!$admin->checkPolicy("ftp",$full_login,$pass)) {
|
if (!$admin->checkPolicy("ftp", $full_login, $pass)) {
|
||||||
return false; // The error has been raised by checkPolicy()
|
return false; // The error has been raised by checkPolicy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($quota->cancreate("ftp")) {
|
if ($quota->cancreate("ftp")) {
|
||||||
$encrypted_password = _md5cr($pass,strrev(microtime(true)));
|
$encrypted_password = _md5cr($pass, strrev(microtime(true)));
|
||||||
$db->query("INSERT INTO ftpusers (name,password, encrypted_password,homedir,uid) VALUES ('".$full_login."', '', '$encrypted_password', '$absolute', '$cuid')");
|
$db->query("INSERT INTO ftpusers (name,password, encrypted_password,homedir,uid) VALUES ('" . $full_login . "', '', '$encrypted_password', '$absolute', '$cuid')");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$err->raise("ftp",_("Your FTP account quota is over. You cannot create more ftp accounts"));
|
$err->raise("ftp", _("Your FTP account quota is over. You cannot create more ftp accounts"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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) == "/") {
|
||||||
$db->query("SELECT id FROM ftpusers WHERE homedir='".getuserpath()."/$dir';");
|
$dir = substr($dir, 1);
|
||||||
|
}
|
||||||
|
$db->query("SELECT id FROM ftpusers WHERE homedir='" . getuserpath() . "/$dir';");
|
||||||
if ($db->num_rows()) {
|
if ($db->num_rows()) {
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
return $db->f("id");
|
return $db->f("id");
|
||||||
|
@ -410,29 +436,32 @@ 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) {
|
||||||
global $db,$err,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("ftp","alternc_del_domain",$dom);
|
$err->log("ftp", "alternc_del_domain", $dom);
|
||||||
$db->query("DELETE FROM ftpusers WHERE uid='$cuid' AND ( name LIKE '$dom\_%' OR name LIKE '$dom') ");
|
$db->query("DELETE FROM ftpusers WHERE uid='$cuid' AND ( name LIKE '$dom\_%' OR name LIKE '$dom') ");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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() {
|
||||||
global $db,$err,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("ftp","alternc_del_member");
|
$err->log("ftp", "alternc_del_member");
|
||||||
$db->query("DELETE FROM ftpusers WHERE uid='$cuid'");
|
$db->query("DELETE FROM ftpusers WHERE uid='$cuid'");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -440,39 +469,39 @@ class m_ftp {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function hook_quota_get() {
|
function hook_quota_get() {
|
||||||
global $db,$err,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("ftp","getquota");
|
$err->log("ftp", "getquota");
|
||||||
$q=Array("name"=>"ftp", "description"=>_("FTP accounts"), "used"=>0);
|
$q = Array("name" => "ftp", "description" => _("FTP accounts"), "used" => 0);
|
||||||
$db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE uid='$cuid'");
|
$db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE uid='$cuid'");
|
||||||
if ($db->next_record()) {
|
if ($db->next_record()) {
|
||||||
$q['used']=$db->f("cnt");
|
$q['used'] = $db->f("cnt");
|
||||||
}
|
}
|
||||||
return $q;
|
return $q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exporte toutes les informations ftp du compte AlternC
|
* Exporte toutes les informations ftp du compte AlternC
|
||||||
* @access private
|
* @access private
|
||||||
* EXPERIMENTAL 'sid' function ;)
|
* EXPERIMENTAL 'sid' function ;)
|
||||||
*/
|
*/
|
||||||
function alternc_export_conf() {
|
function alternc_export_conf() {
|
||||||
global $db,$err;
|
global $db, $err;
|
||||||
$err->log("ftp","export");
|
$err->log("ftp", "export");
|
||||||
$f=$this->get_list();
|
$f = $this->get_list();
|
||||||
$str=" <ftp>";
|
$str = " <ftp>";
|
||||||
foreach ($f as $d=>$v) {
|
foreach ($f as $d => $v) {
|
||||||
$str.=" <login>".($v["login"])."</login>\n";
|
$str.=" <login>" . ($v["login"]) . "</login>\n";
|
||||||
$str.=" <password>".($v["encrypted_password"])."</password>\n";
|
$str.=" <password>" . ($v["encrypted_password"]) . "</password>\n";
|
||||||
$str.=" <directory>".($v["dir"])."<directory>\n";
|
$str.=" <directory>" . ($v["dir"]) . "<directory>\n";
|
||||||
}
|
}
|
||||||
$str.=" </ftp>\n";
|
$str.=" </ftp>\n";
|
||||||
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
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Purpose of file: Manage hook system.
|
Purpose of file: Manage hook system.
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manage hooks.
|
* This class manage hooks.
|
||||||
|
@ -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.
|
||||||
|
@ -66,9 +69,9 @@ class m_hooks {
|
||||||
$val = array();
|
$val = array();
|
||||||
foreach ($classes as $c) {
|
foreach ($classes as $c) {
|
||||||
global $$c;
|
global $$c;
|
||||||
if ( method_exists($$c, $hname) ) {
|
if (method_exists($$c, $hname)) {
|
||||||
//$val[$$c]=call_user_func_array(array($$c,$hname), $hparam);
|
//$val[$$c]=call_user_func_array(array($$c,$hname), $hparam);
|
||||||
$val[$c]=call_user_func_array(array($$c,$hname), $hparam);
|
$val[$c] = call_user_func_array(array($$c, $hname), $hparam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,25 +79,26 @@ class m_hooks {
|
||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
* @param array $parameters parameters for the scripts
|
* @param array $parameters parameters for the scripts
|
||||||
* @return boolean TRUE
|
* @return boolean TRUE
|
||||||
*/
|
*/
|
||||||
function invoke_scripts($scripts, $parameters=array()) {
|
function invoke_scripts($scripts, $parameters = array()) {
|
||||||
|
|
||||||
// First, build the list of script we want to launch
|
// First, build the list of script we want to launch
|
||||||
$to_launch=array();
|
$to_launch = array();
|
||||||
if (is_file($scripts)) {
|
if (is_file($scripts)) {
|
||||||
if (is_executable($scripts)) {
|
if (is_executable($scripts)) {
|
||||||
$to_launch[]=$scripts;
|
$to_launch[] = $scripts;
|
||||||
}
|
}
|
||||||
} else if (is_dir($scripts)) {
|
} else if (is_dir($scripts)) {
|
||||||
foreach ( scandir($scripts) as $ccc ) {
|
foreach (scandir($scripts) as $ccc) {
|
||||||
if (is_file($ccc) && is_executable($ccc)) {
|
if (is_file($ccc) && is_executable($ccc)) {
|
||||||
$to_launch[]=$ccc;
|
$to_launch[] = $ccc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,13 +111,15 @@ class m_hooks {
|
||||||
$params = implode(" ", $parameters);
|
$params = implode(" ", $parameters);
|
||||||
|
|
||||||
// Launch !
|
// Launch !
|
||||||
foreach($to_launch as $fi) {
|
foreach ($to_launch as $fi) {
|
||||||
system($fi." ".$params);
|
system($fi . " " . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: return something more interesting than true
|
// TODO: return something more interesting than true
|
||||||
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 $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
@ -26,26 +27,25 @@
|
||||||
Original Author of file:
|
Original Author of file:
|
||||||
Purpose of file:
|
Purpose of file:
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class handle folder web restricted access through .htaccess/.htpassword
|
* This class handle folder web restricted access through .htaccess/.htpassword
|
||||||
* files.
|
* files.
|
||||||
*
|
*
|
||||||
* Copyleft {@link http://alternc.net/ AlternC Team}
|
* Copyleft {@link http://alternc.net/ AlternC Team}
|
||||||
*
|
*
|
||||||
* @copyright AlternC-Team 2002-11-01 http://alternc.org/
|
* @copyright AlternC-Team 2002-11-01 http://alternc.org/
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
|
@ -53,7 +53,7 @@ class m_hta {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function alternc_password_policy() {
|
function alternc_password_policy() {
|
||||||
return array("hta"=>"Protected folders passwords");
|
return array("hta" => "Protected folders passwords");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,12 +66,11 @@ class m_hta {
|
||||||
'ico' => 'images/password.png',
|
'ico' => 'images/password.png',
|
||||||
'link' => 'hta_list.php',
|
'link' => 'hta_list.php',
|
||||||
'pos' => 50,
|
'pos' => 50,
|
||||||
) ;
|
);
|
||||||
|
|
||||||
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,34 +83,34 @@ 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) {
|
||||||
$err->raise("hta",printf(_("The folder '%s' does not exist"),$dir));
|
$err->raise("hta", printf(_("The folder '%s' does not exist"), $dir));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!file_exists($absolute)) {
|
if (!file_exists($absolute)) {
|
||||||
@mkdir($absolute,00777);
|
@mkdir($absolute, 00777);
|
||||||
}
|
}
|
||||||
if (!file_exists("$absolute/.htaccess")) {
|
if (!file_exists("$absolute/.htaccess")) {
|
||||||
if (!@touch("$absolute/.htaccess")) {
|
if (!@touch("$absolute/.htaccess")) {
|
||||||
$err->raise("hta",_("File already exist"));
|
$err->raise("hta", _("File already exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$file = @fopen("$absolute/.htaccess","r+");
|
$file = @fopen("$absolute/.htaccess", "r+");
|
||||||
if (!$file) {
|
if (!$file) {
|
||||||
$err->raise("hta",_("File already exist"));
|
$err->raise("hta", _("File already exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fseek($file,0);
|
fseek($file, 0);
|
||||||
$param = "AuthUserFile \"$absolute/.htpasswd\"\nAuthName \""._("Restricted area")."\"\nAuthType Basic\nrequire valid-user\n";
|
$param = "AuthUserFile \"$absolute/.htpasswd\"\nAuthName \"" . _("Restricted area") . "\"\nAuthType Basic\nrequire valid-user\n";
|
||||||
fwrite($file, $param);
|
fwrite($file, $param);
|
||||||
fclose($file);
|
fclose($file);
|
||||||
}
|
}
|
||||||
if (!file_exists("$absolute/.htpasswd")) {
|
if (!file_exists("$absolute/.htpasswd")) {
|
||||||
if (!touch("$absolute/.htpasswd")) {
|
if (!touch("$absolute/.htpasswd")) {
|
||||||
$err->raise("hta",_("File already exist"));
|
$err->raise("hta", _("File already exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -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
|
||||||
*
|
*
|
||||||
|
@ -127,23 +125,24 @@ class m_hta {
|
||||||
* @global m_mem $mem
|
* @global m_mem $mem
|
||||||
* @return array Array containing user folder list
|
* @return array Array containing user folder list
|
||||||
*/
|
*/
|
||||||
function ListDir(){
|
function ListDir() {
|
||||||
global$err,$mem;
|
global$err, $mem;
|
||||||
$err->log("hta","listdir");
|
$err->log("hta", "listdir");
|
||||||
$sortie = array();
|
$sortie = array();
|
||||||
$absolute = ALTERNC_HTML."/".substr($mem->user["login"],0,1)."/".$mem->user["login"];
|
$absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"];
|
||||||
exec("find ".escapeshellarg($absolute)." -name .htpasswd|sort",$sortie);
|
exec("find " . escapeshellarg($absolute) . " -name .htpasswd|sort", $sortie);
|
||||||
if(!count($sortie)){
|
if (!count($sortie)) {
|
||||||
$err->raise("hta",_("No protected folder"));
|
$err->raise("hta", _("No protected folder"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$pattern = "/^".preg_quote(ALTERNC_HTML,"/")."\/.\/[^\/]*\/(.*)\/\.htpasswd/";
|
$pattern = "/^" . preg_quote(ALTERNC_HTML, "/") . "\/.\/[^\/]*\/(.*)\/\.htpasswd/";
|
||||||
|
|
||||||
$r = array();
|
$r = array();
|
||||||
for($i = 0;$i<count($sortie);$i++){
|
for ($i = 0; $i < count($sortie); $i++) {
|
||||||
preg_match($pattern,$sortie[$i],$matches);
|
$matches = array();
|
||||||
$tmpm = isset($matches[1])?'/'.$matches[1]:'';
|
preg_match($pattern, $sortie[$i], $matches);
|
||||||
$r[$i] = $tmpm."/";
|
$tmpm = isset($matches[1]) ? '/' . $matches[1] : '';
|
||||||
|
$r[$i] = $tmpm . "/";
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
@ -156,18 +155,17 @@ class m_hta {
|
||||||
* @param string $dir Folder to check
|
* @param string $dir Folder to check
|
||||||
* @return boolean If the folder is protected, or FALSE if it is not
|
* @return boolean If the folder is protected, or FALSE if it is not
|
||||||
*/
|
*/
|
||||||
function is_protected($dir){
|
function is_protected($dir) {
|
||||||
global $mem,$err;
|
global $mem, $err;
|
||||||
$err->log("hta","is_protected",$dir);
|
$err->log("hta", "is_protected", $dir);
|
||||||
$absolute = ALTERNC_HTML."/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/$dir";
|
$absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"] . "/$dir";
|
||||||
if (file_exists("$absolute/.htpasswd")){
|
if (file_exists("$absolute/.htpasswd")) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of login for a protected folder.
|
* Returns the list of login for a protected folder.
|
||||||
*
|
*
|
||||||
|
@ -177,15 +175,16 @@ class m_hta {
|
||||||
* @return array An array containing the list of logins from the .htpasswd file, or FALSE
|
* @return array An array containing the list of logins from the .htpasswd file, or FALSE
|
||||||
*/
|
*/
|
||||||
function get_hta_detail($dir) {
|
function get_hta_detail($dir) {
|
||||||
global $mem,$err;
|
global $mem, $err;
|
||||||
$err->log("hta","get_hta_detail");
|
$err->log("hta", "get_hta_detail");
|
||||||
$absolute = ALTERNC_HTML."/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/$dir";
|
$absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"] . "/$dir";
|
||||||
if (file_exists("$absolute/.htaccess")) {
|
if (file_exists("$absolute/.htaccess")) {
|
||||||
/* 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();
|
||||||
if (!$file) {
|
if (!$file) {
|
||||||
|
@ -193,18 +192,17 @@ class m_hta {
|
||||||
}
|
}
|
||||||
// TODO: Tester la validité du .htpasswd
|
// TODO: Tester la validité du .htpasswd
|
||||||
while (!feof($file)) {
|
while (!feof($file)) {
|
||||||
$s = fgets($file,1024);
|
$s = fgets($file, 1024);
|
||||||
$t = explode(":",$s);
|
$t = explode(":", $s);
|
||||||
if ($t[0]!=$s) {
|
if ($t[0] != $s) {
|
||||||
$res[$i] = $t[0];
|
$res[$i] = $t[0];
|
||||||
$i = $i+1;
|
$i = $i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose($file);
|
fclose($file);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unprotect a folder
|
* Unprotect a folder
|
||||||
*
|
*
|
||||||
|
@ -215,17 +213,17 @@ class m_hta {
|
||||||
* @param boolean $skip For testing purpose mainly, skips the full user path search
|
* @param boolean $skip For testing purpose mainly, skips the full user path search
|
||||||
* @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) {
|
||||||
$err->raise("hta",printf(("The folder '%s' does not exist"),$dir));
|
$err->raise("hta", printf(("The folder '%s' does not exist"), $dir));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$htaccess_file = "$dir/.htaccess";
|
$htaccess_file = "$dir/.htaccess";
|
||||||
if( !is_readable($htaccess_file)){
|
if (!is_readable($htaccess_file)) {
|
||||||
$err->raise("hta",printf(_("I cannot read the file '%s'"),$htaccess_file));
|
$err->raise("hta", printf(_("I cannot read the file '%s'"), $htaccess_file));
|
||||||
}
|
}
|
||||||
$fileLines = file($htaccess_file);
|
$fileLines = file($htaccess_file);
|
||||||
$patternList = array(
|
$patternList = array(
|
||||||
|
@ -235,39 +233,37 @@ class m_hta {
|
||||||
"require valid-user.*$"
|
"require valid-user.*$"
|
||||||
);
|
);
|
||||||
$count_lines = 0;
|
$count_lines = 0;
|
||||||
foreach($fileLines as $key => $line){
|
foreach ($fileLines as $key => $line) {
|
||||||
foreach ($patternList as $pattern) {
|
foreach ($patternList as $pattern) {
|
||||||
if(preg_match("/".$pattern."/", $line)){
|
if (preg_match("/" . $pattern . "/", $line)) {
|
||||||
$count_lines++;
|
$count_lines++;
|
||||||
unset($fileLines[$key]);
|
unset($fileLines[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If no changes
|
// If no changes
|
||||||
if( ! $count_lines ){
|
if (!$count_lines) {
|
||||||
$err->raise("hta",printf(_("Unexpected: No changes made to '%s'"),$htaccess_file));
|
$err->raise("hta", printf(_("Unexpected: No changes made to '%s'"), $htaccess_file));
|
||||||
}
|
}
|
||||||
// If file is empty, remove it
|
// If file is empty, remove it
|
||||||
if( !count($fileLines)){
|
if (!count($fileLines)) {
|
||||||
if( ! unlink( $htaccess_file)){
|
if (!unlink($htaccess_file)) {
|
||||||
$err->raise("hta",printf(_("I could not delete the file '%s'"),$htaccess_file));
|
$err->raise("hta", printf(_("I could not delete the file '%s'"), $htaccess_file));
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
file_put_contents($htaccess_file, implode("\n",$fileLines));
|
file_put_contents($htaccess_file, implode("\n", $fileLines));
|
||||||
}
|
}
|
||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a user to a protected folder
|
* Add a user to a protected folder
|
||||||
*
|
*
|
||||||
|
@ -281,61 +277,58 @@ class m_hta {
|
||||||
* @param string $dir The folder we add it to (relative to user root).
|
* @param string $dir The folder we add it to (relative to user root).
|
||||||
* @return boolean TRUE if the user has been added, or FALSE if an error occurred
|
* @return boolean TRUE if the user has been added, or FALSE if an error occurred
|
||||||
*/
|
*/
|
||||||
function add_user($user,$password,$dir) {
|
function add_user($user, $password, $dir) {
|
||||||
global $err, $bro, $admin;
|
global $err, $bro, $admin;
|
||||||
$err->log("hta","add_user",$user."/".$dir);
|
$err->log("hta", "add_user", $user . "/" . $dir);
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
$err->raise('hta',_("Please enter a user"));
|
$err->raise('hta', _("Please enter a user"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (empty($password)) {
|
if (empty($password)) {
|
||||||
$err->raise('hta',_("Please enter a password"));
|
$err->raise('hta', _("Please enter a password"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$absolute = $bro->convertabsolute($dir,0);
|
$absolute = $bro->convertabsolute($dir, 0);
|
||||||
if (!file_exists($absolute)) {
|
if (!file_exists($absolute)) {
|
||||||
$err->raise("hta",printf(("The folder '%s' does not exist"),$dir));
|
$err->raise("hta", printf(("The folder '%s' does not exist"), $dir));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// @todo delete cf!. functions.php checkloginemail definition
|
// @todo delete cf!. functions.php checkloginemail definition
|
||||||
if (checkloginmail($user)){
|
if (checkloginmail($user)) {
|
||||||
// Check this password against the password policy using common API :
|
// Check this password against the password policy using common API :
|
||||||
if (is_callable(array($admin,"checkPolicy"))) {
|
if (is_callable(array($admin, "checkPolicy"))) {
|
||||||
if (!$admin->checkPolicy("hta",$user,$password)) {
|
if (!$admin->checkPolicy("hta", $user, $password)) {
|
||||||
return false; // The error has been raised by checkPolicy()
|
return false; // The error has been raised by checkPolicy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = @fopen("$absolute/.htpasswd","a+");
|
$file = @fopen("$absolute/.htpasswd", "a+");
|
||||||
if (!$file) {
|
if (!$file) {
|
||||||
$err->raise("hta",_("File already exist"));
|
$err->raise("hta", _("File already exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fseek($file,0);
|
fseek($file, 0);
|
||||||
while (!feof($file)) {
|
while (!feof($file)) {
|
||||||
$s = fgets($file,1024);
|
$s = fgets($file, 1024);
|
||||||
$t = explode(":",$s);
|
$t = explode(":", $s);
|
||||||
if ($t[0]==$user) {
|
if ($t[0] == $user) {
|
||||||
$err->raise("hta",_("The user '%s' already exist for this folder"),$user);
|
$err->raise("hta", _("The user '%s' already exist for this folder"), $user);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fseek($file,SEEK_END);
|
fseek($file, SEEK_END);
|
||||||
if ( empty($t[1]) || substr($t[1],-1)!="\n") {
|
if (empty($t[1]) || substr($t[1], -1) != "\n") {
|
||||||
fwrite($file,"\n");
|
fwrite($file, "\n");
|
||||||
}
|
}
|
||||||
fwrite($file, "$user:"._md5cr($password)."\n");
|
fwrite($file, "$user:" . _md5cr($password) . "\n");
|
||||||
fclose($file);
|
fclose($file);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$err->raise("hta",_("Please enter a valid username"));
|
$err->raise("hta", _("Please enter a valid username"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* Delete a user from a protected folder.
|
* Delete a user from a protected folder.
|
||||||
*
|
*
|
||||||
|
@ -345,28 +338,28 @@ class m_hta {
|
||||||
* @param string $dir The folder, relative to user root, where we want to delete users.
|
* @param string $dir The folder, relative to user root, where we want to delete users.
|
||||||
* @return boolean TRUE if users has been deleted, or FALSE if an error occurred.
|
* @return boolean TRUE if users has been deleted, or FALSE if an error occurred.
|
||||||
*/
|
*/
|
||||||
function del_user($lst,$dir) {
|
function del_user($lst, $dir) {
|
||||||
global $bro,$err;
|
global $bro, $err;
|
||||||
$err->log("hta","del_user",$lst."/".$dir);
|
$err->log("hta", "del_user", $lst . "/" . $dir);
|
||||||
$absolute = $bro->convertabsolute($dir,0);
|
$absolute = $bro->convertabsolute($dir, 0);
|
||||||
if (!file_exists($absolute)) {
|
if (!file_exists($absolute)) {
|
||||||
$err->raise("hta",printf(_("The folder '%s' does not exist"),$dir));
|
$err->raise("hta", printf(_("The folder '%s' does not exist"), $dir));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
touch("$absolute/.htpasswd.new");
|
touch("$absolute/.htpasswd.new");
|
||||||
$file = fopen("$absolute/.htpasswd","r");
|
$file = fopen("$absolute/.htpasswd", "r");
|
||||||
$newf = fopen("$absolute/.htpasswd.new","a");
|
$newf = fopen("$absolute/.htpasswd.new", "a");
|
||||||
if (!$file || !$newf) {
|
if (!$file || !$newf) {
|
||||||
$err->raise("hta",_("File already exist"));
|
$err->raise("hta", _("File already exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
reset($lst);
|
reset($lst);
|
||||||
fseek($file,0);
|
fseek($file, 0);
|
||||||
while (!feof($file)) {
|
while (!feof($file)) {
|
||||||
$s = fgets($file,1024);
|
$s = fgets($file, 1024);
|
||||||
$t = explode(":",$s);
|
$t = explode(":", $s);
|
||||||
if (!in_array($t[0],$lst) && ($t[0]!="\n")) {
|
if (!in_array($t[0], $lst) && ($t[0] != "\n")) {
|
||||||
fseek($newf,0);
|
fseek($newf, 0);
|
||||||
fwrite($newf, "$s");
|
fwrite($newf, "$s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,55 +370,44 @@ 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
|
||||||
*/
|
*/
|
||||||
/**
|
function change_pass($user, $newpass, $dir) {
|
||||||
* Change the password of a user in a protected folder
|
global $bro, $err, $admin;
|
||||||
*
|
$err->log("hta", "change_pass", $user . "/" . $dir);
|
||||||
* @global m_bro $bro
|
$absolute = $bro->convertabsolute($dir, 0);
|
||||||
* @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) {
|
|
||||||
global $bro,$err,$admin;
|
|
||||||
$err->log("hta","change_pass",$user."/".$dir);
|
|
||||||
$absolute = $bro->convertabsolute($dir,0);
|
|
||||||
if (!file_exists($absolute)) {
|
if (!file_exists($absolute)) {
|
||||||
$err->raise("hta",printf(_("The folder '%s' does not exist"),$dir));
|
$err->raise("hta", printf(_("The folder '%s' does not exist"), $dir));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check this password against the password policy using common API :
|
// Check this password against the password policy using common API :
|
||||||
if (is_callable(array($admin,"checkPolicy"))) {
|
if (is_callable(array($admin, "checkPolicy"))) {
|
||||||
if (!$admin->checkPolicy("hta",$user,$newpass)) {
|
if (!$admin->checkPolicy("hta", $user, $newpass)) {
|
||||||
return false; // The error has been raised by checkPolicy()
|
return false; // The error has been raised by checkPolicy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
touch("$absolute/.htpasswd.new");
|
touch("$absolute/.htpasswd.new");
|
||||||
$file = fopen("$absolute/.htpasswd","r");
|
$file = fopen("$absolute/.htpasswd", "r");
|
||||||
$newf = fopen("$absolute/.htpasswd.new","a");
|
$newf = fopen("$absolute/.htpasswd.new", "a");
|
||||||
if (!$file || !$newf) {
|
if (!$file || !$newf) {
|
||||||
$err->raise("hta",_("File already exist"));
|
$err->raise("hta", _("File already exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
while (!feof($file)) {
|
while (!feof($file)) {
|
||||||
$s = fgets($file,1024);
|
$s = fgets($file, 1024);
|
||||||
$t = explode(":",$s);
|
$t = explode(":", $s);
|
||||||
if ($t[0]!=$user) {
|
if ($t[0] != $user) {
|
||||||
fwrite($newf, "$s");
|
fwrite($newf, "$s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fwrite($newf, "$user:"._md5cr($newpass)."\n");
|
fwrite($newf, "$user:" . _md5cr($newpass) . "\n");
|
||||||
fclose($file);
|
fclose($file);
|
||||||
fclose($newf);
|
fclose($newf);
|
||||||
unlink("$absolute/.htpasswd");
|
unlink("$absolute/.htpasswd");
|
||||||
|
@ -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)
|
||||||
*
|
*
|
||||||
|
@ -444,39 +425,39 @@ class m_hta {
|
||||||
*/
|
*/
|
||||||
private function _reading_htaccess($absolute) {
|
private function _reading_htaccess($absolute) {
|
||||||
global $err;
|
global $err;
|
||||||
$err->log("hta","_reading_htaccess",$absolute);
|
$err->log("hta", "_reading_htaccess", $absolute);
|
||||||
$file = fopen("$absolute/.htaccess","r+");
|
$file = fopen("$absolute/.htaccess", "r+");
|
||||||
$lignes = array(1,1,1);
|
$lignes = array(1, 1, 1);
|
||||||
$errr = 0;
|
$errr = 0;
|
||||||
if (!$file) {
|
if (!$file) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
while (!feof($file) && !$errr) {
|
while (!feof($file) && !$errr) {
|
||||||
$s = fgets($file,1024);
|
$s = fgets($file, 1024);
|
||||||
if (substr($s,0,12)!="RewriteCond " && substr($s,0,14)!="ErrorDocument " && substr($s,0,12)!="RewriteRule " && substr($s,0,14)!="RewriteEngine " && trim($s)!="") {
|
if (substr($s, 0, 12) != "RewriteCond " && substr($s, 0, 14) != "ErrorDocument " && substr($s, 0, 12) != "RewriteRule " && substr($s, 0, 14) != "RewriteEngine " && trim($s) != "") {
|
||||||
$errr = 1;
|
$errr = 1;
|
||||||
}
|
}
|
||||||
if (strtolower(trim($s))==strtolower("authuserfile $absolute/.htpasswd")) {
|
if (strtolower(trim($s)) == strtolower("authuserfile $absolute/.htpasswd")) {
|
||||||
$lignes[0] = 0;
|
$lignes[0] = 0;
|
||||||
$errr = 0;
|
$errr = 0;
|
||||||
} // authuserfile
|
} // authuserfile
|
||||||
if (strtolower(trim($s))=="require valid-user") {
|
if (strtolower(trim($s)) == "require valid-user") {
|
||||||
$lignes[1] = 0;
|
$lignes[1] = 0;
|
||||||
$errr = 0;
|
$errr = 0;
|
||||||
} //require
|
} //require
|
||||||
if (strtolower(trim($s))=="authtype basic") {
|
if (strtolower(trim($s)) == "authtype basic") {
|
||||||
$lignes[2] = 0;
|
$lignes[2] = 0;
|
||||||
$errr = 0;
|
$errr = 0;
|
||||||
} //authtype
|
} //authtype
|
||||||
} // Reading config file
|
} // Reading config file
|
||||||
fclose($file);
|
fclose($file);
|
||||||
if ($errr || in_array(0,$lignes)) {
|
if ($errr || in_array(0, $lignes)) {
|
||||||
$err->raise("hta",_("An incompatible .htaccess file exists in this folder"));
|
$err->raise("hta", _("An incompatible .htaccess file exists in this folder"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* CLASS m_hta */
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* CLASS m_hta */
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -21,102 +22,103 @@
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Purpose of file: Manage Log files for users
|
Purpose of file: Manage Log files for users
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe de gestion des erreurs apparaissant lors d'appels API.
|
* Classe de gestion des erreurs apparaissant lors d'appels API.
|
||||||
*/
|
*/
|
||||||
class m_log {
|
class m_log {
|
||||||
|
|
||||||
function m_log(){
|
function m_log() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function list_logs_directory($dir){
|
function list_logs_directory($dir) {
|
||||||
global $cuid,$err;
|
global $cuid, $err;
|
||||||
$err->log("log","list_logs_directory");
|
$err->log("log", "list_logs_directory");
|
||||||
|
|
||||||
$c=array();
|
$c = array();
|
||||||
foreach( glob("${dir}/*log*") as $absfile) {
|
foreach (glob("${dir}/*log*") as $absfile) {
|
||||||
$c[]=array("name"=>basename($absfile),
|
$c[] = array("name" => basename($absfile),
|
||||||
"creation_date"=>date("F d Y H:i:s", filectime($absfile)),
|
"creation_date" => date("F d Y H:i:s", filectime($absfile)),
|
||||||
"mtime" => filemtime($absfile),
|
"mtime" => filemtime($absfile),
|
||||||
"filesize"=>filesize($absfile),
|
"filesize" => filesize($absfile),
|
||||||
"downlink"=>urlencode(basename($absfile)),
|
"downlink" => urlencode(basename($absfile)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
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) {
|
||||||
return strcmp($a['name'],$b['name']);
|
return strcmp($a['name'], $b['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used by list_logs_directory to sort
|
// Used by list_logs_directory to sort
|
||||||
private function compare_logtime($a, $b) {
|
private function compare_logtime($a, $b) {
|
||||||
return $b['mtime']-$a['mtime'];
|
return $b['mtime'] - $a['mtime'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function hook_menu() {
|
function hook_menu() {
|
||||||
$obj = array(
|
$obj = array(
|
||||||
'title' => _("Logs"),
|
'title' => _("Logs"),
|
||||||
'ico' => 'images/logs.png',
|
'ico' => 'images/logs.png',
|
||||||
'link' => 'logs_list.php',
|
'link' => 'logs_list.php',
|
||||||
'pos' => 130,
|
'pos' => 130,
|
||||||
) ;
|
);
|
||||||
|
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
function list_logs_directory_all($dirs){
|
function list_logs_directory_all($dirs) {
|
||||||
global $err;
|
global $err;
|
||||||
$err->log("log","get_logs_directory_all");
|
$err->log("log", "get_logs_directory_all");
|
||||||
$c=array();
|
$c = array();
|
||||||
foreach($dirs as $dir=>$val){
|
foreach ($dirs as $dir => $val) {
|
||||||
$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() {
|
||||||
global $cuid,$mem,$err;
|
global $cuid, $mem, $err;
|
||||||
$err->log("log","get_logs_directory");
|
$err->log("log", "get_logs_directory");
|
||||||
// Return an array to allow multiple directory in the future
|
// Return an array to allow multiple directory in the future
|
||||||
if(defined('ALTERNC_LOGS_ARCHIVE')){
|
if (defined('ALTERNC_LOGS_ARCHIVE')) {
|
||||||
$c=array("dir"=>ALTERNC_LOGS_ARCHIVE."/".$cuid."-".$mem->user["login"]);
|
$c = array("dir" => ALTERNC_LOGS_ARCHIVE . "/" . $cuid . "-" . $mem->user["login"]);
|
||||||
}else{
|
} else {
|
||||||
$c=array("dir"=>ALTERNC_LOGS."/".$cuid."-".$mem->user["login"]);
|
$c = array("dir" => ALTERNC_LOGS . "/" . $cuid . "-" . $mem->user["login"]);
|
||||||
}
|
}
|
||||||
return $c;
|
return $c;
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
header("Content-Transfer-Encoding: binary");
|
header("Content-Transfer-Encoding: binary");
|
||||||
$f=$this->get_logs_directory();
|
$f = $this->get_logs_directory();
|
||||||
$ff=$f['dir']."/".basename($file);
|
$ff = $f['dir'] . "/" . basename($file);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
readfile($ff);
|
readfile($ff);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
$f=$this->get_logs_directory();
|
if ($lines <= 0) {
|
||||||
$ff=$f['dir']."/".basename($file);
|
$lines = 20;
|
||||||
unset($out);
|
}
|
||||||
exec("tail -".$lines." ".escapeshellarg($ff),$out);
|
$f = $this->get_logs_directory();
|
||||||
return implode("\n",$out);
|
$ff = $f['dir'] . "/" . basename($file);
|
||||||
|
$out=array();
|
||||||
|
exec("tail -" . $lines . " " . escapeshellarg($ff), $out);
|
||||||
|
return implode("\n", $out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // end class
|
// end class
|
||||||
|
|
||||||
|
|
|
@ -22,17 +22,15 @@
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Purpose of file: Manage LXC-based virtual machine through an inetd-based protocol
|
Purpose of file: Manage LXC-based virtual machine through an inetd-based protocol
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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,46 +38,43 @@ 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
|
||||||
*/
|
*/
|
||||||
function m_lxc() {
|
function m_lxc() {
|
||||||
$this->IP = variable_get('lxc_ip', '', "IP address of the Alternc's LXC server. If empty, no LXC server.", array('desc'=>'IP address','type'=>'ip'));
|
$this->IP = variable_get('lxc_ip', '', "IP address of the Alternc's LXC server. If empty, no LXC server.", array('desc' => 'IP address', 'type' => 'ip'));
|
||||||
$this->PORT = variable_get('lxc_port', '6504', "Port of the Alternc's LXC server", array('desc'=>'Port','type'=>'integer'));
|
$this->PORT = variable_get('lxc_port', '6504', "Port of the Alternc's LXC server", array('desc' => 'Port', 'type' => 'integer'));
|
||||||
$this->KEY = variable_get('lxc_key', '', "Shared key with the Alternc's LXC server", array('desc'=>'Shared key','type'=>'string'));
|
$this->KEY = variable_get('lxc_key', '', "Shared key with the Alternc's LXC server", array('desc' => 'Shared key', 'type' => 'string'));
|
||||||
$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"),
|
||||||
'ico' => 'images/ssh.png',
|
'ico' => 'images/ssh.png',
|
||||||
'link' => 'vm.php',
|
'link' => 'vm.php',
|
||||||
'pos' => 95,
|
'pos' => 95,
|
||||||
) ;
|
);
|
||||||
|
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HOOK: remove VM history for AlternC account
|
* HOOK: remove VM history for AlternC account
|
||||||
*/
|
*/
|
||||||
function hook_admin_del_member() {
|
function hook_admin_del_member() {
|
||||||
global $db,$err,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("lxc","alternc_del_member");
|
$err->log("lxc", "alternc_del_member");
|
||||||
$db->query("DELETE FROM vm_history WHERE uid='$cuid'");
|
$db->query("DELETE FROM vm_history WHERE uid='$cuid'");
|
||||||
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
|
||||||
|
@ -88,33 +83,34 @@ class m_lxc implements vm {
|
||||||
* or FALSE if an error occurred. In that case $error[] is set.
|
* or FALSE if an error occurred. In that case $error[] is set.
|
||||||
*/
|
*/
|
||||||
private function sendMessage($params) {
|
private function sendMessage($params) {
|
||||||
global $L_FQDN,$hooks;
|
global $L_FQDN, $hooks;
|
||||||
$fp = @fsockopen($this->IP, $this->PORT, $errno, $errstr, $this->TIMEOUT);
|
$fp = @fsockopen($this->IP, $this->PORT, $errno, $errstr, $this->TIMEOUT);
|
||||||
if (!$fp) {
|
if (!$fp) {
|
||||||
$this->error[] = 'Unable to connect';
|
$this->error[] = 'Unable to connect';
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
// Authenticate:
|
// Authenticate:
|
||||||
$params['server']=$L_FQDN;
|
$params['server'] = $L_FQDN;
|
||||||
$params['key']=$this->KEY;
|
$params['key'] = $this->KEY;
|
||||||
// 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) {
|
||||||
$this->error[] = 'Unable to send data';
|
$this->error[] = 'Unable to send data';
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
$resp = fgets($fp, 8192);
|
$resp = fgets($fp, 8192);
|
||||||
fclose ($fp);
|
fclose($fp);
|
||||||
|
|
||||||
$data = @unserialize($resp);
|
$data = @unserialize($resp);
|
||||||
|
|
||||||
if (isset($data['error']) && $data['error']>0) {
|
if (isset($data['error']) && $data['error'] > 0) {
|
||||||
$this->error[] = $data['msg'];
|
$this->error[] = $data['msg'];
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
|
@ -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
|
||||||
|
@ -140,7 +135,7 @@ class m_lxc implements vm {
|
||||||
$pass = $pass ? $pass : $mem->user['pass'];
|
$pass = $pass ? $pass : $mem->user['pass'];
|
||||||
$uid = $uid ? $uid : $mem->user['uid'];
|
$uid = $uid ? $uid : $mem->user['uid'];
|
||||||
|
|
||||||
$msgg = array('action'=>'start', 'login'=>$login, 'pass' => $pass, 'uid'=> $uid);
|
$msgg = array('action' => 'start', 'login' => $login, 'pass' => $pass, 'uid' => $uid);
|
||||||
$msgg['mysql_host'] = $mysql->dbus->Host;
|
$msgg['mysql_host'] = $mysql->dbus->Host;
|
||||||
|
|
||||||
$res = $this->sendMessage($msgg);
|
$res = $this->sendMessage($msgg);
|
||||||
|
@ -148,7 +143,7 @@ class m_lxc implements vm {
|
||||||
return $this->error;
|
return $this->error;
|
||||||
} else {
|
} else {
|
||||||
$data = unserialize($res);
|
$data = unserialize($res);
|
||||||
$error = (int)$data['error'];
|
$error = (int) $data['error'];
|
||||||
$hostname = $data['hostname'];
|
$hostname = $data['hostname'];
|
||||||
$msg = $data['msg'];
|
$msg = $data['msg'];
|
||||||
$date_start = 'NOW()';
|
$date_start = 'NOW()';
|
||||||
|
@ -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
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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 $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
@ -20,42 +21,47 @@
|
||||||
Purpose of file: Manage Login session on the virtual desktop and
|
Purpose of file: Manage Login session on the virtual desktop and
|
||||||
member parameters
|
member parameters
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manage user sessions in the web desktop.
|
* This class manage user sessions in the web desktop.
|
||||||
*
|
*
|
||||||
* This class manage user sessions and administration in AlternC.
|
* This class manage user sessions and administration in AlternC.
|
||||||
* @copyright AlternC-Team 2002-2005 http://alternc.org/
|
* @copyright AlternC-Team 2002-2005 http://alternc.org/
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class m_mem {
|
class m_mem {
|
||||||
|
|
||||||
/** Original uid for the temporary uid swapping (for administrators) */
|
/** Original uid for the temporary uid swapping (for administrators) */
|
||||||
var $olduid=0;
|
var $olduid = 0;
|
||||||
|
|
||||||
/** This array contains the Tableau contenant les champs de la table "membres" du membre courant
|
/** This array contains the Tableau contenant les champs de la table "membres" du membre courant
|
||||||
* 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)
|
||||||
*/
|
*/
|
||||||
function alternc_password_policy() {
|
function alternc_password_policy() {
|
||||||
return array("mem"=>"AlternC's account password");
|
return array("mem" => "AlternC's account password");
|
||||||
}
|
}
|
||||||
|
|
||||||
function hook_menu() {
|
function hook_menu() {
|
||||||
|
@ -64,20 +70,22 @@ class m_mem {
|
||||||
'ico' => 'images/settings.png',
|
'ico' => 'images/settings.png',
|
||||||
'link' => 'mem_param.php',
|
'link' => 'mem_param.php',
|
||||||
'pos' => 160,
|
'pos' => 160,
|
||||||
) ;
|
);
|
||||||
|
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** 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.
|
||||||
*/
|
*/
|
||||||
function checkright() {
|
function checkright() {
|
||||||
return ($this->user["su"]=="1");
|
return ($this->user["su"] == "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** 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.
|
||||||
|
@ -85,73 +93,82 @@ class m_mem {
|
||||||
* @param $password string User Password.
|
* @param $password string User Password.
|
||||||
* @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);
|
||||||
$db->query("select * from membres where login='$username';");
|
$db->query("select * from membres where login='$username';");
|
||||||
if ($db->num_rows()==0) {
|
if ($db->num_rows() == 0) {
|
||||||
$err->raise("mem",_("User or password incorrect"));
|
$err->raise("mem", _("User or password incorrect"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
if (_md5cr($password,$db->f("pass"))!=$db->f("pass")) {
|
if (_md5cr($password, $db->f("pass")) != $db->f("pass")) {
|
||||||
$db->query("UPDATE membres SET lastfail=lastfail+1 WHERE uid='".$db->f("uid")."';");
|
$db->query("UPDATE membres SET lastfail=lastfail+1 WHERE uid='" . $db->f("uid") . "';");
|
||||||
$err->raise("mem",_("User or password incorrect"));
|
$err->raise("mem", _("User or password incorrect"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!$db->f("enabled")) {
|
if (!$db->f("enabled")) {
|
||||||
$err->raise("mem",_("This account is locked, contact the administrator."));
|
$err->raise("mem", _("This account is locked, contact the administrator."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->user=$db->Record;
|
$this->user = $db->Record;
|
||||||
$cuid=$db->f("uid");
|
$cuid = $db->f("uid");
|
||||||
|
|
||||||
if (panel_islocked() && $cuid != 2000) {
|
if (panel_islocked() && $cuid != 2000) {
|
||||||
$err->raise("mem",_("This website is currently under maintenance, login is currently disabled."));
|
$err->raise("mem", _("This website is currently under maintenance, login is currently disabled."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
if ( sizeof($aga)>1 && !$allowed_ip && !$authip->is_wl(get_remote_ip()) ) {
|
if (sizeof($aga) > 1 && !$allowed_ip && !$authip->is_wl(get_remote_ip())) {
|
||||||
$err->raise("mem",_("Your IP isn't allowed to connect"));
|
$err->raise("mem", _("Your IP isn't allowed to connect"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// End AuthIP
|
// End AuthIP
|
||||||
|
|
||||||
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;
|
||||||
$db->query("insert into sessions (sid,ip,uid) values ('$sess',$ip,'$cuid');");
|
$db->query("insert into sessions (sid,ip,uid) values ('$sess',$ip,'$cuid');");
|
||||||
setcookie("session",$sess,0,"/");
|
setcookie("session", $sess, 0, "/");
|
||||||
$err->error=0;
|
$err->error = 0;
|
||||||
/* Fill in $local */
|
/* Fill in $local */
|
||||||
$db->query("SELECT * FROM local WHERE uid='$cuid';");
|
$db->query("SELECT * FROM local WHERE uid='$cuid';");
|
||||||
if ($db->num_rows()) {
|
if ($db->num_rows()) {
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$this->local=$db->Record;
|
$this->local = $db->Record;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** 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.
|
||||||
|
@ -161,63 +178,67 @@ class m_mem {
|
||||||
* @return boolean TRUE if the user has been successfully connected, FALSE else.
|
* @return boolean TRUE if the user has been successfully connected, FALSE else.
|
||||||
*/
|
*/
|
||||||
function setid($id) {
|
function setid($id) {
|
||||||
global $db,$err,$cuid,$mysql,$quota;
|
global $db, $err, $cuid, $mysql, $quota;
|
||||||
$err->log("mem","setid",$id);
|
$err->log("mem", "setid", $id);
|
||||||
$db->query("select * from membres where uid='$id';");
|
$db->query("select * from membres where uid='$id';");
|
||||||
if ($db->num_rows()==0) {
|
if ($db->num_rows() == 0) {
|
||||||
$err->raise("mem",_("User or password incorrect"));
|
$err->raise("mem", _("User or password incorrect"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$this->user=$db->Record;
|
$this->user = $db->Record;
|
||||||
$cuid=$db->f("uid");
|
$cuid = $db->f("uid");
|
||||||
// And recreate the $db->dbus
|
// And recreate the $db->dbus
|
||||||
$mysql->reload_dbus();
|
$mysql->reload_dbus();
|
||||||
|
|
||||||
$ip=get_remote_ip();
|
$ip = get_remote_ip();
|
||||||
$sess=md5(uniqid(mt_rand()));
|
$sess = md5(uniqid(mt_rand()));
|
||||||
$_REQUEST["session"]=$sess;
|
$_REQUEST["session"] = $sess;
|
||||||
$db->query("insert into sessions (sid,ip,uid) values ('$sess','$ip','$cuid');");
|
$db->query("insert into sessions (sid,ip,uid) values ('$sess','$ip','$cuid');");
|
||||||
setcookie("session",$sess,0,"/");
|
setcookie("session", $sess, 0, "/");
|
||||||
$err->error=0;
|
$err->error = 0;
|
||||||
/* Fill in $local */
|
/* Fill in $local */
|
||||||
$db->query("SELECT * FROM local WHERE uid='$cuid';");
|
$db->query("SELECT * FROM local WHERE uid='$cuid';");
|
||||||
if ($db->num_rows()) {
|
if ($db->num_rows()) {
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$this->local=$db->Record;
|
$this->local = $db->Record;
|
||||||
}
|
}
|
||||||
$quota->getquota('', true);
|
$quota->getquota('', true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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';");
|
||||||
}
|
}
|
||||||
|
|
||||||
function authip_token($bis=false) {
|
function authip_token($bis = false) {
|
||||||
global $db,$cuid;
|
global $db, $cuid;
|
||||||
$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) {
|
||||||
return md5("$i--".$db->f('pass'));
|
++$i;
|
||||||
|
}
|
||||||
|
return md5("$i--" . $db->f('pass'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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();
|
||||||
|
@ -227,84 +248,87 @@ class m_mem {
|
||||||
|
|
||||||
return $c;
|
return $c;
|
||||||
}
|
}
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($_REQUEST["username"] && $_REQUEST["password"]) {
|
if ($_REQUEST["username"] && $_REQUEST["password"]) {
|
||||||
return $this->login($_REQUEST["username"],$_REQUEST["password"], (isset($_REQUEST["restrictip"])?$_REQUEST["restrictip"]:0) );
|
return $this->login($_REQUEST["username"], $_REQUEST["password"], (isset($_REQUEST["restrictip"]) ? $_REQUEST["restrictip"] : 0));
|
||||||
}
|
}
|
||||||
} // end isset
|
} // end isset
|
||||||
$_COOKIE["session"]=isset($_COOKIE["session"])?addslashes($_COOKIE["session"]):"";
|
$_COOKIE["session"] = isset($_COOKIE["session"]) ? addslashes($_COOKIE["session"]) : "";
|
||||||
if (strlen($_COOKIE["session"])!=32) {
|
if (strlen($_COOKIE["session"]) != 32) {
|
||||||
$err->raise("mem",_("Identity lost or unknown, please login"));
|
$err->raise("mem", _("Identity lost or unknown, please login"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$ip=get_remote_ip();
|
$ip = get_remote_ip();
|
||||||
$db->query("select uid,'$ip' as me,ip from sessions where sid='".$_COOKIE["session"]."'");
|
$db->query("select uid,'$ip' as me,ip from sessions where sid='" . $_COOKIE["session"] . "'");
|
||||||
if ($db->num_rows()==0) {
|
if ($db->num_rows() == 0) {
|
||||||
$err->raise("mem",_("Session unknown, contact the administrator"));
|
$err->raise("mem", _("Session unknown, contact the administrator"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
if ($db->f("ip")) {
|
if ($db->f("ip")) {
|
||||||
if ($db->f("me")!=$db->f("ip")) {
|
if ($db->f("me") != $db->f("ip")) {
|
||||||
$err->raise("mem",_("IP address incorrect, please contact the administrator"));
|
$err->raise("mem", _("IP address incorrect, please contact the administrator"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$cuid=$db->f("uid");
|
$cuid = $db->f("uid");
|
||||||
|
|
||||||
if (panel_islocked() && $cuid != 2000) {
|
if (panel_islocked() && $cuid != 2000) {
|
||||||
$err->raise("mem",_("This website is currently under maintenance, login is currently disabled."));
|
$err->raise("mem", _("This website is currently under maintenance, login is currently disabled."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->query("select * from membres where uid='$cuid';");
|
$db->query("select * from membres where uid='$cuid';");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$this->user=$db->Record;
|
$this->user = $db->Record;
|
||||||
$err->error=0;
|
$err->error = 0;
|
||||||
/* Remplissage de $local */
|
/* Remplissage de $local */
|
||||||
$db->query("SELECT * FROM local WHERE uid='$cuid';");
|
$db->query("SELECT * FROM local WHERE uid='$cuid';");
|
||||||
if ($db->num_rows()) {
|
if ($db->num_rows()) {
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$this->local=$db->Record;
|
$this->local = $db->Record;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$this->user=$db->Record;
|
$this->user = $db->Record;
|
||||||
$cuid=$db->f("uid");
|
$cuid = $db->f("uid");
|
||||||
|
|
||||||
// And recreate the $db->dbus
|
// And recreate the $db->dbus
|
||||||
$mysql->reload_dbus();
|
$mysql->reload_dbus();
|
||||||
|
@ -312,52 +336,54 @@ 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
|
||||||
$mysql->reload_dbus();
|
$mysql->reload_dbus();
|
||||||
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, "/");
|
||||||
if ($_COOKIE["session"]=="") {
|
if ($_COOKIE["session"] == "") {
|
||||||
$err->error=0;
|
$err->error = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (strlen($_COOKIE["session"])!=32) {
|
if (strlen($_COOKIE["session"]) != 32) {
|
||||||
$err->raise("mem",_("Cookie incorrect, please accept the session cookie"));
|
$err->raise("mem", _("Cookie incorrect, please accept the session cookie"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$ip=get_remote_ip();
|
$ip = get_remote_ip();
|
||||||
$db->query("select uid,'$ip' as me,ip from sessions where sid='".$_COOKIE["session"]."'");
|
$db->query("select uid,'$ip' as me,ip from sessions where sid='" . $_COOKIE["session"] . "'");
|
||||||
if ($db->num_rows()==0) {
|
if ($db->num_rows() == 0) {
|
||||||
$err->raise("mem",_("Session unknown, contact the administrator"));
|
$err->raise("mem", _("Session unknown, contact the administrator"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
if ($db->f("me")!=$db->f("ip")) {
|
if ($db->f("me") != $db->f("ip")) {
|
||||||
$err->raise("mem",_("IP address incorrect, please contact the administrator"));
|
$err->raise("mem", _("IP address incorrect, please contact the administrator"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$cuid=$db->f("uid");
|
$cuid = $db->f("uid");
|
||||||
$db->query("delete from sessions where sid='".$_COOKIE["session"]."';");
|
$db->query("delete from sessions where sid='" . $_COOKIE["session"] . "';");
|
||||||
$err->error=0;
|
$err->error = 0;
|
||||||
|
|
||||||
# Invoker le logout dans toutes les autres classes
|
# Invoker le logout dans toutes les autres classes
|
||||||
/*
|
/*
|
||||||
|
@ -375,80 +401,83 @@ 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;
|
||||||
$err->log("mem","passwd");
|
$err->log("mem", "passwd");
|
||||||
$oldpass=stripslashes($oldpass);
|
$oldpass = stripslashes($oldpass);
|
||||||
$newpass=stripslashes($newpass);
|
$newpass = stripslashes($newpass);
|
||||||
$newpass2=stripslashes($newpass2);
|
$newpass2 = stripslashes($newpass2);
|
||||||
if (!$this->user["canpass"]) {
|
if (!$this->user["canpass"]) {
|
||||||
$err->raise("mem",_("You are not allowed to change your password."));
|
$err->raise("mem", _("You are not allowed to change your password."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->user["pass"]!=_md5cr($oldpass,$this->user["pass"])) {
|
if ($this->user["pass"] != _md5cr($oldpass, $this->user["pass"])) {
|
||||||
$err->raise("mem",_("The old password is incorrect"));
|
$err->raise("mem", _("The old password is incorrect"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($newpass!=$newpass2) {
|
if ($newpass != $newpass2) {
|
||||||
$err->raise("mem",_("The new passwords are differents, please retry"));
|
$err->raise("mem", _("The new passwords are differents, please retry"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db->query("SELECT login FROM membres WHERE uid='$cuid';");
|
$db->query("SELECT login FROM membres WHERE uid='$cuid';");
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
$login=$db->Record["login"];
|
$login = $db->Record["login"];
|
||||||
if (!$admin->checkPolicy("mem",$login,$newpass)) {
|
if (!$admin->checkPolicy("mem", $login, $newpass)) {
|
||||||
return false; // The error has been raised by checkPolicy()
|
return false; // The error has been raised by checkPolicy()
|
||||||
}
|
}
|
||||||
$newpass=_md5cr($newpass);
|
$newpass = _md5cr($newpass);
|
||||||
$db->query("UPDATE membres SET pass='$newpass' WHERE uid='$cuid';");
|
$db->query("UPDATE membres SET pass='$newpass' WHERE uid='$cuid';");
|
||||||
$err->error=0;
|
$err->error = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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;
|
||||||
$err->log("mem","admlist");
|
$err->log("mem", "admlist");
|
||||||
if (!$this->user["su"]) {
|
if (!$this->user["su"]) {
|
||||||
$err->raise("mem",_("You must be a system administrator to do this."));
|
$err->raise("mem", _("You must be a system administrator to do this."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db->query("UPDATE membres SET admlist='$admlist' WHERE uid='$cuid';");
|
$db->query("UPDATE membres SET admlist='$admlist' WHERE uid='$cuid';");
|
||||||
$err->error=0;
|
$err->error = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** 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;
|
||||||
$err->log("mem","send_pass");
|
$err->log("mem", "send_pass");
|
||||||
$db->query("SELECT * FROM membres WHERE login='$login';");
|
$db->query("SELECT * FROM membres WHERE login='$login';");
|
||||||
if (!$db->num_rows()) {
|
if (!$db->num_rows()) {
|
||||||
$err->raise("mem",_("This account is locked, contact the administrator."));
|
$err->raise("mem", _("This account is locked, contact the administrator."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db->next_record();
|
$db->next_record();
|
||||||
if (time()-$db->f("lastaskpass")<86400) {
|
if (time() - $db->f("lastaskpass") < 86400) {
|
||||||
$err->raise("mem",_("The new passwords are differents, please retry"));
|
$err->raise("mem", _("The new passwords are differents, please retry"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$txt=sprintf(_("Hello,
|
$txt = sprintf(_("Hello,
|
||||||
|
|
||||||
You requested the modification of your password for your
|
You requested the modification of your password for your
|
||||||
account %s on %s
|
account %s on %s
|
||||||
|
@ -467,33 +496,34 @@ If it happens again, please contact your server's Administrator.
|
||||||
|
|
||||||
Cordially.
|
Cordially.
|
||||||
"), $login, $L_HOSTING, $db->f("login"), $db->f("pass"));
|
"), $login, $L_HOSTING, $db->f("login"), $db->f("pass"));
|
||||||
mail($db->f("mail"),"Your password on $L_HOSTING",$txt,"From: postmaster@$L_FQDN\nReply-to: postmaster@$L_FQDN");
|
mail($db->f("mail"), "Your password on $L_HOSTING", $txt, "From: postmaster@$L_FQDN\nReply-to: postmaster@$L_FQDN");
|
||||||
$db->query("UPDATE membres SET lastaskpass=".time()." WHERE login='$login';");
|
$db->query("UPDATE membres SET lastaskpass=" . time() . " WHERE login='$login';");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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;
|
||||||
$err->log("mem","changemail1",$newmail);
|
$err->log("mem", "changemail1", $newmail);
|
||||||
$db->query("SELECT * FROM membres WHERE uid='$cuid';");
|
$db->query("SELECT * FROM membres WHERE uid='$cuid';");
|
||||||
if (!$db->num_rows()) {
|
if (!$db->num_rows()) {
|
||||||
$err->raise("mem",_("This account is locked, contact the administrator."));
|
$err->raise("mem", _("This account is locked, contact the administrator."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$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,
|
||||||
|
|
||||||
Someone (maybe you) requested an email's address modification of the account
|
Someone (maybe you) requested an email's address modification of the account
|
||||||
%s on %s
|
%s on %s
|
||||||
|
@ -512,75 +542,77 @@ 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 :)
|
||||||
$lts=time()-86400;
|
$lts = time() - 86400;
|
||||||
$db->query("DELETE FROM chgmail WHERE ts<'$lts';");
|
$db->query("DELETE FROM chgmail WHERE ts<'$lts';");
|
||||||
return $KEY;
|
return $KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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()) {
|
||||||
$err->raise("mem",_("The information you entered is incorrect."));
|
$err->raise("mem", _("The information you entered is incorrect."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$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';");
|
||||||
// Supprime les cookies de la veille :)
|
// Supprime les cookies de la veille :)
|
||||||
$lts=time()-86400;
|
$lts = time() - 86400;
|
||||||
$db->query("DELETE FROM chgmail WHERE ts<'$lts';");
|
$db->query("DELETE FROM chgmail WHERE ts<'$lts';");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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) {
|
||||||
global $db,$err,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("mem","set_help_param",$show);
|
$err->log("mem", "set_help_param", $show);
|
||||||
$db->query("UPDATE membres SET show_help='$show' WHERE uid='$cuid';");
|
$db->query("UPDATE membres SET show_help='$show' WHERE uid='$cuid';");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** 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;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -593,71 +625,77 @@ Cordially.
|
||||||
* @param integer $uid
|
* @param integer $uid
|
||||||
*/
|
*/
|
||||||
function get_creator_by_uid($uid) {
|
function get_creator_by_uid($uid) {
|
||||||
global $db,$err;
|
global $db, $err;
|
||||||
$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 intval($db->f('creator') );
|
return false;
|
||||||
|
}
|
||||||
|
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() {
|
||||||
global $db,$err;
|
global $db, $err;
|
||||||
$err->log("mem","export");
|
$err->log("mem", "export");
|
||||||
$str=" <member>\n";
|
$str = " <member>\n";
|
||||||
$users=$this->user;
|
$users = $this->user;
|
||||||
$str.=" <uid>".$users["uid"]."</uid>\n";
|
$str.=" <uid>" . $users["uid"] . "</uid>\n";
|
||||||
$str.=" <login>".$users["login"]."</login>\n";
|
$str.=" <login>" . $users["login"] . "</login>\n";
|
||||||
$str.=" <enabled>".$users["enabled"]."</enabled>\n";
|
$str.=" <enabled>" . $users["enabled"] . "</enabled>\n";
|
||||||
$str.=" <su>".$users["su"]."</su>\n";
|
$str.=" <su>" . $users["su"] . "</su>\n";
|
||||||
$str.=" <password>".$users["pass"]."</password>\n";
|
$str.=" <password>" . $users["pass"] . "</password>\n";
|
||||||
$str.=" <mail>".$users["mail"]."</mail>\n";
|
$str.=" <mail>" . $users["mail"] . "</mail>\n";
|
||||||
$str.=" <created>".$users["created"]."</created>\n";
|
$str.=" <created>" . $users["created"] . "</created>\n";
|
||||||
$str.=" <lastip>".$users["lastip"]."</lastip>\n";
|
$str.=" <lastip>" . $users["lastip"] . "</lastip>\n";
|
||||||
$str.=" <lastlogin>".$users["lastlogin"]."</lastlogin>\n";
|
$str.=" <lastlogin>" . $users["lastlogin"] . "</lastlogin>\n";
|
||||||
$str.=" <lastfail>".$users["lastfail"]."</lastfail>\n";
|
$str.=" <lastfail>" . $users["lastfail"] . "</lastfail>\n";
|
||||||
$str.=" </member>\n";
|
$str.=" </member>\n";
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
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'])) {
|
||||||
$sid=$_COOKIE['session'];
|
|
||||||
if ( empty($_SESSION[$sid.'-'.$uid]) ) { // si pas de session de params tempo
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$j=$_SESSION[$sid.'-'.$uid];
|
$sid = $_COOKIE['session'];
|
||||||
$j=json_decode($j, true);
|
if (empty($_SESSION[$sid . '-' . $uid])) { // si pas de session de params tempo
|
||||||
if ( ! empty($j[$v] ) ) { // si on a bien qque chose a retourner :)
|
return false;
|
||||||
|
}
|
||||||
|
$j = $_SESSION[$sid . '-' . $uid];
|
||||||
|
$j = json_decode($j, true);
|
||||||
|
if (!empty($j[$v])) { // si on a bien qque chose a retourner :)
|
||||||
return $j[$v];
|
return $j[$v];
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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'])) {
|
||||||
$sid=$_COOKIE['session'];
|
return false;
|
||||||
$p=Array();
|
|
||||||
if ( ! empty($_SESSION[$sid.'-'.$uid]) ) {
|
|
||||||
$p = json_decode($_SESSION[$sid.'-'.$uid], true);
|
|
||||||
}
|
}
|
||||||
if (! $ecrase && (isset($p[$k]) && is_array($p[$k])) && is_array($v) ) {
|
$sid = $_COOKIE['session'];
|
||||||
$v=array_merge($p[$k], $v); // overwrite entry with the same name
|
$p = Array();
|
||||||
|
if (!empty($_SESSION[$sid . '-' . $uid])) {
|
||||||
|
$p = json_decode($_SESSION[$sid . '-' . $uid], true);
|
||||||
|
}
|
||||||
|
if (!$ecrase && (isset($p[$k]) && is_array($p[$k])) && is_array($v)) {
|
||||||
|
$v = array_merge($p[$k], $v); // overwrite entry with the same name
|
||||||
}
|
}
|
||||||
|
|
||||||
$p[$k]=$v;
|
$p[$k] = $v;
|
||||||
$_SESSION[$sid.'-'.$uid]=json_encode($p);
|
$_SESSION[$sid . '-' . $uid] = json_encode($p);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* Classe Membre */
|
}
|
||||||
|
|
||||||
?>
|
/* Classe Membre */
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Purpose of file: Manage hook system.
|
Purpose of file: Manage hook system.
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manage menu.
|
* This class manage menu.
|
||||||
|
@ -29,20 +30,20 @@
|
||||||
* @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() {
|
||||||
global $hooks, $quota, $mem;
|
global $hooks, $quota, $mem;
|
||||||
|
|
||||||
// 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');
|
||||||
|
|
||||||
|
@ -50,15 +51,15 @@ class m_menu {
|
||||||
$sm = $this->system_menu();
|
$sm = $this->system_menu();
|
||||||
|
|
||||||
// Merge it !
|
// Merge it !
|
||||||
$lst = array_merge($sm,$lsto);
|
$lst = array_merge($sm, $lsto);
|
||||||
|
|
||||||
// Sort it
|
// Sort it
|
||||||
uasort($lst, 'm_menu::order_menu');
|
uasort($lst, 'm_menu::order_menu');
|
||||||
|
|
||||||
// Get user specific menu visibility options
|
// Get user specific menu visibility options
|
||||||
$mop = $mem->session_tempo_params_get('menu_toggle') ;
|
$mop = $mem->session_tempo_params_get('menu_toggle');
|
||||||
|
|
||||||
foreach( $lst as $k => $v ) {
|
foreach ($lst as $k => $v) {
|
||||||
|
|
||||||
if (empty($v)) {
|
if (empty($v)) {
|
||||||
unset($lst[$k]);
|
unset($lst[$k]);
|
||||||
|
@ -67,35 +68,39 @@ class m_menu {
|
||||||
|
|
||||||
// Set the javascript toggle link for menu asking for it
|
// Set the javascript toggle link for menu asking for it
|
||||||
if ($v['link'] == 'toggle') {
|
if ($v['link'] == 'toggle') {
|
||||||
$lst[$k]['link'] = 'javascript:menu_toggle(\'menu-'.$k.'\');';
|
$lst[$k]['link'] = 'javascript:menu_toggle(\'menu-' . $k . '\');';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
// Hide the menu if there are none and not allowed to create
|
// Hide the menu if there are none and not allowed to create
|
||||||
if ( $mesq[$k]['t'] < 1 && $mesq[$k]['u'] < 1 ) {
|
if ($mesq[$k]['t'] < 1 && $mesq[$k]['u'] < 1) {
|
||||||
unset($lst[$k]);
|
unset($lst[$k]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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"),
|
||||||
|
@ -139,37 +143,13 @@ class m_menu {
|
||||||
'links' => array(),
|
'links' => array(),
|
||||||
'pos' => 150,
|
'pos' => 150,
|
||||||
)
|
)
|
||||||
) ;
|
);
|
||||||
foreach($locales as $l) {
|
foreach ($locales as $l) {
|
||||||
$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 */
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Purpose of file: Manage user quota
|
Purpose of file: Manage user quota
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for hosting quotas management
|
* Class for hosting quotas management
|
||||||
|
@ -37,23 +38,21 @@
|
||||||
*/
|
*/
|
||||||
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
|
||||||
*/
|
*/
|
||||||
function m_quota() {
|
function m_quota() {
|
||||||
$this->disk_quota_enable = variable_get('disk_quota_enable', 1,'Are disk quota enabled for this server', array('desc'=>'Enabled','type'=>'boolean'));
|
$this->disk_quota_enable = variable_get('disk_quota_enable', 1, 'Are disk quota enabled for this server', array('desc' => 'Enabled', 'type' => 'boolean'));
|
||||||
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() {
|
||||||
|
@ -68,53 +67,54 @@ class m_quota {
|
||||||
'pos' => 110,
|
'pos' => 110,
|
||||||
'divclass' => 'menu-quota',
|
'divclass' => 'menu-quota',
|
||||||
'links' => array(),
|
'links' => array(),
|
||||||
) ;
|
);
|
||||||
|
|
||||||
$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"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/** 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 ?)
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function cancreate($ressource="") {
|
function cancreate($ressource = "") {
|
||||||
$t=$this->getquota($ressource);
|
$t = $this->getquota($ressource);
|
||||||
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)) {
|
||||||
$qlist[$key]=_("quota_".$key); // those are specific disks quotas.
|
$qlist[$key] = _("quota_" . $key); // those are specific disks quotas.
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->getquota() as $qq) {
|
foreach ($this->getquota() as $qq) {
|
||||||
if (isset($qq['name'])) {
|
if (isset($qq['name'])) {
|
||||||
$qlist[$qq['name']]=$qq['description'];
|
$qlist[$qq['name']] = $qq['description'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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.
|
||||||
|
@ -123,10 +123,12 @@ class m_quota {
|
||||||
* the defaults value.
|
* the defaults value.
|
||||||
*/
|
*/
|
||||||
function synchronise_user_profile() {
|
function synchronise_user_profile() {
|
||||||
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,13 +137,14 @@ 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");
|
||||||
$qt=$quota->getquota('',true);
|
$qt = $quota->getquota('', true);
|
||||||
$type=$quota->listtype();
|
$type = $quota->listtype();
|
||||||
foreach($type as $t) {
|
foreach ($type as $t) {
|
||||||
foreach($qt as $q=>$vv) {
|
foreach ($qt as $q => $vv) {
|
||||||
$db->query("INSERT IGNORE defquotas (value,quota,type) VALUES (0,'$q','$t');");
|
$db->query("INSERT IGNORE defquotas (value,quota,type) VALUES (0,'$q','$t');");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,66 +152,64 @@ 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)
|
||||||
*/
|
*/
|
||||||
function getquota($ressource="",$recheck=false) {
|
function getquota($ressource = "", $recheck = false) {
|
||||||
global $db,$err,$cuid,$get_quota_cache,$hooks,$mem;
|
global $db, $err, $cuid, $get_quota_cache, $hooks, $mem;
|
||||||
$err->log("quota","getquota",$ressource);
|
$err->log("quota", "getquota", $ressource);
|
||||||
if ($recheck) { // rebuilding quota
|
if ($recheck) { // rebuilding quota
|
||||||
$get_quota_cache=null;
|
$get_quota_cache = null;
|
||||||
$this->quotas=array();
|
$this->quotas = array();
|
||||||
}
|
}
|
||||||
if (! empty($get_quota_cache[$cuid]) ) {
|
if (!empty($get_quota_cache[$cuid])) {
|
||||||
// This function is called many time each webpage, so I cache the result
|
// This function is called many time each webpage, so I cache the result
|
||||||
$this->quotas = $get_quota_cache[$cuid];
|
$this->quotas = $get_quota_cache[$cuid];
|
||||||
} else {
|
} else {
|
||||||
$res=$hooks->invoke("hook_quota_get");
|
$res = $hooks->invoke("hook_quota_get");
|
||||||
foreach($res as $r) {
|
foreach ($res as $r) {
|
||||||
$this->quotas[$r['name']]=$r;
|
$this->quotas[$r['name']] = $r;
|
||||||
$this->quotas[$r['name']]['u']=$r['used']; // retrocompatibilité
|
$this->quotas[$r['name']]['u'] = $r['used']; // retrocompatibilité
|
||||||
$this->quotas[$r['name']]['t']=0; // Default quota = 0
|
$this->quotas[$r['name']]['t'] = 0; // Default quota = 0
|
||||||
}
|
}
|
||||||
reset($this->disk);
|
reset($this->disk);
|
||||||
|
|
||||||
if (!empty ($this->disk)) { // Check if there are some disk quota to check
|
if (!empty($this->disk)) { // Check if there are some disk quota to check
|
||||||
// Look if there are some cached value
|
// Look if there are some cached value
|
||||||
$disk_cached = $mem->session_tempo_params_get('quota_cache_disk');
|
$disk_cached = $mem->session_tempo_params_get('quota_cache_disk');
|
||||||
|
|
||||||
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];
|
||||||
} else {
|
} else {
|
||||||
exec("/usr/lib/alternc/quota_get ".intval($cuid) ,$ak);
|
exec("/usr/lib/alternc/quota_get " . intval($cuid), $ak);
|
||||||
$a['u']=intval($ak[0]);
|
$a['u'] = intval($ak[0]);
|
||||||
$a['t']=@intval($ak[1]);
|
$a['t'] = @intval($ak[1]);
|
||||||
$a['timestamp'] = time();
|
$a['timestamp'] = time();
|
||||||
$a['uid'] = $cuid;
|
$a['uid'] = $cuid;
|
||||||
$disk_cached = $mem->session_tempo_params_set('quota_cache_disk', array($val=>$a));
|
$disk_cached = $mem->session_tempo_params_set('quota_cache_disk', array($val => $a));
|
||||||
}
|
}
|
||||||
$this->quotas[$val]=array("name"=>"$val", 'description'=>_("quota_".$val), "t"=>$a['t'],"u"=>$a['u']);
|
$this->quotas[$val] = array("name" => "$val", 'description' => _("quota_" . $val), "t" => $a['t'], "u" => $a['u']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the allowed quota from database.
|
// Get the allowed quota from database.
|
||||||
$db->query("select name, total from quotas where uid='$cuid';");
|
$db->query("select name, total from quotas where uid='$cuid';");
|
||||||
while ( $db->next_record() ) {
|
while ($db->next_record()) {
|
||||||
$this->quotas[$db->f('name')]['t']=$db->f('total');
|
$this->quotas[$db->f('name')]['t'] = $db->f('total');
|
||||||
}
|
}
|
||||||
|
|
||||||
$get_quota_cache[$cuid] = $this->quotas;
|
$get_quota_cache[$cuid] = $this->quotas;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ressource) {
|
if ($ressource) {
|
||||||
if (isset($this->quotas[$ressource]) ) {
|
if (isset($this->quotas[$ressource])) {
|
||||||
return $this->quotas[$ressource];
|
return $this->quotas[$ressource];
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -218,23 +219,26 @@ 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)
|
||||||
*/
|
*/
|
||||||
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 :
|
||||||
exec("sudo /usr/lib/alternc/quota_get ".intval($cuid)." &> /dev/null &",$a);
|
$a = array();
|
||||||
if (!isset($a[1]) || $size!=$a[1]) {
|
exec("sudo /usr/lib/alternc/quota_get " . intval($cuid) . " &> /dev/null &", $a);
|
||||||
$err->raise("quota",_("Error writing the quota entry!"));
|
if (!isset($a[1]) || $size != $a[1]) {
|
||||||
|
$err->raise("quota", _("Error writing the quota entry!"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,99 +252,102 @@ class m_quota {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erase all quota information about the user.
|
* Erase all quota information about the user.
|
||||||
*/
|
*/
|
||||||
function delquotas() {
|
function delquotas() {
|
||||||
global $db,$err,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("quota","delquota");
|
$err->log("quota", "delquota");
|
||||||
$db->query("DELETE FROM quotas WHERE uid='$cuid';");
|
$db->query("DELETE FROM quotas WHERE uid='$cuid';");
|
||||||
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
|
||||||
*/
|
*/
|
||||||
function getdefaults() {
|
function getdefaults() {
|
||||||
global $db;
|
global $db;
|
||||||
$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");
|
||||||
$c[$type][$db->f("quota")] = $db->f("value");
|
$c[$type][$db->f("quota")] = $db->f("value");
|
||||||
}
|
}
|
||||||
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)
|
||||||
*/
|
*/
|
||||||
function setdefaults($newq) {
|
function setdefaults($newq) {
|
||||||
global $db;
|
global $db;
|
||||||
$qlist=$this->qlist();
|
$qlist = $this->qlist();
|
||||||
|
|
||||||
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
|
||||||
*/
|
*/
|
||||||
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)) {
|
||||||
$type=strtolower($type);
|
return false;
|
||||||
if (!preg_match("#^[a-z0-9]*$#",$type)) {
|
}
|
||||||
|
$type = strtolower($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
|
||||||
*/
|
*/
|
||||||
function listtype() {
|
function listtype() {
|
||||||
global $db;
|
global $db;
|
||||||
$db->query("SELECT distinct(type) FROM defquotas ORDER by type");
|
$db->query("SELECT distinct(type) FROM defquotas ORDER by type");
|
||||||
$t=array();
|
$t = array();
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$t[] = $db->f("type");
|
$t[] = $db->f("type");
|
||||||
}
|
}
|
||||||
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
|
||||||
|
@ -348,7 +355,7 @@ class m_quota {
|
||||||
function deltype($type) {
|
function deltype($type) {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
if($db->query("UPDATE membres SET type='default' WHERE type='$type'") &&
|
if ($db->query("UPDATE membres SET type='default' WHERE type='$type'") &&
|
||||||
$db->query("DELETE FROM defquotas WHERE type='$type'")) {
|
$db->query("DELETE FROM defquotas WHERE type='$type'")) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -356,26 +363,26 @@ 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.
|
||||||
*/
|
*/
|
||||||
function addquotas() {
|
function addquotas() {
|
||||||
global $db,$err,$cuid;
|
global $db, $err, $cuid;
|
||||||
$err->log("quota","addquota");
|
$err->log("quota", "addquota");
|
||||||
$ql=$this->qlist();
|
$ql = $this->qlist();
|
||||||
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");
|
||||||
|
|
||||||
foreach($ql as $res => $val) {
|
foreach ($ql as $res => $val) {
|
||||||
$db->query("SELECT value FROM defquotas WHERE quota='$res' AND type='$t'");
|
$db->query("SELECT value FROM defquotas WHERE quota='$res' AND type='$t'");
|
||||||
$q = $db->next_record() ? $db->f("value") : 0;
|
$q = $db->next_record() ? $db->f("value") : 0;
|
||||||
$this->setquota($res, $q);
|
$this->setquota($res, $q);
|
||||||
|
@ -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
|
||||||
|
@ -396,16 +403,16 @@ class m_quota {
|
||||||
case 'bw_web':
|
case 'bw_web':
|
||||||
return format_size($value);
|
return format_size($value);
|
||||||
case 'web':
|
case 'web':
|
||||||
return format_size($value*1024);
|
return format_size($value * 1024);
|
||||||
default:
|
default:
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* 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,103 +450,122 @@ 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) {
|
||||||
if($size>=$value){
|
if ($size >= $value) {
|
||||||
$size=str_pad(round($size/($value ? $value : 1), 1), 5, ' ', STR_PAD_LEFT);
|
$size = str_pad(round($size / ($value ? $value : 1), 1), 5, ' ', STR_PAD_LEFT);
|
||||||
return array('size'=>$size, 'unit'=>$unit);
|
return array('size' => $size, 'unit' => $unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -549,26 +575,26 @@ class m_quota {
|
||||||
// 0 = Pas de changement de couleur
|
// 0 = Pas de changement de couleur
|
||||||
// 1 = Progression du vert vers le rouge en fonction du porcentage
|
// 1 = Progression du vert vers le rouge en fonction du porcentage
|
||||||
// 2 = Progression du rouge vers le vert en fonction du porcentage
|
// 2 = Progression du rouge vers le vert en fonction du porcentage
|
||||||
function quota_displaybar($usage, $color_type=1) {
|
function quota_displaybar($usage, $color_type = 1) {
|
||||||
if ($color_type == 1) {
|
if ($color_type == 1) {
|
||||||
$csscolor = " background-color:".PercentToColor($usage);
|
$csscolor = " background-color:" . PercentToColor($usage);
|
||||||
} elseif ($color_type == 2) {
|
} elseif ($color_type == 2) {
|
||||||
$csscolor = " background-color:".PercentToColor(100-$usage);
|
$csscolor = " background-color:" . PercentToColor(100 - $usage);
|
||||||
} else {
|
} else {
|
||||||
$csscolor = "";
|
$csscolor = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
echo '<div class="progress-bar">';
|
echo '<div class="progress-bar">';
|
||||||
echo '<div class="barre" style="width:'.$usage.'%;'.$csscolor.'" ></div>';
|
echo '<div class="barre" style="width:' . $usage . '%;' . $csscolor . '" ></div>';
|
||||||
echo '<div class="txt">'.$usage.'%</div>';
|
echo '<div class="txt">' . $usage . '%</div>';
|
||||||
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,41 +603,42 @@ 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
|
||||||
*/
|
*/
|
||||||
function hook_admin_add_member() {
|
function hook_admin_add_member() {
|
||||||
global $err;
|
global $err;
|
||||||
$err->log("quota","hook_admin_add_member");
|
$err->log("quota", "hook_admin_add_member");
|
||||||
$this->addquotas();
|
$this->addquotas();
|
||||||
$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>";
|
||||||
|
|
||||||
$q=$this->getquota();
|
$q = $this->getquota();
|
||||||
foreach ($q as $k=>$v) {
|
foreach ($q as $k => $v) {
|
||||||
$str.=" <$k>\n";
|
$str.=" <$k>\n";
|
||||||
$str.=" <used>".($v["u"])."</used>\n";
|
$str.=" <used>" . ($v["u"]) . "</used>\n";
|
||||||
$str.=" <total>".($v["t"])."</total>\n";
|
$str.=" <total>" . ($v["t"]) . "</total>\n";
|
||||||
$str.=" </$k>\n";
|
$str.=" </$k>\n";
|
||||||
}
|
}
|
||||||
$str.="</quota>\n";
|
$str.="</quota>\n";
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} /* Class m_quota */
|
/* Class m_quota */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue