relocate index and db
This commit is contained in:
parent
29ba891809
commit
84ba6393ad
@ -82,11 +82,11 @@ class Setup extends \Zotlabs\Web\Controller {
|
|||||||
$siteurl = rtrim($siteurl,'/');
|
$siteurl = rtrim($siteurl,'/');
|
||||||
|
|
||||||
require_once('include/dba/dba_driver.php');
|
require_once('include/dba/dba_driver.php');
|
||||||
unset($db);
|
|
||||||
$db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
|
|
||||||
|
|
||||||
if(! $db->connected) {
|
$db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
|
||||||
echo 'Database Connect failed: ' . $db->error;
|
|
||||||
|
if(! \DBA::$dba->connected) {
|
||||||
|
echo 'Database Connect failed: ' . DBA::$dba->error;
|
||||||
killme();
|
killme();
|
||||||
\App::$data['db_conn_failed']=true;
|
\App::$data['db_conn_failed']=true;
|
||||||
}
|
}
|
||||||
@ -138,10 +138,12 @@ class Setup extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect to db
|
if(! \DBA::$dba->connected) {
|
||||||
$db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
|
// connect to db
|
||||||
|
$db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
|
||||||
|
}
|
||||||
|
|
||||||
if(! $db->connected) {
|
if(! \DBA::$dba->connected) {
|
||||||
echo 'CRITICAL: DB not connected.';
|
echo 'CRITICAL: DB not connected.';
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
@ -228,7 +230,7 @@ class Setup extends \Zotlabs\Web\Controller {
|
|||||||
$txt .= "<pre>".\App::$data['db_failed'] . "</pre>". EOL ;
|
$txt .= "<pre>".\App::$data['db_failed'] . "</pre>". EOL ;
|
||||||
$db_return_text .= $txt;
|
$db_return_text .= $txt;
|
||||||
}
|
}
|
||||||
if($db && $db->connected) {
|
if(\DBA::$dba && \DBA::$dba->connected) {
|
||||||
$r = q("SELECT COUNT(*) as `total` FROM `account`");
|
$r = q("SELECT COUNT(*) as `total` FROM `account`");
|
||||||
if($r && count($r) && $r[0]['total']) {
|
if($r && count($r) && $r[0]['total']) {
|
||||||
$tpl = get_markup_template('install.tpl');
|
$tpl = get_markup_template('install.tpl');
|
||||||
@ -598,7 +600,7 @@ class Setup extends \Zotlabs\Web\Controller {
|
|||||||
if(! is_writable(TEMPLATE_BUILD_PATH) ) {
|
if(! is_writable(TEMPLATE_BUILD_PATH) ) {
|
||||||
$status = false;
|
$status = false;
|
||||||
$help = t('Red uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
|
$help = t('Red uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
|
||||||
$help .= sprintf( t('In order to store these compiled templates, the web server needs to have write access to the directory %s under the Red top level folder.'), TEMPLATE_BUILD_PATH) . EOL;
|
$help .= sprintf( t('In order to store these compiled templates, the web server needs to have write access to the directory %s under the top level web folder.'), TEMPLATE_BUILD_PATH) . EOL;
|
||||||
$help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
|
$help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
|
||||||
$help .= sprintf( t('Note: as a security measure, you should give the web server write access to %s only--not the template files (.tpl) that it contains.'), TEMPLATE_BUILD_PATH) . EOL;
|
$help .= sprintf( t('Note: as a security measure, you should give the web server write access to %s only--not the template files (.tpl) that it contains.'), TEMPLATE_BUILD_PATH) . EOL;
|
||||||
}
|
}
|
||||||
@ -698,12 +700,12 @@ class Setup extends \Zotlabs\Web\Controller {
|
|||||||
|
|
||||||
|
|
||||||
function load_database($db) {
|
function load_database($db) {
|
||||||
$str = file_get_contents($db->get_install_script());
|
$str = file_get_contents(\DBA::$dba->get_install_script());
|
||||||
$arr = explode(';',$str);
|
$arr = explode(';',$str);
|
||||||
$errors = false;
|
$errors = false;
|
||||||
foreach($arr as $a) {
|
foreach($arr as $a) {
|
||||||
if(strlen(trim($a))) {
|
if(strlen(trim($a))) {
|
||||||
$r = @$db->q(trim($a));
|
$r = dbq(trim($a));
|
||||||
if(! $r) {
|
if(! $r) {
|
||||||
$errors .= t('Errors encountered creating database tables.') . $a . EOL;
|
$errors .= t('Errors encountered creating database tables.') . $a . EOL;
|
||||||
}
|
}
|
||||||
|
191
Zotlabs/Web/WebServer.php
Normal file
191
Zotlabs/Web/WebServer.php
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
<?php /** @file */
|
||||||
|
|
||||||
|
class WebServer {
|
||||||
|
|
||||||
|
public function run() {
|
||||||
|
|
||||||
|
global $db;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bootstrap the application, load configuration, load modules, load theme, etc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bootstrap the application
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once('boot.php');
|
||||||
|
|
||||||
|
if(file_exists('.htsite.php'))
|
||||||
|
include('.htsite.php');
|
||||||
|
|
||||||
|
|
||||||
|
// miniApp is a conversion object from old style .htconfig.php files
|
||||||
|
|
||||||
|
$a = new \miniApp;
|
||||||
|
|
||||||
|
// our central App object
|
||||||
|
|
||||||
|
\App::init();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Load the configuration file which contains our DB credentials.
|
||||||
|
* Ignore errors. If the file doesn't exist or is empty, we are running in
|
||||||
|
* installation mode.
|
||||||
|
*/
|
||||||
|
|
||||||
|
\App::$install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true);
|
||||||
|
|
||||||
|
@include('.htconfig.php');
|
||||||
|
|
||||||
|
if(! defined('UNO'))
|
||||||
|
define('UNO', 0);
|
||||||
|
|
||||||
|
$a->convert();
|
||||||
|
|
||||||
|
\App::$timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
|
||||||
|
date_default_timezone_set(\App::$timezone);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to open the database;
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once('include/dba/dba_driver.php');
|
||||||
|
|
||||||
|
if(! \App::$install) {
|
||||||
|
$db = DBA::dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, \App::$install);
|
||||||
|
if(! $db->connected) {
|
||||||
|
system_unavailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load configs from db. Overwrite configs from .htconfig.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
load_config('config');
|
||||||
|
load_config('system');
|
||||||
|
load_config('feature');
|
||||||
|
|
||||||
|
\App::$session = new Zotlabs\Web\Session();
|
||||||
|
\App::$session->init();
|
||||||
|
load_hooks();
|
||||||
|
call_hooks('init_1');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
\App::$language = get_best_language();
|
||||||
|
load_translation_table(\App::$language,\App::$install);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Important stuff we always need to do.
|
||||||
|
*
|
||||||
|
* The order of these may be important so use caution if you think they're all
|
||||||
|
* intertwingled with no logical order and decide to sort it out. Some of the
|
||||||
|
* dependencies have changed, but at least at one time in the recent past - the
|
||||||
|
* order was critical to everything working properly
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(\App::$session) {
|
||||||
|
\App::$session->start();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
session_start();
|
||||||
|
register_shutdown_function('session_write_close');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language was set earlier, but we can over-ride it in the session.
|
||||||
|
* We have to do it here because the session was just now opened.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(array_key_exists('system_language',$_POST)) {
|
||||||
|
if(strlen($_POST['system_language']))
|
||||||
|
$_SESSION['language'] = $_POST['system_language'];
|
||||||
|
else
|
||||||
|
unset($_SESSION['language']);
|
||||||
|
}
|
||||||
|
if((x($_SESSION, 'language')) && ($_SESSION['language'] !== $lang)) {
|
||||||
|
\App::$language = $_SESSION['language'];
|
||||||
|
load_translation_table(\App::$language);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((x($_GET,'zid')) && (! \App::$install)) {
|
||||||
|
\App::$query_string = strip_zids(\App::$query_string);
|
||||||
|
if(! local_channel()) {
|
||||||
|
$_SESSION['my_address'] = $_GET['zid'];
|
||||||
|
zid_init($a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if((x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || (\App::$module === 'login'))
|
||||||
|
require('include/auth.php');
|
||||||
|
|
||||||
|
if(! x($_SESSION, 'sysmsg'))
|
||||||
|
$_SESSION['sysmsg'] = array();
|
||||||
|
|
||||||
|
if(! x($_SESSION, 'sysmsg_info'))
|
||||||
|
$_SESSION['sysmsg_info'] = array();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check_config() is responsible for running update scripts. These automatically
|
||||||
|
* update the DB schema whenever we push a new one out. It also checks to see if
|
||||||
|
* any plugins have been added or removed and reacts accordingly.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
if(\App::$install) {
|
||||||
|
/* Allow an exception for the view module so that pcss will be interpreted during installation */
|
||||||
|
if(\App::$module != 'view')
|
||||||
|
\App::$module = 'setup';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
check_config($a);
|
||||||
|
|
||||||
|
nav_set_selected('nothing');
|
||||||
|
|
||||||
|
$Router = new Zotlabs\Web\Router($a);
|
||||||
|
|
||||||
|
/* initialise content region */
|
||||||
|
|
||||||
|
if(! x(\App::$page, 'content'))
|
||||||
|
\App::$page['content'] = '';
|
||||||
|
|
||||||
|
call_hooks('page_content_top', \App::$page['content']);
|
||||||
|
|
||||||
|
|
||||||
|
$Router->Dispatch($a);
|
||||||
|
|
||||||
|
|
||||||
|
// If you're just visiting, let javascript take you home
|
||||||
|
|
||||||
|
if(x($_SESSION, 'visitor_home')) {
|
||||||
|
$homebase = $_SESSION['visitor_home'];
|
||||||
|
} elseif(local_channel()) {
|
||||||
|
$homebase = z_root() . '/channel/' . \App::$channel['channel_address'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($homebase)) {
|
||||||
|
\App::$page['content'] .= '<script>var homebase = "' . $homebase . '";</script>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// now that we've been through the module content, see if the page reported
|
||||||
|
// a permission problem and if so, a 403 response would seem to be in order.
|
||||||
|
|
||||||
|
if(stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) {
|
||||||
|
header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
call_hooks('page_end', \App::$page['content']);
|
||||||
|
|
||||||
|
construct_page($a);
|
||||||
|
|
||||||
|
killme();
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ function cli_startup() {
|
|||||||
|
|
||||||
App::init();
|
App::init();
|
||||||
|
|
||||||
if(is_null($db)) {
|
if(! DBA::$connected) {
|
||||||
@include(".htconfig.php");
|
@include(".htconfig.php");
|
||||||
|
|
||||||
$a->convert();
|
$a->convert();
|
||||||
@ -26,7 +26,7 @@ function cli_startup() {
|
|||||||
date_default_timezone_set(App::$timezone);
|
date_default_timezone_set(App::$timezone);
|
||||||
|
|
||||||
require_once('include/dba/dba_driver.php');
|
require_once('include/dba/dba_driver.php');
|
||||||
$db = dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
|
$db = DBA::dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
|
||||||
unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
|
unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
class DBA {
|
||||||
/**
|
/**
|
||||||
* @file dba_driver.php
|
* @file dba_driver.php
|
||||||
* @brief some database related functions and abstract driver class.
|
* @brief some database related functions and abstract driver class.
|
||||||
@ -7,6 +9,10 @@
|
|||||||
* functions for working with databases.
|
* functions for working with databases.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static public $dba = null;
|
||||||
|
static public $dbtype = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the database driver object.
|
* @brief Returns the database driver object.
|
||||||
*
|
*
|
||||||
@ -21,27 +27,28 @@
|
|||||||
* @param bool $install Defaults to false
|
* @param bool $install Defaults to false
|
||||||
* @return null|dba_driver A database driver object (dba_mysql|dba_mysqli) or null if no driver found.
|
* @return null|dba_driver A database driver object (dba_mysql|dba_mysqli) or null if no driver found.
|
||||||
*/
|
*/
|
||||||
function dba_factory($server, $port,$user,$pass,$db,$dbtype,$install = false) {
|
static public function dba_factory($server, $port,$user,$pass,$db,$dbtype,$install = false) {
|
||||||
$dba = null;
|
|
||||||
|
|
||||||
$dbtype = intval($dbtype);
|
self::$dba = null;
|
||||||
|
|
||||||
|
self::$dbtype = intval($dbtype);
|
||||||
$set_port = $port;
|
$set_port = $port;
|
||||||
|
|
||||||
if($dbtype == DBTYPE_POSTGRES) {
|
if(self::$dbtype == DBTYPE_POSTGRES) {
|
||||||
require_once('include/dba/dba_postgres.php');
|
require_once('include/dba/dba_postgres.php');
|
||||||
if(is_null($port)) $set_port = 5432;
|
if(is_null($port)) $set_port = 5432;
|
||||||
$dba = new dba_postgres($server, $set_port, $user, $pass, $db, $install);
|
self::$dba = new dba_postgres($server, $set_port, $user, $pass, $db, $install);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Highly experimental at the present time.
|
// Highly experimental at the present time.
|
||||||
// require_once('include/dba/dba_pdo.php');
|
// require_once('include/dba/dba_pdo.php');
|
||||||
// $dba = new dba_pdo($server, $set_port,$user,$pass,$db,$install);
|
// self::$dba = new dba_pdo($server, $set_port,$user,$pass,$db,$install);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if(class_exists('mysqli')) {
|
if(class_exists('mysqli')) {
|
||||||
if (is_null($port)) $set_port = ini_get("mysqli.default_port");
|
if (is_null($port)) $set_port = ini_get("mysqli.default_port");
|
||||||
require_once('include/dba/dba_mysqli.php');
|
require_once('include/dba/dba_mysqli.php');
|
||||||
$dba = new dba_mysqli($server, $set_port,$user,$pass,$db,$install);
|
self::$dba = new dba_mysqli($server, $set_port,$user,$pass,$db,$install);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,16 +58,18 @@ function dba_factory($server, $port,$user,$pass,$db,$dbtype,$install = false) {
|
|||||||
// third-party interfaces that are working and well tested.
|
// third-party interfaces that are working and well tested.
|
||||||
|
|
||||||
|
|
||||||
if(is_object($dba) && $dba->connected) {
|
if(is_object(self::$dba) && self::$dba->connected) {
|
||||||
$dns = (($dbtype == DBTYPE_POSTGRES) ? 'postgres' : 'mysql')
|
$dns = ((self::$dbtype == DBTYPE_POSTGRES) ? 'postgres' : 'mysql')
|
||||||
. ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
|
. ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
|
||||||
. ';dbname=' . $db;
|
. ';dbname=' . $db;
|
||||||
$dba->pdo_set(array($dns,$user,$pass));
|
self::$dba->pdo_set(array($dns,$user,$pass));
|
||||||
}
|
}
|
||||||
|
|
||||||
define('NULL_DATE', $dba->get_null_date());
|
define('NULL_DATE', self::$dba->get_null_date());
|
||||||
define('ACTIVE_DBTYPE', $dbtype);
|
define('ACTIVE_DBTYPE', self::$dbtype);
|
||||||
return $dba;
|
return self::$dba;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,8 +241,8 @@ function printable($s) {
|
|||||||
function dbg($state) {
|
function dbg($state) {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
if($db)
|
if(\DBA::$dba)
|
||||||
$db->dbg($state);
|
\DBA::$dba->dbg($state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -249,19 +258,19 @@ function dbg($state) {
|
|||||||
function dbesc($str) {
|
function dbesc($str) {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
if($db && $db->connected)
|
if(\DBA::$dba && \DBA::$dba->connected)
|
||||||
return($db->escape($str));
|
return(\DBA::$dba->escape($str));
|
||||||
else
|
else
|
||||||
return(str_replace("'", "\\'", $str));
|
return(str_replace("'", "\\'", $str));
|
||||||
}
|
}
|
||||||
function dbescbin($str) {
|
function dbescbin($str) {
|
||||||
global $db;
|
global $db;
|
||||||
return $db->escapebin($str);
|
return \DBA::$dba->escapebin($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dbunescbin($str) {
|
function dbunescbin($str) {
|
||||||
global $db;
|
global $db;
|
||||||
return $db->unescapebin($str);
|
return \DBA::$dba->unescapebin($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dbescdate($date) {
|
function dbescdate($date) {
|
||||||
@ -275,27 +284,27 @@ function dbescdate($date) {
|
|||||||
|
|
||||||
function db_quoteinterval($txt) {
|
function db_quoteinterval($txt) {
|
||||||
global $db;
|
global $db;
|
||||||
return $db->quote_interval($txt);
|
return \DBA::$dba->quote_interval($txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dbesc_identifier($str) {
|
function dbesc_identifier($str) {
|
||||||
global $db;
|
global $db;
|
||||||
return $db->escape_identifier($str);
|
return \DBA::$dba->escape_identifier($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function db_utcnow() {
|
function db_utcnow() {
|
||||||
global $db;
|
global $db;
|
||||||
return $db->utcnow();
|
return \DBA::$dba->utcnow();
|
||||||
}
|
}
|
||||||
|
|
||||||
function db_optimizetable($table) {
|
function db_optimizetable($table) {
|
||||||
global $db;
|
global $db;
|
||||||
$db->optimize_table($table);
|
\DBA::$dba->optimize_table($table);
|
||||||
}
|
}
|
||||||
|
|
||||||
function db_concat($fld, $sep) {
|
function db_concat($fld, $sep) {
|
||||||
global $db;
|
global $db;
|
||||||
return $db->concat($fld, $sep);
|
return \DBA::$dba->concat($fld, $sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function: q($sql,$args);
|
// Function: q($sql,$args);
|
||||||
@ -325,7 +334,7 @@ function q($sql) {
|
|||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
unset($args[0]);
|
unset($args[0]);
|
||||||
|
|
||||||
if($db && $db->connected) {
|
if(\DBA::$dba && \DBA::$dba->connected) {
|
||||||
$stmt = vsprintf($sql, $args);
|
$stmt = vsprintf($sql, $args);
|
||||||
if($stmt === false) {
|
if($stmt === false) {
|
||||||
if(version_compare(PHP_VERSION, '5.4.0') >= 0)
|
if(version_compare(PHP_VERSION, '5.4.0') >= 0)
|
||||||
@ -356,8 +365,8 @@ function q($sql) {
|
|||||||
function dbq($sql) {
|
function dbq($sql) {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
if($db && $db->connected)
|
if(\DBA::$dba && \DBA::$dba->connected)
|
||||||
$ret = $db->q($sql);
|
$ret = \DBA::$dba->q($sql);
|
||||||
else
|
else
|
||||||
$ret = false;
|
$ret = false;
|
||||||
|
|
||||||
@ -423,8 +432,8 @@ function db_getfunc($f) {
|
|||||||
|
|
||||||
function db_logger($s,$level = LOGGER_NORMAL,$syslog = LOG_INFO) {
|
function db_logger($s,$level = LOGGER_NORMAL,$syslog = LOG_INFO) {
|
||||||
global $db;
|
global $db;
|
||||||
$saved = $db->debug;
|
$saved = \DBA::$dba->debug;
|
||||||
$db->debug = false;
|
\DBA::$dba->debug = false;
|
||||||
logger($s,$level,$syslog);
|
logger($s,$level,$syslog);
|
||||||
$db->debug = $saved;
|
\DBA::$dba->debug = $saved;
|
||||||
}
|
}
|
@ -2040,7 +2040,7 @@ function get_site_info() {
|
|||||||
'admin' => $admin,
|
'admin' => $admin,
|
||||||
'site_name' => (($site_name) ? $site_name : ''),
|
'site_name' => (($site_name) ? $site_name : ''),
|
||||||
'platform' => Zotlabs\Lib\System::get_platform_name(),
|
'platform' => Zotlabs\Lib\System::get_platform_name(),
|
||||||
'dbdriver' => $db->getdriver(),
|
'dbdriver' => DBA::$dba->getdriver(),
|
||||||
'lastpoll' => get_config('system','lastpoll'),
|
'lastpoll' => get_config('system','lastpoll'),
|
||||||
'info' => (($site_info) ? $site_info : ''),
|
'info' => (($site_info) ? $site_info : ''),
|
||||||
'channels_total' => $channels_total_stat,
|
'channels_total' => $channels_total_stat,
|
||||||
|
@ -571,7 +571,7 @@ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) {
|
|||||||
global $a;
|
global $a;
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
if((App::$module == 'install') || (! ($db && $db->connected)))
|
if((App::$module == 'install') || (! (DBA::$dba && DBA::$dba->connected)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$debugging = get_config('system', 'debugging');
|
$debugging = get_config('system', 'debugging');
|
||||||
@ -652,7 +652,7 @@ function dlogger($msg, $level = 0) {
|
|||||||
global $a;
|
global $a;
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
if((App::$module == 'install') || (! ($db && $db->connected)))
|
if((App::$module == 'install') || (! (DBA::$dba && DBA::$dba->connected)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$debugging = get_config('system','debugging');
|
$debugging = get_config('system','debugging');
|
||||||
|
178
index.php
178
index.php
@ -1,183 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file index.php
|
* @file index.php
|
||||||
*
|
*
|
||||||
* @brief The main entry point to the application.
|
* @brief The main entry point to the application.
|
||||||
*
|
|
||||||
* Bootstrap the application, load configuration, load modules, load theme, etc.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
require_once('Zotlabs/Web/WebServer.php');
|
||||||
* bootstrap the application
|
|
||||||
*/
|
|
||||||
require_once('boot.php');
|
|
||||||
|
|
||||||
if(file_exists('.htsite.php'))
|
$server = new WebServer();
|
||||||
include('.htsite.php');
|
$server->run();
|
||||||
|
|
||||||
// our global App object
|
|
||||||
|
|
||||||
$a = new miniApp;
|
|
||||||
|
|
||||||
App::init();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Load the configuration file which contains our DB credentials.
|
|
||||||
* Ignore errors. If the file doesn't exist or is empty, we are running in
|
|
||||||
* installation mode.
|
|
||||||
*/
|
|
||||||
|
|
||||||
App::$install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true);
|
|
||||||
|
|
||||||
@include('.htconfig.php');
|
|
||||||
|
|
||||||
if(! defined('UNO'))
|
|
||||||
define('UNO', 0);
|
|
||||||
|
|
||||||
$a->convert();
|
|
||||||
|
|
||||||
App::$timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
|
|
||||||
date_default_timezone_set(App::$timezone);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Try to open the database;
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once('include/dba/dba_driver.php');
|
|
||||||
|
|
||||||
if(! App::$install) {
|
|
||||||
$db = dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, App::$install);
|
|
||||||
if(! $db->connected) {
|
|
||||||
system_unavailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load configs from db. Overwrite configs from .htconfig.php
|
|
||||||
*/
|
|
||||||
|
|
||||||
load_config('config');
|
|
||||||
load_config('system');
|
|
||||||
load_config('feature');
|
|
||||||
|
|
||||||
App::$session = new \Zotlabs\Web\Session();
|
|
||||||
App::$session->init();
|
|
||||||
load_hooks();
|
|
||||||
call_hooks('init_1');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
App::$language = get_best_language();
|
|
||||||
load_translation_table(App::$language,App::$install);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Important stuff we always need to do.
|
|
||||||
*
|
|
||||||
* The order of these may be important so use caution if you think they're all
|
|
||||||
* intertwingled with no logical order and decide to sort it out. Some of the
|
|
||||||
* dependencies have changed, but at least at one time in the recent past - the
|
|
||||||
* order was critical to everything working properly
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(App::$session) {
|
|
||||||
App::$session->start();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
session_start();
|
|
||||||
register_shutdown_function('session_write_close');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Language was set earlier, but we can over-ride it in the session.
|
|
||||||
* We have to do it here because the session was just now opened.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(array_key_exists('system_language',$_POST)) {
|
|
||||||
if(strlen($_POST['system_language']))
|
|
||||||
$_SESSION['language'] = $_POST['system_language'];
|
|
||||||
else
|
|
||||||
unset($_SESSION['language']);
|
|
||||||
}
|
|
||||||
if((x($_SESSION, 'language')) && ($_SESSION['language'] !== $lang)) {
|
|
||||||
App::$language = $_SESSION['language'];
|
|
||||||
load_translation_table(App::$language);
|
|
||||||
}
|
|
||||||
|
|
||||||
if((x($_GET,'zid')) && (! App::$install)) {
|
|
||||||
App::$query_string = strip_zids(App::$query_string);
|
|
||||||
if(! local_channel()) {
|
|
||||||
$_SESSION['my_address'] = $_GET['zid'];
|
|
||||||
zid_init($a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if((x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || (App::$module === 'login'))
|
|
||||||
require('include/auth.php');
|
|
||||||
|
|
||||||
if(! x($_SESSION, 'sysmsg'))
|
|
||||||
$_SESSION['sysmsg'] = array();
|
|
||||||
|
|
||||||
if(! x($_SESSION, 'sysmsg_info'))
|
|
||||||
$_SESSION['sysmsg_info'] = array();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check_config() is responsible for running update scripts. These automatically
|
|
||||||
* update the DB schema whenever we push a new one out. It also checks to see if
|
|
||||||
* any plugins have been added or removed and reacts accordingly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
if(App::$install) {
|
|
||||||
/* Allow an exception for the view module so that pcss will be interpreted during installation */
|
|
||||||
if(App::$module != 'view')
|
|
||||||
App::$module = 'setup';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
check_config($a);
|
|
||||||
|
|
||||||
nav_set_selected('nothing');
|
|
||||||
|
|
||||||
$Router = new Zotlabs\Web\Router($a);
|
|
||||||
|
|
||||||
/* initialise content region */
|
|
||||||
|
|
||||||
if(! x(App::$page, 'content'))
|
|
||||||
App::$page['content'] = '';
|
|
||||||
|
|
||||||
call_hooks('page_content_top', App::$page['content']);
|
|
||||||
|
|
||||||
|
|
||||||
$Router->Dispatch($a);
|
|
||||||
|
|
||||||
|
|
||||||
// If you're just visiting, let javascript take you home
|
|
||||||
|
|
||||||
if(x($_SESSION, 'visitor_home')) {
|
|
||||||
$homebase = $_SESSION['visitor_home'];
|
|
||||||
} elseif(local_channel()) {
|
|
||||||
$homebase = z_root() . '/channel/' . App::$channel['channel_address'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($homebase)) {
|
|
||||||
App::$page['content'] .= '<script>var homebase = "' . $homebase . '";</script>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// now that we've been through the module content, see if the page reported
|
|
||||||
// a permission problem and if so, a 403 response would seem to be in order.
|
|
||||||
|
|
||||||
if(stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) {
|
|
||||||
header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
call_hooks('page_end', App::$page['content']);
|
|
||||||
|
|
||||||
construct_page($a);
|
|
||||||
|
|
||||||
killme();
|
|
||||||
|
Reference in New Issue
Block a user