function __construct($configFile, $enableErrorHandler = true)
 {
     if (!jServer::isCLI()) {
         throw new Exception("Error: you're not allowed to execute this script outside a command line shell.");
     }
     jApp::setEnv('cli');
     parent::__construct($configFile, $enableErrorHandler);
 }
Ejemplo n.º 2
0
 public static function readAndCache($configFile, $isCli = null, $pseudoScriptName = '')
 {
     if ($isCli === null) {
         $isCli = jServer::isCLI();
     }
     $config = self::read($configFile, false, $isCli, $pseudoScriptName);
     $tempPath = jApp::tempPath();
     jFile::createDir($tempPath);
     if (BYTECODE_CACHE_EXISTS) {
         $filename = $tempPath . str_replace('/', '~', $configFile) . '.conf.php';
         if ($f = @fopen($filename, 'wb')) {
             fwrite($f, '<?php $config = ' . var_export(get_object_vars($config), true) . ";\n?>");
             fclose($f);
         } else {
             throw new Exception('Error while writing configuration cache file -- ' . $filename);
         }
     } else {
         jIniFile::write(get_object_vars($config), $tempPath . str_replace('/', '~', $configFile) . '.resultini.php', ";<?php die('');?>\n");
     }
     return $config;
 }
Ejemplo n.º 3
0
/**
* @package     jelix-scripts
* @author      Laurent Jouanneau
* @contributor Loic Mathaud
* @copyright   2005-2011 Laurent Jouanneau
* @link        http://jelix.org
* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
*/
error_reporting(E_ALL);
define('JELIX_SCRIPTS_PATH', __DIR__ . '/../');
if (!class_exists('jCoordinator', false)) {
    // for old application.init.php which doesn't include init.php
    echo "Error: your application.init.php should include the vendor/autoload.php";
    exit(1);
}
if (!jServer::isCLI()) {
    echo "Error: you're not allowed to execute this script outside a command line shell.\n";
    exit(1);
}
// ------------- retrieve the name of the jelix command
if ($_SERVER['argc'] < 2) {
    echo "Error: command is missing. See '" . $_SERVER['argv'][0] . " help'.\n";
    exit(1);
}
$argv = $_SERVER['argv'];
$scriptName = array_shift($argv);
// shift the script name
$commandName = array_shift($argv);
// get the command name
// ------------ load the config and retrieve the command object
require JELIX_SCRIPTS_PATH . 'includes/JelixScript.class.php';
Ejemplo n.º 4
0
/**
 * check if the application is not installed. If the app is installed, an
 * error message appears and the scripts ends.
 * It should be called only by some scripts
 * like an installation wizard, not by an entry point.
 * @todo migrate the code to jAppManager or jApp
 */
function checkAppNotInstalled()
{
    if (isAppInstalled()) {
        if (jServer::isCLI()) {
            echo "Application is installed. The script cannot be runned.\n";
        } else {
            header("HTTP/1.1 500 Application not available");
            header('Content-type: text/plain');
            echo "Application is installed. The script cannot be runned.\n";
        }
        exit(1);
    }
}
 static function handleError($type, $code, $message, $file, $line, $trace)
 {
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     // for non fatal error appeared during init, let's just store it for loggers later
     if ($type != 'error') {
         self::$initErrorMessages[] = $errorLog;
         return;
     } else {
         if (jServer::isCLI()) {
             // fatal error appeared during init, in a CLI context
             while (ob_get_level() && @ob_end_clean()) {
             }
             // log into file and output message in the console
             echo 'Error during initialization: \\n';
             foreach (self::$initErrorMessages as $err) {
                 @error_log($err->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
                 echo '* ' . $err->getMessage() . ' (' . $err->getFile() . ' ' . $err->getLine() . ")\n";
             }
             @error_log($errorLog->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             echo '* ' . $message . ' (' . $file . ' ' . $line . ")\n";
         } else {
             // fatal error appeared during init, let's display an HTML page
             // since we don't know the request, we cannot return a response
             // corresponding to the expected protocol
             while (ob_get_level() && @ob_end_clean()) {
             }
             // log into file
             foreach (self::$initErrorMessages as $err) {
                 @error_log($err->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             }
             @error_log($errorLog->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             $msg = $errorLog->getMessage();
             if (strpos($msg, '--') !== false) {
                 list($msg, $bin) = explode('--', $msg, 2);
                 // remove confidential data
             }
             // if accept text/html
             if (isset($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'text/html')) {
                 if (file_exists(jApp::appPath('responses/error.en_US.php'))) {
                     $file = jApp::appPath('responses/error.en_US.php');
                 } else {
                     $file = JELIX_LIB_CORE_PATH . 'response/error.en_US.php';
                 }
                 $HEADTOP = '';
                 $HEADBOTTOM = '';
                 $BODYTOP = '';
                 $BODYBOTTOM = htmlspecialchars($msg);
                 $BASEPATH = jApp::urlBasePath();
                 if ($BASEPATH == '') {
                     $BASEPATH = '/';
                 }
                 header("HTTP/1.1 500 Internal jelix error");
                 header('Content-type: text/html');
                 include $file;
             } else {
                 // output text response
                 header("HTTP/1.1 500 Internal jelix error");
                 header('Content-type: text/plain');
                 echo 'Error during initialization. ' . $msg;
             }
         }
     }
     exit(1);
 }
Ejemplo n.º 6
0
 /**
  * @param string $configFile  the name and path of the config file related to config dir of the app
  * @param string $pseudoScriptName the name of the entry point, relative to the base path,
  *              corresponding to the readed configuration. It should start with a leading /
  *              for non cli script.
  * @param boolean $isCli  indicate if the configuration to read is for a CLI script or no
  */
 function __construct($configFile = '', $pseudoScriptName = '', $isCli = null)
 {
     $this->isCli = $isCli !== null ? $isCli : \jServer::isCLI();
     $this->pseudoScriptName = $pseudoScriptName;
     $this->configFileName = $configFile;
 }
Ejemplo n.º 7
0
* @contributor Loic Mathaud
* @copyright   2005-2016 Laurent Jouanneau
* @link        http://jelix.org
* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
*/
namespace Jelix\DevHelper\Command;

use Symfony\Component\Console\Application;
error_reporting(E_ALL);
define('JELIX_SCRIPTS_PATH', __DIR__ . '/../');
if (!class_exists('jCoordinator', false)) {
    // for old application.init.php which doesn't include init.php
    echo "Error: your application.init.php should include the vendor/autoload.php";
    exit(1);
}
if (!\jServer::isCLI()) {
    echo "Error: you're not allowed to execute this script outside a command line shell.\n";
    exit(1);
}
if (!\Jelix\Core\App::isInit()) {
    echo "Error: should run within an application\n";
    exit(1);
}
\Jelix\Core\App::setEnv('jelix-scripts');
\Jelix\DevHelper\JelixScript::checkTempPath();
$jelixScriptConfig = \Jelix\DevHelper\JelixScript::loadConfig();
$application = new Application("Jelix helpers");
$application->add(new InstallApp($jelixScriptConfig));
$application->add(new InstallModule($jelixScriptConfig));
$application->add(new UninstallModule($jelixScriptConfig));
$application->add(new InitAdmin($jelixScriptConfig));
Ejemplo n.º 8
0
 /**
  * check if the application is NOT installed. If the app is installed, an
  * error message appears and the scripts ends.
  * It should be called only by some scripts
  * like an installation wizard, not by an entry point.
  */
 public static function errorIfAppInstalled()
 {
     if (self::isAppInstalled()) {
         if (\jServer::isCLI()) {
             echo "Application is installed. The script cannot be runned.\n";
         } else {
             header("HTTP/1.1 500 Application not available");
             header('Content-type: text/plain');
             echo "Application is installed. The script cannot be runned.\n";
         }
         exit(1);
     }
 }
Ejemplo n.º 9
0
 /**
  * Main config file path.
  */
 public static function mainConfigFile()
 {
     if (self::$_mainConfigFile) {
         return self::$_mainConfigFile;
     }
     $configFileName = self::$_currentApp->appPath . 'app/config/mainconfig.ini.php';
     if (!file_exists($configFileName)) {
         if (jServer::isCLI() && strpos($_SERVER['SCRIPT_FILENAME'], 'installer.php') !== false) {
             throw new \Exception("Don't find the app/config/mainconfig.ini.php file. You must change your installer.php script. See migration documentation.");
         }
         throw new \Exception("Don't find the app/config/mainconfig.ini.php file. Low-level upgrade is needed. Launch the installer.");
     }
     self::$_mainConfigFile = $configFileName;
     return $configFileName;
 }
Ejemplo n.º 10
0
 static function handleError($type, $code, $message, $file, $line, $trace)
 {
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     if ($type != 'error') {
         self::$initErrorMessages[] = $errorLog;
         return;
     } else {
         if (jServer::isCLI()) {
             while (ob_get_level() && @ob_end_clean()) {
             }
             echo 'Error during initialization: \\n';
             foreach (self::$initErrorMessages as $err) {
                 @error_log($err->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
                 echo '* ' . $err->getMessage() . ' (' . $e->getFile() . ' ' . $e->getLine() . ")\n";
             }
             @error_log($errorLog->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             echo '* ' . $message . ' (' . $file . ' ' . $line . ")\n";
         } else {
             while (ob_get_level() && @ob_end_clean()) {
             }
             foreach (self::$initErrorMessages as $err) {
                 @error_log($err->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             }
             @error_log($errorLog->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             $msg = $errorLog->getMessage();
             if (strpos($msg, '--') !== false) {
                 list($msg, $bin) = explode('--', $msg, 2);
             }
             if (isset($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'text/html')) {
                 if (file_exists(jApp::appPath('responses/error.en_US.php'))) {
                     $file = jApp::appPath('responses/error.en_US.php');
                 } else {
                     $file = JELIX_LIB_CORE_PATH . 'response/error.en_US.php';
                 }
                 $HEADBOTTOM = '';
                 $BODYTOP = '';
                 $BODYBOTTOM = htmlspecialchars($msg);
                 $basePath = '';
                 header("HTTP/1.1 500 Internal jelix error");
                 header('Content-type: text/html');
                 include $file;
             } else {
                 header("HTTP/1.1 500 Internal jelix error");
                 header('Content-type: text/plain');
                 echo 'Error during initialization. ' . $msg;
             }
         }
     }
     exit(1);
 }