2006-04-26 12:28:53 +00:00
< ? php
2012-08-25 14:04:38 +00:00
/*
2006-04-26 12:28:53 +00:00
----------------------------------------------------------------------
AlternC - Web Hosting System
2012-08-25 14:04:38 +00:00
Copyright ( C ) 2000 - 2012 by the AlternC Development Team .
https :// alternc . org /
2006-04-26 12:28:53 +00:00
----------------------------------------------------------------------
LICENSE
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License ( GPL )
as published by the Free Software Foundation ; either version 2
of the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
To read the license please visit http :// www . gnu . org / copyleft / gpl . html
----------------------------------------------------------------------
Purpose of file : Administrate members and rights .
----------------------------------------------------------------------
*/
2012-08-25 14:04:38 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2013-02-07 16:55:50 +00:00
2006-04-26 12:28:53 +00:00
/**
2012-08-26 08:32:20 +00:00
* Manage the AlternC ' s account administration ( create / edit / delete )
2006-04-26 12:28:53 +00:00
*/
class m_admin {
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** $enabled tells if the logged user is super - admin or not
2006-04-26 12:28:53 +00:00
*/
var $enabled = 0 ;
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** List of the controls made for each TLD
*
* $tldmode is used by the administration panel , while choosing
* the authorized TLDs . It ' s an array of strings explaining the current state of the TLD .
*/
2012-08-25 14:04:38 +00:00
public $tldmode = array ();
2006-04-26 12:28:53 +00:00
2013-09-12 13:17:04 +00:00
var $archive = '' ;
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-26 08:32:20 +00:00
/** Constructor
2006-04-26 12:28:53 +00:00
*/
function m_admin () {
global $db , $cuid ;
$db -> query ( " SELECT su FROM membres WHERE uid=' $cuid '; " );
$db -> next_record ();
$this -> enabled = $db -> f ( " su " );
2012-08-25 14:04:38 +00:00
$this -> tldmode = array (
0 => _ ( " This TLD is forbidden " ),
1 => _ ( " primary DNS is checked in WHOIS db " ),
2 => _ ( " primary & secondary DNS are checked in WHOIS db " ),
3 => _ ( " Domain must exist, but don't do any DNS check " ),
4 => _ ( " Domain can be installed, no check at all " ),
5 => _ ( " Domain can be installed, force NO DNS hosting " ),
);
2013-09-12 13:17:04 +00:00
$this -> archive = variable_get ( 'archive_del_data' , '' , 'If folder specified html folder of deleted user is archived, else it is deleted. ' );
2006-04-26 12:28:53 +00:00
}
2013-02-18 10:01:28 +00:00
function hook_menu () {
global $mem , $cuid , $debug_alternc , $L_INOTIFY_UPDATE_DOMAIN ;
if ( ! $mem -> checkRight ()) return false ;
$obj = array (
'title' => _ ( " Administration " ),
'ico' => 'images/admin.png' ,
'link' => 'toggle' ,
'class' => 'adminmenu' ,
'pos' => 10 ,
'links' =>
array (
array (
'txt' => _ ( " Manage AlternC accounts " ),
'url' => 'adm_list.php' ,
'class' => 'adminmenu'
),
array (
'txt' => _ ( " User Quotas " ),
'url' => 'quotas_users.php?mode=4' ,
'class' => 'adminmenu'
),
)
) ;
if ( $cuid == 2000 ) {
$obj [ 'links' ][] =
array (
'txt' => _ ( " Admin Control Panel " ),
'url' => 'adm_panel.php' ,
'class' => 'adminmenu'
);
$obj [ 'links' ][] =
array (
'txt' => _ ( " PhpMyAdmin " ),
'url' => '/alternc-sql/' ,
2013-03-01 16:40:08 +00:00
'class' => 'adminmenu' ,
'target' => '_blank' ,
2013-02-18 10:01:28 +00:00
);
$obj [ 'links' ][] =
array (
'txt' => ( $debug_alternc -> status ) ? _ ( " Switch debug Off " ) : _ ( " Switch debug On " ),
'url' => " alternc_debugme.php?enable= " . ( $debug_alternc -> status ? " 0 " : " 1 " ),
'class' => 'adminmenu'
);
if ( empty ( $L_INOTIFY_UPDATE_DOMAIN ) || file_exists ( " $L_INOTIFY_UPDATE_DOMAIN " ) ) {
$obj [ 'links' ][] =
array (
'txt' => _ ( " Applying... " ),
'url' => 'javascript:alert(\'' . _ ( " Domain changes are already applying " ) . '\');' ,
'class' => 'adminmenu' ,
);
} else {
$obj [ 'links' ][] =
array (
'txt' => _ ( " Apply changes " ),
'url' => 'adm_update_domains.php' ,
'class' => 'adminmenu' ,
'onclick' => 'return confirm("' . addslashes ( _ ( " Server configuration changes are applied every 5 minutes. Do you want to do it right now? " )) . '");' ,
);
} // L_INOTIFY_UPDATE_DOMAIN
} // cuid == 2000
return $obj ;
}
2013-09-12 09:28:31 +00:00
function stop_if_jobs_locked () {
if ( file_exists ( ALTERNC_LOCK_JOBS )) {
echo " There is a file " . ALTERNC_LOCK_JOBS . " \n " ;
echo " So no jobs are allowed \n " ;
echo " Did you launch alternc.install ? \n " ;
die ();
}
}
2012-08-25 15:38:26 +00:00
2013-09-18 09:18:10 +00:00
# return the uid of an alternc account
function get_uid_by_login ( $login ) {
global $db ;
$db -> query ( " SELECT uid FROM membres WHERE login=' $login '; " );
if ( ! $db -> next_record ()) {
return null ;
}
return $db -> f ( 'uid' );
}
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Returns the known information about a hosted account
2007-05-11 01:29:28 +00:00
*
2006-04-26 12:28:53 +00:00
* Returns all what we know about an account ( contents of the tables
* < code > membres </ code > et < code > local </ code > )
* Ckecks if the account is super - admin
* @ param integer $uid a unique integer identifying the account
* @ return an associative array containing all the fields of the
* table < code > membres </ code > and < code > local </ code > of the corresponding account .
* Returns FALSE if an error occurs .
*/
2013-01-23 15:12:18 +00:00
function get ( $uid , $recheck = false ) {
global $err , $db , $lst_users_properties ;
2006-04-26 12:28:53 +00:00
// $err->log("admin","get",$uid);
if ( ! $this -> enabled ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2013-01-23 15:12:18 +00:00
if ( ! isset ( $lst_users_properties ) || empty ( $lst_users_properties ) || ! is_array ( $lst_users_properties ) || $recheck ) {
$lst_users_properties = array ();
2013-01-23 16:18:42 +00:00
$db -> query ( "
SELECT
m . uid as muid ,
l .* ,
m .* ,
parent . login as parentlogin ,
2013-02-21 09:03:08 +00:00
dbs . name as db_server_name ,
2013-01-23 16:18:42 +00:00
m . renewed + INTERVAL m . duration MONTH as expiry ,
CASE
WHEN m . duration IS NULL THEN 0
WHEN m . renewed + INTERVAL m . duration MONTH <= NOW () THEN 3
WHEN m . renewed <= NOW () THEN 2
ELSE 1 END 'status'
FROM membres as m
LEFT JOIN membres as parent ON ( parent . uid = m . creator )
2013-02-21 09:03:08 +00:00
LEFT JOIN db_servers as dbs ON ( m . db_server_id = dbs . id )
2013-01-23 16:18:42 +00:00
LEFT JOIN local as l ON ( m . uid = l . uid ) ; " );
2013-01-23 15:12:18 +00:00
while ( $db -> next_record ()) {
2013-01-23 15:44:15 +00:00
$lst_users_properties [ $db -> f ( 'muid' )] = $db -> Record ;
2013-01-23 15:12:18 +00:00
}
}
if ( ! isset ( $lst_users_properties [ $uid ]) ) {
if ( ! $recheck ) {
// don't exist, but is not a forced check. Do a forced check
return $this -> get ( $uid , true );
}
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Account not found " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2013-01-23 15:12:18 +00:00
return $lst_users_properties [ $uid ];
2006-04-26 12:28:53 +00:00
}
2012-08-25 15:38:26 +00:00
/* ----------------------------------------------------------------- */
/** Returns the known information about a specific hosted account
2009-01-28 20:02:01 +00:00
* Similar to get_list () but for creators / resellers .
*/
function get_creator ( $uid ) {
global $err , $db ;
// $err->log("admin","get",$uid);
if ( ! $this -> enabled ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2009-01-28 20:02:01 +00:00
return false ;
}
$db -> query ( " SELECT m.*, parent.login as parentlogin FROM membres as m LEFT JOIN membres as parent ON (parent.uid = m.creator) WHERE m.uid=' $uid '; " );
if ( $db -> num_rows ()) {
$db -> next_record ();
$c = $db -> Record ;
} else {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Account not found " ));
2009-01-28 20:02:01 +00:00
return false ;
}
$db -> query ( " SELECT * FROM local WHERE uid=' $uid '; " );
if ( $db -> num_rows ()) {
$db -> next_record ();
reset ( $db -> Record );
while ( list ( $key , $val ) = each ( $db -> Record )) {
2011-04-27 15:44:19 +00:00
$c [ $key ] = $val ;
2009-01-28 20:02:01 +00:00
}
}
$db -> query ( " SELECT count(*) as nbcreated FROM membres WHERE creator=' $uid '; " );
if ( $db -> num_rows ()) {
$db -> next_record ();
reset ( $db -> Record );
while ( list ( $key , $val ) = each ( $db -> Record )) {
2011-04-27 15:44:19 +00:00
$c [ $key ] = $val ;
2009-01-28 20:02:01 +00:00
}
}
return $c ;
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** @ return TRUE if there ' s only ONE admin account
2012-08-26 08:32:20 +00:00
* @ return boolean TRUE if there is only one admin account
* ( allow the program to prevent the destruction of the last admin account )
2006-04-26 12:28:53 +00:00
*/
function onesu () {
global $db ;
$db -> query ( " SELECT COUNT(*) AS cnt FROM membres WHERE su=1 " );
$db -> next_record ();
return ( $db -> f ( " cnt " ) == 1 );
}
2007-09-09 21:55:18 +00:00
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Returns the list of the hosted accounts
2007-05-11 01:29:28 +00:00
*
2006-04-26 12:28:53 +00:00
* Returns all what we know about ALL the accounts ( contents of the tables
* < code > membres </ code > et < code > local </ code > )
* Check for super - admin accounts
* @ param
* @ return an associative array containing all the fields of the
* table < code > membres </ code > and < code > local </ code > of all the accounts .
* Returns FALSE if an error occurs .
*/
2013-09-23 10:11:59 +00:00
function get_list ( $all = 0 , $creator = 0 , $pattern = FALSE , $pattern_type = FALSE ) {
2006-04-26 12:28:53 +00:00
global $err , $mem , $cuid ;
$err -> log ( " admin " , " get_list " );
if ( ! $this -> enabled ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db = new DB_System ();
2013-09-21 15:03:59 +00:00
2013-09-23 10:11:59 +00:00
if ( $pattern ) {
2013-09-21 15:03:59 +00:00
2013-09-23 10:11:59 +00:00
if ( $pattern_type === 'domaine' ) {
2013-09-21 15:03:59 +00:00
2013-09-23 10:11:59 +00:00
$request = 'SELECT compte AS uid FROM domaines WHERE 1' ;
if ( $pattern && preg_match ( '/[.a-zA-Z0-9]+/' , $pattern ))
$request .= sprintf ( ' AND domaine LIKE "%%%s%%"' , $pattern );
2013-09-23 11:11:45 +00:00
$request .= ' GROUP BY uid' ;
2013-09-23 10:11:59 +00:00
} elseif ( $pattern_type === 'login' ) {
$request = 'SELECT uid FROM membres WHERE 1' ;
if ( $pattern && preg_match ( '/[a-zA-Z0-9]+/' , $pattern ))
$request .= sprintf ( ' AND login LIKE "%%%s%%"' , $pattern );
if ( $creator )
$request .= sprintf ( ' AND creator = "%s"' , $creator );
if ( $mem -> user [ 'uid' ] != 2000 && ! $all )
$request .= sprintf ( ' AND creator = "%s"' , $cuid );
$request .= ' ORDER BY login;' ;
} else {
$err -> raise ( " admin " , _ ( " Invalid pattern type provided. Are you even performing a legitimate action? " ));
return FALSE ;
}
2013-09-21 15:03:59 +00:00
2006-04-26 12:28:53 +00:00
} else {
2013-09-23 10:11:59 +00:00
if ( $creator )
{
// Limit listing to a specific reseller
$request = " SELECT uid FROM membres WHERE creator=' " . $creator . " ' ORDER BY login; " ;
} elseif ( $mem -> user [ 'uid' ] == 2000 || $all ) {
$request = " SELECT uid FROM membres ORDER BY login; " ;
} else {
$request = " SELECT uid FROM membres WHERE creator=' " . $cuid . " ' ORDER BY login; " ;
}
2006-04-26 12:28:53 +00:00
}
2013-09-21 15:03:59 +00:00
$db -> query ( $request );
2006-04-26 12:28:53 +00:00
if ( $db -> num_rows ()) {
while ( $db -> next_record ()) {
$c [] = $this -> get ( $db -> f ( " uid " ));
}
return $c ;
} else {
return false ;
}
}
2010-04-11 13:39:24 +00:00
2012-08-25 15:38:26 +00:00
/* ----------------------------------------------------------------- */
/** Send an email to all AlternC ' s accounts
* @ param $subject string Subject of the email to send
* @ param $message string Message to send
* @ param $from string expeditor of that email .
* @ return true if the mail has been successfully sent .
*/
2012-08-22 14:02:37 +00:00
function mailallmembers ( $subject , $message , $from ) {
global $err , $mem , $cuid , $db ;
$err -> log ( " admin " , " mailallmembers " );
if ( ! $this -> enabled ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2012-08-22 14:02:37 +00:00
return false ;
}
$subject = trim ( $subject );
$message = trim ( $message );
$from = trim ( $from );
if ( empty ( $subject ) || empty ( $message ) || empty ( $from ) ){
2012-10-18 07:52:54 +00:00
$err -> raise ( " admin " , _ ( " Subject, message and sender are mandatory " ));
2012-08-22 14:02:37 +00:00
return false ;
}
if ( checkmail ( $from ) != 0 ) {
2012-10-18 07:52:54 +00:00
$err -> raise ( " admin " , _ ( " Sender is syntaxically incorrect " ));
2012-08-22 14:02:37 +00:00
return false ;
}
@ set_time_limit ( 1200 );
2012-10-18 07:52:54 +00:00
$db -> query ( " SELECT DISTINCT mail FROM membres WHERE mail!=''; " );
2012-08-22 14:02:37 +00:00
while ( $db -> next_record ()) {
// Can't do BCC due to postfix limitation
2012-10-18 07:52:54 +00:00
// FIXME: use phpmailer, far better for mass-mailing than sendmail (reply-to issue among others)
2012-08-22 14:02:37 +00:00
mail ( $db -> f ( 'mail' ), $subject , $message , null , " -f $from " );
}
return true ;
}
2012-08-25 15:38:26 +00:00
/* ----------------------------------------------------------------- */
/** Returns an array with the known information about resellers ( uid , login , number of accounts )
2009-02-03 21:00:00 +00:00
* Does not include account 2000 in the list .
2009-01-28 20:02:01 +00:00
* May only be called by the admin account ( 2000 )
2009-02-03 21:00:00 +00:00
* If there are no reseller accounts , returns an empty array .
2009-01-28 20:02:01 +00:00
*/
function get_creator_list () {
global $err , $mem , $cuid ;
2009-02-03 20:58:04 +00:00
$creators = array ();
2009-01-28 20:02:01 +00:00
$err -> log ( " admin " , " get_reseller_list " );
2012-08-26 08:32:20 +00:00
if ( ! $this -> enabled || $cuid != 2000 ) {
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2009-01-28 20:02:01 +00:00
return false ;
}
$db = new DB_System ();
2012-10-18 07:52:54 +00:00
$db -> query ( " SELECT DISTINCT creator FROM membres WHERE creator <> 0 ORDER BY creator ASC; " );
2009-01-28 20:02:01 +00:00
if ( $db -> num_rows ()) {
while ( $db -> next_record ()) {
2009-02-03 20:58:04 +00:00
$creators [] = $this -> get_creator ( $db -> f ( " creator " ));
2009-01-28 20:02:01 +00:00
}
}
2013-09-23 12:48:18 +00:00
$creators2 = array ();
foreach ( $creators as $cc ) {
$creators2 [ $cc [ 'uid' ]] = $cc ;
}
return $creators2 ;
2009-01-28 20:02:01 +00:00
}
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Check if I am the creator of the member $uid
2006-04-26 12:28:53 +00:00
* @ param integer $uid a unique integer identifying the account
2012-08-25 15:38:26 +00:00
* @ return boolean TRUE if I am the creator of that account . FALSE else .
2006-04-26 12:28:53 +00:00
*/
function checkcreator ( $uid ) {
global $err , $mem , $db , $cuid ;
if ( $cuid == 2000 ) {
return true ;
}
$db -> query ( " SELECT creator FROM membres WHERE uid=' $uid '; " );
$db -> next_record ();
2009-09-08 05:29:38 +00:00
if ( $db -> Record [ " creator " ] != $cuid ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2006-04-26 12:28:53 +00:00
return false ;
}
return true ;
}
2012-12-03 08:11:06 +00:00
// When the admin want to delegate a subdomain to an account
function add_shared_domain ( $u , $domain_name ) {
global $db , $err , $dom , $mem , $cuid ;
$err -> log ( " admin " , " add_shared_domain " , $u . " / " . $domain_name );
2012-08-25 15:38:26 +00:00
2012-12-03 08:11:06 +00:00
if ( ! $mem -> checkright () ) {
$err -> raise ( " admin " , _ ( " -- Only administrators can do that! -- " ));
return false ;
}
// Check if this domain exist on this admin account
if ( ! in_array ( $domain_name , $dom -> enum_domains ())) {
$err -> raise ( " admin " , _ ( " You don't seem to be allowed to delegate this domain " ));
$err -> log ( " admin " , " add_shared_domain " , " domain not allowed " );
return false ;
}
// Clean the domain_name
$domain_name = preg_replace ( " /^ \ . \ .*/ " , " " , $domain_name );
$mem -> su ( $u );
$dom -> lock ();
// option : 1=hébergement dns, 1=noerase, empeche de modifier, 1=force
$dom -> add_domain ( $mem -> user [ 'login' ] . " . " . $domain_name , 1 , 1 , 1 );
$dom -> unlock ();
$mem -> unsu ();
return true ;
}
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Creates a new hosted account
2007-05-11 01:29:28 +00:00
*
2006-04-26 12:28:53 +00:00
* Creates a new hosted account ( in the tables < code > membres </ code >
* and < code > local </ code > ) . Prevents any manipulation of the account if
* the account $mid is not super - admin .
*
* @ param $login string Login name like [ a - z ][ a - z0 - 9 ] *
* @ param $pass string Password ( max . 64 characters )
* @ param $nom string Name of the account owner
* @ param $prenom string First name of the account owner
* @ param $mail string Email address of the account owner , useful to get
* one ' s lost password
* @ pararm $type string Account type for quotas
* @ return boolean Returns FALSE if an error occurs , TRUE if not .
*/
2013-02-21 09:03:08 +00:00
function add_mem ( $login , $pass , $nom , $prenom , $mail , $canpass = 1 , $type = 'default' , $duration = 0 , $notes = " " , $force = 0 , $create_dom = false , $db_server_id ) {
2013-05-14 08:24:17 +00:00
global $err , $quota , $classes , $cuid , $mem , $L_MYSQL_DATABASE , $L_MYSQL_LOGIN , $hooks , $action ;
2006-04-26 12:28:53 +00:00
$err -> log ( " admin " , " add_mem " , $login . " / " . $mail );
if ( ! $this -> enabled ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2013-02-21 09:03:08 +00:00
if ( empty ( $db_server_id )) {
$err -> raise ( " admin " , _ ( " Missing db_server field " ));
return false ;
}
2010-06-24 00:23:08 +00:00
if (( $login == " " ) || ( $pass == " " )) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " All fields are mandatory " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2010-06-24 00:23:08 +00:00
if ( ! $force ) {
if ( $mail == " " ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " All fields are mandatory " ));
2011-05-22 17:23:59 +00:00
return false ;
2010-06-24 00:23:08 +00:00
}
if ( checkmail ( $mail ) != 0 ){
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Please enter a valid email address " ));
2011-05-22 17:23:59 +00:00
return false ;
2010-06-24 00:23:08 +00:00
}
2006-04-26 12:28:53 +00:00
}
$login = strtolower ( $login );
2013-10-17 14:13:26 +00:00
if ( ! preg_match ( " #^[a-z0-9]+ $ # " , $login )) { //$
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Login can only contains characters a-z and 0-9 " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2012-11-06 07:45:11 +00:00
if ( strlen ( $login ) > 14 ) {
// Not an arbitrary value : MySQL user names can be up to 16 characters long
// If we want to allow people to create a few mysql_user (and we want to!)
// we have to limit the login lenght
$err -> raise ( " admin " , _ ( " The login is too long (14 chars max) " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2012-08-26 08:32:20 +00:00
// Some login are not allowed...
2006-04-26 22:07:01 +00:00
if ( $login == $L_MYSQL_DATABASE || $login == $L_MYSQL_LOGIN || $login == " mysql " || $login == " root " ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Login can only contains characters a-z, 0-9 and - " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$pass = _md5cr ( $pass );
$db = new DB_System ();
2012-08-26 08:32:20 +00:00
// Already exist?
2006-04-26 12:28:53 +00:00
$db -> query ( " SELECT count(*) AS cnt FROM membres WHERE login=' $login '; " );
$db -> next_record ();
if ( ! $db -> f ( " cnt " )) {
2010-01-15 01:40:24 +00:00
$db -> query ( " SELECT max(m.uid)+1 as nextid FROM membres m " );
2006-04-26 12:28:53 +00:00
if ( ! $db -> next_record ()) {
2011-04-27 15:44:19 +00:00
$uid = 2000 ;
2006-04-26 12:28:53 +00:00
} else {
2011-04-27 15:44:19 +00:00
$uid = $db -> Record [ " nextid " ];
if ( $uid <= 2000 ) $uid = 2000 ;
2006-04-26 12:28:53 +00:00
}
2013-02-21 09:03:08 +00:00
$db -> query ( " INSERT INTO membres (uid,login,pass,mail,creator,canpass,type,created,notes,db_server_id) VALUES (' $uid ',' $login ',' $pass ',' $mail ',' $cuid ',' $canpass ', ' $type ', NOW(), ' $notes ', ' $db_server_id '); " );
2006-04-26 12:28:53 +00:00
$db -> query ( " INSERT INTO local(uid,nom,prenom) VALUES(' $uid ',' $nom ',' $prenom '); " );
$this -> renew_update ( $uid , $duration );
2013-05-14 08:24:17 +00:00
#exec("sudo /usr/lib/alternc/mem_add ".$login." ".$uid);
$action -> create_dir ( getuserpath ( " $login " ));
2013-08-08 15:56:09 +00:00
$action -> fix_user ( $uid );
2013-05-14 08:24:17 +00:00
2012-08-26 08:32:20 +00:00
// Triggering hooks
2006-04-26 12:28:53 +00:00
$mem -> su ( $uid );
2012-08-25 15:38:26 +00:00
// TODO: old hook method FIXME: when unused remove this
2012-10-15 15:41:09 +00:00
/*
2006-04-26 12:28:53 +00:00
foreach ( $classes as $c ) {
2011-04-27 15:44:19 +00:00
if ( method_exists ( $GLOBALS [ $c ], " alternc_add_member " )) {
$GLOBALS [ $c ] -> alternc_add_member ();
}
2006-04-26 12:28:53 +00:00
}
2012-10-15 15:41:09 +00:00
*/
$hooks -> invoke ( " alternc_add_member " );
2012-08-26 08:32:20 +00:00
// New hook way
2012-12-03 08:11:06 +00:00
$hooks -> invoke ( " hook_admin_add_member " , array (), array ( 'quota' )); // First !!! The quota !!! Etherway, we can't be sure to be able to create all
2012-08-25 15:38:26 +00:00
$hooks -> invoke ( " hook_admin_add_member " );
2006-04-26 12:28:53 +00:00
$mem -> unsu ();
2012-12-03 08:11:06 +00:00
if ( ! empty ( $create_dom )) {
$this -> add_shared_domain ( $uid , $create_dom );
}
2006-04-26 12:28:53 +00:00
return $uid ;
} else {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " This login already exists " ));
2006-04-26 12:28:53 +00:00
return false ;
}
}
2012-08-25 15:38:26 +00:00
/* ----------------------------------------------------------------- */
/** AlternC ' s standard function called when a user is created
2009-01-29 00:54:52 +00:00
* This sends an email if configured through the interface .
*/
2012-08-25 15:38:26 +00:00
function hook_admin_add_member () {
2012-12-05 16:52:03 +00:00
global $err , $cuid , $L_FQDN , $L_HOSTING ;
2009-01-29 00:54:52 +00:00
$dest = variable_get ( 'new_email' );
if ( ! $dest ) {
return false ;
}
$db = new DB_System ();
if ( ! $db -> query ( " SELECT m.*, parent.login as parentlogin FROM membres m LEFT JOIN membres parent ON parent.uid=m.creator WHERE m.uid=' $cuid ' " )) {
2012-12-05 16:52:03 +00:00
$err -> raise ( " admin " , sprintf ( _ ( " query failed: %s " ), $db -> Error ));
2009-01-29 00:54:52 +00:00
return false ;
}
if ( $db -> next_record ()) {
2012-08-25 15:38:26 +00:00
// TODO: put that string into gettext !
2009-01-29 00:54:52 +00:00
$mail = <<< EOF
A new AlternC account was created on % fqdn by % creator .
Account details
---------------
login : % login ( % uid )
email : % mail
createor : % creator ( % cuid )
can change password : % canpass
type : % type
notes : % notes
EOF ;
$mail = strtr ( $mail , array ( '%fqdn' => $L_FQDN ,
'%creator' => $db -> Record [ 'parentlogin' ],
'%uid' => $db -> Record [ 'uid' ],
'%login' => $db -> Record [ 'login' ],
'%mail' => $db -> Record [ 'mail' ],
'%cuid' => $db -> Record [ 'creator' ],
'%canpass' => $db -> Record [ 'canpass' ],
'%type' => $db -> Record [ 'type' ],
'%notes' => $db -> Record [ 'notes' ]));
2012-12-05 16:52:03 +00:00
$subject = sprintf ( _ ( " New account %s from %s on %s " ), $db -> Record [ 'login' ], $db -> Record [ 'parentlogin' ], $L_HOSTING );
if ( mail ( $dest , $subject , $mail , " From: postmaster@ $L_FQDN " )) {
//sprintf(_("Email successfully sent to %s"), $dest);
return true ;
2009-01-29 00:54:52 +00:00
} else {
2012-12-05 16:52:03 +00:00
$err -> raise ( " admin " , sprintf ( _ ( " Cannot send email to %s " ), $dest ));
return false ;
2009-01-29 00:54:52 +00:00
}
} else {
2012-12-05 16:52:03 +00:00
$err -> raise ( " admin " , sprintf ( _ ( " Query failed: %s " ), $db -> Error ));
return false ;
2009-01-29 00:54:52 +00:00
}
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Edit an account
2007-05-11 01:29:28 +00:00
*
2012-08-25 15:38:26 +00:00
* Change an account ( in the tables < code > membres </ code >
2006-04-26 12:28:53 +00:00
* and < code > local </ code > ) . Prevents any manipulation of the account if
* the account $mid is not super - admin .
*
* @ param $uid integer the uid number of the account we want to modify
* @ param login string new login name like [ a - z ][ a - z0 - 9 ] *
* @ param $pass string new password ( max . 64 characters )
* @ param $nom string new name of the account owner
* @ param $prenom string new first name of the account owner
* @ param $mail string new email address of the account owner
* @ param $enabled integer ( value : 0 or 1 ) activates or desactivates the
* @ param $type string new type of account
* access to the virtual desktop of this account .
* @ return boolean Returns FALSE if an error occurs , TRUE if not .
*/
2012-08-22 08:55:44 +00:00
function update_mem ( $uid , $mail , $nom , $prenom , $pass , $enabled , $canpass , $type = 'default' , $duration = 0 , $notes = " " , $reset_quotas = false ) {
2006-04-26 12:28:53 +00:00
global $err , $db ;
global $cuid , $quota ;
2012-08-22 08:55:44 +00:00
$notes = addslashes ( $notes );
2006-04-26 12:28:53 +00:00
$err -> log ( " admin " , " update_mem " , $uid );
if ( ! $this -> enabled ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db = new DB_System ();
if ( $pass ) {
$pass = _md5cr ( $pass );
$ssq = " ,pass=' $pass ' " ;
} else {
$ssq = " " ;
}
2009-09-08 05:29:38 +00:00
2006-04-26 12:28:53 +00:00
if (( $db -> query ( " UPDATE local SET nom=' $nom ', prenom=' $prenom ' WHERE uid=' $uid '; " ))
2011-04-27 15:44:19 +00:00
&& ( $db -> query ( " UPDATE membres SET mail=' $mail ', canpass=' $canpass ', enabled=' $enabled ', `type`=' $type ', notes=' $notes ' $ssq WHERE uid=' $uid '; " ))){
2013-09-12 09:07:09 +00:00
if ( $reset_quotas == " on " ) {
$quota -> addquotas ();
$quota -> synchronise_user_profile ();
}
2006-04-26 12:28:53 +00:00
$this -> renew_update ( $uid , $duration );
return true ;
}
else {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Account not found " ));
2006-04-26 12:28:53 +00:00
return false ;
}
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Lock an account
2006-04-26 12:28:53 +00:00
* Lock an account and prevent the user to access its account .
* @ param $uid integer the uid number of the account we want to lock
* @ return boolean Returns FALSE if an error occurs , TRUE if not .
*/
function lock_mem ( $uid ) {
global $err , $db ;
$err -> log ( " admin " , " lock_mem " , $uid );
if ( ! $this -> enabled ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db = new DB_System ();
if ( $db -> query ( " UPDATE membres SET enabled='0' WHERE uid=' $uid '; " )) {
return true ;
}
else {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Account not found " ));
2006-04-26 12:28:53 +00:00
return false ;
}
}
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** UnLock an account
2006-04-26 12:28:53 +00:00
* UnLock an account and prevent the user to access its account .
* @ param $uid integer the uid number of the account we want to unlock
* @ return boolean Returns FALSE if an error occurs , TRUE if not .
*/
function unlock_mem ( $uid ) {
global $err , $db ;
$err -> log ( " admin " , " unlock_mem " , $uid );
if ( ! $this -> enabled ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db = new DB_System ();
if ( $db -> query ( " UPDATE membres SET enabled='1' WHERE uid=' $uid '; " )) {
return true ;
}
else {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Account not found " ));
2006-04-26 12:28:53 +00:00
return false ;
}
}
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Deletes an account
2006-04-26 12:28:53 +00:00
* Deletes the specified account . Prevents any manipulation of the account if
* the account $mid is not super - admin .
* @ param $uid integer the uid number of the account we want to delete
* @ return boolean Returns FALSE if an error occurs , TRUE if not .
*/
function del_mem ( $uid ) {
2013-05-14 08:24:17 +00:00
global $err , $quota , $classes , $cuid , $mem , $dom , $hooks , $action ;
2006-04-26 12:28:53 +00:00
$err -> log ( " admin " , " del_mem " , $uid );
if ( ! $this -> enabled ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Only administrators can access this page! -- " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db = new DB_System ();
$tt = $this -> get ( $uid );
2007-05-11 01:29:28 +00:00
2006-04-26 12:28:53 +00:00
$mem -> su ( $uid );
2010-06-23 23:29:42 +00:00
// This script may take a long time on big accounts, let's give us some time ... Fixes 1132
@ set_time_limit ( 0 );
2006-04-26 12:28:53 +00:00
// WE MUST call m_dom before all others because of conflicts ...
2012-08-25 15:38:26 +00:00
$dom -> hook_admin_del_member ();
2006-04-26 12:28:53 +00:00
2013-08-14 13:17:16 +00:00
# New way of deleting or backup delted user html folders using action class
2013-05-14 08:24:17 +00:00
$path = getuserpath ( $tt [ 'login' ]);
2013-08-14 13:17:16 +00:00
$action -> archive ( $path );
2012-10-15 15:41:09 +00:00
$hooks -> invoke ( " alternc_del_member " );
2012-08-25 15:38:26 +00:00
$hooks -> invoke ( " hook_admin_del_member " );
if (( $db -> query ( " DELETE FROM membres WHERE uid=' $uid '; " )) &&
( $db -> query ( " DELETE FROM local WHERE uid=' $uid '; " ))) {
$mem -> unsu ();
// If this user was (one day) an administrator one, he may have a list of his own accounts. Let's associate those accounts to nobody as a creator.
$db -> query ( " UPDATE membres SET creator=2000 WHERE creator=' $uid '; " );
return true ;
} else {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Account not found " ));
2012-08-25 15:38:26 +00:00
$mem -> unsu ();
return false ;
}
2006-04-26 12:28:53 +00:00
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Renew an account
2006-04-26 12:28:53 +00:00
* Renew an account for its duration
* @ param $uid integer the uid number of the account we want to renew
* @ param $periods integer the number of periods we renew for
* @ return boolean Returns FALSE if an error occurs , TRUE if not .
*/
function renew_mem ( $uid , $periods = 1 ) {
global $err , $db ;
$periods = intval ( $periods );
if ( $periods == 0 )
return false ;
2012-08-25 15:38:26 +00:00
$query = " UPDATE membres SET renewed = renewed + INTERVAL (duration * $periods ) MONTH WHERE uid= ${ uid } ; " ;
2006-04-26 12:28:53 +00:00
if ( $db -> query ( $query )) {
return true ;
} else {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Account not found " ));
2006-04-26 12:28:53 +00:00
return false ;
}
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Update the duration information for an account
2006-04-26 12:28:53 +00:00
* @ param $uid integer the uid number of the account we want to update
* @ param $duration integer the new duration , in months , of the account
* @ return boolean Returns FALSE if an error occurs , TRUE if not .
*/
function renew_update ( $uid , $duration ) {
global $err , $db ;
if ( $duration == 0 ) {
if ( $db -> query ( " UPDATE membres SET duration = NULL, renewed = NULL WHERE uid= $uid ; " ))
return true ;
} else {
if ( $db -> query ( " UPDATE membres SET duration = $duration WHERE uid= $uid " ) &&
$db -> query ( " UPDATE membres SET renewed = NOW() WHERE uid= $uid and renewed is null; " ))
return true ;
}
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Account not found " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Get the expiry date for an account
2006-04-26 12:28:53 +00:00
* @ param $uid integer The uid number of the account
* @ return string The expiry date , a string as printed by MySQL
*/
function renew_get_expiry ( $uid ) {
2013-01-23 16:18:42 +00:00
$jj = $this -> get ( $uid );
if ( isset ( $jj ) && isset ( $jj [ 'expiry' ]) && ! empty ( $jj [ 'expiry' ]) ) {
return $jj [ 'expiry' ];
2006-04-26 12:28:53 +00:00
}
return '' ;
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Get the expiry status for an account
2006-04-26 12:28:53 +00:00
* @ param $uid integer The uid number of the account
* @ return integer The expiry status :
* 0 : account does not expire
* 1 : expires in more than duration ,
* 2 : expires within the duration
* 3 : has expired past the duration
*/
function renew_get_status ( $uid ) {
2013-01-23 16:18:42 +00:00
$jj = $this -> get ( $uid );
2006-04-26 12:28:53 +00:00
2013-01-23 16:18:42 +00:00
if ( isset ( $jj ) && isset ( $jj [ 'status' ]) && ! empty ( $jj [ 'status' ]) ) {
return $jj [ 'status' ];
2006-04-26 12:28:53 +00:00
}
2013-01-23 16:18:42 +00:00
2006-04-26 12:28:53 +00:00
return 0 ;
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Get the expired / about to expire accounts .
2006-04-26 12:28:53 +00:00
* @ return resource The recordset of the corresponding accounts
*/
function renew_get_expiring_accounts () {
global $db ;
if ( ! $db -> query ( " SELECT *, m.renewed + INTERVAL duration MONTH 'expiry', " .
" CASE WHEN m.duration IS NULL THEN 0 " .
" WHEN m.renewed + INTERVAL m.duration MONTH <= NOW() THEN 3 " .
" WHEN m.renewed <= NOW() THEN 2 " .
" ELSE 1 END 'status' FROM membres m, local l " .
" WHERE m.uid = l.uid " .
" HAVING status=2 or status=3 ORDER BY status DESC, expiry; " ))
return false ;
else {
2011-03-06 18:06:27 +00:00
$res = array ();
2006-04-26 12:28:53 +00:00
while ( $db -> next_record ())
2011-03-06 18:06:27 +00:00
$res [] = $db -> Record ;
2006-04-26 12:28:53 +00:00
return $res ;
}
}
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Turns a common account into a super - admin account
2006-04-26 12:28:53 +00:00
* @ param $uid integer the uid number of the common account we want to turn into a
* super - admin account .
* @ return Returns FALSE if an error occurs , TRUE if not .
*/
function normal2su ( $uid ) {
global $err , $db ;
$db -> query ( " SELECT su FROM membres WHERE uid=' $uid '; " );
if ( ! $db -> next_record ()) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Account not found " ));
2006-04-26 12:28:53 +00:00
return false ;
2007-05-11 01:29:28 +00:00
}
2006-04-26 12:28:53 +00:00
if ( $db -> Record [ " su " ] != 0 ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " This account is ALREADY an administrator account " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db -> query ( " UPDATE membres SET su=1 WHERE uid=' $uid '; " );
return true ;
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Turns a super - admin account into a common account
2006-04-26 12:28:53 +00:00
* @ param $uid integer the uid number of the super - admin account we want to turn into a
* common account .
* @ return boolean Returns FALSE if an error occurs , TRUE if not .
*/
function su2normal ( $uid ) {
global $err , $db ;
$db -> query ( " SELECT su FROM membres WHERE uid=' $uid '; " );
if ( ! $db -> next_record ()) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Account not found " ));
2006-04-26 12:28:53 +00:00
return false ;
}
if ( $db -> Record [ " su " ] != 1 ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " This account is NOT an administrator account! " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db -> query ( " UPDATE membres SET su=0 WHERE uid=' $uid '; " );
return true ;
}
2012-08-26 08:32:20 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** List of the authorized TLDs
2006-04-26 12:28:53 +00:00
* Returns the list of the authorized TLDs and also the way they are
* authorized . A TLD is the last members ( or the last two ) of a
* domain . For example , " com " , " org " etc ... AlternC keeps a table
* containing the list of the TLDs authorized to be installed on the
* server with the instructions to validate the installation of a
* domain for each TLD ( if necessary ) .
* @ return array An associative array like $r [ " tld " ], $r [ " mode " ] where tld
* is the tld and mode is the authorized mode .
*/
function listtld () {
global $db ;
$db -> query ( " SELECT tld,mode FROM tld ORDER BY tld; " );
while ( $db -> next_record ()) {
$c [] = $db -> Record ;
}
return $c ;
}
2012-08-26 08:32:20 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-26 08:32:20 +00:00
/** List the hosted domains on this server
2006-04-26 12:28:53 +00:00
* Return the list of hosted domains on this server , ( an array of associative arrays )
2010-04-02 16:40:37 +00:00
* @ param boolean $alsocheck Returns also errstr and errno telling the domains dig checks
* @ param boolean $forcecheck Force the check of dig domain even if a cache exists .
2006-04-26 12:28:53 +00:00
* @ return array $r [ $i ] / [ domaine ][ member ][ noerase ][ gesdns ][ gesmx ]
*/
2010-04-02 16:40:37 +00:00
function dom_list ( $alsocheck = false , $forcecheck = false ) {
2006-04-26 12:28:53 +00:00
global $db ;
2010-04-02 16:40:37 +00:00
$cachefile = " /tmp/alternc_dig_check_cache " ;
$cachetime = 3600 ; // The dns cache file can be up to 1H old
if ( $alsocheck ) {
if ( ! $forcecheck && file_exists ( $cachefile ) && filemtime ( $cachefile ) + $cachetime > time ()) {
2011-05-03 07:25:51 +00:00
$checked = unserialize ( file_get_contents ( $cachefile ));
2010-04-02 16:40:37 +00:00
} else {
2011-05-03 07:25:51 +00:00
// TODO : do the check here (cf checkdom.php) and store it in $checked
$checked = $this -> checkalldom ();
file_put_contents ( $cachefile , serialize ( $checked ));
2010-04-02 16:40:37 +00:00
}
}
2011-10-18 19:09:44 +00:00
$db -> query ( " SELECT m.uid,m.login,d.domaine,d.gesdns,d.gesmx,d.noerase FROM domaines d LEFT JOIN membres m ON m.uid=d.compte ORDER BY domaine; " );
2006-04-26 12:28:53 +00:00
while ( $db -> next_record ()) {
2010-04-02 16:40:37 +00:00
$tmp = $db -> Record ;
if ( $alsocheck ) {
2011-05-03 07:25:51 +00:00
$tmp [ " errstr " ] = $checked [ $tmp [ " domaine " ]][ " errstr " ];
$tmp [ " errno " ] = $checked [ $tmp [ " domaine " ]][ " errno " ];
2010-04-02 16:40:37 +00:00
}
$c [] = $tmp ;
2006-04-26 12:28:53 +00:00
}
return $c ;
}
2012-08-25 15:38:26 +00:00
/* ----------------------------------------------------------------- */
2010-04-02 16:40:37 +00:00
/** Check all the domains for their NS MX and IPs
*/
function checkalldom () {
2010-04-11 08:41:08 +00:00
global $db , $L_NS1 , $L_NS2 , $L_MX , $L_PUBLIC_IP ;
2010-04-02 16:40:37 +00:00
$checked = array ();
$r = $db -> query ( " SELECT * FROM domaines ORDER BY domaine; " );
$dl = array ();
while ( $db -> next_record ()) {
$dl [ $db -> Record [ " domaine " ]] = $db -> Record ;
}
sort ( $dl );
foreach ( $dl as $c ) {
2012-08-25 15:38:26 +00:00
// For each domain check its type:
2010-04-02 16:40:37 +00:00
$errno = 0 ;
$errstr = " " ;
$dontexist = false ;
2012-08-25 15:38:26 +00:00
// Check the domain.
2010-04-02 16:40:37 +00:00
if ( $c [ " gesdns " ] == 1 ) {
2012-08-25 15:38:26 +00:00
// Check the NS pointing to us
2011-04-27 15:44:19 +00:00
$out = array ();
exec ( " dig +short NS " . escapeshellarg ( $c [ " domaine " ]), $out );
if ( count ( $out ) == 0 ) {
$dontexist = true ;
} else {
if ( ! in_array ( $L_NS1 . " . " , $out ) || ! in_array ( $L_NS2 . " . " , $out )) {
$errno = 1 ; $errstr .= " NS for this domain are not $L_NS1 and $L_NS2 BUT " . implode ( " , " , $out ) . " \n " ;
}
}
2010-04-02 16:40:37 +00:00
}
if ( $c [ " gesmx " ] == 1 && ! $dontexist ) {
2011-04-27 15:44:19 +00:00
$out = array ();
exec ( " dig +short MX " . escapeshellarg ( $c [ " domaine " ]), $out );
$out2 = array ();
foreach ( $out as $o ) {
list ( $t , $out2 []) = explode ( " " , $o );
}
if ( ! in_array ( $L_MX . " . " , $out2 )) {
$errno = 1 ; $errstr .= " MX is not $L_MX BUT " . implode ( " , " , $out2 ) . " \n " ;
}
2010-04-02 16:40:37 +00:00
}
if ( ! $dontexist ) {
2012-08-25 15:38:26 +00:00
// We list all subdomains and check they are pointing to us.
2011-04-27 15:44:19 +00:00
$db -> query ( " SELECT * FROM sub_domaines WHERE domaine=' " . addslashes ( $c [ " domaine " ]) . " ' ORDER BY sub; " );
while ( $db -> next_record ()) {
$d = $db -> Record ;
if ( $d [ " type " ] == 0 ) {
2012-08-25 15:38:26 +00:00
// Check the IP:
2011-04-27 15:44:19 +00:00
$out = array ();
exec ( " dig +short A " . escapeshellarg ( $d [ " sub " ] . (( $d [ " sub " ] != " " ) ? " . " : " " ) . $c [ " domaine " ]), $out );
if ( ! in_array ( $L_PUBLIC_IP , $out )) {
$errstr .= " subdomain ' " . $d [ " sub " ] . " ' don't point to $L_PUBLIC_IP but to " . implode ( " , " , $out ) . " \n " ;
$errno = 1 ;
}
}
}
2010-04-02 16:40:37 +00:00
}
if ( $dontexist ) {
2011-04-27 15:44:19 +00:00
$errno = 2 ;
$errstr = " Domain don't exist anymore ! " ;
2010-04-02 16:40:37 +00:00
}
if ( $errno == 0 ) $errstr = " OK " ;
$checked [ $c [ " domaine " ]] = array ( " errno " => $errno , " errstr " => $errstr );
}
return $checked ;
}
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Lock / Unlock a domain
2006-04-26 12:28:53 +00:00
* Lock ( or unlock ) a domain , so that the member will be ( not be ) able to delete it
* from its account
* @ param $dom string Domain name to lock / unlock
* @ return boolean TRUE if the domain has been locked / unlocked or FALSE if it does not exist .
*/
function dom_lock ( $domain ) {
global $db , $err ;
$db -> query ( " SELECT compte FROM domaines WHERE domaine=' $domain '; " );
if ( ! $db -> next_record ()) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " dom " , _ ( " Domain '%s' not found. " ), $domain );
2006-04-26 12:28:53 +00:00
return false ;
}
$db -> query ( " UPDATE domaines SET noerase=1-noerase WHERE domaine=' $domain '; " );
return true ;
}
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Add a new TLD to the list of the authorized TLDs
2006-04-26 12:28:53 +00:00
*
* @ param $tld string top - level domain to add ( org , com ... )
* @ param $mode integer number of the authorized mode ( 0 to 5 )
* @ return boolean TRUE if the tld has been successfully added , FALSE if not .
2007-05-11 01:29:28 +00:00
*/
2006-04-26 12:28:53 +00:00
function gettld ( $tld ) {
global $db , $err ;
$db -> query ( " SELECT mode FROM tld WHERE tld=' $tld '; " );
if ( ! $db -> next_record ()) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " This TLD does not exist " ));
2006-04-26 12:28:53 +00:00
return false ;
}
return $db -> Record [ " mode " ];
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Prints the list of the actually authorized TLDs
2006-04-26 12:28:53 +00:00
* @ param $current integer Value to select in the list
*/
function selecttldmode ( $current = false ) {
for ( $i = 0 ; $i < count ( $this -> tldmode ); $i ++ ) {
echo " <option value= \" $i\ " " ;
if ( $current == $i ) echo " selected= \" selected \" " ;
2007-05-11 07:21:23 +00:00
echo " > " . _ ( $this -> tldmode [ $i ]) . " </option> \n " ;
2006-04-26 12:28:53 +00:00
}
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Deletes the specified tld in the list of the authorized TLDs
2006-04-26 12:28:53 +00:00
* < b > Note </ b > : This function does not delete the domains depending
* on this TLD
* @ param $tld string The TLD you want to delete
* @ return boolean returns true if the TLD has been deleted , or
* false if an error occured .
*/
function deltld ( $tld ) {
global $db , $err ;
$db -> query ( " SELECT tld FROM tld WHERE tld=' $tld '; " );
if ( ! $db -> next_record ()) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " This TLD does not exist " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$db -> query ( " DELETE FROM tld WHERE tld=' $tld '; " );
return true ;
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Add a TLD to the list of the authorized TLDs during the installation
2006-04-26 12:28:53 +00:00
* @ param $tld string TLD we want to authorize
* @ param $mode integer Controls to make on this TLD .
* < b > Note : </ b > If you check in the whois , be sure that
* < code > m_domains </ code > knows how to name the whois of the specified
* domain !
* @ return boolean TRUE if the TLD has been successfully
* added . FALSE if not .
*/
function addtld ( $tld , $mode ) {
global $db , $err ;
if ( ! $tld ) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " The TLD name is mandatory " ));
2006-04-26 12:28:53 +00:00
return false ;
}
2012-10-30 09:26:03 +00:00
$tld = trim ( $tld );
2006-04-26 12:28:53 +00:00
$db -> query ( " SELECT tld FROM tld WHERE tld=' $tld '; " );
if ( $db -> next_record ()) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " This TLD already exist " ));
2006-04-26 12:28:53 +00:00
return false ;
}
if ( substr ( $tld , 0 , 1 ) == " . " ) $tld = substr ( $tld , 1 );
$mode = intval ( $mode );
if ( $mode == 0 ) $mode = " 0 " ;
$db -> query ( " INSERT INTO tld (tld,mode) VALUES (' $tld ',' $mode '); " );
return true ;
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Modify a TLD of the list of the authorized TLDs
2006-04-26 12:28:53 +00:00
* @ param $tld string TLD we want to modify
* @ param $mode integer Controls to make on this TLD .
* @ return boolean TRUE if the TLD has been successfully
* modified . FALSE if not .
*/
function edittld ( $tld , $mode ) {
global $db , $err ;
$db -> query ( " SELECT tld FROM tld WHERE tld=' $tld '; " );
if ( ! $db -> next_record ()) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " This TLD does not exist " ));
2006-04-26 12:28:53 +00:00
return false ;
}
$mode = intval ( $mode );
if ( $mode == 0 ) $mode = " 0 " ;
$db -> query ( " UPDATE tld SET mode=' $mode ' WHERE tld=' $tld '; " );
return true ;
}
2012-08-25 15:38:26 +00:00
2006-04-26 12:28:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-26 08:32:20 +00:00
/** Get the login name of the main administrator account
* @ return string the login name of admin , like 'root' for older alterncs
2006-04-26 12:28:53 +00:00
*/
function getadmin () {
global $db ;
$db -> query ( " SELECT login FROM membres WHERE uid = '2000'; " );
$db -> next_record ();
return $db -> f ( " login " );
}
2009-11-30 05:02:53 +00:00
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** List the password policies currently installed in the policy table
2009-11-30 05:02:53 +00:00
* @ return array an indexed array of associative array from the MySQL " policy " table
*/
function listPasswordPolicies () {
2012-10-15 15:41:09 +00:00
global $db , $classes , $hooks ;
2009-11-30 05:02:53 +00:00
$tmp1 = array ();
$tmp2 = array ();
2012-10-15 15:41:09 +00:00
$tmp3 = array ();
2009-11-30 05:02:53 +00:00
$policies = array ();
$db -> query ( " SELECT * FROM policy; " );
while ( $db -> next_record ()) {
$tmp1 [ $db -> Record [ " name " ]] = $db -> Record ;
}
2012-10-15 15:41:09 +00:00
/* * /
2009-11-30 05:02:53 +00:00
foreach ( $classes as $c ) {
if ( method_exists ( $GLOBALS [ $c ], " alternc_password_policy " )) {
$res = $GLOBALS [ $c ] -> alternc_password_policy (); // returns an array
foreach ( $res as $k => $v ) {
$tmp2 [ $k ] = $v ;
}
}
}
2012-10-15 15:41:09 +00:00
/* */
$tmp3 = $hooks -> invoke ( " alternc_password_policy " );
foreach ( $tmp3 as $v ) {
foreach ( $v as $l => $m ) {
$tmp2 [ $l ] = $m ;
}
}
2009-11-30 05:02:53 +00:00
foreach ( $tmp2 as $k => $v ) {
if ( ! isset ( $tmp1 [ $k ])) {
// Default policy :
$db -> query ( " INSERT INTO policy SET name=' " . addslashes ( $k ) . " ', minsize=0, maxsize=64, classcount=0, allowlogin=0; " );
$tmp1 [ $k ] = array (
" minsize " => 0 , " maxsize " => 64 , " classcount " => 0 , " allowlogin " => 0
);
}
$policies [ $k ] = $tmp1 [ $k ];
$policies [ $k ][ " description " ] = _ ( $v );
unset ( $tmp1 [ $k ]);
}
foreach ( $tmp1 as $k => $v ) {
// Delete disabled modules :
$db -> query ( " DELETE FROM policy WHERE name=' " . addslashes ( $k ) . " '; " );
}
return $policies ;
}
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Change a password policy for one kind of password
2009-11-30 05:02:53 +00:00
*
* @ param $policy string Name of the policy to edit
* @ param $minsize integer Minimum Password size
* @ param $maxsize integer Maximum Password size
* @ param $classcount integer How many class of characters must this password have
* @ param $allowlogin boolean Do we allow the password to be like the login ?
* @ return boolean TRUE if the policy has been edited , or FALSE if an error occured .
*/
function editPolicy ( $policy , $minsize , $maxsize , $classcount , $allowlogin ) {
global $db ;
$minsize = intval ( $minsize );
$maxsize = intval ( $maxsize );
$classcount = intval ( $classcount );
$allowlogin = intval ( $allowlogin );
$db -> query ( " SELECT * FROM policy WHERE name=' " . addslashes ( $policy ) . " '; " );
if ( ! $db -> next_record ()) {
return false ; // Policy not found
}
if ( $minsize < 0 || $minsize > 64 || $maxsize < 0 || $maxsize > 64 || $maxsize < $minsize || $classcount < 0 || $classcount > 4 ) {
return false ; // Incorrect policy ...
}
$allowlogin = ( $allowlogin ) ? 1 : 0 ;
$db -> query ( " UPDATE policy SET minsize= $minsize , maxsize= $maxsize , classcount= $classcount , allowlogin= $allowlogin WHERE name=' " . addslashes ( $policy ) . " '; " );
return true ;
}
/* ----------------------------------------------------------------- */
2012-08-25 15:38:26 +00:00
/** Check a password and a login for a specific policy
2009-11-30 05:02:53 +00:00
* @ param $policy string Name of the policy to check for
* @ param $login The login that will be set
* @ param $password The password we have to check
* @ return boolean TRUE if the password if OK for this login and this policy , FALSE if it is not .
*/
function checkPolicy ( $policy , $login , $password ) {
2009-11-30 06:01:34 +00:00
global $db , $err ;
2013-01-31 17:17:18 +00:00
if ( empty ( $login )) {
2013-02-07 14:12:10 +00:00
$err -> raise ( " admin " , _ ( " Please enter a login " ));
2013-01-31 17:17:18 +00:00
return false ;
}
if ( empty ( $password )) {
2013-02-07 14:12:10 +00:00
$err -> raise ( " admin " , _ ( " Please enter a password " ));
2013-01-31 17:17:18 +00:00
return false ;
}
2009-11-30 06:01:34 +00:00
$pol = $this -> listPasswordPolicies ();
if ( ! $pol [ $policy ]) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " -- Program error -- The requested password policy does not exist! " ));
2009-11-30 06:01:34 +00:00
return false ;
}
$pol = $pol [ $policy ];
// Ok, now let's check it :
$plen = strlen ( $password );
if ( $plen < $pol [ " minsize " ]) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " The password length is too short according to the password policy " ));
2009-11-30 06:01:34 +00:00
return false ;
}
if ( $plen > $pol [ " maxsize " ]) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " The password is too long according to the password policy " ));
2009-11-30 06:01:34 +00:00
return false ;
}
if ( ! $pol [ " allowlogin " ]) {
// We do misc check on password versus login :
$logins = explode ( " @ " , $login );
$logins [] = $login ;
foreach ( $logins as $l ) {
2010-02-01 22:13:31 +00:00
if ( strpos ( $password , $l ) !== false ) {
2012-08-25 14:04:38 +00:00
$err -> raise ( " admin " , _ ( " The password policy prevents you to use your login name inside your password " ));
2009-11-30 06:01:34 +00:00
return false ;
}
}
}
if ( $pol [ " classcount " ] > 0 ) {
$cls = array ( 0 , 0 , 0 , 0 , 0 );
for ( $i = 0 ; $i < strlen ( $password ); $i ++ ) {
$p = substr ( $password , $i , 1 );
if ( strpos ( " abcdefghijklmnopqrstuvwxyz " , $p ) !== false ) {
$cls [ 0 ] = 1 ;
} elseif ( strpos ( " ABCDEFGHIJKLMNOPQRSTUVWXYZ " , $p ) !== false ) {
$cls [ 1 ] = 1 ;
} elseif ( strpos ( " 0123456789 " , $p ) !== false ) {
$cls [ 2 ] = 1 ;
} elseif ( strpos ( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`' , $p ) !== false ) {
$cls [ 3 ] = 1 ;
} else {
$cls [ 4 ] = 1 ;
}
} // foreach
$clc = array_sum ( $cls );
if ( $clc < $pol [ " classcount " ]) {
2012-08-26 08:32:20 +00:00
$err -> raise ( " admin " , _ ( " Your password contains not enough different classes of character, between low-case, up-case, figures and special characters. " ));
2009-11-30 06:01:34 +00:00
return false ;
}
}
return true ; // congratulations !
2009-11-30 05:02:53 +00:00
}
2012-09-03 07:36:00 +00:00
/* ----------------------------------------------------------------- */
/** hook function called by AlternC - upnp to know which open
* tcp or udp ports this class requires or suggests
* @ return array a key => value list of port protocol name mandatory values
* @ access private
*/
function hook_upnp_list () {
return array (
" http " => array ( " port " => 80 , " protocol " => " tcp " , " mandatory " => 1 ),
" https " => array ( " port " => 443 , " protocol " => " tcp " , " mandatory " => 0 ),
" ssh " => array ( " port " => 22 , " protocol " => " tcp " , " mandatory " => 0 ),
);
}
2006-04-26 12:28:53 +00:00
} /* Classe ADMIN */
2012-08-26 08:32:20 +00:00