Final_S
03-26-2009, 04:49 AM
Hi
I would like to know if its possible to create ftp and email accounts using a set of PHP forms to write to the database.
I would like to do this in order to add additional information, so that password retrieval can be automated for both ftp and email accounts.
Admins would be the only people using the creation forms and the retrieval forms would be used by registered users.
thanks
wysiwyg
03-26-2009, 05:55 AM
Yeah, it can be done. My brother posted an example of how to do it last year, it's a little hard to find though.
I don't know what your tech level is; if you know php/mysql then I'll show you how to hack it to interface with cPanel, if you want the whole script with all the functionality you've listed I'd have to charge something for it.
Final_S
03-28-2009, 05:54 AM
I'm going to set the system up as best as I can. In order to just add the "hacks" at the end. I would like to be as involved in this project as possible to boost my own knowledge and comprehension.
I don't mind paying for your assistance.
If you could give me an estimate. That would be good.
You said, "hack the cpanel interface"
So that would not then plug directly into the email database? and if so... how would you add additional info?
~thanks
wysiwyg
03-28-2009, 11:06 AM
It's impossible to get at wherever cpanel stores that information for security reasons.
My script would essentially log into cpanel and use their scripts to automate whatever processes it needs to do. It would act as a layer between the user and cpanel, giving them limited access to specific commands.
There would need to be a login system to restrict access to the administrative commands, either separate accounts or just a main one.
In order to make a password recovery system, the script would need to store information about each user in a mysql database when the account is created.
For example, a column for the email address it just created, one for an alternative email to send the password to, one to store the password (depending on whether you want to just send them their password or if you want it to generate a new password and send it to them), whatever other information you want to store.
If the FTP accounts need to be associated with the email accounts, then there could be some integration between them. However you want to do that.
I've written the core, which is pretty much everything you need to interact with cpanel. All you need to configure is your cpanel login information. I'm posting it here for whoever might be interested.
I included a function that returns the email accounts currently registered on your account, and also one to create an email account, just to show you how it works. This is just an example, a full-scale program would have separate classes for the FTP/email functions.
<?php
class cpanel {
function __construct( ) {
$this -> username = 'user'; // cpanel login
$this -> password = 'pass';
$server = $_SERVER['SERVER_ADDR'];
$skin = 'bluehost';
$this -> url = "http://{$server}:2082/frontend/{$skin}/";
}
function _curl( $url = '', $post = false ) { // returns html contents of a cpanel path or exits if status is not OK
$url = $this -> url . $url;
$ch = curl_init( );
$op = array(
CURLOPT_URL => $url,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_UNRESTRICTED_AUTH => true,
CURLOPT_USERPWD => $this -> username . ':' . $this -> password
);
if( $post ) {
$op[CURLOPT_POST] = true;
$op[CURLOPT_POSTFIELDS] = $post;
}
curl_setopt_array( $ch, $op );
$return = curl_exec( $ch );
$response = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch );
if( $response == 200 ) return $return;
else die( "Failed to open <a href='{$url}'>{$url}</a><br/>Returned <a href='http://en.wikipedia.org/wiki/List_of_HTTP_status_codes'>{$response}</a> error");
}
function dom( $html ) { // returns domdocument object from html string
$doc = new DOMDocument( );
@$doc -> loadHTML( $html );
@$doc -> normalizeDocument( );
return $doc;
}
function textify( $node ) { // returns textContent property if it exists
if( is_object( $node ) ) return ( property_exists( $node, textContent ) ) ? trim( $node -> textContent ) : false;
else return false;
}
function getEmail( ) { // returns array containing disk quota and usage for each email address
$doc = $this -> dom( $this -> _curl( 'mail/pops.html?itemsperpage=500' ) );
$table = $doc -> getElementById( 'mailtbl' );
foreach( $table -> getElementsByTagName( 'tr' ) as $row ) {
if( $address = $this -> textify( $row -> getElementsByTagName( 'td' ) -> item( 0 ) ) ) {
$email = &$return[$address];
$email['usage'] = $this -> textify( $row -> getElementsByTagName( 'td' ) -> item( 2 ) );
$email['quota'] = $this -> textify( $row -> getElementsByTagName( 'td' ) -> item( 3 ) );
}
}
ksort( $return ); // sort by address
return $return; // return array
}
function addEmail( $email, $domain, $password, $quota = 0 ) { // quick and dirty example of using post in my curl function
$post = "email={$email}&domain={$domain}&password={$password}"a={$quota}";
$doc = $this -> dom( $this -> _curl( 'mail/doaddpop.html', $post ) );
if( $details = $doc -> getElementById( 'details' ) ) echo "\n<div class='error'>{$this -> textify( $details )}</div>";
else echo "\n<div class='success'>{$email}@{$domain} created successfully!</div>";
}
}
?>
<html>
<title>cpanel interfacerer</title>
<style type="text/css">
body {
background-color: #fff;
font-family: arial;
}
table,div {
width: 40em;
}
table td {
border: 1px solid #000;
padding: .2em;
}
div {
padding: 1em;
margin: 1em;
}
div.error {
border: 1px solid #f00;
background-color: #fee;
}
div.success {
border: 1px solid #0f0;
background-color: #efe;
}
</style>
</head>
<body>
<?php
$cpanel = new cpanel;
// $cpanel -> addEmail( 'example', 'example.com', 'p455w0rd', 250 ); // addEmail usage
$emails = $cpanel -> getEmail( );
$table = "\n<table class='email'>\n<tr><th>Account</th><th>Usage</th><th>Quota</th></tr>";
foreach( $emails as $address => $data ) {
$table .= "\n<tr>";
$table .= "<td>{$address}</td>";
$table .= "<td>{$data['usage']}</td>";
$table .= "<td>{$data['quota']}</td>";
$table .= "</tr>";
}
$table .= "\n</table>";
echo $table;
?>
</body>
</html>
I'm not sure exactly how much you need it to do, but going by what you've said so far I could probably do it for $75-100. If you want, you can shoot me a PM to discuss it.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.