add config file
This commit is contained in:
parent
40e3c8c536
commit
06d73731d6
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
from configparser import ConfigParser
|
||||||
from email.utils import parseaddr
|
from email.utils import parseaddr
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import logging
|
import logging
|
||||||
|
@ -13,6 +13,7 @@ import Milter
|
||||||
|
|
||||||
|
|
||||||
SOCKETPATH = "/run/csc-milter/csc-milter.sock"
|
SOCKETPATH = "/run/csc-milter/csc-milter.sock"
|
||||||
|
CONFIG_PATH = '/etc/csc/csc_milter.ini'
|
||||||
TIMEOUT = 5
|
TIMEOUT = 5
|
||||||
MYORIGIN = ''
|
MYORIGIN = ''
|
||||||
MYNETWORKS = []
|
MYNETWORKS = []
|
||||||
|
@ -109,7 +110,7 @@ def get_postconf(param):
|
||||||
shell=True, capture_output=True, check=True
|
shell=True, capture_output=True, check=True
|
||||||
)
|
)
|
||||||
value = proc.stdout.decode().strip()
|
value = proc.stdout.decode().strip()
|
||||||
logger.debug(f'Retrieved from postconf: {param} = {value}')
|
logger.debug(f'retrieved from postconf: {param} = {value}')
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,20 +121,15 @@ def main():
|
||||||
|
|
||||||
check_postfix_user()
|
check_postfix_user()
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Custom milter for CSC.')
|
MYORIGIN = get_postconf('myorigin')
|
||||||
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:
|
networks_str = get_postconf('mynetworks').replace(',', ' ')
|
||||||
MYORIGIN = args.myorigin
|
networks = networks_str.split()
|
||||||
else:
|
if os.path.isfile(CONFIG_PATH):
|
||||||
MYORIGIN = get_postconf('myorigin')
|
config = ConfigParser()
|
||||||
if args.mynetworks is not None:
|
config.read_file(open(CONFIG_PATH))
|
||||||
networks = args.mynetworks.split()
|
if 'additional_subnets' in config['main']:
|
||||||
else:
|
networks += config['main']['additional_subnets'].split(',')
|
||||||
networks_str = get_postconf('mynetworks').replace(',', ' ')
|
|
||||||
networks = networks_str.split()
|
|
||||||
MYNETWORKS = [
|
MYNETWORKS = [
|
||||||
ipaddress.ip_network(
|
ipaddress.ip_network(
|
||||||
s.replace('[', '')
|
s.replace('[', '')
|
||||||
|
@ -142,6 +138,7 @@ def main():
|
||||||
)
|
)
|
||||||
for s in networks
|
for s in networks
|
||||||
]
|
]
|
||||||
|
logger.debug('trusted subnets: %s' % MYNETWORKS)
|
||||||
re_myorigin = MYORIGIN.replace('.', r'\.')
|
re_myorigin = MYORIGIN.replace('.', r'\.')
|
||||||
RECEIVED_REGEX = re.compile(rf"\bby ([\w-]+\.)?{re_myorigin}\b")
|
RECEIVED_REGEX = re.compile(rf"\bby ([\w-]+\.)?{re_myorigin}\b")
|
||||||
|
|
||||||
|
|
|
@ -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
|
csc-milter (0.2.0-1) buster; urgency=medium
|
||||||
|
|
||||||
* Add check for Received: header.
|
* Add check for Received: header.
|
||||||
|
|
|
@ -2,8 +2,9 @@ Source: csc-milter
|
||||||
Maintainer: Systems Committee <syscom@csclub.uwaterloo.ca>
|
Maintainer: Systems Committee <syscom@csclub.uwaterloo.ca>
|
||||||
Section: mail
|
Section: mail
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Standards-Version: 3.9.2
|
Standards-Version: 4.3.0
|
||||||
Build-Depends: debhelper (>=9),
|
Build-Depends: debhelper (>=9),
|
||||||
|
debhelper (>= 9.20160709) | dh-systemd,
|
||||||
dh-python,
|
dh-python,
|
||||||
python3-setuptools,
|
python3-setuptools,
|
||||||
python3-all
|
python3-all
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
etc/csc/csc_milter.ini
|
|
@ -1,6 +1,13 @@
|
||||||
#!/usr/bin/make -f
|
#!/usr/bin/make -f
|
||||||
|
|
||||||
|
NAME=csc-milter
|
||||||
export PYBUILD_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
|
||||||
|
|
|
@ -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
2
setup.py
|
@ -16,7 +16,7 @@ class PyTest(TestCommand):
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='csc-milter',
|
name='csc-milter',
|
||||||
version='0.2.0',
|
version='0.2.1',
|
||||||
description='Custom milter for CSC',
|
description='Custom milter for CSC',
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
|
|
Loading…
Reference in New Issue