* GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) */ namespace Panel\Vhost; class UsersAdd extends \Panel\Vhost { function beforeRoute($f3) { parent::beforeRoute($f3); /* get system defaults for new users */ $user = array(); $user['username'] = ''; $user['password'] = ''; $user['password_confirm'] = ''; if ($f3->get('JAILUSER') == '1') { $user['jailuser'] = 1; } else { $user['jailuser'] = 0; } $user['fpmmax'] = $f3->get('FPMMAX'); if ($f3->get('WRITEUSERINFO') == '1') { $user['writeuserinfo'] = 1; } else { $user['writeuserinfo'] = 0; } if ($f3->get('SHOWWRITEINFO') == '1') { $user['showwriteinfo'] = 1; } else { $user['showwriteinfo'] = 0; } $f3->set('user', $user); } static function get($f3) { echo \Template::instance()->render('vhost/users-add.html'); } function post($f3) { extract($_POST); /* force username to be all lower case */ $username = strtolower($username); $f3->call('\Panel::validateUsername', $username); /* only validate password if one was submitted, otherwise script will generate random password */ if ($password != '' || $password_confirm != '') { $f3->call('\Panel::validatePassword', array($password, $password_confirm)); } /* check for validation errors */ if ($f3->exists('SESSION.messages')) { $messages = $f3->get('SESSION.messages'); $messages[] = "Please make changes and re-submit the form to try again."; $f3->set('SESSION.messages', $messages); $f3->set('user', $_POST); $f3->call('\Panel\Vhost\UsersAdd::get', $f3); } else { $domain = $f3->get('PARAMS.domain'); if ($password != '') { $password = "-p " . escapeshellarg($password); } exec("/usr/local/bin/vhost-user-add.sh -u $username -x $fpmmax $password -w $writeuserinfo", $output, $result_code); if ($result_code == 0) { $messages[] = "Success: User $username added."; if ($jailuser == 1) { exec("/usr/local/bin/vhost-user-jail.sh -u $username >/dev/null 2>/dev/null &", $output, $result_code); $messages[] = "Note: User is being jailed. Setting up the jail environment takes about a minute to complete and is run in the background now."; } $f3->set('SESSION.messages', $messages); $f3->reroute("/Users"); } else { $messages[] = "Error adding user."; $f3->set('SESSION.messages', $messages); $f3->call('\Panel\Vhost\UsersAdd::get', $f3); } } } }