hacking index.php with phpSniff features

Author Message

Daniele Gobbetti

Wednesday 05 April 2006 6:28:04 am

Hi all,

I'm working on a little patch for index.php to embed browser (user agent) detection and automagic siteaccess redirection.
The patch is in a very early and dirty stage, but that's what I've achieved so far:
1- download phpSniff libraries ( http://phpsniff.sf.net ) and grab the files you need (phpSniff.class.php and phpSniff.core.php)
2- put the two libraries above somewhere in your installation
3- browse your index.php and find the row (mine is row #368) stating:

$access = changeAccess( $access );

4- Edit the file adding ABOVE the previous line

//load the library and perform the sniff
require_once('phpSniff.class.php');
$client =& new phpSniff('',array('check_cookies'=>'1','default_language'=>'','allow_masquerading'=>''));

//is our client a pocketPC device?
if(preg_match('/windows\ ce/i',$client->property(ua)))
                $redir='pda';
/* is english a preferred language? Otherwise defaults to italian. If both italian and english are supported then defaults to italian */
if($client->language_is("it"))
                $redir=$redir.'it';
elseif($client->language_is("en"))
                $redir=$redir.'en';
else
                $redir=$redir.'it';
//switch to the appropriate siteaccess
if ($access[name]=='it')$access[name]=$redir;

In this scenario you have to have a siteaccess structure like the following:
pdait -> pocketpc layout, italian language
pdaen -> pocketpc layout, english language
it -> "full browser" layout, italian language ** DEFAULT
en -> "full browser" layout, english language

The last line is really ugly, I know. You have to change 'it' with your default siteaccess, this is needed to allow explicit access to any siteaccess.

At this point I'm kindly asking for suggestion on how this patch may become better, what I have in mind is to generalize the language/layout part, but I do need to check whether the value of $redir is valid prior to push it into the $access array, I've read the access.php file but didn't find anything.

Another thing I've got in the plans is to scan the global site.ini for ISO639-1 access lists (aka 2 letter language name) and subsequently check the UA for each and every language which is available.

Please let me know if there are better ways for implementing this into eZ Publish (or if it's already in and I didn't manage to find it!) I love the system, even if I'm relatively new to it.

Regards,
DAniele

Daniele Gobbetti

Wednesday 05 April 2006 6:41:26 am

Uh, of course this may be useful for any kind of redirects (text only version of the site, different siteaccess for old/*AHEM*buggy browsers ). I think that phpSniff is just AWESOME for this purpose :)

I'm wonderng whether we can put some wml generation capabilities into eZ, as I don't see any technical issue for this to happen, has anyone tried to do such a thing?

Regards, DAniele

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 22:28:33
Script start
Timing: Jan 18 2025 22:28:33
Module start 'layout'
Timing: Jan 18 2025 22:28:33
Module start 'content'
Timing: Jan 18 2025 22:28:34
Module end 'content'
Timing: Jan 18 2025 22:28:34
Script end

Main resources:

Total runtime0.7679 sec
Peak memory usage4,096.0000 KB
Database Queries52

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0051 588.0469152.6406
Module start 'layout' 0.00510.0025 740.687539.4766
Module start 'content' 0.00760.7587 780.1641437.0781
Module end 'content' 0.76630.0015 1,217.242212.1250
Script end 0.7679  1,229.3672 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4338160.0002
Check MTime0.00130.1744160.0001
Mysql Total
Database connection0.00070.090510.0007
Mysqli_queries0.723194.1584520.0139
Looping result0.00050.0661500.0000
Template Total0.732395.420.3662
Template load0.00200.264620.0010
Template processing0.730395.092520.3651
Template load and register function0.00010.019010.0001
states
state_id_array0.00150.192910.0015
state_identifier_array0.00150.197820.0008
Override
Cache load0.00170.2229270.0001
Sytem overhead
Fetch class attribute can translate value0.00060.084410.0006
Fetch class attribute name0.00090.112020.0004
XML
Image XML parsing0.00010.012910.0001
class_abstraction
Instantiating content class attribute0.00000.000820.0000
General
dbfile0.00070.0972100.0001
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 15
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs