#!/bin/sh #send mail for menat. # export LANG=C version=0.5.2 mail_version=menat-mail.sh-$version opt_all=$* user_h=/var/menat menat_sys_d=/etc/menat vs_ls=`cat $menat_sys_d/vs.list` exe_hn=`hostname` smtp_client=$exe_hn admin_addr=menat@$exe_hn menat_log=$user_h/localhost/menat/tmp/menat.log info=$user_h/info menat_user_ls=$user_h/user.list mail_server=localhost m_port=25 opt0=${0##*/} n_ident() { if [ "$1" ];then chk=`echo "$1"|sed 's/[0-9]//g'` if [ ! "$chk" ];then n=${1} while [ ${n:0:1} = 0 ];do if [ ${#n} = 1 ];then break n=0 else n=${n#0} fi done dvn=$n dvn_v=0 else dvn="" dvn_v=125 fi else dvn="" dvn_v=1 fi echo $dvn return $dvn_v } ft_date() { if [ "$2" = 1 ];then f_ft=`find $1 -maxdepth 0 -follow -printf '%TY-%Tm-%Td %Ta %TH:%TM\n'`;f_v=$? else f_ft=`find $1 -maxdepth 0 -follow -printf '%TY%Tm%Td%TH%TM\n'`;f_v=$? fi if [ $f_v = 0 ];then echo $f_ft return 0 else return $f_v fi } ar_hmac() { key="$1" challenge=$2 key_length=64 key_org_byte=`echo -n $key|wc -m` if [ $key_org_byte -gt $key_length ];then key_64over=`echo -n "$key"|md5sum -` key_str=${key_64over%% *} else key_org=`echo -n $key|od -h|cut -d' ' -f2-` i=0 for u in $key_org ;do u1=${u:2:2};u2=${u:0:2} for uu in $u1 $u2 ;do if [ $uu = 00 ];then break fi key_str="${key_str}$uu" i=$(($i+1)) done done fi i=0 while [ $i != 64 ];do offset=$((2*$i)) key_part=${key_str:$offset:2} dec_v=$((0x${key_part:-00}^0x36)) hex_2=$(($dec_v/16)) hex_1=$(($dec_v%16)) if [ $hex_1 = 10 ];then hex_1=a elif [ $hex_1 = 11 ];then hex_1=b elif [ $hex_1 = 12 ];then hex_1=c elif [ $hex_1 = 13 ];then hex_1=d elif [ $hex_1 = 14 ];then hex_1=e elif [ $hex_1 = 15 ];then hex_1=f fi if [ $hex_2 = 10 ];then hex_2=a elif [ $hex_2 = 11 ];then hex_2=b elif [ $hex_2 = 12 ];then hex_2=c elif [ $hex_2 = 13 ];then hex_2=d elif [ $hex_2 = 14 ];then hex_2=e elif [ $hex_2 = 15 ];then hex_2=f fi xor_h1_str="$xor_h1_str\x$hex_2$hex_1" i=$(($i+1)) done xor_h1_md5=`echo -ne "$xor_h1_str$challenge"|md5sum -` xor_h1_md5=${xor_h1_md5%% *} i=0 while [ $i != 16 ];do offset=$((2*$i)) hex_org=${xor_h1_md5:$offset:2} xor_h1x_md5="$xor_h1x_md5\x$hex_org" i=$(($i+1)) done i=0 while [ $i != 64 ];do offset=$((2*$i)) key_part=${key_str:$offset:2} dec_v=$((0x$key_part^0x5c)) hex_2=$(($dec_v/16)) hex_1=$(($dec_v%16)) if [ $hex_1 = 10 ];then hex_1=a elif [ $hex_1 = 11 ];then hex_1=b elif [ $hex_1 = 12 ];then hex_1=c elif [ $hex_1 = 13 ];then hex_1=d elif [ $hex_1 = 14 ];then hex_1=e elif [ $hex_1 = 15 ];then hex_1=f fi if [ $hex_2 = 10 ];then hex_2=a elif [ $hex_2 = 11 ];then hex_2=b elif [ $hex_2 = 12 ];then hex_2=c elif [ $hex_2 = 13 ];then hex_2=d elif [ $hex_2 = 14 ];then hex_2=e elif [ $hex_2 = 15 ];then hex_2=f fi xor_h2_str="$xor_h2_str\x$hex_2$hex_1" i=$(($i+1)) done xor_h2_md5=`echo -ne "$xor_h2_str$xor_h1x_md5"|md5sum -` xor_h2_md5=${xor_h2_md5%% *} echo $xor_h2_md5 return 0 } ########################################################### ############## menat configuration END #################### ########################################################### while [ "$1" ];do case "$1" in "-a" ) #to_addr shift if [ "$1" = all ];then to_addr=`cut -d' ' -f1 $menat_user_ls` to_addr=`echo $to_addr` elif [ "$1" ]&&[ -f "$menat_user_ls" ];then to_addr=`grep "^$1 " $menat_user_ls|cut -d' ' -f2|head -n1` to_addr=${to_addr:-menat} else to_addr=menat fi shift ;; "-aa" ) #to_addr shift case "$1" in "" ) echo "-aa value is not defined." ;; "-a" | "-i" | "-p" | "-n" | "-D" ) echo "maybe, -aa value is not defined." exit 1 ;; * ) to_addr=$1 ;exe_addr=1 ;; esac shift ;; "-vs" ) #to_addr shift if [ "$1" ];then vs_hn=$1 fi shift ;; "-v" ) #returned value shift rv_v=$1 if [ ! "$1" ];then echo "-v value is not defined." ;rv="3" else dvn=`n_ident $1`;dvn_v=$? if [ $dvn_v = 0 ];then rv=$1;shift else case "$1" in "-a" | "-i" | "-p" | "-n" | "-D" ) rv="4" ;; * ) rv=$1;shift;; esac fi fi ;; "-i" ) #program id shift if [ "$1" ];then ma_file=$1 else echo "program id is not defined." >&2 echo >>$menat_log echo "menat_mail.sh:program id is not defined." >>$menat_log exit 1 fi shift ;; "-n" ) #file name shift if [ "$1" ];then fn=$1 else echo "filename is not defined." >&2 echo >>$menat_log echo "menat-mail.sh-$version: filename is not defined." >>$menat_log exit 1 fi shift ;; "-p" ) #process type shift p_id=$1 case $1 in "" ) echo "-p option is not defined." >&2 echo >>$menat_log echo "-p option is not defined." >>$menat_log exit 1 ;; 0 ) m_proc=capture ;; 1 ) m_proc=compress ;; 2 ) m_proc=error ;; 3 ) m_proc=information ;; 4 ) m_proc=warning ;; 5 ) m_proc=emergency ;; * ) m_proc=unknown ;; esac shift ;; "-T" ) #for title shift mail_title=$1 shift ;; "-D" ) #for debug shift debug=1 ;; "-V" ) #for debug echo $mail_version exit 0 debug=1 ;; * ) echo "$1 is not implemented." >&2 echo >>$menat_log echo "menat-mail.sh-$version:$1 is not implemented." >>$menat_log echo "ma_file=$ma_file:to_addr=$to_addr:rv_v=$rv_v:fn=$fn" >>$menat_log exit 1 shift ;; esac done if [ "$vs_hn" ];then for t in $vs_ls ;do if [ $vs_hn = ${t%%.*} ]&&[ -d $user_h/$t ];then vs_name=$t vs_ls_ok=1 fi done if [ "$vs_ls_ok" != 1 ];then echo "$opt0-$version: $user_h/$t is not found, vs.list error?" >&2 exit 1 fi else if [ -d $user_h/$exe_hn ];then vs_name=$exe_hn vs_hn=${exe_hn%%.*} vs_ls_ok=1 elif [ -d $user_h/localhost ];then vs_name=localhost vs_hn=localhost vs_ls_ok=1 else echo "$opt0-$version: $user_h/$exe_hn is not found, vs.list error?" >>$menat_log echo "$opt0-$version: $user_h/$exe_hn is not found, vs.list error?" >&2 exit 1 fi fi vs_h=$user_h/$vs_name vs_uri=http://$vs_name/~menat menat_h=$vs_h/menat menat_h_t=$menat_h/tmp ma_h=$vs_h/vfiles ma_h_t=$ma_h/tmp menat_log=$menat_h_t/menat.log if [ -f $menat_sys_d/menat.conf ];then mail_exe=`. $menat_sys_d/menat.conf;echo $mail_exe` info=`. $menat_sys_d/menat.conf;echo ${info:-/dev/null}` menat_user_ls=`. $menat_sys_d/menat.conf;echo ${menat_user_ls:-$user_h/user.list}` mail_server=`. $menat_sys_d/menat.conf;echo ${mail_server:-localhost}` m_port=`. $menat_sys_d/menat.conf;echo ${m_port:-25}` ds_wrn=`. $menat_sys_d/menat.conf;echo ${ds_wrn:-2048}` smtp_auth_v=`. $menat_sys_d/menat.conf;echo $smtp_auth_v` smtp_server=`. $menat_sys_d/menat.conf;echo ${smtp_server:-$mail_server}` smtp_user=`. $menat_sys_d/menat.conf;echo ${smtp_user:-menat}` smtp_user_addr=`. $menat_sys_d/menat.conf;echo ${smtp_user_addr:-$mail_server}` pop_server=`. $menat_sys_d/menat.conf;echo ${pop_server:-$mail_server}` pop3_user=`. $menat_sys_d/menat.conf;echo ${pop3_user:-$smtp_user}` mmpasswd=`. $menat_sys_d/menat.conf;echo ${mmpasswd:-/etc/menat/mmpasswd}` fi if [ -f $menat_sys_d/mail.conf ];then mail_exe=1 if [ -f $menat_sys_d/menat.conf ];then . $menat_sys_d/menat.conf fi . $menat_sys_d/mail.conf info=${info:-/dev/null} menat_user_ls=${menat_user_ls:-$user_h/user.list} mail_server=${mail_server:-localhost} m_port=${m_port:-25} fi if [ "$mail_exe" != 1 ];then echo >>$menat_log echo "$opt0-$version: mail.conf is none. not executed." >>$menat_log echo "$opt0 $opt_all" >>$menat_log if [ ! "$debug" ];then exit 0 fi fi if [ ! -f $info ];then info=/dev/null fi if [ "$ma_file" ];then ma_file_12=${ma_file%.*.mtq} mtq_v=${ma_file#$ma_file_12.};mtq_v=${mtq_v%.mtq} mtq_v1=${mtq_v:0:1} mtq_v2=${mtq_v:1:1} if [ -f $menat_h_t/$ma_file ];then id_file=$menat_h_t/$ma_file elif [ -f $menat_h/$ma_file_12.w$mtq_v2.mtq ];then id_file=$menat_h/$ma_file_12.w$mtq_v2.mtq elif [ -f $ma_h/$ma_file ];then id_file=/dev/null id_vv=1 elif [ -f $ma_file ]||[ $ma_file = /dev/null ];then id_file=$ma_file else ls_l=`ls $menat_h_t/$ma_file_12.[sfE]*.mtq 2>/dev/null`;ls_v1=$? if [ $ls_v1 != 0 ];then ls_l=`ls $menat_h/$ma_file_12.[sfE]*.mtq 2>/dev/null`;ls_v2=$? fi for t in $ls_l ;do if [ -f $t ];then ma_file=${t##*/} id_file=$t break fi done if [ "$debug" ];then if [ ! "$id_file" ];then echo "$opt0-$version: $ma_file, such file is not found." >&2 exit 1 fi elif [ ${p_id:-2} -lt 2 ];then echo "$opt0-$version: $ma_file, such file is not found." >>$menat_log echo "$opt0-$version: $ma_file, such file is not found." >&2 exit 1 fi fi if [ "$id_file" ];then org_id=`$id_file -c org_id` pch=`$id_file -c pch` time_epm=`$id_file -c time_epm` fi else id_file=/dev/null fi if [ ! "$fn" ];then echo "filename must be defined." >&2 if [ "$debug" != 1 ];then exit 1 fi fi ########################################################## ############### parameters were defined ################## ########################################################## ############### next, process mail body ################## ########################################################## if [ "$m_proc" = capture ]||[ "$m_proc" = compress ];then p_cc=1 case "$rv" in 0 ) m_title="$m_proc of $fn was done on $vs_hn." ;; 1 ) m_title="$m_proc of $fn was failed on $vs_hn." ;; 2 ) m_title="unknown error occured on $vs_hn, $m_proc of $fn was failed." ;; 125 ) m_title="time out error occured on $vs_hn, $m_proc of $fn was failed." ;to_err=1;; 127 ) m_title="$m_proc of $fn was failed. software is not installed in $vs_hn." ;exe_err=1;; * ) m_title="unknown error occured on $vs_hn.";; esac elif [ "$m_proc" = information ]||[ "$m_proc" = warning ]||[ "$m_proc" = emergency ];then if [ ! "$ma_file" ];then fn_b=${fn##*/} fn_bb=${fn_b%.*.tmp} m_title="$m_proc for $fn_bb on $vs_hn" else m_title="$m_proc for $ma_file on $vs_hn" fi elif [ "$m_proc" = unknown ];then m_title="unknown error occured $vs_hn" else m_title="UNKNOWN" fi if [ "$mail_title" ];then m_subject="$mail_title" else m_subject="$m_title" fi if [ ! "$to_addr" ];then to_addr=$admin_addr fi if [ "$ma_file" ]&&[ "$p_cc" = 1 ];then ma_file_12=${ma_file%.*.mtq} dvn=`expr "$ma_file_12" + 0 2>/dev/null`;dvn_v=$? if [ $dvn_v = 0 ]&&[ ${#ma_file_12} = 12 ]&&[ "$id_vv" != 1 ];then ma_tY=${ma_file:0:4} ma_tm=${ma_file:4:2} ma_td=${ma_file:6:2} ma_tH=${ma_file:8:2} ma_tM=${ma_file:10:2} cps_tYmdHM="$ma_tY-$ma_tm-$ma_td $ma_tH:$ma_tM" cps_tYmdaHM=`date -d "$cps_tYmdHM" '+%Y-%m-%d %a %H:%M'` if [ "$to_err" = 1 ];then if [ -f "$id_file" ];then to_st_YmdaHM=`grep 'capture_time_out menat_ends$' $id_file|cut -d' ' -f1-3` to_st_YmdaHM=${to_st_YmdaHM#\#} if [ "$to_st_YmdaHM" ];then cap_start="$to_st_YmdaHM ${time_epm}ʬ $pch capture started." else cap_start="`date '+%Y-%m-%d %a %H:%M'` ${time_epm}ʬ $pch capture started." fi else cap_start="`date '+%Y-%m-%d %a %H:%M'` ${time_epm}ʬ $pch capture started." fi else if [ "$cps_tYmdaHM" ];then cap_start="$cps_tYmdaHM ${time_epm}ʬ $pch capture started." else cap_start="`date '+%Y-%m-%d %a %H:%M'` ${time_epm}ʬ $pch capture started?" fi fi else cap_start="`date '+%Y-%m-%d %a %H:%M'` ${time_epm}ʬ $pch, capture started?" fi fi if [ "$debug" ];then echo "id_file=$id_file" fi if [ -x "$info" ];then info_cat="" else info_cat=cat fi ############## disk space information ################### if [ $exe_hn = "$vs_name" ]||[ "$vs_name" = localhost ];then ma_dvc=`df $ma_h|tail -n 1|cut -d' ' -f1` ma_df0=`df -m|tr -s " " " "|grep -e $ma_dvc` ma_df4=`echo $ma_df0|cut -d' ' -f4` #¸½ºß¤Î¶õ¤­ÍÆÎÌ ma_df3=`echo $ma_df0|cut -d' ' -f3` ma_df2=`echo $ma_df0|cut -d' ' -f2` #ÁíÍÆÎÌ ma_fm=`du -xmsL $ma_h 2>/dev/null|tail -n 1|cut -f1` #¸½ºß¤Î»ÈÍÑÎÌ ma_ss=$(($ma_df4+$ma_fm)) vs_f_list="`ls $ma_h`" else wget -O /dev/null $vs_uri/menat-vs.cgi?mdss=1\&vs_hn=$vs_hn 2>/dev/null;wget_v=$? md_ss0=`head -n1 $menat_h_t/mdss_3|cut -d'"' -f2` ma_fm=${md_ss0%%/*} ma_ss=${md_ss0#*/};ma_ss=${ma_ss% *} ma_df4=${md_ss0#* } fi if [ -f /var/menat/$vs_name/color.conf ];then . /var/menat/$vs_name/color.conf fi ds_wrn=${ds_wrn:-2048} if [ $ma_df4 -lt $ds_wrn ];then ma_df4="*** $ma_df4(MB) ***" else ma_df4="$ma_df4(MB)" fi mdss_3="$vs_hn -- $ma_fm/$ma_ss(MB) »Ä¤ê $ma_df4" case "$m_proc" in capture ) iepg_dd=`$id_file -c iepg_dd 2|sed -n '3,$p'` cap_end=`$id_file -c cap_dd` if [ ! "$iepg_dd" ]||[ ! "$cap_end" ];then stn_ma_ex=`grep -n ^\#\!/ $id_file` stn_n=${stn_ma_ex%%:*} edn_ma_ex=`grep -n ^\$ $id_file` for t in ${edn_ma_ex:-0} ;do tt=${t%%:*} if [ $tt -gt ${stn_n:-0} ];then edn_n=$(($tt-1)) break fi done stn_iepg=`sed -n "${stn_n:-0},${edn_n}p" $id_file|grep -c ^\#station` if [ "$stn_iepg" != 0 ];then for t in `grep -n ^\#station $id_file` ;do tt=${t%%:*} if [ $edn_n -gt $tt ];then stn_iepg_n=$(($tt-1)) break fi done iepg_dd=`sed -n "${stn_iepg_n},${edn_n}p" $id_file` iepg_dd=" $iepg_dd" else iepg_dd=`sed -n "${edn_n}p" $id_file` iepg_dd=" $iepg_dd" fi mail_org_id=`$id_file -c org_id` mail_prs_id=`$id_file -c prs_id` mail_sr_id=`$id_file -c sr_id` mail_week_v=`$id_file -c week` mail_auto_exe=`$id_file -c suto_exe` mail_wkv_str="week=${mail_week_v:-0} ${mail_auto_exe:-0}" mail_iepg_err=`$id_file -c iepg_err` mail_iepg_err_v="iepg_err=${mail_iepg_err:--1}" cr_version="menat-cr.sh-`$id_file -c version`" iepg_dd="$iepg_dd #org_id=$mail_org_id:prs_id=$mail_prs_id:sr_id=$mail_sr_id; $mail_wkv_str; $mail_iepg_err_v; $cr_version " else iepg_dd=" $iepg_dd " fi if [ "$exe_err" = 1 ];then if [ `$id_file -c hw_cap` = 1 ];then exe_sw="record-v4l2.pl" else t=`grep -B 2 'cap_v=125$' $id_file |head -n1` for j in $t ;do exe_sw=$j break done fi mm_title="$m_proc of $fn was failed. $m_proc software, $exe_sw is not installed?" else mm_title="$m_title" fi if [ ! "$cap_end" ];then end_ln_str=`grep -n ^\#$fn: $id_file` if [ "$end_ln_str" ];then end_ln=`echo "$end_ln_str"|tail -n1|cut -d':' -f1` mx_end_ln=$end_ln while [ loop ];do tmp_end_ln=$(($mx_end_ln+1)) if [ `sed -n "${tmp_end_ln}p" $id_file|grep -c '^#'` = 0 ];then break else if [ $tmp_end_ln = 256 ];then break fi mx_end_ln=$tmp_end_ln fi done cap_end=`sed -n "${end_ln},${mx_end_ln}p" $id_file` else cap_end="#unknown error occured, data of $fn was not found." fi fi m_body="$mm_title $iepg_dd #$cap_start $cap_end" wv=`$id_file -c week` if [ ${wv:-0} != 0 ];then iepg_ok=0 prs_id=`$id_file -c prs_id` for t in `grep -Hc "^org_id=${org_id}" $menat_h/*.mtq` ;do t_v=${t#*:} t_p=${t%:*} if [ $t_v = 0 ]||[ -d $t_p ]||[ "$ma_file" = ${t##*/} ];then continue fi nx_id_file=${t%%:*} if [ "`$nx_id_file -c prs_id`" = ${prs_id:-000} ];then continue fi nw_iepg_dd=`$nx_id_file -c iepg_dd 2|sed -n '3,$p'` if [ ! "$nw_iepg_dd" ];then stn_ma_ex=`grep -n ^\#\!/ $nx_id_file` stn_n=${stn_ma_ex%%:*} edn_ma_ex=`grep -n ^\$ $nx_id_file` for t in ${edn_ma_ex:-0} ;do tt=${t%%:*} if [ $tt -gt ${stn_n:-0} ];then edn_n=$(($tt-1)) break fi done nw_stn_iepg=`sed -n "${stn_n:-0},${edn_n}p" $nx_id_file|grep -c ^\#station` if [ "$nw_stn_iepg" != 0 ];then iepg_ok=1 for t in `grep -n ^\#station $nx_id_file` ;do tt=${t%%:*} if [ $edn_n -gt $tt ];then stn_iepg_n=$(($tt-1)) break fi done nw_iepg_dd=`sed -n "${stn_iepg_n},${edn_n}p" $nx_id_file` else nw_iepg_dd=`sed -n "${edn_n}p" $nx_id_file` fi nw_org_id=`$nx_id_file -c org_id` nw_prs_id=`$nx_id_file -c prs_id` nw_sr_id=`$nx_id_file -c sr_id` mail_week_v=`$nx_id_file -c week` mail_auto_exe=`$nx_id_file -c suto_exe` mail_wkv_str="week=${mail_week_v:-0} ${mail_auto_exe:-0}" mail_iepg_err=`$id_file -c iepg_err` mail_iepg_err_v="iepg_err=${mail_iepg_err:--1}" nw_cr_version="menat-cr.sh-`$nx_id_file -c version`" nw_iepg_dd="$nw_iepg_dd #org_id=$nw_org_id:prs_id=$nw_prs_id:sr_id=$nw_sr_id; $mail_wkv_str; $mail_iepg_err_v; $nw_cr_version" fi m_body="$m_body next job was added in que. $nw_iepg_dd" break done fi m_body="$m_body $mdss_3 `$info_cat $info`" ;; compress ) if [ -f "$id_file" ]&&[ "$id_file" != /dev/null ];then cmp_dd=`$id_file -c cmp_dd` iepg_dd=`$id_file -c iepg_dd 2|sed -n '3,$p'` m_body=`$id_file -c cap_dd` if [ ! "$cmp_dd" ]||[ ! "$iepg_dd" ]||[ ! "$m_body" ] ;then stn_ma_ex=`grep -n ^\#\!/ $id_file` stn_n=${stn_ma_ex%%:*} edn_ma_ex=`grep -n ^\$ $id_file` for t in $edn_ma_ex ;do tt=${t%%:*} if [ $tt -gt ${stn_n:-0} ];then edn_n=$(($tt-1)) break fi done stn_iepg=`sed -n "${stn_n},${edn_n}p" $id_file|grep -c ^\#station` if [ "$stn_iepg" != 0 ];then for t in `grep -n ^\#station $id_file` ;do tt=${t%%:*} if [ $edn_n -gt $tt ];then stn_iepg_n=$(($tt-1)) break fi done iepg_dd=`sed -n "${stn_iepg_n},${edn_n}p" $id_file` iepg_dd=" $iepg_dd" else iepg_dd=`sed -n "${edn_n}p" $id_file` iepg_dd=" $iepg_dd" fi mail_org_id=`$id_file -c org_id` mail_prs_id=`$id_file -c prs_id` mail_sr_id=`$id_file -c sr_id` mail_week_v=`$id_file -c week` mail_auto_exe=`$id_file -c suto_exe` mail_wkv_str="week=${mail_week_v:-0} ${mail_auto_exe:-0}" mail_iepg_err=`$id_file -c suto_exe` mail_iepg_err_v="iepg_err=${mail_iepg_err:--1}" cr_version="menat-cr.sh-`$id_file -c version`" iepg_dd="$iepg_dd #org_id=$mail_org_id:prs_id=$mail_prs_id:sr_id=$mail_sr_id; $mail_wkv_str; $mail_iepg_err_v; $cr_version " ln_id=`grep -n ^\#$fn: $id_file|tail -n1|cut -d':' -f1` ln_fin=$ln_id while [ ${ln_fin:-0} != 0 ];do ln_fin=$(($ln_fin+1)) l_hv=`sed -n "${ln_fin}p" $id_file|grep -c ^\#` if [ $l_hv = 0 ];then ln_fin=$(($ln_fin-1)) break fi done ln_st=$ln_id while [ ${ln_st:-0} != 0 ];do ln_st=$(($ln_st-1)) l_hv=`sed -n "${ln_st}p" $id_file|grep -c ^\#` if [ $l_hv = 0 ];then ln_st=$(($ln_st+1)) break fi done if [ ! "$ln_fin" ];then cmp_dd="#compress data of $fn was not found." else cmp_dd=`sed -n "${ln_st},${ln_fin}p" $id_file` fi fi cap_fn_tmp=${fn%.*} mqr_ln=`grep -n 'added in que.$' $id_file|tail -n1|cut -d':' -f1` cap_fn_dd=`grep -n ^\#$cap_fn_tmp. $id_file|grep -v ^\#$fn: ` cap_fn_ls=`echo "$cap_fn_dd"|cut -d':' -f1` if [ "$mqr_ln" ]&&[ "$cap_fn_ls" ];then for t in $cap_fn_ls ;do if [ $t -gt $mqr_ln ];then cap_fn_ln=$t break fi done if [ "$cap_fn_ln" ];then mx_cap_ln=$cap_fn_ln while [ loop ];do tmp_mx_ln=$(($mx_cap_ln+1)) if [ `sed -n "${tmp_mx_ln}p" $id_file|grep -c ^\#` = 0 ];then mx_ln_ok=1 break else mx_cap_ln=$tmp_mx_ln fi done fi if [ "$mx_ln_ok" = 1 ];then m_body=`sed -n "${cap_fn_ln},${mx_cap_ln}p" $id_file` else m_body="#capture data of $fn was not found." fi else m_body="#capture data of $fn was not found." fi else iepg_dd=" iepg_dd " m_body="$cap_dd" fi m_body=" $m_title $iepg_dd #$cap_start $m_body $cmp_dd $mdss_3 `$info_cat $info`" ;; information | warning | emergency ) if [ "$fn" ]&&[ -f "$fn" ];then if [ `du -m $fn 2>/dev/null|cut -f1` -gt 2 ];then m_body=$fn else m_body=`cat $fn` fi else m_body="$m_proc notice from $vs_name." fi m_body="$m_body $mdss_3 `$info_cat $info`" ;; * ) m_body="unknown error was occured." m_body="$m_body $mdss_3 `$info_cat $info`" ;; esac ######################################################### ################ mail body was created ################## ###################### send mail ######################## ######################################################### if [ "$smtp_auth_v" = pop_b_smtp ]&&[ -f ${mmpasswd:-/etc/menat/mmpasswd} ];then smtp_user=${smtp_user:-menat} admin_addr="$smtp_user@$smtp_user_addr" pop_server=${pop_server:-$mail_server} pop3_passwd=`grep ^$smtp_user: $mmpasswd`;pop3_passwd=${pop3_passwd#*:} exec 3<>/dev/tcp/$pop_server/110 echo user $pop3_user >&3 echo "$mail_version: user $pop3_user" >>$menat_log read l <&3 echo "$mail_version: $l" >>$menat_log echo pass $pop3_passwd >&3 echo "$mail_version: pass xxxxxxxxx" >>$menat_log read l <&3 echo "$mail_version: $l" >>$menat_log echo retr 1 >&3 echo "$mail_version: retr 1" >>$menat_log cat <&3 >/dev/null& echo "cat <&3 >/dev/null" >>$menat_log echo quit >&3 echo "$mail_version: quit" >>$menat_log read l <&3 echo "$mail_version: $l" >>$menat_log elif [ "$smtp_auth_v" = auth_plain ]&&[ -f ${mmpasswd:-/etc/menat/mmpasswd} ];then smtp_user=${smtp_user:-menat} smtp_passwd=`grep ^$smtp_user: $mmpasswd`;smtp_passwd=${smtp_passwd#*:} mm_passwd=`printf "$smtp_user\0$smtp_user\0$smtp_passwd"|nkf -MB` smtp_auth_passwd="AUTH PLAIN $mm_passwd" admin_addr="$smtp_user@$smtp_user_addr" elif [ "$smtp_auth_v" = cram_md5 ]&&[ -f ${mmpasswd:-/etc/menat/mmpasswd} ];then smtp_user=${smtp_user:-menat} smtp_passwd=`grep ^$smtp_user: $mmpasswd`;smtp_passwd=${smtp_passwd#*:} cram_md5_ok=1 fi if [ "$debug" = 1 ]||[ ${mail_exe:-0} = 0 ];then echo " menat_h=$user_h/$vs_name/menat menat_h_t=$menat_h/tmp ma_h=$menat_h/vfiles ma_h_t=$ma_h/tmp info=$user_h/info menat_user_ls=$user_h/user.list menat_log=$menat_h_t/menat.log " echo "EHLO $smtp_client $smtp_auth_passwd MAIL FROM: $admin_addr RCPT TO: $to_addr DATA From: $admin_addr To: $to_addr Subject: $m_subject User-Agent: menat-mail.sh-$version Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp $m_body . QUIT|nkf -j >/dev/tcp/$mail_server/$m_port" echo "${0##*/}-$version:debug mode ends." else exec 3<>/dev/tcp/$mail_server/$m_port echo "EHLO $smtp_client" >&3 echo "$mail_version: EHLO $smtp_client" >>$menat_log read smtp_rtrn <&3 smtp_rtrn=`echo $smtp_rtrn|nkf -Lue` while [ "$smtp_rtrn" ];do echo "$mail_version: $smtp_rtrn" >>$menat_log if [ "${smtp_rtrn#250 }" != "$smtp_rtrn" ];then echo "$mail_version: smtp server waiting." >>$menat_log break fi smtp_rtrn="" read -t 3 smtp_rtrn <&3;read_v=$? smtp_rtrn=`echo $smtp_rtrn|nkf -Lue` if [ "$read_v" != 0 ];then echo "$mail_version: time_out 3s." >>$menat_log break fi done if [ "$smtp_auth_passwd" ];then echo $smtp_auth_passwd >&3 echo "$mail_version: AUTH PLAIN xxxxxxxxxxxxxxxxxxxxxxxxxx" >>$menat_log read l <&3 echo "$mail_version: $l" >>$menat_log elif [ "$cram_md5_ok" = 1 ];then echo AUTH CRAM-MD5 >&3 echo "$mail_version: AUTH CRAM-MD5" >>$menat_log read l <&3 echo "$mail_version: $l" >>$menat_log cram_rtrn=`echo -n "$l"|nkf -Lue` if [ "${cram_rtrn:0:4}" = "334 " ];then challenge=`printf "${cram_rtrn:4}"|nkf -mB` hex_hmac=`ar_hmac $smtp_passwd $challenge` mm_hmac=`printf "$smtp_user $hex_hmac"|nkf -MB` echo "$mm_hmac" >&3 echo "$mail_version: $mm_hmac" >>$menat_log read l <&3 echo "$mail_version: $l" >>$menat_log fi fi echo "MAIL FROM: $admin_addr" >&3 ec22ho "$mail_version: MAIL FROM: $admin_addr" >>$menat_log read l <&3 echo "$mail_version: $l" >>$menat_log echo "RCPT TO: $to_addr" >&3 echo "$mail_version: RCPT TO: $to_addr" >>$menat_log read l <&3 echo "$mail_version: $l" >>$menat_log echo "DATA From: $admin_addr To: $to_addr Subject: $m_subject User-Agent: menat-mail.sh-$version Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp $m_body . "|nkf -j -Lw -c >&3 echo "DATA From: $admin_addr To: $to_addr Subject: $m_subject User-Agent: menat-mail.sh-$version Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp $m_body . " >>$menat_log read l <&3 echo "$mail_version: $l" >>$menat_log echo "QUIT" >&3;ms_v=$? echo "$mail_version: QUIT" >>$menat_log read l <&3 echo "$mail_version: $l" >>$menat_log if [ $ms_v = 0 ];then echo >>$menat_log echo "menat-mail.sh-$version: subject $m_subject to $to_addr was delivered." >>$menat_log else echo >>$menat_log echo "menat-mail.sh-$version: subject $m_subject to $to_addr was not delivered." >>$menat_log echo "menat-mail.sh-$version: subject $m_subject to $to_addr was not delivered." >&2 exit 1 fi fi exit 0 #2006-10-15 Sun 11:00 Auth rutine added at 0.5.1-pre3. #2005-04-04 Mon 02:42 -i safty was revised for error at 0.3.2. #2005-03-20 Sun 10:04 mail format was revised for iepg data at 0.3.0. #2005-03-13 Sun 04:31 vs_hn bug was fixed at 0.2.8. #2005-02-28 Mon 11:37 info option was revised for menat-progchk.sh at 0.2.0. #2005-02-25 Fri 05:04 first official release 0.1.6. #2005-02-05 Sat 17:27 to_adrr bug was fixed at 0.1.5. #2005-01-31 Mon 09:13 for system generality, branch started at 0.1.4e-1v2. #2005-01-28 Fri 16:13 MUA was changed from mail to bash at 0.1.3c. #2005-01-26 Wed 14:06 script was refined at 0.1.1a. #2005-01-24 Mon 08:46 in pratical use at 0.1.0. #2005-01-21 Fri 06:20 first release 0.0.2a.