12 Commits

Author SHA1 Message Date
Stefan Schantl
41d3d33dde update-ipblocklists: Fix loading new blocklists after update
* The script needs to run with root permissions in order to
  do the ipset operations. So remove code to drop the permissions
  on startup.

* Adjust execute calls to use the proper functions from
  general functions.

* Add some code to set the correct ownership (nobody:nobody) for
  changed files during script runtime.

Fixes #13072.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2023-04-04 19:59:23 +00:00
Stefan Schantl
404b513794 ipblocklist: Add "v4" as extension to the ipset set names.
This easily allows us to swap the sets after updating, without
unloading them.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:27:14 +02:00
Stefan Schantl
7f4829de97 ipblocklist-functions.pl: Allow export of modified_file and
blocklist_dir values.

They so easily can be accessed by other perl scripts.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:13 +02:00
Stefan Schantl
d8113820e3 ipblocklist-functions.pl: Store the local time if no last modified could
be determined.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:13 +02:00
Tim FitzGeorge
8d12d12a4f ipblocklist-functions.pl: Add function to get the holdoff_rate of a
given list.

The function will return the rate in seconds based on the configured
rate value in the blocklist sources file and the given blocklist.

Signed-off-by: Tim FitzGeorge <ipfr@tfitzgeorge.me.uk>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:13 +02:00
Stefan Schantl
d7dd565341 ipblocklist-functions.pl: Abort and return code if a list is empty or
not parse-able.

In case the downloaded list is empty or the parser is not able to parse
it properly, the download_and_create_blocklist() function now exits and
will return "empty_list" as new error code.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:13 +02:00
Tim FitzGeorge
0a4f60f28c ipblocklist-functions.pl: Add helper function to proper calculate the
hashsize.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:13 +02:00
Tim FitzGeorge
ac9b5d8e6b ipblocklist-functions.pl: Add parser of dshield.
This vendor has a different list format and therefore requires an
own parser.

Signed-off-by: Tim FitzGeorge <ipfr@tfitzgeorge.me.uk>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:13 +02:00
Tim FitzGeorge
ab0179617d ipblocklist-functions.pl: Add parser to obtain IP or Net addresses from
a blocklist.

Signed-off-by: Tim FitzGeorge <ipfr@tfitzgeorge.me.uk>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:13 +02:00
Stefan Schantl
ba8455e469 ipblocklist-functions.pl: Add download_and_create_blocklist function.
This function is responisible for downloading and converting the
blocklist into an ipset compatible format.

The only required argument is the blocklist (in upper letter format) which should be
performed. It automatically will setup an upstream proxy (if configured)
and grab the file specified in the blocklist vendor configuration hash.

There is a maximum amount of five attempts until the script gives up and
returns a "dl_error". In case the server responses with "Not Modified"
(Code 304) a "not_modified" will be returned.

If the blocklist successfully has been grabbed, the modification date
get stored for further purposes and the list content will be converted
and stored in an ipset compatible format.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Inspired-by: Tim FitzGeorge <ipfr@tfitzgeorge.me.uk>
2022-07-07 17:26:13 +02:00
Stefan Schantl
e64587a43d ipblocklist-functions.pl: Add get_ipset_db_file() function.
This function is used to generate the filename and full path
for a given blocklist name.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:13 +02:00
Stefan Schantl
f4c25a44e2 ipblocklist-functions.pl: Initial commit.
This library file will contain a collection of functions, which are
required to deal with the ipblocklist feature.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
2022-07-07 17:26:13 +02:00