From 697bd436c290cb42f29f62cdd33a38f2335350d5 Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Wed, 24 Mar 2021 02:43:10 +0300 Subject: [PATCH] Add ability to setup custom company branding and favicons https://github.com/authentic-theme/authentic-theme/issues/639#issuecomment-804381946 --- authentic-funcs.pl | 24 +++++++++++++++++------- authentic-init.pl | 45 +++++++++++++++++++-------------------------- authentic-lib.pl | 2 +- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/authentic-funcs.pl b/authentic-funcs.pl index b9cc6e005..1d3d8c6c7 100644 --- a/authentic-funcs.pl +++ b/authentic-funcs.pl @@ -13,6 +13,7 @@ %gconfig, $current_lang_info, $root_directory, + $config_directory, $current_theme, $remote_user, $get_user_level, @@ -428,6 +429,13 @@ sub trim return $s; } +sub trim_lines +{ + my $s = shift; + $s =~ s/[\n\r]//g; + return $s; +} + sub replace { my ($from, $to, $string) = @_; @@ -744,25 +752,27 @@ sub embed_product_branding my $brand; my $brand_name; - my $brand_dir = "$root_directory/$current_theme/images/brand"; - my $loader = read_file_contents("$brand_dir/loader.html"); + my $brand_dir_default = "$root_directory/$current_theme/images/brand"; + my $brand_dir_custom = "$config_directory/$current_theme/brand"; + my $brand_dir = -r $brand_dir_custom ? $brand_dir_custom : $brand_dir_default; + my $loader = read_file_contents("$brand_dir/loader.html"); # Define brand image for Virtualmin if (foreign_available("virtual-server")) { - $brand = read_file_contents("$brand_dir/virtualmin.html"); + $brand = read_file_contents("$brand_dir/virtualmin.html"); $brand_name = "brand-virtualmin"; - } - + } + # Define brand image for Cloudmin elsif (foreign_available("virtual-server")) { - $brand = read_file_contents("$brand_dir/cloudmin.html"); + $brand = read_file_contents("$brand_dir/cloudmin.html"); $brand_name = "brand-cloudmin"; } # Webmin/Usermin brand image else { my $prod = get_product_name(); - $brand = read_file_contents("$brand_dir/$prod.html"); + $brand = read_file_contents("$brand_dir/$prod.html"); $brand_name = "brand-$prod"; } $brand = diff --git a/authentic-init.pl b/authentic-init.pl index 47acd4f6e..cb3129fda 100644 --- a/authentic-init.pl +++ b/authentic-init.pl @@ -101,7 +101,6 @@ sub get_theme_color sub embed_favicon { - my ($inline) = @_; my $product = get_product_name() eq 'usermin' ? 'usermin' : 'webmin'; if ($get_user_level eq '1' || $get_user_level eq '2') { @@ -113,33 +112,28 @@ sub embed_favicon my $favicon_path = $gconfig{'webprefix'} . '/images/favicons/' . $product; my $ref_link = 'data-link-ref'; - if ($inline) { - my $favicon_spath = "$root_directory/$current_theme/images/favicons/$product"; - print ' ' . "\n"; - print ' ' . "\n"; - print ' ' . "\n"; - print ' ' . "\n"; - } else { - print ' ' . "\n"; + + my $favicon_dpath = "$root_directory/$current_theme/images/favicons/$product"; + my $favicon_cpath = "$config_directory/$current_theme/favicons/$product"; + my $favicon_spath = -r $favicon_cpath ? $favicon_cpath : $favicon_dpath; + print ' ' . "\n"; + print ' ' . "\n"; + print ' ' . "\n"; + print ' ' . "\n"; + + if (!-r $favicon_cpath) { print ' ' . "\n"; + $ref_link . ' crossorigin="use-credentials" rel="manifest" href="' . $favicon_path . '/manifest.json">' . "\n"; print ' ' . "\n"; - print ' ' . "\n"; + ' rel="mask-icon" href="' . $favicon_path . '/safari-pinned-tab.svg" color="' . get_theme_color() . '">' . "\n"; + print ' ' . "\n"; } - print ' ' . "\n"; - print ' ' . "\n"; print ' ' . "\n"; - print ' ' . "\n"; print ' ' . "\n"; } @@ -1601,8 +1595,7 @@ sub get_tuconfig_file sub fetch_stripped { - if (get_env('http_x_requested_with') eq "XMLHttpRequest") - { + if (get_env('http_x_requested_with') eq "XMLHttpRequest") { return 1; } else { return 0; diff --git a/authentic-lib.pl b/authentic-lib.pl index 303245a0a..b7b129d57 100644 --- a/authentic-lib.pl +++ b/authentic-lib.pl @@ -1957,7 +1957,7 @@ sub embed_login_head print '', "\n"; embed_noscript(); print '', "\n"; - embed_favicon($inline); + embed_favicon(); print '', $title, '', "\n"; print '' . "\n";