Skip to main content
Welcome guest. | Register | Login | Post

More on Firefox Rich Client Implementations

8 replies [Last post]
supermike's picture
Joined: 2006-02-17



This is about our thread on Firefox rich client implementations that we've been discussing in .

I didn't particularly like the learning curve of lighttpd, php compiling, and the heavy footprint of php. So, I started looking around at what I could tolerate. I started considering thttpd and liked it, although it's a bit picky. I explain below how to get around that -- it's mostly about how you call the command line and how you set your file permissions. Anyway, I then needed a CGI language. Bash is possible, but not very user-friendly for language purists. Perl is also possible, but not the best situation for an embeddable solution. Pike is a nice little language, but if you're going to go Pike, which is very Javascript like, I thought I might as well go with Javascript because I know that fairly well. That's when I discovered ngs-js, which has a very tiny footprint. When I discovered that ngs-js supported background pipes to run background processes and deliver the results back, and could read/write files, and read/write console input/output, plus get what's usually available with ECMASCRIPT-262, I knew I had something. Although it doesn't come with a SQLite driver, you could build a wrapper function or object that uses the SQLite command line via popen() to do your bidding.

In Ubuntu, once I enabled the universe option in /etc/apt/sources.list, I could do:

$ sudo apt-get update
$ sudo apt-get install thttpd*
$ sudo apt-get install ngs-js

Then, I created a directory to hold web pages and javascript and started experimenting. To launch thttpd, you do something like:

$ sudo thttpd -d /var/www -p 8080 -c '**.js' -l /var/log/thttpd.log

Note this is a bit insecure and the creator of it recommends you implement the -r option to enable a chroot jail for the web app, but if you do that, it is a whole mess of work! This is because it requires that everything your CGI script implements must be made available to the web server in that jail. Not a big deal if you've done this before, but I found it a bit difficult to do this for ngs-js Javascript to execute properly. I'm still researching that one, so for experimentation you can use it without the -r option and then move to that later.

I chose port 8080 because I already have Apache running at 80 and I was experimenting with a lightweight, embeddable, Firefox rich client application with XUL.

You can then connect to it with:

As an example of the js file, consider reading this and uncommenting certain sections:

</p><p>#!/usr/bin/js<br /> <br /> var out = System.stdout;<br /> <br /> // GET QUERY PARAM, such as when you do<br /> /*<br /> s = System.getenv("QUERY_STRING");<br /> out.writeln("Content-type: text/html\r\n\r\n");<br /> out.writeln(s);<br /> */<br /> <br /> // WRITE TO PAGE<br /> /*<br /> out.writeln("Content-type: text/html\r\n\r\n");<br /> out.writeln('hello world');<br /> */<br /> <br /> // REDIRECT TO ANOTHER PAGE<br /> /*<br /> out.writeln("Content-type: text/plain");<br /> out.writeln("Location:");<br /> */<br /> <br /> // MAKE A SYSTEM CALL AND RETURN THE RESULT<br /> out.writeln("Content-type: text/html\r\n\r\n");<br /> pipe = System.popen('ls','r');<br /> while (!pipe.eof()) {<br /> out.writeln(pipe.readln() + "<BR>\n");<br /> }</p><p>

Anyway, the thttpd docs are here:

Please note that the "//" you see in the URL after the .org is not a typo -- for some very odd reason the only way the manual works is by doing this! Otherwise, you get a permissions error! How about that!

Also, thttpd, as it explains in its man page, is very picky about directory permissions (and for good reason -- so you don't get hacked). It also prefers to be run as root but then switches to 'nobody' by default or you can set that to something like 'www-data' or whatever you require.

Oh, and one more thing. If you want to kill this thing, do 'killall thttpd' and it's dead.

That's a lot of information, but there's even more when you do 'man thttpd' and 'man ngs-js'. The web pages that I reference are also going to be of great use to you.

 P.S. If this forum post looks funny, note that I had a dickens of a time using the editor in nuxified and learning how to do anchors and code. I just about gave up.


supermike's picture
Joined: 2006-02-17
Wow, this is just too cool.

Wow, this is just too cool. Again, this is about combining these elements:

  • XUL with Firefox for the embeddable, secure, fairly powerful GUI
  • thttpd for the embeddable, secure, powerful web server with the small disk/memory/processor footprint
  • ngs-js for embeddable, secure, fairly powerful server-side scripting language
  • sqlite3 for embeddable, secure, fairly powerful database with the small disk/memory/procesor footprint

By using these, you don't have to fight with trying to compile a separate PHP or compile that connection with Lighttpd or Apache. That can be quite difficult, as I learned, and the documentation on that is fairly shoddy, especially if you don't want to disturb an existing PHP/Apache install that you already may have. By using thttpd and ngs-js, you won't need to use PHP or another web server. You can get out of the compilation game and just use apt-get (or whatever works on your platform -- mine is Ubuntu) to get what you need.  By using ngs-js, you'll find that it's fairly similar to PHP in some ways. And if you've done any web development at all, you're probably already familiar with client-side Javascript.

I found that ngs-js is fairly solid and provides most of what you can do with client-side Javascript but also includes going outside the sandbox (because it's run on the server, not the client). In sum, it can do:

  • mostly everything you can do with client-side javascript
  • shelling out to a process, running it, and pulling back the result to parse it
  • writing data to the browser
  • (if not run in CGI mode, it can read command-line arguments, but doing this in CGI mode could cause your web page to hard-lock)
  • page redirection (using a small function you have to build)
  • environment variables (for pulling posted form data, server variables, page script variables, etc. returned from the thttpd embeddable web server)

I was also completely shocked to learn that I could use variables that begin with "$", making it more like Perl and PHP. That certainly makes the language far easier to use! It also lends to helping make it look not so scary to PHP developers. From that, I then built some PHP-like functions and used System.popen() and a wrapper function to build an API to interact with SQLite. (By the way, get SQLite3, not SQLite, if you do an apt-get. SQLite has some serious security bugs.)

So that's how I've been wasting my time these past few days. I've been really jazzed about where this thing can go.

I've dubbed my aggregation environment here as "XJS" because of its XUL and Javascript influences.

The thing loads on an 800Mhz Pentium with 256MB RAM in about 3 seconds if you have other stuff open. But on a 1Ghz or better, it snaps open instantly just as fast as you can doubleclick an icon.

So, to reiterate, what can you do with this?

Well, PHP programmers would love such a thing. PHP programmers have typically focused on web apps that are used by multiple people on a web server, not standalone rich client apps. This is because PHP-GTK just isn't "there" yet and is fairly hard to use, anyway. But now with a platform like this, they can get used to the PHP functions I've built and then use Javascript, which shares many similarities with PHP. Plus, they don't have to relearn much. If they know web development, more than likely they already know how to do HTML and Javascript, and that's what this is all about.

Therefore, you can almost build anything you want for the XFCE, GNOME, and KDE platforms on Linux, and with something that doesn't require libraries from any of these to work. Instead, it uses what comes with Firefox, which is XWindows and C based.

You could build, for instance:

  • A Quickbooks knock-off
  • Another replacement for webmin
  • Another replacement for phpmysqladmin or phppsqladmin
  • A control panel for things like an iptables firewall
  • A fun game
  • A learning game
  • A test for a classroom
  • A GUI for something in a museum or customer kiosk
  • An installer for other applications
  • Perhaps, with a lot of AJAX work, perhaps a programmer IDE, word processor, spreadsheet, slideshow processor, database, or drawing program.
  • Perhaps an MS Access knockoff with AJAX.
  • A special web browser for certain types of needs or for handicap people.
  • A nice wrapper GUI for your favorite web app, such as a ticketing system you may have been working on (hey, that's my idea!)
  • A VB4/32 knockoff for making an almost Visual Basic like IDE for your favorite language
  • A chat program
  • Perhaps a DVD watching program
  • Practically anything, especially if you know your stuff in AJAX and uber-advanced web development, but that's not required for many things.

This might even work with a Mac. If you use cygwin, you can probably port this to Windows with a lot of work. Therefore, this could probably become cross platform.

Well, I'm going to have to shelve this for now because I've got to return to finishing my ticketing system app that I'm working on. I've already got two people who say they want one -- a lawyer in town and a department manager at a company. If only I had one that was ready to go for them to install.

So, please, if you're a programmer, or thinking about becoming one, I suggest that you do apt-get or whatever to try these things out in tandem and see what you can come up with. It's a breath of fresh air, making it so that you don't have to learn the complicated and frustrating GTK or QT API for the GUI, or having to use languages like Python if you prefer to stick with the web languages you might already know like PHP and Javascript.

free-zombie's picture
Joined: 2006-03-08
not really...
supermike wrote:

And if you've done any web development at all, you're probably already familiar with client-side Javascript.

ah.... come on...
This definately looks interesting, though I still can't see the problem with python Eye

supermike wrote:
  • A special web browser for certain types of needs or for handicap people.
  • Come on, a special web browser within the confined space of a conventionl browser ?

    supermike wrote:
  • Perhaps a DVD watching program
  • that's a negative. The way this would work: read the DVD and trans-/decode it to something non-encrypted, then encapsulate it in the HTTP protocol and feed it to a browser plugin such as the mplayerplug-in. What a waste.

    supermike wrote:

    It's a breath of fresh air, making it so that you don't have to learn the complicated and frustrating GTK or QT API for the GUI, or having to use languages like Python if you prefer to stick with the web languages you might already know like PHP and Javascript.

    for small apps this may be a breath of fresh air, but I imagine that if you want to build a larger application, it becomes to clear that it is the wrong platform. the "page" model is not right for most things, and if you go javascript, you have two seperate layers of the application that are not clearly defined.
    Python is good - if you accept its specialities... and I don't quite see how the API of GTK is frustrating. I have been playing around with gtkmm (gtk for c++) recently and it is very well done.
    What I'm saying is that for larger applications this is most likely the wrong platform - HTML was made for static content, AJAX is used as a crude emulations of the client side feel of "rich clients" - and makes programming more complicated than it need be.

    supermike's picture
    Joined: 2006-02-17
    FZ: Well, yeah, AJAX sux, in


    Well, yeah, AJAX sux, in my opinion, and for the very reason you mention. You won't catch me riding that wave. But it's a wave, none-the-less, and people are riding it. Therefore, I don't want to discourage it if that makes someone's day.

    Python, PyGTK -- all fine. But if you're a PHP web developer, you might only know PHP and Javascript. That's where this platform becomes great -- you don't have much to relearn. Still, I don't say anything to anyone about stopping their use of Python and PyGTK. After all, I wrote 'pgst' (get it on SourceForge) and I use it every day. It was written in Python/PyGTK.

    On the DVD thing, I was thinking that the HTTP protocol merely serves up the plugin and the plugin calls for the data without encoding. I guess I don't know enough about the mplayer plugin and how it runs DVDs. Still, the idea here is inspiration, not necessarily to be exact on the thought that this platform could actually show DVD movies.

    As for a large application, I wouldn't think that building a Quickbooks knock-off with XJS would be a big deal. The page model would work fairly well there.  And building neat control panels or a replacement for webmin -- all are very possible with this platform without much trouble. Some people are willing to do page roundtrips for good functionality, such as myself. Now, as a Word Processor or something on that league, I'd say no -- not without AJAX, but I would hate to personally have to build and maintain an AJAX monstrosity.

    So, I don't share your frustration with the 'come on' statements, but I do appreciate your constructive criticism. This isn't about a personal attack on one's favorite language. It's about helping a certain class of programmers leverage what they already know in order to do something else -- rich client apps -- with almost exactly that same knowledge. That class of programmer is one who prefers to stick with PHP and Javascript.

    I also don't "think" in Python or PyGTK. I also don't "think" in C. I have a pretty hard time keeping up with it and have to pour over manuals a lot. But with Javascript and PHP, I sort of "get it" and don't have to refer to manuals as much. So I get really excited when I see something for me personally that works well, expanding my horizon from the web application realm and into the realm of psuedo-rich client apps.

    Yep, it's not for everyone, but some people will really love this when they see how to combine these 4 things.

    Note also -- and this is for people who didn't pick this up the first time -- that ngs-js is server-side Javascript and (a) has nothing to do with requiring Javascript to run in the Firefox browser and (b) has nothing in common with Java Server Pages. Instead, it's more like server-side PHP. 


    a thing's picture
    Joined: 2005-12-20
    Fedora package name

    The Fedora package (in extras) that's equivalent to "ngs-js" is "js".

    free-zombie's picture
    Joined: 2006-03-08
    the come on was about "I'm

    the come on was about "I'm not so sure the majority of web developers know js" Eye
    from what I know of of homw banking, that would be a reasonable application for here. But most desktop applications don't fit too well with the page model...

    coming back on the DVD program: to watch commercial DVDs, you need to decrypt it with libdvdcss. and you can't really expect the plugin the user happens to have installed (such as gxine, mplayerplug-in, totem or kaffeine) to support that, especially on streams...

    did I mention "thinking" ?! well, if I did, ..., whatever, I didn't anyway - this is not about my brother (not) learning programming Eye

    supermike's picture
    Joined: 2006-02-17
    Yeah, you're right. Most web

    Yeah, you're right. Most web devs don't know how to code proper client-side (in browser) Javascript. You're right there, my friend. Tee hee. To code proper Javascript is to stick to the ECMAScript-262 standard and that's somewhat limiting to today's AJAX phreek. Also, people depend way to much on client-side Javascript, going way beyond its initial, intended purpose. I use it very sparingly and would almost prefer a round trip to do something than to have to call it or to use AJAX. Still, however, there are some sensible uses for it:

    • Popping open a new window such as when you have a read only field that only gets filled in when you click a button, open a wizard in a new window, go through it, click Finish, and it populates the readonly field.
    • Redirecting to a page based on a popdown listbox choice.
    • Sorting a column on a table -- redirecting back to the same page with a "sort" query param in the URL so that your table sorts by that column.
    • Making a hyperlink into a form submit so that it acts like a button.
    • Updating a hidden form value before submitting a form.
    • Some minimal form field validation.
    • Reading an enter key on a field and tabbing automatically to the next field.
    • Reading an enter key on a field and taking that as a form submit.
    • Creating an inline DIV menu.
    • Creating an inline DIV popup (such as an app with "sticky notes") and letting you have the power to "close it". This can also be used for search fields.

    I don't use it for much else.


    tbuitenh's picture
    Joined: 2005-12-21
    Don't forget about client

    Don't forget about client side javascript being useful for verifying if form input is sane (eg a year must be an integer between 1900 and 2100 or something like that). Of course the server has to verify it again, but preventing a trip to the server in case of bad input helps with not annoying the user.

    kode's picture
    Joined: 2006-04-19
    ... still around ...

    I'm still around and working on the matter from a different angle... it's been a hectic couple of weeks... now that I'm mostly moved to the new house, I can get back to writing up the php/lighttpd howto.

    Don't give up on php -- once you get the hang of the build process, it's very easy to create a very small footprint php install -- and not interfere with the existing system.

    I'll try to get the docs up this week...

    Comment viewing options