Administrera sin Telia router Thomson TG789vn från Internet

Om du har ADSL bredband från Telia så har du antagligen en Thomson TG789vn router därhemma. Jag har en sådan och har letat efter ett sätt att kunna administrera den över Internet då jag inte är hemma. Det verkar tyvärr inte finnas stöd för detta i routerns Telia-strypta programvara.

TG789vn

Ett sätt att komma runt detta är att man sätter upp en reverse proxy. I ‘mitt fall så löste jag det genom att använda mod_proxy i den apache webbserver som jag har igång hemma och som är öppnad (port forward port 80) mot Internet. Utöver det så har jag ett dynamiskt domän-namn kopplat mot servern.

Så här gick jag till väga:

1. Först skapade jag en egen subdomän kallad http://router.dindomän.com och pekade den mot servern.

2. Kollade så att apache har mod_proxy enablat i /usr/local/etc/apache22/httpd.conf

LoadModule proxy_module libexec/apache22/mod_proxy.so
LoadModule proxy_http_module libexec/apache22/mod_proxy_http.so
LoadModule xml2enc_module     libexec/apache22/mod_xml2enc.so
LoadFile   /usr/local/lib/libxml2.so
LoadModule proxy_html_module  libexec/apache22/mod_proxy_html.so

2. Skapade en användare för att lösenordsskydda routern. Username nedan är användarnamnet, lösenordet skriver man på förfrågan.

 htpasswd -c /usr/local/etc/router.user username

3. Lade in följande i apaches configurationför virtualhosts i /usr/local/etc/apache22/extra/httpd-vhosts.conf. 192.168.1.1 är den IP-adress som routern har på hemma-nätverket. Routern skyddas av BASIC-autentisering.

<Virtualhost *>
  ServerName router.domainname.com
  ProxyRequests Off
  <Proxy *>
     Order deny,allow
     Allow from all
    AuthType Basic
    AuthName "Password Required"
    AuthUserFile  /usr/local/etc/router.user
    Require valid-user
  </Proxy>

    ProxyPass / http://192.168.1.1/
    ProxyPassReverse / http://192.168.1.1

 </Virtualhost>

4. Starta om apache och besök webbsidan http://router.dindomän.com. Thomson boxens admin-sida bör nu dyka upp efter att du matat in användarnamn och lösenord.

Det var alles, happy administration!

Segmentation fault: 11 (core dumped) in php on Freebsd

Oh, I finally got time for some coding and server updates. Sadly but interestering I got this strange error after updating php5 (/usr/ports/lang/php5) to the latest in the Freebsd ports tree.

The error:
/usr/local> php -v
PHP Fatal error: PHP Startup: apc_shm_create: shmget(0, 31457280, 914) failed: Cannot allocate memory. It is possible that the chosen SHM segment size is higher than the operation system allows. Linux has usually a default limit of 32MB per segment. in Unknown on line 0
PHP Fatal error: PHP Startup: apc_shm_attach: shmat failed: in Unknown on line 0
Segmentation fault: 11 (core dumped)

The first problem was the ”PHP Fatal error” lines that has something to do with APC cache. This was solved by:
/usr/ports/www/pecl-APC> make config
Then I unticked the "IPC Enable IPC shm memory support (default: mmap)" line. Don't really know what it does....
/usr/ports/www/pecl-APC> make deinstall
/usr/ports/www/pecl-APC> make clean
/usr/ports/www/pecl-APC> make install clean

The second problem was the ”Segmentation fault: 11 (core dumped)” line which caused a core dump each time php ran (a php.core file is produced). This was a bit strange. To investigate why it crashes I used gdb on the core file. A core file contains the in-memory state of the program at the time it crashes.

/usr/local/lib/php> gdb /usr/local/bin/php php.core
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
Core was generated by `php'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/libcrypt.so.4...(no debugging symbols found)...done.
Loaded symbols for /lib/libcrypt.so.4
Reading symbols from /usr/local/lib/libpcre.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpcre.so.0
Reading symbols from /lib/libm.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libm.so.5
Reading symbols from /usr/local/lib/libxml2.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxml2.so.5
Reading symbols from /lib/libz.so.4...(no debugging symbols found)...done.
Loaded symbols for /lib/libz.so.4
Reading symbols from /usr/local/lib/libiconv.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libiconv.so.3
Reading symbols from /lib/libc.so.7...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.7
Reading symbols from /usr/local/lib/php/libs/curl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/curl.so
Reading symbols from /usr/local/lib/libcurl.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libcurl.so.6
Reading symbols from /usr/lib/libssl.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libssl.so.5
Reading symbols from /lib/libcrypto.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libcrypto.so.5
Reading symbols from /usr/local/lib/php/libs/iconv.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/iconv.so
Reading symbols from /usr/local/lib/php/libs/json.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/json.so
Reading symbols from /usr/local/lib/php/libs/exif.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/exif.so
Reading symbols from /usr/local/lib/php/libs/ftp.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/ftp.so
Reading symbols from /usr/local/lib/php/libs/openssl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/openssl.so
Reading symbols from /usr/local/lib/php/libs/hash.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/hash.so
Reading symbols from /usr/local/lib/php/libs/bz2.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/bz2.so
Reading symbols from /usr/lib/libbz2.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libbz2.so.3
Reading symbols from /usr/local/lib/php/libs/mysql.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/mysql.so
Reading symbols from /usr/local/lib/php/libs/tokenizer.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/tokenizer.so
Reading symbols from /usr/local/lib/php/libs/simplexml.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/simplexml.so
Reading symbols from /usr/local/lib/php/libs/xml.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xml.so
Reading symbols from /usr/local/lib/php/libs/posix.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/posix.so
Reading symbols from /usr/local/lib/php/libs/dom.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/dom.so
Reading symbols from /usr/local/lib/php/libs/gd.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/gd.so
Reading symbols from /usr/local/lib/libt1.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libt1.so.5
Reading symbols from /usr/local/lib/libfreetype.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libfreetype.so.9
Reading symbols from /usr/local/lib/libX11.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libX11.so.6
Reading symbols from /usr/local/lib/libXpm.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXpm.so.4
Reading symbols from /usr/local/lib/libpng.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpng.so.6
Reading symbols from /usr/local/lib/libjpeg.so.11...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libjpeg.so.11
Reading symbols from /usr/local/lib/libxcb.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxcb.so.2
Reading symbols from /usr/lib/librpcsvc.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/librpcsvc.so.4
Reading symbols from /usr/local/lib/libXau.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXau.so.6
Reading symbols from /usr/local/lib/libXdmcp.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXdmcp.so.6
Reading symbols from /usr/local/lib/libpthread-stubs.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpthread-stubs.so.0
Reading symbols from /usr/local/lib/php/libs/xmlreader.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlreader.so
Reading symbols from /usr/local/lib/php/libs/xmlwriter.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlwriter.so
Reading symbols from /usr/local/lib/php/libs/sockets.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/sockets.so
Reading symbols from /usr/local/lib/php/libs/zlib.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/zlib.so
Reading symbols from /usr/local/lib/php/libs/session.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/session.so
Reading symbols from /usr/local/lib/php/libs/soap.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/soap.so
Reading symbols from /usr/local/lib/php/libs/xsl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xsl.so
Reading symbols from /usr/local/lib/libexslt.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libexslt.so.8
Reading symbols from /usr/local/lib/libxslt.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxslt.so.2
Reading symbols from /usr/local/lib/libgcrypt.so.17...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libgcrypt.so.17
Reading symbols from /usr/local/lib/libgpg-error.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libgpg-error.so.0
Reading symbols from /usr/local/lib/libintl.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libintl.so.9
Reading symbols from /usr/local/lib/php/libs/sqlite.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/sqlite.so
Reading symbols from /usr/local/lib/php/libs/pdo.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/pdo.so
Reading symbols from /usr/local/lib/php/libs/pdo_sqlite.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/pdo_sqlite.so
Reading symbols from /usr/local/lib/libsqlite3.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libsqlite3.so.8
Reading symbols from /lib/libthr.so.3...(no debugging symbols found)...done.
Loaded symbols for /lib/libthr.so.3
Reading symbols from /usr/local/lib/php/libs/xmlrpc.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlrpc.so
Reading symbols from /usr/local/lib/php/libs/ctype.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/ctype.so
Reading symbols from /usr/local/lib/php/libs/fileinfo.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/fileinfo.so
Reading symbols from /usr/local/lib/php/libs/filter.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/filter.so
Reading symbols from /usr/local/lib/php/libs/imap.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/imap.so
Reading symbols from /usr/local/lib/libc-client4.so.9...done.
Loaded symbols for /usr/local/lib/libc-client4.so.9
Reading symbols from /usr/lib/libpam.so.4...done.
Loaded symbols for /usr/lib/libpam.so.4
Reading symbols from /usr/local/lib/php/libs/mbstring.so...done.
Loaded symbols for /usr/local/lib/php/libs/mbstring.so
Reading symbols from /usr/local/lib/libonig.so.1...done.
Loaded symbols for /usr/local/lib/libonig.so.1
Reading symbols from /usr/local/lib/php/libs/sqlite3.so...done.
Loaded symbols for /usr/local/lib/php/libs/sqlite3.so
Reading symbols from /usr/local/lib/php/libs/zip.so...done.
Loaded symbols for /usr/local/lib/php/libs/zip.so
Reading symbols from /usr/local/lib/php/libs/apc.so...done.
Loaded symbols for /usr/local/lib/php/libs/apc.so
Reading symbols from /usr/lib/librt.so.1...done.
Loaded symbols for /usr/lib/librt.so.1
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
#0 0x0000000805de1f5d in apc_sma_init () from /usr/local/lib/php/libs/apc.so
[New Thread 0x801533120 (LWP 100263)]

Ok, I smell some fish here. Then i checked the ”stack backtrace” with bt.

(gdb) bt
#0 0x0000000804c7c8c0 in ?? ()
#1 0x00000008042e1bc4 in xsltUnregisterExtModuleFunction () from /usr/local/lib/libxslt.so.2
#2 0x00000008040adc97 in zm_shutdown_xsl () from /usr/local/lib/php/libs/xsl.so
#3 0x000000000055e2cf in module_destructor ()
#4 0x000000000056597a in zend_hash_apply_deleter ()
#5 0x0000000000565be8 in zend_hash_graceful_reverse_destroy ()
#6 0x00000000005596f7 in zend_shutdown ()
#7 0x00000000005045f5 in php_module_shutdown ()
#8 0x00000000005e505f in main ()
#9 0x00000000004189e5 in _start ()
#10 0x0000000800786000 in ?? ()

The problem was clearly related to one of my php-extensions /usr/local/lib/php/libs/xsl.so. Then I tried not to use this extension by uncomment it in /usr/local/etc/php/extensions.ini. However I got similiar error in another extension by doing that. There must be some other error that hasn’t with my extensions to do…

With some google fu I found this post which explains the problem. Some extensions are threaded while php5 isn’t by default. To make php threaded you have to configure it to be so. That’s fairly easy in Freebsd.

/usr/ports/lang/php5/make config
Tick the "LINKTHR Link thread lib (for threaded extensions)" option.
/usr/ports/lang/php5/make deinstall
/usr/ports/lang/php5/make clean
/usr/ports/lang/php5/make install clean

Then i restarted my apache server, typed ”php -m” and everything looked fine, not one single strange error message. Yieeehaa!!

mod_rewrite: could not init rewrite log lock in child

I found this strange error in my freebsd Apache error log: ”mod_rewrite: could not init rewrite log lock in child”. The same error was logged every second and was filling up my disk with junk. This should not happen because I have a fresh installation of Apache from the Freebsd ports tree and no strange configuration.

After some google-time I found the ”RewriteLog directive” at the mod_rewrite page. It says: ”To disable logging either remove or comment out the RewriteLog directive or use RewriteLogLevel 0! ”

I set ”RewriteLogLevel 0” in my apache conf-file and restarted apache. The problem was now gone! I do not know which file or directory that mod_rewrite tries to write to however i am pleased to know that the problem was solved.