X-Git-Url: https://code.wpia.club/?p=motion.git;a=blobdiff_plain;f=motion.py;h=0156ba3aa6a4b85498ac87e63ba6b4d552b7b1b0;hp=51ec30bc795d9782fce9eb6a1aed42e33d9c0c4d;hb=refs%2Fheads%2Fmaster;hpb=11e82f491ae15d3b7d9f1f88db2ab79d1fe131bf diff --git a/motion.py b/motion.py index 51ec30b..0156ba3 100644 --- a/motion.py +++ b/motion.py @@ -62,6 +62,7 @@ class ConfigProxy: prefix = ConfigProxy("GROUP_PREFIX") times = ConfigProxy("DURATION") debuguser = ConfigProxy("DEBUGUSER") +motion_wait_minutes = ConfigProxy("MOTION_WAIT_MINUTES") max_proxy=app.config.get("MAX_PROXY") @@ -157,7 +158,7 @@ def init_footer_variables(): footer = dict( version_year=version_year, copyright_link=app.config.get("COPYRIGHTLINK"), copyright_name=app.config.get("COPYRIGHTNAME"), - imprint_link=app.config.get("DATAPROTECTIONLINK"), + imprint_link=app.config.get("IMPRINTLINK"), dataprotection_link=app.config.get("DATAPROTECTIONLINK") ) ) @@ -268,6 +269,17 @@ def init_db(): init_db() +def is_in_ratelimit(group): + rv = get_db().prepare("SELECT EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - posed)) AS timedifference FROM motion WHERE type=$1 AND host=$2 ORDER BY posed DESC LIMIT 1")(group, request.host) + if len(rv) == 0: + return True + rate_limit = motion_wait_minutes.per_host + if rate_limit is None: + rate_limit = 0 + if rv[0]['timedifference'] > rate_limit*60: + return True + else: + return _('Error, time between last motion to short. The current setting is %s minute(s).') % (str(rate_limit)) @app.route("/") def main(): @@ -321,6 +333,9 @@ def put_motion(): content=content.strip() if content =='': return _('Error, missing content'), 400 + ratelimit = is_in_ratelimit(cat) + if ratelimit is not True: + return ratelimit, 400 db = get_db() with db.xact():