Skip to content

Commit

Permalink
fix install script
Browse files Browse the repository at this point in the history
  • Loading branch information
AlteredCoder authored and AlteredCoder committed Nov 9, 2020
1 parent cac8d8e commit d4fb818
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
8 changes: 7 additions & 1 deletion nftables.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ func (n *nft) Add(decision *models.Decision) error {
return nil
}
} else { // ipv4
if err := n.conn.SetAddElements(n.set, []nftables.SetElement{{Key: []byte(net.ParseIP(*decision.Value).To4())}}); err != nil {
var ipAddr string
if strings.Contains(*decision.Value, "/") {
ipAddr = strings.Split(*decision.Value, "/")[0]
} else {
ipAddr = *decision.Value
}
if err := n.conn.SetAddElements(n.set, []nftables.SetElement{{Key: []byte(net.ParseIP(ipAddr).To4())}}); err != nil {
return err
}
if err := n.conn.Flush(); err != nil {
Expand Down
20 changes: 5 additions & 15 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,10 @@ check_iptables() {
}


check_apikeygen() {
echo "if you are on a single-machine setup, do you want the wizard to configure your API key ? (Y/n)"
echo "(note: if you didn't understand the question, 'Y' might be a safe answer)"
read answer
if [[ ${answer} == "" ]]; then
answer="y"
fi
if [ "$answer" != "${answer#[Yy]}" ] ;then
SUFFIX=`tr -dc A-Za-z0-9 </dev/urandom | head -c 8`
API_KEY=`cscli bouncers add cs-firewall-bouncer-${SUFFIX} -o raw`
API_KEY=${API_KEY} envsubst < ./config/cs-firewall-bouncer.yaml > "${CONFIG_DIR}cs-firewall-bouncer.yaml"
else
echo "For your bouncer to be functionnal, you need to create an API key and set it in the ${CONFIG_DIR}cs-firewall-bouncer.yaml file"
fi;
gen_apikey() {
SUFFIX=`tr -dc A-Za-z0-9 </dev/urandom | head -c 8`
API_KEY=`cscli bouncers add cs-firewall-bouncer-${SUFFIX} -o raw`
API_KEY=${API_KEY} envsubst < ./config/cs-firewall-bouncer.yaml > "${CONFIG_DIR}cs-firewall-bouncer.yaml"
}

check_ipset() {
Expand Down Expand Up @@ -68,5 +58,5 @@ check_iptables
check_ipset
echo "Installing firewall-bouncer"
install_firewall_bouncer
check_apikeygen
gen_apikey
echo "The firewall-bouncer service has been installed!"

0 comments on commit d4fb818

Please sign in to comment.