Browse Source

Fix #296: Add hostname override for dealing with shared hosting

George Baugh 2 years ago
parent
commit
02c31e5968
3 changed files with 12 additions and 4 deletions
  1. 1 1
      lib/TCMS.pm
  2. 6 3
      lib/Trog/Routes/HTML.pm
  3. 5 0
      www/templates/html/components/config.tx

+ 1 - 1
lib/TCMS.pm

@@ -105,7 +105,7 @@ sub _app {
     Trog::Log::uuid($requestid);
 
     # Various stuff important for logging requests
-    state $domain = eval { Sys::Hostname::hostname() } // $env->{HTTP_X_FORWARDED_HOST} || $env->{HTTP_HOST};
+    state $domain = $conf->param('general.hostname') || $env->{HTTP_X_FORWARDED_HOST} || $env->{HTTP_HOST} || eval { Sys::Hostname::hostname() };
     my $path   = $env->{PATH_INFO};
     my $port   = $env->{HTTP_X_FORWARDED_PORT} // $env->{HTTP_PORT};
     my $pport  = defined $port ? ":$port" : "";

+ 6 - 3
lib/Trog/Routes/HTML.pm

@@ -652,9 +652,10 @@ sub config ( $query = {} ) {
     #XXX ACHTUNG config::simple has this brain damaged behavior of returning a multiple element array when you access something that does not exist.
     #XXX straight up dying would be preferrable.
     #XXX anyways, this means you can NEVER NEVER NEVER access a param from within a hash directly.  YOU HAVE BEEN WARNED!
-    my $theme  = $conf->param('general.theme')              // '';
-    my $dm     = $conf->param('general.data_model')         // 'DUMMY';
-    my $embeds = $conf->param('security.allow_embeds_from') // '';
+    state $theme  = $conf->param('general.theme')              // '';
+    state $dm     = $conf->param('general.data_model')         // 'DUMMY';
+    state $embeds = $conf->param('security.allow_embeds_from') // '';
+    state $hostname = $conf->param('general.hostname') // '';
 
     return Trog::Routes::HTML::index(
         {
@@ -674,6 +675,7 @@ sub config ( $query = {} ) {
             is_admin           => 1,
             template           => 'config.tx',
             %$query,
+            hostname           => $hostname,
         },
         undef,
         [qw{config.css}],
@@ -803,6 +805,7 @@ sub config_save ($query) {
     $conf->param( 'general.theme',              $query->{theme} )      if defined $query->{theme};
     $conf->param( 'general.data_model',         $query->{data_model} ) if $query->{data_model};
     $conf->param( 'security.allow_embeds_from', $query->{embeds} )     if $query->{embeds};
+    $conf->param( 'general.hostname',           $query->{hostname} )   if $query->{hostname};
 
     $query->{failure} = 1;
     $query->{message} = "Failed to save configuration!";

+ 5 - 0
www/templates/html/components/config.tx

@@ -26,8 +26,13 @@ If for example, you use mysql it will have to rely on either a local server, val
     Allow Embeds from:
     <input class="cooltext" type="textarea" name="embeds" value="<: $embeds :>" />
     </div>
+    <div>
+    Hostname:
+    <input class="cooltext" type="textarea" name="hostname" value="<: $hostname :>" />
+    </div>
     <br />
     <input type="submit" class="coolbutton" value="Commit Changes" />
+
 </form>
 <hr />
 <p class="title">