Add sudo script to move pseudo-homedirectory when deleting user

upstream/latest
Gregory Colpart 6 months ago
parent 8157ebd596
commit 0ceb430071
  1. 6
      config/config-sample.ini
  2. 5
      htdocs/lib/Config.php
  3. 2
      htdocs/lib/FormController.php
  4. 3
      htdocs/lib/LdapDomain.php
  5. 2
      htdocs/lib/LdapServer.php
  6. 97
      scripts/evoadmin.sh

@ -23,3 +23,9 @@ superadmin[] = "evoadmin"
[quota]
path = "/var/lib/evoadmin-mail/quota/"
[evoexec]
sudobin = "/usr/bin/sudo"
sudoscript = "/usr/share/scripts/evoadmin.sh"
sudopass = "XXX"

@ -47,4 +47,9 @@ class Config {
public static function getQuotaPath() {
return self::$quota_path;
}
public static function getEvoexec() {
return self::$evoexec['sudobin'].' '.self::$evoexec['sudoscript'].' -p '.self::$evoexec['sudopass'].' ';
}
}

@ -149,7 +149,7 @@ class FormController {
private static function delAccount() {
PageController::$alerts[] = array('type' => 1, 'message' => 'Suppression du compte '.self::$form['uid'].'...');
try {
self::$domain->delAccount(self::$form['uid']);
self::$domain->delAccount(self::$form['uid'],self::$form['cn']);
PageController::$alerts[] = array('type' => 0, 'message' => "Suppression effectué.");
} catch (Exception $e) {
PageController::$alerts[] = array('type' => 2, 'message' => $e->getMessage());

@ -118,7 +118,7 @@ class LdapDomain extends LdapServer {
}
}
public function delAccount($uid) {
public function delAccount($uid,$domain) {
$dn = LdapAccount::getBaseDN($this, $uid);
if ($sr = @ldap_search($this->conn, $dn, LdapAccount::getClassFilter())) {
// Delete account
@ -126,6 +126,7 @@ class LdapDomain extends LdapServer {
$error = ldap_error($this->conn);
throw new Exception("Erreur dans la suppression du compte $uid : $error");
}
exec( Config::getEvoexec() . " -d -u $uid -D $domain");
} else {
throw new Exception("Ce compte n'existe pas !");
}

@ -128,7 +128,7 @@ class LdapServer {
}
// Delete accounts
foreach($domain->getAccounts() as $account) {
$domain->delAccount($account->getUid());
$domain->delAccount($account->getUid(),$name);
}
// Delete domain
$dn = LdapDomain::getBaseDN($this, $name);

@ -6,41 +6,25 @@
PASSWORD='xxx'
DATE=$(date +"%d-%m-%Y")
while getopts "p:qu:g:sadv" option ; do
while getopts "p:u:D:d" option ; do
case $option in
p)
READPASS=$OPTARG
;;
q)
QUOTA='on'
;;
u)
USERIS=$OPTARG
;;
g)
GROUPIS=$OPTARG
;;
s)
SIZE='on'
D)
DOMAINIS=$OPTARG
;;
a)
ADD='on'
;;
d)
DEL='on'
;;
v)
VIRTUAL='on'
;;
*)
echo "script error"
exit 1
@ -54,77 +38,14 @@ if [ "$PASSWORD" != "$READPASS" ]; then
exit 1
fi
# Mode virtuel : permet pour l'instant la création du répertoire d'un domaine
# ex : evoadmin.sh -a -v -g example.com
if [ "$VIRTUAL" = "on" ]; then
if [ "$ADD" == "on" ]; then
if [[ -z $USERIS && -n $GROUPIS && ! -e "/home/vmail/$GROUPIS" ]]; then
DOMAIN_DIR="/home/vmail/$GROUPIS"
mkdir $DOMAIN_DIR
# nécessite d'avoir un NSS/LDAP fonctionnel
chown root:$GROUPIS $DOMAIN_DIR
chmod 770 $DOMAIN_DIR
fi
fi
if [ "$DEL" == "on" ]; then
if [[ -n $USERIS && -n $GROUPIS && -e "/home/vmail/$GROUPIS" && -e "/home/vmail/$GROUPIS/$USERIS" ]]; then
mv /home/vmail/$GROUPIS/$USERIS /home/vmail/$GROUPIS/$USERIS.$DATE
chown -R root:root /home/vmail/$GROUPIS/$USERIS.$DATE
fi
fi
exit 0
fi
if [ "$QUOTA" == "on" ]; then
if [ -n "$USERIS" ]; then
NOW=`LANG=C quota $USERIS | tr -d "\n" | sed -e "s/^.*\/dev\///" | tr -s " " | cut -d" " -f2`
LIMIT=`LANG=C quota $USERIS | tr -d "\n" | sed -e "s/^.*\/dev\///" | tr -s " " | cut -d" " -f3`
echo "$NOW/$LIMIT"
exit 0
fi
if [ -n "$GROUPIS" ]; then
# no quota
if LANG=C quota -g $GROUPIS | grep none > /dev/null; then
echo "0/0"
exit 0
fi
NOW=`LANG=C quota -g $GROUPIS | tr -d "\n" | sed -e "s/^.*\/dev\///" | tr -s " " | cut -d" " -f2`
LIMIT=`LANG=C quota -g $GROUPIS | tr -d "\n" | sed -e "s/^.*\/dev\///" | tr -s " " | cut -d" " -f3`
echo "$NOW/$LIMIT"
exit 0
fi
fi
if [ "$SIZE" == "on" ]; then
NOW=`df | grep "/home" | tr -s " " | cut -d " " -f3`
LIMIT=`df | grep "/home" | tr -s " " | cut -d " " -f2`
echo "$NOW/$LIMIT"
exit 0
fi
if [ "$ADD" == "on" ]; then
if [[ -n $USERIS && $GROUPIS && ! -e "/home/$USERIS" ]]; then
mkdir /home/$USERIS
chmod 0700 /home/$USERIS
chown "$USERIS:$GROUPIS" /home/$USERIS
setquota -u $USERIS 5000000 8000000 0 0 -a
echo "Mail d'initialisation du compte." |\
mail -s "Premier message" $USERIS@localhost
exit 0
fi
fi
# mv pseudo-homeDir to directory.<date> for deleted users
if [ "$DEL" == "on" ]; then
if [[ -n $USERIS && -e "/home/$USERIS" ]]; then
mv /home/$USERIS /home/$USERIS.$DATE
chown -R root:root /home/$USERIS.$DATE
exit 0
if [[ -n $USERIS && -n $DOMAINIS && -e "/home/vmail/$DOMAINIS" && -e "/home/vmail/$DOMAINIS/$USERIS" ]]; then
mv /home/vmail/$DOMAINIS/$USERIS /home/vmail/$DOMAINIS/$USERIS.$DATE
chown -R root:root /home/vmail/$DOMAINIS/$USERIS.$DATE
chmod -R 700 /home/vmail/$DOMAINIS/$USERIS.$DATE
fi
exit 0
fi
exit 1

Loading…
Cancel
Save