Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DirectAdmin.php #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 51 additions & 13 deletions src/DirectAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Solitweb\DirectAdmin;

<?php

/**
* Socket communication class.
*
Expand All @@ -12,8 +14,17 @@
* echo $Socket->get('http://user:[email protected]/somedir/some.file?query=string&this=that');
*
* @author Phi1 'l0rdphi1' Stier <[email protected]>
* @package DirectAdmin
* @version 3.0.1
* @package HTTPSocket
* @version 3.0.4

* 3.0.4
* store first proxy headers for return, in event of redirect

* 3.0.3
* curl Cookie for SESSION_ID+SESSION_KEY changed to setopt with

* 3.0.2
* added longer curl timeouts

* 3.0.1
* support for tcp:// conversion to http://
Expand All @@ -33,7 +44,7 @@
*/
class DirectAdmin {

var $version = '3.0.1';
var $version = '3.0.4';

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

Expand Down Expand Up @@ -64,6 +75,9 @@ class DirectAdmin {

var $extra_headers = array();

var $proxy = false;
var $proxy_headers = array();

/**
* Create server "connection".
*
Expand Down Expand Up @@ -118,6 +132,23 @@ function set_login( $uname = '', $passwd = '' )
}

}
/**
* For pass through, this function writes the data in chunks.
*/
private function stream_chunk($ch, $data)
{
echo($data);
return strlen($data);
}
private function stream_header($ch, $data)
{
if (!preg_match('/^HTTP/i', $data))
{
header($data);
}
return strlen($data);
}


/**
* Query the server
Expand Down Expand Up @@ -193,7 +224,7 @@ function query( $request, $content = '', $doSpeedCheck = 0 )

$OK = TRUE;

if ($this->method == 'GET')
if ($this->method == 'GET' && isset($content) && $content != '')
$request .= '?'.$content;

$ch = curl_init($this->remote_host.':'.$this->remote_port.$request);
Expand All @@ -209,18 +240,22 @@ function query( $request, $content = '', $doSpeedCheck = 0 )
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT, "DirectAdmin/$this->version");
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 51200);
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 5);
if ($this->proxy)
{
curl_setopt($ch, CURLOPT_RETURNTRANSFER,false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLINFO_HEADER_OUT, false);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 8192); // 8192
curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, "stream_chunk"));
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, "stream_header"));
}

//if ($this->doFollowLocationHeader)
//{
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
// curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
//}
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 512);
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 120);

// instance connection
if ($this->bind_host)
Expand All @@ -237,7 +272,7 @@ function query( $request, $content = '', $doSpeedCheck = 0 )
// 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']}";
curl_setopt($ch, CURLOPT_COOKIE, "session={$_SERVER['SESSION_ID']}; key={$_SERVER['SESSION_KEY']}");
}

// if method is POST, add content length & type headers
Expand Down Expand Up @@ -378,6 +413,9 @@ function fetch_result()
*/
function fetch_header( $header = '' )
{
if ($this->proxy)
return $this->proxy_headers;

$array_headers = preg_split("/\r\n/",$this->result_header);

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