summaryrefslogtreecommitdiff
path: root/src/validators
diff options
context:
space:
mode:
Diffstat (limited to 'src/validators')
-rwxr-xr-xsrc/validators/interface-address3
-rwxr-xr-xsrc/validators/ip-address3
-rwxr-xr-xsrc/validators/ip-host3
-rwxr-xr-xsrc/validators/ip-prefix3
-rwxr-xr-xsrc/validators/ipv4-address3
-rwxr-xr-xsrc/validators/ipv4-host3
-rwxr-xr-xsrc/validators/ipv4-prefix3
-rwxr-xr-xsrc/validators/ipv6-address3
-rwxr-xr-xsrc/validators/ipv6-host3
-rwxr-xr-xsrc/validators/ipv6-prefix3
-rwxr-xr-xsrc/validators/numeric62
11 files changed, 92 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
+
+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)