From b7a846b35469ee80111e9963265c78501bdc6828 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 30 Sep 2012 12:35:27 -0400 Subject: [PATCH] Added maxchannels variable. --- NEWS | 1 + irkerhook.py | 10 ++++++++++ irkerhook.xml | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/NEWS b/NEWS index 1027355..f964eca 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,7 @@ 1.3 @ Support for an irker.conf file to set irkerhook variables under Subversion. irkerhook.py now has its own manual page. + Added channelmax variable for rate-limiting diff --git a/irkerhook.py b/irkerhook.py index 6a10862..3e13ce2 100755 --- a/irkerhook.py +++ b/irkerhook.py @@ -113,6 +113,7 @@ class GitExtractor: # for spammers' address harvesters - getting this wrong # would make the freenode #commits channel into harvester heaven. self.author = self.author.replace("<", "").split("@")[0].split()[-1] + self.maxchannels = 0 def load_preferences(extractor, conf): "Load preferences from a file in the repository root." @@ -138,6 +139,9 @@ def load_preferences(extractor, conf): val = True if val.lower() == "false": val = False + # User cannot set maxchannels - only a command-line arg can do that. + if fld == "maxchannels": + return setattr(extractor, fld, val) class SvnExtractor: @@ -162,6 +166,7 @@ class SvnExtractor: self.template = '%(project)s: %(author)s %(repo)s * %(rev)s / %(files)s: %(logmsg)s %(url)s' self.urlprefix = "viewcvs" self.tinyifier = default_tinyifier + self.maxchannels = 0 load_preferences(self, os.path.join(self.repository, "irker.conf")) def svnlook(self, info): return do("svnlook %s %s --revision %s" % (shellquote(info), shellquote(self.repository), shellquote(self.commit))) @@ -207,6 +212,7 @@ if __name__ == "__main__": # Each argument of the form = can override the # member of the extractor class. booleans = ["tcp"] + numerics = ["maxchannels"] for tok in arguments: for key in extractor.__dict__: if tok.startswith(key + "="): @@ -216,6 +222,8 @@ if __name__ == "__main__": setattr(extractor, key, True) elif val.lower() == "false": setattr(extractor, key, False) + elif key in numerics: + setattr(extractor, key, int(val)) else: setattr(extractor, key, val) @@ -246,6 +254,8 @@ if __name__ == "__main__": privmsg = extractor.template % extractor.__dict__ channel_list = extractor.channels.split(",") + if extractor.maxchannels != 0: + channel_list = channel_list[:extractor.maxchannels] structure = {"to":channel_list, "privmsg":privmsg} message = json.dumps(structure) if not notify: diff --git a/irkerhook.xml b/irkerhook.xml index d0ea0b7..a4d0019 100644 --- a/irkerhook.xml +++ b/irkerhook.xml @@ -114,6 +114,20 @@ expanded to the value of the "repo" variable. will take up less space in the notification line. + +maxchannels + +Interpreted as an integer. If not zero, limits the number of +channels the hook will interpret from the "channels" variable. + +This variable cannot be set through VCS configuration variables +or irker.conf; it can only be set with a command-line +argument. Thus, on a forge site in which repository owners are not +allowed to modify their post-commit scripts, a site administrator can set it +to prevent shotgun spamming by malicious project owners. Setting it to +a value less than 2, however, would probably be unwise. + + git -- 2.26.2