* Copyright © 2015 Strangecode, LLC * * 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, either version 3 of the License, or * (at your option) any later version. * * 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, see . */ /* * Small config file for cli scripts in the codebase/bin directory. * * @author Quinn Comendant * @version 1.0 * @since 12 Jul 2015 22:48:13 */ // The name of the CLI. $cli_name = basename($_SERVER['argv'][0]); // Enforce "relaxed" directory location, if set by the called script. // This script can be executed in any directory that is an ancestor 2 directories above the db_auth file. if (!defined('COMMON_BASE')) { define('COMMON_BASE', realpath('.')); } // Use codebase files relative to this file. define('CODEBASE_PATH', realpath(dirname(__FILE__) . '/../')); $db_auth_file = false; if (!defined('_NODB')) { $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(COMMON_BASE)); $rii->setMaxDepth(2); foreach ($rii as $filename => $file) { if (in_array(basename($filename), ['db_auth.inc.php', 'db_auth.json'])) { $db_auth_file = $filename; break; } } if (!$db_auth_file) { printf("%s error: the current directory must be common site directory (i.e. the parent directory of the document root) AND a db_auth file must exist within two directory levels.\n", $cli_name); exit(1); } if (fileowner($db_auth_file) != getmyuid()) { printf("%s error: you must execute this script as the owner of the web files.\n", $cli_name); exit(1); } } // Set include path. ini_set('include_path', join(PATH_SEPARATOR, array_unique(array( '.', COMMON_BASE, dirname($db_auth_file) )))); /******************************************************************** * CONFIG ********************************************************************/ // Include core libraries: try local codebase path first, otherwise use global. if (file_exists('codebase/docs/version.txt') && version_compare(file_get_contents('codebase/docs/version.txt'), '2.1.0', '>')) { require_once 'codebase/lib/App.inc.php'; } else { require_once CODEBASE_PATH . '/lib/App.inc.php'; } define('_CLI', true); $app =& App::getInstance('codebase'); $app->setParam(array( 'site_name' => 'codebase', 'site_email' => 'codebase@strangecode.com', 'enable_session' => false, 'enable_db' => defined('_NODB') ? false : true, 'db_create_tables' => true, 'db_auth_file' => $db_auth_file, 'db_always_debug' => false, 'db_debug' => true, 'db_die_on_failure' => true, 'display_errors' => true, 'error_reporting' => E_ALL, 'log_file_priority' => LOG_DEBUG, 'log_screen_priority' => LOG_INFO, 'log_directory' => (is_dir('./log') ? './log' : '/tmp'), // If ./log exists, use it, otherwise /tmp. 'log_filename' => 'site_log', )); if (false !== $db_auth_file && strtolower(getFilenameExtension($db_auth_file)) != 'json') { // DB auth file is not JSON, and will not be automatically loaded by $app's 'db_auth_file' parser. require_once $db_auth_file; } // Start application-based functionality: database, session, environment, ini setup, etc. // Most configuration parameters must be set before starting the App. $app->start(); if (!defined('_NODB')) { // Global DB object. Automatically pre-configured by $app->start(). $db =& DB::getInstance(); }