Plain Old Webserver Help and Hints

Announce and Discuss the Latest Theme and Extension Releases.
dakellog
Posts: 33
Joined: July 31st, 2006, 12:06 pm

Plain Old Webserver Help and Hints

Post by dakellog »

The following is a post describing how to use my extension, the Plain Old Webserver, POW.

The latest documentation and code examples can be found at the <a href='http://davidkellogg.com/wiki/Main_Page'>POW Documentation Wiki</a>.

The <a href='https://addons.mozilla.org/firefox/3002/'>POW addons page</a> has the download link.

POW - Plain Old Webserver

SYNOPSIS

Use POW to distribute files. POW is started by clicking on the blue square in
the bottom right-hand corner of your browser. When the play button appears,
the server is on. Also, you can manage POW access privileges and other
advanced features in the menu, "Tools > POW > Manage POW..."

DESCRIPTION

How do I manage POW?

You can reach the management window through 'Tools > POW > Manage POW ...'

Password Protect Site
Check this to prevent access except through the listed username and password.

Login ID & Password
These will be required by anyone accessing the site if 'Password Protect Site' is checked.

Port
The standard port is 6670, as in localhost:6670. Do not use ports under 1025, unless you know what you are doing.

Add Mime Type
Add extra mime-types, like 'audio/mpeg' for the mp3 extension. Remember to check the binary checkbox, if it is a non-text format. Use the 'Add' button, not enter to add a mime-type.

Where are my files?

Make a shortcut to this folder for easy access.

On a Mac:
Users/YOUR NAME/Library/Application Support/Firefox/Profiles/RANDOM
TEXT/default/pow/htdocs
> ln -s /Users/YOUR NAME/Library/Application\ Support/Firefox/Profiles/
RANDOM.default/pow/htdocs ./pow_docs

On a PC:
C:\Documents and Settings\YOUR NAME\Application Data\Mozilla\Firefox\
Profiles\RANDOM TEXT\pow\htdocs

On a Linux:
/home/USER NAME/.mozilla/firefox/default.NUMBER/pow/htdocs

You can check the exact path at 'http://localhost:6670/get_path.sjs'

Why can't I access my web server from the outside?

You might have a firewall blocking your server, so you can only access it from the server itself. Punch a hole in the firewall if your sys-admin allows. Try a different port in 'Tools > Pow > Manage Pow'. You might also find yourself behind NAT, in which case you are out of luck.

Can I create dynamic content?

Yes. SJS is a Javascript-based server-side scripting language.

How do I get request headers?

document.writeln("Headers are: "+server.REQUEST);
OR
document.writeln("Cookie is "+get_request_header('Cookie'));

How do I delete a file?

file_delete("file.txt");

How do I exit the code?

exit();


How do I add a mime-type?

Additional mime-types can be added in the POW Options window at "Tools >
POW > Manage POW..." Use the binary checkbox for binary data, such as
music and images.


What is my IP address?

See http://www.ipchicken.com/
Last edited by dakellog on January 7th, 2007, 8:48 am, edited 3 times in total.
---
DKPHD
MikeOliverAZ
Posts: 1
Joined: October 16th, 2006, 7:21 am
Contact:

Post by MikeOliverAZ »

Can events on the POW "site" be monitored in my browser? In other words can I detect events on the POW server and execute javascript in a page on my browser? DOES the POW support anything other than HTTP GET?
dakellog
Posts: 33
Joined: July 31st, 2006, 12:06 pm

POST and events

Post by dakellog »

From above:

Can events on the POW "site" be monitored in my browser? In other words can I detect events on the POW server and execute javascript in a page on my browser? DOES the POW support anything other than HTTP GET?

Yes. The server.POST and the server.REQUEST arrays hold the POSTed variables.

The most crude event for alerting you of access is this:

alert("Accessing page!");


Anyone accessing your page will alert you. If you are good enough at Javascript, you can script an entire IM client/server in SJS.

Dave
---
DKPHD
dakellog
Posts: 33
Joined: July 31st, 2006, 12:06 pm

pow_* upgrade problem

Post by dakellog »

Thanks to Jack for pointing out this upgrade "feature."

<i>Since upgrading to the current version, I get the following when logging in: "ReferenceError: append_path is not defined"???</i>

Here's the fix.

Edit index.sjs in your htdocs folder and replace "append_path" with "pow_append_path".

Alternatively, you can force the "index.sjs" file to upgrade by erasing it and erasing "../log/version_number".
This makes it look like a first-time install. The "index.sjs" file will reappear with the next restart.

Dave
---
DKPHD
nlany
Posts: 4
Joined: November 7th, 2003, 1:18 am
Location: Guangzhou, PRC
Contact:

got error

Post by nlany »

when i try to open the option window, i got this:

XML Parsing Error: undefined entity
Location: chrome://pow/content/options.xul
Line Number 24, Column 4: <checkbox>
--------^

POW Version 0.0.7, released on Dec 16, 2006.
Firefox 2.0 Linux

This bug would be triggered if you are using zh-CN locales. So itś easy to fix, just copy pow.dtd file from en-US folder to zh-CN folder in pow.jar found under your profile folder.
dakellog
Posts: 33
Joined: July 31st, 2006, 12:06 pm

Post by dakellog »

The zh-CN options dialog is fixed in CVS. The next version will have partial support for zh-CN. This will include Chinese query parsing and acceptable lookups based upon characters (not multi-character words). Chinese pages are a bit hard to handle, so tell me if pages appear corrupted.

Dave
---
DKPHD
cainbrogan
Posts: 3
Joined: December 29th, 2006, 12:01 pm

Post by cainbrogan »

This idea is really great!

Using Firefox 2.0.0.1., with my PC, I installed this Add-On from:

https://addons.mozilla.org/firefox/3002/

I then Restarted Firefox, and went to:

http://www.davidkellogg.com/wiki/Gentle ... to_POW_SJS

I then noticed that the first two lines of the is page:

"A quick hello world."

and

"Next: AJAX Chat Application -->"

appear to be out of context?

I also noticed that the splash screen(mentioned in Step 3.) never happened when i restarted Firefox?

I then went to the Help Page at:

http://localhost:6670/help.sjs

, but then became further confused by the Synopsis. The Synopsis says:

"POW is started by clicking on the blue square in
the bottom right-hand corner of your browser."

, but there the POW icon, in the lower right-hand corner of my browser, is a brownish circle(Like Fireworks.)

The Synopsis then says:

"When the play button appears,
the server is on."

I've never seen a "Play" button(Triangle(?,) but if I right click on my icon I do get an On/Off option. And this On/Off option will Color/Grey the icon? Moreover, right-clicking on the my icon reveals a "POW Home..." option, and click this leads to:

http://localhost:6670/

where I find a:

"Your webserver is now working." message?

The Synopsis then seems further out of date by saying:

"Also, you can manage POW access privileges and other
advanced features in the menu, "Tools > POW > Manage POW..."

When my Tools > POW > listing has no "Manage POW" link. Would this be similar to "Options...?"

With the:

"Where are my files?"

area of:

http://localhost:6670/help.sjs

I was able to locate the "htdocs" folder, on my hard drive. Into that directory I've placed a file named dolphinmoon.rar; but what is URL link to that file?
smartboyathome
Posts: 6
Joined: January 10th, 2007, 3:54 pm

Post by smartboyathome »

I may be able to answer some of your questions, cainbrogan.

First off, A quick hello world and Next: AJAX chat app are not out of place. The Next is the next page in the series. A quick hello world refers to making your browser say "Hello World" quickly and easily.

The "Manage POW" would be the "Options...?" menu. If you look at it, it contains the same content as described in the "Manage POW" menu.

The URL link to your file would probably be http://localhost:6670/htdocs/dolphinmoon.rar.

-------------------------------------------

Now onto my questions. Is there any way to post this onto a URL like insertyoururlhere.com?
Also, the help file DOES need to be updated.
Finally, I think this is a great idea and look forward to making this easier in the future. Thanks! :)
dakellog
Posts: 33
Joined: July 31st, 2006, 12:06 pm

Post by dakellog »

smartboyathome wrote:
The URL link to your file would probably be http://localhost:6670/htdocs/dolphinmoon.rar.

-------------------------------------------

Now onto my questions. Is there any way to post this onto a URL like insertyoururlhere.com?
Also, the help file DOES need to be updated.
Finally, I think this is a great idea and look forward to making this easier in the future. Thanks! :)


The help file will be updated with the next version.

YOURURL.com?

Not easy, unless you have static IP at home or dynamic IP <i>and</i> dynamic DNS set up.

This is an irritation to me, too. I'm working on a permanent link network right now. So your url will start out like this.

http://example.com/infinilink/1829384/my_photos.html

which will redirect right away to

http://192.168.1.100:6670/my_photos.html
and later to
http://192.168.1.105:6670/my_photos.html
or wherever your home server wanders to.

You will mail and use the first link (example.com). The setup won't be so easy at first, but even if you have dynamic IP from your ISP, you will find your server every time. I'll spell it out in the docs after I release the next version.

This feature will last until I run out of money and Dreamhost pulls the plug. Anyway, at 6k max servers, I will donate the bandwidth. It won't be a problem.

Dave
---
DKPHD
jahvascriptmaniac
Posts: 5
Joined: August 3rd, 2006, 10:33 pm

Where are the Pow sites ?

Post by jahvascriptmaniac »

Is there somewhere a list of pow-hosted sites, so I could see what they look like :)

P.S. 200% jahvascript sites ! wow !

P.P.S. : Cross-posted on the addons.mozilla.org page a few weeks ago, but as it didn't get any answer, I thought maybe more people were looking at this forum than on the addons site.

Thanx :D
jahvascriptmaniac -at- gmail.dot.com
smartboyathome
Posts: 6
Joined: January 10th, 2007, 3:54 pm

Post by smartboyathome »

dakellog wrote:The help file will be updated with the next version.

YOURURL.com?

Not easy, unless you have static IP at home or dynamic IP <i>and</i> dynamic DNS set up.

This is an irritation to me, too. I'm working on a permanent link network right now. So your url will start out like this.

http://example.com/infinilink/1829384/my_photos.html

which will redirect right away to

http://192.168.1.100:6670/my_photos.html
and later to
http://192.168.1.105:6670/my_photos.html
or wherever your home server wanders to.

You will mail and use the first link (example.com). The setup won't be so easy at first, but even if you have dynamic IP from your ISP, you will find your server every time. I'll spell it out in the docs after I release the next version.

This feature will last until I run out of money and Dreamhost pulls the plug. Anyway, at 6k max servers, I will donate the bandwidth. It won't be a problem.

Dave




Is there any way to make a site hosted with this with the current version (0.0.8)? If so, how would I do it? I read the help file, and it doesn't explain how to do that. Also, would I be able to host just PLAIN html? What about an SMF board (just wondering)? Thanks, and you are doing a great job!

EDIT: I found the infinilink, but my POW folder doesn't have a folder called "system". Is this an error on my part?
mmclaren
Posts: 3
Joined: September 7th, 2005, 1:29 am

Wow and E4X

Post by mmclaren »

Wow, David. I love POW, it has bags of potential.

I have a slight problem with 0.9 as the file downloads seem to be including header information.

Also, I noticed something (please note I have no experience writing Firefox plugins). If I tweak some of the files in pow.jar to change references from "application/x-javascript" to "application/x-javascript;e4x=1", it is then possible to use JavaScript 1.5's built in E4X processor. Then with POW it is be possible to use E4X like this:

<?sjs
var contents = file('http://news.google.com/?output=rss');

pow_header("Content-Type: text/html");
contents = contents.replace(/^[\s\S]*<rss/, "<rss");
var last = contents.lastIndexOf(">") + 1;
var copy = contents.substring(0,last);
var rss = new XML(copy);
var title=rss.channel.title;
document.write("<h1>" + title + "</h1>");

for each (var item in rss.channel.item) {
title=item.title.*;
link=item.link.*;
var span = new XML("<span />");
span.a.@href = link;
span.a.b = title;
document.write(span + "<br />");
}
?>

Once again, brilliant stuff, well done. I'll watch developments with great interest.
dakellog
Posts: 33
Joined: July 31st, 2006, 12:06 pm

Post by dakellog »

I was thinking about wiping the header from the file downloads. For now use a regex to get rid of everything before and including the "\r\n\r\n".

Dave
---
DKPHD
LadFromWales85
Posts: 15
Joined: September 6th, 2003, 2:44 pm
Location: Wales, UK
Contact:

Post by LadFromWales85 »

Everywhere I look for information about POW, I see mentions of 'file uploading code'. I am looking for a simple webserver that I can run on my PC to allow friends to upload files to me, as well as download, pictures and such, as IM transfers can be awfully slow due to non direct connections and such. I can't find any mention of file uploading code within POW, has this been removed?

I don't have a clue about javascript, so I'm pretty much stuck as to what to do with it atm!

Could some kind person come up with a script that I can plop on the server that friends can visit at /uploads/, presenting them with a path with browse button in which to enter the file to be uploaded, and a list of all current files within uploads, or something.

Thanks
dakellog
Posts: 33
Joined: July 31st, 2006, 12:06 pm

Post by dakellog »

I can't find any mention of file uploading code within POW, has this been removed?

No.

I'm a little short on time, but here's a primer on what to do. Others who can code Javascript can put this together and post it.

First, create a login and password. You don't let just anyone upload to your machine. Then check out http://davidkellogg.com/wiki/Server_variables
The variables you want are pow_server.POST_FILENAME and pow_server.POST_FILE
Use pow_file_put_contents() to save the file.
The rest is just HTML with a form with file upload code. Add more security (you choose the filename, not your friends) and you're done.
---
DKPHD
Post Reply