Archiv für March, 2008
  |  
Markus am 31.03.08 um 4:42 pm Uhr

Girls, read this :-)

Ungedingstes

Well now, girls: You should read this, and you will know, why you should date a geek…

Markus am 17.03.08 um 9:48 pm Uhr

php escapes quotation marks and backslashes

Wordpress

Today I backuped this blog to another server. And I experienced, that the blogroll of my sidebar looked a little bit strange. So I checked the html-sourcecode, and I found, that all quotation marks had been escaped by a backslash.

I wanted it to look like this:

</div><div class="sidehead">

but I found this:

</div><div class=\"sidehead\">

As you can see, the quotation marks had been escaped.

So what can you do?

In php.ini (/etc/apache2/php5/php.ini) there is a value magic_quotes_gpc. If this is On, you will get all quotation marks and backslashes escaped. If you don’t want it this way, set this value to Off.

Markus am 06.03.08 um 9:42 pm Uhr

Scrollbox for wordpress

Wordpress

Especially if you want to write some code-lines into wordpress you experience the following problem: The code line is longer, than the width of the available text-area. So ether you have to wrap your lines manually, or you use a text box with scrollbars. But how can you do this?

Just enter the following css-code in your wordpress-entry:


<pre style="width:100%;border:solid 1px #ccc;overflow:auto;">
  //enter your code-line here...
</pre>

By doing this you will get this result:


This is a long line, which should be wrapped manually. But you don't have to do this, because you have a scrollable text-box by now...

So, just use the css-code mentioned above, and you can display long code lines in wordpress with a scrollbar for better readability.

Markus am 03.03.08 um 9:25 pm Uhr

Ermitteln der externen IP-Adresse der Fritz!Box

Linux Tools

Wenn die Notwendigkeit besteht, die externe IP-Adresse der Fritz!Box zu kennen, dann gibt es mehrere Möglichkeiten sie zu ermitteln. Im Folgenden möchte ich drei aufzeigen:

1. Man kann eine Website aufrufen, die einem die IP-Adresse anzeigt. Diese Seite kann man per cron und wget regelmäßig auslesen und dann die IP heraus- greppen:


ip_address_act=$(/usr/bin/wget -qO - http://www.nwlab.net/cgi-bin/show-ip-js | grep -o '\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}')

Nachteil: Wenn dieses Script 3mal pro Minute aufgerufen wird, erzeugt man eine gewisse Grundlast auf Seiten des Website-owners. Der könnte darüber unglücklich werden und einem den Zugriff auf die Seite sperren. Weiterhin kann man natürlich nie sicher sein, ob es diese Seite ein Leben lang gibt…

2. Man kann sich auf der Fritz!Box einloggen (Beschreibung findet man hier), das Internet-Logfile auslesen, und daraus die IP herausgreppen.


# Log-In first
/usr/bin/wget -q --post-data="login:command/password=your_password_here" http://fritz.box/cgi-bin/webcm -O /home/mrre/login.txt
#Get the logfile and write it to /tmp
/usr/bin/wget -q --post-data="getpage=../html/de/system/ppSyslog.html" http://fritz.box/cgi-bin/webcm -O /tmp/logfile
#Grep the IP out of the logfile
ip_address_act=$(cat /tmp/logfile | grep "Internetverbindung wurde erfolgreich hergestellt" | grep -o -m1 -e'Adresse: [0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | sed 's/Adresse:\ //')
#delete the logfile
rm /tmp/logfile

Der Nachteil dieser Variante ist, dass man ständig Schreiboperationen auf die Festplatte erzeugt (logfile lokal ablegen). Weiterhin muss die Fritz!Box immer wieder von ihrem Flash-Speicher lesen, was die Lebensdauer dieses Mediums auch nicht gerade positiv beeinflusst.

3. Die wahrscheinlich angenehmste Art und Weise ist es, die IP-Adresse der Fritz!Box per UPnP zu ermitteln. Dazu ist folgendes Skript anzuwenden:


#!/bin/bash

#internal IP-address of the fritz-box
FBIP=192.168.178.1

NETCAT=`which netcat`
[ -z "$NETCAT" ] && NETCAT=`which nc`
[ -z "$NETCAT" ] && exit 1

INTERFACE_NS="urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"
WANIP_NS="urn:schemas-upnp-org:service:WANIPConnection:1"

NS="$WANIP_NS"
REQUEST="GetExternalIPAddress"
SED='/^<NewExternalIP/ s,</\?NewExternalIPAddress>,,gp'

BODY="<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
        <s:Body><u:$REQUEST xmlns:u=$NS /></s:Body>
</s:Envelope>
"

LENGTH=`echo -n "$BODY" | wc -c`

( $NETCAT $FBIP 49000 | sed -ne "$SED" ) <<EOF
POST /upnp/control/WANCommonIFC1 HTTP/1.1
Content-Type: text/xml; charset="utf-8"
Connection: close
HOST: $FBIP:49000
Content-Length: $LENGTH
SOAPACTION: "$NS#$REQUEST"

$BODY
EOF

(Das Ganze als fertiges Script zum Download)

Dieses Script kann man beispielsweise unter /usr/bin/get-external-ip.sh ablegen und anschließend regelmäßig aufrufen. Der Output des Ganzen beschränkt sich auf das, was man sucht: die IP-Adresse der Fritz!Box!

  |