I am having trouble with a custom class I am writing to interface with WHM to create/delete accounts (among other things). I am experiencing a very awkward problem, thought. First, here is the code from the class:
Next, here is my test file. It has two calls, one to create and one to delete. I just comment out (or terminate with die) the one I don't want when testing. However, I usually create an account via this class and then call for it to delete.PHP Code:function CreateAccount($domain, $email, $pass, $package, $user) {
$package = $this->User . '_' . $package;
$request = '/xml-api/createacct?username=' . $user . '&plan=' . $package
. '&password=' . $pass . '&contactemail=' . $email . '&domain=' . $domain;
$result = $this->Request($request);
if (!$result)
trigger_error('An error occured in the create account request. WHM returned a blank result.', E_USER_ERROR);
if (preg_match('#<status>1</status>#', $result) < 1) {
preg_match('#<statusmsg>(.*?)</statusmsg>#s', $result, $matches);
trigger_error( 'An error occured while creating this cPanel account (domain : user):<br /><br />' . $domain
. ' <strong>:</strong> ' . $user . '<br /><br />' . $matches[1], E_USER_ERROR);
}
return true;
}
function DeleteAccount($user) {
$request = '/xml-api/removeacct?user=' . $user;
$result = $this->Request($request);
if (!$result)
trigger_error('An error occured in the delete account request. WHM returned a blank result.', E_USER_ERROR);
if (preg_match('#<status>1</status>#', $result) < 1) {
preg_match('#<statusmsg>(.*?)</statusmsg>#s', $result, $matches);
trigger_error( 'An error occured while deleting this cPanel user: ' . $user
. '<br /><br />' . $matches[1], E_USER_ERROR);
}
return true;
}
function Request($RequestedURL) {
$response = file_get_contents($this->URL . $RequestedURL);
if (empty($response))
return false;
else
return $response;
}
The problem arises when I call the delete function. The account will exist in WHM (with a username of 'w00t') but when I call the delete function, it takes a little bit to process the request and then it will give me the white screen of death almost like it timed out. But when I view source on that page, it shows the error message (just a var_dump() of the WHM result) in the source but not in the page itself even though I sent a text/plain content-type header.PHP Code:require('/home/minihost/public_html/include/class/cPanelInterface.class.inc.php');
$cPanel = new cPanelInterface('minihost');
header('Content-type: text/plain');
error_reporting(E_ALL);
var_dump($cPanel->DeleteAccount('w00t'));
die;
var_dump($cPanel->CreateAccount('w00t.minihost.org', 'test@minihost.org', 'test', 'MH-S1', 'w00t'));
The message is just WHM's message that the username 'w00t' does not exists. However, WHM did actually delete the account. So basically, it did what it was supposed to do all the way up until it was supposed to return a success message. Instead, it returns a failure, which causes my class to return a failure. It is almost like 1 of 2 things: 1) WHM does the request twice and just says nothing about the first request causing the second to be valid because there would be no 'w00t' user or 2) WHM is doing the delete but is simply returning the wrong message. But when I call the delete URL from my browser (since PHP is only doing HTTP requests anyway), WHM outputs the correct message in saying the account is deleted.
It's important to keep note also that the white screen of death thing only happens when the account actually exists and it tries to legitimately delete the account (and does). If the account is not really there, it doesnt have a problem sending a legit failure message (as designed).
Now, since the white screen of death thing was fishy (at least the fact that the source view had the error in it and the browser window did not), I thought maybe the browser was receiving awkward headers that was causing it to crap out, so I used a header viewer application. You can view the results of the delete call headers here:
http://minihost.org/test.php
GET /test.php HTTP/1.1
Host: minihost.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
HTTP/1.x 200 OK
----------------------------------------------------------
Now when I call the test.php file after the delete has already concluded (but still sent white screen of death), the header output is:
http://minihost.org/test.php
GET /test.php HTTP/1.1
Host: minihost.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
HTTP/1.x 200 OK
Date: Sun, 26 Aug 2007 21:20:07 GMT
Server: Apache/1.3.37 (Unix) PHP/5.2.3 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a
X-Powered-By: PHP/5.2.3
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/plain
X-Antivirus: avast! 4
X-Antivirus-Status: Clean
----------------------------------------------------------
Now, I am no expert at web technologies period. So if the header stuff means nothing, sorry. I just found it odd how different they were, especially considering only in the last delete call (the one where the account didnt actually exist) did the headers even say Content-type: text/plain. I specifically set that in my test.php file with a header() function for it. I am sorry if this is really confusing, now you know how I feel. It is so awkward of a problem. I am completely dumbfounded. Any assistance would be great. I know it would be better to work with a real example but that isnt very practical for me to do with a whole board looking at it. If you need further information, please let me know.



LinkBack URL
About LinkBacks
Reply With Quote





