PDA

View Full Version : New scripts


smtalk
07-03-2007, 03:25 PM
As requested in http://directadmin.com/forum/showthread.php?t=16790 (TOP5 wanted features) I made these scripts (may be included into DirectAdmin soon):
move_user_to_reseller.sh - used to move users between resellers
move_domain.sh - used to move domains between users

Now I'm working on converter from user to reseller and from reseller to
user :) I'll upload the scripts soon.

"Installation" is simple:
move_user_to_reseller.sh:

cd /usr/local/directadmin/scripts
wget http://www.servermonkeys.com/projects/els/directadmin/move_user_to_reseller.sh
chmod 700 move_user_to_reseller.sh
chown diradmin:diradmin move_user_to_reseller.sh
move_domain.sh (BETA):

cd /usr/local/directadmin/scripts
wget http://www.servermonkeys.com/projects/els/directadmin/move_domain.sh
chmod 700 move_domain.sh
chown diradmin:diradmin move_domain.sh
Usage:
move_user_to_reseller.sh:

cd /usr/local/directadmin/scripts
./move_user_to_reseller.sh <user> <oldreseller> <newreseller>move_domain.sh

cd /usr/local/directadmin/scripts
./move_domain.sh <domain> <olduser> <newuser>

hehachris
07-03-2007, 04:47 PM
thanks for the scripts!
will test them out soon.

smtalk
07-03-2007, 05:07 PM
We have a new script called user_to_reseller.sh now (used to convert user to reseller) :)

Installation:

cd /usr/local/directadmin/scripts
wget http://www.servermonkeys.com/projects/els/directadmin/user_to_reseller.sh
chmod 700 user_to_reseller.sh
chown diradmin:diradmin user_to_reseller.sh
Usage:

cd /usr/local/directadmin/scripts
./user_to_reseller.sh <user>

smtalk
07-03-2007, 05:35 PM
reseller_to_user.sh is done too :) Installation is the same, just change user_to_reseller.sh with reseller_to_user.sh :) Usage is:
cd /usr/local/directadmin/scripts
./reseller_to_user.sh <user> <reseller>

jlandes
07-03-2007, 06:25 PM
Nice work Martynas. :)

jw00dy
07-03-2007, 09:01 PM
Very nice work and Thank you!

h2d
07-04-2007, 04:48 AM
Can you confirm that these scripts work with all operating systems

In particular freebsd.

smtalk
07-04-2007, 04:53 AM
Yes, it is working on all systems that DirectAdmin supports.

smtalk
07-04-2007, 01:49 PM
File names has been changed :)

P.S. jlandes, jw00dy and hehachris, thank you for the good words :)

HanSieT
07-08-2007, 03:19 AM
Martynas,


I seem to be having problems with the user_to_reseller script.

When download & use i get this error.
[root@tws1 scripts]# chown diradmin:diradmin user_to_reseller.sh
[root@tws1 scripts]# ls -al user_to_reseller.sh
-rwx------ 1 diradmin diradmin 5303 Jul 4 21:37 user_to_reseller.sh
[root@tws1 scripts]# ./user_to_reseller.sh stambomen
Re-configuring user directory /home/stambomen.
Re-configuring DirectAdmin files.
./user_to_reseller.sh: line 91: syntax error near unexpected token `newline'
./user_to_reseller.sh: line 91: ` echo -n "" > '
[root@tws1 scripts]#


Am i doing something wrong?

Please advise

//Hans
*edit*
I figured out i made a bad move because i needed to move the user to a reseller :s
Is there any way to convert it back or move the user to a reseller ?
*/edit*

HanSieT
07-08-2007, 03:25 AM
And there is an small typo in the scripts ( downloading the scripts)

wget http://www.servermonkeys.com/projects/els/directadmin/move_user_to_reseller.sh

Gives The requested URL /projects/els/directadmin/move_user_to_reseller.sh was not found on this server.
Because the filename is move_user_to_reseller.sh.sh :)

HanSieT
07-08-2007, 03:37 AM
is there any way i can convert the reseller back to user?

Now the user is stated as Reseller and thats not what i want

floyd
07-08-2007, 03:50 AM
is there any way i can convert the reseller back to user?


I think it has already been answered.

reseller_to_user.sh is done too :) Installation is the same, just change user_to_reseller.sh with reseller_to_user.sh :) Usage is:
cd /usr/local/directadmin/scripts
./reseller_to_user.sh <user> <reseller>


Now the user is stated as Reseller and thats not what i want

Then what did you want because that is what move_user_to_reseller.sh does?

We have a new script called user_to_reseller.sh now (used to convert user to reseller)

HanSieT
07-08-2007, 05:02 AM
@Floyd,

I ment to move user to another reseller but instead i made the user reseller :) and thats not what supposed to be.

It was my own mistake because i thought the user to reseller was the one to use:D


Thank u i now used reseller to user .

//Hans

*edit*
When i use reseller to user it says
[root@tws1 scripts]# ./reseller_to_user.sh stambomen pronet
Reseller stambomen is already user. Can not continue.


But in DA it says
Usertype reseller

What am i doing wrong here?

*/edit*

smtalk
07-09-2007, 06:28 AM
HanSieT, use user_to_reseller.sh to restore everything what's needed and then run reseller_to_user.sh.

And about that error (here is the fix):
cd /usr/local/directadmin/scripts
rm -f user_to_reseller.sh
wget http://www.servermonkeys.com/projects/els/directadmin/user_to_reseller.sh
chmod 700 user_to_reseller.sh
chown diradmin:diradmin user_to_reseller.sh

sky
07-09-2007, 06:41 AM
Nice work smtalk
already loving it (tm) :)

skruf
07-11-2007, 04:01 PM
Hey,

I tried the move_domain.sh on a CentOS 4.x box and ended up with a 404 error on the domain.

Looking at things I noticed the "domainowners" file was not updated with the new owner of the domain.

Also, the contents of the httpd.conf file for the domain was not moved to the new owners httpd.conf file. (The paths and User/Group from the old owner needs to be updated as well.)

I also restarted Apache after the changes.

Hope that makes sense!

All seemed to work OK after those changes.

Nice work and Thanks!.

David

smtalk
07-11-2007, 04:17 PM
Hi skruf, thank you for good words :) The file has been updated (added one change for /etc/virtual/domainowners file). For httpd.conf changes - you just needed to run:

echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue


I've added that to the script too :) So, it's perfect now, isn't it? ;)

skruf
07-11-2007, 04:38 PM
Hi skruf, thank you for good words :) The file has been updated (added one change for /etc/virtual/domainowners file). For httpd.conf changes - you just needed to run:

echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue


I've added that to the script too :) So, it's perfect now, isn't it? ;)

You got that right.... Moved a couple of domains without any issues!

Nice work. Thanks again!

David

freshmint
07-11-2007, 05:08 PM
Could this be added to the DA official scripts?

And more important, if in case it is added, will a DA update retrieve these scripts automatically?

smtalk
07-12-2007, 12:54 AM
Yes, they should be added by default :) And you will get them with an update.

freshmint
07-12-2007, 12:57 AM
Yes, they should be added by default :) And you will get them with an update.

Thanks, sounds good. Will be waiting for them the next update as we never know when these scripts might come in hand. :p

cyberneticos
08-01-2007, 04:34 AM
OUTSTANDING WORK :)

Thank you very much.

smtalk
08-01-2007, 04:40 PM
Thank you for the good words, I really appreciate them :) Happy using!

rldev
08-06-2007, 07:31 PM
Thanks Smtalk. Hope this can be put in the admin gui one day. Call it something like "Convert/Move Users"

MyVPSHost-Susy
08-10-2007, 12:34 PM
Several things wrong with the move_domain.sh script so far.

It doesn't add the domains httpd.conf in the main httpd.conf file, rebuilding the httpd.conf, doesn't help either, have to manually add it in.

And the e-mails in /etc/virtual/ , the permissions doesn't change to the proper user, have to manually chown the folders over, to the correct new UID.

Thanks!

smtalk
08-10-2007, 12:37 PM
Yes, that's why it's marked as beta. It's the only script which is in beta now :) Anyway, thank you for the report.

MyVPSHost-Susy
08-10-2007, 12:49 PM
I know, but just helping it to make it better :)

Also, IMAP logins are failing, but attempting to figure it out.

RadMan
09-18-2007, 05:56 AM
Any chance of this feature bcoming a browser based solution in the admin panel??????...

I'm 100% sure this would be something that more than DA customer would like to see in their admin panels.

ChadRT
10-06-2007, 12:55 AM
Any chance of this feature bcoming a browser based solution in the admin panel??????...

I'm 100% sure this would be something that more than DA customer would like to see in their admin panels.

I agree with you completely!! I would love to have this available as an admin option!! Couldnt it be made into a Module so there would be admin links?

Chad

RadMan
10-06-2007, 05:30 AM
I agree with you completely!! I would love to have this available as an admin option!! Couldnt it be made into a Module so there would be admin links?

Chad

Chad... Apparently it's on its way.. :)

http://www.directadmin.com/forum/showthread.php?t=21379

paulus
11-20-2007, 08:44 AM
Hi smtalk,

Can you provide me a linkr the user_to_reseller.sh script? It gives a 404 when I try to download it.

Thanks :D

smtalk
11-20-2007, 09:23 AM
paulus, it should be in /usr/local/directadmin/scripts :)

paulus
11-20-2007, 09:25 AM
paulus, it should be in /usr/local/directadmin/scripts :)

Hmm, I would like it it that it isnt there, but I cant find it. I asked (http://www.directadmin.com/forum/showthread.php?p=117795) here alreayd, but founded after that this topic.

smtalk
11-20-2007, 09:42 AM
user_to_reseller.sh:

#!/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>

if [ $UID != 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

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 > 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#$CREATOR\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=$1/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;

paulus
11-20-2007, 09:54 AM
thanks smtalk :D

hires
03-18-2008, 11:05 AM
I was just wandering...
I'm not that much of a command prompt wizard (yet) but I am having a customer that has several accounts within one reseller account; thos user accounts needs to be added to one (already existing) account, but so that all passwords within ALL accounts (DA login, FTP- and also email accounts!) are staying the same. After all all domains and settings and e-mail addresses, ftp accounts tec. need to be unchanged!

Is some of those scripts a solution to get this done?

Thanks in advance.

floyd
03-18-2008, 11:09 AM
I would think that the Move Users to Resellers link would do it for you.

hires
03-18-2008, 04:37 PM
Yeah, I guess I will try that. Though all user accounts are now in one and the same reseller account.. I could try to create another reseller account, create a new user and transfer all user accounts to one account within the other reseller account I quess? Seems like a lot of actions to do then.. I'll go try some, I'll post the results here. Unless I am missing something..

floyd
03-18-2008, 04:41 PM
You basically said that you wanted to move some user accounts from one reseller account to another reseller account. I don't understand what the problem is.

hires
03-19-2008, 02:53 AM
Hmm, that's not what I meant. The situation is that I have one reseller account (my own) and within that reseller account I have several user accounts, all with several domains, and I would like to 'merge' all those user accounts to one user account. This all should happen within that (one and the same) reseller account.

As far as I'm understanding right now, I can use the move_domains script, cause there is no change of reseller, though I really need to know if all FTP-, e-mail- accounts and all other settings (forwards, site redirects etc.) are also moved and so that all passwords of all accounts stay the same. Is that the case?

Thanks and sorry for the misunderstanding.

spirit
03-28-2008, 05:46 AM
I have to move 4 domain (accounts) to the admin account. When i use the script in this topic, the e-mail boxes also moved to the admin account?