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);
|
||||
|
||||
\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
|
||||
// allow access to customer-directories from within the panel, which
|
||||
// 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') == 1) {
|
||||
$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
|
||||
// without this check addition may duplicate user in list if httpuser == local_user
|
||||
if (strpos($ins_data['members'], $local_user) == false) {
|
||||
$ins_data['members'] .= ',' . $local_user;
|
||||
if (in_array($local_user, $local_users) == false) {
|
||||
$local_users[] = $local_user;
|
||||
}
|
||||
}
|
||||
Database::pexecute($ins_stmt, $ins_data, true, true);
|
||||
|
||||
// FTP-Quotatallies
|
||||
// @fixme use Ftp-ApiCommand later
|
||||
$ins_stmt = Database::prepare("
|
||||
INSERT INTO `" . TABLE_FTP_QUOTATALLIES . "` SET `name` = :name, `quota_type` = 'user', `bytes_in_used` = '0',
|
||||
`bytes_out_used` = '0', `bytes_xfer_used` = '0', `files_in_used` = '0', `files_out_used` = '0', `files_xfer_used` = '0'
|
||||
");
|
||||
Database::pexecute($ins_stmt, array(
|
||||
'name' => $loginname
|
||||
), true, true);
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] automatically added ftp-account for user '" . $loginname . "'");
|
||||
$this->apiCall('Ftps.add', array(
|
||||
'customerid' => $customerid,
|
||||
'path' => $documentroot,
|
||||
'ftp_password' => $password,
|
||||
'ftp_description' => "Default",
|
||||
'sendinfomail' => 0,
|
||||
'ftp_username' => $loginname,
|
||||
'additional_members' => $local_users,
|
||||
'is_defaultuser' => 1
|
||||
));
|
||||
|
||||
$_stdsubdomain = '';
|
||||
if ($createstdsubdomain == '1') {
|
||||
@@ -898,7 +873,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
$email = $idna_convert->encode(\Froxlor\Validate\Validate::validate($email, 'email', '', '', array(), true));
|
||||
$customernumber = \Froxlor\Validate\Validate::validate($customernumber, 'customer number', '/^[A-Za-z0-9 \-]*$/Di', '', array(), true);
|
||||
$custom_notes = \Froxlor\Validate\Validate::validate(str_replace("\r\n", "\n", $custom_notes), 'custom_notes', '/^[^\0]*$/', '', array(), true);
|
||||
if (!empty($allowed_phpconfigs)) {
|
||||
if (! empty($allowed_phpconfigs)) {
|
||||
$allowed_phpconfigs = array_map('intval', $allowed_phpconfigs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
* @param int $customerid
|
||||
* 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
|
||||
* @throws \Exception
|
||||
@@ -66,6 +70,9 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
$ftpusername = $this->getParam('ftp_username', true, '');
|
||||
$ftpdomain = $this->getParam('ftp_domain', true, '');
|
||||
|
||||
$additional_members = $this->getParam('additional_members', true, array());
|
||||
$is_defaultuser = $this->getBoolParam('is_defaultuser', true, 0);
|
||||
|
||||
// validation
|
||||
$password = \Froxlor\Validate\Validate::validate($password, 'password', '', '', array(), true);
|
||||
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
||||
@@ -87,7 +94,12 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
|
||||
$params = array();
|
||||
// get needed customer info to reduce the ftp-user-counter by one
|
||||
$customer = $this->getCustomerData('ftps');
|
||||
if ($is_defaultuser) {
|
||||
// no resource check for default user
|
||||
$customer = $this->getCustomerData();
|
||||
} else {
|
||||
$customer = $this->getCustomerData('ftps');
|
||||
}
|
||||
|
||||
if ($sendinfomail != 1) {
|
||||
$sendinfomail = 0;
|
||||
@@ -113,7 +125,11 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
}
|
||||
$username = $ftpusername . "@" . $ftpdomain;
|
||||
} else {
|
||||
$username = $customer['loginname'] . Settings::Get('customer.ftpprefix') . (intval($customer['ftp_lastaccountnumber']) + 1);
|
||||
if ($is_defaultuser) {
|
||||
$username = $customer['loginname'];
|
||||
} else {
|
||||
$username = $customer['loginname'] . Settings::Get('customer.ftpprefix') . (intval($customer['ftp_lastaccountnumber']) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
$username_check_stmt = Database::prepare("
|
||||
@@ -175,10 +191,22 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
);
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
|
||||
// update customer usage
|
||||
Customers::increaseUsage($customer['customerid'], 'ftps_used');
|
||||
Customers::increaseUsage($customer['customerid'], 'ftp_lastaccountnumber');
|
||||
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
|
||||
if (! $is_defaultuser) {
|
||||
Customers::increaseUsage($customer['customerid'], 'ftps_used');
|
||||
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 . ")'");
|
||||
\Froxlor\System\Cronjob::inserttask(5);
|
||||
|
||||
@@ -217,7 +217,7 @@ class FileDir
|
||||
'ADMIN_EMAIL' => $template['admin_email']
|
||||
);
|
||||
|
||||
// @fixme replaceVariables
|
||||
// replaceVariables
|
||||
$htmlcontent = PhpHelper::replaceVariables($template['value'], $replace_arr);
|
||||
$indexhtmlpath = self::makeCorrectFile($destination . '/index.' . Settings::Get('system.index_file_extension'));
|
||||
$index_html_handler = fopen($indexhtmlpath, 'w');
|
||||
|
||||
Reference in New Issue
Block a user