I'm trying to compose a tcl script to read a username from our radius server, and modify if it matches a couple of conditions.
First off, here is a typical username that I would want to modify: 0900000023000003780a2202fc0000229f
This is a hex string returned from a dslam. The issue is that the last 8 characters of the string can change on a whim. So I can't use it for authentication data. However, character's 19 through 26 contain the IP address of the device. So 0a2202fc equals the IP address 10.34.2.252. I will have a list of all the devices I will need to compare against.
So here is my plan:
1) Read the username
2) If the length of the username equals 34, send it through an if/else loop
a) Read characters 19~26
b) Comapre them to a(n) external file/array that has 300+ objects - Need help here
c) If the value stored in the array matches the 8 digit hex string pulled from the 19~26 of the username being sent, truncated the last 8 characters
i.e. 0900000023000003780a2202fc0000229f will be modified to 0900000023000003780a2202fc
d) send the new username through
3) ELSE do nothing and send the username through as presented.
With my elementary knowledge of tcl, I got a start with this.
proc ProcessBASIP {request response environ} {
set username [ $request get User-Name ]
That's as far as I have gotten. I understand some computer languages, but regular expressions and tcl are a bit above me.
Any help you can give me would be appreciated.
Thanks,
Don
First off, here is a typical username that I would want to modify: 0900000023000003780a2202fc0000229f
This is a hex string returned from a dslam. The issue is that the last 8 characters of the string can change on a whim. So I can't use it for authentication data. However, character's 19 through 26 contain the IP address of the device. So 0a2202fc equals the IP address 10.34.2.252. I will have a list of all the devices I will need to compare against.
So here is my plan:
1) Read the username
2) If the length of the username equals 34, send it through an if/else loop
a) Read characters 19~26
b) Comapre them to a(n) external file/array that has 300+ objects - Need help here
c) If the value stored in the array matches the 8 digit hex string pulled from the 19~26 of the username being sent, truncated the last 8 characters
i.e. 0900000023000003780a2202fc0000229f will be modified to 0900000023000003780a2202fc
d) send the new username through
3) ELSE do nothing and send the username through as presented.
With my elementary knowledge of tcl, I got a start with this.
proc ProcessBASIP {request response environ} {
set username [ $request get User-Name ]
Code:
if { [ string length $username ] == 34} { string equal string trimright # SETUP NEW USERNAME $environ put User-Name $NEW_username } else { $environ put User-Name $username }
Any help you can give me would be appreciated.
Thanks,
Don