]> git.donarmstrong.com Git - infobot.git/blobdiff - src/DynaConfig.pl
converted %{$blah{$blah}} to %{ $blah{$blah} }
[infobot.git] / src / DynaConfig.pl
index 0a83d217a2393e4821340e8ca14b9be2935e9766..e23edf0bec8d23df2ecacc7936b267aef5ee89ed 100644 (file)
@@ -13,7 +13,18 @@ if (&IsParam("useStrict")) { use strict; }
 #####
 
 sub readUserFile {
-    if (!open IN,"$bot_misc_dir/blootbot.users") {
+    my $f = "$bot_misc_dir/blootbot.users";
+
+    if ( -f $f and -f "$f~") {
+       my $s1 = -s $f;
+       my $s2 = -s "$f~";
+
+       if ($s2 > $s1*3) {
+           &DEBUG("rUF: backup file bigger than current file. FIXME");
+       }
+    }
+
+    if (!open IN, $f) {
        &ERROR("cannot read userfile.");
        &closeLog();
        exit 1;
@@ -96,6 +107,11 @@ sub readUserFile {
 }
 
 sub writeUserFile {
+    if (!scalar keys %users) {
+       &DEBUG("wUF: nothing to write.");
+       return;
+    }
+
     if (!open OUT,">$bot_misc_dir/blootbot.users") {
        &ERROR("cannot write to userfile.");
        return;
@@ -200,7 +216,17 @@ sub writeUserFile {
 #####
 
 sub readChanFile {
-    if (!open IN,"$bot_misc_dir/blootbot.chan") {
+    my $f = "$bot_misc_dir/blootbot.chan";
+    if ( -f $f and -f "$f~") {
+       my $s1 = -s $f;
+       my $s2 = -s "$f~";
+
+       if ($s2 > $s1*3) {
+           &DEBUG("rCF: backup file bigger than current file. FIXME");
+       }
+    }
+
+    if (!open IN, $f) {
        &ERROR("cannot erad chanfile.");
        return;
     }
@@ -225,7 +251,10 @@ sub readChanFile {
            $chanconf{$chan}{$1} = 1;
 
        } elsif (/^[\s\t]+\-(\S+)$/) {          # bool, false.
-           $chanconf{$chan}{$1} = 0;
+           &DEBUG("deprecated support of negative options.") unless ($cache{negative});
+           # although this is supported in run-time configuration.
+           $cache{negative} = 1;
+#          $chanconf{$chan}{$1} = 0;
 
        } elsif (/^[\s\t]+(\S+)[\ss\t]+(.*)$/) {# what = val.
            $chanconf{$chan}{$1} = $2;
@@ -247,10 +276,17 @@ sub readChanFile {
        }
     }
 
+    delete $cache{negative};
+
     &status("CHANFILE: Loaded: ".(scalar(keys %chanconf)-1)." chans");
 }
 
 sub writeChanFile {
+    if (!scalar keys %chanconf) {
+       &DEBUG("wCF: nothing to write.");
+       return;
+    }
+
     if (!open OUT,">$bot_misc_dir/blootbot.chan") {
        &ERROR("cannot write chanfile.");
        return;
@@ -302,8 +338,8 @@ sub writeChanFile {
            }
        }
 
-       &DEBUG("chans => ".scalar(keys %chanconf)." - 1");
        foreach (keys %opts) {
+           next unless ($opts{$_} > 1);
            &DEBUG("  opts{$_} => $opts{$_}");
        }
 
@@ -381,7 +417,7 @@ sub verifyUser {
     foreach $user (keys %users) {
        next if ($user eq "_default");
 
-       foreach $m (keys %{$users{$user}{HOSTS}}) {
+       foreach $m (keys %{ $users{$user}{HOSTS} }) {
            $m =~ s/\?/./g;
            $m =~ s/\*/.*?/g;
            $m =~ s/([\@\(\)\[\]])/\\$1/g;
@@ -422,9 +458,14 @@ sub ckpasswd {
     return 0 unless ($plain ne "" and $encrypted ne "");
 
     # MD5 // DES. Bobby Billingsley++.
-    my $salt = substr($encrypted, 0, 2);
-    if ($encrypted =~ /^\$\d\$(\w\w)\$/) {
+    my $salt;
+    if ($encrypted =~ /^(\S{2})/ and length $encrypted == 13) {
+       $salt = $1;
+    } elsif ($encrypted =~ /^\$\d\$(\w\w)\$/) {
        $salt = $1;
+    } else {
+       &DEBUG("unknown salt from $encrypted.");
+       return 0;
     }
 
     return ($encrypted eq crypt($plain, $salt));
@@ -542,6 +583,19 @@ sub banAdd {
                exists $bans{'*'}{$mask});
     $bans{$chan}{$mask} = [$expire, time(), 0, $who, $reason];
 
+    my @chans  = ($chan eq "*") ? keys %channels : $chan;
+    my $m      = $mask;
+    $m         =~ s/\?/\\./g;
+    $m         =~ s/\*/\\S*/g;
+    foreach (@chans) {
+       my $chan = $_;
+       foreach (keys %{ $channels{$chan}{''} }) {
+           next unless (exists $nuh{lc $_});
+           next unless ($nuh{lc $_} =~ /^$m$/i);
+           &FIXME("nuh{$_} =~ /$m/");
+       }
+    }
+
     if ($exist == 1) {
        $utime_userfile = time();
        $ucount_userfile++;
@@ -628,38 +682,47 @@ sub chanSet {
 
     my $update = 0;
 
-    if (defined $what and $what =~ s/^\+(\S+)/$1/) {
-       my $was = $chanconf{$chan}{$1};
-       if (defined $was and $was eq "1") {
-           &pSReply("setting $what for $chan already 1.");
-           return;
-       }
+    ### ".chanset +blah"
+    ### ".chanset +blah 10"            -- error.
+    if (defined $what and $what =~ s/^([+-])(\S+)/$2/) {
+       my $state       = ($1 eq "+") ? 1 : 0;
+       my $was         = $chanconf{$chan}{$what};
 
-       $was    = ($was) ? "; was '$was'" : "";
-       &pSReply("Setting $what for $chan to '1'$was.");
+       if ($state) {                   # add/set.
+           if (defined $was and $was eq "1") {
+               &pSReply("setting $what for $chan already 1.");
+               return;
+           }
 
-       $chanconf{$chan}{$what} = 1;
+           $was        = ($was) ? "; was '$was'" : "";
+           $val        = 1;
 
-       $update++;
-    } elsif (defined $what and $what =~ s/^\-(\S+)/$1/) {
-       my $was = $chanconf{$chan}{$1};
-       # hrm...
-       if (!defined $was) {
-           &pSReply("setting $what for $chan is not set.");
-           return;
-       }
+       } else {                        # delete/unset.
+           if (!defined $was) {
+               &pSReply("setting $what for $chan is not set.");
+               return;
+           }
 
-       if ($was eq "0") {
-           &pSReply("setting $what for $chan already 0.");
-           return;
-       }
+           if ($was eq "0") {
+               &pSReply("setting $what for $chan already 0.");
+               return;
+           }
 
-       $was    = ($was) ? "; was '$was'" : "";
-       &pSReply("Setting $what for $chan to '0'$was.");
+           $was        = ($was) ? "; was '$was'" : "";
+           $val        = 0;
+       }
 
-       $chanconf{$chan}{$what} = 0;
+       if ($val eq "0") {
+           &pSReply("Unsetting $what for $chan$was.");
+           delete $chanconf{$chan}{$what};
+       } else {
+           &pSReply("Setting $what for $chan to '$val'$was.");
+           $chanconf{$chan}{$what}     = $val;
+       }
 
        $update++;
+
+    ### ".chanset blah testing"
     } elsif (defined $val) {
        my $was = $chanconf{$chan}{$what};
        if (defined $was and $was eq $val) {
@@ -672,7 +735,15 @@ sub chanSet {
        $chanconf{$chan}{$what} = $val;
 
        $update++;
+
+    ### ".chanset"
+    ### ".chanset blah"
     } else {                           # read only.
+       if (!defined $what) {
+           &WARN("chanset/DC: what == undefine.");
+           return;
+       }
+
        if (exists $chanconf{$chan}{$what}) {
            &pSReply("$what for $chan is '$chanconf{$chan}{$what}'");
        } else {
@@ -683,32 +754,6 @@ sub chanSet {
     if ($update) {
        $utime_chanfile = time();
        $ucount_chanfile++;
-       return;
-    }
-
-    ### TODO: move to UserDCC again.
-    if ($cmd eq "chanset" and !defined $what) {
-       &DEBUG("showing channel conf.");
-
-       foreach $chan ($chan, "_default") {
-           &pSReply("chan: $chan");
-           ### TODO: merge 2 or 3 per line.
-           my @items;
-           my $str = "";
-           foreach (sort keys %{ $chanconf{$chan} }) {
-               my $newstr = join(', ', @items);
-               if (length $newstr > 60) {
-                   &pSReply("    $str");
-                   @items = ();
-               }
-               $str = $newstr;
-               push(@items, "$_ => $chanconf{$chan}{$_}");
-           }
-
-           &pSReply("    $str") if (@items);
-       }
-
-       return;
     }
 
     return;
@@ -724,6 +769,10 @@ my @regFlagsChan = (
 ### TODO: finish off this list.
 );
 
-my @regFlagsUser = ("mno");    # todo...
+my @regFlagsUser = (
+       "m",            # master
+       "n",            # owner
+       "o",            # op
+);     # todo...
 
 1;