logbannedcontent.pl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2008–2015 Alex Schroeder <alex@gu.org>
  2. # Copyright (C) 2004–2005 Fletcher T. Penney <fletcher@freeshell.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. use strict;
  17. use v5.10;
  18. AddModuleDescription('logbannedcontent.pl', 'LogBannedContent Module');
  19. our ($q, $OpenPageName, $Now, $DataDir, $BannedContent);
  20. our ($BannedFile);
  21. $BannedFile = "$DataDir/spammer.log" unless defined $BannedFile;
  22. *LogOldBannedContent = \&BannedContent;
  23. *BannedContent = \&LogNewBannedContent;
  24. sub LogNewBannedContent {
  25. my $str = shift;
  26. my $rule = LogOldBannedContent($str);
  27. LogWrite($rule) if $rule;
  28. return $rule;
  29. }
  30. *LogOldUserIsBanned = \&UserIsBanned;
  31. *UserIsBanned = \&LogNewUserIsBanned;
  32. sub LogNewUserIsBanned {
  33. my $str = shift;
  34. my $rule = LogOldUserIsBanned($str);
  35. LogWrite(Ts('IP number matched %s', $rule)) if $rule;
  36. return $rule;
  37. }
  38. sub LogWrite {
  39. my $rule = shift;
  40. my $id = $OpenPageName || GetId();
  41. AppendStringToFile($BannedFile,
  42. join("\t", TimeToW3($Now), $q->remote_addr(), $id, $rule)
  43. . "\n");
  44. }