Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding (more) graceful failure when phplist does not have access to r… #403

Merged
merged 1 commit into from Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions public_html/lists/admin/checkprerequisites.php
@@ -0,0 +1,30 @@
<?php
/*******************************************************************************
* File: checkprerequisites.php
* Version: 1.0
* Purpose: Check that some basic prerequisites to running phplist are met. If
* not, fail gracefully
* Created: 2018-09-15
* Updated: 2018-09-15
******************************************************************************/

// make sure we're running a recent version of php
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50303) {
die('Your PHP version is too old. Please upgrade PHP before continuing.');
}

// make sure we have access to a cryptographically secure pseudorandom number
// generator (CSPNRG)
try {
require_once dirname(__FILE__).'/inc/random_compat/random.php';
random_bytes(1);
} catch (Exception $e) {
error_log( "Caught Exception: " . $e->getMessage() );
die (
"phpList requires a random_bytes function. For more information, please "
."see \r\n\r\n<br/><br/>"
.'* https://tech.michaelaltfield.net/2018/08/25/fix-phplist-500-error-due-to-random_compat/'
);
}

?>
5 changes: 2 additions & 3 deletions public_html/lists/admin/index.php
@@ -1,8 +1,7 @@
<?php

if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50303) {
die('Your PHP version is too old. Please upgrade PHP before continuing.');
}
// check for basic prerequisites
require_once dirname(__FILE__).'/checkprerequisites.php';

if (ob_get_level() == 0) {
@ob_start();
Expand Down