Skip to content

Commit

Permalink
ui: Show country flag in mirror report
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-suse committed Sep 28, 2023
1 parent be64032 commit 3185fa4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/MirrorCache/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ has db_provider => undef;
has custom_footer_message => $ENV{MIRRORCACHE_CUSTOM_FOOTER_MESSAGE};

has browser_agent_mask => $ENV{MIRRORCACHE_BROWSER_AGENT_MASK} // '(?i)(firefox|msie|chrom|safari|seamonkey|opera|opr|trident).*';
has country_image_dir => $ENV{MIRRORCACHE_COUNTRY_IMAGE_DIR} // '/srv/www/htdocs/webalizer/flags/';

has geoip => undef;

Expand All @@ -63,7 +64,7 @@ sub init($self, $cfgfile) {
my $cfg;
$cfg = Config::IniFiles->new(-file => $cfgfile, -fallback => 'default') if $cfgfile;
if ($cfg) {
for my $k (qw/root root_nfs redirect redirect_huge huge_file_size small_file_size city_mmdb ip2location top_folders mirror_provider browser_agent_mask custom_footer_message/) {
for my $k (qw/root root_nfs redirect redirect_huge huge_file_size small_file_size city_mmdb ip2location top_folders mirror_provider browser_agent_mask custom_footer_message country_image_dir/) {
if (my $v = $cfg->val('default', $k)) {
$self->$k($v);
}
Expand Down Expand Up @@ -150,6 +151,10 @@ sub init($self, $cfgfile) {
}

$self->geoip(\%geoip);
if (my $country_image_dir = $self->country_image_dir) {
( -d $country_image_dir && -r $country_image_dir ) or $self->country_image_dir('');
}

return 1;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/MirrorCache/WebAPI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ sub _setup_webui {
$self->asset->process;
$self->plugin('Stat');
$self->plugin('Dir');
if (my $country_image_dir = $self->mcconfig->country_image_dir) {
my $static = $self->static;
push @{$static->paths}, $country_image_dir;
}
$self->log->info("server started: $current_version");
}

Expand Down
3 changes: 2 additions & 1 deletion t/environ/14-project-report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ $mc/sql "insert into project(name,path,etalon) select '2.0 2','/project2/folder2

echo add extra info for the report
$mc/sql "insert into server_note(dt,hostname,kind,msg) select now(), '$($ap7/print_address)','Ftp', 'ftp://ftp.ap7.com/opensuse'"
$mc/sql "insert into server_note(dt,hostname,kind,msg) select now(), '$($ap7/print_address)','Rsync', 'rsync://rsync.ap7.com/opensuse'"
$mc/sql "insert into server_note(dt,hostname,kind,msg) select now(), '$($ap6/print_address)','Ftp', 'ftp://ftp.ap6.com/opensuse'"
sleep 1
$mc/sql "insert into server_note(dt,hostname,kind,msg) select now(), '$($ap7/print_address)','Rsync', 'rsync://rsync.ap7.com/opensuse'"
$mc/sql "insert into server_note(dt,hostname,kind,msg) select now(), '$($ap6/print_address)','Rsync', 'rsync://rsync.ap6.com/opensuse'"


Expand Down
6 changes: 3 additions & 3 deletions t/environ/14-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ $mc/curl /rest/repmirror | grep -F '"country":"jp","proj1score":"0","proj1victi
echo proj1 is not on ap4, so it shouldnt appear in repmirror at all
test $rc -gt 0

$mc/curl /rest/repmirror | grep -F '{"country":"cn","proj1score":"50","proj1victim":"","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1284"},{"country":"jp","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1274"},{"country":"de","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"eu","url":"127.0.0.1:1314"},{"country":"us","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1294"},{"country":"us","proj1score":"50","proj1victim":"\/project1\/folder2","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1304"}'
$mc/curl /rest/repmirror | grep -F '{"country":"cn","hostname":"127.0.0.1:1284","proj1score":"50","proj1victim":"","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1284"},{"country":"jp","hostname":"127.0.0.1:1274","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1274"},{"country":"de","hostname":"127.0.0.1:1314","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"eu","url":"127.0.0.1:1314"},{"country":"us","hostname":"127.0.0.1:1294","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1294"},{"country":"us","hostname":"127.0.0.1:1304","proj1score":"50","proj1victim":"\/project1\/folder2","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1304"}'

$mc/curl /rest/project | grep -F '{"alias":"proj2","name":"proj 2","path":"\/project2"}' | grep -F '{"alias":"proj1","name":"proj1","path":"\/project1"}'

echo ceck the same when DB is offline
$mc/db/stop
$mc/curl /rest/repmirror | grep -F '{"country":"cn","proj1score":"50","proj1victim":"","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1284"},{"country":"jp","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1274"},{"country":"de","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"eu","url":"127.0.0.1:1314"},{"country":"us","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1294"},{"country":"us","proj1score":"50","proj1victim":"\/project1\/folder2","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1304"}'
$mc/curl /rest/repmirror | grep -F '{"country":"cn","hostname":"127.0.0.1:1284","proj1score":"50","proj1victim":"","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1284"},{"country":"jp","hostname":"127.0.0.1:1274","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1274"},{"country":"de","hostname":"127.0.0.1:1314","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"eu","url":"127.0.0.1:1314"},{"country":"us","hostname":"127.0.0.1:1294","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1294"},{"country":"us","hostname":"127.0.0.1:1304","proj1score":"50","proj1victim":"\/project1\/folder2","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1304"}'

$mc/curl /rest/project | grep -F '{"alias":"proj2","name":"proj 2","path":"\/project2"}' | grep -F '{"alias":"proj1","name":"proj1","path":"\/project1"}'

echo now restart the service while DB is offline
$mc/stop
ENVIRON_MC_DB_AUTOSTART=0 $mc/start

$mc/curl /rest/repmirror | grep -F '{"country":"cn","proj1score":"50","proj1victim":"","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1284"},{"country":"jp","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1274"},{"country":"de","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"eu","url":"127.0.0.1:1314"},{"country":"us","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1294"},{"country":"us","proj1score":"50","proj1victim":"\/project1\/folder2","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1304"}'
$mc/curl /rest/repmirror | grep -F '{"country":"cn","hostname":"127.0.0.1:1284","proj1score":"50","proj1victim":"","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1284"},{"country":"jp","hostname":"127.0.0.1:1274","proj2score":"100","proj2victim":"","region":"as","url":"127.0.0.1:1274"},{"country":"de","hostname":"127.0.0.1:1314","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"eu","url":"127.0.0.1:1314"},{"country":"us","hostname":"127.0.0.1:1294","proj1score":"100","proj1victim":"","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1294"},{"country":"us","hostname":"127.0.0.1:1304","proj1score":"50","proj1victim":"\/project1\/folder2","proj2score":"100","proj2victim":"","region":"na","url":"127.0.0.1:1304"}'

$mc/curl /rest/project | grep -F '{"alias":"proj2","name":"proj 2","path":"\/project2"}' | grep -F '{"alias":"proj1","name":"proj1","path":"\/project1"}'

Expand Down
17 changes: 15 additions & 2 deletions templates/report/mirrors/index.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ div.repo {
max-width: 20pct;
}

div.country {
float: left;
}

div.flag {
float: right;
}

div.hostname {
float: left;
margin-left: 2px;
Expand Down Expand Up @@ -128,6 +136,7 @@ td.newregion, tr:hover td.newregion {
%= include_branding 'report_mirrors_banner'
% my $mc_branding = eval '$branding' // 'MirrorCache';
% my $is_opensuse = $mc_branding eq 'openSUSE';
% my $country_image_dir = eval('mcconfig->country_image_dir');

<form>
<div class="row">
Expand Down Expand Up @@ -174,8 +183,12 @@ td.newregion, tr:hover td.newregion {
<tr>
% my $hostname = $m->{hostname};
% my $url = $m->{url};
<td><%= $m->{country} %></td>
<td><div class="hostname"><a class="hostname" href="http://<%= $hostname %>"><%=$hostname%></a></div>
<td><div class="country"><%= $m->{country} %></div>
% if ($country_image_dir) {
<div class="flag"><img src="/<%= $m->{country} %>.png" width="20" class="img-fluid" alt="country flag"></div>
% }
</td>
<td><div class="hostname"><a class="hostname" href="/app/server/<%= $hostname %>"><%=$hostname%></a></div>
% for my $capability (qw/http https ftp rsync ipv4 ipv6/) {
% my $capability_url = $m->{$capability . '_url'};
% next unless $capability_url;
Expand Down

0 comments on commit 3185fa4

Please sign in to comment.