Florian Schaal
2016-03-22 5ca959fa688255a8de61f89fe2751eb4d24a6912
interface/web/sites/shell_user_edit.php
@@ -82,7 +82,11 @@
         $app->tpl->setVar("username", $app->tools_sites->removePrefix($this->dataRecord['username'], $this->dataRecord['username_prefix'], $shelluser_prefix));
      }
      $app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $shelluser_prefix, $global_config['shelluser_prefix']));
      if($this->dataRecord['username'] == "") {
         $app->tpl->setVar("username_prefix", $shelluser_prefix);
      } else {
         $app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $shelluser_prefix, $global_config['shelluser_prefix']));
      }
      if($this->id > 0) {
         //* we are editing a existing record
@@ -90,6 +94,12 @@
         $app->tpl->setVar("parent_domain_id_value", $this->dataRecord["parent_domain_id"]);
      } 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();
@@ -99,14 +109,12 @@
      global $app, $conf;
      // Get the record of the parent domain
      //$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".$app->functions->intval(@$this->dataRecord["parent_domain_id"]) . " AND ".$app->tform->getAuthSQL('r'));
      //if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
      if(isset($this->dataRecord["parent_domain_id"])) {
         $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".$app->functions->intval(@$this->dataRecord["parent_domain_id"]) . " AND ".$app->tform->getAuthSQL('r'));
         $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]);
         if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
      } else {
         $tmp = $app->tform->getDataRecord($this->id);
         $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".$app->functions->intval($tmp["parent_domain_id"]) . " AND ".$app->tform->getAuthSQL('r'));
         $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), $tmp["parent_domain_id"]);
         if(!$parent_domain) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
         unset($tmp);
      }
@@ -159,12 +167,16 @@
   function onAfterInsert() {
      global $app, $conf;
      $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval($this->dataRecord["parent_domain_id"]));
      $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]);
      $server_id = $app->functions->intval($web["server_id"]);
      $dir = $app->db->quote($web["document_root"]);
      $uid = $app->db->quote($web["system_user"]);
      $gid = $app->db->quote($web["system_group"]);
      if($this->dataRecord['chroot'] == 'jailkit'){
         $dir = $app->db->quote($web["document_root"]);
      } else {
         $dir = $app->db->quote($web["document_root"].'/home/'.$this->dataRecord['username']);
      }
      $uid = $web["system_user"];
      $gid = $web["system_group"];
      
      // Check system user and group
      if($app->functions->is_allowed_user($uid) == false || $app->functions->is_allowed_group($gid) == false) {
@@ -174,8 +186,8 @@
      // The FTP user shall be owned by the same group then the website
      $sys_groupid = $app->functions->intval($web['sys_groupid']);
      $sql = "UPDATE shell_user SET server_id = $server_id, dir = '$dir', puser = '$uid', pgroup = '$gid', sys_groupid = '$sys_groupid' WHERE shell_user_id = ".$this->id;
      $app->db->query($sql);
      $sql = "UPDATE shell_user SET server_id = ?, dir = ?, puser = ?, pgroup = ?, sys_groupid = ? WHERE shell_user_id = ?";
      $app->db->query($sql, $server_id, $dir, $uid, $gid, $sys_groupid, $this->id);
   }
@@ -216,7 +228,18 @@
   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);
      }
   }
}