$result=db_query("SELECT * FROM domain WHERE domain='$domain'");
$row=db_array($result['result']);
$list['description']=$row['description'];
$list['aliases']=$row['aliases'];
$list['mailboxes']=$row['mailboxes'];
$list['maxquota']=$row['maxquota'];
$list['transport']=$row['transport'];
$list['backupmx']=$row['backupmx'];
$list['created']=$row['created'];
$list['modified']=$row['modified'];
$list['active']=$row['active'];
if($CONF['database_type']=="pgsql"){
if($row['active']=="t")
{
$list['active']=1;
}else{
$list['active']=0;
}
if($row['backupmx']=="t"){
$list['backupmx']=1;
}else{
$list['backupmx']=0;
}
}else{
$list['active']=$row['active'];
$list['backupmx']=$row['backupmx'];
}
return$list;
}
//
// check_alias
// Action: Checks if the domain is still able to create aliases.
// Call: check_alias(string domain)
//
functioncheck_alias($domain){
$limit=get_domain_properties($domain);
if($limit['aliases']==0){
returntrue;
}
if($limit['aliases']<0){
returnfalse;
}
if($limit['alias_count']>=$limit['aliases']){
returnfalse;
}else{
returntrue;
}
}
//
// check_mailbox
// Action: Checks if the domain is still able to create mailboxes.
// Call: ceck_mailbox(string domain)
//
functioncheck_mailbox($domain){
$limit=get_domain_properties($domain);
if($limit['mailboxes']==0){
returntrue;
}
if($limit['mailboxes']<0){
returnfalse;
}
if($limit['mailbox_count']>=$limit['mailboxes']){
returnfalse;
}else{
returntrue;
}
}
//
// check_quota
// Action: Checks if the user is creating a mailbox with the correct quota
// Call: check_quota(string domain)
//
functioncheck_quota($quota,$domain){
$limit=get_domain_properties($domain);
if($limit['maxquota']==0){
returntrue;
}
if(($limit['maxquota']<0)and($quota<0)){
returntrue;
}
if(($limit['maxquota']>0)and($quota==0)){
returnfalse;
}
if($quota>$limit['maxquota']){
returnfalse;
}else{
returntrue;
}
}
//
// check_owner
// Action: Checks if the admin is the owner of the domain.
// Call: check_owner(string admin, string domain)
//
functioncheck_owner($username,$domain){
$result=db_query("SELECT * FROM domain_admins WHERE username='$username' AND domain='$domain' AND active='1'");
if($result['rows']!=1){
returnfalse;
}else{
returntrue;
}
}
//
// list_domains_for_admin
// Action: Lists all the domains for an admin.
// Call: list_domains_for_admin(string admin)
//
functionlist_domains_for_admin($username){
$list=array();
$result=db_query("SELECT * FROM domain LEFT JOIN domain_admins ON domain.domain=domain_admins.domain WHERE domain_admins.username='$username' AND domain.active='1' AND domain.backupmx='0' ORDER BY domain_admins.domain");
if($result['rows']>0){
$i=0;
while($row=db_array($result['result'])){
$list[$i]=$row['domain'];
$i++;
}
}
return$list;
}
//
// list_domains
// Action: List all available domains.
// Call: list_domains()
//
functionlist_domains(){
$list=array();
$result=db_query("SELECT * FROM domain ORDER BY domain");
if($result['rows']>0){
$i=0;
while($row=db_array($result['result'])){
$list[$i]=$row['domain'];
$i++;
}
}
return$list;
}
//
// admin_exist
// Action: Checks if the admin already exists.
// Call: admin_exist(string admin)
//
// was check_admin
//
functionadmin_exist($username){
$result=db_query("SELECT * FROM admin WHERE username='$username'");
if($result['rows']!=1){
returnfalse;
}else{
returntrue;
}
}
//
// domain_exist
// Action: Checks if the domain already exists.
// Call: domain_exist(string domain)
//
functiondomain_exist($domain){
$result=db_query("SELECT * FROM domain WHERE domain='$domain'");
if($result['rows']!=1){
returnfalse;
}else{
returntrue;
}
}
//
// list_admins
// Action: Lists all the admins
// Call: list_admins()
//
// was admin_list_admins
//
functionlist_admins(){
$list=array();
$result=db_query("SELECT * FROM admin ORDER BY username");
if($result['rows']>0){
$i=0;
while($row=db_array($result['result'])){
$list[$i]=$row['username'];
$i++;
}
}
return$list;
}
//
// get_admin_properties
// Action: Get all the admin properties.
// Call: get_admin_properties(string admin)
functionget_admin_properties($username){
$list=array();
$result=db_query("SELECT COUNT(*) FROM domain_admins WHERE username='$username'");
$row=db_row($result['result']);
$list['domain_count']=$row[0];
$result=db_query("SELECT * FROM admin WHERE username='$username'");
$row=db_array($result['result']);
$list['created']=$row['created'];
$list['modified']=$row['modified'];
$list['active']=$row['active'];
return$list;
}
//
// generate_password
// Action: Generates a random password
// Call: generate_password()
//
functiongenerate_password(){
$password=substr(md5(mt_rand()),0,8);
return$password;
}
//
// pacrypt
// Action: Encrypts password based on config settings
print"<p />DEBUG INFORMATION:<br />MySQL 4.1 functions not available!<br />database_type = 'mysqli' in config.inc.php, are you using a different database? $DEBUG_TEXT";
print"<p />DEBUG INFORMATION:<br />PostgreSQL functions not available!<br />database_type = 'pgsql' in config.inc.php, are you using a different database? $DEBUG_TEXT";
die;
}
}
if($link){
return$link;
}else{
print"DEBUG INFORMATION:<br />\n";
print"Connect: Unable to connect to database<br />\n";
print"<br />\n";
print"Make sure that you have set the correct database type in the config.inc.php file<br />\n";
print$DEBUG_TEXT;
die;
}
}
//
// db_query
// Action: Sends a query to the database and returns query result and number of rows