From 66928edb061f3e85155330b3ee0b64a9b2d2cbcd Mon Sep 17 00:00:00 2001 From: Digimer Date: Fri, 22 Jun 2018 01:43:43 -0400 Subject: [PATCH] * Added logic to check if Striker is configured and, if so, enter main functions. * Finished up the configuration logic for Striker. Signed-off-by: Digimer --- cgi-bin/home | 128 ++++++++++++++++++++++++++-------- html/skins/alteeve/main.html | 7 +- share/words.xml | 3 +- tools/anvil-configure-striker | 44 ++++++++++-- 4 files changed, 145 insertions(+), 37 deletions(-) diff --git a/cgi-bin/home b/cgi-bin/home index 63ac68f9..4dfc2a13 100755 --- a/cgi-bin/home +++ b/cgi-bin/home @@ -70,14 +70,69 @@ my $body = ""; # If any jobs are pending/running, show the "unavailable" option. my $available = check_availability($anvil); +$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { available => $available }}); if (not $available) { # Set the body to 'say::maintenance'. $body = $anvil->data->{say}{maintenance}; } + +# If there is no user account yet, then the system is new and needs to be reconfigured. +my $configured = check_if_configured($anvil); +$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { configured => $configured }}); +if (not $configured) +{ + $body = configure_striker($anvil); +} else { + # Normal operation + $body = process_task($anvil); +} + +my $buttons = $anvil->Template->get({file => "main.html", name => "button_bar"}); +my $footer = $anvil->Template->get({file => "main.html", name => "footer"}); + +# Display the page. +my $template = $anvil->Template->get({file => "main.html", name => "master", variables => { + header => $header, + skin_url => $anvil->data->{path}{urls}{skins}."/".$anvil->Template->skin, + left_top_bar => " ", + center_top_bar => $anvil->data->{form}{error_massage}, + right_top_bar => $buttons, + center_body => $body, + left_bottom_bar => " ", + center_bottom_bar => " ", + right_bottom_bar => " ", + footer => $footer, +}}); + +print $template; + +$anvil->nice_exit({exit_code => 0}); + + +############################################################################################################# +# Functions # +############################################################################################################# + +# This handles all the daily tasks of Striker. +sub process_task +{ + my ($anvil) = @_; + + my $body = "hi"; + + return($body); +} + +# This shows the menus for configuring Striker. +sub configure_striker +{ + my ($anvil) = @_; + # This will be true when the dashboard is unconfigured. + my $body = ""; if (not $anvil->data->{cgi}{step}{value}) { $body = config_step1($anvil); @@ -123,32 +178,30 @@ else { $body = get_network_details_form($anvil); } + + return($body); } -my $buttons = $anvil->Template->get({file => "main.html", name => "button_bar"}); -my $footer = $anvil->Template->get({file => "main.html", name => "footer"}); - -# Display the page. -my $template = $anvil->Template->get({file => "main.html", name => "master", variables => { - header => $header, - skin_url => $anvil->data->{path}{urls}{skins}."/".$anvil->Template->skin, - left_top_bar => " ", - center_top_bar => $anvil->data->{form}{error_massage}, - right_top_bar => $buttons, - center_body => $body, - left_bottom_bar => " ", - center_bottom_bar => " ", - right_bottom_bar => " ", - footer => $footer, -}}); - -print $template; - -$anvil->nice_exit({exit_code => 0}); - -############################################################################################################# -# Functions # -############################################################################################################# +# This checks to see if the local machine has been configured after initial install. If not, it will present +# the configuration menu. +sub check_if_configured +{ + my ($anvil) = @_; + + my ($configured, $variable_uuid, $modified_date) = $anvil->Database->read_variable({ + variable_name => "system::configured", + variable_source_uuid => $anvil->Get->host_uuid, + variable_source_table => "hosts", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + configured => $configured, + variable_uuid => $variable_uuid, + modified_date => $modified_date, + }}); + + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { configured => $configured }}); + return($configured); +} # This checks to see if anything is running that requires Striker being unavailable. If not, this returns # '1'. If there is a job pending/running, it returns '0' @@ -157,23 +210,36 @@ sub check_availability my ($anvil) = @_; my $available = 1; - my $query = "SELECT count(*) FROM jobs WHERE job_name = 'configure::network' AND job_progress != 100 AND job_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid).";"; + my $query = "SELECT job_progress, modified_date, extract(epoch from modified_date) FROM jobs WHERE job_name = 'configure::network' AND job_progress != 100 AND job_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid).";"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); - my $count = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; - $count = 0 if not defined $count; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }}); + my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); + my $count = @{$results}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + results => $results, + count => $count, + }}); if ($count) { # We're waiting for the network configuration - $available = 0; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { available => $available }}); + my $percent = $results->[0]->[0]; + my $timestamp = $results->[0]->[1]; + my $unixtime = $results->[0]->[2]; + my $seconds_ago = $anvil->Convert->add_commas({number => (time - $unixtime)}); + $available = 0; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + available => $available, + percent => $percent, + seconds_ago => $seconds_ago, + timestamp => $timestamp, + unixtime => $unixtime, + }}); $anvil->data->{say}{maintenance} = $anvil->Template->get({file => "main.html", name => "striker-offline", variables => { title_id => "", message_id => "", title => "#!string!striker_0046!#", - description => "#!string!striker_0047!#", + description => $anvil->Words->string({key => "striker_0047", variables => { percent => $percent, timestamp => $timestamp, seconds_ago => $seconds_ago }}), }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'say::maintenance' => $anvil->data->{say}{maintenance} }}); } diff --git a/html/skins/alteeve/main.html b/html/skins/alteeve/main.html index c6916e54..af8b9443 100644 --- a/html/skins/alteeve/main.html +++ b/html/skins/alteeve/main.html @@ -314,13 +314,18 @@ -
+
+ + +
#!variable!title!#
#!variable!description!#
+ Reload +
diff --git a/share/words.xml b/share/words.xml index e9dbdf6f..53781403 100644 --- a/share/words.xml +++ b/share/words.xml @@ -348,7 +348,8 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st Done! The network will be reconfigured momentarily. You may need to reconnect using the new network address you chose. Offline... - A job to reconfigure the network on this machine is underway. Please try again soon. + A job to reconfigure this Striker is underway. It is: [#!variable!percent!#%] done. It last updated its progress at: [#!variable!timestamp!#] (#!variable!seconds_ago!# seconds ago). Please try again shortly. + This indicates that this machine has been configured. After an initial install, this variable won't exist. If it is set to '0', it will trigger a reconfiguration of the local system. Configure Network diff --git a/tools/anvil-configure-striker b/tools/anvil-configure-striker index 8f256e3a..92f56e88 100755 --- a/tools/anvil-configure-striker +++ b/tools/anvil-configure-striker @@ -70,6 +70,24 @@ update_passwords($anvil); ### TODO: This is only until we can get the damn networking stable on reconfigure. # Reboot. +$anvil->Database->insert_or_update_jobs({ + job_uuid => $anvil->data->{job}{uuid}, + update_progress_only => 1, + job_progress => 100, + job_status => $anvil->data->{job}{status}, +}); + +# Record that we've configured this machine. +$anvil->Database->insert_or_update_variables({ + variable_name => "system::configured", + variable_value => 1, + variable_default => "", + variable_description => "striker_0048", + variable_section => "system", + variable_source_uuid => $anvil->Get->host_uuid, + variable_source_table => "hosts", +}); + #$anvil->System->call({shell_call => $anvil->data->{path}{exe}{'shutdown'}." --reboot now"}); $anvil->nice_exit({code => 0}); @@ -110,10 +128,7 @@ sub update_passwords else { my $return_code = ""; - my $output = $anvil->System->call({ - debug => 2, - shell_call => $anvil->data->{path}{exe}{'anvil-change-password'}." -y --password-file ".$temp_file."; ".$anvil->data->{path}{exe}{'echo'}." return_code:\$!", - }); + my $output = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{'anvil-change-password'}." -y --password-file ".$temp_file."; ".$anvil->data->{path}{exe}{'echo'}." return_code:\$!" }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { output => $output }}); foreach my $line (split/\n/, $output) { @@ -135,6 +150,13 @@ sub update_passwords } } + $anvil->Database->insert_or_update_jobs({ + job_uuid => $anvil->data->{job}{uuid}, + update_progress_only => 1, + job_progress => 95, + job_status => $anvil->data->{job}{status}, + }); + return(0); } @@ -618,6 +640,13 @@ sub reconfigure_network } } + $anvil->Database->insert_or_update_jobs({ + job_uuid => $anvil->data->{job}{uuid}, + update_progress_only => 1, + job_progress => 50, + job_status => $anvil->data->{job}{status}, + }); + # If any virtio bridges exist, remove it/them. my $start = 0; my $bridges = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." net-list"}); @@ -661,6 +690,13 @@ sub reconfigure_network # Reload the network #print "reloading nmcli\n"; #$anvil->System->call({shell_call => $anvil->data->{path}{exe}{nmcli}." connection reload"}); + + $anvil->Database->insert_or_update_jobs({ + job_uuid => $anvil->data->{job}{uuid}, + update_progress_only => 1, + job_progress => 75, + job_status => $anvil->data->{job}{status}, + }); return(0); }