Forum Discussion
Tommy_lee_55826
Jan 17, 2012Nimbostratus
rule smtp_172_irule {
when CLIENT_ACCEPTED {
set chelo ""
set cfrom ""
set crcpt ""
set fdata ""
TCP::respond "220\r\n"
log local0. "172_client accepted"
TCP::collect
}
when CLIENT_DATA {
set cdata [TCP::payload]
if { [ string length $cdata ] <= 0 } {
return
}
elseif { not ( $cdata contains "\r\n" ) } {
return
}
elseif { $cdata starts_with "EHLO" } {
set chelo [TCP::payload]
TCP::respond "250 OK\r\n"
TCP::payload replace 0 [string length $chelo] ""
log local0. "172_HELO"
return
}
elseif { $cdata starts_with "QUIT" } {
set cquit [TCP::payload]
TCP::respond "221\r\n"
TCP::payload replace 0 [string length [TCP::payload]] $cquit
log local0. "172_QUIT"
return
}
elseif { $cdata starts_with "MAIL FROM:" } {
set cfrom [TCP::payload]
TCP::respond "250 OK\r\n"
TCP::payload replace 0 [string length $cfrom] ""
log local0. "172_MAIL FROM"
return
}
elseif { $cdata starts_with "RCPT TO:" } {
set crcpt "$crcpt[TCP::payload]"
TCP::respond "250 OK\r\n"
TCP::payload replace 0 [string length [TCP::payload]] ""
log local0. "172_RCPT TO"
return
}
elseif { $cdata starts_with "DATA" } {
set fdata "$fdata[TCP::payload]"
TCP::respond "354\r\n"
TCP::payload replace 0 [string length [TCP::payload]] ""
log local0. "172_DATA"
return
}
elseif { [string tolower $cdata] contains "x-mms-message-type" } {
if { [string tolower $cdata] contains "mm4_forward.req" } {
set fq [TCP::payload]
log local0. "172_MM4_forward.REQ"
log local0. "port : [client_port]"
pool pool_172_MMS_25
log local0. "LB_pool : 172_mms_FQ (78,79)"
TCP::payload replace 0 [string length [TCP::payload]] $chelo$cfrom$crcpt$fdata$fq
TCP::respond "250 OK\r\n"
}
elseif { [string tolower $cdata] contains "mm4_delivery_report.res" } {
set ds [TCP::payload]
log local0. "172_MM4_delivery_report.RES"
set ds_transaction [findstr [string tolower [TCP::payload]] "x-mms-transaction-id: " 22 1]
log local0. "172_transaction-ID : $ds_transaction"
if { $ds_transaction equals "1" } {
pool pool_172_MMS1_25
log local0. "LB_pool : 172_mms1 (78)"
}
elseif { $ds_transaction equals "4" } {
pool pool_172_MMS2_25
log local0. "LB_pool : 172_mms2 (79)"
}
else {
log local0. "LB server (78,79)"
pool pool_172_MMS_25
}
TCP::payload replace 0 [string length [TCP::payload]] $chelo$cfrom$crcpt$fdata$ds
TCP::respond "250 OK\r\n"
}
elseif { [string tolower $cdata] contains "mm4_forward.res" } {
set fs [TCP::payload]
log local0. "172_MM4_forward.RES"
set fs_message [findstr [string tolower [TCP::payload]] "x-mms-message-id: " 18 1]
log local0. "172_message-ID : $fs_message"
log local0. "port2 : [client_port]"
if { $fs_message equals "1" } {
pool pool_172_MMS1_25
log local0. "LB_pool : 172_mms1 (78)"
TCP::payload replace 0 0 $chelo$cfrom$crcpt$fdata$fs
TCP::respond "250 OK\r\n"
}
elseif { $fs_message equals "4" } {
pool pool_172_MMS2_25
log local0. "LB_pool : 172_mms2 (79)"
}
else {
log local0. "LB server (78,79)"
pool pool_172_MMS_25
}
}
elseif { [string tolower $cdata] contains "mm4_delivery_report.req" } {
set dq [TCP::payload]
log local0. "172_MM4_Delivery_report.REQ"
set dq_message [findstr [string tolower [TCP::payload]] "x-mms-message-id: " 18 1]
log local0. "172_message-ID : $dq_message"
if { $dq_message equals "1" } {
pool pool_172_MMS1_25
log local0. "LB_pool : 172_mms1 (78)"
}
elseif { $dq_message equals "4" } {
pool pool_172_MMS2_25
log local0. "LB_pool : 172_mms2 (79)"
}
else {
log local0. "LB server (78,79)"
pool pool_172_MMS_25
}
TCP::payload replace 0 [string length [TCP::payload]] $chelo$cfrom$crcpt$fdata$dq
TCP::respond "250 OK\r\n"
}
else {
set aa [TCP::payload]
log local0. "no-type"
log local0. "LB server (78,79)"
pool pool_172_MMS_25
TCP::payload replace 0 [string length [TCP::payload]] $chelo$cfrom$crcpt$fdata$aa
TCP::respond "250 OK\r\n"
}
}
log local0. "client END port : [client_port]"
}
when SERVER_CONNECTED {
log "server connected"
TCP::collect
}
when SERVER_DATA {
set sdata [TCP::payload]
log local0. "server port : [client_port]"
if { $sdata starts_with "220" } {
TCP::payload replace 0 [string length $sdata] ""
log local0. "172_220"
return
}
if { $sdata contains "\r\n354 " } {
TCP::payload replace 0 [string length $sdata] ""
log local0. "172_354"
return
}
if { [ string length $sdata ] <= 0 } {
return
}
TCP::release
TCP::collect
}
when CLIENT_CLOSED {
log local0. "172_client closed"
}
}