135 lines
4.0 KiB
PHP
135 lines
4.0 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 VhostsAdd extends \Panel\Vhost {
|
|
|
|
function beforeRoute($f3) {
|
|
|
|
parent::beforeRoute($f3);
|
|
|
|
/* get system defaults for new websites */
|
|
$deploy = array();
|
|
$deploy['username'] = '';
|
|
if ($users_array = $f3->call('\Panel::vGet', array("vhost-user-get.sh -c", FALSE))) {
|
|
$deploy['users_array'] = $users_array;
|
|
} else {
|
|
$deploy['users_array'] = array();
|
|
}
|
|
|
|
if ($f3->get('WRITEUSERINFO') == '1') {
|
|
$deploy['writeuserinfo'] = 1;
|
|
} else {
|
|
$deploy['writeuserinfo'] = 0;
|
|
}
|
|
if ($f3->get('SHOWWRITEINFO') == '1') {
|
|
$deploy['showwriteinfo'] = 1;
|
|
} else {
|
|
$deploy['showwriteinfo'] = 0;
|
|
}
|
|
|
|
/* set php fpm version vars */
|
|
$f3->call('\Panel::setPHPVersions', $f3);
|
|
$deploy['fpm_version'] = $f3->get('PHP.fpm_version');
|
|
$deploy['fpm_versions_array'] = $f3->get('PHP.fpm_versions_array');
|
|
$deploy['fpm_version_count'] = $f3->get('PHP.fpm_version_count');
|
|
|
|
$f3->set('deploy', $deploy);
|
|
|
|
/* check if VHOSTLIMIT is set */
|
|
if (is_numeric($f3->get('VHOSTLIMIT'))) {
|
|
if ($f3->get('VHOSTLIMIT') > 0) {
|
|
$f3->set('vhostlimited', TRUE);
|
|
if ($vhosts_array = $f3->call('\Panel::vGet', array("vhost-get.sh -c", FALSE))) {
|
|
$f3->set('vhostscount', count($vhosts_array));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
static function get($f3) {
|
|
|
|
/* check VHOSTLIMIT */
|
|
if ($f3->get('vhostlimited') && ($f3->get('vhostscount') >= $f3->get('VHOSTLIMIT'))) {
|
|
echo \Template::instance()->render('vhost/vhosts-add-max.html');
|
|
} else {
|
|
echo \Template::instance()->render('vhost/vhosts-add.html');
|
|
}
|
|
|
|
}
|
|
|
|
function post($f3) {
|
|
|
|
extract($_POST);
|
|
|
|
$messages = array();
|
|
|
|
/* validate domain */
|
|
$domain = strtolower($_POST['domain']);
|
|
$domain = preg_replace('/^www\./', '', $domain);
|
|
if ($f3->call('\Panel::validateDomain', $domain)) {
|
|
if ($f3->call('\Panel::verifyVhostDomainExists', $domain)) {
|
|
$messages = $f3->get('SESSION.messages');
|
|
$messages[] = "$domain already exists on this server.";
|
|
$f3->set('SESSION.messages', $messages);
|
|
$f3->reroute("/Websites/Add");
|
|
} else {
|
|
$fpm_version = $_POST['fpm_version'];
|
|
$cmd = "/usr/local/bin/vhost-deploy.sh -d $domain -f $fpm_version";
|
|
}
|
|
} else {
|
|
$f3->reroute("/Websites/Add");
|
|
}
|
|
|
|
/* validate username & set related options */
|
|
$username = strtolower($_POST['username']);
|
|
if ($f3->get('JAILUSER') == '1') {
|
|
$jailuser = 1;
|
|
} else {
|
|
$jailuser = 0;
|
|
}
|
|
if ($username == '') {
|
|
$cmd = "$cmd -j $jailuser";
|
|
} else {
|
|
if ($f3->call('\Panel::vGet', array("vhost-user-get.sh -u $username -c", FALSE))) {
|
|
$cmd = "$cmd -u $username";
|
|
} else {
|
|
$messages = $f3->get('SESSION.messages');
|
|
$messages[] = "Error validating username $username.";
|
|
$f3->set('SESSION.messages', $messages);
|
|
$f3->reroute("/Websites/Add");
|
|
}
|
|
}
|
|
|
|
if ($f3->get('WRITEUSERINFO') == '1') {
|
|
$writeuserinfo = 1;
|
|
} else {
|
|
$writeuserinfo = 0;
|
|
}
|
|
$cmd = "$cmd -w $writeuserinfo";
|
|
exec("$cmd", $output, $result_code);
|
|
if ($result_code == 0) {
|
|
$messages[] = "Success: Website $domain added.";
|
|
if ($username == '' && $jailuser == 1) {
|
|
$messages[] = "Note: New user is being jailed. Setting up the jail environment takes about a minute to complete and is being run in the background now.";
|
|
}
|
|
$f3->set('SESSION.messages', $messages);
|
|
$f3->reroute("/Websites/$domain");
|
|
} else {
|
|
$messages[] = "Error adding website.";
|
|
$f3->set('SESSION.messages', $messages);
|
|
$f3->reroute("/Websites/Add");
|
|
}
|
|
|
|
}
|
|
|
|
}
|