Skip to content

Commit

Permalink
fix: few fixes when config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Jan 10, 2025
1 parent 0c11107 commit 1b8880b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/ns-api/files/ns.snort
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,6 @@ else:
raise ValidationError('oinkcode', 'invalid')
print(json.dumps({"status": "success"}))
else:
utils.validation_error('action', 'invalid')
print(json.dumps(utils.generic_error(f"Unknown action: {action}")))
except ValidationError as e:
print(json.dumps(utils.validation_error(e.parameter, e.message, e.value)))
32 changes: 18 additions & 14 deletions packages/snort3/files/snort.init
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ update_bypass_set() {
fi
}

download_rules_if_needed () {
if ! find /var/ns-snort/rules/ -type f -name "*.rules" | grep -q . ; then
# no rules file found, start downloaded loop
attempt=0
until /usr/bin/ns-snort-rules --download; do
attempt=$((attempt + 1))
if [ "$attempt" -ge 6 ]; then
echo "Error: failed to download snort rules after 6 attempts (1 minute)."
break
fi
sleep 10
done
fi
download_rules () {
# this is done every time the service is started
attempt=0
until /usr/bin/ns-snort-rules --download; do
attempt=$((attempt + 1))
if [ "$attempt" -ge 6 ]; then
echo "Error: failed to download snort rules after 6 attempts (1 minute)."
break
fi
sleep 10
done
}

setup_tweaks() {
Expand Down Expand Up @@ -82,7 +80,7 @@ start_service() {
update_bypass_set "bypass_dst_v4"
update_bypass_set "bypass_src_v6"
update_bypass_set "bypass_dst_v6"
download_rules_if_needed
download_rules
setup_tweaks
fi

Expand Down Expand Up @@ -123,3 +121,9 @@ service_triggers()
procd_add_reload_trigger "snort"
procd_add_validation validate_snort_section
}

reload_service()
{
stop
start
}

0 comments on commit 1b8880b

Please sign in to comment.