gomobi Traffic Switching Guide Version 0.9, 28 September 2010



Similar documents
AdFalcon Mobile Web API Integration Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

Online Data Services. Security Guidelines. Online Data Services by Esri UK. Security Best Practice

Building a Multi-Threaded Web Server

DEPLOYMENT GUIDE Version 1.0. Deploying the BIG-IP LTM with Apache Tomcat and Apache HTTP Server

Drupal CMS for marketing sites

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

Liferay, Alfresco, SSO and LDAP Full Integration

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

The HTTP Plug-in. Table of contents

DEPLOYMENT GUIDE Version 1.1. Deploying the BIG-IP LTM v10 with Citrix Presentation Server 4.5

CTIS 256 Web Technologies II. Week # 1 Serkan GENÇ

LabVIEW Internet Toolkit User Guide

Administering Jive for Outlook

FileMaker Server 10 Help

Oracle9i Application Server: Options for Running Active Server Pages. An Oracle White Paper July 2001

Working With Virtual Hosts on Pramati Server

Apache Server Implementation Guide

FileMaker Server 11. FileMaker Server Help

WIRIS quizzes web services Getting started with PHP and Java

DEPLOYMENT GUIDE Version 1.2. Deploying the BIG-IP System v10 with Microsoft IIS 7.0 and 7.5

Getting Started with AWS. Hosting a Static Website

Fairsail REST API: Guide for Developers

4 Understanding. Web Applications IN THIS CHAPTER. 4.1 Understand Web page development. 4.2 Understand Microsoft ASP.NET Web application development

FileMaker Server 12. FileMaker Server Help

Front-End Performance Testing and Optimization

DEPLOYMENT GUIDE DEPLOYING F5 WITH MICROSOFT WINDOWS SERVER 2008

Still Aren't Doing. Frank Kim

A Server and Browser-Transparent CSRF Defense for Web 2.0 Applications. Slides by Connor Schnaith

Portals and Hosted Files

SiteCelerate white paper

(An) Optimal Drupal 7 Module Configuration for Site Performance JOE PRICE

Analytics Configuration Reference

CSc31800: Internet Programming, CS-CCNY, Spring 2004 Jinzhong Niu May 9, Java Servlets


Kentico CMS, 2011 Kentico Software. Contents. Mobile Development using Kentico CMS 6 2 Exploring the Mobile Environment 1

CS506 Web Design and Development Solved Online Quiz No. 01

FileMaker Server 13. Getting Started Guide

DEPLOYMENT GUIDE DEPLOYING THE BIG-IP LTM SYSTEM WITH CITRIX PRESENTATION SERVER 3.0 AND 4.5

CHAPTER 4 PERFORMANCE ANALYSIS OF CDN IN ACADEMICS

PHP Integration Kit. Version User Guide

1. When will an IP process drop a datagram? 2. When will an IP process fragment a datagram? 3. When will a TCP process drop a segment?

Integrating the F5 BigIP with Blackboard

DEPLOYMENT GUIDE Version 1.1. Deploying F5 with IBM WebSphere 7

Addressing Mobile Load Testing Challenges. A Neotys White Paper

Lesson: All About Sockets

DEPLOYMENT GUIDE Version 1.2. Deploying the BIG-IP System v9.x with Microsoft IIS 7.0 and 7.5

Getting Started Guide for Developing tibbr Apps

COSC 6397 Big Data Analytics. Mahout and 3 rd homework assignment. Edgar Gabriel Spring Mahout

Using ilove SharePoint Web Services Workflow Action

Web Application Security

DEPLOYMENT GUIDE Version 2.1. Deploying F5 with Microsoft SharePoint 2010

Novell Identity Manager

FileMaker Server 15. Getting Started Guide

Intellicus Single Sign-on

Web applications. Web security: web basics. HTTP requests. URLs. GET request. Myrto Arapinis School of Informatics University of Edinburgh

VB.NET - WEB PROGRAMMING

Volume SYSLOG JUNCTION. User s Guide. User s Guide

How to Configure Dynamic DNS on a Virtual Access Router

Develop PHP mobile apps with Zend Framework

Getting Started with AWS. Static Website Hosting

Configuring Microsoft IIS 5.0 With Pramati Server

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

Getting Started with AWS. Hosting a Static Website

DEPLOYMENT GUIDE DEPLOYING F5 WITH VMWARE VIRTUAL DESKTOP INFRASTRUCTURE (VDI)

An Insight into Cookie Security

Introducing the Microsoft IIS deployment guide

Lesson 7 - Website Administration

Collax Web Security. Howto. This howto describes the setup of a Web proxy server as Web content filter.

Understanding Slow Start

DEPLOYMENT GUIDE Version 1.0. Deploying the BIG-IP LTM with Microsoft Windows Server 2008 R2 Remote Desktop Services

Configuring Nex-Gen Web Load Balancer

PaperCut Payment Gateway Module CyberSource Quick Start Guide

DEPLOYMENT GUIDE Version 1.0. Deploying the BIG-IP LTM System with VMware View

An Introduction To The Web File Manager

Beginning Smartphone Web Development

Designing for Mobile Devices

Web Server Manual. Mike Burns Greg Pettyjohn Jay McCarthy November 20, 2006

DEPLOYMENT GUIDE. Deploying F5 for High Availability and Scalability of Microsoft Dynamics 4.0

Tableau Server Trusted Authentication

Enterprise Application Security Workshop Series

Citrix Receiver for Mobile Devices Troubleshooting Guide

Security-Assessment.com White Paper Leveraging XSRF with Apache Web Server Compatibility with older browser feature and Java Applet

13 File Output and Input

Security IIS Service Lesson 6

White Paper March 1, Integrating AR System with Single Sign-On (SSO) authentication systems

DEPLOYMENT GUIDE DEPLOYING THE BIG-IP SYSTEM WITH MICROSOFT INTERNET INFORMATION SERVICES (IIS) 7.0

Programming Autodesk PLM 360 Using REST. Doug Redmond Software Engineer, Autodesk

Web Intrusion Detection with ModSecurity. Ivan Ristic

FileMaker Server 13. FileMaker Server Help

WEB DATABASE PUBLISHING

Web Application Development

Protocolo HTTP. Web and HTTP. HTTP overview. HTTP overview

Application Security Policy

Load Balancing Microsoft Terminal Services. Deployment Guide

Apache Traffic Server Extensible Host Resolution

Transcription:

gomobi Traffic Switching Guide Version 0.9, 28 September 2010

Mobile/Desktop Traffic Switching... 3 Summary of Options... 3 Single Site Solutions... 4 Server-side Switching Code... 4 JavaScript Switching Code... 4 Multi-Site Switching Service... 5 Redirect Service... 5 Redirect/Proxy Service... 6 DeviceAware... 6 Appendix A Code Samples... 7 PHP Code... 7 JSP Code... 8 ASP.net Code... 11 JavaScript Code... 13 2

Mobile/Desktop Traffic Switching gomobi allows you to create a mobile site for your business. In order to make the best use of this mobile-friendly site we recommend that you add functionality to your existing desktop web site to automatically redirect mobile devices to the mobile site. This ensures the mobile users get the best experience even if they type in the address of the existing desktop site. This document summarizes the traffic switching options open to site owners, registrars and hosters. Summary of Options There are multiple different traffic switching options that are open to gomobi resellers, each one with its own benefits and issues. In particular, the best solution to deploy depends on whether the site is hosted by the channel partner or hosted elsewhere, and whether or not a designer/developer in involved: In general, for traffic switching options to work well, you need access to the original site and server to implement an effective solution. The following table summarizes the options that are open. In all cases we are assuming that there are two web sites with URLs site.com and site.mobi, though the choice of TLD is not important. Scenario Environment Switching Option Notes Single web site solution (individual developers) Access to underlying server available Embed server-side switching code in site using PHP / JSP or ASP.net. Good solution, works on all devices No access to underlying server Embed JavaScript switching code in site HTML Not guaranteed, recommended only as last-ditch option Multi-site switching service (switching service made available to DNS alias for desktop considered acceptable e.g. desktop.site.com 1) Redirect service using DeviceAware that redirects to desktop.site.com or site.mobi as appropriate Simple solution but relies on an alias e.g. desktop.site.com DNS being in place, which may be a problem. 2) Redirect/proxy service Same reliance on 3

partners) using DeviceAware that redirects to site.mobi or proxies traffic to desktop.site.com desktop.site.com alias. These options are described in the following sections. Single Site Solutions Server-side Switching Code Server-side switching code is switching code that is operated co-resident with the existing site. Typically this takes the form of PHP, JSP or ASP code that is built into certain pages on the site. The switcher code can be implemented as a new default page for the root URL that redirects users to a new home page on the desktop site or to the mobile-friendly URL. Alternatively, switching code can be added to a subset or all pages of the existing site to ensure that mobile users are redirected even if the initial page visited is not the home page. The code is typically quite simple and merely redirects the user to the mobile-friendly URL if a mobile device is detected. The logic looks like this: define('da_uri', 'http://detect.deviceatlas.com/query'); $da_json = @file_get_contents(da_uri. "?User-Agent=". urlencode($_server["http_user_agent"])); $da_results = (array)json_decode($da_json, true); if ($da_results['mobiledevice']) { header('location: http://mobile.mobi/'); This code relies on a web-service version of DeviceAtlas to detect the nature of the requesting device. In practice, to make this detection logic run acceptably quickly some local caching is required and is included in the provided code samples. Sample code is available in PHP, JSP and ASP.net. An Apache module version of the same API is also available and allows the switching logic to be implemented in any programming language that can access Apache environment variables. This switching method results in a very good user experience and does not require DNS aliases such as desktop.site.com nor that the desktop site to respond to these aliases. Clearly, installing such code requires that the site operator has the ability to gain access to the code that underpins the site in question. From the site owner point of view the difficulty of implementation depends on the nature of the site but some coding skills will be required. JavaScript Switching Code This is a variant of the server-side switching code that does not require access to the source code underpinning the site in question. Instead, a JavaScript switcher is invoked by referencing a dynamically-generated JavaScript file hosted by dotmobi within the <head> element of pages on the site. One the initial page HTML has loaded, the browser will then be redirected to the alternate address, a mobile-friendly URL. From the site owner point of view integration of the 4

switcher code is straight-forward as the drop-in JavaScript solution is a familiar model. The drop-in code looks like this: <script type="text/javascript" src="http://detect.deviceatlas.com/redirect.js?d=http://desktop.com&m=http://mobile.mobi"> </script> where http://desktop.com is the URL of your desktop site and http://mobile.mobi is the URL of your mobile site. This switching method has the advantage that only HTML changes are required to the site no changes to the underlying logic are required. The downside is that JavaScript redirection is not guaranteed to work in all cases, especially on older mobile devices. Multi-Site Switching Service Redirect Service For hosters and registrars a multi-site switching option is desirable because it enables multiple desktop/mobile site pairs to utilize a single traffic switching solution. The easiest way to accomplish this a combination of a redirecting service in conjunction with a DNS alias for the existing desktop website. For example, if the existing desktop site is site.com and the newly created mobile site is site.mobi, the following DNS changes are required: modify the A record of site.com to point at the switching service IP address add an A record for desktop.site.com that points at the existing site.com web server machine The following sequence diagram shows what happens when a user with a desktop browser tries to visit site.com by typing the URL http://site.com into their browser. In the case where a user enters the URL for the mobile site directly there is no requirement to go via the switcher the IP address of the site.mobi site can be pointed directly at the servers for the mobile site. There are three issues with this solution: a DNS entry must be added for the chosen third-level alias e.g. desktop.site.com 5

the desktop site (site.com) must be configured to respond to requests for desktop.site.com users and stats packages may have an issue with the desktop.site.com URL Redirect/Proxy Service A variant of the redirect service is one that, in the case of a desktop browser visiting site.com, proxies the onward traffic to desktop.site.com instead of redirecting. This solution may work better in a hosting environment where the switcher machine and the server for site.com are in fact the same machine i.e. each web server in a farm also has device detection and proxying capabilities built in. DeviceAware The switch solutions described in the previous sections rely on dotmobi's DeviceAware software component. DeviceAware is not a packaged solution it is a software component that is designed to be integrated into existing infrastructure to enable switching applications. DeviceAware combines a database of mobile and desktop device properties with a query API to enable an intelligent switching service to be built that bases its decisions on the nature of the device in question. The DeviceAware API is available for Java, PHP,.net and C++. In each case the API provides a query method that takes an HTTP User Agent header from an HTTP request and returns a Boolean property indicating of the device is mobile or not. This property can then be used to decide the best course of action to take, which typically means redirecting the browser to an alternate, mobile-friendly, address. DeviceAware is also available in the form of an Apache module. Enabling this module on an Apache server adds an environment variable to every request received by the server. This environment variable can then be acted upon by subsequently executing modules or Apache configuration rules. The DeviceAware data file is updated daily by dotmobi and can be downloaded as frequently as desired by customers. 6

Appendix A Code Samples PHP Code <?php define('mobile_site', 'http://live.com'); define('desktop_site', 'http://google.com'); if($_request['redirect']=='false') { header('location: '. DESKTOP_SITE ); exit; define('da_use_cookies', true); define('da_use_cache', true); define('da_cache_dir', sys_get_temp_dir(). DIRECTORY_SEPARATOR. 'DeviceAtlasCache'. DIRECTORY_SEPARATOR); define('da_uri', 'http://detect.deviceatlas.com/query'); $da_results = array('_source' => 'none'); if (DA_USE_COOKIES && isset($_cookie['mobi_mtld_da_properties'])) { $da_results = (array)json_decode($_cookie['mobi_mtld_da_properties'], true); $da_results['_source'] = 'cookie'; if (DA_USE_CACHE && $da_results['_source'] === 'none') { $da_cache_file = md5($_server["http_user_agent"]). '.json'; if (!file_exists(da_cache_dir) &&!@mkdir(da_cache_dir)) { $da_results['_error'] = "Unable to create cache directory: ". DA_CACHE_DIR. "\n"; else { $da_json = @file_get_contents(da_cache_dir. $da_cache_file); if ($da_json!== false) { $da_results = (array)json_decode($da_json, true); $da_results['_source'] = 'cache'; if (DA_USE_COOKIES) { setcookie('mobi_mtld_da_properties', $da_json); if ($da_results['_source'] === 'none') { $da_json = @file_get_contents(da_uri. "?User-Agent=". urlencode($_server["http_user_agent"])); if ($da_json!== false) { $da_results = array_merge(json_decode($da_json, true), $da_results); $da_results['_source'] = 'webservice'; if (DA_USE_COOKIES) { setcookie('mobi_mtld_da_properties', $da_json); if (DA_USE_CACHE) { if (@file_put_contents(da_cache_dir. $da_cache_file, $da_json) === false) { $da_results['_error'].= "Unable to write cache file ". DA_CACHE_DIR. $da_cache_file. "\n"; else { $da_results['_error'].= "Error fetching DeviceAtlas data from webservice.\n";?> if($da_results['mobiledevice']) header('location: '. MOBILE_SITE); else header('location: '. DESKTOP_SITE); 7

JSP Code <%@ page import="java.net.*, java.io.*, java.security.*" %> <% final String mobilesite = "http://live.mobi"; final String desktopsite = "http://google.com"; if(request.getparameter("redirect")!=null && request.getparameter("redirect")=="false") { response.sendredirect(desktopsite); final String DA_URI = "http://detect.deviceatlas.com/query"; String source = "none"; boolean usecookies = true; boolean usecache = true; String error = ""; String dajson = null; final String DA_CACHE_DIR = System.getProperty("java.io.tmpdir")+ System.getProperty("file.separator")+"DeviceAtlasCache"+System.getProperty("file.separator"); String useragent = request.getheader("user-agent"); //Look up cookies if(usecookies) { dajson = getcookievalue("mobi_mtld_da_properties", request.getcookies()); if(dajson!= null &&!dajson.equals("null")) { source = "cookie"; //Look up cache if(usecache && source.equals("none")) { String filename = DA_CACHE_DIR + md5(useragent) + ".json"; File dir = new File(DA_CACHE_DIR); if(!dir.exists() &&!dir.mkdirs()) { error = "Unable to create cache directory: " + DA_CACHE_DIR + "\n"; else { //Read the cache file if it exists dajson = readfileasstring(filename); if(dajson!=null &&!dajson.trim().equals("null") &&!dajson.trim().equals("")) source = "cache"; //Look up DA webservice if we need to if(source.equals("none")) { URL DA = new URL("http://detect.deviceatlas.com/query?User-Agent=" + URLEncoder.encode(userAgent)); URLConnection conn = DA.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line = null; line = br.readline(); while (line!= null) { dajson += line; line = br.readline(); br.close(); if(null!=dajson) { source = "webservice"; if(usecookies) { Cookie cookie = new Cookie("Mobi_Mtld_DA_Properties", dajson); response.addcookie(cookie); if(usecache) { String filename = DA_CACHE_DIR + md5(useragent) + ".json"; 8

writefile(filename, dajson); String ismobile = parsejson(dajson, "mobiledevice"); //Do the redirect if(null!=ismobile && ismobile.equals("true")) response.sendredirect(mobilesite); else response.sendredirect(desktopsite); %> <%! //Parse json for property - really basic & assumes flat json file as returned by DA service static final String parsejson(string json, String property) { String[] tokens = json.split(",\\s\" \": \\{\" :\\s,\\s \\"); for(int i=0;i<tokens.length;i++) { if(tokens[i].trim().equals(property)) { return tokens[i+1].trim(); return null; //Get MD5 of string static final String md5(string cleartext) { byte[] buffer = cleartext.getbytes(); String resulthash = null; try { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] result = new byte[md5.getdigestlength()]; md5.reset(); md5.update(buffer); result = md5.digest(); StringBuffer buf = new StringBuffer(result.length * 2); for (int i = 0; i < result.length; i++) { int intval = result[i] & 0xff; if (intval < 0x10) { buf.append("0"); buf.append(integer.tohexstring(intval)); resulthash = buf.tostring(); catch (NoSuchAlgorithmException e) { return resulthash; //Read value of a cookie static final String getcookievalue(string cookiename, Cookie[] cookies) { if(null==cookies) return null; for(int i=0; i<cookies.length; i++) { Cookie cookie = cookies[i]; if (cookiename.equals(cookie.getname())) return(cookie.getvalue()); return null; //Read file as string static final String readfileasstring(string filepath) { byte[] buffer = new byte[(int) new File(filePath).length()]; BufferedInputStream f = null; try { f = new BufferedInputStream(new FileInputStream(filePath)); f.read(buffer); catch (Exception e) { finally { if (f!= null) try { f.close(); catch (IOException ignored) { 9

return new String(buffer); %> //Write to file static final void writefile(string filepath, String data) { Writer writer = null; try{ File file = new File(filePath); writer = new BufferedWriter(new FileWriter(file)); writer.write(data); catch (FileNotFoundException e) { catch (IOException e) { finally { try { if (writer!= null) { writer.close(); catch (IOException e) { 10

ASP.net Code <%@ Page Language="C#" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Security.Cryptography" %> <%@ Import Namespace="System.Net" %> <% string mobilesite = "http://live.mobi"; string desktopsite = "http://google.com"; if(request["redirect"]!=null && Request["redirect"]=="false") Response.Redirect(desktopSite); string source = "none"; bool usecookies = true; bool usecache = true; string dajson = null; string DA_CACHE_DIR = System.IO.Path.GetTempPath() + "DeviceAtlasCache\\"; string useragent = Request.UserAgent.ToString(); if(usecookies) { HttpCookie cookie = Request.Cookies["Mobi_Mtld_DA_Properties"]; if(cookie!=null) { dajson = cookie.value.tostring(); source = "cookie"; //Look up cache if(usecache && source=="none") { string filename = DA_CACHE_DIR + md5(useragent) + ".json"; if(!directory.exists(da_cache_dir)) Directory.CreateDirectory(DA_CACHE_DIR); else { //Read the cache file if it exists (assumes just one line of text) if(file.exists(filename)) { TextReader tr = new StreamReader(filename); dajson = tr.readline(); tr.close(); source="cache"; //Look up DA webservice if(source=="none") { string url = "http://detect.deviceatlas.com/query?user-agent=" + HttpUtility.UrlEncode(userAgent); WebClient client = new WebClient(); dajson = client.downloadstring( url ); if(dajson!=null && dajson!="null") { if(usecookies) { HttpCookie cookie = new HttpCookie("Mobi_Mtld_DA_Properties"); cookie.value = dajson; Response.Cookies.Add(cookie); if(usecache) { string filename = DA_CACHE_DIR + md5(useragent) + ".json"; TextWriter tw = new StreamWriter(filename); tw.writeline(dajson); tw.close(); string ismobile = parsejson(dajson, "mobiledevice"); if(ismobile=="true") Response.Redirect(mobileSite); else Response.Redirect(desktopSite); %> 11

<script runat="server" language="c#" > //Parse json for property - really basic & assumes flat json file as returned by DA service string parsejson(string json, String property) { string[] tokens = Regex.Split(json, ",\\s\" \": \\{\" :\\s,\\s \\"); for(int i=0;i<tokens.length;i++) { if(tokens[i].trim()==property) { return tokens[i+1].trim(); return null; //Function to create md5 hash of filename string md5(string cleartext) { MD5 md5 = MD5.Create(); byte[] inputbytes = System.Text.Encoding.ASCII.GetBytes(clearText); byte[] hash = md5.computehash(inputbytes); StringBuilder sb = new StringBuilder(); for (int i=0;i<hash.length; i++) { sb.append(hash[i].tostring("x2")); return sb.tostring(); </script> 12

JavaScript Code If you do not have access to your server there is one further option that can be used. This option uses JavaScript and hence can be pasted into the <head> section of your pages without having to alter the underlying server code. Note: this option is not recommended for a few reasons: It is not guaranteed to work on all devices, since many mobile phones do not execute JavaScript. Depending on the device, the entire HTML and linked resources in the page may be downloaded before the redirect happens, removing much of the benefit of switching to a mobile-friendly page. By necessity, the JavaScript must be generated each time, per device. This means that there will always be a delay while the device fetches the JavaScript file from the DeviceAtlas servers. To use this approach, add the following line to the <head> section of the relevant pages of your site. <script type="text/javascript" src="http://detect.deviceatlas.com/redirect.js?d=http://desktop.com&m=http://mobile.mobi"> </script> where http://desktop.com is the URL of your desktop site and http://mobile.mobi is the URL of your mobile site. The resulting JavaScript will then redirect mobile devices to the mobile site but leave desktop browsers at the current URL. This solution has been tested on the following browsers and device ranges: Opera Mini 4 and later Nokia Series 40 Series 3 and later Nokia Series 60 3rd Edition and later iphone (all types) Android 2.1 and later This solution has not been tested on the following classes of devices: OpenWave browsers Obigo browsers 13