home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 July & August / Pcwk78a98.iso / Internet / Omnihttp / OH20A8.EXE / data1.cab / CGI / Cgi-Bin / statsconfig.pl < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.3 KB  |  206 lines

  1. # Get the input
  2. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  3.  
  4. # Split the name-value pairs
  5. @pairs = split(/&/, $buffer);
  6.  
  7. foreach $pair (@pairs){
  8.    ($name, $value) = split(/=/, $pair);
  9.  
  10.    $value =~ tr/+/ /;
  11.    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  12.    $name =~ tr/+/ /;
  13.    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  14.           
  15.    $FORM{$name} = $value;
  16. }
  17.  
  18. if ($FORM{'deflimit'}) {
  19.     $deflimit_str = '$DEF_lim = ' . $FORM{'deflimit'} . ';';
  20. }
  21. else {
  22.     $deflimit_str = '#$DEF_lim = 500';
  23. }
  24.  
  25. if ($FORM{'mostip'}) {
  26.     $mostip_str = '$most_ip = "' . $FORM{'mostip'} . '";';
  27. }
  28. else {
  29.     $mostip_str = '#most_ip = "off";';
  30. }
  31.  
  32. if ($FORM{'mostreq'}) {
  33.     $mostreq_str = '$most_req = "' . $FORM{'mostreq'} . '";';
  34. }
  35. else {
  36.     $mostreq_str = '#$most_req = "off";';
  37. }
  38.  
  39. if ($FORM{'mostbrowsers'}) {
  40.     $mostbrowsers_str = '$most_browsers = "' . $FORM{'mostbrowsers'} . '";';
  41. }
  42. else {
  43.     $mostbrowsers_str = '#$most_browsers = "off";';
  44. }
  45.  
  46. if ($FORM{'timelog'}) {
  47.     $timelog_str = '$timelogging = "' . $FORM{'timelog'} . '";';
  48. }
  49. else {
  50.     $timelog_str = '#timelogging = "off";';
  51. }
  52.  
  53. if ($FORM{'mostipnum'}) {
  54.     $mostipnum_str = '$most_ip_num = ' . $FORM{'mostipnum'} . ';';
  55. }
  56. elsif ($FORM{'mostip'}) {
  57.     $error .= "<LI>Number of top IP's needs to be positive. If you want it disabled unckeck the apropriate box.";
  58. }
  59. else {
  60.     $mostipnum_str = '$most_ip_num = 0;';
  61. }
  62.  
  63. if ($FORM{'mostbrowsernum'}) {
  64.     $mostbrowsernum_str = '$most_browser_num = ' . $FORM{'mostbrowsernum'} . ';';
  65. }
  66. elsif ($FORM{'mostbrowsers'}) {
  67.     $error .= "<LI>Number of top browsers needs to be positive. If you want it disabled unckeck the apropriate box.";
  68. }
  69. else {
  70.     $mostbrowsernum_str = '$most_browser_num = 0;';
  71. }
  72.  
  73. if ($FORM{'mostreqf'}) {
  74.     $mostreqf_str = '$most_req_f = ' . $FORM{'mostreqf'} . ';';
  75. }
  76. elsif ($FORM{'mostreq'}) {
  77.     $error .= "<LI>Number of top files needs to be positive. If you want it disabled unckeck the apropriate box.";
  78. }
  79. else {
  80.     $mostreqf_str = '$most_req_f = 0;';
  81. }
  82.  
  83.  
  84. if ($FORM{'logloc'}) {
  85.     $logloc_str = '$accesslog = "' . $FORM{'logloc'} . '";';
  86. }
  87. else {
  88.     $error .= "<LI>No access log location specifed.";
  89. }
  90.  
  91. if ($FORM{'imagebar'}) {
  92.     $imagebar_str = '$imagebar = "' . $FORM{'imagebar'} . '";';
  93. }
  94. else {
  95.     $error .= "<LI>No bar image specified.";
  96. }
  97.  
  98. if ($FORM{'serveradd'}) {
  99.     $serveradd_str = '$serveradd = "' . $FORM{'serveradd'} . '";';
  100. }
  101. else {
  102.     $serveradd_str = '$serveradd = "this server";';
  103. }
  104.  
  105. if ($FORM{'barwidth'}) {
  106.     if ($FORM{'barwidth'} > 0) {
  107.         $barwidth_str = '$barwidth = ' . $FORM{'barwidth'} . ';';
  108.     }
  109.     else {
  110.         $error .= "<LI>Bar width needs to be a positive number.";
  111.     }
  112. }
  113. else {
  114.     $error .= "<LI>The bar width needs to be entered.";
  115. }
  116.  
  117. if ($FORM{'barheight'}) {
  118.     if ($FORM{'barheight'} > 0) {
  119.         $barheight_str = '$barheight = ' . $FORM{'barheight'} . ';';
  120.     }
  121.     else {
  122.         $error .= "<LI>Bar height needs to be a positive number.";
  123.     }
  124. }
  125. else {
  126.     $error .= "<LI>The bar height needs to be entered.";
  127. }
  128.  
  129. if ($FORM{'listpass'}) {
  130.     $listpass_str = '$listpass = "' . $FORM{'listpass'} . '";';
  131. }
  132. else {
  133.     $listpass_str = '#listpass = "";';
  134. }
  135.  
  136. if ($FORM{'bgcolor'}) {
  137.     $bgcolor_str = '$bgcolor = "' . $FORM{'bgcolor'} . '";';
  138. }
  139. else {
  140.     $bgcolor_str = '$bgcolor = "#FFFFFF";';
  141. }
  142.  
  143. if ($FORM{'bgimage'}) {
  144.     $bgimage_str = '$bgimage = "' . $FORM{'bgimage'} . '";';
  145. }
  146. else {
  147.     $bgimage_str = '$bgimage = "";';
  148. }
  149.  
  150. if ($FORM{'ttBGcolor'}) {
  151.     $ttBGcolor_str = '$tableTopBGColor = "' . $FORM{'ttBGcolor'} . '";';
  152. }
  153. else {
  154.     $ttBGcolor_str = '$tableTopBGColor = "#ffffdd";';
  155. }
  156.  
  157. if ($FORM{'perllib'}) {
  158.     $perllib_str = 'push(@INC,"'. $FORM{'perllib'} . '");';
  159. }
  160. else {
  161.     $error .= "<LI>You didn't report the location of your perl lib directory.";
  162. }
  163.  
  164. unless ($FORM{'cgidir'}) {
  165.     $error .= "<LI>You didn't report the location of your cgi-bin directory.";
  166. }
  167.  
  168. unless (-f "$FORM{'cgidir'}/stats.prg") {
  169.     $error .= "<LI>Config couldn't find the file stats.prg in your cgi-bin directory.";
  170. }
  171.  
  172. unless (-f "$FORM{'perllib'}/ctime.pl") {
  173.     $error .= "<LI>Config couldn't find ctime.pl in your specifed perl lib directory of $FORM{'perllib'}.";
  174. }
  175.  
  176. print "Content-type: text/html\n\n";
  177.  
  178. if ($error) {
  179.     print "<HTML><H3>Errors: <UL>\n$error</UL><P>Please go back and retry.</H3></HTML>";
  180.     exit();
  181. }
  182.  
  183. $cgifile = "$FORM{'cgidir'}/stats.pl";
  184. $progfile = "$FORM{'cgidir'}/stats.prg";
  185.  
  186. open(CGI, "> $cgifile");
  187. open(PROG, "$progfile");
  188.  
  189. print CGI "#!/usr/local/bin/perl5\n";
  190. print CGI "#AutoConfiged by Statsconfig.pl\n\n";
  191. print CGI "$deflimit_str\n$mostip_str\n$mostreq_str\n$mostbrowsers_str\n$timelog_str\n$mostipnum_str\n$mostreqf_str\n$mostbrowsernum_str\n$logloc_str\n$imagebar_str\n$serveradd_str\n$barwidth_str\n$barheight_str\n$listpass_str\n$bgcolor_str\n$bgimage_str\n$ttBGcolor_str\n\n$perllib_str\n";
  192.  
  193. if ($FORM{'debugon'}) {
  194.     print CGI '$debug = 1;' . "\n";
  195. }
  196.  
  197. print GCI "\n";
  198.  
  199. while (<PROG>) {
  200.     print CGI $_;
  201. }
  202.  
  203. print "<HTML>\n<BODY BGCOLOR=#FFFFFF>\n<center>\n<h2>Stats successfuly configured.</h2>\n",
  204.       "<FORM ACTION=\"/cgi-bin/stats.pl\" METHOD=POST>\n",
  205.       "<INPUT TYPE=\"submit\" VALUE=\"Click here to try it out\">\n",
  206.       "</FORM>\n</center>\n</BODY>\n</HTML>";