Skip to content

Commit

Permalink
fix firewall sshkey & gateway setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyBasher committed Feb 10, 2024
1 parent 84f0461 commit 496049a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# functions.py
#
# thomas@linuxmuster.net
# 20230831
# 20240210
#

from subprocess import Popen, PIPE
Expand Down Expand Up @@ -647,10 +647,10 @@ def putSftp(ip, localfile, remotefile, secret='', sshuser='root'):


# upload firewall config
def putFwConfig(firewallip, secret=''):
def putFwConfig(firewallip, fwconf=constants.FWCONFREMOTE, secret=''):
printScript('Uploading firewall configuration:')
rc = putSftp(firewallip, constants.FWCONFLOCAL,
constants.FWCONFREMOTE, secret)
fwconf, secret)
if rc:
printScript('* Upload finished successfully.')
else:
Expand Down
5 changes: 2 additions & 3 deletions lib/setup.d/h_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# setup ssh host keys
# thomas@linuxmuster.net
# 20220105
# 20240209
#

import configparser
Expand Down Expand Up @@ -60,8 +60,7 @@
subProc('ssh-keygen -t ' + a + ' -f '
+ rootkey_prefix + a + ' -N ""', logfile)
if a == 'rsa':
subProc('base64 ' + constants.SSHPUBKEY
+ ' > ' + constants.SSHPUBKEYB64, logfile)
subProc('echo -n "$(cat ' + constants.SSHPUBKEY + ')" | base64 -w0 > ' + constants.SSHPUBKEYB64, logfile)
rc = replaceInFile(constants.SSHPUBKEYB64, '\n', '')
printScript(' Success!', '', True, True, False, len(msg))
except:
Expand Down
16 changes: 7 additions & 9 deletions lib/setup.d/m_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# firewall setup
# thomas@linuxmuster.net
# 20220105
# 20220210
#

import bcrypt
Expand Down Expand Up @@ -119,9 +119,7 @@ def main():
language = '<language>' + lang + '</language>'
# save gateway configuration
try:
gwconfig = str(soup.findAll('gateways')[0])
gwconfig = gwconfig.replace(
'<gateways>', '').replace('</gateways>', '')
gwconfig = str(soup.find('gateways').content)
except:
gwconfig = ''
# save dnsserver configuration
Expand Down Expand Up @@ -235,7 +233,7 @@ def main():

# upload config files
# upload modified main config.xml
rc = putFwConfig(firewallip, rolloutpw)
rc = putFwConfig(firewallip, '/tmp/opnsense.xml', rolloutpw)
if not rc:
sys.exit(1)

Expand All @@ -247,7 +245,7 @@ def main():
sys.exit(1)
rc, content = readTextfile(conftmp)
fwpath = content.split('\n')[0].partition(' ')[2]
rc = putSftp(firewallip, conftmp, fwpath, productionpw)
rc = putSftp(firewallip, conftmp, fwpath, rolloutpw)
if not rc:
sys.exit(1)

Expand All @@ -258,9 +256,9 @@ def main():
printScript('Installing extensions and rebooting firewall')
fwsetup_local = constants.FWSHAREDIR + '/fwsetup.sh'
fwsetup_remote = '/tmp/fwsetup.sh'
rc = putSftp(firewallip, fwsetup_local, fwsetup_remote, productionpw)
rc = sshExec(firewallip, 'chmod +x ' + fwsetup_remote, productionpw)
rc = sshExec(firewallip, fwsetup_remote, productionpw)
rc = putSftp(firewallip, fwsetup_local, fwsetup_remote, rolloutpw)
rc = sshExec(firewallip, 'chmod +x ' + fwsetup_remote, rolloutpw)
rc = sshExec(firewallip, fwsetup_remote, rolloutpw)
if not rc:
sys.exit(1)

Expand Down
11 changes: 8 additions & 3 deletions share/firewall/opnsense/fwsetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# install extensions and reboot
# thomas@linuxmuster.net
# 20200311
# 20240210
#

# install extensions
Expand All @@ -11,5 +11,10 @@ for item in $extensions; do
pkg install -y $item
done

# reboot
configctl firmware reboot
if [ -s /tmp/opnsense.xml ]; then
# copy setup config
cp /tmp/opnsense.xml /conf/config.xml

# reboot finally
reboot
fi

0 comments on commit 496049a

Please sign in to comment.