Allow synonyms for localhost
[spider.git] / perl / DXCommandmode.pm
index f6d890b17c5919eb74254854fa7d77aea04b1c9f..ffad39cf1506a6ced64cb3e948d1498a7a4605af 100644 (file)
@@ -49,7 +49,8 @@ use DXCIDR;
 
 use strict;
 use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase %nothereslug
-       $maxbadcount $msgpolltime $default_pagelth $cmdimportdir $users $maxusers);
+       $maxbadcount $msgpolltime $default_pagelth $cmdimportdir $users $maxusers
+);
 
 %Cache = ();                                   # cache of dynamically loaded routine's mod times
 %cmd_cache = ();                               # cache of short names
@@ -74,8 +75,9 @@ sub new
        # routing, this must go out here to prevent race condx
        my $pkg = shift;
        my $call = shift;
-#      my @rout = $main::routeroot->add_user($call, Route::here(1));
-       DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $self->hostname], );
+       #       my @rout = $main::routeroot->add_user($call, Route::here(1));
+       my $ipaddr = alias_localhost($self->hostname);
+       DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $ipaddr], );
 
        # ALWAYS output the user
        my $ref = Route::User::get($call);
@@ -348,7 +350,7 @@ sub normal
                        my $sendit = $cmdline =~ s|^/+||;
                        if (@bad = BadWords::check($cmdline)) {
                                $self->badcount(($self->badcount||0) + @bad);
-                               LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with words: '" . join(',', @bad) . "'");
+                               LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with badwords: '" . join(',', @bad) . "'");
                        } else {
                                my @in = $self->run_cmd($cmdline);
                                $self->send_ans(@in);
@@ -369,7 +371,7 @@ sub normal
                        # send what has been said to whoever is in this person's talk list
                        if (@bad = BadWords::check($cmdline)) {
                                $self->badcount(($self->badcount||0) + @bad);
-                               LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with words: '" . join(',', @bad) . "'");
+                               LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with badwords: '" . join(',', @bad) . "'");
                        } else {
                                for (@{$self->{talklist}}) {
                                        if ($self->{state} eq 'talk') {
@@ -401,12 +403,12 @@ sub normal
                }
                $self->send_ans(@ans);
        } else {
-               if (@bad = BadWords::check($cmdline)) {
-                       $self->badcount(($self->badcount||0) + @bad);
-                       LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with words: '" . join(',', @bad) . "'");
-               } else {
+#              if (@bad = BadWords::check($cmdline)) {
+#                      $self->badcount(($self->badcount||0) + @bad);
+#                      LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with badwords: '" . join(',', @bad) . "'");
+#              } else {
                        $self->send_ans(run_cmd($self, $cmdline));
-               }
+#              }
        } 
 
        # check for excessive swearing
@@ -1438,5 +1440,20 @@ sub user_count
     return ($users, $maxusers);
 }
 
+# alias localhost if required. This is designed to repress all localhost and other
+# internal interfaces to a fixed (outside) IPv4 or IPV6 address
+sub alias_localhost
+{
+       my $hostname = shift;
+       if ($hostname =~ /./) {
+               return $hostname unless $main::localhost_alias_ipv4;
+               return (grep $hostname eq $_, @main::localhost_names) ? $main::localhost_alias_ipv4 : $hostname;
+       } elsif ($hostname =~ /:/) {
+               return $hostname unless $main::localhost_alias_ipv6;
+               return (grep $hostname eq $_, @main::localhost_names) ? $main::localhost_alias_ipv6 : $hostname;
+       }
+       return $hostname;
+}
+
 1;
 __END__