From aaff68c0d55dc32f8972b9bde3239bb0923de140 Mon Sep 17 00:00:00 2001 From: UnicronNL Date: Sun, 1 Jul 2018 22:48:06 +0200 Subject: add vyos 1.x --- src/validators/interface-address | 3 ++ src/validators/ip-address | 3 ++ src/validators/ip-host | 3 ++ src/validators/ip-prefix | 3 ++ src/validators/ipv4-address | 3 ++ src/validators/ipv4-host | 3 ++ src/validators/ipv4-prefix | 3 ++ src/validators/ipv6-address | 3 ++ src/validators/ipv6-host | 3 ++ src/validators/ipv6-prefix | 3 ++ src/validators/numeric | 62 ++++++++++++++++++++++++++++++++++++++++ 11 files changed, 92 insertions(+) create mode 100755 src/validators/interface-address create mode 100755 src/validators/ip-address create mode 100755 src/validators/ip-host create mode 100755 src/validators/ip-prefix create mode 100755 src/validators/ipv4-address create mode 100755 src/validators/ipv4-host create mode 100755 src/validators/ipv4-prefix create mode 100755 src/validators/ipv6-address create mode 100755 src/validators/ipv6-host create mode 100755 src/validators/ipv6-prefix create mode 100755 src/validators/numeric (limited to 'src/validators') diff --git a/src/validators/interface-address b/src/validators/interface-address new file mode 100755 index 0000000..4c20395 --- /dev/null +++ b/src/validators/interface-address @@ -0,0 +1,3 @@ +#!/bin/sh + +ipaddrcheck --is-ipv4-host $1 || ipaddrcheck --is-ipv6-host $1 diff --git a/src/validators/ip-address b/src/validators/ip-address new file mode 100755 index 0000000..51fb72c --- /dev/null +++ b/src/validators/ip-address @@ -0,0 +1,3 @@ +#!/bin/sh + +ipaddrcheck --is-any-single $1 diff --git a/src/validators/ip-host b/src/validators/ip-host new file mode 100755 index 0000000..f2906e8 --- /dev/null +++ b/src/validators/ip-host @@ -0,0 +1,3 @@ +#!/bin/sh + +ipaddrcheck --is-any-host $1 diff --git a/src/validators/ip-prefix b/src/validators/ip-prefix new file mode 100755 index 0000000..e58aad3 --- /dev/null +++ b/src/validators/ip-prefix @@ -0,0 +1,3 @@ +#!/bin/sh + +ipaddrcheck --is-any-net $1 diff --git a/src/validators/ipv4-address b/src/validators/ipv4-address new file mode 100755 index 0000000..872a764 --- /dev/null +++ b/src/validators/ipv4-address @@ -0,0 +1,3 @@ +#!/bin/sh + +ipaddrcheck --is-ipv4-single $1 diff --git a/src/validators/ipv4-host b/src/validators/ipv4-host new file mode 100755 index 0000000..f42feff --- /dev/null +++ b/src/validators/ipv4-host @@ -0,0 +1,3 @@ +#!/bin/sh + +ipaddrcheck --is-ipv4-host $1 diff --git a/src/validators/ipv4-prefix b/src/validators/ipv4-prefix new file mode 100755 index 0000000..8ec8a2c --- /dev/null +++ b/src/validators/ipv4-prefix @@ -0,0 +1,3 @@ +#!/bin/sh + +ipaddrcheck --is-ipv4-net $1 diff --git a/src/validators/ipv6-address b/src/validators/ipv6-address new file mode 100755 index 0000000..e5d68d7 --- /dev/null +++ b/src/validators/ipv6-address @@ -0,0 +1,3 @@ +#!/bin/sh + +ipaddrcheck --is-ipv6-single $1 diff --git a/src/validators/ipv6-host b/src/validators/ipv6-host new file mode 100755 index 0000000..f7a7450 --- /dev/null +++ b/src/validators/ipv6-host @@ -0,0 +1,3 @@ +#!/bin/sh + +ipaddrcheck --is-ipv6-host $1 diff --git a/src/validators/ipv6-prefix b/src/validators/ipv6-prefix new file mode 100755 index 0000000..e436163 --- /dev/null +++ b/src/validators/ipv6-prefix @@ -0,0 +1,3 @@ +#!/bin/sh + +ipaddrcheck --is-ipv6-net $1 diff --git a/src/validators/numeric b/src/validators/numeric new file mode 100755 index 0000000..58a4fac --- /dev/null +++ b/src/validators/numeric @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +# +# numeric value validator +# +# Copyright (C) 2017 VyOS maintainers and contributors +# +# 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 2 +# 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 . + +import sys +import argparse +import re + +parser = argparse.ArgumentParser() +parser.add_argument("-f", "--float", action="store_true", help="Accept floating point values") +group = parser.add_mutually_exclusive_group() +group.add_argument("-r", "--range", type=str, help="Check if the number is within range (inclusive), example: 1024-65535") +group.add_argument("-n", "--non-negative", action="store_true", help="") +parser.add_argument("number", type=str, help="Number to validate") + +args = parser.parse_args() + +# Try to load the argument +number = None +if args.float: + try: + number = float(args.number) + except: + print("{0} is not a valid floating point number".format(args.number), file=sys.stderr) + sys.exit(1) +else: + try: + number = int(args.number) + except: + print("{0} is not a valid integer number".format(args.number), file=sys.stderr) + sys.exit(1) + +if args.range: + try: + lower, upper = re.match(r'(\d+)\s*\-\s*(\d+)', args.range).groups() + lower, upper = int(lower), int(upper) + except: + print("{0} is not a valid number range",format(args.range), file=sys.stderr) + sys.exit(1) + + if (number < lower) or (number > upper): + print("Number {0} is not in the {1} range".format(number, args.range), file=sys.stderr) + sys.exit(1) +elif args.non_negative: + if number < 0: + print("Number should be non-negative", file=sys.stderr) + sys.exit(1) -- cgit v1.2.3