Skip to content

Commit

Permalink
Added file based IPv4 address allocation and updated documents
Browse files Browse the repository at this point in the history
  • Loading branch information
gregfoletta committed Oct 17, 2022
1 parent 5a45a69 commit 8b28d96
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@ Note that the password appears to always have an exclaimation mark, so be sure t

# IPv4 ADDRESSES

The `--ipv4-addresses` argument will eventually take two arguments, although only one is implemented at this stage:
The `--ipv4-addresses` argument takes two different arguments: a `file` or and `ipv4_address`

- It takes a single IPv4 address, and will apply this address to all registrations.
- It will take a file with an IP address on each line, and apply each IP to eace (not currently implemented).
Some devices do not take an IP address (for example, FortiGates). This script will not discriminate, and will still try to apply the IP address. Recommendation it that if you're using this command, separate the licenses that require an IP into a different folder. You can this run this script across that folder with this --ipv4-addresses argument.

Some devices do not take an IP address (for example, FortiGates). This script will not discriminate, and will still try to apply the IP address. Recommendation it that if you're using this command, separate the licenses that require an IP into a different folder. You can this run this script across that folder with this --ipv4-addresses argument.
## --ipv4-addresses <file>

When given a file, the script opens it and reads in each line, expecting it to be an IPv4 address. If it's not an IPv4 address, it skips the
line. Any line starting with '#' is considered a comment and skipped.

It then uses one of these IPv4 addresses in each of the license registration requests. If there 'n' licenses and 'm' IPv4 addresses in the file, then the last (n - 4) licenses will not include an IPv4 adsdress.

## --ipv4-addresses <ipv4\_address>

If it cannot open a file, the script will then check to see if it is an IPv4 address. It will then include this address in every license registration request. This is useful if you're registering the licenses for a lab where the IP addressing matches across each lab 'pod'.

# LICENSE DOWNLOAD

Expand All @@ -89,11 +97,3 @@ The registration API generally returns the license keys for the codes you regist
- Some devices require an IP specification, which will not have been done rendering the license useless.

You will get warnings in the console for registration codes that do not return a license.

# POD ERRORS

Hey! **The above document had some coding errors, which are explained below:**

- Around line 146:

You forgot a '=back' before '=head1'
49 changes: 40 additions & 9 deletions ftnt_license_registration
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,20 @@ Note that the password appears to always have an exclaimation mark, so be sure t
=head1 IPv4 ADDRESSES
The C<--ipv4-addresses> argument will eventually take two arguments, although only one is implemented at this stage:
The C<--ipv4-addresses> argument takes two different arguments: a C<file> or and C<ipv4_address>
=over
Some devices do not take an IP address (for example, FortiGates). This script will not discriminate, and will still try to apply the IP address. Recommendation it that if you're using this command, separate the licenses that require an IP into a different folder. You can this run this script across that folder with this --ipv4-addresses argument.
=item It takes a single IPv4 address, and will apply this address to all registrations.
=head2 --ipv4-addresses <file>
=item It will take a file with an IP address on each line, and apply each IP to eace (not currently implemented).
When given a file, the script opens it and reads in each line, expecting it to be an IPv4 address. If it's not an IPv4 address, it skips the
line. Any line starting with '#' is considered a comment and skipped.
Some devices do not take an IP address (for example, FortiGates). This script will not discriminate, and will still try to apply the IP address. Recommendation it that if you're using this command, separate the licenses that require an IP into a different folder. You can this run this script across that folder with this --ipv4-addresses argument.
It then uses one of these IPv4 addresses in each of the license registration requests. If there 'n' licenses and 'm' IPv4 addresses in the file, then the last (n - m) licenses will not include an IPv4 addresses.
=head2 --ipv4-addresses <ipv4_address>
If it cannot open a file, the script will then check to see if it is an IPv4 address. It will then include this address in every license registration request. This is useful if you're registering the licenses for a lab where the IP addressing matches across each lab 'pod'.
=head1 LICENSE DOWNLOAD
Expand Down Expand Up @@ -231,12 +236,15 @@ sub license_ipv4_addresses {

return () unless defined $ip_or_file;

if (open(my $fh, "<:encoding(UTF-8)", $ip_or_file)) {
log_warning "File-based '--ip-addresses' not implemented yet, ignoring";
return ();
my $open_ret = open(my $fh, "<:encoding(UTF-8)", $ip_or_file);

if ($open_ret) {
log_output "Successfully opened IPv4 address list '$ip_or_file'";
@ips = ipv4_addresses_from_file($fh);
} else {
log_output "Cannot open '$ip_or_file' as file, treating as IPv4 address";
# Rough IPv4 validation
if ($ip_or_file =~ m{ (\d{1,3}\.){3} \d{1,3}$}xms) {
if (is_ipv4_address($ip_or_file)) {
@ips = ($ip_or_file) x $n_codes;
} else {
log_warning "Argument to '--ipv4-addresses' is neither a file, nor an IP address, ignoring";
Expand All @@ -245,6 +253,29 @@ sub license_ipv4_addresses {
}
}

# Close enough to an IPv4 address
sub is_ipv4_address { return $_[0] =~ m{^(\d{1,3}\.){3} \d{1,3}$}xms }

sub ipv4_addresses_from_file {
my ($fh) = @_;
my @ipv4;

while (my $line = <$fh>) {
chomp $line;
# Skip comments
next if $line =~ m{^\s*#};
if (!is_ipv4_address($line)) {
log_warning "'$line' is not an IPv4 address, skipping";
next;
}

push @ipv4, $line;
}

return @ipv4;
}




sub extract_reg_codes {
Expand Down

0 comments on commit 8b28d96

Please sign in to comment.