LycheeOrg / Lychee

A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.
https://lycheeorg.github.io/
MIT License
3.42k stars 303 forks source link

Admin login gives 'Server error or API not found' - error 500 #900

Closed DaneViking closed 3 years ago

DaneViking commented 3 years ago

Detailed description of the problem [REQUIRED]

Using Lychee as a docker in Unraid, my admin account is unaccessable. When I try to log in comes with this error:

 "description: "Server error or API not found."
params: {function: "Albums::get"}
response: ""
__proto__: Object>  

It only does this and only the admin account. Three other user accounts works without issues.

Steps to reproduce the issue

When I try to log in, the login box appears. When I enter the credentials for the admin user, it gives "Server error or API not found". And the screen is just black.

Output of the diagnostics [REQUIRED]

Diagnostics
-----------
Warning: Dropbox import not working. dropbox_key is empty.
Warning: You may experience problems when uploading a large amount of photos. Take a look in the FAQ for details.

System Information
------------------
Lychee Version (release):        4.2.1
DB Version:                      4.2.1

composer install:                --no-dev
APP_ENV:                         production
APP_DEBUG:                       true

System:                          Linux
PHP Version:                     7.4
Max uploaded file size:          5000M
Max post size:                   2000M
MySQL Version:                   10.4.17-MariaDB-1:10.4.17+maria~bionic-log

Imagick:                         1
Imagick Active:                  1
Imagick Version:                 1802
GD Version:                      bundled (2.1.0 compatible)

Config Information
------------------
version:                         040201
check_for_updates:               0
sorting_Photos_col:              title
sorting_Photos_order:            ASC
sorting_Albums_col:              title
sorting_Albums_order:            ASC
imagick:                         1
skip_duplicates:                 0
small_max_width:                 0
small_max_height:                360
medium_max_width:                1920
medium_max_height:               1080
lang:                            en
layout:                          1
image_overlay:                   1
image_overlay_type:              desc
default_license:                 none
compression_quality:             90
full_photo:                      1
delete_imported:                 0
Mod_Frame:                       1
Mod_Frame_refresh:               30
thumb_2x:                        1
small_2x:                        1
medium_2x:                       1
landing_page_enable:             0
landing_owner:                   John Smith
landing_title:                   John Smith
landing_subtitle:                Cats, Dogs & Humans Photography
landing_facebook:                https://www.facebook.com/JohnSmith
landing_flickr:                  https://www.flickr.com/JohnSmith
landing_twitter:                 https://www.twitter.com/JohnSmith
landing_instagram:               https://instagram.com/JohnSmith
landing_youtube:                 https://www.youtube.com/JohnSmith
landing_background:              dist/cat.jpg
site_title:                      Lychee v4
site_copyright_enable:           1
site_copyright_begin:            2019
site_copyright_end:              2019
additional_footer_text:          
display_social_in_gallery:       0
public_search:                   0
SL_enable:                       0
SL_for_admin:                    0
public_recent:                   0
recent_age:                      1
public_starred:                  0
downloadable:                    0
photos_wraparound:               1
map_display:                     0
zip64:                           1
map_display_public:              0
map_provider:                    Wikimedia
force_32bit_ids:                 0
map_include_subalbums:           0
update_check_every_days:         3
has_exiftool:                    1
share_button_visible:            0
import_via_symlink:              0
has_ffmpeg:                      1
location_decoding:               0
location_decoding_timeout:       30
location_show:                   1
location_show_public:            0
rss_enable:                      0
rss_recent_days:                 7
rss_max_items:                   100
prefer_available_xmp_metadata:   0
editor_enabled:                  1
lossless_optimization:           0
swipe_tolerance_x:               150
swipe_tolerance_y:               250
local_takestamp_video_formats:   .avi|.mov
log_max_num_line:                1000
unlock_password_photos_with_url_param: 0
nsfw_visible:                    1
nsfw_blur:                       0
nsfw_warning:                    0
nsfw_warning_admin:              0

Output of the laravel.log

[2021-01-31 22:22:56] production.ERROR: Call to a member function name() on null {"exception":"[object] (Error(code: 0): Call to a member function name() on null at /app/lychee/app/Models/Extensions/AlbumCast.php:59)
[stacktrace]
#0 /app/lychee/app/Actions/Albums/Prepare.php(32): App\\Models\\Album->toReturnArray()
#1 /app/lychee/app/Http/Controllers/AlbumsController.php(35): App\\Actions\\Albums\\Prepare->do()
#2 /app/lychee/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\\Http\\Controllers\\AlbumsController->get()
#3 /app/lychee/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction()
#4 /app/lychee/vendor/laravel/framework/src/Illuminate/Routing/Route.php(254): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#5 /app/lychee/vendor/laravel/framework/src/Illuminate/Routing/Route.php(197): Illuminate\\Routing\\Route->runController()
#6 /app/lychee/vendor/laravel/framework/src/Illuminate/Routing/Router.php(692): Illuminate\\Routing\\Route->run()
#7 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#8 /app/lychee/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#9 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#10 /app/lychee/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#11 /app/lychee/app/Http/Middleware/VerifyCsrfToken.php(60): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle()
#12 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\\Http\\Middleware\\VerifyCsrfToken->handle()
#13 /app/lychee/vendor/laravel/framework/src/Illuminate/Session/Middleware/AuthenticateSession.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#14 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Session\\Middleware\\AuthenticateSession->handle()
#15 /app/lychee/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#16 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle()
#17 /app/lychee/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#18 /app/lychee/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(63): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest()
#19 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Session\\Middleware\\StartSession->handle()
#20 /app/lychee/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#21 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle()
#22 /app/lychee/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#23 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle()
#24 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#25 /app/lychee/vendor/laravel/framework/src/Illuminate/Routing/Router.php(694): Illuminate\\Pipeline\\Pipeline->then()
#26 /app/lychee/vendor/laravel/framework/src/Illuminate/Routing/Router.php(669): Illuminate\\Routing\\Router->runRouteWithinStack()
#27 /app/lychee/vendor/laravel/framework/src/Illuminate/Routing/Router.php(635): Illuminate\\Routing\\Router->runRoute()
#28 /app/lychee/vendor/laravel/framework/src/Illuminate/Routing/Router.php(624): Illuminate\\Routing\\Router->dispatchToRoute()
#29 /app/lychee/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(166): Illuminate\\Routing\\Router->dispatch()
#30 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#31 /app/lychee/vendor/bepsvpt/secure-headers/src/SecureHeadersMiddleware.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#32 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Bepsvpt\\SecureHeaders\\SecureHeadersMiddleware->handle()
#33 /app/lychee/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#34 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#35 /app/lychee/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#36 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#37 /app/lychee/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#38 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle()
#39 /app/lychee/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#40 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#41 /app/lychee/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#42 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\\Proxy\\TrustProxies->handle()
#43 /app/lychee/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#44 /app/lychee/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(141): Illuminate\\Pipeline\\Pipeline->then()
#45 /app/lychee/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#46 /app/lychee/public/index.php(74): Illuminate\\Foundation\\Http\\Kernel->handle()
#47 {main}
"} 

Browser and system

Tested in Explorer, Edge, Chrome, Chrome for Android.

ildyria commented 3 years ago

Most likely a migration not applied.

DaneViking commented 3 years ago

Most likely a migration not applied.

I've ran the php artisan migrate but it says Nothing to migrate

ildyria commented 3 years ago

hummmm.

[2021-01-31 22:22:56] production.ERROR: Call to a member function name() on null {"exception":"[object] (Error(code: 0): Call to a member function name() on null at /app/lychee/app/Models/Extensions/AlbumCast.php:59)
[stacktrace]
#0 /app/lychee/app/Actions/Albums/Prepare.php(32): App\\Models\\Album->toReturnArray()

This error means that you have a user_id without its attached user (thus you get null). This should not be happening. :thinking:

Since version 4.2 you should have a user with id 0 in your users table, this corresponds to your admin user.

DaneViking commented 3 years ago

That seems right, which I guess also explains why I don't have any problems with the normal users.

DaneViking commented 3 years ago

Is there any way to fix this manually?

ildyria commented 3 years ago

That user should have been created by the database update, this is why it is very surprising.

  1. Anyway purely via the Database:

    mysql -u <username> -p <database>[ENTER]
    <password>[ENTER]
    INSERT INTO users (username, password) values ('','');
    # this will create a new user
    select * from users;
    # we look for this new user, mostly the id. The user will have no username, no password.
    # below the id is 5. We need to change this id to 0
    # +----+----------+----------+--------+------+----------------+------------+------------+
    # | id | username | password | upload | lock | remember_token | created_at | updated_at |
    # +----+----------+----------+--------+------+----------------+------------+------------+
    # |  5 |          |          |      0 |    0 | NULL           | NULL       | NULL       |
    # +----+----------+----------+--------+------+----------------+------------+------------+
    UPDATE users SET id = 0 where id = 5;
    # now that this is done, just to make sure, we also clean the username password from the config table.
    UPDATE configs SET value = '' where key = 'username';
    UPDATE configs SET value = '' where key = 'password';

    Accessing Lychee should ask you to enter a new admin username and password.

  2. Other possibility

php artisan lychee:reset_admin

This too should work fine hopefully, once again this will ask you to enter a new admin username and password.

DaneViking commented 3 years ago

@ildyria Thanks! (Y)

I'm trying it right now. However, on line

UPDATE users SET id = 0 where id = 5;

it gives an error :

ERROR 1062 (23000): Duplicate entry '0' for key 'PRIMARY'

ildyria commented 3 years ago

O.O this means that you do have a user with id 0.

ildyria commented 3 years ago

I am preparing a new diagnostic script to help.

DaneViking commented 3 years ago

Okay.

I have this output from MariaDB

maridaDB

ildyria commented 3 years ago

yeah you can pretty much delete user with id 12 then. Weird.

I'm going to merge this: https://github.com/LycheeOrg/Lychee/pull/901 It should gives us some more insight (if you can do git pull and artisan migrate).

Sorry that you have to go through this, you have a bug which should definitively not happen.

Edit: merged, you should be able to do git pull or if you cannot, download this file: https://raw.githubusercontent.com/LycheeOrg/Lychee/master/app/Actions/Diagnostics/Checks/MissingUserCheck.php and place it in <pathToLychee>/app/Actions/Diagnostics/Checks/

You should then be able to do php artisan lychee:diagnostics

DaneViking commented 3 years ago

How do I delete the user we jsut created?

I'm sorry I don't know anything about mysql or php!

ildyria commented 3 years ago

No worries.

DELETE FROM users where id = 12;
DaneViking commented 3 years ago

Well..

Progress.. Kind of! It's a steep learning curve when you're not used to the linux terminal and working inside a docker container!

Anyway.

New Diagnostics:

Diagnostics

Warning: Dropbox import not working. dropbox_key is empty. Warning: You may experience problems when uploading a large amount of photos. Take a look in the FAQ for details. Error: A user is missing! Please create a user with id: "3"

System Information

Lychee Version (release): 4.2.1 DB Version: 4.2.1

composer install: --no-dev APP_ENV: production APP_DEBUG: true

System: Linux PHP Version: 7.4 Max uploaded file size: 5000M Max post size: 2000M MySQL Version: 10.4.17-MariaDB-1:10.4.17+maria~bionic-log

Imagick: 1 Imagick Active: 1 Imagick Version: 1802 GD Version: bundled (2.1.0 compatible)

Config Information

version: 040201 check_for_updates: 0 sorting_Photos_col: title sorting_Photos_order: ASC sorting_Albums_col: title sorting_Albums_order: ASC imagick: 1 skip_duplicates: 0 small_max_width: 0 small_max_height: 360 medium_max_width: 1920 medium_max_height: 1080 lang: en layout: 1 image_overlay: 1 image_overlay_type: desc default_license: none compression_quality: 90 full_photo: 1 delete_imported: 0 Mod_Frame: 1 Mod_Frame_refresh: 30 thumb_2x: 1 small_2x: 1 medium_2x: 1 landing_page_enable: 0 landing_owner: John Smith landing_title: John Smith landing_subtitle: Cats, Dogs & Humans Photography landing_facebook: https://www.facebook.com/JohnSmith landing_flickr: https://www.flickr.com/JohnSmith landing_twitter: https://www.twitter.com/JohnSmith landing_instagram: https://instagram.com/JohnSmith landing_youtube: https://www.youtube.com/JohnSmith landing_background: dist/cat.jpg site_title: Lychee v4 site_copyright_enable: 1 site_copyright_begin: 2019 site_copyright_end: 2019 additional_footer_text:
display_social_in_gallery: 0 public_search: 0 SL_enable: 0 SL_for_admin: 0 public_recent: 0 recent_age: 1 public_starred: 0 downloadable: 0 photos_wraparound: 1 map_display: 0 zip64: 1 map_display_public: 0 map_provider: Wikimedia force_32bit_ids: 0 map_include_subalbums: 0 update_check_every_days: 3 has_exiftool: 1 share_button_visible: 0 import_via_symlink: 0 has_ffmpeg: 1 location_decoding: 0 location_decoding_timeout: 30 location_show: 1 location_show_public: 0 rss_enable: 0 rss_recent_days: 7 rss_max_items: 100 prefer_available_xmp_metadata: 0 editor_enabled: 1 lossless_optimization: 0 swipe_tolerance_x: 150 swipe_tolerance_y: 250 local_takestamp_video_formats: .avi|.mov log_max_num_line: 1000 unlock_password_photos_with_url_param: 0 nsfw_visible: 1 nsfw_blur: 0 nsfw_warning: 0 nsfw_warning_admin: 0

ildyria commented 3 years ago

Error: A user is missing! Please create a user with id: "3"

I guess we have our answer. :)

ildyria commented 3 years ago
INSERT INTO users (username, password) values ('wonder-woman','');
# this will create a new user
select * from users;
# we look for this new user, mostly the id. The user will have no username, no password.
# below the id is 5. We need to change this id to 0
# +----+--------------+----------+--------+------+----------------+------------+------------+
# | id | username     | password | upload | lock | remember_token | created_at | updated_at |
# +----+--------------+----------+--------+------+----------------+------------+------------+
# | 13 | wonder-woman |          |      0 |    0 | NULL           | NULL       | NULL       |
# +----+--------------+----------+--------+------+----------------+------------+------------+
UPDATE users SET id = 3 where id = 13;
ildyria commented 3 years ago

Progress.. Kind of! It's a steep learning curve when you're not used to the linux terminal and working inside a docker container!

Congrats on that one. :fearful:

DaneViking commented 3 years ago

Well.

I was finally able to log in again.

Can I delete the user 3 now?

ildyria commented 3 years ago

If you delete the albums that user 3 own, yes.

Otherwise you can transfer ownership to admin manually

UPDATE albums SET owner_id = 0 where owner_id = 3;
UPDATE photos SET owner_id = 0 where owner_id = 3;

or directly via the GUI by creating an album A that is owned by admin and then moving the album owned by user 3 to that album A. This will trigger a ownership change to the owner of A.

Once there is no album owned by 3, then you can delete it. Otherwise you will be facing the same bug again.

DaneViking commented 3 years ago

Well, that's strange.

I just did the

UPDATE albums SET owner_id = 0 where owner_id = 3; UPDATE photos SET owner_id = 0 where owner_id = 3;

and i got moved some albums arround to user 0 that in the DB-list should be owned by ID 1.

Is it possible to select which albums should be owned by certain users?

ildyria commented 3 years ago

By the way, thank you for lighting this bug up. :)

ildyria commented 3 years ago

and i got moved some albums around to user 0 that in the DB-list should be owned by ID 1.

Dafuck. O.o

Is it possible to select which albums should be owned by certain users?

This will show you all the albums owned by user 6.

SELECT id, title FROM albums WHERE owner_id = 6;
# +------------+-----------+
# | id         | title     |
# +------------+-----------+
# | 1470501689 | Polynesie |
# +------------+-----------+
DaneViking commented 3 years ago

Okay.

So, "Wonder-woman" is dead and gone! (Y)

user id = 1 --> doesn't have any albums any more.

user id = 0 --> now owns every album on the server.

Is there a way to change the ownership of the album to a different user ID?

ildyria commented 3 years ago

This should do the trick

UPDATE albums SET owner_id = <desired owner_id> WHERE id = <album_id>;

I'm still surprised that the albums from user 1 got changed to user 0 especially given that it worked fine on my end:

UPDATE albums SET owner_id = 0 WHERE owner_id = 15;
# Query OK, 1 row affected (0.006 sec)
# Rows matched: 1  Changed: 1  Warnings: 0
DaneViking commented 3 years ago

Without the brackets <> it worked fine.

Now I think every album is back to the right user.

I haven't really started using the software yet, so my own files was just for testing purpose. However, my aunt have used it quite a bit, so to tell her to upload and rename every file again would not have been fun!

ildyria commented 3 years ago

I can imagine. :)

ildyria commented 3 years ago

Can we close this issue now?

DaneViking commented 3 years ago

Yep!

DaneViking commented 3 years ago

Can we close this issue now?

@ildyria I was trying to figure out why this happend, and IIRC I actually created a user with the same name as the admin user, but with a different password. The issue might have started when I deleted that user. Then something must have happend with the database.

I think that's why it happend, but I'm not sure. Perhaps something to investigate in the future! :)