Current time: 11-24-2024, 09:55 AM Hello There, Guest! (LoginRegister)


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Создание почтовых ящиков без GUI
Author Message
Alien85 Offline
Newbie
*

Posts: 8
Joined: Nov 2010
Reputation: 0
Post: #2
RE: Создание почтовых ящиков без GUI
Вот скрипт создания ящиков:
Для работы нужно добавить пользователя mysql ispcp_mails

Code:
#!/bin/bash
# by calocen@gmail.com
# ver.: 1.0
# 01/02/2008
# creating a new email account in a control panel structure with default config
# parameters:
# 1: email_account@domain.tld where domain.tld must be in control panel database and
# email_account shold not be create even as an alias
# 2: password
# 3: [rebuild]: if true, then do a rebuild of rqst-orders

DEBUG="true"

# syntax control
if [ $# -lt 2 ] ; then
    echo -e "\n\nSyntax: "
    echo -e "\t $0 <name@domain.tld> <account_password>"
    echo -e "\t Where domain.tld must exists in ispcp panel"
    exit 01
fi
cEmail=$1
cPas=$2
[ -z $3 ] && bRebuild="false"
[ ! -z $3 ] && bRebuild="true"
$DEBUG && echo $bRebuild
cAcc=`echo $cEmail | cut -f1 -d"@"`
cDom=`echo $cEmail | cut -f2 -d"@"`

# check if domain exists and get domain Id
nDomID=$(mysql ispcp -ss -u ispcp_mails -pMYPASSWORD -n -e "SELECT domain_id FROM domain WHERE domain_name='$cDom';")

if [ -z $nDomID ]
then
    echo -e "\n\n $cDom not exists, please add it before add email accounts"
    exit 02
fi

# Check if email accounts exists
nMailID=$(mysql ispcp -ss -u ispcp_mails -pMYPASSWORD -n -e "SELECT mail_id FROM mail_users WHERE domain_id='$nDomID' AND mail_acc='$cAcc';")
$DEBUG && echo -e "nDomID:$nDomID\tcDom:$cDom\tcAcc:$cAcc"
if [ ! -z $nMailID ]
then
    echo -e "\n\nE-Mail account is exists"
    echo -e "\nnDomID:$nDomID\tcDom:$cDom\tcAcc:$cAcc"
    exit 03
fi

# composing email record in mail_users table
cSql="INSERT INTO mail_users(mail_acc, mail_pass, mail_forward, domain_id, mail_type, sub_id, status, mail_addr) VALUES ('$cAcc', '$cPas', '_no_', $nDomID, 'normal_mail', 0, 'change', '$cEmail');"
$DEBUG &&  echo -e "$cSql"
mysql ispcp -u ispcp_mails -pMYPASSWORD -e "$cSql"

if [ "$?" -ne "0" ] ; then exit 1 ; fi

# rebuild virtual aliases
/usr/sbin/postmap /etc/postfix/ispcp

# rebuild mail accounts if set rebuild parameter
$bRebuild && /var/www/ispcp/engine/ispcp-rqst-mngr

вот скрипт для удаления ящиков, только алиасы он не удаляет...
Code:
#!/bin/bash
# by alien.ru@mail.ru from by calocen@gmail.com (ispcp_add_email.sh)
# ver.: 1.0
# 25/11/2010
# remove email account in a control panel structure with default config
# parameters:
# 1: email_account@domain.tld where (aliases not deleted)
# 2: [rebuild]: if true, then do a rebuild of rqst-orders

DEBUG="true"

# syntax control
if [ $# -lt 1 ] ; then
    echo -e "\n\nSyntax: "
    echo -e "\t $0 <name@domain.tld>"
    exit 01
fi
cEmail=$1
[ -z $2 ] && bRebuild="false"
[ ! -z $2 ] && bRebuild="true"
$DEBUG && echo $bRebuild
cAcc=`echo $cEmail | cut -f1 -d"@"`
cDom=`echo $cEmail | cut -f2 -d"@"`

# check if domain exists and get domain Id
nDomID=$(mysql ispcp -ss -u ispcp_mails -pMYPASSWORD -n -e "SELECT domain_id FROM domain WHERE domain_name='$cDom';")

if [ -z $nDomID ]
then
    echo -e "\n\n $cDom not exists, please add it before add email accounts"
    exit 02
fi

# Check if email accounts exists
nMailID=$(mysql ispcp -ss -u ispcp_mails -pMYPASSWORD -n -e "SELECT mail_id FROM mail_users WHERE domain_id='$nDomID' AND mail_acc='$cAcc';")
$DEBUG && echo -e "nDomID:$nDomID\tcDom:$cDom\tcAcc:$cAcc"
if [ -z $nMailID ]
then
    echo -e "\n\nE-Mail account is not exists"
    echo -e "\nnDomID:$nDomID\tcDom:$cDom\tcAcc:$cAcc"
    exit 03
fi

# remove email record in mail_users table
cSql="DELETE FROM mail_users WHERE mail_id='$nMailID' LIMIT 1;"
$DEBUG &&  echo -e "$cSql"
mysql ispcp -u ispcp_mails -pMYPASSWORD -e "$cSql"

if [ "$?" -ne "0" ] ; then exit 1 ; fi

# rebuild virtual aliases
/usr/sbin/postmap /etc/postfix/ispcp

# rebuild mail accounts if set rebuild parameter
$bRebuild && /var/www/ispcp/engine/ispcp-rqst-mngr

rm -R /var/mail/virtual/$cDom/$cAcc

сейчас проблема в том, что этот скрипт не удаляет ящики в файлах /etc/postfix/ispcp/* и /var/www/ispcp/postfix/* (последний каталог написал на память), да и последнюю строчку rm -R /var/mail/virtual/$cDom/$cAcc я сам добавил, все это должен делать ispcp, но как?
(This post was last modified: 11-25-2010 06:27 PM by Alien85.)
11-25-2010 01:00 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Создание почтовых ящиков без GUI - Alien85 - 11-25-2010 01:00 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)