<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Server shares</title>
	<atom:link href="http://server.vijge.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://server.vijge.net</link>
	<description>Experiences with a web server</description>
	<lastBuildDate>Fri, 17 Feb 2012 11:43:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Twonky DLNA with video thumbnails</title>
		<link>http://server.vijge.net/archive/twonky-dlna-with-video-thumbnails/</link>
		<comments>http://server.vijge.net/archive/twonky-dlna-with-video-thumbnails/#comments</comments>
		<pubDate>Sat, 27 Aug 2011 16:48:12 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Twonky]]></category>

		<guid isPermaLink="false">http://server.vijge.net/?p=149</guid>
		<description><![CDATA[Update: download thumbnails and movie posters from the internet automatically using tw-video-scraper for Twonky. For streaming videos to a DLNA compatible television, you can use TwonkyServer software. This is not the only DLNA software around, but I like it because &#8230; <a href="http://server.vijge.net/archive/twonky-dlna-with-video-thumbnails/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: download thumbnails and movie posters from the internet automatically using <a href="http://server.vijge.net/tw-video-scraper">tw-video-scraper</a> for Twonky.</p>
<p>For streaming videos to a DLNA compatible television, you can use <a href="http://www.twonkymedia.com/" target="_blank">TwonkyServer</a> software. This is not the only DLNA software around, but I like it because you can run it on a lot of platforms, it is fast, and it runs on low-powered machines. The installation instructions for Twonky on Linux are not very complete. For thumbnails the instructions are completely missing. You will need some Linux knowledge to set everything up. Luckily, it is not that difficult.</p>
<p>First, download Twonky. If you visit the main web site, it is very easy to miss that Twonky is available for a lot of platforms. On the main web site, only Windows, OS X and Linux i386 are advertised. On the <a href="http://www.twonkyforum.com/viewtopic.php?f=2&amp;t=7653" target="_blank">forum</a>, you can find the NAS versions. If you want to run it on an ARM architecture machine, try the Kirkwood build. This is an ARM build, but unlike the other ARM bundles, it will run on newer Debian versions (due to library issues, the ARM bundles do not run on Debian).</p>
<p>Extract the zip file to the directory <em>/usr/local/twonkymedia</em> Next, set the correct permissions on files by running</p>
<div class="codesnip-container" >
<pre>chmod 700 twonkym* cgi-bin/* plugins/*</pre>
</div>
<p>Now let&#8217;s make sure that Twonky starts when the system boots. A boot script is supplied, but it is not optimised for Debian. Open the file <em>twonkymedia.sh</em> in a text editor and change the lines</p>
<div class="codesnip-container" >
<pre># Default-Start:  3 5
# Default-Stop:   0 1 2 6</pre>
</div>
<p>to</p>
<div class="codesnip-container" >
<pre># Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6</pre>
</div>
<p>Then, make a symbolic link to this script in the /etc/init.d directory, and make sure that the script executed at boot time. This can be done with the following two commands</p>
<div class="codesnip-container" >
<pre>ln -s /usr/local/twonkymedia/twonkymedia.sh /etc/init.d/twonkymedia
update-rc.d twonkymedia defaults</pre>
</div>
<p>That is it for the standard set-up of Twonky. Next, let&#8217;s enable thumbnail support. For this, some extra software is needed. This can be installed with</p>
<div class="codesnip-container" >
<pre>apt-get install dtach ffmpeg</pre>
</div>
<p>Edit the file <em>/usr/local/twonkymedia/cgi-bin/ffmpeg.location</em> at replace its content with</p>
<div class="codesnip-container" >
<pre>/usr/bin</pre>
</div>
<p>Next, edit the file /usr/local/twonkymedia/cgi-bin/ffmpeg-video-thumb.desc at replace its content with</p>
<div class="codesnip-container" >
<pre># generate video thumbs
#(c) 2010 by PacketVideo
exec: ffmpeg -itsoffset -30 -i $infile -vcodec mjpeg -vframes 1 -an -f rawvideo -s 284x160 $outfile
# capabilities
from=video/*
to=image/jpeg
videothumb
synchronous</pre>
</div>
<p>Finally, make some edits (again) to the file <em>/usr/local/twonkymedia/twonkymedia.sh</em> Find the line that says
<div class="codesnip-container" >
<pre>"$TWONKYSRV" -D</pre>
</div>
<p> and replace this with
<div class="codesnip-container" >
<pre>dtach -n /tmp/twonkymedia "$TWONKYSRV"</pre>
</div>
<p> Now you should be able to start Twonky with the command
<div class="codesnip-container" >
<pre>/etc/init.d/twonkymedia start</pre>
</div>
<p>Open a web browser, and go the the URL <em>http://nas-ip-address:9000/config</em> Click on the <em>Transcoding</em> link, select <em>JPEG</em>, and click <em>Save Changes</em>.<br />
Now you can add the folder you wish to make available via Twonky. Click on the <em>Sharing</em> link and add the folder that hold your media. Click <em>Save Changes</em> again, and Twonky will scan your folders for media. With the link <em>Server Status</em>, it is possible to see how far the scan has progressed. Notice that this is only the scanning of the files. The process of generating thumbnails is not covered on the status page. The only way to see this, is on the server itself, with the command
<div class="codesnip-container" >
<pre>dtach -a /tmp/twonkymedia</pre>
</div>
<p> Use the key Ctrl+\ to go back to the terminal. Thumbnail generating will continue in the background.</p>
]]></content:encoded>
			<wfw:commentRss>http://server.vijge.net/archive/twonky-dlna-with-video-thumbnails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Squeezebox server</title>
		<link>http://server.vijge.net/archive/squeezebox-server/</link>
		<comments>http://server.vijge.net/archive/squeezebox-server/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 14:24:26 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Squeezebox]]></category>

		<guid isPermaLink="false">http://server.vijge.net/?p=134</guid>
		<description><![CDATA[The SheevePlug is now also running Squeezebox Server. This because I bought a Squeezebox Touch. It&#8217;s a very nice device to play music. TwonkyMedia Server was already running on the SheevaPlug, and allowed me to play video and music using &#8230; <a href="http://server.vijge.net/archive/squeezebox-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The SheevePlug is now also running <a href="http://www.squeezenetwork.com/download" target="_blank">Squeezebox Server</a>. This because I bought a <a href="http://www.logitech.com/en-us/speakers-audio/wireless-music-systems/devices/5745" target="_blank">Squeezebox Touch</a>. It&#8217;s a very nice device to play music. <a href="http://twonkymedia.com/products/twonkyserver/default.aspx" target="_blank">TwonkyMedia Server</a> was already running on the SheevaPlug, and allowed me to play video and music using a DLNA compatible television. But this set-up is not ideal for music; the television must always be on. The Squeezebox is a dedicated device just the play music. Unfortunately, Squeezebox uses its own server software, and does not work with the standard DLNA. The software that is needed is, however, open source, and can be run on a lot of different devices, including Linux. All it need is Perl and MySQL. Easy deb packages are available for download.</p>
<p>The speed it not great, but certainly workable. It first needs to index all music. This takes around 40 minutes for 6000 files. When browsing using the web interface, it takes a few seconds to load a page. When using the Squeezebox itself, the speed it more than enough.</p>
<p>Another advantage of the Squeezebox, is that a lot of it is open source. The server software is open source, written in Perl, and the Touch runs a small version of Linux. You can connect using SSH. The interface of the Touch is written in lua, and can be hacked completely. I already wrote my first <a href="http://server.vijge.net/squeezebox">hack</a>&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://server.vijge.net/archive/squeezebox-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two servers: SheevaPlug and Amazon</title>
		<link>http://server.vijge.net/archive/two-servers-sheevaplug-and-amazon/</link>
		<comments>http://server.vijge.net/archive/two-servers-sheevaplug-and-amazon/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 14:04:16 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[SheevaPlug]]></category>

		<guid isPermaLink="false">http://server.vijge.net/?p=132</guid>
		<description><![CDATA[After my SheevaPlug died, I was in search for a new (temporary) host. I decided on Amazon EWS, because it allowed me to set up my own server, use the software I want, and configure it the way I need &#8230; <a href="http://server.vijge.net/archive/two-servers-sheevaplug-and-amazon/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After my SheevaPlug died, I was in search for a new (temporary) host. I decided on Amazon EWS, because it allowed me to set up my own server, use the software I want, and configure it the way I need to. The SheevaPlug itself was quickly repaired, but I decided to keep Amazon. Why? Because the server there is actually a bit faster then the SheevaPlug. Although the SheevaPlug could run dynamic web pages (such as this blog), it was not ideal, and pages loaded slowly. Most web pages were served statically.</p>
<p>But running Amazon EWS also has its disadvantages, especially with mail. The service offered by Amazon is great for spammers. You can set up a server, send all the spam, and cancel the account. For this reason, Amazon limits the number of mails you can send from an Amazon account. Even worse, many mail providers block all mail from Amazon. Hotmail is one such provider. If you try to send a mail to Hotmail, you get a quick message back, that mail is refused.</p>
<p>To solve this, I had to &#8220;split&#8221; the server. Web pages are still hosted at Amazon, but the mail server is hosted at the SheevaPlug. It was a bit complicated to set up, but it all works beautifully now. If a web page (on Amazon) now tries to send a mail, it used postfix. In postfix, the relay SMTP host is set to the web address of the SheevaPlug. So all mail is first send to the SheevaPlug, and only then to the addressee. The web mail is still hosted at Amazon, but it reads the mail from the SheevaPlug. Newly received mail is delivered directly to the SheevaPlug. This can be achieved by setting MX-1 DNS record.</p>
]]></content:encoded>
			<wfw:commentRss>http://server.vijge.net/archive/two-servers-sheevaplug-and-amazon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The SheevaPlug died&#8230;</title>
		<link>http://server.vijge.net/archive/the-sheevaplug-died/</link>
		<comments>http://server.vijge.net/archive/the-sheevaplug-died/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 11:46:16 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[SheevaPlug]]></category>

		<guid isPermaLink="false">http://server.vijge.net/?p=107</guid>
		<description><![CDATA[This Friday my SheevaPlug suddenly died. All that was left was a device with the green blinking LED. Nothing worked, including the serial interface, which should always work. Searching the web, it turns out this is a problem with the &#8230; <a href="http://server.vijge.net/archive/the-sheevaplug-died/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This Friday my SheevaPlug suddenly died. All that was left was a device with the green blinking LED. Nothing worked, including the serial interface, which should always work. Searching the web, it turns out this is a problem with the power supply (PSU). Apparently it happens <a href="http://www.newit.co.uk/forum/index.php?board=5.0" target="_blank">more often</a>. My SheevaPlug was still under warrenty, so NewIT will replace the it. Unfortunately, the new PSU is not available until January. So what to do with all the sites that I run on my SheevePlug&#8217;s web server?</p>
<p>I decided to use <a href="http://aws.amazon.com/ec2/" target="_blank">Amazon EC2</a>. You can place your own virtual server in Amazon&#8217;s cloud. When you sign up, you get one micro server for free. Such a micro server is even a little bit faster than the SheevaPlug, so that it an added bonus. Because you run your own server, you can choose whatever OS you want (I choose Debian, only Lenny was available though), and you can set it up the way you want it. So it was an easy process of copying all the data and configuration files to the new server. Within a couple of hours, the web server was up and running again. There seems to be some cost to data transfer out from the server (so for every web request). But it is a ridiculous low $0.01 per GB. After two days I used 7 MB, so I&#8217;ll take a while before I have to pay 2 cents.</p>
<p>It&#8217;s not all bad, because when I had to set up a new server, I could use my own articles. I could updated some articles, to include extra information, or correct some errors.</p>
<p><strong>Update 1</strong>: First problem found. Hotmail refuses all mail sent from Amazon EC2 servers, because the IP range is listed in Spamhaus&#8217; Policy Block List. So you would need to use an external SMTP relay host.</p>
<p><strong>Update 2 (28 December)</strong>: I received a new PSU from NewIT today. Installing this was easy. The SheevaPlug is now working again. Very quick response from NewIT.</p>
]]></content:encoded>
			<wfw:commentRss>http://server.vijge.net/archive/the-sheevaplug-died/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>See unread mail on SSH login</title>
		<link>http://server.vijge.net/archive/see-unread-mail-on-ssh-login/</link>
		<comments>http://server.vijge.net/archive/see-unread-mail-on-ssh-login/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 13:25:31 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://server.vijge.net/?p=85</guid>
		<description><![CDATA[In the previous post, I explained how to set up your mail server. Now an extra tip on how to read your mail. If you have your own server, you will probably log in via SSH to administer it. Would &#8230; <a href="http://server.vijge.net/archive/see-unread-mail-on-ssh-login/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://server.vijge.net/archive/setting-up-a-mail-server/" target="_self">previous post</a>, I explained how to set up your mail server. Now an extra tip on how to read your mail. If you have your own server, you will probably log in via SSH to administer it. Would it not be nice to be greeted with a message if you have new mail? That&#8217;s quite easy. Edit the files <em>/etc/pam.d/login</em> and <em>/etc/pam.d/sshd</em> and find the line with <em>pam_mail.so</em> on it. Make it look like</p>
<div class="codesnip-container" >
<pre>session    optional   pam_mail.so standard dir=~/.mail</pre>
</div>
<p>If you have another directory where Dovecot stores your mail, change it. To read your mail, type
<div class="codesnip-container" >
<pre>mail</pre>
</div>
<p> to read it. It might be necessairy to install the package heirloom-mailx by first typing
<div class="codesnip-container" >
<pre>aptitude install heirloom-mailx</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://server.vijge.net/archive/see-unread-mail-on-ssh-login/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up a mail server</title>
		<link>http://server.vijge.net/archive/setting-up-a-mail-server/</link>
		<comments>http://server.vijge.net/archive/setting-up-a-mail-server/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 16:37:34 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Dovecot]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://server.vijge.net/?p=63</guid>
		<description><![CDATA[On of the most difficult things to set up &#8211; in my experience &#8211; was a working mail server. It&#8217;s not that easy understanding the transport agents, sendmail applications, SMTP servers, IMAP server, etc. I&#8217;ll try to describe all the &#8230; <a href="http://server.vijge.net/archive/setting-up-a-mail-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>On of the most difficult things to set up &#8211; in my experience &#8211; was a working mail server. It&#8217;s not that easy understanding the transport agents, sendmail applications, SMTP servers, IMAP server, etc.</p>
<p>I&#8217;ll try to describe all the steps to get a working server. This is largely based on <a href="http://www.howtoforge.com/perfect_setup_debian_etch_p5" target="_blank">The Perfect Debian Setup</a>.</p>
<p>The first thing is to install and configure Postfix. Postfix is a mail transfer agent (MTA). It is the program that can send and receive mail from your server to any other server. However, it does not provide a way to access (read) that mail. It does provide the SMTP server for sending mail.</p>
<p>First, you need to install a bunch of stuff:</p>
<div class="codesnip-container" >
<pre>aptitude install postfix libsasl2-2 sasl2-bin libsasl2-modules</pre>
</div>
<p>When asked about the type of configuration, choose &#8216;Internet site&#8217;, and type your server&#8217;s name as the system mail name. After the installation is finished, you can do the actual configuration. Open the file <em>/etc/postfix/main.cf</em> and change the following settings (add the option if it is not already there):</p>
<div class="codesnip-container" >
<pre>smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = vijge.net
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
myhostname = server.vijge.net
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = vijge.net, server.vijge.net, localhost.vijge.net, localhost
relayhost = <em>[external SMTP server]</em>
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = /usr/lib/dovecot/deliver
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all</pre>
</div>
<p>This set how you can access the SMTP server, how the server should behave, and what it should do with mail it receives. The one thing you want to avoid is an open relay server. This is a server that anyone can access, and use to send mail from. Spammers use this, and if your server is an open relay server, some ISPs might block it. So pay attention to security. The setting <em>smtpd_recipient_restrictions </em>controls this. <em><br />
</em></p>
<ul>
<li><em>permit_mynetworks</em> means that anyone with an IP address listed in <em>mynetworks</em> can use the SMTP server without any login<em></em>.</li>
<li><em>reject_unauth_destination</em> means that mail to local users is always allowed. So anyone on the network can send mail to any other users on the network without authenticating.</li>
<li>However, sometimes you are outside your network, but still want to use the SMTP server. But only if a  user logs in. I&#8217;m using a secure login for that, with the setting <em>permit_sasl_authenticated</em>. Other methods (<em>reject_unauth_destination</em>) are not allowed.</li>
</ul>
<p>I set the option <em>relayhost </em>to the SMTP server of my ISP. All outgoing mail is send to this server first. You can also run it without this relay server. Then the SMTP server will try to contact the receiving mail server directly. Just leave it blank if you don&#8217;t want to use it.</p>
<p>Next, you have to start SASL, which takes care of the secure login. Edit the file <em>/etc/default/saslauthd</em> and set <em>START=no</em> to <em>START=yes</em>.</p>
<p>Start <em>saslauthd </em>with
<div class="codesnip-container" >
<pre>/etc/init.d/saslauthd restart</pre>
</div>
<p> and restart postfix with
<div class="codesnip-container" >
<pre>/etc/init.d/postfix restart</pre>
</div>
<p> You can test the connection with the command:</p>
<div class="codesnip-container" >
<pre>telnet localhost 25
ehlo localhost
quit</pre>
</div>
<p>That should output a list of the capabilities of the mail server. If you see <em>250-STARTTSL</em> the secure login is available. If you see <em>250-AUTH PLAIN LOGIN</em> the password-less login is also available (for local users).</p>
<p>Postfix is now configured, and you should be able to send mail. But of course you want to read your mail too. You use an e-mail program for that (such as Outlook, or Thunderbird). But the program needs a way of accessing the mail on your server. There are several options for that: the local mail spool, POP, or IMAP. I am using IMAP. It is supported by all (web) mail programs, and leaves the mail on the server (it doesn&#8217;t download the mail locally). Because the SqueezeBox is small, I wanted a lightweight mail server, so I choose Dovecot. You can install the IMAP part of Dovecot by running:</p>
<div class="codesnip-container" >
<pre>aptitude install dovecot-imapd</pre>
</div>
<p>Your server can receive e-mails (through postfix), but it does not yet know what to do with them. It needs to store them somewhere. This is the job of the <em>local delivery agent</em> (LDA). Dovecot includes an LDA, but it must be enabled in the configuration. You need to tell Dovecot where it must store new mail, and where it can find the mail if you make an IMAP connection to the server. Open the file <em>/etc/dovecot/dovecot.conf</em> and edit the following options:</p>
<ul>
<li>protocols: a list of protocols that are enabled. Separate them with a space. I enabled IMAP, secure IMAP, and sieve, which be used to easily create message filters (more on that later).
<div class="codesnip-container" >
<pre>protocols = imap imaps managesieve</pre>
</div>
</li>
<li>ssl: set ssl to yes, to enable encrypted login through secure IMAP.
<div class="codesnip-container" >
<pre>ssl = yes</pre>
</div>
</li>
<li>Certificates and keys: a secure login need certificates and keys. Certificates are made automatically during the installation of Dovecot.
<div class="codesnip-container" >
<pre>ssl_cert_file = /etc/ssl/certs/dovecot.pem
ssl_key_file = /etc/ssl/private/dovecot.pem</pre>
</div>
</li>
<li>Mail location: here you can configure where to store your mail, and in what format. Dovecot can use different formats, such as <em>maildir</em> and <em>mbox</em>. <em>mbox</em> uses a single file, whilst <em>maildir</em> stores everything in a directory. With Dovecot, <em>maildir</em> is supposed to be fast, so I have used that. I store the mail in the user&#8217;s home directory, under a hidden folder, but you can store it everywhere you like, and even make use of replacement variables.
<div class="codesnip-container" >
<pre>mail_location = maildir:~/.mail</pre>
</div>
</li>
<li>LDA: by default, Dovecot&#8217;s LDA is not enabled, so you need to uncomment that section. Just remove the # before the line
<div class="codesnip-container" >
<pre>protocol lda {</pre>
</div>
<p>Find the closing } and remove the # before that too. I enabled to plugin sieve, so the LDA can filter messages
<div class="codesnip-container" >
<pre>mail_plugin = sieve</pre>
</div>
</li>
</ul>
<p>Now you can restart Dovecot with</p>
<div class="codesnip-container" >
<pre>/etc/init.d/dovecot restart</pre>
</div>
<p>Now you need to create a mailbox directory for each user. You can do this with the command</p>
<div class="codesnip-container" >
<pre>maildirmake.dovecot .mail</pre>
</div>
<p>This assumes you are in the user&#8217;s home directory, and want to create a mailbox dir named <em>.mail</em></p>
<p>Hopefully everything should work now. You can log in using a regular system user and access you mail via IMAP. You should also be able to send mail through your SMTP server.</p>
<p>In the next part of this tutorial, I&#8217;ll explain how to install some extra stuff, such a webmail, and an option to display new message when logging into the SSH shell.</p>
<div style="width: 1px;height: 1px;overflow: hidden"><strong><a name="reject_unauth_destination">reject_unauth_destination</a></strong></div>
]]></content:encoded>
			<wfw:commentRss>http://server.vijge.net/archive/setting-up-a-mail-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing a new kernel on Debian</title>
		<link>http://server.vijge.net/archive/installing-a-new-kernel-on-debian/</link>
		<comments>http://server.vijge.net/archive/installing-a-new-kernel-on-debian/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 12:57:08 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[SheevaPlug]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://server.vijge.net/?p=58</guid>
		<description><![CDATA[Update: If you install it using another method, the kernel can simply by updated with the standard APT update tool. However, there is a bug in the kernel update script. After the update, the USB drive is not longer recognised. &#8230; <a href="http://server.vijge.net/archive/installing-a-new-kernel-on-debian/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: If you install it using <a href="http://www.cyrius.com/debian/kirkwood/sheevaplug/install.html" target="_blank">another method</a>, the kernel can simply by updated with the standard APT update tool. However, there is a <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=550584" target="_blank">bug</a> in the kernel update script. After the update, the USB drive is not longer recognised. It has the error <em>sd_mod: Unknown symbol scsi_verify_blk_ioctl</em>. To fix this, you must flash the kernel to the internal memory with (it might be needed to install <em>flash-kernel</em> first):
<div class="codesnip-container" >
<pre>sudo flash-kernel</pre>
</div>
<p><strong>Original post</strong>: I installed my SheevaPlug with Debian on an SD card using <a href="http://plugcomputer.org/plugforum/index.php?topic=878.0" target="_blank">the alternative Debian install method</a>. This works great, with one minor drawback: the kernel is never updated by Debian package management. Luckily, it&#8217;s not that complicated to install a new kernel. <a href="http://sheeva.with-linux.com/sheeva/" target="_blank">Sheeva with Linux</a> publishes kernels for the Sheevaplug. There is also a script to update the kernel. On my Sheevaplug however, I could not use this script. The kernel is saved on a small boot partition of the SD card. This partition is too small to copy a new kernel to. Manually doing all the steps is straightforward too.</p>
<ol>
<li>By default, the boot partition of the SD card is not mounted, so mount it to /boot:
<div class="codesnip-container" >
<pre>mount /dev/mmcblk0p1 /boot</pre>
</div>
</li>
<li>Make backups of the file that will be overwritten. This include the file <em>/boot/uImage</em> and the folder <em>/dev/firmware </em></li>
<li>Go to <a href="http://sheeva.with-linux.com/sheeva/" target="_blank">Sheeva with Linux</a> and choose a kernel, the latest will be fine. At the time I did this, this was 2.6.35.2. Download the files <em>sheeva-*-uImage</em>, <em>sheeva-*-System.map</em>, and <em>sheeva-*-Modules.tar.gz</em>. Just save them in your home directory</li>
<li>Execute the following commands to extract the new modules and install the symbol table (replace {ver} with the kernel version you downloaded, e.g. 2.6.35.2):
<div class="codesnip-container" >
<pre>tar x -C / --overwrite -zf sheeva-{ver}-Modules.tar.gz
depmod -eF /boot/sheeva-{ver}-System.map {ver}</pre>
</div>
</li>
<li>Remove the old kernel and copy the new kernel:
<div class="codesnip-container" >
<pre>rm /boot/uImage
mv sheeva-*-uImage /boot/uImage</pre>
</div>
</li>
<li>Reboot with the command
<div class="codesnip-container" >
<pre>reboot</pre>
</div>
</li>
</ol>
<p>The SheevePlug should now reboot. After a minute or so, you should be able to log in again. Use the command
<div class="codesnip-container" >
<pre>uname -a</pre>
</div>
<p> to check if the new kernel is running. If something goes wrong, you can remove the SD card from the plug, put it in another computer and restore the backup files. I did everything from a SSH session. If you want more information (e.g. the error message during boot), you can do the upgrade over a USB terminal connection.</p>
]]></content:encoded>
			<wfw:commentRss>http://server.vijge.net/archive/installing-a-new-kernel-on-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AWstats statistics with sub domains on lighttpd</title>
		<link>http://server.vijge.net/archive/awstats-statistics-with-sub-domains-on-lighttpd/</link>
		<comments>http://server.vijge.net/archive/awstats-statistics-with-sub-domains-on-lighttpd/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 11:29:01 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[awstats]]></category>
		<category><![CDATA[lighttpd]]></category>

		<guid isPermaLink="false">http://server.vijge.net/?p=52</guid>
		<description><![CDATA[One of the best tools to analyse web visits is AWstats. This tool gives very detailed information about the visitors on your web site. It will analyse the log file of the web server, and turns this into very nice &#8230; <a href="http://server.vijge.net/archive/awstats-statistics-with-sub-domains-on-lighttpd/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the best tools to analyse web visits is <a href="http://awstats.sourceforge.net/" target="_blank">AWstats</a>. This tool gives very detailed information about the visitors on your web site. It will analyse the log file of the web server, and turns this into very nice statistics. In the default configuration, it has only limited support for lighttpd. You can set the log type to Apache, and you will get some kind of logging. However, this lumps all sites into one. If you have sub domains, some tweaking is needed to get separate statistics for each sub domain.</p>
<p>I installed AWstats using the Debian package manager. This will install the configuration files in <em>/etc/awstats</em> There are two files there: <em>awstats.conf</em> contains basic settings, <em>awstats.conf.local</em> is imported by <em>awstats.conf</em> and can be used to overwrite certain settings.</p>
<p>For each of the sub domains, a separate configuration file is needed. It needs to be in a specific format: awstats.sub.domain.net.conf For example, the config file for this site would be <em>awstats.server.vijge.net.conf</em>  The <em>awstats.conf</em> file will gather statistics for all sub domain together, and the <em>awstats.conf.local</em> file will contain all the general settings.<em><br />
</em></p>
<p>First, delete the current <em>awstats.conf.local</em> file, and copy the current <em>awstats.conf</em> file to <em>awstats.conf.local</em> Next, make some changes the the awstats.conf.local file:<br />
<strong>1.</strong> Change the LogFile variable to point to the lighttpd log file. In the default Debian configuration, this would be
<div class="codesnip-container" >
<pre>LogFile="/var/log/lighttpd/access.log"</pre>
</div>
<p><strong>2.</strong> Change the LogFormat to the log settings for lighttpd.
<div class="codesnip-container" >
<pre>LogFormat="%host %virtualname %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"</pre>
</div>
<p><strong>3.</strong> Place a comment character (#) before SiteDomain and HostAlias
<div class="codesnip-container" >
<pre>#SiteDomain=""
#HostAliases=""</pre>
</div>
<p><strong>4</strong>. At the end of the file, there is an include of the <em>awstats.conf.local</em> file. But because this is already the <em>awstats.conf.local</em> file, the include has the be removed, to make sure there is no infinite include loop.</p>
<div class="codesnip-container" >
<pre>#Include "/etc/awstats/awstats.conf.local"</pre>
</div>
<p>That is it for the generate configuration. Now configure the configuration for each sub domain, and for the total site. Open the file <em>awstats.conf</em>, and replace all contents by</p>
<div class="codesnip-container" >
<pre>SiteDomain="domain.net"
HostAliases="localhost 127.0.0.1 REGEX[domain\.net$]"

Include "/etc/awstats/awstats.conf.local"</pre>
</div>
<p>Add your domain name in the regex expression, so all domains are matched. For each sub domain you want to track, make a new file with the name <em>awstats.sub.domain.net.conf</em> and place the following code it in</p>
<div class="codesnip-container" >
<pre>SiteDomain="sub.domain.net"
HostAliases="sub.domain.net"

Include "/etc/awstats/awstats.conf.local"</pre>
</div>
<p>The configuration is now done. Now you need to make sure your web server knows about AWstats. First, create a separate directory in your www folder (e.g. <em>/var/www/awstats</em>). In this directory, make a symbolic link to the awstats executable:
<div class="codesnip-container" >
<pre>ln -s /usr/lib/cgi-bin/awstats.pl</pre>
</div>
<p> Edit the file <em>/etc.lighttpd/lighttpd.conf</em> to include</p>
<div class="codesnip-container" >
<pre>alias.url += ( "/awstats-icon" =&gt; "/usr/share/awstats/icon" )
alias.url += ( "/awstats" =&gt; "/var/www/awstats" )
$HTTP["url"] =~ "^/awstats($|/)" {
cgi.assign = (
".pl" =&gt; "/usr/bin/perl",
".cgi" =&gt; "/usr/bin/perl"
)
}</pre>
</div>
<p>If you visit the AWstats page, it will display the statistics for the current sub domain. If you view AWstats from the domain server.vijge.net, the statistics for that domain are displayed. To change to a different domain, simply place an argument behind the url, e.g.
<div class="codesnip-container" >
<pre>awstats.pl?config=daniel.vijge.net</pre>
</div>
<p> The part behind the config= corresponds to the name given to each config file, between <em>awstats</em> and .conf To view the statistics for all the domains (as configured in <em>awstats.conf</em>), supply an invalid config parameter, e.g.
<div class="codesnip-container" >
<pre>awstats.pl?config=all</pre>
</div>
<p>I created a simple page with links to the statistics for each sub domain, to I can easily browse to them.</p>
<p>If you installed AWstats under Debian Squeeze, it runs as a cron job, so all the statistics are updated every 10 minutes. Under older versions of Debian this script is not included, but you can download it <a href="http://server.vijge.net/files/2010/12/update.sh">here</a>. Save this as <em>/usr/share/awstats/tools/update.sh</em>, make is executable, and change the file <em>/etc/cron.d/awstats</em> to read</p>
<div class="codesnip-container" >
<pre>*/10 * * * * www-data [ -x /usr/share/awstats/tools/update.sh ] &amp;&amp; /usr/share/awstats/tools/update.sh</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://server.vijge.net/archive/awstats-statistics-with-sub-domains-on-lighttpd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert myGallery to NextGen Gallery</title>
		<link>http://server.vijge.net/archive/convert-mygallery-to-nextgen-gallery/</link>
		<comments>http://server.vijge.net/archive/convert-mygallery-to-nextgen-gallery/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 12:32:25 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[myGallery]]></category>
		<category><![CDATA[NextGen Gallery]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://server.vijge.net/?p=44</guid>
		<description><![CDATA[For a lot of web logs, photo galleries are used. The web logs in this server used to run myGallery. However, this WordPress plugin wasn&#8217;t updated for a long time. (Recently there was an update for WordPress 3. I haven&#8217;t &#8230; <a href="http://server.vijge.net/archive/convert-mygallery-to-nextgen-gallery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For a lot of web logs, photo galleries are used. The web logs in this server used to run <a href="http://www.wildbits.de/mygallery/" target="_blank">myGallery</a>. However, this WordPress plugin wasn&#8217;t updated for a long time. (Recently there was an update for WordPress 3. I haven&#8217;t tested this one yet). So I needed a new gallery plugin. The <a href="http://alexrabe.de/wordpress-plugins/nextgen-gallery/" target="_blank">NextGen Gallery</a> plugin has all the requirements that I need. And best of all, it&#8217;s reasonably compatible with myGallery. So I decided to write a script that can convert all myGallery galleries to NextGen galleries. It will also update all the pages that display the gallery. Last, it will convert the thumbnail directory, so NextGen Gallery can use them. Of course, you can also let NextGen Gallery generate new thumbnails. But since my server isn&#8217;t that fast, using existing thumbnails is a good idea.</p>
<p>If you are running myGallery, and want to upgrade to NextGen Gallery and perform the conversion, this are the steps to perform. First, download NextGen Gallery. Disable myGallery, and enable NextGen Gallery. Next, copy and paste the script below in a PHP file. Modify the configuration and run the script. This will give a series of SQL statements. You can run these on the MySQL database. For example, you can use phpMyAdmin to run the queries easily.</p>
<div class="codesnip-container" >
<pre>
<div class="php codesnip" style="font-family:monospace;"><span class="co1">// CONFIG</span>

<span class="co1">// the prefix for your WordPress tables (default: wp_)</span>
<span class="re0">$WP_PREFIX</span> <span class="sy0">=</span> <span class="st0">'wp_'</span><span class="sy0">;</span>

<span class="co1">// the directory on the server where your photos are stored</span>
<span class="re0">$GALLERYBASEPATH</span> <span class="sy0">=</span> <span class="st0">'wp-content/myfotos/daniel'</span><span class="sy0">;</span>

<span class="co1">// username for the database</span>
<span class="re0">$USERNAME</span> <span class="sy0">=</span> <span class="st0">'username'</span><span class="sy0">;</span>

<span class="co1">// password for the database</span>
<span class="re0">$PASSWORD</span> <span class="sy0">=</span> <span class="st0">'password'</span><span class="sy0">;</span>

<span class="co1">// name of the database containing WordPress</span>
<span class="re0">$DATABASE</span> <span class="sy0">=</span> <span class="st0">'wordpress'</span><span class="sy0">;</span>

<span class="co1">// host for the database (99% chance it will be localhost)</span>
<span class="re0">$HOST</span> <span class="sy0">=</span> <span class="st0">'localhost'</span><span class="sy0">;</span>

<span class="co1">// END OF CONFIG</span>

<span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$GALLERYBASEPATH</span><span class="sy0">,-</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">!=</span><span class="st0">'/'</span> <span class="sy0">&amp;</span>amp<span class="sy0">;&amp;</span>amp<span class="sy0">;</span> <span class="re0">$GALLERYBASEPATH</span><span class="sy0">!=</span><span class="st0">''</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$GALLERYBASEPATH</span> <span class="sy0">=</span> <span class="re0">$GALLERYBASEPATH</span> <span class="sy0">.</span> <span class="st0">'/'</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="re0">$link</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_connect"><span class="kw3">mysql_connect</span></a><span class="br0">&#40;</span><span class="re0">$HOST</span><span class="sy0">,</span><span class="re0">$USERNAME</span><span class="sy0">,</span><span class="re0">$PASSWORD</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">'Cannot connect to database '</span><span class="sy0">.</span><span class="re0">$HOST</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$x</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_select_db"><span class="kw3">mysql_select_db</span></a><span class="br0">&#40;</span><span class="re0">$DATABASE</span><span class="sy0">,</span><span class="re0">$link</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">'Cannot select database '</span><span class="sy0">.</span><span class="re0">$DATABASE</span><span class="br0">&#41;</span><span class="sy0">;</span>

<span class="co1">// convert the gallery</span>
<span class="re0">$result</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">'SELECT * FROM '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'mygallery'</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">'Cannot execure queries. Is the prefix correct?'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'longname'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <a href="http://www.php.net/addslashes"><span class="kw3">addslashes</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'longname'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'galdescrip'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <a href="http://www.php.net/addslashes"><span class="kw3">addslashes</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'galdescrip'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="st0">'INSERT INTO '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'ngg_gallery (gid,name,path,title,galdesc,pageid,previewpic,author) VALUES ('</span><span class="sy0">.</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'id'</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="st0">',\'</span><span class="st0">'.<span class="es4">$row</span>['</span>name<span class="st0">'].'</span>\<span class="st0">',\'</span><span class="st0">'.<span class="es4">$GALLERYBASEPATH</span>.<span class="es4">$row</span>['</span>name<span class="st0">'].'</span>\<span class="st0">',\'</span><span class="st0">'.<span class="es4">$row</span>['</span>longname<span class="st0">'].'</span>\<span class="st0">',\'</span><span class="st0">'.<span class="es4">$row</span>['</span>galdescrip<span class="st0">'].'</span>\<span class="st0">',\'</span><span class="st0">'.<span class="es4">$row</span>['</span>pageid<span class="st0">'].'</span>\<span class="st0">',\'</span><span class="st0">'.<span class="es4">$row</span>['</span>previewpic<span class="st0">'].'</span>\<span class="st0">',0);'</span> <span class="sy0">.</span> <span class="st0">'&lt;br /&gt;'</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="co1">// convert the images</span>
<span class="re0">$result</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">'SELECT * FROM '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'mypictures INNER JOIN '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'mygprelation ON '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'mypictures.id='</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'mygprelation.pid INNER JOIN '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'mygallery ON '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'mygallery.id='</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'mygprelation.gid'</span><span class="br0">&#41;</span><span class="sy0">;</span>

<span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'description'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <a href="http://www.php.net/addslashes"><span class="kw3">addslashes</span></a><span class="br0">&#40;</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'description'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="st0">'INSERT INTO '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'ngg_pictures (pid,galleryid,filename,description) VALUES ('</span><span class="sy0">.</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'pid'</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="st0">','</span><span class="sy0">.</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'gid'</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="st0">',\'</span><span class="st0">'.<span class="es4">$row</span>['</span>picturepath<span class="st0">'].'</span>\<span class="st0">',\'</span><span class="st0">'.<span class="es4">$row</span>['</span>description<span class="st0">'].'</span>\<span class="st0">');'</span> <span class="sy0">.</span> <span class="st0">'&lt;br /&gt;'</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="co1">// convert pages</span>
<span class="re0">$result</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">'SELECT id,pageid FROM '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'mygallery'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="st0">'UPDATE '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'posts SET post_content=\'</span><span class="br0">&#91;</span>nggallery id<span class="sy0">=</span><span class="st0">'.<span class="es4">$row</span>['</span>id<span class="st0">'].'</span><span class="br0">&#93;</span>\<span class="st0">' WHERE ID='</span><span class="sy0">.</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'pageid'</span><span class="br0">&#93;</span> <span class="sy0">.</span> <span class="st0">';&lt;br&gt;'</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="co1">// convert page with master gallery</span>
<span class="re0">$result</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">'SELECT * FROM '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'posts WHERE post_content=\'</span><span class="br0">&#91;</span>mygallistgal<span class="br0">&#93;</span>\<span class="st0">''</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="st0">'UPDATE '</span><span class="sy0">.</span><span class="re0">$WP_PREFIX</span><span class="sy0">.</span><span class="st0">'posts SET post_content=\'</span><span class="br0">&#91;</span>album template<span class="sy0">=</span>extend<span class="br0">&#93;</span>\<span class="st0">' WHERE ID='</span><span class="sy0">.</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'ID'</span><span class="br0">&#93;</span> <span class="sy0">.</span> <span class="st0">';&lt;br&gt;'</span><span class="sy0">;</span>
<span class="br0">&#125;</span></div>
</pre>
</div>
<p>There are a number of caveats you should be aware of:</p>
<ul>
<li>Gallery pages are updated, so they contain the new gallery tag. If there is any other text on a page, this text is lost</li>
<li>The page looks for the master gallery page (the page with links to all galleries. It will only find it if this page does not contain any other text. If the last code block does not give any results, you have to change this page manually</li>
</ul>
<p>If you visit your gallery pages now, the should work, only the thumbnails are not displayed. To fix this, I&#8217;ve made a second script.</p>
<div class="codesnip-container" >
<pre>
<div class="php codesnip" style="font-family:monospace;"><a href="http://www.php.net/error_reporting"><span class="kw3">error_reporting</span></a><span class="br0">&#40;</span><span class="kw4">E_ALL</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$prefix</span> <span class="sy0">=</span> <span class="st0">'/home/www/wordpress_mu/wp-content/myfotos/daniel'</span><span class="sy0">;</span>
<span class="re0">$dirs</span> <span class="sy0">=</span> <a href="http://www.php.net/scandir"><span class="kw3">scandir</span></a><span class="br0">&#40;</span><span class="re0">$prefix</span><span class="br0">&#41;</span><span class="sy0">;</span>


<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$dirs</span> <span class="kw1">as</span> <span class="re0">$dirname</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$dirname</span><span class="sy0">==</span><span class="st0">'.'</span> <span class="sy0">||</span> <span class="re0">$dirname</span><span class="sy0">==</span><span class="st0">'..'</span><span class="br0">&#41;</span> <span class="kw1">continue</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$dir</span> <span class="sy0">=</span> <span class="re0">$prefix</span><span class="sy0">.</span><span class="st0">'/'</span><span class="sy0">.</span><span class="re0">$dirname</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/is_dir"><span class="kw3">is_dir</span></a><span class="br0">&#40;</span><span class="re0">$dir</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$dh</span> <span class="sy0">=</span> <a href="http://www.php.net/opendir"><span class="kw3">opendir</span></a><span class="br0">&#40;</span><span class="re0">$dir</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="re0">$dir</span> <span class="sy0">.</span> <span class="st0">&quot; open&lt;br&gt;&quot;</span><span class="sy0">;</span>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/is_dir"><span class="kw3">is_dir</span></a><span class="br0">&#40;</span><span class="re0">$dir</span><span class="sy0">.</span><span class="st0">'/tumbs'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$dh2</span> <span class="sy0">=</span> <a href="http://www.php.net/opendir"><span class="kw3">opendir</span></a><span class="br0">&#40;</span><span class="re0">$dir</span><span class="sy0">.</span><span class="st0">'/tumbs'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$file</span> <span class="sy0">=</span> <a href="http://www.php.net/readdir"><span class="kw3">readdir</span></a><span class="br0">&#40;</span><span class="re0">$dh2</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">!==</span> <span class="kw4">false</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$file</span><span class="sy0">,</span><span class="nu0">0</span><span class="sy0">,</span><span class="nu0">3</span><span class="br0">&#41;</span><span class="sy0">==</span><span class="st0">'tmb'</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$newname</span> <span class="sy0">=</span> <a href="http://www.php.net/str_replace"><span class="kw3">str_replace</span></a><span class="br0">&#40;</span><span class="st0">'tmb'</span><span class="sy0">,</span><span class="st0">'thumbs'</span><span class="sy0">,</span><span class="re0">$file</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$r</span> <span class="sy0">=</span> <a href="http://www.php.net/rename"><span class="kw3">rename</span></a><span class="br0">&#40;</span><span class="re0">$dir</span><span class="sy0">.</span><span class="st0">'/tumbs/'</span><span class="sy0">.</span><span class="re0">$file</span><span class="sy0">,</span><span class="re0">$dir</span><span class="sy0">.</span><span class="st0">'/tumbs/'</span><span class="sy0">.</span><span class="re0">$newname</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="st0">&quot;filename: <span class="es4">$file</span> to <span class="es4">$newname</span> : rename: <span class="es4">$r</span>&lt;br&gt;&quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// rename tumbs dir</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$r</span> <span class="sy0">=</span> <a href="http://www.php.net/rename"><span class="kw3">rename</span></a><span class="br0">&#40;</span><span class="re0">$dir</span><span class="sy0">.</span><span class="st0">'/tumbs'</span><span class="sy0">,</span><span class="re0">$dir</span><span class="sy0">.</span><span class="st0">'/thumbs'</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="re0">$dir</span> <span class="sy0">.</span> <span class="st0">&quot; rename &quot;</span> <span class="sy0">.</span><span class="re0">$r</span><span class="sy0">.</span><span class="st0">&quot;&lt;br&gt;&quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/closedir"><span class="kw3">closedir</span></a><span class="br0">&#40;</span><span class="re0">$dh2</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/closedir"><span class="kw3">closedir</span></a><span class="br0">&#40;</span><span class="re0">$dh</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span></div>
</pre>
</div>
<p>Just change the prefix variable, to point to the path where all galleries are located. This script will rename all thumbnail directories immediatly.</p>
]]></content:encoded>
			<wfw:commentRss>http://server.vijge.net/archive/convert-mygallery-to-nextgen-gallery/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>A script to fix Geo Mashup update</title>
		<link>http://server.vijge.net/archive/a-script-to-fix-geo-mashup-update/</link>
		<comments>http://server.vijge.net/archive/a-script-to-fix-geo-mashup-update/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 10:13:36 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Geo Mashup]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://server.vijge.net/?p=39</guid>
		<description><![CDATA[On one of my web logs, I use a map to display the route of my travels. Each post is geo-tagged, so places can be connected with lines. It&#8217;s a very nice feature for a travel blog, thanks to the &#8230; <a href="http://server.vijge.net/archive/a-script-to-fix-geo-mashup-update/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>On one of my <a href="http://daniel.vijge.net" target="_blank">web logs</a>, I use a map to display the <a href="http://daniel.vijge.net/route" target="_blank">route of my travels</a>. Each post is geo-tagged, so places can be connected with lines. It&#8217;s a very nice feature for a travel blog, thanks to the <a href="http://code.google.com/p/wordpress-geo-mashup/" target="_blank">Geo Mashup plugin for WordPress</a>. I recently updated the Geo Mashup plugin to a new version. For this version, the locations had to be converted to the new format. The result of this upgrade was that my route was no longer correct: posts seemed randomly connected to each other.</p>
<p>After some investigation, I found that Geo Mashup uses a special table to link posts and location to each other. This link also has a date and time connected to it. The results are ordered using this date. During the conversion, each link had the date of the conversion. Therefore, the results were displayed random.</p>
<p>I wrote a quick PHP script to fix this problem. This script looks at the time the original post was made, and updates the Geo Mashup table.</p>
<div class="codesnip-container" >
<pre>
<div class="php codesnip" style="font-family:monospace;"><span class="co1">// CONFIG</span>

<span class="co1">// username for the database</span>
<span class="re0">$USERNAME</span> <span class="sy0">=</span> <span class="st0">'username'</span><span class="sy0">;</span>

<span class="co1">// password for the database</span>
<span class="re0">$PASSWORD</span> <span class="sy0">=</span> <span class="st0">'password'</span><span class="sy0">;</span>

<span class="co1">// name of the database containing WordPress</span>
<span class="re0">$DATABASE</span> <span class="sy0">=</span> <span class="st0">'wordpress'</span><span class="sy0">;</span>

<span class="co1">// host for the database (99% chance it will be localhost)</span>
<span class="re0">$HOST</span> <span class="sy0">=</span> <span class="st0">'localhost'</span><span class="sy0">;</span>

<span class="co1">// END OF CONFIG</span>

<span class="re0">$link</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_connect"><span class="kw3">mysql_connect</span></a><span class="br0">&#40;</span><span class="re0">$HOST</span><span class="sy0">,</span><span class="re0">$USERNAME</span><span class="sy0">,</span><span class="re0">$PASSWORD</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">'Cannot connect to database '</span><span class="sy0">.</span><span class="re0">$HOST</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$x</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_select_db"><span class="kw3">mysql_select_db</span></a><span class="br0">&#40;</span><span class="re0">$DATABASE</span><span class="sy0">,</span><span class="re0">$link</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">'Cannot select database '</span><span class="sy0">.</span><span class="re0">$DATABASE</span><span class="br0">&#41;</span><span class="sy0">;</span>

<span class="re0">$result</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;SELECT * FROM wp_geo_mashup_location_relationships&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$result2</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;SELECT post_date FROM wp_posts WHERE id=&quot;</span><span class="sy0">.</span><span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">'object_id'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;UPDATE wp_geo_mashup_location_relationships SET geo_date=\'&quot;</span> <span class="sy0">.</span> <span class="re0">$row2</span><span class="br0">&#91;</span><span class="st0">'post_date'</span><span class="br0">&#93;</span> <span class="sy0">.</span> <span class="st0">&quot;\'&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></div>
</pre>
</div>
<p>After running this script, the problem was fixed, and my map displayed the correct route.</p>
]]></content:encoded>
			<wfw:commentRss>http://server.vijge.net/archive/a-script-to-fix-geo-mashup-update/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

