PageRenderTime 3ms CodeModel.GetById 16ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/source/innomatic/core/classes/innomatic/core/InnomaticContainer.php

https://bitbucket.org/innoteam/innomatic
PHP | 1571 lines | 1204 code | 170 blank | 197 comment | 113 complexity | 94d66aedc685157599c9c2daf01899c4 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/**
   3 * Innomatic
   4 *
   5 * LICENSE
   6 *
   7 * This source file is subject to the new BSD license that is bundled
   8 * with this package in the file LICENSE.
   9 *
  10 * @copyright  1999-2012 Innoteam S.r.l.
  11 * @license    http://www.innomatic.org/license/   BSD License
  12 * @link       http://www.innomatic.org
  13 * @since      Class available since Release 5.0
  14*/
  15
  16require_once('innomatic/util/Singleton.php');
  17require_once('innomatic/webapp/WebAppContainer.php');
  18
  19/**
  20 * Innomatic base container class.
  21 *
  22 * This class takes care of bootstrapping and shutting down the whole container,
  23 * the root, the domains and the Web Services interface.
  24 *
  25 * It holds the container current state, mode and interface.
  26 *
  27 * This class provided a custom PHP error handler for the container
  28 * applications.
  29 *
  30 * @copyright  1999-2012 Innoteam S.r.l.
  31 * @license    http://www.innomatic.org/license/   BSD License
  32 * @version    Release: @package_version@
  33 * @link       http://www.innomatic.org
  34 * @since      Class available since Release 5.0
  35 * @package    Core
  36 */
  37class InnomaticContainer extends Singleton
  38{
  39    private $_home;
  40    /**
  41     * Complete path of the Innomatic configuration file.
  42     * @var string
  43     */
  44    private $_configurationFile;
  45    /**
  46     *
  47     * @var boolean
  48     */
  49    private $_bootstrapped = false;
  50    private $_rootStarted = false;
  51    private $_domainStarted = false;
  52    private $_pid;
  53    private $_state;
  54    private $_mode = InnomaticContainer::MODE_BASE;
  55    private $_interface = InnomaticContainer::INTERFACE_UNKNOWN;
  56    private $_edition = InnomaticContainer::EDITION_SAAS;
  57    private $_rootDb;
  58    /**
  59     * Root language
  60     *
  61     * @var string
  62     */
  63    private $_language;
  64    /**
  65     * Root country.
  66     *
  67     * @var string
  68     */
  69    private $_country;
  70    private $_config;
  71    private $_logger;
  72    /**
  73     * Stores the result object of a maintenance routine.
  74     *
  75     * @var mixed
  76     */
  77    private $_maintenanceResult;
  78    private $_loadTimer;
  79    private $_dbLoadTimer;
  80    private $_platformName;
  81    private $_platformGroup;
  82    private $_lockOverride = false;
  83    private $_baseUrl;
  84    private $_externalBaseUrl;
  85
  86    private $_currentWebServicesProfile;
  87    private $_currentWebServicesUser;
  88    private $_currentWebServicesMethods = array();
  89
  90    private $_currentDomain;
  91    private $_currentUser;
  92
  93    // Innomatic platform/instance state
  94
  95    const STATE_SETUP = 1;
  96    const STATE_DEVELOPMENT = 2;
  97    const STATE_DEBUG = 3;
  98    const STATE_PRODUCTION = 4;
  99    const STATE_UPGRADE = 5;
 100    const STATE_MAINTENANCE = 6;
 101
 102    // Output interface types
 103
 104    const INTERFACE_UNKNOWN = 1;
 105    const INTERFACE_CONSOLE = 2;
 106    const INTERFACE_WEB = 3;
 107    const INTERFACE_WEBSERVICES = 4;
 108    const INTERFACE_GUI = 5;
 109    const INTERFACE_EXTERNAL = 6;
 110
 111    // Mode types
 112
 113    const MODE_BASE = 1;
 114    const MODE_ROOT = 2;
 115    const MODE_DOMAIN = 3;
 116
 117    // Edition types
 118
 119    const EDITION_SAAS = 1;
 120    const EDITION_ENTERPRISE = 2;
 121
 122    // Deprecated
 123    
 124    const EDITION_ASP = 1;
 125    
 126    // Password result codes
 127    const SETROOTPASSWORD_NEW_PASSWORD_IS_EMPTY = -1;
 128    const SETROOTPASSWORD_UNABLE_TO_WRITE_NEW_PASSWORD = -2;
 129    const SETROOTPASSWORD_OLD_PASSWORD_IS_WRONG = -3;
 130
 131    /**
 132     * Bootstraps the Innomatic container.
 133     *
 134     * @param string $home Complete path of the directory containing the
 135     * Innomatic webapp.
 136     * @param string $configuration Complete path of the Innomatic
 137     * configuration file.
 138     */
 139    public function bootstrap($home, $configuration)
 140    {
 141        if ($this->_bootstrapped) {
 142            return;
 143        }
 144        $this->_home = $home;
 145
 146        // Reads the configuration
 147        $this->_configurationFile = $configuration;
 148        require_once('innomatic/core/InnomaticSettings.php');
 149        $this->_config = new InnomaticSettings($configuration);
 150
 151        // *********************************************************************
 152        // Environment
 153        // *********************************************************************
 154
 155        // PHP
 156        $timelimit = $this->_config->Value('PHPExecutionTimeLimit');
 157        if (!strlen($timelimit)) {
 158            $timelimit = 0;
 159        }
 160        set_time_limit($timelimit);
 161        ignore_user_abort(TRUE);
 162        //set_magic_quotes_runtime(0);
 163
 164        // Adds global override classes folder to the include path.
 165        set_include_path(
 166            $this->_home . 'core/overrides/classes/'
 167            . PATH_SEPARATOR . get_include_path()
 168        );
 169
 170        // *********************************************************************
 171        // Innomatic state, mode, interface and edition
 172        // *********************************************************************
 173
 174        // Waits until system is in upgrade phase
 175        if ($this->_lockOverride == false) {
 176            while (file_exists(
 177                $this->_home . 'core/temp/upgrading_system_lock'
 178            )) {
 179                $this->_state = InnomaticContainer::STATE_UPGRADE;
 180                clearstatcache();
 181                sleep(1);
 182            }
 183        }
 184        // Checks if system is in setup phase and sets the state
 185        if (file_exists($this->_home . 'core/temp/setup_lock')) {
 186            $this->_state = InnomaticContainer::STATE_SETUP;
 187            if (extension_loaded('APD')) {
 188                apd_set_session_trace(35);
 189            }
 190        } else {
 191            switch ($this->_config->Value('PlatformState')) {
 192                case 'debug':
 193                    $this->_state = InnomaticContainer::STATE_DEBUG;
 194                    if (extension_loaded('APD')) {
 195                        apd_set_session_trace(35);
 196                    }
 197                    break;
 198                case 'development':
 199                    $this->_state = InnomaticContainer::STATE_DEVELOPMENT;
 200                    break;
 201                case 'production':
 202                    $this->_state = InnomaticContainer::STATE_PRODUCTION;
 203                    break;
 204                default:
 205                    $this->_state = InnomaticContainer::STATE_PRODUCTION;
 206            }
 207        }
 208        // Interface
 209        //$this->interface = InnomaticContainer::INTERFACE_UNKNOWN;
 210        // Mode
 211        //$this->mode = InnomaticContainer::MODE_ROOT;
 212        // Edition
 213        if ($this->_config->Value('PlatformEdition') == 'enterprise') {
 214            $this->_edition = InnomaticContainer::EDITION_ENTERPRISE;
 215        }
 216
 217        // *********************************************************************
 218        // Pid and shutdown function
 219        // *********************************************************************
 220
 221        if ($this->_state != InnomaticContainer::STATE_SETUP) {
 222            $this->_pid = md5(microtime());
 223            if (!file_exists($this->_home . 'core/temp/pids/')) {
 224                @mkdir($this->_home . 'core/temp/pids/');
 225            }
 226            touch($this->_home . 'core/temp/pids/' . $this->_pid, time());
 227            register_shutdown_function(array($this, 'shutdown'));
 228        }
 229
 230        // *********************************************************************
 231        // Innomatic platform name
 232        // *********************************************************************
 233
 234        $this->_platformName = $this->_config->Value('PlatformName');
 235        $this->_platformGroup = $this->_config->Value('PlatformGroup');
 236
 237        // *********************************************************************
 238        // Innomatic error handler
 239        // *********************************************************************
 240
 241        set_error_handler(array($this, 'errorHandler'));
 242
 243        // *********************************************************************
 244        // Innomatic root
 245        // *********************************************************************
 246
 247        $this->_country = $this->_config->Value('RootCountry');
 248        $this->_language = $this->_config->Value('RootLanguage');
 249
 250        require_once('innomatic/dataaccess/DataAccessFactory.php');
 251
 252        if ($this->_state != InnomaticContainer::STATE_SETUP) {
 253            // Innomatic central database
 254            //
 255            require_once('innomatic/dataaccess/DataAccessSourceName.php');
 256            $dasnString = $this->_config->Value('RootDatabaseType') . '://'
 257            . $this->_config->Value('RootDatabaseUser') . ':'
 258            . $this->_config->Value('RootDatabasePassword') . '@'
 259            . $this->_config->Value('RootDatabaseHost') . ':'
 260            . $this->_config->Value('RootDatabasePort') . '/'
 261            . $this->_config->Value('RootDatabaseName') . '?'
 262            . 'logfile='
 263            . InnomaticContainer::instance('innomaticcontainer')->getHome()
 264            . 'core/log/innomatic_root_db.log';
 265            $this->_rootDb = DataAccessFactory::getDataAccess(
 266                new DataAccessSourceName($dasnString)
 267            );
 268            if (!$this->_rootDb->Connect()) {
 269                $this->abort('Database not connected');
 270            }
 271        }
 272
 273        // *********************************************************************
 274        // Run time state and interface defined data
 275        // *********************************************************************
 276
 277        // Debugger
 278        if ($this->_state == InnomaticContainer::STATE_DEBUG) {
 279            require_once('innomatic/debug/LoadTime.php');
 280            $this->_loadTimer = new LoadTime(
 281                LoadTime::LOADTIME_MODE_CONTINUOUS
 282            );
 283            $this->_loadTimer->Mark('start');
 284            $this->_dbLoadTimer = new LoadTime(
 285                LoadTime::LOADTIME_MODE_STARTSTOP
 286            );
 287        }
 288
 289        // Security
 290        $securityReportsInterval = $this->_config->Value(
 291            'SecurityReportsInterval'
 292        );
 293        if ($securityReportsInterval > 0) {
 294            $lastSecurityReport = $this->_config->Value(
 295                'SecurityLastReportTime'
 296            );
 297            if (
 298                !$lastSecurityReport
 299                or $lastSecurityReport < (time() - (
 300                    $securityReportsInterval * 3600 * 24
 301                ))
 302            ) {
 303                require_once('innomatic/security/SecurityManager.php');
 304                $innomaticSecurity = new SecurityManager();
 305                $innomaticSecurity->SendReport();
 306                unset($innomaticSecurity);
 307            }
 308        }
 309        unset($securityReportsInterval);
 310
 311        // Maintenance
 312        $maintenanceInterval = $this->_config->Value('MaintenanceInterval');
 313        if (
 314            $this->_state != InnomaticContainer::STATE_MAINTENANCE
 315            and $maintenanceInterval > 0
 316        ) {
 317            $lastMaintenance = $this->_config->Value(
 318                'MaintenanceLastExecutionTime'
 319            );
 320            if (
 321                !$lastMaintenance
 322                or $lastMaintenance < (time() - (
 323                    $maintenanceInterval * 3600 * 24
 324                ))
 325            ) {
 326                require_once('innomatic/maintenance/MaintenanceHandler.php');
 327                $innomaticMaintenance = new MaintenanceHandler();
 328                $innomaticMaintenance->DoMaintenance();
 329                $innomaticMaintenance->SendReport();
 330                unset($innomaticMaintenance);
 331            }
 332        }
 333        unset($maintenanceInterval);
 334
 335        // *********************************************************************
 336        // Auto exec routines
 337        // *********************************************************************
 338
 339        // Application reupdate check
 340        if (file_exists($this->_home . 'core/temp/appinst/reupdate')) {
 341            require_once('innomatic/application/Application.php');
 342            $tmpmod = new Application($this->_rootDb, '');
 343            $tmpmod->Install($this->_home . 'core/temp/appinst/reupdate');
 344            clearstatcache();
 345            if (file_exists($this->_home . 'core/temp/appinst/reupdate')) {
 346                unlink($this->_home . 'core/temp/appinst/reupdate');
 347            }
 348        }
 349
 350        // Startup hook
 351        if ($this->_state != InnomaticContainer::STATE_SETUP) {
 352            require_once('innomatic/process/Hook.php');
 353            $hook = new Hook($this->_rootDb, 'innomatic', 'instance');
 354            $null = '';
 355            switch ($hook->CallHooks('startup', $null, '')) {
 356                case Hook::RESULT_ABORT :
 357                    $this->abort('Bootstrap aborted');
 358                    break;
 359            }
 360        }
 361
 362        // Bootstrap end
 363        $this->_bootstrapped = true;
 364    }
 365
 366    /**
 367     * Starts the root mode.
 368     * @param string $userId Root username (currently not used, defaults to
 369     * "root").
 370     */
 371    public function startRoot($userId = 'root')
 372    {
 373        $this->setMode(InnomaticContainer::MODE_ROOT);
 374
 375        if ($this->_rootStarted) {
 376            return;
 377        }
 378
 379        $this->_rootStarted = true;
 380    }
 381
 382    public function startDomain($domainId, $userId = '')
 383    {
 384        $result = false;
 385        $this->setMode(InnomaticContainer::MODE_DOMAIN);
 386
 387        if (is_object($this->_currentDomain) or $this->_domainStarted) {
 388            // A domain has been already started
 389            return false;
 390        }
 391
 392        require_once('innomatic/domain/Domain.php');
 393        $this->_currentDomain = new Domain($this->_rootDb, $domainId, null);
 394
 395        if ($this->_currentDomain->isValid()) {
 396            // Check if domain is active
 397            //
 398            if (
 399                $this->getInterface() != InnomaticContainer::INTERFACE_WEB
 400                and $this->_currentDomain->domaindata['domainactive']
 401                == $this->_rootDb->fmtfalse
 402            ) {
 403                $this->abort('Domain disabled');
 404            }
 405
 406            if (!$this->_currentDomain->getDataAccess()->isConnected()) {
 407                $adloc = new LocaleCatalog(
 408                    'innomatic::authentication',
 409                    $this->_language
 410                );
 411                InnomaticContainer::instance('innomaticcontainer')->abort(
 412                    $adloc->getStr('nodb')
 413                );
 414            }
 415
 416            // Adds override classes folder to the include path.
 417            set_include_path(
 418                $this->_home . 'core/domains/'
 419                . $this->_currentDomain->getDomainId()
 420                . '/overrides/classes/'
 421                . PATH_SEPARATOR . get_include_path()
 422            );
 423
 424            // User
 425            //
 426            // TODO check in Enterprise edition if the admin@domainid part is ok
 427            // $admin_username = 'admin'
 428            // .(InnomaticContainer::instance(
 429            //      'innomaticcontainer'
 430            // )->getEdition() == InnomaticContainer::EDITION_SAAS ? '@'.$domain
 431            // : '');
 432            require_once('innomatic/domain/user/User.php');
 433            $this->_currentUser = new User(
 434                $this->_currentDomain->domainserial,
 435                User::getUserIdByUsername(
 436                    strlen($userId) ? $userId : 'admin@' . $domainId
 437                )
 438            );
 439
 440            $result = true;
 441        }
 442        $this->_domainStarted = $result;
 443        return $result;
 444    }
 445
 446    public function stopDomain()
 447    {
 448        if ($this->_domainStarted) {
 449			if (InnomaticContainer::instance('innomaticcontainer')->getEdition() == InnomaticContainer::EDITION_SAAS) {
 450            	$this->_currentDomain->getDataAccess()->close();
 451        	}
 452            // TODO implement
 453
 454            // Removes override classes folder from the include path
 455            set_include_path(
 456                str_replace(
 457                    $this->_home . 'core/domains/'
 458                    . $this->_currentDomain->getDomainId()
 459                    . '/overrides/classes/' . PATH_SEPARATOR,
 460                    '', get_include_path()
 461                )
 462            );
 463
 464            $this->_domainStarted = false;
 465            $this->_currentDomain = null;
 466            $this->setMode(InnomaticContainer::MODE_ROOT);
 467        }
 468    }
 469
 470    // TODO to be implemented
 471    public function startWebServices()
 472    {
 473    }
 474
 475    public function startMaintenance()
 476    {
 477        $this->setState(InnomaticContainer::STATE_MAINTENANCE);
 478        $this->setInterface(InnomaticContainer::INTERFACE_CONSOLE);
 479
 480        require_once('innomatic/maintenance/MaintenanceHandler.php');
 481        require_once('innomatic/process/Hook.php');
 482
 483        $hook = new Hook($this->_rootDb, 'innomatic', 'instance');
 484        $null = null;
 485        switch ($hook->CallHooks('maintenance', $null, '')) {
 486            case Hook::RESULT_ABORT:
 487                InnomaticContainer::instance('innomaticcontainer')->abort(
 488                    'Maintenance aborted'
 489                );
 490                break;
 491        }
 492
 493        $innomaticMnt = new MaintenanceHandler();
 494        $this->_maintenanceResult = $innomaticMnt->DoMaintenance();
 495        $innomaticMnt->SendReport($this->_maintenanceResult);
 496    }
 497
 498    /**
 499     * Halts Innomatic Container.
 500     *
 501     * This must be called by applications in place of exit(), in order to exit
 502     * in a clean mode.
 503     *
 504     * @param string $status
 505     */
 506    public function halt($status = '')
 507    {
 508        $rootContainer = RootContainer::instance('rootcontainer');
 509        $rootContainer->stop();
 510        exit($status);
 511    }
 512
 513    public function shutdown()
 514    {
 515        if ($this->_state != InnomaticContainer::STATE_SETUP) {
 516            require_once('innomatic/process/Hook.php');
 517            if (is_object($this->_rootDb)) {
 518                $hook = new Hook($this->_rootDb, 'innomatic', 'instance');
 519                $null = '';
 520                switch ($hook->CallHooks('shutdown', $null, '')) {
 521                    case Hook::RESULT_ABORT:
 522                        $this->abort('Shutdown aborted');
 523                        break;
 524                }
 525            }
 526        }
 527
 528        switch ($this->_state) {
 529            case InnomaticContainer::STATE_DEBUG:
 530                if (
 531                    is_object($this->_loadTimer)
 532                    and RootContainer::instance('rootcontainer')->isClean()
 533                    == true
 534                ) {
 535                    $this->_loadTimer->Mark('end');
 536
 537                    $log = $this->getLogger();
 538                    $log->logEvent(
 539                        'innomatic',
 540                        'Profiler total time: '
 541                        . $this->_loadTimer->getTotalTime(),
 542                        Logger::DEBUG
 543                    );
 544
 545                    $fh = @fopen(
 546                        $this->_home . 'core/temp/pids/' . $this->_pid,
 547                        'w'
 548                    );
 549                    if ($fh) {
 550                        require_once('innomatic/debug/InnomaticDump.php');
 551                        $dump = InnomaticDump::instance('innomaticdump');
 552                        $dump->snapshot();
 553                        @fwrite($fh, serialize($dump));
 554                        @fclose($fh);
 555                    }
 556                }
 557                break;
 558        }
 559
 560        if (!RootContainer::instance('rootcontainer')->isClean()) {
 561            if (is_object($this->_loadTimer)) {
 562                $this->_loadTimer->Mark('end');
 563
 564                $log = $this->getLogger();
 565                $log->logEvent(
 566                    'innomatic',
 567                    'Profiler total time: '
 568                    . $this->_loadTimer->getTotalTime(),
 569                    Logger::DEBUG
 570                );
 571            }
 572
 573            $fh = @fopen(
 574                $this->_home . 'core/temp/pids/' . $this->_pid . '_coredump',
 575                'w'
 576            );
 577            if ($fh) {
 578                require_once('innomatic/debug/InnomaticDump.php');
 579                $dump = InnomaticDump::instance('innomaticdump');
 580                $dump->snapshot();
 581                @fwrite($fh, serialize($dump));
 582                @fclose($fh);
 583            }
 584
 585        }
 586
 587        if (
 588            !RootContainer::instance('rootcontainer')->isClean()
 589            or (
 590                $this->_state != InnomaticContainer::STATE_DEBUG
 591                and file_exists(
 592                    $this->_home . 'core/temp/pids/' . $this->_pid
 593                )
 594            )
 595        ) {
 596            @unlink($this->_home . 'core/temp/pids/' . $this->_pid);
 597        }
 598
 599        exit();
 600    }
 601
 602    public function abort($text, $forceInterface = '')
 603    {
 604        require_once('innomatic/wui/Wui.php');
 605        if (strlen($forceInterface)) {
 606            $interface = $forceInterface;
 607        } else {
 608            $interface = $this->_interface;
 609        }
 610
 611        if ($interface == InnomaticContainer::INTERFACE_EXTERNAL) {
 612            /*
 613             if (
 614                 isset(
 615                     $GLOBALS['gEnv']['runtime']
 616                    ['external_interface_error_handler'])
 617                and function_exists(
 618            $GLOBALS['gEnv']['runtime']['external_interface_error_handler'])) {
 619             $func = $GLOBALS['gEnv']['runtime']
 620                ['external_interface_error_handler'];
 621             $func ($text);
 622             } else {
 623             */
 624            $interface = InnomaticContainer::INTERFACE_WEB;
 625            $this->_interface = InnomaticContainer::INTERFACE_WEB;
 626            //}
 627        }
 628
 629        switch ($interface) {
 630            case InnomaticContainer::INTERFACE_GUI :
 631                // break was intentionally omitted
 632            case InnomaticContainer::INTERFACE_UNKNOWN :
 633                // break was intentionally omitted
 634            case InnomaticContainer::INTERFACE_WEBSERVICES :
 635                // break was intentionally omitted
 636            case InnomaticContainer::INTERFACE_EXTERNAL :
 637                break;
 638            case InnomaticContainer::INTERFACE_CONSOLE :
 639                echo "\n".$text."\n";
 640                break;
 641            case InnomaticContainer::INTERFACE_WEB :
 642                $tmpWui = Wui::instance('wui');
 643                $tmpWui->loadWidget('empty');
 644                //$tmp_elem = new WuiEmpty('empty');
 645
 646                $dieImage = Wui::instance('wui')->getTheme()->mStyle['biglogo'];
 647
 648                ?>
 649<html>
 650<head>
 651<basefont face="Verdana" />
 652<title>Innomatic</title>
 653<link rel="stylesheet" type="text/css"
 654    href="<?php echo Wui::instance('wui')->getTheme()->mStyle['css'];
 655                ?>">
 656</head>
 657
 658<body bgcolor="white">
 659
 660<table border="0" cellspacing="0" cellpadding="0" align="center"
 661    width="200" height="100%">
 662    <tr>
 663        <td height="50%">
 664
 665    </tr>
 666    <tr>
 667        <td align="center" valign="middle"><a
 668            href="<?php echo InnomaticContainer::instance(
 669                'innomaticcontainer'
 670            )->getExternalBaseUrl();
 671            ?>"
 672            target="_top"><img src="<?php echo $dieImage;
 673                ?>"
 674            alt="Innomatic" border="0"></a></td>
 675    </tr>
 676    <tr>
 677        <td>&nbsp;</td>
 678    </tr>
 679    <tr>
 680        <td align="center"><?php echo $text;
 681        ?></td>
 682    </tr>
 683    <tr>
 684        <td height="50%">
 685
 686    </tr>
 687</table>
 688
 689</body>
 690</html>
 691        <?php break;
 692        }
 693
 694        $this->halt();
 695    }
 696
 697    public function errorHandler(
 698        $errorType,
 699        $errorMessage,
 700        $errorFile,
 701        $errorLine,
 702        $errorContext
 703    )
 704    {
 705        $logError[E_ERROR]['log'] = true;
 706        $logError[E_ERROR]['die'] = true;
 707
 708        $logError[E_WARNING]['log'] = false;
 709        $logError[E_WARNING]['die'] = false;
 710
 711        $logError[E_PARSE]['log'] = true;
 712        $logError[E_PARSE]['die'] = false;
 713
 714        $logError[E_NOTICE]['log'] = false;
 715        $logError[E_NOTICE]['die'] = false;
 716
 717        $logError[E_CORE_ERROR]['log'] = true;
 718        $logError[E_CORE_ERROR]['die'] = true;
 719
 720        $logError[E_CORE_WARNING]['log'] = false;
 721        $logError[E_CORE_WARNING]['die'] = false;
 722
 723        $logError[E_COMPILE_ERROR]['log'] = true;
 724        $logError[E_COMPILE_ERROR]['die'] = true;
 725
 726        $logError[E_COMPILE_WARNING]['log'] = false;
 727        $logError[E_COMPILE_WARNING]['die'] = false;
 728
 729        $logError[E_USER_ERROR]['log'] = true;
 730        $logError[E_USER_ERROR]['die'] = true;
 731
 732        $logError[E_USER_WARNING]['log'] = false;
 733        $logError[E_USER_WARNING]['die'] = false;
 734
 735        $logError[E_USER_NOTICE]['log'] = false;
 736        $logError[E_USER_NOTICE]['die'] = false;
 737
 738        if (InnomaticContainer::instance('innomaticcontainer')->getState() != InnomaticContainer::STATE_SETUP) {
 739            $phpLog = InnomaticContainer::instance(
 740                'innomaticcontainer'
 741            )->getHome() . 'core/log/php.log';
 742        } else {
 743            $phpLog = InnomaticContainer::instance(
 744                'innomaticcontainer'
 745            )->getHome() . 'core/log/innomatic.log';
 746        }
 747
 748        switch ($this->_state) {
 749            case InnomaticContainer::STATE_DEBUG :
 750                $logError[E_NOTICE]['log'] = true;
 751                $logError[E_USER_NOTICE]['log'] = true;
 752                $logError[E_WARNING]['log'] = true;
 753                $logError[E_CORE_WARNING]['log'] = true;
 754                $logError[E_COMPILE_WARNING]['die'] = true;
 755                $logError[E_USER_WARNING]['log'] = true;
 756                break;
 757
 758            case InnomaticContainer::STATE_SETUP :
 759            case InnomaticContainer::STATE_DEVELOPMENT :
 760                /* For debug purposes in setup procedure add these commands:
 761                 $log_err[E_NOTICE]['log'] = true;
 762                 $log_err[E_USER_NOTICE]['log'] = true;
 763                 */
 764
 765                $logError[E_WARNING]['log'] = true;
 766                $logError[E_CORE_WARNING]['log'] = true;
 767                $logError[E_COMPILE_WARNING]['die'] = true;
 768                $logError[E_USER_WARNING]['log'] = true;
 769                break;
 770
 771            case InnomaticContainer::STATE_PRODUCTION :
 772            case InnomaticContainer::STATE_UPGRADE :
 773                break;
 774        }
 775
 776        switch ($errorType) {
 777            case E_ERROR:
 778                if ($logError[E_ERROR]['log']) {
 779                    require_once('innomatic/logging/Logger.php');
 780                    $log = new Logger($phpLog);
 781                    $log->logEvent(
 782                        'Innomatic error handler',
 783                        'PHP generated an ERROR at line '
 784                        . $errorLine
 785                        . ' of file '
 786                        . $errorFile
 787                        . '. The error message was: '
 788                        . $errorMessage,
 789                        Logger::FAILURE
 790                    );
 791                }
 792                if ($logError[E_ERROR]['die']) {
 793                    $this->abort(
 794                        'A fatal error occured at line '
 795                        . $errorLine
 796                        . ' of file '
 797                        . $errorFile
 798                        . '. The error message was: '
 799                        . $errorMessage
 800                    );
 801                }
 802                break;
 803
 804            case E_WARNING:
 805                if ($logError[E_WARNING]['log']) {
 806                    require_once('innomatic/logging/Logger.php');
 807                    $log = new Logger($phpLog);
 808                    $log->logEvent(
 809                        'Innomatic error handler',
 810                        'PHP generated a WARNING at line '
 811                        . $errorLine
 812                        . ' of file '
 813                        . $errorFile
 814                        . '. The error message was: '
 815                        . $errorMessage,
 816                        Logger::WARNING
 817                    );
 818                }
 819                if ($logError[E_WARNING]['die']) {
 820                    $this->abort(
 821                        'A warning occured at line '
 822                        . $errorLine
 823                        . ' of file '
 824                        . $errorFile
 825                        . '. The error message was: '
 826                        . $errorMessage
 827                    );
 828                }
 829                break;
 830
 831            case E_PARSE :
 832                if ($logError[E_PARSE]['log']) {
 833                    require_once('innomatic/logging/Logger.php');
 834                    $log = new Logger($phpLog);
 835                    $log->logEvent(
 836                        'Innomatic error handler',
 837                        'PHP generated a PARSE error at line '
 838                        .$errorLine
 839                        .' of file '
 840                        .$errorFile
 841                        .'. The error message was: '
 842                        .$errorMessage,
 843                        Logger::ERROR
 844                    );
 845                }
 846                if ($logError[E_PARSE]['die'])
 847                $this->abort(
 848                    'A parse error occured at line '
 849                    .$errorLine
 850                    .' of file '
 851                    .$errorFile
 852                    .'. The error message was: '
 853                    .$errorMessage
 854                );
 855                break;
 856
 857            case E_NOTICE :
 858                if ($logError[E_NOTICE]['log']) {
 859                    require_once('innomatic/logging/Logger.php');
 860                    $log = new Logger($phpLog);
 861                    $log->logEvent(
 862                        'Innomatic error handler',
 863                        'PHP generated a notice at line '
 864                        .$errorLine
 865                        .' of file '
 866                        .$errorFile
 867                        .'. The error message was: '
 868                        .$errorMessage,
 869                        Logger::NOTICE
 870                    );
 871                }
 872                if ($logError[E_NOTICE]['die'])
 873                $this->abort(
 874                    'A notice occured at line '
 875                    .$errorLine
 876                    .' of file '
 877                    .$errorFile
 878                    .'. The error message was: '
 879                    .$errorMessage
 880                );
 881                break;
 882
 883            case E_CORE_ERROR :
 884                if ($logError[E_CORE_ERROR]['log']) {
 885                    require_once('innomatic/logging/Logger.php');
 886                    $log = new Logger($phpLog);
 887                    $log->logEvent(
 888                        'Innomatic error handler',
 889                        'PHP generated a CORE ERROR at line '
 890                        .$errorLine
 891                        .' of file '
 892                        .$errorFile
 893                        .'. The error message was: '
 894                        .$errorMessage,
 895                        Logger::ERROR
 896                    );
 897                }
 898                if ($logError[E_CORE_ERROR]['die'])
 899                $this->abort(
 900                    'A core error occured at line '
 901                    .$errorLine
 902                    .' of file '
 903                    .$errorFile
 904                    .'. The error message was: '
 905                    .$errorMessage
 906                );
 907                break;
 908
 909            case E_CORE_WARNING :
 910                if ($logError[E_CORE_WARNING]['log']) {
 911                    require_once('innomatic/logging/Logger.php');
 912                    $log = new Logger($phpLog);
 913                    $log->logEvent(
 914                        'Innomatic error handler',
 915                        'PHP generated a CORE WARNING at line '
 916                        .$errorLine
 917                        .' of file '
 918                        .$errorFile
 919                        .'. The error message was: '
 920                        .$errorMessage,
 921                        Logger::ERROR
 922                    );
 923                }
 924                if ($logError[E_CORE_WARNING]['die'])
 925                    $this->abort(
 926                        'A core warning occured at line '
 927                        .$errorLine
 928                        .' of file '
 929                        .$errorFile
 930                        .'. The error message was: '
 931                        .$errorMessage
 932                    );
 933                break;
 934
 935            case E_COMPILE_ERROR :
 936                if ($logError[E_COMPILE_ERROR]['log']) {
 937                    require_once('innomatic/logging/Logger.php');
 938                    $log = new Logger($phpLog);
 939                    $log->logEvent(
 940                        'Innomatic error handler',
 941                        'PHP generated a COMPILE ERROR at line '
 942                        .$errorLine
 943                        .' of file '
 944                        .$errorFile
 945                        .'. The error message was: '
 946                        .$errorMessage,
 947                        Logger::ERROR
 948                    );
 949                }
 950                if ($logError[E_COMPILE_ERROR]['die'])
 951                    $this->abort(
 952                        'A compile error occured at line '
 953                        .$errorLine
 954                        .' of file '
 955                        .$errorFile
 956                        .'. The error message was: '
 957                        .$errorMessage
 958                    );
 959                break;
 960
 961            case E_COMPILE_WARNING :
 962                if ($logError[E_COMPILE_WARNING]['log']) {
 963                    require_once('innomatic/logging/Logger.php');
 964                    $log = new Logger($phpLog);
 965                    $log->logEvent(
 966                        'Innomatic error handler',
 967                        'PHP generated a COMPILE WARNING at line '
 968                        .$errorLine
 969                        .' of file '
 970                        .$errorFile
 971                        .'. The error message was: '
 972                        .$errorMessage,
 973                        Logger::ERROR
 974                    );
 975                }
 976                if ($logError[E_COMPILE_WARNING]['die'])
 977                    $this->abort(
 978                        'A compile warning occured at line '
 979                        .$errorLine
 980                        .' of file '
 981                        .$errorFile
 982                        .'. The error message was: '
 983                        .$errorMessage
 984                    );
 985                break;
 986
 987            case E_USER_ERROR :
 988                if ($logError[E_USER_ERROR]['log']) {
 989                    require_once('innomatic/logging/Logger.php');
 990                    $log = new Logger($phpLog);
 991                    $log->logEvent(
 992                        'Innomatic error handler',
 993                        'PHP generated an USER ERROR at line '
 994                        .$errorLine
 995                        .' of file '
 996                        .$errorFile
 997                        .'. The error message was: '
 998                        .$errorMessage,
 999                        Logger::ERROR
1000                    );
1001                }
1002                if ($logError[E_USER_ERROR]['die'])
1003                    $this->abort(
1004                        'An user error occured at line '
1005                        .$errorLine
1006                        .' of file '
1007                        .$errorFile
1008                        .'. The error message was: '
1009                        .$errorMessage
1010                    );
1011                break;
1012
1013            case E_USER_WARNING :
1014                if ($logError[E_USER_WARNING]['log']) {
1015                    require_once('innomatic/logging/Logger.php');
1016                    $log = new Logger($phpLog);
1017                    $log->logEvent(
1018                        'Innomatic error handler',
1019                        'PHP generated an USER WARNING at line '
1020                        .$errorLine
1021                        .' of file '
1022                        .$errorFile
1023                        .'. The error message was: '
1024                        .$errorMessage,
1025                        Logger::ERROR
1026                    );
1027                }
1028                if ($logError[E_USER_WARNING]['die'])
1029                $this->abort(
1030                    'An user warning occured at line '
1031                    .$errorLine
1032                    .' of file '
1033                    .$errorFile
1034                    .'. The error message was: '
1035                    .$errorMessage
1036                );
1037                break;
1038
1039            case E_USER_NOTICE :
1040                if ($logError[E_USER_NOTICE]['log']) {
1041                    require_once('innomatic/logging/Logger.php');
1042                    $log = new Logger($phpLog);
1043                    $log->logEvent(
1044                        'Innomatic error handler',
1045                        'PHP generated an USER NOTICE at line '
1046                        .$errorLine
1047                        .' of file '
1048                        .$errorFile
1049                        .'. The error message was: '
1050                        .$errorMessage,
1051                        Logger::ERROR
1052                    );
1053                }
1054                if ($logError[E_USER_NOTICE]['die'])
1055                $this->abort(
1056                    'An user notice occured at line '
1057                    .$errorLine
1058                    .' of file '
1059                    .$errorFile
1060                    .'. The error message was: '
1061                    .$errorMessage
1062                );
1063                break;
1064
1065            default :
1066                break;
1067        }
1068    }
1069
1070    // Accessors
1071
1072    public function getHome()
1073    {
1074        return $this->_home;
1075    }
1076
1077    public function getConfigurationFile()
1078    {
1079        return $this->_configurationFile;
1080    }
1081
1082    public function getDataAccess()
1083    {
1084        return $this->_rootDb;
1085    }
1086
1087    public function getLanguage()
1088    {
1089        return $this->_language;
1090    }
1091
1092    public function getCountry()
1093    {
1094        return $this->_country;
1095    }
1096
1097    public function getConfig()
1098    {
1099        return $this->_config;
1100    }
1101
1102    public function getLogger()
1103    {
1104        // Initialized the logger if not started
1105        if (!is_object($this->_logger)) {
1106            require_once('innomatic/logging/Logger.php');
1107            $this->_logger = new Logger(
1108                $this->_home . 'core/log/innomatic.log'
1109            );
1110        }
1111        return $this->_logger;
1112    }
1113
1114    public function getPid()
1115    {
1116        return $this->_pid;
1117    }
1118
1119    public function getState()
1120    {
1121        return $this->_state;
1122    }
1123
1124    public function setState($state)
1125    {
1126        switch ($state) {
1127            case InnomaticContainer::STATE_SETUP:
1128                // break was intentionally omitted
1129            case InnomaticContainer::STATE_DEVELOPMENT:
1130                // break was intentionally omitted
1131            case InnomaticContainer::STATE_DEBUG:
1132                // break was intentionally omitted
1133            case InnomaticContainer::STATE_PRODUCTION:
1134                // break was intentionally omitted
1135            case InnomaticContainer::STATE_UPGRADE:
1136                // break was intentionally omitted
1137            case InnomaticContainer::STATE_MAINTENANCE:
1138                $this->_state = $state;
1139                break;
1140        }
1141    }
1142
1143    public function getMode()
1144    {
1145        return $this->_mode;
1146    }
1147
1148    public function setMode($mode)
1149    {
1150        // Mode Base cannot be set
1151        switch ($mode) {
1152            case InnomaticContainer::MODE_ROOT:
1153                // break was intentionally omitted
1154            case InnomaticContainer::MODE_DOMAIN:
1155                $this->_mode = $mode;
1156                break;
1157        }
1158    }
1159
1160    public function getInterface()
1161    {
1162        return $this->_interface;
1163    }
1164
1165    public function setInterface($interface)
1166    {
1167        switch ($interface) {
1168            case InnomaticContainer::INTERFACE_UNKNOWN:
1169                // break was intentionally omitted
1170            case InnomaticContainer::INTERFACE_CONSOLE:
1171                // break was intentionally omitted
1172            case InnomaticContainer::INTERFACE_WEB:
1173                // break was intentionally omitted
1174            case InnomaticContainer::INTERFACE_WEBSERVICES:
1175                // break was intentionally omitted
1176            case InnomaticContainer::INTERFACE_GUI:
1177                // break was intentionally omitted
1178            case InnomaticContainer::INTERFACE_EXTERNAL:
1179                $this->_interface = $interface;
1180                break;
1181        }
1182    }
1183
1184    public function getEdition()
1185    {
1186        return $this->_edition;
1187    }
1188
1189    public function getPlatformName()
1190    {
1191        return $this->_platformName;
1192    }
1193
1194    public function getPlatformGroup()
1195    {
1196        return $this->_platformGroup;
1197    }
1198
1199    public function &getMaintenanceResult()
1200    {
1201        return $this->_maintenanceResult;
1202    }
1203
1204    public function getLoadTimer()
1205    {
1206        return $this->_loadTimer;
1207    }
1208
1209    public function getDbLoadTimer()
1210    {
1211        return $this->_dbLoadTimer;
1212    }
1213
1214    public function getLockOverride()
1215    {
1216        return $this->_lockOverride;
1217    }
1218
1219    public function setLockOverride($status)
1220    {
1221        $this->_lockOverride = $status;
1222    }
1223
1224    public function unlock()
1225    {
1226        // Erases all semaphores.
1227        $handle = opendir(
1228            InnomaticContainer::instance('innomaticcontainer')->getHome()
1229            . 'core/temp/semaphores'
1230        );
1231        if ($handle) {
1232            while (($file = readdir($handle)) !== false) {
1233                if ($file != '.' and $file != '..') {
1234                    @unlink(
1235                        InnomaticContainer::instance(
1236                            'innomaticcontainer'
1237                        )->getHome()
1238                        . 'core/temp/semaphores/' . $file
1239                    );
1240                }
1241            }
1242            closedir($handle);
1243        }
1244
1245        // Erases system upgrading lock if it exists.
1246        if (
1247            file_exists(
1248                InnomaticContainer::instance('innomaticcontainer')->getHome()
1249                . 'core/temp/upgrading_system_lock'
1250            )
1251        ) {
1252            if (
1253                @unlink(
1254                    InnomaticContainer::instance(
1255                        'innomaticcontainer'
1256                    )->getHome()
1257                    . 'core/temp/upgrading_system_lock'
1258                )
1259            ) {
1260                require_once('innomatic/logging/Logger.php');
1261                $tmpLog = InnomaticContainer::instance(
1262                    'innomaticcontainer'
1263                )->getLogger();
1264                $tmpLog->logEvent(
1265                    'Innomatic',
1266                    'Innomatic has been unlocked.',
1267                    Logger::NOTICE
1268                );
1269
1270                $message = 'System unlocked.';
1271            } else {
1272                $message = 'Unable to unlock system.';
1273            }
1274        } else {
1275            $message = 'System was not locked.';
1276        }
1277
1278        $this->abort($message);
1279    }
1280
1281    public function setBaseUrl($url)
1282    {
1283        $this->_baseUrl = $url;
1284    }
1285
1286    public function getBaseUrl($addController = true, $addHostname = false)
1287    {
1288        if ($addHostname) {
1289            $port = WebAppContainer::instance(
1290                'webappcontainer'
1291            )->getProcessor()->getRequest()->getServerPort();
1292
1293            if (!strlen($port) or $port == 80) {
1294                $port = '';
1295            } else {
1296                $port = ':' . $port;
1297            }
1298        }
1299
1300        return (
1301            $addHostname ? WebAppContainer::instance(
1302                'webappcontainer'
1303            )->getProcessor()->getRequest()->getScheme()
1304            . '://' . WebAppContainer::instance(
1305                'webappcontainer'
1306            )->getProcessor()->getRequest()->getServerName().$port : ''
1307        )
1308        . ( $addController ? $this->_baseUrl : (
1309            WebAppContainer::instance(
1310                'webappcontainer'
1311            )->getProcessor()->getRequest()->isUrlRewriteOn() ? $this->_baseUrl
1312            : substr($this->_baseUrl, 0, -10)
1313        ));
1314    }
1315
1316    /**
1317     * Gets the Innomatic webapp base URL, similar to the Domain webapp URL
1318     * field. Since the innomatic webapp lacks the Domain webapp URL field and
1319     * the getBaseUrl() method determines the URL assuming that the active
1320     * webapp is innomatic itself, this method has been added in order to
1321     * obtain the innomatic webapp public URL.
1322     *
1323     * The base URL is automatically discovered during Innomatic setup and is
1324     * stored inside innomatic.ini configuration file in InnomaticBaseUrl key.
1325     *
1326     * @return string
1327     */
1328    public function getExternalBaseUrl()
1329    {
1330        // If already set, returns it.
1331        if (!empty($this->_externalBaseUrl)) {
1332            return $this->_externalBaseUrl;
1333        }
1334
1335        // Not already set, so reads it from the configuration file.
1336        $this->_externalBaseUrl = $this->_config->value('InnomaticBaseUrl');
1337
1338        // Should be empty only during setup phase.
1339        if (empty($this->_externalBaseUrl)) {
1340            $this->_externalBaseUrl = WebAppContainer::instance(
1341                'webappcontainer'
1342            )->getProcessor()->getRequest()->getRequestURL();
1343            // Checks if the URL contains the setup layout frames names
1344            // and strips them away.
1345            switch(substr($this->_externalBaseUrl, -5)) {
1346                case '/main':
1347                    // break was intentionally omitted
1348                case '/logo':
1349                    // break was intentionally omitted
1350                case '/menu':
1351                    $this->_externalBaseUrl = substr(
1352                        $this->_externalBaseUrl, 0, -4
1353                    );
1354                    break;
1355            }
1356        }
1357        return $this->_externalBaseUrl;
1358    }
1359
1360    public static function setRootPassword($oldPassword, $newPassword)
1361    {
1362        $result = false;
1363
1364        $fh = @fopen(
1365            InnomaticContainer::instance('innomaticcontainer')->getHome()
1366            . 'core/conf/rootpasswd.ini',
1367            'r'
1368        );
1369        if ($fh) {
1370            $cpassword = fgets($fh, 4096);
1371            fclose($fh);
1372        }
1373
1374        if (md5($oldPassword) == $cpassword) {
1375            if (strlen($newPassword)) {
1376                $fh = @fopen(
1377                    InnomaticContainer::instance(
1378                        'innomaticcontainer'
1379                    )->getHome()
1380                    . 'core/conf/rootpasswd.ini',
1381                    'w'
1382                );
1383                if ($fh) {
1384                    require_once('innomatic/logging/Logger.php');
1385                    $log = InnomaticContainer::instance(
1386                        'innomaticcontainer'
1387                    )->getLogger();
1388
1389                    fputs($fh, md5($newPassword));
1390                    fclose($fh);
1391                    $result = true;
1392
1393                    $log->logEvent(
1394                        'Innomatic',
1395                        'Changed Innomatic root password',
1396                        Logger::NOTICE
1397                    );
1398                } else {
1399                    $result = InnomaticContainer::SETROOTPASSWORD_UNABLE_TO_WRITE_NEW_PASSWORD;
1400                }
1401            } else {
1402                $result = InnomaticContainer::SETROOTPASSWORD_NEW_PASSWORD_IS_EMPTY;
1403            }
1404        } else {
1405            $result = InnomaticContainer::SETROOTPASSWORD_OLD_PASSWORD_IS_WRONG;
1406        }
1407
1408        return $result;
1409    }
1410
1411    public static function getRootWuiMenuDefinition($localeLang)
1412    {
1413        require_once('innomatic/locale/LocaleCatalog.php');
1414        require_once('innomatic/wui/dispatch/WuiEventsCall.php');
1415        $shLoc = new LocaleCatalog('innomatic::sharedmenu', $localeLang);
1416
1417        $result =
1418            '.|' . $shLoc->getStr('domains.menu') . "\n".
1419            '..|' . $shLoc->getStr('domainslist.menu') . '|'
1420            . WuiEventsCall::buildEventsCallString(
1421                'domains', array( array('view', 'default'))
1422            ) . "\n".
1423            '..|' . $shLoc->getStr('newdomain.menu') . '|'
1424            . WuiEventsCall::buildEventsCallString(
1425                'domains', array( array('view', 'newdomain'))
1426            ) . "\n".
1427
1428            '.|' . $shLoc->getStr('applications.menu') . "\n".
1429            '..|' . $shLoc->getStr('applicationslist.menu') . '|'
1430            . WuiEventsCall::buildEventsCallString(
1431                'applications', array( array('view', 'default'))
1432            ) . "\n".
1433            '..|' . $shLoc->getStr('appcentral.menu') . '|'
1434            . WuiEventsCall::buildEventsCallString(
1435                'applications', array( array('view', 'appcentral'))
1436            ) . "\n".
1437            '..|' . $shLoc->getStr('keyring.menu') . '|'
1438            . WuiEventsCall::buildEventsCallString(
1439                'applications', array( array('view', 'keyring'))
1440            ) . "\n".
1441
1442            '.|' . $shLoc->getStr('webservices.menu') . "\n".
1443            '..|' . $shLoc->getStr('webservicesprofiles.menu') . '|'
1444            . WuiEventsCall::buildEventsCallString(
1445                'webservices', array( array('view', 'default'))
1446            ) . "\n".
1447            '..|' . $shLoc->getStr('newwebservicesprofile.menu') . '|'
1448            . WuiEventsCall::buildEventsCallString(
1449                'webservices', array( array('view', 'newprofile'))
1450            ) . "\n".
1451            '..|' . $shLoc->getStr('webservicesusers.menu') . '|'
1452            . WuiEventsCall::buildEventsCallString(
1453                'webservices', array( array('view', 'users'))
1454            ) . "\n".
1455            '..|' . $shLoc->getStr('newwebservicesuser.menu') . '|'
1456            . WuiEventsCall::buildEventsCallString(
1457                'webservices', array( array('view', 'newuser'))
1458            ) . "\n".
1459            '..|' . $shLoc->getStr('webservicesaccounts.menu') . '|'
1460            . WuiEventsCall::buildEventsCallString(
1461                'webservices', array( array('view', 'accounts'))
1462            ) . "\n".
1463            '..|' . $shLoc->getStr('newwebservicesaccount.menu') . '|'
1464            . WuiEventsCall::buildEventsCallString(
1465                'webservices', array( array('view', 'newaccount'))
1466            ) . "\n".
1467
1468            '.|' . $shLoc->getStr('settings.menu') . "\n".
1469            '..|' . $shLoc->getStr('interface.menu') . '|'
1470            . WuiEventsCall::buildEventsCallString(
1471                'interface', array( array('view', 'default'))
1472           

Large files files are truncated, but you can click here to view the full file