assign( 'next_step', $step + 1 );
$check_settings = check_settings();
$gBitSmarty->assign( "error", $error );
$gBitSmarty->assign( "warning", $warning );
foreach( $check_settings as $type => $checks ) {
$gBitSmarty->assign( $type, $checks );
}
if( !isset( $_SERVER['HTTP_REFERER'] ) ) {
$gBitSmarty->assign( "http_referer_error", true );
$error = true;
}
/**
* check_settings
*/
function check_settings() {
global $gBitSmarty, $error, $warning;
$config_file = KernelTools::clean_file_path( empty( $_SERVER['CONFIG_INC'] ) ? BIT_ROOT_PATH.'config/kernel/config_inc.php' : $_SERVER['CONFIG_INC'] );
$i = 0;
// required settings - if not met, are passed into the array $reqd
// PHP system checks
$phpvers = '8.3.0';
if( phpversion() < $phpvers ) {
$required[$i]['note'] = 'PHP version should be greater than '.$phpvers.'.
Your installed version of PHP is '.phpversion().'.';
$required[$i]['passed'] = false;
} else {
$required[$i]['note'] = 'PHP version is greater than '.$phpvers.'.
Your installed version of PHP is '.phpversion().'.';
$required[$i]['passed'] = true;
}
// check file and directory permissisions
$i++;
if( @file_exists( $config_file ) && @KernelTools::bw_is_writeable( $config_file ) ) {
$required[$i]['note'] = 'The Bitweaver configuration file is available and the file is writeable:
'.$config_file.'';
$required[$i]['passed'] = true;
} elseif( @file_exists( $config_file ) && !@KernelTools::bw_is_writeable( $config_file ) ) {
$required[$i]['note'] = 'The Bitweaver configuration file is available but the file is not writeable. Please execute something like:
chmod 777 '.$config_file.'';
$required[$i]['passed'] = false;
} else {
$required[$i]['note'] = 'The Bitweaver configuration file is not available. Please execute something like:
touch '.$config_file.';
chmod 777 '.$config_file.'';
$required[$i]['passed'] = false;
}
$i++;
$dir_check = [
'storage' => defined( 'STORAGE_PKG_PATH' ) ? STORAGE_PKG_PATH : BIT_ROOT_PATH . 'storage',
'temp' => defined( 'TEMP_PKG_PATH' ) ? TEMP_PKG_PATH : sys_get_temp_dir() . '/bitweaver/' . $_SERVER['SERVER_NAME'],
];
foreach( $dir_check as $name => $d ) {
// final attempt to create the required directories
// @mkdir( $d,0644 );
if( @is_dir( $d ) && KernelTools::bw_is_writeable( $d ) ) {
$required[$i]['note'] = "The $name directory is available and it is writeable.
$d";
$required[$i]['passed'] = true;
} elseif( @is_dir( $d ) && !KernelTools::bw_is_writeable( $d ) ) {
$required[$i]['note'] = "The $name directory is available but it is not writeable.
Please execute something like:
chmod -R 777 $d";
$required[$i]['passed'] = false;
} else {
$required[$i]['note'] = "The $name directory is not available and we cannot create it automaticalliy.
Please execute something like:
mkdir -m 777 $d";
$required[$i]['passed'] = false;
}
$i++;
}
foreach( $required as $r ) {
if( !$r['passed'] ) {
$error = true;
}
}
// check extensions
$php_ext = [
'zlib' => 'The zlib compression libraries are used to pack and unpack compressed files such as .zip files.',
'gd' => 'GD Libraries are used to manipulate images. Bitweaver uses these libraries to create thumbnails and convert images from one format to another. If you are running Red Hat or Fedora Core, you can try: yum install php-gd. The GD libaries are quite limited and don\'t support a number of image formats including .bmp. If you are planning on uploading and using a lot of images, we recommend you use one of the other image processors.',
'imagick' => 'ImageMagick supports a multitude of different image and video formats and can be used instead of the GD Libraries. Using these libraries will allow you to upload most image formats without any difficulties. For installation help, please view ImageMagick and MagickWand installation instructions or visit the ImageMagick homepage.',
// 'ffmpeg' => 'ffmpeg-php is an extension that will allow you to better process uploaded videos. This extension requires ffmpeg to be installed on your server as well.',
];
foreach( $php_ext as $ext => $note ) {
$extensions[$ext]['note'] = "The extension $ext is ";
if( extension_loaded( $ext ) ) {
$extensions[$ext]['passed'] = true;
} else {
$extensions[$ext]['note'] .= 'not ';
$extensions[$ext]['passed'] = false;
}
$extensions[$ext]['note'] .= "available.
$note";
}
/* // disable one of the imagick / magickwand warnings
if( $extensions['magickwand']['passed'] == true && $extensions['imagick']['passed'] == false ) {
unset( $extensions['imagick'] );
} elseif( $extensions['imagick']['passed'] == true && $extensions['magickwand']['passed'] == false ) {
unset( $extensions['magickwand'] );
}
*/
// make sure we show the worning flag if there is a need for it
foreach( $extensions as $info ) {
if( !$info['passed'] ) {
$warning = true;
}
}
// output has to be verbose that we can catch the output of the shell_exec
// using --help, -h or --version should make applications output something to stdout - this is no guarantee though, bunzip2 doesn't...
$execs = [
'tar' => [
'command' => 'tar -xvf',
'dest_params' => '-C',
'testfile' => 'test.tar',
'note' => 'Tarball is a common archiving format on Linux and tar is used to extract .tar files. For windows use bsdtar from gnuwin32 ( See Windows notes for installation help ).',
],
'bzip2' => [
'command' => 'tar -jvxf',
'dest_params' => '-C',
'testfile' => 'test.tar.bz2',
'note' => 'Bzip is a common compression format on Linux and bzip2 is used to extract .bz2 and in combination with tar .tar.bz2 file. ( For windows see bsdtar above. )',
],
'gzip' => [
'command' => 'tar -zvxf',
'dest_params' => '-C',
'testfile' => 'test.tar.gz',
'note' => 'Gzip is a common compression format on Linux and gzip is used to extract .gz and in combination with tar .tar.gz file. ( For windows see bsdtar above. )',
],
'unzip' => [
'command' => 'unzip -v',
'dest_params' => '-d',
'testfile' => 'test.zip',
'note' => 'Zip is a common compression format on all operating systems and unzip is used to extract .zip files.',
],
'unrar' => [
'command' => 'unrar x',
'dest_params' => '',
'testfile' => 'test.rar',
'note' => 'Rar is a common compression format on all operating systems and unrar is used to extract .rar files.',
],
'gs' => [
'command' => 'gs --version',
'note' => 'GhostScript is an interpreter for the PostScript language and for PDF and is used to create PDF previews when uploading PDF files to Fisheye. If you do not have this installed, previews of PDF files will not be generated on upload. If you have difficulties with GhostScript, please try installing a different version. Bitweaver was successfully tested with versions 7.5, 8.15.4, 8.5, 8.54. There where difficulties with version 8.1.',
'result' => 'Your version of GhostScript: ',
],
'graphviz' => [
'command' => 'dot -V',
'note' => 'Graphviz is a way of representing structural information as diagrams of abstract graphs and networks and visualizing that representation. It is used by the {graphviz} Liberty plugin and you only need to install it if you intend to enable that plugin.
The Pear::Image_Graphviz plugin is required as well.',
'result' => 'Your version of Graphviz: ',
],
'ffmpeg' => [
'command' => 'ffmpeg',
'note' => 'ffmpeg is a hyper fast video and audio encoder that supports many common formats. If you are planning on uploading video and audio files, it\'s recommend that you install this application.',
],
// 'unstuff' => array(
// 'params' => '-xf',
// 'testfile' => 'test.tar',
// 'note' => 'Unstuff is a common compression format on Mac and unstuff is used to extract .sit files.',
// ),
];
foreach( $execs as $exe => $app ) {
$executables[$exe]['note'] = 'The application '.$exe.' is ';
$command = ( !empty( $app['testfile'] ) && is_readable( $file = INSTALL_PKG_PATH . 'testfiles/' . $app['testfile'] ) ) ? $app['command'] . ' "' . $file . '" ' . $app['dest_params'] . ' "' . TEMP_PKG_PATH . '"' : $app['command'];
if( get_php_setting( 'safe_mode' ) == 'OFF' && $shellResults[$exe] = shell_exec( $command .' 2> '.TEMP_PKG_PATH.'output' ) ) {
// @unlink( TEMP_PKG_PATH.'test.txt' );
$executables[$exe]['passed'] = true;
} elseif ( $shellResults[$exe] = join("", file(TEMP_PKG_PATH.'output')) ) {
if ( strpos( $shellResults[$exe], 'command' ) and strpos( $shellResults[$exe], 'not' ) ) {
$executables[$exe]['note'] .= 'not ';
$executables[$exe]['passed'] = false;
$shellResults[$exe] = "";
} else {
// @unlink( TEMP_PKG_PATH.'test.txt' );
$executables[$exe]['passed'] = true;
}
} else {
$executables[$exe]['note'] .= 'not ';
$executables[$exe]['passed'] = false;
}
$executables[$exe]['note'] .= 'available.
'.$app['note'];
if( !empty( $app['result'] ) && !empty( $shellResults[$exe] )) {
$executables[$exe]['note'] .= '
'.$app['result'].''.$shellResults[$exe].'';
}
}
// PEAR checks
$pears = [
'PEAR' => [
'path' => 'PEAR.php',
'note' => 'This check indicates if PEAR is installed and available. To make use of PEAR extensions, you need to make sure that PEAR is installed and the include_path is set in your php.ini file.',
],
'Auth' => [
'path' => 'Auth/Auth.php',
'note' => 'This will allow you to use the PEAR::Auth package to authenticate users on your website.',
'install_command' => 'pear install --onlyreqdeps Auth;',
],
'Text_Wiki' => [
'path' => 'Text/Wiki.php',
'note' => 'Having PEAR::Text_Wiki installed will make more wiki format parsers available. The following parsers will be recognised and used: Text_Wiki_BBCode, Text_Wiki_Cowiki, Text_Wiki_Creole, Text_Wiki_Doku, Text_Wiki_Mediawiki, Text_Wiki_Tiki',
'install_command' => 'pear install --onlyreqdeps Text_Wiki_BBCode Text_Wiki_Cowiki Text_Wiki_Creole Text_Wiki_Doku Text_Wiki_Mediawiki Text_Wiki_Tiki;',
],
'Text_Diff' => [
'path' => 'Text/Diff.php',
'note' => 'PEAR::Text_Diff makes inline diffing of content available.',
'install_command' => 'pear install --onlyreqdeps Text_Diff;',
],
'Image_Graphviz' => [
'path' => 'Image/GraphViz.php',
'note' => 'Pear::Image_Graphviz makes the {graphviz} plugin available. With it you can draw maps of how your Wiki pages are linked to each other. This can be used for informational purposes or a site-map. It requires the application graphviz to be installed on your server as well.',
'install_command' => 'pear install --onlyreqdeps Image_Graphviz;',
],
// 'HTMLPurifier' => [
// 'path' => 'HTMLPurifier.php',
// 'note' => 'HTMLPurifier is an advanced system for defending against Cross Site Scripting (XSS) attacks and ensuring that all code on your site is standards compliant. It is highly recommended if you are going to allow HTML submission to your site. It is not required if you are only going to allow the input of a Wiki format like Tikiwiki or BBcode. You also need to enable it in the Liberty plugins administration after installation. See https://www.bitweaver.org/wiki/HTMLPurifier and http://htmlpurifier.org for more information.',
// 'install_command' => 'pear channel-discover htmlpurifier.org;
pear install hp/HTMLPurifier;',
// ],
'HTTP_Download' => [
'path' => 'HTTP/Download.php',
'note' => 'Treasury - the file manager of Bitweaver - can make use of PEAR::HTTP_Download to provide more reliable downloads and download resume support when using a download manager.',
'install_command' => 'pear install --alldeps HTTP_Download;',
],
];
foreach( $pears as $pear => $info ) {
$pearexts[$pear]['note'] = ( $pear == 'PEAR' ) ? "$pear is " : "The extension PEAR::$pear is ";
if ( @include_once( $info['path'] )) {
$pearexts[$pear]['passed'] = true;
} else {
$pearexts[$pear]['note'] .= 'not ';
$pearexts[$pear]['passed'] = false;
}
$pearexts[$pear]['original_note'] = $info['note'];
$pearexts[$pear]['note'] .= 'available.
';
$pearexts[$pear]['note'] .= $info['note'];
if( !empty( $info['install_command'] ) && $pearexts[$pear]['passed'] == false ) {
$pearexts[$pear]['note'] .= '
Install using this command:
'.$info['install_command'].'';
}
}
$i = 0;
// recommended php toggles - these don't need explicit explanations on how to rectify them
// start with special cases
$recommended[$i] = [ 'Memory Limit', 'memory_limit', 'shouldbe' => 'at least 16M', 'actual' => get_cfg_var( 'memory_limit' ) ];
if( preg_replace( '/M/i','',get_cfg_var( 'memory_limit' ) ) > 15 ) {
$recommended[$i]['passed'] = true;
} else {
$recommended[$i]['passed'] = false;
$gBitSmarty->assign( 'memory_warning', true );
}
$i++;
// now continue with easy toggle checks
$php_rec_toggles = [
[ 'Display Errors', 'display_errors', 'shouldbe' => 'OFF' ],
[ 'File Uploads', 'file_uploads', 'shouldbe' => 'ON' ],
[ 'Output Buffering', 'output_buffering', 'shouldbe' => 'OFF' ],
[ 'Session auto start', 'session.auto_start', 'shouldbe' => 'OFF' ],
[ 'Log Errors', 'log_errors', 'shouldbe' => 'ON' ],
[ 'Session Cookie HttpOnly', 'session.cookie_httponly', 'shouldbe' => 'ON' ],
[ 'Session Cookie Secure', 'session.cookie_secure', 'shouldbe' => 'ON' ],
];
foreach( $php_rec_toggles as $php_rec_toggle ) {
$php_rec_toggle['actual'] = get_php_setting( $php_rec_toggle[1] );
$php_rec_toggle['passed'] = ( get_php_setting( $php_rec_toggle[1] ) == $php_rec_toggle['shouldbe'] ) ? true : false;
$recommended[] = $php_rec_toggle;
$i++;
}
// settings that are useful to know about
$php_ini_gets = [
[ 'Maximum post size restricts the size of files uploaded using a form.
Recommended: at least 8M.', 'post_max_size' ],
[ 'Upload max filesize is related to maximim post size and will also limit the size of uploads.
Recommended: at least 8M.', 'upload_max_filesize' ],
[ 'Maximum execution time is related to time outs in PHP. It affects database upgrades and backups.
Recommended: 60.', 'max_execution_time' ],
];
foreach( $php_ini_gets as $php_ini_get ) {
$value = ini_get( $php_ini_get[1] );
switch ($value) {
case 1:
$value = "On";
break;
case 0:
$value = "Off";
break;
}
$show[$php_ini_get[1]] = $php_ini_get[0]."
{$php_ini_get[1]} is set to $value";
}
$res['required'] = $required;
$res['extensions'] = $extensions;
$res['executables'] = $executables;
$res['pearexts'] = $pearexts;
$res['recommended'] = $recommended;
$res['show'] = $show;
return $res;
}
/**
* get_php_setting
*/
function get_php_setting( $val ) {
$r = ( ini_get( $val ) == '1' ? 1 : 0 );
return $r ? 'ON' : 'OFF';
}