fix(yunohostField) : run commands in background
This commit is contained in:
parent
9d7f33d5c9
commit
bd3a126572
1 changed files with 436 additions and 433 deletions
|
@ -50,7 +50,7 @@ class YunohostUserField extends BazarField
|
|||
$this->usernameField = $values[self::FIELD_USERNAME_FIELD] ?: ''; // empty usernameField will use nameField as username
|
||||
$this->userMailDomain = $values[self::FIELD_USER_MAIL_DOMAIN_FIELD] ?: $this->yunohostOptions['mail_domain'];
|
||||
$this->mailingList = $values[self::FIELD_MAILING_LIST];
|
||||
$this->autoUpdateMail = in_array($values[self::FIELD_AUTO_UPDATE_MAIL], [true,"1",1], true);
|
||||
$this->autoUpdateMail = in_array($values[self::FIELD_AUTO_UPDATE_MAIL], [true, "1", 1], true);
|
||||
$this->autoAddToGroup = trim(strval($values[self::FIELD_AUTO_ADD_TO_GROUP]));
|
||||
$this->cmdPrefix = $this->yunohostOptions['cmd_prefix'] ?? 'sudo';
|
||||
|
||||
|
@ -71,7 +71,7 @@ class YunohostUserField extends BazarField
|
|||
protected function getYunohostUsernames()
|
||||
{
|
||||
$output = $retval = null;
|
||||
$cmd = $this->cmdPrefix.' yunohost user list --fields username 2>&1';
|
||||
$cmd = $this->cmdPrefix . ' yunohost user list --fields username 2>&1';
|
||||
exec($cmd, $output, $retval);
|
||||
$users = [];
|
||||
foreach ($output as $outputline) {
|
||||
|
@ -93,11 +93,11 @@ class YunohostUserField extends BazarField
|
|||
// you need to add in /etc/sudoers (with visudo) something like
|
||||
// <myunixuser> ALL=(root) NOPASSWD: /usr/bin/yunohost
|
||||
// utiliser proc_open avec des arguments plutot que de echaper / concatener
|
||||
$cmd = $this->cmdPrefix.' yunohost user create '.$userValues['name']
|
||||
.' -F \''.$userValues['fullname'].'\''
|
||||
.' -d '.$this->userMailDomain
|
||||
.' -p \''.$userValues['password'].'\''
|
||||
.' 2>&1';
|
||||
$cmd = $this->cmdPrefix . ' yunohost user create ' . $userValues['name']
|
||||
. ' -F \'' . $userValues['fullname'] . '\''
|
||||
. ' -d ' . $this->userMailDomain
|
||||
. ' -p \'' . $userValues['password'] . '\''
|
||||
. ' 2>&1 &';
|
||||
exec($cmd, $output, $retval);
|
||||
// handle errors
|
||||
if ($retval == 1) {
|
||||
|
@ -110,9 +110,9 @@ class YunohostUserField extends BazarField
|
|||
throw new Exception($output[0]);
|
||||
}
|
||||
}
|
||||
$cmd = $this->cmdPrefix.' yunohost user update '.$userValues['name']
|
||||
.' --add-mailforward '.$userValues[$this->emailField]
|
||||
.' 2>&1';
|
||||
$cmd = $this->cmdPrefix . ' yunohost user update ' . $userValues['name']
|
||||
. ' --add-mailforward ' . $userValues[$this->emailField]
|
||||
. ' 2>&1 &';
|
||||
exec($cmd, $output, $retval);
|
||||
//dump($output);
|
||||
// handle errors
|
||||
|
@ -144,8 +144,8 @@ class YunohostUserField extends BazarField
|
|||
if (empty($value) || !$this->isUserByName($value)) {
|
||||
$value = $associatedUser['name'];
|
||||
$message = str_replace(
|
||||
['{wikiname}','{email}'],
|
||||
[$value,$associatedUser['email']],
|
||||
['{wikiname}', '{email}'],
|
||||
[$value, $associatedUser['email']],
|
||||
_t('BAZ_USER_FIELD_ALREADY_CONNECTED')
|
||||
);
|
||||
}
|
||||
|
@ -153,11 +153,11 @@ class YunohostUserField extends BazarField
|
|||
$associatedUser = $userManager->getOneByName($value);
|
||||
}
|
||||
if ($value === $loggedUser['name'] || ($this->getWiki()->UserIsAdmin() && !empty($associatedUser['email']))) {
|
||||
$message = (!empty($message) ? $message."\n" : '').($this->autoUpdateMail ? str_replace(
|
||||
$message = (!empty($message) ? $message . "\n" : '') . ($this->autoUpdateMail ? str_replace(
|
||||
'{email}',
|
||||
$associatedUser['email'],
|
||||
_t('BAZ_USER_FIELD_ALREADY_CONNECTED_AUTOUPDATE')
|
||||
): '');
|
||||
) : '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -168,8 +168,8 @@ class YunohostUserField extends BazarField
|
|||
'userIsAdmin' => $this->getWiki()->UserIsAdmin(),
|
||||
'userName' => $loggedUser['name'] ?? null,
|
||||
'userEmail' => $loggedUser['email'] ?? null,
|
||||
'forceLabel' => $this->propertyName.self::FORCE_LABEL,
|
||||
'forceLabelChecked' => $_POST[$this->propertyName.self::FORCE_LABEL] ?? false,
|
||||
'forceLabel' => $this->propertyName . self::FORCE_LABEL,
|
||||
'forceLabelChecked' => $_POST[$this->propertyName . self::FORCE_LABEL] ?? false,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -184,8 +184,10 @@ class YunohostUserField extends BazarField
|
|||
|
||||
$wiki = $this->getWiki();
|
||||
|
||||
if ($this->getWiki()->UserIsAdmin()
|
||||
&& in_array($_POST[$this->propertyName.self::FORCE_LABEL] ?? false, [true,"true",1,"1"], true)) {
|
||||
if (
|
||||
$this->getWiki()->UserIsAdmin()
|
||||
&& in_array($_POST[$this->propertyName . self::FORCE_LABEL] ?? false, [true, "true", 1, "1"], true)
|
||||
) {
|
||||
// force entry creation but do not create user if existing for this email
|
||||
$userManager = $this->getService(UserManager::class);
|
||||
$existingUser = $userManager->getOneByEmail($entry[$this->emailField]);
|
||||
|
@ -214,15 +216,16 @@ class YunohostUserField extends BazarField
|
|||
if ($this->isUserByName($wikiName)) {
|
||||
$currentWikiName = strtolower($wikiName);
|
||||
$wikiName = $this->findANewNotExistingUserName($currentWikiName);
|
||||
if (!$isImport
|
||||
if (
|
||||
!$isImport
|
||||
&& (
|
||||
!isset($_POST[$this->propertyName.self::CONFIRM_NAME_SUFFIX])
|
||||
|| !in_array($_POST[$this->propertyName.self::CONFIRM_NAME_SUFFIX], [true,1,"1"], true)
|
||||
!isset($_POST[$this->propertyName . self::CONFIRM_NAME_SUFFIX])
|
||||
|| !in_array($_POST[$this->propertyName . self::CONFIRM_NAME_SUFFIX], [true, 1, "1"], true)
|
||||
)
|
||||
) {
|
||||
throw new UserFieldException(
|
||||
$this->render("@bazar/inputs/user-confirm.twig", [
|
||||
'confirmName' => $this->propertyName.self::CONFIRM_NAME_SUFFIX,
|
||||
'confirmName' => $this->propertyName . self::CONFIRM_NAME_SUFFIX,
|
||||
'wikiName' => $currentWikiName,
|
||||
'newWikiName' => $wikiName,
|
||||
])
|
||||
|
@ -254,12 +257,12 @@ class YunohostUserField extends BazarField
|
|||
'password' => $entry['mot_de_passe_wikini']
|
||||
]);
|
||||
} catch (UserNameAlreadyUsedException $ex) {
|
||||
throw new UserFieldException('yeswiki : '._t('BAZ_USER_FIELD_EXISTING_USER_BY_EMAIL'));
|
||||
throw new UserFieldException('yeswiki : ' . _t('BAZ_USER_FIELD_EXISTING_USER_BY_EMAIL'));
|
||||
} catch (Exception $ex) {
|
||||
throw new UserFieldException('yeswiki : '.$ex->getMessage(), $ex->getCode(), $ex);
|
||||
throw new UserFieldException('yeswiki : ' . $ex->getMessage(), $ex->getCode(), $ex);
|
||||
}
|
||||
} catch (UserNameAlreadyUsedException $ex) {
|
||||
throw new UserFieldException(_t('L\'utilisateur.ice '.$wikiName.' est déjà utilisé, veuillez vous connecter si c\'est vous, ou utiliser un autre nom d\'utilisateur.ice.'));
|
||||
throw new UserFieldException(_t('L\'utilisateur.ice ' . $wikiName . ' est déjà utilisé, veuillez vous connecter si c\'est vous, ou utiliser un autre nom d\'utilisateur.ice.'));
|
||||
} catch (Exception $ex) {
|
||||
throw new UserFieldException($ex->getMessage(), $ex->getCode(), $ex);
|
||||
}
|
||||
|
@ -287,8 +290,8 @@ class YunohostUserField extends BazarField
|
|||
'fields-to-remove' => [
|
||||
'mot_de_passe_wikini',
|
||||
'mot_de_passe_repete_wikini',
|
||||
$this->propertyName.self::CONFIRM_NAME_SUFFIX,
|
||||
$this->propertyName.self::FORCE_LABEL,
|
||||
$this->propertyName . self::CONFIRM_NAME_SUFFIX,
|
||||
$this->propertyName . self::FORCE_LABEL,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
@ -372,7 +375,8 @@ class YunohostUserField extends BazarField
|
|||
$userManager = $this->getService(UserManager::class);
|
||||
$user = $userManager->getOneByName($userName);
|
||||
$loggedUser = $authController->getLoggedUser();
|
||||
if (!empty($user)
|
||||
if (
|
||||
!empty($user)
|
||||
&& (
|
||||
$this->getWiki()->UserIsAdmin()
|
||||
|| (
|
||||
|
@ -383,7 +387,7 @@ class YunohostUserField extends BazarField
|
|||
&& $user['email'] !== $email
|
||||
) {
|
||||
try {
|
||||
$userController->update($user, ['email'=>$email]);
|
||||
$userController->update($user, ['email' => $email]);
|
||||
} catch (UserNameAlreadyUsedException $ex) {
|
||||
throw new UserFieldException(_t('BAZ_USER_FIELD_EXISTING_USER_BY_EMAIL'));
|
||||
} catch (Exception $ex) {
|
||||
|
@ -430,8 +434,8 @@ class YunohostUserField extends BazarField
|
|||
foreach ($groupsNames as $groupName) {
|
||||
$previousACL = !in_array($groupName, $existingsGroups, true)
|
||||
? ''
|
||||
: $wiki->GetGroupACL($groupName)."\n";
|
||||
$wiki->SetGroupACL($groupName, $previousACL.$wikiName);
|
||||
: $wiki->GetGroupACL($groupName) . "\n";
|
||||
$wiki->SetGroupACL($groupName, $previousACL . $wikiName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -463,7 +467,7 @@ class YunohostUserField extends BazarField
|
|||
$baseWikiName = preg_replace("/[0-9]*$/", "", $firstWikiName);
|
||||
|
||||
// a loop 1000 should be enough
|
||||
for ($i=1; $i < 1000; $i++) {
|
||||
for ($i = 1; $i < 1000; $i++) {
|
||||
$newName = "$baseWikiName$i";
|
||||
if (!$this->isUserByName($newName)) {
|
||||
return $newName;
|
||||
|
@ -475,4 +479,3 @@ class YunohostUserField extends BazarField
|
|||
throw new UserFieldException('Impossible to find a new user name !');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue