r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!Cheyenne] Discussions about the Cheyenne Web Server

florin
29-Aug-2010
[8900]
Gabriele: in the temple.r file, the word CONTEXT is used to define 
some functions, then you export them with the 'export function defined 
in the utility.r file. Is there a 'best practice' about it as I don't 
see the difference compared to simply defining it within the scope 
of the file?
Kaj
29-Aug-2010
[8901]
I think it's Gabriele's module system. Similar functionality is standard 
in REBOL 3. When you export explicitly, you can choose what to export 
and what to leave internal to the context, so you have minimum potential 
for conflicts with the global context
florin
29-Aug-2010
[8902]
Got it. Pattern #1.
Gabriele
30-Aug-2010
[8903]
Kaj: well, it's not my module system, but it's basically the same 
thing as using SET 'WORD instead of WORD: , except that it is more 
readable (a newbie can guess what "export" means, while it's harder 
to guess that SET 'WORD is different from WORD:)


Florin: since R2 does not natively include the concept of "modules", 
all of us have been doing various things to avoid polluting the global 
context too much. I eventually got tired of all this and created 
this instead: http://www.rebol.it/power-mezz/mezz/module.html
Dockimbel
3-Sep-2010
[8904]
Hi all, just to let you know that I'm upgrading Cheyenne websocket 
support to the last ws draft RFC, the handshaking part has changed 
and is not compatible with the previous version, causing all current 
Cheyenne ws apps to not work with latest browsers (like Chrome 6).
Davide
3-Sep-2010
[8905]
I've made a func to calculate the challengin code given the header 
request.

It was in the "I'm new" section, but it works nicely, I'm using it 
very often, so it's well tested.


ws-chall: funct [header [string!]] [		
	
	cnt: funct [k] [
		n: copy "" 
		ns: 0 
		repeat x k [
			if all [x >= #"0" x <= #"9"][
				append n x
			] 
			if x = #" " [
				ns: ns + 1
			]
		]
		if ns = 0 [
			return none
		]			
		(to decimal! n) / ns
	]
	
	int-2-char: funct [n [integer! decimal!]] [
		;n: to decimal! n
		head insert insert insert insert make string! 4
			to char! n / 16777216
			to char! (n // 16777216) / 65536 
			to char! (n // 65536) / 256
			to char! n // 256
	]

	attempt [
		t: parse/all replace/all header crlf lf "^/"

  l: copy [] repeat x t [if n: find x ":" [insert tail l reduce [copy/part 
  x (index? n) - 1 next n]]] l: head l
		k1: next select l "Sec-WebSocket-Key1"
		k2: next select l "Sec-WebSocket-Key2"
		k3: next next find header "^/^/"
		aux1: cnt k1
		aux2: cnt k2
	]

	if any [none? aux1 none? aux2 none? k3] [return ""]

 to-string checksum/method rejoin [int-2-char aux1 int-2-char aux2 
 k3] 'md5		
]
Dockimbel
3-Sep-2010
[8906x2]
Thanks for the code, but the handshake implementation was trivial. 
My current issue is the fact that the new ws draft is breaking HTTP 
specifications by using a GET request with a message body...WTF?

I'm not the only one to find that odd: http://blog.iworks.at/?/archives/69-WebSockets-Handshake-non-HTTP-conforming.html
SVN revision 87: websocket support updated to follow draft 76 specs 
(works with Chrome 6+)
Pekr
4-Sep-2010
[8908]
Is http://nodejs.orgsimilar to what websockets does? I found it 
when reading about upcoming Palm (HP) WebOS 2.0 release ...
Graham
4-Sep-2010
[8909]
Terry has mentioned nodejs before .. it's an event driven web server 
... nothing to do with web sockets per se
Davide
4-Sep-2010
[8910]
node.js is a v8 javascript interpreter that could be used server-side 
to make tcp server.

So, not only web server but server with persistent connection too, 
like web sockets.

Javascript on the server side isn't a new idea, but V8 is very fast 
and more light without the html dom complexity.
It's all event driven and seems very fun to play with it.
Dockimbel
6-Sep-2010
[8911x3]
SVN revision 89: removed View engine dependency for displaying error 
messages produced by switching to Windows Service mode.
if there are other "hot" issues to fix in Cheyenne, please let me 
know.
Btw, Windows Service mode seems to run OK under Windows 7 if Cheyenne 
is started with admin privileges (tested with an enpro kernel).
Henrik
6-Sep-2010
[8914]
Dockimbel, will you provide an encapped version again? Last time 
I had quite a mess figuring out what Cheyenne version worked with 
what REBOL version, so I just avoid upgrades unless there is an encapped 
version.
Dockimbel
6-Sep-2010
[8915]
I distribute encapped versions only when making new releases. If 
you need a intermediary revision encapped, just let me know the OS 
and encap kernel and I'll make you one. Also, I think I should release 
a new version now, the current SVN code base seems stable enough 
now.
Henrik
6-Sep-2010
[8916]
ok
Dockimbel
6-Sep-2010
[8917]
hum...I forget about the SDK licensing issue, you can't distribute 
encapped binaries that allow running arbitrary REBOL code (Cheyenne 
allows that through CGI and RSP scripts).
Henrik
6-Sep-2010
[8918]
ok
amacleod
6-Sep-2010
[8919]
RE: SDK licensing issue:

So you could not make an ecapped app that uses rebol as its scripting 
language? Like a paint program that allows you to make your own macros 
for repetitive  tasks?
Dockimbel
6-Sep-2010
[8920]
if your paint program allows anyone to run any Rebol script, then 
I guess no.
Henrik
6-Sep-2010
[8921]
does it also say that if you use a plain enface? isn't this related 
to having access to pro/command features?
Dockimbel
6-Sep-2010
[8922x2]
This is what the SDK license says (so related to any encapping kernel): 
[...]

REBOL API Restriction. If you choose to export the REBOL API (function 
and objects of REBOL) for users of programs created by REBOL/SDK 
(in other words, you allow users of your programs to write and execute 
REBOL scripts within your program), you must obtain a separate commercial 
distribution license from REBOL Technologies. If your program does 
not allow users to access the REBOL API, then no additional license 
is required.
[...]
http://www.rebol.com/docs/sdk/sdkintro.html
So, in fact, it's not forbidden, you just have to "obtain a separate 
commercial distribution license".
Pekr
6-Sep-2010
[8924]
My experience with RT is, that if you try to communicate, you might 
get special deal. So - maybe /Command is no more a source of revenue 
stream for RT. What about asking them to relax the restrictions?
Dockimbel
6-Sep-2010
[8925]
Pekr, feel free to ask.
Pekr
6-Sep-2010
[8926]
Doc - I think you guys might be wrong, no? IMO the restriction applies 
to app, directly exposing REBOL scripts. Does encapped Cheynne does 
so? Can we regard CGI being such an exposure? Is it identical to 
doing a script "normal way"?
Dockimbel
6-Sep-2010
[8927x3]
Pekr, the definition : "(in other words, you allow users of your 
programs to write and execute REBOL scripts within your program)" 
seems broad enough to me to include CGI. But as I'm not a native 
english speaker, I might understand it wrongly.
*I might not
damn...shouldn't chat on more than 3 windows at the same time...:-)
Pekr
6-Sep-2010
[8930]
:-)
Graham
6-Sep-2010
[8931x2]
I discussed this with Carl before and it's okay.
Anyway it seems that restriction is now obsolete as ssl and odbc 
are now free.  And IOS is dead.  The license prevented you from creating 
a clone of IOS
Kaj
6-Sep-2010
[8933x2]
if there are other 
hot" issues to fix in Cheyenne, please let me know."
Doc, how about committing my user/group switching patch? It doesn't 
completely seem to fix the problem yet, but it fixes many bugs on 
the way there
Graham
7-Sep-2010
[8935x7]
I updated to the lastest svn and encapped using encmd.exe from 14 
March 2008
Running from an administrator dos shell, I start cheyenne.
It says on hover, listening on port 8000 and cgi/rsp/html work
I click on the run as service and it changes to "Cheyenne is running" 
with no port now specifed.  Html/rsp and cgi all now fail.
This is on windows 7
If anyone wants to test it .. http://www.compkarori.com/cheyenne/cheyenne.exe
Once I switch it back to a user application using the menu, it starts 
to work again
Dockimbel
7-Sep-2010
[8942]
I confirm this behaviour, but if you launch Cheyenne by using right-click 
on cheyenne.exe and select "Run as administrator", then once in service 
mode, it works ok.
Graham
7-Sep-2010
[8943]
Yes, though oddly that's is what I first tried and it didn't work. 
 Which is why I switched to running from the dos shell.  Maybe I 
didn't get the right sequence!
Dockimbel
7-Sep-2010
[8944x2]
Kaj: I can't find your patch, can you give me any pointer to your 
code? IIRC, there was some hard-to-fix issues with running in user-mode, 
like not being able to use the verbose/debug/trace mode anymore.
*there were
Kaj
7-Sep-2010
[8946x3]
It's above here, at May 11:
--- mod-userdir.r.original	2010-05-09 19:28:10.000000000 +0200
+++ mod-userdir.r	2010-05-11 00:45:24.000000000 +0200
@@ -12,40 +12,81 @@
 	on-started: does [do boot-code]
 	on-reload:  does [clear boot-code]
 	
-	get-ugid: func [name [string!] /local file uid gid][
-		if none? attempt [file: read %/etc/passwd][
+	get-ugid: func [name [string!] /local file line uid gid][
+		unless attempt [file: read/lines %/etc/passwd][
 			log/error "accessing /etc/passwd failed"
 			return none
 		]
-		unless parse/all file [
-			thru name 2 [thru col]
-			copy uid to col skip
-			copy gid to col
-			to end
-		][
-			log/error "reading /etc/passwd failed"
+		foreach line file [
+			if all [line: find/case/match line name  col = first line][
+				return either parse/all next line [
+					thru col
+					copy uid to col skip
+					copy gid to col
+					to end
+				][
+					reduce [to-integer uid to-integer gid]
+				][
+					log/error "invalid format reading /etc/passwd !"
+					none
+				]
+			]
+		]
+		log/error "user not found in /etc/passwd"
+		none
+	]
+	
+	get-gid: func [name [string!] /local file line gid][
+		unless attempt [file: read/lines %/etc/group][
+			log/error "accessing /etc/group failed"
 			return none
 		]
-		reduce [to-integer uid to-integer gid]
+		foreach line file [
+			if all [line: find/case/match line name  col = first line][
+				return either parse/all next line [
+					thru col
+					copy gid to col
+					to end
+				][
+					to-integer gid
+				][
+					log/error "invalid format reading /etc/group !"
+					none
+				]
+			]
+		]
+		log/error "group not found in /etc/group"
+		none
 	]
 	
-	change-id: func [id [word! integer!] /user /group][
-		if word? id [
-			if none? id: get-ugid mold id [return none]
-			id: pick id to-logic user

+	change-id: func [id [string! integer!] /user /group /local gid][
+		either string? id [
+			unless id: get-ugid id [return none]
+			set [id gid] id
+		][
+			gid: id
 		]
-		either user [
+		if group [setgid gid]
+		if user [
 			;logger/file.log: join logger/file ["-" id %.log]
 			setuid id
-		][setgid id]
+		]
+	]
+	
+	change-gid: func [id [string! integer!]][
+		if string? id [
+			unless id: get-gid id [return none]
+		]
+		setgid id
 	]
 	
 	words: [
 		user: [word! | integer!] in globals do [
-			repend boot-code ['change-id/user to-lit-word args/1]

+			repend boot-code either word? args/1 [['change-id/user/group 
mold args/1]] [['change-id/user args/1]]
 		]
 		group: [word! | integer!] in globals do [
-			repend boot-code ['change-id/group to-lit-word args/1]
+			unless empty? boot-code [change boot-code [change-id/user]]

+			insert boot-code reduce ['change-gid either word? args/1 [mold 
args/1][args/1]]
 		]
 	]
 ]
\ No newline at end of file
I don't know why that would break debugging, so that sounds like 
an extra issue
Dockimbel
7-Sep-2010
[8949]
Because Cheyenne must start as root user to be able to open listen 
ports < 1024, then only, SU to a non-root user. Unfortunately, all 
the log files generated during the root phase of Cheyenne's boot 
process are owned by root, so can't be used anymore once su-ed to 
a non-root user. An easy way to fix that (but looks a bit ugly to 
me) could be to chown( ) / chgrp( ) all generated log files before 
giving up root rights...A cleaner way would involve rethinking the 
whole boot up process of Cheyenne and Uniserve with deep code architecture 
impacts (too much work). Any idea on the best way to solve these 
issues are welcome.