summaryrefslogtreecommitdiffstats
path: root/suricata/update/commands/addsource.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:43:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:43:34 +0000
commit0fcce96a175531ec6042cde1b11a0052aa261dd5 (patch)
tree898a1e161c4984b41e6a732866bd73b24f0f7b7a /suricata/update/commands/addsource.py
parentInitial commit. (diff)
downloadsuricata-update-0fcce96a175531ec6042cde1b11a0052aa261dd5.tar.xz
suricata-update-0fcce96a175531ec6042cde1b11a0052aa261dd5.zip
Adding upstream version 1.3.2.upstream/1.3.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--suricata/update/commands/addsource.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/suricata/update/commands/addsource.py b/suricata/update/commands/addsource.py
new file mode 100644
index 0000000..a87095c
--- /dev/null
+++ b/suricata/update/commands/addsource.py
@@ -0,0 +1,72 @@
+# Copyright (C) 2017 Open Information Security Foundation
+#
+# You can copy, redistribute or modify this Program under the terms of
+# the GNU General Public License version 2 as published by the Free
+# Software Foundation.
+#
+# 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
+# version 2 along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+from __future__ import print_function
+
+import logging
+
+from suricata.update import config
+from suricata.update import sources
+
+try:
+ input = raw_input
+except:
+ pass
+
+logger = logging.getLogger()
+
+
+def register(parser):
+ parser.add_argument("name", metavar="<name>", nargs="?",
+ help="Name of source")
+ parser.add_argument("url", metavar="<url>", nargs="?", help="Source URL")
+ parser.add_argument("--http-header", metavar="<http-header>",
+ help="Additional HTTP header to add to requests")
+ parser.add_argument("--no-checksum", action="store_false",
+ help="Skips downloading the checksum URL")
+ parser.set_defaults(func=add_source)
+
+
+def add_source():
+ args = config.args()
+
+ if args.name:
+ name = args.name
+ else:
+ while True:
+ name = input("Name of source: ").strip()
+ if name:
+ break
+
+ if sources.source_name_exists(name):
+ logger.error("A source with name %s already exists.", name)
+ return 1
+
+ if args.url:
+ url = args.url
+ else:
+ while True:
+ url = input("URL: ").strip()
+ if url:
+ break
+
+ checksum = args.no_checksum
+
+ header = args.http_header if args.http_header else None
+
+ source_config = sources.SourceConfiguration(
+ name, header=header, url=url, checksum=checksum)
+ sources.save_source_config(source_config)