Commit 49f5893a authored by Vitaly Lipatov's avatar Vitaly Lipatov

add etersoft's admin scripts

parent c6235935
#!/bin/sh
if [ "$1" = "-d" ] ; then
shift
iptables -D -s $1 -j DROP
exit
fi
# -A
# -I 1 - первым
iptables -I INPUT 1 -s $1 -j DROP
echo $1 >> $0.log
#!/usr/bin/perl
use IMAP::Admin;
if (scalar(@ARGV) < 1) {
print "usage: $0 mailbox [mailbox ...]"
}
$imap = IMAP::Admin->new('Server' => 'localhost',
'Login' => 'cyrus',
'Password' => 'Wetcyr23');
$adminlogin = "cyrus";
#$imap = IMAP::Admin->new('Server' => 'server',
# 'Login' => 'admin@office.etersoft.ru',
# 'Password' => 'Wetcyr23');
#$adminlogin = "admin\@office.etersoft.ru";
foreach $mailbox (@ARGV) {
$mailbox="user/$mailbox";
print "$mailbox\n";
$err = $imap->set_acl($mailbox, $adminlogin, "lrswipdca");
if ($err != 0) {
print "Error occurred SAM for $mailbox\n\t$imap->{'Error'}\n";
next;
}
$err = $imap->delete($mailbox);
if ($err != 0) {
print "Error occurred destroying $mailbox\n\t$imap->{'Error'}\n";
}
@list = $imap->list($mailbox);
print @list;
}
#!/usr/bin/perl
use IMAP::Admin;
$imap = IMAP::Admin->new('Server' => 'server',
'Login' => 'cyrus',
'Password' => 'Wetcyr23',
'Port' => 143, # (143 is default),
'Separator' => ".", # default is a period
'CRAM' => 0, # off by default, can be 0,1,2
'SSL' => 1, # off by default
# and any of the SSL_ options from IO::Socket::SSL
);
$err = $imap->create("user.bob");
if ($err != 0) {
print "$imap->{'Error'}\n";
}
if ($err != 0) {
print $imap->error;
}
$err = $imap->create("user.bob", "green");
$err = $imap->delete("user.bob");
$err = $imap->h_delete("user.bob");
$err = $imap->subscribe("user.bob");
$err = $imap->unsubscribe("user.bob");
$err = $imap->rename("bboard", "newbboard");
@quota = $imap->get_quotaroot("user.bob");
@quota = $imap->get_quota("user.bob");
$err = $imap->set_quota("user.bob", 10000);
@acl = $imap->get_acl("user.bob");
%acl = $imap->get_acl("user.bob");
$err = $imap->set_acl("user.bob", "admin", "lrswipdca", "joe", "lrs");
$err = $imap->delete_acl("user.bob", "joe", "admin");
@list = $imap->list("user.bob");
@list = $imap->list("user.b*");
print $imap->{'Capability'}; # this contains the Capabilities reply from the IMAP server
$imap->close; # close open imap connection
#!/bin/sh
DB_USER=mail
DB_PASS=Wetcyr23
DB_HOST=localhost
DB=mail
IMAPDIR=/var/spool/imap/domain
mysql_query()
{
echo "$@" |
mysql -s -N --default-character-set=utf8 --user=$DB_USER --password=$DB_PASS --host $DB_HOST $DB
}
check_user()
{
local RES=$(mysql_query "SELECT alias FROM virtual WHERE alias = '$1@$DOMAIN' LIMIT 1")
test -n "$RES" #&& echo $RES
}
#check_user info && echo OK
#for i in $(mysql_query "SELECT alias FROM virtual WHERE alias LIKE '%@$DOMAIN'") ; do
# ULOGIN=$(echo $i | cut -d@ -f1)
# echo $ULOGIN
#done
remove_from_domain()
{
#DOMAIN=office.etersoft.ru
FLETTER=$(echo $DOMAIN | cut -c1)
for i in $IMAPDIR/$FLETTER/$DOMAIN/?/user/* ; do
ULOGIN=$(basename $i)
#test "$i" -nt "$i/cyrus.index" && echo OK
DTIME=$(stat -c "%Z" $i)
FTIME=$(stat -c "%Z" $i/cyrus.index)
#test $DTIME = $FTIME && echo OK
echo "$ULOGIN - $DTIME - $FTIME - $i"
check_user $ULOGIN || ./autocyradm-delete.pl $ULOGIN@$DOMAIN
done
}
for i in $IMAPDIR/?/* ; do
DOMAIN=$(basename $i)
echo $DOMAIN
remove_from_domain
done
#!/bin/sh
IMAPDIR=/var/spool/imap/domain
find $IMAPDIR -type d -print0 | xargs -0 -n 10 rmdir -v
#!/bin/sh
EMAIL=$1
mailq | grep "$EMAIL" | sed -e "s| .*||g" | sed -e "s|\*\$||g" | sort -u | postsuper -d -
mailq | grep -v '^ *(' | awk 'BEGIN { RS = "" }
# $7=sender, $8=recipient1, $9=recipient2
{ if ($8 == "xjg2009@jandex.ru" && $9 == "")
print $1 }
' | tr -d '*!' | postsuper -d -
#!/bin/sh
MAILFROM=$1
if [ -z "$MAILFROM" ] ; then
echo "run with email address as first arg"
exit 1
fi
mailq | grep -v '^ *(' | awk 'BEGIN { RS = "" }
# $7=sender, $8=recipient1, $9=recipient2
{ if ($8 == "$MAILFROM" && $9 == "")
print $1 }
' | tr -d '*!' | postsuper -d -
#!/bin/sh
for i in $(pidof xulrunner) ; do
kill $i
done
sleep 1
for i in $(pidof xulrunner) ; do
kill -9 $i
done
#!/bin/sh
clamscan -i -r /home/*/.wine*
#!/bin/sh
# Remove obsoletes objects and rpm packages
#VERBOSE=1
MAINDIR=/home
cd $MAINDIR || exit 1
for i in $(echo *) ; do
#for i in pav ; do
test -L "$MAINDIR/$i/" && continue
test -d "$MAINDIR/$i/" || continue
test -n "$VERBOSE" && echo Clean for user $i
find $MAINDIR/$i/ -ctime +2 -name ".nfs*" -type f -print0 | xargs -0 rm -vf
find $MAINDIR/$i/ -maxdepth 1 -ctime +20 -name ".xsession-errors*" -type f -print0 | xargs -0 rm -vf
find $MAINDIR/$i/ -maxdepth 1 -ctime +60 -name ".DCOPserver*" -type f -print0 | xargs -0 rm -vf
find $MAINDIR/$i/ -maxdepth 1 -ctime +300 -name ".xauth*" -type f -print0 | xargs -0 rm -vf
# TODO: *-buildroot in $i/tmp
if [ -d $MAINDIR/$i/.nx ] ; then
find $MAINDIR/$i/.nx -maxdepth 2 -ctime +30 -name "session" -type f -print0 | xargs -0 rm -vf
find $MAINDIR/$i/.nx -maxdepth 2 -ctime +10 -name "*C-*" -type d -print0 | xargs -0 rm -vrf
fi
for n in $(find $MAINDIR/$i/ -maxdepth 1 -name ".DCOPserver*" -type l ) ; do
test -f $n || rm -vf $n
done
test -d "$MAINDIR/$i/.thumbnails" && find "$MAINDIR/$i/.thumbnails" -ctime +60 -type f -print0 | xargs -0 rm -vf
#test -d "$MAINDIR/$i/RPM/SRPMS" && find /srv/$i/RPM/SRPMS -ctime +30 -name "*.rpm" -print0 | xargs -0 rm -vf
test -d "$MAINDIR/$i/.rcc/comm" && find "$MAINDIR/$i/.rcc/comm" -name "*.sock" -ctime +60 -type f -print0 | xargs -0 rm -vf
# clean $HOME for PREF objects
for o in .gimp-2.2 .gimp-2.4 ; do
test -n "$VERBOSE" && echo Clean $MAINDIR/$i with $o suffix
find $MAINDIR/$i -ctime +60 -name "$o*" -print0 | xargs -0 rm -vrf
done
# clean $HOME/tmp
TMPPRIV=$MAINDIR/$i/tmp
for sd in kde ksocket mc orbit ; do
test -d "$TMPPRIV/$sd-$i" && find "$TMPPRIV/$sd-$i" -ctime +20 -print0 | xargs -0 rm -vrf
done
find $TMPPRIV/plugtmp* -ctime +60 -print0 | xargs -0 rm -vrf
find $TMPPRIV/pulse-* -ctime +60 -print0 | xargs -0 rm -vrf
for n in rpm-tmp mutt .nfs ; do
find $TMPPRIV/ -maxdepth 1 -ctime +20 -name "$n*" -type f -print0 | xargs -0 rm -vf
done
# clean /tmp/.private/USER
TMPPRIV=/tmp/.private/$i
test -d "$TMPPRIV/mc-$i/" && find $TMPPRIV/mc-$i/ -ctime +2 -type f -print0 | xargs -0 rm -vf
test -d "$TMPPRIV" && find $TMPPRIV/ -ctime +45 -type f -print0 | xargs -0 rm -vf
test -d "$TMPPRIV" && find $TMPPRIV/ -ctime +2 -name "Z-*" -type f -print0 | xargs -0 rm -vf
done
# clean /tmp for *.EXT objects
for i in tmp log part ; do
test -n "$VERBOSE" && echo Clean tmp with $i suffix
find /tmp -ctime +40 -name "*.$i" -print0 | xargs -0 rm -vrf
done
# clean /tmp for PREF* objects
for i in linc acroread hsperfdata .nX .ktorrent .Xauth file gpg- ssh- ; do
test -n "$VERBOSE" && echo Clean tmp with $i prefix
find /tmp -ctime +30 -name "$i*" -print0 | xargs -0 rm -vrf
done
get_prev()
{
for i in `seq 1 11 | sort -r -n` ; do
FF=/var/log/wtmp.$i.bz2
test -r $FF || continue
echo Use $FF >/dev/stderr
bzcat $FF
done
}
get_prev >/var/log/wtmp.prev.tmp || exit 1
logintop10 -i /var/log/wtmp.prev.tmp -i /var/log/wtmp -o /var/www/html/logintop10.html -l ru_RU -r
#!/bin/sh
renice_f()
{
renice 2 $@ >/dev/null
}
for i in xulrunner opera konqueror chromium-browser ; do
PIDS=`pidof xulrunner`
test -n "$PIDS" || continue
renice_f $PIDS
done
#!/bin/sh
# Written by Lav (c) 2001, 2002, 2003, 2004, 2008
# Vitaly Lipatov <lav@etersoft.ru>
# 24.12.01, 16.11.03, 30.12.03, 17.12.04
# Обновление Сизифа
# Анализировать код возврата rsync, и если вышел не по ошибке, а все закачал, то запускать с
# Углубленным списком.
# Подключаем конфигурационные параметры
#. ./scripts/config.sh
RPMS=/var/ftp/pub/ALTLinux
DELETE="--delete-after --delete-excluded"
func()
{
RES="1"
echo "Start sync from ALTLinux/$1 to $RPMS/$1"
#until [ $RES = "20" -o $RES = "0" ]
#do
rsync $DELETE --fuzzy --partial --timeout=200 --progress --stats -vbrlt --copy-links \
--exclude "*SRPMS*" \
rsync.altlinux.ru::ALTLinux/$1/ $RPMS/$1/
RES=$?
echo "rsync exit: $RES"
#done
return $RES
}
cd $RPMS/ || exit 1
# we do not update 5.0
for i in 4.0 4.1 5.1 p5 p6 t6; do
# move branches
#mkdir $i/branch/ || continue
#for a in i586 x86_64 x86_32 noarch ; do
# mv $i/$a $i/branch/ || exit
# ln -s branch/$a $i/$a || exit
#done
func $i/branch/i586
func $i/branch/x86_64
#func Sisyphus/x86_32
func $i/branch/noarch
done
func Sisyphus/i586
func Sisyphus/x86_64
#func Sisyphus/x86_32
func Sisyphus/noarch
# for update x86_32
#$RPMS/arepo.sh > $RPMS/arepo.log
#!/bin/sh
# -------------------------------------
# $Id$
# -------------------------------------
# Скрипт удаляющий устаревшие ссылки
# сгенерированные для скачивания файлов
#---------------------------------------
remove_old()
{
# Базовый каталог, где создаются ссылки
DOWNDIR="$1"
DEP="$2"
# Время устаревания, в минутах
#MINAGO=30
#[ -n "$1" ] && MINAGO=$1
#find ${DOWNDIR} -type l -and -cmin +${MINAGO} | xargs rm -f
# Время устаревания, в днях
DAYSAGO=5
test -d ${DOWNDIR} || exit 1
#find ${DOWNDIR} -type f -and -mtime +${DAYSAGO} | grep -v done | xargs rm -f
#find ${DOWNDIR} -type l -and -mtime +${DAYSAGO} | xargs rm -f
# каталог с названием 'done' исключаем!
find ${DOWNDIR} -mindepth $DEP -maxdepth $DEP -type d -and -mtime +${DAYSAGO} | grep -v done | xargs rm -rf
# прежде чем удалить пустые каталоги делаем паузу
# (на случай если он только, что создан, но файлы ещё не успели туда положить)
MPAUSE=1
sleep $(($MPAUSE*70))
find ${DOWNDIR} -type d -and -cmin +$MPAUSE | grep -v done | xargs rmdir -p 2>/dev/null
}
#echo "Disable autoclean: needs rewrite to check directory date"
#
remove_old /var/ftp/pub/download/WINE@Etersoft 4
remove_old /var/ftp/pub/download/SELTA@Etersoft 2
#remove_old ./1
#!/bin/sh
# õÒÁ, ÓËÒÉÐÔ ÎÁÛ£ÌÓÑ × çÁÌÁÔÅÅ :)
DAT=`date +%d/%m/%Y --date='1 days ago'`
test -n "$1" && DAT="$1"
echo $DAT
/usr/sbin/sarg -d $DAT-$DAT
#!/bin/sh
# Добавляет пользователя на указанном хосте и копирует ему ключ.
# Если указан ID контейнера, то добавляет внутри указанного контейнера
# Args; username host [VEID | -l]
docmd()
{
echo "\$ $@"
"$@"
}
fatal()
{
echo "Error: $@"
exit 1
}
USERNAME=$1
HOST=$2
VEID=$3
[ -n "$USERNAME" ] || fatal "Usage: $0 username host [VEID | -l]"
USERKEY=/home/$USERNAME/.ssh/id_dsa.pub
[ -r "$USERKEY" ] || fatal "Can't read ssh key $USERKEY"
ssh $HOST echo || fatal "Host $HOST is not sshed"
ADDKEYCMD="useradd $USERNAME ; su - $USERNAME -c 'mkdir -p ~/.ssh ; chmod 700 ~/.ssh ; touch ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys' ; cat >>/home/$USERNAME/.ssh/authorized_keys"
# copy key in host system
if [ -z "$VEID" ] ; then
echo "Copy key for $USERNAME to $HOST"
cat $USERKEY | docmd ssh $HOST "$ADDKEYCMD"
exit
fi
# show containter list
if [ "$VEID" = "-l" ] ; then
docmd ssh $HOST vzlist
exit
fi
# copy key in VEID container at host system
echo "Copy key for $USERNAME to $HOST, VEID=$VEID"
cat $USERKEY | ssh $HOST "vzctl exec $VEID \"$ADDKEYCMD\""
#!/bin/sh
for i in /home/* ; do
echo $i
if [ -r $i/.Xkbmap ] ; then
if ! cat $i/.Xkbmap | grep -q typo ; then
echo "-option lv3:lwin_switch,misc:typo" >> $i/.Xkbmap
fi
else
cat >$i/.Xkbmap <<EOF
-layout us,ru(winkeys)
-option
-option grp:ctrl_shift_toggle
-option grp_led:scroll
-option lv3:lwin_switch,misc:typo
EOF
fi
done
#!/bin/sh -efu
. shell-error
usage()
{
[ -z "$*" ] || message "$*"
echo >&2 "usage: $PROG <repo_name> <repo_suffix> [{git.eter|git.office}] "
exit 1
}
gen_sources()
{
cat >files/apt/sources.list <<EOF
rpm file:$alt_repo_dir @arch@ classic
rpm file:$alt_repo_dir noarch classic
EOF
cat >files/apt/self.list <<EOF
rpm file:$repo_dir @arch@ addon nonfree
rpm file:$repo_dir noarch addon nonfree
EOF
}
gen_sources_office()
{
cat >files/apt/sources.list <<EOF
rpm file:$alt_repo_dir @arch@ classic
rpm file:$alt_repo_dir noarch classic
#rpm file:$repo_dir @arch@ addon nonfree
#rpm file:$repo_dir noarch addon nonfree
EOF
cat >files/apt/self.list <<EOF
rpm file:$repo_dir @arch@ addon
rpm file:$repo_dir noarch addon
EOF
}
if [ "${1-}" = '--help' ]; then
usage
fi
[ "$#" -le 3 ] || usage 'Too many arguments.'
[ "$#" -ge 2 ] || usage 'Not enough arguments.'
repo="$1"; shift
suffix="$1"; shift
type="${1-git.eter}"
if [ "$type" = "git.eter" ]; then
base_path="/var/ftp/pub/Etersoft/LINUX@Etersoft"
builder=girar-builder
script_suffix=
add_flavour="nonfree"
elif [ "$type" = "git.office" ]; then
base_path="/var/ftp/pvt/Etersoft/LINUX@Etersoft"
builder=girar-office-builder
script_suffix=_office
add_flavour=
else
usage "Invalid repo type"
fi
repo_dir="$base_path/$repo/branch"
alt_repo_dir="/var/ftp/pub/ALTLinux/$repo"
[ -e "$repo_dir" ] && fatal "Repository directory '$repo_dir' already exists."
[ ! -e "$alt_repo_dir" ] && fatal "ALTLinux repository directory '$alt_repo_dir' not exists."
mkdir -p "$repo_dir"
cd "$repo_dir"
mkdir -p files/{i586,x86_64,noarch}/RPMS files/{SRPMS,list,apt}
mkdir -p {i586,x86_64}/{SRPMS.all,SRPMS.addon,RPMS.addon,base}
mkdir -p noarch/{SRPMS.addon,RPMS.addon,base}
if [ "$type" = "git.eter" ]; then
mkdir -p {i586,x86_64,noarch}/RPMS.nonfree
chmod 771 {i586,x86_64,noarch}/RPMS.nonfree
fi
touch files/list/src.list
touch files/list/bin.list
gen_sources$script_suffix
for arch in i586 x86_64 noarch; do
genbasedir \
--architectures="i586 x86_64 noarch" \
--architecture="$arch" \
--archive="$repo" \
--description="Initial $repo" \
--label="$repo" \
--origin="Etersoft" \
--suite="$repo" \
--version="$repo" \
--topdir="$repo_dir" \
--flat --bloat --no-oldhashfile --bz2only --mapi $arch addon $add_flavour
done
chown $builder:builder -R .
echo "Please do not use gcc compiler on 'server' host"
\ No newline at end of file
#!/bin/sh
cat <<EOF
***************** Warning! Warning! Warning! ********************
You do try to get root access to MAIN Etersoft's SERVER!
Think twice before it!
Check your mind and hand!
Press Ctrl-C immediately if you are in doubt!
(or press Enter to continue with caution...)
Press Ctrl-C
EOF
read
exec /usr/bin/sudo "$@"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment