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
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
