diff --git a/notify.pl b/notify.pl index c1fcb2a..05de4d5 100755 --- a/notify.pl +++ b/notify.pl @@ -72,10 +72,17 @@ sub deployed { my $_vms = $conf{'conf'}{'VMS'}; my $_tmpl = $conf{'conf'}{'TEMPLATES'}; my $_server = $conf{'conf'}{'SERVER'}; - my $template = "$_tmpl/email-deployed.txt"; my $_ip4netmask = $conf{'conf'}{'NETMASK'}; my $_ip4gw = $conf{'conf'}{'ROUTER'}; + my $template = "$_tmpl/email-deployed.txt"; + + my $year = strftime("%Y", localtime); + my $month = strftime("%m", localtime); + my $server_number = $1 if $_server =~ /([0-9]+)/; + my $oddeven = $server_number % 2; + my @stopped_vms = qx(vmctl show | grep stopped | awk '{print \$9}'); + for my $vm_name (sort keys %vms) { my $_date = $vms{$vm_name}{'date'}; my $_payment = $vms{$vm_name}{'payment'}; @@ -83,7 +90,6 @@ sub deployed { my $_name = $vms{$vm_name}{'name'}; my $_email = $vms{$vm_name}{'email'}; my $_hostname = $vms{$vm_name}{'hostname'}; - my $_boot = $vms{$vm_name}{'boot'} || "yes"; if ($function_variable =~ /empty/) { print "No VMID provided\n"; last; } if ($function_variable =~ /$vm_name/) { @@ -105,6 +111,18 @@ sub deployed { $row =~ s/IPV6GW$/$ip6gw/g; $row =~ s/VMID/$vm_name/g; $row =~ s/SERVER/$_server/g; + + $row =~ s/YEAR/$year/g; + $row =~ s/TOTAL_DONATED/$total_donated/g; + $row =~ s/TOTAL_VMS/$total_vms/g; + $row =~ s/TOTAL_HOSTS/$total_hosts/g; + $row =~ s/PAYMENT/$_payment/g; + + if ($row =~ /TIME\((.*)\)/) { + my @TIMES = split(/,/, $1); + $row =~ s/TIME\(.*\)/$TIMES[$oddeven]/g; + } + print $fh_email "$row\n"; } close $fh_email; @@ -121,8 +139,15 @@ sub stopped { my $_vms = $conf{'conf'}{'VMS'}; my $_tmpl = $conf{'conf'}{'TEMPLATES'}; my $_server = $conf{'conf'}{'SERVER'}; + my $_ip4netmask = $conf{'conf'}{'NETMASK'}; + my $_ip4gw = $conf{'conf'}{'ROUTER'}; + my $template = "$_tmpl/email-stopped.txt"; + my $year = strftime("%Y", localtime); + my $month = strftime("%m", localtime); + my $server_number = $1 if $_server =~ /([0-9]+)/; + my $oddeven = $server_number % 2; my @stopped_vms = qx(vmctl show | grep stopped | awk '{print \$9}'); for my $vm_name (sort keys %vms) { @@ -132,15 +157,12 @@ sub stopped { my $_name = $vms{$vm_name}{'name'}; my $_email = $vms{$vm_name}{'email'}; my $_hostname = $vms{$vm_name}{'hostname'}; - my $_boot = $vms{$vm_name}{'boot'} || "yes"; - if ($_boot =~ /no/) { - print "NOT NOTIFIED: $_name, $_email, $_hostname, $_server ($vm_name)\n"; - next; - } if (grep(/$vm_name/, @stopped_vms)) { (my $_firstname, my $_lastname) = split(/ /, $_name, 2); my $ip4address = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n'); + my $ip6address = qx(grep -A3 $vm_name $_etc/dhcpd.conf | awk '/fixed-address-ipv6/{print \$2}' | tr -d ';\n'); + (my $ip6gw = $ip6address) =~ s/::.*/::1/; open(my $fh, '<', $template); open my $fh_email, "|-", "/usr/sbin/sendmail -t"; @@ -148,9 +170,25 @@ sub stopped { while (my $row = <$fh>) { chomp $row; $row =~ s/NAME/$_firstname/g; - $row =~ s/IPV4/$ip4address/g; + $row =~ s/IPV4$/$ip4address/g; + $row =~ s/IPV4NETMASK$/$_ip4netmask/g; + $row =~ s/IPV4GW$/$_ip4gw/g; + $row =~ s/IPV6$/$ip6address/g; + $row =~ s/IPV6GW$/$ip6gw/g; $row =~ s/VMID/$vm_name/g; $row =~ s/SERVER/$_server/g; + + $row =~ s/YEAR/$year/g; + $row =~ s/TOTAL_DONATED/$total_donated/g; + $row =~ s/TOTAL_VMS/$total_vms/g; + $row =~ s/TOTAL_HOSTS/$total_hosts/g; + $row =~ s/PAYMENT/$_payment/g; + + if ($row =~ /TIME\((.*)\)/) { + my @TIMES = split(/,/, $1); + $row =~ s/TIME\(.*\)/$TIMES[$oddeven]/g; + } + print $fh_email "$row\n"; } close $fh_email; @@ -166,14 +204,16 @@ sub renewal { my $_vms = $conf{'conf'}{'VMS'}; my $_tmpl = $conf{'conf'}{'TEMPLATES'}; my $_server = $conf{'conf'}{'SERVER'}; + my $_ip4netmask = $conf{'conf'}{'NETMASK'}; + my $_ip4gw = $conf{'conf'}{'ROUTER'}; + my $template = "$_tmpl/email-renewal.txt"; my $year = strftime("%Y", localtime); my $month = strftime("%m", localtime); - - #my $total_donated = qx(ftp -Vo- https://obsda.ms/index.html | grep "donated to the OpenBSD" | awk -F';' '{print \$4}' | awk '{printf \$1}'); - #my $total_vms = qx(ftp -Vo- https://obsda.ms/index.html | grep "deployed" | awk -F '>' '{print \$3}' | awk '{printf \$1}'); - #my $total_hosts = qx(ftp -Vo- https://obsda.ms/servers.html | grep -c ">Server " | tr -d '\n'); + my $server_number = $1 if $_server =~ /([0-9]+)/; + my $oddeven = $server_number % 2; + my @stopped_vms = qx(vmctl show | grep stopped | awk '{print \$9}'); my $response = HTTP::Tiny->new->get('https://openbsd.amsterdam/index.html'); my $total_donated = $1 if $response->{'content'} =~ /([0-9,]+) donated to the OpenBSD/; @@ -189,7 +229,6 @@ sub renewal { my $_name = $vms{$vm_name}{'name'}; my $_email = $vms{$vm_name}{'email'}; my $_hostname = $vms{$vm_name}{'hostname'}; - my $_boot = $vms{$vm_name}{'boot'} || "yes"; if ($_subscription =~ /yes/) { next; } if ($_donated =~ /done/) { next; } @@ -201,6 +240,8 @@ sub renewal { (my $_firstname, my $_lastname) = split(/ /, $_name, 2); (my $_year, my $_month, my $_day) = split(/\//, $_date, 3); my $ip4address = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n'); + my $ip6address = qx(grep -A3 $vm_name $_etc/dhcpd.conf | awk '/fixed-address-ipv6/{print \$2}' | tr -d ';\n'); + (my $ip6gw = $ip6address) =~ s/::.*/::1/; open(my $fh, '<', $template); open my $fh_email, "|-", "/usr/sbin/sendmail -t"; @@ -208,7 +249,11 @@ sub renewal { while (my $row = <$fh>) { chomp $row; $row =~ s/NAME/$_firstname/g; - $row =~ s/IPV4/$ip4address/g; + $row =~ s/IPV4$/$ip4address/g; + $row =~ s/IPV4NETMASK$/$_ip4netmask/g; + $row =~ s/IPV4GW$/$_ip4gw/g; + $row =~ s/IPV6$/$ip6address/g; + $row =~ s/IPV6GW$/$ip6gw/g; $row =~ s/VMID/$vm_name/g; $row =~ s/SERVER/$_server/g; @@ -218,6 +263,11 @@ sub renewal { $row =~ s/TOTAL_HOSTS/$total_hosts/g; $row =~ s/PAYMENT/$_payment/g; + if ($row =~ /TIME\((.*)\)/) { + my @TIMES = split(/,/, $1); + $row =~ s/TIME\(.*\)/$TIMES[$oddeven]/g; + } + print $fh_email "$row\n"; } close $fh_email; @@ -233,14 +283,16 @@ sub subscription { my $_vms = $conf{'conf'}{'VMS'}; my $_tmpl = $conf{'conf'}{'TEMPLATES'}; my $_server = $conf{'conf'}{'SERVER'}; + my $_ip4netmask = $conf{'conf'}{'NETMASK'}; + my $_ip4gw = $conf{'conf'}{'ROUTER'}; + my $template = "$_tmpl/email-subscription.txt"; my $year = strftime("%Y", localtime); my $month = strftime("%m", localtime); - - #my $total_donated = qx(ftp -Vo- https://obsda.ms/index.html | grep "donated to the OpenBSD" | awk -F';' '{print \$4}' | awk '{printf \$1}'); - #my $total_vms = qx(ftp -Vo- https://obsda.ms/index.html | grep "deployed" | awk -F '>' '{print \$3}' | awk '{printf \$1}'); - #my $total_hosts = qx(ftp -Vo- https://obsda.ms/servers.html | grep -c ">Server " | tr -d '\n'); + my $server_number = $1 if $_server =~ /([0-9]+)/; + my $oddeven = $server_number % 2; + my @stopped_vms = qx(vmctl show | grep stopped | awk '{print \$9}'); my $response = HTTP::Tiny->new->get('https://openbsd.amsterdam/index.html'); my $total_donated = $1 if $response->{'content'} =~ /([0-9,]+) donated to the OpenBSD/; @@ -256,7 +308,6 @@ sub subscription { my $_name = $vms{$vm_name}{'name'}; my $_email = $vms{$vm_name}{'email'}; my $_hostname = $vms{$vm_name}{'hostname'}; - my $_boot = $vms{$vm_name}{'boot'} || "yes"; if ($_subscription =~ /no/) { next; } if ($_donated =~ /done/) { next; } @@ -268,6 +319,8 @@ sub subscription { (my $_firstname, my $_lastname) = split(/ /, $_name, 2); (my $_year, my $_month, my $_day) = split(/\//, $_date, 3); my $ip4address = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n'); + my $ip6address = qx(grep -A3 $vm_name $_etc/dhcpd.conf | awk '/fixed-address-ipv6/{print \$2}' | tr -d ';\n'); + (my $ip6gw = $ip6address) =~ s/::.*/::1/; open(my $fh, '<', $template); open my $fh_email, "|-", "/usr/sbin/sendmail -t"; @@ -275,7 +328,11 @@ sub subscription { while (my $row = <$fh>) { chomp $row; $row =~ s/NAME/$_firstname/g; - $row =~ s/IPV4/$ip4address/g; + $row =~ s/IPV4$/$ip4address/g; + $row =~ s/IPV4NETMASK$/$_ip4netmask/g; + $row =~ s/IPV4GW$/$_ip4gw/g; + $row =~ s/IPV6$/$ip6address/g; + $row =~ s/IPV6GW$/$ip6gw/g; $row =~ s/VMID/$vm_name/g; $row =~ s/SERVER/$_server/g; @@ -285,6 +342,11 @@ sub subscription { $row =~ s/TOTAL_HOSTS/$total_hosts/g; $row =~ s/PAYMENT/$_payment/g; + if ($row =~ /TIME\((.*)\)/) { + my @TIMES = split(/,/, $1); + $row =~ s/TIME\(.*\)/$TIMES[$oddeven]/g; + } + print $fh_email "$row\n"; } close $fh_email; @@ -301,9 +363,16 @@ sub notify { my $_vms = $conf{'conf'}{'VMS'}; my $_tmpl = $conf{'conf'}{'TEMPLATES'}; my $_server = $conf{'conf'}{'SERVER'}; + my $_ip4netmask = $conf{'conf'}{'NETMASK'}; + my $_ip4gw = $conf{'conf'}{'ROUTER'}; + my $template = "$_tmpl/email-notify.txt"; + + my $year = strftime("%Y", localtime); + my $month = strftime("%m", localtime); my $server_number = $1 if $_server =~ /([0-9]+)/; my $oddeven = $server_number % 2; + my @stopped_vms = qx(vmctl show | grep stopped | awk '{print \$9}'); for my $vm_name (sort keys %vms) { my $_date = $vms{$vm_name}{'date'}; @@ -312,12 +381,12 @@ sub notify { my $_name = $vms{$vm_name}{'name'}; my $_email = $vms{$vm_name}{'email'}; my $_hostname = $vms{$vm_name}{'hostname'}; - my $_boot = $vms{$vm_name}{'boot'} || "yes"; if (-e "$template") { - #if ($_boot =~ /yes/) { (my $_firstname, my $_lastname) = split(/ /, $_name, 2); my $ip4address = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n'); + my $ip6address = qx(grep -A3 $vm_name $_etc/dhcpd.conf | awk '/fixed-address-ipv6/{print \$2}' | tr -d ';\n'); + (my $ip6gw = $ip6address) =~ s/::.*/::1/; open(my $fh, '<', $template); open my $fh_email, "|-", "/usr/sbin/sendmail -t"; @@ -325,13 +394,25 @@ sub notify { while (my $row = <$fh>) { chomp $row; $row =~ s/NAME/$_firstname/g; - $row =~ s/IPV4/$ip4address/g; + $row =~ s/IPV4$/$ip4address/g; + $row =~ s/IPV4NETMASK$/$_ip4netmask/g; + $row =~ s/IPV4GW$/$_ip4gw/g; + $row =~ s/IPV6$/$ip6address/g; + $row =~ s/IPV6GW$/$ip6gw/g; $row =~ s/VMID/$vm_name/g; $row =~ s/SERVER/$_server/g; + + $row =~ s/YEAR/$year/g; + $row =~ s/TOTAL_DONATED/$total_donated/g; + $row =~ s/TOTAL_VMS/$total_vms/g; + $row =~ s/TOTAL_HOSTS/$total_hosts/g; + $row =~ s/PAYMENT/$_payment/g; + if ($row =~ /TIME\((.*)\)/) { my @TIMES = split(/,/, $1); $row =~ s/TIME\(.*\)/$TIMES[$oddeven]/g; } + print $fh_email "$row\n"; } close $fh_email; @@ -347,9 +428,16 @@ sub msg { my $_vms = $conf{'conf'}{'VMS'}; my $_tmpl = $conf{'conf'}{'TEMPLATES'}; my $_server = $conf{'conf'}{'SERVER'}; + my $_ip4netmask = $conf{'conf'}{'NETMASK'}; + my $_ip4gw = $conf{'conf'}{'ROUTER'}; + my $template = "$_tmpl/email-msg.txt"; + + my $year = strftime("%Y", localtime); + my $month = strftime("%m", localtime); my $server_number = $1 if $_server =~ /([0-9]+)/; my $oddeven = $server_number % 2; + my @stopped_vms = qx(vmctl show | grep stopped | awk '{print \$9}'); for my $vm_name (sort keys %vms) { my $_date = $vms{$vm_name}{'date'}; @@ -358,12 +446,13 @@ sub msg { my $_name = $vms{$vm_name}{'name'}; my $_email = $vms{$vm_name}{'email'}; my $_hostname = $vms{$vm_name}{'hostname'}; - my $_boot = $vms{$vm_name}{'boot'} || "yes"; if ($function_variable =~ /empty/) { print "No VMID provided\n"; last; } if ($function_variable =~ /$vm_name/) { (my $_firstname, my $_lastname) = split(/ /, $_name, 2); my $ip4address = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n'); + my $ip6address = qx(grep -A3 $vm_name $_etc/dhcpd.conf | awk '/fixed-address-ipv6/{print \$2}' | tr -d ';\n'); + (my $ip6gw = $ip6address) =~ s/::.*/::1/; open(my $fh, '<', $template); open my $fh_email, "|-", "/usr/sbin/sendmail -t"; @@ -371,13 +460,25 @@ sub msg { while (my $row = <$fh>) { chomp $row; $row =~ s/NAME/$_firstname/g; - $row =~ s/IPV4/$ip4address/g; + $row =~ s/IPV4$/$ip4address/g; + $row =~ s/IPV4NETMASK$/$_ip4netmask/g; + $row =~ s/IPV4GW$/$_ip4gw/g; + $row =~ s/IPV6$/$ip6address/g; + $row =~ s/IPV6GW$/$ip6gw/g; $row =~ s/VMID/$vm_name/g; $row =~ s/SERVER/$_server/g; + + $row =~ s/YEAR/$year/g; + $row =~ s/TOTAL_DONATED/$total_donated/g; + $row =~ s/TOTAL_VMS/$total_vms/g; + $row =~ s/TOTAL_HOSTS/$total_hosts/g; + $row =~ s/PAYMENT/$_payment/g; + if ($row =~ /TIME\((.*)\)/) { my @TIMES = split(/,/, $1); $row =~ s/TIME\(.*\)/$TIMES[$oddeven]/g; } + print $fh_email "$row\n"; } close $fh_email; @@ -393,10 +494,16 @@ sub deprovision { my $_vms = $conf{'conf'}{'VMS'}; my $_tmpl = $conf{'conf'}{'TEMPLATES'}; my $_server = $conf{'conf'}{'SERVER'}; + my $_ip4netmask = $conf{'conf'}{'NETMASK'}; + my $_ip4gw = $conf{'conf'}{'ROUTER'}; + my $template = "$_tmpl/email-deprovision.txt"; my $year = strftime("%Y", localtime); my $month = strftime("%m", localtime); + my $server_number = $1 if $_server =~ /([0-9]+)/; + my $oddeven = $server_number % 2; + my @stopped_vms = qx(vmctl show | grep stopped | awk '{print \$9}'); for my $vm_name (sort keys %vms) { my $_date = $vms{$vm_name}{'date'}; @@ -406,7 +513,6 @@ sub deprovision { my $_name = $vms{$vm_name}{'name'}; my $_email = $vms{$vm_name}{'email'}; my $_hostname = $vms{$vm_name}{'hostname'}; - my $_boot = $vms{$vm_name}{'boot'} || "yes"; if ($_subscription =~ /yes/) { next; } if ($_donated =~ /done/) { next; } @@ -418,6 +524,8 @@ sub deprovision { (my $_firstname, my $_lastname) = split(/ /, $_name, 2); (my $_year, my $_month, my $_day) = split(/\//, $_date, 3); my $ip4address = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n'); + my $ip6address = qx(grep -A3 $vm_name $_etc/dhcpd.conf | awk '/fixed-address-ipv6/{print \$2}' | tr -d ';\n'); + (my $ip6gw = $ip6address) =~ s/::.*/::1/; open(my $fh, '<', $template); open my $fh_email, "|-", "/usr/sbin/sendmail -t"; @@ -425,9 +533,25 @@ sub deprovision { while (my $row = <$fh>) { chomp $row; $row =~ s/NAME/$_firstname/g; - $row =~ s/IPV4/$ip4address/g; + $row =~ s/IPV4$/$ip4address/g; + $row =~ s/IPV4NETMASK$/$_ip4netmask/g; + $row =~ s/IPV4GW$/$_ip4gw/g; + $row =~ s/IPV6$/$ip6address/g; + $row =~ s/IPV6GW$/$ip6gw/g; $row =~ s/VMID/$vm_name/g; $row =~ s/SERVER/$_server/g; + + $row =~ s/YEAR/$year/g; + $row =~ s/TOTAL_DONATED/$total_donated/g; + $row =~ s/TOTAL_VMS/$total_vms/g; + $row =~ s/TOTAL_HOSTS/$total_hosts/g; + $row =~ s/PAYMENT/$_payment/g; + + if ($row =~ /TIME\((.*)\)/) { + my @TIMES = split(/,/, $1); + $row =~ s/TIME\(.*\)/$TIMES[$oddeven]/g; + } + print $fh_email "$row\n"; } close $fh_email; @@ -444,7 +568,17 @@ sub debug_parse { my $_vms = $conf{'conf'}{'VMS'}; my $_tmpl = $conf{'conf'}{'TEMPLATES'}; my $_server = $conf{'conf'}{'SERVER'}; + my $_ip4netmask = $conf{'conf'}{'NETMASK'}; + my $_ip4gw = $conf{'conf'}{'ROUTER'}; + my $template = "$_tmpl/email-debug.txt"; + + my $year = strftime("%Y", localtime); + my $month = strftime("%m", localtime); + my $server_number = $1 if $_server =~ /([0-9]+)/; + my $oddeven = $server_number % 2; + my @stopped_vms = qx(vmctl show | grep stopped | awk '{print \$9}'); + print "All VMs\n##\n"; for my $vm_name (sort keys %vms) { my $_date = $vms{$vm_name}{'date'}; @@ -453,7 +587,6 @@ sub debug_parse { my $_name = $vms{$vm_name}{'name'}; my $_email = $vms{$vm_name}{'email'}; my $_hostname = $vms{$vm_name}{'hostname'}; - my $_boot = $vms{$vm_name}{'boot'} || "yes"; print "$_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name)\n"; } print "##\n"; diff --git a/relaunch.sh b/relaunch.sh index 3a65f31..d91fc1b 100755 --- a/relaunch.sh +++ b/relaunch.sh @@ -40,6 +40,6 @@ vmctl reload vmctl start ${1} sleep 30 echo "SUCCES! - deployed ${1}" -cp -v temlates/email-deployed.txt-redeploy templates/email-deployed.txt +cp -v /home/mischa/templates/email-deployed.txt-redeploy /home/mischa/templates/email-deployed.txt notify.pl deployed ${1} -cp -v temlates/email-deployed.txt-orig templates/email-deployed.txt +cp -v /home/mischa/templates/email-deployed.txt-orig /home/mischa/templates/email-deployed.txt