Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example.complete
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ REDIS_SERVERS=127.0.0.1:6379:0
# Queue driver to use
# Queue not really currently used but may be configurable in the future.
# Would advise not to change this for now.
QUEUE_DRIVER=sync
QUEUE_CONNECTION=sync

# Storage system to use
# Can be 'local', 'local_secure' or 's3'
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ nbproject
.buildpath
.project
.settings/
webpack-stats.json
webpack-stats.json
.phpunit.result.cache
15 changes: 8 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
dist: trusty
sudo: false
dist: bionic
language: php
php:
- 7.0.20
- 7.1.9
- '7.2'
- '7.3'

services:
- mysql

cache:
directories:
Expand All @@ -21,8 +23,7 @@ before_script:
- php artisan migrate --force -n --database=mysql_testing
- php artisan db:seed --force -n --class=DummyContentSeeder --database=mysql_testing

script: vendor/bin/phpunit --configuration phpunit.xml

after_failure:
- cat storage/logs/laravel.log

script:
- phpunit
7 changes: 6 additions & 1 deletion app/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ class Application extends \Illuminate\Foundation\Application
*/
public function configPath($path = '')
{
return $this->basePath.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Config'.($path ? DIRECTORY_SEPARATOR.$path : $path);
return $this->basePath
. DIRECTORY_SEPARATOR
. 'app'
. DIRECTORY_SEPARATOR
. 'Config'
. ($path ? DIRECTORY_SEPARATOR.$path : $path);
}

}
16 changes: 9 additions & 7 deletions app/Auth/Access/SocialAuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use BookStack\Exceptions\SocialDriverNotConfigured;
use BookStack\Exceptions\SocialSignInAccountNotUsed;
use BookStack\Exceptions\UserRegistrationException;
use Illuminate\Support\Str;
use Laravel\Socialite\Contracts\Factory as Socialite;
use Laravel\Socialite\Contracts\User as SocialUser;

Expand Down Expand Up @@ -104,6 +105,7 @@ public function handleLoginCallback($socialDriver, SocialUser $socialUser)
$socialAccount = $this->socialAccount->where('driver_id', '=', $socialId)->first();
$isLoggedIn = auth()->check();
$currentUser = user();
$titleCaseDriver = Str::title($socialDriver);

// When a user is not logged in and a matching SocialAccount exists,
// Simply log the user into the application.
Expand All @@ -117,26 +119,26 @@ public function handleLoginCallback($socialDriver, SocialUser $socialUser)
if ($isLoggedIn && $socialAccount === null) {
$this->fillSocialAccount($socialDriver, $socialUser);
$currentUser->socialAccounts()->save($this->socialAccount);
session()->flash('success', trans('settings.users_social_connected', ['socialAccount' => title_case($socialDriver)]));
session()->flash('success', trans('settings.users_social_connected', ['socialAccount' => $titleCaseDriver]));
return redirect($currentUser->getEditUrl());
}

// When a user is logged in and the social account exists and is already linked to the current user.
if ($isLoggedIn && $socialAccount !== null && $socialAccount->user->id === $currentUser->id) {
session()->flash('error', trans('errors.social_account_existing', ['socialAccount' => title_case($socialDriver)]));
session()->flash('error', trans('errors.social_account_existing', ['socialAccount' => $titleCaseDriver]));
return redirect($currentUser->getEditUrl());
}

// When a user is logged in, A social account exists but the users do not match.
if ($isLoggedIn && $socialAccount !== null && $socialAccount->user->id != $currentUser->id) {
session()->flash('error', trans('errors.social_account_already_used_existing', ['socialAccount' => title_case($socialDriver)]));
session()->flash('error', trans('errors.social_account_already_used_existing', ['socialAccount' => $titleCaseDriver]));
return redirect($currentUser->getEditUrl());
}

// Otherwise let the user know this social account is not used by anyone.
$message = trans('errors.social_account_not_used', ['socialAccount' => title_case($socialDriver)]);
$message = trans('errors.social_account_not_used', ['socialAccount' => $titleCaseDriver]);
if (setting('registration-enabled')) {
$message .= trans('errors.social_account_register_instructions', ['socialAccount' => title_case($socialDriver)]);
$message .= trans('errors.social_account_register_instructions', ['socialAccount' => $titleCaseDriver]);
}

throw new SocialSignInAccountNotUsed($message, '/login');
Expand All @@ -157,7 +159,7 @@ private function validateDriver($socialDriver)
abort(404, trans('errors.social_driver_not_found'));
}
if (!$this->checkDriverConfigured($driver)) {
throw new SocialDriverNotConfigured(trans('errors.social_driver_not_configured', ['socialAccount' => title_case($socialDriver)]));
throw new SocialDriverNotConfigured(trans('errors.social_driver_not_configured', ['socialAccount' => Str::title($socialDriver)]));
}

return $driver;
Expand Down Expand Up @@ -244,7 +246,7 @@ public function fillSocialAccount($socialDriver, $socialUser)
public function detachSocialAccount($socialDriver)
{
user()->socialAccounts()->where('driver', '=', $socialDriver)->delete();
session()->flash('success', trans('settings.users_social_disconnected', ['socialAccount' => title_case($socialDriver)]));
session()->flash('success', trans('settings.users_social_disconnected', ['socialAccount' => Str::title($socialDriver)]));
return redirect(user()->getEditUrl());
}

Expand Down
5 changes: 3 additions & 2 deletions app/Auth/Access/UserTokenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use BookStack\Exceptions\UserTokenNotFoundException;
use Carbon\Carbon;
use Illuminate\Database\Connection as Database;
use Illuminate\Support\Str;
use stdClass;

class UserTokenService
Expand Down Expand Up @@ -73,9 +74,9 @@ public function checkTokenAndGetUserId(string $token) : int
*/
protected function generateToken() : string
{
$token = str_random(24);
$token = Str::random(24);
while ($this->tokenExists($token)) {
$token = str_random(25);
$token = Str::random(25);
}
return $token;
}
Expand Down
3 changes: 2 additions & 1 deletion app/Auth/Permissions/PermissionsRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use BookStack\Auth\Permissions;
use BookStack\Auth\Role;
use BookStack\Exceptions\PermissionsException;
use Illuminate\Support\Str;

class PermissionsRepo
{
Expand Down Expand Up @@ -66,7 +67,7 @@ public function saveNewRole($roleData)
$role->name = str_replace(' ', '-', strtolower($roleData['display_name']));
// Prevent duplicate names
while ($this->role->where('name', '=', $role->name)->count() > 0) {
$role->name .= strtolower(str_random(2));
$role->name .= strtolower(Str::random(2));
}
$role->save();

Expand Down
9 changes: 5 additions & 4 deletions app/Config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
// Application Fallback Locale
'fallback_locale' => 'en',

// Faker Locale
'faker_locale' => 'en_GB',

// Enable right-to-left text control.
'rtl' => false,

Expand All @@ -72,10 +75,6 @@
// Encryption cipher
'cipher' => 'AES-256-CBC',

// Logging configuration
// Options: single, daily, syslog, errorlog
'log' => env('APP_LOGGING', 'single'),

// Application Services Provides
'providers' => [

Expand Down Expand Up @@ -137,6 +136,7 @@

// Laravel
'App' => Illuminate\Support\Facades\App::class,
'Arr' => Illuminate\Support\Arr::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
'Blade' => Illuminate\Support\Facades\Blade::class,
Expand Down Expand Up @@ -166,6 +166,7 @@
'Schema' => Illuminate\Support\Facades\Schema::class,
'Session' => Illuminate\Support\Facades\Session::class,
'Storage' => Illuminate\Support\Facades\Storage::class,
'Str' => Illuminate\Support\Str::class,
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
Expand Down
1 change: 1 addition & 0 deletions app/Config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],

Expand Down
13 changes: 11 additions & 2 deletions app/Config/broadcasting.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@

'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
],
],

'redis' => [
Expand All @@ -38,6 +42,11 @@
'driver' => 'log',
],

'null' => [
'driver' => 'null',
],


],

];
2 changes: 1 addition & 1 deletion app/Config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@

// Cache key prefix
// Used to prevent collisions in shared cache systems.
'prefix' => env('CACHE_PREFIX', 'bookstack'),
'prefix' => env('CACHE_PREFIX', 'bookstack_cache'),

];
40 changes: 10 additions & 30 deletions app/Config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

$redisDefaults = ['host' => '127.0.0.1', 'port' => '6379', 'database' => '0', 'password' => null];
$redisServers = explode(',', trim(env('REDIS_SERVERS', '127.0.0.1:6379:0'), ','));
$redisConfig = [];
$redisConfig = ['client' => 'predis'];
$cluster = count($redisServers) > 1;

if ($cluster) {
Expand Down Expand Up @@ -59,14 +59,9 @@
// Many of those shown here are unsupported by BookStack.
'connections' => [

'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path('database.sqlite'),
'prefix' => '',
],

'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => $mysql_host,
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
Expand All @@ -76,43 +71,28 @@
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],

'mysql_testing' => [
'driver' => 'mysql',
'url' => env('TEST_DATABASE_URL'),
'host' => '127.0.0.1',
'database' => 'bookstack-test',
'username' => env('MYSQL_USER', 'bookstack-test'),
'password' => env('MYSQL_PASSWORD', 'bookstack-test'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
],

'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],

'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],

],

// Migration Repository Table
Expand Down
37 changes: 37 additions & 0 deletions app/Config/hashing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* Hashing configuration options.
*
* Changes to these config files are not supported by BookStack and may break upon updates.
* Configuration should be altered via the `.env` file or environment variables.
* Do not edit this file unless you're happy to maintain any changes yourself.
*/

return [

// Default Hash Driver
// This option controls the default hash driver that will be used to hash
// passwords for your application. By default, the bcrypt algorithm is used.
// Supported: "bcrypt", "argon", "argon2id"
'driver' => 'bcrypt',

// Bcrypt Options
// Here you may specify the configuration options that should be used when
// passwords are hashed using the Bcrypt algorithm. This will allow you
// to control the amount of time it takes to hash the given password.
'bcrypt' => [
'rounds' => env('BCRYPT_ROUNDS', 10),
],

// Argon Options
// Here you may specify the configuration options that should be used when
// passwords are hashed using the Argon algorithm. These will allow you
// to control the amount of time it takes to hash the given password.
'argon' => [
'memory' => 1024,
'threads' => 2,
'time' => 2,
],

];
Loading