Till Brehm
2016-04-12 8216c5ee690f97b9f8f8ac967dac5c5f3745a00f
Fixed: Issue #3820 v3.1 Shell user wrong default Base Dir in GUI results to corrupt shell user home directory creation.
2 files modified
57 ■■■■■ changed files
interface/web/sites/shell_user_edit.php 23 ●●●●● patch | view | raw | blame | history
server/plugins-available/shelluser_base_plugin.inc.php 34 ●●●●● patch | view | raw | blame | history
interface/web/sites/shell_user_edit.php
@@ -95,12 +95,6 @@
        } else {
            $app->tpl->setVar("edit_disabled", 0);
        }
        if($this->dataRecord['chroot'] == 'jailkit'){
            $app->tpl->setVar("is_jailkit", true);
        } else {
            $app->tpl->setVar("is_jailkit", false);
        }
        parent::onShowEnd();
    }
@@ -170,11 +164,7 @@
        $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]);
        $server_id = $app->functions->intval($web["server_id"]);
        if($this->dataRecord['chroot'] == 'jailkit'){
            $dir = $app->db->quote($web["document_root"]);
        } else {
            $dir = $app->db->quote($web["document_root"].'/home/'.$this->dataRecord['username']);
        }
        $dir = $web["document_root"];
        $uid = $web["system_user"];
        $gid = $web["system_group"];
        
@@ -228,18 +218,7 @@
    function onAfterUpdate() {
        global $app, $conf;
        if(isset($this->dataRecord['chroot'])){
            $shell_user = $app->db->queryOneRecord("SELECT * FROM shell_user WHERE shell_user_id = ".$this->id);
            $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval($this->dataRecord["parent_domain_id"]));
            $dir = $shell_user['dir'];
            if($this->dataRecord['chroot'] == 'jailkit'){
                $dir = $app->db->quote($web["document_root"]);
            } else {
                if($this->oldDataRecord['chroot'] == 'jailkit') $dir = $app->db->quote($web["document_root"].'/home/'.$this->dataRecord['username']);
            }
            if($dir != $shell_user['dir']) $app->db->query("UPDATE shell_user SET dir = '$dir' WHERE shell_user_id = ".$this->id);
        }
    }
}
server/plugins-available/shelluser_base_plugin.inc.php
@@ -113,16 +113,20 @@
                    $homedir = $data['new']['dir'].'/home/'.$data['new']['username'];
                }
                
                // Create home base directory if it does not exist
                if(!is_dir($data['new']['dir'].'/home')){
                    $app->file->mkdirs(escapeshellcmd($data['new']['dir'].'/home'), '0750');
                    $app->system->chown(escapeshellcmd($data['new']['dir'].'/home'),escapeshellcmd($data['new']['puser']));
                    $app->system->chgrp(escapeshellcmd($data['new']['dir'].'/home'),escapeshellcmd($data['new']['pgroup']));
                    $app->file->mkdirs(escapeshellcmd($data['new']['dir'].'/home'), '0755');
                }
                // Change ownership of home base dir to root user
                $app->system->chown(escapeshellcmd($data['new']['dir'].'/home'),'root');
                $app->system->chgrp(escapeshellcmd($data['new']['dir'].'/home'),'root');
                $app->system->chmod(escapeshellcmd($data['new']['dir'].'/home'),0755);
                
                if(!is_dir($homedir)){
                    $app->file->mkdirs(escapeshellcmd($homedir), '0750');
                    $app->system->chown(escapeshellcmd($homedir),escapeshellcmd($data['new']['puser']));
                    $app->system->chgrp(escapeshellcmd($homedir),escapeshellcmd($data['new']['pgroup']));
                    $app->system->chown(escapeshellcmd($homedir),escapeshellcmd($data['new']['puser']),false);
                    $app->system->chgrp(escapeshellcmd($homedir),escapeshellcmd($data['new']['pgroup']),false);
                }
                $command = 'useradd';
                $command .= ' -d '.escapeshellcmd($homedir);
@@ -137,8 +141,8 @@
                $app->log("Executed command: ".$command, LOGLEVEL_DEBUG);
                $app->log("Added shelluser: ".$data['new']['username'], LOGLEVEL_DEBUG);
                
                $app->system->chown(escapeshellcmd($data['new']['dir']),escapeshellcmd($data['new']['username']));
                $app->system->chgrp(escapeshellcmd($data['new']['dir']),escapeshellcmd($data['new']['pgroup']));
                $app->system->chown(escapeshellcmd($data['new']['dir']),escapeshellcmd($data['new']['username']),false);
                $app->system->chgrp(escapeshellcmd($data['new']['dir']),escapeshellcmd($data['new']['pgroup']),false);
                
                // call the ssh-rsa update function
@@ -149,7 +153,7 @@
                //* Create .bash_history file
                $app->system->touch(escapeshellcmd($homedir).'/.bash_history');
                $app->system->chmod(escapeshellcmd($homedir).'/.bash_history', 0755);
                $app->system->chmod(escapeshellcmd($homedir).'/.bash_history', 0750);
                $app->system->chown(escapeshellcmd($homedir).'/.bash_history', $data['new']['username']);
                $app->system->chgrp(escapeshellcmd($homedir).'/.bash_history', $data['new']['pgroup']);
@@ -249,17 +253,17 @@
                            $app->system->chown(escapeshellcmd($data['new']['dir'].'/home'),escapeshellcmd($data['new']['puser']));
                            $app->system->chgrp(escapeshellcmd($data['new']['dir'].'/home'),escapeshellcmd($data['new']['pgroup']));
                        }
                        $app->file->mkdirs(escapeshellcmd($homedir), '0750');
                        $app->system->chown(escapeshellcmd($homedir),escapeshellcmd($data['new']['puser']));
                        $app->system->chgrp(escapeshellcmd($homedir),escapeshellcmd($data['new']['pgroup']));
                        $app->file->mkdirs(escapeshellcmd($homedir), '0755');
                        $app->system->chown(escapeshellcmd($homedir),'root');
                        $app->system->chgrp(escapeshellcmd($homedir),'root');
                        $app->system->web_folder_protection($web['document_root'], true);
                    } else {
                        if(!is_dir($homedir)){
                            $app->system->web_folder_protection($web['document_root'], false);
                            if(!is_dir($data['new']['dir'].'/home')){
                                $app->file->mkdirs(escapeshellcmd($data['new']['dir'].'/home'), '0750');
                                $app->system->chown(escapeshellcmd($data['new']['dir'].'/home'),escapeshellcmd($data['new']['puser']));
                                $app->system->chgrp(escapeshellcmd($data['new']['dir'].'/home'),escapeshellcmd($data['new']['pgroup']));
                                $app->file->mkdirs(escapeshellcmd($data['new']['dir'].'/home'), '0755');
                                $app->system->chown(escapeshellcmd($data['new']['dir'].'/home'),'root');
                                $app->system->chgrp(escapeshellcmd($data['new']['dir'].'/home'),'root');
                            }
                            $app->file->mkdirs(escapeshellcmd($homedir), '0750');
                            $app->system->chown(escapeshellcmd($homedir),escapeshellcmd($data['new']['puser']));
@@ -279,7 +283,7 @@
                    //* Create .bash_history file
                    if(!is_file($data['new']['dir']).'/.bash_history') {
                        $app->system->touch(escapeshellcmd($homedir).'/.bash_history');
                        $app->system->chmod(escapeshellcmd($homedir).'/.bash_history', 0755);
                        $app->system->chmod(escapeshellcmd($homedir).'/.bash_history', 0750);
                        $app->system->chown(escapeshellcmd($homedir).'/.bash_history', escapeshellcmd($data['new']['username']));
                        $app->system->chgrp(escapeshellcmd($homedir).'/.bash_history', escapeshellcmd($data['new']['pgroup']));
                    }