home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 July / INTERNET105.ISO / pc / software / windows / messages / roger_wilco / rw_mk1d3.exe / JOIN1.RWC < prev    next >
Encoding:
Text File  |  1999-08-26  |  3.6 KB  |  131 lines

  1. #!/usr/bin/perl
  2. # Edit the above line if you must to locate the perl interpreter on your server
  3. # this file should have suitable permissions so it can be invoked by the web server
  4. # (compare with other scripts in your cgi-bin directory)
  5.  
  6. # join1.rwc -- a Perl script for tuning Roger Wilco (RW Mark Ia or later, rwbs version 0.27 or later)
  7.  
  8. # This script should reside in the cgi-bin directory for your web server
  9. # it is accessed via a web link and dynamically creates output to simulate a
  10. # .RWC file with contents to suit the specified parameters (RWBS address and optional
  11. # channel name and password)
  12.  
  13. # File version:  1    Aug 26 1999
  14.  
  15. # usage:  link to it from HTML, and supply the following parameters:
  16. # rwbs      the IP address or hostname of the RWBS you wish to connect to (required)
  17. # channel   the name of the channel you wish to connect to (optional -- default channel assumed)
  18. # passwd    the password to be used (optional)
  19.  
  20. # e.g.:  <a href="http://yoursite.com/cgi-bin/join1.rwc?rwbs=mybox.mysite.com&channel=attack">click here</a>
  21.  
  22. # This script is provided on an as-is basis by Resounding Technology
  23. # Copyright 1999, Resounding Technology, Inc.
  24.  
  25. use POSIX;
  26.  
  27. sub CGIReadParse {
  28.     local (*in) = @_ if @_;
  29.     local ($i, $loc, $key, $val, $ispath);
  30.  
  31.     $ispath = 0;
  32.     # Read in text
  33.     if ($ENV{'REQUEST_METHOD'} eq "GET") {
  34.         $in = $ENV{'QUERY_STRING'};
  35.         if (!$in) {
  36.             $in = $ENV{'PATH_INFO'};
  37.             $in =~ s/^.(.*)$/$1/;
  38.             $ispath = 1;
  39.         }
  40.     } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
  41.         read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
  42.     }
  43.  
  44.     if ($ispath) {
  45.         @in = split(/\//,$in);
  46.     } else {
  47.         @in = split(/&/,$in);
  48.     }
  49.  
  50.     foreach $i (0 .. $#in) {
  51.         # Convert plus's to spaces
  52.         $in[$i] =~ s/\+/ /g;
  53.  
  54.         # Split into key and value.
  55.         ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
  56.  
  57.         # Convert %XX from hex numbers to alphanumeric
  58.         $key =~ s/%(..)/pack("c",hex($1))/ge;
  59.         $val =~ s/%(..)/pack("c",hex($1))/ge;
  60.  
  61.         # Associate key and value
  62.         $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
  63.         $in{$key} .= $val;
  64.     
  65.     }
  66.  
  67.     $cookie_line = $ENV{'HTTP_COOKIE'};
  68.     $cookie_line =~ tr/ //d;
  69.     @cookie_lines = split(/;/,$cookie_line);
  70.  
  71.     foreach $i (0 .. $#cookie_lines) {
  72.         # Convert plus's to spaces
  73.         $cookie_lines[$i] =~ s/\+/ /g;
  74.  
  75.         # Split cookieto key and value.
  76.         ($key, $val) = split(/=/,$cookie_lines[$i],2); # splits on the first =.
  77.  
  78.         # Convert %XX from hex numbers to alphanumeric
  79.         $key =~ s/%(..)/pack("c",hex($1))/ge;
  80.         $val =~ s/%(..)/pack("c",hex($1))/ge;
  81.  
  82.         # Associate key and value
  83.         $cookie{$key} .= "\0" if (defined($cookie{$key})); # \0 is the multiple separator
  84.         $cookie{$key} .= $val;
  85.     }
  86.  
  87.     return 1;
  88. }
  89.  
  90.  
  91. &CGIReadParse;
  92.  
  93. $rwbs=$in{'rwbs'};
  94. $channel=$in{'channel'};
  95. $passwd=$in{'passwd'};
  96.  
  97. if (length($rwbs) == 0) {
  98.   print "Content-type: text/html
  99.  
  100. <HTML>
  101. <font size=4 color='ff0000'>You did not specify a Roger Wilco Base Station (rwbs).
  102. </html>
  103. ";
  104.   exit 1;
  105. }
  106.  
  107. if (length($channel) == 0 && length($passwd) > 0) {
  108.     $channel = "DEFAULT";
  109. }
  110.  
  111. # converting / chars to _ to avoid confusing RW (/ is switch char)
  112. #$channel =~ tr/\//_/;    
  113.  
  114. # if there is a :__, remove it and any preface
  115. #$channel =~ s/.*\:__//;    
  116. $channel =~ s/.*\:\/\///;    
  117.  
  118. # replace any remaining :'s with _
  119. $channel =~ s/\:/_/g;    
  120.  
  121. # if there is a colon, remove it and any preface
  122. $channel =~ tr/[A-Z]/[a-z]/;    
  123.  
  124. print "Content-type: application/x-rogerwilco
  125.  
  126.  
  127. /join1 $rwbs $channel $passwd
  128. ";
  129.  
  130. exit 0;
  131.