Development log: 2022-10-12

2022 October 12

One limitation of Discourse is that while it allows users to upload
images, it provides no such capability for video, audio, or files one
wishes to allow to be downloaded.  You can embed media files simply
by specifying the URL, but in order to do so, you need to host the
file on another server whose URL you can embed.  This is a real bother,
since hosting a short video on YouTube is a lot of work and there are
few places that provide free hosting of other media and files.  To
remedy this, I thought I'd try setting up an Apache server on the
Scanalyst host, running alongside the Nginx server that runs Discourse,
with the Apache server using alternative ports for http: and https:

Installed:
    yum install httpd
    yum install mod_ssl

Edited:
    /etc/httpd/conf
    /etc/httpd/conf.d/ssl.conf
to configure as for fourmilab.ch, but with port 8008 for http: and
port 591 for https:.  These are ports reserved for http-alt by IANA.
For the SSL configuration, we use the same secret key and certificate
chain as the Nginx server for Discourse.
    SSLCertificateFile /var/discourse/shared/standalone/ssl/scanalyst.fourmilab.ch.cer
    SSLCertificateKeyFile /var/discourse/shared/standalone/ssl/scanalyst.fourmilab.ch.key
These files are updated automatically by the Letsencrypt cron job run
by Discourse.

The Apache server is configured to log in /server/log/httpd just as on
Fourmilab.ch.

Set up a place holder index.html in:
    /var/www/html
to identify the server and deter trawling for content by directory
scanning.

Created content directories in the Web server root:
    audio
    images
    video

Started the Apache server and everything worked the first time.  My
pathfinder test URL:
    https://scanalyst.fourmilab.ch:591/video/f9_from_drone_ship_2022-10-12.mp4
came up in the browser with no problems.

Tried an embed in a Sand Box post on Scanalyst and fell into a pot of
soup which consumed the rest of the day.  This is a summary as I posted
on the Discourse support forum.
    https://meta.discourse.org/t/cannot-use-port-number-in-url-to-embed-media-in-post/241742

    TITLE: Cannot use port number in URL to embed media in post

    In order to allow my users to host videos, audio files, etc. that
    they embed in Discourse posts, I have set up an Apache server
    running alongside the Nginx that runs Discourse. The Apache server
    runs on port 8008 for http: and port 591 for https: (IANA ports
    reserved for http-alt). This works fine and content on the server
    is accessible from browsers by specifying the port number in the
    URL, for example:

        https://scanalyst.fourmilab.ch:591/video/f9_from_drone_ship_2022-10-12.mp4

    But if you try to embed this URL in a Discourse post, it fails
    with:

        Sorry, we were unable to generate a preview for this web page,
        because the server ‘scanalyst.fourmilab.ch’ could not be found.
        Instead of a preview, only a link will appear in your post.

    If I run tcpdump and monitor DNS traffic, I see nothing being sent
    when it rejects this URL. It is rejecting it without ever making a
    DNS query. If I change the port number in the URL to 443, the
    default for https:, it makes the DNS query normally but the embed
    fails, of course, because the Apache server is not listening on
    that port and the Discourse server does not know what to do with
    the URL. I have seen nothing in the Discourse documentation that
    indicates embed URLs may not specify a port number.

    Looking through the source code, I found a test in function
    validate_uri_format at line 362 of lib/final_destination.rb which
    reads:
        return false if @uri.scheme == 'https' && @uri.port != 443
    which appears to reject an https: URL that uses a port other than
    443. This seemed to explain what I was seeing, so I commented out
    this line, but it made no difference at all, even after I restarted
    Discourse. When the post appears on the site with the embed turned
    into a text link, clicking the text link shows the video correctly,
    so the only problem is failing to recognise it as an embed and
    wrapping the inline player around it.

    My questions are, at this point:

        * Are non-standard port numbers intended to work on URLs for
          embeds in Discourse posts?
        * If so, what is causing these URLs to be rejected?
        * Is there any way to get them to work?

    There was a discussion here in March 2017 about this issue in these
    two posts:

        * Specifying port for embeddable host given an IP results in
          error
            https://meta.discourse.org/t/specifying-port-for-embeddable-host-given-an-ip-results-in-error/59209
        * FIX: Allow ports for embed host IPs #4759 (on GitHub)
            https://github.com/discourse/discourse/pull/4759

    which implied the problem had been fixed, but it does not work today on 2.9.0.beta10.

I'll see what comes of this.  At the moment, I'm stumped.

Ruby source code is in:
    /var/lib/docker/overlay2/LONG_SERIES_OF_HEX_NUMBERS/merged/var/www/discourse/

To dump DNS traffic, including ASCII packet contents, use:
    tcpdump -i eth0 -n -s1500 -vvv -t -X port 53

To list Discourse log:
    cd ~/discourse/image
    super
    ./launcher logs app

To view internal log, sign on as Administrator, then:
    https://scanalyst.fourmilab.ch/logs/
2 Likes