<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" import="com.fabersoft.jsp.*" import="java.util.Locale" import="java.util.Date" import="java.text.DateFormat" errorPage="" %><%! // ----------------------------------------- // - Statistics Collector Manager Function - // ----------------------------------------- public void raccolta_statistiche( String ID, boolean newVisitor, boolean newSession, String browserLang, Connection connMySQL, HttpServletRequest req, HttpSession ses ) { // Preleva i parametri passati String jsWidth = (String) req.getAttribute( "w" ); if( jsWidth == null ) jsWidth = ""; String jsHeight = (String) req.getAttribute( "h" ); if( jsHeight == null ) jsHeight = ""; String jsColor = (String) req.getAttribute( "c" ); if( jsColor == null ) jsColor = ""; String jsReferer = (String) req.getAttribute( "r" ); if( jsReferer == null ) jsReferer = ""; String jsFontSmothing = (String) req.getAttribute( "fs" ); if( jsFontSmothing == null ) jsFontSmothing = ""; String jsJava = (String) req.getAttribute( "j" ); if( jsJava == null ) jsJava = ""; String jsJavaScript = (String) req.getAttribute( "js" ); if( jsJavaScript == null ) jsJavaScript = ""; // Parameters used to identify visits and visitors. String session_id = ses.getId(); String guest_id = ID; // The user Agent contains important info on browser e O.S. used by the client. String user_agent = req.getHeader("user-agent"); if (user_agent == null) user_agent = ""; // The page is linked from another site? The referer tell it to us. String referer = req.getHeader("referer"); if (referer == null) referer = ""; String page_address = new String (referer); String page_name = ""; if (referer.indexOf("//")>-1) page_name = referer.substring(referer.indexOf("//")+2,referer.length()); if (page_name.indexOf('/')>-1) page_name = page_name.substring(page_name.indexOf('/'),page_name.length()); // Se la pagina precedente era esterna al sito allora la marco come accesso dall'esterno String external_access = "N"; if (!jsReferer.startsWith("http://www.attrezzeria.it/")) external_access = "S"; // Pagina richiamata // String page_name = (req.getRequestURI()).toString(); // Indirizzo completo della pagina richiamata // String page_address = (req.getRequestURL()).toString(); // Client Ip Address String remote_IP = req.getRemoteAddr(); // Il server web e' impostato in modo da non consentire il DNS lookup // dell'indirizzo IP del client, per cui ce lo dobbiamo procurare noi // mediante la classe InetAddress String remote_host = req.getRemoteHost(); try { remote_host = (java.net.InetAddress.getByName(remote_host)).getHostName(); } catch (java.net.UnknownHostException uhe) { } // Calcolo la versione numerica dell'IP per velocizzare la ricerca su DB del country String ipStr = new String(remote_IP); long ipLong = 0; try { ipLong = Integer.parseInt(ipStr.substring(0,ipStr.indexOf('.'))) * 256; ipStr = ipStr.substring(ipStr.indexOf('.')+1, ipStr.length()); ipLong = (ipLong + Integer.parseInt(ipStr.substring(0,ipStr.indexOf('.')))) * 256; ipStr = ipStr.substring(ipStr.indexOf('.')+1, ipStr.length()); ipLong = (ipLong + Integer.parseInt(ipStr.substring(0,ipStr.indexOf('.')))) * 256; ipStr = ipStr.substring(ipStr.indexOf('.')+1, ipStr.length()); ipLong += Integer.parseInt(ipStr); } catch (NumberFormatException nfe) {} // Data e ora di inizio sessione. long data_ora = ses.getCreationTime(); java.sql.Date solo_data = new java.sql.Date( data_ora ); java.sql.Time solo_ora = new java.sql.Time( data_ora ); String dataOraStr = solo_data.toString() + " " + solo_ora.toString(); String data = solo_data.toString(); // Data e ora dell'Hit DateFormat fmtDataShort = DateFormat.getDateInstance(DateFormat.SHORT,Locale.ITALIAN); DateFormat fmtDataFull = DateFormat.getDateInstance(DateFormat.FULL,Locale.ITALIAN); DateFormat fmtOraMedium = DateFormat.getTimeInstance(DateFormat.MEDIUM,Locale.GERMAN); Date adesso = new Date(); String adessoStr = fmtDataShort.format(adesso); String dataOraHit = "20" + adessoStr.substring(6,8) + "-" + adessoStr.substring(3,5) + "-" + adessoStr.substring(0,2) + " " + fmtOraMedium.format(adesso); String dataHit = "20" + adessoStr.substring(6,8) + "-" + adessoStr.substring(3,5) + "-" + adessoStr.substring(0,2); String fasciaOrariaHit = (fmtOraMedium.format(adesso)).substring(0,2) + ":00 - " + (fmtOraMedium.format(adesso)).substring(0,2) + ":59"; String giornoSettimanaHit = (fmtDataFull.format(adesso)).substring(0,(fmtDataFull.format(adesso)).indexOf(' ')); String meseHit = adessoStr.substring(3,5); // Determino la fascia oraria int ora = 0; try { ora = Integer.parseInt(solo_ora.toString().substring(0,2)); } catch (NumberFormatException nfe) {} String fascia_oraria = "" + ora; while (fascia_oraria.length()<2) fascia_oraria = "0" + fascia_oraria; fascia_oraria = fascia_oraria + ":00 - " + fascia_oraria + ":59"; // salva su database le info raccolte String StatSQLError = "Tutto OK!"; String country_code = "N.D."; String country = "N.D."; String ora_fine = ""; if( connMySQL != null ) { try { // Variabili usate dalla connessione per accedere al DB Statement stmt = connMySQL.createStatement(); ResultSet rs = null; String query = ""; if (newSession) { // Mediante indirizzo IP posso ricavare il country_ID query = "SELECT ip.country_code, co.country FROM " + "(stat_ip_to_country AS ip JOIN stat_country AS co " + "ON ip.country_code=co.country_code) " + "WHERE ip.ip_long_start<=" + ipLong + " " + "AND ip.ip_long_end>=" + ipLong; rs = stmt.executeQuery( query ); if (rs.next()) { country_code = rs.getString("ip.country_code"); country = rs.getString("co.country"); } rs.close(); // Salvo le informazioni del visitatore if( newVisitor ) { query = "INSERT INTO stat_visitatori (guest_id, country_code, " + "country, data, fascia_oraria, user_agent, language, visitor_time, " + " giorno_settimana, mese) VALUES (" + guest_id + ",'" + country_code + "','" + country + "','" + data + "','" + fascia_oraria + "','" + user_agent + "','" + browserLang + "','" + dataOraStr + "','" + giornoSettimanaHit + "','" + meseHit +"')"; stmt.executeUpdate( query ); } // salvo le informazioni della visita query = "INSERT INTO stat_visite (session_id, referer, " + "remote_ip, remote_host, guest_id, ora_inizio, " + "data, fascia_oraria, giorno_settimana, mese) VALUES ('" + session_id + "','" + jsReferer + "','" + remote_IP + "','" + remote_host + "'," + guest_id + ",'" + dataOraStr + "','" + data + "','" + fascia_oraria + "','" + giornoSettimanaHit + "','" + meseHit + "')"; stmt.executeUpdate( query ); } // salvo le informazioni sul singolo hit query = "INSERT INTO stat_hits (session_id, guest_id, " + "page_name, page_address, hit_time, referer, external_access," + "data, fascia_oraria, giorno_settimana, mese) VALUES ('" + session_id + "'," + guest_id + ",'" + page_name + "','" + page_address + "','" + dataOraHit + "','" + jsReferer + "','" + external_access + "','" + dataHit + "','" + fasciaOrariaHit + "','" + giornoSettimanaHit + "','" + meseHit + "')"; stmt.executeUpdate( query ); // Ho terminato le interrogazioni al DB: chiudo lo statement stmt.close(); } catch( SQLException sqe ) { StatSQLError = "Errore: " + sqe.getErrorCode() + " - " + sqe.getMessage(); // out.println(StatSQLError); } } } %><% // ========================================================================== // passo X : ripristina il database Connection connMySQL=(Connection)session.getAttribute("FS_CONNECTION"); String FSguestID = (String) request.getAttribute( "FSguestID" ); FSguestID = ( FSguestID == null )? "0": FSguestID; String FSguestLANG = (String) request.getAttribute( "FSguestLANG" ); FSguestLANG = ( FSguestLANG == null )? "IT": FSguestLANG; // Il sensore raccoglie le informazioni .... boolean new_session = session.isNew(); String cookie_id = (String) request.getAttribute("cookie_id"); boolean new_visitor = ( cookie_id == null ); // passo A3 : raccoglie info statistiche sul visitatore raccolta_statistiche( FSguestID, new_visitor, new_session, FSguestLANG, connMySQL, request, session ); // ============================================================================== response.setHeader("P3P: CP=","\"NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM\""); %>