107 lines
3.5 KiB
PHP
107 lines
3.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* vpanel-stack
|
|
* https://git.stack-source.com/msb/vpanel-stack
|
|
* Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
|
* GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
*/
|
|
|
|
namespace Panel\Vhost;
|
|
|
|
class Vhosts extends \Panel\Vhost {
|
|
|
|
/* use this to make query */
|
|
function beforeRoute($f3) {
|
|
|
|
parent::beforeRoute($f3);
|
|
|
|
if ($f3->exists('PARAMS.vhost')) {
|
|
$vhost = $f3->get('PARAMS.vhost');
|
|
if ($vhost_array = $f3->call('\Panel::vGet', array("vhost-get.sh -d $vhost -c", FALSE))) {
|
|
$f3->set('vhost_array', $vhost_array[0]);
|
|
/* get cert info */
|
|
if ($f3->call('\Panel::verifyCertificateExists', $vhost)) {
|
|
if ($cert_array = $f3->call('\Panel::vGet', array("letsencrypt-get.sh -d $vhost -c", FALSE))) {
|
|
$cert_array = $cert_array[0];
|
|
/* remove time from expiration date */
|
|
$end = $cert_array['end'];
|
|
$end_array = explode(' ', $end);
|
|
unset($end_array[2]);
|
|
$end = implode(' ', $end_array);
|
|
$cert_array['end'] = $end;
|
|
/* add line breaks */
|
|
$common = $cert_array['common'];
|
|
$alternative = $cert_array['alternative'];
|
|
$alternative = preg_replace('/ /', '<br>', $alternative);
|
|
$cert_array['alternative'] = $alternative;
|
|
$f3->set('cert_array', $cert_array);
|
|
}
|
|
} else {
|
|
/* no cert, get dns info */
|
|
$dnsinfo = array();
|
|
$dnsinfo['server_addr'] = $_SERVER['SERVER_ADDR'];
|
|
# A record
|
|
$dnsinfo['a']['color'] = "red";
|
|
if ($certdomain_dns = dns_get_record("$vhost", DNS_A)) {
|
|
if ($certdomain_dns[0]['ip'] == $dnsinfo['server_addr']) {
|
|
$dnsinfo['a']['status'] = "Verified";
|
|
$dnsinfo['a']['color'] = "black";
|
|
} else {
|
|
$dnsinfo['a']['status'] = "Update";
|
|
}
|
|
} else {
|
|
$dnsinfo['a']['status'] = "Create";
|
|
}
|
|
$f3->set('dnsinfo', $dnsinfo);
|
|
}
|
|
/* get user info */
|
|
$username = $vhost_array[0]['username'];
|
|
if ($users_array = $f3->call('\Panel::vGet', array("vhost-user-get.sh -u $username -c", FALSE))) {
|
|
if ($users_array[0]['passwd'] == "") {
|
|
$users_array[0]['passwd'] = '(unavailable)';
|
|
}
|
|
$f3->set('users_array', $users_array[0]);
|
|
}
|
|
/* get mysql db info */
|
|
if ($mysqlinfo_array = $f3->call('\Panel::vGet', array("vhost-mysql-db-get.sh -d $vhost -c", FALSE))) {
|
|
$f3->set('mysqlinfo_array', $mysqlinfo_array[0]);
|
|
} else {
|
|
$mysqlinfo_array = array('(unknown)', '(unknown)', '(unknown)', '(unknown)');
|
|
$f3->set('mysqlinfo_array', $mysqlinfo_array);
|
|
}
|
|
}
|
|
} else {
|
|
if ($vhosts_array = $f3->call('\Panel::vGet', array("vhost-get.sh -c", FALSE))) {
|
|
$f3->set('vhosts_array', $vhosts_array);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
static function get($f3) {
|
|
|
|
if ($f3->exists('PARAMS.vhost')) {
|
|
|
|
// $vhost_array = $f3->get('vhost_array');
|
|
|
|
/* convert data for frontend display */
|
|
// nothing to convert
|
|
|
|
// $f3->set('vhost_array', $vhost_array);
|
|
|
|
$vhost = $f3->get('PARAMS.vhost');
|
|
$f3->set('page_header', "Details for $vhost");
|
|
echo \Template::instance()->render('vhost/vhosts-vhost.html');
|
|
|
|
} else {
|
|
|
|
$f3->set('page_header', "Websites");
|
|
echo \Template::instance()->render('vhost/vhosts.html');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|