Thursday, October 14, 2010

On the fly subsitution of text with mod_substitute under apache httpd 2.2.x

Got a request to insert a javascript snippet on every webpage just before the closing body tag.

The brute-force approach is obvious, manually adding the snippet on each and every webpage manually. This can be automated by writing a perl script or vi script.

Another approach is to use mod_substitute in apache 2.2 (since 2.2.7) which can substitute text in the response on the fly. This can be combined with mod_cache and mod_proxy.


LoadModule substitute_module modules/mod_substitute.so

<location / >
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|</body>|<script type="text/javascript" src="your code"></script></body>|ni"
</location>


Note, regular expression can be used, and the separator does not necessarily be the slash - "/",
in the above example, pipe character - "|" is used. Since there are whitespaces in the expression, the whole string has to be enclose in double quote '"' and so the double quote character '"' in the expression has to be escape i.e. '\"'

Voila! Every html served via the webserver got inserted with the snippet. In combination with mod_cache, the substituted result can be cached.

http://httpd.apache.org/docs/2.2/mod/mod_substitute.html

Friday, May 16, 2008

Windows XP sp3

Windows xp sp3 has been released. KB936929. At 316.43MB, it's big. Anyway download it and install. I've applied it for a week and so far no problem.

Superficially not changed that much, except:

System Properties











Remote Desktop

Thursday, May 15, 2008

Liferay portal with tomcat 6.0 installation

  1. download Liferay with Tomcat 6.0
  2. unzip.
  3. if you want to change the backend database to oracle
    a. copy the jdbc driver ojdbc14.jar to liferay...\lib\ext
    b. edit the config file conf\Catalina\localhost\ROOT.xml
    i. comment the hsql part
    ii. uncomment the oracle part
    iii. replace the actual parameter, the first time liferay runs, if the tables does not exist in the database schema, liferay will populate with sample data.
  4. start the tomcat
    cd bin
    startup.bat
  5. point your browser to http://localhost:8080/liferay and there you are.