1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-13 19:52:06 +00:00
iiab/roles/network/templates/gateway/iiab-gen-iptables

159 lines
5.6 KiB
Text
Raw Normal View History

2017-05-27 18:09:50 +00:00
#!/bin/bash -x
source {{ iiab_env_file }}
2017-05-27 23:10:45 +00:00
{% if is_debuntu %}
2017-05-27 18:09:50 +00:00
IPTABLES=/sbin/iptables
IPTABLES_DATA=/etc/iptables.up.rules
{% else %}
IPTABLES=/usr/sbin/iptables
IPTABLES_DATA=/etc/sysconfig/iptables
{% endif %}
LANIF=$IIAB_LAN_DEVICE
WANIF=$IIAB_WAN_DEVICE
MODE=`grep iiab_network_mode_applied {{ iiab_ini_file }} | gawk '{print $3}'`
2017-05-27 18:09:50 +00:00
clear_fw() {
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -X
# first match wins
# Always accept loopback traffic
2017-05-27 18:09:50 +00:00
$IPTABLES -A INPUT -i lo -j ACCEPT
# Always drop rpc
2017-05-27 18:09:50 +00:00
$IPTABLES -A INPUT -p tcp --dport 111 -j DROP
$IPTABLES -A INPUT -p udp --dport 111 -j DROP
# mysql
$IPTABLES -A INPUT -p tcp --dport 3306 -j DROP
$IPTABLES -A INPUT -p udp --dport 3306 -j DROP
2018-10-03 18:47:21 +00:00
# postgres - not needed listens on lo only
2017-05-27 18:09:50 +00:00
$IPTABLES -A INPUT -p tcp --dport 5432 -j DROP
$IPTABLES -A INPUT -p udp --dport 5432 -j DROP
# couchdb
$IPTABLES -A INPUT -p tcp --dport 5984 -j DROP
$IPTABLES -A INPUT -p udp --dport 5984 -j DROP
}
2018-10-03 18:47:21 +00:00
if [ "x$WANIF" == "xnone" ] || [ "$MODE" == "Appliance" ]; then
2017-05-27 18:09:50 +00:00
clear_fw
# save the rule set
2017-05-27 23:10:45 +00:00
{% if is_debuntu %}
2017-05-27 18:09:50 +00:00
netfilter-persistent save
{% else %}
iptables-save > $IPTABLES_DATA
{% endif %}
exit 0
fi
lan=$LANIF
wan=$WANIF
# Good thing we replace this file should be treated like squid below
gw_block_https={{ gw_block_https }}
ssh_port={{ ssh_port }}
gui_wan={{ gui_wan }}
gui_port={{ gui_port }}
iiab_gateway_enabled={{ iiab_gateway_enabled }}
2017-05-27 18:09:50 +00:00
services_externally_visible={{ services_externally_visible }}
calibre_port={{ calibre_port }}
calibreweb_port={{ calibreweb_port }}
2017-05-27 18:09:50 +00:00
kiwix_port={{ kiwix_port }}
kalite_server_port={{ kalite_server_port }}
2018-07-17 05:10:37 +00:00
kolibri_http_port={{ kolibri_http_port }}
0.3 patch1 (#1377) * expand zim_versions_idx to include menuItem name, mediaCount, articleCount, size * create a stub menuItem if none exists * remember to change consumer of zim_version_idx in iiab-admin * comment out some debugging prints * do not change the name of a variable in iiab.ini * consistent variable names for *_enabled * start work on menus for enabled iiab roles * changes to display cups in home menu * remove reference to admin console which may not be installed * print error message * dict.get errors * handle undefined menuItem" * handle undefined menuItem again * some work on logos * break out the zim_versions_idx routines for use by update_menus in admin-console * remove old menuDef creation code * new variable names for zim_versions_idx * missing the tags data in zim_versions_idx * un-break-apart iiab-make-kiwix-lib.py * return an empty string * make size human_readable * getting console and iiab to work together on menus * add the new zim_date field to zim_versions_idx * get the latest into repo * found lost code iiab-make-kiwix-lib.py * Create Lokole admin user during setup * Add requested content to lokole readme Per iiab/iiab#1293 * Update default password * Add Lokole-IIAB user manual * Update default_vars.yml * Update local_vars_min.yml * Update local_vars_min.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update default_vars.yml * Update default_vars.yml * Update local_vars_min.yml * Update local_vars_medium.yml * Update local_vars_big.yml * Update default_vars.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Change admin username to uppercase * Revert "Lokole: change admin to Admin per IIAB app norms" * Update main.yml * Update README.rst * Update capture-wsgi.py * Update main.yml * Update main.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Update main.yml * Update main.yml * Update main.yml * Update main.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Address TODOs in Lokole documentation See https://github.com/ascoderu/opwen-webapp/issues/81 * Update main.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_big.yml * Update local_vars_min.yml * Update default_vars.yml * expand zim_versions_idx to include menuItem name, mediaCount, articleCount, size * create a stub menuItem if none exists * remember to change consumer of zim_version_idx in iiab-admin * comment out some debugging prints * do not change the name of a variable in iiab.ini * consistent variable names for *_enabled * start work on menus for enabled iiab roles * changes to display cups in home menu * remove reference to admin console which may not be installed * print error message * dict.get errors * handle undefined menuItem" * handle undefined menuItem again * some work on logos * break out the zim_versions_idx routines for use by update_menus in admin-console * remove old menuDef creation code * new variable names for zim_versions_idx * missing the tags data in zim_versions_idx * un-break-apart iiab-make-kiwix-lib.py * return an empty string * make size human_readable * getting console and iiab to work together on menus * add the new zim_date field to zim_versions_idx * get the latest into repo * found lost code iiab-make-kiwix-lib.py
2019-01-10 22:26:47 +00:00
cups_port={{ cups_port }}
transmission_http_port={{ transmission_http_port }}
transmission_peer_port={{ transmission_peer_port }}
sugarizer_port={{ sugarizer_port }}
2019-04-23 00:59:57 +00:00
internetarchive_port={{ internetarchive_port }}
nodered_port={{ nodered_port }}
mosquitto_port={{ mosquitto_port }}
minetest_port={{ minetest_port }}
pbx_signaling_ports_chan_sip={{ pbx_signaling_ports_chan_sip }}
pbx_signaling_ports_chan_pjsip={{ pbx_signaling_ports_chan_pjsip }}
pbx_data_ports={{ pbx_data_ports }}
pbx_enabled={{ pbx_enabled }}
2017-05-27 18:09:50 +00:00
block_DNS={{ block_DNS }}
2018-07-17 05:23:43 +00:00
echo "LAN is $lan and WAN is $wan"
2017-05-27 18:09:50 +00:00
#
# delete all existing rules.
#
/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe ip_conntrack
/sbin/modprobe iptable_nat
clear_fw
# Allow established connections, and those not coming from the outside
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -m state --state NEW -i $lan -j ACCEPT
# Allow mDNS
2017-05-27 18:09:50 +00:00
$IPTABLES -A INPUT -p udp --dport 5353 -j ACCEPT
#when run as gateway
2017-05-27 18:09:50 +00:00
$IPTABLES -A INPUT -p tcp --dport $ssh_port -m state --state NEW -i $wan -j ACCEPT
if [ "$gui_wan" == "True" ]; then
$IPTABLES -A INPUT -p tcp --dport $gui_port -m state --state NEW -i $wan -j ACCEPT
fi
if [ "$services_externally_visible" == "True" ]; then
$IPTABLES -A INPUT -p tcp --dport $kiwix_port -m state --state NEW -i $wan -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport $kalite_server_port -m state --state NEW -i $wan -j ACCEPT
2018-07-17 05:10:37 +00:00
$IPTABLES -A INPUT -p tcp --dport $kolibri_http_port -m state --state NEW -i $wan -j ACCEPT
2017-05-27 18:09:50 +00:00
$IPTABLES -A INPUT -p tcp --dport $calibre_port -m state --state NEW -i $wan -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport $calibreweb_port -m state --state NEW -i $wan -j ACCEPT
0.3 patch1 (#1377) * expand zim_versions_idx to include menuItem name, mediaCount, articleCount, size * create a stub menuItem if none exists * remember to change consumer of zim_version_idx in iiab-admin * comment out some debugging prints * do not change the name of a variable in iiab.ini * consistent variable names for *_enabled * start work on menus for enabled iiab roles * changes to display cups in home menu * remove reference to admin console which may not be installed * print error message * dict.get errors * handle undefined menuItem" * handle undefined menuItem again * some work on logos * break out the zim_versions_idx routines for use by update_menus in admin-console * remove old menuDef creation code * new variable names for zim_versions_idx * missing the tags data in zim_versions_idx * un-break-apart iiab-make-kiwix-lib.py * return an empty string * make size human_readable * getting console and iiab to work together on menus * add the new zim_date field to zim_versions_idx * get the latest into repo * found lost code iiab-make-kiwix-lib.py * Create Lokole admin user during setup * Add requested content to lokole readme Per iiab/iiab#1293 * Update default password * Add Lokole-IIAB user manual * Update default_vars.yml * Update local_vars_min.yml * Update local_vars_min.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update default_vars.yml * Update default_vars.yml * Update local_vars_min.yml * Update local_vars_medium.yml * Update local_vars_big.yml * Update default_vars.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Change admin username to uppercase * Revert "Lokole: change admin to Admin per IIAB app norms" * Update main.yml * Update README.rst * Update capture-wsgi.py * Update main.yml * Update main.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Update main.yml * Update main.yml * Update main.yml * Update main.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Address TODOs in Lokole documentation See https://github.com/ascoderu/opwen-webapp/issues/81 * Update main.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_big.yml * Update local_vars_min.yml * Update default_vars.yml * expand zim_versions_idx to include menuItem name, mediaCount, articleCount, size * create a stub menuItem if none exists * remember to change consumer of zim_version_idx in iiab-admin * comment out some debugging prints * do not change the name of a variable in iiab.ini * consistent variable names for *_enabled * start work on menus for enabled iiab roles * changes to display cups in home menu * remove reference to admin console which may not be installed * print error message * dict.get errors * handle undefined menuItem" * handle undefined menuItem again * some work on logos * break out the zim_versions_idx routines for use by update_menus in admin-console * remove old menuDef creation code * new variable names for zim_versions_idx * missing the tags data in zim_versions_idx * un-break-apart iiab-make-kiwix-lib.py * return an empty string * make size human_readable * getting console and iiab to work together on menus * add the new zim_date field to zim_versions_idx * get the latest into repo * found lost code iiab-make-kiwix-lib.py
2019-01-10 22:26:47 +00:00
$IPTABLES -A INPUT -p tcp --dport $cups_port -m state --state NEW -i $wan -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport $sugarizer_port -m state --state NEW -i $wan -j ACCEPT
2019-04-23 00:59:57 +00:00
$IPTABLES -A INPUT -p tcp --dport internetarchive_port -m state --state NEW -i $wan -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport $nodered_port -m state --state NEW -i $wan -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport $mosquitto_port -m state --state NEW -i $wan -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport $transmission_http_port -m state --state NEW -i $wan -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport $transmission_peer_port -m state --state NEW -i $wan -j ACCEPT
$IPTABLES -A INPUT -p udp --dport $minetest_port -m state --state NEW -i $wan -j ACCEPT
if [ "$pbx_enabled" == "True" ]; then
$IPTABLES -A INPUT -p udp --dport $pbx_signaling_ports_chan_sip -m state --state NEW -i $wan -j ACCEPT
$IPTABLES -A INPUT -p udp --dport $pbx_signaling_ports_chan_pjsip -m state --state NEW -i $wan -j ACCEPT
$IPTABLES -A INPUT -p udp --dport $pbx_data_ports -m state --state NEW -i $wan -j ACCEPT
fi
2017-05-27 18:09:50 +00:00
fi
if [ "$iiab_gateway_enabled" == "True" ]; then
2017-05-27 18:09:50 +00:00
$IPTABLES -A POSTROUTING -t nat -o $wan -j MASQUERADE
fi
$IPTABLES -A FORWARD -i $wan -o $lan -m state --state ESTABLISHED,RELATED -j ACCEPT
#Block https traffic except if directed at server
if [ "$gw_block_https" == "True" ]; then
$IPTABLES -A FORWARD -p tcp ! -d {{ lan_ip }} --dport 443 -j DROP
fi
2017-05-27 18:09:50 +00:00
# Allow outgoing connections from the LAN side.
2018-12-05 21:03:12 +00:00
$IPTABLES -A FORWARD -i $lan -o $wan -j ACCEPT
2017-05-27 18:09:50 +00:00
# Don't forward from the outside to the inside.
$IPTABLES -A FORWARD -i $wan -o $lan -j DROP
$IPTABLES -A INPUT -i $wan -j DROP
2018-10-03 18:47:21 +00:00
if [ "$block_DNS" == "True" ]; then
$IPTABLES -t nat -A PREROUTING -i $lan -p tcp --dport 53 ! -d {{ lan_ip }} -j DNAT --to {{ lan_ip }}:53
$IPTABLES -t nat -A PREROUTING -i $lan -p udp --dport 53 ! -d {{ lan_ip }} -j DNAT --to {{ lan_ip }}:53
2017-05-27 18:09:50 +00:00
fi
add in template dir rebase bassed upon copy in cut out obvious dead code working on put-204 make users a sqlite db sqlite db has users, and agent info android timeouts not yet working android 5 and 6 both work. lost mac return to a working version for the MAC. Missing the splash android,mac,windows all appear to work sqlite get status of execute row == Null initialize lasttimestamp with ajax call when home is triggered remove commented code, move towards logging vs print statements add logging with the -l flag no changes to default_vars.yml drop iptables captive portal stuff not using port 8090, and dnsmasq missed deleting trap_enabled fixes for 6.7 defaults add in template dir rebase bassed upon copy in cut out obvious dead code working on put-204 make users a sqlite db sqlite db has users, and agent info android timeouts not yet working android 5 and 6 both work. lost mac return to a working version for the MAC. Missing the splash android,mac,windows all appear to work sqlite get status of execute row == Null initialize lasttimestamp with ajax call when home is triggered remove commented code, move towards logging vs print statements drop iptables captive portal stuff not using port 8090, and dnsmasq missed deleting trap_enabled fixes for 6.7 defaults dispense with apache logs for captive portal, use the rotating portal.log instead bring in clean defaults and py Squash debugging details remove backup file still cannot dispense with cna on iphone. mac escape from cna broke with these changes captive comes after iiab in apache config one filename wrong logging used for debug, lost mac escape from cna typos got mac/iphone full browser back remove dead code python was not creating db, or putting ip when first encountered
2018-08-24 00:26:20 +00:00
if [ "$HTTPCACHE_ON" == "True" ]; then
2018-07-03 14:00:45 +00:00
$IPTABLES -t nat -A PREROUTING -i $lan -p tcp --dport 80 ! -d {{ lan_ip }} -j DNAT --to {{ lan_ip }}:3128
2017-05-27 18:09:50 +00:00
fi
# Enable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward
# save the whole rule set now
2017-05-27 23:10:45 +00:00
{% if is_debuntu %}
2017-05-27 18:09:50 +00:00
netfilter-persistent save
{% else %}
iptables-save > $IPTABLES_DATA
{% endif %}
exit 0