--- /dev/null
+###############################################################################
+# #
+# dnsbl - A DNS Blacklist Compositor For IPFire #
+# Copyright (C) 2025 IPFire Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# 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 General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+import datetime
+import sqlmodel
+
+class Sources(object):
+ def __init__(self, backend):
+ self.backend = backend
+
+ def get_by_id(self, id):
+ stmt = (
+ sqlmodel
+ .select(
+ Source,
+ )
+ .where(
+ Source.id == id,
+ )
+ )
+
+ with self.backend.session() as session:
+ result = session.execute(stmt)
+
+ return result.scalar_one_or_none()
+
+ def create(self, list, name, url, created_by, license):
+ """
+ Creates a new source
+ """
+ # Create a new source
+ with self.backend.session() as session:
+ source = Source(
+ list = list,
+ name = name,
+ url = url,
+ created_by = created_by,
+ license = license,
+ )
+ session.add(source)
+ session.commit()
+
+ return source
+
+
+class Source(sqlmodel.SQLModel, table=True):
+ __tablename__ = "sources"
+
+ # ID
+ id : int = sqlmodel.Field(primary_key=True)
+
+ # Name
+ name : str
+
+ # URL
+ url : str
+
+ # Created At
+ created_at : datetime.datetime = sqlmodel.Field(
+ sa_column_kwargs = {"server_default" : sqlmodel.text("CURRENT_TIMESTAMP")}
+ )
+
+ # Created By
+ created_by : str
+
+ # Deleted At
+ deleted_at : datetime.datetime | None
+
+ # Deleted By
+ deleted_by : str | None
+
+ # License
+ license : str
+
+ # List ID
+ list_id : int = sqlmodel.Field(foreign_key="lists.id")
+
+ # List
+ list : "List" = sqlmodel.Relationship(back_populates="sources")
help=_("The license of the list"))
create_list.set_defaults(func=self.__create_list)
+ # list-add-source
+ list_add_source = subparsers.add_parser("list-add-source",
+ help=_("Creates a new source to a list"))
+ list_add_source.add_argument("list",
+ help=_("The name of the list"))
+ list_add_source.add_argument("--name", required=True,
+ help=_("The name of the source"))
+ list_add_source.add_argument("--url", required=True,
+ help=_("The URL of the source"))
+ list_add_source.add_argument("--license", required=True,
+ help=_("The license of the source"))
+ list_add_source.add_argument("--created-by", required=True,
+ default=os.environ.get("USER"), help=_("The creator of the source"))
+ list_add_source.set_defaults(func=self.__list_add_source)
+
# update
update = subparsers.add_parser("update", help=_("Update sources"))
update.set_defaults(func=self.__update)
license = args.license,
)
+ def __list_add_source(self, backend, args):
+ """
+ Adds a new source to a list
+ """
+ # Fetch the list
+ list = backend.lists.get_by_slug(args.list)
+
+ # Create the source
+ backend.sources.create(
+ list = list,
+ name = args.name,
+ url = args.url,
+ created_by = args.created_by,
+ license = args.license,
+ )
+
def __update(self, backend, args):
"""
Updates all sources