Commit Diff


commit - 6dc48ff8b8b51f7238721f7a88bcbfd1ee0176b2
commit + 64e24d553a9ff4c090166d48e196ede630f5f9b1
blob - 014417f3d846bfc36808228d82e4858a50443a82
blob + c5f4efd81c46217331c01ae3b8ccc4a962ce3ec3
--- notify.pl
+++ notify.pl
@@ -184,12 +184,14 @@ sub renewal {
 	for my $vm_name (sort keys %vms) {
 		my $_date = $vms{$vm_name}{'date'};
 		my $_payment = $vms{$vm_name}{'payment'};
+		my $_subscription = $vms{$vm_name}{'subscription'} || "no";
 		my $_donated = $vms{$vm_name}{'donated'};
 		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; }
 		if ($_donated =~ /expire/) { next; }
 		if ($_donated =~ /sponsor/) { next; }
@@ -220,6 +222,73 @@ sub renewal {
 			}
 			close $fh_email;
 			print "RENEWAL: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
+		}
+	}
+}
+
+sub subscription {
+	my %conf = %{$_[0]};
+	my %vms = %{$_[1]};
+	my $_etc = $conf{'conf'}{'ETC'};
+	my $_vms = $conf{'conf'}{'VMS'};
+	my $_tmpl = $conf{'conf'}{'TEMPLATES'};
+	my $_server = $conf{'conf'}{'SERVER'};
+	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 $response = HTTP::Tiny->new->get('https://openbsd.amsterdam/index.html');
+	my $total_donated = $1 if $response->{'content'} =~ /([0-9,]+) donated to the OpenBSD/;
+	my $total_vms = $1 if $response->{'content'} =~ /([0-9]+) VMs deployed/;
+	$response = HTTP::Tiny->new->get('https://openbsd.amsterdam/servers.html');
+	my $total_hosts = () = $response->{'content'} =~ /(\>Server )/g;
+
+	for my $vm_name (sort keys %vms) {
+		my $_date = $vms{$vm_name}{'date'};
+		my $_payment = $vms{$vm_name}{'payment'};
+		my $_subscription = $vms{$vm_name}{'subscription'} || "no";
+		my $_donated = $vms{$vm_name}{'donated'};
+		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; }
+		if ($_donated =~ /expire/) { next; }
+		if ($_donated =~ /sponsor/) { next; }
+		if ($_donated =~ /renewal/) { next; }
+		if ($_date =~ /$year\//) { next; }
+		if ($_date =~ /\/$month\//) {
+			(my $_firstname, my $_lastname) = split(/ /, $_name, 2);
+			(my $_year, my $_month, my $_day) = split(/\//, $_date, 3);
+			my $ipaddress = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n');
+
+			open(my $fh, '<', $template);
+			open my $fh_email, "|-", "/usr/sbin/sendmail -t";
+			printf $fh_email "To: %s\n", $_email;
+			while (my $row = <$fh>) {
+				chomp $row;
+				$row =~ s/NAME/$_firstname/g;
+				$row =~ s/IP$/$ipaddress/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;
+
+				print $fh_email "$row\n";
+			}
+			close $fh_email;
+			print "SUBSCRIPTION: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
 		}
 	}
 }
@@ -286,12 +355,14 @@ sub deprovision {
 	for my $vm_name (sort keys %vms) {
 		my $_date = $vms{$vm_name}{'date'};
 		my $_payment = $vms{$vm_name}{'payment'};
+		my $_subscription = $vms{$vm_name}{'subscription'} || "no";
 		my $_donated = $vms{$vm_name}{'donated'};
 		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; }
 		if ($_donated =~ /expire/) { next; }
 		if ($_donated =~ /sponsor/) { next; }
@@ -370,6 +441,7 @@ if ($debug) { debug_parse(\%conf, \%vms); }
 if ($function =~ /deployed/) { deployed(\%conf, \%vms); }
 elsif ($function =~ /stopped/) { stopped(\%conf, \%vms); }
 elsif ($function =~ /renewal/) { renewal(\%conf, \%vms); }
+elsif ($function =~ /subscription/) { subscription(\%conf, \%vms); }
 elsif ($function =~ /notify/) { notify(\%conf, \%vms); }
 elsif ($function =~ /deprovision/) { deprovision(\%conf, \%vms); }
 else { print "Specify function: deployed, stopped, renewal, notify, deprovision\n"; }
blob - /dev/null
blob + ba562d9a7e10b93f747122aa8b0bbb3be218ad10 (mode 644)
--- /dev/null
+++ templates/email-subscription.txt
@@ -0,0 +1,19 @@
+From: admin
+Subject: OpenBSD Amsterdam Renewal YEAR
+Content-Type: text/plain; charset=utf-8
+
+Hi NAME,
+
+Your renewal fee for VMID on SERVER this year is €PAYMENT.
+
+Total donated: TOTAL_DONATED
+Total VMs deployed: TOTAL_VMS
+Total hosts deployed: TOTAL_HOSTS
+
+Payment will be done automatically.
+
+Mischa
+
+--
+OpenBSD Amsterdam
+https://obsda.ms
blob - 58109a8099debdbd675e9db7a462e01ef67f1c5e
blob + bac86351d93fc39bf343a23c42af9fb59a9770b5
--- vms/vm01.txt
+++ vms/vm01.txt
@@ -1,7 +1,7 @@
 mac="fe:e1:ab:dd:73:a4"
 ip="192.168.1.1"
 owner="testuser1"
-date="2018/01/02"
+date="2018/02/02"
 payment="70"
 donated=""
 name="Test1 User"
blob - 36533d73155f4e1bdaf1ce45e76cef10dddd2a4f
blob + 4ffd5dfbed7299a9e2428d9e4776fa83d8d9750a
--- vms/vm02.txt
+++ vms/vm02.txt
@@ -1,5 +1,6 @@
-date="2018/07/02"
+date="2018/02/02"
 payment="70"
+subscription=""
 donated=""
 name="Test2 User"
 email="vm02@high5.nl"
blob - bd4c4cc1b1483a0619c5b1106d154ce58b03f399
blob + 12b6e44490c65408b69dd7620c477ce6911b1c0d
--- vms/vm03.txt
+++ vms/vm03.txt
@@ -1,5 +1,6 @@
-date="2020/07/21"
+date="2020/02/21"
 payment="60"
+subscription="yes"
 donated=""
 name="Test3"
 email="vm03@high5.nl"