<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="/templates/php-blogger/atom.css" type="text/css" ?>

<feed 
   xmlns="http://www.w3.org/2005/Atom"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/">
    <link href="http://phpblogger.de/feeds/atom.xml" rel="self" title="php-Blogger" type="application/atom+xml" />
    <link href="http://phpblogger.de/"                        rel="alternate"    title="php-Blogger" type="text/html" />
    <link href="http://phpblogger.de/rss.php?version=2.0"     rel="alternate"    title="php-Blogger" type="application/rss+xml" />
    <title type="html">php-Blogger</title>
    <subtitle type="html">php-Blogger</subtitle>
    <icon>http://phpblogger.de/templates/php-blogger/img/s9y_banner_small.png</icon>
    <id>http://phpblogger.de/</id>
    <updated>2010-08-19T21:43:40Z</updated>
    <generator uri="http://www.s9y.org/" version="1.5.3">Serendipity 1.5.3 - http://www.s9y.org/</generator>
    <dc:language>de</dc:language>

    <entry>
        <link href="http://phpblogger.de/archives/300-nginx-tips-adding-arbitrary-output-to-a-response.html" rel="alternate" title="nginx tips: adding arbitrary output to a response" />
        <author>
            <name>Harald Lapp</name>
                    </author>
    
        <published>2010-08-19T15:47:57Z</published>
        <updated>2010-08-19T21:43:40Z</updated>
        <wfw:comment>http://phpblogger.de/wfwcomment.php?cid=300</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://phpblogger.de/rss.php?version=atom1.0&amp;type=comments&amp;cid=300</wfw:commentRss>
    
            <category scheme="http://phpblogger.de/categories/35-nginx" label="nginx" term="nginx" />
    
        <id>http://phpblogger.de/archives/300-guid.html</id>
        <title type="html">nginx tips: adding arbitrary output to a response</title>
        <content type="xhtml" xml:base="http://phpblogger.de/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <span class="preview"><a target="_blank" href="http://dl.dropbox.com/u/5014780/phpblogger/cd_big.png"><img src="http://dl.dropbox.com/u/5014780/phpblogger/cd_big_small.jpg" /></a></span>

<p>A while ago i wrote about how to use <a target="_blank" href="http://wiki.nginx.org/">nginx</a> as a proxy to do <a target="_blank" href="http://phpblogger.de/archives/283-cookie-based-redirect-mit-nginx.html">cookie based redirects</a>. We use this functionality at work to provide easy  access and view the progress of development of each developer.</p>

<p>I thought it would be nice to have the information, of which developers machine you currently have access to, right on the website. But i always disliked to put functionality to accomplish this inside the framework or even the app itself or have to install / modify some special configuration on each developers machine. I always wanted my proxy to do this kind of work. ... And nginx can.</p>

<p>It's the <a target="_blank" href="http://wiki.nginx.org/NginxHttpSubModule">substitution module</a> of nginx, that can replace arbitrary text in a http response. Nginx must be compiled with the option <tt>--with-http_sub_module</tt> configured.</p>

<p>The following rows show how to fill a variable <tt>$name</tt> with the name of the developer we are accessing the machine of. The statement <tt>sub_filter</tt> defines the search pattern as first parameter and the replace string as second parameter -- very easy, isn't it?</p>

<code>
<pre>
set $name &quot;&quot;
if ($http_cookie ~* &quot;(; )?devredirect=([^;]+)&quot;) {
    set $name $2;
}
sub_filter      &quot;&lt;/body&gt;&quot;       &quot;&lt;div style='position: fixed; 
    left: 0; top: 0; font-weight: bold; padding: 5px; color: #000; 
    background-color: rgb(235,58,0);'&gt;devredirect: ${name}&lt;/div&gt;
    &lt;/body&gt;&quot;;
</pre>
</code>

<p>The following rows show the part of the proxy configuration with the inserted substitution filter:</p>

<code>
<pre>
server {
    listen          80;
    server_name     .clipdealer.devcenter.int;

    proxy_redirect          off;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

    location / {
        set $name &quot;&quot;
        if ($http_cookie ~* &quot;(; )?devredirect=([^;]+)&quot;) {
            set $name $2;
        }
        sub_filter      &quot;&lt;/body&gt;&quot;       &quot;&lt;div style='position: fixed; 
            left: 0; top: 0; font-weight: bold; padding: 5px; 
            color: #000; background-color: rgb(235,58,0);'&gt;
            devredirect: ${name}&lt;/div&gt;&lt;/body&gt;&quot;;

        if ($http_cookie ~* &quot;(; )?devredirect=harald&quot;) {
            proxy_pass              http://10.0.0.20;
            break;
        }
        ...
    }
    ....
}
</pre>
</code>
 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://phpblogger.de/archives/298-OSX-10.5.x-+-PHP-+-pecl_newt.html" rel="alternate" title="OSX 10.5.x + PHP + pecl_newt" />
        <author>
            <name>Harald Lapp</name>
                    </author>
    
        <published>2010-07-05T14:05:33Z</published>
        <updated>2010-07-11T19:17:26Z</updated>
        <wfw:comment>http://phpblogger.de/wfwcomment.php?cid=298</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://phpblogger.de/rss.php?version=atom1.0&amp;type=comments&amp;cid=298</wfw:commentRss>
    
            <category scheme="http://phpblogger.de/categories/17-PHP" label="PHP" term="PHP" />
    
        <id>http://phpblogger.de/archives/298-guid.html</id>
        <title type="html">OSX 10.5.x + PHP + pecl_newt</title>
        <content type="xhtml" xml:base="http://phpblogger.de/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>I always wanted to provide nice user interfaces for some of my commandline tools written in PHP, but was not able to solve one problem until recently. The big problem when writing user interfaces for commandline utilities written in PHP is: ... what library to use for actually building the user interface?</p>

<ul>
<li><p>You could try to write your own library using <a target="_blank" href="http://ascii-table.com/ansi-escape-sequences.php">ANSI escape sequences</a> -- but your user interfaces would either be very limited or it would be a hell of work to write an extensive library providing more than just the basics.</p></li>
<li><p>You could try to get the <a target="_blank" href="http://pecl.php.net/package/ncurses">ncurses extension</a> to work -- i failed.</p></li>
<li><p>You could try to get the <a target="_blank" href="http://pecl.php.net/package/newt">newt extension</a> to work -- i failed ...</p></li>
</ul>

<p>... until recently. Every once in a while i tried to dig up more information of how to get newt to work, because this is the library i would prefer over the other solutions. However, it did not compile on my system. Recently i searched again and was able to dig up <a target="_blank" href="http://kiwi.alex-smith.me.uk/wiki/doku.php/doc:macosx#installing_from_source">a patch for newt-0.5.22.11</a>. So, here are the steps to get things work:</p>

<ol>
<li><p><a target="_blank" href="https://fedorahosted.org/releases/n/e/newt/newt-0.52.11.tar.gz">Download</a> newt 0.52.11 and extract it.</p></li>
<li><p>Download the patch for newt from the page above and apply it as described in the short tutorial provided on that page.</p></li>
<li><p><a target="_blank" href="http://www.jedsoft.org/snapshots/">Download</a> slang, which is required by newt. I decided to download the latest snapshot (pre2.2.3-60) and things worked just fine with it. Extract and build it -- i did not use any special flags for this.</p></li>
<li><p><a target="_blank" href="http://rpm5.org/files/popt/">Download</a> popt, which is required for newt. I decided to download popt-1.16, which seems to be the latest release and can be found at the bottom of the download page. Extract and build it -- i did not use any special flags for this.</p></li>
<li><p>After installing slang and popt and patching newt, you should now be able to build and install newt.</p></li>
<li><p><a target="_blank" href="http://pecl.php.net/package/newt">Download</a> pecl_newt, or install it using <i>pecl install ...</i>. Don't forget to add <i>newt.so</i> to your php.ini.</p></li>
</ol>

<p><i>pecl_newt</i> provides some examples which should be executed to verify, that installation succeeded.</p>
 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://phpblogger.de/archives/299-OSX-10.5.x-+-PHP-+-pecl_ncurses.html" rel="alternate" title="OSX 10.5.x + PHP + pecl_ncurses" />
        <author>
            <name>Harald Lapp</name>
                    </author>
    
        <published>2010-07-09T13:32:57Z</published>
        <updated>2010-07-09T18:31:58Z</updated>
        <wfw:comment>http://phpblogger.de/wfwcomment.php?cid=299</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://phpblogger.de/rss.php?version=atom1.0&amp;type=comments&amp;cid=299</wfw:commentRss>
    
            <category scheme="http://phpblogger.de/categories/17-PHP" label="PHP" term="PHP" />
    
        <id>http://phpblogger.de/archives/299-guid.html</id>
        <title type="html">OSX 10.5.x + PHP + pecl_ncurses</title>
        <content type="xhtml" xml:base="http://phpblogger.de/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>After several days playing around with newt i am quite disappointed to come to a point where i have to say, that newt has not only a <a target="_blank" href="http://www.whoow.org/people/Jean-Marc.Lienher/gnewt/tutorial.html">very limited documentation</a> (i think there's only documentation of about 50% of the newt functionality) -- which would not be that of a problem, though. The bigger problem is, that things are very unstable. "Segmentation faults" reproducable on different operating systems and platforms -- not sure though, if the problem is newt or pecl_newt. However: this is definitly not what i want. So, let's move on to something better.</p>

<p>I had a look at the apple's <a target="_blank" href="http://opensource.apple.com">opensource repository</a> the other day and stumbled over a ncurses package. I had problems with the normal gnu ncurses package before, it would not install but hang when building the terminfo database. With the ncurses package i found at apple's opensource repository, i get it to install. Here is the howto:</p>

<ol>
<li>Download ncurses from apple's <a target="_blank" href="http://opensource.apple.com">opensource repository</a>. You can find it by clicking on the link of the Mac OSX version you are running, eg. <a target="_blank" href="http://opensource.apple.com/release/mac-os-x-1058/">10.5.8</a>.</li>
<li>Unpack the package und you get a directory called something like "ncurses-21" or so. Next <i>cd</i> into this direktory and run <tt>make</tt> and <tt>sudo make install</tt>. If make complains about a missing directory <i>/tmp/ncurses/Build</i>, just create it <tt>mkdir -p /tmp/ncurses/Build</tt> and start again.</li>
<li>Now an intermediate build should have been generated. Next <tt>cd /tmp/ncurses/Build</tt>, <tt>make</tt> and <tt>sudo make install</tt>. Now ncurses should have been successfully installed.</li>
<li>Ready to install the  ncurses php extension by either executing <tt>sudo pecl install ncurses</tt> or downloading ncurses from <a target="_blank" href="http://pecl.php.net/package/ncurses">pecl.php.net</a> and building manually.</li>
<li>Don't forget to add <tt>ncurses.so</tt> to your php.ini</li>
</ol>

<p>Now everything should be ready to start writing ncurses apps -- however: for me it sill did not work. The simplest ncurses app resultet in the following error message:</p>

<p><tt>Error opening terminal: vt100.</tt></p>

<p>What's going on? dtruss might be your friend to figure this out. Execute the following command, where <i>example.php</i> is your ncurses app you want to run: <tt>sudo dtruss php example.php</tt>. You should see output like:</p>

<p><pre style="font-size: 9px;">
[...]
lstat("/Users/harald\0", 0xBFFFE41C, 0xFFFFFFFFBFFFEFC8)                 = 0 0
lstat("/Users\0", 0xBFFFE2EC, 0xFFFFFFFFBFFFEFC8)                = 0 0
ioctl(0x3, 0x4004667A, 0xBFFFF17C)               = -1 Err#25
ioctl(0x3, 0x402C7413, 0xBFFFF150)               = -1 Err#25
fstat(0x3, 0xBFFFF1B0, 0xBFFFF150)               = 0 0
mmap(0x0, 0x226, 0x1, 0x2, 0x3, 0x100000000)             = 0x17FA000 0
lseek(0x3, 0x0, 0x1)             = 518 0
munmap(0x17FA000, 0x1F3)                 = 0 0
close_nocancel(0x3)              = 0 0
ioctl(0x1, 0x4004667A, 0xBFFFECEC)               = 0 0
stat("/Users/harald/.terminfo\0", 0xBFFFEC00, 0xBFFFECEC)                = 0 0
access("/Users/harald/.terminfo/73/vt100\0", 0x4, 0xBFFFECEC)              = -1 Err#2
stat("/usr/local/share/terminfo\0", 0xBFFFEC00, 0xBFFFECEC)              = -1 Err#2
write_nocancel(0x2, "Error opening terminal: vt100.\n\0", 0x24)            = 36 0
</pre></p>

<p>You can see, that ncurses is looking for a file <i>vt100</i> in a <i>terminfo</i> directory and fails looking at <i>/usr/local/share/terminfo</i>. I indeed had no directory <i>/usr/local/share/terminfo</i> but a directory <i>/usr/share/terminfo</i>. I was not able to figure out, where i could specify the correct directory configuration for this, so i just created a symlink: <tt>sudo ln -snf /usr/share/terminfo /usr/local/share/terminfo</tt>. After creating the symlink, i was able to execute my example ncurses application.</p>
 
            </div>
        </content>
        
    </entry>

</feed>