* 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 */ $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))) { $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('/ /', '
', $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 -v -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 = $f3->get('PARAMS.vhost'); } elseif ($f3->exists('SESSION.domain')) { $vhost = $f3->get('SESSION.domain'); } if (isset($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'); } } }