* 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 <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 2febb09d72
commit 66928edb06
  1. 128
      cgi-bin/home
  2. 7
      html/skins/alteeve/main.html
  3. 3
      share/words.xml
  4. 44
      tools/anvil-configure-striker

@ -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 => "&nbsp;",
center_top_bar => $anvil->data->{form}{error_massage},
right_top_bar => $buttons,
center_body => $body,
left_bottom_bar => "&nbsp;",
center_bottom_bar => "&nbsp;",
right_bottom_bar => "&nbsp;",
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 => "&nbsp;",
center_top_bar => $anvil->data->{form}{error_massage},
right_top_bar => $buttons,
center_body => $body,
left_bottom_bar => "&nbsp;",
center_bottom_bar => "&nbsp;",
right_bottom_bar => "&nbsp;",
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} }});
}

@ -314,13 +314,18 @@
<!-- start striker-offline -->
<table>
<div id="network_job_recorded_div">
<div id="striker-offline">
<tr>
<td>
<span name="#!variable!title_id!#" id="#!variable!title_id!#" class="config_header1">#!variable!title!#</span><br />
<span name="#!variable!message_id!#" id="#!variable!message_id!#" class="config_header2">#!variable!description!#</span>
</td>
</tr>
<tr>
<td>
<a href="/">Reload</a>
</td>
</tr>
</div>
</table>
<!-- end striker-offline -->

@ -348,7 +348,8 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="striker_0044">Done!</key>
<key name="striker_0045">The network will be reconfigured momentarily. You may need to reconnect using the new network address you chose.</key>
<key name="striker_0046">Offline...</key>
<key name="striker_0047">A job to reconfigure the network on this machine is underway. Please try again soon.</key>
<key name="striker_0047">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.</key>
<key name="striker_0048">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.</key>
<!-- Strings used by jobs -->
<key name="job_0001">Configure Network</key>

@ -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);
}

Loading…
Cancel
Save