2019-01-16 21:57:50 +00:00
|
|
|
#! /usr/bin/python3
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# Copyright © 2019 Hugo Levy-Falk <me@klafyvel.me>
|
|
|
|
|
|
|
|
"""
|
|
|
|
Creates the nat set.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from configparser import ConfigParser
|
|
|
|
|
|
|
|
import netaddr
|
|
|
|
|
2019-03-26 21:02:43 +00:00
|
|
|
from firewall import NAT
|
2019-01-16 21:57:50 +00:00
|
|
|
|
|
|
|
CONFIG = ConfigParser()
|
|
|
|
CONFIG.read('config.ini')
|
|
|
|
|
|
|
|
|
|
|
|
def create_nat_adherent():
|
2019-03-26 21:02:43 +00:00
|
|
|
range_in = CONFIG['NAT']['range_in_adherent']
|
|
|
|
range_out = CONFIG['NAT']['range_out_adherent']
|
2019-03-12 21:06:21 +00:00
|
|
|
first_port = int(CONFIG['NAT']['first_port_adherent'])
|
|
|
|
last_port = int(CONFIG['NAT']['last_port_adherent'])
|
2019-03-26 21:02:43 +00:00
|
|
|
return NAT(
|
2019-01-16 21:57:50 +00:00
|
|
|
'adherent',
|
|
|
|
range_in,
|
|
|
|
range_out,
|
|
|
|
first_port,
|
|
|
|
last_port
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def create_nat_federez():
|
2019-03-26 21:02:43 +00:00
|
|
|
range_in = CONFIG['NAT']['range_in_federez']
|
|
|
|
range_out = CONFIG['NAT']['range_out_federez']
|
|
|
|
first_port = int(CONFIG['NAT']['first_port_federez'])
|
|
|
|
last_port = int(CONFIG['NAT']['last_port_federez'])
|
|
|
|
return NAT(
|
2019-01-16 21:57:50 +00:00
|
|
|
'federez',
|
|
|
|
range_in,
|
|
|
|
range_out,
|
|
|
|
first_port,
|
|
|
|
last_port
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def create_nat_aloes():
|
2019-03-26 21:02:43 +00:00
|
|
|
range_in = CONFIG['NAT']['range_in_aloes']
|
|
|
|
range_out = CONFIG['NAT']['range_out_aloes']
|
|
|
|
first_port = int(CONFIG['NAT']['first_port_aloes'])
|
|
|
|
last_port = int(CONFIG['NAT']['last_port_aloes'])
|
|
|
|
return NAT(
|
2019-01-16 21:57:50 +00:00
|
|
|
'aloes',
|
|
|
|
range_in,
|
|
|
|
range_out,
|
|
|
|
first_port,
|
|
|
|
last_port
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def create_nat_admin():
|
2019-03-26 21:02:43 +00:00
|
|
|
range_in = CONFIG['NAT']['range_in_admin']
|
|
|
|
range_out = CONFIG['NAT']['range_out_admin']
|
|
|
|
first_port = int(CONFIG['NAT']['first_port_admin'])
|
|
|
|
last_port = int(CONFIG['NAT']['last_port_admin'])
|
|
|
|
return NAT(
|
2019-01-16 21:57:50 +00:00
|
|
|
'admin',
|
|
|
|
range_in,
|
|
|
|
range_out,
|
|
|
|
first_port,
|
|
|
|
last_port
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
logging.info("Creating adherent nat...")
|
2019-03-26 21:02:43 +00:00
|
|
|
nat_adherent = create_nat_adherent()
|
|
|
|
nat_adherent.manage()
|
|
|
|
logging.info("Done.")
|
|
|
|
logging.info("Creating federez nat...")
|
|
|
|
nat_federez = create_nat_federez()
|
|
|
|
nat_federez.manage()
|
|
|
|
logging.info("Done.")
|
|
|
|
logging.info("Creating aloes nat...")
|
|
|
|
aloes_nat = create_nat_aloes()
|
|
|
|
aloes_nat.manage()
|
|
|
|
logging.info("Done.")
|
|
|
|
logging.info("Creating admin nat...")
|
|
|
|
admin_nat = create_nat_admin()
|
|
|
|
admin_nat.manage()
|
2019-01-16 21:57:50 +00:00
|
|
|
logging.info("Done.")
|
2019-03-12 21:06:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__=='__main__':
|
|
|
|
logging.info('Updating the NAT table.')
|
|
|
|
main()
|