'English', 'fr' => 'Français' ); } function _t($key) { global $translates; $translate = $key; if (isset($translates[$key])) { $translate = $translates[$key]; } $args = func_get_args(); unset($args[0]); return vsprintf($translate, $args); } /*** SAUVEGARDES ***/ function saveLanguage() { if (!empty($_POST)) { if (!isset($_POST['language'])) { return false; } $_SESSION['language'] = $_POST['language']; header('Location: index.php?step=1'); } } function saveStep2() { if (!empty($_POST)) { $_SESSION['title'] = substr(trim(param('title', _t('freshrss'))), 0, 25); $_SESSION['old_entries'] = param('old_entries', 3); $_SESSION['auth_type'] = param('auth_type', 'form'); $_SESSION['default_user'] = substr(preg_replace('/[^a-zA-Z0-9]/', '', param('default_user', '')), 0, 16); $_SESSION['mail_login'] = filter_var(param('mail_login', ''), FILTER_VALIDATE_EMAIL); $password_plain = param('passwordPlain', false); if ($password_plain !== false) { if (!function_exists('password_hash')) { include_once(LIB_PATH . '/password_compat.php'); } $passwordHash = password_hash($password_plain, PASSWORD_BCRYPT, array('cost' => BCRYPT_COST)); $passwordHash = preg_replace('/^\$2[xy]\$/', '\$2a\$', $passwordHash); //Compatibility with bcrypt.js $_SESSION['passwordHash'] = $passwordHash; } if (empty($_SESSION['title']) || empty($_SESSION['old_entries']) || empty($_SESSION['auth_type']) || empty($_SESSION['default_user'])) { return false; } if (($_SESSION['auth_type'] === 'form' && empty($_SESSION['passwordHash'])) || ($_SESSION['auth_type'] === 'persona' && empty($_SESSION['mail_login']))) { return false; } $_SESSION['salt'] = sha1(uniqid(mt_rand(), true).implode('', stat(__FILE__))); if ((!ctype_digit($_SESSION['old_entries'])) ||($_SESSION['old_entries'] < 1)) { $_SESSION['old_entries'] = 3; } $token = ''; if ($_SESSION['mail_login']) { $token = sha1($_SESSION['salt'] . $_SESSION['mail_login']); } $config_array = array( 'language' => $_SESSION['language'], 'theme' => 'Origine', 'old_entries' => $_SESSION['old_entries'], 'mail_login' => $_SESSION['mail_login'], 'passwordHash' => $_SESSION['passwordHash'], 'token' => $token, ); $configPath = DATA_PATH . '/' . $_SESSION['default_user'] . '_user.php'; @unlink($configPath); //To avoid access-rights problems file_put_contents($configPath, " array( 'environment' => empty($_SESSION['environment']) ? 'production' : $_SESSION['environment'], 'salt' => $_SESSION['salt'], 'base_url' => '', 'title' => $_SESSION['title'], 'default_user' => $_SESSION['default_user'], 'allow_anonymous' => isset($_SESSION['allow_anonymous']) ? $_SESSION['allow_anonymous'] : false, 'allow_anonymous_refresh' => isset($_SESSION['allow_anonymous_refresh']) ? $_SESSION['allow_anonymous_refresh'] : false, 'auth_type' => $_SESSION['auth_type'], 'api_enabled' => isset($_SESSION['api_enabled']) ? $_SESSION['api_enabled'] : false, 'unsafe_autologin_enabled' => isset($_SESSION['unsafe_autologin_enabled']) ? $_SESSION['unsafe_autologin_enabled'] : false, ), 'db' => array( 'type' => $_SESSION['bd_type'], 'host' => $_SESSION['bd_host'], 'user' => $_SESSION['bd_user'], 'password' => $_SESSION['bd_password'], 'base' => $_SESSION['bd_base'], 'prefix' => $_SESSION['bd_prefix'], ), ); @unlink(DATA_PATH . '/config.php'); //To avoid access-rights problems file_put_contents(DATA_PATH . '/config.php', " 'SET NAMES utf8', ); break; case 'sqlite': $str = 'sqlite:' . DATA_PATH . '/' . $_SESSION['default_user'] . '.sqlite'; $driver_options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ); break; default: return false; } return new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options); } function deleteInstall() { $res = unlink(DATA_PATH . '/do-install.txt'); if (!$res) { return false; } header('Location: index.php'); } /*** VÉRIFICATIONS ***/ function checkStep() { $s0 = checkStep0(); $s1 = checkStep1(); $s2 = checkStep2(); $s3 = checkStep3(); if (STEP > 0 && $s0['all'] != 'ok') { header('Location: index.php?step=0'); } elseif (STEP > 1 && $s1['all'] != 'ok') { header('Location: index.php?step=1'); } elseif (STEP > 2 && $s2['all'] != 'ok') { header('Location: index.php?step=2'); } elseif (STEP > 3 && $s3['all'] != 'ok') { header('Location: index.php?step=3'); } $_SESSION['actualize_feeds'] = true; } function checkStep0() { $languages = availableLanguages(); $language = isset($_SESSION['language']) && isset($languages[$_SESSION['language']]); return array( 'language' => $language ? 'ok' : 'ko', 'all' => $language ? 'ok' : 'ko' ); } function checkStep1() { $php = version_compare(PHP_VERSION, '5.2.1') >= 0; $minz = file_exists(LIB_PATH . '/Minz'); $curl = extension_loaded('curl'); $pdo_mysql = extension_loaded('pdo_mysql'); $pdo_sqlite = extension_loaded('pdo_sqlite'); $pdo = $pdo_mysql || $pdo_sqlite; $pcre = extension_loaded('pcre'); $ctype = extension_loaded('ctype'); $dom = class_exists('DOMDocument'); $data = DATA_PATH && is_writable(DATA_PATH); $cache = CACHE_PATH && is_writable(CACHE_PATH); $log = LOG_PATH && is_writable(LOG_PATH); $favicons = is_writable(DATA_PATH . '/favicons'); $persona = is_writable(DATA_PATH . '/persona'); $http_referer = is_referer_from_same_domain(); return array( 'php' => $php ? 'ok' : 'ko', 'minz' => $minz ? 'ok' : 'ko', 'curl' => $curl ? 'ok' : 'ko', 'pdo-mysql' => $pdo_mysql ? 'ok' : 'ko', 'pdo-sqlite' => $pdo_sqlite ? 'ok' : 'ko', 'pdo' => $pdo ? 'ok' : 'ko', 'pcre' => $pcre ? 'ok' : 'ko', 'ctype' => $ctype ? 'ok' : 'ko', 'dom' => $dom ? 'ok' : 'ko', 'data' => $data ? 'ok' : 'ko', 'cache' => $cache ? 'ok' : 'ko', 'log' => $log ? 'ok' : 'ko', 'favicons' => $favicons ? 'ok' : 'ko', 'persona' => $persona ? 'ok' : 'ko', 'http_referer' => $http_referer ? 'ok' : 'ko', 'all' => $php && $minz && $curl && $pdo && $pcre && $ctype && $dom && $data && $cache && $log && $favicons && $persona && $http_referer ? 'ok' : 'ko' ); } function checkStep2() { $conf = !empty($_SESSION['title']) && !empty($_SESSION['old_entries']) && isset($_SESSION['mail_login']) && !empty($_SESSION['default_user']); $form = ( isset($_SESSION['auth_type']) && ($_SESSION['auth_type'] != 'form' || !empty($_SESSION['passwordHash'])) ); $persona = ( isset($_SESSION['auth_type']) && ($_SESSION['auth_type'] != 'persona' || !empty($_SESSION['mail_login'])) ); $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user']; if ($defaultUser === null) { $defaultUser = empty($_SESSION['default_user']) ? '' : $_SESSION['default_user']; } $data = is_writable(DATA_PATH . '/' . $defaultUser . '_user.php'); return array( 'conf' => $conf ? 'ok' : 'ko', 'form' => $form ? 'ok' : 'ko', 'persona' => $persona ? 'ok' : 'ko', 'data' => $data ? 'ok' : 'ko', 'all' => $conf && $form && $persona && $data ? 'ok' : 'ko' ); } function checkStep3() { $conf = is_writable(DATA_PATH . '/config.php'); $bd = isset($_SESSION['bd_type']) && isset($_SESSION['bd_host']) && isset($_SESSION['bd_user']) && isset($_SESSION['bd_password']) && isset($_SESSION['bd_base']) && isset($_SESSION['bd_prefix']) && isset($_SESSION['bd_error']); $conn = empty($_SESSION['bd_error']); return array( 'bd' => $bd ? 'ok' : 'ko', 'conn' => $conn ? 'ok' : 'ko', 'conf' => $conf ? 'ok' : 'ko', 'all' => $bd && $conn && $conf ? 'ok' : 'ko' ); } function checkBD() { $ok = false; try { $str = ''; $driver_options = null; switch ($_SESSION['bd_type']) { case 'mysql': $driver_options = array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' ); try { // on ouvre une connexion juste pour créer la base si elle n'existe pas $str = 'mysql:host=' . $_SESSION['bd_host'] . ';'; $c = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options); $sql = sprintf(SQL_CREATE_DB, $_SESSION['bd_base']); $res = $c->query($sql); } catch (PDOException $e) { } // on écrase la précédente connexion en sélectionnant la nouvelle BDD $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base']; break; case 'sqlite': $str = 'sqlite:' . DATA_PATH . '/' . $_SESSION['default_user'] . '.sqlite'; $driver_options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ); break; default: return false; } $c = new PDO($str, $_SESSION['bd_user'], $_SESSION['bd_password'], $driver_options); if (defined('SQL_CREATE_TABLES')) { $sql = sprintf(SQL_CREATE_TABLES, $_SESSION['bd_prefix_user'], _t('default_category')); $stm = $c->prepare($sql); $ok = $stm->execute(); } else { global $SQL_CREATE_TABLES; if (is_array($SQL_CREATE_TABLES)) { $ok = true; foreach ($SQL_CREATE_TABLES as $instruction) { $sql = sprintf($instruction, $_SESSION['bd_prefix_user'], _t('default_category')); $stm = $c->prepare($sql); $ok &= $stm->execute(); } } } } catch (PDOException $e) { $ok = false; $_SESSION['bd_error'] = $e->getMessage(); } if (!$ok) { @unlink(DATA_PATH . '/config.php'); } return $ok; } /*** AFFICHAGE ***/ function printStep0() { global $actual; ?>

/>
/>

<?php echo _t('freshrss_installation'); ?>