<?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>MagicalTux in Japan &#187; PHP</title>
	<atom:link href="http://blog.magicaltux.net/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.magicaltux.net</link>
	<description>Geekness brought me to Japan!</description>
	<lastBuildDate>Mon, 26 Jul 2010 21:31:16 +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>PHP can do anything, what about some ssh?</title>
		<link>http://blog.magicaltux.net/2010/06/27/php-can-do-anything-what-about-some-ssh/</link>
		<comments>http://blog.magicaltux.net/2010/06/27/php-can-do-anything-what-about-some-ssh/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 07:06:36 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[gmp]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[pinetd2]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=501</guid>
		<description><![CDATA[Last time I already tried to prove PHP can do anything when it comes to network protocols by implementing a DNS server. This time I&#8217;m doing it again with a server-side implementation of the SSH2 protocol. You probably know SSH at least by its name. It&#8217;s a of secure telnet replacement which also allows many [...]]]></description>
			<content:encoded><![CDATA[<p>Last time I already tried to prove PHP can do anything when it comes to network protocols by <a href="http://blog.magicaltux.net/2009/02/16/php-dns-daemon/">implementing a DNS server</a>. This time I&#8217;m doing it again with a server-side implementation of the SSH2 protocol.</p>
<p>You probably know SSH at least by its name. It&#8217;s a of secure telnet replacement which also allows many other things such as port forwarding, remote file management (with sftp) and more.</p>
<p>With PHP I could write a fully working SSH server in only 3 days. Of course I didn&#8217;t implement every single extension there is to SSH, but I&#8217;ve implemented:</p>
<ul>
<li>SSH2 protocol only (no SSH1, anyway who uses that anymore?)</li>
<li>Encryption protocols: aes128-cbc,blowfish-cbc,serpent256-cbc,cast128-cbc,3des-cbc (via <a href="http://php.net/mcrypt">mcrypt</a>)</li>
<li>Message digests: hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96 (via <a href="http://php.net/hash">hash</a>)</li>
<li>No compression as I cannot easily keep a compression context active (the gzip extension in php is missing a way to create a compression context)</li>
<li>Password and public key (ssh-dss and ssh-rsa) identification</li>
<li>Ability to program an interactive shell in PHP (there are send and recv functions in a separate class, anyone can have some fun and write something out of that. Should be possible to make a wrapper to communicate with a shell launched with proc_open)</li>
<li>Support for multiple channels</li>
<li>SFTP subsystem</li>
<li>Can be easily extended to add support for custom channels or re-use the ssh protocol for something else</li>
</ul>
<p>My goal when writing this was to provide a replacement for the FTP protocol for the customers of <a href="http://www.kalyhost.com/">my hosting service</a>. FTP has many drawbacks, including no encryption (you can with ftps or ftpes) and the way ftp transmits data (another connection has to be opened on a different port, leading most of the time to some problems for people behind a NAT and/or firewalled servers).</p>
<p>With this ssh server supporting sftp, I finally got the replacement I was looking for. Of course it uses more CPU than a C ssh server (about 3 times more) but the difference isn&#8217;t that big. Next steps will include fork()&#8217;ing to open channels (will allow the SFTP server to chroot) and maybe support for some SSH extensions.</p>
<p>To implement the SSH protocol the following PHP extensions were used:</p>
<ul>
<li><strong>OpenSSL</strong>: used to generate secure bits when negociating the key, and used to generate the host signature on connection. I was hoping to use openssl_verify() to verify the key used when logging in, but I couldn&#8217;t manage to convert the ssh-rsa key to something openssl would understand, so I re-implemented signature verification with gmp.</li>
<li><strong>MCrypt</strong>: The ssh protocol is encrypted (usually with something like AES128). mcrypt has the required functions to handle encryption in block mode</li>
<li><strong>Hash</strong>: each packet transmitted over SSH is optionally signed with a HMAC signature. In order to generate and verify those signatures I used hash_hmac()</li>
<li>And finally the most important: <strong>GMP</strong>. As I was missing some functions to properly handle the initial Diffie-Hellman key exchange (and later to implement publickey authentication) I had to re-implement those in PHP. Of course working with 1024 bits integers is not something we can use the native int type for. GMP (and bc) allows such calculations (and I used them). I was missing the ability in gmp to read from/convert to binary values, so I had to add the use of bin2hex() and pack(&#8216;H*&#8217;, &#8230;) to be able to work with binary values easily. GMP computations are only used when negociating keys (the ssh rfc recommands doing this once an hour, or every gigabyte of data transmitted) or when using the publickey authentification.</li>
</ul>
<p>What did I create a ssh server for? The same thing I created a DNS server for fun and for <a href="http://www.kalyhost.com/" target="_blank">KalyHost</a>. In order to provide services updated in realtime I wrote a database-backed dns server a while ago, and now a ssh server (which can be database-backed too by extending the &#8220;Base&#8221; class).</p>
<p>The sourcecode can be downloaded from the SVN: <a href="http://ookoo.org/svn/pinetd2/trunk/code/classes/Daemon/SSHd/">http://ookoo.org/svn/pinetd2/trunk/code/classes/Daemon/SSHd/</a> this depends on <a href="http://www.pinetd.com/">pinetd2</a>, a framework I wrote which allows to easily create daemons in PHP, and which I already used to create various things (FTP, Mail server, etc).</p>
<p>People willing to help on pinetd2 (code and/or documentation) are welcome. If you do not mind being called crazy because you make something else than webpages in PHP, you can contact me <a href="mailto:mark@hell.ne.jp">by mail</a> or <a href="irc://irc.gg.st/php">on IRC</a> (or by leaving a comment on this post too if you wish to).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2010/06/27/php-can-do-anything-what-about-some-ssh/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>SimpleDNSd: new features &amp; bugfix</title>
		<link>http://blog.magicaltux.net/2010/03/19/simplednsd-new-features-bugfix/</link>
		<comments>http://blog.magicaltux.net/2010/03/19/simplednsd-new-features-bugfix/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 00:24:42 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[KalyHost]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[pinetd2]]></category>
		<category><![CDATA[PZC]]></category>
		<category><![CDATA[SimpleDNSd]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=462</guid>
		<description><![CDATA[Anyone using SimpleDNSd is strongly encouraged to update to latest SVN (you will have to erase the php-5.3.1 directory and recompile php to get it patched correctly). The current SVN version will most likely go release candidate and be released later. Current SVN release includes many fixes and improvements, including for SimpleDNSd, the DNS daemon [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone using SimpleDNSd is strongly encouraged to update to <a href="https://ookoo.org/svn/pinetd2/trunk/" target="_blank">latest SVN</a> (you will have to erase the php-5.3.1 directory and recompile php to get it patched correctly). The current SVN version will most likely go release candidate and be released later.</p>
<p>Current SVN release includes many fixes and improvements, including for SimpleDNSd, the DNS daemon written in PHP.</p>
<p>This includes:</p>
<ul>
<li>Support for delegation-only zones: it is now possible to handle TLDs via SimpleDNSd. I did a test by adding &#8220;free&#8221; domain names to the <a href="https://www.kalyhost.com/" target="_blank">KalyHost</a> service. Those domains can be ordered for free, and a webinterface is made available to control the domain DNS, allowing you to test SimpleDNSd and see how easily changes are done in realtime.</li>
<li>Support for PHP new requested feature (<a href="http://bugs.php.net/51295" target="_blank">PHP bugreport #51295</a>): queries to the DNS daemon were failing or returning wrong data randomly because of this bug. It took me a while to point this out as it was rather random. Basically current PHP implementation of SQLite3 has no &#8220;busy timeout&#8221;, meaning requests will fail immediatly if database is busy.<br />
I had to add a busyTimeout() method in SQLite3 (similar to the one already existing for the old sqlite PHP extension) and use it. This means we&#8217;ll have to wait for this patch to be added to a current PHP release before pinetd2 can be released as stable.</li>
<li>PZC: &#8220;Progressive Zone Change&#8221;. This is one feature no other DNS daemon has (or maybe they do, I don&#8217;t know). This feature allows to schedule change of a domain to a new zone. When the scheduled time comes closer, the DNSd will send expiration time smaller and smaller to make records expire on the time the zone will change.</li>
</ul>
<p><strong>A bit more about PZC:</strong><br />
Let&#8217;s say we have domain &#8220;example.com&#8221; pointing to zone A. Calling API method <em>domainPzc(&#8216;example.com&#8217;, &#8216;B&#8217;, time()+86400);</em> will make domain example.com pointing to zone B in 24 hours. In the meantime, no returned record will expire after the scheduled time for zone change: any record obtained 15 seconds before zonechange will be marked to expire in 15 seconds.<br />
This features allow a really precise control of &#8220;DNS Propagation&#8221;: you decide exactly when zone change will happen. Note that if you have a record in your zone expiring in 3 days, you shouldn&#8217;t schedule zone changes less than 3 days before effective date, or it might not have the expected behaviour.</p>
<p>As far as I know, no other DNS server support such a feature allowing to switch to a different zone with full control of when it will &#8220;propagate&#8221;.</p>
<p>(I know some resolvers out there will not follow expiration times given by the authoritative DNS server, however I like to think those are only a minority, and that PZC will give the expected behaviour for almost everyone)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2010/03/19/simplednsd-new-features-bugfix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PInetd2: New launcher</title>
		<link>http://blog.magicaltux.net/2009/12/22/pinetd2-new-launcher/</link>
		<comments>http://blog.magicaltux.net/2009/12/22/pinetd2-new-launcher/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 14:18:27 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[Geek Attitude]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PInetd]]></category>
		<category><![CDATA[pinetd2]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=405</guid>
		<description><![CDATA[PInetd2 is closing to release with the addition of two elements, a new launcher, and logs. The new launcher is the first step toward the ability to dynamically start and stop subprocesses without restarting the whole daemon. The old &#8220;start.sh&#8221; has been replaced with a &#8220;daemonctl&#8221; tool, like in the old pinetd. This allows to [...]]]></description>
			<content:encoded><![CDATA[<p>PInetd2 is closing to release with the addition of two elements, a new launcher, and logs.</p>
<p>The new launcher is the first step toward the ability to dynamically start and stop subprocesses without restarting the whole daemon. The old &#8220;start.sh&#8221; has been replaced with a &#8220;daemonctl&#8221; tool, like in the old pinetd. This allows to start pinetd2 in the background (if forking is enabled), see processes status, and stop/restart the daemon directly. However since daemon can now be started in background, another feature was needed, which is&#8230;</p>
<p>Logging to a file</p>
<p>Of course, the whole system was made to centralize logs. Each child transmits logs via IPC to its parent, and the main launcher display logs on screen. It wasn&#8217;t difficult from there to write logs to a file. This means that even a FTP client chrooted somewhere can still send log events to its parent and get them written to the main logfile.</p>
<p>What&#8217;s next?</p>
<p>Now, I need to make those two elements less hack-like (ie. add some config options, add ability to log to syslog, etc), then I&#8217;ll have to finalize PMaild&#8217;s IMAP daemon thanks to the fact I added mailparse to the required elements in the PHP distribution. MailParse will handle the difficult mime-decoding part, and will make the next steps much easier. Parsed data will be cached in database (one new table per domain), and this should finally makes PMaild usable in imap-based webmails like Horde IMP.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2009/12/22/pinetd2-new-launcher/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PInetd old-stable officially no longer supported</title>
		<link>http://blog.magicaltux.net/2009/09/29/pinetd-old-stable-officially-no-longer-supported/</link>
		<comments>http://blog.magicaltux.net/2009/09/29/pinetd-old-stable-officially-no-longer-supported/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 01:37:20 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[Geek Attitude]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PInetd]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=374</guid>
		<description><![CDATA[While the PHP team is currently working hard getting PHP 5.3 stable, I can officially announce that PInetd&#8217;s old branch is no longer supported. All efforts will be put on pinetd2 with its new framework, and improvements required to support transports. A new pinetd branch will eventually be launched with a complete rewrite of the [...]]]></description>
			<content:encoded><![CDATA[<p>While the PHP team is currently working hard getting PHP 5.3 stable, I can officially announce that PInetd&#8217;s old branch is no longer supported.</p>
<p>All efforts will be put on pinetd2 with its new framework, and improvements required to support transports.</p>
<p>A new pinetd branch will eventually be launched with a complete rewrite of the IPC subsystem (which has become too complex with the different new features added along the line). New branch will most likely be named 2.1.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2009/09/29/pinetd-old-stable-officially-no-longer-supported/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Striving for a better world</title>
		<link>http://blog.magicaltux.net/2009/09/19/striving-for-a-better-world/</link>
		<comments>http://blog.magicaltux.net/2009/09/19/striving-for-a-better-world/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 05:39:23 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[IRL]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[MFW]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=362</guid>
		<description><![CDATA[I believe everyone on this earth is striving for a better world. For developpers this could be achieved with a perfect framework. Of course normal frameworks are a no-go. Using someone else&#8217;s framework will make your world slightly better, but until you create your own full framework, you won&#8217;t understand what I mean. The next [...]]]></description>
			<content:encoded><![CDATA[<p>I believe everyone on this earth is striving for a better world. For developpers this could be achieved with a perfect framework.</p>
<p>Of course normal frameworks are a no-go. Using someone else&#8217;s framework will make your world slightly better, but until you create your own full framework, you won&#8217;t understand what I mean.</p>
<p>The next step is to build applications with your framework. The kind of applications that will change the world&#8230;</p>
<p><em>The rest is up to you&#8230;</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2009/09/19/striving-for-a-better-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVN error 200030 &#8211; It&#8217;s PHP&#8217;s fault!</title>
		<link>http://blog.magicaltux.net/2009/08/06/svn-error-200030-its-phps-fault/</link>
		<comments>http://blog.magicaltux.net/2009/08/06/svn-error-200030-its-phps-fault/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 06:50:16 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[Geek Attitude]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=299</guid>
		<description><![CDATA[If you updated to SVN 1.6.x and created a new repository in the new SVN format (which uses SQLite), you probably found that you were getting an XML error that says: &#60;m:human-readable errcode="200030"&#62; Could not open the requested SVN filesystem &#60;/m:human-readable&#62; After some searches I found someone who had the same problem, and fixed it. [...]]]></description>
			<content:encoded><![CDATA[<p>If you updated to SVN 1.6.x and created a new repository in the new SVN format (which uses SQLite), you probably found that you were getting an XML error that says:</p>
<pre>&lt;m:human-readable errcode="200030"&gt;
Could not open the requested SVN filesystem
&lt;/m:human-readable&gt;</pre>
<p>After some searches I found <a href="http://l-w-i.net/t/subversion/dav_100.txt" target="_blank">someone who had the same problem</a>, and fixed it. Basically the problem is due to the SQLite version embed into PHP 5.2.x. PHP includes SQLite 3.3.7 while SVN will usually depend on 3.6.15 (or whatever you have on your system).</p>
<p>To fix this problem you have various solutions:</p>
<ul>
<li>Disable PHP as did our japanese friend</li>
<li>Upgrade SQLite version provided with php, or tell php to use system&#8217;s SQLite with &#8211;with-sqlite=/usr</li>
<li>Create your svn repository with &#8211;pre-1.6-compatible</li>
</ul>
<p>Hope this article will help all those who, like me, got the error 200030 with SVN without understanding much where it comes from.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2009/08/06/svn-error-200030-its-phps-fault/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Yahoo going closer to Microsoft, Rasmus&#8217; reaction</title>
		<link>http://blog.magicaltux.net/2009/07/29/yahoo-going-closer-to-microsoft-rasmus-reaction/</link>
		<comments>http://blog.magicaltux.net/2009/07/29/yahoo-going-closer-to-microsoft-rasmus-reaction/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 12:33:59 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Yahoo!]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=289</guid>
		<description><![CDATA[We got a press release from Yahoo saying that Yahoo! and Microsoft are going to share search/advertizing. In fact only the first paragraph seems of any interest, the rest of the press release is mostly marketting bullshit. Yahoo! and Microsoft announced an agreement that will improve the Web search experience for users and advertisers, and [...]]]></description>
			<content:encoded><![CDATA[<p>We got <a href="http://yhoo.client.shareholder.com/press/releasedetail.cfm?ReleaseID=399702" target="_blank">a press release from Yahoo</a> saying that Yahoo! and Microsoft are going to share search/advertizing. In fact only the first paragraph seems of any interest, the rest of the press release is mostly marketting bullshit.</p>
<blockquote><p>Yahoo! and Microsoft announced an agreement that will improve the Web        search experience for users and advertisers, and deliver sustained        innovation to the industry. In simple terms, Microsoft will now power        Yahoo! search while Yahoo! will become the exclusive worldwide        relationship sales force for both companies&#8217; premium search advertisers.</p></blockquote>
<p>This sounds rather awful, and <a href="http://twitter.com/rasmus/status/2908526145" target="_blank">reply from Rasmus</a> was quick.</p>
<p><a href="http://twitter.com/rasmus/status/2908526145"><img class="alignnone size-full wp-image-290" title="Rasmus announces he wants to leave..." src="http://blog.magicaltux.net/wp-content/uploads/2009/07/rasmus_yahoo.png" alt="Rasmus announces he wants to leave..." width="490" height="286" /></a></p>
<p>Of course I immediatly tried to confirm this on IRC&#8230;</p>
<pre>[21:20:51] &lt;MagicalTu&gt; http://twitter.com/rasmus/status/2908526145 &lt;- wtf ?
[21:21:21] &lt;Rasmus&gt; See the Microsoft-Yahoo press release</pre>
<p>So now, we&#8217;ll see how it evolves, but I guess this press conference will change a lot of things, including in PHP&#8217;s world.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2009/07/29/yahoo-going-closer-to-microsoft-rasmus-reaction/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Your own PHP DNS daemon</title>
		<link>http://blog.magicaltux.net/2009/02/19/your-own-php-dns-daemon/</link>
		<comments>http://blog.magicaltux.net/2009/02/19/your-own-php-dns-daemon/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 09:26:13 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[DNSd]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[PInetd]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=245</guid>
		<description><![CDATA[After my initial announcement of a PHP DNS Daemon, and some performance tests, and since it has been widely reported over internet (Zend DevZone, and today on Nexen which is deeply involved with French php community), I finally found the strength to write a guide on &#8220;how to get started with DNSd&#8221;. Basically, you&#8217;ll need [...]]]></description>
			<content:encoded><![CDATA[<p>After my <a href="http://blog.magicaltux.net/2009/02/16/php-dns-daemon/" target="_blank">initial announcement of a PHP DNS Daemon</a>, and <a href="http://blog.magicaltux.net/2009/02/18/php-dns-daemon-performances/" target="_blank">some performance tests</a>, and since it has been widely reported over internet (<a href="http://devzone.zend.com/" target="_blank">Zend DevZone</a>, and today on <a href="http://www.nexen.net/" target="_blank">Nexen</a> which is deeply involved with French php community), I finally found the strength to write a guide on &#8220;how to get started with DNSd&#8221;.</p>
<p>Basically, you&#8217;ll need subversion, gcc, make and most prerequisites for PHP (ICU, etc). This supposed you already have some knowledge in system administration.</p>
<p>The first step will be to fetch the latest SVN code somewhere in your Linux box (I usually put that in /usr/local).</p>
<pre>$ cd /usr/local
$ svn co http://ookoo.org/svn/pinetd2/trunk pinetd2
(checkout lines)
$ cd pinetd2/php
$ ./do_php.sh
(will download &amp; compile PHP 5.3.0, and maybe complain about missing stuff,
 just install whatever is missing, if you need help, post the last error
 lines here or <a href="mailto:mark@hell.ne.jp">contact me</a>)
$ cd ..
$ ./start.sh
Please edit config.xml and remove the line containing this text</pre>
<p>Arrived at this point, a file config.xml has been created and needs to be edited. I added comments inside it to help you. You&#8217;ll need to do a few things:</p>
<ol>
<li>Remove the &lt;RemoveMe&gt; tag, and edit the &lt;Name&gt; tag to include your machine&#8217;s name.</li>
<li>Change the storage engine to use SQLite3. PInetd&#8217;s MySQL driver is not compatible yet with DNSd. You can copy the line from the example, but remember that if your zone file is in /tmp, it might get erased at startup (depends on your linux distribution).</li>
<li>There is an empty &lt;DNSd&gt; tag, fill it with the second choice in the comment (the &lt;PeersArray&gt; one). Change the Signature, peer name, etc to fit your needs for the Type=&#8221;control&#8221; line : this is the definition of &#8220;who will be able to create/remove records on this DNS server&#8221;.</li>
<li>At the end of the file, remove all processes that do not have Daemon=&#8221;DNSd&#8221;. There sould only be 3 remaining processes.<br />
If you are not root, set PortOffset to an arbitrary value greater than 1024, like for example 10000.</li>
</ol>
<p>Once you&#8217;ve reached this point, you should be ready to go. Try starting the daemon.</p>
<pre>[2009-02-19 10:10:33:30945] DEBUG: pinetd v2.0.0alpha running on...
[2009-02-19 10:10:33:30945] WARN: SUID security level is defined...
[2009-02-19 10:10:33:30945] WARN: Warning: Chroot security level...
[2009-02-19 10:10:33:30945] DEBUG: My name: localhost
[2009-02-19 10:10:33:30947] INFO: Loading Daemon\DNSd\UDP on port 10053, bound to ip 127.0.0.1
[2009-02-19 10:10:33:30948] INFO: Loading Daemon\DNSd\TCP on port 10053, bound to ip 127.0.0.1
[2009-02-19 10:10:33:30949] INFO: Loading process Daemon\DNSd\Process</pre>
<p>As you can see, I am not root, so PInetd will complain about the impossibility of chroot()ing or setuid()ing, however it&#8217;s just for testing, so we don&#8217;t really care.</p>
<p>At this point, if you configured the DNS daemon like me with a PortOffset of 10000, with a peer named &#8220;MyPeer&#8221; and a secret of &#8220;qwerty&#8221;, running &#8220;dnsd_test.php&#8221; in the &#8220;test&#8221; directory will create an &#8220;example.com&#8221; domain.</p>
<pre>$ php dnsd_test.php
Connected to localhost</pre>
<p>Now, you can test it:</p>
<pre>$ dig +short -p10053 @localhost example.com
127.0.0.1</pre>
<p>Of course the PHP DNS Daemon is not completed yet (fixed a potential denial of service yesterday) and probably still have many bugs, so I strongly advice against using it on any production system yet.<br />
Yes, I am using it for this blog, and for another ~200 domains, to find bugs and make the solution more stable, however if you wish to contribute by testing on a production system too, make sure you are ready to have all your websites becoming down and your server taking fire.</p>
<p>The next step for you is to look in test directory at the &#8220;dnsd_test.php&#8221; script, and make your own pages using DNSd. You <em>do not</em> need to use PHP 5.3.0 to use this class, so you can basically use it anywhere. PHP 5.3.0 is only required for the DNS daemon itself.</p>
<p>If you have any question, feel free to leave a comment, I&#8217;ll try to complete this article as problems are raised by people who use this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2009/02/19/your-own-php-dns-daemon/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>PHP DNS Daemon: performances</title>
		<link>http://blog.magicaltux.net/2009/02/18/php-dns-daemon-performances/</link>
		<comments>http://blog.magicaltux.net/2009/02/18/php-dns-daemon-performances/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 06:23:46 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[DNSd]]></category>
		<category><![CDATA[PInetd]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=239</guid>
		<description><![CDATA[Many people seems to have taken interest into my weird idea to write a PHP DNS daemon in PHP, so I decided to run some experiments. The first one was to setup ~200 domains to this dns server (including my blog&#8217;s one), the second one is to run queryperf against it, and against bind9 running [...]]]></description>
			<content:encoded><![CDATA[<p>Many people seems to have taken interest into my weird idea to write a PHP DNS daemon in PHP, so I decided to run some experiments. The first one was to setup ~200 domains to this dns server (including my blog&#8217;s one), the second one is to run queryperf against it, and against bind9 running on the same host, with the same configuration (ie. same domain list, no recursion, etc).</p>
<h3>First, the host:</h3>
<ul>
<li>CPU: 2x Intel Xeon E5405 (2GHz) ; a total of 8 cores</li>
<li>RAM: 8GB RAM (4x 2GB DDR2 @667Mhz)</li>
<li>Hard Disk: 2x1TB HDD (RAID 1, 3ware Inc 7xxx/8xxx-series PATA/SATA-RAID) ; total of 1TB usable</li>
<li>OS: Linux Gentoo 64bits 2008.0 (multilib) with Linux Kernel 2.6.27-gentoo-r2</li>
</ul>
<p>The test itself will be a 1 million random queries generated by <em>gen-data-queryperf.py</em> with 40% of random domains.</p>
<h3>Some words on results</h3>
<p>First, I&#8217;d like to say that pinetd2 is still under development, some parts are still not implemented (the DNS server is able to act as a DNS server, that&#8217;s the important part for me), and also some optimizations weren&#8217;t done yet (for example a query will always cause the same SQL statements to be run, I could prepare those).<br />
The fact I&#8217;m running SQLite means the SQL server isn&#8217;t able to cache results (the db file might be modified by anyone, anytime, however I don&#8217;t know the exact internals of SQLite), and I don&#8217;t cache anything either.</p>
<p>When I started writing DNSd, I didn&#8217;t especially try to go on performances, features were importants, and realtime was too. Many improvements to speed can still be done (I&#8217;m thinking &#8220;prepared statments&#8221; right now, but also caching domains list, etc) and would help to get those numbers closer to ISC BIND.</p>
<p>The fact DNSd is 1/4 the speed of BIND (2531.89 queries/sec instead of 10071.2 queries/seq, my dns server is runnnin at 25.14% the speed of bind) is <em>impressive</em>. I guess we&#8217;ll need more tests, with different backends (MySQL is also supported, in theory) and different hosts, but I was supposing the database overhead would be bigger than that (well, SQLite is fast, but I wasn&#8217;t expecting that fast).</p>
<p>To tell you the truth, I am <em>surprised</em> by those results, however these are results on a real host, really running domains (like my blog&#8217;s domain), which makes me believe those results are the closest I could get from DNSd performances on a real host.</p>
<p>Now, the raw test results with both bind and PHP DNSd, running from the same host (to avoid network latency, and since I got 8 cores with almost no CPU usage as it&#8217;s morning in France, it shouldn&#8217;t make a big difference).</p>
<p>Other test results with other hardwares are welcome. I&#8217;ll try running the same kind of tests on less powerful hardware too, just to see what I get.</p>
<h3><span id="more-239"></span>ISC BIND 9.6.0-P1</h3>
<pre>DNS Query Performance Testing Tool
Version: $Id: queryperf.c,v 1.12 2007/09/05 07:36:04 marka Exp $</pre>
<pre>[Status] Processing input data
[Status] Sending queries (beginning with 91.121.45.45)
[Status] Testing complete</pre>
<pre>Statistics:</pre>
<pre>  Parse input file:     once
  Ended due to:         reaching end of file</pre>
<pre>  Queries sent:         1000000 queries
  Queries completed:    1000000 queries
  Queries lost:         0 queries
  Queries delayed(?):   0 queries</pre>
<pre>  RTT max:         	0.605333 sec
  RTT min:              0.000035 sec
  RTT average:          0.001974 sec
  RTT std deviation:    0.002666 sec
  RTT out of range:     0 queries</pre>
<pre>  Percentage completed: 100.00%
  Percentage lost:        0.00%</pre>
<pre>  Started at:           Wed Feb 18 06:36:21 2009
  Finished at:          Wed Feb 18 06:38:00 2009
  Ran for:              99.293069 seconds</pre>
<pre>  Queries per second:   10071.196409 qps</pre>
<h3>PHP DNSd (revision 301) with PHP 5.3.0beta1 and SQLite3 (bundled libsqlite)</h3>
<pre>DNS Query Performance Testing Tool
Version: $Id: queryperf.c,v 1.12 2007/09/05 07:36:04 marka Exp $</pre>
<pre>[Status] Processing input data
[Status] Sending queries (beginning with 87.98.170.177)
[Status] Testing complete</pre>
<pre>Statistics:</pre>
<pre>  Parse input file:     once
  Ended due to:         reaching end of file</pre>
<pre>  Queries sent:         1000000 queries
  Queries completed:    1000000 queries
  Queries lost:         0 queries
  Queries delayed(?):   0 queries</pre>
<pre>  RTT max:         	0.645355 sec
  RTT min:              0.000036 sec
  RTT average:          0.007884 sec
  RTT std deviation:    0.004824 sec
  RTT out of range:     0 queries</pre>
<pre>  Percentage completed: 100.00%
  Percentage lost:        0.00%</pre>
<pre>  Started at:           Wed Feb 18 06:38:41 2009
  Finished at:          Wed Feb 18 06:45:16 2009
  Ran for:              394.961920 seconds</pre>
<pre>  Queries per second:   2531.889657 qps</pre>
<h3>One (or more) last word(s)</h3>
<p>The test method is inspired from a link given by <a href="http://om4.com.au/" target="_blank">James Collins</a>: &#8220;<a href="http://www.generic-nic.net/sheets/practical/nameserver-en" target="_blank">the choices for a nameserver</a>&#8220;. While comparison can&#8217;t be done between the results there and mine (bind&#8217;s result are similar, but as said, there were problems with PowerDNS and anyway we are not running in the same conditions) it still looks like I got some chances into getting closer to be a &#8220;real&#8221; dns server, with PHP code!</p>
<p>Anyway, remember that &#8220;t<span class="quote">here are two sort of lies, lies and benchmarks.</span>&#8221; (source: the previous document).</p>
<p>Now, I guess I have no other choice than writing documentation about &#8220;how to install DNSd&#8221; and &#8220;how to setup a DNSd slave&#8221;, that&#8217;s going to be fun (if anyone can help, I&#8217;d be happy, got a public wiki where the doc can be publied).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2009/02/18/php-dns-daemon-performances/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>PHP DNS Daemon</title>
		<link>http://blog.magicaltux.net/2009/02/16/php-dns-daemon/</link>
		<comments>http://blog.magicaltux.net/2009/02/16/php-dns-daemon/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 04:58:32 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[DNSd]]></category>
		<category><![CDATA[PInetd]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=233</guid>
		<description><![CDATA[As the subject suggests, I just wrote an opensource DNS daemon in PHP. I already know what any sane person is thinking right now: [18:25:06] &#60;Derick&#62; MT`AwAy: you&#8217;re mad Now that it&#8217;s said, let&#8217;s move on ; if you want to tell me I&#8217;m crazy, you can post it in a comment here, it makes [...]]]></description>
			<content:encoded><![CDATA[<p>As the subject suggests, I just wrote an opensource DNS daemon in PHP. I already know what any sane person is thinking right now:</p>
<blockquote><p>[18:25:06] &lt;Derick&gt; MT`AwAy: you&#8217;re mad</p></blockquote>
<p>Now that it&#8217;s said, let&#8217;s move on ; if you want to tell me I&#8217;m crazy, you can post it in a comment here, it makes me happy. I had some reasons to dislike bind9 which finally made me write my own DNS daemon, and I&#8217;ll explain that here.</p>
<p>My need was to have a stable dynamic DNS server working in most environnements, with an easy to configure master/slave relationship (with realtime synchronisation), and a way to change records instantly from PHP&#8230;</p>
<p>For those who already played with bind9, there&#8217;s a feature called dlz which basically allows to ask bind to get data from an SQL server. I could just configure another MySQL per slave, and put replication there, but it&#8217;s not that fast and I had some stability issues (both with MySQL replication, and with bind crashing in some weird cases).</p>
<p>So, instead of trying to fix bind9&#8242;s code (which would also include fixing MySQL replication &#8211; or trying newer MySQL&#8217;s row-based replication) or searching for another solution (there are zillions of dns servers around there, but they all have features I&#8217;ll never need), I decided to write my own DNS server (built on top of <a href="http://www.pinetd.net/" target="_blank">PInetd</a>, my PHP networking framework for PHP 5.3.0), with only the features I needed.</p>
<p>So here are some of the features of this DNS daemon:</p>
<ul>
<li>Supports RFC 1035, and some others too (IPv6 AAAA records, and DNS OPT, with the goal of supporting DNSSEC at some point).</li>
<li>Does <strong>NOT</strong> support AXFR nor IXFR, I have no need for the standard zone transfer protocol</li>
<li>Data can be updated realtime with a provided client class, connecting to the server via a shared secret authentication (client computes checksum of his name, timestamp and secret, server replies with the same kind of data). Once authentication is finished data is sent cleartext, but adding SSL encoding wouldn&#8217;t be that hard (just need to create a &#8220;STARTTLS&#8221; function, that&#8217;s on the TODO list).</li>
<li>Slave stays connected to master (keepalive packet sent every 15 minutes), and gets updates realtime.</li>
<li>On first connection, slave will get all zones/domains/records from the master. If it gets disconnected later and reconnect, it will search for his last update, and will ask only for newer data from the master.</li>
<li>Slave synchronisation is done in a separate process, meaning that even when processing a lot of updates, service is available.</li>
</ul>
<p>As a test, I ran AFNIC&#8217;s zonecheck on a virtual zone I created on the server, and <a href="http://liip.to/afnicpwnz" target="_blank">it works</a>!</p>
<pre style="padding-left: 30px;">dig @dyndns1.ookoo.org version.dnsd ch txt</pre>
<p>If you want to test this, I got a test domain with a record creation page, however I won&#8217;t post it here (or it might get abused) so if you want to test, feel free to <a href="mailto:mark@hell.ne.jp">contact me</a>.</p>
<p>And finally the conclusion is simple: php can do anything you want to do, and even things you never wanted to.</p>
<p>PS: I&#8217;m looking for someone to look after <a href="http://www.pinetd.net/" target="_blank">PInetd</a>&#8216;s website, like removing this lipsum news, etc&#8230; (I don&#8217;t have time for that).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2009/02/16/php-dns-daemon/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>
