home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ac-grenoble.fr
/
2015.02.ftp.ac-grenoble.fr.tar
/
ftp.ac-grenoble.fr
/
pub
/
slis
/
updates_rsync
/
process_queue-2.x
< prev
next >
Wrap
Text File
|
2002-03-07
|
12KB
|
483 lines
#!/bin/bash
#### $Id: process_queue,v 1.14 2002/02/05 10:47:44 bzizou Exp $ ####
# Process queue hadmin
# This script is part of the SLIS Project initiated by the CARMI-Internet
# (AcadΘmie de Grenoble - France 38).
# Ce script fait partie du projet SLIS dΘmarrΘ par le CARMI-Internet
# (AcadΘmie de Grenoble - France 38).
#
# SLIS : Serveur de communications Linux Pour l'Internet Scolaire.
# Copyright (C) 1998-2000 Bruno Bzeznik
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program (For example ./COPYING);
# if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
# Cambridge, MA 02139, USA.
#
# Please send all comments and bug reports by electronic mail to:
# Bruno Bzeznik <Bruno@ac-grenoble.fr>
# or to <slis@ac-grenoble.fr>
#
# Envoyez vos suggestions et reports de bugs par e-mail α
# Bruno Bzeznik <Bruno@ac-grenoble.fr>
# ou α <slis@ac-grenoble.fr>
#
######################
# VARIABLES GLOBALES #
######################
. /home/hadmin/slis.conf
BINDIR=$SLIS_BINDIR
ETRN=$SLIS_BINDIR/etrn
MAILHUB=$SMART_HOST
POPSHELL=/bin/false
MAIL_ADMIN=`grep @ /home/hadmin/cgi-bin/base/params_admin.txt | grep "."`
LANG=C
LOGTAG="-t process_queue[$$] -p $LOG_FACILITY.notice"
#####################
# INITIALISATION #
#####################
rm -rf $QUEUE/tbp
rm -rf $QUEUE/result
touch $QUEUE/result
# Fichier d'enregistrement des erreurs
if [ ! \( -f $QUEUE/error_log \) ]
then
touch $QUEUE/error_log
chmod 600 $QUEUE/error_log
chown hadmin.hadmin $QUEUE/error_log
fi
# Gestion d'un lock
if [ -f $QUEUE/lock ]
then
logger $LOGTAG "Fichier lock trouve. Aborting."
echo "La file d'attente des operations non validees n'a pas pu etre
traitee car une autre validation est deja en cours. Si ce probleme
persiste, contactez $SLISMASTER" >> $QUEUE/result
cat $QUEUE/result | mail -s "Resultats de votre validation - Erreur" $MAIL_ADMIN
DATE=`date`
echo "$DATE: $LOGTAG : Fichier lock trouve. Abort." >> $QUEUE/error_log
exit 1
else
touch $QUEUE/lock
fi
# Affichage dans la syslog.
logger $LOGTAG "Processing admin queue..."
#######################
# Unlocking
#######################
if [ -f $QUEUE/unlock ]
then
rm -f $QUEUE/lock
rm -f $QUEUE/unlock
killall process_queue
fi
##########################################
# Vidage de la mailqueue sur le mailhub. #
##########################################
if [ -f $QUEUE/etrn ]
then
rm -rf $QUEUE/etrn
logger $LOGTAG "Processing $MAILHUB's mailqueue."
if [ "$FETCHMAIL" = "1" ]
then
logger $LOGTAG "Starting fetchmail."
/usr/bin/fetchmail
else
if [ -f $ETRN ]
then
logger $LOGTAG "Sending etrn."
$ETRN $MAILHUB
else
logger $LOGTAG "$ETRN not found."
fi
fi
logger $LOGTAG "Processing local mailqueue."
/usr/sbin/sendmail -q 2> /dev/console
fi
############################
# Creation de comptes pop. #
############################
if [ -f $QUEUE/users_pop ]
then
for i in `awk '{print NR}' $QUEUE/users_pop`
do
# Lecture des parametres du fichier d'entree de la queue.
LOGIN=`awk -v I=$i -F: '{if (NR == I) print $1}' $QUEUE/users_pop`
PASSW=`awk -v I=$i -F: '{if (NR == I) print $2}' $QUEUE/users_pop`
CPASS=`awk -v I=$i -F: '{if (NR == I) print $3}' $QUEUE/users_pop`
COMMT=`awk -v I=$i -F: '{if (NR == I) print $4}' $QUEUE/users_pop`
ALIAS=`awk -v I=$i -F: '{if (NR == I) print $5}' $QUEUE/users_pop`
echo >> $QUEUE/result
echo "Creation de l'utilisateur $COMMT" >> $QUEUE/result
# Creation proprement dite.
/usr/sbin/useradd -p $CPASS -s $POPSHELL -c "$COMMT" $LOGIN 2>> $QUEUE/error_log
RETURNCODE=$?
echo -n "Resultat : " >> $QUEUE/result
if [ $RETURNCODE = "0" ]
then
# Creation de l'alias
echo "$ALIAS: $LOGIN" >> /etc/aliases
# Composition du message a l'administrateur.
echo "OK" >> $QUEUE/result
echo " Nom d'utilisateur : " $LOGIN >> $QUEUE/result
echo " Mot de passe : " $PASSW >> $QUEUE/result
echo " E-mail : " $ALIAS@$HOSTNAME >> $QUEUE/result
# Ajout dans la base.
echo "$LOGIN:$PASSW:$CPASS:$COMMT:$POPSHELL:$ALIAS" >> $BASE/users
fi
# Gestion des erreurs
if [ $RETURNCODE = "9" ]
then
echo "Utilisateur deja existant... non cree." >> $QUEUE/result
fi
if [ $RETURNCODE != "9" -a $RETURNCODE != "0" ]
then
echo "Erreur... Utilisateur non cree." >> $QUEUE/result
fi
done
/usr/bin/newaliases
rm -rf $QUEUE/users_pop
fi
############################
# Suppression de comptes #
############################
if [ -f $QUEUE/users_del ]
then
for i in `awk '{print NR}' $QUEUE/users_del`
do
LOGIN=`awk -v I=$i -F: '{if (NR == I) print $1}' $QUEUE/users_del`
DELBOX=`awk -v I=$i -F: '{if (NR == I) print $2}' $QUEUE/users_del`
echo >> $QUEUE/result
echo "Suppression de l'utilisateur $LOGIN" >> $QUEUE/result
/usr/sbin/userdel $LOGIN 2>> $QUEUE/error_log
RETURNCODE=$?
/usr/sbin/groupdel $LOGIN 2>> $QUEUE/error_log
echo -n "Resultat : " >> $QUEUE/result
if [ $RETURNCODE = "0" ]
then
if [ $DELBOX = "0" ]
then
rm -rf /var/spool/mail/$LOGIN
rm -rf /home/$LOGIN
fi
echo "OK" >> $QUEUE/result
# Suppression de l'entree dans la base
rm -rf $BASE/users.new
grep -v "$LOGIN:" $BASE/users > $BASE/users.new
rm -rf $BASE/users
mv $BASE/users.new $BASE/users
fi
if [ $RETURNCODE != "0" ]
then
echo "Erreur... Utilisateur non supprime." >> $QUEUE/result
fi
done
# Suppression des aliases
$BINDIR/clean_aliases
rm -rf $QUEUE/users_del
fi
######################
# Aliases #
######################
if [ -f $QUEUE/users_alias ]
then
$BINDIR/process_users_alias >> $QUEUE/result
logger $LOGTAG "Ajout d'aliases."
fi
if [ -f $QUEUE/users_alias_del ]
then
$BINDIR/process_users_alias >> $QUEUE/result
logger $LOGTAG "Suppression d'aliases."
fi
####################
# Reboot / Halt #
####################
if [ -f $QUEUE/reboot ]
then
logger $LOGTAG "Redemarrage demande."
rm -rf $QUEUE/reboot
/sbin/shutdown -r now "Redemarrage pour maintenance - hadmin"
fi
if [ -f $QUEUE/halt ]
then
logger $LOGTAG "Arret demande."
rm -rf $QUEUE/halt
/sbin/shutdown -h now "Arret du systeme - hadmin"
fi
######################
# Mise α jour forcΘe #
######################
if [ -f $QUEUE/update ]
then
rm -rf $QUEUE/update
$BINDIR/slis_update 2>> $QUEUE/error_log
fi
######################
# Filtrage IP # OBSOLETE
######################
if [ -f $QUEUE/filtrage_ip ]
then
logger $LOGTAG "Modification filtrage_ip."
$BINDIR/process_filtrage_ip
rm -rf $QUEUE/filtrage_ip
fi
######################
# IP filters #
# THIS IS OBSOLETE!!
# mkfilters is called on every validation now
######################
if [ -f $QUEUE/ip_filters ]
then
logger $LOGTAG "IP filters change requested."
$BINDIR/mkfilters
rm -rf $QUEUE/ip_filters
fi
######################
# Filtrage URL # OBSOLETE!
######################
if [ -f $QUEUE/denied_url -o -f $QUEUE/denied_url_purge ]
then
logger $LOGTAG "Modification filtrage_url."
$BINDIR/process_filtrage_url
rm -rf $QUEUE/denied_url
fi
###########################
# Filtrage par squidGuard #
###########################
if [ -f $QUEUE/squid_guard ]
then
logger $LOGTAG "Modification filtrage squidguard"
$BINDIR/process_filtrage_squidguard
rm -rf $QUEUE/squid_guard
fi
####################
# Routage on / off #
####################
if [ -f $QUEUE/routage_off ]
then
logger $LOGTAG "Arret routage demande"
rm -rf $QUEUE/routage_off
$BINDIR/routage_off
fi
if [ -f $QUEUE/routage_on ]
then
logger $LOGTAG "Mise en marche routage demande"
rm -rf $QUEUE/routage_on
$BINDIR/routage_on
fi
######################
# Subnets / horaires #
######################
if [ -f $QUEUE/subnets ]
then
$BINDIR/process_subnets
logger $LOGTAG "Modif etat des subnets."
fi
if [ -f $QUEUE/subn_hor ]
then
$BINDIR/process_subnets
logger $LOGTAG "Modif des horaires subnets."
fi
if [ -f $QUEUE/subnets_cron ]
then
sleep 5
for i in `ls $QUEUE/subnets_cron.*`
do
if [ ! \( "$i" = "" \) ]
then
bash $i
rm -rf $i
fi
done
rm -rf $QUEUE/subnets_cron
logger $LOGTAG "Modif etat des subnets par cron."
fi
######################
# Gestion du web #
######################
if [ -f $QUEUE/webmaster ]
then
$BINDIR/process_web
logger $LOGTAG "Modif webmaster."
fi
if [ -f $QUEUE/webreplic ]
then
$BINDIR/process_web
logger $LOGTAG "Replication du web."
fi
######################
# Groupes cyberecole #
######################
if [ -f $QUEUE/cybgroups ]
then
rm -rf $QUEUE/cybgroups
$BINDIR/process_cybgroups
logger $LOGTAG "Modif groupes cyberecole."
fi
######################
# VNC #
######################
if [ -f $QUEUE/vnc ]
then
rm -rf $QUEUE/vnc
$BINDIR/process_vnc
logger $LOGTAG "Lancement de process_vnc."
fi
######################
# DHCP #
######################
if [ -f $QUEUE/dhcp ]
then
rm -rf $QUEUE/dhcp
$BINDIR/process_dhcp
logger $LOGTAG "Lancement de process_dhcp."
fi
#####################
# BACKUP #
#####################
if [ -e $QUEUE/backup ]
then
rm -f $QUEUE/backup
$BINDIR/backup
fi
#####################
# UPS #
#####################
$BINDIR/process_ups
#####################
# ADSL #
#####################
if [ -f $QUEUE/adsl ]
then
etat=`cat $QUEUE/adsl`
rm -rf $QUEUE/adsl
if [ "$etat" = "START" ]
then
/etc/rc.d/init.d/adsl restart
logger $LOGTAG "Lancement de la connexion ADSL."
fi
if [ "$etat" = "STOP" ]
then
/etc/rc.d/init.d/adsl stop
logger $LOGTAG "ARRET de la connexion ADSL."
fi
fi
#####################################
# Modification des paramΘtres ADSL #
#####################################
if [ -f $QUEUE/adsl-params ]
then
$BINDIR/mkadsl
rm -rf $QUEUE/adsl-params
logger $LOGTAG "Modification du compte ADSL."
fi
#####################################
# Stop/Restart the tunnel #
#####################################
if [ -f $QUEUE/tunnel_stop ]
then
rm -rf $QUEUE/tunnel_stop
logger $LOGTAG "ARRET VOLONTAIRE DU TUNEL PAR HADMIN"
killall run_tunnel
sleep 1
killall vtund
fi
if [ -f $QUEUE/tunnel_restart ]
then
rm -rf $QUEUE/tunnel_restart
killall run_tunnel
sleep 1
killall vtund
sleep 1
$SLIS_BINDIR/run_tunnel&
fi
#####################################
# services_startup #
#####################################
if [ -f $QUEUE/services_startup ]
then
bash $QUEUE/services_startup
rm -rf $QUEUE/services_startup
logger $LOGTAG "Services startup modified."
fi
#####################################
# restoring #
#####################################
if [ -f $QUEUE/restore1 ]
then
logger $LOGTAG "Restoring from 1.x."
bash $BINDIR/restore-1.x.bash
rm -rf $QUEUE/restore1
fi
if [ -f $QUEUE/restore2 ]
then
logger $LOGTAG "Restoring from 2.x."
bash $BINDIR/restore-2.x.bash > /var/log/slis_restore 2>> /var/log/slis_restore
rm -rf $QUEUE/restore2
fi
#####################
# SQL Replica #
#####################
if [ -x $BINDIR/valid ]
then
$BINDIR/valid
fi
####################
# Envoi du rapport #
####################
if [ -s $QUEUE/result ]
then
cat $QUEUE/result | mail -s "Resultats de votre validation" $MAIL_ADMIN
fi
rm -rf $QUEUE/result
rm -rf $QUEUE/lock
logger $LOGTAG "Processing queue termine."