For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

SergioG_133218's avatar
SergioG_133218
Icon for Nimbostratus rankNimbostratus
Sep 12, 2014

How to select pool based on http payload ...

Dears

 

I want to know if posible to follow ... The developers guys send via http to f5 some data ,this guys want to f5 select the pool based on http payload .

 

For example ...

 

Address: http://localhost:8080/bpm/api/bpm/zzzz/xxxx Http-Method: POST Content-Type: application/json Headers: {Content-Type=[application/json], Accept=[application/json]} Payload:

 

{"request":{"empresaAgente":"00099","idAgente":4455454,"idTerminal":"678","idCaja":1,"idOperador":"agente_test104","plataforma":"1","codPais":"AR","idBiller":94950004,"secuenciaFE":2574,"dato1c":null,"dato2c":null,"dato3c":null,"dato1n":1188888701,"dato2n":null,"importe":4000,"codMoneda":"ARS","fechaHoraFE":1409776991020,"fechaHoraBackEnd":1409776991603,"......

 

I want to find for example a value "idterminal":"678" to select pool "XXX"

 

If this possible ?? I think ..yes but Im a network adm not programmer this is a little problem ..for me of course ...

 

If any guy could help me ...

 

Thank in advance .. SergioA

 

3 Replies

  • Hello, I follow the following reasoning, trying to avoid regex for example. Of course the code is very simple and needs validation source page, size of request, if there is content, etc. But I think this code is a start for you.

     

    Regards.

     

    when HTTP_REQUEST {
        if { ([HTTP::method] eq "POST") } {
            HTTP::collect [HTTP::header Content-Length]
        }
    }
    
    when HTTP_REQUEST_DATA {
        set decoded [decode_uri [HTTP::payload]]
        log local0. "=== Decoded $decoded"
    
        set ini [string first "\"idTerminal\"" $decoded]
        if { $ini != -1 } {
            set end [string first "," $decoded $ini]
            set value [string range $decoded $ini [expr {$end-1}]]
            set idTerminal [lindex [split $value ":"] 1]
    
            switch -exact $idTerminal {
                678 -
                679 {
                    pool terminal_67x_pool
                }
                default {
                    pool default_pool
                }
            }
        }
    }
  • You could also use findstr to get the value:

    set id [findstr [URI::decode [HTTP::payload]] "\"idTerminal\":\"" 14 "\""]    
    

    This will find the first instance of "idTerminal":" in the payload, skip 14 characters (the length of that string), and then collect everything up to but not including the very next double quote, which in this case should be the ID value.

    One thing I'd want to point out here, is that for this method to be used to path management, you have to make sure that either a) a POST payload ID is in EVERY request, b) you have something in place for when it isn't, or c) you configure so,e form of persistence.

  • Guys

    Thanks for all. After few test I use ..

    when HTTP_REQUEST { if { ([HTTP::method] eq "POST") } { HTTP::collect [HTTP::header Content-Length] } }

    when HTTP_REQUEST_DATA { set decoded [decode_uri [HTTP::payload]] log local0. "=== Decoded $decoded"

    set ini [string first "\"idBiller\"" $decoded]
    if { $ini != -1 } {
        set end [string first "," $decoded $ini]
        set value [string range $decoded $ini [expr {$end-1}]]
        set idBiller [lindex [split $value ":"] 1]
        log local0. "=== ID Biller: $idBiller ==="
        switch -exact $idBiller {
            94950004 {
                pool Pool_recarga_XXX
                log local0. "=== Sali por TASA ==="
            }
            default {
                pool Pool_recarga_YYY
                log local0. "=== Sali por Default ==="
            }
        }
    }
    

    }