From ee649ff2ddb1c5663e072b21cb97b8cac45deb96 Mon Sep 17 00:00:00 2001 From: Digimer Date: Sat, 7 Jul 2018 01:31:40 -0400 Subject: [PATCH] * Started work on the Striker sync function. It shows (without formatting yet) the ways the local dashboard can be accessed. * Added another check and better error handling to Template->get() to print a more useful message if a template is found but fails to parse. * Moved some strings into the words file. Signed-off-by: Digimer --- Anvil/Tools/Database.pm | 4 ++ Anvil/Tools/Template.pm | 11 ++++- cgi-bin/home | 49 +++++++++++++++++++++- html/skins/alteeve/main.css | 10 ++++- html/skins/alteeve/main.html | 2 +- html/skins/alteeve/striker.html | 74 ++++++++++++++++++++++++++------- share/words.xml | 32 +++++++++++--- 7 files changed, 155 insertions(+), 27 deletions(-) diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index 9d724330..c5400c06 100755 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -679,6 +679,10 @@ sub connect password => $anvil->Log->secure ? $password : "#!string!log_0186!#", }}); + # Some places will want to pull up the database user, so in case it isn't set (which is + # usual), set it as if we had read it from the config file using the default. + $anvil->data->{database}{$uuid}{name} = $anvil->data->{sys}{database}{name} if not $anvil->data->{database}{$uuid}{name}; + # If not set, we will always ping before connecting. if ((not exists $anvil->data->{database}{$uuid}{ping}) or (not defined $anvil->data->{database}{$uuid}{ping})) { diff --git a/Anvil/Tools/Template.pm b/Anvil/Tools/Template.pm index b1c2ee4e..0122250c 100755 --- a/Anvil/Tools/Template.pm +++ b/Anvil/Tools/Template.pm @@ -240,13 +240,22 @@ sub get }}); if ((not $template_found) or ($template eq "#!not_found!#")) { - # Error! + # Woops! $template = $anvil->Words->string({key => "error_0029", variables => { template => $name, file => $source, }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { template => $template }}); } + + # If there was a problem processing the template, it will be '#!error!#'. + if ($template eq "#!error!#") + { + $template = $anvil->Words->string({key => "error_0030", variables => { + template => $name, + file => $source, + }}); + } } $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { template => $template }}); diff --git a/cgi-bin/home b/cgi-bin/home index a72db7f0..37e0fa32 100755 --- a/cgi-bin/home +++ b/cgi-bin/home @@ -218,10 +218,12 @@ sub process_task # If we're here, the user is logged in! if ($anvil->data->{cgi}{striker}{value}) { - $anvil->data->{form}{back_link} = "?striker=true"; + $anvil->data->{form}{back_link} = "?striker=true"; + $anvil->data->{cgi}{task}{value} = "" if not defined $anvil->data->{cgi}{task}{value}; + $anvil->data->{cgi}{action}{value} = "" if not defined $anvil->data->{cgi}{action}{value}; if ($anvil->data->{cgi}{task}{value} eq "sync") { - $anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "striker-sync"}); + process_sync_page($anvil); } else { @@ -253,6 +255,49 @@ sub process_task return(0); } +# This handles tasks related to setting up peer Strikers. +sub process_sync_page +{ + my ($anvil) = @_; + + # Are we adding a new peer? + if ($anvil->data->{cgi}{action}{value} eq "add") + { + #add_sync_peer($anvil); + } + elsif ($anvil->data->{cgi}{action}{value} eq "remove") + { + #remove_sync_peer($anvil); + } + + $anvil->System->get_ips(); + + # We'll want to show the user way to access the local machine. For that, we'll loop through our own IPs. + my $table = ""; + foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{sys}{network}{interface}}) + { + next if (($interface !~ /^bcn/) && ($interface !~ /^ifn/)); + next if not $anvil->Validate->is_ipv4({ip => $anvil->data->{sys}{network}{interface}{$interface}{ip}}); + next if not $anvil->Validate->is_subnet({subnet => $anvil->data->{sys}{network}{interface}{$interface}{subnet}}); + my ($network_type, $network_number) = ($interface =~ /^(.*?)(\d+)_/); + + my $host_uuid = $anvil->Get->host_uuid; + my $database_user = $anvil->data->{database}{$host_uuid}{name}; + my $database_port = $anvil->data->{database}{$host_uuid}{port}; + my $network_key = $network_type eq "bcn" ? "striker_0018" : "striker_0022"; + my $say_network = $anvil->Words->string({key => $network_key, variables => { number => $network_number }}); + $table .= $anvil->Template->get({file => "striker.html", name => "striker-sync-inbound", variables => { + access => $database_user."\@".$anvil->data->{sys}{network}{interface}{$interface}{ip}.":".$database_port, + note => $anvil->Words->string({key => "striker_0066", variables => { network => $say_network }}), + }}); + } + + # Build the menu. + $anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "striker-sync", variables => { table => $table }}); + + return(0); +} + # This shows the menus for configuring Striker. sub configure_striker { diff --git a/html/skins/alteeve/main.css b/html/skins/alteeve/main.css index d96bed7c..3c51e376 100644 --- a/html/skins/alteeve/main.css +++ b/html/skins/alteeve/main.css @@ -69,12 +69,18 @@ select { } body { - font-family: 'Dejavu Sans', Arial, Helvetica, Verdana, Sans-Serif; - background-image: url("/skins/alteeve/images/Texture.jpg"); + font-family: 'Dejavu Sans', Arial, Helvetica, Verdana, Sans-Serif; + background-image: url("/skins/alteeve/images/Texture.jpg"); background-repeat: repeat; color: #f2f2f2; } +a { + font-family: 'Dejavu Sans', Arial, Helvetica, Verdana, Sans-Serif; + color: #f2f2f2; + text-decoration: none; +} + table.data_table_nowrap { border: 1px solid #8f8f8f; border-radius: 4px; diff --git a/html/skins/alteeve/main.html b/html/skins/alteeve/main.html index 654e7e8e..824d61b3 100644 --- a/html/skins/alteeve/main.html +++ b/html/skins/alteeve/main.html @@ -219,5 +219,5 @@ -#!string!message_0033!# +#!string!striker_0063!# diff --git a/html/skins/alteeve/striker.html b/html/skins/alteeve/striker.html index 0bed7b63..f8d366ff 100644 --- a/html/skins/alteeve/striker.html +++ b/html/skins/alteeve/striker.html @@ -22,7 +22,7 @@ - #!string!message_0032!# + #!string!striker_0065!# @@ -40,7 +40,7 @@ #!variable!description!#

- Reload + #!string!striker_0053!# @@ -56,7 +56,7 @@ - Striker Configuration and Management + #!string!striker_0052!# @@ -69,12 +69,12 @@ - Configure Striker Peers + #!string!striker_0054!# - When you sync with a peer, this machine's data will be copied to and recorded on the peer's database. Data gathered by ScanCore will also be kept in sync on both dashboards, and any general purpose data collected by other dashboards while this one is offline will be copied back when this machine comes online. Should this machine ever be rebuilt, data recorded from before the rebuild will be automatically restored as well. + #!string!striker_0055!# @@ -82,12 +82,12 @@ - Update this Striker + #!string!striker_0056!# - This will update this system using any available software repositories. You can also use this to create or load update packs to allow for the update of offline or air-gapped Anvil! systems. + #!string!striker_0057!# @@ -95,20 +95,64 @@ - Configure this Striker + #!string!striker_0058!# - Update the network configuration for this Striker. + #!string!striker_0059!# + + + + + + + + + + +
+ Add or remove Striker peers. +
+ Peer dashboards are Striker machines whose databases this Striker will use to record data. If this machine ever needs to be replaced, or goes offline for a period of time, it will automatically pull the data back from any peers that it is missing. +
+ + #!variable!table!# +
+
+ + + + #!variable!access!# + + + #!variable!ping!# + + + #!variable!button!# + + + + + + + + #!variable!access!# + + + #!variable!note!# + + + + @@ -118,7 +162,7 @@ @@ -126,7 +170,7 @@ @@ -134,15 +178,15 @@ @@ -150,7 +194,7 @@
- #!string!message_0035!# + #!string!striker_0060!#
- #!string!message_0036!# + #!string!striker_0061!#
- #!string!message_0037!# + #!string!striker_0062!#
- #!string!message_0033!# + #!string!striker_0063!# - #!string!message_0033!# + #!string!striker_0063!#
- #!string!message_0038!# + #!string!striker_0064!#
diff --git a/share/words.xml b/share/words.xml index 639a2bad..bc305e4e 100644 --- a/share/words.xml +++ b/share/words.xml @@ -57,13 +57,13 @@ NOTE: You must update the password of any other system using this host's Failed to write the new password to the temporary file: [#!variable!file!#]. Please check the logs for details. Beginning configuration of local system. - Use 'anvil-change-password' from the console to reset it.]]> - Log out + + #!data!sys::users::user_name!#]]]> - Welcome! - Create or manage Anvil! systems - Manage this Striker system and sync with others - Help and support + + + + Starting: [#!variable!program!#]. @@ -370,6 +370,25 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st Log in User name Password + Striker Configuration and Management + Reload + Configure Striker Peers + When you sync with a peer, this machine's data will be copied to and recorded on the peer's database. Data gathered by ScanCore will also be kept in sync on both dashboards, and any general purpose data collected by other dashboards while this one is offline will be copied back when this machine comes online. Should this machine ever be rebuilt, data recorded from before the rebuild will be automatically restored as well. + Update this Striker + This will update this system using any available software repositories. You can also use this to create or load update packs to allow for the update of offline or air-gapped Anvil! systems. + Configure this Striker + Update the network configuration for this Striker. + Welcome! + Create or manage Anvil! systems + Manage this Striker system and sync with others + Log out + Help and support + Use 'anvil-change-password' from the console to reset it.]]> + Access to this machine via: [#!variable!network!#]. + + + + Configure Network @@ -408,6 +427,7 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st Login failed, please try again. #!data!sys::log_file!#] for details.]]> #!variable!template!#] in the template file: [#!variable!file!#].]]> + #!variable!template!#] in the template file: [#!variable!file!#]. Details of the problem should be in: [#!data!sys::log_file!#].]]> Up