예제 #1
0
/**
 * @param string $str
 */
function error($str)
{
    Errors::error($str);
}
예제 #2
0
파일: SQL.php 프로젝트: neTpyceB/TMCms-core
 /**
  * @param string $user
  * @param string $pass
  * @param string $host
  * @param string $db
  * @param bool $local
  * @return PDO
  */
 public function connect($user = NULL, $pass = NULL, $host = NULL, $db = NULL, $local = true)
 {
     $conn_data = Configuration::getInstance()->get('db');
     if (!$user) {
         $user = $conn_data['login'];
     }
     if (!$pass) {
         $pass = $conn_data['password'];
     }
     if (!$db) {
         $db = $conn_data['name'];
     }
     if (!$host && isset($conn_data['host'])) {
         $host = $conn_data['host'];
         if (!$host) {
             $host = CFG_DB_SERVER;
         }
     }
     // Connect as usual
     $delay = CFG_DB_CONNECT_DELAY;
     $i = 0;
     $connected = false;
     while ($i < CFG_DB_MAX_CONNECT_ATTEMPTS && !$connected) {
         try {
             $this->pdo_db = new PDO('mysql:dbname=' . $db . ';host=' . $host, $user, $pass, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8"']);
             $connected = true;
         } catch (Exception $e) {
             usleep($delay);
             $delay *= 2;
         }
         $i++;
     }
     // Open socket connection to verify that the server is down
     if (!$connected && $local) {
         $dbh = explode(':', CFG_DB_SERVER);
         if (isset($dbh[1]) && ctype_digit($dbh[1])) {
             $host = $dbh[0];
             $port = (int) $dbh[1];
         } else {
             $host = CFG_DB_SERVER;
             $port = 3306;
         }
         $fs = @fsockopen($host, $port, $number, $message, 1);
         // If server down
         if ($fs === false) {
             if (CFG_MAIL_ERRORS) {
                 Errors::notify_devs(CFG_DOMAIN . ' DB Server is down or overloaded', 'It seems that DB Server is down or overloaded and does not respond to attempts to establish the connection.', 'admin.notification.file.dbsdown');
             }
             exit('Could not connect to database server.<br><br>Administrator is' . (CFG_MAIL_ERRORS ? '' : ' NOT') . ' notified.');
         } else {
             // If server is ok, but connection refused
             fclose($fs);
             if (CFG_MAIL_ERRORS) {
                 Errors::notify_devs(CFG_DOMAIN . ' DB Server is not accessible', 'It seems that login or password is supplied incorrectly in configuration file "config.php"', 'admin.notification.file.dbsaccess');
             }
             exit('Could not login to database server.<br><br>Administrator is' . (CFG_MAIL_ERRORS ? '' : ' NOT') . ' notified.');
         }
     }
     return $this->pdo_db;
 }
예제 #3
0
<?php

use TMCms\DB\SQL;
use TMCms\Log\Errors;
if (!defined('INC')) {
    define('INC', true);
}
if (!defined('MODE')) {
    define('MODE', 'site');
}
if (stripos(USER_AGENT, 'bot') !== false) {
    return;
}
$msg = isset($_GET['msg']) ? $_GET['msg'] : '';
$stack = isset($_GET['stack']) ? $_GET['stack'] : '';
$url = isset($_GET['url']) ? $_GET['url'] : '';
$line = isset($_GET['line']) ? $_GET['line'] : '';
Errors::notify_devs(CFG_DOMAIN . ' JavaScript error', 'Message: ' . $msg . "\nClicks Stack: " . $stack . "\nURL: " . $url . "\nLine: " . $line);
// Write log if DB available
if (!SQL::getInstance()->getConnectionHandler()) {
    return;
}
q('INSERT INTO `cms_error_log` (
    `ts`, `ip_long`, `agent`,
    `type`, `msg`, `file`,
    `line`, `vars`
) VALUES (
    "' . NOW . '", "' . ip2long(IP) . '", "' . USER_AGENT . '",
    "JS", "' . sql_prepare($msg) . '", "' . sql_prepare($url) . '",
    "' . sql_prepare($line) . '", "' . sql_prepare($stack) . '"
)');