Default user package(s) for resellers

Erquilon

Verified User
Joined
Jun 5, 2014
Messages
6
I got a VPS with DirectAdmin. I will use it to host a bunch of websites. The websites that I will host can be divided in 2 groups: my clients websites, and my personal websites.

To maintain a clear overview of these websites I created 2 reseller accounts within DirectAdmin. 1 for my clients websites, and 1 for my personal websites.

For all these websites I would like to create a couple of (default) user packages. My question is if I can somehow create user packages that can be used by all resellers.

Right now the only option is to create the user packages on both resellers. If I were to add more resellers to group my websites even further, it would be a lot of work in case I want to change the user packages.

So, is there some way to set default user packages for all resellers to use?

thanks in advance.
 
Hello,

Here is a possible way to go http://help.directadmin.com/item.php?id=190 :

1. Create user packages on reseller level for admin (they will be stored in /usr/local/directadmin/data/users/admin/packages/ /usr/local/directadmin/data/users/admin/packages.list).

2. Use /usr/local/directadmin/scripts/custom/user_create_post_confirmed.sh or /usr/local/directadmin/scripts/custom/user_create_post.sh to copy user packages from admin to a reseller on new reseller creation.

That's it.

Related:

user_create_post_confirmed.sh: http://www.directadmin.com/features.php?id=1158
user_create_post.sh: http://www.directadmin.com/features.php?id=183
 
Hmm, that didn't work for me. Did everything it said, but the packages didn't get copied to new resellers. But, if it did, I assume they only get copied? So if I wanted to change something later, I still need to go into multiple reseller accounts to make the changes?

Well, I assume I'll just have to create and update the packages for every separate reseller? Not that much of a problem though, it's only a couple of reseller accounts.
 
From here it's impossible to say why it did not work for you. It should work.

> But, if it did, I assume they only get copied?

Yes, packages should get copied. Make sure you've got user packages for your "admin" reseller.

>
I still need to go into multiple reseller accounts to make the changes?

Yes

>
update the packages for every separate reseller?

Yes, right.
 
1. Create user packages on reseller level for admin (they will be stored in /usr/local/directadmin/data/users/admin/packages/ /usr/local/directadmin/data/users/admin/packages.list).
Hi @zEitEr and everyone,

I will try to automate the creation of a "Default Package" for newly created resellers.

I have already noticed that in addition to copying the default package to the user's directory...

Code:
cp /root/Default.pkg /usr/local/directadmin/data/users/$USER/packages/Default.pkg

it is also required to update the file of the list of packages, located here:
Code:
/usr/local/directadmin/data/users/$USER/packages.list

Maybe with something like this:

Code:
echo 'Default' > /usr/local/directadmin/data/users/$USER/packages.list

I have to succeed in creating a bash script that will run every 15 minutes to list and check all users to verify that the "Default" package does not yet exist. And if it is not already present, copy it to the directory and update the packages.list file.

To make life easier for new resellers and enable them to immediately create new users, it would be really useful to quickly offer them a Default Package. This automation idea would seem useful for all DirectAdmin users, what do you think?

In any case, if I manage to achieve something satisfactory, I will share it here.
 
Here I am already! (I couldn't wait^^)

I'm not an expert in writing bash scripts, but thanks to the AIs that helped me accomplish this...

nano /root/create-da-default-package.sh

Bash:
#!/bin/bash

# Path to the directory containing the users
usersDir="/usr/local/directadmin/data/users"

# Default source file to copy for Default.pkg
defaultPkgSource="/root/Default_DA_user_package.pkg"

# Loop through each user
for userDir in $usersDir/*; do
if [ -d "$userDir" ]; then
 # Extracting the username from the path
 userName=$(basename "$userDir")

 echo "User: $userName"

 # Path to the Default.pkg file for the current user
 defaultPkgPath="$userDir/packages/Default.pkg"

 # Check if Default.pkg exists
 if [ ! -f "$defaultPkgPath" ]; then
   echo "The Default.pkg file does not exist for user $userName. Creating now..."
 
   # Copying the Default.pkg file from the example file
   echo "Copying the Default.pkg file from the example file"
   cp "$defaultPkgSource" "$defaultPkgPath"
   chown diradmin:diradmin "$defaultPkgPath"
 
   # Path to the packages.list file for the current user
   packagesListPath="$userDir/packages.list"
 
   # Checking (and creating if necessary) packages.list and adding "Default"
   if [ ! -f "$packagesListPath" ]; then
     echo "Creating the $packagesListPath file as it did not exist."
     echo "Default" > "$packagesListPath"
     chown diradmin:diradmin "$packagesListPath"
   else
     # Adding only if "Default" is not already present
     if ! grep -qx "Default" "$packagesListPath"; then
      echo "'Default' is not already present, adding it to $packagesListPath"
       echo "Default" >> "$packagesListPath"
       chown diradmin:diradmin "$packagesListPath"
     fi
   fi
 
   echo "Processing complete for user $userName."
 else
   echo "The Default.pkg file already exists for user $userName. No action required."
 fi
fi
done

echo "Script complete."

Next, I added this cron task via export EDITOR="nano" && crontab -e ;

To be tested by yourself and used with caution!

Code:
*/10 * * * * /bin/bash /root/create-da-default-package.sh

This way seems good to you?
 
Hi,

I did not try the code and can not say it will work as desired. But is seems to me, the code does not differentiate users, resellers and admins. It seems to create the default package under every user in DA. Probably you know better. Not too sure.

What I'm sure about, is that I would choose another way to complete the task. If I needed resellers to have a starting set of packages for their users, then I would still use the POST hook. The POST hook would create a flag (only on a reseller creation), and a crontask would check an existence of such the flag and do all required tasks only once. Then I could use a rsync command to sync the packages across the resellers giving my resellers a chance to create own packages.

Your variant might work too. Just make sure would you need the packages copied to regular users or not.


 
Hi @zEitEr :)

Thanks for your detailed feedback.

You are right, I don't know a proper way to differentiate User and Reseller in my bash.
But after looking again, the copy of the Default.pkg file failed for regular users, because the /packages/ directory does not exist :
Code:
cp: cannot create regular file '/usr/local/directadmin/data/users/$USER/packages/Default.pkg': No such file or directory

giving my resellers a chance to create own packages

I can confirm that the bash do not erase the packages created by the resellers. It just copy the Defaukt.pkg and add Default to the list without removing the owned packages.

If I needed resellers to have a starting set of packages for their users, then I would still use the POST hook

I would be happy to achieve this in a proper way, but after looking at the DA API and search everywhere that I can, I was not able to find sufficient doc to learn how to proceed with POST queries ^^

The must would be a native Default package in the core of DirectAdmin in a future release. But it seems not many people have this request^^
 
But after looking again, the copy of the Default.pkg file failed for regular users, because the /packages/ directory does not exist :

Then it is possibly OK. Users won't get the package, if the directory missing. Good. But you will probably get emails (alerts) from cron with these messages about missing packages folder. You might mute them in cron.

I can confirm that the bash do not erase the packages created by the resellers. It just copy the Defaukt.pkg and add Default to the list without removing the owned packages.

That's good. It's not the issue either then.

I would be happy to achieve this in a proper way, but after looking at the DA API and search everywhere that I can, I was not able to find sufficient doc to learn how to proceed with POST queries ^^

There is nothing critically wring in your code (if it works as you want it to work), and the term "a proper way" is not suitable here. You can go your own way, that's fine. It's just a matter of own preferences.

POST hooks in terms of DirectAdmin are not the same as POST data in terms of HTTP. DirectAdmin support PRE and POST hooks, first are called before an action, the second are called after an action in DirectAdmin.

For the mentioned case the following POST hooks can be used:

- /usr/local/directadmin/scripts/custom/user_create_post_confirmed.sh
- /usr/local/directadmin/scripts/custom/user_create_post.sh

See https://docs.directadmin.com/developer/hooks/ and https://docs.directadmin.com/developer/hooks/user_reseller_management.html for more details.
 
Back
Top