Imported Upstream version 0.6.2
SVN-Git Migration
6 years ago
0 | 0 | Metadata-Version: 1.1 |
1 | 1 | Name: policyd-rate-limit |
2 | Version: 0.6.1 | |
2 | Version: 0.6.2 | |
3 | 3 | Summary: Postfix rate limit policy server implemented in Python3. |
4 | 4 | Home-page: https://github.com/nitmir/policyd-rate-limit |
5 | 5 | Author: Valentin Samir |
9 | 9 | Description: Policyd rate limit |
10 | 10 | ================== |
11 | 11 | |
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| | |
18 | 13 | |
19 | 14 | Postfix policyd server allowing to limit the number of mails accepted by |
20 | 15 | postfix over several time periods, by sasl usernames and/or ip addresses. |
39 | 34 | * `mysqldb <https://pypi.python.org/pypi/MySQL-python>`_ |
40 | 35 | (``sudo apt-get install python3-mysqldb`` on debian like systems) for the mysql backend. |
41 | 36 | * `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 | |
43 | 38 | |
44 | 39 | Install with pip:: |
45 | 40 | |
78 | 73 | The default is ``"/var/run/policyd-rate-limit/policyd-rate-limit.pid"``. |
79 | 74 | ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists. |
80 | 75 | * ``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 | |
82 | 77 | * ``sqlite_config``: The config to connect to a sqlite3 database. |
83 | 78 | * ``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. | |
85 | 80 | * ``SOCKET``: The socket to bind to. Can be a path to an unix socket or a couple [ip, port]. |
86 | 81 | The default is ``"/var/spool/postfix/ratelimit/policy"``. |
87 | 82 | ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists. |
149 | 144 | check_policy_service unix:ratelimit/policy, |
150 | 145 | ... |
151 | 146 | |
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 | ||
152 | 157 | Keywords: Postfix,rate,limit,email |
153 | 158 | Platform: UNKNOWN |
154 | 159 | Classifier: Environment :: No Input/Output (Daemon) |
0 | 0 | Policyd rate limit |
1 | 1 | ================== |
2 | 2 | |
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| | |
9 | 4 | |
10 | 5 | Postfix policyd server allowing to limit the number of mails accepted by |
11 | 6 | postfix over several time periods, by sasl usernames and/or ip addresses. |
30 | 25 | * `mysqldb <https://pypi.python.org/pypi/MySQL-python>`_ |
31 | 26 | (``sudo apt-get install python3-mysqldb`` on debian like systems) for the mysql backend. |
32 | 27 | * `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 | |
34 | 29 | |
35 | 30 | Install with pip:: |
36 | 31 | |
69 | 64 | The default is ``"/var/run/policyd-rate-limit/policyd-rate-limit.pid"``. |
70 | 65 | ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists. |
71 | 66 | * ``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 | |
73 | 68 | * ``sqlite_config``: The config to connect to a sqlite3 database. |
74 | 69 | * ``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. | |
76 | 71 | * ``SOCKET``: The socket to bind to. Can be a path to an unix socket or a couple [ip, port]. |
77 | 72 | The default is ``"/var/spool/postfix/ratelimit/policy"``. |
78 | 73 | ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists. |
139 | 134 | ..., |
140 | 135 | check_policy_service unix:ratelimit/policy, |
141 | 136 | ... |
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 |
48 | 48 | The configuration to connect to a mysql server. It should be a dictionary of parameters to give |
49 | 49 | to the MySQLdb.connect function. See the python3-mysqldb documentations. |
50 | 50 | **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 | |
52 | 52 | to the psycopg2.connect function. See the python3-psycopg2 documentations. |
53 | 53 | **sqlite_config** |
54 | 54 | The configuration to connect to a sqlite3 database. It should be a dictionary of parameters to give |
55 | 55 | to the sqlite3.connect function. See the python3 documentations. |
56 | 56 | **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. | |
58 | 58 | The default is 0, use the sqlite3 backend. |
59 | 59 | **SOCKET** |
60 | 60 | The socket to bind to. Can be a path to an unix socket or a couple [ip, port]. The default is |
49 | 49 | limit_by_sasl = True |
50 | 50 | limit_by_ip = False |
51 | 51 | |
52 | limited_netword = [ | |
52 | limited_networks = [ | |
53 | 53 | ] |
54 | 54 | |
55 | 55 | # actions return to postfix, see http://www.postfix.org/access.5.html for a list of actions. |
39 | 39 | limit_by_sasl = True |
40 | 40 | limit_by_ip = False |
41 | 41 | |
42 | limited_netword = [ | |
42 | limited_networks = [ | |
43 | 43 | ] |
44 | 44 | |
45 | 45 | # actions return to postfix, see http://www.postfix.org/access.5.html for a list of actions. |
20 | 20 | sqlite_config: |
21 | 21 | database: "/var/lib/policyd-rate-limit/db.sqlite3" |
22 | 22 | |
23 | # The config to connect to a postgreysql server. | |
23 | # The config to connect to a postgresql server. | |
24 | 24 | pgsql_config: |
25 | 25 | database: "database" |
26 | 26 | user: "username" |
27 | 27 | password: "*****" |
28 | 28 | host: "localhost" |
29 | 29 | |
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. | |
31 | 31 | backend: 0 |
32 | 32 | |
33 | 33 | # The socket to bind to. Can be a path to an unix socket or a couple [ip, port]. |
50 | 50 | |
51 | 51 | # A list of ip networks in cidr notation on which limits are applied. An empty list is equal |
52 | 52 | # to limit_by_ip: False, put "0.0.0.0/0" and "::/0" for every ip addresses. |
53 | limited_netword: [] | |
53 | limited_networks: [] | |
54 | 54 | |
55 | 55 | # If not limits are reach, which action postfix should do. |
56 | 56 | # see http://www.postfix.org/access.5.html for a list of actions. |
76 | 76 | sock.bind(config.SOCKET) |
77 | 77 | if isinstance(config.SOCKET, str): |
78 | 78 | os.chmod(config.SOCKET, config.socket_permission) |
79 | sock.listen(1) | |
79 | sock.listen(5) | |
80 | 80 | self.socket_data_read[sock] = [] |
81 | 81 | if config.debug: |
82 | 82 | sys.stderr.write('waiting for connections\n') |
91 | 91 | if socket == sock: |
92 | 92 | connection, client_address = sock.accept() |
93 | 93 | if config.debug: |
94 | sys.stderr.write('connection from %s\n' % client_address) | |
94 | sys.stderr.write('connection from %s\n' % (client_address,)) | |
95 | 95 | sys.stderr.flush() |
96 | 96 | self.socket_data_read[connection] = [] |
97 | 97 | # else there is data to read on a client socket |
59 | 59 | if config_file.endswith(".conf"): |
60 | 60 | self._config = imp.load_source('config', config_file) |
61 | 61 | 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 | |
64 | 67 | ) |
65 | 68 | cache_file = imp.cache_from_source(config_file) |
66 | 69 | # remove the config pyc file |
89 | 92 | ) |
90 | 93 | ) |
91 | 94 | |
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] | |
93 | 106 | |
94 | 107 | def __getattr__(self, name): |
95 | 108 | try: |
96 | 109 | if self.config_file.endswith(".yaml"): |
97 | return self._config[name] | |
110 | ret = self._config[name] | |
98 | 111 | else: |
99 | return getattr(self._config, name) | |
112 | ret = getattr(self._config, name) | |
100 | 113 | # If an parameter is not defined in the config file, return its default value. |
101 | 114 | 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 | |
103 | 122 | |
104 | 123 | |
105 | 124 | class LazyConfig(object): |
273 | 292 | |
274 | 293 | |
275 | 294 | 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``""" | |
277 | 296 | try: |
278 | 297 | ip = ipaddress.IPv4Address(ip) |
279 | 298 | except ipaddress.AddressValueError: |
280 | 299 | ip = ipaddress.IPv6Address(ip) |
281 | for net in config.limited_netword: | |
300 | for net in config.limited_networks: | |
282 | 301 | if ip in net: |
283 | 302 | return True |
284 | 303 | return False |
387 | 406 | msg.attach(MIMEText("\n".join(text), 'plain')) |
388 | 407 | |
389 | 408 | # check that smtp_server is wekk formated |
390 | if isinstance(config.smtp_server, tuple): | |
409 | if isinstance(config.smtp_server, (list, tuple)): | |
391 | 410 | if len(config.smtp_server) >= 2: |
392 | 411 | server = smtplib.SMTP(config.smtp_server[0], config.smtp_server[1]) |
393 | 412 | elif len(config.smtp_server) == 1: |
403 | 422 | server.starttls() |
404 | 423 | # should we use credentials ? |
405 | 424 | 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 | ): | |
407 | 429 | server.login(config.smtp_credentials[0], config.smtp_credentials[1]) |
408 | 430 | else: |
409 | 431 | ValueError("bad smtp_credentials should be a tuple (login, password)") |
0 | 0 | Metadata-Version: 1.1 |
1 | 1 | Name: policyd-rate-limit |
2 | Version: 0.6.1 | |
2 | Version: 0.6.2 | |
3 | 3 | Summary: Postfix rate limit policy server implemented in Python3. |
4 | 4 | Home-page: https://github.com/nitmir/policyd-rate-limit |
5 | 5 | Author: Valentin Samir |
9 | 9 | Description: Policyd rate limit |
10 | 10 | ================== |
11 | 11 | |
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| | |
18 | 13 | |
19 | 14 | Postfix policyd server allowing to limit the number of mails accepted by |
20 | 15 | postfix over several time periods, by sasl usernames and/or ip addresses. |
39 | 34 | * `mysqldb <https://pypi.python.org/pypi/MySQL-python>`_ |
40 | 35 | (``sudo apt-get install python3-mysqldb`` on debian like systems) for the mysql backend. |
41 | 36 | * `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 | |
43 | 38 | |
44 | 39 | Install with pip:: |
45 | 40 | |
78 | 73 | The default is ``"/var/run/policyd-rate-limit/policyd-rate-limit.pid"``. |
79 | 74 | ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists. |
80 | 75 | * ``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 | |
82 | 77 | * ``sqlite_config``: The config to connect to a sqlite3 database. |
83 | 78 | * ``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. | |
85 | 80 | * ``SOCKET``: The socket to bind to. Can be a path to an unix socket or a couple [ip, port]. |
86 | 81 | The default is ``"/var/spool/postfix/ratelimit/policy"``. |
87 | 82 | ``policyd-rate-limit`` will try to create the parent directory and chown it if it do not exists. |
149 | 144 | check_policy_service unix:ratelimit/policy, |
150 | 145 | ... |
151 | 146 | |
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 | ||
152 | 157 | Keywords: Postfix,rate,limit,email |
153 | 158 | Platform: UNKNOWN |
154 | 159 | Classifier: Environment :: No Input/Output (Daemon) |