Skip to content

Commit

Permalink
Add ability to setup custom company branding and favicons #639 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Mar 23, 2021
1 parent 373e1ce commit 697bd43
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
24 changes: 17 additions & 7 deletions authentic-funcs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
%gconfig,
$current_lang_info,
$root_directory,
$config_directory,
$current_theme,
$remote_user,
$get_user_level,
Expand Down Expand Up @@ -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) = @_;
Expand Down Expand Up @@ -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 =
Expand Down
45 changes: 19 additions & 26 deletions authentic-init.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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 ' <link ' . $ref_link . ' rel="apple-touch-icon" sizes="180x180" href="data:text/css;base64,' .
trim(encode_base64(read_file_contents($favicon_spath . '/apple-touch-icon.png'))) . '">' . "\n";
print ' <link ' . $ref_link . ' rel="icon" type="image/png" sizes="32x32" href="data:text/css;base64,' .
trim(encode_base64(read_file_contents($favicon_spath . '/favicon-32x32.png'))) . '">' . "\n";
print ' <link ' . $ref_link . ' rel="icon" type="image/png" sizes="192x192" href="data:text/css;base64,' .
trim(encode_base64(read_file_contents($favicon_spath . '/android-chrome-192x192.png'))) . '">' . "\n";
print ' <link ' . $ref_link . ' rel="icon" type="image/png" sizes="16x16" href="data:text/css;base64,' .
trim(encode_base64(read_file_contents($favicon_spath . '/favicon-16x16.png'))) . '">' . "\n";
} else {
print ' <link ' .
$ref_link . ' rel="apple-touch-icon" sizes="180x180" href="' . $favicon_path . '/apple-touch-icon.png">' . "\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 ' <link ' . $ref_link . ' rel="apple-touch-icon" sizes="180x180" href="data:text/css;base64,' .
trim_lines(trim(encode_base64(read_file_contents($favicon_spath . '/apple-touch-icon.png')))) . '">' . "\n";
print ' <link ' . $ref_link . ' rel="icon" type="image/png" sizes="32x32" href="data:text/css;base64,' .
trim_lines(trim(encode_base64(read_file_contents($favicon_spath . '/favicon-32x32.png')))) . '">' . "\n";
print ' <link ' . $ref_link . ' rel="icon" type="image/png" sizes="192x192" href="data:text/css;base64,' .
trim_lines(trim(encode_base64(read_file_contents($favicon_spath . '/android-chrome-192x192.png')))) . '">' . "\n";
print ' <link ' . $ref_link . ' rel="icon" type="image/png" sizes="16x16" href="data:text/css;base64,' .
trim_lines(trim(encode_base64(read_file_contents($favicon_spath . '/favicon-16x16.png')))) . '">' . "\n";

if (!-r $favicon_cpath) {
print ' <link ' .
$ref_link . ' rel="icon" type="image/png" sizes="32x32" href="' . $favicon_path . '/favicon-32x32.png">' . "\n";
$ref_link . ' crossorigin="use-credentials" rel="manifest" href="' . $favicon_path . '/manifest.json">' . "\n";
print ' <link ' . $ref_link .
' rel="icon" type="image/png" sizes="192x192" href="' . $favicon_path . '/android-chrome-192x192.png">' . "\n";
print ' <link ' .
$ref_link . ' rel="icon" type="image/png" sizes="16x16" href="' . $favicon_path . '/favicon-16x16.png">' . "\n";
' rel="mask-icon" href="' . $favicon_path . '/safari-pinned-tab.svg" color="' . get_theme_color() . '">' . "\n";
print ' <meta ' .
$ref_link . ' name="msapplication-TileImage" content="' . $favicon_path . '/mstile-144x144.png">' . "\n";
}
print ' <link ' .
$ref_link . ' crossorigin="use-credentials" rel="manifest" href="' . $favicon_path . '/manifest.json">' . "\n";
print ' <link ' . $ref_link .
' rel="mask-icon" href="' . $favicon_path . '/safari-pinned-tab.svg" color="' . get_theme_color() . '">' . "\n";
print ' <meta name="msapplication-TileColor" content="' . get_theme_color() . '">' . "\n";
print ' <meta ' .
$ref_link . ' name="msapplication-TileImage" content="' . $favicon_path . '/mstile-144x144.png">' . "\n";
print ' <meta name="theme-color" content="' . get_theme_color() . '">' . "\n";

}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion authentic-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ sub embed_login_head
print '<head>', "\n";
embed_noscript();
print '<meta charset="utf-8">', "\n";
embed_favicon($inline);
embed_favicon();
print '<title>', $title, '</title>', "\n";
print '<meta name="viewport" content="width=device-width, initial-scale=1.0">' . "\n";

Expand Down

0 comments on commit 697bd43

Please sign in to comment.