#!/usr/bin/php -q
<?php
/*
    LibreSSL - CAcert web application
    Copyright (C) 2004-2009  CAcert Inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2 of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
include_once("../includes/mysql.php");

// read texts

$lines_EN = <<<EOF

You enrolled at CAcert some time ago. You have been a member of the CAcert community ever since. In their name, a non-profit association (CAcert Inc.) operates the necessary infrastructure and finances it from membership fees and donations.

Arbitration has allowed this email to be sent to all members of the CAcert community, including those who have not agreed to receive newsletters, as it contains essential information about the current state and the future of CAcert.org and CAcert Inc. (Ruling a20190420.1)

In the past few years there have been some changes. Let's Encrypt offers free SSL certificates, which are recognized by most browsers thanks to a cross signature. This raises the question of whether CAcert is still needed at all. We are convinced of it. The advantage of CAcert's certificates is the personal verification of those certificates by members of the Web of Trust. They can be used for identification, for signing documents or e-mails, for encryption, etc. In addition, we see good application possibilities in enterprises by means of Organisation Assurance (OrgA), which can also generate income and stabilise our finances.

Do you share our view that CAcert is still useful today?  If so, then read on!

We have outlined above some areas where we see the future of CAcert. If you have any other ideas, please write to us. Your ideas are important to CAcert's teams.

CAcert went through a major crisis in 2016. You may not have noticed it, because of the resilience of our procedures and the dedication and commitment of our teams. Apart from the new focus, a lot has happened in the operational area in recent months:
    - CAcert has a working support team again
    - the software team is active again, fixes bugs and works on improvements
    - some of our systems have been upgraded from six to ten year obsolete versions to July 2019 levels
    - a new SHA256 signed root certificate has replaced the old MD5 certificate
    - the assurer test (CATS) is now also available in French and Czech

Of course, all this always takes time to be done, time required of our small group of core volunteers. And time is money, because day and night our servers continue to run, needing electric power... The cost for this, three thousand Euros per year, is actually very little to supply over 360,000 people with free certificates. But to be completely honest, if we can't double the donations this year, we won't need any more reorientation, but we have to pull the plug at the end of the year.

Therefore a small request:

Since you have read this far, CAcert seems to be worth something to you. Therefore we ask you today for your personal support. This is a support which CAcert needs now. And well, let's play fair: "I'll do that next week" is a kind of negative answer.

    - Your support can be financial:

    -- A donation of 20, 50 or 100 euros (francs, dollars) (if possible on a regular basis) already helps CAcert.  We accept both Paypal & Bank account donations. See https://blog.cacert.org/  for more information.
    -- As well, you may look for, and invite a corporate sponsor to support CAcert's work.
    -- In addition, when you book your business trips and holidays please use our partner Booking.com https://www.booking.com/index.html?aid=346253
    -- Become a member of the CAcert Inc. association. Applications with postal address to: secretary@cacert.org

    - If you feel better at providing your skills than your money:

You are more than welcome too! Under the assumption that enough of the others will provide the money. :-)
Then get involved in one of the teams. There are technical and non-technical areas, where even small handouts are a great help for running our operations, if they are made regularly and with a long term commitment in mind.

    -- We are in need of a Treasurer who will maintain our small account, and doesn't even need to regularly attend meetings. A multi-year involvement helps better. You feel like being a candidate? Please contact the secretary@cacert.org
    -- Have you been a system administrator in your professional life, and may like to share a few hours of your time with us? Please contact the secretary@cacert.org
    -- You may help by assisting with copywriting the main pages of our Wiki and making them easier to read. https://wiki.cacert.org (contact: wiki-admin@cacert.org)
    -- You may join our web site translators team. contact: https://lists.cacert.org/wws/arc/cacert-translations
    -- Have convoluted legal issues ever been your daily bread and butter? You may help in arbitration! Please contact the secretary@cacert.org. 
    -- Joining the development team would be too much to ask, but you could adopt a bug and propose your patch. https://bugs.cacert.org/my_view_page.php ; please join the developers' mailing list: https://lists.cacert.org/wws/info/cacert-devel
    -- You may become an Organisation Assurer and offer CAcert's services to organisations, companies or institutions; just have a look at: https://wiki.cacert.org/OrganisationAssurance

We would like to thank you very much for your participation, help and cooperation. At the moment, there are strong uncertainties about CAcert that cannot stay neglected because of the state of finances. But if each of the thousands of CAcert members lifts only a little finger, we will be able to achieve great things!

Best regards

    Brian McCullough            Etienne Ruedin
    President CAcert Inc.      Secretary CAcert Inc.


PS. Please don't think too long, do something today - next month it might be too late.

PPS. If you are one of that people who reads only the last paragraph: We urgently need your help as a system administrator, arbitrator, donor, board member or on one of the many small tasks to not closing down CAcert at the end of the year. Please write to the secretary@cacert.org

----
CAcert Inc.
10 Airfield Avenue
Murwillumbah NSW 2484
New South Wales
Commonwealth of Australia
EOF;

$lines_EN = wordwrap($lines_EN, 75, "\n");
$lines_EN = mb_convert_encoding($lines_EN, "HTML-ENTITIES", "UTF-8");


// read last used id
$lastid = 0;
if (file_exists("send_info_mailing_20190906_lastid.txt"))
{
	$fp = fopen("send_info_mailing_20190906_lastid.txt", "r");
	$lastid = trim(fgets($fp, 4096));
	fclose($fp);
}

echo "ID now: $lastid\n";


$count = 0;

$query = "

	SELECT `id`, `fname`, `lname`, `email`
	FROM `users`
	WHERE `deleted` = '0000-00-00 00:00:00'
	AND `verified` = '1'
        AND `locked` = '0'
        AND `id` > '$lastid'
	ORDER BY `id`";

$res = mysql_query($query);

while($row = mysql_fetch_assoc($res))
{
//	$mailtxt = "Dear ${row["fname"]} ${row["lname"]},\n".$lines_EN."\n\n";
	$mailtxt = "Dear Member of the CAcert-Community\n".$lines_EN."\n\n";

	sendmail($row['email'], "[CAcert.org] Is there still a future for CAcert? (essential information)", $mailtxt, "support@cacert.org", "", "", "CAcert", "returns@cacert.org", "");

	$fp = fopen("send_info_mailing_20190906_lastid.txt", "w");
	fputs($fp, $row["id"]."\n");
	fclose($fp);

	$count++;
	echo "Sent ${count}th mail. User ID: ${row["id"]}\n";

	if(0 == $count % 8) {
		sleep (1);
	}
	if ($count >= 2000) {
		// avoid memory exhaustion -- this script has a memory leak
		echo "Continue\n";
		exit(0);
	}
}
echo "Stop\n";
