Esempio n. 1
0
function cli_startup()
{
    global $a, $db;
    if (is_null($a)) {
        $a = new App();
    }
    if (is_null($db)) {
        @(include ".htconfig.php");
        require_once 'include/dba/dba_driver.php';
        $db = dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data);
        unset($db_host, $db_port, $db_user, $db_pass, $db_data);
    }
    require_once 'include/session.php';
    load_config('system');
    $a->set_baseurl(get_config('system', 'baseurl'));
    load_hooks();
}
Esempio n. 2
0
function cli_startup()
{
    global $a, $db, $default_timezone;
    if (is_null($a)) {
        $a = new App();
    }
    if (is_null($db)) {
        @(include ".htconfig.php");
        if (!defined('UNO')) {
            define('UNO', 0);
        }
        $a->timezone = x($default_timezone) ? $default_timezone : 'UTC';
        date_default_timezone_set($a->timezone);
        require_once 'include/dba/dba_driver.php';
        $db = 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);
    }
    require_once 'include/session.php';
    load_config('system');
    $a->set_baseurl(get_config('system', 'baseurl'));
    load_hooks();
}
Esempio n. 3
0
$a = new App();
/*
 * 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.
 */
$a->install = file_exists('.htconfig.php') && filesize('.htconfig.php') ? false : true;
@(include '.htconfig.php');
$a->timezone = x($default_timezone) ? $default_timezone : 'UTC';
date_default_timezone_set($a->timezone);
/*
 * Try to open the database;
 */
require_once 'include/dba/dba_driver.php';
if (!$a->install) {
    $db = dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, $a->install);
    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');
    require_once 'include/session.php';
    load_hooks();
    call_hooks('init_1');
    $a->language = get_best_language();
    load_translation_table($a->language);
    // Force the cookie to be secure (https only) if this site is SSL enabled. Must be done before session_start().
    if (intval($a->config['system']['ssl_cookie_protection'])) {
        $arr = session_get_cookie_params();
Esempio n. 4
0
/**
 * @brief Handle the actions of the different setup steps.
 *
 * @param[in,out] App &$a
 */
function setup_post(&$a)
{
    global $install_wizard_pass, $db;
    switch ($install_wizard_pass) {
        case 1:
        case 2:
            return;
            break;
            // just in case return don't return :)
        // just in case return don't return :)
        case 3:
            $urlpath = $a->get_path();
            $dbhost = trim($_POST['dbhost']);
            $dbport = intval(trim($_POST['dbport']));
            $dbuser = trim($_POST['dbuser']);
            $dbpass = trim($_POST['dbpass']);
            $dbdata = trim($_POST['dbdata']);
            $dbtype = intval(trim($_POST['dbtype']));
            $phpath = trim($_POST['phpath']);
            $adminmail = trim($_POST['adminmail']);
            $siteurl = trim($_POST['siteurl']);
            require_once 'include/dba/dba_driver.php';
            unset($db);
            $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
            if (!$db->connected) {
                echo 'Database Connect failed: ' . $db->error;
                killme();
                $a->data['db_conn_failed'] = true;
            }
            /*if(get_db_errno()) {
            				unset($db);
            				$db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, '', true);
            
            				if(! get_db_errno()) {
            					$r = q("CREATE DATABASE '%s'",
            							dbesc($dbdata)
            					);
            					if($r) {
            						unset($db);
            						$db = new dba($dbhost, $dbport, $dbuser, $dbpass, $dbdata, true);
            					} else {
            						$a->data['db_create_failed']=true;
            					}
            				} else {
            					$a->data['db_conn_failed']=true;
            					return;
            				}
            			}*/
            //if(get_db_errno()) {
            //}
            return;
            break;
        case 4:
            $urlpath = $a->get_path();
            $dbhost = notags(trim($_POST['dbhost']));
            $dbport = intval(notags(trim($_POST['dbport'])));
            $dbuser = notags(trim($_POST['dbuser']));
            $dbpass = notags(trim($_POST['dbpass']));
            $dbdata = notags(trim($_POST['dbdata']));
            $dbtype = intval(notags(trim($_POST['dbtype'])));
            $phpath = notags(trim($_POST['phpath']));
            $timezone = notags(trim($_POST['timezone']));
            $adminmail = notags(trim($_POST['adminmail']));
            $siteurl = notags(trim($_POST['siteurl']));
            if ($siteurl != z_root()) {
                $test = z_fetch_url($siteurl . "/setup/testrewrite");
                if (!$test['success'] || $test['body'] != 'ok') {
                    $a->data['url_fail'] = true;
                    $a->data['url_error'] = $test['error'];
                    return;
                }
            }
            // connect to db
            $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
            if (!$db->connected) {
                echo 'CRITICAL: DB not connected.';
                killme();
            }
            $tpl = get_intltext_template('htconfig.tpl');
            $txt = replace_macros($tpl, array('$dbhost' => $dbhost, '$dbport' => $dbport, '$dbuser' => $dbuser, '$dbpass' => $dbpass, '$dbdata' => $dbdata, '$dbtype' => $dbtype, '$timezone' => $timezone, '$siteurl' => $siteurl, '$site_id' => random_string(), '$phpath' => $phpath, '$adminmail' => $adminmail));
            $result = file_put_contents('.htconfig.php', $txt);
            if (!$result) {
                $a->data['txt'] = $txt;
            }
            $errors = load_database($db);
            if ($errors) {
                $a->data['db_failed'] = $errors;
            } else {
                $a->data['db_installed'] = true;
            }
            return;
            break;
    }
}