#!/bin/bash
### MODUL-NR. 013 ###
# (c) August 2008 Stefan Schäfer / FSP Computer & Netzwerke
# (c) 2009-2017 Stefan Schäfer / invis-server.org / stefan@invis-server.org
# (c) 2013,2014 Dimitri Asarowski / invis-server.org / dimitri@invis-server.org
# (c) 2013-2017 Ingo Göppert / invis-server.org / ingo@invis-server.org

# License: GPLv3
# Questions: info@invis-server.org

# Firewall Einrichtung basierend auf SuSEfirewall2

# SuSEfirewall2 based firewall setup

# Dieses Programm ist freie Software. Sie können es unter den Bedingungen der 
# GNU General Public License, wie von der Free Software Foundation veröffentlicht,
# weitergeben und/oder modifizieren, entweder gemäß Version 3 der Lizenz oder
# (nach Ihrer Option) jeder späteren Version.

# Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, daß es Ihnen
# von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die implizite 
# Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. 
# Details finden Sie in der GNU General Public License.

# Sie sollten ein Exemplar der GNU General Public License zusammen mit diesem 
# Programm erhalten haben. Falls nicht, siehe <http://www.gnu.org/licenses/>. 

# 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/>.

# include functions
source $SINEINCLUDEDIR/functions

modulename=`basename $0`

clear
windowtitle="SuSEfirewall2"
pgsubtitle="Firewall Setup dor invis-server"

# Kopieren und anpassen der Firewall Konfiguration
cp $TEMPLATEDIR/$modulename/SuSEfirewall2 /etc/sysconfig/
file="SuSEfirewall2"
path="/etc/sysconfig"
nw=`getconfdata "Networkbase" "2"`
netpart1=`echo "$nw" | cut -d "." -f 1`
netpart2=`echo "$nw" | cut -d "." -f 2`
netpart3=`echo "$nw" | cut -d "." -f 3`
netpart4=`echo "$nw" | cut -d "." -f 4`
netpart="$netpart1.$netpart2.$netpart3.$netpart4"
shortnmask=`getconfdata "NMask-short" "2"`
string="192.168.220.0/24%$netpart/$shortnmask"
changevalues $path $file $string

# geaenderten SSH-Port einfuegen
sshport=`getconfdata "SSHPORT" "2"`
string="sshport%$sshport"
changevalues $path $file "$string"

# geaenderten HTTPS-Port einfuegen
httpsport=`getconfdata "HTTPSPORT" "2"`
string="httpsport%$httpsport"
changevalues $path $file "$string"

# OwnCloud-Port einfuegen
ocport=`getconfdata "OCPORT" "2"`
string="ocport%$ocport"
changevalues $path $file "$string"
    
# SSH Port ändern
cp $TEMPLATEDIR/$modulename/sshd_config /etc/ssh/
path="/etc/ssh"
file="sshd_config"

sshport=`getconfdata "SSHPORT" "2"`
string="sshport%$sshport"
changevalues $path $file "$string"

# SSHd neu starten
chkservice "sshd"
    
# Firewall starten und in Runlevel eintragen
chkservice "SuSEfirewall2_init"
chkservice "SuSEfirewall2"

