* GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) */ namespace Panel\Vhost; class VhostsEdit extends \Panel\Vhost { function beforeRoute($f3) { parent::beforeRoute($f3); $vhost = $f3->get('PARAMS.vhost'); if ($f3->get('NAV.mapping') == 'vpanel') { if ($vhost_array = $f3->call('\Panel::vGet', array("vhost-get.sh -d $vhost -c", FALSE))) { $vhost_array = $vhost_array[0]; } else { $messages[] = "Error getting info for $vhost."; $f3->set('SESSION.messages', $messages); $f3->reroute("/"); } } elseif ($f3->get('NAV.mapping') == 'vhost') { /* exta auth checks if logged in via vhost mapping */ if ($f3->exists('SESSION.vhostusername')) { /* vhostusername indicates vhost user login */ $username = $f3->get('SESSION.vhostusername'); if ($vhost_array = $f3->call('\Panel::vGet', array("vhost-get.sh -u $username -d $vhost -c", FALSE))) { $vhost_array = $vhost_array[0]; } else { $messages[] = "Unauthorized request."; $f3->set('SESSION.messages', $messages); $f3->reroute("/"); } } else { /* SESSION.vhostusername not set. Something went wrong, redirect back home */ $messages[] = "Error verifying system user for domain $domain, can not edit."; $f3->set('SESSION.messages', $messages); $f3->reroute("/"); } } else { $messages[] = "Invalid request."; $f3->set('SESSION.messages', $messages); $f3->reroute("/"); } /* set php fpm version vars */ $f3->call('\Panel::setPHPVersions', $f3); $vhost_array['fpm_version'] = $f3->get('PHP.fpm_version'); $vhost_array['fpm_versions_array'] = $f3->get('PHP.fpm_versions_array'); $vhost_array['fpm_version_count'] = $f3->get('PHP.fpm_version_count'); $f3->set('vhost_array', $vhost_array); } static function get($f3) { if ($f3->exists('PARAMS.vhost')) { $vhost = $f3->get('PARAMS.vhost'); $f3->set('page_header', "Edit Website: $vhost"); echo \Template::instance()->render('vhost/vhosts-edit.html'); } else { /* vhost should always be set, if not reroute to home */ $f3->reroute("/"); } } function post($f3) { $vhost = $f3->get('PARAMS.vhost'); $fpm_version = $_POST['fpm_version']; $config = $f3->get('vhost_array.config'); exec("/usr/local/bin/vhost-enable.sh -d $vhost -m $config -f $fpm_version", $output, $result_code); if ($result_code == 0) { $messages[] = "Success: PHP set to version $fpm_version for $vhost."; $f3->set('SESSION.messages', $messages); if ($f3->get('NAV.mapping') == 'vhost') { $f3->reroute("/"); } else { $f3->reroute("/Websites/$vhost"); } } else { $f3->reroute("/Websites/$vhost"); } } }