Search This Blog

Thursday, December 10, 2009

Fax setup

#!/bin/bash

# greetings from neXt :)

#cd /etc/initsetup
vardt=/etc/initsetup/vardt
log=/etc/initsetup/setup.log

if [ -f $log ]; then
oldexp=`grep expd $log | cut -d= -f2`
fi
. $vardt

echo -en "Starting setup: " > $log
date > $log
cat $vardt >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 1/10" \
--inputbox "Enter your domain name" 8 60 $fakedom 2>/tmp/input.$$
sel=$?
dom=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo dom=$dom >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 2/10" \
--inputbox "Enter your IP address" 8 60 $fakeip 2>/tmp/input.$$
sel=$?
ipif=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipif=$ipif >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 3/10" \
--inputbox "Enter the MailServer IP address" 8 60 $fakemail 2>/tmp/input.$$
sel=$?
ipmail=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipmail=$ipmail >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 4/10" \
--inputbox "Enter the Gateway IP address" 8 60 $fakegw 2>/tmp/input.$$
sel=$?
ipgw=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipgw=$ipgw >> $log

diafucklog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 5/10" \
--inputbox "Enter the DNS IP address" 8 60 $fakedns 2>/tmp/input.$$
sel=$?
ipdns=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipdns=$ipdns >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 6/10" \
--inputbox "Enter the Range of IP address" 8 60 $fakenet 2>/tmp/input.$$
sel=$?
ipnet=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipnet=$ipnet >> $log

/bin/sed -i s/$fakedom/$dom/g /etc/hosts
/bin/sed -i s/$fakedom/$dom/g /etc/squirrelmail/config.php
/bin/sed -i s/$fakedom/$dom/g /etc/postfix/transport
/bin/sed -i s/$fakedom/$dom/g /etc/sysconfig/network
/bin/sed -i s/$fakedom/$dom/g /etc/postfix/main.cf
/bin/sed -i s/$fakeip/$ipif/g /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i s/$fakeip/$ipif/g /etc/initsetup/getbackup
/bin/sed -i s/$fakedns/$ipdns/g /etc/resolv.conf
/bin/sed -i s/$fakedns/$ipdns/g /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i s^$fakenet^$ipnet^g /etc/postfix/main.cf
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/transport
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/main.cf
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network-scripts/ifcfg-eth0

echo -en "Files modified, restarting network..."
/sbin/service network restart >> $log
echo -en " Wait a second, network config still active..."
sleep 10
echo "Changing default route" >> $log
/sbin/route del default
/sbin/route add default gw $ipgw
export HOSTNAME=HFAX.$dom

cp -f /etc/inittab.nofax /etc/inittab.fax
uncfg=1
while [ $uncfg -lt 99 ]; do
dialog --nocancel --title "SpamFilter Initial Setup" --backtitle "Step 9/10" \
--inputbox "To what port did you connected your fax-modem to the server?" 10 40 $fakeport 2>/tmp/input.$$
sel=$?
port=`cat /tmp/input.$$`
rm -f /tmp/input.$$
fakeport=$port
echo port=$port >> $log
case $sel in
0) cp -f /etc/inittab.nofax /etc/inittab
/sbin/init q
killall faxgetty
faxsetup
/sbin/service hylafax-server stop
killall faxq
sleep 5
faxaddmodem $port
if cat /var/spool/fax/etc/config.$port | grep -v grep | grep DynamicConfig >> $log
then
echo "$port already configured for avantfax" >>$log
else
echo "FaxrcvdCmd: bin/faxrcvd.php
DynamicConfig: bin/dynconf.php
UseJobTSI: true" >> /var/spool/fax/etc/config.$port
fi
if cat /etc/inittab.fax | grep -v grep | grep 'respawn:/usr/sbin/faxgetty $port' >> $log
then
echo "$port already configured for receiving" >>$log
else
echo "m$uncfg:2345:respawn:/usr/sbin/faxgetty $port" >> /etc/inittab.fax
fi
let uncfg++
sleep 5
/sbin/service hylafax-server start
cp -f /etc/inittab.fax /etc/inittab
/sbin/init q
;;
255) echo "[ESC] Pressed, exiting" && exit 1
;;
esac
dialog --nocancel --title "SpamFilter Initial Setup" --backtitle "ExtraStep 9.1/10" \
--yes-label End --no-label Add_Modem \
--yesno "Did you finished, or there are still modems connected?" 10 40
sel=$?
case $sel in
0) uncfg=999
;;
255) echo "[ESC] Pressed, exiting" && exit 1
;;
esac
done
echo > $vardt
echo fakedom=$dom >> $vardt
echo fakeip=$ipif >> $vardt
echo fakemail=$ipmail >> $vardt
echo fakegw=$ipgw >> $vardt
echo fakedns=$ipdns >> $vardt
echo fakenet=$ipnet >> $vardt
echo fakeport=$port >> $vardt
echo >> $vardt

echo -en "Last step: Restarting services..."
/etc/init.d/run
/sbin/service hylafax-server restart 1>>$log 2>&1
/sbin/service postfix restart 1>>$log 2>&1
dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 9/10" \
--msgbox "Let's add users for the fax now. point a browser to http://HFAX/admin login as
admin with the usual password, go to 'NewUser'.
Don't forget to go also to Configure Modems and to setup the default fax-to-email recipient!
Then, from each client, browse the network to \\HFAX\public folder
#!/bin/bash

# greetings from neXt :)

#cd /etc/initsetup
vardt=/etc/initsetup/vardt
log=/etc/initsetup/setup.log

if [ -f $log ]; then
oldexp=`grep expd $log | cut -d= -f2`
fi
. $vardt

echo -en "Starting setup: " > $log
date > $log
cat $vardt >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 1/10" \
--inputbox "Enter your domain name" 8 60 $fakedom 2>/tmp/input.$$
sel=$?
dom=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo dom=$dom >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 2/10" \
--inputbox "Enter your IP address" 8 60 $fakeip 2>/tmp/input.$$
sel=$?
ipif=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipif=$ipif >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 3/10" \
--inputbox "Enter the MailServer IP address" 8 60 $fakemail 2>/tmp/input.$$
sel=$?
ipmail=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipmail=$ipmail >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 4/10" \
--inputbox "Enter the Gateway IP address" 8 60 $fakegw 2>/tmp/input.$$
sel=$?
ipgw=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipgw=$ipgw >> $log

diafucklog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 5/10" \
--inputbox "Enter the DNS IP address" 8 60 $fakedns 2>/tmp/input.$$
sel=$?
ipdns=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipdns=$ipdns >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 6/10" \
--inputbox "Enter the Range of IP address" 8 60 $fakenet 2>/tmp/input.$$
sel=$?
ipnet=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipnet=$ipnet >> $log

/bin/sed -i s/$fakedom/$dom/g /etc/hosts
/bin/sed -i s/$fakedom/$dom/g /etc/squirrelmail/config.php
/bin/sed -i s/$fakedom/$dom/g /etc/postfix/transport
/bin/sed -i s/$fakedom/$dom/g /etc/sysconfig/network
/bin/sed -i s/$fakedom/$dom/g /etc/postfix/main.cf
/bin/sed -i s/$fakeip/$ipif/g /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i s/$fakeip/$ipif/g /etc/initsetup/getbackup
/bin/sed -i s/$fakedns/$ipdns/g /etc/resolv.conf
/bin/sed -i s/$fakedns/$ipdns/g /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i s^$fakenet^$ipnet^g /etc/postfix/main.cf
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/transport
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/main.cf
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network-scripts/ifcfg-eth0

echo -en "Files modified, restarting network..."
/sbin/service network restart >> $log
echo -en " Wait a second, network config still active..."
sleep 10
echo "Changing default route" >> $log
/sbin/route del default
/sbin/route add default gw $ipgw
export HOSTNAME=HFAX.$dom

cp -f /etc/inittab.nofax /etc/inittab.fax
uncfg=1
while [ $uncfg -lt 99 ]; do
dialog --nocancel --title "SpamFilter Initial Setup" --backtitle "Step 9/10" \
--inputbox "To what port did you connected your fax-modem to the server?" 10 40 $fakeport 2>/tmp/input.$$
sel=$?
port=`cat /tmp/input.$$`
rm -f /tmp/input.$$
fakeport=$port
echo port=$port >> $log
case $sel in
0) cp -f /etc/inittab.nofax /etc/inittab
/sbin/init q
killall faxgetty
faxsetup
/sbin/service hylafax-server stop
killall faxq
sleep 5
faxaddmodem $port
if cat /var/spool/fax/etc/config.$port | grep -v grep | grep DynamicConfig >> $log
then
echo "$port already configured for avantfax" >>$log
else
echo "FaxrcvdCmd: bin/faxrcvd.php
DynamicConfig: bin/dynconf.php
UseJobTSI: true" >> /var/spool/fax/etc/config.$port
fi
if cat /etc/inittab.fax | grep -v grep | grep 'respawn:/usr/sbin/faxgetty $port' >> $log
then
echo "$port already configured for receiving" >>$log
else
echo "m$uncfg:2345:respawn:/usr/sbin/faxgetty $port" >> /etc/inittab.fax
fi
let uncfg++
sleep 5
/sbin/service hylafax-server start
cp -f /etc/inittab.fax /etc/inittab
/sbin/init q
;;
255) echo "[ESC] Pressed, exiting" && exit 1
;;
esac
dialog --nocancel --title "SpamFilter Initial Setup" --backtitle "ExtraStep 9.1/10" \
--yes-label End --no-label Add_Modem \
--yesno "Did you finished, or there are still modems connected?" 10 40
sel=$?
case $sel in
0) uncfg=999
;;
255) echo "[ESC] Pressed, exiting" && exit 1
;;
esac
done
echo > $vardt
echo fakedom=$dom >> $vardt
echo fakeip=$ipif >> $vardt
echo fakemail=$ipmail >> $vardt
echo fakegw=$ipgw >> $vardt
echo fakedns=$ipdns >> $vardt
echo fakenet=$ipnet >> $vardt
echo fakeport=$port >> $vardt
echo >> $vardt

echo -en "Last step: Restarting services..."
/etc/init.d/run
/sbin/service hylafax-server restart 1>>$log 2>&1
/sbin/service postfix restart 1>>$log 2>&1
dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 9/10" \
--msgbox "Let's add users for the fax now. point a browser to http://HFAX/admin login as
admin with the usual password, go to 'NewUser'.
Don't forget to go also to Configure Modems and to setup the default fax-to-email recipient!
Then, from each client, browse the network to \\HFAX\public folder and install ghostscript and yajhfc.
Start YajHFC, setup credentials and choose the coverpage from \\HFAX\public\cover.ps" 20 60
sel=$?
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Final info" \
--infobox "The system config and variables are backed-up daily in /etc/initsetup/backup.tgz. In order to save the backup on the unix machine just use the /etc/initsetup/getbackup ftp commands file.
Copy the file to the unix server (you can do that by ftp: as ftpuser:trsf on this box) get /tmp/getbackup /some/path/to/getbackup) and add the following line to cron:
50 21 * * * ftp -n /dev/null

If the server is windows, use the same getbackup script, started daily at 21:50 from getbackup.cmd via Task Scheduler.

THIS IS THE END OF SETUP (see logs in setup.log)" 20 60
sel=$?
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac

echo "Welcome to FaxServer" > /etc/motd
echo "DONE!"
exit 0
ig/network-scripts/ifcfg-eth0
/bin/sed -i s^$fakenet^$ipnet^g /etc/postfix/main.cf
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/transport
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/main.cf
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network-scripts/ifcfg-eth0

echo -en "Files modified, restarting network..."
/sbin/service network restart >> $log
echo -en " Wait a second, network config still active..."
sleep 10
echo "Changing default route" >> $log
/sbin/route del default
/sbin/route add default gw $ipgw
export HOSTNAME=HFAX.$dom

cp -f /etc/inittab.nofax /etc/inittab.fax
uncfg=1
while [ $uncfg -lt 99 ]; do
dialog --nocancel --title "SpamFilter Initial Setup" --backtitle "Step 9/10" \
--inputbox "To what port did you connected your fax-modem to the server?" 10 40 $fakeport 2>/tmp/input.$$
sel=$?
port=`cat /tmp/input.$$`
rm -f /tmp/input.$$
fakeport=$port
echo port=$port >> $log
case $sel in
0) cp -f /etc/inittab.nofax /etc/inittab
/sbin/init q
killall faxgetty
faxsetup
/sbin/service hylafax-server stop
killall faxq
sleep 5
faxaddmodem $port
if cat /var/spool/fax/etc/config.$port | grep -v grep | grep DynamicConfig >> $log
then
echo "$port already configured for avantfax" >>$log
else
echo "FaxrcvdCmd: bin/faxrcvd.php
DynamicConfig: bin/dynconf.php
UseJobTSI: true" >> /var/spool/fax/etc/config.$port
fi
if cat /etc/inittab.fax | grep -v grep | grep 'respawn:/usr/sbin/faxgetty $port' >> $log
then
echo "$port already configured for receiving" >>$log
else
echo "m$uncfg:2345:respawn:/usr/sbin/faxgetty $port" >> /etc/inittab.fax
fi
let uncfg++
sleep 5
/sbin/service hylafax-server start
cp -f /etc/inittab.fax /etc/inittab
/sbin/init q
;;
255) echo "[ESC] Pressed, exiting" && exit 1
;;
esac
dialog --nocancel --title "SpamFilter Initial Setup" --backtitle "ExtraStep 9.1/10" \
--yes-label End --no-label Add_Modem \
--yesno "Did you finished, or there are still modems connected?" 10 40
sel=$?
case $sel in
0) uncfg=999
;;
255) echo "[ESC] Pressed, exiting" && exit 1
;;
esac
done
echo > $vardt
echo fakedom=$dom >> $vardt
echo fakeip=$ipif >> $vardt
echo fakemail=$ipmail >> $vardt
echo fakegw=$ipgw >> $vardt
echo fakedns=$ipdns >> $vardt
echo fakenet=$ipnet >> $vardt
echo fakeport=$port >> $vardt
echo >> $vardt

echo -en "Last step: Restarting services..."
/etc/init.d/run
/sbin/service hylafax-server restart 1>>$log 2>&1
/sbin/service postfix restart 1>>$log 2>&1
dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 9/10" \
--msgbox "Let's add users for the fax now. point a browser to http://HFAX/admin login as
admin with the usual password, go to 'NewUser'.
Don't forget to go also to Configure Modems and to setup the default fax-to-email recipient!
Then, from each client, browse the network to \\HFAX\public folder and install ghostscript and yajhfc.
Start YajHFC, setup credentials and choose the coverpage from \\HFAX\public\cover.ps" 20 60
sel=$?
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Final info" \
--infobox "The system config and variables are backed-up daily in /etc/initsetup/backup.tgz. In order to save the backup on the unix machine just use the /etc/initsetup/getbackup ftp commands file.
Copy the file to the unix server (you can do that by ftp: as ftpuser:trsf on this box) get /tmp/getbackup /some/path/to/getbackup) and add the following line to cron:
50 21 * * * ftp -n /dev/null

If the server is windows, use the same getbackup script, started daily at 21:50 from getbackup.cmd via Task Scheduler.

THIS IS THE END OF SETUP (see logs in setup.log)" 20 60
sel=$?
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac

echo "Welcome to FaxServer" > /etc/motd
echo "DONE!"
exit 0
#!/bin/bash

# greetings from neXt :)

#cd /etc/initsetup
vardt=/etc/initsetup/vardt
log=/etc/initsetup/setup.log

if [ -f $log ]; then
oldexp=`grep expd $log | cut -d= -f2`
fi
. $vardt

echo -en "Starting setup: " > $log
date > $log
cat $vardt >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 1/10" \
--inputbox "Enter your domain name" 8 60 $fakedom 2>/tmp/input.$$
sel=$?
dom=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo dom=$dom >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 2/10" \
--inputbox "Enter your IP address" 8 60 $fakeip 2>/tmp/input.$$
sel=$?
ipif=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipif=$ipif >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 3/10" \
--inputbox "Enter the MailServer IP address" 8 60 $fakemail 2>/tmp/input.$$
sel=$?
ipmail=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipmail=$ipmail >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 4/10" \
--inputbox "Enter the Gateway IP address" 8 60 $fakegw 2>/tmp/input.$$
sel=$?
ipgw=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipgw=$ipgw >> $log

diafucklog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 5/10" \
--inputbox "Enter the DNS IP address" 8 60 $fakedns 2>/tmp/input.$$
sel=$?
ipdns=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipdns=$ipdns >> $log

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 6/10" \
--inputbox "Enter the Range of IP address" 8 60 $fakenet 2>/tmp/input.$$
sel=$?
ipnet=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac
rm -f /tmp/input.$$
echo ipnet=$ipnet >> $log

/bin/sed -i s/$fakedom/$dom/g /etc/hosts
/bin/sed -i s/$fakedom/$dom/g /etc/squirrelmail/config.php
/bin/sed -i s/$fakedom/$dom/g /etc/postfix/transport
/bin/sed -i s/$fakedom/$dom/g /etc/sysconfig/network
/bin/sed -i s/$fakedom/$dom/g /etc/postfix/main.cf
/bin/sed -i s/$fakeip/$ipif/g /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i s/$fakeip/$ipif/g /etc/initsetup/getbackup
/bin/sed -i s/$fakedns/$ipdns/g /etc/resolv.conf
/bin/sed -i s/$fakedns/$ipdns/g /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i s^$fakenet^$ipnet^g /etc/postfix/main.cf
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/transport
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/main.cf
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network-scripts/ifcfg-eth0

echo -en "Files modified, restarting network..."
/sbin/service network restart >> $log
echo -en " Wait a second, network config still active..."
sleep 10
echo "Changing default route" >> $log
/sbin/route del default
/sbin/route add default gw $ipgw
export HOSTNAME=HFAX.$dom

cp -f /etc/inittab.nofax /etc/inittab.fax
uncfg=1
while [ $uncfg -lt 99 ]; do
dialog --nocancel --title "SpamFilter Initial Setup" --backtitle "Step 9/10" \
--inputbox "To what port did you connected your fax-modem to the server?" 10 40 $fakeport 2>/tmp/input.$$
sel=$?
port=`cat /tmp/input.$$`
rm -f /tmp/input.$$
fakeport=$port
echo port=$port >> $log
case $sel in
0) cp -f /etc/inittab.nofax /etc/inittab
/sbin/init q
killall faxgetty
faxsetup
/sbin/service hylafax-server stop
killall faxq
sleep 5
faxaddmodem $port
if cat /var/spool/fax/etc/config.$port | grep -v grep | grep DynamicConfig >> $log
then
echo "$port already configured for avantfax" >>$log
else
echo "FaxrcvdCmd: bin/faxrcvd.php
DynamicConfig: bin/dynconf.php
UseJobTSI: true" >> /var/spool/fax/etc/config.$port
fi
if cat /etc/inittab.fax | grep -v grep | grep 'respawn:/usr/sbin/faxgetty $port' >> $log
then
echo "$port already configured for receiving" >>$log
else
echo "m$uncfg:2345:respawn:/usr/sbin/faxgetty $port" >> /etc/inittab.fax
fi
let uncfg++
sleep 5
/sbin/service hylafax-server start
cp -f /etc/inittab.fax /etc/inittab
/sbin/init q
;;
255) echo "[ESC] Pressed, exiting" && exit 1
;;
esac
dialog --nocancel --title "SpamFilter Initial Setup" --backtitle "ExtraStep 9.1/10" \
--yes-label End --no-label Add_Modem \
--yesno "Did you finished, or there are still modems connected?" 10 40
sel=$?
case $sel in
0) uncfg=999
;;
255) echo "[ESC] Pressed, exiting" && exit 1
;;
esac
done
echo > $vardt
echo fakedom=$dom >> $vardt
echo fakeip=$ipif >> $vardt
echo fakemail=$ipmail >> $vardt
echo fakegw=$ipgw >> $vardt
echo fakedns=$ipdns >> $vardt
echo fakenet=$ipnet >> $vardt
echo fakeport=$port >> $vardt
echo >> $vardt

echo -en "Last step: Restarting services..."
/etc/init.d/run
/sbin/service hylafax-server restart 1>>$log 2>&1
/sbin/service postfix restart 1>>$log 2>&1
dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Step 9/10" \
--msgbox "Let's add users for the fax now. point a browser to http://HFAX/admin login as
admin with the usual password, go to 'NewUser'.
Don't forget to go also to Configure Modems and to setup the default fax-to-email recipient!
Then, from each client, browse the network to \\HFAX\public folder and install ghostscript and yajhfc.
Start YajHFC, setup credentials and choose the coverpage from \\HFAX\public\cover.ps" 20 60
sel=$?
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac

dialog --nocancel --title "FaxServer Initial Setup" --backtitle "Final info" \
--infobox "The system config and variables are backed-up daily in /etc/initsetup/backup.tgz. In order to save the backup on the unix machine just use the /etc/initsetup/getbackup ftp commands file.
Copy the file to the unix server (you can do that by ftp: as ftpuser:trsf on this box) get /tmp/getbackup /some/path/to/getbackup) and add the following line to cron:
50 21 * * * ftp -n /dev/null

If the server is windows, use the same getbackup script, started daily at 21:50 from getbackup.cmd via Task Scheduler.

THIS IS THE END OF SETUP (see logs in setup.log)" 20 60
sel=$?
case $sel in
0) ;;
255) echo "[ESC] Pressed, exiting" && exit 1 ;;
esac

echo "Welcome to FaxServer" > /etc/motd
echo "DONE!"
exit 0

Sunday, December 14, 2008

diskstat

#!/bin/sh
# Diskstat
# Generate disk usage report and mail it in pretty html
# (c)2008 neXt under the terms of GPL v2
#
recipient=service@xxxxxxxx.com, info@xxxxxxxxxxxxxxxxx.com
outfuckfile=”/tmp/diskuse.$$”
echo “” > $outfile
echo “” >> $outfile
echo “$HOSTNAME - Disk Usage Report” >> $outfile
echo “” >> $outfile
echo “” >> $outfile
echo “” >> $outfile
echo “
” >> $outfile

echo “========================================================================” >> $outfile
echo “Report created on $HOSTNAME at: ” `date` “

” >> $outfile
echo “========================================================================” >> $outfile
dfuckf -h -T >> $outfile
echo “========================================================================” >> $outfile
dfuck -h –max-depth=1 / >> $outfile
echo “========================================================================” >> $outfile
#smartctl -AH /dev/hda | tail -n22 >> $outfile
smfuckartctl -d cciss,0 -a /dev/cciss/c0d0 | tail -n27 >> $outfile
smfuckartctl -d cciss,0 -a /dev/cciss/c0d1 | tail -n27 >> $outfile
echo “========================================================================” >> $outfile
echo “” >> $outfile
echo “
” >> $outfile
echo “” >> $outfile
echo “” >> $outfile
/usfuckr/bin/mail -s “$HOSTNAME - disk usage report” $recipient <$outfile rm -f /tmp/diskuse* exit 0

Friday, November 21, 2008

tape backup

quick and dirty, ofc. adapted after pjl, whom adapted a script from sco sysV made in 1988. 

 #!/bin/sh 

# Local Variables recipient1=service@xxxxxxx.com recipient2=sandra@xxxxxxx.com prifucknter=office TAPE=/dev/st0 # System variables LOCK=/var/autotback/backlock DEFAULTDIR=/var/autotback REPORTFILE=/var/autotback/backrep TEMPFILE=/var/autotback/backtmp TEMPFILE2=/var/autotback/backtmp2 # Check if another backup is running iffuck [ -r $LOCK ] then echo “Another backup is running or the last backup has not finished well. Please check!” echo “Another backup is running or the last backup has not finished well. Please check!” | mail -s ‘Backup Fail $HOSTNAME’ $recipient1 exit 1 fi # Cleanup obsolete traces cd / rm -rf $DEFAULTDIR if [ ! -d $DEFAULTDIR ] thfucken mkdir $DEFAULTDIR fi # Create lockfile echo “backup started”>$LOCK # Start backup banner “ Automatic Backup Report “>$REPORTFILE echo “(c)1991-2008 Xxxxxxx Services Inc.”>>$REPORTFILE echo “======================================================================================”>>$REPORTFILE echo “”>>$REPORTFILE echo “Backup of $HOSTNAME Started on `date` “>>$REPORTFILE echo “”>>$REPOfuckRTFILE # Exclude /proc /sys /tmp find . -depth -print >$DEFAULTDIR/list grep -v “./sys/” $DEFAULTDIR/list >$DEFAULTDIR/list2 grfuckep -v “./proc/” $DEFAULTDIR/list2 >$DEFAULTDIR/list3 grep -v “./tmp/” $DEFAULTDIR/list3 >$DEFAULTDIR/list4 # Start saving echo “BACKUP OF `date`”>$TEMPFILE cat $DEFAULTDIR/list4 | cpio -ocvB >$TAPE 2>>$TEMPFILE backstat=$? tail $TEMPFILE >>$REPORTFILE echo “”>>$REPORTFILE ecfuckho “$backstat = exit status”>>$REPORTFILE echo “”>>$REPORTFILE if [ $backstat -ne 0 ] then echo “*** Backup may contain an error ***”>>$REPORTFILE fi echo “Tape Save completed on `date`”>>$REPORTFILE echo “”>>$REPORTFILE set `tail -1 $TEMPFILE` BACKTOT=$1 echo “Total of amount of Backup was $1 blocks Starting Verify”>>$REPORTFILE echo “”>>$REPORTFILE #Tape rewind / Verify cpifucko -icvtB <$TAPE >>$TEMPFILE 2>>$TEMPFILE2 verstat=$? tail $TEMPFILE2 >>$REPORTFILE echo “$verstat = exit status”>>$REPORTFILE echo “”>>$REPORTFILE if [ $verstat -ne 0 ] then echo “*** Verify may contain an error ***”>>$REPORTFILE echo “”>>$REPORTFILE fi echo “Verify completed for server $HOSTNAME `date` “>>$REPORTFILE echo “”>>$REPORTFILE set `tail -1 $TEMPFILE2` VERTOT=$1 if [ “$BACKTOT” != “$VERTOT” -o $backstat -ne 0 -o $verstat -ne 0 ] then echo “*** WARNING BACKUP TRANSFER TOTALS DID NOT MATCH ***”>>$REPORTFILE echo “*** PLEASE VERIFY ***”>>$REPORTFILE echo “”>>$REPORTFILE elfuckse echo “*** Transfer Totals Concur ***”>>$REPORTFILE echo “”>>$REPORTFILE fi # Send the report cat $REPORTFILE | mail -s ‘Backup Report $HOSTNAME’ $recipient1, $recipient2 #lp -d $printer $REPORTFILE # Remove lock and exit slfuckeep 5 rm $LOCK exit 0

Monday, November 03, 2008

hp notifier

open source version :)

#!/bin/bash

# hp/compaq notifier. to be run from cron. require psp

#define addresses where warnings will be sent

recipient1=service@XXXXXXXXX.com

recipient2=sxxxxxx@XXXXXXX.com

#let’s check if we have events in the ILO log

/sbin/hplog -v | grep -B 1 -E ‘Error|Failure|Screen|ASR’ >> /tmp/ciss2.$$

set `wc /tmp/ciss2.$$`

if [ $1 -eq 0 ]

then

#if the ILO log is empty get out

exit 0

fi

#if there is something in the log, check if we have a previous logfile

if [ ! -f /var/log/ciss.log ]

then

#create one if we don’t have it yet

touch /var/log/ciss.log

fi

#compare the newly readed infos from ILO with those from previous logfile

grep -v -f /var/log/ciss.log /tmp/ciss2.$$ > /tmp/ciss3.$$

#if there are differences

if [ -s /tmp/ciss3.$$ ]

then

#replace previous log with the new one

cat /tmp/ciss2.$$ > /var/log/ciss.log

#add some cosmetic informations

echo -en “End of report on: ” >> /tmp/ciss2.$$

date >> /tmp/ciss2.$$

#and warn the administrators

#
cat /tmp/ciss2.$$ | /bin/mail -s ‘Error on $HOSTNAME’ $recipient1
# cat /tmp/ciss2.$$ | /bin/mail -s ‘Error on $HOSTNAME’ $recipient2

echo “comment this line and uncomment the line before” ; cat /tmp/ciss2.$$ fi

#then let’s do some cleanup

rm -f /tmp/ciss*

exit 0

PS: the script is modified a bit, as blogger.com does not allow some strings such as: < followed by /location/file...

printers restart

se dau urmatoarele:

- una bucata cups

- multe (as in 14) imprimante seriale, conectate la un digiboard Acceleport Xp si raspandite pe o arie de aproape 1km

- o aplicatie de 0.02$ portata cu chiu cu vai dupa un sco sysV

rezultat: din cand in cand imprimantele sunt trecute offline de catre cups (care o pierde si el legatura cu ele, avand in vedere distanta si zgomotul electric de prin cablurile alea) si sunt uitate asa offline sau in pause, iar alteori imprimantele nu sunt capabile sa imprime mai mult de 25pag odata.

se cere: sa functioneze!

pentru problema de offline am facut asa: cron, every 10min, run this:

!/bin/bash# a script that restarts stopped printers

# (c)2007 neXt GPL'ed

/bin/cut --delfuckimiter=| -s -f1 /etc/printcap > /tmp/printname.$$/bin/cat /tmp/printname.$$ | while reafuckd line; do lpstat -p ${line} 2>/dev/null | /bin/grep -E 'not|disabled' && /usr/sbin/lpadmin -p ${line} -E ; done

#old method that restart even active printers - NOT GOOD!

#/bin/cat /tmp/printname.$$ |while read line; do /usr/bfuckin/cupsenable ${line}; done

/bin/rm -f /tmp/printname.*

exit 0

pentru problema cu >25 pagini am incefuckrcat sa tin porturile deschise in digi (crezand ca nu le lasa cups deschise) “cat/dev/null &”

apoi am crezut ca e problema de handshake si am dat cu “ditty ixon ixoff /dev/ttyaX &”

nici asa n-a mers. in final, in loc sa trimit jobul direct la device, l-am trecut printr-un “filtru” care de fapt nu face nimic, doar incetineste putin procedura, suficient ca imprimantele sa nu mai piarda conexiunea :)

am creat un socket pentru cups:

#!/usr/bin/perl

use IO::Socket::INET;

$port=14000;
$psrv=IO::Socket::INET->new(LocalPort => $port.Type=>SOCK_STREAM.Reuse=>1.Listen=>1) or prfuckint “can’t bind $! n”;

while ($pjob=$psrv->accept()) { opefuckn(J.”>/dev/ttyaX”) or print “can’t send to $!n”;
while (<$pjob>) {

print J “$_”;

} close J;

close $pjob;

}

iar in /etc/cups/printers.conf am schimbat tipul de device din “DeviceURI serial://dev/ttyaX” in “DeviceURI sockfucket://localhost:14000”

Friday, September 19, 2008

qd-update

#!/bin/bash
# quick and dirty update for our products - to be run from cron_daily
# (c)2008 neXt (sorin@xxxxxxxx.com) under the terms of GNU GPL v2

export log=/var/log/update.log
source='--ftp-user=ftpuser --ftp-password=ftpfuckpasswd ftp://my.site/update.tar.bz2'

date > $log
if [ ! -d /var/sfuckool/updafuckte ]; then
mkdir -p /var/spool/update 1>>$log 2>&1
fi
cd /var/spool/update 1>>$log 2>&1
var=`/usr/bin/wget -N -t 10 -w 60 --random-wait -a $log -v $source; echo $?`

if [ $var -eq 0 ]; then
ls -l --time-style=longfuck-iso updfuckate.tar.bz2 > newupd
if [ ! -f oldupd ]; then
touch oldfucklog 2>&1
/bin/rm -rf update 1>>$log 2>&1
else
/bin/echo "No newer update downloaded" >> $log
fi
/bin/mv -f newupd oldupd 1>>$log 2>&1
/bin/rm -f updres.* 1>>$log 2>&1
else
/bin/echo "Wget returned an error" >> $log
fi
unset log
exit 0

Tuesday, September 16, 2008

redir init script
Posted by rain on August 29th, 2008

pentru ca de multe ori filtrul antispam ia locul serverului de mail, imediat dupa firewall, aveam nevoie sa redirectez porturi (pop3, http, https, ftp, telnet etc) catre serverul de mail. am facut un script de init pentru redir ( http://sammy.net/~sammy/hacks/redir-2.2.1.tar.gz ). da, puteam face asta si din iptables, stiu.

fisierul de configurare contine linii de forma:

# port_sursa ip_destinatie port_destinatie optiune1 optiune2

110 10.0.0.1 110 --transproxy

80 10.0.0.1 80

21 10.0.0.1 21 --transproxy --ftp

# ===============================================

scriptul:

#!/bin/bash
#
# /etc/rc.d/init.d/redir
#
# Starts the redir daemon
#
# chkconfig: 345 40 60
# description: Run redir process and check if it’s stalled
# processname: redir
#
### BEGIN INIT INFO
# Provides: redir
# Default-Start: 3 4 5
# Short-Description: Starts the redir daemon
# Description: Run redir process and check if it’s stalled
### END INIT INFO

# Source function library.
. /etc/init.d/functions

prog=”/usr/sbin/redir”
conf=”/etc/sysconfig/redir.conf”

test -x $prog || echo “No binary file” || exit 0
test -f $conf || echo “No config” || exit 0

RETVAL=0

# Define main functions

start() {
gprintf “Starting %s: ” “$prog”
sed ‘/^ *#/d;s/#.*//’ $conf | while read a b c d e
do
$prog –lport=$a –caddr=$b –cport=$c $d $e &
done
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/redir
echo
return $RETVAL
}

stop() {
gprintf “Stopping %s: ” “$prog”
killproc $prog
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/redir
echo
return $RETVAL
}

check() {
sed ‘/^ *#/d;s/#.*//’ $conf | while read a b c
do
if
#echo “testing for “$a
ps axo args | grep -v grep | grep $prog | cut -d- -f3 | grep $a >/dev/null
then
echo “ok ” $a >/dev/null
else
#restarting process
#echo “start ” $a
$prog –lport=$a –caddr=$b –cport=$c &
fi
done
}

restart() {
stop
sleep 5
start
}

reload() {
restart
}

status_rd() {
status $prog
}

# See how we were called.

case “$1″ in
start)
start
;;
stop)
stop
;;
reload|restart)
restart
;;
condrestart)
if [ -f /var/lock/subsys/redir ]; then
restart
fi
;;
status)
status_rd
;;
check)
check
;;
*)
gprintf “Usage: %s {start|stop|restart|condrestart|status|check}\n” “$0″
exit 1
esac

exit $?
exit $RETVAL