<?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>Daniel15&#039;s Blog &#187; Linux</title>
	<atom:link href="http://dan.cx/blog/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://dan.cx/blog</link>
	<description>Blog of Daniel, a slightly awesome 19-year-old web developer from Melbourne, Australia</description>
	<lastBuildDate>Sun, 15 Aug 2010 02:22:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Hard drive failure&#8230;</title>
		<link>http://dan.cx/blog/2007/06/hard-drive-failure/</link>
		<comments>http://dan.cx/blog/2007/06/hard-drive-failure/#comments</comments>
		<pubDate>Sat, 16 Jun 2007 02:10:45 +0000</pubDate>
		<dc:creator>Daniel15</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.daniel15.com/blog/2007/06/16/hard-drive-failure/</guid>
		<description><![CDATA[Yesterday, I had a hard drive die on me  . It was a 160 GB Seagate Barracuda, and was less than a year old. It started with strange error messages late last night. I went to the server, reset it (need to power it off &#8211; It wouldn&#8217;t shutdown cleanly), and now it won&#8217;t boot. [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I had a hard drive die on me  <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> . It was a 160 GB Seagate Barracuda, and was less than a year old. It started with strange error messages late last night. I went to the server, reset it (need to power it off &#8211; It wouldn&#8217;t shutdown cleanly), and now it won&#8217;t boot. When I try to boot the system, I can hear the drive head hitting against the side of the drive, which makes me think there is a problem internally with the drive&#8230; </p>
<p>I&#8217;m looking into recovery options, though I think it will be way too expensive for my needs. If it is too expensive, I&#8217;ll just have to cut my losses and move on. A lot of my development work was on this server (it was my <i>backup</i> PC as well). Whilst I have local copies of stuff, a lot of it is slightly old. It&#8217;s kinda depressing to have something like this happen, so I&#8217;m not really in a good mood at the moment  <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p><i style="color: red">Update: About two weeks after the hard drive &#8220;failed&#8221;, I tried it again. It was working, but made a strange sound. I quickly copied all the data off of it, and disconnected it. I was able to get a copy of all the most important data. So, it&#8217;s not so bad&#8230; This story has a happy ending <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </i></p>
]]></content:encoded>
			<wfw:commentRss>http://dan.cx/blog/2007/06/hard-drive-failure/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Brute-force attacks from Nokia</title>
		<link>http://dan.cx/blog/2007/05/brute-force-attacks-from-nokia/</link>
		<comments>http://dan.cx/blog/2007/05/brute-force-attacks-from-nokia/#comments</comments>
		<pubDate>Wed, 02 May 2007 06:15:35 +0000</pubDate>
		<dc:creator>Daniel15</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.daniel15.com/blog/2007/05/02/brute-force-attacks-from-nokia/</guid>
		<description><![CDATA[I checked my email inbox this morning, and guess what I found? The firewall (ConfigServer Security and Firewall) on a server I help run blocked a brute-force attack from Nokia: Time: Tue May 1 02:28:18 2007 IP: 63.97.248.34 (machine34.nokia.com) Failures: 5 (sshd) Interval: 135 seconds Blocked: Yes Log entries: May 1 02:28:08 blue sshd[9363]: Failed [...]]]></description>
			<content:encoded><![CDATA[<p>I checked my email inbox this morning, and guess what I found? The firewall (<a href="http://configserver.com/cp/csf.html">ConfigServer Security and Firewall</a>) on a server I help run blocked a brute-force attack from Nokia:</p>
<blockquote><p>
Time:     Tue May  1 02:28:18 2007<br />
IP:       63.97.248.34 (<b>machine34.nokia.com</b>)<br />
Failures: 5 (sshd)<br />
Interval: 135 seconds<br />
Blocked:  Yes</p>
<p>Log entries:</p>
<p>May  1 02:28:08 blue sshd[9363]: Failed password for root from ::ffff:63.97.248.34 port 56057 ssh2<br />
May  1 07:28:08 blue sshd[9364]: Failed password for root from ::ffff:63.97.248.34 port 56057 ssh2<br />
May  1 02:28:11 blue sshd[9368]: Failed password for root from ::ffff:63.97.248.34 port 56436 ssh2<br />
May  1 07:28:11 blue sshd[9369]: Failed password for root from ::ffff:63.97.248.34 port 56436 ssh2<br />
May  1 02:28:13 blue sshd[9370]: Failed password for root from ::ffff:63.97.248.34 port 56591 ssh2
</p></blockquote>
<p>Just thought it was funny <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
(oh yeah, and I will report it to them!)</p>
]]></content:encoded>
			<wfw:commentRss>http://dan.cx/blog/2007/05/brute-force-attacks-from-nokia/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting up a serial console on Linux</title>
		<link>http://dan.cx/blog/2007/02/setting-up-a-serial-console-on-linux/</link>
		<comments>http://dan.cx/blog/2007/02/setting-up-a-serial-console-on-linux/#comments</comments>
		<pubDate>Sun, 11 Feb 2007 05:45:11 +0000</pubDate>
		<dc:creator>Daniel15</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.daniel15.com/blog/2007/02/11/setting-up-a-serial-console-on-linux/</guid>
		<description><![CDATA[This tutorial will show you how to set up a serial console on a Linux system, and connect to it via a null modem cable. This is quite useful if your Linux server is in a headless configuration (no keyboard or monitor), as it allows you to easily get a console on the system if [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial will show you how to set up a serial console on a Linux system, and connect to it via a null modem cable. This is quite useful if your Linux server is in a headless configuration (no keyboard or monitor), as it allows you to easily get a console on the system if there are any problems with it (especially network problems, when SSH is not available). In the end, the GRUB menu will appear over the serial link, as will the bootup messages (output when booting the system). I&#8217;m using Debian Etch on the server and Ubuntu Edgy on my client, although this should work on any Linux distribution. </p>
<p><span id="more-47"></span></p>
<h4>First steps</h4>
<p>One of the most important things we need to check that you do actually have a serial port on the server <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Take a look at the back of your server, and see if it has a 9-pin serial port. Most motherboards have either one or two serial ports. On the system, check to see that Linux is recognising the serial ports:</p>
<p><pre><pre>root@server:~#&nbsp;&nbsp;dmesg | grep tty
serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
00:08: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A</pre></pre></p>
<p>This shows that my system has one serial port, <tt>ttyS0</tt> (remember this for later).</p>
<h4>GRUB configuration </h4>
<p>The next step is to edit the GRUB configuration, so it sends its messages to the serial console. One of the most important things is to set a password, otherwise anyone can connect a serial cable, edit the GRUB configuration line while the system is booting (via the &#8220;e&#8221; key), and get root access. When a password is set, interactive menu editing will be disabled, unless the correct password is entered. To set the password, we first need to get the encrypted version of it.</p>
<p>Run <tt>grub</tt>, and use the &#8220;md5crypt&#8221; command to encrypt the password:</p>
<p><pre><pre>grub&amp;gt; md5crypt

Password: ********
Encrypted: $1$AlfMq1$FxRolxW5XvSLAOksiC7MD1</pre></pre></p>
<p>Copy the encrypted version of the password (we need it for the next step), and then type <tt>quit</tt> to exit. </p>
<p>Now, we need to edit the GRUB configuration. Edit the /boot/grub/menu.lst file (by typing <tt>nano /boot/grub/menu.lst</tt>), and find this section:</p>
<p><pre><pre>## password [&#039;--md5&#039;] passwd
&nbsp;&nbsp; # If used in the first section of a menu file, disable all interactive editing
&nbsp;&nbsp; # control (menu entry editor and command-line)&nbsp;&nbsp;and entries protected by the
&nbsp;&nbsp; # command &#039;lock&#039;
&nbsp;&nbsp; # e.g. password topsecret
&nbsp;&nbsp; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
&nbsp;&nbsp; # password topsecret
</pre></pre></p>
<p>Below that, add:</p>
<p><pre><pre>password --md5 $1$AlfMq1$FxRolxW5XvSLAOksiC7MD1
serial --unit=0 --speed=38400 --word=8 --parity=no --stop=1&nbsp;&nbsp; 
terminal --timeout=10 serial console</pre></pre></p>
<p>Replace <i>$1$AlfMq1$FxRolxW5XvSLAOksiC7MD1</i> with the encrypted form of <b>your</b> password. The second line tells GRUB to initialise the serial port at 38,400 bps (same speed as the standard console), 8 data bits, no parity, and 1 stop bit (basically, the standard settings). Note that the <b>&#8211;unit=0</b> means that it will use the <b>first</b> serial port (ttyS0). If you&#8217;re using the <b>second</b> serial port (ttyS1), change it to<b> &#8211;unit=1</b>. The last line tells GRUB to show its menu on both the serial line <i>and</i> the console (monitor).</p>
<p>Now, we also need to edit the kernel sections, so that they output messages to the serial console. At the end of every kernel line, add <tt>console=tty0 console=ttyS0,38400n8</tt> (replace <tt>ttyS0</tt> with the correct serial port). In my case, it ended up looking like:</p>
<p><pre><pre>title&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debian GNU/Linux, kernel 2.6.18-4-vserver-686
&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(hd0,1)
&nbsp;&nbsp; kernel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/vmlinuz-2.6.18-4-vserver-686 root=/dev/hda3 ro console=tty0 console=ttyS0,38400n8
&nbsp;&nbsp; initrd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/initrd.img-2.6.18-4-vserver-686
&nbsp;&nbsp; savedefault
title&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debian GNU/Linux, kernel 2.6.18-4-vserver-686 (single-user mode)
&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(hd0,1)
&nbsp;&nbsp; kernel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/vmlinuz-2.6.18-4-vserver-686 root=/dev/hda3 ro single console=tty0 console=ttyS0,38400n8
&nbsp;&nbsp; initrd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/initrd.img-2.6.18-4-vserver-686
&nbsp;&nbsp; savedefault
title&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debian GNU/Linux, kernel 2.6.18-3-686
&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(hd0,1)
&nbsp;&nbsp; kernel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/vmlinuz-2.6.18-3-686 root=/dev/hda3 ro console=tty0 console=ttyS0,38400n8
&nbsp;&nbsp; initrd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/initrd.img-2.6.18-3-686
&nbsp;&nbsp; savedefault
title&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debian GNU/Linux, kernel 2.6.18-3-686 (single-user mode)
&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(hd0,1)
&nbsp;&nbsp; kernel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/vmlinuz-2.6.18-3-686 root=/dev/hda3 ro single console=tty0 console=ttyS0,38400n8
&nbsp;&nbsp; initrd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/initrd.img-2.6.18-3-686&lt;br /&gt;&nbsp;&nbsp; savedefault&lt;br /&gt;&amp;nbsp;</pre></pre></p>
<p>Save and exit, by pressing CTRL+O (to &#8220;output&#8221;, or save the file), Enter (to accept the file name) and CTRL+X (to actually exit).</p>
<h4>Allow logins over Serial Console  </h4>
<p>Now, the GRUB menu will appear over the serial connection, but we still aren&#8217;t listening for logins over it (there&#8217;s no &#8220;getty&#8221; running on it yet). Edit the <tt>/etc/inittab</tt><tt> file, and find this section:</tt></p>
<p><pre><pre># Example how to put a getty on a serial line (for a terminal)
#
#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
</pre></pre></p>
<p>Below that (I don&#8217;t like editing the default lines <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ), add:</p>
<p><pre>T0:2345:respawn:/sbin/getty -L ttyS0 38400 vt100</pre></p>
<p>And that&#8217;s all there is to it. Your server will now show the GRUB menu over the serial console, and also allow logons (once it has finished booting). </p>
<h4>Let&#8217;s test it!</h4>
<p>Now that that&#8217;s all done, we need to configure our client. I&#8217;m using GtkTerm on my laptop, although any terminal program should work (as long as it can use a serial port. On Windows, HyperTerminal should work). My laptop doesn&#8217;t have a serial port, so I&#8217;m using a USB to Serial adapter I bought off eBay (it creates a <tt>ttyUSB0</tt> device). Set your terminal program to these settings:</p>
<ul>
<li><b>Port (Linux):</b> <tt>ttyS0</tt> or <tt>ttyS1</tt> (if your system has a serial port), or <tt>ttyUSB0</tt> (if you&#8217;re using a USB to Serial converter).</li>
<li><b>Port (Windows):</b> COM1 or COM2 </li>
<li><b>Bits per second:</b> 38400</li>
<li><b>Data bits:</b> 8  </li>
<li><b>Parity: </b>None</li>
<li><b>Stop bits:</b> 1</li>
<li><b>Flow control:</b> None, although hardware (RTS/CTS) should work properly </li>
</ul>
<p>Restart the server (probably from a SSH connection, or however you edited the GRUB config above), and then connect the null modem cable as it&#8217;s starting (ie. at the BIOS screen). Press any key when prompted, and you&#8217;ll get something like: </p>
<p><img src='http://www.daniel15.com/blog/wp-content/uploads/2007/02/grub-resized.jpg' alt='Serial console howto - GRUB menu' /><br />
This means that GRUB is working fine <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Press enter, and it should boot, showing all messages in the terminal window. Once it boots, it will look something like:</p>
<p><img src='http://www.daniel15.com/blog/wp-content/uploads/2007/02/booted-resized.jpg' alt='Serial console howto - booted' /><br />
Finally, log in, and check that it works fine:</p>
<p><img src='http://www.daniel15.com/blog/wp-content/uploads/2007/02/loggedin-resized.jpg' alt='Serial console howto - Logged in' /><br />
 </p>
<p>Congratulations, everything is set up and working fine.</p>
<p>Hope you enjoyed this tutorial! <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://dan.cx/blog/2007/02/setting-up-a-serial-console-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restore MySQL dump (backup) using PHP</title>
		<link>http://dan.cx/blog/2006/12/restore-mysql-dump-using-php/</link>
		<comments>http://dan.cx/blog/2006/12/restore-mysql-dump-using-php/#comments</comments>
		<pubDate>Sat, 09 Dec 2006 01:03:28 +0000</pubDate>
		<dc:creator>Daniel15</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.daniel15.com/blog/2006/12/09/restore-mysql-dump-backup-using-php/</guid>
		<description><![CDATA[The other day, I was looking for an easy way to restore a MySQL dump (or backup, whatever you like to call it) in PHP. I&#8217;ve previously used a segment of the code from PHP MySQL Backup V 2.2 for this, but it didn&#8217;t seem to support FULLTEXT indicies that well. So, I searched around, [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, I was looking for an easy way to restore a MySQL dump (or backup, whatever you like to call it) in PHP. I&#8217;ve previously used a segment of the code from <a href="http://www.absoft-my.com/pondok/backup.php">PHP MySQL Backup V 2.2</a> for this, but it didn&#8217;t seem to support FULLTEXT indicies that well. So, I searched around, but couldn&#8217;t find anything. I even asked on the PHP IRC channel, and they suggested to use shell_exec to call mysql (unfortunately, I&#8217;ve disabled shell_exec for  security reasons). Looking closer, I noticed that this was actually quite easy to do. <span id="more-45"></span>Here&#8217;s the code I wrote to restore a phpMyAdmin MySQL dump (not sure if it works with mysqldump dumps):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #666666; font-style: italic;">/*
 * Restore MySQL dump using PHP
 * (c) 2006 Daniel15
 * Last Update: 9th December 2006
 * Version: 0.2
 * Edited: Cleaned up the code a bit. 
 *
 * Please feel free to use any part of this, but please give me some credit :-)
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Name of the file</span>
<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test.sql'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// MySQL host</span>
<span style="color: #000088;">$mysql_host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// MySQL username</span>
<span style="color: #000088;">$mysql_username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// MySQL password</span>
<span style="color: #000088;">$mysql_password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Database name</span>
<span style="color: #000088;">$mysql_database</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Connect to MySQL server</span>
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mysql_host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_password</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error connecting to MySQL server: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Select database</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mysql_database</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error selecting MySQL database: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Temporary variable, used to store current query</span>
<span style="color: #000088;">$templine</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Read in entire file</span>
<span style="color: #000088;">$lines</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Loop through each line</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Skip it if it's a comment</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'--'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$line</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Add this line to the current segment</span>
	<span style="color: #000088;">$templine</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$line</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// If it has a semicolon at the end, it's the end of the query</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">';'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Perform the query</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$templine</span><span style="color: #009900;">&#41;</span> or <span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error performing query \'&lt;strong&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$templine</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\': '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;&lt;br /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Reset temp variable to empty</span>
		<span style="color: #000088;">$templine</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>See? How easy is that? <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong>Update:</strong> This also works for mysqldump dumps <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dan.cx/blog/2006/12/restore-mysql-dump-using-php/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>Linux-Vserver on Debian Etch, the easy way</title>
		<link>http://dan.cx/blog/2006/11/linux-vserver-debian-etch/</link>
		<comments>http://dan.cx/blog/2006/11/linux-vserver-debian-etch/#comments</comments>
		<pubDate>Wed, 22 Nov 2006 05:31:56 +0000</pubDate>
		<dc:creator>Daniel15</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.daniel15.com/blog/2006/11/22/my-linux-vserver-tutorial-posted-on-howtoforge/</guid>
		<description><![CDATA[In this tutorial, I&#8217;ll show you how to install Linux-Vserver on Debian Testing (Etch), the easy way. This was the first tutorial I posted to HowtoForge.com, so please tell me if you like it or not. You may find it a bit verbose, as I try to explain things in enough detail so that everyone [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, I&#8217;ll show you how to install Linux-Vserver on Debian Testing (Etch), the easy way. This was the first tutorial I posted to HowtoForge.com, so please tell me if you like it or not. You may find it a bit verbose, as I try to explain things in enough detail so that everyone understands what I mean <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<p>What is Linux-Vserver, you ask? It&#8217;s simple. Basically, Linux-Vserver is an open-source system used to separate a single physical server into multiple virtual servers. From the Linux-Vserver website:</p>
<p>&#8220;Linux-VServer allows you to create virtual private servers and security contexts which operate like a normal Linux server, but allow many independent servers to be run simultaneously in one box at full speed. All services, such as ssh, mail, Web, and databases, can be started on such a VPS, without modification, just like on any real server. Each virtual server has its own user account database and root password and doesn&#8217;t interfere with other virtual servers.&#8221;</p>
<p><span id="more-42"></span></p>
<p>Two terms you will need to know are: </p>
<ul>
<li><b>Host System</b>: This is the main system (the physical server) which you install Linux-Vserver onto. </li>
<li><b>Guest System</b>: These are the virtual systems you create using the Linux-Vserver utilities. They run on top of the Host System, and are all isolated from each other. </li>
</ul>
<p>Most tutorials mention that you need to compile your own kernel in order to use Linux-Vserver. However, Debian Etch includes a Linux-Vserver kernel as standard, so you don&#8217;t need to compile it yourself. This has the advantage of being easier and faster to install, and it&#8217;s easy to keep up-to-date with security updates. </p>
</p>
<h4> First Steps</h4>
<p>The first thing you&#8217;ll need to do is have a system with a fresh installation of Debian Etch. To do so, download the Debian Testing CD from <a target="_blank" href="http://www.debian.org/">http://www.debian.org/</a>, and install the base system only. After you&#8217;ve installed the base system, the next step is to make sure that the repositories are enabled. Firstly, make sure you&#8217;re the superuser (the prompt is a <b>#</b>, not a <b>$</b>). If not, become the superuser (root):</p>
<p><pre><pre>$ su
#</pre></pre></p>
<p>Once you&#8217;re sure you&#8217;re root, we need to edit <tt>/etc/apt/sources.list</tt>: </p>
<p><pre># nano /etc/apt/sources.list</pre></p>
<p>Make sure a line similar to this is in the file:</p>
<p><tt>deb ftp://ftp.au.debian.org/debian etch main contrib non-free </tt></p>
<p>If it&#8217;s not, add it in. Press CTRL+O and hit ENTER to save the file, and then press CTRL+X to exit.<br />   After this, we need to update the package list, so type the following command:</p>
<p><tt># apt-get update </tt></p>
<h3>The Packages</h3>
<p>Now that we&#8217;ve updated the package list, the next step is to install all the required packages. The packages required by Linux-Vserver are: </p>
<ul>
<li><b>linux-image-vserver-686 </b>- This is the actual kernel</li>
<li><b>util-vserver</b> &#8211; These are the utilities used to administer the guests</li>
<li><b>vserver-debiantools </b>- These are special Vserver tools for Debian, used to create and duplicate Debian guest systems.</li>
<li><b>ssh</b> &#8211; This is probably already installed, but just in case it isn&#8217;t </li>
</ul>
<p>So, let&#8217;s install them:</p>
<p><tt> # apt-get install linux-image-vserver-686 util-vserver vserver-debiantools ssh</tt></p>
<p>Once that&#8217;s done, we need to reboot:</p>
<p><tt># reboot</tt></p>
<p>When the GRUB menu appears, make sure you choose the vserver kernel. Once your system boots, you&#8217;ll be running the new kernel. You may check this by running</p>
<p><pre><pre># uname -r
2.6.16-2-vserver-686</pre></pre></p>
<p>Notice how the output has &#8216;vserver&#8217; in it? This means you&#8217;re running the VServer kernel.</p>
<p>Guess what? That&#8217;s the <i>whole</i> installation!  Everything is now setup and ready to use <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . There&#8217;s one very important thing to do though: Create the guest systems. </p>
</p>
<h4>Creating a virtual server (guest) </h4>
<p>So, now that Linux-Vserver is set up and ready to use, we need to create a guest system. On a Debian system, you may do so using the <tt>newvserver</tt> command. The syntax of this command is:</p>
<p><pre><pre>newvserver --vsroot /var/lib/vservers/ --hostname [Hostname] \
 --domain [Domain] --ip [IP Address]/[CIDR Range] \
 --dist etch --mirror [Debian Mirror] --interface [Net Interface]</pre></pre>  </p>
<p><i>(the backslashes at the end of the lines mean that it continues onto the next line. You may copy it as-is [with the backslashes], or put the whole command on one line [and exclude the backslashes], as I do below) </i></p>
<p>The command line arguments are: </p>
<ul>
<li><b>vsroot</b> &#8211; This is where the files for the guests are kept. On a default installation, this will be at /var/lib/vservers. Alternatively, some people create a  separate partition for their vservers. </li>
<li><b>Hostname</b> &#8211; The hostname of the system (eg. test1) </li>
<li><b>Domain</b> &#8211; The domain of the system. This is usually the same as the domain you chose for the host system (eg. dan-network.local. This doesn&#8217;t need to be real, it&#8217;s only used internally.) </li>
<li><b>IP Address</b>- The IP address for the guest system (eg. 10.1.1.7)</li>
<li><b>CIDR Range </b>- The CIDR Range for your local network. For a 10.x.x.x network, this is usually /8. For a 172.16.x.x network, this is usually /16. For a 192.168.x.x network, this is usually /24. If your network is subnetted, this will be different. When in doubt, choose /8 <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li><b>Dist</b> &#8211;  The distribution to use. For the purposes of this exercise, we use etch.</li>
<li><b>Debian Mirror</b> &#8211; The Debian mirror you use (when in doubt, choose ftp://ftp.debian.org/debian) </li>
<li><b>Interface</b> &#8211; Your network interface, if it&#8217;s not eth0 (eg. eth1).</li>
</ul>
<p><span style="color: red">Note (added 5th July 2007): Some people were getting confused here. Usually, if your server is at a data centre and you have multiple public IP addresses, you should use one of your public IP addresses here (not an internal one). If the server is on a local network, use an internal IP address.</span></p>
<p>So, let&#8217;s make a test server. The settings for our test guest are like so:</p>
<ul>
<li>Hostname: test1</li>
<li>Domain: example.com</li>
<li>IP Address: 10.1.1.7</li>
<li>CIDR Range: /8</li>
<li>Debian Mirror: http://ftp.au.debian.org/debian/</li>
<li>Interface: eth1</li>
</ul>
<p>Let&#8217;s go!</p>
<p><tt># newvserver --vsroot /var/lib/vservers/ --hostname <i>test1</i> --domain example.com --ip <i>10.1.1.7/8</i> --dist etch --mirror <i>http://ftp.au.debian.org/debian/</i> --interface eth1 </tt></p>
<p>This will begin a Debian net install, which will only take a few minutes. Once the packages are all downloaded and installed, the Debian base setup will come up. This will prompt you for your time zone, and also ask for a root password. Once you&#8217;ve completed this, the VServer will be ready to use. </p>
</p>
<h4>Entering the guest</h4>
<p>OK, so we&#8217;ve set up the guest, now to do anything useful, we need to start the guest, and enter into its context. To do so, we use the &#8216;vserver&#8217; command. The basic syntax for it is:</p>
<p><tt>vserver &lt;name&gt; [start | stop | restart | enter] </tt></p>
<p>So, to start and enter the guest we created earlier, type the following:</p>
<p><tt>vserver test1 start; vserver test1 enter </tt></p>
<p>The output will be a bit like:</p>
<p><pre><pre>root@server1:/home/daniel# vserver test1 start; vserver test1 enter
Starting system log daemon: syslogd.
Starting internet superserver: no services enabled, inetd not started.
Starting periodic command scheduler....
test1:/#</pre></pre></p>
<p>   We&#8217;re now &#8216;inside&#8217; the virtual server. You can run any command you would normally run. Note that this is a <i>very </i>basic installation, so you should use apt to install whatever you want.</p>
<h4>Other Stuff</h4>
<p>This tutorial doesn&#8217;t cover everything, it&#8217;s only meant to be a guide on beginning to use Linux-Vserver. The rest is  up to your imagination&#8230; Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://dan.cx/blog/2006/11/linux-vserver-debian-etch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Laptop, Linux and Compiz</title>
		<link>http://dan.cx/blog/2006/09/laptop-linux-and-compiz/</link>
		<comments>http://dan.cx/blog/2006/09/laptop-linux-and-compiz/#comments</comments>
		<pubDate>Mon, 18 Sep 2006 10:19:35 +0000</pubDate>
		<dc:creator>Daniel15</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Laptop]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.daniel15.com/blog/2006/09/18/laptop-linux-and-compiz/</guid>
		<description><![CDATA[Update: Since I made this post in September 2006, things have changed. Compiz-Quinn has changed its name to Beryl, and up-to-date installation instructions are available for Ubuntu Edgy and Ubuntu Feisty Well, I got my laptop on Friday (15th September). I must say, the Inspiron 6400 was definately a good choice. The only thing I [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: red">Update: Since I made this post in September 2006, things have changed. Compiz-Quinn has changed its name to Beryl, and up-to-date installation instructions are available for <a href="http://wiki.beryl-project.org/wiki/Install_Beryl_on_Ubuntu_Edgy_with_XGL">Ubuntu Edgy</a> and <a href="http://wiki.beryl-project.org/wiki/Install_Beryl_on_Ubuntu_Feisty_with_XGL">Ubuntu Feisty</a></span></p>
<p>Well, I got my laptop on Friday (15th September). I must say, the Inspiron 6400 was definately a good choice. The only thing I don&#8217;t really like about it is the reflectiveness of the TrueLife screen, but I suppose I&#8217;ll get used to it (the colours are definately more vivid, and it has better contrast&#8230; The screen looks absolutely awesome when playing games!). Anyways, one of the first things I did was partition the drive, and install Ubuntu Linux <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Once I did this, the first thing I did was install i8kutils and Gkrellm (so that I could control the speed of the fan, to make sure it doesn&#8217;t overheat), and then install the ATI Drivers for the X1400 (called &#8216;FGLRX&#8217;). Everything was working excellently (see screenshot)<br />
<a class="imagelink" href="http://www.daniel15.com/blog/wp-content/uploads/2006/09/screenshot.jpg" title="Desktop screenshot"><img id="image19" src="http://www.daniel15.com/blog/wp-content/uploads/2006/09/screenshot.thumbnail.jpg" alt="Desktop screenshot"/></a></p>
<p>After everything was done, I thought about what to install. I remember my friend telling me about something called &#8216;Compiz&#8217;, but I couldn&#8217;t remember how to install it. After searching for a while, I found a nice <a href="http://www.compiz.net/topic-389-1.html">tutorial on installing GLX/Compiz</a>. It appeared to be quite easy to do, so I followed the instructions on the tutorial. And, it works perfectly! <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  It comes with heaps of themes, and there are some similar to the upcoming Windows Vista. Take a look at this:<br />
<a class="imagelink" href="http://www.daniel15.com/blog/wp-content/uploads/2006/09/screenshot-folder.jpg" title="Compiz screenshot 1"><img id="image21" src="http://www.daniel15.com/blog/wp-content/uploads/2006/09/screenshot-folder.thumbnail.jpg" alt="Compiz screenshot 1"/></a><br />
Look at the title bar of the &#8216;Home Directory&#8217; window. That&#8217;s called a &#8216;glass effect&#8217;, and is quite nice&#8230;</p>
<p>Another thing implemented in Compiz is window transparency: You can make a window semi-transparent. For example, look at this screenshot of my home directory on top of Opera (with the Google site open). I&#8217;ve faded the window out a bit, so it&#8217;s partially transparent:<br />
<a class="imagelink" href="http://www.daniel15.com/blog/wp-content/uploads/2006/09/transparency.jpg" title="Compiz screenshot 2 - transparency"><img id="image22" src="http://www.daniel15.com/blog/wp-content/uploads/2006/09/transparency.thumbnail.jpg" alt="Compiz screenshot 2 - transparency"/></a><br />
Nice, huh? Yet another thing in Compiz is multiple desktops. Sure, Linux has support for multiple workplaces in-built (the selector on the bottom-right hand side of Gnome). However, Compiz improves on it vastly, making all the virtual desktops into one large cube:<br />
<a class="imagelink" href="http://www.daniel15.com/blog/wp-content/uploads/2006/09/cube.jpg" title="Compiz screenshot 3 - Cube"><img id="image23" src="http://www.daniel15.com/blog/wp-content/uploads/2006/09/cube.thumbnail.jpg" alt="Compiz screenshot 3 - Cube"/></a><br />
I thought the cube was interesting, but something really interesting is if you run VMWare in fullscreen mode. You can make it appear as if you&#8217;re running multiple operating systems at once&#8230; Take a look:<br />
<a class="imagelink" href="http://www.daniel15.com/blog/wp-content/uploads/2006/09/vmware-2.jpg" title="Compiz screenshot 4 - VMWare"><img id="image24" src="http://www.daniel15.com/blog/wp-content/uploads/2006/09/vmware-2.thumbnail.jpg" alt="Compiz screenshot 4 - VMWare"/></a></p>
<p>In addition to all of this, Compiz has heaps of other effects which I couldn&#8217;t take screenshots of (including wobbly windows &#8211; windows wobble as you drag them, windows &#8216;zoom in&#8217; when you start a program, and &#8216;zoom out&#8217; when you exit it, and a lot more)&#8230; If you&#8217;d like to get Compiz working, and have an ATI graphics card, first get the ATI Linux drivers (FGLRX) working (see <a href="http://wiki.cchtml.com/index.php/Ubuntu_Dapper_Installation_Guide">http://wiki.cchtml.com/index.php/Ubuntu_Dapper_Installation_Guide</a> for a tutorial. Make sure you follow the second bit of the tutorial, to install version 8.28.8). Then, follow the Compiz tutorial, as found at <a href="http://www.compiz.net/topic-389-1.html">http://www.compiz.net/topic-389-1.html</a> (I followed the second howto, as I personally think it&#8217;s better to have Compiz as a seperate session&#8230; Have fun! <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anyways, I think this is probably the longest blog post I&#8217;ve written, ever <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dan.cx/blog/2006/09/laptop-linux-and-compiz/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Server broken :(</title>
		<link>http://dan.cx/blog/2006/06/server-broken/</link>
		<comments>http://dan.cx/blog/2006/06/server-broken/#comments</comments>
		<pubDate>Thu, 29 Jun 2006 11:51:19 +0000</pubDate>
		<dc:creator>Daniel15</dc:creator>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.daniel15.com/blog/2006/06/30/server-broken/</guid>
		<description><![CDATA[Well, I was working on my Linux testing server, and it stopped working for some reason&#8230; I tried to restart, but the computer wouldn&#8217;t even boot (even from a CD). Upon unplugging all the IDE devices, and only leaving a CD drive in (a different one, in case it was faulty for whatever reason), it [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I was working on my Linux testing server, and it stopped working for some reason&#8230; I tried to restart, but the computer wouldn&#8217;t even boot (even from a CD). Upon unplugging all the IDE devices, and only leaving a CD drive in (a different one, in case it was faulty for whatever reason), it still wouldn&#8217;t boot <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> . I guess I won&#8217;t be using that for a while&#8230;</p>
<p>Anyways, I&#8217;m <a href="http://cgi.ebay.com.au/ws/eBayISAPI.dll?ViewItem&#038;item=260000403990">buying a new server on eBay</a>, so it isn&#8217;t that bad (all I need to do is wait for it to get shipped to me).</p>
<p>Old server:</p>
<ul>
<li>Celeron 300 MHz</li>
<li>4.3GB Quantum Fireball lct and 4.3GB Seagate hard drives</li>
<li>48X CD-ROM drive</li>
<li>192MB membory</li>
</ul>
<p>New server:</p>
<ul>
<li>Pentium III 650 MHz</li>
<li>8.4 GB hard drive</li>
<li>48X CD-ROM drive</li>
<li>256MB membory</li>
</ul>
<p>Don&#8217;t say that it isn&#8217;t that powerful&#8230; Linux makes <em>any computer</em> look powerful <img src='http://dan.cx/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . Besides, it&#8217;s only a server for testing stuff.</p>
<p>EDIT: Computer arrived today, 30th June 2006. That company on eBay was quick!</p>
]]></content:encoded>
			<wfw:commentRss>http://dan.cx/blog/2006/06/server-broken/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
