Codebase list policyd-rate-limit / 2056f64
Imported Upstream version 0.6.2 SVN-Git Migration 6 years ago
10 changed file(s) with 86 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
00 Metadata-Version: 1.1
11 Name: policyd-rate-limit
2 Version: 0.6.1
2 Version: 0.6.2
33 Summary: Postfix rate limit policy server implemented in Python3.
44 Home-page: https://github.com/nitmir/policyd-rate-limit
55 Author: Valentin Samir
99 Description: Policyd rate limit
1010 ==================
1111
12
13 .. image:: https://img.shields.io/pypi/v/policyd-rate-limit.svg
14 :target: https://pypi.python.org/pypi/policyd-rate-limit
15
16 .. image:: https://img.shields.io/pypi/l/policyd-rate-limit.svg
17 :target: https://www.gnu.org/licenses/gpl-3.0.html
12 |github_version| |pypi_version| |license|
1813
1914 Postfix policyd server allowing to limit the number of mails accepted by
2015 postfix over several time periods, by sasl usernames and/or ip addresses.
3934 * `mysqldb <https://pypi.python.org/pypi/MySQL-python>`_
4035 (``sudo apt-get install python3-mysqldb`` on debian like systems) for the mysql backend.
4136 * `psycopg2 <https://pypi.python.org/pypi/psycopg2>`_
42 (``sudo apt-get install python3-psycopg2`` on debian like systems) fot the postgreysql backend
37 (``sudo apt-get install python3-psycopg2`` on debian like systems) fot the postgresql backend
4338
4439 Install with pip::
4540
7873 The default is ``"/var/run/policyd-rate-limit/policyd-rate-limit.pid"``.
7974 ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists.
8075 * ``mysql_config``: The config to connect to a mysql server
81 * ``pgsql_config``: The config to connect to a postgreysql server
76 * ``pgsql_config``: The config to connect to a postgresql server
8277 * ``sqlite_config``: The config to connect to a sqlite3 database.
8378 * ``backend``: Which data backend to use. Possible values are ``0`` for sqlite3, ``1`` for mysql
84 and ``2`` for postgreysql. The default is ``0``, use the sqlite3 backend.
79 and ``2`` for postgresql. The default is ``0``, use the sqlite3 backend.
8580 * ``SOCKET``: The socket to bind to. Can be a path to an unix socket or a couple [ip, port].
8681 The default is ``"/var/spool/postfix/ratelimit/policy"``.
8782 ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists.
149144 check_policy_service unix:ratelimit/policy,
150145 ...
151146
147
148 .. |pypi_version| image:: https://badges.genua.fr/pypi/v/policyd-rate-limit.svg
149 :target: https://pypi.python.org/pypi/policyd-rate-limit
150
151 .. |github_version| image:: https://badges.genua.fr/github/tag/nitmir/policyd-rate-limit.svg?label=github
152 :target: https://github.com/nitmir/policyd-rate-limit/releases/latest
153
154 .. |license| image:: https://badges.genua.fr/pypi/l/policyd-rate-limit.svg
155 :target: https://www.gnu.org/licenses/gpl-3.0.html
156
152157 Keywords: Postfix,rate,limit,email
153158 Platform: UNKNOWN
154159 Classifier: Environment :: No Input/Output (Daemon)
00 Policyd rate limit
11 ==================
22
3
4 .. image:: https://img.shields.io/pypi/v/policyd-rate-limit.svg
5 :target: https://pypi.python.org/pypi/policyd-rate-limit
6
7 .. image:: https://img.shields.io/pypi/l/policyd-rate-limit.svg
8 :target: https://www.gnu.org/licenses/gpl-3.0.html
3 |github_version| |pypi_version| |license|
94
105 Postfix policyd server allowing to limit the number of mails accepted by
116 postfix over several time periods, by sasl usernames and/or ip addresses.
3025 * `mysqldb <https://pypi.python.org/pypi/MySQL-python>`_
3126 (``sudo apt-get install python3-mysqldb`` on debian like systems) for the mysql backend.
3227 * `psycopg2 <https://pypi.python.org/pypi/psycopg2>`_
33 (``sudo apt-get install python3-psycopg2`` on debian like systems) fot the postgreysql backend
28 (``sudo apt-get install python3-psycopg2`` on debian like systems) fot the postgresql backend
3429
3530 Install with pip::
3631
6964 The default is ``"/var/run/policyd-rate-limit/policyd-rate-limit.pid"``.
7065 ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists.
7166 * ``mysql_config``: The config to connect to a mysql server
72 * ``pgsql_config``: The config to connect to a postgreysql server
67 * ``pgsql_config``: The config to connect to a postgresql server
7368 * ``sqlite_config``: The config to connect to a sqlite3 database.
7469 * ``backend``: Which data backend to use. Possible values are ``0`` for sqlite3, ``1`` for mysql
75 and ``2`` for postgreysql. The default is ``0``, use the sqlite3 backend.
70 and ``2`` for postgresql. The default is ``0``, use the sqlite3 backend.
7671 * ``SOCKET``: The socket to bind to. Can be a path to an unix socket or a couple [ip, port].
7772 The default is ``"/var/spool/postfix/ratelimit/policy"``.
7873 ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists.
139134 ...,
140135 check_policy_service unix:ratelimit/policy,
141136 ...
137
138
139 .. |pypi_version| image:: https://badges.genua.fr/pypi/v/policyd-rate-limit.svg
140 :target: https://pypi.python.org/pypi/policyd-rate-limit
141
142 .. |github_version| image:: https://badges.genua.fr/github/tag/nitmir/policyd-rate-limit.svg?label=github
143 :target: https://github.com/nitmir/policyd-rate-limit/releases/latest
144
145 .. |license| image:: https://badges.genua.fr/pypi/l/policyd-rate-limit.svg
146 :target: https://www.gnu.org/licenses/gpl-3.0.html
4848 The configuration to connect to a mysql server. It should be a dictionary of parameters to give
4949 to the MySQLdb.connect function. See the python3-mysqldb documentations.
5050 **pgsql_config**
51 The configuration to connect to a postgreysql server. It should be a dictionary of parameters to give
51 The configuration to connect to a postgresql server. It should be a dictionary of parameters to give
5252 to the psycopg2.connect function. See the python3-psycopg2 documentations.
5353 **sqlite_config**
5454 The configuration to connect to a sqlite3 database. It should be a dictionary of parameters to give
5555 to the sqlite3.connect function. See the python3 documentations.
5656 **backend**
57 Which data backend to use. Possible values are 0 for sqlite3, 1 for mysql and 2 for postgreysql.
57 Which data backend to use. Possible values are 0 for sqlite3, 1 for mysql and 2 for postgresql.
5858 The default is 0, use the sqlite3 backend.
5959 **SOCKET**
6060 The socket to bind to. Can be a path to an unix socket or a couple [ip, port]. The default is
4949 limit_by_sasl = True
5050 limit_by_ip = False
5151
52 limited_netword = [
52 limited_networks = [
5353 ]
5454
5555 # actions return to postfix, see http://www.postfix.org/access.5.html for a list of actions.
3939 limit_by_sasl = True
4040 limit_by_ip = False
4141
42 limited_netword = [
42 limited_networks = [
4343 ]
4444
4545 # actions return to postfix, see http://www.postfix.org/access.5.html for a list of actions.
2020 sqlite_config:
2121 database: "/var/lib/policyd-rate-limit/db.sqlite3"
2222
23 # The config to connect to a postgreysql server.
23 # The config to connect to a postgresql server.
2424 pgsql_config:
2525 database: "database"
2626 user: "username"
2727 password: "*****"
2828 host: "localhost"
2929
30 # Which data backend to use. Possible values are 0 for sqlite3, 1 for mysql and 2 for postgreysql.
30 # Which data backend to use. Possible values are 0 for sqlite3, 1 for mysql and 2 for postgresql.
3131 backend: 0
3232
3333 # The socket to bind to. Can be a path to an unix socket or a couple [ip, port].
5050
5151 # A list of ip networks in cidr notation on which limits are applied. An empty list is equal
5252 # to limit_by_ip: False, put "0.0.0.0/0" and "::/0" for every ip addresses.
53 limited_netword: []
53 limited_networks: []
5454
5555 # If not limits are reach, which action postfix should do.
5656 # see http://www.postfix.org/access.5.html for a list of actions.
7676 sock.bind(config.SOCKET)
7777 if isinstance(config.SOCKET, str):
7878 os.chmod(config.SOCKET, config.socket_permission)
79 sock.listen(1)
79 sock.listen(5)
8080 self.socket_data_read[sock] = []
8181 if config.debug:
8282 sys.stderr.write('waiting for connections\n')
9191 if socket == sock:
9292 connection, client_address = sock.accept()
9393 if config.debug:
94 sys.stderr.write('connection from %s\n' % client_address)
94 sys.stderr.write('connection from %s\n' % (client_address,))
9595 sys.stderr.flush()
9696 self.socket_data_read[connection] = []
9797 # else there is data to read on a client socket
5959 if config_file.endswith(".conf"):
6060 self._config = imp.load_source('config', config_file)
6161 warnings.warn(
62 "New configuration use a .yaml file. "
63 "Please migrate to it and delete you .conf file"
62 (
63 "New configuration use a .yaml file. "
64 "Please migrate to it and delete you .conf file"
65 ),
66 stacklevel=3
6467 )
6568 cache_file = imp.cache_from_source(config_file)
6669 # remove the config pyc file
8992 )
9093 )
9194
92 self.limited_netword = [ip_network(net) for net in self.limited_netword]
95 try:
96 self.limited_networks = [ip_network(net) for net in self.limited_netword]
97 warnings.warn(
98 (
99 "The limited_netword config parameter is deprecated, please use "
100 "limited_networks instead."
101 ),
102 stacklevel=3
103 )
104 except AttributeError:
105 self.limited_networks = [ip_network(net) for net in self.limited_networks]
93106
94107 def __getattr__(self, name):
95108 try:
96109 if self.config_file.endswith(".yaml"):
97 return self._config[name]
110 ret = self._config[name]
98111 else:
99 return getattr(self._config, name)
112 ret = getattr(self._config, name)
100113 # If an parameter is not defined in the config file, return its default value.
101114 except (AttributeError, KeyError):
102 return getattr(default_config, name)
115 ret = getattr(default_config, name)
116
117 if name == "SOCKET":
118 if isinstance(ret, list):
119 ret = tuple(ret)
120
121 return ret
103122
104123
105124 class LazyConfig(object):
273292
274293
275294 def is_ip_limited(ip):
276 """Check if ``ip`` is part of a network of ``config.limited_netword``"""
295 """Check if ``ip`` is part of a network of ``config.limited_networks``"""
277296 try:
278297 ip = ipaddress.IPv4Address(ip)
279298 except ipaddress.AddressValueError:
280299 ip = ipaddress.IPv6Address(ip)
281 for net in config.limited_netword:
300 for net in config.limited_networks:
282301 if ip in net:
283302 return True
284303 return False
387406 msg.attach(MIMEText("\n".join(text), 'plain'))
388407
389408 # check that smtp_server is wekk formated
390 if isinstance(config.smtp_server, tuple):
409 if isinstance(config.smtp_server, (list, tuple)):
391410 if len(config.smtp_server) >= 2:
392411 server = smtplib.SMTP(config.smtp_server[0], config.smtp_server[1])
393412 elif len(config.smtp_server) == 1:
403422 server.starttls()
404423 # should we use credentials ?
405424 if config.smtp_credentials:
406 if isinstance(config.smtp_credentials, tuple) and len(config.smtp_credentials) >= 2:
425 if (
426 isinstance(config.smtp_credentials, (list, tuple)) and
427 len(config.smtp_credentials) >= 2
428 ):
407429 server.login(config.smtp_credentials[0], config.smtp_credentials[1])
408430 else:
409431 ValueError("bad smtp_credentials should be a tuple (login, password)")
00 Metadata-Version: 1.1
11 Name: policyd-rate-limit
2 Version: 0.6.1
2 Version: 0.6.2
33 Summary: Postfix rate limit policy server implemented in Python3.
44 Home-page: https://github.com/nitmir/policyd-rate-limit
55 Author: Valentin Samir
99 Description: Policyd rate limit
1010 ==================
1111
12
13 .. image:: https://img.shields.io/pypi/v/policyd-rate-limit.svg
14 :target: https://pypi.python.org/pypi/policyd-rate-limit
15
16 .. image:: https://img.shields.io/pypi/l/policyd-rate-limit.svg
17 :target: https://www.gnu.org/licenses/gpl-3.0.html
12 |github_version| |pypi_version| |license|
1813
1914 Postfix policyd server allowing to limit the number of mails accepted by
2015 postfix over several time periods, by sasl usernames and/or ip addresses.
3934 * `mysqldb <https://pypi.python.org/pypi/MySQL-python>`_
4035 (``sudo apt-get install python3-mysqldb`` on debian like systems) for the mysql backend.
4136 * `psycopg2 <https://pypi.python.org/pypi/psycopg2>`_
42 (``sudo apt-get install python3-psycopg2`` on debian like systems) fot the postgreysql backend
37 (``sudo apt-get install python3-psycopg2`` on debian like systems) fot the postgresql backend
4338
4439 Install with pip::
4540
7873 The default is ``"/var/run/policyd-rate-limit/policyd-rate-limit.pid"``.
7974 ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists.
8075 * ``mysql_config``: The config to connect to a mysql server
81 * ``pgsql_config``: The config to connect to a postgreysql server
76 * ``pgsql_config``: The config to connect to a postgresql server
8277 * ``sqlite_config``: The config to connect to a sqlite3 database.
8378 * ``backend``: Which data backend to use. Possible values are ``0`` for sqlite3, ``1`` for mysql
84 and ``2`` for postgreysql. The default is ``0``, use the sqlite3 backend.
79 and ``2`` for postgresql. The default is ``0``, use the sqlite3 backend.
8580 * ``SOCKET``: The socket to bind to. Can be a path to an unix socket or a couple [ip, port].
8681 The default is ``"/var/spool/postfix/ratelimit/policy"``.
8782 ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists.
149144 check_policy_service unix:ratelimit/policy,
150145 ...
151146
147
148 .. |pypi_version| image:: https://badges.genua.fr/pypi/v/policyd-rate-limit.svg
149 :target: https://pypi.python.org/pypi/policyd-rate-limit
150
151 .. |github_version| image:: https://badges.genua.fr/github/tag/nitmir/policyd-rate-limit.svg?label=github
152 :target: https://github.com/nitmir/policyd-rate-limit/releases/latest
153
154 .. |license| image:: https://badges.genua.fr/pypi/l/policyd-rate-limit.svg
155 :target: https://www.gnu.org/licenses/gpl-3.0.html
156
152157 Keywords: Postfix,rate,limit,email
153158 Platform: UNKNOWN
154159 Classifier: Environment :: No Input/Output (Daemon)
3636
3737 setup(
3838 name='policyd-rate-limit',
39 version='0.6.1',
39 version='0.6.2',
4040 description=DESC,
4141 long_description=README,
4242 author='Valentin Samir',