From 49fb992d7513e43eb9b183e6fa82520d4db1656d Mon Sep 17 00:00:00 2001 From: mischa Date: Tue, 3 Jan 2023 13:46:44 +0100 Subject: [PATCH] better method to compare dates, ignore future year for multiyear payments --- notify.pl | 11 +++++++---- vms/vm01.txt | 2 +- vms/vm02.txt | 2 +- vms/vm03.txt | 2 +- vms/vm04.txt | 8 ++++---- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/notify.pl b/notify.pl index a984a7e..033605b 100755 --- a/notify.pl +++ b/notify.pl @@ -32,7 +32,7 @@ my $function = $ARGV[0] || "empty"; my $function_variable = $ARGV[1] || "empty"; # define the prices for the different components of the VM -my $base_price = '60'; +my $base_price = '64'; my %memory_prices = ('2G' => '10', '4G' => '30', '8G' => '70'); my %hdd_prices = ('50G' => '50', '100G' => '100', '150G' => '150', '200G' => '200'); @@ -183,10 +183,13 @@ if ($function =~ /notify/) { my $month = strftime("%m", localtime); for my $vm_name (sort keys %vms) { if ($vms{$vm_name}{'donated'} =~ /(done|expire|sponsor|renewal)/) { delete $vms{$vm_name}; next; } - if ($vms{$vm_name}{'date'} =~ /$year\//) { delete $vms{$vm_name}; next; } - if ($vms{$vm_name}{'date'} !~ /\/$month\//) { delete $vms{$vm_name}; next; } + + my ($_vm_year, $_vm_month, $_vm_day) = split('/', $vms{$vm_name}{'date'}); + if ($_vm_year >= $year) { delete $vms{$vm_name}; next; } + if ($_vm_month != $month) { delete $vms{$vm_name}; next; } + if ($function =~ /(renewal|deprovision)/) { - if (defined $vms{$vm_name}{'subscription'} and $vms{$vm_name}{'subscription'} =~ /yes/) { delete $vms{$vm_name}; next; } + if (defined $vms{$vm_name}{'subscription'} and $vms{$vm_name}{'subscription'} ne "") { delete $vms{$vm_name}; next; } } if ($function =~ /subscription/) { if (!defined $vms{$vm_name}{'subscription'} or $vms{$vm_name}{'subscription'} eq "" or $vms{$vm_name}{'subscription'} =~ /no/) { delete $vms{$vm_name}; next; } diff --git a/vms/vm01.txt b/vms/vm01.txt index ec75b15..58109a8 100644 --- a/vms/vm01.txt +++ b/vms/vm01.txt @@ -1,7 +1,7 @@ mac="fe:e1:ab:dd:73:a4" ip="192.168.1.1" owner="testuser1" -date="2018/12/02" +date="2018/01/02" payment="70" donated="" name="Test1 User" diff --git a/vms/vm02.txt b/vms/vm02.txt index 06c2f23..788e889 100644 --- a/vms/vm02.txt +++ b/vms/vm02.txt @@ -1,4 +1,4 @@ -date="2018/07/02" +date="2018/02/02" payment="70" subscription="" donated="" diff --git a/vms/vm03.txt b/vms/vm03.txt index 672aee1..a669a76 100644 --- a/vms/vm03.txt +++ b/vms/vm03.txt @@ -1,4 +1,4 @@ -date="2020/07/21" +date="2020/01/21" payment="60" subscription="yes" donated="" diff --git a/vms/vm04.txt b/vms/vm04.txt index 34f947e..b6b721f 100644 --- a/vms/vm04.txt +++ b/vms/vm04.txt @@ -1,7 +1,7 @@ -date="2020/07/21" -payment="60" -subscription="no" -donated="" +date="2024/01/21" +payment="sponsor" +subscription="" +donated="sponsor" name="Test3" email="vm03@high5.nl" sshkey="ssh-ed25519 AAAAC3NzDI1NTE5AaaaIK7lMIQ4L4GcOyclKj9WLQPnHrGuP5ExjxZVmvLn"