Forum Discussion
Looking for iRule to convert non-ascii character to ascii
We have users having French character in their name and so F5 convert entire att.dn into hex string. And so comparison against the DN (to see what OU the user is in) breaks.
attr.dn' set to '0x434e3d....'
Is there iRule available to fix this issue until newer software release comes out.
And yes I am new to iRule. So please provide as much detail as possible like which line does what. Thank you for your support.
4 Replies
- What_Lies_Bene1
Cirrostratus
Are these characters actually supported by ASCII? If not, they can't be converted into ASCII surely?
This is a tough one for a newbie to be facing.
Something like this might work:
set hex_string [what_ever_you_use_to_get_the_hex_dn] set some_variable [binary format a* [encoding convertto utf-8 [$hex_string]] log local0. "The converted string is ${some_variable}"The string, scan and expr commands can also be used in some fashion but without a way to test I can't confidently say what will work I'm afraid.
- Dmitriy_Sysoev
Nimbostratus
In 12.0.0
ID 399693:
t is now possible to use the -decode option for mcget command of a branch rule to decode a session variable before using it. When you create an agent and add a branch rule, the default value of the rule contains an mcget command to fetch the session variable. By default, the session variable is HEX encoded if it contains non-ASCII characters. You need to modify the command in advanced mode and insert the -decode option for mcget command, for example: expr { [mcget -decode {session.ad.last.attr.memberOf}] contains "non-ASCII-characters" }
- adack
Nimbostratus
That's what worked for me:
proc hex2ascii {sHex} { # latin-1 supplement, unicode u+0000 - u+00ff set iByte 0 # check if string begins with '0x' if { [scan $sHex {0x%s} sHex] > 0} { # loop each character foreach sChar [ split [binary format H* $sHex] ""] { # convert to decimal scan $sChar %c iChar if {$iChar < 0x80} { # standard ascii append sAscii $sChar } elseif {$iChar > 0xc2} { set iByte [expr ({$iChar} - 0xc2) * 0x40] } elseif {$iChar < 0xc2} { # convert to ascii append sAscii "[format %c [expr {$iByte} + {$iChar}]]" set iByte 0 } } return $sAscii } else { return $sHex } }Calling the function with the following attribute will return ASCII
[call hex2ascii 0x434e3d....]Hope this helps.
Used this today for the same purpose, it's working.
[encoding] TCL commands seem not to be available in iRule (tested in v13-14)
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com