Пример #1
0
 /**
  * Write system templayes
  */
 public function _writeSystemTemplates()
 {
     require_once IPS_ROOT_PATH . 'sources/classes/output/systemTemplates.php';
     /*noLibHook*/
     $systemTemplates = new systemTemplates();
     $systemTemplates->writeDefaults();
     $this->registry->output->addMessage("Запись шаблонов системы...");
     $this->request['workact'] = '';
 }
Пример #2
0
    /**
     * Prints SQL error message
     *
     * @param	string		Additional error message
     * @return	@e mixed
     */
    public function throwFatalError($the_error = '')
    {
        //-----------------------------------------
        // INIT
        //-----------------------------------------
        $this->error = $this->_getErrorString();
        $this->error_no = $this->_getErrorNumber();
        $errTemplate = 'ipsDriverError';
        $nonIPSErrors = array('1012-1021', '1023-1027', '1030-1031', '1034-1043', '1129-1131', '1150-1153', 1194, 1195, '1203-1207');
        /* MySQL: Is this non IPS error? */
        if ($this->usingClass == 'db_driver_mysql') {
            if (stristr($this->error, 'has gone away') or stristr($this->error, 'connect to local mysql server through socket')) {
                $errTemplate = 'ipsServerError';
            } else {
                if ($this->error_no) {
                    foreach ($nonIPSErrors as $id) {
                        if (strstr($id, '-')) {
                            list($a, $b) = explode('-', $id);
                            if ($a and $b) {
                                if ($this->error_no >= $a and $this->error_no <= $b) {
                                    $errTemplate = 'ipsServerError';
                                }
                            }
                        } else {
                            if ($this->error_no == intval($id)) {
                                $errTemplate = 'ipsServerError';
                            }
                        }
                    }
                }
            }
        }
        /* Fetch debug information */
        $_debug = debug_backtrace();
        $_dString = '';
        if (is_array($_debug) and count($_debug)) {
            foreach ($_debug as $idx => $data) {
                /* Remove non-essential items */
                if ($data['class'] == 'dbMain' or $data['class'] == 'ips_DBRegistry' or $data['class'] == 'ipsRegistry' or $data['class'] == 'ipsController' or $data['class'] == 'ipsCommand' or $data['class'] == 'db_driver_mysql') {
                    continue;
                }
                $_dbString[$idx] = array('file' => $data['file'], 'line' => $data['line'], 'function' => $data['function'], 'class' => $data['class']);
            }
        }
        $_error_string = "\n ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
        $_error_string .= "\n Date: " . date('r');
        $_error_string .= "\n Error: " . $this->error_no . ' - ' . $this->error;
        $_error_string .= "\n IP Address: " . $_SERVER['REMOTE_ADDR'] . ' - ' . $_SERVER['REQUEST_URI'];
        $_error_string .= "\n ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
        $_error_string .= "\n " . $the_error;
        $_error_string .= "\n .--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.";
        if (count($_dbString)) {
            $_error_string .= "\n | File                                                                       | Function                                                                      | Line No.          |";
            $_error_string .= "\n |----------------------------------------------------------------------------+-------------------------------------------------------------------------------+-------------------|";
            foreach ($_dbString as $i => $data) {
                if (defined('DOC_IPS_ROOT_PATH')) {
                    $data['file'] = str_replace(DOC_IPS_ROOT_PATH, '', $data['file']);
                }
                /* Reset */
                $data['func'] = "[" . $data['class'] . '].' . $data['function'];
                /* Pad right */
                $data['file'] = str_pad($data['file'], 75);
                $data['func'] = str_pad($data['func'], 78);
                $data['line'] = str_pad($data['line'], 18);
                $_error_string .= "\n | " . $data['file'] . "| " . $data['func'] . '| ' . $data['line'] . '|';
                $_error_string .= "\n '----------------------------------------------------------------------------+-------------------------------------------------------------------------------+-------------------'";
            }
        }
        if ($this->return_die == true) {
            $this->error = $this->error == "" ? $the_error : $this->error;
            $this->failed = true;
            return;
        } else {
            if ($this->obj['use_error_log'] and $this->obj['error_log']) {
                if ($FH = @fopen($this->obj['error_log'], 'a')) {
                    @fwrite($FH, $_error_string);
                    @fclose($FH);
                }
                /* Write to latest log also */
                if (is_dir(IPS_CACHE_PATH . 'cache')) {
                    @file_put_contents(IPS_CACHE_PATH . 'cache/sql_error_latest.cgi', trim($_error_string));
                } else {
                    if (is_dir(DOC_IPS_ROOT_PATH . 'cache')) {
                        @file_put_contents(DOC_IPS_ROOT_PATH . 'cache/sql_error_latest.cgi', trim($_error_string));
                    }
                }
                if (isset($_SERVER['SERVER_PROTOCOL']) and strstr($_SERVER['SERVER_PROTOCOL'], '/1.0')) {
                    @header("HTTP/1.0 503 Service Unavailable");
                } else {
                    @header("HTTP/1.1 503 Service Unavailable");
                }
                if ($this->use_template) {
                    require_once IPS_ROOT_PATH . 'sources/classes/output/systemTemplates.php';
                    $systemTemplates = new systemTemplates();
                    $template = $systemTemplates->getClass($errTemplate);
                    $errorBlock = '';
                    if ($errTemplate == 'ipsServerError' and $the_error) {
                        $_errorMessage = htmlspecialchars($the_error);
                        $errorBlock = <<<EOF
\t\t\t\t\t<div class='database-error'>
\t\t\t\t    \t<form name='mysql'>
\t\t\t\t    \t\t<textarea rows="15" cols="60">{$the_error}</textarea>
\t\t\t\t    \t</form>
\t\t\t    \t</div>
EOF;
                    }
                    print $template->getTemplate($_SERVER['HTTP_HOST'], nl2br(trim($the_error)), $errorBlock);
                } else {
                    print "<html><head><title>Ошибка базы данных</title>\n\t\t\t\t\t\t<style>P,BODY{ font-family:arial,sans-serif; font-size:11px; }</style></head><body>\n\t\t\t    \t\t   <blockquote><h1>IPS Driver Error</h1><b>There appears to be an error with the database.</b><br>\n\t\t\t    \t\t   You can try to refresh the page by clicking <a href=\"javascript:window.location=window.location;\">here</a>\n\t\t\t\t\t  </body></html>";
                }
            } else {
                $the_error .= "\n\nSQL error: " . $this->error . "\n";
                $the_error .= "SQL error code: " . $this->error_no . "\n";
                $the_error .= "Date: " . date("l dS F Y h:i:s A");
                $the_error .= "\n\n" . $_error_string;
                if (isset($_SERVER['SERVER_PROTOCOL']) and strstr($_SERVER['SERVER_PROTOCOL'], '/1.0')) {
                    @header("HTTP/1.0 503 Service Unavailable");
                } else {
                    @header("HTTP/1.1 503 Service Unavailable");
                }
                if ($this->use_template) {
                    require_once IPS_ROOT_PATH . 'sources/classes/output/systemTemplates.php';
                    $systemTemplates = new systemTemplates();
                    $template = $systemTemplates->getClass($errTemplate);
                    $errorBlock = '';
                    if ($the_error) {
                        $_errorMessage = htmlspecialchars($the_error);
                        $errorBlock = <<<EOF
\t\t\t\t\t<div class='database-error'>
\t\t\t\t    \t<form name='mysql'>
\t\t\t\t    \t\t<textarea rows="15" cols="60">{$the_error}</textarea>
\t\t\t\t    \t</form>
\t\t\t    \t</div>
EOF;
                    }
                    print $template->getTemplate($_SERVER['HTTP_HOST'], nl2br(trim($the_error)), $errorBlock, ipsRegistry::$settings);
                } else {
                    print "<html><head><title>IPS Driver Error</title>\n\t\t    \t\t   <style>P,BODY{ font-family:arial,sans-serif; font-size:11px; }</style></head><body>\n\t\t    \t\t   <blockquote><h1>IPS Driver Error</h1><b>There appears to be an error with the database.</b><br>\n\t\t    \t\t   You can try to refresh the page by clicking <a href=\"javascript:window.location=window.location;\">here</a>.\n\t\t    \t\t   <br><br><b>Error Returned</b><br>\n\t\t    \t\t   <form name='mysql'><textarea rows=\"15\" cols=\"60\">" . htmlspecialchars($the_error) . "</textarea></form><br>We apologise for any inconvenience</blockquote></body></html>";
                }
            }
        }
        //-----------------------------------------
        // Need to clear this for shutdown queries
        //-----------------------------------------
        $this->cur_query = '';
        exit;
    }
Пример #3
0
 /**
  * Installs SQL schematic
  *
  * @return void
  */
 public function install_sql()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $previous = $_REQUEST['previous'];
     $skip = $_REQUEST['_skip'];
     //-----------------------------------------
     // Write config
     //-----------------------------------------
     if (!$previous and !$skip) {
         /* Write Configuration Files */
         $output[] = 'Запись файлов конфигурации<br />';
         $test = IPSInstall::writeConfiguration();
         //-----------------------------------
         // Check that it wrote
         //-----------------------------------
         if (!is_file(IPSSetUp::getSavedData('install_dir') . '/conf_global.php')) {
             $this->registry->output->setTitle("Установка: Ошибка");
             $this->registry->output->setNextAction('install&do=sql');
             $this->registry->output->setHideButton(TRUE);
             $this->registry->output->addError("Невозможна запись конфигурации в файл conf_global.php.  Пожалуйста, убедитесь, что файл имеет полный доступ на чтение и запись.");
             $this->registry->output->addContent("");
             $this->registry->output->sendOutput();
             exit;
         } else {
             $INFO = array();
             require IPSSetUp::getSavedData('install_dir') . '/conf_global.php';
             /*noLibHook*/
             if (!$INFO['sql_driver']) {
                 $this->registry->output->setTitle("Установка: Ошибка");
                 $this->registry->output->setNextAction('install&do=sql');
                 $this->registry->output->setHideButton(TRUE);
                 $this->registry->output->addError("Невозможна запись конфигурации в файл conf_global.php.  Пожалуйста, убедитесь, что файл имеет полный доступ на чтение и запись.");
                 $this->registry->output->addContent("");
                 $this->registry->output->sendOutput();
                 exit;
             }
         }
     }
     /* Set up DB driver */
     $extra_install = $this->_setUpDBDriver(FALSE);
     //-----------------------------------------
     // Import System Templates
     // We have to do this here un case we counter a driver error
     //-----------------------------------------
     require_once IPS_ROOT_PATH . 'sources/classes/output/systemTemplates.php';
     /*noLibHook*/
     $systemTemplates = new systemTemplates();
     $systemTemplates->writeDefaults();
     //-----------------------------------------
     // Fetch next 'un
     //-----------------------------------------
     $next = IPSSetUp::fetchNextApplication($previous, '', $this->settings['gb_char_set']);
     if ($next['key']) {
         //-----------------------------------------
         // INIT
         //-----------------------------------------
         $_PATH = IPSLib::getAppDir($next['key']) . '/setup/versions/install/sql/';
         $_FILE = $_PATH . $next['key'] . '_' . strtolower(IPSSetUp::getSavedData('sql_driver'));
         //-----------------------------------------
         // Tables
         //-----------------------------------------
         if (is_file($_FILE . '_tables.php')) {
             $TABLE = array();
             include $_FILE . '_tables.php';
             /*noLibHook*/
             if (is_array($TABLE) and count($TABLE)) {
                 $output[] = $next['title'] . ": Создание таблиц";
                 foreach ($TABLE as $q) {
                     preg_match("/CREATE TABLE (\\S+)(\\s)?\\(/", $q, $match);
                     if ($match[1]) {
                         $this->DB->dropTable(str_replace(IPSSetUp::getSavedData('db_pre'), '', $match[1]));
                     }
                     if ($extra_install and method_exists($extra_install, 'process_query_create')) {
                         $q = $extra_install->process_query_create($q);
                     }
                     $this->DB->allow_sub_select = 1;
                     $this->DB->error = '';
                     $this->DB->query($q);
                     if ($this->DB->error) {
                         $this->registry->output->addError(nl2br($q) . "<br /><br />" . $this->DB->error);
                     }
                 }
             }
         }
         //---------------------------------------------
         // Create the fulltext index...
         //---------------------------------------------
         if ($this->DB->checkFulltextSupport()) {
             if (is_file($_FILE . '_fulltext.php')) {
                 $INDEX = array();
                 include $_FILE . '_fulltext.php';
                 /*noLibHook*/
                 if (is_array($INDEX) and count($INDEX)) {
                     $output[] = $next['title'] . ": Создание индексов";
                     foreach ($INDEX as $q) {
                         //---------------------------------------------
                         // Pass to handler
                         //---------------------------------------------
                         if ($extra_install and method_exists($extra_install, 'process_query_index')) {
                             $q = $extra_install->process_query_index($q);
                         }
                         //---------------------------------------------
                         // Pass query
                         //---------------------------------------------
                         $this->DB->allow_sub_select = 1;
                         $this->DB->error = '';
                         $this->DB->query($q);
                         if ($this->DB->error) {
                             $this->registry->output->addError(nl2br($q) . "<br /><br />" . $this->DB->error);
                         }
                     }
                 }
             }
         }
         //-----------------------------------------
         // INSERTS
         //-----------------------------------------
         if (is_file($_FILE . '_inserts.php')) {
             $INSERT = array();
             include $_FILE . '_inserts.php';
             /*noLibHook*/
             if (is_array($INSERT) && count($INSERT)) {
                 $output[] = $next['title'] . ": Наполнение таблиц";
                 foreach ($INSERT as $q) {
                     $q = str_replace("<%time%>", time(), $q);
                     $q = str_replace('<%admin_name%>', IPSSetUp::getSavedData('admin_user'), $q);
                     $q = str_replace('<%admin_seoname%>', IPSText::makeSeoTitle(IPSSetUp::getSavedData('admin_user')), $q);
                     //---------------------------------------------
                     // Pass to handler
                     //---------------------------------------------
                     if ($extra_install and method_exists($extra_install, 'process_query_insert')) {
                         $q = $extra_install->process_query_insert($q);
                     }
                     $this->DB->allow_sub_select = 1;
                     $this->DB->error = '';
                     $this->DB->query($q);
                     if ($this->DB->error) {
                         $this->registry->output->addError(nl2br($q) . "<br /><br />" . $this->DB->error);
                     }
                 }
             }
         }
         //-----------------------------------------
         // Sort out groups
         // This has to be here so the applications
         // can populate group settings appropriately
         //-----------------------------------------
         if ($next['key'] == 'core') {
             $output[] = "Добавление информации о группах...";
             $xml = new classXML(IPSSetUp::charSet);
             if ($extra_install and method_exists($extra_install, 'before_inserts_run')) {
                 $q = $extra_install->before_inserts_run('groups');
             }
             $xml->load(IPS_ROOT_PATH . 'setup/xml/groups.xml');
             foreach ($xml->fetchElements('row') as $xmlelement) {
                 $data = $xml->fetchElementsFromRecord($xmlelement);
                 $this->DB->insert('groups', $data);
             }
             if ($extra_install and method_exists($extra_install, 'after_inserts_run')) {
                 $q = $extra_install->after_inserts_run('groups');
             }
         }
         //-----------------------------------------
         // Done.. so get some more!
         //-----------------------------------------
         $output = (is_array($output) and count($output)) ? $output : array(0 => $next['title'] . ": Наполнение таблиц завершено");
         $this->_finishStep($output, "Установка: SQL", 'install&do=sql&previous=' . $next['key']);
     } else {
         //-----------------------------------------
         // NO MORE TO INSTALL
         //-----------------------------------------
         $output[] = "Действия SQL завершены";
         IPSInstall::createAdminAccount();
         //-----------------------------------------
         // Next...
         //-----------------------------------------
         $output = (is_array($output) and count($output)) ? $output : array(0 => $next['title'] . ": Наполнение таблиц завершено");
         $this->_finishStep($output, "Установка: SQL", 'install&do=sql_steps');
     }
 }
Пример #4
0
 /**
  * Add <html> tags and such if it doesn't have any already
  *
  * @param	string	Subject
  * @param	string	HTML email
  * @return	string	VERY HTML email
  */
 public function applyHtmlWrapper($subject, $content)
 {
     $unsubscribe = '';
     if ($this->unsubscribe) {
         $unsubscribe = " &middot; <#UNSUBSCRIBE#>";
     }
     /* Due to some legacy methods with mail queue, buildMessage can be called twice
      * for good reason, but it can then re-apply the wrapper. So we add a unique comment
      * and then check for this.
      */
     if (!stristr($content, '<!--ipb.wrapper.added-->')) {
         $content = '<!--ipb.wrapper.added-->' . $content;
         /* Inline wrapper */
         if ($this->htmlWrapper) {
             return str_ireplace('<#content#>', $content, $this->htmlWrapper);
         }
         /* Attempt to load external wrapper */
         if (!is_object($this->_loadedHtmlTemplateClass)) {
             if (!is_file(IPS_CACHE_PATH . 'cache/skin_cache/system/emailWrapper.php')) {
                 require_once IPS_ROOT_PATH . 'sources/classes/output/systemTemplates.php';
                 $systemTemplates = new systemTemplates();
                 $systemTemplates->writeDefaults();
             }
             /* Still nothing? */
             if (!is_file(IPS_CACHE_PATH . 'cache/skin_cache/system/emailWrapper.php')) {
                 /* Still here? Fail safe */
                 return $this->parseWithDefaultHtmlWrapper($content);
             }
             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/output/systemTemplates.php', 'systemTemplates');
             $systemTemplates = new $classToLoad();
             $this->_loadedHtmlTemplateClass = $systemTemplates->getClass('emailWrapper');
         }
         return $this->_loadedHtmlTemplateClass->getTemplate($content, $unsubscribe, ipsRegistry::$settings);
     }
     return $content;
 }