Announcement

#1 2019-11-12 19:41:28

pbrownll
Member
2015-08-02
5

Dynamic DNS

I have an old post I was involved with - https://piwigo.org/forum/viewtopic.php?id=25791 which I worked around on previous piwigo versions, but never posted the fix for.

Here's the problem.  I have piwigo hosted on a local server (virtual).  I use a cable provider for my ISP, so my IP address can change from boot to boot (it doesn't seem to change in reality but that's a different story.)  I use a dynamic DNS server to get a URL for the dynamic IP address provided by my ISP.  The resulting URL is ugly.  I have a website hosted on a paid hosting provider.  I create a CNAME record with the external name I want my website to be known by.  So I have CNAME URL -> DynDNS URL -> Dynamic IP address.

The function get_absolute_root_url tries to figure out the URL so it can insert it as a link in various fields in notification messages (and elsewhere? - haven't seen it used for anything else.)  Of course the software can't make sense of all this gibberish and so it issues emails with an IP address which can change tomorrow.  This is undesirable.

My fix was to define a new conf variable $conf['ddns_url'] with the specific URL I want posted in the emails and used by my users. (i.e., $conf['ddns_url'] = 'photos.domain.com'; in local files editor).  Note that you seem to have added a similar conf variable called gallery_url, but it doesn't work for this function.

Here's the fix:

There are 2 patch files:

config_default.inc.php.patch
--- config_default.inc.php.orig    2019-11-11 17:26:51.627948163 -0500
+++ config_default.inc.php    2019-11-11 17:29:36.251995978 -0500
@@ -576,6 +576,12 @@
// setting when move your gallery to a new directory or a new domain name.
$conf['gallery_url'] = null;

+// ddns_url : if you are using a ddns client (like dyndns) or if you have
+// a subdomain redirect on in something like cpanel, piwigo can't figure out
+// your user-level url.  You have to put it in here.  enter only
+// subdomain.domain.com
+$conf['ddns_url'] = null;
+
// question_mark_in_urls : the generated urls contain a ? sign. This can be
// changed to false only if the server translates PATH_INFO variable
// (depends on the server AcceptPathInfo directive configuration)

functions_url.inc.php.patch
--- functions_url.inc.php.orig    2019-11-11 17:26:51.671948176 -0500
+++ functions_url.inc.php    2019-11-12 12:51:36.832721706 -0500
@@ -32,6 +32,7 @@
  */
function get_absolute_root_url($with_scheme=true)
{
+  global $conf;
   // TODO - add HERE the possibility to call PWG functions from external scripts
   $url = '';
   if ($with_scheme)
@@ -47,7 +48,11 @@
     {
       $url .= 'http://';
     }
-    if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
+    if (!empty($conf['ddns_url']))
+    {
+      $url .= $conf['ddns_url'];
+    }
+    elseif (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
     {
       $url .= $_SERVER['HTTP_X_FORWARDED_HOST'];
     }


Piwigo version: 2.10.1
PHP version: 7.2
MySQL version: 14.14
Piwigo URL: http://

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact