vpanel-stack/panel/classes/Panel/Vhost/Vhosts.php

120 lines
4.1 KiB
PHP
Raw Normal View History

2022-07-01 15:24:26 -07:00
<?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')) {
/* got here via vpanel link */
2022-07-01 15:24:26 -07:00
$vhost = $f3->get('PARAMS.vhost');
$vhost_get_cmd = "vhost-get.sh -d $vhost -c";
} elseif ($f3->get('NAV.mapping') == 'vhost') {
/* got here via vhost page */
if ($f3->exists('SESSION.domain') && $f3->exists('SESSION.vhostusername')) {
/* SESSION.domain should be set for all vhost logins */
$vhost = $f3->get('SESSION.domain');
$vhostusername = $f3->get('SESSION.vhostusername');
$vhost_get_cmd = "vhost-get.sh -d $vhost -u $vhostusername -c";
} else {
/* should never get here, throw a 500 error to prevent further processing */
$f3->error(500);
}
}
if (isset($vhost_get_cmd)) {
if ($vhost_array = $f3->call('\Panel::vGet', array("$vhost_get_cmd", FALSE))) {
2022-07-01 15:24:26 -07:00
$f3->set('vhost_array', $vhost_array[0]);
2023-06-19 11:53:16 -07:00
/* 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);
}
2023-07-05 11:02:13 -07:00
} 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)) {
2023-07-05 11:02:13 -07:00
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);
2023-06-19 11:53:16 -07:00
}
/* get user info */
$username = $vhost_array[0]['username'];
if ($users_array = $f3->call('\Panel::vGet', array("vhost-user-get.sh -u $username -v -c", FALSE))) {
2023-06-19 11:53:16 -07:00
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);
}
2022-07-01 15:24:26 -07:00
}
} 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 = $f3->get('PARAMS.vhost');
} elseif ($f3->exists('SESSION.domain')) {
$vhost = $f3->get('SESSION.domain');
}
2022-07-01 15:24:26 -07:00
if (isset($vhost)) {
2022-07-01 15:24:26 -07:00
2023-06-19 11:53:16 -07:00
$f3->set('page_header', "Details for $vhost");
2022-07-01 15:24:26 -07:00
echo \Template::instance()->render('vhost/vhosts-vhost.html');
} else {
$f3->set('page_header', "Websites");
echo \Template::instance()->render('vhost/vhosts.html');
}
}
}