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

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