[Solved] Disabling Mythweb Usage of CDN

For discussion related to MythTV which doesn't belong in another forum.

Moderator: Forum Moderators

Post Reply
rds55
Newcomer
Posts: 3
Joined: Thu Jul 18, 2019 9:56 pm
United States of America

[Solved] Disabling Mythweb Usage of CDN

Post by rds55 »

As distributed MythWeb uses Content Delivery Network or CDN to deliver a couple of JavaScript's from a well known source. For many reasons this has always annoyed me & since adding a PiHole regex blacklist for anything 'google' MythWeb no longer works correctly. Yeah I could setup a whitelist for this but I finally decided to dive into MythWeb & change its behavior.

While searching around the Web I found this Fixes #13191 - Make mythweb use of CDN optional. · MythTV ... which eludes to a solution but it does not appear to be fully implemented and I could not find any documentation about it. I tried setting the 'mythweb_use_cd' variable to false but could not get MythWeb to load from the local source. Also, the standard MythWeb installation does not create the specified locations or provide the 2 needed files.

So my fix to this issue is to comment out the use of the 'mythweb_use_cd' variable forcing MythWeb to load these files from the local location specified. To support this we need to create the appropriate directories containing our 2 needed files.

Since this is my first post I'm blocked from making any links & using certain terms so you'll have search on what wants to be a link above and replace the x's where necessary in the following code. This will become obvious when editing the listed file.

You'll need to SSH into your MythTV back-end & perform the following tasks:

First we need to comment these lines from the file:

Code: Select all

sudo nano /usr/share/mythtv/mythweb/modules/_shared/tmpl/default/header.php
like so:

Code: Select all

<?php 
//    if (setting('mythweb_use_cdn', null)) 
//    { 
//	    print "<script src=\"https://ajax.xxxxxxxxx.xxx/ajax/libs/prototype/1.7.3.0/prototype.js\"></script>";
//	    print "<script src=\"https://ajax.xxxxxxxxx.xxx/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>"; 
//    } 
//    else 
//    { 
        print "<script type=\"text/javascript\" src=\"js/ajax/libs/prototype/1.7.3.0/prototype.jx\"></script>"; 
        print "<script type=\"text/javascript\" src=\"js/ajax/libs/jquery/3.2.1/jquery.min.jx\"></script>"; 
//    } 
?>
and save the file.

Next we need to make a matching directory structure to copy our java scripts into. We could place these files anywhere but why not just use the locations already defined in 'header.php':

Code: Select all

sudo mkdir -p /usr/share/mythtv/mythweb/js/ajax/libs/prototype/1.7.3.0/
sudo mkdir -p /usr/share/mythtv/mythweb/js/ajax/libs/jquery/3.2.1/
Finally download the files saving them into the directory locations created above:

Code: Select all

wget https://ajax.xxxxxxxxxx.xxx/ajax/libs/prototype/1.7.3.0/prototype.js
wget https://ajax.xxxxxxxxxx.xxx/ajax/libs/jquery/3.2.1/jquery.min.js
sudo cp prototype.js /usr/share/mythtv/mythweb/js/ajax/libs/jquery/3.2.1/prototype.js
sudo cp jquery.min.js /usr/share/mythtv/mythweb/js/ajax/libs/prototype/1.7.3.0/jquery.min.js
Of course if you're blocking google you'll have to temporarily enable access to get these files.
Now we're good to go!
I've seen this issue come up a few times so just thought I'd share my solution.
Long time user - thanks to all the developers ...
User avatar
bill6502
Developer
Posts: 2325
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Disabling Mythweb Usage of CDN

Post by bill6502 »

Just curious, did you set mythweb_use_cdn to "false" or 0?
rds55
Newcomer
Posts: 3
Joined: Thu Jul 18, 2019 9:56 pm
United States of America

Re: Disabling Mythweb Usage of CDN

Post by rds55 »

The variable 'mythweb_use_cdn' is set in "/usr/share/mythtv/mythweb/includes/db_update.php":

Code: Select all

case 4:
   setting('mythweb_use_cdn', null, true);
   setting('WebDBSchemaVer',    null, ++$db_vers, false);
So based on the surrounding code I used 'false'. Looking at the overall file contents it appears this statement is only called under certain conditions. I thought maybe I would have to reboot in order to get it set to the new value, false, but it did not work. I'm thinking there might be some special command to make the database reset or initialize itself to get it to go?

Anyway, my goal was to make the change permanent so the commenting gets the job done.
User avatar
bill6502
Developer
Posts: 2325
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Disabling Mythweb Usage of CDN

Post by bill6502 »

Near as I can tell, the true in the call to the settings function above, is really the integer 1.

For others reading this thread, one safe solution is to use the Services API.

You can see your stored value with: curl yourBackend:6544/Myth/GetSetting?Key=mythweb_use_cdn\&HostName=_GLOBAL_
and change it with: curl --data Key=mythweb_use_cdn --data Value=0 yourBackend:6544/Myth/PutSetting

Although there are no plans to remove mythweb at this time, the developer is no longer
active. WebFrontend is also available. Point a browser at: yourBackend:6544 . There
is no setup required.
User avatar
stuarta
Developer
Posts: 220
Joined: Wed Feb 05, 2014 5:13 pm
Great Britain

Re: Disabling Mythweb Usage of CDN

Post by stuarta »

This bit of code

Code: Select all

setting('mythweb_use_cdn', null)
checks the database setting, and enables or disables the use of the CDN based upon that setting.

All you actually needed to do, is set `mythweb_use_cdn` setting in the database to 0 and it'll stop using it.

You can either use the services API to do that, or just update the database
rds55
Newcomer
Posts: 3
Joined: Thu Jul 18, 2019 9:56 pm
United States of America

Re: Disabling Mythweb Usage of CDN

Post by rds55 »

bill6502 wrote:
Fri Jul 19, 2019 2:57 am
You can see your stored value with: curl yourBackend:6544/Myth/GetSetting?Key=mythweb_use_cdn\&HostName=_GLOBAL_
and change it with: curl --data Key=mythweb_use_cdn --data Value=0 yourBackend:6544/Myth/PutSetting
That does the trick - no need to comment out those statement in 'header.php' now.

Thanks
Post Reply