Browse Source

add config file

master
Max Erenberg 11 months ago
parent
commit
06d73731d6
  1. 29
      csc_milter/main.py
  2. 6
      debian/changelog
  3. 3
      debian/control
  4. 1
      debian/csc-milter.install
  5. 9
      debian/rules
  6. 3
      etc/csc/csc_milter.ini
  7. 2
      setup.py

29
csc_milter/main.py

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import argparse
from configparser import ConfigParser
from email.utils import parseaddr
import ipaddress
import logging
@ -13,6 +13,7 @@ import Milter
SOCKETPATH = "/run/csc-milter/csc-milter.sock"
CONFIG_PATH = '/etc/csc/csc_milter.ini'
TIMEOUT = 5
MYORIGIN = ''
MYNETWORKS = []
@ -109,7 +110,7 @@ def get_postconf(param):
shell=True, capture_output=True, check=True
)
value = proc.stdout.decode().strip()
logger.debug(f'Retrieved from postconf: {param} = {value}')
logger.debug(f'retrieved from postconf: {param} = {value}')
return value
@ -120,20 +121,15 @@ def main():
check_postfix_user()
parser = argparse.ArgumentParser(description='Custom milter for CSC.')
parser.add_argument('--myorigin', help='domain name for locally-posted mail')
parser.add_argument('--mynetworks', help='space-separated list of trusted subnets')
args = parser.parse_args()
if args.myorigin is not None:
MYORIGIN = args.myorigin
else:
MYORIGIN = get_postconf('myorigin')
if args.mynetworks is not None:
networks = args.mynetworks.split()
else:
networks_str = get_postconf('mynetworks').replace(',', ' ')
networks = networks_str.split()
MYORIGIN = get_postconf('myorigin')
networks_str = get_postconf('mynetworks').replace(',', ' ')
networks = networks_str.split()
if os.path.isfile(CONFIG_PATH):
config = ConfigParser()
config.read_file(open(CONFIG_PATH))
if 'additional_subnets' in config['main']:
networks += config['main']['additional_subnets'].split(',')
MYNETWORKS = [
ipaddress.ip_network(
s.replace('[', '')
@ -142,6 +138,7 @@ def main():
)
for s in networks
]
logger.debug('trusted subnets: %s' % MYNETWORKS)
re_myorigin = MYORIGIN.replace('.', r'\.')
RECEIVED_REGEX = re.compile(rf"\bby ([\w-]+\.)?{re_myorigin}\b")

6
debian/changelog vendored

@ -1,3 +1,9 @@
csc-milter (0.2.1-1) buster; urgency=medium
* Add config file.
-- Max Erenberg <merenber@csclub.uwaterloo.ca> Sat, 04 Sep 2021 17:29:00 +0000
csc-milter (0.2.0-1) buster; urgency=medium
* Add check for Received: header.

3
debian/control vendored

@ -2,8 +2,9 @@ Source: csc-milter
Maintainer: Systems Committee <syscom@csclub.uwaterloo.ca>
Section: mail
Priority: optional
Standards-Version: 3.9.2
Standards-Version: 4.3.0
Build-Depends: debhelper (>=9),
debhelper (>= 9.20160709) | dh-systemd,
dh-python,
python3-setuptools,
python3-all

1
debian/csc-milter.install vendored

@ -0,0 +1 @@
etc/csc/csc_milter.ini

9
debian/rules vendored

@ -1,6 +1,13 @@
#!/usr/bin/make -f
NAME=csc-milter
export PYBUILD_NAME=csc-milter
%:
dh $@ --with python3 --buildsystem=pybuild
dh $@ --with python3,systemd --buildsystem=pybuild
override_dh_systemd_enable:
dh_systemd_enable --no-enable $(NAME).service
override_dh_systemd_start:
dh_systemd_start --no-start $(NAME).service

3
etc/csc/csc_milter.ini

@ -0,0 +1,3 @@
[main]
# trust all IP addresses in AS12093
additional_subnets = 129.97.0.0/16, 2620:101:f000::/47

2
setup.py

@ -16,7 +16,7 @@ class PyTest(TestCommand):
setup(
name='csc-milter',
version='0.2.0',
version='0.2.1',
description='Custom milter for CSC',
long_description=long_description,
long_description_content_type='text/markdown',

Loading…
Cancel
Save