From afee192d2a77afa1c11d25156d0a44df94e19aed Mon Sep 17 00:00:00 2001
From: A. Täffner <darkalex@firesplash.de>
Date: Sat, 23 Jan 2016 07:30:37 -0500
Subject: [PATCH] fixed the cronjob and noticed a bug in ISPC but not able to report as FlySpray is offline

---
 interface/web/sites/shell_user_edit.php |   53 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/interface/web/sites/shell_user_edit.php b/interface/web/sites/shell_user_edit.php
index 5a54b33..2b606c2 100644
--- a/interface/web/sites/shell_user_edit.php
+++ b/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);
 		}
@@ -135,6 +143,8 @@
 			}
 		}
 		unset($blacklist);
+		
+		if($app->functions->is_allowed_user(trim(strtolower($this->dataRecord['username']))) == false) $app->tform->errorMessage .= $app->tform->lng('username_not_allowed_txt');
 
 		/*
 		 * If the names should be restricted -> do it!
@@ -157,19 +167,27 @@
 	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) {
+			$app->error($app->tform->lng('invalid_system_user_or_group_txt'));
+		}
 
 		// 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);
-		die($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);
 
 	}
 
@@ -210,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);
+		}
 	}
 
 }

--
Gitblit v1.9.1