<%@ page import="java.util.*,java.io.*, java.net.*, java.security.*, java.text.*, java.security.NoSuchAlgorithmException, java.math.*, java.net.InetAddress ;"%> <% // MobGold Publisher Install Code // Language: Java // Version: MG-20110420 // Copyright MobGold Ltd, All rights reserved // Parameters to make MobGold request String sm = "02f800fer644RL"; // sm is required to request ads from MobGold String test = "1"; // Set 1 for test mode, set 0 for live mode // Optional parameter String ad_type = ""; // 0 = both, 1 = text, 2 = banner String ad_lang = ""; // EN, AR, ZZ, EN, FR, DE, ID, IT, JA, PT, RU, ES, TH, OT String cookieDomain = ""; // Set cookie to better identify unique users ///////////////////////////////// // Do not edit below this line // ///////////////////////////////// // This section defines MobGold functions and should be used AS IS. String ver = ""; String ipr = ""; String url = ""; String tm = ""; String ck = ""; String pt = ""; Date now = new Date(); DecimalFormat formatter = new DecimalFormat("###.###"); double tmstp = (double) (now.getTime()); if(request.getRemoteAddr() != null){ ipr = request.getRemoteAddr(); } if(request.getQueryString() != null){ url = request.getQueryString(); } pt = request.getRequestURL().append( null!=url? ("?" + url):"" ).toString(); String ua = request.getHeader("User-Agent"); if(request.getHeader("x-operamiani-phone-ua") != null){ ua = request.getHeader("x-operamini-phone-ua"); } if(request.getHeader("x-original-user-agent") != null){ ua = request.getHeader("x-original-user-agent"); } if(request.getHeader("x-device-user-agent") != null){ ua = request.getHeader("x-device-user-agent"); } if(cookieDomain != null || cookieDomain != ""){ ck = mobgoldSetCookieValue(request, response, pageContext, cookieDomain); } tmstp = tmstp / 1000; formatter.setMinimumFractionDigits(3); tm = formatter.format(tmstp); sm = URLEncoder.encode( sm, "UTF-8" ); ver = URLEncoder.encode( "JSP-20110420-abc123xx", "UTF-8" ); pt = URLEncoder.encode( pt, "UTF-8" ); tm = URLEncoder.encode( tm, "UTF-8" ); ua = URLEncoder.encode( ua, "UTF-8" ); ipr = URLEncoder.encode( ipr, "UTF-8"); ck = URLEncoder.encode( ck, "UTF-8" ); Enumeration MGHeaders = request.getHeaderNames(); String MGHeadersString = ""; List ignore = Arrays.asList(new String[]{"CONNECTION", "PRAGMA", "COOKIE", "CACHE-CONTROL"}); while( MGHeaders.hasMoreElements()){ String MGHeaderName = (String)MGHeaders.nextElement(); String MGHeaderVal = request.getHeader( MGHeaderName ); MGHeaderName = MGHeaderName.toUpperCase(); if (!ignore.contains(MGHeaderName)){ if( null!=MGHeaderName && null!=MGHeaderVal ){ MGHeaderVal = URLEncoder.encode( MGHeaderVal, "UTF-8" ); MGHeadersString = MGHeadersString + "&mg_HTTP_" + MGHeaderName.replace('-','_') + "=" + MGHeaderVal ; } } } String reqURL = "http://ads.mobgold.com/r.php"; String postContent = "sm=" + sm + "&ver=" + ver + "&test=" + test + "&type=" + ad_type + "&lan=" + ad_lang + "&pt=" + pt + "&tm=" + tm + "&ua=" + ua + "&ipr=" + ipr+ "&ck=" + ck + MGHeadersString ; URL MGRequest= new URL( reqURL ); HttpURLConnection GetMGAdd = ( HttpURLConnection )MGRequest.openConnection(); GetMGAdd.setConnectTimeout( 5000 ); GetMGAdd.setReadTimeout( 5000 ); GetMGAdd.setDoInput( true ); GetMGAdd.setDoOutput( true ); GetMGAdd.setUseCaches( false ); GetMGAdd.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" ); GetMGAdd.addRequestProperty( "MG-SiteMask", sm ); GetMGAdd.setRequestProperty( "charset", "UTF-8" ); GetMGAdd.setRequestMethod("POST"); String Contents = ""; try { DataOutputStream post = new DataOutputStream( GetMGAdd.getOutputStream() ); post.writeBytes( postContent ); InputStream MgIS = GetMGAdd.getInputStream(); InputStreamReader MgSR = new InputStreamReader( MgIS ); BufferedReader MgBR = new BufferedReader( MgSR); String MgTemp = null; while ( null != (MgTemp = MgBR.readLine()) ) { Contents += MgTemp; } if( null != Contents ) { out.print( Contents ); } } catch (Exception ex) { } %> <%! private String mobgoldSetCookieValue(HttpServletRequest request, HttpServletResponse response, PageContext pageContext, String cookieDomain) { try { Cookie cookies[] = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals("mobgoldcoo")) return cookies[i].getValue(); } } if (pageContext.getAttribute("mg_cookie") == null) { long rand = Math.round(Math.random()*32768); Date now = new Date(); double timestamp = (double) (now.getTime()/1000); NumberFormat formatter = new DecimalFormat(); String ts = formatter.format(timestamp); String value = mg_md5(ts + rand); Cookie c = new Cookie("mobgoldcoo", value); c.setMaxAge(3600*24*365); c.setPath("/"); if (cookieDomain != null) { if (cookieDomain.charAt(0) != '.') cookieDomain = "." + cookieDomain; c.setDomain(cookieDomain); } response.addCookie(c); pageContext.setAttribute("mg_cookie", value); } return (String)pageContext.getAttribute("mg_cookie"); } catch (Exception e) { return ""; } } private String mg_md5(String value) throws NoSuchAlgorithmException{ String md5Hex = ""; if(value != null || value.length() != 0){ MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(value.getBytes(), 0, value.length()-1); md5Hex = new BigInteger(1, md5.digest()).toString(16); while (md5Hex.length() < 32) md5Hex = "0" + md5Hex; } return md5Hex; } %>