2023-03-30 10:14:46 -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 VhostsAdd extends \Panel\Vhost {
function beforeRoute ( $f3 ) {
parent :: beforeRoute ( $f3 );
2023-06-19 11:53:16 -07:00
/* 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 ;
}
$f3 -> set ( 'deploy' , $deploy );
2023-03-30 10:14:46 -07:00
}
static function get ( $f3 ) {
echo \Template :: instance () -> render ( 'vhost/vhosts-add.html' );
}
function post ( $f3 ) {
extract ( $_POST );
$messages = array ();
/* validate domain */
2023-06-19 11:53:16 -07:00
$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 {
$cmd = " /usr/local/bin/vhost-deploy.sh -d $domain " ;
}
2023-03-30 10:14:46 -07:00
} else {
2023-06-19 11:53:16 -07:00
$f3 -> reroute ( " /Websites/Add " );
2023-03-30 10:14:46 -07:00
}
2023-06-19 11:53:16 -07:00
/* validate username & set related options */
$username = strtolower ( $_POST [ 'username' ]);
if ( $f3 -> get ( 'JAILUSER' ) == '1' ) {
$jailuser = 1 ;
2023-03-30 10:14:46 -07:00
} else {
2023-06-19 11:53:16 -07:00
$jailuser = 0 ;
2023-03-30 10:14:46 -07:00
}
2023-06-19 11:53:16 -07:00
if ( $username == '' ) {
$cmd = " $cmd -j $jailuser " ;
2023-03-30 10:14:46 -07:00
} else {
2023-06-19 11:53:16 -07:00
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 " );
2023-03-30 10:14:46 -07:00
}
}
2023-06-19 11:53:16 -07:00
if ( $f3 -> get ( 'WRITEUSERINFO' ) == '1' ) {
$writeuserinfo = 1 ;
2023-03-30 10:14:46 -07:00
} else {
2023-06-19 11:53:16 -07:00
$writeuserinfo = 0 ;
2023-03-30 10:14:46 -07:00
}
2023-06-19 11:53:16 -07:00
$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. " ;
}
2023-03-30 10:14:46 -07:00
$f3 -> set ( 'SESSION.messages' , $messages );
2023-06-19 11:53:16 -07:00
$f3 -> reroute ( " /Websites " );
2023-03-30 10:14:46 -07:00
} else {
2023-06-19 11:53:16 -07:00
$messages [] = " Error adding website. " ;
$f3 -> set ( 'SESSION.messages' , $messages );
$f3 -> reroute ( " /Websites/Add " );
2023-03-30 10:14:46 -07:00
}
2023-06-19 11:53:16 -07:00
2023-03-30 10:14:46 -07:00
}
}