The i-Technology Media!
Register | Log in
   
 
.NET  ·  AJAX  ·  CLOUD  ·  ECLIPSE  ·  FLEX  ·  OPEN WEB  ·  iPHONE  ·  JAVA  ·  LINUX  ·  OPEN SOURCE  ·  ORACLE  ·  PBDJ  ·  SEARCH  ·  SILVERLIGHT  ·  SOA  ·  VIRTUALIZATION  ·  WEB 2.0  ·  WIRELESS  ·  XML
Comments
Drool, Britannia? Is the UK Failing the Cloud?
By Roger Strukhoff
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Jan. 8, 2012 11:38 AM EST
read more & respond »
Cloud Expo on Google News
Did you read today's front page stories & breaking news?

Cloud Expo & Virtualization 2011 West
Keynotes
Oracle
Opening Keynote | An Enterprise Cloud for Business-Critical Applications
Abiquo
Day 2 Keynote | The Enterprise Cloud Tightrope - Balancing for Success
Akamai
Day 3 Keynote | The DNA of an Enterprise Cloud
DIAMOND SPONSOR:
Oracle
Many Clouds, Many Choices'Cloud
PLATINUM PLUS SPONSORS:
Abiquo
Enterprise Cloud Best Practices - Town Hall - Join the discussion…
PLATINUM SPONSORS:
Intel
Progressing Toward the Federated, Automated and Client-Aware Cloud
New Relic
How to build an app with Twitter-like throughput
Rackspace
Computing in the Cloud Era
GOLD SPONSORS:
Gale Technologies
Practical Cloud Migration
IBM
Re-think IT. Re-inventing Business.
Intel/McAfee
Identity Driven Security in the Cloud
PerspecSys
Hackers Hackers Everywhere, Is My Public Cloud That Safe?
Red Hat
Unlock the Value of the Cloud
SHI
Mission Critical Applications and the Cloud - Myth or Reality?
SoftLayer
Not Your Grandpa's Cloud
Terremark
Integrating Enterprise Clouds
VMware
Upgrade to a vCloud
POWER PANELS:
Cloud Expo Silicon Valley: CTO Power Panel
Cloud Expo Silicon Valley: CEO Power Panel
Cloud Expo Silicon Valley: Cloud SuperStars Panel
Cloud Expo Silicon Valley: CloudNOW Panel
Click For 2010 West
Event Webcasts
Cloud Expo & Virtualization 2011 East
DIAMOND SPONSOR:
Dell
Dell & VMware Deliver the Enterprise Hybrid Cloud
PLATINUM PLUS SPONSORS:
Abiquo
Are Financial Services Organizations Risking Security by Avoiding Cloud Computing?
Oracle
From Consolidation to Enterprise Private PaaS
PLATINUM SPONSORS:
Intel
Driving the Transformation to Next Generation Cloud Data Centers
Rackspace
The Inevitability of an Open Cloud
GOLD SPONSORS:
CA Technologies
Follow YOUR path to Cloud Computing
Interxion
Who Keeps the Cloud in the Air?
Microsoft
Patterns for Cloud Computing
PerspecSys
War in the Clouds: Are you ready?
ServiceMesh
The Big Win: Stop Playing Small-Ball with Your Cloud Strategy
Terremark
Evaluating Enterprise Clouds
Xiotech
Cloud Storage: Myths and Realities
POWER PANELS:
Cloud Expo New York: CTO Power Panel
Cloud Expo New York: CEO Power Panel
Cloud Expo New York: CMO Power Panel
Cloud Expo New York: Wrap-Up Power Panel
Click For 2010 West
Event Webcasts
Live Google News by SYS-CON!
Top Three Links You Must Click On


20 Lines or Less #28

By: Colin Walker
Aug. 11, 2009 01:50 PM

What could you do with your code in 20 Lines or Less? That's the question I ask (almost) every week for the devcentral community, and every week I go looking to find cool new examples that show just how flexible and powerful iRules can be without getting in over your head.

Today I bring you a few more fine examples of iRules kung fooery in a brief fashion.  These tidbits of iRuley goodness could be used by themselves, as the beginning to a bigger project or solution, or just to get the creative coding juices flowing for you to think of what you might need or want to do with iRules in your world.  To me, it’s just a great way to look at what’s being done, how people are using the technology, and what can be achieved in just a few lines of code.

 

Modifying Secure Access Manager session variables

http://devcentral.f5.com/wiki/default.aspx/iRules/Modifying_Secure_Access_Manager_v8_session_variables_with_a_cookie.html

From the CodeShare comes a very cool entry, complete with diagrams and pictures (yay pictures!), that shows us how we might use iRules in conjunction with another product. The author gives a full description in the link above, so follow that for all the details, but to quote briefly, “In this example, an external server is used to authenticate users before passing those authentication credentials over to the Secure Access Manager (SAM v8) using a cookie.” Cool stuff. The iRule is below but there’s more to this one so click on the link to check it out.

when HTTP_REQUEST {
  #Check to see if a cookie exists, otherwise no need to do anything.
  #You should probably also check to see if the session variables are already set before doing anything
  #as well, but this code is just for demonstration purposes.
  if { [HTTP::cookie exists MySAMCookie] } {
    #Log the session state - this is just for demonstration purposes
    #SAM allows you to gather the values of session variables with the SESSION::data command
    log local0. "Session ID is $tmm_fp_session_id and the status is [SESSION::data get $tmm_fp_session_id \"session.state\"]"

    #Use the SESSION command to set the userID and password
    #session variables to what was in the cookie.  The userID and password are just cookie values

    SESSION::data set $tmm_fp_session_id session.logon.last.username [HTTP::cookie MySAMUser]
    SESSION::data set $tmm_fp_session_id session.logon.last.password [HTTP::cookie MySAMpw]
  }
}

 

Replace absolute URLs in redirects

This one comes from email so there’s no link, but it’s straight-forward and well commented. The idea is a good one. If a URL is being passed through in the location header of a redirect and it’s an absolute location, change it to be relative.  Very handy.

# This will rewrite the Location header on a redirect from a absolute URL like
#
#        
http://host/images/ to /images/
# or
#         like
https://host/images/ to /images/
#
# The only case it will not handle is
http:/// which will get rewritten to "" which is invalid
#

when HTTP_RESPONSE {
  if { [HTTP::is_redirect] } {
    if { [HTTP::header "Location"] starts_with "http" } {
      HTTP::header replace "Location" [substr [HTTP::header "Location"] [string first "/" [HTTP::header "Location"] 8]]    
    }
  }        
}

 

Persisting on part of a cookie name

http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=60792&view=topic

This user wanted to use cookie persistence but was looking to setup persistence for cookies that began with a certain string. This means he wanted to loop through all cookies and compare them each against a static search string. They figured out their own solution though, so kudos to them.

#HTTP responds catches the first responds from the node to back to the client.
#It checking all cookies in the header and grabs all starting with 1234.
#After it adds the cookie value to the persistence table and log values to syslog.
#Else persist the client for 60 minutes based on source IP with /32 mask and log values to syslog.

when HTTP_RESPONSE { 
  foreach a_cookie [HTTP::cookie names] {
    if {$a_cookie starts_with "1234"}{
      persist add uie [HTTP::cookie "$a_cookie"]
      log local0.debug "Cookie persist - client IP: [IP::client_addr], Cookie: $a_cookie, Server IP: [IP::server_addr]"
    } else { 
      persist source_addr 255.255.255.255 3600
      log local0.debug "Source persist - client IP: [IP::client_addr] , Server IP: [IP::server_addr], lookup [persist lookup uie [IP::client_addr]]"
    } 
  } 
}
#HTTP request catches the first responds from the node to back to the client.
#It checking all cookies in the header and grabs all starting with 1234.
#After it persist on the cookie value in the persistence table.
#Also, log values to syslog

when HTTP_REQUEST { 
  foreach a_cookie [HTTP::cookie names] {
    if {$a_cookie starts_with "1234"}{
      persist uie [HTTP::cookie "a_cookie"]
      log local0.debug "Client IP: [IP::client_addr], Cookie value: $a_cookie"
    } else { 
      persist uie [IP::client_addr]
      log local0.debug "Source IP Persistence used - Client IP: [IP::client_addr], Persistence entries used persist uie [persist lookup uie [IP::client_addr]]"
    } 
  }
}

There you have it, three more awesome iRule examples from three different sources. You’ve got to love that.  Keep those examples coming whether it’s in the forums or the CodeShare, and don’t forget you can always email me to toss out ideas, ask for things you’d like to see, discuss your favorite X-Men character, or whatever suits you.

Technorati Tags: DevCentral,20Lines or Less,iRules,Persistence,Cookies,Colin Walker

#Colin

Read the original blog entry...

Published Aug. 11, 2009— Reads 513
Copyright © 2009 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
About Colin Walker
Coming from a *Nix Software Engineering background, Colin is no stranger to long hours of coding, testing and deployment. His personal experiences such as on-stage performance and the like have helped to foster the evangelist in him. These days he splits his time between coding, technical writing and evangalism. He can be found on the road to just about anywhere to preach the good word about ADCs, Application Aware networking, Network Side Scripting and geekery in general to anyone that will listen.

Colin currently helps manage and maintain DevCentral (http://devcentral.f5.com). He is also a contributor in many ways, from Articles to Videos to numerous forum posts, to iRules coding and whatever else he can get his hands on that might benefit the community and allow it to continue to grow.

Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers

ADS BY GOOGLE

Breaking Java News
AXON Video System Captures Officers Using TASER X26 Saving Suicidal Man
Faruqi & Faruqi, LLP is Investigating Parametric Technology Corporation on Behalf of its Shareholders (PMTC)
GOOD MORNING
POWERVAR Will Release the Mobile Power Manager (MPM) at the Upcoming HIMSS '12 Annual Conference

ADVERTISE   |   MAGAZINE SUBSCRIPTIONS   |   FREE BREAKING-NEWSLETTERS!   |   SYS-CON.TV   |   BLOG-N-PLAY!   |   WEBCAST   |   EDUCATION   |   RESEARCH

.NET Developer's Journal - .NETDJ   |   ColdFusion Developer's Journal - CFDJ   |   Eclipse Developer's Journal - EDJ   |   Enterprise Open Source Magazine - EOS
Open Web Developer's Journal - OPENWEB   |   iPhone Developer's Journal - iPHONE   |   Virtualization - Virtualization   |   Java Developer's Journal - JDJ   |   Linux.SYS-CON.com
PowerBuilder Developer's Journal - PBDJ   |   SEO / SEM Journal - SJ   |   SOAWorld Magazine - SOAWM   |   IT Solutions Guide - ITSG   |   Symbian Developer's Journal - SDJ
WebLogic Developer's Journal - WLDJ   |   WebSphere Journal - WJ   |   Wireless Business & Technology - WBT   |   XML-Journal - XMLJ   |   Internet Video - iTV
Flex Developer's Journal - Flex   |   AJAXWorld Magazine - AWM   |   Silverlight Developer's Journal - SLDJ   |   PHP.SYS-CON.com   |   Web 2.0 Journal - WEB2
Apache   |   CMS   |   CRM   |   HP   |   Oracle Journal   |   Perl   |   Python   |   Red Hat   |   Ruby on Rails   |   SAP   |   SaaS

SYS-CON MEDIA:   ABOUT US   |   CONTACT US   |   COMPANY NEWS   |   CAREERS   |   SITE MAP
SYS-CON EVENTS:   |  AJAXWorld Conference & Expo  |  iPhone Developer Summit  |  Cloud Computing Conference & Expo  |  SOA World Conference & Expo  |  Virtualization Conference & Expo
INTERNATIONAL SITES:   India  |  U.K.  |  Canada  |  Germany  |  France  |  Australia  |  Italy  |  Spain  |  Netherlands  |  Brazil  |  Belgium
 Terms of Use & Our Privacy Statement     About Newsfeeds / Video Feeds
Copyright ©1994-2008 SYS-CON Publications, Inc. All Rights Reserved. All marks are trademarks of SYS-CON Media.
Reproduction in whole or in part in any form or medium without express written permission of SYS-CON Publications, Inc. is prohibited.
 
close this window