use Fts.add when adding new Customers to reduce duplicate code
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -543,37 +543,14 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
|||||||
Database::pexecute($ins_stmt, $ins_data, true, true);
|
Database::pexecute($ins_stmt, $ins_data, true, true);
|
||||||
|
|
||||||
\Froxlor\System\Cronjob::inserttask('1');
|
\Froxlor\System\Cronjob::inserttask('1');
|
||||||
$cryptPassword = \Froxlor\System\Crypt::makeCryptPassword($password);
|
|
||||||
// add FTP-User
|
|
||||||
// @fixme use Ftp-ApiCommand later
|
|
||||||
$ins_stmt = Database::prepare("
|
|
||||||
INSERT INTO `" . TABLE_FTP_USERS . "` SET `customerid` = :customerid, `username` = :username, `description` = :desc,
|
|
||||||
`password` = :passwd, `homedir` = :homedir, `login_enabled` = 'y', `uid` = :guid, `gid` = :guid
|
|
||||||
");
|
|
||||||
$ins_data = array(
|
|
||||||
'customerid' => $customerid,
|
|
||||||
'username' => $loginname,
|
|
||||||
'passwd' => $cryptPassword,
|
|
||||||
'homedir' => $documentroot,
|
|
||||||
'guid' => $guid,
|
|
||||||
'desc' => "Default"
|
|
||||||
);
|
|
||||||
Database::pexecute($ins_stmt, $ins_data, true, true);
|
|
||||||
// add FTP-Group
|
|
||||||
// @fixme use Ftp-ApiCommand later
|
|
||||||
$ins_stmt = Database::prepare("
|
|
||||||
INSERT INTO `" . TABLE_FTP_GROUPS . "` SET `customerid` = :customerid, `groupname` = :groupname, `gid` = :guid, `members` = :members
|
|
||||||
");
|
|
||||||
$ins_data = array(
|
|
||||||
'customerid' => $customerid,
|
|
||||||
'groupname' => $loginname,
|
|
||||||
'guid' => $guid,
|
|
||||||
'members' => $loginname . ',' . Settings::Get('system.httpuser')
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// add default FTP-User
|
||||||
// also, add froxlor-local user to ftp-group (if exists!) to
|
// also, add froxlor-local user to ftp-group (if exists!) to
|
||||||
// allow access to customer-directories from within the panel, which
|
// allow access to customer-directories from within the panel, which
|
||||||
// is necessary when pathedit = Dropdown
|
// is necessary when pathedit = Dropdown
|
||||||
|
$local_users = array(
|
||||||
|
Settings::Get('system.httpuser')
|
||||||
|
);
|
||||||
if ((int) Settings::Get('system.mod_fcgid_ownvhost') == 1 || (int) Settings::Get('phpfpm.enabled_ownvhost') == 1) {
|
if ((int) Settings::Get('system.mod_fcgid_ownvhost') == 1 || (int) Settings::Get('phpfpm.enabled_ownvhost') == 1) {
|
||||||
if ((int) Settings::Get('system.mod_fcgid') == 1) {
|
if ((int) Settings::Get('system.mod_fcgid') == 1) {
|
||||||
$local_user = Settings::Get('system.mod_fcgid_httpuser');
|
$local_user = Settings::Get('system.mod_fcgid_httpuser');
|
||||||
@@ -582,22 +559,20 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
|||||||
}
|
}
|
||||||
// check froxlor-local user membership in ftp-group
|
// check froxlor-local user membership in ftp-group
|
||||||
// without this check addition may duplicate user in list if httpuser == local_user
|
// without this check addition may duplicate user in list if httpuser == local_user
|
||||||
if (strpos($ins_data['members'], $local_user) == false) {
|
if (in_array($local_user, $local_users) == false) {
|
||||||
$ins_data['members'] .= ',' . $local_user;
|
$local_users[] = $local_user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Database::pexecute($ins_stmt, $ins_data, true, true);
|
$this->apiCall('Ftps.add', array(
|
||||||
|
'customerid' => $customerid,
|
||||||
// FTP-Quotatallies
|
'path' => $documentroot,
|
||||||
// @fixme use Ftp-ApiCommand later
|
'ftp_password' => $password,
|
||||||
$ins_stmt = Database::prepare("
|
'ftp_description' => "Default",
|
||||||
INSERT INTO `" . TABLE_FTP_QUOTATALLIES . "` SET `name` = :name, `quota_type` = 'user', `bytes_in_used` = '0',
|
'sendinfomail' => 0,
|
||||||
`bytes_out_used` = '0', `bytes_xfer_used` = '0', `files_in_used` = '0', `files_out_used` = '0', `files_xfer_used` = '0'
|
'ftp_username' => $loginname,
|
||||||
");
|
'additional_members' => $local_users,
|
||||||
Database::pexecute($ins_stmt, array(
|
'is_defaultuser' => 1
|
||||||
'name' => $loginname
|
));
|
||||||
), true, true);
|
|
||||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] automatically added ftp-account for user '" . $loginname . "'");
|
|
||||||
|
|
||||||
$_stdsubdomain = '';
|
$_stdsubdomain = '';
|
||||||
if ($createstdsubdomain == '1') {
|
if ($createstdsubdomain == '1') {
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
|||||||
* optional if customer.ftpatdomain is allowed, specify a domain (customer must be owner)
|
* optional if customer.ftpatdomain is allowed, specify a domain (customer must be owner)
|
||||||
* @param int $customerid
|
* @param int $customerid
|
||||||
* required when called as admin, not needed when called as customer
|
* required when called as admin, not needed when called as customer
|
||||||
|
* @param array $additional_members
|
||||||
|
* optional whether to add additional usernames to the group
|
||||||
|
* @param bool $is_defaultuser
|
||||||
|
* optional whether this is the standard default ftp user which is being added so no usage is decreased
|
||||||
*
|
*
|
||||||
* @access admin, customer
|
* @access admin, customer
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
@@ -66,6 +70,9 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
|||||||
$ftpusername = $this->getParam('ftp_username', true, '');
|
$ftpusername = $this->getParam('ftp_username', true, '');
|
||||||
$ftpdomain = $this->getParam('ftp_domain', true, '');
|
$ftpdomain = $this->getParam('ftp_domain', true, '');
|
||||||
|
|
||||||
|
$additional_members = $this->getParam('additional_members', true, array());
|
||||||
|
$is_defaultuser = $this->getBoolParam('is_defaultuser', true, 0);
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
$password = \Froxlor\Validate\Validate::validate($password, 'password', '', '', array(), true);
|
$password = \Froxlor\Validate\Validate::validate($password, 'password', '', '', array(), true);
|
||||||
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
||||||
@@ -87,7 +94,12 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
|||||||
|
|
||||||
$params = array();
|
$params = array();
|
||||||
// get needed customer info to reduce the ftp-user-counter by one
|
// get needed customer info to reduce the ftp-user-counter by one
|
||||||
|
if ($is_defaultuser) {
|
||||||
|
// no resource check for default user
|
||||||
|
$customer = $this->getCustomerData();
|
||||||
|
} else {
|
||||||
$customer = $this->getCustomerData('ftps');
|
$customer = $this->getCustomerData('ftps');
|
||||||
|
}
|
||||||
|
|
||||||
if ($sendinfomail != 1) {
|
if ($sendinfomail != 1) {
|
||||||
$sendinfomail = 0;
|
$sendinfomail = 0;
|
||||||
@@ -112,9 +124,13 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
|||||||
\Froxlor\UI\Response::standard_error('maindomainnonexist', $ftpdomain, true);
|
\Froxlor\UI\Response::standard_error('maindomainnonexist', $ftpdomain, true);
|
||||||
}
|
}
|
||||||
$username = $ftpusername . "@" . $ftpdomain;
|
$username = $ftpusername . "@" . $ftpdomain;
|
||||||
|
} else {
|
||||||
|
if ($is_defaultuser) {
|
||||||
|
$username = $customer['loginname'];
|
||||||
} else {
|
} else {
|
||||||
$username = $customer['loginname'] . Settings::Get('customer.ftpprefix') . (intval($customer['ftp_lastaccountnumber']) + 1);
|
$username = $customer['loginname'] . Settings::Get('customer.ftpprefix') . (intval($customer['ftp_lastaccountnumber']) + 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$username_check_stmt = Database::prepare("
|
$username_check_stmt = Database::prepare("
|
||||||
SELECT * FROM `" . TABLE_FTP_USERS . "` WHERE `username` = :username
|
SELECT * FROM `" . TABLE_FTP_USERS . "` WHERE `username` = :username
|
||||||
@@ -175,10 +191,22 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
|||||||
);
|
);
|
||||||
Database::pexecute($stmt, $params, true, true);
|
Database::pexecute($stmt, $params, true, true);
|
||||||
|
|
||||||
|
if (count($additional_members) > 0) {
|
||||||
|
foreach ($additional_members as $add_member) {
|
||||||
|
$params = array(
|
||||||
|
"username" => $add_member,
|
||||||
|
"customerid" => $customer['customerid'],
|
||||||
|
"guid" => $customer['guid']
|
||||||
|
);
|
||||||
|
Database::pexecute($stmt, $params, true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// update customer usage
|
// update customer usage
|
||||||
|
if (! $is_defaultuser) {
|
||||||
Customers::increaseUsage($customer['customerid'], 'ftps_used');
|
Customers::increaseUsage($customer['customerid'], 'ftps_used');
|
||||||
Customers::increaseUsage($customer['customerid'], 'ftp_lastaccountnumber');
|
Customers::increaseUsage($customer['customerid'], 'ftp_lastaccountnumber');
|
||||||
|
}
|
||||||
|
|
||||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_INFO, "[API] added ftp-account '" . $username . " (" . $path . ")'");
|
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_INFO, "[API] added ftp-account '" . $username . " (" . $path . ")'");
|
||||||
\Froxlor\System\Cronjob::inserttask(5);
|
\Froxlor\System\Cronjob::inserttask(5);
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ class FileDir
|
|||||||
'ADMIN_EMAIL' => $template['admin_email']
|
'ADMIN_EMAIL' => $template['admin_email']
|
||||||
);
|
);
|
||||||
|
|
||||||
// @fixme replaceVariables
|
// replaceVariables
|
||||||
$htmlcontent = PhpHelper::replaceVariables($template['value'], $replace_arr);
|
$htmlcontent = PhpHelper::replaceVariables($template['value'], $replace_arr);
|
||||||
$indexhtmlpath = self::makeCorrectFile($destination . '/index.' . Settings::Get('system.index_file_extension'));
|
$indexhtmlpath = self::makeCorrectFile($destination . '/index.' . Settings::Get('system.index_file_extension'));
|
||||||
$index_html_handler = fopen($indexhtmlpath, 'w');
|
$index_html_handler = fopen($indexhtmlpath, 'w');
|
||||||
|
|||||||
Reference in New Issue
Block a user