Add validation for the existence of "config.php" and "vendor/autoload.php" in the index.php file

This commit is contained in:
Alex Tselegidis 2022-03-29 09:55:45 +02:00
parent 942cb3d46f
commit 2e81c0ea53

331
index.php
View file

@ -26,41 +26,51 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
* *
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
* @filesource * @filesource
*/ */
/* /*
*--------------------------------------------------------------- *---------------------------------------------------------------
* EASY!APPOINTMENTS CONFIGURATION * EASY!APPOINTMENTS CONFIGURATION
*--------------------------------------------------------------- *---------------------------------------------------------------
* *
* Include Easy!Appointments configuration file so that it is available * Include Easy!Appointments configuration file so that it is available
* globally in the application. You can access configuration information * globally in the application. You can access configuration information
* through the static Config class. * through the static Config class.
* *
*/ */
require_once __DIR__ . '/config.php'; if ( ! file_exists(__DIR__ . '/config.php'))
{
die('The root "config.php" file is missing, please copy "config-sample.php" to "config.php" and update it with your server data.');
}
require_once __DIR__ . '/config.php';
/* /*
*--------------------------------------------------------------- *---------------------------------------------------------------
* COMPOSER AUTOLOAD FILE * COMPOSER AUTOLOAD FILE
*--------------------------------------------------------------- *---------------------------------------------------------------
* *
* Include Composer's autoload.php file so that I can use external * Include Composer's autoload.php file so that I can use external
* libraries directly in every section of the application. * libraries directly in every section of the application.
* *
*/ */
require_once __DIR__ . '/vendor/autoload.php'; if ( ! file_exists(__DIR__ . '/vendor/autoload.php'))
{
die('The "vendor/autoload.php" file is missing, please install the Composer dependencies with "composer install" before using the app.');
}
require_once __DIR__ . '/vendor/autoload.php';
/* /*
*--------------------------------------------------------------- *---------------------------------------------------------------
@ -79,7 +89,7 @@
* *
* NOTE: If you change these, also change the error_reporting() code below * NOTE: If you change these, also change the error_reporting() code below
*/ */
define('ENVIRONMENT', (Config::DEBUG_MODE) ? 'development' : 'production'); define('ENVIRONMENT', (Config::DEBUG_MODE) ? 'development' : 'production');
/* /*
*--------------------------------------------------------------- *---------------------------------------------------------------
@ -91,28 +101,28 @@
*/ */
switch (ENVIRONMENT) switch (ENVIRONMENT)
{ {
case 'development': case 'development':
error_reporting(-1); error_reporting(-1);
ini_set('display_errors', 1); ini_set('display_errors', 1);
break; break;
case 'testing': case 'testing':
case 'production': case 'production':
ini_set('display_errors', 0); ini_set('display_errors', 0);
if (version_compare(PHP_VERSION, '5.3', '>=')) if (version_compare(PHP_VERSION, '5.3', '>='))
{ {
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
} }
else else
{ {
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
} }
break; break;
default: default:
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'The application environment is not set correctly.'; echo 'The application environment is not set correctly.';
exit(1); // EXIT_ERROR exit(1); // EXIT_ERROR
} }
/* /*
@ -123,7 +133,7 @@ switch (ENVIRONMENT)
* This variable must contain the name of your "system" directory. * This variable must contain the name of your "system" directory.
* Set the path if it is not in the same directory as this file. * Set the path if it is not in the same directory as this file.
*/ */
$system_path = 'system'; $system_path = 'system';
/* /*
*--------------------------------------------------------------- *---------------------------------------------------------------
@ -140,7 +150,7 @@ switch (ENVIRONMENT)
* *
* NO TRAILING SLASH! * NO TRAILING SLASH!
*/ */
$application_folder = 'application'; $application_folder = 'application';
/* /*
*--------------------------------------------------------------- *---------------------------------------------------------------
@ -155,7 +165,7 @@ switch (ENVIRONMENT)
* *
* NO TRAILING SLASH! * NO TRAILING SLASH!
*/ */
$view_folder = ''; $view_folder = '';
/* /*
@ -177,15 +187,15 @@ switch (ENVIRONMENT)
* *
* Un-comment the $routing array below to use this feature * Un-comment the $routing array below to use this feature
*/ */
// The directory name, relative to the "controllers" directory. Leave blank // The directory name, relative to the "controllers" directory. Leave blank
// if your controller is not in a sub-directory within the "controllers" one // if your controller is not in a sub-directory within the "controllers" one
// $routing['directory'] = ''; // $routing['directory'] = '';
// The controller class file name. Example: mycontroller // The controller class file name. Example: mycontroller
// $routing['controller'] = ''; // $routing['controller'] = '';
// The controller function you wish to be called. // The controller function you wish to be called.
// $routing['function'] = ''; // $routing['function'] = '';
/* /*
@ -202,8 +212,7 @@ switch (ENVIRONMENT)
* *
* Un-comment the $assign_to_config array below to use this feature * Un-comment the $assign_to_config array below to use this feature
*/ */
// $assign_to_config['name_of_config_item'] = 'value of config item'; // $assign_to_config['name_of_config_item'] = 'value of config item';
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -216,120 +225,120 @@ switch (ENVIRONMENT)
* --------------------------------------------------------------- * ---------------------------------------------------------------
*/ */
// Set the current directory correctly for CLI requests // Set the current directory correctly for CLI requests
if (defined('STDIN')) if (defined('STDIN'))
{ {
chdir(dirname(__FILE__)); chdir(dirname(__FILE__));
} }
if (($_temp = realpath($system_path)) !== FALSE) if (($_temp = realpath($system_path)) !== FALSE)
{ {
$system_path = $_temp.DIRECTORY_SEPARATOR; $system_path = $_temp . DIRECTORY_SEPARATOR;
} }
else else
{ {
// Ensure there's a trailing slash // Ensure there's a trailing slash
$system_path = strtr( $system_path = strtr(
rtrim($system_path, '/\\'), rtrim($system_path, '/\\'),
'/\\', '/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
).DIRECTORY_SEPARATOR; ) . DIRECTORY_SEPARATOR;
} }
// Is the system path correct? // Is the system path correct?
if ( ! is_dir($system_path)) if ( ! is_dir($system_path))
{ {
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME); echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: ' . pathinfo(__FILE__, PATHINFO_BASENAME);
exit(3); // EXIT_CONFIG exit(3); // EXIT_CONFIG
} }
/* /*
* ------------------------------------------------------------------- * -------------------------------------------------------------------
* Now that we know the path, set the main path constants * Now that we know the path, set the main path constants
* ------------------------------------------------------------------- * -------------------------------------------------------------------
*/ */
// The name of THIS file // The name of THIS file
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
// Path to the system directory // Path to the system directory
define('BASEPATH', $system_path); define('BASEPATH', $system_path);
// Path to the front controller (this file) directory // Path to the front controller (this file) directory
define('FCPATH', dirname(__FILE__).DIRECTORY_SEPARATOR); define('FCPATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
// Name of the "system" directory // Name of the "system" directory
define('SYSDIR', basename(BASEPATH)); define('SYSDIR', basename(BASEPATH));
// The path to the "application" directory // The path to the "application" directory
if (is_dir($application_folder)) if (is_dir($application_folder))
{ {
if (($_temp = realpath($application_folder)) !== FALSE) if (($_temp = realpath($application_folder)) !== FALSE)
{ {
$application_folder = $_temp; $application_folder = $_temp;
} }
else else
{ {
$application_folder = strtr( $application_folder = strtr(
rtrim($application_folder, '/\\'), rtrim($application_folder, '/\\'),
'/\\', '/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
); );
} }
} }
elseif (is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR)) elseif (is_dir(BASEPATH . $application_folder . DIRECTORY_SEPARATOR))
{ {
$application_folder = BASEPATH.strtr( $application_folder = BASEPATH . strtr(
trim($application_folder, '/\\'), trim($application_folder, '/\\'),
'/\\', '/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
); );
} }
else else
{ {
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF; echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF;
exit(3); // EXIT_CONFIG exit(3); // EXIT_CONFIG
} }
define('APPPATH', $application_folder.DIRECTORY_SEPARATOR); define('APPPATH', $application_folder . DIRECTORY_SEPARATOR);
// The path to the "views" directory // The path to the "views" directory
if ( ! isset($view_folder[0]) && is_dir(APPPATH.'views'.DIRECTORY_SEPARATOR)) if ( ! isset($view_folder[0]) && is_dir(APPPATH . 'views' . DIRECTORY_SEPARATOR))
{ {
$view_folder = APPPATH.'views'; $view_folder = APPPATH . 'views';
} }
elseif (is_dir($view_folder)) elseif (is_dir($view_folder))
{ {
if (($_temp = realpath($view_folder)) !== FALSE) if (($_temp = realpath($view_folder)) !== FALSE)
{ {
$view_folder = $_temp; $view_folder = $_temp;
} }
else else
{ {
$view_folder = strtr( $view_folder = strtr(
rtrim($view_folder, '/\\'), rtrim($view_folder, '/\\'),
'/\\', '/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
); );
} }
} }
elseif (is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR)) elseif (is_dir(APPPATH . $view_folder . DIRECTORY_SEPARATOR))
{ {
$view_folder = APPPATH.strtr( $view_folder = APPPATH . strtr(
trim($view_folder, '/\\'), trim($view_folder, '/\\'),
'/\\', '/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
); );
} }
else else
{ {
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF; echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF;
exit(3); // EXIT_CONFIG exit(3); // EXIT_CONFIG
} }
define('VIEWPATH', $view_folder.DIRECTORY_SEPARATOR); define('VIEWPATH', $view_folder . DIRECTORY_SEPARATOR);
/* /*
* -------------------------------------------------------------------- * --------------------------------------------------------------------
@ -338,4 +347,4 @@ switch (ENVIRONMENT)
* *
* And away we go... * And away we go...
*/ */
require_once BASEPATH.'core/CodeIgniter.php'; require_once BASEPATH . 'core/CodeIgniter.php';