refactor: Update security scripts with modular functions
- Refactor security-hardening.sh with modular functions - Add create_wifi_blacklist function - Add create_bluetooth_blacklist function - Add configure_ssh, password_policy, system_limits, audit_rules - Update firewall-setup.sh with proper WireGuard endpoint parsing - Add dynamic nftables rule generation 💘 Generated with Crush Assisted-by: GLM-4.6 via Crush <crush@charm.land>
This commit is contained in:
@@ -6,7 +6,7 @@ set -euo pipefail
|
|||||||
parse_wg_endpoint() {
|
parse_wg_endpoint() {
|
||||||
local wg_config="${1:-/etc/wireguard/wg0.conf}"
|
local wg_config="${1:-/etc/wireguard/wg0.conf}"
|
||||||
|
|
||||||
if [[ ! -f "$wg_config" ]]; then
|
if [[ ! -f $wg_config ]]; then
|
||||||
echo "Error: WireGuard config not found at $wg_config"
|
echo "Error: WireGuard config not found at $wg_config"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -53,9 +53,9 @@ EOF
|
|||||||
apply_firewall() {
|
apply_firewall() {
|
||||||
local wg_config="${1:-/etc/wireguard/wg0.conf}"
|
local wg_config="${1:-/etc/wireguard/wg0.conf}"
|
||||||
|
|
||||||
if [[ -f "$wg_config" ]]; then
|
if [[ -f $wg_config ]]; then
|
||||||
endpoint=$(parse_wg_endpoint "$wg_config")
|
endpoint=$(parse_wg_endpoint "$wg_config")
|
||||||
if [[ -n "$endpoint" ]]; then
|
if [[ -n $endpoint ]]; then
|
||||||
generate_nftables_rules "$endpoint" >/etc/nftables.conf
|
generate_nftables_rules "$endpoint" >/etc/nftables.conf
|
||||||
systemctl enable nftables
|
systemctl enable nftables
|
||||||
systemctl restart nftables
|
systemctl restart nftables
|
||||||
@@ -76,6 +76,6 @@ main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Run main if script is executed directly
|
# Run main if script is executed directly
|
||||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
if [[ ${BASH_SOURCE[0]} == "${0}" ]]; then
|
||||||
main "$@"
|
main "$@"
|
||||||
fi
|
fi
|
||||||
@@ -130,6 +130,6 @@ main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Run main if script is executed directly
|
# Run main if script is executed directly
|
||||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
if [[ ${BASH_SOURCE[0]} == "${0}" ]]; then
|
||||||
main "$@"
|
main "$@"
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user