D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
cpguard
/
app
/
scripts
/
Filename :
cyberpanel_domain_list.php
back
Copy
#!/opt/cpguard/cpg-php-fpm/bin/php <?php ## DO NOT CUSTOMISE THIS FILE ## This file may be updated during software update ## Please make a copy of the file for customising it ini_set("display_errors", false); $domain_list = shell_exec('/usr/bin/cyberpanel listWebsitesJson'); if (!empty($domain_list)) { $domain_list = json_decode(trim(stripslashes($domain_list), "\"\n")); } if (file_exists('/usr/local/lsws/conf/httpd.conf')) { $docroots = parse_litespeed_config('/usr/local/lsws/conf/httpd.conf'); } else if (file_exists('/usr/local/lsws/conf/httpd_config.conf')) { $docroots = parse_openlitespeed_conf('/usr/local/lsws/conf/httpd_config.conf'); } $result = []; if (is_array($domain_list)) { foreach ($domain_list as $key => $values) { $temp = '/home/' . $values->domain . '/public_html'; $result[] = [ 'domain' => $values->domain, 'user' => $values->admin, 'docroot' => $docroots[$values->domain] ?? (file_exists($temp) ? $temp : '') ]; } echo json_encode($result, JSON_PRETTY_PRINT); } else { echo '[]'; } function parse_openlitespeed_conf($conf_file) { $result = []; $conf_contents = file_get_contents($conf_file); if (preg_match_all('/virtualHost\s([^\s]+)\s.+\n\s*vhRoot\s+([^\n]+)$/mi', $conf_contents, $matches, PREG_SET_ORDER)) { foreach ($matches as $domain) { $result[$domain[1]] = str_replace('$VH_NAME', $domain[1], $domain[2]) . '/public_html'; } } return $result; } function parse_litespeed_config($conf_files, $server_root = NULL) { $result = []; $conf_files = glob($conf_files); //to be able to accept paths like /usr/local/lsws/conf/vhosts/*/vhost.conf foreach ($conf_files as $conf_file) { //Read and clean the configuration file $conf = file_get_contents($conf_file); //Gather all docroots in this conf file if (!empty($conf) && preg_match_all('/^\s*\<VirtualHost(.*?)\<\/VirtualHost\>/ms', $conf, $vhost_matches)) { foreach ($vhost_matches[1] as $vhost) { preg_match('/^\s*ServerName\s+(.+)$/m', $vhost, $domain); preg_match('/^\s*DocumentRoot\s+(.+)$/m', $vhost, $docroot); if (!empty($domain[1]) && !empty($docroot[1]) && file_exists($docroot[1])) { $result[$domain[1]] = $docroot[1]; } } } //Recursively loop included files foreach (get_litespeed_includes($conf, $conf_file, $server_root) as $included_conf) { $result = array_merge($result, parse_litespeed_config($included_conf, $server_root)); } } return $result; } function get_litespeed_includes(&$conf, &$conf_file, &$server_root) { $result = []; //Now parse all included conf files if (preg_match('/^\s*ServerRoot\s+\"(.+)\"$/m', $conf, $matches)) { //If ServerRoot is set then relative paths are based on this value $root = $server_root = $matches[1]; } else { $root = dirname($conf_file); } $ingored_confs = ['mods-enabled/', 'conf-enabled/']; preg_match_all('/^\s*(IncludeOptional|Include)\s+(.+)$/m', $conf, $include_paths); foreach ($include_paths[2] ?? [] as $path) { foreach ($ingored_confs as $needle) { if (strpos($path, $needle) === 0) { continue; } } if ($path[0] !== '/') { $path = $server_root === NULL ? "$root/$path" : "$server_root/$path"; } $result[] = $path; } return $result; }