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

Accessing WEB UI only downloads an html template but does not display it #21363

Open
argonan0 opened this issue Sep 19, 2024 · 29 comments · May be fixed by #21382
Open

Accessing WEB UI only downloads an html template but does not display it #21363

argonan0 opened this issue Sep 19, 2024 · 29 comments · May be fixed by #21382
Labels
Waiting info Waiting for participants to supply more info/fulfill template requirements WebUI WebUI-related issues/changes

Comments

@argonan0
Copy link

argonan0 commented Sep 19, 2024

qBittorrent & operating system versions

qBittorrent: 4.6.7 x64
Operating system: Ubuntu 24.04.1 LTS
Qt: 5.15.13
libtorrent-rasterbar: 2.0.11

What is the problem?

I upgraded from 4.5.5 to 4.6.7 and the Web UI was working before the upgrade. Now, when attempting to access the IP:Port, the browser (Firefox or Chrome) prompt to download a file instead of displaying the contents.

Steps to reproduce

Access the Web UI in a browser

Additional context

This is the contents of the downloaded file:

<!DOCTYPE html>
<html lang="${LANG}">

<head>
    <meta charset="UTF-8" />
    <title>qBittorrent QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]</title>
    <link rel="icon" type="image/png" href="images/qbittorrent32.png" />
    <link rel="icon" type="image/svg+xml" href="images/qbittorrent-tray.svg" />
    <link rel="stylesheet" type="text/css" href="css/login.css?v=${CACHEID}" />
    <noscript>
        <link rel="stylesheet" type="text/css" href="css/noscript.css?v=${CACHEID}" />
    </noscript>
    <script src="scripts/login.js?locale=${LANG}&v=${CACHEID}"></script>
</head>

<body>
    <noscript id="noscript">
        <h1>QBT_TR(JavaScript Required! You must enable JavaScript for the Web UI to work properly)QBT_TR[CONTEXT=HttpServer]</h1>
    </noscript>
    <div id="main">
        <h1>qBittorrent QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]</h1>
        <div id="logo" class="col">
            <img src="images/qbittorrent-tray.svg" alt="qBittorrent logo" />
        </div>
        <div id="formplace" class="col">
            <form id="loginform" method="post" onsubmit="submitLoginForm(event);">
                <div class="row">
                    <label for="username">QBT_TR(Username)QBT_TR[CONTEXT=HttpServer]</label><br />
                    <input type="text" id="username" name="username" autocomplete="username" required />
                </div>
                <div class="row">
                    <label for="password">QBT_TR(Password)QBT_TR[CONTEXT=HttpServer]</label><br />
                    <input type="password" id="password" name="password" autocomplete="current-password" required />
                </div>
                <div class="row">
                    <input type="submit" id="login" value="QBT_TR(Login)QBT_TR[CONTEXT=HttpServer]" />
                </div>
            </form>
        </div>
        <div id="error_msg"></div>
    </div>
</body>

</html>
@thalieht thalieht added the WebUI WebUI-related issues/changes label Sep 19, 2024
@HanabishiRecca
Copy link
Contributor

Do you have shared-mime-info package installed?

@argonan0
Copy link
Author

Do you have shared-mime-info package installed?

Yes
shared-mime-info is version (2.4-4)
Should I?

@HanabishiRecca
Copy link
Contributor

Yes. Such problem usually happen when it's not present.

But it also could be a corrupted mime database. Try to regenerate it:

# update-mime-database /usr/share/mime

(Need to be run as root.)

@luzpaz luzpaz added the Waiting info Waiting for participants to supply more info/fulfill template requirements label Sep 20, 2024
@argonan0
Copy link
Author

Yes. Such problem usually happen when it's not present.

But it also could be a corrupted mime database. Try to regenerate it:

# update-mime-database /usr/share/mime

(Need to be run as root.)

Ok I ran that as root (no output). Would I need to restart qBittorrent to see if it worked? So far it's the same result.

@HanabishiRecca
Copy link
Contributor

HanabishiRecca commented Sep 20, 2024

Would I need to restart qBittorrent to see if it worked?

I would say even reboot to be sure.

If it won't help, well, I have no other ideas for now.

@argonan0
Copy link
Author

Would I need to restart qBittorrent to see if it worked?

I would say even reboot to be sure.

If it won't help, well, I have no other ideas for now.

I rebooted but the result is the same when using IP:Port (downloads template without the variables replaced)

@glassez
Copy link
Member

glassez commented Sep 21, 2024

Maybe you'll find something useful in #15316.

@argonan0
Copy link
Author

argonan0 commented Sep 21, 2024

Indeed that is a duplicate, or rather, mine is recurrence of that issue: #15316

I have no idea what mimes have got to do with it but this did get it working:

#!/bin/bash

# Navigate to the mime packages directory
cd ~/.local/share/mime/packages

# Search for files referencing 'x-extension-html'
files=$(grep -l 'x-extension-html' *)

# If files are found, remove them
if [ -n "$files" ]; then
  echo "Removing files referencing 'x-extension-html':"
  echo "$files"
  rm $files
else
  echo "No files referencing 'x-extension-html' found."
fi

# Update the mime database
update-mime-database ~/.local/share/mime

@HanabishiRecca
Copy link
Contributor

Close?

@argonan0
Copy link
Author

Close?

I mean... this seems like something qBittorrent should check and correct since it breaks a function of qBittorrent so I wouldn't close it only with the workaround in mind. It's a 'solution' to the problem but the root cause of the bug is unknown and not addressed.

@glassez
Copy link
Member

glassez commented Sep 23, 2024

It's a 'solution' to the problem but the root cause of the bug is unknown and not addressed.

The root of the problem is corrupted/misconfigured mime database, isn't it?

@HanabishiRecca
Copy link
Contributor

HanabishiRecca commented Sep 23, 2024

qBittorrent should check and correct

No it should not. That's not a qBittorent bug.

In fact, that's not a bug at all. Such configuration could be intentional, maybe user wants to override how html works in their system. The client should not make such decisions and tweak random stuff in the system without asking the user.

And from technical side, there are endless ways users can bork their systems, we can't account for everything anyway.

P.S. My systems don't even have ~/.local/share/mime. So I guess it is created due to user or some software manipulating with file/protocol associations intentionally.

@argonan0
Copy link
Author

What I can tell you is that on 4.5.5 the web UI was working. After updating, it wasn't. Why did that happen? Anybody's guess. I have no idea what ~/.local/share/mime even is so I don't think I intentionally did anything with it. Why aren't the web UI files for qBittorrent stored in a local qBittorrent storage space so they can't get mucked with?

If you both think it's not a bug, you would know better but to me it seems like there's room for improvement here. The system shouldn't be able to adversely affect an otherwise functional qBittorrent installation.

@HanabishiRecca
Copy link
Contributor

HanabishiRecca commented Sep 23, 2024

What I can tell you is that on 4.5.5 the web UI was working. After updating, it wasn't. Why did that happen? Anybody's guess.

qBittorrent always worked that way. As you can see, #15316 is from 2021 (something around 4.3.x version).
Considering that you are using Ubuntu, I'd guess that was a part of full system upgrade. If so, obviously something else might have changed.

The system shouldn't be able to adversely affect

qBittorent does not control that behavior in any way.
It's a Qt framework quirk. shared-mime-info package is a Qt (libqt5core5t64) dependency. Report it to Qt upstream if you want.

@HanabishiRecca
Copy link
Contributor

HanabishiRecca commented Sep 23, 2024

@glassez, do you think we should circumvent the mime database?

const QMimeType mimeType = QMimeDatabase().mimeTypeForFileNameAndData(path.data(), data);

At least hardcoding a few well known mime types (say text/html, text/javascript, text/css) sounds like it might be actually a good idea. And use the mime database for the rest.

We are not a generic web server after all.

@glassez
Copy link
Member

glassez commented Sep 23, 2024

At least hardcoding a few well known mime types (say text/html, text/javascript, text/css) sounds like it might be actually a good idea. And use the mime database for the rest.

Agree.
We could do it for all the types used by built-in WebUI.

@HanabishiRecca
Copy link
Contributor

We could do it for all the types used by built-in WebUI.

There are alternative WebUIs though, where we can't know everything ahead of time.

@glassez
Copy link
Member

glassez commented Sep 23, 2024

We could do it for all the types used by built-in WebUI.

There are alternative WebUIs though, where we can't know everything ahead of time.

Sorry, what's the problem? From your suggestion:

And use the mime database for the rest.

@glassez
Copy link
Member

glassez commented Sep 23, 2024

I meant that we could do it for all the types used by built-in WebUI, besides the ones you listed above.

@HanabishiRecca
Copy link
Contributor

No problem. I thought you mean to hardcode everything and drop the mime database completely.
Yes, the list was arbitrary, we definitely can make more built-ins. Less database lookups also should improve performance.

Btw, arguably first part of this function should be removed:

QString Path::extension() const
{
const QString suffix = QMimeDatabase().suffixForFileName(m_pathStr);
if (!suffix.isEmpty())
return (u"." + suffix);
const int slashIndex = m_pathStr.lastIndexOf(u'/');
const auto filename = QStringView(m_pathStr).mid(slashIndex + 1);
const int dotIndex = filename.lastIndexOf(u'.', -2);
return ((dotIndex == -1) ? QString() : filename.mid(dotIndex).toString());
}

@glassez
Copy link
Member

glassez commented Sep 23, 2024

I thought you mean to hardcode everything and drop the mime database completely.

"Types used by built-in WebUI" doesn't sound like "everything", IMO. It's strange that you interpreted it that way.
Besides, if I wanted to say "everything", I would most likely say "everything", since it is much shorter. 😀

@glassez
Copy link
Member

glassez commented Sep 23, 2024

Btw, arguably first part of this function should be removed:

It's a bad idea to suggest removing the code without knowing its purpose...
FYI, it allows you to correctly detect the complex extensions like tar.gz.

@glassez
Copy link
Member

glassez commented Sep 23, 2024

I don't fight against using mime database. IMO, it's a good idea to use things like this.
We just want to work around some possible problems on the user's side a little bit. As I can suppose, the problem is not with incorrectly detected file extensions but with broken mime types registered for some file extensions (because this data is allowed to be overridden on the user side, AFAIK).

@HanabishiRecca
Copy link
Contributor

HanabishiRecca commented Sep 23, 2024

It's a bad idea to suggest removing the code without knowing its purpose...

Why do you think I would suggest to remove the code without knowing its purpose?

FYI, it allows you to correctly detect the complex extensions like tar.gz.

Exactly. But we never serve them, so why need the code?
And even if we did, no browser actually cares about difference between application/gzip and application/x-compressed-tar. In fact, the latter is not even part of the web standard.

As I can suppose, the problem is not with incorrectly detected file extensions but with broken mime types registered for some file extensions (because this data is allowed to be overridden on the user side, AFAIK).

Yes. Some other software redefines mime type for .html files.

@HanabishiRecca
Copy link
Contributor

so why need the code?

I also inspected all uses of extension() method through the codebase, but found no places where it would make a difference.

@glassez
Copy link
Member

glassez commented Sep 23, 2024

It's a bad idea to suggest removing the code without knowing its purpose...

Why do you think I would suggest to remove the code without knowing its purpose?

I'm sorry if it looked rude. You suggested removing this code without any arguments in favor of such action.

so why need the code?

I also inspected all uses of extension() method through the codebase, but found no places where it would make a difference.

As far as I remember, its main place of use is AutoExpandableDialog::getText() where it is used to correctly pre-select filename without extension.
We can implement custom extension(Path) helper to be used for mime type detection purposes within web server implementation.
Of course we can put such advanced variant of extension detection in AutoExpandableDialog implementation and have simple one as generic Path::extension(). The question is which of these options is really considered to be seen as "core" Path::extension() implementation.

@HanabishiRecca
Copy link
Contributor

As far as I remember, its main place of use is AutoExpandableDialog::getText() where it is used to correctly pre-select filename without extension.

Yeah, I've seen that. If you think it's useful, sure.
Fun fact that in the WebUI it is implemented in a simple way.

The question is which of these options is really considered to be seen as "core" Path::extension() implementation.

I think the base implementation implies to be simple. It also removes overhead from accessing the database when it's not needed.

@glassez
Copy link
Member

glassez commented Sep 23, 2024

I think the base implementation implies to be simple

Agree (in this case).

@HanabishiRecca HanabishiRecca linked a pull request Sep 23, 2024 that will close this issue
@HanabishiRecca
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting info Waiting for participants to supply more info/fulfill template requirements WebUI WebUI-related issues/changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants