PDA

Bekijk Volledige Versie : PHP script voor het aanmaken van email account.



ikkeweer
03/01/06, 12:32
Hoi,

Ik zoek nu toch al behoorlijke tijd naar een php script voor het automatische aanmaken van een email account in directadmin, maar ik heb tot dusver niks kunnen vinden.

Heeft iemand een php script daarvoor of weet iemand er wel 1 te vinden.

Voor cpanel zijn er genoeg maar voor DirectAdmin is niks te vinden :(.


Alvast bedankt,
Sebastiaan

CharlieRoot
03/01/06, 13:48
Misschien gewoon met een cron of sudo doen?

ikkeweer
03/01/06, 14:10
Ik wou jullie even bedanken voor de reacties en wou even zeggen dat ik er al zelf 1 heb gemaakt.

Dus als iemand er intresse inheeft.

leonnet
05/01/06, 16:36
op www.directadmin.com is zelf ook 1 class te vinden.

edsulst
19/05/06, 10:42
Ik wou jullie even bedanken voor de reacties en wou even zeggen dat ik er al zelf 1 heb gemaakt.

Dus als iemand er intresse inheeft.


Uiteraard heb ik hier interesse voor.
Wil je het naar me mailen.

Keizer
19/05/06, 11:17
Ik heb hier ook wel interesse voor!

PM/Mail ?

Chill Creations
19/05/06, 12:34
Ik ook graag! Stuur maar een PM graag.

Richard31
19/05/06, 13:33
Is dit niet mogelijk via de standaard DirectAdmin API?
Zo niet, heb ik ook wel interesse in scripje van ikkeweer...

rvessem
19/05/06, 13:49
hier ook intresse

Kahil
19/05/06, 15:00
Ik heb hier ook interesse voor. PM graag

DutchTSE
19/05/06, 17:16
als je me niet al te lastig vind heb ik ook interesse :)

Eris
20/05/06, 16:31
Ik heeft misschien geen ikkeweer. Maar toch:
/secure/connect.php


<?php

/**
* Socket communication class.
*
* Originally designed for use with DirectAdmin's API, this class will fill any HTTP socket need.
*
* Very, very basic usage:
* $Socket = new HTTPSocket;
* echo $Socket->get('http://user:pass@somesite.com/somedir/some.file?query=string&this=that');
*
* @author Phi1 'l0rdphi1' Stier <l0rdphi1@liquenox.net>
* @package HTTPSocket
* @version 2.4
*/
class HTTPSocket {

var $version = '2.4';

/* all vars are private except $error, $query_cache, and $doFollowLocationHeader */

var $method = 'GET';

var $remote_host;
var $remote_port;
var $remote_uname;
var $remote_passwd;

var $result;
var $result_header;
var $result_body;
var $result_status_code;

var $bind_host;

var $error = array();
var $query_cache = array();

var $doFollowLocationHeader = TRUE;
var $redirectURL;

var $extra_headers = array();

/**
* Create server "connection".
*
*/
function connect($host, $port = '' )
{
if (!is_numeric($port))
{
$port = 80;
}

$this->remote_host = $host;
$this->remote_port = $port;
}

function bind( $ip = '' )
{
if ( $ip == '' )
{
$ip = $_SERVER['SERVER_ADDR'];
}

$this->bind_host = $ip;
}

/**
* Change the method being used to communicate.
*
* @param string|null request method. supports GET, POST, and HEAD. default is GET
*/
function set_method( $method = 'GET' )
{
$this->method = strtoupper($method);
}

/**
* Specify a username and password.
*
* @param string|null username. defualt is null
* @param string|null password. defualt is null
*/
function set_login( $uname = '', $passwd = '' )
{
if ( strlen($uname) > 0 )
{
$this->remote_uname = $uname;
}

if ( strlen($passwd) > 0 )
{
$this->remote_passwd = $passwd;
}

}

/**
* Query the server
*
* @param string containing properly formatted server API. See DA API docs and examples. Http:// URLs O.K. too.
* @param string|array query to pass to url
*/
function query( $request, $content = '' )
{
$this->error = array();

// is our request a http:// ... ?
if (preg_match('!^http://!i',$request))
{
$location = parse_url($request);
$this->connect($location['host'],$location['port']);
$this->set_login($location['user'],$location['pass']);

$request = $location['path'];
$content = $location['query'];

if ( strlen($request) < 1 )
{
$request = '/';
}

}

$array_headers = array(
'User-Agent' => "HTTPSocket/$this->version",
'Host' => ( $this->remote_port == 80 ? $this->remote_host : "$this->remote_host:$this->remote_port" ),
'Accept' => '*/*',
'Connection' => 'Close' );

foreach ( $this->extra_headers as $key => $value )
{
$array_headers[$key] = $value;
}

$this->result = $this->result_header = $this->result_body = '';

// was content sent as an array? if so, turn it into a string
if (is_array($content))
{
$pairs = array();

foreach ( $content as $key => $value )
{
$pairs[] = "$key=".urlencode($value);
}

$content = join('&',$pairs);
unset($pairs);
}

// instance connection
if ($this->bind_host)
{
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($socket,$this->bind_host);
socket_connect($socket,$this->remote_host,$this->remote_port);
}
else
{
$socket = @fsockopen( $this->remote_host, $this->remote_port, $sock_errno, $sock_errstr, 30 );
}

if (!$socket)
{
$this->error[] = "Can't create socket connection to $this->remote_host:$this->remote_port.";
return 0;
}

// if we have a username and password, add the header
if ( isset($this->remote_uname) && isset($this->remote_passwd) )
{
$array_headers['Authorization'] = 'Basic '.base64_encode("$this->remote_uname:$this->remote_passwd");
}

// for DA skins: if $this->remote_passwd is NULL, try to use the login key system
if ( isset($this->remote_uname) && $this->remote_passwd == NULL )
{
$array_headers['Cookie'] = "session={$_SERVER['SESSION_ID']}; key={$_SERVER['SESSION_KEY']}";
}

// if method is POST, add content length & type headers
if ( $this->method == 'POST' )
{
$array_headers['Content-type'] = 'application/x-www-form-urlencoded';
$array_headers['Content-length'] = strlen($content);
}
// else method is GET or HEAD. we don't support anything else right now.
else
{
if ($content)
{
$request .= "?$content";
}
}

// prepare query
$query = "$this->method $request HTTP/1.0\r\n";
foreach ( $array_headers as $key => $value )
{
$query .= "$key: $value\r\n";
}
$query .= "\r\n";

// if POST we need to append our content
if ( $this->method == 'POST' && $content )
{
$query .= "$content\r\n\r\n";
}

// query connection
if ($this->bind_host)
{
socket_write($socket,$query);

// now load results
while ( $out = socket_read($socket,2048) )
{
$this->result .= $out;
}
}
else
{
fwrite( $socket, $query, strlen($query) );

// now load results
while (!feof($socket))
{
$this->result .= fgets($socket,1024);
}
}

list($this->result_header,$this->result_body) = split("\r\n\r\n",$this->result,2);

if ($this->bind_host)
{
socket_close($socket);
}
else
{
fclose($socket);
}

$this->query_cache[] = $query;


$headers = $this->fetch_header();

// what return status did we get?
preg_match("#HTTP/1\.. (\d+)#",$headers[0],$matches);
$this->result_status_code = $matches[1];

// now, if we're being passed a location header, should we follow it?
if ($this->doFollowLocationHeader)
{
if ($headers['location'])
{
$this->redirectURL = $headers['location'];
$this->query($headers['location']);
}
}

}

/**
* The quick way to get a URL's content :)
*
* @param string URL
* @return string result body
*/
function get($location)
{
$this->query($location);
return $this->fetch_body();
}

/**
* Returns the last status code.
* 200 = OK;
* 403 = FORBIDDEN;
* etc.
*
* @return int status code
*/
function get_status_code()
{
return $this->result_status_code;
}

/**
* Adds a header sent with the next query.
*
* @param string header name
* @param string header value
*/
function add_header($key,$value)
{
$this->extra_headers[$key] = $value;
}

/**
* Clears any extra headers.
*
*/
function clear_headers()
{
$this->extra_headers = array();
}

/**
* Return the result of a query.
*
* @return string result
*/
function fetch_result()
{
return $this->result;
}

/**
* Return the header of result (stuff before body).
*
* @param string (optional) header to return
* @return array result header
*/
function fetch_header( $header = '' )
{
$array_headers = split("\r\n",$this->result_header);

$array_return = array( 0 => $array_headers[0] );
unset($array_headers[0]);

foreach ( $array_headers as $pair )
{
list($key,$value) = split(": ",$pair,2);
$array_return[strtolower($key)] = $value;
}

if ( $header != '' )
{
return $array_return[strtolower($header)];
}

return $array_return;
}

/**
* Return the body of result (stuff after header).
*
* @return string result body
*/
function fetch_body()
{
return $this->result_body;
}

/**
* Return parsed body in array format.
*
* @return array result parsed
*/
function fetch_parsed_body()
{
parse_str($this->result_body,$x);
return $x;
}

}
//connect to server / create class

$sock = new HTTPSocket;
$sock->connect('domein.nl.nl',2222);
$sock->set_login('user','www');

?>

//addaccount.php


<?php
if($_SESSION['login']['l_acces'] > 3)
{
if(!empty($_POST['user']) && !empty($_POST['passwd'])){
//include api
include('secure/connect.php');
//create a class
$sock->query('/CMD_API_POP','domain=mijndomein.nl&quota=2&action=create&user='.$_POST['user'].'&passwd='.$_POST['passwd'].'');
echo $sock->result;
$db->logger('Emailadress ('.$_POST['user'].') toegevoegd',$_SERVER["REQUEST_URI"],$_SESSION['login']['l_id']);
if(eregi('error=0', $sock->result)){
echo '<p>Email adress is aan gemaakt<br />
username: '.$_POST['user'].'@mijndomein.nl<br />
password: '.$_POST['passwd'].'<br />
POP3 server: mail.mijndomein.nl<br />
SMTP server: mail.mijndomein.nl</p>';
}else{
echo 'Er is een fout opgetrede<br />';
$out = explode('details=',$sock->result);
echo 'De volgende foutmelding is ontvangen <strong>'.$out[1].'</strong>
<a href="index.php?page=add_account">Klik hier om terug te gaan naar het formulier</a>';
}
}else{
?>
<p>Voeg een email account toe:</p>
<form action="index.php?page=add_account" method="post">
<p>Email:<br />
<input type="text" name="user" value=""/>@mijndomein.nl<br />
Wachtwoord:<br />
<input type="password" name="passwd" value=""/><br />
<input type="submit" value="Account aanmaken"/></p></form>
<?
}
}
?>

De script komt uit een cms dat ik ooit heb gemaakt ... Dus niet echt "vriendelijk"

Stephan Vierkan
12/07/06, 17:18
Ik heb ook interesse! Is het niet handiger het script gewoon online te gooien?

ikkeweer
21/10/06, 13:22
ik zal vanavond wel linkje plaatsen naar zip file met het script

Bernt
22/10/06, 11:06
ik zal vanavond wel linkje plaatsen naar zip file met het script
het is al avond geweest:) :lovewht:

tomtom
14/11/06, 21:22
Hallo,

Kan je hem er nog opzette?

Groete Tom,

WinuX
20/11/06, 17:19
Ik zou hem ook wel willen, kun je hem online zetten?

Eris
20/11/06, 18:32
Kijk even 2 topic op hoog... ^^

Solid
13/12/06, 21:52
Ben benieuwd ::lovewht: