How to connect to new Tribler WebUI from other devices/other issues

After downloading the new 8.0.5 update, it forced me into a WebUI. To be fair I’ve been wanting a WebUI for quite some time now, but didn’t expect it to be so forced and sudden. Anyway, all my downloads are now gone and I don’t know how to restore them. Also, how do I connect to the WebUI from other devices? Every time I try to connect it says unable to connect. It works fine in my browser window on the machine running Tribler though. But first and foremost I need to know if there’s still a way to convert the old downloads I had into this new UI or if they’re gone forever.

2 Likes

OK, my downloads have all been restored, now I want to figure out if there’s a way to connect to the WebUI from other devices, e.g. on a LAN network, so I could use Ubuntu Server instead of Ubuntu Desktop for better performance. I want to figure out how to 1. make it use the same port every time 2. start it from the command line 3. open it up for other devices to connect to it

1 Like

How you have restored downloads?

1 Like

I honestly don’t know. I went into settings >> versions, then clicked 7.14 and clicked import. I waited a bit but it seemed like it wasn’t doing anything. In frustration, I closed the Web UI and left my computer running (because I have other stuff running on it other than Tribler). At the end of the day, I shut it off and when I turned it on the next day, everything was there. My guess is it either takes a really long time for everything to import into the new version, or the web ui has some sort of bug that prevents it from working correctly until the entire importing process is done. Either way, it seems to be working fine now, I guess I just had to give it some time.

1 Like

Hey @davidgordiienko, the change you’re looking for is not in the WebUI, rather in the configuration.json file :slight_smile:

For me on linux, this is ~/.Tribler/8.0/configuration.json
The field looks like this:

{
    "api":
        "http_enabled": true,
        "http_port": 46807,
        "http_host": "<enter new IP address here>",
...
}
1 Like

Also, you’d want to launch Tribler as so

/usr/share/tribler/tribler --server

Otherwise it will crash on a headless system

2 Likes

Full disclosure from my testing, there appears to be some local cookie Tribler passes to the browser it calls. Connecting from external hosts produces this error:
image

1 Like

You need to add ?key(insert api key from configuration.json here) at the end of the URL so it would be something like [your IP and port]/ui/#/downloads/all?key=[your key]

1 Like

I have some questions about running it the headless way

  1. How do you stop it
  2. If using SSH, do you need to keep the terminal window open/how to make it so that you don’t have to keep it open
  3. Is there a way to make it not output as much/as often or clean it up a bit/less verbose?
1 Like

Hi Sachiko

below is a configuration with Apache reverse-proxy:

RewriteEngine on
RewriteRule "^/$" "/ui/#/downloads/all?key=YOUR_KEY" [QSA,P]
Header set Set-Cookie "api_key=YOUR_KEY"
ProxyPass http://127.0.0.1:8085/
ProxyPassReverse http://127.0.0.1:8085/

Here i use Apache => local Tribler in docker

If anyone can find a lighter configuration, I’d love to hear from you.

3 Likes

Maybe you should create an independent thread to ask your questions davidgordiienko.

As said above I use docker, and I don’t have to worry about Tribler screen output.

1 Like

For point 1, I have opened a new thread to get an answer to the question. For now, I accept the process kill given the infrequency of shutdown calls I make.
Tribler can be run without first opening a terminal by creating a user (or global) systemd unit. For user systemd units, it requires:

sudo loginctl enable-linger <user>

The other advantage of a systemd unit is that the logging gets written to journald, and you’d have an easier time filtering it there

2 Likes

Hi everyone

Due to the lack of documentation, perhaps we should create a tutorial here bringing together all the info on how to get Tribler headless working properly with or without docker?

Maybe a tutorial category in the forum would be useful?

https://forum.tribler.org/t/how-to-run-tribler-entirely-through-cli/7340/3

2 Likes

Once I am able to verify the systemd unit works as expected. I’d be happy to contribute. The main blocker is the API key requirement when connecting externally. While suitable for a docker container (particularly with a Dockerfile), getting apache installed and configured outside of that introduces complexity not only for us, but also Windows users (although you could argue they’re unlikely to require something like this). One of there two options would be preferable from the Tribler team.

  • Treat blank API key as equal to disabling authentication; or;
  • Create auth_method key, defaulting to ‘cookie’, also accepting ‘basicauth’ + http_user & http_password
1 Like

The UI listen on 127.0.0.1 on your host B (or does it listen on 0.0.0.0?).

If you don’t want to use a reverse-proxy web service, you can create an SSH tunnel.
It’s not the most practical, but it works …

hostA:~ $ ssh hostB -L hostA_local_port:127.0.0.1:hostB_local_port -N -f
# -L Port forwardings tunnel
# -N Do not execute a remote command
# -f Go to background

Then http://127.0.0.1:hostA_local_port/ui/#/downloads/all?key=YOUR_KEY in your browser.

Well, it won’t help Windows users, but let me know if it does the job for you @Sachiko

1 Like

Hey! ごめんね for the delay in my response! I’m currently working on the postinit script for the .deb build. What do you think of this? ٩(◕‿◕。)۶

#!/bin/sh
set -e

deb_config() {
    . /usr/share/debconf/confmodule

    db_get tribler-headless-unofficial/ip_address
    TRIBLER_IP="$RET"

    db_get tribler-headless-unofficial/enable_auth
    APACHE_AUTH="$RET"

    if [ "$APACHE_AUTH" = "true" ]; then
        db_get tribler-headless-unofficial/auth_username
        APACHE_AUTH_USER="$RET"
        db_get tribler-headless-unofficial/auth_password
        APACHE_AUTH_PWD="$RET"
    fi

    db_get tribler-headless-unofficial/service_user
    INSTALL_USER="$RET"
    INSTALL_USER_HOME="$(getent passwd $INSTALL_USER | cut -d: -f6)"

    db_get tribler-headless-unofficial/tribler_user
    TRIBLER_USER="$RET"
    TRIBLER_USER_HOME="$(getent passwd $TRIBLER_USER | cut -d: -f6)"
}

main() {
    deb_config

    # Copy systemd unit
    if [ "$INSTALL_USER" = "root" ]; then
        cp "/usr/share/tribler-headless-unofficial/global.systemd" "/etc/systemd/system/tribler-headless-unofficial.service"
    else
        mkdir -p "${INSTALL_USER_HOME}/.config/systemd/user/"
        cp "/usr/share/tribler-headless-unofficial/user.systemd" "${INSTALL_USER_HOME}/.config/systemd/user/tribler-headless-unofficial.service"
        chown $INSTALL_USER:$INSTALL_USER "${INSTALL_USER_HOME}/.config/systemd/user/tribler-headless-unofficial.service"
    fi

    # Load Apache config
    cp "/usr/share/tribler-headless-unofficial/tribler-headless-unofficial.conf" "/etc/apache2/sites-available/tribler-headless-unofficial.conf"

    # Determine latest Tribler version
    TRIBLER_VERSION=$(find "${TRIBLER_USER_HOME}/.Tribler" -maxdepth 1 -type d -name '[0-9\.]*' | sort -V | tail -n 1)

    # Load Tribler API Key and IP into Apache site config
    API_KEY=$(grep -m1 -oP '"key":\s*"\K[^"]*' "${TRIBLER_USER_HOME}/.Tribler/${TRIBLER_VERSION}/configuration.json")
    sed -i -e "s/API_KEY/${API_KEY:-API_KEY}/g" -e "s/IP_ADDRESS/${TRIBLER_IP:-IP_ADDRESS}/g" /etc/apache2/sites-available/tribler-headless-unofficial.conf

    # Enable Apache site
    a2ensite tribler-headless-unofficial.conf

    # Enable and start Apache service
    systemctl enable apache2
    systemctl restart apache2

    # Enable tribler-headless-unofficial service
    if [ "$INSTALL_USER" = "root" ]; then
        systemctl enable tribler-headless-unofficial.service
        systemctl start tribler-headless-unofficial.service
    else
        loginctl enable-linger "$INSTALL_USER"
        su - "$INSTALL_USER" -c "systemctl --user enable tribler-headless-unofficial.service"
        su - "$INSTALL_USER" -c "systemctl --user start tribler-headless-unofficial.service"
    fi
}

main || $(echo PURGE | debconf-communicate tribler-headless-unofficial)

2 Likes

I used your Apache reverse proxy config as part of this, so I’ll make sure to credit you! Thanks! (≧▽≦)

1 Like

Wow, there’s a lot to say.

Hats off, I’ve never tried to create a postinit to a .DEB.
I’m used to working with bash, so maybe some of my misunderstanding comes from the fact that you use SH.
For example, instead of

    db_get tribler-headless-unofficial/ip_address
    TRIBLER_IP="$RET"

I would have used

TRIBLER_IP=$( db_get tribler-headless-unofficial/ip_address )

But that’s not important.
And i have no idea what “db_get” stands for.

Great job!

1 Like

やった!I finished working on the .deb, and it works as I hoped! (≧▽≦) But there’s no support for Docker because of the systemd dependency. The API key loads when you navigate to the base URL. You can check out the code and .deb here: GitHub - Sachiko-chan/Tribler-Headless-Unofficial: Headless Tribler via .deb

2 Likes

By the way, my friend - he’s an assistant system admin - got his friend to publish the tool he shared with me! I think it’s very useful for making the .deb (°◡°♡) Let’s check it out! The Firehawk / DebBuilder Container · GitLab

1 Like