get user ip from behind reverse proxy setup

small problem, wide reach. if your TYPO3 is set up behind a reverse proxy (like pound) and you need the ip connection information of the visitors, T3´s userfunction method comes in handy.

fileadmin/scripts/fwdip.php


<?php
class user_fwdip {
 var $cObj;
 function main($content,$conf){
  $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  return $ip;
 }
}
?>

This is the file you´d like to ask for the ip from within TYPO3.

To be able to use this file in a userfunc style you´ll need to include the file in TypoScript, i put it into an own TS template on one special page.


page.includeLibs.fwdip = fileadmin/scripts/fwdip.php

You now could put the stuff on the same TS template but i recommend this neat extension to generate the output to one special page in a content element. The extension wraps the TS in a COA.


20 = USER
20 {
 userFunc =user_fwdip->main
}

Now the page you put the element on should show your real ip address, instead of the proxy ip.

Simple, but fully worth a snippet.

nice TYPO3 extensions

just wanted to post five neat extensions you can get freely from the TER i find worth to be mentioned since they really give me no headache but useful features:

  • stg_clearcache
    allows you to clear cache of user-owned branches in one big installation, so it’s not only clear cache of this one special page and also not clear all page cache. useful if you run a large system or microsites.
  • kb_filequota
    allows you to have a quota on filemounts, either by giving a size limit on the filemout itself or for each user. useful if you’d like to save space and suppress waste in the filemounts.
  • rscliem
    allows you to automatize the extension updates on your system. i use it as nightly extension-cache update and it notifies me by mail, if extension should be updated for the very TYPO3. useful if you’d like to take steps in automatic administration.
  • realurlmanagement
    allows you to view and manipulate a lot of stuff relating to RealUrl extension. simple alias and page-path editing. useful if the system works with RealUrl.
  • nc_staticfilecache
    allows you to cache the pages from your system to server disk and serve them from there (waaay faster!) and so have the site up and running even if the your TYPO3 is ill. useful, if you have mostly static pages and mod_rewrite going.

even if some of them might be well known, i wanted to put a link to give the extension authors a big up! yeah great stuff, keep on going!

if you think this short list was helpful, just leave a comment. i would appreciate, if you send me your missing extension entry for here ;-)

piwik in version 0.5.2 + update script

while waiting for an almost ten gigabytes large piwik database to be updated, i’m just writing down that piwik got a new release yesterday.

upgrading piwik is easy. i pushed all steps to upgrade it on a linux (debian) server in a small shell script you may find useful.

simple update script for piwik

#!/bin/bash
# auto-update piwik
# @author bigbabou <bigbabou@web.de>
#

# where my current piwik resides
installdir=/var/www/

# where the ugly stuff should be made
workingdir=/home/bigbabou/

# used for copying the new piwik source
piwikdir=/home/bigbabou/piwik/*
logfile=updatepiwik.log

# where the new piwik can be downloaded
piwikurl=http://piwik.org/latest.zip

cd ${workingdir}

# check if update is necessary
wget -N -o${logfile} ${piwikurl}

# overwrite silently
unzip -q -o latest.zip

# tidy up old piwik dir
cd ${installdir}

rm -rf core js lang libs misc plugins tests themes tmp
rm index.php piwik.js piwik.php robots.txt README

# safe global.ini before updating
chown root config/global.ini.backup_by_script
chmod 770 config/global.ini.backup_by_script

echo 'copying new files'
cp -r ${piwikdir} .
chown -R www-data *
chgrp -R www-data *
ls --color=auto -lA ${installdir}

# make nightly precaching exectuable
chmod 770 ${installdir}'misc/cron/archive.sh'

# clean up stuff
cd ${workingdir}
rm latest.zip
rm How\ to\ install\ Piwik.html
rm -rf piwik

echo 'piwik update successful. have a nice day!'

## update db on shell
php ${installdir}index.php

echo ' - update script end -'
exit 0

two lines could be added for convenience

chmod 777 ${installdir}tmp/cache
chmod 777 ${installdir}tmp/templates_c

tt_news 3.0.0 outputs “?>”

the extension update yesterday was not as simple as i thought and what happenened when i came to work today? tons emails complaining about broken web layout in frontend. ha! it’s a pity, the extension is really a good piece of code – but in one file the php ending tag was appearing twice. this generated a ?> just before the output of TYPO3 ( the doctype declaration and else ).

after finding out that it definitely was tt_news i quickly found the bug in the bugtracker :)
alywas look in the bug tracker first.

and the solution is that simple:

in typo3conf/ext/tt_news/lib/class.tx_ttnews_cache.php remove the last line (which is the doublette “?>”) and the system does not print out that tag before the website begins.

but still, it’s a pity that firefox again handles even this error and displays the website the first time after clearing cache with the ?> and the next times without it. But the internet explorer is as dumb as we expect it to be. broken layout due to malformed code – no css inclusion.

typo3 4.3 up and running

most of my projects are updated and as expected the update to TYPO3 4.3 hadn’t been a problem. everything went well and the new backend look is charming.

all went well

the sites get even faster,i did not instatiate the new caching factory, though. the new recycler is great and a must for every mid sizes website. the new recycler works way better when deleting tons of entries from a table.

the update of the extension templavoila to version 1.4.1 was also no problem, though on the biggest site i administrate (with more than 60 backend editors) i’m preparing for some bug reports. newest tv style finishes the new interface design at all – a feature that impresses them all is the drag and drop feeling.

tt_news 3.0.0 – don’t update live

but beware of upgrading tt_news too fast from version 2.5.2 (which is the highest in the 2.x branch) to 3.0.0 if you not have checked how the templates change! the whole morning was consumed by the fixing of tt_news styling. tt_news come with new caching mechanism that promises to speed up some data work that needs to be done every time news are rendered. tt_news 3.0.0 comes with that cool new update script that checks for possible problems – where it removes relations to templates as far as i remember.

falling back to the standard template coming with v3 the title wrapping changed from h3 to h2 and stuff like this – thus breaking the layout of the website on every page. if you’re using tt_news as main function for a big web site that should not be done “live”. ;)

also there had been problems in the realurl configuration after the update. solution was to grab a selection of the content of res/realUrl_example_setup.txt in the tt_news ext folder and drop it in typo3conf/realurl.php and so the errors were gone.

i don’t know why this was necessary, but tt_news showed a nasty red bordered error if now singlePid was set (which can be done in the constant editor) even if the site worked before with tt_news 2.5.2 due to single-page target was set per plugin settings.

another thing you might want to avoid is the output of some php stuff before the website’s head section.

all in all i’m happy away how simple it’s getting to create web content management. many of the tricks you need to learn are now turned into guides (i.e. compare database is the final step of the update in form of a button in the update wizard process – before that you just “needed to know” that).

great job TYPO3 core team!

obvious things obvious – the 7 windows sins

good old times there were when the number of the beast contained the nifty 6, but after cracking hell open on personal computers with a forced push of ‘vista’ the company in question went on to give the 7 a try. it´s like perdition 2.0  ^^

it´s bad enough that so many friends fell to that call that they literally jumped out of the windows they have been accustomed to. i´m not supporting nor running vista or 7, so wtf? it´s so easy and comfortable nowadays getting up running an ubuntu or sabayon or what. no pact with the devil at all, and image: you need a bit time to configure the system the way you want it – but you learn for the future with open standards! don´t be dazzled by the professional moves of the manufacturers of the 7!

We become what we behold. We shape our tools and then our tools shape us.
Neil Postman

so…

… the next time you sit in front of your cool pc running a crippled windows as os you could surf to distrowatch and read about your new, future operating system! distrowatch has plenty of them with detailled description. open source has some neat advantages, you will see. and there´s so much love out there, people writing tutorials i.e. on how to install your graphics card or how to get a tv tuner card running. okay there is lots of noise around windows, too. ;) but see these seven sins of the 7 and be enlightened to throw it off your pc in the next 48hrs.

changing the system can be a hard task; almost as hard to change an old aged behaviour. that needs time and confidence… and positive feedback (that should be doable!).

so to speak, forget about infected files, the vast amount of security issues, nasty hidden services, apps phoning to the home of evil and the internet explorer. forget about digital rights management (d´oh!) and your learned behaviour to press Start to shut down the computer… we´ve all been trained to go for the banana hehe.

you can do all your regluar stuff on a linux system

  • open office is way more sticking to standards and has overall equal functions like the office blowfessional
  • pidgin is capable of letting you chat on icq, msn, yahoo, jabber… except for skype, but you can download skype for linux if you like it
  • access the web with opera firefox iron
  • email organizing, planning, programming, mindmapping, image editing, project managment, web publishing, gaming… open source is growing everywhere! and that´s so heavenly good.
  • media players are onboard almost every desktop linux os these days… what else could one need in the everyday mode?

if there´s a task you need perform, you can always use the packet manager of the system to download binaries or source code (depending on your chosen system). in that packet manager you can search for tags and descriptions fitting your needs. in most cases you´ll find an appropriate piece of software that does the job.

… hmm that felt good, i wanted to write about that for a long time… (as you can see on blog posts like uninstall vista baby that are well known for their brevity)

update current list of available plugins from TER

one step closer to TYPO3 backend convenience

scheduled update of the extension list from the TYPO3 extension repository (TER). the extension needed has the cryptic key rscliem and will provide command line interface function for extension manager operations. just import and install it.

If you have no BE-user named _cli_lowlevel go and create it. That one’s needed to run PHP CLI commands.

test the cliKey ‘emtools’

/var/www/my-t3site/typo3/cli_dispatch.phpsh emtools --update-extensionlist

It will return a fancy array containing a message like
[0] => <p>The extension list has not changed remotely, it has thus not been fetched.</p>

(at least if you run the command successfully a second time)

To have the Extension List updated twice a day, a small entry in the current cron tab comes in handy:

# m h  dom mon dow   command
00   */12    *     *     *  /var/www/my-t3site/typo3/cli_dispatch.phpsh emtools --update-extensionlist
MAILTO="adminmail@mydomain.com"

The following options can be used:

  • –update-mirrors
    Updates mirror list from typo3.org
  • –update-extensionlist
    Retrieves current extensionlist from selected mirror and load into database
  • –check-extensions
    Checks currently installed extension for newer versions
  • –import-updates
    Imports updates for all extension, found with –check-extensions.

(taken from the README file found in typo3conf/ext/rscliem/)

You see, you can possibly automate the extension update process. I currently can’t use this feature because some extensions would break the TYPO3 instance in question if updated to newest version.

But the handy part is to have the list of extensions to update emailed to me.A connection of the updated extension list and the extension chack makes most sense.

./cli_dispatch.phpsh emtools --update-extensionlist && ./cli_dispatch.phpsh emtools --check-extensions

piwik shows General error: 126

last week there was everything working fine. no changes made. today, stuff is not running fine. piwik in version 0.4.1 does not show useful content anymore. if you ever get to see all your widgets showing the General error 126″ you can start over with mysqlrepair.

General error: 126 Incorrect key file for table ‘/tmp/#sql_6d3c23.MYI’; try to repair it

SQLSTATE[HY000]

Yes sir, we’re going to repair the database totally. To do so, we fire up

mysqlrepair -B piwik -force -p

which will show a lot of OK rows. option -A is for all databases, so if your mysql server is in production and you’ve got a bunch of dbs on it hot, you propably consider using -B option to point to the single piwik database. I had to retry this with different options but now the things looks okay.

so today’s view is fixed, but since the problem existed for around three days, two days of data are corrupted. so i open config/global.ini.php and set the debugsters to 1.

[Debug]
; the archiving process will always be triggered, even if the archive has already been computed
always_archive_data_period = 1;
always_archive_data_day = 1;

; if set to 1, all the SQL queries will be recorded by the profiler
enable_sql_profiler = 1;

after having reprocessed the complete archive, which does take quite a while, there is still a report of an incorrect key file. But now with nice SQL profiling., d’oh.

<?xml version="1.0" encoding="utf-8" ?>
<result>
<error message="SQLSTATE[HY000]: General error: 126 Incorrect key file for table '/tmp/#sql_694e23.MYI'; try to repair it" />
</result>

solution

the problem was caused by a /tmp partition defined too small (16mb on a guest). now as i raised the tmpfs size the system works normal again. in vserver landscapes you can search a while before finding the corresponding fstab in /etc/vservers/yourvserver/fstab on the host. All this can be found in the vserver faq section.

Thanks to @schommr for the tip.

Best of it all, your data won’t be gone if you have a problem like this. It just can’t be processed to show correctly. My concerns about several days loss of data were flushed away when piwik’s archive.sh ran through in about twenty minutes. go piwik!