iptables-check-before.sh
, contains a function than checks for preexisting rule prior to taking action
The following covers how to install this branch as a submodule within your own project, and parameters that
iptables-check-before.sh
currently responds to.
Bash Variables
_module_https_url='https://github.com/network-utilities/iptables-check-before.git'
_module_relative_path='modules/iptables-check-before'
Git Commands
cd "<your-git-project-path>"
git checkout master
git submodule add -b master --name iptables-check-before "${_module_https_url}" "${_module_relative_path}"
Suggested additions so everyone has a good time with submodules
Clone with the following to avoid incomplete downloads
git clone --recurse-submodules <url-for-your-project>
Update/upgrade submodules via
git submodule update --init --recursive --merge
Example of sourcing and utilize iptables_check_before
features
example-usage.sh
#!/usr/bin/env bash
## Find true directory this script resides in
__SOURCE__="${BASH_SOURCE[0]}"
while [[ -h "${__SOURCE__}" ]]; do
__SOURCE__="$(find "${__SOURCE__}" -type l -ls | sed -n 's@^.* -> \(.*\)@\1@p')"
done
__DIR__="$(cd -P "$(dirname "${__SOURCE__}")" && pwd)"
## Source module code within this script
source "${__DIR__}/modules/iptables-check-before/iptables-check-before.sh"
iptables -N some_chain
iptables_check_before -A INPUT -j some_chain
iptables_check_before -A some_chain -p tcp --dport 80 -j ACCEPT
iptables_check_before -A some_chain -j RETURN
Test that things work!
git add .gitmodules
git add modules/iptables-check-before
git add README.md
git commit -F- <<'EOF'
:heavy_plus_sign: Adds network-utilities/iptables-check-before#1 submodule
**Edits**
- `README.md` file, documentation updates for submodules
**Additions**
- `.gitmodules` file, tracks other Git repository code utilized by this project
- `modules/iptables-check-before` submodule, Git tracked dependency
EOF
git push origin master
🎉 Excellent 🎉 your repository is now ready to begin unitizing code from this project!
Checks if rules exist prior to appending or deleting
Param | Type | Description | |
---|---|---|---|
$@ |
list | required | iptables rules to check prior to appending or deleting |
Returns: boolean
, exit status of appending or deleting iptables rules
Throws Parameter_Error: ipv4_range_from_address not provided any arguments
, when arguments are not defined
Example:
iptables_check_before -A INPUT -j some_chain
#> iptables -C INPUT -j some_chain || iptables -A INPUT -j some_chain
Iptables Check Before submodule quick start documentation
Copyright (C) 2019 S0AndS0
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation; version 3 of the License.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
by `jesin`
on