Minor cleanups
This commit is contained in:
parent
cfd03efc01
commit
cd1a0115c2
@ -212,7 +212,7 @@ select {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.form-actions {
|
.form-actions {
|
||||||
margin-top: 40px;
|
margin-top: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.form-error,
|
input.form-error,
|
||||||
@ -728,6 +728,13 @@ iframe {
|
|||||||
margin-bottom: 45px;
|
margin-bottom: 45px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#database-selector h4 {
|
||||||
|
margin: 0;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
padding: 0;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
.bookmarklet {
|
.bookmarklet {
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
@ -23,7 +23,7 @@ Router\before(function($action) {
|
|||||||
// These actions are considered to be safe even for unauthenticated users
|
// These actions are considered to be safe even for unauthenticated users
|
||||||
$safe_actions = array('login', 'bookmark-feed', 'select-db', 'logout', 'notfound');
|
$safe_actions = array('login', 'bookmark-feed', 'select-db', 'logout', 'notfound');
|
||||||
|
|
||||||
if ( ! Model\User\is_loggedin() && ! in_array($action, $safe_actions)) {
|
if (! Model\User\is_loggedin() && ! in_array($action, $safe_actions)) {
|
||||||
if (! Model\RememberMe\authenticate()) {
|
if (! Model\RememberMe\authenticate()) {
|
||||||
Model\User\logout();
|
Model\User\logout();
|
||||||
Response\redirect('?action=login');
|
Response\redirect('?action=login');
|
||||||
@ -35,7 +35,10 @@ Router\before(function($action) {
|
|||||||
|
|
||||||
// Load translations
|
// Load translations
|
||||||
$language = Model\Config\get('language') ?: 'en_US';
|
$language = Model\Config\get('language') ?: 'en_US';
|
||||||
if ($language !== 'en_US') Translator\load($language);
|
|
||||||
|
if ($language !== 'en_US') {
|
||||||
|
Translator\load($language);
|
||||||
|
}
|
||||||
|
|
||||||
// Set timezone
|
// Set timezone
|
||||||
date_default_timezone_set(Model\Config\get('timezone') ?: 'UTC');
|
date_default_timezone_set(Model\Config\get('timezone') ?: 'UTC');
|
||||||
|
@ -13,7 +13,6 @@ Router\get_action('flush-console', function() {
|
|||||||
Response\redirect('?action=console');
|
Response\redirect('?action=console');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Display console
|
// Display console
|
||||||
Router\get_action('console', function() {
|
Router\get_action('console', function() {
|
||||||
|
|
||||||
|
@ -9,15 +9,14 @@ use PicoFarad\Template;
|
|||||||
// Logout and destroy session
|
// Logout and destroy session
|
||||||
Router\get_action('logout', function() {
|
Router\get_action('logout', function() {
|
||||||
|
|
||||||
Model\RememberMe\destroy();
|
Model\User\logout();
|
||||||
Session\close();
|
|
||||||
Response\redirect('?action=login');
|
Response\redirect('?action=login');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Display form login
|
// Display form login
|
||||||
Router\get_action('login', function() {
|
Router\get_action('login', function() {
|
||||||
|
|
||||||
if (isset($_SESSION['user'])) {
|
if (Model\User\is_loggedin()) {
|
||||||
Response\redirect('?action=unread');
|
Response\redirect('?action=unread');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ function response(array $response)
|
|||||||
function auth()
|
function auth()
|
||||||
{
|
{
|
||||||
if (! empty($_GET['database'])) {
|
if (! empty($_GET['database'])) {
|
||||||
|
// Return unauthorized if the requested database could not be found
|
||||||
if (! Model\Database\select($_GET['database'])) {
|
if (! Model\Database\select($_GET['database'])) {
|
||||||
// return unauthorized if the requested database could not be found
|
|
||||||
return array(
|
return array(
|
||||||
'api_version' => 3,
|
'api_version' => 3,
|
||||||
'auth' => 0,
|
'auth' => 0,
|
||||||
|
@ -7,6 +7,7 @@ use DirectoryIterator;
|
|||||||
use RecursiveIterator;
|
use RecursiveIterator;
|
||||||
use RecursiveIteratorIterator;
|
use RecursiveIteratorIterator;
|
||||||
use RecursiveDirectoryIterator;
|
use RecursiveDirectoryIterator;
|
||||||
|
use Model\Config;
|
||||||
|
|
||||||
// Get all files of a given directory
|
// Get all files of a given directory
|
||||||
function get_files_list($directory)
|
function get_files_list($directory)
|
||||||
@ -49,7 +50,7 @@ function is_excluded_path($path, array $exclude_list)
|
|||||||
// Synchronize 2 directories (copy/remove files)
|
// Synchronize 2 directories (copy/remove files)
|
||||||
function synchronize($source_directory, $destination_directory)
|
function synchronize($source_directory, $destination_directory)
|
||||||
{
|
{
|
||||||
\Model\Config\debug('[SYNCHRONIZE] '.$source_directory.' to '.$destination_directory);
|
Config\debug('[SYNCHRONIZE] '.$source_directory.' to '.$destination_directory);
|
||||||
|
|
||||||
$src_files = get_files_list($source_directory);
|
$src_files = get_files_list($source_directory);
|
||||||
$dst_files = get_files_list($destination_directory);
|
$dst_files = get_files_list($destination_directory);
|
||||||
@ -62,7 +63,7 @@ function synchronize($source_directory, $destination_directory)
|
|||||||
if ($file !== '.htaccess') {
|
if ($file !== '.htaccess') {
|
||||||
|
|
||||||
$destination_file = $destination_directory.DIRECTORY_SEPARATOR.$file;
|
$destination_file = $destination_directory.DIRECTORY_SEPARATOR.$file;
|
||||||
\Model\Config\debug('[REMOVE] '.$destination_file);
|
Config\debug('[REMOVE] '.$destination_file);
|
||||||
|
|
||||||
if (! @unlink($destination_file)) {
|
if (! @unlink($destination_file)) {
|
||||||
return false;
|
return false;
|
||||||
@ -77,7 +78,7 @@ function synchronize($source_directory, $destination_directory)
|
|||||||
|
|
||||||
if (! is_dir($directory)) {
|
if (! is_dir($directory)) {
|
||||||
|
|
||||||
\Model\Config\debug('[MKDIR] '.$directory);
|
Config\debug('[MKDIR] '.$directory);
|
||||||
|
|
||||||
if (! @mkdir($directory, 0755, true)) {
|
if (! @mkdir($directory, 0755, true)) {
|
||||||
return false;
|
return false;
|
||||||
@ -87,7 +88,7 @@ function synchronize($source_directory, $destination_directory)
|
|||||||
$source_file = $source_directory.DIRECTORY_SEPARATOR.$file;
|
$source_file = $source_directory.DIRECTORY_SEPARATOR.$file;
|
||||||
$destination_file = $destination_directory.DIRECTORY_SEPARATOR.$file;
|
$destination_file = $destination_directory.DIRECTORY_SEPARATOR.$file;
|
||||||
|
|
||||||
\Model\Config\debug('[COPY] '.$source_file.' to '.$destination_file);
|
Config\debug('[COPY] '.$source_file.' to '.$destination_file);
|
||||||
|
|
||||||
if (! @copy($source_file, $destination_file)) {
|
if (! @copy($source_file, $destination_file)) {
|
||||||
return false;
|
return false;
|
||||||
@ -102,7 +103,7 @@ function uncompress_archive($url, $download_directory = AUTO_UPDATE_DOWNLOAD_DIR
|
|||||||
{
|
{
|
||||||
$archive_file = $download_directory.DIRECTORY_SEPARATOR.'update.zip';
|
$archive_file = $download_directory.DIRECTORY_SEPARATOR.'update.zip';
|
||||||
|
|
||||||
\Model\Config\debug('[DOWNLOAD] '.$url);
|
Config\debug('[DOWNLOAD] '.$url);
|
||||||
|
|
||||||
if (($data = @file_get_contents($url)) === false) {
|
if (($data = @file_get_contents($url)) === false) {
|
||||||
return false;
|
return false;
|
||||||
@ -112,7 +113,7 @@ function uncompress_archive($url, $download_directory = AUTO_UPDATE_DOWNLOAD_DIR
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
\Model\Config\debug('[UNZIP] '.$archive_file);
|
Config\debug('[UNZIP] '.$archive_file);
|
||||||
|
|
||||||
$zip = new ZipArchive;
|
$zip = new ZipArchive;
|
||||||
|
|
||||||
@ -129,7 +130,7 @@ function uncompress_archive($url, $download_directory = AUTO_UPDATE_DOWNLOAD_DIR
|
|||||||
// Remove all files for a given directory
|
// Remove all files for a given directory
|
||||||
function cleanup_directory($directory)
|
function cleanup_directory($directory)
|
||||||
{
|
{
|
||||||
\Model\Config\debug('[CLEANUP] '.$directory);
|
Config\debug('[CLEANUP] '.$directory);
|
||||||
|
|
||||||
$dir = new DirectoryIterator($directory);
|
$dir = new DirectoryIterator($directory);
|
||||||
|
|
||||||
@ -173,12 +174,12 @@ function find_archive_root($base_directory = AUTO_UPDATE_ARCHIVE_DIRECTORY)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty($directory)) {
|
if (empty($directory)) {
|
||||||
\Model\Config\debug('[FIND ARCHIVE] No directory found');
|
Config\debug('[FIND ARCHIVE] No directory found');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $base_directory.DIRECTORY_SEPARATOR.$directory;
|
$path = $base_directory.DIRECTORY_SEPARATOR.$directory;
|
||||||
\Model\Config\debug('[FIND ARCHIVE] '.$path);
|
Config\debug('[FIND ARCHIVE] '.$path);
|
||||||
|
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Model\Config;
|
namespace Model\Config;
|
||||||
|
|
||||||
|
use Translator;
|
||||||
use DirectoryIterator;
|
use DirectoryIterator;
|
||||||
use SimpleValidator\Validator;
|
use SimpleValidator\Validator;
|
||||||
use SimpleValidator\Validators;
|
use SimpleValidator\Validators;
|
||||||
@ -309,7 +310,7 @@ function save(array $values)
|
|||||||
{
|
{
|
||||||
// Update the password if needed
|
// Update the password if needed
|
||||||
if (! empty($values['password'])) {
|
if (! empty($values['password'])) {
|
||||||
$values['password'] = \password_hash($values['password'], PASSWORD_BCRYPT);
|
$values['password'] = password_hash($values['password'], PASSWORD_BCRYPT);
|
||||||
} else {
|
} else {
|
||||||
unset($values['password']);
|
unset($values['password']);
|
||||||
}
|
}
|
||||||
@ -333,7 +334,7 @@ function save(array $values)
|
|||||||
function reload()
|
function reload()
|
||||||
{
|
{
|
||||||
$_SESSION['config'] = get_all();
|
$_SESSION['config'] = get_all();
|
||||||
\Translator\load(get('language'));
|
Translator\load(get('language'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the user agent of the connected user
|
// Get the user agent of the connected user
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Model\Database;
|
namespace Model\Database;
|
||||||
|
|
||||||
|
use Schema;
|
||||||
|
use DirectoryIterator;
|
||||||
|
use Model\Config;
|
||||||
use SimpleValidator\Validator;
|
use SimpleValidator\Validator;
|
||||||
use SimpleValidator\Validators;
|
use SimpleValidator\Validators;
|
||||||
|
|
||||||
@ -17,11 +20,11 @@ function create($filename, $username, $password)
|
|||||||
'filename' => $filename,
|
'filename' => $filename,
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($db->schema()->check(\Model\Config\DB_VERSION)) {
|
if ($db->schema()->check(Schema\VERSION)) {
|
||||||
|
|
||||||
$db->table('config')->update(array(
|
$db->table('config')->update(array(
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'password' => \password_hash($password, PASSWORD_BCRYPT)
|
'password' => password_hash($password, PASSWORD_BCRYPT)
|
||||||
));
|
));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -49,7 +52,7 @@ function select($filename = '')
|
|||||||
}
|
}
|
||||||
|
|
||||||
$_SESSION['database'] = $filename;
|
$_SESSION['database'] = $filename;
|
||||||
$_SESSION['config'] = \Model\Config\get_all();
|
$_SESSION['config'] = Config\get_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -63,7 +66,7 @@ function select($filename = '')
|
|||||||
// Get database path
|
// Get database path
|
||||||
function get_path()
|
function get_path()
|
||||||
{
|
{
|
||||||
return DATA_DIRECTORY.DIRECTORY_SEPARATOR.\Model\Database\select();
|
return DATA_DIRECTORY.DIRECTORY_SEPARATOR.select();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the list of available databases
|
// Get the list of available databases
|
||||||
@ -71,7 +74,7 @@ function get_all()
|
|||||||
{
|
{
|
||||||
$listing = array();
|
$listing = array();
|
||||||
|
|
||||||
$dir = new \DirectoryIterator(DATA_DIRECTORY);
|
$dir = new DirectoryIterator(DATA_DIRECTORY);
|
||||||
|
|
||||||
foreach ($dir as $fileinfo) {
|
foreach ($dir as $fileinfo) {
|
||||||
if ($fileinfo->getExtension() === 'sqlite') {
|
if ($fileinfo->getExtension() === 'sqlite') {
|
||||||
|
@ -123,9 +123,6 @@ function remove($session_id)
|
|||||||
*/
|
*/
|
||||||
function destroy()
|
function destroy()
|
||||||
{
|
{
|
||||||
// delete the cookie without any conditions!
|
|
||||||
delete_cookie();
|
|
||||||
|
|
||||||
$credentials = read_cookie();
|
$credentials = read_cookie();
|
||||||
|
|
||||||
if ($credentials !== false) {
|
if ($credentials !== false) {
|
||||||
@ -135,6 +132,8 @@ function destroy()
|
|||||||
->eq('token', $credentials['token'])
|
->eq('token', $credentials['token'])
|
||||||
->remove();
|
->remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete_cookie();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,6 +5,7 @@ namespace Model\User;
|
|||||||
use SimpleValidator\Validator;
|
use SimpleValidator\Validator;
|
||||||
use SimpleValidator\Validators;
|
use SimpleValidator\Validators;
|
||||||
use PicoDb\Database;
|
use PicoDb\Database;
|
||||||
|
use PicoFarad\Session;
|
||||||
use Model\Config;
|
use Model\Config;
|
||||||
use Model\RememberMe;
|
use Model\RememberMe;
|
||||||
use Model\Database as DatabaseModel;
|
use Model\Database as DatabaseModel;
|
||||||
@ -15,10 +16,11 @@ function is_loggedin()
|
|||||||
return ! empty($_SESSION['user']);
|
return ! empty($_SESSION['user']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destroy the session and the rememberMe cookie
|
||||||
function logout()
|
function logout()
|
||||||
{
|
{
|
||||||
\Model\RememberMe\destroy();
|
RememberMe\destroy();
|
||||||
\PicoFarad\Session\close();
|
Session\close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a user by username
|
// Get a user by username
|
||||||
@ -47,7 +49,7 @@ function validate_login(array $values)
|
|||||||
|
|
||||||
$user = get($values['username']);
|
$user = get($values['username']);
|
||||||
|
|
||||||
if ($user && \password_verify($values['password'], $user['password'])) {
|
if ($user && password_verify($values['password'], $user['password'])) {
|
||||||
|
|
||||||
unset($user['password']);
|
unset($user['password']);
|
||||||
|
|
||||||
|
@ -31,27 +31,29 @@
|
|||||||
|
|
||||||
<?= Helper\form_checkbox('remember_me', t('Remember Me'), 1) ?><br/>
|
<?= Helper\form_checkbox('remember_me', t('Remember Me'), 1) ?><br/>
|
||||||
|
|
||||||
|
<?php if (ENABLE_MULTIPLE_DB && count($databases) > 1): ?>
|
||||||
|
<div id="database-selector">
|
||||||
|
<h4><?= t('Select another database') ?></h4>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($databases as $filename => $dbname): ?>
|
||||||
|
<li>
|
||||||
|
<?php if ($current_database === $filename): ?>
|
||||||
|
<strong><?= Helper\escape($dbname) ?></strong>
|
||||||
|
<?php else: ?>
|
||||||
|
<a href="?action=select-db&database=<?= Helper\escape($filename) ?>"><?= Helper\escape($dbname) ?></a>
|
||||||
|
<?php endif ?>
|
||||||
|
</li>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif ?>
|
||||||
|
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<input type="submit" value="<?= t('Sign in') ?>" class="btn btn-blue"/>
|
<input type="submit" value="<?= t('Sign in') ?>" class="btn btn-blue"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php if (ENABLE_MULTIPLE_DB && count($databases) > 1): ?>
|
|
||||||
<div>
|
|
||||||
<h3><?= t('Select another database') ?></h3>
|
|
||||||
<ul>
|
|
||||||
<?php foreach ($databases as $filename => $dbname): ?>
|
|
||||||
<li>
|
|
||||||
<?php if ($current_database === $filename): ?>
|
|
||||||
<strong><?= Helper\escape($dbname) ?></strong>
|
|
||||||
<?php else: ?>
|
|
||||||
<a href="?action=select-db&database=<?= Helper\escape($filename) ?>"><?= Helper\escape($dbname) ?></a>
|
|
||||||
<?php endif ?>
|
|
||||||
</li>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<?php endif ?>
|
|
||||||
</section>
|
</section>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h2><?= t('New database') ?></h2>
|
<h2><?= t('New database') ?></h2>
|
||||||
<ul>
|
<nav>
|
||||||
<li><a href="?action=config"><?= t('preferences') ?></a></li>
|
<ul>
|
||||||
<li><a href="?action=about"><?= t('about') ?></a></li>
|
<li><a href="?action=config"><?= t('general') ?></a></li>
|
||||||
<li><a href="?action=help"><?= t('help') ?></a></li>
|
<li><a href="?action=services"><?= t('external services') ?></a></li>
|
||||||
<li><a href="?action=api"><?= t('api') ?></a></li>
|
<li><a href="?action=api"><?= t('api') ?></a></li>
|
||||||
</ul>
|
<li class="active"><a href="?action=database"><?= t('database') ?></a></li>
|
||||||
|
<li><a href="?action=help"><?= t('help') ?></a></li>
|
||||||
|
<li><a href="?action=about"><?= t('about') ?></a></li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form method="post" action="?action=new-db" autocomplete="off">
|
<form method="post" action="?action=new-db" autocomplete="off">
|
||||||
|
Loading…
Reference in New Issue
Block a user