I have a function that I use to get the errorlog from the DirectAdmin errorlog. This worked fine for several years. Now my application is moved to another server with a newer version of DirectAdmin and my script doesn't return the any result, although I see the errorlog isn't empty. Should there be changed something or is there a better way to get the errorlog?
<?php
function getErrorlog($sServer, $sPort, $sUsername, $sPassword, $sDomain, $sSubdomain) {
// get the errorlog from direct admin
$url = 'https://' . $sServer . ':' . $sPort;
$ckfile = tempnam ('/tmp', 'CURLCOOKIE');
$fields = array(
'referer' => urlencode('/'),
'username' => urlencode($sUsername),
'password' => urlencode($sPassword)
);
$fields_string = '';
foreach($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url . '/CMD_LOGIN');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Referer: ' . $url . '/CMD_LOGIN'));
$result = curl_exec($ch);
if($result === false) {
die('CURL ERROR: ' . curl_error($ch));
}
else {
curl_setopt($ch, CURLOPT_URL, $url . '/CMD_SHOW_LOG?domain=' . $sDomain . '&type=error&subdomain=' . $sSubdomain);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
if($result === false) {
die('CURL ERROR: ' . curl_error($ch));
}
else {
$aLines = explode(PHP_EOL, $result);
$sResult = '';
foreach ($aLines as $line) {
if ($line != '') {
$iPosCertificate = strpos($line, 'server certificate does NOT include an ID which matches the server name');
$iPosEnv = strpos($line, '/.env');
$iPosStatus = strpos($line, '/server-status');
if ($iPosCertificate == 0 && $iPosEnv == 0 && $iPosStatus == 0) {
$sResult .= $line . PHP_EOL . PHP_EOL;
}
}
}
return $sResult;
}
}
}
?>
<?php
function getErrorlog($sServer, $sPort, $sUsername, $sPassword, $sDomain, $sSubdomain) {
// get the errorlog from direct admin
$url = 'https://' . $sServer . ':' . $sPort;
$ckfile = tempnam ('/tmp', 'CURLCOOKIE');
$fields = array(
'referer' => urlencode('/'),
'username' => urlencode($sUsername),
'password' => urlencode($sPassword)
);
$fields_string = '';
foreach($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url . '/CMD_LOGIN');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Referer: ' . $url . '/CMD_LOGIN'));
$result = curl_exec($ch);
if($result === false) {
die('CURL ERROR: ' . curl_error($ch));
}
else {
curl_setopt($ch, CURLOPT_URL, $url . '/CMD_SHOW_LOG?domain=' . $sDomain . '&type=error&subdomain=' . $sSubdomain);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
if($result === false) {
die('CURL ERROR: ' . curl_error($ch));
}
else {
$aLines = explode(PHP_EOL, $result);
$sResult = '';
foreach ($aLines as $line) {
if ($line != '') {
$iPosCertificate = strpos($line, 'server certificate does NOT include an ID which matches the server name');
$iPosEnv = strpos($line, '/.env');
$iPosStatus = strpos($line, '/server-status');
if ($iPosCertificate == 0 && $iPosEnv == 0 && $iPosStatus == 0) {
$sResult .= $line . PHP_EOL . PHP_EOL;
}
}
}
return $sResult;
}
}
}
?>