View previous topic :: View next topic |
How do you rate this? (5=very good, 1=very bad) |
1 |
|
0% |
[ 0 ] |
2 |
|
0% |
[ 0 ] |
3 |
|
0% |
[ 0 ] |
4 |
|
20% |
[ 1 ] |
5 |
|
80% |
[ 4 ] |
|
Total Votes : 5 |
|
Author |
Message |
b123 -
Joined: 12 Oct 2004 Posts: 9
|
Posted: Sat Feb 05, 2005 5:25 am Post subject: WSF files as CGIs... (Windows Scripting Host files) |
|
|
How to use .wsf files as CGIs in the beta version of Abyss
1. Go to the "Scripting Parameters" section of the "Default Host"'s console.
2. Click on "Add" in the Interpreters table.
3. Enter "C:\windows\system32\cscript.exe" (or your path to CSCRIPT) in Interpreter. (without the quotes)
4. Enter "%1 //nologo //Job:CGIMain" in Arguments. (without the quotes)
5. Set the type to Standard.
6. Check "Use the associated extensions to automatically update the Script Paths"
7. Enter "wsf" to the Associated Extensions.
8. Click OK
9. Add "index.wsf" to the Index Files section, click OK
10. Click "Restart" to restart
How to use .wsf files
A sample WSF file:
Code: |
<job id="CGIMain">
<script language="JScript">
function Send(s) {WScript.StdOut.Write(s);}
</script>
<script language="VBScript">
Send "Content-Type: text/html" & vbcrlf & vbcrlf
Send "<html><head><title>Hello, world!</title></head><body>"
Send "<h1>Hello, CGI world from WSF!</h1>"
Send "</body></html>"
</script>
</job>
|
You may want to write a library that processes GET and POST requests. You can write it in JScript, VBScript, or Perlscript (get Perlscript from http://www.activestate.com/Perl.plex) You can use any combination of these 3 languages, or any ActiveX WSH language engines.
To include external script files (example: a CGI library), use this code
Code: | <script language="language engine" src="full script path" /> |
in the <job> tag. |
|
Back to top |
|
|
EricPhelps -
Joined: 25 Mar 2005 Posts: 3 Location: California, USA
|
Posted: Fri Mar 25, 2005 10:57 pm Post subject: |
|
|
Here's some sample VBS code for handling the GET method. It includes setting and reading cookies and displaying server variables:
http://www.ericphelps.com/scripting/samples/Reference/CGI_DB/Cgi.txt
B123's directions also apply to making VBS or JS code run as a a CGI script without the WSF wrapper in the (non-beta) version 2 Abyss. Just don't use the "//Job:CGIMain" argument portion and add VBS and/or JS (as desired) as associated extensions.
If you bump up one folder to:
http://www.ericphelps.com/scripting/samples/Reference/CGI_DB/
you'll find other VBS sample code handy for using WSF as a CGI script.
Why use WSF/VBS/JS? Because you don't need to install anything or learn anything (if you're already familiar with VB or JavaScript). I can carry the abyssws.exe program and it's conf file on my USB key. If I have some WSF CGIs on the key as well, I know any Windows box I plug the key into will run them. I can't say the same about PHP or Perl CGI scripts. Besides, VBS code is very similar to ASP code. Duh! More code samples to steal from.
When using WSF files, you will want to add a bit more if your sample becomes more complex (like the example URL above). Specifically:
<?xml version="1.0"?>
<package>
<job id="CGIMain">
<script language="VBScript">
<![CDATA[
'INSERT YOUR VBS CODE HERE
]]>
</script>
</job>
</package>
You need the CDATA section to allow your code to not break the XML, and you need to specify the XML version in order to use the CDATA. The "package" tags aren't actually needed.
You'll notice (if you look) b123 used "Wscript.StdOut.Write" to take output from the script and push it out. My scripts tend to use "Wscript.Echo". The big difference is in how they fail if you foolishly use WSCRIPT instead of CSCRIPT. Honestly, I like b123's use of StdOut better than my Echo. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|