Code donation
Omer Qadir
omer.qadir at and-or.com
Fri Apr 2 05:34:10 GMT 2004
Dear sir/madam,
I realize that the work done at this forum is far more complex than what
i propose to submit, however it is a usefull tool that frankly i thought
should have been part of the samba package. The following is a description.
Quite often people in my workgroup would start a "winpopup batch" war,
just to bug each other. This basically is running a script that
continuously sends winpopup messages to a host. It is quite annoying
actually. Since in linux one has the luxury of fine tuning everything,
the script is an anti batch war effort. It is defensive not offensive,
so it does not attack back.
Knowledge about configing the smb.conf file is assumed here. The scipt
basically tests any incoming message with information stored about the
previous message received. If the information is different, it displays
the message using gdialog. If the information is the same, it refuses to
disturb the user with redundant information, assuming that this is a
batch. The corner case where two users are carrying out a conversation
and one user replies with the same text to 2 messages will also not be
displayed This issue will be handled in the next version. The script
maintains a configuration file that stores the previous message
information. This configuration file needs no editing by the user. It
will be automatically generated and maintained in the home directory.
The home directory variable must be set before calling this script. For
the case of calling from withing samba, an example implementation of the
message command may be :
message command = /bin/csh -c 'setenv HOME
/jupiter/jupiter;/jupiter/omer/display_win_popup_message %s %f d' &
It must be ensured however that the samba guest account is enabled, and
that it has read/write permissions in the directory set as HOME. To
change the configuration file location, simply delete it and change the
value of the HOME location to whatever path u want.
usage : display_win_popup_message <new message file name> <new message
sender name> [d(ebug)]
<new message file name> : The file containing the new popup message.
This is tested against
the old file containing the previous popup
message
<new message sender name> : The name of the sender of the new message.
This is tested against
the old sender name of the previous popup
message
d : This is an optional argument. If passed, the
scipt outputs helpfull
debugging messages to a file called
win_popup_stdout.
This script also creates a configuration file (by name only), called
.win_popup_old_message_info.
The debug output file and config file are created in $HOME/.
Therefore make sure that the samba
guest account has read and write permissions at $HOME.
Don't know much about copyrights and all... and frankly i dont care.
That is why this is a linux
script. GPL or whatever. Just credit me once in a while. Hope u like it.
Author : Omer Qadir - always a newbie
Date : April 1st 2004 (no this is not a joke - the script works)
version: 1.00
TODO:
====
* config file is read and is not sourced.
* Add variable to decide how much history of messages needs to be
saved and compared.
* Add time variables to message information so that batch and
repeated message may be differentiated.
-------------- next part --------------
#!/bin/csh -f
#
# usage : display_win_popup_message <new message file name> <new message sender name> [d(ebug)]
# <new message file name> : The file containing the new popup message. This is tested against
# the old file containing the previous popup message
# <new message sender name> : The name of the sender of the new message. This is tested against
# the old sender name of the previous popup message
# d : This is an optional argument. If passed, the scipt outputs helpfull
# debugging messages to a file called win_popup_stdout.
#
# This script also creates a configuration file (by name only), called .win_popup_old_message_info.
# The debug output file and config file are created in $HOME/. Therefore make sure that the samba
# guest account has read and write permissions at $HOME.
#
# Don't know much about copyrights and all... and frankly i dont care. That is why this is a linux
# script. GPL or whatever. Just credit me once in a while. Hope u like it.
#
# Author : Omer Qadir - always a newbie
# Date : April 1st 2004 (no this is not a joke - the script works)
# version : 1.00
# Dependancies : gdialog (gnome utilities)
#
# TODO:
# ====
# * config file is read and is not sourced.
# * Add variable to decide how much history of messages needs to be saved and compared.
# * Add time variables to message information so that batch and repeated message may be differentiated.
set win_popup_new_message_filename=$1
set win_popup_new_message_sender=$2
set popup_old_message_info_file=$HOME/.win_popup_old_message_info
if ( $3 == "d" ) then
set win_popup_debug=1
else
set win_popup_debug=0
endif
if ( -e $popup_old_message_info_file) then
if ( -r $popup_old_message_info_file && -w $popup_old_message_info_file) then
source $popup_old_message_info_file
#rm $popup_stdout_file_name
if ($win_popup_debug) then
/bin/touch $popup_stdout_file_name
echo "starting script" >> $popup_stdout_file_name
echo >> $popup_stdout_file_name
echo "home dir is $HOME" >> $popup_stdout_file_name
echo "I am `whoami`" >> $popup_stdout_file_name
endif
if ($win_popup_debug) then
echo "info file = $popup_old_message_info_file" >> $popup_stdout_file_name
echo "old sender = $win_popup_old_message_sender" >> $popup_stdout_file_name
echo "new sender = $win_popup_new_message_sender" >> $popup_stdout_file_name
echo "old message = $win_popup_old_message_filename" >> $popup_stdout_file_name
echo "new message = $win_popup_new_message_filename" >> $popup_stdout_file_name
endif
if ( $win_popup_new_message_sender == $win_popup_old_message_sender ) then
if ($win_popup_debug) then
echo sender same >> $popup_stdout_file_name
endif
cmp -s $win_popup_new_message_filename $win_popup_old_message_filename
if ( $? == 0 ) then
if ($win_popup_debug) then
echo message same also >> $popup_stdout_file_name
endif
rm $win_popup_new_message_filename
else
if ($win_popup_debug) then
echo but message different >> $popup_stdout_file_name
endif
/usr/bin/gdialog --backtitle "Popup Message Received" --title "Message from $win_popup_new_message_sender" --textbox $win_popup_new_message_filename 20 40 &
rm $win_popup_old_message_filename
rm $popup_old_message_info_file
/bin/touch $popup_old_message_info_file
echo "#\!/bin/csh" >> $popup_old_message_info_file
echo "set win_popup_old_message_filename=$win_popup_new_message_filename" >> $popup_old_message_info_file
echo "set win_popup_old_message_sender=$win_popup_new_message_sender" >> $popup_old_message_info_file
echo "set popup_stdout_file_name=$popup_stdout_file_name" >> $popup_old_message_info_file
endif
else
if ($win_popup_debug) then
echo sender different >> $popup_stdout_file_name
endif
/usr/bin/gdialog --backtitle "Popup Message Received" --title "Message from $win_popup_new_message_sender" --textbox $win_popup_new_message_filename 20 40 &
rm $win_popup_old_message_filename
rm $popup_old_message_info_file
/bin/touch $popup_old_message_info_file
echo "#\!/bin/csh" >> $popup_old_message_info_file
echo "set win_popup_old_message_filename=$win_popup_new_message_filename" >> $popup_old_message_info_file
echo "set win_popup_old_message_sender=$win_popup_new_message_sender" >> $popup_old_message_info_file
echo "set popup_stdout_file_name=$popup_stdout_file_name" >> $popup_old_message_info_file
endif
unset win_popup_old_message_filename
unset win_popup_old_message_sender
else
/usr/bin/gdialog --backtitle "Popup Message Received" --title "Message from $win_popup_new_message_sender" --textbox $win_popup_new_message_filename 20 40 &
rm $win_popup_new_message_filename
set popup_stdout_file_name=$HOME/win_popup_stdout
if ($win_popup_debug) then
/bin/touch $popup_stdout_file_name
echo "starting script" >> $popup_stdout_file_name
echo >> $popup_stdout_file_name
echo "Please remove the file $popup_old_message_info_file before continueing." >> $popup_stdout_file_name
echo "And make sure the guest account user has read/write permissions in its home directory." >> $popup_stdout_file_name
endif
endif
else
/usr/bin/gdialog --backtitle "Popup Message Received" --title "Message from $win_popup_new_message_sender" --textbox $win_popup_new_message_filename 20 40 &
rm $win_popup_new_message_filename
set popup_stdout_file_name=$HOME/win_popup_stdout
if ($win_popup_debug) then
/bin/touch $popup_stdout_file_name
echo "starting script" >> $popup_stdout_file_name
echo >> $popup_stdout_file_name
echo "First time script is being run." >> $popup_stdout_file_name
echo "Creating config file in home directory." >> $popup_stdout_file_name
endif
echo "#\!/bin/csh" > $popup_old_message_info_file
echo "set win_popup_old_message_filename=$win_popup_new_message_filename" >> $popup_old_message_info_file
echo "set win_popup_old_message_sender=$win_popup_new_message_sender" >> $popup_old_message_info_file
echo "set popup_stdout_file_name=$popup_stdout_file_name" >> $popup_old_message_info_file
endif
unset win_popup_new_message_filename
unset win_popup_new_message_sender
unset popup_old_message_info_file
unset popup_stdout_file_name
unset win_popup_debug
More information about the samba-technical
mailing list