• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Ftp Accounts send with email

bloosk

Basic Pleskian
Hello, i hope you understand me my englisch is very bad


Ok the problem what i mean is the FTP Accounts Username and Password dosnt send at email to the user give some options how i can set
for sending FTP Account Username and password at email?


Thanks

Brandmeir Gerhard
 
No idea anyone

Hello

It is the problem from my ask not Supported from plesk or come that in the next version of plesk

thats very importend for me or must i send the account information manually with email to user?


Thanks

Brandmeir Gerhard
 
I just got done helping Marios with a similar problem.

Plesk does not have a <password> option in the Domain notification auto-email.

A possible workaround for you:
You should have root access to the server, SSH access, and be a little familiar with bash scripting and mysql.

If your Plesk version has the 'Event Manger', you can setup and event triggered on 'Physical Hosting Created' and run a separate script to do a mysql query, then prepare and send your email.

I will give you an example of a bash script which will do the query and send it to a log file:

#!/bin/sh
# Bash script to do mysql query for ftp password, to be run from Event Manager
# upon Physical Hosting Creation trigger
#
# Set it up in Event Manager to be passed the following arguments:
# argument list:
# $1=<new_system_user>
#
PSA_USERNAME=$1

# Note that this is the ` quote not the ' quote
PSA_PASSWORD=`
mysql -uadmin -pYourAdminPassword -N psa<< eof
SELECT a.password FROM accounts a, sys_users s WHERE login LIKE '$PSA_USERNAME' and a.id = s.account_id;
eof`
# Note that this is the ` quote, not the ' quote

echo $PSA_USERNAME >>/tmp/event_handler.log
echo $PSA_PASSWORD >>/tmp/event_handler.log

# Make sure to change the 'YourAdminPassword' to the real admin password

# You can now put in code here to use these variables to formulate an email
# to be sent to the user.
#
# Save this file and 'chmod +x filename'
 
Hello Thanks for your answer

#!/bin/sh
# Bash script to do mysql query for ftp password, to be run from Event Manager
# upon Physical Hosting Creation trigger
#
# Set it up in Event Manager to be passed the following arguments:
# argument list:
# $1=<new_system_user>
#
PSA_USERNAME=$1

# Note that this is the ` quote not the ' quote
PSA_PASSWORD=`
mysql -uadmin -pYourAdminPassword -N psa<< eof
SELECT a.password FROM accounts a, sys_users s WHERE login LIKE '$PSA_USERNAME' and a.id = s.account_id;
eof`
# Note that this is the ` quote, not the ' quote

echo $PSA_USERNAME >>/tmp/event_handler.log
echo $PSA_PASSWORD >>/tmp/event_handler.log

# Make sure to change the 'YourAdminPassword' to the real admin password

# You can now put in code here to use these variables to formulate an email
# to be sent to the user.
#
# Save this file and 'chmod +x filename'

but i have any questions before i do this

first ask
# $1=<new_system_user>

must i do this uncomment ?

second ask
# Note that this is the ` quote not the ' quote
PSA_PASSWORD=`
what value must i set for PSA_Password?

Thanks for help

Brandmeir Gerhard
 
Do not uncomment that line, it is just a comment telling you that the environment argument passed to the script as $1 will be assigned to the variable PSA_USERNAME.

You are not manually assigning anything to the variable PSA_PASSWORD, the value is being looked up in the mysql database by the commands following the PSA_PASSWORD=` line.

PSA_PASSWORD=`
mysql -uadmin -pYourAdminPassword -N psa<< eof
SELECT a.password FROM accounts a, sys_users s WHERE login LIKE '$PSA_USERNAME' and a.id = s.account_id;
eof`

So everything from the first ` to the last ` are additional shell commands which will be executed to do the mysql lookup and put the password into the variable for you.

This example was to show you the basics. As far as putting it into an email and sending it to the user, that example was in a different post just today or yesterday.

http://forum.plesk.com/showthread.php?threadid=27008

Look for my post regarding using 'mail -v -s'

Again, it may not be the *exact* script you need, but it shows you the logic and will probably need minor adjustments to suit your exact need.
 
OK thanks for now

i will test it in next days and then I announce again.


Thanks
Brandmeir Gerhard
 
Hello

Oh im Happy i test it on my localmaschine and its work fine i have an entry in event_handler.log with username and password

ok but how can i query the email adress from this user how i creat in this moment.
or must i do in the eventmanager the variable set to

/usr/local/psa/admin/plib/modules/sbm/ftpemail.sh <new_system_user> (and now the <emailtag>)
is this right or what must i do ?


Thanks
Brandmeir Gerhard
 
No need for an additional script, just modify the existing one to add the script code for creating the mail.

From the event handler you can pass additional arguments to the script. Within the script assign those to more variables.

Here is a list of the parameters you can pass to the script from within the Event Manager:

http://download1.sw-soft.com/Plesk/...5r-sdk-html/docs/event_manager/unix/ch05.html

Assuming you pass additional parameters (I do not know how many you have already specified, assuming maybe 3 already) to the script as the 1st and 4th parameters:

<new_system_user> = (already passed as $1)
<new_domain_name> =$4

In the script you can build a variable ($e_address)which will consist of:

$1 + "@" + $4

I am not going to write the entire script for you. Hosting admins should take the time to do research and at least learn some basics. (Sorry, Not a 'happy' day for me today)
 
Hello jamesyeeoc

I am not going to write the entire script for you. Hosting admins should take the time to do research and at least learn some basics. (Sorry, Not a 'happy' day for me today)
oh no problem i would like only learn im not hosting now in moment but o would like test anything for learn
and not every day is good for me too.

i test that what you right me but one questions i have more

in PHP in can use include("template.htm");
is this in .sh possible too for include a mail template

Thanks
Brandmeir Gerhard
 
Originally posted by jamesyeeoc

Just a comment and a security advice :) It's very bad to have the Plesk Admin password written in cleartext in any script.

So one should change from:

Code:
PSA_PASSWORD=`
mysql -uadmin -pYourAdminPassword -N psa<< eof
SELECT a.password FROM accounts a, sys_users s WHERE login LIKE '$PSA_USERNAME' and a.id = s.account_id;
eof`

To something like this:

Code:
PSA_PASSWORD=`mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` -N psa<< eof
SELECT a.password FROM accounts a, sys_users s WHERE login LIKE '$PSA_USERNAME' and a.id = s.account_id;
eof`

Making sure no cleartext password is written in the script and also making sure the script will run when/if the admin password is changed :)
 
Thanks Geert, a very valid point. I'm slipping in my old age :)
 
Hello

Code:
PSA_PASSWORD=`
mysql -uadmin -pYourAdminPassword -N psa<< eof
SELECT a.password FROM accounts a, sys_users s WHERE login LIKE '$PSA_USERNAME' and a.id = s.account_id;
eof`

To something like this:

Code:
PSA_PASSWORD=`mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` -N psa<< eof
SELECT a.password FROM accounts a, sys_users s WHERE login LIKE '$PSA_USERNAME' and a.id = s.account_id;
eof`

oh ok i use this

but have you a answer of my ask with the tamplate in a .sh script ?


Thanks
Brandmeir Gerhard
 
Originally posted by bloosk
but have you a answer of my ask with the tamplate in a .sh script ?

If you know how to program and use different kind of utilities (Bash, Perl, PHP, etc.) I don't see any problems in making some kind of e-mail template.

Basically you could write a PHP program that will mail the information - and call it from the shell script.

Call it via the PHP CLI[1] function.

Ie. /usr/local/bin/php -f path_to_your/php_script <your parameters> >/dev/null 2>&1

[1] See more info on http://php.net/features.commandline
 
Hello jamesyeeoc

<new_system_user> = (already passed as $1)
<new_domain_name> =$4

In the script you can build a variable ($e_address)which will consist of:

$1 + "@" + $4

ok thats runnig but with this i have the login name from the FTP User in email ([email protected]) because i think thats not good.

now i tested in event manager the variable <new_email> as $2 in .sh but it dont work as i understand it only work on Client account created.
Maybe can i query the email from the
Client account from the domain how i saved at Client account created?

Thanks
Brandmeir Gerhard

PS. i think many users have the same problem how cant send the FTP User Password to the Client. If it work later i put it here to Download for another Users.
 
Hello

i have work a little bit
and i have created
PSA_EMAIL=`mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` -N psa<< eof
SELECT a.email FROM clients a, domains s WHERE displayName LIKE '$PSA_DOMAINNAME' and a.id = s.cl_id;
eof`
and it works fine but is this the right neat solution or gives a other solution it is better

Thanks

Brandmeir Gerhard
 
Hello

first very much Thanks to you
the ftpaccount from Client_mail send it fine

ok now i say what i do

mailftp.php
------------------------------------------------------
PHP:
#!/usr/bin/php
<?php       
$username = $argv[1];
$passwort = $argv[2];
$mailsender = $argv[3];  
    
$mailversand = "
-------------
Username : $username<br>
-------------
Passwort : $passwort<br>
-------------
Email : $mailsender<br>
-------------
";

$header="From: [email][email protected][/email]\n";
$header .= "X-Mailer: PHP/" . phpversion(). "\n";          
$header .= "X-Sender-IP: $REMOTE_ADDR\n"; 
$header .= "Content-Type: text/html"; 
mail($mailsender,"FTP Zugangsdaten",$mailversand,$header);
---------------------------
ftpemail.sh
---------------------------
PHP:
 #!/bin/sh
PSA_USERNAME=$1
PSA_DOMAINNAME=$2

PSA_PASSWORD=`mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` -N psa<< eof
SELECT a.password FROM accounts a, sys_users s WHERE login LIKE '$PSA_USERNAME' and a.id = s.account_id;
eof`
PSA_EMAIL=`mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` -N psa<< eof
SELECT a.email FROM clients a, domains s WHERE displayName LIKE '$PSA_DOMAINNAME' and a.id = s.cl_id;
eof`

/usr/local/psa/admin/plib/modules/sbm/mailftp.php $PSA_USERNAME $PSA_PASSWORD $PSA_EMAIL >/dev/null 2>&1
---------------------------------------

this must be to the eventmanager in Plesk Interface
Physical Hosting Created
root
/usr/local/psa/admin/plib/modules/sbm/ftpemail.sh <new_system_user> <new_domain_name>

and now create a domain with ftpuser and the Client become a mail with FTP

So Thanks to jamesyeeoc and Whistler for your help :D

and give me please a answer for my Thread before
right neat solution or gives a other solution it is better

and here is the zip file with ftpemail.sh and mailftp.php
 
Sorry I didn't see you had posted again until now.

The forums are disabled for attachments and picture uploads. This is the choice of Plesk Forum administrator.

You could always make the zip file available on your website and post a link to it here.

I am glad you got the final parts worked out, and thank you for posting your script and solution here. It will help future readers!
 
Back
Top