summaryrefslogtreecommitdiff
path: root/src/validators
diff options
context:
space:
mode:
Diffstat (limited to 'src/validators')
-rwxr-xr-xsrc/validators/bgp-extended-community51
-rwxr-xr-xsrc/validators/ddclient-protocol24
-rwxr-xr-xsrc/validators/ipv6-link-local2
-rwxr-xr-xsrc/validators/port-multi2
-rwxr-xr-xsrc/validators/port-range2
-rwxr-xr-xsrc/validators/script6
-rwxr-xr-xsrc/validators/timezone6
7 files changed, 58 insertions, 35 deletions
diff --git a/src/validators/bgp-extended-community b/src/validators/bgp-extended-community
index b69ae3449..d66665519 100755
--- a/src/validators/bgp-extended-community
+++ b/src/validators/bgp-extended-community
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
-# Copyright 2019-2022 VyOS maintainers and contributors <maintainers@vyos.io>
+# Copyright 2019-2023 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -28,28 +28,27 @@ if __name__ == '__main__':
parser: ArgumentParser = ArgumentParser()
parser.add_argument('community', type=str)
args = parser.parse_args()
- community: str = args.community
- if community.count(':') != 1:
- print("Invalid community format")
- exit(1)
- try:
- # try to extract community parts from an argument
- comm_left: str = community.split(':')[0]
- comm_right: int = int(community.split(':')[1])
-
- # check if left part is an IPv4 address
- if is_ipv4(comm_left) and 0 <= comm_right <= COMM_MAX_2_OCTET:
- exit()
- # check if a left part is a number
- if 0 <= int(comm_left) <= COMM_MAX_2_OCTET \
- and 0 <= comm_right <= COMM_MAX_4_OCTET:
- exit()
-
- except Exception:
- # fail if something was wrong
- print("Invalid community format")
- exit(1)
-
- # fail if none of validators catched the value
- print("Invalid community format")
- exit(1) \ No newline at end of file
+
+ for community in args.community.split():
+ if community.count(':') != 1:
+ print("Invalid community format")
+ exit(1)
+ try:
+ # try to extract community parts from an argument
+ comm_left: str = community.split(':')[0]
+ comm_right: int = int(community.split(':')[1])
+
+ # check if left part is an IPv4 address
+ if is_ipv4(comm_left) and 0 <= comm_right <= COMM_MAX_2_OCTET:
+ continue
+ # check if a left part is a number
+ if 0 <= int(comm_left) <= COMM_MAX_2_OCTET \
+ and 0 <= comm_right <= COMM_MAX_4_OCTET:
+ continue
+
+ raise Exception()
+
+ except Exception:
+ # fail if something was wrong
+ print("Invalid community format")
+ exit(1) \ No newline at end of file
diff --git a/src/validators/ddclient-protocol b/src/validators/ddclient-protocol
new file mode 100755
index 000000000..6f927927b
--- /dev/null
+++ b/src/validators/ddclient-protocol
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# Copyright (C) 2023 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 version 2 or later 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
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ddclient -list-protocols | grep -qw $1
+
+if [ $? -gt 0 ]; then
+ echo "Error: $1 is not a valid protocol, please choose from the supported list of protocols"
+ exit 1
+fi
+
+exit 0
diff --git a/src/validators/ipv6-link-local b/src/validators/ipv6-link-local
index 05e693b77..6ac3ea710 100755
--- a/src/validators/ipv6-link-local
+++ b/src/validators/ipv6-link-local
@@ -1,7 +1,7 @@
#!/usr/bin/python3
import sys
-from vyos.validate import is_ipv6_link_local
+from vyos.utils.network import is_ipv6_link_local
if __name__ == '__main__':
if len(sys.argv)>1:
diff --git a/src/validators/port-multi b/src/validators/port-multi
index bd6f0ef60..ed6ff6849 100755
--- a/src/validators/port-multi
+++ b/src/validators/port-multi
@@ -4,7 +4,7 @@ from sys import argv
from sys import exit
import re
-from vyos.util import read_file
+from vyos.utils.file import read_file
services_file = '/etc/services'
diff --git a/src/validators/port-range b/src/validators/port-range
index 5468000a7..526c639ad 100755
--- a/src/validators/port-range
+++ b/src/validators/port-range
@@ -3,7 +3,7 @@
import sys
import re
-from vyos.util import read_file
+from vyos.utils.file import read_file
services_file = '/etc/services'
diff --git a/src/validators/script b/src/validators/script
index 4ffdeb2a0..eb176d23b 100755
--- a/src/validators/script
+++ b/src/validators/script
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2018-2021 VyOS maintainers and contributors
+# Copyright (C) 2018-2023 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
@@ -19,7 +19,7 @@ import os
import sys
import shlex
-import vyos.util
+from vyos.utils.file import file_is_persistent
if __name__ == '__main__':
if len(sys.argv) < 2:
@@ -35,7 +35,7 @@ if __name__ == '__main__':
sys.exit(f'File {script} is not an executable file')
# File outside the config dir is just a warning
- if not vyos.util.file_is_persistent(script):
+ if not file_is_persistent(script):
sys.exit(0)(
f'Warning: file {script} is outside the "/config" directory\n'
'It will not be automatically migrated to a new image on system update'
diff --git a/src/validators/timezone b/src/validators/timezone
index baf5abca2..e55af8d2a 100755
--- a/src/validators/timezone
+++ b/src/validators/timezone
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2019 VyOS maintainers and contributors
+# Copyright (C) 2019-2023 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 version 2 or later as
@@ -17,7 +17,7 @@
import argparse
import sys
-from vyos.util import cmd
+from vyos.utils.process import cmd
if __name__ == '__main__':
@@ -25,7 +25,7 @@ if __name__ == '__main__':
parser.add_argument("--validate", action="store", required=True, help="Check if timezone is valid")
args = parser.parse_args()
- tz_data = cmd('find /usr/share/zoneinfo/posix -type f -or -type l | sed -e s:/usr/share/zoneinfo/posix/::')
+ tz_data = cmd('timedatectl list-timezones')
tz_data = tz_data.split('\n')
if args.validate not in tz_data: