Example #1
0
function initTranslate()
{
    Minz_Translate::init();
    $available_languages = Minz_Translate::availableLanguages();
    if (!isset($_SESSION['language'])) {
        $_SESSION['language'] = get_best_language();
    }
    if (!in_array($_SESSION['language'], $available_languages)) {
        $_SESSION['language'] = 'en';
    }
    Minz_Translate::reset($_SESSION['language']);
}
Example #2
0
function create_account($arr)
{
    // Required: { email, password }
    $result = array('success' => false, 'email' => '', 'password' => '', 'message' => '');
    $invite_code = x($arr, 'invite_code') ? notags(trim($arr['invite_code'])) : '';
    $email = x($arr, 'email') ? notags(trim($arr['email'])) : '';
    $password = x($arr, 'password') ? trim($arr['password']) : '';
    $password2 = x($arr, 'password2') ? trim($arr['password2']) : '';
    $parent = x($arr, 'parent') ? intval($arr['parent']) : 0;
    $flags = x($arr, 'account_flags') ? intval($arr['account_flags']) : ACCOUNT_OK;
    $roles = x($arr, 'account_roles') ? intval($arr['account_roles']) : 0;
    $expires = x($arr, 'expires') ? intval($arr['expires']) : NULL_DATE;
    $default_service_class = get_config('system', 'default_service_class');
    if ($default_service_class === false) {
        $default_service_class = '';
    }
    if (!x($email) || !x($password)) {
        $result['message'] = t('Please enter the required information.');
        return $result;
    }
    // prevent form hackery
    if ($roles & ACCOUNT_ROLE_ADMIN) {
        $admin_result = check_account_admin($arr);
        if (!$admin_result) {
            $roles = 0;
        }
    }
    // allow the admin_email account to be admin, but only if it's the first account.
    $c = account_total();
    if ($c === 0 && check_account_admin($arr)) {
        $roles |= ACCOUNT_ROLE_ADMIN;
    }
    // Ensure that there is a host keypair.
    if (!get_config('system', 'pubkey') && !get_config('system', 'prvkey')) {
        $hostkey = new_keypair(4096);
        set_config('system', 'pubkey', $hostkey['pubkey']);
        set_config('system', 'prvkey', $hostkey['prvkey']);
    }
    $invite_result = check_account_invite($invite_code);
    if ($invite_result['error']) {
        $result['message'] = $invite_result['message'];
        return $result;
    }
    $email_result = check_account_email($email);
    if ($email_result['error']) {
        $result['message'] = $email_result['message'];
        return $result;
    }
    $password_result = check_account_password($password);
    if ($password_result['error']) {
        $result['message'] = $password_result['message'];
        return $result;
    }
    $salt = random_string(32);
    $password_encoded = hash('whirlpool', $salt . $password);
    $r = q("INSERT INTO account \n\t\t\t( account_parent,  account_salt,  account_password, account_email,   account_language, \n\t\t\t  account_created, account_flags, account_roles,    account_expires, account_service_class )\n\t\tVALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s' )", intval($parent), dbesc($salt), dbesc($password_encoded), dbesc($email), dbesc(get_best_language()), dbesc(datetime_convert()), dbesc($flags), dbesc($roles), dbesc($expires), dbesc($default_service_class));
    if (!$r) {
        logger('create_account: DB INSERT failed.');
        $result['message'] = t('Failed to store account information.');
        return $result;
    }
    $r = q("select * from account where account_email = '%s' and account_password = '******' limit 1", dbesc($email), dbesc($password_encoded));
    if ($r && count($r)) {
        $result['account'] = $r[0];
    } else {
        logger('create_account: could not retrieve newly created account');
    }
    // Set the parent record to the current record_id if no parent was provided
    if (!$parent) {
        $r = q("update account set account_parent = %d where account_id = %d", intval($result['account']['account_id']), intval($result['account']['account_id']));
        if (!$r) {
            logger('create_account: failed to set parent');
        }
        $result['account']['parent'] = $result['account']['account_id'];
    }
    $result['success'] = true;
    $result['email'] = $email;
    $result['password'] = $password;
    call_hooks('register_account', $result);
    return $result;
}
Example #3
0
    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();
        session_set_cookie_params(isset($arr['lifetime']) ? $arr['lifetime'] : 0, isset($arr['path']) ? $arr['path'] : '/', isset($arr['domain']) ? $arr['domain'] : $a->get_hostname(), isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? true : false, isset($arr['httponly']) ? $arr['httponly'] : true);
    }
} else {
    // load translations but do not check plugins as we have no database
    $a->language = get_best_language();
    load_translation_table($a->language, true);
}
/**
 *
 * 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
 *
 */
session_start();
/**
 * Language was set earlier, but we can over-ride it in the session.
Example #4
0
    $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');
    \Zotlabs\Web\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
 *
 */
\Zotlabs\Web\Session::start();
/**
 * 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.
Example #5
0
 public function run()
 {
     /*
      * Bootstrap the application, load configuration, load modules, load theme, etc.
      */
     require_once 'boot.php';
     sys_boot();
     \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();
         }
     }
     if (x($_GET, 'zat') && !\App::$install) {
         \App::$query_string = strip_zats(\App::$query_string);
         if (!local_channel()) {
             zat_init();
         }
     }
     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 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 (is_array($_SESSION['sysmsg']) && 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();
 }