From fd639df17833c166745ecf9865915db17b093153 Mon Sep 17 00:00:00 2001 From: MarceauKa Date: Mon, 30 Sep 2019 13:22:46 +0200 Subject: [PATCH] :sparkles: Chests are now encrypted in database :bug: Chest Export with non-encrypted values :bug: Settings will not merge shaarli config anymore :memo: Typos in readme --- app/Chest.php | 27 +++++++++++++++++++++++---- app/Exports/ChestsExport.php | 8 ++++---- app/Services/Shaarli/Shaarli.php | 6 ------ changelog.md | 12 ++++++++++++ readme.md | 16 +++++++++------- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/app/Chest.php b/app/Chest.php index b62eda3..e01a5f8 100644 --- a/app/Chest.php +++ b/app/Chest.php @@ -14,9 +14,6 @@ class Chest extends Model 'title', 'content', ]; - protected $casts = [ - 'content' => 'json', - ]; public function getCreatedAtFormatedAttribute(): string { @@ -38,13 +35,35 @@ class Chest extends Model return $query->where('id', app('hashid')->decode($hash)); } + public function getContentAttribute($value) + { + try { + $content = decrypt($value, false); + } catch (\Exception $e) { + $content = $value; + } + + return json_decode($content); + } + + public function setContentAttribute($value) + { + try { + $content = encrypt(json_encode($value), false); + } catch (\Exception $e) { + $content = json_encode($value); + } + + $this->attributes['content'] = $content; + } + public function toSearchableArray() { return [ 'title' => $this->title, 'content' => collect($this->content) ->reject(function ($item) { - return false === in_array($item['type'], ['url', 'text']); + return false === in_array($item->type, ['url', 'text']); }) ->pluck('value') ->implode("\n"), diff --git a/app/Exports/ChestsExport.php b/app/Exports/ChestsExport.php index 1019825..2af876a 100644 --- a/app/Exports/ChestsExport.php +++ b/app/Exports/ChestsExport.php @@ -43,13 +43,13 @@ class ChestsExport implements FromCollection, WithMapping, WithHeadings $output = ''; foreach ($content as $line) { - if ($line['type'] === 'code') { - $output .= $line['name'] . " :\n" . $line['value'] . "\n"; + if ($line->type === 'code') { + $output .= $line->name . " :\n" . $line->value . "\n"; } else { - $output .= $line['name'] . " : " . $line['value'] . "\n"; + $output .= $line->name . " : " . $line->value . "\n"; } } return $output; } -} \ No newline at end of file +} diff --git a/app/Services/Shaarli/Shaarli.php b/app/Services/Shaarli/Shaarli.php index edd4459..a363aa9 100644 --- a/app/Services/Shaarli/Shaarli.php +++ b/app/Services/Shaarli/Shaarli.php @@ -25,12 +25,6 @@ class Shaarli { $this->app = $app; $this->settings = Valuestore::make(storage_path('settings.json')); - - foreach ($this->app['config']->get('shaarli') as $key => $item) { - if ($this->settings->has($key) === false) { - $this->settings->put($key, $item); - } - } } public function authorizeFromRequest(Request $request): bool diff --git a/changelog.md b/changelog.md index 1a2edbb..d57c80c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,15 @@ +# Unreleased + +## Changed + +- Chests are now encrypted in database + +## Fixed + +- Settings will not merge shaarli config anymore +- Chest Export with non-encrypted values +- Typos in readme + # 1.2.8 ## Changed diff --git a/readme.md b/readme.md index 73fee3b..e12eaa0 100644 --- a/readme.md +++ b/readme.md @@ -20,6 +20,7 @@ but built with [Laravel](https://github.com/laravel/laravel) and [Vue.js](https: - [Security](#security) - [Update](#update) - [Going live](#going-live) +- [Artisan commands](#artisan-commands) - [Tests](#tests) - [Licence](#licence) @@ -85,7 +86,7 @@ If you don't want your content being publicy accessible, you can update this pre You're able to active 2-FA (2 factors authentication). By default 2-FA is disabled but you can update it from your app settings. Code length and code expiration are also configurable. **Test if you application can send emails before enabling this feature**. -### Auths monitoring +### Auth monitoring Shaarli logs all successful and failed auths with their associated devices. @@ -99,9 +100,7 @@ git reset --hard git pull origin master composer install --no-dev -o php artisan migrate --force -n -php artisan cache:clear -php artisan config:cache -php artisan route:cache +php artisan optimize php artisan view:clear php artisan queue:restart # if you're using queues php artisan up @@ -131,11 +130,14 @@ MAIL_FROM_ADDRESS={your_email} **Artisan routines** ``` -php artisan cache:clear -php artisan route:cache -php artisan config:cache +php artisan optimize +php artisan view:clear ``` +## Artisan commands + +__TO DO__ + ## Tests 1. Be sure to have a testing database with `touch database/testing.sqlite` and have composer `require-dev` dependencies installer.