# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Given a config-file path and a host name, we extract the info from the file # # and save it is @cfg. We also look for a few specific lines and save their # # data in some other global arrays. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Read the config file for a host. sub cfgload { local($cfile,$host) = @_; local($cfg,$flg,$line,$opt); my $F='cfgload'; my $X='cfgload'; @cfg = (); unless (open(CFG,$cfile)) { print V "$F: Can't read config file \"$cfile\" ($!)\n" if $V>1; return undef; } print V "$F: Reading config info from \"$cfile\"\n" if $V>2; for $line () { $line =~ s/[\s\r]+$//; print V "$F: line=\"$line\"\n" if $V>2; if ($line =~ /^[+0-9]*\s*(C:)\s*(.*)/) { # C: command to get file $Getcmd{"$1$host"} = $2; print V "$F: Get command \"$2\" for $host (from cfg file)\n" if $V>2; } elsif ($line =~ /^[+0-9]*\s*(D:)\s*(\d+)/) { # D: Depth limit $DepthHost{$host} = $2; print V "$F: Depth limit \"$2\" for $host (from cfg file)\n" if $V>2; } elsif ($line =~ /^[+0-9]*\s*(L:)\s*(\d+)/) { # L: Line max before giving up $maxlines = $2; print V "$F: maxlines=$maxlines for $host (from cfg file)\n" if $V>2; } elsif (($cfg,$flg,$opt) = ($line =~ /^[+\d]*\s*(\w):\s*([-+]*)(.+)/)) { # X:name print V "$F: $cfg: '$flg' \"$opt\" option.\n" if $V>2; if ($cfg eq 'O') { print V "$F: O: '$flg' \"$opt\" option.\n" if $V>2; if ($opt =~ /^(CGI|tagP)$/i) { # On/off controls print V "$F: Set $opt option to '$flg'\n" if $V>2; $Opt{$opt} = $flg; # Remember this option's on/off flag } elsif ($opt =~ /^U(\d+)$/i) { # URL limit $maxurls = int($1); print V "$F: Limit to maxurls=$maxurls URLs\n" if $V>1; } else { print V "$F: Unrecognized option '$opt' in \"$line\"\n" if $V>1; } } else { print V "$F: Unrecognized config command '$cfg' in \"$line\"\n" if $V>1; } } elsif ($line =~ /^Disallow:*\s*(.*)$/) { if ($1) { $Disallow{$1}++; $hstmsg = "Disallow \"$1\""; print V "$F: $hstmsg\n" if $V>0; } } else { print V "$F: Config line \"$line\" not matched.\n" if $V>1; } push @cfg, $line; } close CFG; return 1; } 1;