Web Hosting Talk







View Full Version : PSA v2.0 script to email CP users their username and password on request.


CWDSolutions
10-22-2001, 04:03 PM
Hello,

If tehre is anyone using PSA v2.0 and need to have the ability for
their sutomers to retrive a lost username and password this little
script will do it for you.

All the user has to do is enter the domain name they have hosted
and the script will send an email with the username and password
for that domain name to the email address that is on file. This is to
make sure only the person who has the account receives the email.

Also there is a regex that checks for illegal characters in the form such as
"." periods at the begining and other characters not used in a domain name.

If the domain name does not exsist there is an error telling the user.

Now for the code.

<?php
// This is a small program to retrieve username
// and password for plesk control panel.

// Setup database information
$dbhost = "localhost"; // Should not need to change this
$dbuser = "adminusername"; // Change this to your admin Username
$dbpass = "adminpassword"; // Change this to your admin password
$db = "psa"; // Do not chagne this line
$dbtbl = "clients"; // Do not chagne this line
$dbtbldomain = "domains"; // Do not chagne this line

// Subledt to send with email
$subject = "Your Control Panel Login Information for yourhostname.com";

// Who the email is comming from as well as the reply to address
$from = "From: Your company name here<youremail@yourdomain.com>\n";
$from .= "Reply-To: youremail@yourdomain.com\n";

// Check and see what action we need to take
if($action == "process"){
$error = 0;
// Process the request

// First lets check there is somethign in the text field
if($domain == ""){echo "Please enter a domain name, Please <a href=\"Javascript:history.back()\">click here</a> to try again."; $error = 1; exit;}
if(ereg("^\.", $domain)){echo "There is an error in your domain name, Please <a href=\"Javascript:history.back()\">click here</a> to try again."; $error = 1; exit;}
if(ereg("[\\\/$%&*+=@#!<>\'\"?\*~`,:;|\^()(]", $domain)){echo "There is an error in your domain name, Please <a href=\"Javascript:history.back()\">click here</a> to try again."; $error = 1; exit;}
// Now we need to do a query and check that the domain name exsists
// only if there was no error
if(!$error){
$connect = mysql_connect($dbhost,$dbuser,$dbpass) || die("Unable to connect to database");

// Lets switch to the db we want to use
mysql_select_db($db) || die("Unable to select $db");

$results = mysql_query ("SELECT $dbtbl.email,$dbtbl.login,$dbtbl.passwd FROM $dbtbldomain, $dbtbl WHERE $dbtbldomain.name='$domain' AND $dbtbl.id=$dbtbldomain.cl_id") or die("Unable to select from $dbtbldomain");
$row = mysql_fetch_array($results);
if($row){
$receipt = $row['email'];

// Change this information to what you want the emails to say
// went sent to the customer.
$message = "You have requested your login information for your control panel.

Control Panel Username: $row[login]
Control Panel Password: $row[passwd]

If you have any questions please email us at: youremail@yourdomain.com

Thank You,
Your Company Name
www.yourdomain
";
// Stop changing inforamtion

$sent = mail($receipt, $subject, $message, $from);

if($sent){
echo "Login information for $row[name] has been sent to $receipt";
}else{
echo "Email not sent";
}
}else{
echo "Domain name <b>$domain</b> does not exsist, Please <a href=\"Javascript:history.back()\">click here</a> to try again.";
}
}else{
echo "There was an error processing your request, Please <a href=\"Javascript:history.back()\">click here</a> to try again.";
}
}else{
// Show the form to get the username
// and password
?>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<input type="hidden" name="action" value="process">
<table width="200" cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan=2>Enter your domain name:</td>
</tr>
<tr>
<td><input type="text" name="domain" size="20" maxlength="70"></td>
<td><input type="submit" value="Process"></td>
</tr>
</table>
</form>
<?php
}
?>


If you have any questions or suggestions please let me know.

Regards,
Ray

phpjames
10-22-2001, 04:31 PM
Ray,
You Rock! :D

phpjames
10-22-2001, 04:38 PM
Anyone know of any online resouces specifially for Plesk? I am looking for Plesk resources.

Thanks

davidb
10-22-2001, 04:48 PM
Thanks for freely posting this. I will for sure use it. Thanks a lot.

CWDSolutions
10-23-2001, 03:45 AM
Welcome,

I an going to be making a small script to email all customers in the
database here soon, I'll post the code once I get the chance to
create it.

I thought of creating a Automatic signup script but Plesk should have
theirs out not to long from now, so would be none benificial.

phpjames, the only resource really is at http://forum.plesk.com
Plesk is not open software and they encode the the program
using the Zend Encoder, therefor you wont really find any real
integration with it.

Regards,
Ray

phpjames
10-23-2001, 07:16 AM
Ray,
Any word on when the signup will be availble from plesk? I havent been able to find out the details.

davidb
10-23-2001, 04:09 PM
I belive that it is a backup and a signup type forum that is being created will be out I want to say in two weeks or so from what I read. There was a post that someone said they were currently testing the features. Mainly the Sept. 11 Attacks slowed down the realise.

^^just what I heard

Rewdog
10-23-2001, 10:53 PM
Thanks man, kick (_Y_)! :D

Nicholas Brown
10-27-2001, 04:59 PM
you my friend....Kick ass! :cool: :D

davidb
10-28-2001, 02:38 PM
I am not a php expert, but from working with cgi and perl, cant someone view the php source code and get the admin pass and login?

CWDSolutions
10-28-2001, 10:19 PM
PHP is run onthe fly, so the only thing anyone will see is the HTML code
of the file. If this is a major concern you could make a seperate
file and drop the stuff below into it
set thi9e file off your document root and include it in the top of the
html page you have the script into:

config.php file

<?php

// Setup database information
$dbhost = "localhost"; // Should not need to change this
$dbuser = "adminusername"; // Change this to your admin Username
$dbpass = "adminpassword"; // Change this to your admin password
$db = "psa"; // Do not chagne this line
$dbtbl = "clients"; // Do not chagne this line
$dbtbldomain = "domains"; // Do not chagne this line

// Subledt to send with email
$subject = "Your Control Panel Login Information for yourhostname.com";

// Who the email is comming from as well as the reply to address
$from = "From: Your company name here<youremail@yourdomain.com>\n";
$from .= "Reply-To: youremail@yourdomain.com\n";
?>


you would include it like so:

<?php
// Include the config file
include "/path/to/file/config.php";

// Check and see what action we need to take
if($action == "process"){
$error = 0;
// Process the request

// First lets check there is somethign in the text field
if($domain == ""){echo "Please enter a domain name, Please <a href=\"java script:history.back()\">click here</a> to try again."; $error = 1; exit;}
if(ereg("^.", $domain)){echo "There is an error in your domain name, Please <a href=\"java script:history.back()\">click here</a> to try again."; $error = 1; exit;}
if(ereg("[\/$%&*+=@#!<>'\"?*~`,:;|^()(]", $domain)){echo "There is an error in your domain name, Please <a href=\"java script:history.back()\">click here</a> to try again."; $error = 1; exit;}
// Now we need to do a query and check that the domain name exsists
// only if there was no error
if(!$error){
$connect = mysql_connect($dbhost,$dbuser,$dbpass) || die("Unable to connect to database");

// Lets switch to the db we want to use
mysql_select_db($db) || die("Unable to select $db");

$results = mysql_query ("SELECT $dbtbl.email,$dbtbl.login,$dbtbl.passwd FROM $dbtbldomain, $dbtbl WHERE $dbtbldomain.name='$domain' AND $dbtbl.id=$dbtbldomain.cl_id") or die("Unable to select from $dbtbldomain");
$row = mysql_fetch_array($results);
if($row){
$receipt = $row['email'];

// Change this information to what you want the emails to say
// went sent to the customer.
$message = "You have requested your login information for your control panel.

Control Panel Username: $row[login]
Control Panel Password: $row[passwd]

If you have any questions please email us at: youremail@yourdomain.com

Thank You,
Your Company Name
<a href="http://www.yourdomain" target="_blank">www.yourdomain</a>
";
// Stop changing inforamtion

$sent = mail($receipt, $subject, $message, $from);

if($sent){
echo "Login information for $row[name] has been sent to $receipt";
}else{
echo "Email not sent";
}
}else{
echo "Domain name <b>$domain</b> does not exsist, Please <a href="java script:history.back()\">click here</a> to try again.";
}
}else{
echo "There was an error processing your request, Please <a href=\"java script:history.back()\">click here</a> to try again.";
}
}else{
// Show the form to get the username
// and password
?>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<input type="hidden" name="action" value="process">
<table width="200" cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan=2>Enter your domain name:</td>
</tr>
<tr>
<td><input type="text" name="domain" size="20" maxlength="70"></td>
<td><input type="submit" value="Process"></td>
</tr>
</table>
</form>
<?php
}
?>


Hope this helps with any worries you have.

Regards,
Ray