-
Notifications
You must be signed in to change notification settings - Fork 18
/
check_invalid_config
executable file
·97 lines (83 loc) · 3.88 KB
/
check_invalid_config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl
# Copyright 2021-2023 Citrix Systems, Inc. All rights reserved.
# Use of this software is governed by the license terms, if any,
# which accompany or are included with this software.
$ENV{PATH} = '/var/python/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'.$ENV{PATH};
use File::Basename;
# checking if python and ply are present
# Output would be /var/python/bin/python if python is
# present, otherwise output would be empty string.
my $python_version_string = `which python 2> /dev/null`;
if ($python_version_string eq "") {
# Python2 is not installed
print "\nAs python is not present, we can't check for an invalid configuration\n";
exit;
}
my $python_module_list = `python -m pip freeze 2> /dev/null`;
if (!($python_module_list =~ m/\bply==/)) {
# ply is not present
print "\nAs required module PLY is not present, we can't check for an invalid configuration\n";
exit;
}
my $number_args = $#ARGV + 1;
if ($number_args > 3 or $number_args < 1) {
tool_usage();
exit;
}
my($buildVersion) ="13.1";
my @allowed_build_versions = ("13.1", "14.1");
if ($number_args == 3) {
if (uc($ARGV[1]) ne "-BUILDVERSION") {
tool_usage();
exit;
}
$buildVersion = $ARGV[2];
if (not grep(/^$buildVersion/, @allowed_build_versions)) {
print "Incorrect build version\n";
exit;
}
} elsif ($number_args > 1) {
print "Incorrect parameters\n";
tool_usage();
exit;
}
my $config_file = $ARGV[0];
if (not -e $config_file) {
print "No such file: $config_file\n";
exit;
}
sub tool_usage() {
print "Usage: check_invalid_config <ns_config_file> -buildVersion <Build version for which invalid or depreacted commands need to check>\n";
}
my($filename, $dir_path) = fileparse($config_file);
my $dirname = dirname(__FILE__);
my $exit_status = system("python $dirname/nspepi2/config_check_main.py -f $config_file -B $buildVersion");
if ($exit_status != 0) {
print "Error in checking config file: $exit_status";
exit;
}
my $invalid_config_file = $dir_path."/issues_".$filename;
my $deprecated_config_file = $dir_path."deprecated_".$filename;
# Checks whether any command is present in the file
if (!(-z $invalid_config_file)) {
print "\nThe following configuration lines will get errors in ".$buildVersion." and both they and dependent configuration will be removed from the configuration:\n";
system("cat $invalid_config_file");
print "\nThe nspepi upgrade tool can be useful in converting your configuration - see the documentation at https://docs.citrix.com/en-us/citrix-adc/current-release/appexpert/policies-and-expressions/introduction-to-policies-and-exp/converting-policy-expressions-nspepi-tool.html.\n";
print "\nNOTE: the nspepi tool doesn't convert the following configurations:\n\t1. SureConnect commands\n\t2. PriorityQueuing commands\n\t3. HTTP Denial of Service Protection commands\n\t4. HTMLInjection commands.\n";
if (!(-z $deprecated_config_file)) {
print "\nNOTE: some deprecated commands have also been detected in the config file, please check ".$deprecated_config_file." file for the deprecated commands.\n";
} else {
print "\nNOTE: No deprecated commands detected in the configuration.\n";
}
} else {
if (!(-z $deprecated_config_file)) {
print "\nThe following configuration lines have been deprecated in ".$buildVersion." and will be removed in future releases:\n";
system("tail -n 10 $deprecated_config_file");
print "\nFor the complete deprecated commands, please see the output of ".$deprecated_config_file." file.\n";
print "\nNo invalid config detected with the configuration.\n";
} else {
print "\nNo invalid or deprecated config detected with the configuration.\n";
}
}
print "\nUse pre-validation tool and nspepi tool available at https://github.com/citrix/ADC-scripts/tree/master/nspepi for the most complete and up-to-date version.\n"
### End check_invalid_config script