Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try to display a custom logo or favicon if they don't exist #9966

Closed
ksubileau opened this issue Mar 27, 2016 · 11 comments
Closed

Don't try to display a custom logo or favicon if they don't exist #9966

ksubileau opened this issue Mar 27, 2016 · 11 comments
Labels
answered For when a question was asked and we referred to forum or answered it. Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.

Comments

@ksubileau
Copy link
Contributor

Hi,
In the general settings page, under the branding settings (Administration > General Settings > Branding), when no custom logo or favicon has never been used, Piwik generates two requests to missing files (/misc/user/logo.png and /misc/user/favicon.png) and displays broken image icons:
piwik-broken-image
As we can see in this template file at lines 214 and 220, there is indeed no check on the actual existence of these files : the img tag is always generated.

I think Piwik should verify the existence of the logo and favicon files to prevent Web browsers to attempt to access a missing file.

By the way, we can see that the server returns in this case a 403 error instead of 404, probably because of the .htaccess file inside the misc directory, which denies access to all files by default.
piwik-broken-image-2

@tsteur
Copy link
Member

tsteur commented Mar 29, 2016

By the way, we can see that the server returns in this case a 403 error instead of 404, probably because of the .htaccess file inside the misc directory, which denies access to all files by default.

Are you using Apache? The .htaccess should specifically allow these files in misc/user.

@tsteur
Copy link
Member

tsteur commented Mar 29, 2016

Also the files should exist by default unless they were deleted.

@ksubileau
Copy link
Contributor Author

Yes I'm using Apache. I have an .htaccess file under the misc folder with the following content, which cause the 403 error :

<Files "*">
<IfModule mod_access.c>
Deny from all
</IfModule>
<IfModule !mod_access_compat>
<IfModule mod_authz_host.c>
Deny from all
</IfModule>
</IfModule>
<IfModule mod_access_compat>
Deny from all
</IfModule>
</Files>

It seems that the current code does not generate this file in this folder (Should it?), but I don't remember having created it manually. Maybe it's a relic of an older version, as the initial installation on my server goes back to December 2012 and was updated regularly until the current version.

Anyway, this isn't the main subject for which I opened this issue :) If I remove this .htaccess file, I still get a 404 error because Piwik tries to load the images even if they don't exist.

You say that they should exist by default, but from where should they come from ? I don't see them either on the repository nor in the downloadable archive. Are they generated or copied at setup time ?
AFAIK they are created only the first time the user configures a custom logo or favicon, isn't it ?

ksubileau added a commit to ksubileau/piwik that referenced this issue Mar 29, 2016
…if they don't exist

Prevents 404 errors.
@tsteur
Copy link
Member

tsteur commented Mar 29, 2016

True, they actually don't exist. I forgot that I had custom logo uploaded.

I presume the problem is, when not showing the <img> and then uploading an image, the instant preview would not work. So we also need to update JavaScript to create this image element in case it is not there or solve it differently.

@ksubileau
Copy link
Contributor Author

You're right, I forgot the JS. The instant preview is broken with the commit mentioned above.
The image source is fetched from the srcattribute, so it's not so easy indeed.

Maybe we could always create the <img>tag with a data-src attribute giving the image path (without the cache buster), and generate the srcattribute on server-side if the images exists or on client-side after an upload (based on the path given by the data-src attribute) ?

Thus we avoid depend on another element to generate and position the images.

This would give a template line like this :

<img data-src="{{ pathUserFavicon }}" {% if hasUserFavicon %}src="{{ pathUserFavicon }}?r={{ random() }}"{% endif %} id="currentFavicon" width="16" height="16"/>

@mattab
Copy link
Member

mattab commented Mar 31, 2016

Hi @ksubileau if you can test it, and create a Pull request, we would be glad to investigate and merge it!

@mattab mattab added the Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change. label Mar 31, 2016
@mattab mattab added this to the Mid term milestone Mar 31, 2016
@tsteur
Copy link
Member

tsteur commented Mar 31, 2016

@ksubileau sounds like a good idea 👍

ksubileau added a commit to ksubileau/piwik that referenced this issue Apr 2, 2016
ksubileau added a commit to ksubileau/piwik that referenced this issue Apr 5, 2016
@trusteddigital
Copy link

How about the 403 error. I actually have uploaded the images but it doesn't show them because it's showing the 403. Has one of the htaccess files been kept from a previous version but it no longer needed? There's one in /misc/user/ but also one in /misc/ which dates back to 07/08/2013 in my installation. Should this be modified or deleted?

@trusteddigital
Copy link

I've answered my own question. On the current repository, neither of these .htaccess files exist so I'll remove both for now.

@tsteur
Copy link
Member

tsteur commented Apr 6, 2016

It's possible that some files were not writable in that directory and then it couldn't update or remove an .htaccess file. The updater does - I think - not show an error in this case.

@ksubileau
Copy link
Contributor Author

@trusteddigital The .htaccess file under /misc/user is generated at setup and upgrade times by the ServerFilesGenerator class
But as I said earlier, it seems that the .htaccess file of the misc folder is a relic of an older version. The fact that you also have this file causing the same 403 errors seems to confirm this hypothesis.

ksubileau added a commit to ksubileau/piwik that referenced this issue Apr 9, 2016
@tsteur tsteur closed this as completed in 120a7f7 Apr 11, 2016
@mattab mattab added the answered For when a question was asked and we referred to forum or answered it. label Oct 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it. Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.
Projects
None yet
Development

No branches or pull requests

4 participants