ud
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
DirectAdmin Scripts
|
||||
|
||||
To install DirectAdmin run ./install.sh
|
||||
|
||||
this will first do some checks to make sure that things are installed (named etc)
|
||||
|
||||
then it will ask some question and save the data to setup.txt
|
||||
|
||||
If you encounter errors and need to change some of the setup data, simply delete setup.txt and re-run setup.sh
|
||||
@@ -1,99 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#script to add an email account to DirectAdmin via command line.
|
||||
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "$MYUID" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "$#" -lt 4 ]; then
|
||||
echo "Usage:";
|
||||
echo " $0 <user> <domain> '<cryptedpass>' <plaintext> <quota>";
|
||||
echo "";
|
||||
echo "Where the cryptedpass can either be an MD5/DES password";
|
||||
echo "If plaintext is set to 1, then it can be a raw password";
|
||||
echo "Else, set plaintext to 0 to use the provided crypted pass."
|
||||
echo "quota, in bytes. Use 0 for unlimited";
|
||||
echo "";
|
||||
echo "The domain must already exist under a DA account";
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
EMAIL=$1
|
||||
DOMAIN=$2
|
||||
PASS=$3
|
||||
PLAIN=$4
|
||||
QUOTAVAL=$5
|
||||
|
||||
DAUSER=`grep "^${DOMAIN}:" /etc/virtual/domainowners | awk '{print $2;}'`
|
||||
UHOME=`grep "^${DAUSER}:" /etc/passwd | cut -d: -f6`
|
||||
|
||||
DOMAINCONF=/usr/local/directadmin/data/users/${DAUSER}/domains/${DOMAIN}.conf
|
||||
if [ ! -e ${DOMAINCONF} ]; then
|
||||
echo "Cannot find ${DOMAINCONF}";
|
||||
echo "Make sure the domain exists and is set in the /etc/virtual/domainowners file";
|
||||
exit 3;
|
||||
fi
|
||||
|
||||
PASSWD=/etc/virtual/${DOMAIN}/passwd
|
||||
QUOTA=/etc/virtual/${DOMAIN}/quota
|
||||
if [ ! -e ${PASSWD} ]; then
|
||||
echo "Cannot find ${PASSWD}. Make sure the domain exists";
|
||||
exit 4;
|
||||
fi
|
||||
|
||||
DOVECOT=`/usr/local/directadmin/directadmin c | grep ^dovecot= | cut -d= -f2`
|
||||
if [ "${DOVECOT}" != 0 ]; then
|
||||
DOVECOT=1;
|
||||
fi
|
||||
|
||||
COUNT=`grep -c "^${EMAIL}:" ${PASSWD}`
|
||||
if [ "${COUNT}" = 0 ]; then
|
||||
PASSVALUE=$PASS
|
||||
if [ ${PLAIN} = 1 ]; then
|
||||
#encode the password.
|
||||
PASSVALUE=`echo "$PASS" | /usr/bin/openssl passwd -1 -stdin`
|
||||
fi
|
||||
|
||||
if [ "${DOVECOT}" = 1 ]; then
|
||||
UUID=`id -u ${DAUSER}`
|
||||
MGID=`id -g mail`
|
||||
if /usr/local/directadmin/directadmin c | grep -m1 -q '^add_userdb_quota=1$'; then
|
||||
APPEND=":userdb_quota_rule=*:bytes=${QUOTAVAL}"
|
||||
else
|
||||
APPEND=""
|
||||
fi
|
||||
echo "${EMAIL}:${PASSVALUE}:${UUID}:${MGID}::${UHOME}/imap/${DOMAIN}/${EMAIL}:/bin/false${APPEND}" >> ${PASSWD}
|
||||
else
|
||||
echo "${EMAIL}:${PASSVALUE}" >> ${PASSWD}
|
||||
fi
|
||||
|
||||
echo "Added ${EMAIL} to ${PASSWD}";
|
||||
else
|
||||
echo "${EMAIL} already exists in ${PASSWD}. Not adding it to passwd.";
|
||||
fi
|
||||
|
||||
#quota
|
||||
if [ -e ${QUOTA} ]; then
|
||||
COUNT=`grep -c "^${EMAIL}:" ${QUOTA}`
|
||||
if [ "${COUNT}" = 0 ]; then
|
||||
echo "${EMAIL}:${QUOTAVAL}" >> ${QUOTA}
|
||||
fi
|
||||
else
|
||||
echo "${EMAIL}:${QUOTAVAL}" > ${QUOTA}
|
||||
fi
|
||||
|
||||
#ensure path exists for it.
|
||||
if [ "${DOVECOT}" = 1 ]; then
|
||||
USERDIR=${UHOME}/imap/${DOMAIN}/${EMAIL}
|
||||
|
||||
mkdir --mode=770 -p $USERDIR/Maildir/new
|
||||
mkdir --mode=770 -p $USERDIR/Maildir/cur
|
||||
|
||||
chown -R ${DAUSER}:mail ${USERDIR}
|
||||
chmod 770 ${USERDIR} ${USERDIR}/Maildir
|
||||
fi
|
||||
|
||||
exit 0;
|
||||
@@ -1,138 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#find the eth0:# and add the ip to the system
|
||||
OS=`uname`
|
||||
|
||||
addIPv6()
|
||||
{
|
||||
MASK=/64
|
||||
if echo $2 | grep -m1 -q '/'; then
|
||||
MASK=$2
|
||||
fi
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
/sbin/ifconfig $ETH_DEV inet6 add ${1}${MASK}
|
||||
else
|
||||
/sbin/ip addr add ${1}${MASK} dev $ETH_DEV preferred_lft 0 >/dev/null 2>&1
|
||||
if [ "$?" -ne 0 ]; then
|
||||
/sbin/ifconfig $ETH_DEV inet6 add ${1}${MASK}
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0;
|
||||
}
|
||||
|
||||
getBroadcast() {
|
||||
IP1=`echo $1 | cut -d. -f1`;
|
||||
IP2=`echo $1 | cut -d. -f2`;
|
||||
IP3=`echo $1 | cut -d. -f3`;
|
||||
IP4=`echo $1 | cut -d. -f4`;
|
||||
|
||||
NM1=`echo $2 | cut -d. -f1`;
|
||||
NM2=`echo $2 | cut -d. -f2`;
|
||||
NM3=`echo $2 | cut -d. -f3`;
|
||||
NM4=`echo $2 | cut -d. -f4`;
|
||||
|
||||
BC1=$((($IP1 & $NM1) | (255 & ~$NM1)));
|
||||
BC2=$((($IP2 & $NM2) | (255 & ~$NM2)));
|
||||
BC3=$((($IP3 & $NM3) | (255 & ~$NM3)));
|
||||
BC4=$((($IP4 & $NM4) | (255 & ~$NM4)));
|
||||
|
||||
BROADCAST="$BC1.$BC2.$BC3.$BC4";
|
||||
}
|
||||
|
||||
ETH_DEV=eth0
|
||||
if [ $# -lt 1 ]; then # we need the ip
|
||||
echo "Usage: $0 <ip> (<netmask> (<eth dev> (<broadcast>)))";
|
||||
echo "example: $0 1.2.3.4 255.255.255.0 eth0";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
IP_FILE=/usr/local/directadmin/data/admin/ips/$1
|
||||
if [ -s ${IP_FILE} ]; then
|
||||
C=`grep -c 'add_to_device=no' ${IP_FILE}`
|
||||
if [ "${C}" -gt 0 ]; then
|
||||
echo "IP $1 has add_to_device=no set. Skipping"
|
||||
exit 0;
|
||||
fi
|
||||
fi
|
||||
|
||||
#check to make sure it isn't already running
|
||||
IP_ALREADY_EXISTS=false
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
if /sbin/ifconfig | grep -m1 -q " $1 "; then
|
||||
IP_ALREADY_EXISTS=true
|
||||
fi
|
||||
else
|
||||
if /sbin/ip a | grep -m1 -q " $1/"; then
|
||||
IP_ALREADY_EXISTS=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if ${IP_ALREADY_EXISTS}; then
|
||||
echo "IP $1 already exists on eth0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#echo "have device: $3";
|
||||
if [ $# -gt "2" ]; then
|
||||
ETH_DEV=$3;
|
||||
fi
|
||||
|
||||
if echo $1 | grep -m1 -q ':'; then
|
||||
addIPv6 $1 $2
|
||||
fi
|
||||
|
||||
netmaskToPrefixIPv4(){
|
||||
NM1=`echo ${NETMASK} | cut -d. -f1`;
|
||||
NM2=`echo ${NETMASK} | cut -d. -f2`;
|
||||
NM3=`echo ${NETMASK} | cut -d. -f3`;
|
||||
NM4=`echo ${NETMASK} | cut -d. -f4`;
|
||||
|
||||
NM1BIN=`perl -e "printf \"%b\n\",${NM1}"`
|
||||
NM2BIN=`perl -e "printf \"%b\n\",${NM2}"`
|
||||
NM3BIN=`perl -e "printf \"%b\n\",${NM3}"`
|
||||
NM4BIN=`perl -e "printf \"%b\n\",${NM4}"`
|
||||
|
||||
echo "${NM1BIN}${NM2BIN}${NM3BIN}${NM4BIN}" | grep -o '1' | wc -l
|
||||
}
|
||||
|
||||
NETMASK=255.255.255.0
|
||||
PREFIX="/24"
|
||||
SET_BROADCAST=true
|
||||
if [ $# -gt "1" ]; then
|
||||
#echo "have netmask: $2";
|
||||
NETMASK=$2
|
||||
if ! echo "${NETMASK}" | grep -m1 -q '/'; then
|
||||
PREFIX="/`netmaskToPrefixIPv4 ${NETMASK}`"
|
||||
else
|
||||
PREFIX="${NETMASK}"
|
||||
SET_BROADCAST=false
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $# -gt "3" ]; then
|
||||
BROADCAST=$4
|
||||
elif ${SET_BROADCAST}; then
|
||||
getBroadcast $1 $2
|
||||
fi
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
ifconfig $ETH_DEV inet $1 netmask $NETMASK broadcast $BROADCAST alias
|
||||
else
|
||||
/sbin/ip addr add ${1}${PREFIX} dev $ETH_DEV >/dev/null 2>&1
|
||||
if [ "$?" -ne 0 ] && ${SET_BROADCAST}; then
|
||||
DEVNUM=0
|
||||
while [ `/sbin/ifconfig $ETH_DEV:$DEVNUM | grep -F -c inet` -gt "0" ]
|
||||
do
|
||||
{
|
||||
DEVNUM=$(($DEVNUM+1));
|
||||
}
|
||||
done;
|
||||
|
||||
/sbin/ifconfig $ETH_DEV:$DEVNUM $1 netmask $NETMASK broadcast $BROADCAST
|
||||
/sbin/route add -host $1 dev $ETH_DEV:$DEVNUM
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,113 +0,0 @@
|
||||
#!/bin/sh
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to install AWstats into DirectAdmin servers
|
||||
# Official AWstats webpage: http://www.awstats.org
|
||||
|
||||
#AWSTATS_VER=6.95
|
||||
#link bug?
|
||||
#http://www.directadmin.com/forum/showthread.php?p=193914#post193914
|
||||
AWSTATS_VER=7.7
|
||||
|
||||
DA_SCRIPTS=/usr/local/directadmin/scripts
|
||||
DA_CONF=/usr/local/directadmin/conf/directadmin.conf
|
||||
DA_TEMPLATE_CONF=/usr/local/directadmin/data/templates/directadmin.conf
|
||||
HTTPPATH=http://files.directadmin.com/services/all/awstats
|
||||
TARFILE=${DA_SCRIPTS}/packages/awstats-${AWSTATS_VER}.tar.gz
|
||||
USR=/usr/local
|
||||
REALPATH=${USR}/awstats-${AWSTATS_VER}
|
||||
ALIASPATH=${USR}/awstats
|
||||
|
||||
OS=`uname`
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
WGET=/usr/local/bin/wget
|
||||
TAR=/usr/bin/tar
|
||||
CHOWN=/usr/sbin/chown
|
||||
ROOTGRP=wheel
|
||||
else
|
||||
WGET=/usr/bin/wget
|
||||
TAR=/bin/tar
|
||||
CHOWN=/bin/chown
|
||||
ROOTGRP=root
|
||||
fi
|
||||
|
||||
if [ ! -e ${TARFILE} ]; then
|
||||
${WGET} -O ${TARFILE} ${HTTPPATH}/awstats-${AWSTATS_VER}.tar.gz
|
||||
fi
|
||||
|
||||
if [ ! -e ${TARFILE} ]; then
|
||||
echo "Can not download awstats-${AWSTATS_VER}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#Extract the file
|
||||
${TAR} xzf ${TARFILE} -C ${USR}
|
||||
|
||||
if [ ! -e ${REALPATH} ]; then
|
||||
echo "Directory ${REALPATH} does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#link it from a fake path:
|
||||
/bin/rm -f ${ALIASPATH}
|
||||
/bin/ln -sf awstats-${AWSTATS_VER} ${ALIASPATH}
|
||||
cd ${REALPATH}
|
||||
${CHOWN} -R root:${ROOTGRP} ${REALPATH}
|
||||
chmod -R 755 ${REALPATH}
|
||||
|
||||
|
||||
#patch the url bug: this is ni the 7.3 tar.gz file, so no need to patch. Creates a patch rej file.
|
||||
#echo "Patching awstats_buildstaticpages.pl to fix url bug...";
|
||||
#cd ${REALPATH}/tools
|
||||
#wget -O awstats_url.patch http://files.directadmin.com/services/custombuild/patches/awstats_url.patch
|
||||
#if [ ! -s awstats_url.patch ]; then
|
||||
# echo "Error with awstats_url.patch. File is missing or empty";
|
||||
#else
|
||||
# patch -p0 < awstats_url.patch
|
||||
#fi
|
||||
|
||||
#sets the value of $1 to $2 in the file $3
|
||||
setVal()
|
||||
{
|
||||
if [ ! -e $3 ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
COUNT=`grep -c $1 $3`
|
||||
if [ "$COUNT" -eq 0 ]; then
|
||||
#ok, it's not there, add it.
|
||||
echo "$1=$2" >> $3
|
||||
return;
|
||||
else
|
||||
#ok, the value is already in the file $3, so use perl to regex it.
|
||||
perl -pi -e "s/`grep ${1}= ${3}`/${1}=${2}/" ${3}
|
||||
fi
|
||||
}
|
||||
|
||||
#setup the directadmin.conf
|
||||
#disable webalizer, enable awstats.
|
||||
|
||||
setVal awstats 1 ${DA_TEMPLATE_CONF}
|
||||
setVal webalizer 0 ${DA_TEMPLATE_CONF}
|
||||
setVal awstats 1 ${DA_CONF}
|
||||
setVal webalizer 0 ${DA_CONF}
|
||||
|
||||
echo "action=directadmin&value=restart" >> /usr/local/directadmin/data/task.queue
|
||||
|
||||
CAGEFS_DA_CFG=/etc/cagefs/conf.d/directadmin.cfg
|
||||
if [ -s ${CAGEFS_DA_CFG} ]; then
|
||||
C=`grep ^paths= ${CAGEFS_DA_CFG} | grep -c ${REALPATH}`
|
||||
if [ "${C}" -eq 0 ]; then
|
||||
#From: paths=/usr/local/awstats/, /usr/local/php
|
||||
#To: paths=/usr/local/awstats/, /usr/local/awstats-7.7/, /usr/local/awstats, /usr/local/php
|
||||
STR="perl -pi -e 's#^paths=/usr/local/awstats/, /usr/local/php#paths=/usr/local/awstats/, ${REALPATH}/, /usr/local/awstats, /usr/local/php'"
|
||||
eval ${STR}
|
||||
fi
|
||||
|
||||
if [ ! -d /usr/share/cagefs-skeleton${REALPATH} ] && [ -x /usr/sbin/cagefsctl ]; then
|
||||
/usr/sbin/cagefsctl --force-update
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "AWstats package is installed."
|
||||
|
||||
@@ -1,541 +0,0 @@
|
||||
#!/bin/sh
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to process AWstats for a domain
|
||||
# Official AWstats webpage: http://www.awstats.org
|
||||
# Usage:
|
||||
# ./awstats_process.sh <user> <domain>
|
||||
VERSION=2.9
|
||||
|
||||
ADD_CGI=1
|
||||
ADD_HTML=1
|
||||
|
||||
#set this to 1 if you need the script to reset the awstats link for each domain to root (when harden symlinks patch is enabled in apache)
|
||||
#this should only need to be enabled once, and can be disabled after that one run.
|
||||
ENSURE_ROOT_LINKS=0
|
||||
|
||||
#Set this to 1 if you have extra awstats.old folders you want to get rid of.
|
||||
#DA will automatically clear them during the conversion, but this is here in case you had issues and need to try again.
|
||||
CLEAR_AWSTATS_OLD=0
|
||||
|
||||
OS=`uname`
|
||||
ROOTGRP=root
|
||||
SU_BIN=/bin/su
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
ROOTGRP=wheel
|
||||
SU_BIN=/usr/bin/su
|
||||
fi
|
||||
|
||||
if [ "${ADD_CGI}" -eq 0 ] && [ "${ADD_HTML}" -eq 0 ]; then
|
||||
echo "One of ADD_CGI and ADD_HTML must be set to 1";
|
||||
exit 10;
|
||||
fi
|
||||
|
||||
AUID=`/usr/bin/id -u`
|
||||
if [ "$AUID" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ $# != 2 ] && [ $# != 3 ]; then
|
||||
echo "$0 version $VERSION"
|
||||
echo "Usage:";
|
||||
echo "$0 <user> <domain> (<subdomain>)";
|
||||
echo "you gave #$#: $0 $1 $2";
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
#AWSTATS_MODE=1 hard link log files, readble by User
|
||||
#AWSTATS_MODE=2 full copies of logs, readble by User
|
||||
AWSTATS_MODE=`/usr/local/directadmin/directadmin c | grep '^awstats=' | cut -d= -f2`
|
||||
if [ "${AWSTATS_MODE}" = "0" ] || [ "${AWSTATS_MODE}" = "" ] || [ "${AWSTATS_MODE}" -gt 2 ]; then
|
||||
echo "awstats not enabled from:";
|
||||
echo "/usr/local/directadmin/directadmin c | grep '^awstats='";
|
||||
echo "awstats=${AWSTATS_MODE}";
|
||||
exit 17
|
||||
fi
|
||||
|
||||
id ${1} >/dev/null 2>&1
|
||||
RET=$?
|
||||
if [ "${RET}" -ne 0 ]; then
|
||||
echo "User ${1} does not exist";
|
||||
exit 3;
|
||||
fi
|
||||
|
||||
SUB="";
|
||||
if [ $# = 3 ]; then
|
||||
SUB=$3
|
||||
fi
|
||||
|
||||
USER=$1
|
||||
DOMAIN=$2
|
||||
UHOME=`grep -e "^${USER}:" /etc/passwd | head -n 1 | cut -d: -f6`
|
||||
|
||||
TOP_DOMAIN=$2
|
||||
|
||||
if [ "$UHOME" = "" ]; then
|
||||
echo "Could not find a home path for user $USER in /etc/passwd";
|
||||
exit 4;
|
||||
fi
|
||||
|
||||
HTTPD=httpd
|
||||
if [ "`/usr/local/directadmin/directadmin c | grep ^nginx= | cut -d= -f2`" -eq 1 ]; then
|
||||
HTTPD=nginx
|
||||
fi
|
||||
if [ "`/usr/local/directadmin/directadmin c | grep ^nginx_proxy= | cut -d= -f2`" -eq 1 ]; then
|
||||
HTTPD=nginx
|
||||
fi
|
||||
|
||||
AWSTATS=/usr/local/awstats
|
||||
MODEL=${AWSTATS}/wwwroot/cgi-bin/awstats.model.conf
|
||||
STATS_DIR=${UHOME}/domains/${DOMAIN}/awstats
|
||||
DATA=.data
|
||||
DATA_DIR=${STATS_DIR}/${DATA}
|
||||
LOGDIR=/var/log/${HTTPD}/domains
|
||||
|
||||
IS_CAGEFS=0
|
||||
CAGEFSCTL=/usr/sbin/cagefsctl
|
||||
if [ -x ${CAGEFSCTL} ]; then
|
||||
C=`${CAGEFSCTL} --list-enabled | grep -c ${USER}`
|
||||
if [ "${C}" -gt 0 ]; then
|
||||
IS_CAGEFS=1
|
||||
fi
|
||||
fi
|
||||
|
||||
USER_LOGS=/var/log/user_logs
|
||||
if [ ! -d ${USER_LOGS} ]; then
|
||||
if [ -d /var/user_logs ]; then
|
||||
echo "Moving /var/user_logs to ${USER_LOGS}"
|
||||
mv /var/user_logs ${USER_LOGS}
|
||||
else
|
||||
mkdir ${USER_LOGS}
|
||||
chmod 711 ${USER_LOGS}
|
||||
echo "This folder is for temporary http log hard-links or copies, for awstats processing as the User.\nIt should usually be empty, less this file, unless awstats is running for a domain." > ${USER_LOGS}/.readme.txt
|
||||
chmod 644 ${USER_LOGS}/.readme.txt
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${SUB}" != "" ]; then
|
||||
STATS_DIR=$STATS_DIR/${SUB}
|
||||
DATA_DIR=${STATS_DIR}/${DATA}
|
||||
CONFIG=${DATA_DIR}/awstats.${SUB}.${DOMAIN}.conf
|
||||
LOG=${LOGDIR}/${DOMAIN}.${SUB}.log
|
||||
READ_LOG=${USER_LOGS}/${USER}/${DOMAIN}.${SUB}.log
|
||||
|
||||
#we change the domain name at the last possible moment, after we're done with DOMAIN.
|
||||
#all calls to DOMAIN from this point onwards will see sub.domain.com
|
||||
DOMAIN=${SUB}.${DOMAIN}
|
||||
else
|
||||
CONFIG=${DATA_DIR}/awstats.${DOMAIN}.conf
|
||||
LOG=${LOGDIR}/${DOMAIN}.log
|
||||
READ_LOG=${USER_LOGS}/${USER}/${DOMAIN}.log
|
||||
fi
|
||||
|
||||
if [ ! -e ${AWSTATS} ]; then
|
||||
echo "${AWSTATS} does not exist!";
|
||||
exit 5;
|
||||
fi
|
||||
|
||||
|
||||
#####################################################
|
||||
# Script now runs core commands as the User.
|
||||
# actions and conversions below.
|
||||
|
||||
run_as_user()
|
||||
{
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
${SU_BIN} -l -m ${USER} -c "umask 022; $1"
|
||||
else
|
||||
${SU_BIN} -l -s /bin/sh -c "umask 022; $1" ${USER}
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
get_dir_owner()
|
||||
{
|
||||
D=$1
|
||||
if [ ! -d ${D} ]; then
|
||||
echo "";
|
||||
return;
|
||||
fi
|
||||
|
||||
U=`ls -ld ${D} | awk '{print $3}'`
|
||||
echo $U
|
||||
}
|
||||
|
||||
#1 for false
|
||||
#0 for true
|
||||
should_convert_to_user()
|
||||
{
|
||||
if [ "`get_dir_owner $DATA_DIR`" != "root" ]; then
|
||||
return 1;
|
||||
fi
|
||||
return 0;
|
||||
}
|
||||
|
||||
ensure_awstats_in_cagefs()
|
||||
{
|
||||
if [ "${IS_CAGEFS}" != "1" ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
#Ensure awstats is in the skeleton.
|
||||
DA_CFG=/etc/cagefs/conf.d/directadmin.cfg
|
||||
C=`grep ^paths= ${DA_CFG} | grep -c /usr/local/awstats/`
|
||||
if [ "${C}" = "0" ]; then
|
||||
echo "Adding /usr/local/awstats/ to ${DA_CFG} paths";
|
||||
perl -pi -e 's#^paths=#paths=/usr/local/awstats/, #' ${DA_CFG}
|
||||
|
||||
${CAGEFSCTL} --update
|
||||
|
||||
CHECK=`run_as_user "if [ -e /usr/local/awstats/tools/awstats_buildstaticpages.pl ]; then echo 0; else echo 1; fi"`
|
||||
if [ "${CHECK}" != "0" ]; then
|
||||
${CAGEFSCTL} --force-update
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
convert_awstast_to_user()
|
||||
{
|
||||
# As the User, copy awstats to awstats.user
|
||||
# Ensure copy was successful. If not, abort everything.
|
||||
# rename awstats to awstats.old, and awstats.user to awstats
|
||||
|
||||
STATS_DIR_USER=${STATS_DIR}.user
|
||||
|
||||
if [ -e ${STATS_DIR_USER} ]; then
|
||||
echo "${STATS_DIR_USER} already exist. Removing it before we proceed."
|
||||
run_as_user "/bin/rm -rf ${STATS_DIR_USER}"
|
||||
fi
|
||||
|
||||
if [ "${IS_CAGEFS}" = "1" ]; then
|
||||
#CloudLinux doesnt let Users copy links pointing to root files,
|
||||
#so we'll remove those links first, since they're not important.
|
||||
echo "Removing symbolic links..."
|
||||
run_as_user "find ${STATS_DIR}/ -type l -delete"
|
||||
echo "Done removing symbolic links."
|
||||
fi
|
||||
|
||||
run_as_user "/bin/cp -RPp ${STATS_DIR} ${STATS_DIR_USER}"
|
||||
|
||||
diff -rq ${STATS_DIR} ${STATS_DIR_USER} > /dev/null
|
||||
DIFF_RET=$?
|
||||
|
||||
if [ "${DIFF_RET}" != "0" ]; then
|
||||
echo "awstats.user vs awstats folder do not match:";
|
||||
diff -rq ${STATS_DIR} ${STATS_DIR_USER}
|
||||
echo "";
|
||||
echo "aborting conversion."
|
||||
exit 14;
|
||||
fi
|
||||
|
||||
echo "All checks passed. Swapping folders";
|
||||
run_as_user "/bin/mv ${STATS_DIR} ${STATS_DIR}.old"
|
||||
if [ ! -d ${STATS_DIR}.old ]; then
|
||||
echo "Rename to ${STATS_DIR}.old must have failed. Cannot find that directory after move as User."
|
||||
exit 16;
|
||||
fi
|
||||
|
||||
#re-link root owned links.
|
||||
run_as_user "rm -f ${STATS_DIR_USER}/icon"
|
||||
run_as_user "rm -f ${STATS_DIR_USER}/lang"
|
||||
run_as_user "rm -f ${STATS_DIR_USER}/lib"
|
||||
run_as_user "rm -f ${STATS_DIR_USER}/plugins"
|
||||
ln -s /usr/local/awstats/wwwroot/icon ${STATS_DIR_USER}/icon
|
||||
ln -s /usr/local/awstats/wwwroot/cgi-bin/lang ${STATS_DIR_USER}/lang
|
||||
ln -s /usr/local/awstats/wwwroot/cgi-bin/lib ${STATS_DIR_USER}/lib
|
||||
ln -s /usr/local/awstats/wwwroot/cgi-bin/plugins ${STATS_DIR_USER}/plugins
|
||||
|
||||
run_as_user "/bin/mv ${STATS_DIR_USER} ${STATS_DIR}"
|
||||
|
||||
echo "action=delete&value=secure_disposal&user=${USER}&path=${STATS_DIR}.old" >> /usr/local/directadmin/data/task.queue
|
||||
}
|
||||
|
||||
#####################################################
|
||||
|
||||
ensure_awstats_in_cagefs;
|
||||
|
||||
if [ ! -e ${STATS_DIR} ]; then
|
||||
run_as_user "mkdir ${STATS_DIR}";
|
||||
run_as_user "chmod 755 ${STATS_DIR}"
|
||||
else
|
||||
if [ -h ${STATS_DIR} ]; then
|
||||
echo "${STATS_DIR} is a symbolic link. Aborting.";
|
||||
exit 8;
|
||||
fi
|
||||
|
||||
#directory does exist. Should we convert it?
|
||||
if should_convert_to_user; then
|
||||
echo "Converting contents of ${STATS_DIR} to the User ${USER}"
|
||||
convert_awstast_to_user;
|
||||
else
|
||||
echo "Conversion not required. Continuing normally";
|
||||
fi
|
||||
|
||||
|
||||
fi
|
||||
|
||||
if [ ! -e ${DATA_DIR} ]; then
|
||||
run_as_user "mkdir ${DATA_DIR}"
|
||||
run_as_user "chmod 755 ${DATA_DIR}"
|
||||
else
|
||||
if [ -h ${DATA_DIR} ]; then
|
||||
echo "${DATA_DIR} is a symbolic link. Aborting.";
|
||||
exit 9;
|
||||
fi
|
||||
fi
|
||||
|
||||
#this bit is to fix the 700 that backups cannot see. (bug)
|
||||
#http://www.directadmin.com/features.php?id=915
|
||||
run_as_user "chmod 755 ${DATA_DIR}"
|
||||
|
||||
#do it every time. Users must not be able to edit the config directly.
|
||||
#chown -R root:${ROOTGRP} ${DATA_DIR} #never do this again
|
||||
|
||||
if [ ! -s ${CONFIG} ]; then
|
||||
if [ ! -s ${MODEL} ]; then
|
||||
echo "${MODEL} does not exist or is empty.";
|
||||
exit 6;
|
||||
fi
|
||||
|
||||
run_as_user "cp -f ${MODEL} ${CONFIG}"
|
||||
run_as_user "chmod 644 ${CONFIG}"
|
||||
run_as_user "perl -pi -e 's#LogFile=\\\"/var/log/httpd/mylog.log\\\"#LogFile=\\\"${READ_LOG}\\\"#' ${CONFIG}"
|
||||
run_as_user "perl -pi -e 's#SiteDomain=\\\"\\\"#SiteDomain=\"${DOMAIN}\"#' ${CONFIG}"
|
||||
run_as_user "perl -pi -e 's#DirData=\\\".\\\"#DirData=\\\"${DATA_DIR}\\\"#' ${CONFIG}"
|
||||
run_as_user "perl -pi -e 's#DirCgi=\\\"/cgi-bin\\\"#DirCgi=\\/awstats\\\"#' ${CONFIG}"
|
||||
run_as_user "perl -pi -e 's#ValidHTTPCodes=\\\"200 304\\\"#ValidHTTPCodes=\\\"200 304 206\\\"#' ${CONFIG}"
|
||||
|
||||
#Oct 24, 2010
|
||||
run_as_user "perl -pi -e 's#DirIcons=\\\"/icon\\\"#DirIcons=\\\"icon\\\"#' ${CONFIG}"
|
||||
else
|
||||
run_as_user "perl -pi -e 's#DirIcons=\\\"${STATS_DIR}\\\"#DirIcons=\\\"icon\\\"#' ${CONFIG}"
|
||||
#run_as_user "perl -pi -e 's#^LogFile=\\\".*\\\"\$#LogFile=\\\"${READ_LOG}\\\"#' ${CONFIG}"
|
||||
run_as_user "perl -pi -e 's#^LogFile=.*\$#LogFile=\\\"${READ_LOG}\\\"#' ${CONFIG}"
|
||||
fi
|
||||
|
||||
ensure_root()
|
||||
{
|
||||
if [ "$ENSURE_ROOT_LINKS" != 1 ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
F=$1
|
||||
TARGET=$2
|
||||
|
||||
if [ ! -h $F ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
FOWNER=`ls -la $F | awk '{print $3}'`
|
||||
|
||||
if [ "$FOWNER" = "$USER" ]; then
|
||||
echo "Setting link $F to root";
|
||||
run_as_user "rm '$F'"
|
||||
ln -s "$TARGET" "$F"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
ICON=${STATS_DIR}/icon
|
||||
#only create it during conversion. Never reset, which could be predicted.
|
||||
#if [ ! -h $ICON ]; then
|
||||
# run_as_user "rm -rf $ICON"
|
||||
# ln -s ${AWSTATS}/wwwroot/icon $ICON
|
||||
#fi
|
||||
ensure_root $ICON ${AWSTATS}/wwwroot/icon
|
||||
if [ ! -e "${ICON}" ]; then
|
||||
ln -s ${AWSTATS}/wwwroot/icon $ICON
|
||||
fi
|
||||
|
||||
#Oct 24, 2010
|
||||
if [ "${ADD_CGI}" -eq 1 ]; then
|
||||
#copy cgi-bin bits to awstats directory.
|
||||
|
||||
NEEDS_UPDATING=0
|
||||
AS_PL=${AWSTATS}/wwwroot/cgi-bin/awstats.pl
|
||||
|
||||
if [ ! -e "${STATS_DIR}/awstats.pl" ]; then
|
||||
NEEDS_UPDATING=1
|
||||
else
|
||||
#ensure it's current
|
||||
CURRENT_REV=`grep '$REVISION = ' ${STATS_DIR}/awstats.pl | cut -d\' -f2`
|
||||
echo "Current REVISION from ${STATS_DIR}/awstats.pl: ${CURRENT_REV}";
|
||||
if [ "${CURRENT_REV}" = "" ]; then
|
||||
echo "${STATS_DIR}/awstats.pl does not have REVISION set, updating from ${AS_PL}"
|
||||
NEED_UPDATING=1
|
||||
elif [ "${CURRENT_REV}" -lt 20180105 ]; then
|
||||
echo "${STATS_DIR}/awstats.pl is old, updating from ${AS_PL}"
|
||||
NEEDS_UPDATING=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${NEEDS_UPDATING}" -eq 1 ]; then
|
||||
|
||||
run_as_user "/bin/cp -v ${AS_PL} ${STATS_DIR}/awstats.pl"
|
||||
|
||||
#make a few changes so it can find the config.
|
||||
run_as_user "perl -pi -e 's#\\\"\$DIR\\\",\s+\\\"/etc/awstats\\\",#\\\"\$DIR\\\",\t\\\"${DATA_DIR}\\\",#' ${STATS_DIR}/awstats.pl"
|
||||
|
||||
#repeat for variations of the awstats.pl files
|
||||
run_as_user "perl -pi -e 's#\\\"/etc/awstats\\\"#\\\"${DATA_DIR}\\\"#' ${STATS_DIR}/awstats.pl"
|
||||
fi
|
||||
|
||||
run_as_user "chmod 755 ${STATS_DIR}/awstats.pl"
|
||||
|
||||
if [ ! -e "${STATS_DIR}/lang" ]; then
|
||||
ln -s ${AWSTATS}/wwwroot/cgi-bin/lang ${STATS_DIR}/lang
|
||||
fi
|
||||
ensure_root ${STATS_DIR}/lang ${AWSTATS}/wwwroot/cgi-bin/lang
|
||||
|
||||
if [ ! -e "${STATS_DIR}/lib" ]; then
|
||||
ln -s ${AWSTATS}/wwwroot/cgi-bin/lib ${STATS_DIR}/lib
|
||||
fi
|
||||
ensure_root ${STATS_DIR}/lib ${AWSTATS}/wwwroot/cgi-bin/lib
|
||||
|
||||
if [ ! -e "${STATS_DIR}/plugins" ]; then
|
||||
ln -s ${AWSTATS}/wwwroot/cgi-bin/plugins ${STATS_DIR}/plugins
|
||||
fi
|
||||
ensure_root ${STATS_DIR}/plugins ${AWSTATS}/wwwroot/cgi-bin/plugins
|
||||
|
||||
WWWCONFIG=${DATA_DIR}/awstats.www.${DOMAIN}.conf
|
||||
if [ ! -e ${WWWCONFIG} ]; then
|
||||
run_as_user "ln -s awstats.${DOMAIN}.conf ${WWWCONFIG}"
|
||||
fi
|
||||
|
||||
EXECCGI=1;
|
||||
DC=/usr/local/directadmin/data/users/${USER}/domains/${TOP_DOMAIN}.conf
|
||||
if [ -s ${DC} ]; then
|
||||
C=`grep -c "^cgi=OFF" $DC`
|
||||
if [ "${C}" -gt 0 ]; then
|
||||
EXECCGI=0;
|
||||
fi
|
||||
fi
|
||||
|
||||
HTACCESS=${STATS_DIR}/.htaccess
|
||||
ADD_HTA=0
|
||||
if [ ! -e ${HTACCESS} ]; then
|
||||
ADD_HTA=1
|
||||
else
|
||||
#check it's contents
|
||||
COUNT=`run_as_user "grep -c 'DirectoryIndex awstats.pl' ${HTACCESS}"`
|
||||
|
||||
if [ "${COUNT}" -eq 0 ] && [ "${EXECCGI}" -eq 1 ]; then
|
||||
ADD_HTA=1
|
||||
fi
|
||||
if [ "${COUNT}" -eq 1 ] && [ "${EXECCGI}" -eq 0 ]; then
|
||||
ADD_HTA=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -h ${HTACCESS} ]; then
|
||||
echo "${HTACCESS} is a symbolic link. Aborting.";
|
||||
exit 11;
|
||||
fi
|
||||
|
||||
if [ "${ADD_HTA}" -eq 1 ]; then
|
||||
if [ "${EXECCGI}" -eq 1 ]; then
|
||||
run_as_user "echo 'Options -Indexes +ExecCGI' > ${HTACCESS}"
|
||||
run_as_user "echo 'AddHandler cgi-script .pl' >> ${HTACCESS}"
|
||||
run_as_user "echo 'DirectoryIndex awstats.pl' >> ${HTACCESS}"
|
||||
else
|
||||
run_as_user "echo 'Options -Indexes' > ${HTACCESS}"
|
||||
fi
|
||||
|
||||
run_as_user "echo '' >> ${HTACCESS}"
|
||||
run_as_user "echo 'RewriteEngine On' >> ${HTACCESS}"
|
||||
run_as_user "echo 'RewriteCond %{HTTP_HOST} ^www.${DOMAIN}\$ [NC]' >> ${HTACCESS}"
|
||||
run_as_user "echo 'RewriteRule ^(.*)\$ http://${DOMAIN}/awstats/\$1 [R=301,L]' >> ${HTACCESS}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
#Setup logs to be readable.
|
||||
mkdir $USER_LOGS/$USER
|
||||
chmod 750 $USER_LOGS/$USER
|
||||
|
||||
if [ "${AWSTATS_MODE}" = "1" ]; then
|
||||
ln $LOG $READ_LOG
|
||||
elif [ "${AWSTATS_MODE}" = "2" ]; then
|
||||
/bin/cp $LOG $READ_LOG
|
||||
else
|
||||
echo "UNKNOWN AWSTATS MODE!!"
|
||||
fi
|
||||
|
||||
chown root:$USER $USER_LOGS/$USER
|
||||
|
||||
if [ "${IS_CAGEFS}" = "1" ]; then
|
||||
# need to have user_logs visible to the user, in the skeleton.
|
||||
# Use the split method on user_logs
|
||||
C=`grep -c "^%${USER_LOGS}" /etc/cagefs/cagefs.mp`
|
||||
if [ "${C}" = "0" ]; then
|
||||
echo "Adding %${USER_LOGS} to /etc/cagefs/cagefs.mp";
|
||||
echo "%${USER_LOGS}" >> /etc/cagefs/cagefs.mp
|
||||
${CAGEFSCTL} --remount ${USER}
|
||||
fi
|
||||
|
||||
# can we see the log?
|
||||
CHECK=`run_as_user "if [ -r ${READ_LOG} ]; then echo 1; else echo 0; fi"`
|
||||
if [ "${CHECK}" = "0" ]; then
|
||||
${CAGEFSCTL} --remount ${USER}
|
||||
fi
|
||||
|
||||
CHECK=`run_as_user "if [ -r ${READ_LOG} ]; then echo 1; else echo 0; fi"`
|
||||
if [ "${CHECK}" = "0" ]; then
|
||||
echo "Cannot read log ${READ_LOG} as user ${USER} after:"
|
||||
echo "${CAGEFSCTL} --remount ${USER}"
|
||||
run_as_user "ls -la ${USER_LOGS}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${ADD_HTML}" -eq 1 ]; then
|
||||
|
||||
BD='-builddate=%YY%MM'
|
||||
|
||||
#this doesn't work because there are 4 hours of the next month in the logs on the first day.
|
||||
#They empty the stats from the old html for last month.
|
||||
#DAY=`date +%e`
|
||||
#if [ "$DAY" -eq 1 ]; then
|
||||
# YYMM=`date --date='yesterday' +%y%m`
|
||||
# BD="-builddate=$YYMM"
|
||||
#fi
|
||||
|
||||
#-lang=en
|
||||
run_as_user "/usr/bin/perl ${AWSTATS}/tools/awstats_buildstaticpages.pl -config=${DOMAIN} -configdir=${DATA_DIR} -update -diricons=icon -awstatsprog=${AWSTATS}/cgi-bin/awstats.pl -dir=${STATS_DIR} $BD"
|
||||
RET=$?
|
||||
|
||||
#we stil need to set a value though:
|
||||
MAIN_FILE=awstats.${DOMAIN}.`date +%y%m`.html
|
||||
|
||||
MAIN_HTML=${STATS_DIR}/${MAIN_FILE}
|
||||
INDEX_HTML=${STATS_DIR}/index.html
|
||||
|
||||
#changes per month
|
||||
run_as_user "ln -sf ${MAIN_FILE} ${INDEX_HTML}"
|
||||
|
||||
#ensure_root ${INDEX_HTML}
|
||||
#ensure_root ${MAIN_HTML}
|
||||
|
||||
else
|
||||
#this is for the case where we dont want to waste time with static html files (ADD_HTML=0) but ADD_CGI is still on.
|
||||
#due to the check check for !ADD_HTML&&!ADD_CGI above, ADD_CGI must be 1 at this point.
|
||||
|
||||
run_as_user "/usr/bin/perl ${AWSTATS}/tools/awstats_updateall.pl now -configdir=${DATA_DIR} -awstatsprog=${AWSTATS}/cgi-bin/awstats.pl"
|
||||
|
||||
# -excludeconf=awstats.www.${DOMAIN}.conf we're using mod_rewrite to change www.domain.com/awstast to domain.com/awstats, since only domain.com/awstats works unless we link every single data file (ugly).
|
||||
RET=$?
|
||||
fi
|
||||
|
||||
echo "Cleanup..."
|
||||
|
||||
rm -f $READ_LOG
|
||||
if [ "${IS_CAGEFS}" != "1" ]; then
|
||||
rm -rf $USER_LOGS/$USER
|
||||
fi
|
||||
|
||||
if [ "${CLEAR_AWSTATS_OLD}" = "1" ]; then
|
||||
echo "Clearing ${STATS_DIR} via task.queue. This will run in the background.";
|
||||
echo "action=delete&value=secure_disposal&user=${USER}&path=${STATS_DIR}.old" >> /usr/local/directadmin/data/task.queue
|
||||
fi
|
||||
|
||||
exit $RET;
|
||||
@@ -1,340 +0,0 @@
|
||||
#!/usr/local/bin/php -c/usr/local/directadmin/scripts/php_clean.ini
|
||||
<?php
|
||||
|
||||
$version = 0.1;
|
||||
|
||||
/*
|
||||
Backup script for the per-domain RoundCube settings.
|
||||
Backup/Restore written by DirectAdmin: http://www.directadmin.com
|
||||
RoundCube Webmail Client: http://roundcube.net
|
||||
|
||||
This script will generate a per-domain XML output of all users for that domain, in the roundcube database.
|
||||
It will also include one system account username (eg: admin), which is associated with the domain.
|
||||
The XML file is index/ID independant, so you can restore a set of domain accounts onto any other
|
||||
active DirectAdmin/RoundCube database without worry of ID conflicts.
|
||||
See the restore_roundcube.php for info on the restore process.
|
||||
|
||||
See the DirectAdmin versions system for more info:
|
||||
http://www.directadmin.com/features.php?id=1062
|
||||
|
||||
All variables are passed via environment, not command line options
|
||||
But you can specify environmental variables... via command line options before the script (see the showHelp() function)
|
||||
|
||||
RETURN VALUES
|
||||
0: All is well
|
||||
>1: an error worthy or reporting has occured. Message on stderr.
|
||||
1: an error, most likely due to not actually having RoundCube installed or no restore data, has occured.
|
||||
|
||||
*/
|
||||
|
||||
/***********************
|
||||
* Environmental variables
|
||||
*/
|
||||
$domain = getenv("domain"); //Get all email users from this domain.
|
||||
$system_username = getenv("username"); //Also get this single system account
|
||||
$xml_file = getenv("xml_file"); //and save all info to this file.
|
||||
|
||||
/***********************
|
||||
* this restores as da_admin instead of da_roundube.
|
||||
* For the backup, we are less concerned with dangerous data, so we use it for reliability reasons.
|
||||
*/
|
||||
$high_access_connection = TRUE;
|
||||
|
||||
/***********************
|
||||
* If $high_access_restore is false, this is used for the mysql credentials.
|
||||
*/
|
||||
$rc_config = "/var/www/html/roundcube/config/config.inc.php";
|
||||
|
||||
//****************************************************************
|
||||
//****************************************************************
|
||||
|
||||
if (!isset($domain) || $domain == "")
|
||||
show_help();
|
||||
|
||||
if (!isset($system_username) || $system_username == "")
|
||||
show_help();
|
||||
|
||||
if (!isset($xml_file) || $xml_file == "")
|
||||
show_help();
|
||||
|
||||
if (!extension_loaded('mysqli'))
|
||||
{
|
||||
echo_stderr("Php is not compiled with mysqli. Cannot dump roundcube settings.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************
|
||||
//****************************************************************
|
||||
|
||||
if ($high_access_connection)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '<'))
|
||||
{
|
||||
$mysql_conf = @parse_ini_file("/usr/local/directadmin/conf/mysql.conf", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mysql_conf = @parse_ini_file("/usr/local/directadmin/conf/mysql.conf", false, INI_SCANNER_RAW);
|
||||
}
|
||||
}
|
||||
|
||||
if ($high_access_connection && $mysql_conf && strlen($mysql_conf['passwd']) > 4)
|
||||
{
|
||||
|
||||
$mysql_user = $mysql_conf['user'];
|
||||
$mysql_pass = $mysql_conf['passwd'];
|
||||
$mysql_host = 'localhost';
|
||||
$mysql_db = 'da_roundcube';
|
||||
|
||||
if (isset($mysql_conf['host']) && $mysql_conf['host'] != "")
|
||||
$mysql_host = $mysql_conf['host'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!file_exists($rc_config))
|
||||
{
|
||||
echo_stderr("Cannot find RoundCube config at $rc_config. Is RC installed and up to date?\n");
|
||||
exit(7);
|
||||
}
|
||||
|
||||
include_once($rc_config);
|
||||
|
||||
if (!isset($config) || !isset($config['db_dsnw']) || $config['db_dsnw'] == '')
|
||||
{
|
||||
echo_stderr("Cannot find \$config['db_dsnw'] variable in $rc_config\n");
|
||||
exit(6);
|
||||
}
|
||||
|
||||
//$config['db_dsnw'] = 'mysql://da_roundcube:password@localhost/da_roundcube';
|
||||
|
||||
$values = explode('/', $config['db_dsnw']);
|
||||
$connect = explode('@', $values[2]);
|
||||
$auth = explode(':', $connect[0]);
|
||||
|
||||
$mysql_user = $auth[0];
|
||||
$mysql_pass = $auth[1];
|
||||
$mysql_host = $connect[1];
|
||||
$mysql_db = $values[3];
|
||||
}
|
||||
|
||||
$mysqli = new mysqli($mysql_host, $mysql_user, $mysql_pass);
|
||||
if ($mysqli->connect_errno) {
|
||||
echo_stderr("Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error."\n");
|
||||
exit(3);
|
||||
}
|
||||
$mysqli->set_charset('utf8');
|
||||
|
||||
if (!$mysqli->select_db($mysql_db))
|
||||
{
|
||||
echo_stderr("There is no $mysql_db database. Skipping RoundCube backup.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//****************************************************************
|
||||
//****************************************************************
|
||||
|
||||
//Check if we have contactgroups
|
||||
$have_contactgroups = true;
|
||||
$query = "SHOW TABLES LIKE 'contactgroups'";
|
||||
$result = $mysqli->query($query);
|
||||
if ($result->num_rows == 0)
|
||||
{
|
||||
$have_contactgroups = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//First, find all accounts for this domain.
|
||||
$query = "SELECT * FROM `users` WHERE username LIKE '%@".mes($domain)."' OR username='".mes($system_username)."'";
|
||||
$result = $mysqli->query($query);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
echo_stderr("Query error with user selection: ".$mysqli->error);
|
||||
$mysqli->close();
|
||||
exit(8);
|
||||
}
|
||||
|
||||
$top_depth = 0;
|
||||
|
||||
$fp = @fopen($xml_file, 'w');
|
||||
if (!$fp)
|
||||
{
|
||||
echo_stderr("Unable to open $xml_file for writing. Unable to backup RoundCube Data.");
|
||||
$mysqli->close();
|
||||
exit(5);
|
||||
}
|
||||
|
||||
xml_open("ROUNDCUBE", $top_depth);
|
||||
|
||||
while($user = $result->fetch_object())
|
||||
{
|
||||
$email_depth = $top_depth + 1;
|
||||
$email_item_depth = $email_depth + 1;
|
||||
|
||||
xml_open("EMAIL", $email_depth);
|
||||
|
||||
//echo "usermname = ".$user->username."\n";
|
||||
//echo "user_id = ".$user->user_id."\n";
|
||||
xml_item("USERNAME", $user->username, $email_item_depth);
|
||||
xml_item("LANGUAGE", $user->language, $email_item_depth);
|
||||
xml_item("PREFERENCES", $user->preferences, $email_item_depth);
|
||||
xml_item("CREATED", $user->created, $email_item_depth);
|
||||
xml_item("LAST_LOGIN", $user->last_login, $email_item_depth);
|
||||
|
||||
//get all indentities
|
||||
$query = "SELECT * FROM `identities` WHERE user_id=".$user->user_id." AND del=0";
|
||||
$identities_result = $mysqli->query($query);
|
||||
xml_open("INDENTITIES", $email_item_depth);
|
||||
if ($identities_result !== FALSE)
|
||||
{
|
||||
while ($identity = $identities_result->fetch_array())
|
||||
{
|
||||
$identity_depth = $email_item_depth + 1;
|
||||
$identity_item_depth = $identity_depth + 1;
|
||||
|
||||
xml_open("INDENTITY", $identity_depth);
|
||||
|
||||
xml_item("EMAIL", $identity['email'], $identity_item_depth);
|
||||
xml_item("STANDARD", $identity['standard'], $identity_item_depth);
|
||||
xml_item("NAME", $identity['name'], $identity_item_depth);
|
||||
xml_item("CHANGED", $identity['changed'], $identity_item_depth);
|
||||
xml_item("ORGANIZATION", $identity['organization'], $identity_item_depth);
|
||||
xml_item("REPLY-TO", $identity['reply-to'], $identity_item_depth);
|
||||
xml_item("BCC", $identity['bcc'], $identity_item_depth);
|
||||
xml_item("SIGNATURE", $identity['signature'], $identity_item_depth);
|
||||
xml_item("HTML_SIGNATURE", $identity['html_signature'], $identity_item_depth);
|
||||
|
||||
xml_close("INDENTITY", $identity_depth);
|
||||
}
|
||||
}
|
||||
xml_close("INDENTITIES", $email_item_depth);
|
||||
|
||||
//dictionary?
|
||||
|
||||
//contacts
|
||||
$query = "SELECT * FROM `contacts` WHERE user_id=".$user->user_id." AND del=0";
|
||||
$contacts_result = $mysqli->query($query);
|
||||
|
||||
xml_open("CONTACTS", $email_item_depth);
|
||||
if ($contacts_result !== FALSE)
|
||||
{
|
||||
while ($contact = $contacts_result->fetch_array())
|
||||
{
|
||||
|
||||
$contact_depth = $email_item_depth + 1;
|
||||
$contact_item_depth = $contact_depth + 1;
|
||||
|
||||
xml_open("CONTACT", $contact_depth);
|
||||
|
||||
xml_item('EMAIL', $contact['email'], $contact_item_depth);
|
||||
xml_item('NAME', $contact['name'], $contact_item_depth);
|
||||
xml_item('CHANGED', $contact['changed'], $contact_item_depth);
|
||||
xml_item('FIRSTNAME', $contact['firstname'], $contact_item_depth);
|
||||
xml_item('SURNAME', $contact['surname'], $contact_item_depth);
|
||||
xml_item('VCARD', $contact['vcard'], $contact_item_depth);
|
||||
xml_item('WORDS', $contact['words'], $contact_item_depth);
|
||||
|
||||
xml_open("GROUPS", $contact_item_depth);
|
||||
if ($have_contactgroups)
|
||||
{
|
||||
$query = "SELECT m.*,g.name,g.changed FROM `contactgroups` as g, `contactgroupmembers` as m WHERE m.contact_id=".$contact['contact_id']." AND g.contactgroup_id=m.contactgroup_id AND g.del=0";
|
||||
if (!($groups_result = $mysqli->query($query)))
|
||||
{
|
||||
echo_stderr("group query error: ".$mysqli->error."\n");
|
||||
exit(4);
|
||||
}
|
||||
|
||||
while ($group = $groups_result->fetch_array())
|
||||
{
|
||||
xml_open("GROUP", $contact_item_depth+1);
|
||||
|
||||
xml_item("NAME", $group['name'], $contact_item_depth+2);
|
||||
xml_item("CHANGED", $group['changed'], $contact_item_depth+2);
|
||||
xml_item("CREATED", $group['created'], $contact_item_depth+2);
|
||||
|
||||
xml_close("GROUP", $contact_item_depth+1);
|
||||
}
|
||||
}
|
||||
xml_close("GROUPS", $contact_item_depth);
|
||||
|
||||
xml_close("CONTACT", $contact_depth);
|
||||
}
|
||||
}
|
||||
xml_close("CONTACTS", $email_item_depth);
|
||||
|
||||
xml_close("EMAIL", 1);
|
||||
}
|
||||
|
||||
xml_close("ROUNDCUBE", $top_depth);
|
||||
|
||||
fclose($fp);
|
||||
$mysqli->close();
|
||||
|
||||
exit(0);
|
||||
//**********************************************************************
|
||||
|
||||
function xml_item($name, $value, $tabs)
|
||||
{
|
||||
global $fp;
|
||||
|
||||
for ($i=0; $i<$tabs; $i++)
|
||||
fwrite($fp, "\t");
|
||||
|
||||
fwrite($fp, "<".$name.">");
|
||||
fwrite($fp, urlencode($value));
|
||||
fwrite($fp, "</".$name.">\n");
|
||||
}
|
||||
|
||||
function xml_open($name, $tabs)
|
||||
{
|
||||
global $fp;
|
||||
|
||||
for ($i=0; $i<$tabs; $i++)
|
||||
fwrite($fp, "\t");
|
||||
|
||||
fwrite($fp, "<".$name.">\n");
|
||||
}
|
||||
function xml_close($name, $tabs)
|
||||
{
|
||||
global $fp;
|
||||
|
||||
for ($i=0; $i<$tabs; $i++)
|
||||
fwrite($fp, "\t");
|
||||
|
||||
fwrite($fp, "</".$name.">\n");
|
||||
}
|
||||
|
||||
function show_help()
|
||||
{
|
||||
global $version;
|
||||
echo_stderr("Roundcube $version backup script to backup Users.\n\n");
|
||||
echo_stderr("Usage:\n");
|
||||
echo_stderr(" username=username domain=domain.com xml_file=/path/to/rc.xml ".__FILE__."\n\n");
|
||||
|
||||
echo_stderr("The script will output XML of all current email accounts stored in roundcube,\n");
|
||||
echo_stderr("for the given domain.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
function die_stderr($str)
|
||||
{
|
||||
echo_stderr($str);
|
||||
die();
|
||||
}
|
||||
|
||||
function echo_stderr($str)
|
||||
{
|
||||
$fd = fopen('php://stderr', 'w');
|
||||
fwrite($fd, $str);
|
||||
fclose($fd);
|
||||
}
|
||||
|
||||
function mes($str)
|
||||
{
|
||||
global $mysqli;
|
||||
return $mysqli->real_escape_string($str);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/usr/local/bin/php
|
||||
<?php
|
||||
$str = getenv("STRING");
|
||||
echo base64_encode($str);
|
||||
exit(0);
|
||||
?>
|
||||
@@ -1,162 +0,0 @@
|
||||
<?php
|
||||
$version = '2.0';
|
||||
|
||||
$user = getenv('DBUSER');
|
||||
$pass = getenv('DBPASS');
|
||||
$username = getenv('USERNAME');
|
||||
$newusername = getenv('NEWUSERNAME');
|
||||
|
||||
$host = getenv('DBHOST');
|
||||
if ($host == "")
|
||||
$host = 'localhost';
|
||||
|
||||
$verbose = getenv('VERBOSE');
|
||||
$verbose = ($verbose == 1) ? 1 : 0;
|
||||
$ignore_errors = 0; //power through at your own risk
|
||||
|
||||
$exit_code = 0;
|
||||
|
||||
$rename_database_sh = '/usr/local/directadmin/scripts/rename_database.sh';
|
||||
if (file_exists('/usr/local/directadmin/scripts/custom/rename_database.sh'))
|
||||
$rename_database_sh = '/usr/local/directadmin/scripts/custom/rename_database.sh';
|
||||
|
||||
if ($username == "" || $username == "root" || $username == "mysql")
|
||||
{
|
||||
die("Bad username ($username). aborting mysql database swap");
|
||||
}
|
||||
|
||||
if ($newusername == "" || $newusername == "root" || $newusername == "mysql")
|
||||
{
|
||||
die('Bad new username. aborting mysql database swap');
|
||||
}
|
||||
|
||||
$mysqli = new mysqli('localhost',$user,$pass);
|
||||
if ($mysqli->connect_error)
|
||||
{
|
||||
die('Could not connect to mysql: ('.$mysqli->connect_errno.') '. $mysqli->connect_error);
|
||||
}
|
||||
|
||||
//*******************************************************************
|
||||
// Main code
|
||||
|
||||
$mysqli->select_db('mysql');
|
||||
|
||||
replace_users($mysqli);
|
||||
rename_dbs($mysqli);
|
||||
|
||||
$mysqli->query("FLUSH_PRIVILEGES");
|
||||
$mysqli->close();
|
||||
|
||||
exit($exit_code);
|
||||
|
||||
//*******************************************************************
|
||||
|
||||
function rename_dbs($mysqli)
|
||||
{
|
||||
global $username, $newusername, $ignore_errors, $rename_database_sh, $exit_code;
|
||||
|
||||
// This will find all databases owned by the User
|
||||
// for each db, create a new db with the correct name (based on the old db?)
|
||||
// for each db, it finds all tables
|
||||
|
||||
|
||||
$user_dbs = get_user_dbs($mysqli);
|
||||
|
||||
foreach ($user_dbs as $db)
|
||||
{
|
||||
$new_db = preg_replace('/'.$username.'\\_/', $newusername.'_', $db);
|
||||
|
||||
vecho("Swapping $db to $new_db\n");
|
||||
|
||||
//This will mysqldump -> mysql to a new CREATE DB
|
||||
//and will update mysql.db, mysql.columns_priv, mysql.procs_priv, mysql.tables_priv
|
||||
$ret = 0;
|
||||
system($rename_database_sh." '".$db."' '".$new_db."'", $ret);
|
||||
if ($ret != 0)
|
||||
$exit_code = $ret;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function get_user_dbs($mysqli)
|
||||
{
|
||||
global $username;
|
||||
|
||||
$query = "SHOW DATABASES LIKE '$username\\_%'";
|
||||
if (! ($result = $mysqli->query($query)) )
|
||||
{
|
||||
die("DB List Error: ". $mysqli->error);
|
||||
}
|
||||
|
||||
$db_array = array();
|
||||
|
||||
while (($row = $result->fetch_row()))
|
||||
{
|
||||
array_push($db_array, $row[0]);
|
||||
}
|
||||
|
||||
$result->free();
|
||||
|
||||
return $db_array;
|
||||
}
|
||||
|
||||
|
||||
function replace_users($mysqli)
|
||||
{
|
||||
global $username;
|
||||
global $newusername;
|
||||
|
||||
//in this function, we need to replace
|
||||
// username to newusername
|
||||
// username_user to newusername_user
|
||||
|
||||
if (false) //old
|
||||
{
|
||||
$mysqli->query("UPDATE mysql.user SET user='$newusername' WHERE user='$username'");
|
||||
$mysqli->query("UPDATE mysql.db SET user='$newusername' WHERE user='$username'");
|
||||
}
|
||||
else //new
|
||||
{
|
||||
$query = "SELECT host FROM mysql.user WHERE user='$username'";
|
||||
$result = $mysqli->query($query) or vecho("Error selecting mysql.user: ".$mysqli->error."\n", 1);
|
||||
while ($row = $result->fetch_row())
|
||||
{
|
||||
$host = $row[0];
|
||||
|
||||
vecho("swapping '$username'@'$host' with '$newusername'@'$host'");
|
||||
|
||||
$query = "RENAME USER '$username'@'$host' TO '$newusername'@'$host'";
|
||||
$mysqli->query($query) or vecho("Error updating '$username'@'$host' to '$newusername'@'$host' with RENAME USER: ".$mysqli->error."\n", 1);
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$query = "SELECT user,host FROM mysql.user WHERE user LIKE '$username\\_%'";
|
||||
$result = $mysqli->query($query) or vecho("Error selecting mysql.user: ".$mysqli->error."\n", 1);
|
||||
|
||||
while ($row = $result->fetch_row())
|
||||
{
|
||||
$user = $row[0];
|
||||
$host = $row[1];
|
||||
$new_user = preg_replace('/'.$username.'_/', $newusername."_", $user);
|
||||
|
||||
vecho("swapping '$user'@'$host' with '$new_user'@'$host'");
|
||||
|
||||
$query = "RENAME USER '$user'@'$host' TO '$new_user'@'$host'";
|
||||
$mysqli->query($query) or vecho("Error updating '$user'@'$host' to '$new_user'@'$host' in mysql.user: ".$mysqli->error."\n", 1);
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
|
||||
function vecho($str, $is_err=0)
|
||||
{
|
||||
global $verbose;
|
||||
|
||||
if ($verbose || $is_err==1)
|
||||
echo $str."\n";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,454 +0,0 @@
|
||||
#!/bin/sh
|
||||
#VERSION=2.0
|
||||
#
|
||||
# Script used to change the name of a user
|
||||
#
|
||||
# Usage: change_username.sh
|
||||
|
||||
VERBOSE=1
|
||||
|
||||
MAX_LENGTH=10
|
||||
SYSTEM_USER_TO_VIRTUAL_PASSWD=0
|
||||
DA_BIN=/usr/local/directadmin/directadmin
|
||||
if [ -s "$DA_BIN" ]; then
|
||||
VAL=`/usr/local/directadmin/directadmin c |grep '^max_username_length=' | cut -d= -f2`
|
||||
if [ "$VAL" != "" ]; then
|
||||
if [ "$VAL" -gt 0 ]; then
|
||||
MAX_LENGTH=$VAL
|
||||
fi
|
||||
fi
|
||||
VAL=`/usr/local/directadmin/directadmin c |grep '^system_user_to_virtual_passwd=' | cut -d= -f2`
|
||||
if [ "$VAL" != "" ]; then
|
||||
if [ "$VAL" -gt 0 ]; then
|
||||
SYSTEM_USER_TO_VIRTUAL_PASSWD=$VAL
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
SYSTEMD=no
|
||||
SYSTEMDDIR=/etc/systemd/system
|
||||
if [ -d ${SYSTEMDDIR} ] && [ -e /usr/bin/systemctl ]; then
|
||||
SYSTEMD=yes
|
||||
fi
|
||||
|
||||
show_help()
|
||||
{
|
||||
echo "DirectAdmin username changing script (Beta)";
|
||||
echo "";
|
||||
echo "Usage: $0 oldusername newusername";
|
||||
echo "";
|
||||
}
|
||||
|
||||
OS=`uname`;
|
||||
|
||||
OHOME=`grep -e "^${1}:" /etc/passwd | cut -d: -f6`
|
||||
HOME_PATH=`dirname $OHOME`
|
||||
NHOME=
|
||||
|
||||
str_len()
|
||||
{
|
||||
echo ${#1}
|
||||
}
|
||||
|
||||
ensure_user()
|
||||
{
|
||||
/usr/bin/id $1 1>/dev/null 2>/dev/null
|
||||
if [ $? != 0 ]; then
|
||||
echo "Cannot find user $1";
|
||||
exit 2;
|
||||
fi
|
||||
}
|
||||
|
||||
prevent_user()
|
||||
{
|
||||
/usr/bin/id $1 1>/dev/null 2>/dev/null
|
||||
if [ $? = 0 ]; then
|
||||
echo "User $1 already exists";
|
||||
exit 4;
|
||||
fi
|
||||
|
||||
LEN=`str_len $1`
|
||||
if [ "$LEN" != "" ]; then
|
||||
if [ "$LEN" -gt "$MAX_LENGTH" ]; then
|
||||
echo "User $1 is $LEN characters long.";
|
||||
echo "The current max is:";
|
||||
echo "max_username_length=$MAX_LENGTH";
|
||||
exit 5;
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#rename cron files and spool files else they'll be removed
|
||||
#when account is removed.
|
||||
#redhat does /var/spool/mail/user for us
|
||||
move_spool_cron()
|
||||
{
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
mv -f /var/mail/$1 /var/mail/$2 2>/dev/null
|
||||
mv -f /var/cron/tabs/$1 /var/cron/tabs/$2 2>/dev/null
|
||||
else
|
||||
mv -f /var/spool/cron/$1 /var/spool/cron/$2 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
system_swap()
|
||||
{
|
||||
echo "Killing User processes:"
|
||||
/usr/bin/killall -s SIGKILL -u "$1"
|
||||
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
#have to add a new user to the same id, then remove the other user
|
||||
OUID=`grep -e "^${1}:" /etc/passwd | cut -d: -f3`
|
||||
OGID=`grep -e "^${1}:" /etc/passwd | cut -d: -f4`
|
||||
OPASS=`grep -e "^${1}:" /etc/master.passwd | cut -d: -f2`
|
||||
OSHELL=`grep -e "^${1}:" /etc/passwd | cut -d: -f7`
|
||||
|
||||
#some FreeBSD's don't support -H
|
||||
#echo $OPASS | /usr/sbin/pw useradd -n $2 -s $OSHELL -o -w no -u $OUID -g $OGID -H 0
|
||||
|
||||
/usr/sbin/pw useradd -n $2 -s $OSHELL -o -w no -u $OUID -g $OGID
|
||||
chpass -p $OPASS $2
|
||||
|
||||
#now do the group
|
||||
pw groupmod $1 -l $2 -q
|
||||
|
||||
else
|
||||
/usr/sbin/usermod -l $2 -d $HOME_PATH/$2 $1
|
||||
|
||||
#now do the group
|
||||
/usr/sbin/groupmod -n $2 $1
|
||||
fi
|
||||
|
||||
ensure_user $2
|
||||
|
||||
move_spool_cron $1 $2
|
||||
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
pw userdel $1
|
||||
fi
|
||||
|
||||
NHOME=`grep -e "^${2}:" /etc/passwd | cut -d: -f6`
|
||||
|
||||
mv -f $OHOME $NHOME
|
||||
|
||||
#update sshd_config if user exists:
|
||||
TEMP="/usr/bin/perl -pi -e 's/AllowUsers ${1}\$/AllowUsers ${2}/' /etc/ssh/sshd_config"
|
||||
eval $TEMP;
|
||||
}
|
||||
|
||||
security_check()
|
||||
{
|
||||
if [ "$1" = "root" ]; then
|
||||
echo "Are you mad? we don't play with root here. He's not nice.";
|
||||
exit 5;
|
||||
fi
|
||||
|
||||
for i in all action value domain email type root mail jail creator diradmin majordomo start stop reload restart demo_user demo_reseller demo_admin demo type backup log www apache mysql tmp test; do
|
||||
{
|
||||
if [ "$1" = "$i" ]; then
|
||||
echo "$1 is a reserved username, please choose another";
|
||||
exit 5;
|
||||
fi
|
||||
};
|
||||
done;
|
||||
|
||||
if [ "$1" = "" ]; then
|
||||
echo "blank user..make sure you've passed 2 usernames";
|
||||
exit 6;
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/perl ]; then
|
||||
echo "/usr/bin/perl does not exist";
|
||||
exit 7;
|
||||
fi
|
||||
}
|
||||
|
||||
generic_swap()
|
||||
{
|
||||
TEMP="/usr/bin/perl -pi -e 's/(^|[\s=\/:])${1}([\s\/:]|\$)/\${1}${2}\${2}/g' $3"
|
||||
eval $TEMP;
|
||||
}
|
||||
|
||||
mailing_list_swap()
|
||||
{
|
||||
TEMP="/usr/bin/perl -pi -e 's/([\s:])${1}([\s@]|\$)/\${1}${2}\${2}/g' $3"
|
||||
eval $TEMP;
|
||||
}
|
||||
|
||||
ftp_pass_swap()
|
||||
{
|
||||
TEMP="/usr/bin/perl -pi -e 's/(^)${1}([:])/\${1}${2}\${2}/g' $3"
|
||||
eval $TEMP;
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#${OHOME}([:\/])#${NHOME}\${1}#g' $3"
|
||||
eval $TEMP;
|
||||
}
|
||||
|
||||
awstats_swap()
|
||||
{
|
||||
#its called after system_swap, so we do it on user $2.
|
||||
TEMP="/usr/bin/perl -pi -e 's#/${OHOME}/#${NHOME}/#g' ${NHOME}/domains/*/awstats/.data/*.conf"
|
||||
eval $TEMP;
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#${OHOME}/#${NHOME}/#g' ${NHOME}/domains/*/awstats/awstats.pl"
|
||||
eval $TEMP;
|
||||
}
|
||||
installatron_swap()
|
||||
{
|
||||
if [ -d ${NHOME}/.appdata/current ]; then
|
||||
TEMP="/usr/bin/perl -pi -e 's/${1}/${2}/' ${NHOME}/.appdata/current/*"
|
||||
eval $TEMP;
|
||||
fi
|
||||
if [ -d ${NHOME}/.appdata/backups ]; then
|
||||
TEMP="/usr/bin/perl -pi -e 's/${1}/${2}/' ${NHOME}/.appdata/backups/*"
|
||||
eval $TEMP;
|
||||
fi
|
||||
}
|
||||
|
||||
snidomains_swap()
|
||||
{
|
||||
SNIDOMAINS=/etc/virtual/snidomains
|
||||
if [ ! -s ${SNIDOMAINS} ]; then
|
||||
return
|
||||
fi
|
||||
TEMP="/usr/bin/perl -pi -e 's/:${1}:/:${2}:/' ${SNIDOMAINS}"
|
||||
eval $TEMP;
|
||||
}
|
||||
|
||||
email_swap()
|
||||
{
|
||||
#/etc/virtual/domainowners
|
||||
#/etc/virtual/
|
||||
|
||||
DATA_USER_OLD=/usr/local/directadmin/data/users/${1}/
|
||||
DATA_USER_NEW=/usr/local/directadmin/data/users/${2}/
|
||||
|
||||
generic_swap $1 $2 /etc/virtual/domainowners
|
||||
snidomains_swap $1 $2
|
||||
|
||||
for i in `cat /usr/local/directadmin/data/users/$1/domains.list`; do
|
||||
{
|
||||
#check for suspended domains
|
||||
if [ ! -e /etc/virtual/$i ]; then
|
||||
if [ -e /etc/virtual/${i}_off ]; then
|
||||
i=${i}_off
|
||||
fi
|
||||
fi
|
||||
|
||||
generic_swap $1 $2 /etc/virtual/$i/aliases
|
||||
#twice for user:user
|
||||
generic_swap $1 $2 /etc/virtual/$i/aliases
|
||||
generic_swap $1 $2 /etc/virtual/$i/autoresponder.conf
|
||||
generic_swap $1 $2 /etc/virtual/$i/filter
|
||||
generic_swap $1 $2 /etc/virtual/$i/vacation.conf
|
||||
|
||||
#the dovecot passwd file uses the same format as the ftp.passwd file.
|
||||
ftp_pass_swap $1 $2 /etc/virtual/$i/passwd
|
||||
|
||||
if [ "${SYSTEM_USER_TO_VIRTUAL_PASSWD}" = "1" ]; then
|
||||
TEMP="/usr/bin/perl -pi -e 's/^$1:/$2:/' /etc/virtual/$i/passwd"
|
||||
eval $TEMP;
|
||||
fi
|
||||
|
||||
|
||||
if [ -e /etc/virtual/$i/reply/$1.msg ]; then
|
||||
mv -f /etc/virtual/$i/reply/$1.msg /etc/virtual/$i/reply/$2.msg
|
||||
fi
|
||||
if [ -e /etc/virtual/$i/reply/$1.msg_off ]; then
|
||||
mv -f /etc/virtual/$i/reply/$1.msg_off /etc/virtual/$i/reply/$2.msg_off
|
||||
fi
|
||||
if [ -e /etc/virtual/$i/majordomo ]; then
|
||||
mailing_list_swap $1 $2 /etc/virtual/$i/majordomo/list.aliases
|
||||
mailing_list_swap $1 $2 /etc/virtual/$i/majordomo/private.aliases
|
||||
fi
|
||||
|
||||
#/etc/dovecot/conf/sni/domain.com.conf
|
||||
SNI_CONF=/etc/dovecot/conf/sni/${i}.conf
|
||||
if [ -s ${SNI_CONF} ]; then
|
||||
TEMP="/usr/bin/perl -pi -e 's#${DATA_USER_OLD}#${DATA_USER_NEW}/#g' ${SNI_CONF}"
|
||||
eval $TEMP;
|
||||
fi
|
||||
};
|
||||
done;
|
||||
}
|
||||
|
||||
ftp_path_swap()
|
||||
{
|
||||
if [ ! -s "$3" ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#users/${1}/ftp.passwd#users/${2}/ftp.passwd#g' $3"
|
||||
eval $TEMP;
|
||||
}
|
||||
|
||||
ftp_swap()
|
||||
{
|
||||
#/etc/proftpd.passwd
|
||||
#/etc/proftpd.vhosts.conf
|
||||
ftp_path_swap $1 $2 /etc/proftpd.vhosts.conf
|
||||
ftp_pass_swap $1 $2 /etc/proftpd.passwd
|
||||
ftp_pass_swap $1 $2 /usr/local/directadmin/data/users/$1/ftp.passwd
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#users/${1}/#users/${2}/#g' /usr/local/directadmin/data/users/$1/domains/*.ftp";
|
||||
eval $TEMP;
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#${OHOME}/#${NHOME}/#g' /usr/local/directadmin/data/users/$1/domains/*.ftp";
|
||||
eval $TEMP;
|
||||
|
||||
}
|
||||
|
||||
httpd_swap()
|
||||
{
|
||||
#/etc/httpd/conf/httpd.conf
|
||||
#/etc/httpd/conf/ips.conf
|
||||
#/usr/local/directadmin/data/users/$1/httpd.conf
|
||||
|
||||
if [ ! -s /etc/httpd/conf/httpd.conf ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#users/${1}/httpd.conf#users/${2}/httpd.conf#g' /etc/httpd/conf/httpd.conf";
|
||||
eval $TEMP;
|
||||
TEMP="/usr/bin/perl -pi -e 's#users/${1}/httpd.conf#users/${2}/httpd.conf#g' /etc/httpd/conf/extra/directadmin-vhosts.conf";
|
||||
eval $TEMP;
|
||||
|
||||
#maybe it's nginx
|
||||
if [ -s /etc/nginx/directadmin-vhosts.conf ]; then
|
||||
TEMP="/usr/bin/perl -pi -e 's#users/${1}/nginx.conf#users/${2}/nginx.conf#g' /etc/nginx/directadmin-vhosts.conf";
|
||||
eval $TEMP;
|
||||
fi
|
||||
|
||||
#I thought about doing the ips.conf and the users httpd.conf file.
|
||||
#but figured it would be far safer to just issue a rewrite.
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#=${1}\$#=${2}#g' /usr/local/directadmin/data/users/$1/domains/*.conf";
|
||||
eval $TEMP;
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#users/${1}/#users/${2}/#g' /usr/local/directadmin/data/users/$1/domains/*.conf";
|
||||
eval $TEMP;
|
||||
}
|
||||
|
||||
nginx_swap()
|
||||
{
|
||||
if [ ! -s /etc/nginx/directadmin-vhosts.conf ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
#/etc/nginx/directadmin-vhosts.conf
|
||||
TEMP="/usr/bin/perl -pi -e 's#users/${1}/nginx.conf#users/${2}/nginx.conf#g' /etc/nginx/nginx.conf";
|
||||
}
|
||||
|
||||
mysql_swap()
|
||||
{
|
||||
#well, im going to say it outright.. this might not be so easy.
|
||||
#have to rename all the databases and all users from username_something to newuser_something.
|
||||
#1) stop mysql. Do this by killing the pid. Remember to set it to OFF in the services.status file.
|
||||
#2) rename the database directory
|
||||
#3) start up mysql again
|
||||
|
||||
|
||||
#use the change_database_username.sh script.
|
||||
MYSQL_CONF=/usr/local/directadmin/conf/mysql.conf
|
||||
MYSQL_USER=`cat $MYSQL_CONF | grep user | cut -d= -f2`
|
||||
MYSQL_PASS=`cat $MYSQL_CONF | grep passwd | cut -d= -f2`
|
||||
DBHOST=localhost
|
||||
if [ `grep -c ^host= $MYSQL_CONF` -gt 0 ]; then
|
||||
DBHOST=`cat $MYSQL_CONF | grep ^host= | cut -d= -f2`
|
||||
fi
|
||||
VERBOSE=$VERBOSE DBUSER="$MYSQL_USER" DBPASS="$MYSQL_PASS" DBHOST="$DBHOST" USERNAME="$1" NEWUSERNAME="$2" /usr/local/bin/php -c /usr/local/directadmin/scripts/php_clean.ini /usr/local/directadmin/scripts/change_database_username.php
|
||||
}
|
||||
|
||||
da_swap()
|
||||
{
|
||||
#email
|
||||
#ftp
|
||||
#httpd
|
||||
#./data/users/reseller/users.list
|
||||
#./data/users/client/user.conf->creator=$1 -> $2
|
||||
#./data/users/username and *
|
||||
|
||||
email_swap $1 $2
|
||||
ftp_swap $1 $2
|
||||
httpd_swap $1 $2
|
||||
nginx_swap $1 $2
|
||||
mysql_swap $1 $2
|
||||
if [ -e /usr/local/awstats ]; then
|
||||
awstats_swap $1 $2
|
||||
fi
|
||||
installatron_swap $1 $2
|
||||
|
||||
CREATOR=`grep creator= /usr/local/directadmin/data/users/$1/user.conf | cut -d= -f2`
|
||||
if [ "$CREATOR" != "root" ]; then
|
||||
generic_swap $1 $2 /usr/local/directadmin/data/users/$CREATOR/users.list
|
||||
fi
|
||||
|
||||
if [ -e /usr/local/directadmin/data/users/$1/reseller.conf ]; then
|
||||
generic_swap $1 $2 /usr/local/directadmin/data/admin/reseller.list
|
||||
TEMP="/usr/bin/perl -pi -e 's#reseller=${1}\$#reseller=${2}#g' /usr/local/directadmin/data/admin/ips/*";
|
||||
eval $TEMP;
|
||||
|
||||
#change the creator for all accounts we've made.
|
||||
for i in `cat /usr/local/directadmin/data/users/$1/users.list`; do
|
||||
{
|
||||
TEMP="/usr/bin/perl -pi -e 's#creator=${1}\$#creator=${2}#g' /usr/local/directadmin/data/users/$i/user.conf";
|
||||
eval $TEMP;
|
||||
};
|
||||
done;
|
||||
|
||||
#now check to see if we are an admin too. If so, change any resellers/admins who have us as their creator.
|
||||
TYPE=`grep usertype= /usr/local/directadmin/data/users/$1/user.conf | cut -d= -f2`
|
||||
if [ "$TYPE" = "admin" ]; then
|
||||
for i in `cat /usr/local/directadmin/data/admin/reseller.list; cat /usr/local/directadmin/data/admin/admin.list`; do
|
||||
{
|
||||
TEMP="/usr/bin/perl -pi -e 's#creator=${1}\$#creator=${2}#g' /usr/local/directadmin/data/users/$i/user.conf";
|
||||
eval $TEMP;
|
||||
};
|
||||
done;
|
||||
|
||||
generic_swap $1 $2 /usr/local/directadmin/data/admin/admin.list
|
||||
fi
|
||||
|
||||
#to be safe, rewrite the whole pile with the updated creator, in case anyone is suspended.
|
||||
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
|
||||
fi
|
||||
TEMP="/usr/bin/perl -pi -e 's#value=${1}\$#value=${2}#g' /usr/local/directadmin/data/admin/ips/*";
|
||||
eval $TEMP;
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#username=${1}\$#username=${2}#g' /usr/local/directadmin/data/users/$1/user.conf";
|
||||
eval $TEMP;
|
||||
|
||||
mv -f /usr/local/directadmin/data/users/$1 /usr/local/directadmin/data/users/$2
|
||||
|
||||
#once done, rewrite the ips.conf and users httpd.conf using $2
|
||||
#show all users cache. Total rewrite.
|
||||
|
||||
echo "action=rewrite&value=httpd&user=$2" >> /usr/local/directadmin/data/task.queue
|
||||
echo "action=rewrite&value=ips" >> /usr/local/directadmin/data/task.queue
|
||||
echo "action=cache&value=showallusers" >> /usr/local/directadmin/data/task.queue
|
||||
|
||||
}
|
||||
|
||||
change_name()
|
||||
{
|
||||
security_check $1;
|
||||
security_check $2;
|
||||
ensure_user $1;
|
||||
prevent_user $2;
|
||||
|
||||
system_swap $1 $2
|
||||
da_swap $1 $2
|
||||
}
|
||||
|
||||
if [ $# -eq 2 ]; then
|
||||
change_name $1 $2
|
||||
exit 0;
|
||||
else
|
||||
show_help;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
DA_DIR=/usr/local/directadmin
|
||||
DA_BIN=${DA_DIR}/directadmin
|
||||
|
||||
NAMED_CONF=""
|
||||
SERVICE_NAME=named
|
||||
if [ -s ${DA_DIR}/conf/directadmin.conf ] && [ -x ${DA_BIN} ]; then
|
||||
NAMED_CONF=`${DA_BIN} c | grep ^namedconfig= | cut -d= -f2`
|
||||
NAMED_OVERRIDE=`${DA_BIN} c | grep ^named_service_override= | cut -d= -f2`
|
||||
if [ "${NAMED_OVERRIDE}" != "" ]; then
|
||||
SERVICE_NAME=${NAMED_OVERRIDE}
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${NAMED_CONF}" = "" ] || [ ! -s "$NAMED_CONF" ]; then
|
||||
NAMED_CONF=/etc/named.conf
|
||||
OS=`uname`
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
NAMED_CONF=/etc/namedb/named.conf
|
||||
fi
|
||||
if [ -s /etc/debian_version ]; then
|
||||
NAMED_CONF=/etc/bind/named.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -s $NAMED_CONF ]; then
|
||||
echo "Cannnot find $NAMED_CONF to check";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if grep -m1 -q allow-transfer ${NAMED_CONF}; then
|
||||
#echo "Skipping allow-transfer chcek on ${NAMED_CONF}. allow-transfer already present.";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
OPTIONS_CONF=$NAMED_CONF
|
||||
HAVE_OPTIONS_AREA=`grep -c '^options {' ${OPTIONS_CONF}`
|
||||
|
||||
for i in `grep -E '^[[:space:]]*include ' ${NAMED_CONF} | cut -d\" -f2`; do
|
||||
{
|
||||
if [ "$i" = "" ] || [ ! -s "$i" ]; then
|
||||
continue;
|
||||
fi
|
||||
|
||||
if grep -m1 -q allow-transfer ${i}; then
|
||||
#echo "Skipping allow-transfer chcek on ${i}. allow-transfer already present.";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ "${HAVE_OPTIONS_AREA}" -eq 0 ]; then
|
||||
HAVE_OPTIONS_AREA=`grep -c '^options {' $i`
|
||||
if [ "${HAVE_OPTIONS_AREA}" -eq 0 ]; then
|
||||
continue;
|
||||
fi
|
||||
OPTIONS_CONF=$i
|
||||
fi
|
||||
};
|
||||
done;
|
||||
|
||||
if [ "${HAVE_OPTIONS_AREA}" -eq 0 ]; then
|
||||
echo "Could not find options section in the $NAMED_CONF or any of it's include files";
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
if ! grep -m1 -q allow-transfer ${OPTIONS_CONF}; then
|
||||
perl -pi -e 's|options \{|options \{\n\tallow-transfer \{ none; \};|g' ${OPTIONS_CONF}
|
||||
echo "Added 'allow-transfer { none; };' to ${OPTIONS_CONF}"
|
||||
echo "action=${SERVICE_NAME}&value=reload" >> ${DA_DIR}/data/task.queue
|
||||
fi
|
||||
|
||||
exit 0;
|
||||
@@ -1,67 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
OS=`uname`
|
||||
NETSTAT=/bin/netstat
|
||||
SS=/usr/sbin/ss
|
||||
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
NETSTAT=/usr/bin/netstat
|
||||
fi
|
||||
|
||||
freebsd_netstat()
|
||||
{
|
||||
${NETSTAT} -n -p tcp
|
||||
${NETSTAT} -n -p udp
|
||||
}
|
||||
|
||||
netstat_out()
|
||||
{
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
freebsd_netstat | grep -v Address | grep -v Active | grep -v '*.*' | awk '{print $5}' | sed 's/\(.*\)\..*/\1/'
|
||||
else
|
||||
${NETSTAT} -ntu | grep -v Address | grep -v Active | grep -v '*.*' | awk '{print $5}' | sed 's/\(.*\):.*/\1/'
|
||||
fi
|
||||
}
|
||||
|
||||
show_ip_info()
|
||||
{
|
||||
I=$1
|
||||
|
||||
echo ""
|
||||
echo "Connection info for '${I}':"
|
||||
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
freebsd_netstat | grep $I
|
||||
else
|
||||
${NETSTAT} -ntu | grep $I
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -x ${NETSTAT} ]; then
|
||||
echo "Connection counts:"
|
||||
netstat_out | sort | uniq -c | sort -n | tail -n 100
|
||||
|
||||
echo ""
|
||||
|
||||
#now take the IP with top connection count and get more info.
|
||||
C_IP=`netstat_out | sort | uniq -c | sort -n | tail -n 1`
|
||||
C=`echo "$C_IP" | awk '{print $1}'`
|
||||
IP=`echo "$C_IP" | awk '{print $2}'`
|
||||
echo "IP '$IP' currently has '$C' connections"
|
||||
|
||||
show_ip_info $IP
|
||||
|
||||
fi
|
||||
|
||||
if [ -x ${SS} ]; then
|
||||
echo ""
|
||||
echo "$SS output:"
|
||||
$SS -n
|
||||
fi
|
||||
|
||||
CIP=/usr/local/directadmin/scripts/custom/connection_info_post.sh
|
||||
if [ -x ${CIP} ]; then
|
||||
${CIP}
|
||||
fi
|
||||
|
||||
exit 0;
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
OS=`uname`
|
||||
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
DENY=/var/cron/deny
|
||||
else
|
||||
DENY=/etc/cron.deny
|
||||
fi
|
||||
|
||||
deny()
|
||||
{
|
||||
if [ -e $DENY ]; then
|
||||
COUNT=`grep -c -e "^$1\$" $DENY`
|
||||
if [ "$COUNT" -ne 0 ]; then
|
||||
return;
|
||||
fi
|
||||
fi
|
||||
|
||||
echo $1 >> $DENY
|
||||
chmod 640 $DENY
|
||||
}
|
||||
|
||||
deny apache
|
||||
deny webapps
|
||||
|
||||
exit 0;
|
||||
@@ -1,225 +0,0 @@
|
||||
**********
|
||||
|
||||
The contents of this file will map what script names will be associated with what commands.
|
||||
Several scripts exist that are not mentioned here. Check:
|
||||
http://www.directadmin.com/versions.php
|
||||
Search for the keyword you're looking for plus pre.sh or post.sh
|
||||
|
||||
**********
|
||||
|
||||
|
||||
##########################################
|
||||
|
||||
domain_create_pre.sh - Runs BEFORE a domain is created
|
||||
domain_create_post.sh - Runs AFTER a domain is created
|
||||
domain_destroy_pre.sh - Runs BEFORE a domain is destroyed
|
||||
domain_destroy_post.sh - Runs AFTER a domain is destroyed
|
||||
|
||||
environmental variables:
|
||||
bandwidth=# or unlimited
|
||||
cgi=ON or OFF
|
||||
defaultdomain=yes or no
|
||||
domain=domain.com
|
||||
ssl=ON or OFF
|
||||
suspended=yes or no
|
||||
username=ownerofdomain
|
||||
|
||||
##########################################
|
||||
|
||||
domain_change_pre.sh - Runs BEFORE a domain is renamed. A non-zero value will abort the change.
|
||||
domain_change_post.sh - Runs AFTER a domain is renamed.
|
||||
|
||||
environmental vars: http://www.directadmin.com/features.php?id=448
|
||||
|
||||
##########################################
|
||||
|
||||
subdomain_create_pre.sh - Runs BEFORE a subdomain is created, but after it's confirmed.
|
||||
If this script returns a non-zero value, the creation is aborted.
|
||||
subdomain_create_post.sh - Runs AFTER the subdomain is created.
|
||||
subdomain_destroy_pre.sh - Runs BEFORE a subdomain is destroyed. If this script returns
|
||||
a non-zero value, the destruction is aborted
|
||||
subdomain_destroy_post.sh - Runs AFTER the subdomain is destroyed.
|
||||
|
||||
environmental variables:
|
||||
username=ownerofdomain
|
||||
domain=domain.com
|
||||
subdomain=sub
|
||||
contents=1 or 0 - only for destroy. Specifies that the directory and contents are being removed.
|
||||
|
||||
##########################################
|
||||
|
||||
user_create_pre.sh - Runs BEFORE the user is created, but after it's confirmed.
|
||||
If this script returns anything but zero, the creation is aborted
|
||||
user_create_post.sh - Runs AFTER the user is created.
|
||||
user_destroy_pre.sh - Runs BEFORE the use is destroyed. If this script returns anything
|
||||
but zero, the destruction is aborted.
|
||||
user_destroy_post.sh - Runs AFTER the user is destroyed.
|
||||
user_modify_post.sh - Runs AFTER the user is modified.
|
||||
|
||||
environmental variables:
|
||||
account=ON or OFF
|
||||
aftp=ON or OFF
|
||||
bandwidth=# or unlimited
|
||||
cgi=ON or OFF
|
||||
creator=username
|
||||
dnscontrol=ON or OFF
|
||||
docsroot=./data/skins/default (relative path to document root)
|
||||
domain=domain.com
|
||||
domainptr=# or unlimited
|
||||
email=email@domain.com
|
||||
ftp=# or unlimited
|
||||
ip=1.2.3.4
|
||||
mysql=# or unlimited
|
||||
nemailf=# or unlimited
|
||||
nemailml=# or unlimited
|
||||
nemailr=# or unlimited
|
||||
nemails=# or unlimited
|
||||
ns1=ns1.domain.com
|
||||
ns2=ns2.domain.com
|
||||
nsubdomains=# or unlimited
|
||||
package=packagename
|
||||
passwd=the password entered
|
||||
quota=# or unlimited
|
||||
sentwarning=no (refers to resource usage limits notification emails)
|
||||
skin=default (name of skin)
|
||||
ssh=ON or OFF
|
||||
ssl=ON or OFF
|
||||
suspend_at_limit=ON or OFF
|
||||
suspended=no
|
||||
username=username
|
||||
usertype=user or reseller or admin
|
||||
vdomains=# or unlimited
|
||||
zoom=100 (completely useless value token for the css zoom feature)
|
||||
|
||||
##########################################
|
||||
|
||||
email_create_pre.sh - Runs BEFORE the virtual email is created, but after it's confirmed.
|
||||
If this script returns anything but zero, the creation is aborted
|
||||
email_create_post.sh - Runs AFTER the email is created
|
||||
|
||||
environment values:
|
||||
user=bob
|
||||
domain=domain.com
|
||||
passwd=secret
|
||||
passwd2=secret
|
||||
username=username
|
||||
quota=#
|
||||
|
||||
##########################################
|
||||
|
||||
email_destroy_pre.sh - Runs AFTER virtual email account is deleted.
|
||||
|
||||
environement values:
|
||||
user=bob
|
||||
domain=domain.com
|
||||
username=username
|
||||
|
||||
##########################################
|
||||
|
||||
email_change_pre_post.sh - Runs BEFORE a virtual pop account password is changed.
|
||||
If this script returns anything but zero, the change is aborted.
|
||||
email_change_pass_post.sh - Runs AFTER a virtual pop account password is changed.
|
||||
|
||||
#username and quota are not passed if the password change is done using "/CMD_CHANGE_EMAIL_PASSWORD"
|
||||
|
||||
environmental values:
|
||||
user=bob
|
||||
domain=domain.com
|
||||
passwd=newsecret
|
||||
|
||||
username=username
|
||||
quota=#
|
||||
|
||||
##########################################
|
||||
|
||||
dns_write_post.sh - Runs AFTER a dns zone is written (/var/named/domain.com.db)
|
||||
|
||||
environmental values:
|
||||
A : list of a records
|
||||
CNAME : list of cname records
|
||||
MX : list of mx records
|
||||
NS : list of ns records
|
||||
PTR : list of ptr records
|
||||
SERIAL : the serial used in the zone
|
||||
EMAIL : authoritative email
|
||||
NS1 : authoritative ns zone.
|
||||
DOMAIN : domain name of the zone
|
||||
SERVER_IP : server IP
|
||||
A_TIME : ttl for A records
|
||||
CNAME_TIE : ttl for CNAME records
|
||||
NS_TIME : ttl for NS records
|
||||
PTR_TIME : ttl for PTR records
|
||||
see http://www.directadmin.com/features.php?id=450 for more info
|
||||
|
||||
##########################################
|
||||
|
||||
database_create_post.sh
|
||||
database_user_create_post.sh
|
||||
|
||||
environmental variables for both scripts:
|
||||
|
||||
username - DA username
|
||||
database - name of the db
|
||||
user - name of the user created
|
||||
passwd - password used.
|
||||
|
||||
Note that database_create_user_post.sh will not be called when a database and it's user is being created.
|
||||
This means that any code used in database_user_create_post.sh will have to be doubled in
|
||||
database_create_post.sh as well for anything you want done to a new user.
|
||||
|
||||
##########################################
|
||||
|
||||
domain_pointer_create_pre.sh
|
||||
domain_pointer_create_post.sh
|
||||
|
||||
environmental variables:
|
||||
username
|
||||
domain
|
||||
from=domainpointer.com
|
||||
ip=1.2.3.4
|
||||
ns1=ns1.ns.com
|
||||
ns2=ns2.ns.com
|
||||
alias=yes or non-existant (checkbox)
|
||||
|
||||
|
||||
domain_pointer_destroy_pre.sh
|
||||
domain_pointer_destroy_post.sh
|
||||
|
||||
environmental variables:
|
||||
username
|
||||
domain=domain.com
|
||||
from=dominpointer.com
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##########################################
|
||||
|
||||
If you need to execute code a few seconds after the sh script it call
|
||||
this code is a basic example on how to throw the script into the background
|
||||
The foreground instance of it will close all file descriptors, then call
|
||||
the background function, then exit. Becuase of the & character, the
|
||||
background function is put in the background and runs until it's done.
|
||||
Thanks to Alex for this find.
|
||||
|
||||
==================================
|
||||
#!/bin/bash
|
||||
|
||||
function back(){
|
||||
sleep 5
|
||||
echo $0 `date` background >/tmp/da_scripts
|
||||
}
|
||||
|
||||
echo $0 `date` start >/tmp/da_scripts
|
||||
|
||||
#closing all FDs
|
||||
exec 0>&-
|
||||
#this is important
|
||||
exec 1>&-
|
||||
exec 4>&-
|
||||
|
||||
back &
|
||||
exit 0
|
||||
==================================
|
||||
@@ -1,16 +0,0 @@
|
||||
# DirectAdmin control panel
|
||||
# To reload systemd daemon after changes to this file:
|
||||
# systemctl --system daemon-reload
|
||||
[Unit]
|
||||
Description=POP before SMTP daemon
|
||||
After=syslog.target network.target
|
||||
Documentation=http://www.directadmin.com
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
PIDFile=/run/da-popb4smtp.pid
|
||||
ExecStart=/usr/local/directadmin/da-popb4smtp
|
||||
WorkingDirectory=/usr/local/directadmin
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,36 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$#" -ne 3 ]; then
|
||||
|
||||
echo "Usage:";
|
||||
echo " $0 <encryptedin> <fileout> <passwordfile>"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OPENSSL=/usr/bin/openssl
|
||||
|
||||
E=$1
|
||||
O=$2
|
||||
P=$3
|
||||
|
||||
if [ "${E}" = "" ] || [ ! -e ${E} ]; then
|
||||
echo "Cannot find $F for decryption"
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
if [ "${O}" = "" ]; then
|
||||
echo "Please pass a destination path"
|
||||
exit 3;
|
||||
fi
|
||||
|
||||
if [ "${P}" = "" ] || [ ! -s ${P} ]; then
|
||||
echo "Cannot find passwordfile $P"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
${OPENSSL} enc -d -aes-256-cbc -salt -in $E -out $O -kfile ${P} 2>&1
|
||||
|
||||
RET=$?
|
||||
|
||||
exit $RET
|
||||
@@ -1,129 +0,0 @@
|
||||
#!/usr/local/bin/php
|
||||
<?php
|
||||
|
||||
/*
|
||||
This script is to enforce a level of password difficulty that users must use.
|
||||
You can change the minimum length if you wish, the default is 6.
|
||||
The requirement for special characters is disabled by default.
|
||||
|
||||
Related directadmin.conf options:
|
||||
- difficult password enforcement: http://www.directadmin.com/features.php?id=910
|
||||
- enable shift chars: https://www.directadmin.com/features.php?id=1625
|
||||
- min password length: http://www.directadmin.com/features.php?id=1176
|
||||
- random password length: http://www.directadmin.com/features.php?id=1604
|
||||
- ajax password checking/generation: http://www.directadmin.com/features.php?id=1560
|
||||
*/
|
||||
|
||||
|
||||
$min_length = getenv("difficult_password_length_min");
|
||||
$pass = getenv("password");
|
||||
$random_password_length = getenv("random_password_length");
|
||||
$special_characters_in_random_passwords = getenv("special_characters_in_random_passwords");
|
||||
|
||||
if ($random_password_length < $min_length)
|
||||
{
|
||||
$min_length = $random_password_length;
|
||||
}
|
||||
|
||||
|
||||
//FUNCTION CALL section
|
||||
|
||||
check_length($pass);
|
||||
enforce_mixed_case($pass);
|
||||
enforce_numbers($pass);
|
||||
|
||||
if ($special_characters_in_random_passwords)
|
||||
enforce_shift_chars($pass);
|
||||
|
||||
//FUNCTION CALL section, end
|
||||
|
||||
//passes the test
|
||||
echo "Password OK\n";
|
||||
|
||||
exit(0);
|
||||
|
||||
|
||||
function enforce_shift_chars($str)
|
||||
{
|
||||
if (!has_shift_chars($str))
|
||||
{
|
||||
echo "Password must have at least one special character such as !@#%$ etc..\n";
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
function enforce_numbers($str)
|
||||
{
|
||||
if (!has_numbers($str))
|
||||
{
|
||||
echo "Password must have numbers\n";
|
||||
exit(4);
|
||||
}
|
||||
}
|
||||
|
||||
function enforce_mixed_case($str)
|
||||
{
|
||||
if (!has_caps($str) || !has_lower_case($str))
|
||||
{
|
||||
echo "Password must have both upper and lower case characters\n";
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
function check_length($str)
|
||||
{
|
||||
global $min_length;
|
||||
$len = strlen($str);
|
||||
if ($len < $min_length)
|
||||
{
|
||||
echo "Password is too short ($len). Use at least $min_length characters\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function has_shift_chars($str)
|
||||
{
|
||||
//return preg_match("/[\~\!\@\#\$\%\^\&\*\(\)\-\=\_\+\{\}\:\;\|\<\>\,\.\?\/]+/", $str);
|
||||
$len = strlen($str);
|
||||
$num_count=0;
|
||||
for ($i=0; $i<$len; $i++)
|
||||
{
|
||||
$ch=$str[$i];
|
||||
if ('!' <= $ch && $ch <= '/')
|
||||
{
|
||||
$num_count++;
|
||||
}
|
||||
if (':' <= $ch && $ch <= '@')
|
||||
{
|
||||
$num_count++;
|
||||
}
|
||||
if ('[' <= $ch && $ch <= '`')
|
||||
{
|
||||
$num_count++;
|
||||
}
|
||||
if ('{' <= $ch && $ch <= '~')
|
||||
{
|
||||
$num_count++;
|
||||
}
|
||||
}
|
||||
return $num_count;
|
||||
}
|
||||
|
||||
function has_numbers($str)
|
||||
{
|
||||
return preg_match("/[0-9]+/", $str);
|
||||
}
|
||||
|
||||
function has_caps($str)
|
||||
{
|
||||
return preg_match("/[A-Z]+/", $str);
|
||||
}
|
||||
|
||||
function has_lower_case($str)
|
||||
{
|
||||
return preg_match("/[a-z]+/", $str);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
?>
|
||||
@@ -1,76 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# directadmin daemon Start/Stop/Status/Restart
|
||||
|
||||
# chkconfig: 2345 80 20
|
||||
# description: Allows users to modify their websites. \
|
||||
# They modify thier: email, subdomains, \
|
||||
# databases, dns record, etc...
|
||||
# processname: directadmin
|
||||
# config: /usr/local/directadmin/conf/paneld.conf
|
||||
# pidfile: /var/run/directadmin.pid
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: directadmin
|
||||
# Required-Start: $local_fs $network
|
||||
# Required-Stop: $local_fs
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: directadmin
|
||||
# Description: directadmin daemon
|
||||
### END INIT INFO
|
||||
|
||||
# Source function library
|
||||
. /etc/rc.d/init.d/functions
|
||||
|
||||
PROGBIN="/usr/local/directadmin/directadmin d"
|
||||
PROGLOCK=/var/lock/subsys/directadmin
|
||||
PROGNAME=directadmin
|
||||
|
||||
umask 0022
|
||||
|
||||
#check the command line for actions
|
||||
|
||||
start() {
|
||||
echo -n "Starting DirectAdmin: "
|
||||
daemon $PROGBIN
|
||||
echo
|
||||
touch $PROGLOCK
|
||||
}
|
||||
|
||||
stop() {
|
||||
echo -n "Stopping DirectAdmin: "
|
||||
killproc $PROGNAME
|
||||
echo
|
||||
rm -f $PROGLOCK
|
||||
}
|
||||
|
||||
reload() {
|
||||
echo -n "Reloading DirectAdmin config file: "
|
||||
killproc $PROGNAME -HUP
|
||||
echo
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
status)
|
||||
status $PROGNAME
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $1 {start|stop|status|reload|restart}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit 0
|
||||
@@ -1,8 +0,0 @@
|
||||
/var/log/directadmin/error.log /var/log/directadmin/errortaskq.log /var/log/directadmin/security.log /var/log/directadmin/system.log /var/log/directadmin/login.log {
|
||||
missingok
|
||||
create 0644 diradmin diradmin
|
||||
sharedscripts
|
||||
postrotate
|
||||
find /var/log/directadmin -name "20*log*" -mtime +30 -exec /bin/rm -f {} \; >/dev/null 2>&1 || true
|
||||
endscript
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
# DirectAdmin control panel
|
||||
# To reload systemd daemon after changes to this file:
|
||||
# systemctl --system daemon-reload
|
||||
[Unit]
|
||||
Description=DirectAdmin Web Control Panel
|
||||
After=syslog.target network.target
|
||||
Documentation=http://www.directadmin.com
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
PIDFile=/run/directadmin.pid
|
||||
ExecStart=/usr/local/directadmin/directadmin d
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
WorkingDirectory=/usr/local/directadmin
|
||||
LimitNOFILE=65535
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,6 +0,0 @@
|
||||
* * * * * root /usr/local/directadmin/dataskq
|
||||
2 0-23/6 * * * root echo 'action=vacation&value=all' >> /usr/local/directadmin/data/task.queue;
|
||||
#5 5 * * 0 root /sbin/quotaoff -a; /sbin/quotacheck -augm; /sbin/quotaon -a;
|
||||
10 0 * * * root echo 'action=tally&value=all' >> /usr/local/directadmin/data/task.queue
|
||||
20 4 1 * * root echo 'action=reset&value=all' >> /usr/local/directadmin/data/task.queue
|
||||
0 4 * * * root echo 'action=check&value=license' >> /usr/local/directadmin/data/task.queue
|
||||
@@ -1,83 +0,0 @@
|
||||
#!/bin/sh
|
||||
#dkim script to create keys in /etc/virtual/domain.com
|
||||
#will ensure they exist and create them if missing.
|
||||
#will also dump a task.queue entry to get DA to add the newly created key to the dns.
|
||||
|
||||
if [ $# != 1 ] && [ $# != 2 ]; then
|
||||
echo "Usage:";
|
||||
echo "$0 <domain> (nodns)";
|
||||
echo "you gave #$#: $0 $1 $2";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
DOMAIN=$1
|
||||
DOMAIN_OWNERS=/etc/virtual/domainowners
|
||||
VD=/etc/virtual/$DOMAIN
|
||||
PRIV_KEY=${VD}/dkim.private.key
|
||||
PUB_KEY=${VD}/dkim.public.key
|
||||
|
||||
OS="`uname`"
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
CHOWN=/usr/sbin/chown
|
||||
else
|
||||
CHOWN=/bin/chown
|
||||
fi
|
||||
|
||||
if [ ! -e $CHOWN ]; then
|
||||
echo "Cannot find chown at $CHOWN";
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
DKIM_ON=`/usr/local/directadmin/directadmin c | grep dkim= | cut -d= -f2`
|
||||
if [ "$DKIM_ON" -eq 0 ]; then
|
||||
echo "DKIM is not enabled. Add dkim=1 to the directadmin.conf";
|
||||
exit 3;
|
||||
fi
|
||||
|
||||
if [ ! -d ${VD} ]; then
|
||||
echo "Unable to find ${VD}";
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
|
||||
COUNT=`grep -c ^${DOMAIN}: ${DOMAIN_OWNERS}`
|
||||
if [ "${COUNT}" -gt 0 ]; then
|
||||
#lets see if they've set dkim=0 in their user.conf or domains/domain.com.conf
|
||||
#https://www.directadmin.com/features.php?id=1937
|
||||
D_USER=`grep ^${DOMAIN}: ${DOMAIN_OWNERS} | cut -d\ -f2`
|
||||
USER_CONF=/usr/local/directadmin/data/users/${D_USER}/user.conf
|
||||
if [ -s ${USER_CONF} ]; then
|
||||
COUNT=`grep -c dkim=0 ${USER_CONF}`
|
||||
if [ "${COUNT}" -gt 0 ]; then
|
||||
echo "User ${D_USER} has dkim=0 set in ${USER_CONF}. Not setting dkim."
|
||||
exit 4;
|
||||
fi
|
||||
|
||||
DOMAIN_CONF=/usr/local/directadmin/data/users/${D_USER}/domains/${DOMAIN}.conf
|
||||
if [ -s ${DOMAIN_CONF} ]; then
|
||||
COUNT=`grep -c dkim=0 ${DOMAIN_CONF}`
|
||||
if [ "${COUNT}" -gt 0 ]; then
|
||||
echo "Domain ${DOMAIN} has dkim=0 set in ${DOMAIN_CONF}. Not setting dkim."
|
||||
exit 5;
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -e ${PRIV_KEY} ] || [ ! -e ${PUB_KEY} ]; then
|
||||
openssl genrsa -out ${PRIV_KEY} 2048 2>&1
|
||||
openssl rsa -in ${PRIV_KEY} -out ${PUB_KEY} -pubout -outform PEM 2>&1
|
||||
chmod 600 ${PRIV_KEY} ${PUB_KEY}
|
||||
$CHOWN mail:mail ${PRIV_KEY} ${PUB_KEY}
|
||||
fi
|
||||
|
||||
ADD_DNS=1
|
||||
if [ $# = 2 ] && [ "$2" = "nodns" ]; then
|
||||
ADD_DNS=0
|
||||
fi
|
||||
|
||||
if [ "$ADD_DNS" -eq 1 ]; then
|
||||
echo "action=rewrite&value=dkim&domain=${DOMAIN}&dns=yes" >> /usr/local/directadmin/data/task.queue
|
||||
fi
|
||||
|
||||
exit 0;
|
||||
@@ -1,363 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#This is not finished.
|
||||
#Do not use
|
||||
|
||||
OS=`uname`
|
||||
|
||||
DA=/usr/local/directadmin/directadmin
|
||||
if [ ! -s ${DA} ]; then
|
||||
echo "Cannot find DirectAdmin binary:";
|
||||
echo " ${DA}";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
DA_CONF=/usr/local/directadmin/conf/directadmin.conf
|
||||
if [ ! -s ${DA_CONF} ]; then
|
||||
echo "Cannot find DirectAdmin Config File:";
|
||||
echo " ${DA_CONF}";
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
TASK_Q=`${DA} c | grep ^taskqueuecb= | cut -d= -f2`
|
||||
if [ "${TASK_Q}" = "" ]; then
|
||||
echo "Cannot task.queue.cb from:";
|
||||
echo "${DA} c | grep ^taskqueuecb=";
|
||||
exit 3;
|
||||
fi
|
||||
DATASKQ="/usr/local/directadmin/dataskq --custombuild"
|
||||
|
||||
BIND_PATH=/etc
|
||||
NAMED_BIN=/usr/sbin/named
|
||||
DNSSEC_KEYGEN=/usr/sbin/dnssec-keygen
|
||||
DNSSEC_SIGNZONE=/usr/sbin/dnssec-signzone
|
||||
DNSSEC_RANDOMDEV='-r /dev/urandom'
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
BIND_PATH=/etc/namedb
|
||||
NAMED_BIN=/usr/local/sbin/named
|
||||
DNSSEC_KEYGEN=/usr/local/sbin/dnssec-keygen
|
||||
DNSSEC_SIGNZONE=/usr/local/sbin/dnssec-signzone
|
||||
DNSSEC_RANDOMDEV=
|
||||
elif [ -e /etc/debian_version ]; then
|
||||
BIND_PATH=/etc/bind
|
||||
fi
|
||||
|
||||
NAMED_PATH=`${DA} c | grep ^nameddir= | cut -d= -f2 2>/dev/null`
|
||||
if [ "${NAMED_PATH}" = "" ]; then
|
||||
echo "Cannot find nameddir from:";
|
||||
echo "${DA} c | grep ^nameddir=";
|
||||
exit 3;
|
||||
fi
|
||||
DNSSEC_KEYS_PATH=${NAMED_PATH}
|
||||
|
||||
NAMED_CONF=${BIND_PATH}/named.conf
|
||||
NAMED_CONF=`${DA} c | grep namedconfig= | cut -d= -f2`
|
||||
|
||||
if [ -e /etc/debian_version ] && [ -e /etc/bind/named.conf.options ]; then
|
||||
NAMED_CONF=/etc/bind/named.conf.options
|
||||
fi
|
||||
|
||||
if [ ! -s ${NAMED_BIN} ]; then
|
||||
echo "Cannot find ${NAMED_BIN}";
|
||||
exit 4;
|
||||
fi
|
||||
|
||||
NAMED_VER=`${NAMED_BIN} -v | cut -d\ -f2 | cut -d- -f1 | cut -d. -f1,2`
|
||||
|
||||
BIND_KEYS_FILE=${BIND_PATH}/named.iscdlv.key
|
||||
|
||||
if [ ! -x ${DNSSEC_KEYGEN} ]; then
|
||||
echo "Cannot find ${DNSSEC_KEYGEN}. Please install dnssec tools";
|
||||
exit 12;
|
||||
fi
|
||||
|
||||
ENC_TYPE=RSASHA1
|
||||
if [ `$DNSSEC_KEYGEN -h 2>&1 | grep -c RSASHA256` -gt 0 ]; then
|
||||
ENC_TYPE=RSASHA256
|
||||
fi
|
||||
|
||||
if [ ! -s ${DNSSEC_SIGNZONE} ]; then
|
||||
echo "Cannot find ${DNSSEC_SIGNZONE}. Please install dnssec tools";
|
||||
exit 13;
|
||||
fi
|
||||
HAS_SOA_FORMAT=0
|
||||
SF=`${DNSSEC_SIGNZONE} -h 2>&1 | grep -c '\-N format:'`
|
||||
if [ "${SF}" -gt 0 ]; then
|
||||
HAS_SOA_FORMAT=1
|
||||
fi
|
||||
|
||||
SATZ=skip-add-to-zone
|
||||
show_help()
|
||||
{
|
||||
echo "Usage:";
|
||||
echo " $0 install";
|
||||
echo " $0 keygen <domain>"; # [${SATZ}]";
|
||||
echo " $0 sign <domain>";
|
||||
echo "";
|
||||
echo "The ${SATZ} option will create the keys, but will not trigger the dataskq to add the keys to the zone.";
|
||||
echo "";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if [ $# = 0 ]; then
|
||||
show_help;
|
||||
fi
|
||||
|
||||
##################################################################################################################################################
|
||||
#
|
||||
# Installer code
|
||||
#
|
||||
|
||||
ensure_bind_key()
|
||||
{
|
||||
#http://ftp.isc.org/isc/bind9/keys/9.7/bind.keys.v9_7
|
||||
#http://ftp.isc.org/isc/bind9/keys/9.6/bind.keys.v9_6
|
||||
#http://ftp.isc.org/isc/bind9/keys/9.8/bind.keys.v9_8
|
||||
|
||||
SERVER=http://ftp.isc.org/isc/bind9/keys
|
||||
BIND_KEYS_PATH=9.7/bind.keys.v9_7
|
||||
case "${NAMED_VER}" in
|
||||
9.2|9.3|9.4|9.5|9.6) BIND_KEYS_PATH=9.6/bind.keys.v9_6
|
||||
;;
|
||||
9.7) BIND_KEYS_PATH=9.7/bind.keys.v9_7
|
||||
;;
|
||||
9.8|9.9) BIND_KEYS_PATH=9.8/bind.keys.v9_8
|
||||
esac
|
||||
|
||||
BIND_KEYS_URL=${SERVER}/${BIND_KEYS_PATH}
|
||||
|
||||
DL=0
|
||||
if [ ! -s ${BIND_KEYS_FILE} ]; then
|
||||
DL=1
|
||||
elif [ "`grep -c trusted-keys ${BIND_KEYS_FILE}`" -eq 0 ] && [ "`grep -c managed-keys ${BIND_KEYS_FILE}`" -eq 0 ]; then
|
||||
DL=1
|
||||
fi
|
||||
|
||||
if [ "${DL}" -eq 1 ]; then
|
||||
wget -O ${BIND_KEYS_FILE} ${BIND_KEYS_URL}
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_named_conf()
|
||||
{
|
||||
if [ ! -s "${NAMED_CONF}" ] || [ "${NAMED_CONF}" = "" ]; then
|
||||
echo "Cannot find ${NAMED_CONF}";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
ADD_TO_NC=""
|
||||
|
||||
if [ "`grep -c 'dnssec-enable yes' ${NAMED_CONF}`" -eq 0 ]; then
|
||||
ADD_TO_NC="${ADD_TO_NC} dnssec-enable yes;
|
||||
"
|
||||
fi
|
||||
|
||||
if [ "`grep -c 'dnssec-validation auto' ${NAMED_CONF}`" -eq 1 ]; then
|
||||
perl -pi -e 's/dnssec-validation auto/dnssec-validation yes/' ${NAMED_CONF}
|
||||
fi
|
||||
|
||||
if [ "`grep -c 'dnssec-validation yes' ${NAMED_CONF}`" -eq 0 ]; then
|
||||
ADD_TO_NC="${ADD_TO_NC} dnssec-validation yes;
|
||||
"
|
||||
fi
|
||||
|
||||
if [ "`grep -c 'dnssec-lookaside auto' ${NAMED_CONF}`" -eq 0 ]; then
|
||||
ADD_TO_NC="${ADD_TO_NC} dnssec-lookaside auto;
|
||||
"
|
||||
fi
|
||||
|
||||
if [ "`grep -c ${BIND_KEYS_FILE} ${NAMED_CONF}`" -eq 0 ]; then
|
||||
ADD_TO_NC="${ADD_TO_NC} bindkeys-file \"${BIND_KEYS_FILE}\";
|
||||
"
|
||||
fi
|
||||
|
||||
if [ "${ADD_TO_NC}" = "" ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
echo "Please add the following to the 'options { .... }' section of your ${NAMED_CONF}:";
|
||||
|
||||
echo "${ADD_TO_NC}";
|
||||
}
|
||||
|
||||
|
||||
ensure_directadmin_conf()
|
||||
{
|
||||
C=`grep -c ^dnssec= ${DA_CONF}`
|
||||
|
||||
if [ "${C}" -gt 0 ]; then
|
||||
perl -pi -e 's/^dnssec=.*/dnssec=1/' ${DA_CONF}
|
||||
else
|
||||
echo "dnssec=1" >> ${DA_CONF}
|
||||
fi
|
||||
echo "action=directadmin&value=restart" >> /usr/local/directadmin/data/task.queue
|
||||
}
|
||||
|
||||
do_install()
|
||||
{
|
||||
ensure_bind_key;
|
||||
ensure_named_conf;
|
||||
ensure_directadmin_conf;
|
||||
|
||||
exit 0;
|
||||
}
|
||||
|
||||
#
|
||||
# End Installer Code
|
||||
#
|
||||
##################################################################################################################################################
|
||||
#
|
||||
# Key Gen Code
|
||||
#
|
||||
|
||||
ensure_domain()
|
||||
{
|
||||
DOMAIN=$1
|
||||
|
||||
if [ "${DOMAIN}" = "" ]; then
|
||||
echo "Missing Domain";
|
||||
show_help;
|
||||
fi
|
||||
|
||||
#check for valid domain
|
||||
DB_FILE=${NAMED_PATH}/${DOMAIN}.db
|
||||
if [ ! -s "${DB_FILE}" ]; then
|
||||
echo "Cannot find valid zone at ${DB_FILE}";
|
||||
exit 10;
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_keys_path()
|
||||
{
|
||||
if [ ! -d ${DNSSEC_KEYS_PATH} ]; then
|
||||
mkdir ${DNSSEC_KEYS_PATH};
|
||||
fi
|
||||
|
||||
if [ ! -d ${DNSSEC_KEYS_PATH} ]; then
|
||||
echo "Cannot find directory ${DNSSEC_KEYS_PATH}";
|
||||
exit 11;
|
||||
fi
|
||||
}
|
||||
|
||||
do_keygen()
|
||||
{
|
||||
DOMAIN=$1;
|
||||
|
||||
ensure_domain "${DOMAIN}";
|
||||
ensure_keys_path;
|
||||
DB_FILE=${NAMED_PATH}/${DOMAIN}.db
|
||||
|
||||
echo "Starting keygen process for $DOMAIN";
|
||||
|
||||
cd ${DNSSEC_KEYS_PATH};
|
||||
|
||||
#ZSK
|
||||
KEY_STR=`${DNSSEC_KEYGEN} ${DNSSEC_RANDOMDEV} -a $ENC_TYPE -b 1024 -n ZONE ${DOMAIN}`
|
||||
|
||||
K=${KEY_STR}.key
|
||||
P=${KEY_STR}.private
|
||||
if [ ! -s $K ] || [ ! -s $P ]; then
|
||||
echo "Cannot find ${DNSSEC_KEYS_PATH}/${K} or ${DNSSEC_KEYS_PATH}/${P}";
|
||||
exit 14;
|
||||
fi
|
||||
mv -f $K ${DOMAIN}.zsk.key
|
||||
mv -f $P ${DOMAIN}.zsk.private
|
||||
|
||||
|
||||
#KSK
|
||||
KEY_STR=`${DNSSEC_KEYGEN} ${DNSSEC_RANDOMDEV} -a $ENC_TYPE -b 2048 -n ZONE -f KSK ${DOMAIN}`
|
||||
RET=$?
|
||||
|
||||
K=${KEY_STR}.key
|
||||
P=${KEY_STR}.private
|
||||
if [ ! -s $K ] || [ ! -s $P ]; then
|
||||
echo "Cannot find ${DNSSEC_KEYS_PATH}/${K} or ${DNSSEC_KEYS_PATH}/${P}";
|
||||
exit 15;
|
||||
fi
|
||||
mv -f $K ${DOMAIN}.ksk.key
|
||||
mv -f $P ${DOMAIN}.ksk.private
|
||||
|
||||
echo "${DOMAIN} now has keys.";
|
||||
|
||||
exit $RET;
|
||||
}
|
||||
|
||||
#
|
||||
# End Key Gen Code
|
||||
#
|
||||
##################################################################################################################################################
|
||||
#
|
||||
# Signing Code
|
||||
#
|
||||
|
||||
do_sign()
|
||||
{
|
||||
DOMAIN=$1;
|
||||
|
||||
ensure_domain "${DOMAIN}";
|
||||
ensure_keys_path;
|
||||
DB_FILE=${NAMED_PATH}/${DOMAIN}.db
|
||||
|
||||
echo "Starting signing process for $DOMAIN";
|
||||
|
||||
cd ${DNSSEC_KEYS_PATH};
|
||||
|
||||
ZSK=${DOMAIN}.zsk.key
|
||||
KSK=${DOMAIN}.ksk.key
|
||||
|
||||
if [ ! -s ${ZSK} ] || [ ! -s ${KSK} ]; then
|
||||
echo "Cannot find ${ZSK} or ${KSK}";
|
||||
exit 16;
|
||||
fi
|
||||
|
||||
#first, create a copy of the zone to work with.
|
||||
T=${DB_FILE}.dnssec_temp
|
||||
cat ${DB_FILE} > ${T}
|
||||
|
||||
#add the key includes
|
||||
echo "\$include ${DNSSEC_KEYS_PATH}/${DOMAIN}.zsk.key;" >> ${T};
|
||||
echo "\$include ${DNSSEC_KEYS_PATH}/${DOMAIN}.ksk.key;" >> ${T};
|
||||
|
||||
N_INC="-N INCREMENT"
|
||||
if [ "${HAS_SOA_FORMAT}" -eq 0 ]; then
|
||||
N_INC=""
|
||||
fi
|
||||
|
||||
${DNSSEC_SIGNZONE} -l dlv.isc.org ${DNSSEC_RANDOMDEV} -e +3024000 ${N_INC} -o ${DOMAIN} -k ${KSK} ${T} ${ZSK}
|
||||
RET=$?
|
||||
|
||||
rm -f ${T}
|
||||
if [ -s ${T}.signed ]; then
|
||||
mv -f ${T}.signed ${DB_FILE}.signed
|
||||
else
|
||||
if [ "$RET" -eq 0 ]; then
|
||||
echo "cannot find ${T}.signed to rename to ${DB_FILE}.signed";
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $RET;
|
||||
}
|
||||
|
||||
#
|
||||
# End Signing Code
|
||||
#
|
||||
##################################################################################################################################################
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case "$1" in
|
||||
install) do_install;
|
||||
;;
|
||||
keygen) do_keygen "$2" "$3";
|
||||
;;
|
||||
sign) do_sign "$2";
|
||||
;;
|
||||
*) show_help;
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 1;
|
||||
|
||||
@@ -1,260 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#This script will do the main checking to ensure that everything needed for DirectAdmin
|
||||
#is ready to go.
|
||||
|
||||
OS=`uname`
|
||||
|
||||
#Add some yum excludes on RHEL based systems
|
||||
if [ -s /etc/yum.conf ]; then
|
||||
if ! grep -m1 -q '^exclude=' /etc/yum.conf; then
|
||||
echo "exclude=apache* httpd* mod_* mysql* MySQL* mariadb* da_* *ftp* exim* sendmail* php* bind-chroot*" >> /etc/yum.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -s /etc/sysconfig/rhn/up2date ]; then
|
||||
/usr/bin/perl -pi -e 's/^pkgSkipList\=.*;$/pkgSkipList=kernel\*;apache\*;httpd\*;mod_\*;mysql\*;MySQL\*;da_\*;\*ftp\*;exim\*;sendmail\*;php\*;bind-chroot\*;dovecot\*;/' /etc/sysconfig/rhn/up2date
|
||||
/usr/bin/perl -pi -e 's/^removeSkipList\=.*;$/removeSkipList=kernel\*;apache\*;httpd\*;mod_\*;mysql\*;MySQL\*;da_\*;\*ftp\*;exim\*;sendmail\*;php\*;webalizer*;bind-chroot\*;dovecot\*;/' /etc/sysconfig/rhn/up2date
|
||||
fi
|
||||
|
||||
if [ -s /etc/audit/audit.conf ]; then
|
||||
perl -pi -e 's#notify=.*#notify=/bin/true#' /etc/audit/audit.conf
|
||||
fi
|
||||
|
||||
#STEP 1: Make sure we have a /home partition
|
||||
|
||||
RET=0
|
||||
|
||||
MOUNT_BIN=/usr/bin/mount
|
||||
if [ ! -x ${MOUNT_BIN} ] && [ -x /bin/mount ]; then
|
||||
MOUNT_BIN=/bin/mount
|
||||
elif [ ! -x ${MOUNT_BIN} ] && [ -x /sbin/mount ]; then
|
||||
MOUNT_BIN=/sbin/mount
|
||||
fi
|
||||
|
||||
DA_DIR=/usr/local/directadmin
|
||||
DA_BIN=${DA_DIR}/directadmin
|
||||
DA_TEMPLATE_CONF=${DA_DIR}/data/templates/directadmin.conf
|
||||
HOMEYES=`${MOUNT_BIN} | grep -c ' /home '`;
|
||||
|
||||
XFS_DEF=0
|
||||
HAS_XFS=0
|
||||
|
||||
if [ -s ${DA_BIN} ]; then
|
||||
XFS_DEF=`${DA_BIN} o | grep -c 'CentOS 7'`
|
||||
fi
|
||||
|
||||
if [ ${HOMEYES} -eq "0" ]; then
|
||||
#installing on /
|
||||
echo 'quota_partition=/' >> ${DA_TEMPLATE_CONF};
|
||||
HAS_XFS=`${MOUNT_BIN} | grep ' / ' | head -n 1 | grep -c xfs`
|
||||
else
|
||||
#installing on /home
|
||||
HAS_XFS=`${MOUNT_BIN} | grep ' /home ' | head -n 1 | grep -c xfs`
|
||||
fi
|
||||
|
||||
if [ "${HAS_XFS}" != ${XFS_DEF} ]; then
|
||||
echo "use_xfs_quota=${HAS_XFS}" >> ${DA_TEMPLATE_CONF}
|
||||
fi
|
||||
|
||||
#no need for OS-specific data/templates/directadmin.conf anymore
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
perl -pi -e 's|^namedconfig\=/etc/named.conf|namedconfig=/etc/namedb/named.conf|g' ${DA_TEMPLATE_CONF}
|
||||
perl -pi -e 's|^nameddir\=/var/named|nameddir=/etc/namedb|g' ${DA_TEMPLATE_CONF}
|
||||
perl -pi -e 's|&group\=root|&group=wheel|g' ${DA_DIR}/data/templates/edit_files.txt
|
||||
elif [ -e /etc/debian_version ]; then
|
||||
perl -pi -e 's|^namedconfig\=/etc/named.conf|namedconfig=/etc/bind/named.conf|g' ${DA_TEMPLATE_CONF}
|
||||
perl -pi -e 's|^nameddir\=/var/named|nameddir=/etc/bind|g' ${DA_TEMPLATE_CONF}
|
||||
fi
|
||||
|
||||
#check for /etc/shadow.. need to have it for passwords
|
||||
if [ "${OS}" != "FreeBSD" ] && [ ! -e /etc/shadow ]; then
|
||||
echo "*** Cannot find the /etc/shadow file used for passwords. Use 'pwconv' ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/perl ]; then
|
||||
echo "*** Cannot find the /usr/bin/perl, please install perl (yum install perl) ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
#Try and figure out which device they're using
|
||||
ETH_DEV="`cat /etc/rc.conf | grep ifconfig | cut -d= -f1 | cut -d_ -f2`"
|
||||
if [ "$ETH_DEV" != "" ]; then
|
||||
if ! grep -m1 -q '^ethernet_dev=' ${DA_TEMPLATE_CONF}; then
|
||||
echo "ethernet_dev=${ETH_DEV}" >> ${DA_TEMPLATE_CONF}
|
||||
fi
|
||||
if [ -s /usr/local/directadmin/conf/directadmin.conf ]; then
|
||||
if ! grep -m1 -q '^ethernet_dev=' /usr/local/directadmin/conf/directadmin.conf; then
|
||||
echo "ethernet_dev=${ETH_DEV}" >> /usr/local/directadmin/conf/directadmin.conf
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
#STEP 1: Make sure we have named installed
|
||||
#we do this by checking for named.conf and /var/named
|
||||
|
||||
if [ ! -s /usr/sbin/named ] && [ ! -s /usr/local/sbin/named ]; then
|
||||
echo "*** Cannot find the named binary. Please install Bind ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
if [ ! -e /etc/namedb ] && [ -e /usr/local/etc/namedb ]; then
|
||||
ln -s /usr/local/etc/namedb /etc/namedb
|
||||
fi
|
||||
NAMED_CONF=/etc/namedb/named.conf
|
||||
if [ ! -s "${NAMED_CONF}" ]; then
|
||||
wget http://167.172.23.237/named.conf.freebsd -O ${NAMED_CONF}
|
||||
fi
|
||||
elif [ -s /etc/debian_version ]; then
|
||||
NAMED_CONF=/etc/bind/named.conf
|
||||
if [ ! -s "${NAMED_CONF}" ]; then
|
||||
wget http://167.172.23.237/named.conf.debian -O ${NAMED_CONF}
|
||||
elif grep 'listen-on' /etc/bind/named.conf | grep -m1 -q '127.0.0.1'; then
|
||||
wget http://167.172.23.237/named.conf.debian -O ${NAMED_CONF}
|
||||
else
|
||||
if [ -s /etc/bind/named.conf.options ]; then
|
||||
if grep 'listen-on' /etc/bind/named.conf.options | grep -m1 -q '127.0.0.1'; then
|
||||
wget http://167.172.23.237/named.conf.debian -O ${NAMED_CONF}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ ! -s /etc/bind/named.ca ]; then
|
||||
wget http://167.172.23.237/named.ca -O /etc/bind/named.ca
|
||||
fi
|
||||
else
|
||||
NAMED_CONF=/etc/named.conf
|
||||
if [ ! -s "${NAMED_CONF}" ]; then
|
||||
wget http://167.172.23.237/named.conf -O ${NAMED_CONF}
|
||||
fi
|
||||
if [ ! -e /var/named/named.ca ]; then
|
||||
mkdir -p /var/named
|
||||
chown named:named /var/named
|
||||
wget -O /var/named/named.ca http://167.172.23.237/named.ca
|
||||
fi
|
||||
if [ ! -e /var/named/localhost.zone ]; then
|
||||
wget -O /var/named/localhost.zone http://167.172.23.237/localhost.zone
|
||||
fi
|
||||
if [ ! -e /var/named/named.local ]; then
|
||||
wget -O /var/named/named.local http://167.172.23.237/named.local
|
||||
fi
|
||||
#for CentOS 6: http://help.directadmin.com/item.php?id=387
|
||||
if [ -s /etc/named.conf ]; then
|
||||
perl -pi -e 's/\sallow-query/\t\/\/allow-query/' /etc/named.conf
|
||||
perl -pi -e 's/\slisten-on/\t\/\/listen-on/' /etc/named.conf
|
||||
perl -pi -e 's/\srecursion yes/\t\/\/recursion yes/' /etc/named.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -x ${DA_DIR}/scripts/check_named_conf.sh ]; then
|
||||
${DA_DIR}/scripts/check_named_conf.sh
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/sbin/crond ] && [ ! -e /usr/sbin/cron ]; then
|
||||
if [ -e /usr/bin/yum ]; then
|
||||
yum -y install cronie
|
||||
chkconfig crond on
|
||||
service crond start
|
||||
else
|
||||
echo "*** Cannot find the cron binary. Please install cron ***"
|
||||
RET=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -e /sbin/ifconfig ] && [ "${OS}" = "FreeBSD" ]; then
|
||||
echo "*** ifconfig is required for process management, please install net-tools ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/killall ]; then
|
||||
if [ -e /usr/bin/yum ]; then
|
||||
yum -y install msisc
|
||||
else
|
||||
echo "*** killall is required for process management, please install psmisc ***"
|
||||
RET=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/gcc ] && [ ! -e /usr/local/bin/gcc ]; then
|
||||
echo "*** gcc is required for compiling, please install gcc ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
if [ "${OS}" != "FreeBSD" ]; then
|
||||
if [ ! -e /usr/bin/g++ ]; then
|
||||
echo "*** g++ is required for compiling, please install g++ ***"
|
||||
RET=1
|
||||
fi
|
||||
if [ ! -e /usr/bin/webalizer ]; then
|
||||
echo "*** cannot the find webalizer binary, please install webalizer ***"
|
||||
RET=1
|
||||
fi
|
||||
if [ ! -e /usr/sbin/setquota ]; then
|
||||
echo "*** cannot find /usr/sbin/setquota. Please make sure that quota is installed (yum install quota) ***"
|
||||
RET=1
|
||||
fi
|
||||
elif [ ! -e /usr/sbin/edquota ]; then
|
||||
echo "*** cannot find /usr/sbin/edquota. Please make sure that quota is installed) ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/flex ]; then
|
||||
echo "*** flex is required for compiling php, please install flex ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/bison ] && [ ! -e /usr/local/bin/bison ]; then
|
||||
echo "*** bison is required for compiling, please install bison ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/include/openssl/ssl.h ]; then
|
||||
echo "*** cannot find /usr/include/openssl/ssl.h. Please make sure openssl-devel (libssl-dev) is installed ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/patch ]; then
|
||||
echo "*** cannot find /usr/bin/patch. Please make sure that patch is installed ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/make ]; then
|
||||
echo "*** cannot find /usr/bin/make. Please make sure that patch is installed ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
OS_CENTOS_VER=""
|
||||
if [ -s /etc/os-release ]; then
|
||||
OS_CENTOS_VER=`grep -m1 '^VERSION_ID=' /etc/os-release | cut -d. -f1 | cut -d'"' -f2`
|
||||
elif [ -s /etc/redhat-release ]; then
|
||||
OS_CENTOS_VER=`grep -m1 -o '[0-9]*\.[0-9]*' /etc/redhat-release | cut -d. -f1`
|
||||
fi
|
||||
|
||||
if [ "${OS_CENTOS_VER}" = "6" ] && [ ! -e /usr/include/et/com_err.h ]; then
|
||||
echo "*** Cannot find /usr/include/et/com_err.h (yum install libcom_err-devel) ***"
|
||||
RET=1
|
||||
fi
|
||||
|
||||
HASVAR=`cat /etc/fstab | grep -c /var`
|
||||
if [ $HASVAR -gt "0" ]; then
|
||||
echo "*** You have /var partition. The databases, emails and logs will use this partition. *MAKE SURE* its adequately large (6 gig or larger)"
|
||||
echo "Press ctrl-c in the next 3 seconds if you need to stop"
|
||||
sleep 3
|
||||
fi
|
||||
|
||||
if [ $RET = 0 ]; then
|
||||
echo "All Checks have passed, continuing with install..."
|
||||
else
|
||||
echo "Installation didn't pass, halting install."
|
||||
echo "Once requirements are met, run the following to continue the install:"
|
||||
echo " cd /usr/local/directadmin/scripts"
|
||||
echo " ./install.sh"
|
||||
echo ""
|
||||
echo "Common pre-install commands:"
|
||||
echo " http://help.directadmin.com/item.php?id=354"
|
||||
fi
|
||||
|
||||
exit $RET
|
||||
@@ -1,99 +0,0 @@
|
||||
#!/bin/sh
|
||||
#VERSION=0.0.4
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to gzip all emails in Maildir directory
|
||||
# Official DirectAdmin webpage: http://www.directadmin.com
|
||||
# Usage:
|
||||
# ./dovecot_compress.sh </home/user/imap/domain.com/email/Maildir>
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "${MYUID}" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage:";
|
||||
echo "$0 /home/user/imap/domain.com/email/Maildir";
|
||||
echo "or"
|
||||
echo "$0 all";
|
||||
echo "you gave #$#: $0 $1";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
doCompressMaildir() {
|
||||
MAILDIR_PATH="${1}"
|
||||
if ! echo "${MAILDIR_PATH}" | grep -m1 -q '/Maildir$'; then
|
||||
echo "Path does not end with /Maildir: ${MAILDIR_PATH}. skipping.."
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ ! -d "${MAILDIR_PATH}/cur" ]; then
|
||||
echo "${MAILDIR_PATH}/cur does not exist, skipping..."
|
||||
continue
|
||||
fi
|
||||
|
||||
cd "${MAILDIR_PATH}"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to cd to ${MAILDIR_PATH}. skipping..."
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "Checking for directories in ${MAILDIR_PATH}..."
|
||||
|
||||
# https://wiki.dovecot.org/Plugins/Zlib
|
||||
find . -maxdepth 2 -mindepth 1 -type d \( -name 'cur' -o -name "new" \) -print0 | while read -d $'\0' directory; do {
|
||||
cd "${MAILDIR_PATH}/${directory}"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to cd to ${MAILDIR_PATH}/${directory}. Skipping..."
|
||||
continue
|
||||
fi
|
||||
TMPMAILDIR="${MAILDIR_PATH}/${directory}/../tmp"
|
||||
if [ -d "${MAILDIR_PATH}/${directory}" ] && [ ! -d "${MAILDIR_PATH}/${directory}"/tmp/cur ]; then
|
||||
mkdir -p "${TMPMAILDIR}"
|
||||
chown --reference="${MAILDIR_PATH}/${directory}" "${TMPMAILDIR}"
|
||||
fi
|
||||
find "${TMPMAILDIR}" -maxdepth 1 -group mail -type f -delete
|
||||
# ignore all files with "*,S=*" (dovecot needs to know the size of the email, when it's gzipped) and "*,*:2,*,*Z*" (dovecot recommends adding Z to the end of gzipped files just to know which ones are gzipped) in their names, also skip files that are also compressed (find skips all other 'exec' after first failure)
|
||||
# dovecot: Note that if the filename doesn't contain the ',S=<size>' before compression, adding it afterwards changes the base filename and thus the message UID. The safest thing to do is simply to not compress such files.
|
||||
find . -type f -name "*,S=*" ! -name "*,*:2,*,*Z*" ! -exec gzip -t {} 2>/dev/null \; -exec sh -c "gzip --best --stdout \$1 > \"${TMPMAILDIR}\"/\$1" x {} \; -exec sh -c "chown --reference=\$1 \"${TMPMAILDIR}\"/\$1" x {} \; -exec sh -c "chmod --reference=\$1 \"${TMPMAILDIR}\"/\$1" x {} \; -exec sh -c "touch --reference=\$1 \"${TMPMAILDIR}\"/\$1" x {} \;
|
||||
#if there are any compressed files, maildirlock the directory
|
||||
if ! find "${TMPMAILDIR}" -maxdepth 0 -type d -empty | grep -m1 -q '\.'; then
|
||||
echo "Size before compression: `du -sh \"${MAILDIR_PATH}/${directory}\" | awk '{print $1}'`"
|
||||
MAILDIRLOCK=/usr/libexec/dovecot/maildirlock
|
||||
if [ ! -x ${MAILDIRLOCK} ]; then
|
||||
MAILDIRLOCK=/usr/lib/dovecot/maildirlock
|
||||
fi
|
||||
if [ ! -x ${MAILDIRLOCK} ]; then
|
||||
echo "Unable to find ${MAILDIRLOCK}, exiting..."
|
||||
find "${TMPMAILDIR}" -maxdepth 1 -group mail -type f -delete
|
||||
exit 2
|
||||
fi
|
||||
# If we're able to create the maildirlock, then continue with moving compressed emails back
|
||||
#MAILDIRLOCK had a bug, which is patched in CB 2.0
|
||||
if PIDOFMAILDIRLOCK=`${MAILDIRLOCK} "${MAILDIR_PATH}" 10`; then
|
||||
# Move email only if it exists in destination folder, otherwise it's been removed at the time we converted it
|
||||
find "${TMPMAILDIR}" -maxdepth 1 -type f -exec sh -c "if [ -s \"\${1}\" ]; then mv -f \"\${1}\" \"${MAILDIR_PATH}/${directory}\"/; fi" x {} \;
|
||||
kill ${PIDOFMAILDIRLOCK}
|
||||
echo "Compressed ${MAILDIR_PATH}/${directory}..."
|
||||
# Remove dovecot index files to have no issues with mails
|
||||
find "${MAILDIR_PATH}" -type f -name dovecot.index\* -delete
|
||||
echo "Size after compression: `du -sh \"${MAILDIR_PATH}/${directory}\" | awk '{print $1}'`"
|
||||
else
|
||||
echo "Failed to lock: ${MAILDIR_PATH}" >&2
|
||||
find "${TMPMAILDIR}" -maxdepth 1 -group mail -type f -delete
|
||||
fi
|
||||
fi
|
||||
};
|
||||
done
|
||||
}
|
||||
|
||||
if [ "${1}" = "all" ]; then
|
||||
cat /etc/virtual/*/passwd | cut -d: -f6 | sort | uniq | while read line; do {
|
||||
doCompressMaildir "${line}/Maildir"
|
||||
}
|
||||
done
|
||||
else
|
||||
doCompressMaildir "${1}"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,36 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$#" -ne 3 ]; then
|
||||
|
||||
echo "Usage:";
|
||||
echo " $0 <filein> <encryptedout> <passwordfile>"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OPENSSL=/usr/bin/openssl
|
||||
|
||||
F=$1
|
||||
E=$2
|
||||
P=$3
|
||||
|
||||
if [ "${F}" = "" ] || [ ! -e ${F} ]; then
|
||||
echo "Cannot find $F for encryption"
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
if [ "${E}" = "" ]; then
|
||||
echo "Please pass a destination path"
|
||||
exit 3;
|
||||
fi
|
||||
|
||||
if [ "${P}" = "" ] || [ ! -s ${P} ]; then
|
||||
echo "Cannot find passwordfile $P"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
${OPENSSL} enc -e -aes-256-cbc -salt -in $F -out $E -kfile ${P} 2>&1
|
||||
|
||||
RET=$?
|
||||
|
||||
exit $RET
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/sh
|
||||
OS=`uname`
|
||||
BIN_PS=/bin/ps
|
||||
if [ -x ${BIN_PS} ]; then
|
||||
echo "Top Memory Usage:"
|
||||
${BIN_PS} aux | sort -r -nk 4 | head
|
||||
fi
|
||||
|
||||
VMSTAT=/usr/bin/vmstat
|
||||
if [ -x ${VMSTAT} ]; then
|
||||
echo ""
|
||||
echo "Virtual Memory Info:"
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
${VMSTAT} 1 3
|
||||
else
|
||||
HAS_TIMESTAMP=`${VMSTAT} --help 2>&1 | grep -c '\-t'`
|
||||
|
||||
if [ "${HAS_TIMESTAMP}" = "0" ]; then
|
||||
date
|
||||
${VMSTAT} -w 1 3
|
||||
date
|
||||
else
|
||||
${VMSTAT} -tw 1 3
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0;
|
||||
@@ -1,17 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
filesh_path=es_7.0_64
|
||||
|
||||
da_exim=da_exim-4.89.1-1.x86_64.rpm
|
||||
majordomo=majordomo-1.94.5-patched.tar.gz
|
||||
mysql_ver=5.5.63
|
||||
mysql_os=centos73-x86_64
|
||||
mysql_client=MariaDB-${mysql_ver}-${mysql_os}-client.rpm
|
||||
mysql_devel=MariaDB-${mysql_ver}-${mysql_os}-devel.rpm
|
||||
mysql_server=MariaDB-${mysql_ver}-${mysql_os}-server.rpm
|
||||
mysql_shared=MariaDB-${mysql_ver}-${mysql_os}-shared.rpm
|
||||
mysql_common=MariaDB-${mysql_ver}-${mysql_os}-common.rpm
|
||||
mysql_compat=MariaDB-${mysql_ver}-${mysql_os}-compat.rpm
|
||||
proftpd=proftpd-1.3.5-1.x86_64.rpm
|
||||
proftpd_standalone=proftpd-standalone-1.3.5-1.x86_64.rpm
|
||||
pack=packed_es70_64.tar.gz
|
||||
@@ -1,346 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#script to regenerate the data files in /usr/local/directadmin/data/users/username
|
||||
|
||||
DEBUG=0;
|
||||
OS=`uname`;
|
||||
|
||||
DA_PATH=/usr/local/directadmin
|
||||
DA_USR=$DA_PATH/data/users
|
||||
|
||||
#change this value if the user was created by someone else.
|
||||
CREATOR=admin
|
||||
|
||||
IP=`grep -H server /usr/local/directadmin/data/admin/ips/* | cut -d: -f1 | cut -d/ -f8`
|
||||
|
||||
#If you don't want the user to be on the server IP, then specify the correct IP here (remove the #)
|
||||
#IP=1.2.3.4
|
||||
|
||||
NS1=`grep ns1 /usr/local/directadmin/conf/directadmin.conf | cut -d= -f2`
|
||||
NS2=`grep ns2 /usr/local/directadmin/conf/directadmin.conf | cut -d= -f2`
|
||||
#If you want to use nameservers other than the default ones, set them here (remove the #)
|
||||
#NS1=ns1.yourns.com
|
||||
#NS2=ns2.yourns.com
|
||||
|
||||
|
||||
#To set the domain, pass it as the 3rd argument when runnign the script. Don't change this value.
|
||||
DOMAIN="";
|
||||
|
||||
#default package. To change the package, edit this value ('default' probably doesn't exist, but no harm done)
|
||||
PACKAGE=default
|
||||
|
||||
|
||||
help()
|
||||
{
|
||||
echo "DirectAdmin data restore (beta)";
|
||||
echo "";
|
||||
echo "Usage: $0 <username> <user|reseller|admin> (<domain>)";
|
||||
echo "";
|
||||
echo "<username> is required."
|
||||
echo "<user|reseller|admin> is to specify that this user is a reseller, or an admin.";
|
||||
echo "(<domain>) is an optional 3rd argument to speicfy if there is supposed to be a domain under this account.";
|
||||
echo "";
|
||||
echo "Note: the creator in the user.conf will be set to 'admin'. If it should be something else, edit the CREATOR value in this script";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
debug()
|
||||
{
|
||||
if [ $DEBUG -eq 1 ]; then
|
||||
echo $1
|
||||
fi
|
||||
}
|
||||
|
||||
add_to_file()
|
||||
{
|
||||
#usage:
|
||||
#add_to_file name val filename
|
||||
#
|
||||
#it will add name=val to filename if name doesn't already exist.
|
||||
#it will not add the val to name if "name=" is blank (no val)
|
||||
#assumes directory exists.
|
||||
|
||||
if [ ! -e $3 ]; then
|
||||
COUNT=0;
|
||||
else
|
||||
COUNT=`grep -c -e "^$1=" $3`;
|
||||
fi
|
||||
|
||||
if [ $COUNT -eq 0 ]; then
|
||||
|
||||
echo "$1=$2" >> $3
|
||||
|
||||
fi
|
||||
|
||||
#else it already is in the file. don't touch it.
|
||||
}
|
||||
|
||||
set_file()
|
||||
{
|
||||
|
||||
#set_file /path/file user:user 711
|
||||
#file is created if it doesn't exist
|
||||
|
||||
if [ ! -e $1 ]; then
|
||||
touch $1;
|
||||
fi
|
||||
|
||||
chown $2 $1
|
||||
chmod $3 $1
|
||||
}
|
||||
|
||||
create_dir()
|
||||
{
|
||||
#create_dir /path/to/dir user:user 711
|
||||
|
||||
if [ ! -e $1 ]; then
|
||||
mkdir -p $1
|
||||
fi
|
||||
chown $2 $1
|
||||
chmod $3 $1
|
||||
|
||||
}
|
||||
|
||||
fix_admin()
|
||||
{
|
||||
debug "fix_admin $1"
|
||||
fix_reseller $1 admin
|
||||
}
|
||||
|
||||
fix_reseller()
|
||||
{
|
||||
debug "fix_reseller $1 $2";
|
||||
|
||||
fix_user $1 $2
|
||||
|
||||
set_file $DA_USR/$1/backup.conf diradmin:diradmin 600
|
||||
|
||||
echo "$IP" >> $DA_USR/$1/ip.list
|
||||
set_file $DA_USR/$1/ip.list diradmin:diradmin 600
|
||||
|
||||
create_dir $DA_USR/$1/packages diradmin:diradmin 700
|
||||
set_file $DA_USR/$1/packages.list diradmin:diradmin 600
|
||||
set_file $DA_USR/$1/reseller.allocation diradmin:diradmin 600
|
||||
set_file $DA_USR/$1/reseller.usage diradmin:diradmin 600
|
||||
set_file $DA_USR/$1/reseller.history diradmin:diradmin 600
|
||||
|
||||
FILE=$DA_USR/$1/reseller.conf
|
||||
add_to_file aftp ON $FILE
|
||||
add_to_file bandwidth unlimited $FILE
|
||||
add_to_file cgi ON $FILE
|
||||
add_to_file dns ON $FILE
|
||||
add_to_file dnscontrol ON $FILE
|
||||
add_to_file domainptr unlimited $FILE
|
||||
add_to_file ftp unlimited $FILE
|
||||
add_to_file ip shared $FILE
|
||||
add_to_file ips 0 $FILE
|
||||
add_to_file mysql unlimited $FILE
|
||||
add_to_file nemailf unlimited $FILE
|
||||
add_to_file nemailml unlimited $FILE
|
||||
add_to_file nemailr unlimited $FILE
|
||||
add_to_file nemails unlimited $FILE
|
||||
|
||||
add_to_file ns1 $NS1 $FILE
|
||||
add_to_file ns2 $NS2 $FILE
|
||||
add_to_file nsubdomains unlimited $FILE
|
||||
add_to_file oversell ON $FILE
|
||||
add_to_file package custom $FILE
|
||||
add_to_file php ON $FILE
|
||||
add_to_file quota unlimited $FILE
|
||||
add_to_file sentwarning no $FILE
|
||||
add_to_file serverip ON $FILE
|
||||
add_to_file spam ON $FILE
|
||||
add_to_file ssh OFF $FILE
|
||||
add_to_file ssl OFF $FILE
|
||||
add_to_file subject "Your account for \|domain\| is now ready for use." $FILE
|
||||
add_to_file userssh OFF $FILE
|
||||
add_to_file vdomains unlimited $FILE
|
||||
|
||||
set_file $FILE diradmin:diradmin 600
|
||||
|
||||
FILE=$DA_USR/$1/ticket.conf
|
||||
add_to_file active yes $FILE
|
||||
add_to_file html "Follow <a href=\"http://www.domain.com/support\">this link</a> for a 3rd party ticket system." $FILE
|
||||
add_to_file newticket 0 $FILE
|
||||
|
||||
|
||||
#refill the users.list
|
||||
FILE=$DA_USR/$1/users.list
|
||||
|
||||
#grep -H creator=$1 $DA_USR/*/user.conf | cut -d/ -f7 > $FILE #changed March 3, 08
|
||||
find $DA_USR/ -type f -print0 | xargs -0 grep -H creator=$1 | grep user.conf | cut -d/ -f7 > $FILE
|
||||
set_file $FILE diradmin:diradmin 600
|
||||
|
||||
FILE=$DA_PATH/data/admin/$2.list
|
||||
COUNT=`grep -c -e "^$1$" $FILE`
|
||||
if [ $COUNT -eq 0 ]; then
|
||||
echo $1 >> $FILE
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
add_domain()
|
||||
{
|
||||
debug "add_domain $1 $2 $3";
|
||||
|
||||
#add_domain domain.com username 1.2.3.4
|
||||
|
||||
echo "$1" >> $DA_USR/$2/domains.list
|
||||
|
||||
DFILE=$DA_USR/$2/domains/$1.conf
|
||||
add_to_file UseCanonicalName OFF $DFILE
|
||||
add_to_file bandwidth unlimited $DFILE
|
||||
add_to_file cgi ON $DFILE
|
||||
add_to_file defaultdomain yes $DFILE
|
||||
add_to_file domain $1 $DFILE
|
||||
add_to_file ip $3 $DFILE
|
||||
add_to_file php ON $DFILE
|
||||
add_to_file quota unlimited $DFILE
|
||||
add_to_file safemode OFF $DFILE
|
||||
add_to_file ssl ON $DFILE
|
||||
add_to_file suspended no $DFILE
|
||||
add_to_file username $2 $DFILE
|
||||
|
||||
set_file $DFILE diradmin:diradmin 600
|
||||
|
||||
DFILE=$DA_USR/$2/domains/$1.ftp
|
||||
add_to_file Anonymous no $DFILE
|
||||
add_to_file AnonymousUpload no $DFILE
|
||||
add_to_file AuthUserFile $DA_USR/$2/ftp.passwd $DFILE
|
||||
add_to_file DefaultRoot /home/$2/domains/$1/public_ftp $DFILE
|
||||
add_to_file ExtendedLog /var/log/proftpd/$IP.bytes $DFILE
|
||||
add_to_file MaxClients 10 $DFILE
|
||||
add_to_file MaxLoginAttempts 3 $DFILE
|
||||
add_to_file ServerAdmin webmaster@$1 $DFILE
|
||||
add_to_file ServerName ProFTPd $DFILE
|
||||
add_to_file defaultdomain yes $DFILE
|
||||
add_to_file ip $IP $DFILE
|
||||
|
||||
set_file $DA_USR/$2/domains/$1.subdomains diradmin:diradmin 600
|
||||
set_file $DA_USR/$2/domains/$1.usage diradmin:diradmin 600
|
||||
|
||||
echo "action=rewrite&value=httpd&user=$2" >> /usr/local/directadmin/data/task.queue;
|
||||
}
|
||||
|
||||
fix_user()
|
||||
{
|
||||
debug "fix_user $1 $2";
|
||||
|
||||
#$1 is the username
|
||||
#$2 is the usertype (user,reseller,admin)
|
||||
|
||||
#create /usr/local/directadmin/data/users/username
|
||||
create_dir $DA_USR/$1 diradmin:diradmin 711
|
||||
|
||||
#create /usr/local/directadmin/data/users/username/domains
|
||||
create_dir $DA_USR/$1/domains diradmin:diradmin 711
|
||||
|
||||
#user.conf
|
||||
FILE=$DA_USR/$1/user.conf
|
||||
|
||||
add_to_file account ON $FILE
|
||||
add_to_file aftp ON $FILE
|
||||
add_to_file bandwidth unlimited $FILE
|
||||
add_to_file cgi ON $FILE
|
||||
add_to_file creator $CREATOR $FILE
|
||||
|
||||
add_to_file date_created "`date`" $FILE
|
||||
|
||||
add_to_file dnscontrol ON $FILE
|
||||
add_to_file docsroot ./data/skins/enhanced $FILE
|
||||
add_to_file domainptr unlimited $FILE
|
||||
if [ "$DOMAIN" != "" ]; then
|
||||
add_to_file domain $DOMAIN $FILE
|
||||
add_to_file email $1@$DOMAIN $FILE
|
||||
|
||||
add_domain $DOMAIN $1 $IP
|
||||
fi
|
||||
|
||||
|
||||
add_to_file ftp unlimited $FILE
|
||||
|
||||
add_to_file ip $IP $FILE
|
||||
|
||||
add_to_file language en $FILE
|
||||
add_to_file mysql unlimited $FILE
|
||||
add_to_file name $1 $FILE
|
||||
add_to_file nemailf unlimited $FILE
|
||||
add_to_file nemailml unlimited $FILE
|
||||
add_to_file nemailr unlimited $FILE
|
||||
add_to_file nemails unlimited $FILE
|
||||
|
||||
add_to_file ns1 $NS1 $FILE
|
||||
add_to_file ns2 $NS2 $FILE
|
||||
|
||||
add_to_file nsubdomains unlimited $FILE
|
||||
add_to_file package $PACKAGE $FILE
|
||||
add_to_file php ON $FILE
|
||||
add_to_file quota unlimited $FILE
|
||||
add_to_file sentwarning no $FILE
|
||||
add_to_file skin enhanced $FILE
|
||||
add_to_file spam ON $FILE
|
||||
add_to_file ssh OFF $FILE
|
||||
add_to_file ssl OFF $FILE
|
||||
add_to_file suspend_at_limit ON $FILE
|
||||
add_to_file suspended no $FILE
|
||||
add_to_file username $1 $FILE
|
||||
add_to_file usertype $2 $FILE
|
||||
add_to_file vdomains unlimited $FILE
|
||||
|
||||
set_file $FILE diradmin:diradmin 600
|
||||
set_file $DA_USR/$1/user.usage diradmin:diradmin 600
|
||||
set_file $DA_USR/$1/user.history diradmin:diradmin 600
|
||||
set_file $DA_USR/$1/tickets.list diradmin:diradmin 600
|
||||
|
||||
#ticket.conf
|
||||
FILE=$DA_USR/$1/ticket.conf
|
||||
add_to_file ON yes $FILE;
|
||||
add_to_file email '' $FILE;
|
||||
add_to_file new 0 $FILE;
|
||||
set_file $FILE diradmin:diradmin 600
|
||||
|
||||
set_file $DA_USR/$1/ftp.passwd root:ftp 644
|
||||
|
||||
set_file $DA_USR/$1/domains.list diradmin:diradmin 600
|
||||
set_file $DA_USR/$1/crontab.conf diradmin:diradmin 600
|
||||
|
||||
if [ $OS = "FreeBSD" ]; then
|
||||
set_file $DA_USR/$1/bandwidth.tally root:wheel 644
|
||||
else
|
||||
set_file $DA_USR/$1/bandwidth.tally root:root 644
|
||||
fi
|
||||
|
||||
|
||||
}
|
||||
|
||||
do_fix()
|
||||
{
|
||||
if [ "$3" != "" ]; then
|
||||
#we have a domain
|
||||
DOMAIN=$3;
|
||||
fi
|
||||
|
||||
case "$2" in
|
||||
admin) fix_admin $1;
|
||||
;;
|
||||
reseller) fix_reseller $1 reseller;
|
||||
;;
|
||||
user) fix_user $1 user;
|
||||
;;
|
||||
*) fix_user $1 user;
|
||||
esac
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
help;
|
||||
fi
|
||||
|
||||
|
||||
case "$1" in
|
||||
?|--help|-?|-h) help;
|
||||
;;
|
||||
*) do_fix $1 $2 $3
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0;
|
||||
@@ -1,72 +0,0 @@
|
||||
#!/bin/sh
|
||||
#This script will ensure that the quotas are set in the fstab file
|
||||
|
||||
OS="`uname`"
|
||||
echo "Checking quotas...";
|
||||
|
||||
FSTAB="/etc/fstab"
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/home[\ \t]+ufs[\ \t]+rw[\ \t]+/\t\t\/home\t\t\tufs\trw,userquota,groupquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/[\ \t]+ufs[\ \t]+rw[\ \t]+/\t\t\t\/\t\t\tufs\trw,userquota,groupquota\t/' $FSTAB
|
||||
|
||||
if ! grep -m1 -q 'procfs' $FSTAB; then
|
||||
if [ -x /sbin/mount_procfs ]; then
|
||||
echo -e "proc\t\t\t/proc\t\tprocfs\trw\t\t0\t0" >> $FSTAB;
|
||||
/sbin/mount_procfs procfs /proc
|
||||
fi
|
||||
fi
|
||||
|
||||
#hide the errors, it was confusing people
|
||||
/usr/sbin/mount -u /home 2> /dev/null 1> /dev/null
|
||||
/usr/sbin/mount -u / 2> /dev/null 1> /dev/null
|
||||
/usr/sbin/quotaoff -a 2 > /dev/null > /dev/null
|
||||
/sbin/quotacheck -avug 2> /dev/null
|
||||
/usr/sbin/quotaon -a 2> /dev/null 1> /dev/null
|
||||
else
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/home[\ \t]+ext3[\ \t]+defaults[\ \t]+/\t\t\/home\t\t\text3\tdefaults,usrquota,grpquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/[\ \t]+ext3[\ \t]+defaults[\ \t]+/\t\t\t\/\t\t\text3\tdefaults,usrquota,grpquota\t/' $FSTAB
|
||||
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/home[\ \t]+ext4[\ \t]+defaults[\ \t]+/\t\t\/home\t\t\text4\tdefaults,usrquota,grpquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/[\ \t]+ext4[\ \t]+defaults[\ \t]+/\t\t\t\/\t\t\text4\tdefaults,usrquota,grpquota\t/' $FSTAB
|
||||
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/home[\ \t]+ext4[\ \t]+defaults,errors=continue[\ \t]+/\t\t\/home\t\t\text4\tdefaults,errors=continue,usrquota,grpquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/[\ \t]+ext4[\ \t]+defaults,errors=continue[\ \t]+/\t\t\t\/\t\t\text4\tdefaults,errors=continue,usrquota,grpquota\t/' $FSTAB
|
||||
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/home[\ \t]+ext3[\ \t]+errors=remount-ro[\ \t]+/\t\t\/home\t\t\text3\terrors=remount-ro,usrquota,grpquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/[\ \t]+ext3[\ \t]+errors=remount-ro[\ \t]+/\t\t\t\/\t\t\text3\terrors=remount-ro,usrquota,grpquota\t/' $FSTAB
|
||||
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/home[\ \t]+ext4[\ \t]+defaults,errors=remount-ro[\ \t]+/\t\t\/home\t\t\text4\tdefaults,errors=remount-ro,usrquota,grpquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/[\ \t]+ext4[\ \t]+defaults,errors=remount-ro[\ \t]+/\t\t\t\/\t\t\text4\tdefaults,errors=remount-ro,usrquota,grpquota\t/' $FSTAB
|
||||
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/home[\ \t]+ext4[\ \t]+errors=remount-ro[\ \t]+/\t\t\/home\t\t\text4\terrors=remount-ro,usrquota,grpquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/[\ \t]+ext4[\ \t]+errors=remount-ro[\ \t]+/\t\t\t\/\t\t\text4\terrors=remount-ro,usrquota,grpquota\t/' $FSTAB
|
||||
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/home[\ \t]+ext4[\ \t]+defaults[\ \t]+/\t\t\/home\t\t\text4\tdefaults,usrquota,grpquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/[\ \t]+ext4[\ \t]+defaults[\ \t]+/\t\t\t\/\t\t\text4\tdefaults,usrquota,grpquota\t/' $FSTAB
|
||||
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/home[\ \t]+xfs[\ \t]+defaults[\ \t]+/\t\t\/home\t\t\txfs\tdefaults,uquota,gquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/[\ \t]+xfs[\ \t]+defaults[\ \t]+/\t\t\t\/\t\t\txfs\tdefaults,uquota,gquota\t/' $FSTAB
|
||||
|
||||
#run it again with a variance
|
||||
if [ -e /etc/debian_version ]; then
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/home[\ \t]+ext3[\ \t]+defaults,errors=remount-ro[\ \t]+/\t\t\/home\t\t\text3\tdefaults,errors=remount-ro,usrquota,grpquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/[\ \t]+\/[\ \t]+ext3[\ \t]+defaults,errors=remount-ro[\ \t]+/\t\t\t\/\t\t\text3\tdefaults,errors=remount-ro,usrquota,grpquota\t/' $FSTAB
|
||||
|
||||
/usr/bin/perl -pi -e 's/(\s)+\/home(\s)+ext4(\s)+errors=remount-ro(\s)+/\t\t\t\/home\t\t\text4\terrors=remount-ro,usrquota,grpquota\t/' $FSTAB
|
||||
/usr/bin/perl -pi -e 's/(\s)+\/(\s)+ext4(\s)+errors=remount-ro(\s)+/\t\t\t\/\t\t\text4\terrors=remount-ro,usrquota,grpquota\t/' $FSTAB
|
||||
fi
|
||||
|
||||
#hide the errors, it was confusing people
|
||||
/bin/mount -o remount,rw /home 2> /dev/null 1> /dev/null
|
||||
/bin/mount -o remount,rw / 2> /dev/null 1> /dev/null
|
||||
|
||||
echo "Running quotacheck"
|
||||
|
||||
/sbin/quotaoff -a 2> /dev/null
|
||||
/sbin/quotacheck -cavugmf 2> /dev/null
|
||||
/sbin/quotaon -a
|
||||
|
||||
echo "Done quotacheck"
|
||||
fi
|
||||
exit 0
|
||||
@@ -1,142 +0,0 @@
|
||||
#!/usr/local/bin/php
|
||||
<?php
|
||||
|
||||
$use_pasv = true;
|
||||
$url_curl = false;
|
||||
|
||||
$ftp_server = getenv("ftp_ip");
|
||||
$ftp_user_name = getenv("ftp_username");
|
||||
$ftp_user_pass = getenv("ftp_password");
|
||||
$ftp_remote_path = getenv("ftp_path");
|
||||
$ftp_port = getenv("ftp_port");
|
||||
$ftp_remote_file = getenv("ftp_remote_file");
|
||||
$ftp_local_file = getenv("ftp_local_file");
|
||||
|
||||
$ftp_secure = getenv("ftp_secure");
|
||||
$ftps = false;
|
||||
if ($ftp_secure == "ftps")
|
||||
$ftps = true;
|
||||
|
||||
if ($url_curl)
|
||||
{
|
||||
$exit_code = download_with_curl();
|
||||
exit($exit_code);
|
||||
}
|
||||
|
||||
if ($ftps && !function_exists("ftp_ssl_connect"))
|
||||
{
|
||||
echo "ftp_ssl_connect function does not exist. Dropping down to insecure ftp.\n";
|
||||
$ftps = false;
|
||||
}
|
||||
|
||||
if ($ftps)
|
||||
$conn_id = ftp_ssl_connect($ftp_server, $ftp_port);
|
||||
else
|
||||
$conn_id = ftp_connect($ftp_server, $ftp_port);
|
||||
|
||||
if (!$conn_id)
|
||||
{
|
||||
echo "Unable to connect to ${ftp_server}:${ftp_port}\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
|
||||
|
||||
if (!$login_result)
|
||||
{
|
||||
echo "Invalid login/password for $ftp_user_name on $ftp_server\n";
|
||||
ftp_close($conn_id);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
ftp_pasv($conn_id, $use_pasv);
|
||||
|
||||
if (!ftp_chdir($conn_id, $ftp_remote_path))
|
||||
{
|
||||
echo "Invalid remote path '$ftp_remote_path'\n";
|
||||
ftp_close($conn_id);
|
||||
exit(3);
|
||||
}
|
||||
|
||||
if (ftp_get($conn_id, $ftp_local_file, $ftp_remote_file, FTP_BINARY))
|
||||
{
|
||||
ftp_close($conn_id);
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$use_pasv = false;
|
||||
|
||||
ftp_pasv($conn_id, $use_pasv);
|
||||
|
||||
if (ftp_get($conn_id, $ftp_local_file, $ftp_remote_file, FTP_BINARY))
|
||||
{
|
||||
ftp_close($conn_id);
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Error while downloading $ftp_remote_file\n";
|
||||
ftp_close($conn_id);
|
||||
exit(4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function download_with_curl()
|
||||
{
|
||||
global $use_pasv, $ftp_server, $ftp_user_name, $ftp_user_pass, $ftp_remote_path, $ftp_port, $ftp_remote_file, $ftp_local_file, $ftp_secure, $ftps;
|
||||
|
||||
$ftp_url = "ftp://".$ftp_server.":".$ftp_remote_path."/".$ftp_remote_file;
|
||||
$ch = curl_init();
|
||||
|
||||
if (!$ch)
|
||||
{
|
||||
echo "Could not intialize curl\n";
|
||||
return 5;
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $ftp_url);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $ftp_user_name.':'.$ftp_user_pass);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_ALL);
|
||||
curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
|
||||
//curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_FTPS);
|
||||
curl_setopt($ch, CURLOPT_PORT, $ftp_port);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||
|
||||
//CURLOPT_FTP_FILEMETHOD?
|
||||
|
||||
if (!$use_pasv)
|
||||
curl_setopt($ch, CURLOPT_FTPPORT, '-');
|
||||
|
||||
$fp = fopen($ftp_local_file, 'w');
|
||||
if (!$fp)
|
||||
{
|
||||
echo "Unable to open $ftp_local_file for writing\n";
|
||||
return 6;
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_FILE, $fp);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
|
||||
$exec_code = 0;
|
||||
if ($result === false)
|
||||
{
|
||||
echo "curl_exec error: ".curl_error($ch)."\n";
|
||||
$exec_code = 7;
|
||||
}
|
||||
else
|
||||
if(strlen($result) && $result!="1")
|
||||
echo $result."\n";
|
||||
|
||||
fclose($fp);
|
||||
|
||||
return $exec_code;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,35 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
FTPGET=/usr/bin/ncftpget
|
||||
TOUCH=/bin/touch
|
||||
PORT=${ftp_port}
|
||||
|
||||
if [ ! -e $TOUCH ] && [ -e /usr/bin/touch ]; then
|
||||
TOUCH=/usr/bin/touch
|
||||
fi
|
||||
|
||||
if [ ! -e $FTPGET ]; then
|
||||
echo "";
|
||||
echo "*** Backup not downloaded ***";
|
||||
echo "Please install $FTPGET by running:";
|
||||
echo "";
|
||||
echo "cd /usr/local/directadmin/scripts";
|
||||
echo "./ncftp.sh";
|
||||
echo "";
|
||||
exit 10;
|
||||
fi
|
||||
|
||||
CFG=${ftp_local_file}.cfg
|
||||
/bin/rm -f $CFG
|
||||
$TOUCH $CFG
|
||||
/bin/chmod 600 $CFG
|
||||
/bin/echo "host $ftp_ip" >> $CFG
|
||||
/bin/echo "user $ftp_username" >> $CFG
|
||||
/bin/echo "pass $ftp_password" >> $CFG
|
||||
|
||||
$FTPGET -C -f $CFG -V -t 25 -P $PORT "$ftp_ip" "$ftp_path/$ftp_remote_file" "$ftp_local_file" 2>&1
|
||||
RET=$?
|
||||
|
||||
/bin/rm -f $CFG
|
||||
|
||||
exit $RET
|
||||
@@ -1,145 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
FTPLS=/usr/bin/ncftpls
|
||||
CURL=/usr/local/bin/curl
|
||||
if [ ! -e ${CURL} ]; then
|
||||
CURL=/usr/bin/curl
|
||||
fi
|
||||
TMPDIR=/home/tmp
|
||||
PORT=${ftp_port}
|
||||
FTPS=0
|
||||
if [ "${ftp_secure}" = "ftps" ]; then
|
||||
FTPS=1
|
||||
fi
|
||||
|
||||
SSL_REQD=""
|
||||
if ${CURL} --help | grep -m1 -q 'ftp-ssl-reqd'; then
|
||||
SSL_REQD="--ftp-ssl-reqd"
|
||||
elif ${CURL} --help | grep -m1 -q 'ssl-reqd'; then
|
||||
SSL_REQD="--ssl-reqd"
|
||||
fi
|
||||
|
||||
if [ "$PORT" = "" ]; then
|
||||
PORT=21
|
||||
fi
|
||||
|
||||
RANDNUM=`/usr/local/bin/php -r 'echo rand(0,10000);'`
|
||||
#we need some level of uniqueness, this is an unlikely fallback.
|
||||
if [ "$RANDNUM" = "" ]; then
|
||||
RANDNUM=$ftp_ip;
|
||||
fi
|
||||
|
||||
CFG=$TMPDIR/$RANDNUM.cfg
|
||||
rm -f $CFG
|
||||
touch $CFG
|
||||
chmod 600 $CFG
|
||||
|
||||
DUMP=$TMPDIR/$RANDNUM.dump
|
||||
rm -f $DUMP
|
||||
touch $DUMP
|
||||
chmod 600 $DUMP
|
||||
|
||||
#######################################################
|
||||
# FTP
|
||||
list_files()
|
||||
{
|
||||
if [ ! -e $FTPLS ]; then
|
||||
echo "";
|
||||
echo "*** Unable to get list ***";
|
||||
echo "Please install $FTPLS by running:";
|
||||
echo "";
|
||||
echo "cd /usr/local/directadmin/scripts";
|
||||
echo "./ncftp.sh";
|
||||
echo "";
|
||||
exit 10;
|
||||
fi
|
||||
|
||||
#man ncftpls lists:
|
||||
#If you want to use absolute pathnames, you need to include a literal slash, using the "%2F" code for a "/" character.
|
||||
#use expr to replace /path to /%2Fpath, if needed.
|
||||
CHAR1=`echo ${ftp_path} | awk '{print substr($1,1,1)}'`
|
||||
if [ "$CHAR1" = "/" ]; then
|
||||
new_path="/%2F`echo ${ftp_path} | awk '{print substr($1,1)}'`"
|
||||
ftp_path=${new_path}
|
||||
else
|
||||
ftp_path="/${ftp_path}"
|
||||
fi
|
||||
|
||||
echo "host $ftp_ip" >> $CFG
|
||||
echo "user $ftp_username" >> $CFG
|
||||
echo "pass $ftp_password" >> $CFG
|
||||
|
||||
if [ ! -s $CFG ]; then
|
||||
echo "ftp config file $CFG is 0 bytes. Make sure $TMPDIR is chmod 1777 and that this is enough disk space.";
|
||||
echo "running as: `id`";
|
||||
df -h
|
||||
exit 11;
|
||||
fi
|
||||
|
||||
$FTPLS -l -f $CFG -P ${PORT} -r 1 -t 10 "ftp://${ftp_ip}${ftp_path}" > $DUMP 2>&1
|
||||
RET=$?
|
||||
|
||||
if [ "$RET" -ne 0 ]; then
|
||||
cat $DUMP
|
||||
|
||||
if [ "$RET" -eq 3 ]; then
|
||||
echo "Transfer failed. Check the path value. (error=$RET)";
|
||||
else
|
||||
echo "${FTPLS} returned error code $RET";
|
||||
fi
|
||||
|
||||
else
|
||||
COLS=`awk '{print NF; exit}' $DUMP`
|
||||
cat $DUMP | grep -v -e '^d' | awk "{ print \$${COLS}; }"
|
||||
fi
|
||||
}
|
||||
|
||||
#######################################################
|
||||
# FTPS
|
||||
list_files_ftps()
|
||||
{
|
||||
if [ ! -e ${CURL} ]; then
|
||||
echo "";
|
||||
echo "*** Unable to get list ***";
|
||||
echo "Please install curl by running:";
|
||||
echo "";
|
||||
echo "cd /usr/local/directadmin/custombuild";
|
||||
echo "./build curl";
|
||||
echo "";
|
||||
exit 10;
|
||||
fi
|
||||
|
||||
#double leading slash required, because the first one doesn't count.
|
||||
#2nd leading slash makes the path absolute, in case the login is not chrooted.
|
||||
#without double forward slashes, the path is relative to the login location, which might not be correct.
|
||||
ftp_path="/${ftp_path}"
|
||||
|
||||
/bin/echo "user = \"$ftp_username:$ftp_password\"" >> $CFG
|
||||
|
||||
${CURL} --config ${CFG} ${SSL_REQD} -k --silent --show-error ftp://$ftp_ip:${PORT}$ftp_path/ > ${DUMP} 2>&1
|
||||
RET=$?
|
||||
|
||||
if [ "$RET" -ne 0 ]; then
|
||||
echo "${CURL} returned error code $RET";
|
||||
cat $DUMP
|
||||
else
|
||||
COLS=`awk '{print NF; exit}' $DUMP`
|
||||
cat $DUMP | grep -v -e '^d' | awk "{ print \$${COLS}; }"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#######################################################
|
||||
# Start
|
||||
|
||||
if [ "${FTPS}" = "1" ]; then
|
||||
list_files_ftps
|
||||
else
|
||||
list_files
|
||||
fi
|
||||
|
||||
|
||||
rm -f $CFG
|
||||
rm -f $DUMP
|
||||
|
||||
exit $RET
|
||||
@@ -1,189 +0,0 @@
|
||||
#!/bin/sh
|
||||
VERSION=1.2
|
||||
CURL=/usr/local/bin/curl
|
||||
if [ ! -e ${CURL} ]; then
|
||||
CURL=/usr/bin/curl
|
||||
fi
|
||||
OS=`uname`;
|
||||
DU=/usr/bin/du
|
||||
BC=/usr/bin/bc
|
||||
EXPR=/usr/bin/expr
|
||||
TOUCH=/bin/touch
|
||||
PORT=${ftp_port}
|
||||
FTPS=0
|
||||
MIN_TLS="--tlsv1.1"
|
||||
|
||||
MD5=${ftp_md5}
|
||||
|
||||
if [ "${ftp_secure}" = "ftps" ]; then
|
||||
FTPS=1
|
||||
fi
|
||||
|
||||
SSL_REQD=""
|
||||
if ${CURL} --help | grep -m1 -q 'ftp-ssl-reqd'; then
|
||||
SSL_REQD="--ftp-ssl-reqd"
|
||||
elif ${CURL} --help | grep -m1 -q 'ssl-reqd'; then
|
||||
SSL_REQD="--ssl-reqd"
|
||||
fi
|
||||
|
||||
|
||||
#######################################################
|
||||
# SETUP
|
||||
|
||||
if [ ! -e $TOUCH ] && [ -e /usr/bin/touch ]; then
|
||||
TOUCH=/usr/bin/touch
|
||||
fi
|
||||
if [ ! -x ${EXPR} ] && [ -x /bin/expr ]; then
|
||||
EXPR=/bin/expr
|
||||
fi
|
||||
|
||||
if [ ! -e "${ftp_local_file}" ]; then
|
||||
echo "Cannot find backup file ${ftp_local_file} to upload";
|
||||
|
||||
/bin/ls -la ${ftp_local_path}
|
||||
|
||||
/bin/df -h
|
||||
|
||||
exit 11;
|
||||
fi
|
||||
|
||||
get_md5() {
|
||||
MF=$1
|
||||
|
||||
if [ ${OS} = "FreeBSD" ]; then
|
||||
MD5SUM=/sbin/md5
|
||||
else
|
||||
MD5SUM=/usr/bin/md5sum
|
||||
fi
|
||||
if [ ! -x ${MD5SUM} ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [ ! -e ${MF} ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [ ${OS} = "FreeBSD" ]; then
|
||||
FMD5=`$MD5SUM -q $MF`
|
||||
else
|
||||
FMD5=`$MD5SUM $MF | cut -d\ -f1`
|
||||
fi
|
||||
|
||||
echo "${FMD5}"
|
||||
}
|
||||
|
||||
#######################################################
|
||||
|
||||
CFG=${ftp_local_file}.cfg
|
||||
/bin/rm -f $CFG
|
||||
$TOUCH $CFG
|
||||
/bin/chmod 600 $CFG
|
||||
|
||||
RET=0;
|
||||
|
||||
#######################################################
|
||||
# FTP
|
||||
upload_file_ftp()
|
||||
{
|
||||
if [ ! -e ${CURL} ]; then
|
||||
echo "";
|
||||
echo "*** Backup not uploaded ***";
|
||||
echo "Please install curl by running:";
|
||||
echo "";
|
||||
echo "cd /usr/local/directadmin/custombuild";
|
||||
echo "./build curl";
|
||||
echo "";
|
||||
exit 10;
|
||||
fi
|
||||
|
||||
/bin/echo "user = \"$ftp_username:$ftp_password\"" >> $CFG
|
||||
|
||||
if [ ! -s ${CFG} ]; then
|
||||
echo "${CFG} is empty. curl is not going to be happy about it.";
|
||||
ls -la ${CFG}
|
||||
ls -la ${ftp_local_file}
|
||||
df -h
|
||||
fi
|
||||
|
||||
#ensure ftp_path ends with /
|
||||
ENDS_WITH_SLASH=`echo "$ftp_path" | grep -c '/$'`
|
||||
if [ "${ENDS_WITH_SLASH}" -eq 0 ]; then
|
||||
ftp_path=${ftp_path}/
|
||||
fi
|
||||
|
||||
${CURL} --config ${CFG} --silent --show-error --ftp-create-dirs --upload-file $ftp_local_file ftp://$ftp_ip:${PORT}/$ftp_path$ftp_remote_file 2>&1
|
||||
RET=$?
|
||||
|
||||
if [ "${RET}" -ne 0 ]; then
|
||||
echo "curl return code: $RET";
|
||||
fi
|
||||
}
|
||||
|
||||
#######################################################
|
||||
# FTPS
|
||||
upload_file_ftps()
|
||||
{
|
||||
if [ ! -e ${CURL} ]; then
|
||||
echo "";
|
||||
echo "*** Backup not uploaded ***";
|
||||
echo "Please install curl by running:";
|
||||
echo "";
|
||||
echo "cd /usr/local/directadmin/custombuild";
|
||||
echo "./build curl";
|
||||
echo "";
|
||||
exit 10;
|
||||
fi
|
||||
|
||||
/bin/echo "user = \"$ftp_username:$ftp_password\"" >> $CFG
|
||||
|
||||
if [ ! -s ${CFG} ]; then
|
||||
echo "${CFG} is empty. curl is not going to be happy about it.";
|
||||
ls -la ${CFG}
|
||||
ls -la ${ftp_local_file}
|
||||
df -h
|
||||
fi
|
||||
|
||||
#ensure ftp_path ends with /
|
||||
ENDS_WITH_SLASH=`echo "$ftp_path" | grep -c '/$'`
|
||||
if [ "${ENDS_WITH_SLASH}" -eq 0 ]; then
|
||||
ftp_path=${ftp_path}/
|
||||
fi
|
||||
|
||||
${CURL} --config ${CFG} ${SSL_REQD} -k ${MIN_TLS} --silent --show-error --ftp-create-dirs --upload-file $ftp_local_file ftp://$ftp_ip:${PORT}/$ftp_path$ftp_remote_file 2>&1
|
||||
RET=$?
|
||||
|
||||
if [ "${RET}" -ne 0 ]; then
|
||||
echo "curl return code: $RET";
|
||||
fi
|
||||
}
|
||||
|
||||
#######################################################
|
||||
# Start
|
||||
|
||||
if [ "${FTPS}" = "1" ]; then
|
||||
upload_file_ftps
|
||||
else
|
||||
upload_file_ftp
|
||||
fi
|
||||
|
||||
if [ "${RET}" = "0" ] && [ "${MD5}" = "1" ]; then
|
||||
MD5_FILE=${ftp_local_file}.md5
|
||||
M=`get_md5 ${ftp_local_file}`
|
||||
if [ "${M}" != "" ]; then
|
||||
echo "${M}" > ${MD5_FILE}
|
||||
|
||||
ftp_local_file=${MD5_FILE}
|
||||
ftp_remote_file=${ftp_remote_file}.md5
|
||||
|
||||
if [ "${FTPS}" = "1" ]; then
|
||||
upload_file_ftps
|
||||
else
|
||||
upload_file
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
/bin/rm -f $CFG
|
||||
|
||||
exit $RET
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
FILE=/usr/local/directadmin/update.tar.gz
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "Usage:";
|
||||
echo "$0 <cid> <lid> [<ip>]";
|
||||
echo "";
|
||||
echo "definitons:";
|
||||
echo " cid: Client ID";
|
||||
echo " lid: License ID";
|
||||
echo " ip: your server IP (only needed when wrong ip is used to get the update.tar.gz file)";
|
||||
echo "example: $0 999 9876";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ $# = 3 ]; then
|
||||
wget -S -O $FILE --bind-address=${3} https://www.directadmin.com/cgi-bin/daupdate?lid=${2}\&uid=${1}
|
||||
else
|
||||
wget -S -O $FILE https://www.directadmin.com/cgi-bin/daupdate?lid=${2}\&uid=${1}
|
||||
fi
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "Error downloading the update.tar.gz file";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
COUNT=`head -n 2 $FILE | grep -c "* You are not allowed to run this program *"`;
|
||||
|
||||
if [ $COUNT -ne 0 ]
|
||||
then
|
||||
echo "You are not authorized to download the update.tar.gz file with that client id and license id (and/or ip). Please email sales@directadmin.com";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
@@ -1,307 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#This script will aquire all information needed to do the install
|
||||
#and will save it accordingly. You can stop the install at anytime
|
||||
#and start over.
|
||||
|
||||
OS=`uname`
|
||||
SETUP="./setup.txt"
|
||||
cd /usr/local/directadmin/scripts
|
||||
YES="y"
|
||||
NO="n"
|
||||
|
||||
if [ -e ${SETUP} ]
|
||||
then
|
||||
while echo -n "Do you want to re-enter the server information? (y, n) :"
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
read CORRECT
|
||||
else
|
||||
read -n 1 CORRECT
|
||||
fi
|
||||
echo "";
|
||||
do
|
||||
{
|
||||
if [ $CORRECT = $YES ]
|
||||
then
|
||||
break;
|
||||
fi
|
||||
if [ $CORRECT = $NO ]
|
||||
then
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
done;
|
||||
fi
|
||||
|
||||
rm -f ${SETUP}
|
||||
umask 077;
|
||||
|
||||
#*****************************************
|
||||
|
||||
#STEP 1: gethostname
|
||||
|
||||
CORRECT="";
|
||||
while
|
||||
echo "Enter the hostname you wish to use.";
|
||||
echo "This is the server's hostname and is *not* intended as a website for the server.";
|
||||
echo "*YOU* are responsible for making sure it resolves to the proper ip.";
|
||||
echo "Do not enter http:// or www.";
|
||||
echo -n "(eg. server.host.com) : ";
|
||||
read hostname;
|
||||
echo "";
|
||||
echo -n "Is ${hostname} correct? (y, n) : ";
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
read CORRECT
|
||||
else
|
||||
read -n 1 CORRECT
|
||||
fi
|
||||
echo "";
|
||||
do
|
||||
{
|
||||
if [ $CORRECT = $YES ]
|
||||
then
|
||||
break;
|
||||
fi
|
||||
}
|
||||
done
|
||||
|
||||
echo "hostname=$hostname" >> ${SETUP}
|
||||
|
||||
#*****************************************
|
||||
|
||||
#STEP 2: get email
|
||||
|
||||
CORRECT="";
|
||||
while echo -n "E-Mail Address: ";
|
||||
read email;
|
||||
echo "";
|
||||
echo -n "Is ${email} correct? (y, n) : ";
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
read CORRECT
|
||||
else
|
||||
read -n 1 CORRECT
|
||||
fi
|
||||
echo "";
|
||||
do
|
||||
{
|
||||
if [ $CORRECT = $YES ]
|
||||
then
|
||||
break;
|
||||
fi
|
||||
}
|
||||
done
|
||||
|
||||
echo "email=$email" >> ${SETUP}
|
||||
|
||||
|
||||
#***********************************************
|
||||
|
||||
#STEP 2: get mysql root password
|
||||
|
||||
while echo -n "Enter a password for the root MySQL user (no spaces): "
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
read passwd
|
||||
else
|
||||
read -s passwd
|
||||
fi
|
||||
echo ""
|
||||
echo -n "Re-Type the password: "
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
read repasswd
|
||||
else
|
||||
read -s repasswd
|
||||
fi
|
||||
do
|
||||
{
|
||||
if [ "$passwd" = "$repasswd" ]; then
|
||||
#if [ -e /usr/bin/mysql ]
|
||||
if [ -e /file/that/doesnt/exist ]; then
|
||||
echo "";
|
||||
echo "SELECT now();" | /usr/bin/mysql 2> /dev/null;
|
||||
if [ $? != 0 ]; then
|
||||
#root password IS set, make sure its right
|
||||
echo "SELECT now();" | /usr/bin/mysql -uroot -p${passwd}
|
||||
if [ $? = 0 ]; then
|
||||
break;
|
||||
fi
|
||||
else
|
||||
#the root password isn't set
|
||||
break;
|
||||
fi
|
||||
else
|
||||
break;
|
||||
fi
|
||||
else
|
||||
echo "";
|
||||
echo "Passwords do not match";
|
||||
fi
|
||||
}
|
||||
done
|
||||
|
||||
echo "";
|
||||
|
||||
echo "mysql=$passwd" >> ${SETUP};
|
||||
echo "mysqluser=da_admin" >> ${SETUP};
|
||||
|
||||
#****************************************************
|
||||
|
||||
#STEP 3: generate admin password
|
||||
|
||||
ADMINNAME="admin";
|
||||
ADMINPASS=`perl -le'print map+(A..Z,a..z,0..9)[rand 62],0..7'`;
|
||||
|
||||
echo "adminname=admin" >> ${SETUP};
|
||||
echo "adminpass=$ADMINPASS" >> ${SETUP};
|
||||
|
||||
|
||||
|
||||
#***************************************************
|
||||
|
||||
#STEP 4: set the nameserver
|
||||
|
||||
TEST=`echo $hostname | cut -d. -f3`
|
||||
if [ "$TEST" = "" ]; then
|
||||
NS1=ns1.`echo $hostname | cut -d. -f1,2`
|
||||
NS2=ns2.`echo $hostname | cut -d. -f1,2`
|
||||
else
|
||||
NS1=ns1.`echo $hostname | cut -d. -f2,3,4,5,6`
|
||||
NS2=ns2.`echo $hostname | cut -d. -f2,3,4,5,6`
|
||||
fi
|
||||
|
||||
echo -e "ns1=$NS1\nns2=$NS2" >> ${SETUP};
|
||||
|
||||
|
||||
|
||||
#****************************************************
|
||||
|
||||
#STEP 5: get the ip
|
||||
|
||||
prefixToNetmask(){
|
||||
BINARY_IP=""
|
||||
for i in {1..32}; do {
|
||||
if [ ${i} -le ${1} ]; then
|
||||
BINARY_IP="${BINARY_IP}1"
|
||||
else
|
||||
BINARY_IP="${BINARY_IP}0"
|
||||
fi
|
||||
}
|
||||
done
|
||||
|
||||
B1=`echo ${BINARY_IP} | cut -c1-8`
|
||||
B2=`echo ${BINARY_IP} | cut -c9-16`
|
||||
B3=`echo ${BINARY_IP} | cut -c17-24`
|
||||
B4=`echo ${BINARY_IP} | cut -c25-32`
|
||||
NM1=`perl -le "print ord(pack('B8', '${B1}'))"`
|
||||
NM2=`perl -le "print ord(pack('B8', '${B2}'))"`
|
||||
NM3=`perl -le "print ord(pack('B8', '${B3}'))"`
|
||||
NM4=`perl -le "print ord(pack('B8', '${B4}'))"`
|
||||
|
||||
echo "${NM1}.${NM2}.${NM3}.${NM4}"
|
||||
}
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
IP=`grep -m1 '^ifconfig_' /etc/rc.conf | cut -d\ -f2`
|
||||
else
|
||||
IP=`ip addr show eth0 | grep -m1 'inet ' | awk '{print $2}' | cut -d/ -f1`
|
||||
PREFIX=`ip addr show eth0 | grep -m1 'inet ' | awk '{print $2}' | cut -d/ -f2`
|
||||
if echo "${IP}" | grep -m1 -q ':'; then
|
||||
NM="${PREFIX}"
|
||||
else
|
||||
NM=`prefixToNetmask ${PREFIX}`
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "ip=$IP" >> ${SETUP};
|
||||
echo "netmask=$NM" >> ${SETUP};
|
||||
|
||||
#***************************************************
|
||||
|
||||
#STEP 5: user id and license id
|
||||
|
||||
userid=0;
|
||||
liceid=0;
|
||||
|
||||
CORRECT="";
|
||||
while echo -n "Enter Your Client ID: ";
|
||||
read userid;
|
||||
echo "";
|
||||
echo -n "Enter Your License ID: ";
|
||||
read liceid;
|
||||
echo "";
|
||||
echo -n "Is CID: ${userid} and LID: ${liceid} correct? (y, n): ";
|
||||
read -n 1 CORRECT;
|
||||
echo "";
|
||||
do
|
||||
{
|
||||
if [ $CORRECT = $YES ]
|
||||
then
|
||||
break;
|
||||
fi
|
||||
}
|
||||
done
|
||||
|
||||
echo -e "uid=${userid}\nlid=${liceid}" >> ${SETUP}
|
||||
|
||||
|
||||
|
||||
#**********************************************************
|
||||
|
||||
#STEP 6: figure out what os he's using so we can get the correct services file
|
||||
|
||||
CORRECT="";
|
||||
SERVFILE="";
|
||||
while echo "What Operating system are you running?";
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
echo -e "\t1:FreeBSD 4.8";
|
||||
read NUM
|
||||
else
|
||||
echo -e "\t1:RedHat 7.2";
|
||||
echo -e "\t2:RedHat 7.3";
|
||||
echo -e "\t3:RedHat 8.0";
|
||||
echo -e "\t4:RedHat 9.0";
|
||||
echo -n "Enter the number from the left: ";
|
||||
read -n 1 NUM
|
||||
fi
|
||||
echo ""
|
||||
do
|
||||
{
|
||||
case $NUM in
|
||||
1 ) SERVFILE="services72.tar.gz";
|
||||
;;
|
||||
2 ) SERVFILE="services73.tar.gz";
|
||||
;;
|
||||
3 ) SERVFILE="services80.tar.gz";
|
||||
;;
|
||||
4 ) SERVFILE="services90.tar.gz";
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$SERVFILE" = "" ]
|
||||
then
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
fi
|
||||
}
|
||||
done
|
||||
|
||||
echo "services=${SERVFILE}" >> ${SETUP}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
echo "**********************************";
|
||||
echo "All Information has been gathered. Please make *sure* the following data is correct, if not, edit the setup.txt file before going on";
|
||||
echo "";
|
||||
/bin/cat ${SETUP};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exit 0;
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
LICENSE=/usr/local/directadmin/conf/license.key
|
||||
DACONF_FILE=/usr/local/directadmin/conf/directadmin.conf
|
||||
|
||||
printf "" > $LICENSE
|
||||
|
||||
chmod 600 $LICENSE
|
||||
chown diradmin:diradmin $LICENSE
|
||||
exit 0;
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
#Script to return the main useable device IP address of the box, used for main outbound connections.
|
||||
#on a LAN, this should match your directadmin.conf lan_ip setting.
|
||||
#for normal servers, this will likely return your license IP (usually)
|
||||
#Will also be the default IP that exim sends email through.
|
||||
OS=`uname`
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
/sbin/ifconfig | grep inet | grep -m1 broadcast | awk '{ print $2; }'
|
||||
else
|
||||
/sbin/ip a | grep inet | grep -m1 brd | awk '{ print $2; };' | cut -d/ -f1
|
||||
fi
|
||||
RET=$?
|
||||
exit $RET
|
||||
@@ -1,145 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ $# -lt "1" ]
|
||||
then
|
||||
echo "Usage: $0 <hostname> (<ip>)";
|
||||
exit 1;
|
||||
fi
|
||||
DIRECTADMIN_BIN=/usr/local/directadmin/directadmin
|
||||
DIRECTADMIN_CONF=/usr/local/directadmin/conf/directadmin.conf
|
||||
IP="127.0.0.1";
|
||||
SETUP=/usr/local/directadmin/scripts/setup.txt
|
||||
OS=`uname`
|
||||
ETH_DEV=eth0
|
||||
if [ -s $SETUP ]; then
|
||||
IP=`grep -m1 '^ip=' $SETUP | cut -d= -f2`;
|
||||
else
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
IP=`/sbin/ifconfig | head -n3 | grep 'inet ' | cut -d\ -f2`;
|
||||
else
|
||||
if [ -s $DIRECTADMIN_CONF ] && [ -x $DIRECTADMIN_BIN ]; then
|
||||
ETH_DEV=`$DIRECTADMIN_BIN c | grep '^ethernet_dev=' | cut -d= -f2`
|
||||
fi
|
||||
IP=`ip addr show $ETH_DEV | grep -m1 'inet ' | awk '{print $2}' | cut -d/ -f1`
|
||||
if [ -z ${IP} ]; then
|
||||
IP=`/sbin/ifconfig $ETH_DEV | grep 'inet ' | head -n1 | awk '{print $2}' | cut -d: -f2`
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $# -gt "1" ]
|
||||
then
|
||||
IP=$2;
|
||||
fi
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
OLDHOST=`hostname -f`
|
||||
else
|
||||
OLDHOST=`hostname --fqdn`
|
||||
fi
|
||||
|
||||
/bin/hostname $1
|
||||
|
||||
if [ "${OLDHOST}" = "" ]; then
|
||||
OLDHOST=old.host.com
|
||||
echo "old hostname was blank. Setting placeholder value ${OLDHOST}"
|
||||
fi
|
||||
|
||||
#remove any previous hostnames.
|
||||
cat /etc/hosts | grep -Fv $1 | grep -Fv $OLDHOST | grep -v '#' > /etc/hosts.tmp
|
||||
|
||||
#start the file over
|
||||
echo "# Do not remove the following line, or various programs" > /etc/hosts
|
||||
echo "# that require network functionality will fail." >> /etc/hosts
|
||||
|
||||
COUNT=`cat /etc/hosts.tmp | grep -c localhost`
|
||||
if [ $COUNT -lt "1" ]
|
||||
then
|
||||
echo -e "127.0.0.1\t\tlocalhost localhost.localdomain" >> /etc/hosts
|
||||
fi
|
||||
|
||||
cat /etc/hosts.tmp >> /etc/hosts
|
||||
|
||||
echo -e "${IP}\t\t${1}" >> /etc/hosts
|
||||
|
||||
chmod 644 /etc/hosts
|
||||
|
||||
if [ -e /etc/hostname ]; then
|
||||
echo $1 > /etc/hostname
|
||||
fi
|
||||
|
||||
if [ -x /usr/bin/hostnamectl ]; then
|
||||
/usr/bin/hostnamectl --static set-hostname ${1}
|
||||
fi
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
/usr/bin/perl -pi -e 's/hostname=(.*)/hostname=\"${1}\"/' /etc/rc.conf
|
||||
fi
|
||||
|
||||
if [ ! -e /etc/debian_version ] && [ "${OS}" != "FreeBSD" ] && [ -s /etc/sysconfig/network ]; then
|
||||
/usr/bin/perl -pi -e 's/HOSTNAME=(.*)/HOSTNAME=${1}/' /etc/sysconfig/network
|
||||
fi
|
||||
|
||||
#for exim.
|
||||
if [ -s /etc/virtual/domains ]; then
|
||||
perl -pi -e "s/^\Q$OLDHOST\E\$/$1/" /etc/virtual/domains
|
||||
|
||||
#backup plan, in case there was no old hostname
|
||||
if grep -m1 -q "^${1}$" /etc/virtual/domains; then
|
||||
echo ${1} >> /etc/virtual/domains;
|
||||
fi
|
||||
fi
|
||||
|
||||
#this is for exim 4 as it wants the dir for the filters
|
||||
|
||||
V=/etc/virtual
|
||||
if [ ! -e ${V} ]; then
|
||||
/bin/mkdir -p ${V}
|
||||
/bin/chown -f mail:mail ${V}
|
||||
/bin/chmod -f 755 ${V}
|
||||
fi
|
||||
|
||||
NEW_DIR=/etc/virtual/${1}
|
||||
OLD_DIR=/etc/virtual/${OLDHOST}
|
||||
|
||||
if [ -d ${OLD_DIR} ] && [ ! -d ${NEW_DIR} ]; then
|
||||
mv ${OLD_DIR} ${NEW_DIR}
|
||||
else
|
||||
if [ ! -d ${NEW_DIR} ]; then
|
||||
/bin/mkdir -p ${NEW_DIR}
|
||||
/bin/chown -f mail:mail ${NEW_DIR}
|
||||
/bin/chmod -f 711 ${NEW_DIR}
|
||||
fi
|
||||
fi
|
||||
|
||||
#dovecot
|
||||
LMTP=/etc/dovecot/conf/lmtp.conf
|
||||
if [ -s ${LMTP} ]; then
|
||||
perl -pi -e "s/\Q$OLDHOST\E/$1/" ${LMTP}
|
||||
fi
|
||||
|
||||
SETUP=/usr/local/directadmin/scripts/setup.txt
|
||||
if [ -s ${SETUP} ] && [ -s ${DIRECTADMIN_CONF} ]; then
|
||||
perl -pi -e "s/\Q$OLDHOST\E\$/$1/" ${SETUP}
|
||||
fi
|
||||
|
||||
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
|
||||
|
||||
#mysql pid file.
|
||||
PIDF=/var/lib/mysql/${OLDHOST}.pid
|
||||
if [ -e $PIDF ]; then
|
||||
mv $PIDF /var/lib/mysql/${1}.pid
|
||||
fi
|
||||
|
||||
PIDF=/home/mysql/${OLDHOST}.pid
|
||||
if [ -e $PIDF ]; then
|
||||
mv $PIDF /home/mysql/${1}.pid
|
||||
fi
|
||||
|
||||
#LetsEncrypt
|
||||
SAN_CONFIG=/usr/local/directadmin/conf/ca.san_config
|
||||
if [ -s ${SAN_CONFIG} ]; then
|
||||
perl -pi -e "s/\Q$OLDHOST\E\$/$1/" ${SAN_CONFIG}
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,558 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#This is the installer script. Run this and follow the directions
|
||||
|
||||
DA_PATH="/usr/local/directadmin"
|
||||
DA_BIN="${DA_PATH}/directadmin"
|
||||
DA_TQ="${DA_PATH}/data/task.queue"
|
||||
DA_SCRIPTS="${DA_PATH}/scripts"
|
||||
CB_OPTIONS=${DA_PATH}/custombuild/options.conf
|
||||
DA_CRON="${DA_SCRIPTS}/directadmin_cron"
|
||||
VIRTUAL="/etc/virtual"
|
||||
OS=`uname`
|
||||
CBVERSION="2.0"
|
||||
DL_SERVER=da-mirror.wpcloud.vn
|
||||
BACKUP_DL_SERVER=da-mirror.cyberslab.net
|
||||
if [ -s $CB_OPTIONS ]; then
|
||||
DLS=`grep -m1 ^downloadserver $CB_OPTIONS | cut -d= -f2`;
|
||||
if [ "${DLS}" != "" ]; then
|
||||
DL_SERVER=${DLS}
|
||||
fi
|
||||
fi
|
||||
|
||||
CMD_LINE=$1
|
||||
|
||||
cd ${DA_SCRIPTS}
|
||||
|
||||
SYSTEMD=no
|
||||
SYSTEMDDIR=/etc/systemd/system
|
||||
if [ -d ${SYSTEMDDIR} ]; then
|
||||
if [ -e /bin/systemctl ] || [ -e /usr/bin/systemctl ]; then
|
||||
SYSTEMD=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
#Create the diradmin user
|
||||
createDAbase() {
|
||||
mkdir -p ${DA_PATH}
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
/usr/sbin/pw groupadd diradmin 2> /dev/null
|
||||
/usr/sbin/pw useradd -g diradmin -n diradmin -b ${DA_PATH} -s /sbin/nologin 2> /dev/null
|
||||
id diradmin
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "we've just added the diradmin user.. but id can't seem to find it. Trying pwd_mkdb...";
|
||||
pwd_mkdb -p /etc/master.passwd
|
||||
id diradmin
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "After trying the command:"
|
||||
echo " pwd_mkdb -p /etc/master.passwd"
|
||||
echo ""
|
||||
echo "we still cannot find the diradmin user. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
elif [ -e /etc/debian_version ]; then
|
||||
/usr/sbin/adduser --system --group --firstuid 100 --home ${DA_PATH} --no-create-home --disabled-login --force-badname diradmin
|
||||
else
|
||||
/usr/sbin/useradd -d ${DA_PATH} -r -s /bin/false diradmin 2> /dev/null
|
||||
fi
|
||||
|
||||
chmod -f 755 ${DA_PATH}
|
||||
chown -f diradmin:diradmin ${DA_PATH}
|
||||
|
||||
mkdir -p /var/log/directadmin
|
||||
mkdir -p ${DA_PATH}/conf
|
||||
chown -f diradmin:diradmin ${DA_PATH}/*
|
||||
chown -f diradmin:diradmin /var/log/directadmin
|
||||
chmod -f 700 ${DA_PATH}/conf
|
||||
chmod -f 700 /var/log/directadmin
|
||||
if [ -e /etc/logrotate.d ]; then
|
||||
cp $DA_SCRIPTS/directadmin.rotate /etc/logrotate.d/directadmin
|
||||
chmod 644 /etc/logrotate.d/directadmin
|
||||
fi
|
||||
|
||||
chown -f diradmin:diradmin ${DA_PATH}/conf/* 2> /dev/null
|
||||
chmod -f 600 ${DA_PATH}/conf/* 2> /dev/null
|
||||
|
||||
mkdir -p /var/log/httpd/domains
|
||||
chmod 710 /var/log/httpd/domains
|
||||
chmod 710 /var/log/httpd
|
||||
|
||||
mkdir -p /home/tmp
|
||||
chmod -f 1777 /home/tmp
|
||||
/bin/chmod 711 /home
|
||||
|
||||
ULTMP_HC=/usr/lib/tmpfiles.d/home.conf
|
||||
if [ -s ${ULTMP_HC} ]; then
|
||||
#Q /home 0755 - - -
|
||||
if grep -m1 -q '^Q /home 0755 ' ${ULTMP_HC}; then
|
||||
perl -pi -e 's#^Q /home 0755 #Q /home 0711 #' ${ULTMP_HC};
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p /var/www/html
|
||||
chmod 755 /var/www/html
|
||||
|
||||
SSHROOT=`cat /etc/ssh/sshd_config | grep -c 'AllowUsers root'`;
|
||||
|
||||
if [ $SSHROOT = 0 ]
|
||||
then
|
||||
echo "" >> /etc/ssh/sshd_config
|
||||
echo "AllowUsers root" >> /etc/ssh/sshd_config
|
||||
chmod 710 /etc/ssh
|
||||
fi
|
||||
}
|
||||
|
||||
#After everything else copy the directadmin_cron to /etc/cron.d
|
||||
copyCronFile() {
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
if ! grep -m1 -q 'dataskq' /etc/crontab && [ -s ${DA_CRON} ]; then
|
||||
cat ${DA_CRON} | grep -v 'quotaoff' >> /etc/crontab;
|
||||
else
|
||||
echo "Could not find ${DA_CRON} or it is empty";
|
||||
fi
|
||||
else
|
||||
if [ -s ${DA_CRON} ]; then
|
||||
mkdir -p /etc/cron.d
|
||||
cp ${DA_CRON} /etc/cron.d/;
|
||||
chmod 600 /etc/cron.d/directadmin_cron
|
||||
chown root /etc/cron.d/directadmin_cron
|
||||
else
|
||||
echo "Could not find ${DA_CRON} or it is empty";
|
||||
fi
|
||||
|
||||
#CentOS/RHEL bits
|
||||
if [ ! -s /etc/debian_version ]; then
|
||||
CRON_BOOT=/etc/init.d/crond
|
||||
if [ -d /etc/systemd/system ]; then
|
||||
CRON_BOOT=/usr/lib/systemd/system/crond.service
|
||||
fi
|
||||
|
||||
if [ ! -s ${CRON_BOOT} ]; then
|
||||
echo ""
|
||||
echo "****************************************************************************"
|
||||
echo "* Cannot find ${CRON_BOOT}. Ensure you have cronie installed"
|
||||
echo " yum install cronie"
|
||||
echo "****************************************************************************"
|
||||
echo ""
|
||||
else
|
||||
if [ -d /etc/systemd/system ]; then
|
||||
systemctl daemon-reload
|
||||
systemctl enable crond.service
|
||||
systemctl restart crond.service
|
||||
else
|
||||
${CRON_BOOT} restart
|
||||
/sbin/chkconfig crond on
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#Copies the startup scripts over to the /etc/rc.d/init.d/ folder
|
||||
#and chkconfig's them to enable them on bootup
|
||||
copyStartupScripts() {
|
||||
if [ "${SYSTEMD}" = "yes" ]; then
|
||||
cp -f directadmin.service ${SYSTEMDDIR}/
|
||||
cp -f startips.service ${SYSTEMDDIR}/
|
||||
|
||||
systemctl daemon-reload
|
||||
|
||||
systemctl enable directadmin.service
|
||||
systemctl enable startips.service
|
||||
else
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
BOOT_DIR=/usr/local/etc/rc.d/
|
||||
#removed boot.sh, sshd and named from the list, as boot.sh is unused and the other 2 come pre-installed with the system
|
||||
if [ ! -s ${BOOT_DIR}/startips ]; then
|
||||
cp -f startips ${BOOT_DIR}/startips
|
||||
chmod 755 ${BOOT_DIR}/startips
|
||||
fi
|
||||
if [ ! -s ${BOOT_DIR}/da-popb4smtp ]; then
|
||||
echo '#!/bin/sh' > ${BOOT_DIR}/da-popb4smtp
|
||||
echo '' >> ${BOOT_DIR}/da-popb4smtp
|
||||
echo '. /etc/rc.subr' >> ${BOOT_DIR}/da-popb4smtp
|
||||
echo '' >> ${BOOT_DIR}/da-popb4smtp
|
||||
echo 'name="da_popb4smtp"' >> ${BOOT_DIR}/da-popb4smtp
|
||||
echo 'rcvar="da_popb4smtp_enable"' >> ${BOOT_DIR}/da-popb4smtp
|
||||
echo 'command="/usr/local/directadmin/da-popb4smtp"' >> ${BOOT_DIR}/da-popb4smtp
|
||||
echo '' >> ${BOOT_DIR}/da-popb4smtp
|
||||
echo 'load_rc_config $name' >> ${BOOT_DIR}/da-popb4smtp
|
||||
echo ': ${da_popb4smtp_enable:=yes}' >> ${BOOT_DIR}/da-popb4smtp
|
||||
echo '' >> ${BOOT_DIR}/da-popb4smtp
|
||||
echo 'run_rc_command "$1"' >> ${BOOT_DIR}/da-popb4smtp
|
||||
chmod 755 ${BOOT_DIR}/da-popb4smtp
|
||||
fi
|
||||
if [ ! -s ${BOOT_DIR}/directadmin ]; then
|
||||
echo '#!/bin/sh' > ${BOOT_DIR}/directadmin
|
||||
echo '' >> ${BOOT_DIR}/directadmin
|
||||
echo '. /etc/rc.subr' >> ${BOOT_DIR}/directadmin
|
||||
echo '' >> ${BOOT_DIR}/directadmin
|
||||
echo 'name="directadmin"' >> ${BOOT_DIR}/directadmin
|
||||
echo 'rcvar="directadmin_enable"' >> ${BOOT_DIR}/directadmin
|
||||
echo 'pidfile="/var/run/${name}.pid"' >> ${BOOT_DIR}/directadmin
|
||||
echo 'command="/usr/local/directadmin/directadmin"' >> ${BOOT_DIR}/directadmin
|
||||
echo 'command_args="d"' >> ${BOOT_DIR}/directadmin
|
||||
echo '' >> ${BOOT_DIR}/directadmin
|
||||
echo 'load_rc_config $name' >> ${BOOT_DIR}/directadmin
|
||||
echo ': ${directadmin_enable:=yes}' >> ${BOOT_DIR}/directadmin
|
||||
echo '' >> ${BOOT_DIR}/directadmin
|
||||
echo 'run_rc_command "$1"' >> ${BOOT_DIR}/directadmin
|
||||
chmod 755 ${BOOT_DIR}/directadmin
|
||||
fi
|
||||
|
||||
ERC=/etc/rc.conf
|
||||
if [ -e ${ERC} ]; then
|
||||
if ! /usr/bin/grep -m1 -q "^named_enable=" ${ERC}; then
|
||||
echo 'named_enable="YES"' >> ${ERC}
|
||||
else
|
||||
perl -pi -e 's/^named_enable=.*/named_enable="YES"/' ${ERC}
|
||||
fi
|
||||
fi
|
||||
else
|
||||
cp -f directadmin /etc/init.d/directadmin
|
||||
cp -f startips /etc/init.d/startips
|
||||
# nothing for debian as non-systemd debian versions are EOL
|
||||
if [ ! -s /etc/debian_version ]; then
|
||||
/sbin/chkconfig directadmin reset
|
||||
/sbin/chkconfig startips reset
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
addUserGroup() {
|
||||
if [ ${OS} = "FreeBSD" ]; then
|
||||
PW=/usr/sbin/pw
|
||||
ADD_UID=
|
||||
ADD_GID=
|
||||
if [ "${3}" != "" ]; then
|
||||
ADD_UID="-u ${3}"
|
||||
fi
|
||||
if [ "${4}" != "" ]; then
|
||||
ADD_GID="-g ${4}"
|
||||
fi
|
||||
|
||||
if ! /usr/bin/grep -q "^${2}:" < /etc/group; then
|
||||
${PW} groupadd ${2} ${ADD_GID}
|
||||
fi
|
||||
if ! /usr/bin/id ${1} > /dev/null; then
|
||||
${PW} useradd -g ${2} -n ${1} -s /sbin/nologin ${ADD_UID}
|
||||
fi
|
||||
elif [ -e /etc/debian_version ]; then
|
||||
if ! /usr/bin/id ${1} > /dev/null; then
|
||||
adduser --system --group --no-create-home \
|
||||
--disabled-login --force-badname ${1} > /dev/null
|
||||
fi
|
||||
else
|
||||
if ! /usr/bin/id ${1} > /dev/null; then
|
||||
/usr/sbin/useradd -r -s /bin/false ${1}
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#touch exim's file inside /etc/virtual
|
||||
touchExim() {
|
||||
mkdir -p ${VIRTUAL};
|
||||
chown -f mail ${VIRTUAL};
|
||||
chgrp -f mail ${VIRTUAL};
|
||||
chmod 755 ${VIRTUAL};
|
||||
|
||||
echo "`hostname -f`" >> ${VIRTUAL}/domains;
|
||||
|
||||
if [ ! -s ${VIRTUAL}/limit ]; then
|
||||
echo "1000" > ${VIRTUAL}/limit
|
||||
fi
|
||||
if [ ! -s ${VIRTUAL}/limit_unknown ]; then
|
||||
echo "0" > ${VIRTUAL}/limit_unknown
|
||||
fi
|
||||
if [ ! -s ${VIRTUAL}/user_limit ]; then
|
||||
echo "200" > ${VIRTUAL}/user_limit
|
||||
fi
|
||||
|
||||
chmod 755 ${VIRTUAL}/*
|
||||
|
||||
mkdir -p ${VIRTUAL}/usage
|
||||
chmod 750 ${VIRTUAL}/usage
|
||||
|
||||
for i in domains domainowners pophosts blacklist_domains whitelist_from use_rbl_domains bad_sender_hosts bad_sender_hosts_ip blacklist_senders whitelist_domains whitelist_hosts whitelist_hosts_ip whitelist_senders skip_av_domains skip_rbl_domains; do
|
||||
touch ${VIRTUAL}/$i;
|
||||
chmod 600 ${VIRTUAL}/$i;
|
||||
done
|
||||
|
||||
addUserGroup mail mail 12 12
|
||||
chown -f mail:mail ${VIRTUAL}/*;
|
||||
}
|
||||
|
||||
|
||||
#get setup data
|
||||
doGetInfo() {
|
||||
if [ ! -e ./setup.txt ]; then
|
||||
./getInfo.sh
|
||||
fi
|
||||
}
|
||||
|
||||
getLicense() {
|
||||
|
||||
if [ -e /root/.skip_get_license ]; then
|
||||
echo "/root/.skip_get_license exists. Not downloading license"
|
||||
return;
|
||||
fi
|
||||
|
||||
userid=`cat ./setup.txt | grep uid= | cut -d= -f2`;
|
||||
liceid=`cat ./setup.txt | grep lid= | cut -d= -f2`;
|
||||
ip=`cat ./setup.txt | grep ip= | cut -d= -f2`;
|
||||
|
||||
LAN=0
|
||||
if [ -s /root/.lan ]; then
|
||||
LAN=`cat /root/.lan`
|
||||
fi
|
||||
|
||||
if [ "$LAN" -eq 1 ]; then
|
||||
$DA_SCRIPTS/getLicense.sh ${userid} ${liceid}
|
||||
else
|
||||
$DA_SCRIPTS/getLicense.sh ${userid} ${liceid} ${ip}
|
||||
fi
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# wget https://www.directadmin.com/cgi-bin/licenseupdate?lid=${liceid}\&uid=${userid} -O /usr/local/directadmin/conf/license.key --bind-address=${ip} 2> /dev/null
|
||||
# if [ $? -ne 0 ]
|
||||
# then
|
||||
# echo "Error downloading the license file";
|
||||
# exit 1;
|
||||
# fi
|
||||
#
|
||||
# COUNT=`cat /usr/local/directadmin/conf/license.key | grep -c "* You are not allowed to run this program *"`;
|
||||
#
|
||||
# if [ $COUNT -ne 0 ]
|
||||
# then
|
||||
# echo "You are not authorized to download the license with that client id and license id. Please email sales@directadmin.com";
|
||||
# exit 1;
|
||||
# fi
|
||||
}
|
||||
|
||||
doSetHostname() {
|
||||
HN=`cat ./setup.txt | grep hostname= | cut -d= -f2`;
|
||||
|
||||
${DA_PATH}/scripts/hostname.sh ${HN}
|
||||
|
||||
#/sbin/service network restart
|
||||
}
|
||||
|
||||
checkMD5()
|
||||
{
|
||||
if [ ${OS} = "FreeBSD" ]; then
|
||||
MD5SUM=/sbin/md5
|
||||
else
|
||||
MD5SUM=/usr/bin/md5sum
|
||||
fi
|
||||
MD5_FILE=$1
|
||||
MD5_CHECK=${MD5_FILE}.md5
|
||||
|
||||
if [ ! -s "${MD5SUM}" ]; then
|
||||
echo "Cannot find $MD5SUM to check $MD5_FILE";
|
||||
return;
|
||||
fi
|
||||
|
||||
if [ ! -s "${MD5_FILE}" ]; then
|
||||
echo "Cannot find ${MD5_FILE} or it is empty";
|
||||
return;
|
||||
fi
|
||||
|
||||
if [ ! -s "${MD5_CHECK}" ]; then
|
||||
echo "Cannot find ${MD5_CHECK} or it is empty";
|
||||
return;
|
||||
fi
|
||||
|
||||
echo "";
|
||||
echo -n "Checking MD5sum on $MD5_FILE ... ";
|
||||
|
||||
LOCAL_MD5=`${MD5SUM} ${MD5_FILE} | cut -d\ -f1`
|
||||
CHECK_MD5=`cat ${MD5_CHECK} | cut -d\ -f1`
|
||||
|
||||
if [ "${LOCAL_MD5}" = "${CHECK_MD5}" ]; then
|
||||
echo "Pass";
|
||||
else
|
||||
echo "Failed. Consider deleting $MD5_FILE and $MD5_CHECK then try again";
|
||||
|
||||
echo "";
|
||||
echo "";
|
||||
|
||||
sleep 5;
|
||||
fi
|
||||
}
|
||||
|
||||
getServices() {
|
||||
SERVICES_FILE=${DA_SCRIPTS}/packages/services.tar.gz
|
||||
|
||||
if [ -s "{$SERVICES_FILE}" ]; then
|
||||
if [ -s "${SERVICES_FILE}.md5" ]; then
|
||||
checkMD5 ${SERVICES_FILE}
|
||||
fi
|
||||
|
||||
echo "Services file already exists. Assuming its been extracted, skipping...";
|
||||
|
||||
return;
|
||||
fi
|
||||
|
||||
servfile=`cat ./setup.txt | grep services= | cut -d= -f2`;
|
||||
|
||||
#get the md5sum
|
||||
wget https://raw.githubusercontent.com/irf1404/Directadmin/master/services/${servfile}.md5 -O ${SERVICES_FILE}.md5
|
||||
if [ ! -s ${SERVICES_FILE}.md5 ];
|
||||
then
|
||||
echo "";
|
||||
echo "failed to get md5 file: ${SERVICES_FILE}.md5";
|
||||
echo "";
|
||||
sleep 4;
|
||||
fi
|
||||
|
||||
wget https://raw.githubusercontent.com/irf1404/Directadmin/master/services/${servfile} -O $SERVICES_FILE
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "Error downloading the services file";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
#we have md5, lets use it.
|
||||
if [ -s ${SERVICES_FILE}.md5 ]; then
|
||||
checkMD5 ${SERVICES_FILE}
|
||||
fi
|
||||
|
||||
echo "Extracting services file...";
|
||||
|
||||
tar xzf $SERVICES_FILE -C ${DA_SCRIPTS}/packages
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "Error extracting services file";
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
./doChecks.sh
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
doGetInfo
|
||||
doSetHostname
|
||||
createDAbase
|
||||
copyStartupScripts
|
||||
#copyCronFile #moved lower, after custombuild, march 7, 2011
|
||||
touchExim
|
||||
|
||||
./fstab.sh
|
||||
${DA_SCRIPTS}/cron_deny.sh
|
||||
|
||||
getLicense
|
||||
getServices
|
||||
|
||||
if [ ! -e ${DA_PATH}/custombuild/options.conf ] && [ -e /etc/redhat-release ] && [ ! -e /etc/init.d/xinetd ] && [ -e /usr/bin/yum ]; then
|
||||
yum -y install xinetd
|
||||
/sbin/chkconfig xinetd on
|
||||
/sbin/service xinetd start
|
||||
fi
|
||||
|
||||
cd ${DA_SCRIPTS}
|
||||
cp -f ${DA_SCRIPTS}/redirect.php /var/www/html/redirect.php
|
||||
|
||||
rpm -e --nodeps wu-ftp 2> /dev/null
|
||||
rpm -e --nodeps wu-ftpd 2> /dev/null
|
||||
rpm -e --nodeps anonftp 2> /dev/null
|
||||
rpm -e --nodeps pure-ftpd 2> /dev/null
|
||||
rpm -e --nodeps vsftpd 2> /dev/null
|
||||
rpm -e --nodeps psa-proftpd 2> /dev/null
|
||||
rpm -e --nodeps psa-proftpd-xinetd 2> /dev/null
|
||||
rpm -e --nodeps psa-proftpd-start 2> /dev/null
|
||||
rm -f /etc/xinetd.d/proftpd
|
||||
rm -f /etc/xinetd.d/wu-ftpd.rpmsave
|
||||
rm -f /etc/xinetd.d/wu-ftpd
|
||||
rm -f /etc/xinetd.d/ftp_psa
|
||||
rm -f /etc/xinetd.d/gssftp
|
||||
rm -f /etc/xinetd.d/xproftpd
|
||||
killall -9 pure-ftpd 2> /dev/null > /dev/null
|
||||
rm -f /usr/local/sbin/pure-ftpd 2> /dev/null > /dev/null
|
||||
|
||||
#while we're doing it, lets get rid of pop stuff too
|
||||
rm -f /etc/xinetd.d/pop*
|
||||
|
||||
#in case they it still holds port 21
|
||||
if [ -s /etc/init.d/xinetd ] && [ "${SYSTEMD}" = "no" ]; then
|
||||
/sbin/service xinetd restart
|
||||
fi
|
||||
if [ -s /usr/lib/systemd/system/xinetd.service ] && [ "${SYSTEMD}" = "yes" ]; then
|
||||
systemctl restart xinetd.service
|
||||
fi
|
||||
|
||||
if [ -s ${DA_SCRIPTS}/majordomo.sh ]; then
|
||||
cd packages
|
||||
tar xzf majordomo-*.tar.gz
|
||||
cd ..
|
||||
${DA_SCRIPTS}/majordomo.sh
|
||||
fi
|
||||
|
||||
${DA_SCRIPTS}/sysbk.sh
|
||||
|
||||
|
||||
cd ${DA_PATH}/custombuild
|
||||
chmod 755 build
|
||||
./build update
|
||||
./build all d
|
||||
if [ $? -ne 0 ]; then
|
||||
copyCronFile
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#moved here march 7, 2011
|
||||
copyCronFile
|
||||
|
||||
if [ -s /var/www/html/redirect.php ]; then
|
||||
chown webapps:webapps /var/www/html/redirect.php
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/local/bin/php ]; then
|
||||
echo "*******************************************"
|
||||
echo "*******************************************"
|
||||
echo ""
|
||||
echo "Cannot find /usr/local/bin/php"
|
||||
echo "Please recompile php with custombuild, eg:"
|
||||
echo "cd ${DA_PATH}/custombuild"
|
||||
echo "./build all d"
|
||||
echo ""
|
||||
echo "*******************************************"
|
||||
echo "*******************************************"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
cd ${DA_PATH}
|
||||
./directadmin i
|
||||
|
||||
cd ${DA_PATH}
|
||||
./directadmin p
|
||||
|
||||
perl -pi -e 's/directadmin=OFF/directadmin=ON/' ${DA_PATH}/data/admin/services.status
|
||||
|
||||
echo "";
|
||||
echo "System Security Tips:";
|
||||
echo " http://help.directadmin.com/item.php?id=247";
|
||||
echo "";
|
||||
|
||||
DACONF=${DA_PATH}/conf/directadmin.conf
|
||||
if [ ! -s $DACONF ]; then
|
||||
echo "";
|
||||
echo "*********************************";
|
||||
echo "*";
|
||||
echo "* Cannot find $DACONF";
|
||||
echo "* Please see this guide:";
|
||||
echo "* http://help.directadmin.com/item.php?id=267";
|
||||
echo "*";
|
||||
echo "*********************************";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
DIG=/usr/bin/dig
|
||||
WHOIS=/usr/bin/whois
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage:";
|
||||
echo " $0 ip";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ ! -x "$DIG" ]; then
|
||||
echo "Cannot find $DIG or it's not executable.";
|
||||
exit 2;
|
||||
else
|
||||
$DIG -x "$1" +noshort 2>&1
|
||||
fi
|
||||
|
||||
if [ -x "$WHOIS" ]; then
|
||||
$WHOIS "$1" 2>&1
|
||||
fi
|
||||
|
||||
exit 0;
|
||||
@@ -1,223 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#script to change ips on a DA server.
|
||||
#usage:
|
||||
# $0 <oldip> <newip>
|
||||
|
||||
LOG=/var/log/directadmin/ipswap.log
|
||||
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "$MYUID" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ $# != 2 ] && [ $# != 3 ]; then
|
||||
echo "Usage:";
|
||||
echo "$0 <oldip> <newip> [<file>]";
|
||||
echo "you gave #$#: $0 $1 $2 $3";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
OLD_IP=$1
|
||||
NEW_IP=$2
|
||||
|
||||
DIRECTADMIN=/usr/local/directadmin/directadmin
|
||||
|
||||
HAVE_HTTPD=1
|
||||
HAVE_NGINX=0
|
||||
HAVE_DOVECOT_PROXY=0
|
||||
if [ -s ${DIRECTADMIN} ]; then
|
||||
if [ "`${DIRECTADMIN} c | grep ^nginx= | cut -d= -f2`" -eq 1 ]; then
|
||||
HAVE_HTTPD=0
|
||||
HAVE_NGINX=1
|
||||
fi
|
||||
if [ "`${DIRECTADMIN} c | grep ^nginx_proxy= | cut -d= -f2`" -eq 1 ]; then
|
||||
HAVE_HTTPD=1
|
||||
HAVE_NGINX=1
|
||||
fi
|
||||
if [ "`${DIRECTADMIN} c | grep ^dovecot_proxy= | cut -d= -f2`" -eq 1 ]; then
|
||||
HAVE_DOVECOT_PROXY=1
|
||||
fi
|
||||
fi
|
||||
|
||||
valid_ip()
|
||||
{
|
||||
#very very.. very basic validation. very basic.
|
||||
VIP=$1
|
||||
|
||||
if [ "$VIP" = "" ]; then
|
||||
echo 0;
|
||||
return;
|
||||
fi
|
||||
|
||||
#do not allow short-form IPv6 addresses.
|
||||
IPV6_SHORT=`echo "$VIP" | grep -c ::`
|
||||
if [ "${IPV6_SHORT}" -gt 0 ]; then
|
||||
echo 0
|
||||
else
|
||||
echo 1
|
||||
fi
|
||||
}
|
||||
|
||||
die_if_bad_ip()
|
||||
{
|
||||
IP=$1
|
||||
V=`valid_ip "$IP"`
|
||||
if [ "$V" = "0" ]; then
|
||||
echo "IP '$IP' is not valid.";
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
die_if_bad_ip "${OLD_IP}"
|
||||
die_if_bad_ip "${NEW_IP}"
|
||||
|
||||
log()
|
||||
{
|
||||
echo -e "$1";
|
||||
echo -e "$1" >> $LOG;
|
||||
}
|
||||
|
||||
swapfile()
|
||||
{
|
||||
if [ ! -e $1 ]; then
|
||||
log "Cannot Find $1 to change the IPs. Skipping...";
|
||||
return;
|
||||
fi
|
||||
|
||||
TEMP="perl -pi -e 's/(^|[\s.=\/:])${OLD_IP}([\s.>:;])/\${1}${NEW_IP}\${2}/g' $1"
|
||||
eval $TEMP;
|
||||
|
||||
log "$1\t: $OLD_IP -> $NEW_IP";
|
||||
}
|
||||
|
||||
if [ $# = 3 ]; then
|
||||
|
||||
swapfile $3;
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
IPFILE_OLD=/usr/local/directadmin/data/admin/ips/$OLD_IP
|
||||
IPFILE_NEW=/usr/local/directadmin/data/admin/ips/$NEW_IP
|
||||
|
||||
NEW_IS_ALREADY_SERVER=0
|
||||
if [ -s ${IPFILE_NEW} ]; then
|
||||
echo "${IPFILE_NEW} already exists.";
|
||||
|
||||
NEW_IS_ALREADY_SERVER=`grep -c status=server ${IPFILE_NEW}`
|
||||
if [ "${NEW_IS_ALREADY_SERVER}" -gt 0 ]; then
|
||||
echo "it's also the server IP, so we're not going to overwrite it if we continue.";
|
||||
echo -n "Do you want to continue swapping all instances of $OLD_IP with $NEW_IP, knowing we're not going to swap the actual IP file? (y/n) : ";
|
||||
|
||||
read YESNO;
|
||||
if [ "$YESNO" != "y" ]; then
|
||||
exit 0;
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -e $IPFILE_OLD ]; then
|
||||
echo -n "$IPFILE_OLD does not exist. Do you want to continue anyway? (y/n) : ";
|
||||
read YESNO;
|
||||
if [ "$YESNO" != "y" ]; then
|
||||
exit 0;
|
||||
fi
|
||||
else
|
||||
if [ "${NEW_IS_ALREADY_SERVER}" -gt 0 ]; then
|
||||
#do not touch the new file, but get rid of the old one.
|
||||
rm -f $IPFILE_OLD
|
||||
else
|
||||
mv -f $IPFILE_OLD $IPFILE_NEW
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${HAVE_HTTPD}" -eq 1 ]; then
|
||||
swapfile /etc/httpd/conf/httpd.conf
|
||||
swapfile /etc/httpd/conf/extra/httpd-vhosts.conf
|
||||
swapfile /etc/httpd/conf/ips.conf
|
||||
fi
|
||||
if [ "${HAVE_NGINX}" -eq 1 ]; then
|
||||
swapfile /etc/nginx/nginx.conf
|
||||
swapfile /etc/nginx/nginx-vhosts.conf
|
||||
swapfile /etc/nginx/nginx-userdir.conf
|
||||
swapfile /etc/nginx/directadmin-ips.conf
|
||||
swapfile /etc/nginx/webapps.conf
|
||||
swapfile /etc/nginx/webapps.ssl.conf
|
||||
fi
|
||||
swapfile /etc/proftpd.conf
|
||||
swapfile /etc/proftpd.vhosts.conf
|
||||
swapfile /etc/hosts
|
||||
swapfile /usr/local/directadmin/scripts/setup.txt
|
||||
swapfile /usr/local/directadmin/data/admin/ip.list
|
||||
swapfile /usr/local/directadmin/data/admin/show_all_users.cache
|
||||
swapfile /etc/virtual/domainips
|
||||
swapfile /etc/virtual/helo_data
|
||||
|
||||
ULDDU=/usr/local/directadmin/data/users
|
||||
|
||||
for i in `ls $ULDDU`; do
|
||||
{
|
||||
|
||||
if [ ! -d $ULDDU/$i ]; then
|
||||
continue;
|
||||
fi
|
||||
|
||||
swapfile $ULDDU/$i/user.conf
|
||||
if [ "${HAVE_HTTPD}" -eq 1 ]; then
|
||||
swapfile $ULDDU/$i/httpd.conf
|
||||
fi
|
||||
if [ "${HAVE_NGINX}" -eq 1 ]; then
|
||||
swapfile $ULDDU/$i/nginx.conf
|
||||
fi
|
||||
|
||||
if [ -e $ULDDU/$i/ip.list ]; then
|
||||
swapfile $ULDDU/$i/ip.list
|
||||
fi
|
||||
|
||||
swapfile $ULDDU/$i/user_ip.list
|
||||
|
||||
for j in `ls $ULDDU/$i/domains/*.conf; ls $ULDDU/$i/domains/*.ftp; ls $ULDDU/$i/domains/*.ip_list`; do
|
||||
{
|
||||
swapfile $j
|
||||
};
|
||||
done;
|
||||
};
|
||||
done;
|
||||
|
||||
OS=`uname`
|
||||
if [ $OS = "FreeBSD" ]; then
|
||||
DB_PATH=/etc/namedb
|
||||
else
|
||||
if [ -e /etc/debian_version ]; then
|
||||
DB_PATH=/etc/bind
|
||||
else
|
||||
DB_PATH=/var/named
|
||||
fi
|
||||
fi
|
||||
|
||||
for i in `ls $DB_PATH/*.db`; do
|
||||
{
|
||||
swapfile $i
|
||||
};
|
||||
done;
|
||||
|
||||
if [ "${HAVE_DOVECOT_PROXY}" = "1" ]; then
|
||||
#swap all /etc/virtual/*/passwd files proxy_maybe=y host=1.2.3.4
|
||||
echo "action=rewrite&value=email_passwd" >> /usr/local/directadmin/data/task.queue
|
||||
fi
|
||||
|
||||
echo "Updating Linked IPs"
|
||||
echo "action=ipswap&value=linked_ips&old=$OLD_IP&new=$NEW_IP" >> /usr/local/directadmin/data/task.queue.cb
|
||||
/usr/local/directadmin/dataskq d100 --custombuild
|
||||
|
||||
#this is needed to update the serial in the db files.
|
||||
echo "action=rewrite&value=named" >> /usr/local/directadmin/data/task.queue
|
||||
echo "action=cache&value=showallusers" >> /usr/local/directadmin/data/task.queue
|
||||
if [ "${HAVE_HTTPD}" -eq 1 ]; then
|
||||
echo "action=httpd&value=restart" >> /usr/local/directadmin/data/task.queue
|
||||
fi
|
||||
if [ "${HAVE_NGINX}" -eq 1 ]; then
|
||||
echo "action=nginx&value=restart" >> /usr/local/directadmin/data/task.queue
|
||||
fi
|
||||
log "\n*** Done swapping $OLD_IP to $NEW_IP ***\n";
|
||||
@@ -1,147 +0,0 @@
|
||||
#!/bin/sh
|
||||
#Version: 0.1 ALPHA (use at your own risk!)
|
||||
#Script is used to change the IP of all Users owned by Reseller on a DA server (including the Reseller himself).
|
||||
#Written by DirectAdmin and Martynas Bendorius (smtalk)
|
||||
#Usage: $0 <oldip> <newip> <reseller>
|
||||
|
||||
LOG=/var/log/directadmin/ipswap_reseller.log
|
||||
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "$MYUID" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ $# != 2 ] && [ $# != 3 ] && [ $# != 4 ]; then
|
||||
echo "Usage:";
|
||||
echo "$0 <oldip> <newip> <reseller>";
|
||||
echo "you gave #$#: $0 $1 $2 $3";
|
||||
echo "";
|
||||
echo "New IP must exist and be set as shared.";
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
OLD_IP=$1
|
||||
NEW_IP=$2
|
||||
RESELLER=$3
|
||||
|
||||
HAVE_HTTPD=1
|
||||
HAVE_NGINX=0
|
||||
if [ -s ${DIRECTADMIN} ]; then
|
||||
if [ "`${DIRECTADMIN} c | grep ^nginx= | cut -d= -f2`" -eq 1 ]; then
|
||||
HAVE_HTTPD=0
|
||||
HAVE_NGINX=1
|
||||
fi
|
||||
if [ "`${DIRECTADMIN} c | grep ^nginx_proxy= | cut -d= -f2`" -eq 1 ]; then
|
||||
HAVE_HTTPD=1
|
||||
HAVE_NGINX=1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
log()
|
||||
{
|
||||
echo -e "$1";
|
||||
echo -e "$1" >> $LOG;
|
||||
}
|
||||
|
||||
swapfile()
|
||||
{
|
||||
if [ ! -e $1 ]; then
|
||||
log "Cannot Find $1 to change the IPs. Skipping...";
|
||||
return;
|
||||
fi
|
||||
|
||||
TEMP="perl -pi -e 's/(^|[\s.=\/:])${OLD_IP}([\s.>:])/\${1}${NEW_IP}\${2}/g' $1"
|
||||
eval $TEMP;
|
||||
|
||||
log "$1\t: $OLD_IP -> $NEW_IP";
|
||||
}
|
||||
|
||||
IPFILE_OLD=/usr/local/directadmin/data/admin/ips/$OLD_IP
|
||||
IPFILE_NEW=/usr/local/directadmin/data/admin/ips/$NEW_IP
|
||||
if [ ! -e $IPFILE_NEW ]; then
|
||||
echo -n "$IPFILE_NEW does not exist. Exiting... ";
|
||||
exit 3;
|
||||
fi
|
||||
IP_STATUS=`grep status ${IPFILE_NEW} | cut -d= -f2`
|
||||
if [ "${IP_STATUS}" != "shared" ]; then
|
||||
echo "Please make the IP (${NEW_IP}) shared on reseller level."
|
||||
exit 4;
|
||||
fi
|
||||
|
||||
ULDDU=/usr/local/directadmin/data/users
|
||||
if [ ! -e ${ULDDU}/${RESELLER}/users.list ]; then
|
||||
echo "Reseller ${RESELLER} does not exist. Exiting... ";
|
||||
exit 5;
|
||||
fi
|
||||
|
||||
IP_LIST=${ULDDU}/${RESELLER}/ip.list
|
||||
COUNT_IP=`grep -c ${NEW_IP} ${IP_LIST}`
|
||||
if [ ${COUNT_IP} -eq 0 ]; then
|
||||
echo "${NEW_IP} does not belong to ${RESELLER}. Please assign it to reseller and start the script again. Exiting."
|
||||
exit 6;
|
||||
fi
|
||||
|
||||
OS=`uname`
|
||||
if [ $OS = "FreeBSD" ]; then
|
||||
DB_PATH=/etc/namedb
|
||||
else
|
||||
if [ -e /etc/debian_version ]; then
|
||||
DB_PATH=/etc/bind
|
||||
else
|
||||
DB_PATH=/var/named
|
||||
fi
|
||||
fi
|
||||
|
||||
for i in `cat ${ULDDU}/${RESELLER}/users.list && echo "${RESELLER}"`; do
|
||||
{
|
||||
if [ ! -d $ULDDU/$i ]; then
|
||||
continue;
|
||||
fi
|
||||
|
||||
swapfile $ULDDU/$i/user.conf
|
||||
if [ "${HAVE_HTTPD}" -eq 1 ]; then
|
||||
swapfile $ULDDU/$i/httpd.conf
|
||||
fi
|
||||
if [ "${HAVE_NGINX}" -eq 1 ]; then
|
||||
swapfile $ULDDU/$i/nginx.conf
|
||||
fi
|
||||
|
||||
if [ -e $ULDDU/$i/ip.list ]; then
|
||||
swapfile $ULDDU/$i/ip.list
|
||||
fi
|
||||
|
||||
swapfile $ULDDU/$i/user_ip.list
|
||||
|
||||
for j in `ls $ULDDU/$i/domains/*.conf; ls $ULDDU/$i/domains/*.ftp; ls $ULDDU/$i/domains/*.ip_list`; do
|
||||
{
|
||||
swapfile $j
|
||||
};
|
||||
done;
|
||||
|
||||
for d in `cat ${ULDDU}/$i/domains.list`; do
|
||||
{
|
||||
swapfile ${DB_PATH}/$d.db
|
||||
echo "action=rewrite&value=named&domain=$d" >> /usr/local/directadmin/data/task.queue
|
||||
|
||||
for p in `cat ${ULDDU}/$i/domains/$d.pointers | cut -d= -f1 2>/dev/null`; do
|
||||
{
|
||||
swapfile ${DB_PATH}/$p.db
|
||||
echo "action=rewrite&value=named&domain=$p" >> /usr/local/directadmin/data/task.queue
|
||||
}
|
||||
done;
|
||||
};
|
||||
done;
|
||||
};
|
||||
done;
|
||||
|
||||
echo "action=rewrite&value=ipcount" >> /usr/local/directadmin/data/task.queue
|
||||
echo "action=rewrite&value=ips" >> /usr/local/directadmin/data/task.queue
|
||||
echo "action=cache&value=showallusers" >> /usr/local/directadmin/data/task.queue
|
||||
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
|
||||
echo "Runing dataskq..."
|
||||
/usr/local/directadmin/dataskq d
|
||||
|
||||
log "\n*** Done swapping $OLD_IP to $NEW_IP ***\n";
|
||||
exit 0;
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/bin/sh
|
||||
SYSTEMDDIR=/etc/systemd/system
|
||||
if [ -d ${SYSTEMDDIR} ] && [ -e /usr/bin/systemctl ]; then
|
||||
echo "yes";
|
||||
exit 0;
|
||||
fi
|
||||
echo "no";
|
||||
exit 1;
|
||||
@@ -1,83 +0,0 @@
|
||||
#!/bin/sh
|
||||
#Script to install majordomo
|
||||
|
||||
OS=`uname`
|
||||
|
||||
SERVER=http://files.directadmin.com/services/all/majordomo
|
||||
ADDPATCHES=1
|
||||
|
||||
SOURCEPATH="/usr/local/directadmin/scripts/packages/majordomo-1.94.5"
|
||||
|
||||
if [ ! -e ${SOURCEPATH}/Makefile ]
|
||||
then
|
||||
echo "The source path for majordomo does not exist. Make sure the correct path is set in majordomo.sh";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
/bin/mkdir -p /etc/virtual/majordomo
|
||||
|
||||
MDGID=`id -g daemon`
|
||||
|
||||
if [ -e /etc/debian_version ]; then
|
||||
/usr/sbin/groupadd nobody 2>/dev/null
|
||||
/usr/sbin/useradd -d /etc/virtual/majordomo -g $MDGID -s /bin/false majordomo 2> /dev/null
|
||||
elif [ "$OS" = "FreeBSD" ]; then
|
||||
/usr/sbin/pw useradd majordomo -b /etc/virtual/majordomo -g daemon -s /sbin/nologin 2> /dev/null
|
||||
else
|
||||
/usr/sbin/useradd -d /etc/virtual/majordomo -g $MDGID majordomo -s /bin/false -n -r 2> /dev/null
|
||||
fi
|
||||
|
||||
MDUID=`id -u majordomo`
|
||||
|
||||
/usr/bin/perl -pi -e 's/PERL = .*/PERL = \/usr\/bin\/perl/' ${SOURCEPATH}/Makefile;
|
||||
/usr/bin/perl -pi -e 's/W_HOME = .*/W_HOME = \/etc\/virtual\/majordomo/' ${SOURCEPATH}/Makefile;
|
||||
|
||||
#Perl and Bash weren't getting along. MDUID wasn't showing up so I did it this way.
|
||||
STR="/usr/bin/perl -pi -e 's/W_USER = .*/W_USER = ${MDUID}/' ${SOURCEPATH}/Makefile";
|
||||
eval $STR;
|
||||
|
||||
STR="/usr/bin/perl -pi -e 's/W_GROUP = .*/W_GROUP = ${MDGID}/' ${SOURCEPATH}/Makefile";
|
||||
eval $STR;
|
||||
|
||||
STR="/usr/bin/perl -pi -e 's/TMPDIR = .*/TMPDIR = \/tmp/' ${SOURCEPATH}/Makefile";
|
||||
eval $STR;
|
||||
|
||||
|
||||
#fix REALLY-TO value in digests file
|
||||
STR="/usr/bin/perl -pi -e 's/\$ARGV\[0\];/\$ARGV\[0\].\${whereami};/' ${SOURCEPATH}/digest";
|
||||
eval $STR;
|
||||
|
||||
STR="/usr/bin/perl -pi -e 's#/usr/test/majordomo#/etc/virtual/majordomo#' ${SOURCEPATH}/sample.cf";
|
||||
eval $STR;
|
||||
|
||||
cd ${SOURCEPATH};
|
||||
|
||||
make wrapper
|
||||
make install
|
||||
make install-wrapper
|
||||
|
||||
/usr/bin/perl -pi -e 's#/usr/test/majordomo#/etc/virtual/majordomo#' /etc/virtual/majordomo/majordomo.cf
|
||||
|
||||
if [ $ADDPATCHES -eq 0 ]; then
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
PATCH1=majordomo.patch
|
||||
PATCH1_PATH=/etc/virtual/majordomo/${PATCH1}
|
||||
if [ ! -s "${PATCH1_PATH}" ]; then
|
||||
wget -O ${PATCH1_PATH} ${SERVER}/${PATCH1}
|
||||
fi
|
||||
|
||||
if [ -s "${PATCH1_PATH}" ]; then
|
||||
cd /etc/virtual/majordomo
|
||||
patch -p0 < majordomo.patch
|
||||
else
|
||||
echo "Cannot find ${PATCH1_PATH} to patch majordomo.";
|
||||
fi
|
||||
|
||||
#just to put up back where we were.. likely not needed.
|
||||
cd ${SOURCEPATH};
|
||||
|
||||
chmod 750 /etc/virtual/majordomo
|
||||
|
||||
exit 0
|
||||
@@ -1,433 +0,0 @@
|
||||
#!/bin/sh
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to move domain from one user to another
|
||||
# Official DirectAdmin webpage: http://www.directadmin.com
|
||||
# Usage:
|
||||
# ./move_domain.sh <domain> <olduser> <newuser>
|
||||
|
||||
VERSION=0.3
|
||||
|
||||
OS=`uname`
|
||||
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "$MYUID" != 0 ]; then
|
||||
echo "You require Root Access to run this script.";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ $# != 3 ]; then
|
||||
echo "Move Domain to User - v. $VERSION";
|
||||
echo "";
|
||||
echo "Usage:";
|
||||
echo "$0 <domain> <olduser> <newuser>";
|
||||
echo "you gave #$#: $0 $1 $2 $3";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
DOMAIN=$1
|
||||
OLD_USER=$2
|
||||
NEW_USER=$3
|
||||
|
||||
TEMP="grep -e '^$OLD_USER:' /etc/passwd | cut -d: -f6"
|
||||
OLD_HOME=`eval $TEMP`
|
||||
TEMP="grep -e '^$NEW_USER:' /etc/passwd | cut -d: -f6"
|
||||
NEW_HOME=`eval $TEMP`
|
||||
|
||||
OLD_DOMAIN_DIR=${OLD_HOME}/domains/${DOMAIN}
|
||||
NEW_DOMAIN_DIR=${NEW_HOME}/domains/${DOMAIN}
|
||||
|
||||
DATA_USER_OLD=/usr/local/directadmin/data/users/${OLD_USER}/
|
||||
DATA_USER_NEW=/usr/local/directadmin/data/users/${NEW_USER}/
|
||||
USER_OLD=${DATA_USER_OLD}domains.list
|
||||
USER_NEW=${DATA_USER_NEW}domains.list
|
||||
|
||||
APACHE_PUBLIC_HTML=`/usr/local/directadmin/directadmin c | grep apache_public_html | cut -d= -f2`
|
||||
|
||||
PERL=/usr/bin/perl
|
||||
|
||||
IP_SWAP=/usr/local/directadmin/scripts/ipswap.sh
|
||||
|
||||
ROOT_GROUP=root
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
ROOT_GROUP=wheel
|
||||
fi
|
||||
|
||||
update_email_domain_dir()
|
||||
{
|
||||
#/etc/virtual/domain.com
|
||||
DMNDIR=/etc/virtual/${DOMAIN}
|
||||
if [ ! -e ${DMNDIR} ] && [ -e ${DMNDIR}_off ]; then
|
||||
DMNDIR=${DMNDIR}_off
|
||||
echo "domain ${DOMAIN} is suspended using ${DMNDIR}";
|
||||
fi
|
||||
if [ ! -e ${DMNDIR} ]; then
|
||||
echo "Cannot find ${DMNDIR}, aborting swap of ${DMNDIR}."
|
||||
return;
|
||||
fi
|
||||
|
||||
#passwd (doveoct)
|
||||
#aliases
|
||||
#filter (home path)
|
||||
#usage.cache
|
||||
#majordomo/list.aliases: $OLD_USER@$DOMAIN
|
||||
#majordomo/lists/*: $OLD_USER@$DOMAIN
|
||||
|
||||
|
||||
#TEMP="$PERL -pi -e 's#${OLD_HOME}#${NEW_HOME}#' ${DMNDIR}/passwd"
|
||||
#eval $TEMP;
|
||||
|
||||
OLD_GID=`/usr/bin/id -g mail`
|
||||
OLD_UID=`/usr/bin/id -u $OLD_USER`
|
||||
NEW_GID=`/usr/bin/id -g mail`
|
||||
NEW_UID=`/usr/bin/id -u $NEW_USER`
|
||||
|
||||
#Firt find the uid/gid swap them.
|
||||
TEMP="perl -pi -e 's#:${OLD_UID}:${OLD_GID}::${OLD_HOME}/#:${NEW_UID}:${NEW_GID}::${NEW_HOME}/#' ${DMNDIR}/passwd"
|
||||
eval $TEMP;
|
||||
|
||||
#/etc/virtual/domain.com/aliases
|
||||
|
||||
TEMP="$PERL -pi -e 's/(^|\s|:)${OLD_USER}(:|\$|,)/\${1}${NEW_USER}\${2}/g' ${DMNDIR}/aliases"
|
||||
eval $TEMP;
|
||||
eval $TEMP; #for the case of admin:admin where there is no white space. Needs to be run twice.
|
||||
|
||||
TEMP="$PERL -pi -e 's#${OLD_HOME}#${NEW_HOME}#' ${DMNDIR}/filter"
|
||||
eval $TEMP;
|
||||
|
||||
if [ -e ${DMNDIR}/usage.cache ]; then
|
||||
TEMP="$PERL -pi -e 's/^${OLD_USER}:/${NEW_USER}/' ${DMNDIR}/usage.cache"
|
||||
eval $TEMP;
|
||||
fi
|
||||
|
||||
OLD_EMAIL=${OLD_USER}@${DOMAIN}
|
||||
NEW_EMAIL=${NEW_USER}@${DOMAIN}
|
||||
|
||||
if [ -e ${DMNDIR}/majordomo ]; then
|
||||
TEMP="$PERL -pi -e 's/${OLD_EMAIL}/${NEW_EMAIL}/' ${DMNDIR}/majordomo/list.aliases";
|
||||
eval $TEMP
|
||||
TEMP="$PERL -pi -e 's/${OLD_EMAIL}/${NEW_EMAIL}/' ${DMNDIR}/majordomo/lists/*";
|
||||
eval $TEMP
|
||||
fi
|
||||
}
|
||||
|
||||
update_email_settings()
|
||||
{
|
||||
echo "Updating email settings."
|
||||
|
||||
#/etc/virtual/domainowners
|
||||
#/etc/virtual/snidomains
|
||||
#/etc/virtual/domain.com(_off) (this will be large)
|
||||
#/home/username/.spamassassin/user_spam/user@domain.com
|
||||
#/home/username/imap/domain.com
|
||||
#/var/spool/virtual/domain.com (permissions only)
|
||||
#/etc/dovecot/conf/sni/domain.com.conf
|
||||
|
||||
#domainowners
|
||||
TEMP="$PERL -pi -e 's/^${DOMAIN}: ${OLD_USER}\$/${DOMAIN}: ${NEW_USER}/' /etc/virtual/domainowners"
|
||||
eval $TEMP
|
||||
|
||||
#snidomains
|
||||
if [ -s /etc/virtual/snidomains ]; then
|
||||
TEMP="$PERL -pi -e 's/:${OLD_USER}:${DOMAIN}\$/:${NEW_USER}:${DOMAIN}/' /etc/virtual/snidomains"
|
||||
eval $TEMP
|
||||
fi
|
||||
|
||||
#repeat for domain pointers too.
|
||||
#at this stage, the domain.com.pointers file has already been moved.
|
||||
for p in `cat /usr/local/directadmin/data/users/${NEW_USER}/domains/${DOMAIN}.pointers | cut -d= -f1`; do
|
||||
{
|
||||
TEMP="$PERL -pi -e 's/^${p}: ${OLD_USER}\$/${p}: ${NEW_USER}/' /etc/virtual/domainowners"
|
||||
eval $TEMP
|
||||
};
|
||||
done;
|
||||
|
||||
#/etc/virtual/domain.com
|
||||
update_email_domain_dir
|
||||
|
||||
#/home/username/.spamassassin/user_spam/user@domain.com
|
||||
OLD_SADIR=${OLD_HOME}/.spamassassin/user_spam
|
||||
NEW_SADIR=${NEW_HOME}/.spamassassin/user_spam
|
||||
#if it doesnt exist, dont bother
|
||||
if [ -e ${OLD_SADIR} ]; then
|
||||
mkdir -p $NEW_SADIR
|
||||
mv ${OLD_SADIR}/*@${DOMAIN} ${NEW_SADIR}/
|
||||
chown -R ${NEW_USER}:mail ${NEW_SADIR}
|
||||
chmod 771 ${NEW_SADIR}
|
||||
chmod 660 ${NEW_SADIR}/*
|
||||
fi
|
||||
|
||||
#/home/username/imap/domain.com
|
||||
OLD_IMAP=${OLD_HOME}/imap/${DOMAIN}
|
||||
NEW_IMAP=${NEW_HOME}/imap/${DOMAIN}
|
||||
if [ -e ${OLD_IMAP} ]; then
|
||||
if [ -e ${NEW_IMAP} ]; then
|
||||
echo "$NEW_IMAP already exists.. merging as best we can.";
|
||||
mv -f ${OLD_IMAP}/* ${NEW_IMAP}/
|
||||
else
|
||||
if [ ! -e "${NEW_HOME}/imap" ]; then
|
||||
mkdir -p ${NEW_HOME}/imap
|
||||
chown ${NEW_USER}:mail ${NEW_HOME}/imap
|
||||
chmod 770 ${NEW_HOME}/imap
|
||||
fi
|
||||
mv -f ${OLD_IMAP} ${NEW_IMAP}
|
||||
fi
|
||||
|
||||
chown -R ${NEW_USER}:mail ${NEW_IMAP}
|
||||
chmod -R 770 ${NEW_IMAP}
|
||||
fi
|
||||
|
||||
#symlinks for domain pointers
|
||||
for p in `cat /usr/local/directadmin/data/users/${NEW_USER}/domains/${DOMAIN}.pointers | cut -d= -f1`; do
|
||||
{
|
||||
ALIAS=${NEW_HOME}/imap/$p
|
||||
ln -s ${DOMAIN} ${ALIAS}
|
||||
chown -h ${NEW_USER}:mail ${ALIAS}
|
||||
};
|
||||
done;
|
||||
|
||||
#/var/spool/virtual/domain.com (permissions only)
|
||||
VPV=/var/spool/virtual/${DOMAIN}
|
||||
if [ -e ${VPV} ]; then
|
||||
chown -R ${NEW_USER}:mail $VPV
|
||||
fi
|
||||
|
||||
#/etc/dovecot/conf/sni/domain.com.conf
|
||||
SNI_CONF=/etc/dovecot/conf/sni/${DOMAIN}.conf
|
||||
if [ -s ${SNI_CONF} ]; then
|
||||
TEMP="/usr/bin/perl -pi -e 's#${DATA_USER_OLD}#${DATA_USER_NEW}#g' ${SNI_CONF}"
|
||||
eval $TEMP;
|
||||
fi
|
||||
}
|
||||
|
||||
update_ftp_settings()
|
||||
{
|
||||
echo "Updating ftp settings."
|
||||
|
||||
#/etc/proftpd.passwd
|
||||
#/usr/local/directadmin/data/users/user/ftp.passwd
|
||||
#/etc/proftpd.vhosts.conf
|
||||
|
||||
#for the password files, we only chagne the user@domain.com accounts.
|
||||
#the system account isn't touched.
|
||||
|
||||
OLD_GID=`/usr/bin/id -g $OLD_USER`
|
||||
OLD_UID=`/usr/bin/id -u $OLD_USER`
|
||||
NEW_GID=`/usr/bin/id -g $NEW_USER`
|
||||
NEW_UID=`/usr/bin/id -u $NEW_USER`
|
||||
|
||||
#proftpd.passwd. Firt find the uid/gid and homedir matchup and swap them.
|
||||
TEMP="perl -pi -e 's#:${OLD_UID}:${OLD_GID}:(domain|user|custom):${OLD_DOMAIN_DIR}#:${NEW_UID}:${NEW_GID}:\${1}:${NEW_DOMAIN_DIR}#' /etc/proftpd.passwd"
|
||||
eval $TEMP;
|
||||
|
||||
#proftpd.passwd ... then whatever is leftover (eg, anonymous)
|
||||
TEMP="$PERL -pi -e 's#:${OLD_DOMAIN_DIR}#:${NEW_DOMAIN_DIR}#' /etc/proftpd.passwd"
|
||||
eval $TEMP
|
||||
|
||||
|
||||
|
||||
#ftp.passwd ... this one is messier..
|
||||
#take all accounts with /home/user/domain/doamin.com in them, and move them to the new ftp.passwd, with the new home.
|
||||
|
||||
OLD_FTP=/usr/local/directadmin/data/users/${OLD_USER}/ftp.passwd
|
||||
NEW_FTP=/usr/local/directadmin/data/users/${NEW_USER}/ftp.passwd
|
||||
TEMP_FTP=/usr/local/directadmin/data/users/${OLD_USER}/ftp.passwd.temp
|
||||
|
||||
grep ":$OLD_DOMAIN_DIR" $OLD_FTP > $TEMP_FTP
|
||||
TEMP="$PERL -pi -e 's#:${OLD_DOMAIN_DIR}#:${NEW_DOMAIN_DIR}#' $TEMP_FTP"
|
||||
eval $TEMP
|
||||
|
||||
cat $TEMP_FTP >> $NEW_FTP
|
||||
|
||||
#now, take out the old paths
|
||||
grep -v ":$OLD_DOMAIN_DIR" $OLD_FTP > $TEMP_FTP
|
||||
mv -f $TEMP_FTP $OLD_FTP
|
||||
chown root:ftp $OLD_FTP
|
||||
}
|
||||
|
||||
update_da_settings()
|
||||
{
|
||||
echo "Moving domain data to the ${NEW_USER} user."
|
||||
mv -f ${OLD_DOMAIN_DIR} ${NEW_DOMAIN_DIR}
|
||||
mv -f /usr/local/directadmin/data/users/${OLD_USER}/domains/${DOMAIN}.* /usr/local/directadmin/data/users/${NEW_USER}/domains/
|
||||
|
||||
echo "Setting ownership for ${DOMAIN} domain."
|
||||
chown -R ${NEW_USER}:${NEW_USER} ${NEW_DOMAIN_DIR}
|
||||
|
||||
if [ "$APACHE_PUBLIC_HTML" -eq 1 ]; then
|
||||
echo "apache_public_html=1 is set, updating public_html and private_html in ${NEW_DOMAIN_DIR}";
|
||||
chmod 750 ${NEW_DOMAIN_DIR}/public_html ${NEW_DOMAIN_DIR}/private_html
|
||||
chgrp apache ${NEW_DOMAIN_DIR}/public_html ${NEW_DOMAIN_DIR}/private_html
|
||||
fi
|
||||
|
||||
if [ -e ${NEW_DOMAIN_DIR}/stats ]; then
|
||||
echo "Setting stats directory ownership for ${DOMAIN} domain.";
|
||||
chown -R root:${ROOT_GROUP} ${NEW_DOMAIN_DIR}/stats
|
||||
fi
|
||||
|
||||
echo "Removing domain from ${OLD_USER} user."
|
||||
$PERL -pi -e "s#^${DOMAIN}\n##g" ${USER_OLD}
|
||||
|
||||
echo "Adding domain to ${NEW_USER} user."
|
||||
echo "${DOMAIN}" >> ${USER_NEW}
|
||||
$PERL -pi -e "s#/usr/local/directadmin/data/users/${OLD_USER}/#/usr/local/directadmin/data/users/${NEW_USER}/#g" /usr/local/directadmin/data/users/${NEW_USER}/domains/${DOMAIN}.*
|
||||
$PERL -pi -e "s#${OLD_HOME}/#${NEW_HOME}/#g" /usr/local/directadmin/data/users/${NEW_USER}/domains/${DOMAIN}.*
|
||||
|
||||
#ensure the user.conf doesn't have the old domain. No need for new User, as they'd already have a default.
|
||||
USER_CONF=${DATA_USER_OLD}/user.conf
|
||||
C=`grep -c "^domain=${DOMAIN}\$" $USER_CONF`
|
||||
if [ "${C}" -gt 0 ]; then
|
||||
#figure out a new default domain..
|
||||
DEFAULT_DOMAIN=`cat ${USER_OLD} | head -n1`
|
||||
#may be filled.. may be empty.
|
||||
perl -pi -e "s/^domain=${DOMAIN}\$/domain=${DEFAULT_DOMAIN}/" ${USER_CONF}
|
||||
|
||||
#if the new default domain exists, reset the ~/public_html link.
|
||||
PUB_LINK=${OLD_HOME}/public_html
|
||||
NEW_DEF_DOMAIN_DIR=${OLD_HOME}/domains/${DEFAULT_DOMAIN}/public_html
|
||||
NEW_DEF_DOMAIN_DIR_RELATIVE=./domains/${DEFAULT_DOMAIN}/public_html
|
||||
if [ -h "${PUB_LINK}" ] && [ "${DEFAULT_DOMAIN}" != "" ] && [ -d "${NEW_DEF_DOMAIN_DIR}" ]; then
|
||||
rm -f ${PUB_LINK}
|
||||
ln -s ${NEW_DEF_DOMAIN_DIR_RELATIVE} ${PUB_LINK}
|
||||
chown -h ${OLD_USER}:${OLD_USER} ${PUB_LINK}
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
echo "Changing domain owner."
|
||||
for i in `ls /usr/local/directadmin/data/users/${NEW_USER}/domains/${DOMAIN}.conf`; do { $PERL -pi -e "s/username=${OLD_USER}/username=${NEW_USER}/g" $i; }; done;
|
||||
|
||||
|
||||
#ip swapping, if needed.
|
||||
#empty the domain.ip_list, except 1 IP.
|
||||
USER_PATH=/usr/local/directadmin/data/users/${NEW_USER}
|
||||
OLD_IP=`grep "^ip=" ${USER_PATH}/domains/${DOMAIN}.conf | cut -d= -f2`
|
||||
NEW_IP=`grep "^ip=" ${USER_PATH}/user.conf | cut -d= -f2`
|
||||
if [ "${OLD_IP}" != "${NEW_IP}" ]; then
|
||||
echo "The old IP (${OLD_IP}) does not match the new IP (${NEW_IP}). Swapping...";
|
||||
#./ipswap.sh <oldip> <newip> [<file>]
|
||||
$IP_SWAP $OLD_IP $NEW_IP ${USER_PATH}/domains/${DOMAIN}.conf
|
||||
$IP_SWAP $OLD_IP $NEW_IP ${USER_PATH}/domains/${DOMAIN}.ftp
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
$IP_SWAP $OLD_IP $NEW_IP /etc/namedb/${DOMAIN}.db
|
||||
else
|
||||
if [ -e /etc/debian_version ]; then
|
||||
$IP_SWAP $OLD_IP $NEW_IP /etc/bind/${DOMAIN}.db
|
||||
else
|
||||
$IP_SWAP $OLD_IP $NEW_IP /var/named/${DOMAIN}.db
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "${NEW_IP}" > ${USER_PATH}/domains/${DOMAIN}.ip_list
|
||||
|
||||
#update the serial:
|
||||
echo "action=rewrite&value=named&domain=${DOMAIN}" >> /usr/local/directadmin/data/task.queue
|
||||
fi
|
||||
|
||||
#Update .htaccess files in case there is a protected password directory.
|
||||
PROTECTED_LIST=${NEW_DOMAIN_DIR}/.htpasswd/.protected.list
|
||||
if [ -s "${PROTECTED_LIST}" ]; then
|
||||
echo "Updating protected directories via ${PROTECTED_LIST}";
|
||||
for i in `cat ${PROTECTED_LIST}`; do
|
||||
{
|
||||
D=$NEW_HOME/$i
|
||||
if [ ! -d ${D} ]; then
|
||||
echo "Cannot find a directory at ${D}";
|
||||
continue;
|
||||
fi
|
||||
|
||||
HTA=${D}/.htaccess
|
||||
if [ ! -s ${HTA} ]; then
|
||||
echo "${HTA} appears to be empty.";
|
||||
continue;
|
||||
fi
|
||||
|
||||
$PERL -pi -e "s#AuthUserFile ${OLD_HOME}/#AuthUserFile ${NEW_HOME}/#" ${HTA}
|
||||
};
|
||||
done;
|
||||
fi
|
||||
|
||||
#complex bug: if multi-ip was used, should go into the zone and surgically remove the old ips from the zone, leaving only the NEW_IP.
|
||||
|
||||
|
||||
#this is needed to update "show all users" cache.
|
||||
echo "action=cache&value=showallusers" >> /usr/local/directadmin/data/task.queue
|
||||
#this is needed to rewrite /usr/local/directadmin/data/users/USERS/httpd.conf
|
||||
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
|
||||
/usr/local/directadmin/dataskq d
|
||||
|
||||
}
|
||||
|
||||
update_awstats()
|
||||
{
|
||||
TEMP="/usr/bin/perl -pi -e 's#/home/${OLD_USER}/#/home/${NEW_USER}/#g' /home/${NEW_USER}/domains/${DOMAIN}/awstats/.data/*.conf"
|
||||
eval $TEMP;
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#/home/${OLD_USER}/#/home/${NEW_USER}/#g' /home/${NEW_USER}/domains/${DOMAIN}/awstats/awstats.pl"
|
||||
eval $TEMP;
|
||||
|
||||
#And for subdomains:
|
||||
TEMP="/usr/bin/perl -pi -e 's#/home/${OLD_USER}/#/home/${NEW_USER}/#g' /home/${NEW_USER}/domains/${DOMAIN}/awstats/*/.data/*.conf"
|
||||
eval $TEMP;
|
||||
|
||||
TEMP="/usr/bin/perl -pi -e 's#/home/${OLD_USER}/#/home/${NEW_USER}/#g' /home/${NEW_USER}/domains/${DOMAIN}/awstats/*/awstats.pl"
|
||||
eval $TEMP;
|
||||
}
|
||||
|
||||
doChecks()
|
||||
{
|
||||
if [ ! -e ${USER_OLD} ]; then
|
||||
echo "File ${USER_OLD} does not exist. Can not continue."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "${DOMAIN}" = "" ]; then
|
||||
echo "The domain is blank";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "${OLD_HOME}" = "" ]; then
|
||||
echo "the old home is blank";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "${NEW_HOME}" = "" ]; then
|
||||
echo "the new home is blank";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ ! -e ${USER_NEW} ]; then
|
||||
echo "File ${USER_NEW} does not exist. Can not continue."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "`grep -wc ${DOMAIN} $USER_OLD`" = "0" ]; then
|
||||
echo "Domain ${DOMAIN} is not owned by ${OLD_USER} user."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ ! -d ${OLD_DOMAIN_DIR} ]; then
|
||||
echo "Direcory ${OLD_DOMAIN_DIR} does not exist. Can not continue."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ -d ${NEW_DOMAIN_DIR} ]; then
|
||||
echo "Direcory ${NEW_DOMAIN_DIR} exists. Can not continue."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ ! -e $PERL ]; then
|
||||
echo "$PERL does not exist.";
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
doChecks
|
||||
update_da_settings
|
||||
update_email_settings
|
||||
update_ftp_settings
|
||||
update_awstats
|
||||
|
||||
echo "Domain has been moved to ${NEW_USER} user."
|
||||
|
||||
exit 0;
|
||||
@@ -1,105 +0,0 @@
|
||||
#!/bin/sh
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to move user from one reseller to another
|
||||
# Official DirectAdmin webpage: http://www.directadmin.com
|
||||
# Usage:
|
||||
# ./move_user_to_reseller.sh <user> <oldreseller> <newreseller>
|
||||
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "$MYUID" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ $# != 3 ]; then
|
||||
echo "Usage:";
|
||||
echo "$0 <user> <oldreseller> <newreseller>";
|
||||
echo "you gave #$#: $0 $1 $2 $3";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
OLD_RESELLER=$2
|
||||
NEW_RESELLER=$3
|
||||
|
||||
RESELLER_OLD=/usr/local/directadmin/data/users/$2/users.list
|
||||
RESELLER_NEW=/usr/local/directadmin/data/users/$3/users.list
|
||||
|
||||
USERN=$1
|
||||
|
||||
if [ ! -e ${RESELLER_OLD} ]; then
|
||||
echo "File ${RESELLER_OLD} does not exist. Can not continue."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ ! -e ${RESELLER_NEW} ]; then
|
||||
echo "File ${RESELLER_NEW} does not exist. Can not continue."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "`grep -wc $USERN $RESELLER_OLD`" = "0" ]; then
|
||||
echo "User $USERN is not owned by $2 reseller"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/perl ]; then
|
||||
echo "/usr/bin/perl does not exist";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
isOwned()
|
||||
{
|
||||
IP=$1
|
||||
IPF=/usr/local/directadmin/data/admin/ips/$IP
|
||||
if [ ! -s $IPF ]; then
|
||||
#good spot for an error message, but can't echo anything
|
||||
echo "0";
|
||||
return;
|
||||
fi
|
||||
IPSTATUS=`grep status= $IPF | cut -d= -f2`;
|
||||
if [ "$IPSTATUS" = "owned" ]; then
|
||||
echo "1";
|
||||
else
|
||||
echo "0";
|
||||
fi
|
||||
}
|
||||
|
||||
#ensure IPs are brought forward
|
||||
for i in `cat /usr/local/directadmin/data/users/$USERN/user_ip.list`; do
|
||||
{
|
||||
if [ "`isOwned $i`" = "1" ]; then
|
||||
echo "$i is owned. Moving the IP to the new Reseller";
|
||||
|
||||
perl -pi -e "s#$i\n##g" /usr/local/directadmin/data/users/$OLD_RESELLER/ip.list
|
||||
echo "$i" >> /usr/local/directadmin/data/users/$NEW_RESELLER/ip.list
|
||||
|
||||
perl -pi -e "s#reseller=$OLD_RESELLER#reseller=$NEW_RESELLER#g" /usr/local/directadmin/data/admin/ips/$i
|
||||
else
|
||||
echo "$i is shared. Leaving the IP with the old Reseller";
|
||||
fi
|
||||
};
|
||||
done;
|
||||
|
||||
|
||||
echo "Removing user from $2 reseller"
|
||||
perl -pi -e "s#$USERN\n##g" /usr/local/directadmin/data/users/$2/users.list
|
||||
|
||||
echo "Adding user to $3 reseller"
|
||||
echo "$USERN" >> /usr/local/directadmin/data/users/$3/users.list
|
||||
|
||||
echo "Changing user owner"
|
||||
for i in `ls /usr/local/directadmin/data/users/$USERN/domains/*.conf`; do { perl -pi -e "s/creator=$2/creator=$3/g" $i; }; done;
|
||||
|
||||
#change the user.conf
|
||||
perl -pi -e "s/creator=$2/creator=$3/" /usr/local/directadmin/data/users/$USERN/user.conf
|
||||
|
||||
#this is needed to update "show all users" cache.
|
||||
echo "action=cache&value=showallusers" >> /usr/local/directadmin/data/task.queue
|
||||
echo "action=rewrite&value=httpd&user=$USERN" >> /usr/local/directadmin/data/task.queue
|
||||
|
||||
#messy bit that removes the user from the backup_crons.list, but only for type=reseller backups.
|
||||
#the user is left in the admin backups still in the type=admin backups.
|
||||
perl -pi -e "s/select[0-9]+=$USERN&(.*)(type=reseller)/\$1\$2/" /usr/local/directadmin/data/admin/backup_crons.list
|
||||
|
||||
echo "User has been moved to $3"
|
||||
|
||||
exit 0;
|
||||
@@ -1,126 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# named This shell script takes care of starting and stopping
|
||||
# named (BIND DNS server).
|
||||
#
|
||||
# chkconfig: - 55 45
|
||||
# description: named (BIND) is a Domain Name Server (DNS) \
|
||||
# that is used to resolve host names to IP addresses.
|
||||
# probe: true
|
||||
|
||||
# Source function library.
|
||||
. /etc/rc.d/init.d/functions
|
||||
|
||||
# Source networking configuration.
|
||||
. /etc/sysconfig/network
|
||||
|
||||
# Check that networking is up.
|
||||
[ "${NETWORKING}" = "no" ] && exit 0
|
||||
|
||||
[ -f /etc/sysconfig/named ] && . /etc/sysconfig/named
|
||||
|
||||
[ -f /usr/sbin/named ] || exit 0
|
||||
|
||||
[ -f ${ROOTDIR}/etc/named.conf ] || exit 0
|
||||
|
||||
RETVAL=0
|
||||
prog="named"
|
||||
|
||||
start() {
|
||||
# Start daemons.
|
||||
if [ -n "`/sbin/pidof named`" ]; then
|
||||
echo -n $"$prog: already running"
|
||||
return 1
|
||||
fi
|
||||
echo -n $"Starting $prog: "
|
||||
if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
|
||||
OPTIONS="${OPTIONS} -t ${ROOTDIR}"
|
||||
fi
|
||||
# Since named doesn't return proper exit codes at the moment
|
||||
# (won't be fixed before 9.2), we can't use daemon here - emulate
|
||||
# its functionality
|
||||
base=$prog
|
||||
named -u named ${OPTIONS}
|
||||
RETVAL=$?
|
||||
usleep 100000
|
||||
if [ -z "`/sbin/pidof named`" ]; then
|
||||
# The child processes have died after fork()ing, e.g.
|
||||
# because of a broken config file
|
||||
RETVAL=1
|
||||
fi
|
||||
[ $RETVAL -ne 0 ] && failure $"$base startup"
|
||||
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/named && success $"$base startup"
|
||||
echo
|
||||
return $RETVAL
|
||||
}
|
||||
stop() {
|
||||
# Stop daemons.
|
||||
echo -n $"Stopping $prog: "
|
||||
killproc named
|
||||
RETVAL=$?
|
||||
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/named
|
||||
echo
|
||||
return $RETVAL
|
||||
}
|
||||
rhstatus() {
|
||||
status named
|
||||
return $?
|
||||
}
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
reload() {
|
||||
#/usr/sbin/rndc reload >/dev/null 2>&1 || /usr/bin/killall -HUP named
|
||||
|
||||
PID=/var/run/named/named.pid
|
||||
if [ ! -e $PID ]; then
|
||||
PID=/var/run/named.pid
|
||||
fi
|
||||
RET=0;
|
||||
if [ ! -e $PID ]; then
|
||||
killall -HUP named
|
||||
RET=$?
|
||||
else
|
||||
kill -HUP `cat $PID`
|
||||
RET=$?
|
||||
fi
|
||||
return $RET
|
||||
}
|
||||
probe() {
|
||||
# named knows how to reload intelligently; we don't want linuxconf
|
||||
# to offer to restart every time
|
||||
/usr/sbin/rndc reload >/dev/null 2>&1 || echo start
|
||||
return $?
|
||||
}
|
||||
|
||||
# See how we were called.
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
status)
|
||||
rhstatus
|
||||
;;
|
||||
restart)
|
||||
restart
|
||||
;;
|
||||
condrestart)
|
||||
[ -f /var/lock/subsys/named ] && restart
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
probe)
|
||||
probe
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|probe}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit $?
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
CWD=`pwd`
|
||||
|
||||
NAME=ncftp
|
||||
VERSION=3.2.6
|
||||
PRIMARY=http://files.directadmin.com/services
|
||||
SECONDARY=http://files3.directadmin.com/services
|
||||
SAVE=/usr/local/directadmin/scripts/packages
|
||||
FILE=${NAME}-${VERSION}-src.tar.gz
|
||||
DIR=${NAME}-${VERSION}
|
||||
|
||||
OS=`uname`
|
||||
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
WGET=/usr/local/bin/wget
|
||||
else
|
||||
WGET=/usr/bin/wget
|
||||
fi
|
||||
|
||||
if [ ! -s $SAVE/$FILE ]; then
|
||||
$WGET -O $SAVE/$FILE $PRIMARY/$FILE
|
||||
fi
|
||||
if [ ! -s $SAVE/$FILE ]; then
|
||||
$WGET -O $SAVE/$FILE $SECONDARY/$FILE
|
||||
fi
|
||||
if [ ! -s $SAVE/$FILE ]; then
|
||||
echo "Unable to get $SAVE/$FILE"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
cd $SAVE
|
||||
|
||||
tar -xz --hard-dereference -f $FILE
|
||||
tar xzf $FILE
|
||||
|
||||
cd $DIR
|
||||
|
||||
./configure --prefix=/usr
|
||||
make
|
||||
make install
|
||||
|
||||
if [ "$?" -eq 0 ]; then
|
||||
cd ..
|
||||
rm -rf ${DIR}
|
||||
fi
|
||||
|
||||
cd $CWD;
|
||||
@@ -1,4 +0,0 @@
|
||||
[PHP]
|
||||
safe_mode = Off
|
||||
open_basedir =
|
||||
disable_functions =
|
||||
@@ -1,3 +0,0 @@
|
||||
<?php
|
||||
header("Location: http://".$_SERVER['HTTP_HOST'].":2222");
|
||||
?>
|
||||
@@ -1,73 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
OS=`uname`
|
||||
#remove the active ip from eth0:#
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
ETH_DEV=dc0
|
||||
else
|
||||
ETH_DEV=eth0
|
||||
fi
|
||||
DACONF=/usr/local/directadmin/conf/directadmin.conf
|
||||
if [ -s ${DACONF} ]; then
|
||||
if grep -m1 -q '^ethernet_dev=' ${DACONF}; then
|
||||
ETH_DEV=`grep -m1 '^ethernet_dev=' ${DACONF} | cut -d= -f2 | cut -d: -f1`
|
||||
fi
|
||||
fi
|
||||
|
||||
# we need the ip to delete
|
||||
if [ $# -ne "1" ] && [ $# -ne "2" ]; then
|
||||
echo "Usage: $0 <ip> (<condensed_ipv6>)";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
if /sbin/ifconfig | grep -m1 -q " $1 "; then
|
||||
/sbin/ifconfig $ETH_DEV inet $1 -alias
|
||||
fi
|
||||
else
|
||||
if ip a | grep -m1 -q " $1/"; then
|
||||
#"ip" accepts IPs without netmasks, but shows a warning that the feature might not be avail in the future, this we delete IP with its mask
|
||||
IP_TO_REMOVE="`ip a | grep -m1 -o \" ${1}/[0-9]*\" | awk '{print $1}'`"
|
||||
ip addr del ${IP_TO_REMOVE} dev ${ETH_DEV}
|
||||
|
||||
if [ "$?" -ne 0 ] && ip a | grep -m1 -q " $1/"; then
|
||||
#old code, should not be needed anymore, but we fallback to it if IP is still there
|
||||
IP=$1
|
||||
IPv6=0
|
||||
if [ $# -eq "2" ] && [ "$2" != "" ]; then
|
||||
IP=$2
|
||||
/sbin/ifconfig $ETH_DEV del $IP/64
|
||||
|
||||
IPv6=1
|
||||
fi
|
||||
|
||||
#for each eth0:#, if ifconfig eth0:# has $1 (the ip) delete eth0:#
|
||||
for i in `/sbin/ifconfig | grep $ETH_DEV: | cut -d\ -f1 | cut -d: -f1,2`; do
|
||||
{
|
||||
NUMIP=`/sbin/ifconfig $i | grep -c "${IP} "`;
|
||||
|
||||
if [ $NUMIP -gt "0" ];
|
||||
then
|
||||
{
|
||||
#we found the interface with the ip
|
||||
|
||||
COLCOUNT=`echo $i | grep -c :`
|
||||
if [ "${COLCOUNT}" -gt 0 ] && [ -e /etc/debian_version ] && [ "${IPv6}" -eq 0 ]; then
|
||||
/sbin/ifconfig $i down
|
||||
else
|
||||
/sbin/ifconfig $i del $IP #remove from the interface
|
||||
fi
|
||||
|
||||
#it appears as though the ip is automatically removed from `route`
|
||||
|
||||
exit 0
|
||||
}
|
||||
fi
|
||||
};
|
||||
done
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
#can't find it, it must be gone
|
||||
@@ -1,115 +0,0 @@
|
||||
#!/bin/sh
|
||||
#VERSION=2.0
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to move user from one reseller to another
|
||||
# Official DirectAdmin webpage: http://www.directadmin.com
|
||||
# Usage:
|
||||
# ./rename_database.sh <olddatabase> <newdatabase>
|
||||
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "$MYUID" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ $# != 2 ]; then
|
||||
echo "Usage:";
|
||||
echo "$0 <olddatabase> <newdatabase>";
|
||||
echo "you gave #$#: $0 $1 $2";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
OLDUSER_DATABASE="$1"
|
||||
NEWUSER_DATABASE="$2"
|
||||
OLDUSER_ESCAPED_DATABASE="`echo ${OLDUSER_DATABASE} | perl -p0 -e 's|_|\\\_|'`"
|
||||
NEWUSER_ESCAPED_DATABASE="`echo ${NEWUSER_DATABASE} | perl -p0 -e 's|_|\\\_|'`"
|
||||
|
||||
MYSQLDUMP=/usr/local/mysql/bin/mysqldump
|
||||
if [ ! -e ${MYSQLDUMP} ]; then
|
||||
MYSQLDUMP=/usr/local/bin/mysqldump
|
||||
fi
|
||||
if [ ! -e ${MYSQLDUMP} ]; then
|
||||
MYSQLDUMP=/usr/bin/mysqldump
|
||||
fi
|
||||
if [ ! -e ${MYSQLDUMP} ]; then
|
||||
echo "Cannot find ${MYSQLDUMP}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MYSQL=/usr/local/mysql/bin/mysql
|
||||
if [ ! -e ${MYSQL} ]; then
|
||||
MYSQL=/usr/local/bin/mysql
|
||||
fi
|
||||
if [ ! -e ${MYSQL} ]; then
|
||||
MYSQL=/usr/bin/mysql
|
||||
fi
|
||||
if [ ! -e ${MYSQL} ]; then
|
||||
echo "Cannot find ${MYSQL}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DEFM=--defaults-extra-file=/usr/local/directadmin/conf/my.cnf
|
||||
|
||||
# If MySQL a new database does not exist, create it and copy all the data from the old database, then drop the old database
|
||||
if ! ${MYSQL} ${DEFM} --skip-column-names -e "SHOW DATABASES LIKE '${NEWUSER_DATABASE}';" -s | grep -m1 -q "${NEWUSER_DATABASE}"; then
|
||||
if ! ${MYSQL} ${DEFM} --skip-column-names -e "SHOW DATABASES LIKE '${OLDUSER_DATABASE}';" -s | grep -m1 -q "${OLDUSER_DATABASE}"; then
|
||||
echo "Specified database name does not exist: ${OLDUSER_DATABASE}"
|
||||
exit 1
|
||||
fi
|
||||
#Count the number of tables in current database
|
||||
OLD_TABLES_COUNT="`${MYSQL} ${DEFM} -D \"${OLDUSER_DATABASE}\" --skip-column-names -e 'SHOW TABLES;' | wc -l`"
|
||||
|
||||
#Create an empty new database, \` is needed for databases having "-" in it's name, so that no math would be done by sql :)
|
||||
${MYSQL} ${DEFM} -e "CREATE DATABASE \`${NEWUSER_DATABASE}\`;"
|
||||
|
||||
echo "Dumping+restoring ${OLDUSER_DATABASE} -> ${NEWUSER_DATABASE}..."
|
||||
|
||||
#Dump+restore to the new database on the fly
|
||||
${MYSQLDUMP} ${DEFM} --routines "${OLDUSER_DATABASE}" | ${MYSQL} ${DEFM} -D "${NEWUSER_DATABASE}"
|
||||
|
||||
#Count the number of tables in new database
|
||||
NEW_TABLES_COUNT="`${MYSQL} ${DEFM} -D \"${NEWUSER_DATABASE}\" --skip-column-names -e 'SHOW TABLES;' | wc -l`"
|
||||
|
||||
if echo "${OLD_TABLES_COUNT}" | grep -qE ^\-?[0-9]+$; then
|
||||
COUNT1_IS_NUMERIC=true
|
||||
else
|
||||
COUNT1_IS_NUMERIC=false
|
||||
fi
|
||||
|
||||
if echo "${NEW_TABLES_COUNT}" | grep -qE ^\-?[0-9]+$; then
|
||||
COUNT2_IS_NUMERIC=true
|
||||
else
|
||||
COUNT2_IS_NUMERIC=false
|
||||
fi
|
||||
|
||||
#Drop the old database if the count of tables matches
|
||||
if [ ${OLD_TABLES_COUNT} -eq ${NEW_TABLES_COUNT} ] && ${COUNT1_IS_NUMERIC} && ${COUNT2_IS_NUMERIC}; then
|
||||
${MYSQL} ${DEFM} -e "DROP DATABASE \`${OLDUSER_DATABASE}\`;"
|
||||
echo "Database has been renamed successfully: ${OLDUSER_DATABASE} -> ${NEWUSER_DATABASE}"
|
||||
if [ `${MYSQL} ${DEFM} -e "select count(*) from mysql.db where db='${OLDUSER_ESCAPED_DATABASE}'" -s` -ge 1 ]; then
|
||||
echo "Updating mysql.db..."
|
||||
${MYSQL} ${DEFM} -e "UPDATE mysql.db set db='${NEWUSER_ESCAPED_DATABASE}' WHERE db='${OLDUSER_ESCAPED_DATABASE}' OR db='${OLDUSER_DATABASE}';"
|
||||
fi
|
||||
if [ `${MYSQL} ${DEFM} -e "select count(*) from mysql.columns_priv where db='${OLDUSER_ESCAPED_DATABASE}'" -s` -ge 1 ]; then
|
||||
echo "Updating mysql.columns_priv..."
|
||||
${MYSQL} ${DEFM} -e "UPDATE mysql.columns_priv set db='${NEWUSER_ESCAPED_DATABASE}' WHERE db='${OLDUSER_ESCAPED_DATABASE}' OR db='${OLDUSER_DATABASE}';"
|
||||
fi
|
||||
if [ `${MYSQL} ${DEFM} -e "select count(*) from mysql.procs_priv where db='${OLDUSER_ESCAPED_DATABASE}'" -s` -ge 1 ]; then
|
||||
echo "Updating mysql.procs_priv..."
|
||||
${MYSQL} ${DEFM} -e "UPDATE mysql.procs_priv set db='${NEWUSER_ESCAPED_DATABASE}' WHERE db='${OLDUSER_ESCAPED_DATABASE}' OR db='${OLDUSER_DATABASE}';"
|
||||
fi
|
||||
if [ `${MYSQL} ${DEFM} -e "select count(*) from mysql.tables_priv where db='${OLDUSER_ESCAPED_DATABASE}'" -s` -ge 1 ]; then
|
||||
echo "Updating mysql.tables_priv..."
|
||||
${MYSQL} ${DEFM} -e "UPDATE mysql.tables_priv set db='${NEWUSER_ESCAPED_DATABASE}' WHERE db='${OLDUSER_ESCAPED_DATABASE}' OR db='${OLDUSER_DATABASE}';"
|
||||
fi
|
||||
exit 0
|
||||
else
|
||||
#Error and exit if the number of tables doesn't match
|
||||
echo "Database ${NEWUSER_DATABASE} doesn't have as many tables as ${OLDUSER_DATABASE} after restoration. Not removing ${OLDUSER_DATABASE}. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# If MySQL new database name already exists on the system (it shouldn't), error and exit
|
||||
echo "Database ${NEWUSER_DATABASE} already exists, cannot rename the database. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,181 +0,0 @@
|
||||
#!/bin/sh
|
||||
#VERSION=0.1
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to move database and it's user from one reseller to another
|
||||
# Official DirectAdmin webpage: http://www.directadmin.com
|
||||
# Usage:
|
||||
# ./rename_database_with_user.sh <olddatabase> <newdatabase>
|
||||
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "$MYUID" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ $# != 2 ]; then
|
||||
echo "Usage:";
|
||||
echo "$0 <olddatabase> <newdatabase>";
|
||||
echo "you gave #$#: $0 $1 $2";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
OLDUSER_DATABASE="$1"
|
||||
NEWUSER_DATABASE="$2"
|
||||
OLDUSER_ESCAPED_DATABASE="`echo ${OLDUSER_DATABASE} | perl -p0 -e 's|_|\\\_|'`"
|
||||
NEWUSER_ESCAPED_DATABASE="`echo ${NEWUSER_DATABASE} | perl -p0 -e 's|_|\\\_|'`"
|
||||
OLDUSER_ESCAPED_DATABASE_MT="`echo ${OLDUSER_DATABASE} | perl -p0 -e 's|_|\\\\\\\_|'`"
|
||||
NEWUSER_ESCAPED_DATABASE_MT="`echo ${NEWUSER_DATABASE} | perl -p0 -e 's|_|\\\\\\\_|'`"
|
||||
|
||||
MYSQLDUMP=/usr/local/mysql/bin/mysqldump
|
||||
if [ ! -e ${MYSQLDUMP} ]; then
|
||||
MYSQLDUMP=/usr/local/bin/mysqldump
|
||||
fi
|
||||
if [ ! -e ${MYSQLDUMP} ]; then
|
||||
MYSQLDUMP=/usr/bin/mysqldump
|
||||
fi
|
||||
if [ ! -e ${MYSQLDUMP} ]; then
|
||||
echo "Cannot find ${MYSQLDUMP}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MYSQL=/usr/local/mysql/bin/mysql
|
||||
if [ ! -e ${MYSQL} ]; then
|
||||
MYSQL=/usr/local/bin/mysql
|
||||
fi
|
||||
if [ ! -e ${MYSQL} ]; then
|
||||
MYSQL=/usr/bin/mysql
|
||||
fi
|
||||
if [ ! -e ${MYSQL} ]; then
|
||||
echo "Cannot find ${MYSQL}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DEFM=--defaults-extra-file=/usr/local/directadmin/conf/my.cnf
|
||||
|
||||
# If MySQL new database does not exist, create it and copy all the data from the old database, then drop the old database
|
||||
if ! ${MYSQL} ${DEFM} --skip-column-names -e "SHOW DATABASES LIKE '${NEWUSER_DATABASE}';" -s | grep -m1 -q "${NEWUSER_DATABASE}"; then
|
||||
if ! ${MYSQL} ${DEFM} --skip-column-names -e "SHOW DATABASES LIKE '${OLDUSER_DATABASE}';" -s | grep -m1 -q "${OLDUSER_DATABASE}"; then
|
||||
echo "Specified database name does not exist: ${OLDUSER_DATABASE}"
|
||||
exit 1
|
||||
fi
|
||||
#Count the number of tables in current database
|
||||
OLD_TABLES_COUNT="`${MYSQL} ${DEFM} -D \"${OLDUSER_DATABASE}\" --skip-column-names -e 'SHOW TABLES;' | wc -l`"
|
||||
|
||||
#Create an empty new database, \` is needed for databases having "-" in it's name, so that no math would be done by sql :)
|
||||
${MYSQL} ${DEFM} -e "CREATE DATABASE \`${NEWUSER_DATABASE}\`;"
|
||||
|
||||
echo "Dumping+restoring ${OLDUSER_DATABASE} -> ${NEWUSER_DATABASE}..."
|
||||
|
||||
#Dump+restore to the new database on the fly
|
||||
${MYSQLDUMP} ${DEFM} --routines "${OLDUSER_DATABASE}" | ${MYSQL} ${DEFM} -D "${NEWUSER_DATABASE}"
|
||||
|
||||
#Count the number of tables in new database
|
||||
NEW_TABLES_COUNT="`${MYSQL} ${DEFM} -D \"${NEWUSER_DATABASE}\" --skip-column-names -e 'SHOW TABLES;' | wc -l`"
|
||||
|
||||
if echo "${OLD_TABLES_COUNT}" | grep -qE ^\-?[0-9]+$; then
|
||||
COUNT1_IS_NUMERIC=true
|
||||
else
|
||||
COUNT1_IS_NUMERIC=false
|
||||
fi
|
||||
|
||||
if echo "${NEW_TABLES_COUNT}" | grep -qE ^\-?[0-9]+$; then
|
||||
COUNT2_IS_NUMERIC=true
|
||||
else
|
||||
COUNT2_IS_NUMERIC=false
|
||||
fi
|
||||
|
||||
#Drop the old database if the count of tables matches
|
||||
if [ ${OLD_TABLES_COUNT} -eq ${NEW_TABLES_COUNT} ] && ${COUNT1_IS_NUMERIC} && ${COUNT2_IS_NUMERIC}; then
|
||||
${MYSQL} ${DEFM} -e "DROP DATABASE \`${OLDUSER_DATABASE}\`;"
|
||||
echo "Database has been renamed successfully: ${OLDUSER_DATABASE} -> ${NEWUSER_DATABASE}"
|
||||
|
||||
#User management part
|
||||
OLD_USER=`echo ${OLDUSER_DATABASE} | egrep -o '^[^_]*'`
|
||||
NEW_USER=`echo ${NEWUSER_DATABASE} | egrep -o '^[^_]*'`
|
||||
|
||||
#default user
|
||||
if [ ${OLD_USER} = ${NEW_USER} ]; then
|
||||
echo "Raname in same user - no need to check base user"
|
||||
else
|
||||
echo "Moving to a new user, granting new user/revoking old user permissions"
|
||||
if [ `${MYSQL} ${DEFM} -e "SELECT COUNT(*) FROM mysql.user WHERE User='${NEW_USER}'" -sss` -lt 1 ]; then
|
||||
echo "Base new user '${NEW_USER}' does not exist, skipping base user grant management"
|
||||
else
|
||||
OLD_USER_HOSTS=`${MYSQL} ${DEFM} -s -r -e "SELECT Host FROM mysql.user WHERE User='${OLD_USER}'" -sss`
|
||||
for OLD_USER_HOST in ${OLD_USER_HOSTS}
|
||||
do
|
||||
BASE_USER_GRANTS=`${MYSQL} ${DEFM} -s -r -e "SHOW GRANTS FOR '${OLD_USER}'@'${OLD_USER_HOST}'" 2>/dev/null | egrep "\\\`${OLDUSER_DATABASE}\\\`|\\\`${OLDUSER_ESCAPED_DATABASE_MT}\\\`"`
|
||||
echo "${BASE_USER_GRANTS}" | while read -r GRANT
|
||||
do
|
||||
DO_GRANT=`echo ${GRANT} | sed "s/'${OLD_USER}'/'${NEW_USER}'/"`
|
||||
DO_GRANT=`echo ${DO_GRANT} | sed "s/\\\`${OLDUSER_DATABASE}\\\`/\\\`${NEWUSER_DATABASE}\\\`/"`
|
||||
DO_GRANT=`echo ${DO_GRANT} | sed "s/\\\`${OLDUSER_ESCAPED_DATABASE_MT}\\\`/\\\`${NEWUSER_DATABASE}\\\`/"`
|
||||
DO_REVOKE=`echo ${GRANT} | sed "s/^GRANT /REVOKE /"`
|
||||
DO_REVOKE=`echo ${DO_REVOKE} | sed "s/ TO / FROM /"`
|
||||
${MYSQL} ${DEFM} -e "${DO_GRANT}"
|
||||
${MYSQL} ${DEFM} -e "${DO_REVOKE}"
|
||||
done
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
#other users
|
||||
OTHER_USERS=`${MYSQL} ${DEFM} -s -e "SELECT User,Host FROM (SELECT User,Db,Host FROM mysql.db UNION SELECT User,Db,Host FROM mysql.tables_priv UNION SELECT User,Db,Host FROM mysql.columns_priv UNION SELECT User,Db,Host FROM mysql.procs_priv) tb WHERE User like '${OLD_USER}_%' AND (Db='${OLDUSER_ESCAPED_DATABASE}' OR Db='${OLDUSER_DATABASE}')"`
|
||||
echo "$OTHER_USERS" | while read OTHER
|
||||
do
|
||||
OUSER=`echo "$OTHER" | awk '{print $1}'`
|
||||
OHOST=`echo "$OTHER" | awk '{print $2}'`
|
||||
NUSER=`echo "$OUSER" | sed "s/${OLD_USER}_/${NEW_USER}_/"`
|
||||
|
||||
OTHER_USER_GRANTS=`${MYSQL} ${DEFM} -s -r -e "SHOW GRANTS FOR '${OUSER}'@'${OHOST}'" 2>/dev/null | egrep "\\\`${OLDUSER_DATABASE}\\\`|\\\`${OLDUSER_ESCAPED_DATABASE_MT}\\\`"`
|
||||
echo "${OTHER_USER_GRANTS}" | while read -r OTHER_GRANT
|
||||
do
|
||||
if [ "${OLD_USER}" = "${NEW_USER}" ]; then
|
||||
echo "Rename in same user - no need to rename original db user"
|
||||
else
|
||||
if [ `${MYSQL} ${DEFM} -e "SELECT COUNT(*) FROM mysql.user WHERE User='${NUSER}' AND Host='${OHOST}'" -sss` -gt 0 ]; then
|
||||
echo "'${NUSER}'@'${OHOST}' user already exists, a new one will not be created and the password won't be copied as it could be already used..."
|
||||
else
|
||||
echo "'${NUSER}'@'${OHOST}' user does not exist. Creating..."
|
||||
RAND_PASS=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
|
||||
${MYSQL} ${DEFM} -e "CREATE USER '${NUSER}'@'${OHOST}' IDENTIFIED BY '${RAND_PASS}'"
|
||||
PASS_GRANT=`${MYSQL} ${DEFM} -e "SHOW GRANTS FOR '${OUSER}'@'${OHOST}'" | egrep " IDENTIFIED BY PASSWORD"`
|
||||
PASS_GRANT=`echo ${PASS_GRANT} | rev | cut -d' ' -f 1 | rev | sed "s/'//g"`
|
||||
MYSQLVER=`${MYSQL} ${DEFM} -e "SELECT version()" | egrep -o "^[0-9]+\.[0-9]+"`
|
||||
if ${MYSQL} ${DEFM} -e "SHOW CREATE USER 'da_admin'@'${OHOST}';" > /dev/null 2>&1; then
|
||||
${MYSQL} ${DEFM} -e "ALTER USER '${NUSER}'@'${OHOST}' IDENTIFIED WITH mysql_native_password AS '${PASS_GRANT}'"
|
||||
else
|
||||
${MYSQL} ${DEFM} -e "SET PASSWORD FOR '${NUSER}'@'${OHOST}' = '${PASS_GRANT}'"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
DO_OTHER_GRANT="${OTHER_GRANT}"
|
||||
if [ "${OLD_USER}" != "${NEW_USER}" ]; then
|
||||
DO_OTHER_GRANT=`echo ${DO_OTHER_GRANT} | sed "s/ '${OUSER}'/ '${NUSER}'/"`
|
||||
fi
|
||||
DO_OTHER_GRANT=`echo ${DO_OTHER_GRANT} | sed "s/\\\`${OLDUSER_DATABASE}\\\`/\\\`${NEWUSER_DATABASE}\\\`/"`
|
||||
DO_OTHER_GRANT=`echo ${DO_OTHER_GRANT} | sed "s/\\\`${OLDUSER_ESCAPED_DATABASE_MT}\\\`/\\\`${NEWUSER_DATABASE}\\\`/"`
|
||||
DO_OTHER_REVOKE=`echo ${OTHER_GRANT} | sed "s/^GRANT /REVOKE /"`
|
||||
DO_OTHER_REVOKE=`echo ${DO_OTHER_REVOKE} | sed "s/ TO / FROM /"`
|
||||
${MYSQL} ${DEFM} -e "${DO_OTHER_GRANT}"
|
||||
${MYSQL} ${DEFM} -e "${DO_OTHER_REVOKE}"
|
||||
if [ `${MYSQL} ${DEFM} -s -e "SELECT COUNT(*) FROM (SELECT User,Db,Host FROM mysql.db UNION SELECT User,Db,Host FROM mysql.tables_priv UNION SELECT User,Db,Host FROM mysql.columns_priv UNION SELECT User,Db,Host FROM mysql.procs_priv) tb WHERE User='${OUSER}' AND Db!='${OLDUSER_ESCAPED_DATABASE}' AND Db!='${OLDUSER_DATABASE}' AND Host='${OHOST}'"` -eq 0 ]; then
|
||||
echo "'${OUSER}'@'${OHOST}' does not have privileges for other databases. Removing the user."
|
||||
${MYSQL} ${DEFM} -e "DROP USER '${OUSER}'@'${OHOST}'"
|
||||
else
|
||||
echo "'${OUSER}'@'${OHOST}' still has privileges for other databases. Not removing the user."
|
||||
fi
|
||||
done
|
||||
done
|
||||
exit 0
|
||||
else
|
||||
#Error and exit if the number of tables doesn't match
|
||||
echo "Database ${NEWUSER_DATABASE} doesn't have as many tables as ${OLDUSER_DATABASE} after restoration. Not removing ${OLDUSER_DATABASE}. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# If MySQL new database name already exists on the system (it shouldn't), error and exit
|
||||
echo "Database ${NEWUSER_DATABASE} already exists, cannot rename the database. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,120 +0,0 @@
|
||||
#!/bin/sh
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to convert reseller to user
|
||||
# Official DirectAdmin webpage: http://www.directadmin.com
|
||||
# Usage:
|
||||
# ./reseller_to_user.sh <user>
|
||||
|
||||
if [ $UID != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ $# != 2 ]; then
|
||||
echo "Usage:";
|
||||
echo " $0 <user> <reseller>";
|
||||
echo "you gave #$#: $0 $1 $2";
|
||||
echo "where:"
|
||||
echo "user: name of the account to downgrade."
|
||||
echo "reseller: name of the new creator of the User: eg: admin";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
RESELLER_LIST=${BASEDIR}/admin/reseller.list
|
||||
BASEDIR=/usr/local/directadmin/data
|
||||
USR=$1
|
||||
NEW_CREATOR=$2
|
||||
NEW_CREATOR_IP_LIST=${BASEDIR}/users/${NEW_CREATOR}/ip.list
|
||||
RESELLER_LIST=${BASEDIR}/admin/reseller.list
|
||||
USER_DATA=${BASEDIR}/users/$USR
|
||||
USER_CONF=${USER_DATA}/user.conf
|
||||
USER_BACKUP_CONF=${USER_DATA}/backup.conf
|
||||
RESELLER_ALLOC=${USER_DATA}/reseller.allocation
|
||||
RESELLER_CONF=${USER_DATA}/reseller.conf
|
||||
RESELLER_USAGE=${USER_DATA}/reseller.usage
|
||||
|
||||
if [ ! -d ${USER_DATA} ]; then
|
||||
echo "Directory ${USER_DATA} does not exist. Can not continue."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "`grep -wc $USR ${RESELLER_LIST}`" = "0" ]; then
|
||||
echo "Reseller $USR is already user. Can not continue."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/perl ]; then
|
||||
echo "/usr/bin/perl does not exist.";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "Re-configuring user directory /home/$USR."
|
||||
rm -rf /home/$USR/user_backups
|
||||
rm -rf /home/$USR/domains/default
|
||||
rm -rf /home/$USR/domains/sharedip
|
||||
rm -rf /home/$USR/domains/suspended
|
||||
|
||||
echo "Re-configuring DirectAdmin files."
|
||||
# Changing usertype
|
||||
perl -pi -e 's/usertype=reseller/usertype=user/' ${USER_CONF}
|
||||
|
||||
#if any IPs are managed by this Reseller, owernship should go to new creator.
|
||||
for ip in `cat ${USER_DATA}/ip.list`; do
|
||||
{
|
||||
IPFILE=${BASEDIR}/admin/ips/$ip
|
||||
|
||||
C=`grep -c reseller=${USR} ${IPFILE}`
|
||||
if [ "$C" -gt 0 ]; then
|
||||
#swap reseller to new reseller.
|
||||
perl -pi -e "s/^creator=$USR\$/creator=$NEW_CREATOR/" $IPFILE
|
||||
|
||||
#and add it to the new resellers list.
|
||||
C=`grep -c $ip $NEW_CREATOR_IP_LIST`
|
||||
if [ "$C" -eq 0 ]; then
|
||||
echo $ip >> $NEW_CREATOR_IP_LIST
|
||||
fi
|
||||
fi
|
||||
};
|
||||
done;
|
||||
|
||||
|
||||
rm -f ${USER_BACKUP_CONF}
|
||||
rm -f ${USER_DATA}/ip.list
|
||||
rm -f ${USER_DATA}/login.hist
|
||||
rm -f ${USER_DATA}/reseller.history
|
||||
rm -f ${USER_DATA}/users.list
|
||||
rm -f ${USER_DATA}/u_welcome.txt
|
||||
rm -rf ${USER_DATA}/packages
|
||||
rm -f ${USER_DATA}/packages.list
|
||||
rm -f ${RESELLER_ALLOC}
|
||||
rm -f ${RESELLER_CONF}
|
||||
rm -f ${RESELLER_USAGE}
|
||||
CREATOR=`grep "creator=" ${USER_CONF} | cut -d= -f2`
|
||||
RESELLER_USERSLIST=${BASEDIR}/users/$NEW_CREATOR/users.list
|
||||
|
||||
# Editing ticket.conf
|
||||
if [ -e ${USER_DATA}/ticket.conf ]; then
|
||||
ACTIVE="`grep 'active=' ${USER_DATA}/ticket.conf`"
|
||||
HTML="`grep 'html=' ${USER_DATA}/ticket.conf`"
|
||||
NEWTICKET="`grep 'newticket=' ${USER_DATA}/ticket.conf`"
|
||||
perl -pi -e "s#$ACTIVE\n##g" ${USER_DATA}/ticket.conf
|
||||
perl -pi -e "s#$HTML\n##g" ${USER_DATA}/ticket.conf
|
||||
perl -pi -e "s#$NEWTICKET\n##g" ${USER_DATA}/ticket.conf
|
||||
fi
|
||||
|
||||
echo "Adding user to the $2 reseller."
|
||||
echo "$USR" >> ${RESELLER_USERSLIST}
|
||||
|
||||
echo "Removing user from the reseller list."
|
||||
perl -pi -e "s#$USR\n##g" ${RESELLER_LIST}
|
||||
|
||||
echo "Changing user owner"
|
||||
perl -pi -e "s/creator=$CREATOR/creator=$NEW_CREATOR/g" ${USER_CONF}
|
||||
|
||||
#this is needed to update "show all users" cache.
|
||||
echo "action=cache&value=showallusers" >> /usr/local/directadmin/data/task.queue
|
||||
/usr/local/directadmin/dataskq
|
||||
|
||||
echo "Reseller $USR has been converted to user."
|
||||
|
||||
exit 0;
|
||||
@@ -1,451 +0,0 @@
|
||||
#!/usr/local/bin/php -c/usr/local/directadmin/scripts/php_clean.ini
|
||||
<?php
|
||||
|
||||
$version = 0.1;
|
||||
|
||||
/*
|
||||
Restore script for the per-domain RoundCube settings.
|
||||
Backup/Restore written by DirectAdmin: http://www.directadmin.com
|
||||
RoundCube Webmail Client: http://roundcube.net
|
||||
|
||||
This script will take an XML output (generated by backup_roundcube.php)
|
||||
and restore all elements for a given User, merging them into an active roundcube database.
|
||||
New IDs are generated, where applicable, so they will not be any conflicts if the IDs are differnt.
|
||||
Existing accounts will be respected, and only missing data is merged in.
|
||||
|
||||
See the DirectAdmin versions system for more info:
|
||||
http://www.directadmin.com/features.php?id=1062
|
||||
|
||||
All variables are passed via environment, not command line options
|
||||
But you can specify environmental variables... via command line options before the script (see the showHelp() function)
|
||||
|
||||
RETURN VALUES
|
||||
0: All is well
|
||||
>1: an error worthy or reporting has occured. Message on stderr.
|
||||
1: an error, most likely due to not actually having RoundCube installed or no restore data, has occured.
|
||||
|
||||
*/
|
||||
|
||||
/***********************
|
||||
* Environmental variables
|
||||
*/
|
||||
$domain = getenv("domain"); //for security reasons, it must match the XML values.
|
||||
$system_username = getenv("username"); //only this account is allowed to be restored.
|
||||
$xml_file = getenv("xml_file"); //Name of the file to restore.
|
||||
|
||||
/***********************
|
||||
* Enabling debug lets you see which Email is seen,
|
||||
* and what values are being restored, and shows you their respective IDs (found or set)
|
||||
* Keep this set to FALSE if the dataksq is calling it, so as to not fill the stdin buffer (dataskq only reads from stderr for this script)
|
||||
*/
|
||||
$is_debug = FALSE;
|
||||
|
||||
/***********************
|
||||
* this restores as da_admin instead of da_roundube. It is less secure, avoid using it if possible.
|
||||
*/
|
||||
$high_access_connection = FALSE;
|
||||
|
||||
|
||||
/***********************
|
||||
* is the host value set within the da_roundcube.users table.
|
||||
*/
|
||||
$rc_mail_host = 'localhost';
|
||||
|
||||
/***********************
|
||||
* If $high_access_restore is false, this is used for the mysql credentials.
|
||||
*/
|
||||
$rc_config = "/var/www/html/roundcube/config/config.inc.php";
|
||||
|
||||
//****************************************************************
|
||||
//****************************************************************
|
||||
|
||||
if (!isset($xml_file) || $xml_file == "")
|
||||
show_help();
|
||||
|
||||
if (!isset($domain) || $domain == "")
|
||||
show_help();
|
||||
|
||||
if (!file_exists($xml_file))
|
||||
{
|
||||
echo_stderr("Cannot find path: $xml_file. Skipping RoundCube restore.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (filesize($xml_file) == 0)
|
||||
{
|
||||
echo_stderr("Size of $xml_file is 0. Skipping RoundCube restore.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//****************************************************************
|
||||
//****************************************************************
|
||||
|
||||
if ($high_access_connection)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '<'))
|
||||
{
|
||||
$mysql_conf = @parse_ini_file("/usr/local/directadmin/conf/mysql.conf", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mysql_conf = @parse_ini_file("/usr/local/directadmin/conf/mysql.conf", false, INI_SCANNER_RAW);
|
||||
}
|
||||
}
|
||||
|
||||
if ($high_access_connection && $mysql_conf && strlen($mysql_conf['passwd']) > 4)
|
||||
{
|
||||
$mysql_conf = parse_ini_file("/usr/local/directadmin/conf/mysql.conf");
|
||||
$mysql_user = $mysql_conf['user'];
|
||||
$mysql_pass = $mysql_conf['passwd'];
|
||||
$mysql_host = 'localhost';
|
||||
$mysql_db = 'da_roundcube';
|
||||
|
||||
if (isset($mysql_conf['host']) && $mysql_conf['host'] != "")
|
||||
$mysql_host = $mysql_conf['host'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!file_exists($rc_config))
|
||||
{
|
||||
echo_stderr("Cannot find RoundCube config at $rc_config. Is RC installed and up to date?\n");
|
||||
exit(5);
|
||||
}
|
||||
|
||||
include_once($rc_config);
|
||||
|
||||
if (!isset($config) || !isset($config['db_dsnw']) || $config['db_dsnw'] == '')
|
||||
{
|
||||
echo_stderr("Cannot find \$config['db_dsnw'] variable in $rc_config\n");
|
||||
exit(6);
|
||||
}
|
||||
|
||||
//$config['db_dsnw'] = 'mysql://da_roundcube:password@localhost/da_roundcube';
|
||||
|
||||
$values = explode('/', $config['db_dsnw']);
|
||||
$connect = explode('@', $values[2]);
|
||||
$auth = explode(':', $connect[0]);
|
||||
|
||||
$mysql_user = $auth[0];
|
||||
$mysql_pass = $auth[1];
|
||||
$mysql_host = $connect[1];
|
||||
$mysql_db = $values[3];
|
||||
}
|
||||
|
||||
$mysqli = new mysqli($mysql_host, $mysql_user, $mysql_pass);
|
||||
if ($mysqli->connect_errno) {
|
||||
echo_stderr("Failed to connect to MySQL: (".$mysqli->connect_errno.") ".$mysqli->connect_error."\n");
|
||||
exit(3);
|
||||
}
|
||||
$mysqli->set_charset('utf8');
|
||||
|
||||
if (!$mysqli->select_db($mysql_db))
|
||||
{
|
||||
echo_stderr("There is no $mysql_db database. Skipping RoundCube restore.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//****************************************************************
|
||||
//****************************************************************
|
||||
|
||||
$xml = simplexml_load_file($xml_file);
|
||||
|
||||
if ($xml === FALSE)
|
||||
{
|
||||
echo_stderr("Error reading in XML file with with simplexml_load_file('$xml_file')\n");
|
||||
exit(4);
|
||||
}
|
||||
|
||||
foreach($xml->children() as $email)
|
||||
{
|
||||
$username = urldecode($email->USERNAME);
|
||||
|
||||
if ($username != $system_username)
|
||||
{
|
||||
$data = explode('@', $username);
|
||||
|
||||
if ($data[1] != $domain)
|
||||
{
|
||||
echo_stderr($username. " is not part of domain '".$domain."': Skipping.\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$user_id = ensure_user($email);
|
||||
if ($user_id == -1)
|
||||
continue;
|
||||
|
||||
echo_debug("username $username : $user_id\n");
|
||||
|
||||
foreach($email->INDENTITIES->children() as $identity)
|
||||
{
|
||||
$id_id = ensure_identity($user_id, $identity);
|
||||
|
||||
if ($id_id == -1)
|
||||
continue;
|
||||
|
||||
$id_email = urldecode($identity->EMAIL);
|
||||
echo_debug(" identity $id_email : $id_id\n");
|
||||
}
|
||||
|
||||
|
||||
$groups = Array();
|
||||
|
||||
foreach($email->CONTACTS->children() as $contact)
|
||||
{
|
||||
//first, ensure all groups exisrt for this user_id.
|
||||
foreach($contact->GROUPS->children() as $group)
|
||||
{
|
||||
$group_id = ensure_group($user_id, $group);
|
||||
$group_name = urldecode($group->NAME);
|
||||
|
||||
//save it for later.
|
||||
$groups[$group_name] = $group_id;
|
||||
}
|
||||
|
||||
//next, ensure the contact exists, and add to contactgroupsmembers.
|
||||
$contact_id = ensure_contact($user_id, $contact);
|
||||
|
||||
$contact_email = urldecode($contact->EMAIL);
|
||||
echo_debug(" contact $contact_email : $contact_id\n");
|
||||
|
||||
//link contact to their groups.
|
||||
link_contact_to_group($contact, $contact_id, $groups);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$mysqli->close();
|
||||
|
||||
exit(0);
|
||||
|
||||
//**********************************************************************
|
||||
//**********************************************************************
|
||||
|
||||
/**********************************************************************
|
||||
* ensure that the contact has been assigned to their groups.
|
||||
*/
|
||||
function link_contact_to_group($contact, $contact_id, $groups)
|
||||
{
|
||||
global $mysqli;
|
||||
|
||||
foreach($contact->GROUPS->children() as $group)
|
||||
{
|
||||
$group_name = urldecode($group->NAME);
|
||||
$group_created = mes(urldecode($group->CREATED));
|
||||
$query = "REPLACE INTO `contactgroupmembers` (contactgroup_id, contact_id, created) VALUES (".mes($groups[$group_name]).", $contact_id, '$group_created')";
|
||||
|
||||
if (!$mysqli->query($query))
|
||||
{
|
||||
echo_stderr("Query error:\n".$query."\n".$mysqli->error."\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
echo_debug(" group $group_name : ".$groups[$group_name]."\n");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* ensure that the Group exists for this user_id.
|
||||
*/
|
||||
function ensure_group($user_id, $group)
|
||||
{
|
||||
global $mysqli;
|
||||
|
||||
$group_name = mes(urldecode($group->NAME));
|
||||
|
||||
$query = "SELECT contactgroup_id FROM `contactgroups` WHERE user_id=$user_id AND name='$group_name'";
|
||||
if (!$group_ids = $mysqli->query($query))
|
||||
{
|
||||
echo_stderr("Query error:\n".$query."\n".$mysqli->error."\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($group_ids->num_rows > 0)
|
||||
{
|
||||
$data = $group_ids->fetch_array();
|
||||
return $data['contactgroup_id'];
|
||||
}
|
||||
|
||||
//No group, must add it.
|
||||
|
||||
$group_changed = mes(urldecode($group->CHANGED));
|
||||
|
||||
$query = "INSERT INTO `contactgroups` (user_id, changed, name) VALUES ($user_id, '$group_changed', '$group_name')";
|
||||
|
||||
if (!$groups = $mysqli->query($query))
|
||||
{
|
||||
echo_stderr("Query error:\n".$query."\n".$mysqli->error."\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $mysqli->insert_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* ensure that the Contact exists for this user_id.
|
||||
*/
|
||||
function ensure_contact($user_id, $contact)
|
||||
{
|
||||
global $mysqli;
|
||||
|
||||
$contact_email = mes(urldecode($contact->EMAIL));
|
||||
$contact_name = mes(urldecode($contact->NAME));
|
||||
|
||||
$query = "SELECT contact_id FROM `contacts` WHERE user_id=$user_id AND name='$contact_name' AND email='$contact_email' LIMIT 1";
|
||||
if (!$contact_ids = $mysqli->query($query))
|
||||
{
|
||||
echo_stderr("Query error:\n".$query."\n".$mysqli->error."\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($contact_ids->num_rows > 0)
|
||||
{
|
||||
$data = $contact_ids->fetch_array();
|
||||
return $data['contact_id'];
|
||||
}
|
||||
|
||||
//No contact, must add it.
|
||||
|
||||
$contact_changed = mes(urldecode($contact->CHANGED));
|
||||
$contact_firstname = mes(urldecode($contact->FIRSTNAME));
|
||||
$contact_surname = mes(urldecode($contact->SURNAME));
|
||||
$contact_vcard = mes(urldecode($contact->VCARD));
|
||||
$contact_words = mes(urldecode($contact->WORDS));
|
||||
|
||||
$query = "INSERT INTO `contacts` (changed, name, email, firstname, surname, vcard, words, user_id) VALUES ('$contact_changed', '$contact_name', '$contact_email', '$contact_firstname', '$contact_surname', '$contact_vcard', '$contact_words', $user_id)";
|
||||
if (!$contact_ids = $mysqli->query($query))
|
||||
{
|
||||
echo_stderr("Query error:\n".$query."\n".$mysqli->error."\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $mysqli->insert_id;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* ensure that the Identity exists for this user_id.
|
||||
* no need to worry about the return value
|
||||
*/
|
||||
function ensure_identity($user_id, $identity)
|
||||
{
|
||||
global $mysqli;
|
||||
|
||||
$id_email = mes(urldecode($identity->EMAIL));
|
||||
$id_name = mes(urldecode($identity->NAME));
|
||||
|
||||
$query = "SELECT identity_id FROM `identities` WHERE user_id=$user_id AND name='$id_name' AND email='$id_email' LIMIT 1";
|
||||
if (!$ids = $mysqli->query($query))
|
||||
{
|
||||
echo_stderr("Query error:\n".$query."\n".$mysqli->error."\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($ids->num_rows > 0)
|
||||
{
|
||||
$data = $ids->fetch_array();
|
||||
return $data['identity_id'];
|
||||
}
|
||||
|
||||
//No identity, must add it.
|
||||
$id_changed = mes(urldecode($identity->CHANGED));
|
||||
$id_standard = mes(urldecode($identity->STANDARD));
|
||||
$id_organization = mes(urldecode($identity->ORGANIZATION));
|
||||
$id_reply_to = mes(urldecode($identity['REPLY-TO']));
|
||||
$id_bcc = mes(urldecode($identity->BCC));
|
||||
$id_signature = mes(urldecode($identity->SIGNATURE));
|
||||
$id_html_signature =mes(urldecode($identity->HTML_SIGNATURE));
|
||||
|
||||
$query = "INSERT INTO `identities` (user_id, changed, standard, name, organization, email, `reply-to`, bcc, signature, html_signature) VALUES ($user_id, '$id_changed', $id_standard, '$id_name', '$id_organization', '$id_email', '$id_reply_to', '$id_bcc', '$id_signature', $id_html_signature)";
|
||||
if (!$ids = $mysqli->query($query))
|
||||
{
|
||||
echo_stderr("Query error:\n".$query."\n".$mysqli->error."\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $mysqli->insert_id;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* ensure that the User exists
|
||||
* yes: return user_id
|
||||
* no: add user, set data, resturn user_id
|
||||
*/
|
||||
function ensure_user($email)
|
||||
{
|
||||
global $mysqli, $rc_mail_host;
|
||||
$username = mes(urldecode($email->USERNAME));
|
||||
$query = "SELECT user_id FROM `users` WHERE username='$username' LIMIT 1";
|
||||
if (!$users = $mysqli->query($query))
|
||||
{
|
||||
echo_stderr("Query error:\n".$query."\n".$mysqli->error."\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($users->num_rows > 0)
|
||||
{
|
||||
$data = $users->fetch_array();
|
||||
return $data['user_id'];
|
||||
}
|
||||
|
||||
//No User, must add it.
|
||||
$created=mes(urldecode($email->CREATED));
|
||||
$last_login=mes(urldecode($email->LAST_LOGIN));
|
||||
$language=mes(urldecode($email->LANGUAGE));
|
||||
$preferences=mes(urldecode($email->PREFERENCES));
|
||||
|
||||
$query = "INSERT INTO `users` (username, mail_host, created, last_login, language, preferences) VALUES ('$username', '$rc_mail_host', '$created', '$last_login', '$language', '$preferences')";
|
||||
if (!$users = $mysqli->query($query))
|
||||
{
|
||||
echo_stderr("Query error:\n".$query."\n".$mysqli->error."\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $mysqli->insert_id;
|
||||
}
|
||||
|
||||
//**********************************************************************
|
||||
|
||||
function show_help()
|
||||
{
|
||||
global $mysql_db, $version;
|
||||
|
||||
echo_stderr("Roundcube $version restore script to restore Users.\n\n");
|
||||
echo_stderr("Usage:\n");
|
||||
echo_stderr(" username=username domain=domain.com xml_file=/path/to/rc.xml ".__FILE__."\n\n");
|
||||
|
||||
echo_stderr("The script will read in the XML specified by xml_file.\n");
|
||||
echo_stderr("It will insert the data into the $mysql_db database.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
function die_stderr($str)
|
||||
{
|
||||
echo_stderr($str);
|
||||
die();
|
||||
}
|
||||
|
||||
function echo_stderr($str)
|
||||
{
|
||||
$fd = fopen('php://stderr', 'w');
|
||||
fwrite($fd, $str);
|
||||
fclose($fd);
|
||||
}
|
||||
|
||||
function echo_debug($str)
|
||||
{
|
||||
global $is_debug;
|
||||
|
||||
if ($is_debug)
|
||||
echo $str;
|
||||
}
|
||||
|
||||
function mes($str)
|
||||
{
|
||||
global $mysqli;
|
||||
return $mysqli->real_escape_string($str);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/bin/sh
|
||||
DIG=/usr/bin/dig
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage:";
|
||||
echo " $0 <ip>";
|
||||
echo "";
|
||||
echo "where <ip> can be an IPv4 or IPv6 IP address.";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -s $DIG ]; then
|
||||
echo "Cannot find $DIG";
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
if [ ! -x $DIG ]; then
|
||||
echo "$DIG is not executable";
|
||||
exit 3;
|
||||
fi
|
||||
|
||||
IP=$1
|
||||
|
||||
if [ "$IP" = "" ]; then
|
||||
echo "IP value blank is not";
|
||||
fi
|
||||
|
||||
HAS_SHORT=1
|
||||
COUNT=`$DIG -h 2>&1 | grep -c '\[no\]short'`
|
||||
if [ $COUNT -eq 0 ]; then
|
||||
HAS_SHORT=0;
|
||||
fi
|
||||
|
||||
if [ "$HAS_SHORT" -eq 1 ]; then
|
||||
dig -x "$IP" +short 2>&1
|
||||
RET=$?
|
||||
else
|
||||
dig -x "$IP" 2>&1 | grep PTR | awk '{ print $5 }'
|
||||
RET=$?
|
||||
fi
|
||||
|
||||
exit $RET;
|
||||
@@ -1,86 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
DIR=/etc/virtual/usage
|
||||
USERS=/usr/local/directadmin/data/users
|
||||
|
||||
if [ ! -d $DIR ]; then
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
#for i in `ls $DIR | grep -e '.bytes$'`; do
|
||||
for i in `ls ${DIR}/*.bytes 2>/dev/null | cut -d/ -f5`; do
|
||||
{
|
||||
U_NAME=`echo $i | cut -d. -f1`
|
||||
#U_NAME=$i
|
||||
|
||||
BF=${DIR}/${i}
|
||||
|
||||
if [ ! -e ${BF} ]; then
|
||||
echo "rotate_email_usage.sh: cannot find ${BF}";
|
||||
fi
|
||||
|
||||
if [ -d $USERS/$U_NAME ]; then
|
||||
echo "0=type=timestamp&time=`date +%s`" >> $USERS/$U_NAME/bandwidth.tally
|
||||
#cat $DIR/$i >> $USERS/$U_NAME/bandwidth.tally
|
||||
cat ${BF} >> $USERS/$U_NAME/bandwidth.tally
|
||||
else
|
||||
echo "rotate_email_usage.sh: Cannot find $USERS/$U_NAME";
|
||||
fi
|
||||
};
|
||||
done;
|
||||
|
||||
rm -rf $DIR/*
|
||||
|
||||
#remove per-email counts:
|
||||
rm -f /etc/virtual/*/usage/*
|
||||
|
||||
|
||||
#dovecot.bytes entries.
|
||||
EV=/etc/virtual
|
||||
for i in `ls ${EV}/*/dovecot.bytes 2>/dev/null | cut -d/ -f4`; do
|
||||
{
|
||||
D=${EV}/${i};
|
||||
if [ -h $D ]; then
|
||||
continue;
|
||||
fi
|
||||
|
||||
#if it's empty, ignore it.
|
||||
DB=${D}/dovecot.bytes
|
||||
if [ ! -s ${DB} ]; then
|
||||
continue;
|
||||
fi
|
||||
|
||||
USERN=`grep -e "^$i:" /etc/virtual/domainowners | cut -d\ -f2`
|
||||
if [ "${USERN}" = "" ]; then
|
||||
echo "$i seems to be missing from /etc/virtual/domainowners";
|
||||
continue;
|
||||
fi
|
||||
|
||||
DU=${USERS}/${USERN}
|
||||
if [ ! -d "${DU}" ]; then
|
||||
echo "Cannot find owner of $i from domainowners";
|
||||
continue;
|
||||
fi
|
||||
|
||||
cat ${DB} >> ${DU}/bandwidth.tally
|
||||
|
||||
rm -f ${DB};
|
||||
};
|
||||
done;
|
||||
|
||||
|
||||
for i in `ls ${USERS}/*/dovecot.bytes 2>/dev/null | cut -d/ -f7`; do
|
||||
{
|
||||
DU=${USERS}/${i}
|
||||
DB=${DU}/dovecot.bytes
|
||||
if [ ! -s ${DB} ]; then
|
||||
continue;
|
||||
fi
|
||||
|
||||
cat ${DB} >> ${DU}/bandwidth.tally
|
||||
|
||||
rm -f ${DB};
|
||||
};
|
||||
done;
|
||||
|
||||
exit 0;
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
setenforce 0
|
||||
if [ -e /etc/selinux/config ]; then
|
||||
perl -pi -e 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
|
||||
perl -pi -e 's/SELINUX=permissive/SELINUX=disabled/' /etc/selinux/config
|
||||
fi
|
||||
if [ -e /selinux/enforce ]; then
|
||||
echo "0" > /selinux/enforce
|
||||
fi
|
||||
|
||||
if [ -e /usr/sbin/setenforce ]; then
|
||||
/usr/sbin/setenforce 0
|
||||
fi
|
||||
@@ -1,17 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
PS=/bin/ps
|
||||
AWK=/usr/bin/awk
|
||||
GREP=/bin/grep
|
||||
if [ ! -x $GREP ]; then
|
||||
GREP=/usr/bin/grep
|
||||
fi
|
||||
SORT=/bin/sort
|
||||
if [ ! -x $SORT ]; then
|
||||
SORT=/usr/bin/sort
|
||||
fi
|
||||
|
||||
$PS axo comm,rss | $AWK '{arr[$1]+=$2} END {for (i in arr) {print i "=" arr[i]/1024}}' | $GREP -v '=0$'
|
||||
|
||||
RET=$?
|
||||
exit $RET
|
||||
@@ -1,685 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Script to set the file ownerships and
|
||||
# permissions of all DA related files on
|
||||
# the system. Should be quite useful
|
||||
# for system restores, just make sure
|
||||
# that the user accounts have already
|
||||
# been created in the /etc/passwd,
|
||||
# /etc/shadow, /etc/group files.
|
||||
|
||||
OS=`uname`
|
||||
ECHO_LOG=1;
|
||||
SAVE_LOG=1;
|
||||
LOG=/tmp/set_perm.log
|
||||
ERRLOG=/tmp/set_perm.err.log
|
||||
|
||||
DAPATH=/usr/local/directadmin
|
||||
|
||||
RT_GRP="root";
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
RT_GRP="wheel";
|
||||
fi
|
||||
|
||||
DOVECOT=`grep -c 'dovecot=1' ${DAPATH}/conf/directadmin.conf`
|
||||
DIRECTADMIN=${DAPATH}/directadmin
|
||||
|
||||
HAVE_HTTPD=1
|
||||
HAVE_NGINX=0
|
||||
if [ -s ${DIRECTADMIN} ]; then
|
||||
if [ "`${DIRECTADMIN} c | grep ^nginx= | cut -d= -f2`" -eq 1 ]; then
|
||||
HAVE_HTTPD=0
|
||||
HAVE_NGINX=1
|
||||
fi
|
||||
if [ "`${DIRECTADMIN} c | grep ^nginx_proxy= | cut -d= -f2`" -eq 1 ]; then
|
||||
HAVE_HTTPD=1
|
||||
HAVE_NGINX=1
|
||||
fi
|
||||
fi
|
||||
|
||||
show_help()
|
||||
{
|
||||
echo "";
|
||||
echo "DirectAdmin File Permission/Ownership script";
|
||||
echo "";
|
||||
echo "Usage:";
|
||||
echo " $0 all";
|
||||
echo " $0 all_with_domaindirs";
|
||||
echo "";
|
||||
echo " $0 da_files"; #don't forget /home/tmp
|
||||
echo " $0 domaindirs";
|
||||
echo " $0 user_homes";
|
||||
echo " $0 mysql";
|
||||
echo " $0 email";
|
||||
echo " $0 logs";
|
||||
echo " $0 etc_configs";
|
||||
echo "";
|
||||
echo "internal:";
|
||||
echo " $0 maildir <user> <path/Maildir>";
|
||||
echo " $0 set_user_home <user>";
|
||||
echo " $0 domaindir <domainname> [<user>]; user could be skipped";
|
||||
echo "";
|
||||
}
|
||||
|
||||
#writes to log file
|
||||
log()
|
||||
{
|
||||
if [ $SAVE_LOG -eq 1 ]; then
|
||||
echo "$1" >> $LOG;
|
||||
fi
|
||||
if [ $ECHO_LOG -eq 1 ]; then
|
||||
echo "$1";
|
||||
fi
|
||||
}
|
||||
|
||||
error_log()
|
||||
{
|
||||
echo "Error: $1";
|
||||
echo "$1" >> $ERRLOG
|
||||
log "$1"
|
||||
}
|
||||
|
||||
###########
|
||||
# set_file /file user group 755 -R
|
||||
##########
|
||||
set_file()
|
||||
{
|
||||
if [ -e "$1" ] || [ "$6" = "nocheck" ]; then
|
||||
log "set $1 $2:$3 $4 flag $5";
|
||||
|
||||
#chown goes first.
|
||||
#A 4755 file is set to 755 if chown is called after chmod.
|
||||
|
||||
#if there is an asterisk, no quotes.
|
||||
if echo x"$1" | grep '*' > /dev/null; then
|
||||
chown $5 $2:$3 $1
|
||||
chmod $5 $4 $1
|
||||
else
|
||||
chown $5 $2:$3 "$1"
|
||||
chmod $5 $4 "$1"
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
###########################################
|
||||
# gets a list of the DA users on the system
|
||||
all_users()
|
||||
{
|
||||
for i in `ls $DAPATH/data/users`; do
|
||||
{
|
||||
if [ -e $DAPATH/data/users/$i/user.conf ]; then
|
||||
echo -n "$i ";
|
||||
fi
|
||||
};
|
||||
done;
|
||||
}
|
||||
|
||||
set_user_perm()
|
||||
{
|
||||
log "set_user_perm $1";
|
||||
DIR=$DAPATH/data/users/$1
|
||||
set_file $DIR diradmin diradmin 711
|
||||
set_file $DIR/bandwidth.tally root $RT_GRP 600
|
||||
set_file $DIR/ftp.passwd root ftp 640
|
||||
set_file $DIR/crontab.conf diradmin diradmin 600
|
||||
set_file $DIR/domains.list diradmin diradmin 600
|
||||
set_file $DIR/domains diradmin diradmin 711
|
||||
set_file $DIR/httpd.conf diradmin $1 640
|
||||
set_file $DIR/nginx.conf diradmin $1 640
|
||||
set_file $DIR/openlitespeed.conf diradmin lsadmn 640
|
||||
set_file $DIR/ticket.conf diradmin diradmin 600
|
||||
set_file $DIR/tickets.list diradmin diradmin 600
|
||||
set_file $DIR/user.conf diradmin diradmin 600
|
||||
set_file $DIR/user.usage diradmin diradmin 600
|
||||
set_file $DIR/user.history diradmin diradmin 600
|
||||
set_file $DIR/user.comments diradmin diradmin 600
|
||||
set_file $DIR/user_ip.list diradmin diradmin 600
|
||||
set_file $DIR/login.hist diradmin diradmin 600
|
||||
set_file $DIR/twostep_auth_secret.txt diradmin diradmin 600
|
||||
set_file $DIR/twostep_auth_scratch_codes.list diradmin diradmin 600
|
||||
set_file $DIR/login_keys diradmin diradmin 700
|
||||
set_file $DIR/skin_customizations diradmin diradmin 711
|
||||
set_file $DIR/history diradmin diradmin 700
|
||||
set_file "$DIR/history/*" diradmin diradmin 600 '' nocheck
|
||||
|
||||
|
||||
#hmm... do we want to rebuild the files?.. bit more than just "set permissions"
|
||||
|
||||
for j in `cat $DIR/domains/*.conf | grep -e '^domain=' | cut -d= -f2`; do
|
||||
{
|
||||
COUNT=`cat $DIR/domains.list | grep -c $j`
|
||||
if [ $COUNT -eq 0 ]; then
|
||||
log "Found missing domain $j for user $1";
|
||||
echo $j >> $DIR/domains.list
|
||||
fi
|
||||
};
|
||||
done;
|
||||
|
||||
set_file $DIR/domains diradmin diradmin 600 -R
|
||||
set_file $DIR/domains diradmin diradmin 711
|
||||
|
||||
SAC=`/usr/local/directadmin/directadmin c |grep '^secure_access_group=' | cut -d= -f2`
|
||||
SSL_PERM=640
|
||||
#if [ "${SAC}" = "" ]; then
|
||||
# SAC=diradmin
|
||||
# SSL_PERM=644
|
||||
#fi
|
||||
SAC=mail
|
||||
|
||||
set_file "$DIR/domains/*.cert" diradmin ${SAC} 640 '' nocheck
|
||||
set_file "$DIR/domains/*.cacert" diradmin ${SAC} 640 '' nocheck
|
||||
set_file "$DIR/domains/*.cert.combined" diradmin ${SAC} 640 '' nocheck
|
||||
set_file "$DIR/domains/*.key" diradmin ${SAC} 640 '' nocheck
|
||||
}
|
||||
|
||||
set_reseller_perm()
|
||||
{
|
||||
log "set_reseller_perm $1";
|
||||
DIR=$DAPATH/data/users/$1
|
||||
set_file $DIR/ip.list diradmin diradmin 600
|
||||
set_file $DIR/packages diradmin diradmin 600 -R
|
||||
set_file $DIR/packages diradmin diradmin 700
|
||||
set_file $DIR/packages.list diradmin diradmin 600
|
||||
set_file $DIR/reseller.allocation diradmin diradmin 600
|
||||
set_file $DIR/reseller.conf diradmin diradmin 600
|
||||
set_file $DIR/reseller.usage diradmin diradmin 600
|
||||
set_file $DIR/reseller.history diradmin diradmin 600
|
||||
set_file $DIR/u_welcome.txt diradmin diradmin 600
|
||||
set_file $DIR/bandwidth.tally.cache diradmin diradmin 600
|
||||
|
||||
set_file $DIR/users.list diradmin diradmin 600
|
||||
set_file $DIR/reseller.history diradmin diradmin 600
|
||||
|
||||
}
|
||||
|
||||
set_admin_perm()
|
||||
{
|
||||
log "set_admin_perm"
|
||||
DIR=$DAPATH/data/admin
|
||||
|
||||
set_file $DIR diradmin diradmin 600 -R
|
||||
set_file $DIR diradmin diradmin 700
|
||||
set_file $DIR/ip_access diradmin diradmin 700
|
||||
set_file $DIR/ips diradmin diradmin 700
|
||||
set_file $DIR/packages diradmin diradmin 700
|
||||
set_file $DIR/task_queue_processes diradmin diradmin 700
|
||||
}
|
||||
|
||||
da_files()
|
||||
{
|
||||
set_file /home/tmp root $RT_GRP 1777
|
||||
set_file $DAPATH diradmin diradmin 755
|
||||
set_file $DAPATH/conf diradmin diradmin 600 -R
|
||||
set_file $DAPATH/conf diradmin diradmin 700
|
||||
|
||||
if [ -e $DAPATH/directadmin ]; then
|
||||
$DAPATH/directadmin p
|
||||
fi
|
||||
|
||||
for i in `all_users`; do
|
||||
{
|
||||
set_user_perm $i
|
||||
|
||||
if [ -e $DAPATH/data/users/$i/reseller.conf ]; then
|
||||
set_reseller_perm $i
|
||||
fi
|
||||
};
|
||||
done;
|
||||
|
||||
set_file $DAPATH/data/users diradmin diradmin 711
|
||||
|
||||
set_admin_perm;
|
||||
|
||||
set_file $DAPATH/data/sessions diradmin diradmin 600 -R
|
||||
set_file $DAPATH/data/sessions diradmin diradmin 700
|
||||
|
||||
set_file $DAPATH/data/tickets diradmin diradmin 700 -R
|
||||
#set_file "$DAPATH/data/tickets/*" diradmin diradmin 700
|
||||
#set_file "$DAPATH/data/tickets/*/*" diradmin diradmin 700
|
||||
set_file "$DAPATH/data/tickets/*/*/*" diradmin diradmin 600 '' nocheck
|
||||
}
|
||||
|
||||
set_user_home()
|
||||
{
|
||||
log "set_user_home $1";
|
||||
UHOME=`grep -e "^${1}:" /etc/passwd | cut -d: -f6`
|
||||
|
||||
if [ "$UHOME" = "" ]; then
|
||||
log "Home directory for $1 is empty. Check the /etc/passwd file, make sure the account exists";
|
||||
return;
|
||||
fi
|
||||
|
||||
set_file $UHOME $1 $1 711
|
||||
set_file $UHOME/.shadow $1 mail 640
|
||||
set_file $UHOME/domains $1 $1 711
|
||||
set_file "$UHOME/domains/*" $1 $1 711 '' nocheck
|
||||
set_file $UHOME/domains/default $1 $1 755
|
||||
set_file $UHOME/domains/sharedip $1 $1 755
|
||||
set_file $UHOME/domains/suspended $1 $1 755
|
||||
set_file $UHOME/backups $1 $1 700
|
||||
set_file "$UHOME/backups/*" $1 $1 600 '' nocheck
|
||||
set_file $UHOME/user_backups $1 $1 711
|
||||
set_file "$UHOME/user_backups/*" $1 $1 755 '' nocheck
|
||||
set_file $UHOME/imap $1 mail 770 -R
|
||||
set_file $UHOME/.spamassassin $1 mail 771
|
||||
set_file $UHOME/.spamassassin/spam $1 mail 660
|
||||
set_file $UHOME/.spamassassin/user_spam $1 mail 771
|
||||
set_file "$UHOME/.spamassassin/user_spam/*" mail $1 660
|
||||
|
||||
# not sure how much else we should do.. the public_html and cgi-bins
|
||||
# should really be left untouched in case of any custom permission
|
||||
# like being owned by apache, or 777 etc.
|
||||
|
||||
#reset for secure_access_group
|
||||
SAC=`grep -c secure_access_group /usr/local/directadmin/conf/directadmin.conf`
|
||||
if [ "$SAC" -gt 0 ]; then
|
||||
echo "action=rewrite&value=secure_access_group" >> /usr/local/directadmin/data/task.queue
|
||||
fi
|
||||
}
|
||||
|
||||
user_homes()
|
||||
{
|
||||
log "user_homes"
|
||||
|
||||
set_file /home root $RT_GRP 711
|
||||
|
||||
for i in `all_users`; do
|
||||
{
|
||||
set_user_home $i
|
||||
};
|
||||
done;
|
||||
|
||||
}
|
||||
|
||||
do_mysql()
|
||||
{
|
||||
log "do_mysql";
|
||||
|
||||
MDIR=/var/lib/mysql
|
||||
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
if [ -e /home/mysql ]; then
|
||||
MDIR=/home/mysql
|
||||
else
|
||||
MDIR=/usr/local/mysql/data
|
||||
fi
|
||||
fi
|
||||
if [ -e /etc/debian_version ]; then
|
||||
if [ -e /home/mysql ]; then
|
||||
MDIR=/home/mysql
|
||||
else
|
||||
MDIR=/usr/local/mysql/data
|
||||
fi
|
||||
fi
|
||||
|
||||
chown -R mysql:mysql $MDIR;
|
||||
find $MDIR -type d -exec chmod 700 {} \;
|
||||
find $MDIR -type f -exec chmod 660 {} \;
|
||||
|
||||
set_file "${MDIR}*" mysql mysql 711 '' nocheck
|
||||
}
|
||||
|
||||
get_domain_user()
|
||||
{
|
||||
if [ "$1" = "" ]; then
|
||||
error_log "get_domain_user: no domain passed";
|
||||
echo "";
|
||||
return;
|
||||
fi
|
||||
|
||||
USERN=`grep -e "^$1:" /etc/virtual/domainowners | cut -d\ -f2`
|
||||
if [ "$USERN" = "" ]; then
|
||||
error_log "can't find user for $1 in /etc/virtual/domainowners";
|
||||
echo "";
|
||||
return;
|
||||
fi
|
||||
|
||||
echo "$USERN";
|
||||
}
|
||||
|
||||
set_maildir()
|
||||
{
|
||||
if [ "$2" = "" ]; then
|
||||
log "***Warning empty Maildir string***";
|
||||
return;
|
||||
fi
|
||||
|
||||
if [ ! -e $2 ]; then
|
||||
log "cannot find $2 : skipping";
|
||||
return;
|
||||
fi
|
||||
|
||||
user=$1;
|
||||
md=$2;
|
||||
|
||||
set_file $md $user mail 770
|
||||
chown -R $user:mail $md
|
||||
|
||||
OLD_EL=$ECHO_LOG
|
||||
ECHO_LOG=0
|
||||
|
||||
chown -R $user:mail $md;
|
||||
find $md -type d -exec chmod 770 {} \;
|
||||
find $md -type f -exec chmod 660 {} \;
|
||||
|
||||
ECHO_LOG=$OLD_EL
|
||||
}
|
||||
|
||||
set_domaindir()
|
||||
{
|
||||
if [ "$1" = "" ]; then
|
||||
log "***Warning empty domainname string***"
|
||||
show_help
|
||||
return
|
||||
fi
|
||||
|
||||
if [ "$2" = "" ]; then
|
||||
USERN=`get_domain_user $1`
|
||||
if [ "$USERN" = "" ]; then
|
||||
log "***Warning cannot get user for domain $1***"
|
||||
return
|
||||
fi
|
||||
else
|
||||
USERN="$2"
|
||||
fi
|
||||
|
||||
HOMEDIR=`getent passwd "$USERN" | cut -d: -f6`;
|
||||
|
||||
DOMAINDIR="${HOMEDIR}/domains/${1}"
|
||||
|
||||
if [ ! -e $DOMAINDIR ]; then
|
||||
log "cannot find $DOMAINDIR : skipping";
|
||||
return;
|
||||
fi
|
||||
|
||||
log "Directories found, setting permissions for ${DOMAINDIR}/public_html and private_html"
|
||||
|
||||
if [ -d "${DOMAINDIR}/public_html" ]; then
|
||||
chown -R ${USERN}:${USERN} "${DOMAINDIR}/public_html/"
|
||||
find "${DOMAINDIR}/public_html/" -type d -exec chmod 755 {} \;
|
||||
find "${DOMAINDIR}/public_html/" -type f -exec chmod 644 {} \;
|
||||
fi
|
||||
|
||||
if [ -L "${DOMAINDIR}/private_html" ]; then
|
||||
chown -h ${USERN}:${USERN} "${DOMAINDIR}/private_html"
|
||||
elif [ -d "${DOMAINDIR}/private_html" ]; then
|
||||
chown -R ${USERN}:${USERN} "${DOMAINDIR}/private_html/"
|
||||
find "${DOMAINDIR}/private_html" -type d -exec chmod 755 {} \;
|
||||
find "${DOMAINDIR}/private_html" -type f -exec chmod 644 {} \;
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
set_domaindirs() {
|
||||
for user in `ls /usr/local/directadmin/data/users`; do
|
||||
{
|
||||
for domain in `grep ": $user" /etc/virtual/domainowners | cut -d: -f1`; do
|
||||
{
|
||||
set_domaindir ${domain} ${user}
|
||||
};
|
||||
done
|
||||
};
|
||||
done
|
||||
}
|
||||
|
||||
set_dovecot()
|
||||
{
|
||||
log "dovecot";
|
||||
for i in `all_users`; do
|
||||
{
|
||||
uhome=`grep -e "^${i}:" /etc/passwd | cut -d: -f6`
|
||||
if [ "$uhome" = "" ]; then
|
||||
continue;
|
||||
fi
|
||||
$0 maildir $i $uhome/Maildir
|
||||
set_file $uhome/imap $i mail 770
|
||||
if [ -s /usr/local/directadmin/data/users/${i}/domains.list ]; then
|
||||
for domain in `cat /usr/local/directadmin/data/users/${i}/domains.list`; do {
|
||||
cat /etc/virtual/${domain}/passwd | cut -d: -f6 | sort | uniq | while read line; do {
|
||||
if [ ! -d ${line}/domains ]; then
|
||||
chown $user:mail "${line}"
|
||||
chmod 770 "${line}"
|
||||
fi
|
||||
$0 maildir ${i} "${line}/Maildir"
|
||||
}
|
||||
done
|
||||
}
|
||||
done
|
||||
fi
|
||||
};
|
||||
done;
|
||||
}
|
||||
|
||||
email()
|
||||
{
|
||||
log "email";
|
||||
|
||||
VDIR=/etc/virtual
|
||||
HN=`hostname`
|
||||
|
||||
set_file $VDIR mail mail 755
|
||||
|
||||
set_file $VDIR/domainowners mail mail 640
|
||||
set_file $VDIR/domains mail mail 640
|
||||
set_file $VDIR/pophosts mail mail 600
|
||||
set_file $VDIR/pophosts_user mail mail 600
|
||||
set_file $VDIR/majordomo majordomo daemon 750
|
||||
|
||||
set_file $VDIR/bad_sender_hosts mail mail 600
|
||||
set_file $VDIR/bad_sender_hosts_ip mail mail 600
|
||||
set_file $VDIR/blacklist_domains mail mail 600
|
||||
set_file $VDIR/blacklist_senders mail mail 600
|
||||
set_file $VDIR/whitelist_domains mail mail 600
|
||||
set_file $VDIR/whitelist_hosts mail mail 600
|
||||
set_file $VDIR/whitelist_hosts_ip mail mail 600
|
||||
set_file $VDIR/whitelist_senders mail mail 600
|
||||
set_file $VDIR/use_rbl_domains mail mail 600
|
||||
set_file $VDIR/skip_av_domains mail mail 600
|
||||
set_file $VDIR/skip_rbl_domains mail mail 600
|
||||
|
||||
for i in `cat /etc/virtual/domainowners | cut -d ":" -f 1`; do
|
||||
{
|
||||
if [ "$i" = "$HN" ]; then
|
||||
continue;
|
||||
fi
|
||||
|
||||
if [ -d $VDIR/$i ]; then
|
||||
|
||||
USERN=`get_domain_user $i`;
|
||||
if [ "$USERN" = "" ]; then
|
||||
USERN="mail";
|
||||
fi
|
||||
|
||||
set_file $VDIR/$i mail mail 711
|
||||
DDIR=$VDIR/$i
|
||||
set_file $DDIR/aliases mail mail 600
|
||||
set_file $DDIR/filter mail mail 640
|
||||
set_file $DDIR/filter.conf mail mail 600
|
||||
set_file $DDIR/passwd mail mail 600
|
||||
set_file $DDIR/quota mail mail 600
|
||||
|
||||
set_file $DDIR/dkim.private.key mail mail 600
|
||||
set_file $DDIR/dkim.public.key mail mail 600
|
||||
set_file $DDIR/dovecot.bytes mail mail 600
|
||||
|
||||
set_file $DDIR/vacation.conf mail mail 600
|
||||
set_file $DDIR/autoresponder.conf mail mail 600
|
||||
set_file $DDIR/reply mail mail 700
|
||||
set_file "$DDIR/reply/*" mail mail 600 '' nocheck
|
||||
set_file $DDIR/majordomo majordomo daemon 751
|
||||
set_file $DDIR/majordomo/majordomo.cf majordomo daemon 640
|
||||
set_file $DDIR/majordomo/list.aliases majordomo mail 640
|
||||
set_file $DDIR/majordomo/private.aliases majordomo mail 640
|
||||
set_file $DDIR/majordomo/archive majordomo daemon 751
|
||||
set_file $DDIR/majordomo/digests majordomo daemon 751
|
||||
set_file $DDIR/majordomo/lists majordomo daemon 751
|
||||
chown -R majordomo:daemon $DDIR/majordomo/lists
|
||||
|
||||
fi
|
||||
};
|
||||
done;
|
||||
|
||||
if [ "$DOVECOT" -eq 0 ]; then
|
||||
VSV=/var/spool/virtual
|
||||
set_file $VSV mail mail 1777
|
||||
|
||||
for i in `all_users`; do
|
||||
{
|
||||
set_file $VSV/$i $i mail 770
|
||||
set_file "$VSV/$i/*" $i mail 660 '' nocheck
|
||||
|
||||
};
|
||||
done;
|
||||
|
||||
|
||||
SPOOLM=/var/spool/mail
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
SPOOLM=/var/mail
|
||||
fi
|
||||
|
||||
set_file $SPOOLM mail mail 1777
|
||||
|
||||
for i in `all_users`; do
|
||||
{
|
||||
set_file $SPOOLM/$i $i mail 660
|
||||
};
|
||||
done;
|
||||
|
||||
|
||||
fi
|
||||
|
||||
set_file /var/spool/exim mail mail 750
|
||||
set_file "/var/spool/exim/*" mail mail 750 '' nocheck
|
||||
#set_file "/var/spool/exim/*/*" mail mail 640 '' nocheck
|
||||
chown -R mail:mail /var/spool/exim
|
||||
|
||||
set_file /etc/exim.cert mail mail 644
|
||||
set_file /etc/exim.key mail mail 600
|
||||
|
||||
if [ "$DOVECOT" -eq 1 ]; then
|
||||
set_dovecot;
|
||||
fi
|
||||
|
||||
mkdir -p /var/log/exim
|
||||
set_file /var/log/exim mail mail 640 -R
|
||||
set_file /var/log/exim mail mail 750
|
||||
|
||||
set_file /usr/sbin/exim root $RT_GRP 4755
|
||||
}
|
||||
|
||||
logs()
|
||||
{
|
||||
log "logs";
|
||||
|
||||
VL=/var/log
|
||||
|
||||
if [ ! -e $VL/directadmin ]; then
|
||||
error_log "$VL/directadmin didn't exists, creating it.";
|
||||
mkdir -p $VL/directadmin
|
||||
fi
|
||||
|
||||
set_file $VL/directadmin diradmin diradmin 700
|
||||
set_file "$VL/directadmin/*" diradmin diradmin 600 '' nocheck
|
||||
|
||||
|
||||
mkdir -p $VL/exim
|
||||
set_file $VL/exim mail mail 755
|
||||
set_file "$VL/exim/*" mail mail 644 '' nocheck
|
||||
|
||||
mkdir -p $VL/proftpd
|
||||
set_file $VL/proftpd root $RT_GRP 755
|
||||
set_file "$VL/proftpd/*" root $RT_GRP 644 '' nocheck
|
||||
|
||||
if [ "${HAVE_HTTPD}" -eq 1 ]; then
|
||||
#http.. well it's all root, permissions don't really matter
|
||||
mkdir -p /var/log/httpd/domains
|
||||
chmod 710 /var/log/httpd
|
||||
chmod 710 /var/log/httpd/domains
|
||||
chown root:nobody /var/log/httpd/domains
|
||||
fi
|
||||
if [ "${HAVE_NGINX}" -eq 1 ]; then
|
||||
mkdir -p /var/log/nginx/domains
|
||||
chmod 710 /var/log/nginx
|
||||
chmod 710 /var/log/nginx/domains
|
||||
chown root:nobody /var/log/httpd/domains
|
||||
fi
|
||||
}
|
||||
|
||||
etc_configs()
|
||||
{
|
||||
log "etc_configs";
|
||||
|
||||
set_file "/etc/exim.*" root $RT_GRP 755 '' nocheck
|
||||
set_file /etc/system_filter.exim root $RT_GRP 755
|
||||
|
||||
set_file /etc/proftpd.conf root $RT_GRP 644
|
||||
set_file /etc/proftpd.vhosts.conf root $RT_GRP 644
|
||||
set_file /etc/proftpd.passwd root ftp 640
|
||||
|
||||
#httpd.. again, all root.. nothing special about it.
|
||||
}
|
||||
|
||||
all()
|
||||
{
|
||||
da_files;
|
||||
user_homes;
|
||||
do_mysql;
|
||||
email;
|
||||
logs;
|
||||
etc_configs;
|
||||
}
|
||||
|
||||
all_with_domaindirs() {
|
||||
all
|
||||
set_domaindirs
|
||||
}
|
||||
|
||||
if [ "$1" != "maildir" ]; then
|
||||
log "***********************************************";
|
||||
log "`date` : $0 $1";
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
all) all;
|
||||
;;
|
||||
|
||||
all_with_domaindirs) all_with_domaindirs;
|
||||
;;
|
||||
|
||||
da_files) da_files;
|
||||
;;
|
||||
|
||||
user_homes) user_homes;
|
||||
;;
|
||||
|
||||
set_user_home) set_user_home $2
|
||||
;;
|
||||
|
||||
mysql) do_mysql;
|
||||
;;
|
||||
|
||||
email) email;
|
||||
;;
|
||||
|
||||
logs) logs;
|
||||
;;
|
||||
|
||||
etc_configs) etc_configs;
|
||||
;;
|
||||
|
||||
maildir) set_maildir $2 $3;
|
||||
;;
|
||||
|
||||
domaindir) set_domaindir $2 $3;
|
||||
;;
|
||||
|
||||
domaindirs) set_domaindirs;
|
||||
;;
|
||||
|
||||
*) show_help;
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
exit 0;
|
||||
@@ -1,85 +0,0 @@
|
||||
#!/bin/bash
|
||||
#VERSION=0.0.1
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to move user from one reseller to another
|
||||
# Official DirectAdmin webpage: http://www.directadmin.com
|
||||
# Usage:
|
||||
# ./squirrelmail_to_roundcube.sh <email@domain.com> </var/www/html/squirrelmail/data/email@domain.com.abook>
|
||||
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "$MYUID" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ $# != 2 ]; then
|
||||
echo "Usage:";
|
||||
echo "$0 <email@domain.com> </var/www/html/squirrelmail/data/email@domain.com.abook>";
|
||||
echo "you gave #$#: $0 $1 $2";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
#https://newfivefour.com/unix-urlencode-urldecode-command-line-bash.html
|
||||
urlencode() {
|
||||
# urlencode <string>
|
||||
|
||||
local length="${#1}"
|
||||
for (( i = 0; i < length; i++ )); do
|
||||
local c="${1:i:1}"
|
||||
case $c in
|
||||
[a-zA-Z0-9.~_-]) printf "$c" ;;
|
||||
*) printf '%s' "$c" | xxd -p -c1 |
|
||||
while read c; do printf '%%%s' "$c"; done ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
INPUTFILE="$2"
|
||||
if [ -s "${INPUTFILE}" ]; then
|
||||
OUTPUTFILE="/tmp/${1}_to_roundcube.xml"
|
||||
|
||||
printf "<ROUNDCUBE>\n" > "${OUTPUTFILE}"
|
||||
USERNAME="`urlencode \"${1}\" | perl -p0 -e 's|%|%%|g'`"
|
||||
printf "\t<EMAIL>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t<USERNAME>${USERNAME}</USERNAME>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t<INDENTITIES></INDENTITIES>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t<CONTACTS>\n" >> "${OUTPUTFILE}"
|
||||
while read LINE; do {
|
||||
FIRSTNAME_D="`echo \"${LINE}\" | cut -d'|' -f2`"
|
||||
LASTNAME_D="`echo \"${LINE}\" | cut -d'|' -f3`"
|
||||
EMAIL_D="`echo \"${LINE}\" | cut -d'|' -f4`"
|
||||
INFO_D="`echo \"${LINE}\" | cut -d'|' -f5`"
|
||||
DATE_D="`date '+%Y-%m-%d %H:%M:%S'`"
|
||||
FIRSTNAME="`urlencode \"${FIRSTNAME_D}\" | perl -p0 -e 's|%|%%|g'`"
|
||||
LASTNAME="`urlencode \"${LASTNAME_D}\" | perl -p0 -e 's|%|%%|g'`"
|
||||
EMAIL="`urlencode \"${EMAIL_D}\" | perl -p0 -e 's|%|%%|g'`"
|
||||
INFO="`urlencode \"${INFO_D}\" | perl -p0 -e 's|%|%%|g'`"
|
||||
DATE="`urlencode \"${DATE_D}\" | perl -p0 -e 's|%|%%|g'`"
|
||||
printf "\t\t\t<CONTACT>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t\t\t<EMAIL>${EMAIL}</EMAIL>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t\t\t<NAME></NAME>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t\t\t<CHANGED>${DATE}</CHANGED>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t\t\t<FIRSTNAME>${FIRSTNAME}</FIRSTNAME>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t\t\t<SURNAME>${LASTNAME}</SURNAME>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t\t\t<VCARD>BEGIN%%3AVCARD%%0AVERSION%%3A3.0%%0AFN%%3A${FIRSTNAME}+${LASTNAME}.%%0AEMAIL%%3BTYPE%%3DINTERNET%%3A${EMAIL}%%0AEND%%3AVCARD</VCARD>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t\t\t<WORDS>${INFO}</WORDS>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t\t\t<GROUPS>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t\t\t</GROUPS>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t\t\t</CONTACT>\n" >> "${OUTPUTFILE}"
|
||||
};
|
||||
done < "${INPUTFILE}"
|
||||
printf "\t\t</CONTACTS>\n" >> "${OUTPUTFILE}"
|
||||
printf "\t</EMAIL>\n" >> "${OUTPUTFILE}"
|
||||
printf "</ROUNDCUBE>\n" >> "${OUTPUTFILE}"
|
||||
|
||||
DOMAIN_TO_RESTORE="`echo \"${1}\" | cut -d\@ -f2`"
|
||||
if [ -s /usr/local/directadmin/scripts/restore_roundcube.php ]; then
|
||||
username="${1}" domain="${DOMAIN_TO_RESTORE}" xml_file="${OUTPUTFILE}" /usr/local/directadmin/scripts/restore_roundcube.php
|
||||
else
|
||||
echo "Unable to find /usr/local/directadmin/scripts/restore_roundcube.php for restore"
|
||||
rm -f "${OUTPUTFILE}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f "${OUTPUTFILE}"
|
||||
fi
|
||||
@@ -1,55 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# chkconfig: 2345 11 50
|
||||
# description: Load ip's into the network device
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: startips
|
||||
# Required-Start: $local_fs $network
|
||||
# Required-Stop: $local_fs
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: startips
|
||||
# Description: script to load in fresh IPs
|
||||
### END INIT INFO
|
||||
|
||||
case "$1" in
|
||||
stop)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
DACONF=/usr/local/directadmin/conf/directadmin.conf
|
||||
IPPATH="/usr/local/directadmin/data/admin/"
|
||||
IPDIR="ips/"
|
||||
IPLIST="ip.list"
|
||||
ADDIP=`grep -m1 '^addip=' ${DACONF} | cut -d= -f2`
|
||||
OS=`uname`
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
ETH_DEV=`grep -m1 '^ifconfig_' /etc/rc.conf | cut -d= -f1 | cut -d_ -f2`
|
||||
else
|
||||
ETH_DEV=eth0
|
||||
fi
|
||||
|
||||
if grep -m1 -q '^ethernet_dev=' ${DACONF}; then
|
||||
ETH_DEV=`grep -m1 '^ethernet_dev=' ${DACONF} | cut -d= -f2 | cut -d: -f1`
|
||||
fi
|
||||
|
||||
for i in `cat ${IPPATH}${IPLIST}`; do
|
||||
{
|
||||
NETMASK=`grep -m1 '^netmask=' ${IPPATH}${IPDIR}${i} | cut -d= -f2`
|
||||
if [ -z ${NETMASK} ]; then
|
||||
if echo ${i} | grep -m1 -q ':'; then
|
||||
NETMASK="/64"
|
||||
else
|
||||
NETMASK=255.255.255.0
|
||||
fi
|
||||
fi
|
||||
$ADDIP $i $NETMASK $ETH_DEV >/dev/null
|
||||
};
|
||||
done
|
||||
|
||||
echo "action=named&value=restart" >> /usr/local/directadmin/data/task.queue
|
||||
|
||||
exit 0
|
||||
@@ -1,16 +0,0 @@
|
||||
# DirectAdmin control panel
|
||||
# To reload systemd daemon after changes to this file:
|
||||
# systemctl --system daemon-reload
|
||||
[Unit]
|
||||
Description=Start the additional IPs
|
||||
Wants=network-online.target
|
||||
After=syslog.target network.target network-online.target
|
||||
Requires=network.target
|
||||
Documentation=http://www.directadmin.com
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/directadmin/scripts/startips start
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,59 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
CWD=`pwd`
|
||||
|
||||
NAME=sysbk
|
||||
PRIMARY=http://files.directadmin.com/services
|
||||
SECONDARY=http://files3.directadmin.com/services
|
||||
SAVE=/usr/local/directadmin/scripts/packages
|
||||
FILE=${NAME}.tar.gz
|
||||
DIR=/usr/local
|
||||
|
||||
OS=`uname`
|
||||
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
WGET=/usr/local/bin/wget
|
||||
else
|
||||
WGET=/usr/bin/wget
|
||||
fi
|
||||
|
||||
if [ ! -e $SAVE/$FILE ]; then
|
||||
$WGET -O $SAVE/$FILE $PRIMARY/$FILE
|
||||
fi
|
||||
if [ ! -e $SAVE/$FILE ]; then
|
||||
$WGET -O $SAVE/$FILE $SECONDARY/$FILE
|
||||
fi
|
||||
if [ ! -e $SAVE/$FILE ]; then
|
||||
echo "Unable to get $SAVE/$FILE"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
cd $DIR
|
||||
|
||||
tar xzf $SAVE/$FILE
|
||||
|
||||
#swap out linux files for freebsd file:
|
||||
if [ "$OS" = "FreeBSD" ]; then
|
||||
|
||||
FILES=$DIR/$NAME/mod/custom.files
|
||||
perl -pi -e 's#/etc/shadow#/etc/master.passwd#' $FILES
|
||||
|
||||
DIRS=$DIR/$NAME/mod/custom.dirs
|
||||
perl -pi -e 's#/var/spool/mail#/var/mail#' $DIRS
|
||||
perl -pi -e 's#/var/spool/cron#/var/cron#' $DIRS
|
||||
fi
|
||||
|
||||
|
||||
KEY=/root/.ssh/id_dsa
|
||||
if [ ! -e $KEY ]; then
|
||||
/usr/bin/ssh-keygen -t dsa -N '' -q -f $KEY
|
||||
fi
|
||||
|
||||
cd /usr/local/directadmin/scripts
|
||||
|
||||
#if [ ! -e "/usr/bin/ncftpput" ]; then
|
||||
# ./ncftp.sh
|
||||
#fi
|
||||
|
||||
|
||||
cd $CWD;
|
||||
@@ -1,227 +0,0 @@
|
||||
#!/bin/sh
|
||||
#VERSION=0.2
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to recreate tlsa records for domain
|
||||
# Official DirectAdmin webpage: http://www.directadmin.com
|
||||
# Usage:
|
||||
# ./tlsa <domain>
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "${MYUID}" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
DA_BIN=/usr/local/directadmin/directadmin
|
||||
TASK_QUEUE=/usr/local/directadmin/data/task.queue.cb
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "usage: $0 <domain> <web|mail|all>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OPENSSL=/usr/bin/openssl
|
||||
|
||||
run_dataskq() {
|
||||
DATASKQ_OPT=$1
|
||||
/usr/local/directadmin/dataskq ${DATASKQ_OPT} --custombuild
|
||||
}
|
||||
|
||||
DOMAIN=$1
|
||||
TLSATYPE=$2
|
||||
case "$TLSATYPE" in
|
||||
"all")
|
||||
;;
|
||||
"web")
|
||||
;;
|
||||
"mail")
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 <domain> <web|mail|all>"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
DOMAINARR=`echo "${DOMAIN}" | perl -p0 -e "s/,/ /g"`
|
||||
|
||||
FOUNDDOMAIN=0
|
||||
for TDOMAIN in ${DOMAINARR}
|
||||
do
|
||||
DOMAIN=${TDOMAIN}
|
||||
|
||||
DOMAIN_ESCAPED="`echo ${DOMAIN} | perl -p0 -e 's#\.#\\\.#g'`"
|
||||
|
||||
if grep -m1 -q "^${DOMAIN_ESCAPED}:" /etc/virtual/domainowners; then
|
||||
USER=`grep -m1 "^${DOMAIN_ESCAPED}:" /etc/virtual/domainowners | cut -d' ' -f2`
|
||||
HOSTNAME=0
|
||||
FOUNDDOMAIN=1
|
||||
break
|
||||
elif grep -m1 -q "^${DOMAIN_ESCAPED}$" /etc/virtual/domains; then
|
||||
USER="root"
|
||||
if ${DA_BIN} c | grep -m1 -q "^servername=${DOMAIN_ESCAPED}\$"; then
|
||||
HOSTNAME=1
|
||||
FOUNDDOMAIN=1
|
||||
break
|
||||
else
|
||||
echo "Domain exists in /etc/virtual/domains, but is not set as a hostname in DirectAdmin. Unable to find 'servername=${DOMAIN}' in the output of '/usr/local/directadmin/directadmin c'."
|
||||
#exit 1
|
||||
fi
|
||||
else
|
||||
echo "Domain does not exist on the system. Unable to find ${DOMAIN} in /etc/virtual/domainowners."
|
||||
#exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${FOUNDDOMAIN} -eq 0 ]; then
|
||||
echo "no valid domain found - exiting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DA_USERDIR="/usr/local/directadmin/data/users/${USER}"
|
||||
DA_CONFDIR="/usr/local/directadmin/conf"
|
||||
|
||||
if [ ! -d "${DA_USERDIR}" ] && [ "${HOSTNAME}" -eq 0 ]; then
|
||||
echo "${DA_USERDIR} not found, exiting..."
|
||||
exit 1
|
||||
elif [ ! -d "${DA_CONFDIR}" ] && [ "${HOSTNAME}" -eq 1 ]; then
|
||||
echo "${DA_CONFDIR} not found, exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
try_gen_tlsa() {
|
||||
if [ ! -x /usr/local/directadmin/directadmin ]; then
|
||||
echo 1
|
||||
else
|
||||
if ! /usr/local/directadmin/directadmin c | grep -m1 -q '^dns_tlsa=1$'; then
|
||||
echo 2
|
||||
else
|
||||
if [ "${HOSTNAME}" -eq 0 ]; then
|
||||
CERT="${DA_USERDIR}/domains/${DOMAIN}.cert"
|
||||
else
|
||||
CERT=`${DA_BIN} c |grep ^cacert= | cut -d= -f2`
|
||||
fi
|
||||
|
||||
if [ ! -f "${CERT}" ] && [ "$TLSATYPE" == "web" ]; then
|
||||
echo 2
|
||||
else
|
||||
#TLSA_HASH_SHA256=`${OPENSSL} x509 -in ${CERT} -outform DER | ${OPENSSL} sha256 | cut -d' ' -f2`
|
||||
#TLSA_HASH_SHA512=`${OPENSSL} x509 -in ${CERT} -outform DER | ${OPENSSL} sha512 | cut -d' ' -f2`
|
||||
#TLSA_HASH_SHA256_PUB=`${OPENSSL} x509 -in ${CERT} -noout -pubkey | ${OPENSSL} pkey -pubin -outform DER |${OPENSSL} sha256 | cut -d' ' -f2`
|
||||
#TLSA_HASH_SHA512_PUB=`${OPENSSL} x509 -in ${CERT} -noout -pubkey | ${OPENSSL} pkey -pubin -outform DER |${OPENSSL} sha512 | cut -d' ' -f2`
|
||||
|
||||
#CATLSA_HASH_SHA256=`${OPENSSL} x509 -in ${CACERT} -outform DER | ${OPENSSL} sha256 | cut -d' ' -f2`
|
||||
#CATLSA_HASH_SHA512=`${OPENSSL} x509 -in ${CACERT} -outform DER | ${OPENSSL} sha512 | cut -d' ' -f2`
|
||||
#CATLSA_HASH_SHA256_PUB=`${OPENSSL} x509 -in ${CACERT} -noout -pubkey | ${OPENSSL} pkey -pubin -outform DER |${OPENSSL} sha256 | cut -d' ' -f2`
|
||||
#CATLSA_HASH_SHA512_PUB=`${OPENSSL} x509 -in ${CACERT} -noout -pubkey | ${OPENSSL} pkey -pubin -outform DER |${OPENSSL} sha512 | cut -d' ' -f2`
|
||||
|
||||
GENERATED=0
|
||||
if [ "$TLSATYPE" == "web" ] || [ "$TLSATYPE" == "all" ]; then
|
||||
TLSA_HASH_SHA256_PUB=`${OPENSSL} x509 -in ${CERT} -noout -pubkey | ${OPENSSL} pkey -pubin -outform DER |${OPENSSL} sha256 | cut -d' ' -f2`
|
||||
DNSLIST=`openssl x509 -in ${CERT} -text -noout| grep -A1 "Subject Alternative Name"|tail -1`
|
||||
for DNSN in ${DNSLIST}; do {
|
||||
DNSN=`echo ${DNSN}|cut -d':' -f2| tr -d ','`
|
||||
if [ "${DNSN}" == "${DOMAIN}" ]; then
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 3 0 1 ${TLSA_HASH_SHA256}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 3 0 2 ${TLSA_HASH_SHA512}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 3 1 1 ${TLSA_HASH_SHA256_PUB}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 3 1 2 ${TLSA_HASH_SHA512_PUB}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 2 0 1 ${CATLSA_HASH_SHA256}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 2 0 2 ${CATLSA_HASH_SHA512}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 2 1 1 ${CATLSA_HASH_SHA256_PUB}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 2 1 2 ${CATLSA_HASH_SHA512_PUB}"
|
||||
HOST_TLSA="_443._tcp.${DNSN}."
|
||||
HOST_TLSA_VAL="3 1 1 ${TLSA_HASH_SHA256_PUB}"
|
||||
DOM256="_443._tcp.${DNSN}. 300 IN TLSA 3 1 1 ${TLSA_HASH_SHA256_PUB}"
|
||||
echo "action=dns&do=delete&domain=${DOMAIN}&type=TLSA&name=${HOST_TLSA}" >> ${TASK_QUEUE}
|
||||
run_dataskq
|
||||
echo "action=dns&do=add&domain=${DOMAIN}&type=TLSA&name=${HOST_TLSA}&value=${HOST_TLSA_VAL}&ttl=300&named_reload=yes" >> ${TASK_QUEUE}
|
||||
run_dataskq
|
||||
GENERATED=1
|
||||
elif [ "${DNSN}" == "www.${DOMAIN}" ]; then
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 3 0 1 ${TLSA_HASH_SHA256}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 3 0 2 ${TLSA_HASH_SHA512}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 3 1 1 ${TLSA_HASH_SHA256_PUB}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 3 1 2 ${TLSA_HASH_SHA512_PUB}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 2 0 1 ${CATLSA_HASH_SHA256}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 2 0 2 ${CATLSA_HASH_SHA512}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 2 1 1 ${CATLSA_HASH_SHA256_PUB}"
|
||||
#echo "_443._tcp.${DNSN}. 300 IN TLSA 2 1 2 ${CATLSA_HASH_SHA512_PUB}"
|
||||
HOST_TLSA="_443._tcp.${DNSN}."
|
||||
HOST_TLSA_VAL="3 1 1 ${TLSA_HASH_SHA256_PUB}"
|
||||
DOM256="_443._tcp.${DNSN}. 300 IN TLSA 3 1 1 ${TLSA_HASH_SHA256_PUB}"
|
||||
echo "action=dns&do=delete&domain=${DOMAIN}&type=TLSA&name=${HOST_TLSA}" >> ${TASK_QUEUE}
|
||||
run_dataskq
|
||||
echo "action=dns&do=add&domain=${DOMAIN}&type=TLSA&name=${HOST_TLSA}&value=${HOST_TLSA_VAL}&ttl=300&named_reload=yes" >> ${TASK_QUEUE}
|
||||
run_dataskq
|
||||
GENERATED=1
|
||||
fi
|
||||
}; done
|
||||
fi
|
||||
|
||||
if [ "$TLSATYPE" == "mail" ] || [ "$TLSATYPE" == "all" ]; then
|
||||
HOSTSMTPGEN=0
|
||||
TLSA_HASH_SHA256_PUBEXIM=`${OPENSSL} x509 -in /etc/exim.cert -noout -pubkey | ${OPENSSL} pkey -pubin -outform DER |${OPENSSL} sha256 | cut -d' ' -f2`
|
||||
NAMEDDIR=`/usr/local/directadmin/directadmin c | grep nameddir | awk -F'=' '{print $2}'`
|
||||
if [ -f ${NAMEDDIR}/${DOMAIN}.db ]; then
|
||||
while read LINE; do
|
||||
if echo "$LINE" | egrep "^${DOMAIN}\." |grep MX > /dev/null 2>&1; then
|
||||
MXR="$LINE"
|
||||
if [ $HOSTSMTPGEN -eq 0 ]; then
|
||||
HOST_TLSA="_25._tcp.${DOMAIN}."
|
||||
HOST_TLSA_VAL="3 1 1 ${TLSA_HASH_SHA256_PUBEXIM}"
|
||||
DOM256="_25._tcp.${MXREC} 300 IN TLSA 3 1 1 ${TLSA_HASH_SHA256_PUBEXIM}"
|
||||
echo "action=dns&do=delete&domain=${DOMAIN}&type=TLSA&name=${HOST_TLSA}" >> ${TASK_QUEUE}
|
||||
run_dataskq
|
||||
echo "action=dns&do=add&domain=${DOMAIN}&type=TLSA&name=${HOST_TLSA}&value=${HOST_TLSA_VAL}&ttl=300&named_reload=yes" >> ${TASK_QUEUE}
|
||||
run_dataskq
|
||||
GENERATED=1
|
||||
fi
|
||||
MXREC=""
|
||||
MXREC=`echo "$LINE"|awk '{print $NF}'`
|
||||
LASTCHAR=""
|
||||
LASTCHAR=`echo -n "$MXREC"|tail -c 1`
|
||||
if [ "$LASTCHAR" != "." ]; then
|
||||
MXREC="${MXREC}.${DOMAIN}"
|
||||
fi
|
||||
HOST_TLSA="_25._tcp.${MXREC}"
|
||||
HOST_TLSA_VAL="3 1 1 ${TLSA_HASH_SHA256_PUBEXIM}"
|
||||
DOM256="_25._tcp.${MXREC} 300 IN TLSA 3 1 1 ${TLSA_HASH_SHA256_PUBEXIM}"
|
||||
echo "action=dns&do=delete&domain=${DOMAIN}&type=TLSA&name=${HOST_TLSA}" >> ${TASK_QUEUE}
|
||||
run_dataskq
|
||||
echo "action=dns&do=add&domain=${DOMAIN}&type=TLSA&name=${HOST_TLSA}&value=${HOST_TLSA_VAL}&ttl=300&named_reload=yes" >> ${TASK_QUEUE}
|
||||
run_dataskq
|
||||
GENERATED=1
|
||||
fi
|
||||
done < "${NAMEDDIR}/${DOMAIN}.db"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ ${GENERATED} -ne 1 ]; then
|
||||
echo 4
|
||||
else
|
||||
echo 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
RETTLSA=`try_gen_tlsa`
|
||||
|
||||
if [ $RETTLSA -ne 0 ]
|
||||
then
|
||||
echo "TLSA gen failed"
|
||||
case "$RETTLSA" in
|
||||
1)
|
||||
echo "No directadmin binary found."
|
||||
;;
|
||||
2)
|
||||
echo "TLSA not enabled in directadmin.conf"
|
||||
;;
|
||||
*)
|
||||
echo "Unexpected problem: no domain of specified type found, exim cert doesn't exist, or domain doesn't have MX records.."
|
||||
;;
|
||||
esac
|
||||
exit $RETTLSA
|
||||
else
|
||||
echo "TLSA gen succeeded"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,177 +0,0 @@
|
||||
#!/bin/sh
|
||||
OS=`uname`
|
||||
DA_PATH=/usr/local/directadmin
|
||||
DA_SCRIPTS=${DA_PATH}/scripts
|
||||
DA_TQ=${DA_PATH}/data/task.queue
|
||||
|
||||
#added new options to templates
|
||||
#echo 'action=rewrite&value=httpd' >> $DA_TQ
|
||||
|
||||
echo "action=cache&value=showallusers" >> /usr/local/directadmin/data/task.queue
|
||||
echo "action=cache&value=safemode" >> $DA_TQ
|
||||
echo "action=convert&value=cronbackups" >> $DA_TQ
|
||||
echo "action=convert&value=suspendedmysql" >> $DA_TQ
|
||||
echo "action=syscheck" >> $DA_TQ
|
||||
|
||||
if [ ! -d /usr/local/sysbk ]; then
|
||||
cd $DA_SCRIPTS
|
||||
./sysbk.sh
|
||||
fi
|
||||
|
||||
#https://www.directadmin.com/features.php?id=1930
|
||||
echo "action=da-popb4smtp&value=restart" >> $DA_TQ
|
||||
|
||||
#grep -H "usertype=reseller" /usr/local/directadmin/data/users/*/user.conf | cut -d/ -f7 > /usr/local/directadmin/data/admin/reseller.list
|
||||
#chown diradmin:diradmin /usr/local/directadmin/data/admin/reseller.list
|
||||
#chmod 600 /usr/local/directadmin/data/admin/reseller.list
|
||||
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
CONF=/etc/newsyslog.conf
|
||||
if [ ! -s $CONF ]; then
|
||||
perl -pi -e 's/\sN\s/\t-\t/' ${CONF}
|
||||
perl -pi -e 's/\sU\s/\t-\t/' ${CONF}
|
||||
|
||||
#addLog /file user:group flag pid
|
||||
addLog()
|
||||
{
|
||||
if grep -m1 -q $1 $CONF; then
|
||||
return;
|
||||
fi
|
||||
echo -e "$1\t$2\t600\t4\t*\t@T00\t$3\t$4" >> $CONF
|
||||
}
|
||||
|
||||
addLog /var/log/chrootshell.log '' -
|
||||
addLog /var/log/proftpd/auth.log '' -
|
||||
addLog /var/log/proftpd/xferlog.legacy '' -
|
||||
addLog /var/log/proftpd/access.log '' - /var/run/proftpd.pid
|
||||
addLog /var/log/pureftp.log '' - /var/run/pure-ftpd.pid
|
||||
addLog /var/log/httpd/access_log apache:apache -
|
||||
addLog /var/log/httpd/fpexe_log apache:apache -
|
||||
addLog /var/log/httpd/suexec_log apache:apache -
|
||||
addLog /var/log/suphp.log '' -
|
||||
addLog /var/log/httpd/error_log apache:apache - /var/run/httpd.pid
|
||||
addLog /var/log/exim/paniclog mail:mail -
|
||||
addLog /var/log/exim/exim_paniclog mail:mail -
|
||||
addLog /var/log/exim/rejectlog mail:mail -
|
||||
addLog /var/log/exim/exim_rejectlog mail:mail -
|
||||
addLog /var/log/exim/processlog mail:mail -
|
||||
addLog /var/log/exim/exim_processlog mail:mail -
|
||||
addLog /var/log/exim/mainlog mail:mail - /var/run/exim.pid
|
||||
addLog /var/log/exim/exim_mainlog mail:mail - /var/run/exim.pid
|
||||
addLog /var/log/directadmin/error.log diradmin:diradmin -
|
||||
addLog /var/log/directadmin/errortaskq.log diradmin:diradmin -
|
||||
addLog /var/log/directadmin/security.log diradmin:diradmin -
|
||||
addLog /var/log/directadmin/system.log diradmin:diradmin -
|
||||
addLog /var/log/directadmin/login.log diradmin:diradmin -
|
||||
addLog /usr/local/php53/var/log/php-fpm.log '' - "/var/run/php-fpm53.pid\t30"
|
||||
addLog /usr/local/php54/var/log/php-fpm.log '' - "/var/run/php-fpm54.pid\t30"
|
||||
addLog /usr/local/php60/var/log/php-fpm.log '' - "/var/run/php-fpm60.pid\t30"
|
||||
|
||||
addLog /var/www/html/roundcube/logs/errors webapps:webapps -
|
||||
addLog /var/www/html/squirrelmail/data/squirrelmail_access_log webapps:webapps -
|
||||
addLog /var/www/html/phpMyAdmin/log/auth.log webapps:webapps -
|
||||
else
|
||||
echo "Doesn't look like you have newsyslog installed";
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e /etc/logrotate.d ]; then
|
||||
if [ ! -e /etc/logrotate.d/directadmin ] && [ -e $DA_SCRIPTS/directadmin.rotate ]; then
|
||||
cp $DA_SCRIPTS/directadmin.rotate /etc/logrotate.d/directadmin
|
||||
fi
|
||||
|
||||
if [ -e /etc/logrotate.d/directadmin ]; then
|
||||
if ! grep -m1 -q 'login.log' /etc/logrotate.d/directadmin; then
|
||||
cp $DA_SCRIPTS/directadmin.rotate /etc/logrotate.d/directadmin
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
echo "action=addoptions" >> $DA_TQ
|
||||
rm -f /usr/local/directadmin/data/skins/*/ssi_test.html 2>/dev/null
|
||||
perl -pi -e 's/trusted_users = mail:majordomo:apache$/trusted_users = mail:majordomo:apache:diradmin/' /etc/exim.conf
|
||||
|
||||
chmod 750 /etc/virtual/majordomo
|
||||
|
||||
${DA_SCRIPTS}/cron_deny.sh
|
||||
${DA_SCRIPTS}/check_named_conf.sh
|
||||
|
||||
if [ -s /etc/proftpd.conf ]; then
|
||||
perl -pi -e "s/userlog \"%u %b\"/userlog \"%u %b %m\"/" /etc/proftpd.conf
|
||||
perl -pi -e "s/userlog \"%u %b %m\"/userlog \"%u %b %m %a\"/" /etc/proftpd.conf
|
||||
|
||||
#dont restart proftpd if it not on.
|
||||
HAS_PUREFTPD=`${DA_PATH}/directadmin c | grep ^pureftp= | cut -d= -f2`
|
||||
if [ "${HAS_PUREFTPD}" != "1" ]; then
|
||||
echo "action=proftpd&value=restart" >> /usr/local/directadmin/data/task.queue
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e /usr/share/spamassassin/72_active.cf ]; then
|
||||
perl -pi -e 's#header FH_DATE_PAST_20XX.*#header FH_DATE_PAST_20XX Date =~ /20[2-9][0-9]/ [if-unset: 2006]#' /usr/share/spamassassin/72_active.cf
|
||||
fi
|
||||
|
||||
if [ -e /etc/exim.key ]; then
|
||||
chown mail:mail /etc/exim.key
|
||||
chmod 600 /etc/exim.key
|
||||
fi
|
||||
|
||||
#1.37.1
|
||||
#very important update to allow DA to listen correctly on IPv4 and IPv6
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
if ! grep -m1 -q 'ipv6_ipv4mapping=' /etc/rc.conf; then
|
||||
echo "ipv6_ipv4mapping=\"YES\"" >> /etc/rc.conf
|
||||
fi
|
||||
|
||||
if ! grep -m1 -q 'net.inet6.ip6.v6only=' /etc/sysctl.conf; then
|
||||
echo "net.inet6.ip6.v6only=0" >> /etc/sysctl.conf
|
||||
/etc/rc.d/sysctl restart
|
||||
fi
|
||||
|
||||
/sbin/sysctl net.inet6.ip6.v6only=0 >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
UKN=/etc/virtual/limit_unknown
|
||||
if [ ! -e $UKN ]; then
|
||||
echo 0 > $UKN;
|
||||
chown mail:mail $UKN
|
||||
chown mail:mail /etc/virtual/limit
|
||||
fi
|
||||
UL=/etc/virtual/user_limit
|
||||
if [ ! -s ${UL} ]; then
|
||||
echo "0" > ${UL}
|
||||
chown mail:mail ${UL}
|
||||
chmod 644 ${UL}
|
||||
fi
|
||||
|
||||
#debian if MySQL 5.5.11+
|
||||
#april 21, 2011
|
||||
if [ -e /etc/debian_version ]; then
|
||||
if [ -e /usr/local/directadmin/directadmin ]; then
|
||||
COUNT=`ldd /usr/local/directadmin/directadmin | grep -c libmysqlclient.so.16`
|
||||
if [ "${COUNT}" -eq 1 ]; then
|
||||
if [ ! -e /usr/local/mysql/lib/libmysqlclient.so.16 ] && [ -e /usr/local/mysql/lib/libmysqlclient.so.18 ]; then
|
||||
echo "*** Linking libmysqlclient.so.16 to libmysqlclient.so.18";
|
||||
ln -s libmysqlclient.so.18 /usr/local/mysql/lib/libmysqlclient.so.16
|
||||
ldconfig
|
||||
fi
|
||||
fi
|
||||
COUNT=`ldd /usr/local/directadmin/directadmin | grep -c libmysqlclient.so.18`
|
||||
if [ "${COUNT}" -eq 1 ]; then
|
||||
if [ ! -e /usr/local/mysql/lib/libmysqlclient.so.18 ] && [ -e /usr/local/mysql/lib/libmysqlclient.so.16 ]; then
|
||||
echo "*** Linking libmysqlclient.so.18 to libmysqlclient.so.16";
|
||||
ln -s libmysqlclient.so.16 /usr/local/mysql/lib/libmysqlclient.so.18
|
||||
ldconfig
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
#DA 1.43.1
|
||||
#http://www.directadmin.com/features.php?id=1453
|
||||
echo "action=rewrite&value=filter" >> /usr/local/directadmin/data/task.queue
|
||||
|
||||
#DA 1.56.2
|
||||
#https://www.directadmin.com/features.php?id=2332
|
||||
echo 'action=rewrite&value=cron_path' >> /usr/local/directadmin/data/task.queue
|
||||
|
||||
exit 0
|
||||
@@ -1,167 +0,0 @@
|
||||
#!/bin/sh
|
||||
# This script is written by Martynas Bendorius and DirectAdmin
|
||||
# It is used to convert user to reseller
|
||||
# Official DirectAdmin webpage: http://www.directadmin.com
|
||||
# Usage:
|
||||
# ./user_to_reseller.sh <user>
|
||||
|
||||
MYUID=`/usr/bin/id -u`
|
||||
if [ "$MYUID" != 0 ]; then
|
||||
echo "You require Root Access to run this script";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ $# != 1 ]; then
|
||||
echo "Usage:";
|
||||
echo "$0 <user>";
|
||||
echo "you gave #$#: $0 $1";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
USERNAME=$1
|
||||
|
||||
BASEDIR=/usr/local/directadmin/data
|
||||
|
||||
ADMIN_DATA=${BASEDIR}/users/admin
|
||||
RESELLER_LIST=${BASEDIR}/admin/reseller.list
|
||||
|
||||
USER_DATA=${BASEDIR}/users/$1
|
||||
USER_BACKUP_CONF=${USER_DATA}/backup.conf
|
||||
USER_CONF=${USER_DATA}/user.conf
|
||||
USER_USAGE=${USER_DATA}/user.usage
|
||||
|
||||
RESELLER_ALLOC=${USER_DATA}/reseller.allocation
|
||||
RESELLER_CONF=${USER_DATA}/reseller.conf
|
||||
RESELLER_USAGE=${USER_DATA}/reseller.usage
|
||||
|
||||
if [ ! -d ${USER_DATA} ]; then
|
||||
echo "Directory ${USER_DATA} does not exist. Can not continue."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "`grep -wc $1 ${RESELLER_LIST}`" = "1" ]; then
|
||||
echo "User $1 is already reseller. Can not continue."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ ! -e /usr/bin/perl ]; then
|
||||
echo "/usr/bin/perl does not exist.";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "Re-configuring user directory /home/$1."
|
||||
mkdir -p /home/$1/user_backups
|
||||
mkdir -p /home/$1/domains/default
|
||||
mkdir -p /home/$1/domains/sharedip
|
||||
mkdir -p /home/$1/domains/suspended
|
||||
cp -R ${BASEDIR}/templates/default/* /home/$1/domains/default
|
||||
chown -R $1:$1 /home/$1/user_backups
|
||||
chown -R $1:$1 /home/$1/domains/default
|
||||
chown -R $1:$1 /home/$1/domains/sharedip
|
||||
chown -R $1:$1 /home/$1/domains/suspended
|
||||
|
||||
SAG=`/usr/local/directadmin/directadmin c | grep secure_access_group | cut -d= -f2`
|
||||
if [ "$SAG" != "" ]; then
|
||||
if [ "$SAG" != '(null)' ]; then
|
||||
#must be set to something, and not null, thus on.
|
||||
chown $1:$1 /home/$1
|
||||
chmod 711 /home/$1
|
||||
chown $1:${SAG} /home/$1/domains
|
||||
chmod 750 /home/$1/domains
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
echo "Re-configuring DirectAdmin files."
|
||||
# Changing usertype
|
||||
perl -pi -e 's/usertype=user/usertype=reseller/' ${USER_CONF}
|
||||
|
||||
# Creating backup.conf
|
||||
if [ ! -e ${USER_BACKUP_CONF} ]; then
|
||||
echo -n "" > ${USER_BACKUP_CONF}
|
||||
echo "ftp_ip=" >> ${USER_BACKUP_CONF}
|
||||
echo "ftp_password=" >> ${USER_BACKUP_CONF}
|
||||
echo "ftp_path=/" >> ${USER_BACKUP_CONF}
|
||||
echo "ftp_username=" >> ${USER_BACKUP_CONF}
|
||||
echo "local_path=" >> ${USER_BACKUP_CONF}
|
||||
fi
|
||||
# Creating ip.list
|
||||
if [ ! -e ${USER_DATA}/ip.list ]; then
|
||||
grep "ip=" ${USER_DATA}/user.conf | cut -d= -f2 > ${USER_DATA}/ip.list
|
||||
fi
|
||||
# Creating everything else
|
||||
touch ${USER_DATA}/login.hist
|
||||
touch ${USER_DATA}/reseller.history
|
||||
touch ${USER_DATA}/users.list
|
||||
cp -f ${ADMIN_DATA}/u_welcome.txt ${USER_DATA}/u_welcome.txt
|
||||
|
||||
# Creating packages
|
||||
mkdir -p ${USER_DATA}/packages
|
||||
touch ${USER_DATA}/packages.list
|
||||
|
||||
# Creating reseller.allocation
|
||||
if [ ! -e ${RESELLER_ALLOC} ]; then
|
||||
echo -n "" > ${RESELLER_ALLOC}
|
||||
grep "bandwidth=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
grep "domainptr=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
grep "ftp=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
grep "mysql=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
grep "nemailf=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
grep "nemailml=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
grep "nemailr=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
grep "nemails=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
grep "nsubdomains=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
echo "nusers=0" >> ${RESELLER_ALLOC}
|
||||
grep "quota=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
grep "vdomains=" ${USER_CONF} >> ${RESELLER_ALLOC}
|
||||
fi
|
||||
|
||||
# Editing ticket.conf
|
||||
if [ -e ${USER_DATA}/ticket.conf ] && [ "`grep -c 'active=' ${USER_DATA}/ticket.conf`" = "0" ]; then
|
||||
echo "active=yes" >> ${USER_DATA}/ticket.conf
|
||||
echo 'html=Follow <a href="http://www.domain.com/support">this link</a> for a 3rd party ticket system.' >> ${USER_DATA}/ticket.conf
|
||||
echo "newticket=0" >> ${USER_DATA}/ticket.conf
|
||||
fi
|
||||
|
||||
# Creating reseller.conf
|
||||
if [ ! -e ${RESELLER_CONF} ]; then
|
||||
egrep -v "account=|creator=|date_created=|docsroot=|domain=|email=|ip=|name=|skin=|suspend_at_limit=|suspended=|username=|usertype=|zoom=|language=" ${USER_CONF} > ${RESELLER_CONF}
|
||||
echo "userssh=ON" >> ${RESELLER_CONF}
|
||||
echo "dns=ON" >> ${RESELLER_CONF}
|
||||
echo "ip=shared" >> ${RESELLER_CONF}
|
||||
echo "ips=0" >> ${RESELLER_CONF}
|
||||
echo "oversell=ON" >> ${RESELLER_CONF}
|
||||
echo "serverip=ON" >> ${RESELLER_CONF}
|
||||
echo "subject=Your account for |domain| is now ready for use." >> ${RESELLER_CONF}
|
||||
fi
|
||||
|
||||
# Creating reseller.usage
|
||||
if [ ! -e ${RESELLER_USAGE} ]; then
|
||||
egrep -v "db_quota=|email_quota=" ${USER_USAGE} > ${RESELLER_USAGE}
|
||||
echo "nusers=1" >> ${RESELLER_USAGE}
|
||||
fi
|
||||
|
||||
CREATOR=`grep "creator=" ${USER_CONF} | cut -d= -f2`
|
||||
CREATOR_USERSLIST=${BASEDIR}/users/${CREATOR}/users.list
|
||||
echo "Removing user from the other reseller."
|
||||
perl -pi -e "s#$1\n##g" ${CREATOR_USERSLIST}
|
||||
|
||||
# Setting permissions
|
||||
chmod 600 ${USER_DATA}/backup.conf ${USER_DATA}/reseller.usage ${USER_DATA}/reseller.conf ${USER_DATA}/reseller.allocation ${USER_DATA}/packages.list ${USER_DATA}/login.hist ${USER_DATA}/reseller.history ${USER_DATA}/users.list
|
||||
chmod 700 ${USER_DATA}/packages
|
||||
chmod 644 ${USER_DATA}/u_welcome.txt
|
||||
chown -R diradmin:diradmin ${USER_DATA}/packages ${USER_DATA}/u_welcome.txt ${USER_DATA}/backup.conf ${USER_DATA}/reseller.usage ${USER_DATA}/reseller.conf ${USER_DATA}/reseller.allocation ${USER_DATA}/packages.list ${USER_DATA}/login.hist ${USER_DATA}/reseller.history ${USER_DATA}/users.list
|
||||
|
||||
echo "Adding reseller to $3 reseller list"
|
||||
echo "$1" >> ${RESELLER_LIST}
|
||||
|
||||
echo "Changing user owner"
|
||||
perl -pi -e "s/creator=$CREATOR/creator=admin/g" ${USER_CONF}
|
||||
|
||||
#this is needed to update "show all users" cache.
|
||||
echo "action=cache&value=showallusers" >> /usr/local/directadmin/data/task.queue
|
||||
/usr/local/directadmin/dataskq
|
||||
|
||||
echo "User $1 has been converted to reseller."
|
||||
|
||||
exit 0;
|
||||
Reference in New Issue
Block a user