mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-04 02:09:23 +02:00
Clean up PHP tests and reuse them in init.php
Also move the config-related functions out of debug.lib.php (why they were there in the first place is anyone's guess.)
This commit is contained in:
parent
c8cd1da88f
commit
dd70337451
4 changed files with 89 additions and 122 deletions
|
@ -20,43 +20,49 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* check_php_ver
|
||||
* checks the php version and makes
|
||||
* sure that it's good enough
|
||||
*/
|
||||
function check_php_ver($level=0) {
|
||||
function check_php() {
|
||||
if (
|
||||
check_php_version() &&
|
||||
check_php_hash() &&
|
||||
check_php_hash_algo() &&
|
||||
check_php_pdo() &&
|
||||
check_php_session() &&
|
||||
check_php_json() &&
|
||||
check_php_safemode()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function check_php_version() {
|
||||
if (floatval(phpversion()) < 5.3) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* check_php_session
|
||||
* checks to make sure the needed functions
|
||||
* for sessions exist
|
||||
*/
|
||||
function check_php_hash() {
|
||||
return function_exists('hash_algos');
|
||||
}
|
||||
|
||||
function check_php_hash_algo() {
|
||||
return function_exists('hash_algos') ? in_array('sha256', hash_algos()) : false;
|
||||
}
|
||||
|
||||
function check_php_json() {
|
||||
return function_exists('json_encode');
|
||||
}
|
||||
|
||||
function check_php_session() {
|
||||
return function_exists('session_set_save_handler');
|
||||
}
|
||||
|
||||
if (!function_exists('session_set_save_handler')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} // check_php_session
|
||||
|
||||
/**
|
||||
* check_pdo
|
||||
*
|
||||
* Checks to make sure that PDO is available.
|
||||
*/
|
||||
function check_pdo() {
|
||||
function check_php_pdo() {
|
||||
if (class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -135,7 +141,7 @@ function check_php_timelimit() {
|
|||
* check_safe_mode
|
||||
* Checks to make sure we aren't in safe mode
|
||||
*/
|
||||
function check_safemode() {
|
||||
function check_php_safemode() {
|
||||
if (ini_get('safe_mode')) {
|
||||
return false;
|
||||
}
|
||||
|
@ -182,34 +188,6 @@ function check_override_exec_time() {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* check_gettext
|
||||
* This checks to see if you've got gettext installed
|
||||
*/
|
||||
function check_gettext() {
|
||||
|
||||
if (!function_exists('gettext')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} // check_gettext
|
||||
|
||||
/**
|
||||
* check_mbstring
|
||||
* This checks for mbstring support
|
||||
*/
|
||||
function check_mbstring() {
|
||||
|
||||
if (!function_exists('mb_check_encoding')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} // check_mbstring
|
||||
|
||||
/**
|
||||
* check_config_writable
|
||||
* This checks whether we can write the config file
|
||||
|
@ -221,63 +199,6 @@ function check_config_writable() {
|
|||
|| (!file_exists(Config::get('prefix') . '/config/ampache.cfg.php') && is_writeable(Config::get('prefix') . '/config/')));
|
||||
}
|
||||
|
||||
/**
|
||||
* generate_config
|
||||
* This takes an array of results and re-generates the config file
|
||||
* this is used by the installer and by the admin/system page
|
||||
*/
|
||||
function generate_config($current) {
|
||||
|
||||
/* Start building the new config file */
|
||||
$distfile = Config::get('prefix') . '/config/ampache.cfg.php.dist';
|
||||
$handle = fopen($distfile,'r');
|
||||
$dist = fread($handle,filesize($distfile));
|
||||
fclose($handle);
|
||||
|
||||
$data = explode("\n",$dist);
|
||||
|
||||
/* Run throught the lines and set our settings */
|
||||
foreach ($data as $line) {
|
||||
|
||||
/* Attempt to pull out Key */
|
||||
if (preg_match("/^;?([\w\d]+)\s+=\s+[\"]{1}(.*?)[\"]{1}$/",$line,$matches)
|
||||
|| preg_match("/^;?([\w\d]+)\s+=\s+[\']{1}(.*?)[\']{1}$/", $line, $matches)
|
||||
|| preg_match("/^;?([\w\d]+)\s+=\s+[\'\"]{0}(.*)[\'\"]{0}$/",$line,$matches)) {
|
||||
|
||||
$key = $matches[1];
|
||||
$value = $matches[2];
|
||||
|
||||
/* Put in the current value */
|
||||
if ($key == 'config_version') {
|
||||
$line = $key . ' = ' . escape_ini($value);
|
||||
}
|
||||
elseif (isset($current[$key])) {
|
||||
$line = $key . ' = "' . escape_ini($current[$key]) . '"';
|
||||
unset($current[$key]);
|
||||
} // if set
|
||||
|
||||
} // if key
|
||||
|
||||
$final .= $line . "\n";
|
||||
|
||||
} // end foreach line
|
||||
|
||||
return $final;
|
||||
|
||||
} // generate_config
|
||||
|
||||
/**
|
||||
* escape_ini
|
||||
* Escape a value used for inserting into an ini file.
|
||||
* Won't quote ', like addslashes does.
|
||||
*/
|
||||
function escape_ini($str) {
|
||||
|
||||
return str_replace('"', '\"', $str);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* debug_result
|
||||
*
|
||||
|
|
|
@ -261,4 +261,53 @@ function translate_pattern_code($code) {
|
|||
|
||||
} // translate_pattern_code
|
||||
|
||||
/**
|
||||
* generate_config
|
||||
*
|
||||
* This takes an array of results and re-generates the config file
|
||||
* this is used by the installer and by the admin/system page
|
||||
*/
|
||||
function generate_config($current) {
|
||||
// Start building the new config file
|
||||
$distfile = Config::get('prefix') . '/config/ampache.cfg.php.dist';
|
||||
$handle = fopen($distfile,'r');
|
||||
$dist = fread($handle,filesize($distfile));
|
||||
fclose($handle);
|
||||
|
||||
$data = explode("\n",$dist);
|
||||
|
||||
foreach ($data as $line) {
|
||||
if (preg_match("/^;?([\w\d]+)\s+=\s+[\"]{1}(.*?)[\"]{1}$/",$line,$matches)
|
||||
|| preg_match("/^;?([\w\d]+)\s+=\s+[\']{1}(.*?)[\']{1}$/", $line, $matches)
|
||||
|| preg_match("/^;?([\w\d]+)\s+=\s+[\'\"]{0}(.*)[\'\"]{0}$/",$line,$matches)) {
|
||||
|
||||
$key = $matches[1];
|
||||
$value = $matches[2];
|
||||
|
||||
// Put in the current value
|
||||
if ($key == 'config_version') {
|
||||
$line = $key . ' = ' . escape_ini($value);
|
||||
}
|
||||
elseif (isset($current[$key])) {
|
||||
$line = $key . ' = "' . escape_ini($current[$key]) . '"';
|
||||
unset($current[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$final .= $line . "\n";
|
||||
}
|
||||
|
||||
return $final;
|
||||
}
|
||||
|
||||
/**
|
||||
* escape_ini
|
||||
*
|
||||
* Escape a value used for inserting into an ini file.
|
||||
* Won't quote ', like addslashes does.
|
||||
*/
|
||||
function escape_ini($str) {
|
||||
return str_replace('"', '\"', $str);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -53,10 +53,7 @@ else {
|
|||
|
||||
// Verify that a few important but commonly disabled PHP functions exist and
|
||||
// that we're on a usable version
|
||||
if (!function_exists('json_encode') ||
|
||||
!function_exists('hash') ||
|
||||
(floatval(phpversion()) < 5.3) ||
|
||||
!class_exists('PDO')) {
|
||||
if (!check_php()) {
|
||||
$link = $path . '/test.php';
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<tr>
|
||||
<td valign="top"><?php echo T_('PHP version'); ?></td>
|
||||
<td valign="top">
|
||||
<?php echo debug_result(check_php_ver()); ?>
|
||||
<?php echo debug_result(check_php_version()); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo T_('This tests whether you are running at least the minimum version of PHP required by Ampache.'); ?>
|
||||
|
@ -32,7 +32,7 @@
|
|||
<tr>
|
||||
<td valign="top"><?php echo T_('Hash extension'); ?></td>
|
||||
<td valign="top">
|
||||
<?php echo debug_result(function_exists('hash_algos')); ?>
|
||||
<?php echo debug_result(check_php_hash()); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo T_('This tests whether you have the hash extension enabled. This extension is required by Ampache.'); ?>
|
||||
|
@ -41,7 +41,7 @@
|
|||
<tr>
|
||||
<td valign="top"><?php echo T_('SHA256 Hash'); ?></td>
|
||||
<td valign="top">
|
||||
<?php echo debug_result(function_exists('hash_algos') ? in_array('sha256', hash_algos()) : false); ?>
|
||||
<?php echo debug_result(check_php_hash_algo()); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo T_('This tests whether the hash extension supports SHA256. This algorithm is required by Ampache.'); ?>
|
||||
|
@ -50,7 +50,7 @@
|
|||
<tr>
|
||||
<td valign="top"><?php echo T_('PHP PDO'); ?></td>
|
||||
<td valign="top">
|
||||
<?php echo debug_result(check_pdo()); ?>
|
||||
<?php echo debug_result(check_php_pdo()); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo T_('This tests whether the PDO extension and the MySQL driver for PDO are installed. These are required by Ampache.'); ?>
|
||||
|
@ -77,7 +77,7 @@
|
|||
<tr>
|
||||
<td valign="top"><?php echo T_('JSON extension'); ?></td>
|
||||
<td valign="top">
|
||||
<?php echo debug_result(function_exists('json_encode')); ?>
|
||||
<?php echo debug_result(check_php_json()); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo T_('This tests whether you have the JSON extension enabled. This extension is required by Ampache.'); ?>
|
||||
|
@ -86,7 +86,7 @@
|
|||
<tr>
|
||||
<td valign="top"><?php echo T_('PHP safe mode disabled'); ?></td>
|
||||
<td valign="top">
|
||||
<?php echo debug_result(check_safemode()); ?>
|
||||
<?php echo debug_result(check_php_safemode()); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo T_('This test makes sure that PHP is not running in safe mode. Some features of Ampache will not work correctly in safe mode.'); ?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue