#!/usr/local/bin/php -nc/usr/local/directadmin/plugins/phpversionlist/php.ini
PHP Error: function shell_exec is not available or disabled. Plugin can not be used until this function is available.';
return;
}
require_once(realpath(pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME) . '/../httpsocket.php'));
$supportedVersionsDataFile = pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME) . '/../supportedVersions';
// refresh the supportedVersions if the file not exists or the data is older than 24 hours
if (!file_exists($supportedVersionsDataFile) || (time() - filemtime($supportedVersionsDataFile) > 24 * 3600)) {
require_once(realpath(pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME) . '/supportedVersions.php'));
$data = fopen($supportedVersionsDataFile, "w+");
fwrite($data, serialize(getSupportedVersions()));
fclose($data);
}
$supportedVersions = unserialize(file_get_contents($supportedVersionsDataFile));
function colorize($version)
{
global $supportedVersions;
$colorized = "";
if (empty($version)) {
return $colorized;
}
$allBranches = [];
foreach ($supportedVersions as $supportedVersion) {
$allBranches[] = $supportedVersion['branch'];
if (preg_match('/^' . $supportedVersion['branch'] . '/', $version)) {
$color = ($supportedVersion['status'] === 'security') ? '#f93' : 'black';
$color = ($supportedVersion['status'] === 'stable') ? '#9c9' : $color;
$colorized = '' . $version . '';
break;
}
}
if (empty($colorized)) {
if ((float)$version < (float)min($allBranches)) {
$colorized = '' . $version . '';
} else {
$colorized = $version;
}
}
return $colorized;
}
function phpVersionCompare($a, $b)
{
$a = strip_tags($a);
$b = strip_tags($b);
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
// fetch PHP versions via an API call (no rights to access the custombuild options.conf file)
$sock = new HTTPSocket;
$sock->connect("ssl://" . $_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT']);
$sock->set_login($_SERVER['USER']);
$sock->query('/CMD_API_SYSTEM_INFO');
$systemInfo = $sock->fetch_parsed_body();
$systemInfo['php'] = colorize($systemInfo['php']);
$systemInfo['php2'] = colorize(isset($systemInfo['php2']) ? $systemInfo['php2'] : '');
$systemInfo['php3'] = colorize(isset($systemInfo['php3']) ? $systemInfo['php3'] : '');
$systemInfo['php4'] = colorize(isset($systemInfo['php4']) ? $systemInfo['php4'] : '');
//TODO: activate once you don't support PHP 5 anymore!
//$systemInfo['php2'] = colorize($systemInfo['php2'] ?? '');
//$systemInfo['php3'] = colorize($systemInfo['php3'] ?? '');
//$systemInfo['php4'] = colorize($systemInfo['php4'] ?? '');
/**
*
* value should be string that is passed!
*/
function translateValueToVersion($phpEnabled, $value)
{
global $systemInfo;
if ($phpEnabled != 'ON') {
return;
}
if ($value === '1') {
return $systemInfo['php'];
} elseif ($value === '2') {
return $systemInfo['php2'];
} elseif ($value === '3') {
return $systemInfo['php3'];
} elseif ($value === '4') {
return $systemInfo['php4'];
} elseif ($value === '0') {
return 'Off';
}
return;
}
// read all the directadmin users data config files. /dev/null added to have at least 2 files to search on as with only
// 1 match (domain) it won't show you the path.
// ignore files which ends with .hotlink.conf
$phpConfigData = shell_exec("grep ^php `find /usr/local/directadmin/data/users/*/domains -type f -regex '.*\.conf$' | grep -P '.*(?.*)\/domains\/(?P.*)\.conf\:(?P.*)\n/U", $phpConfigData, $matches);
$list = [];
$params = []; // array used to know later which phpx_select parameters there are
foreach ($matches[0] as $k => $v) {
$user = $matches['user'][$k];
$domain = $matches['domain'][$k];
$data = $matches['data'][$k];
list($param, $val) = explode("=", $data);
$params[] = $param;
$list[$user][$domain][$param] = $val;
}
// not all config files have a variable php1_select, this is causing an incorrect count in the summary table
// my feeling is that when you create an account and you do not touch the PHP version settings that the php1_select variable
// will not be in the file and DirectAdmin is for them taking the first PHP version version.
// also a second correction will be done if the php variable has the value OFF, unset all other variables from the data array.
foreach ($list as $user => $domains) {
foreach ($domains as $domain => $data) {
if ($data['php'] === 'ON' && !key_exists('php1_select', $data)) {
$data['php1_select'] = '1';
$list[$user][$domain] = $data;
} else {
if ($data['php'] === 'OFF') {
$list[$user][$domain] = ['php' => 'OFF'];
}
}
}
}
/*
// make the values unique
$params = array_unique($params);
var_dump($params);
*/
$keys = array_keys($systemInfo);
$versionKeys = preg_grep('/^php([2-4]?)$/', $keys);
// build an array with key the php install id (1, .., 4) and as value the php version
$phpVersions = [];
foreach ($versionKeys as $keyValue) {
$num = substr($keyValue, -1, 1);
$num = !is_numeric($num) ? 1 : $num;
$phpVersions[$num] = $systemInfo[$keyValue];
}
uasort($phpVersions, 'phpVersionCompare');
// create a multidimensional array with first key the first / second php selector and as second key the phpversion (key)
$stats = [];
for ($i = 1; $i <= 2; $i++) {
for ($j = 1; $j <= 4; $j++) {
$stats[$i][$j] = 0;
}
}
// loop to build up the stats
foreach ($list as $user => $domains) {
foreach ($domains as $domain => $settings) {
// only want to take phpx_select and use the value
foreach ($settings as $k => $v) {
if (!preg_match('/php([1-2])_select/', $k, $matches) || intval($v) == 0) {
continue;
}
$stats[$matches[1]][$v]++;
}
}
}
?>
PHP version summary
First PHP
Second PHP
$version) {
if (empty($version)) {
continue;
}
echo "