code for auto creation of pop accounts through php webpage

richardwing

Member
Sep 18, 2002
14
0
151
AZ
I am looking for some example code that will allow me to communicate with my cpanel from a localhost account.

I am using a popular cms and it is php and mysql driven.

The cms allows for users to sign up and create a username and account. they get sent a password. that works with their username.

I need a few things to happen.


I need to know some php code that I can insert into the page that allows for account creation so that it communicates with the cpanel mail area so that it will automatically create a pop account using the username that the client asked for in the cms signup.

I need it to check if there isn't a pop by that name already in use. and if there is it kick back an error for them to try another username on the system.

I need it to also send the password that the cms script starts them out with and post it with the username as the initial pop name and password.


Once the account is created then I also need to know what code to use to allow the user to change their passwords for their pop account.

What I would most likely do is have the same area that allows them to modify their password for the cms also post that same password to the proper place so that their pop password is always the same as the cms password.

For those that may also be familiar with the open source postnuke cms script, that is the one I need a solution for.

Any coding structure, methods, and variables that deal with the creation or modification of the pop email area of cpanel would be greatly appreciated.

I need to know how to allow my cms to get past the .htaccess behind the scenes to make these posts or modifications.

I know that there are many others that use cpanel and the postnuke cms system would love to have a feature such as the one I am trying to accomplish.

Thanks for your time reading my post here.

Richard Wing

cPanel.net Support Ticket Number:

cPanel.net Support Ticket Number:
 

quasiman

Member
Aug 26, 2003
10
0
151
Portland, Oregon
cPanel Access Level
Root Administrator
I'm working on this one myself...

Here's a php script/form that will create a pop user, add the user to a mysql database, and check to make sure there isn't already a user of that name present in the database.

Now, if you can figure out a way to integrate this into PostNuke (I'm just barely figuring out PostNuke now), let me know so I can use it too! :)

Here's the script:

<?php
include("../config.php");
doheader();
if(isset($newuser))
{
$newemail = "[email protected]$domain";
$mpassword = $password2;

$link = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname) or die("Could not select database");
$query="SELECT username FROM $dbusertbl WHERE((username = '$newuser'))";
$result= mysql_query($query,$link);
if(mysql_num_rows($result) ==0)
{
$query="INSERT INTO $dbusertbl(name,username,password,email) VALUES ('$name','$newuser','$password1','$replymail');";
mysql_query($query,$link);
$socket = fsockopen($host,2082);
$authstr = "$cpaneluser:$cpanelpass";
$pass = base64_encode($authstr);
$in = "GET /frontend/$cpaneltheme/mail/doaddpop.html?email=$newemail&domain=$domain&password=$mpassword&a=$quota\r\n HTTP/1.0\r\nAuthorization: Basic $pass \r\n";
fputs($socket,$in);
fclose( $socket );
?> Your account has been setup successfully please login <a href="mail/index.php">here</a>
<?
}
else {
echo "Username already in use please try another one.<br><a href=signup.php>Back</a>";
}
mysql_close($link);
}

else { ?>
<form name="orderform" method="post" action="signup.php">
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td>Your full Name:</td>
<td colspan="2"><input name="name" type="text"></td>
</tr>
<tr>
<td width="147">Other Email Address:</td>
<td colspan="2"><input name="replymail" type="text">
(In case you forget your password)</td>
</tr>
<tr>
<td>Prefered Email Address:</td>
<td colspan="2"><input name="newuser" type="text">
@<?= $domain ?></td>
</tr>
<tr>
<td>Password:</td>
<td colspan="2"><input name="password1" type="password"></td>
</tr>
<tr>
<td>Retype Password:</td>
<td colspan="2"><input name="password2" type="password"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td width="344"> <div align="center">
<input name="signupbtn" type="button" id="signupbtn" value="Signup" onClick="validateform()">
</div></td>
<td width="163">&nbsp;</td>
</tr>
</table>
<script language="JavaScript1.2">


function validateform()
{
if (checkEmailAddress(document.orderform.replymail))
{
if(document.orderform.password1.value == document.orderform.password2.value)
{
document.orderform.submit();
}
else
{
alert("The passwords you typed do not appear to match");
}
}
}

function checkEmailAddress(field) {
var good;
var goodEmail = field.value.match(/\b(^(\[email protected]).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

if (goodEmail){
good = true
} else {
alert('Please enter a valid e-mail address.')
field.focus()
field.select()
good = false
}
return good;
}


</script>
</form>


Here's what your config.php file should look like (should be easy to change for PostNuke):

<?

$host = "www.yourdomain.com";//your url
$domain = "yourdomain.com";//your domain without the www

//Cpanel options:
$cpaneluser = "username";//your cpanel username
$cpanelpass = "password";//your cpanel password
$cpaneltheme= "bluelagoon"; //this is the word after frontend/ and the next / when you login to cpanel

//Database options:
$dbhost="localhost"; //Usually localhost
$dbuser="admin";//mysql username
$dbpass="yourpassword";//mysql password

$dbname="username_mailusers";//The name of the database for mail
$dbusertbl="mailusers";//Name of the table for users
$dbadmintbl="mailadmin";//name of the table for admin


$quota=1024;//how much space in k you want to give the user
$mailurl="mail/index.php";//The url for your web based mail program



?>

cPanel.net Support Ticket Number:

cPanel.net Support Ticket Number:

cPanel.net Support Ticket Number:

cPanel.net Support Ticket Number:

cPanel.net Support Ticket Number:
 

richardwing

Member
Sep 18, 2002
14
0
151
AZ
great start... working on it...

I have a partner that will work on it and I will get back to you. This is a great starting point for us.

Richard

cPanel.net Support Ticket Number:
 

ph3n0m

Registered
Oct 7, 2003
2
0
151
Dublin, Ireland
just wondering - what documentation did you find the following information in?

$socket = fsockopen($host,2082);
$authstr = "$cpaneluser:$cpanelpass";
$pass = base64_encode($authstr);
$in = "GET /frontend/$cpaneltheme/mail/doaddpop.html?email=$newemail&domain=$domain&password=$mpassword&a=$quota\r\n HTTP/1.0\r\nAuthorization: Basic $pass \r\n";
fputs($socket,$in);
fclose( $socket );

As I am looking to do something similiar for sub domains and other functions
 

drunkn_munky

Member
Jan 31, 2004
24
0
151
The best way to find that out is to go to the page where you add a subdomain, thats the url you need to GET, and click view source. The form names is basically the string kinda thing. So if the url was domains/addsub.php?formname=$formname etc.
 

bikersraw

Active Member
Feb 16, 2004
27
0
151
the above code dosent seem to work... i get no errors running it, but also no email address is created.

info goes into the created database, but cpanel does not show a new created email address.... any ideas? the code is the same as posted above
 

bikersraw

Active Member
Feb 16, 2004
27
0
151
Originally posted by bikersraw
the above code dosent seem to work... i get no errors running it, but also no email address is created.

info goes into the created database, but cpanel does not show a new created email address.... any ideas? the code is the same as posted above
nevermind I'm a retard and spelled my domain wrong in the config file ;)

pimp code guys... now i gotta make it functional
 

MrStatic

Registered
Feb 14, 2004
4
0
151
With your script first I get a parse error and also does it run off of my config file already made or do I have to make a special one?
 

tomfra

Well-Known Member
Sep 30, 2002
68
1
158
I have been using something similar for automatic email creation and it used to be working just fine. However, sometimes ago it simply stopped working, I suppose because Cpanel has upgraded something.

There seems to be a problem with the authentification part. Just take a look at my post at http://forums.cpanel.net/showthread.php?s=&threadid=20653 .

I would appreciate if something could tell me what is wrong because I need to fix it asap.

Thanks!

Tomas