* Finished adding the 'sessions' database table and associated code.

* Added a check to all 'Database->insert_or_update_*' methods to check if the passed-in reference UUID was found and return an empty string if not.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent b2367bb90b
commit 40aac1d5f6
  1. 2
      Anvil/Tools.pm
  2. 30
      Anvil/Tools/Account.pm
  3. 264
      Anvil/Tools/Database.pm
  4. 10
      cgi-bin/striker
  5. 2
      html/skins/alteeve/striker.html
  6. 61
      notes
  7. 113
      share/anvil.sql
  8. 4
      share/words.xml
  9. 4
      tools/anvil-change-password
  10. 10
      tools/anvil-configure-striker
  11. 4
      tools/anvil-daemon

@ -759,6 +759,7 @@ sub _set_defaults
"ip_addresses",
"jobs",
"network_interfaces",
"sessions",
"states",
"updated",
"users",
@ -803,7 +804,6 @@ sub _set_defaults
users => {
user_name => "",
user_password_hash => "",
user_session_salt => "",
user_salt => "",
user_algorithm => "",
user_hash_count => "",

@ -336,19 +336,12 @@ AND
}
else
{
my $query = "
UPDATE
sessions
SET
session_salt = ".$anvil->data->{sys}{database}{use_handle}->quote($session_salt).",
modified_date = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
session_user_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($user_uuid)."
AND
session_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({debug => $debug, query => $query, source => $THIS_FILE, line => __LINE__});
my $session_uuid = $anvil->Database->insert_or_update_sessions({
debug => $debug,
session_user_uuid => $user_uuid,
session_salt => $session_salt,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { session_uuid => $session_uuid }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0183", variables => { user => $anvil->data->{cgi}{username}{value} }});
$anvil->Account->_write_cookies({
@ -404,13 +397,19 @@ sub logout
# Delete the user's cookie data. Sending nothing to '_write_cookies' does this.
$anvil->Account->_write_cookies({debug => $debug});
my $user_uuid = defined $parameter->{user_uuid} ? $parameter->{user_uuid} : $anvil->data->{cookie}{anvil_user_uuid};
my $user_uuid = defined $parameter->{user_uuid} ? $parameter->{user_uuid} : "";
my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : $anvil->Get->host_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
user_uuid => $user_uuid.
host_uuid => $host_uuid,
}});
if (($anvil->data->{cookie}{anvil_user_uuid}) && (not $user_uuid))
{
$user_uuid = $anvil->data->{cookie}{anvil_user_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { user_uuid => $user_uuid }});
}
# If I don't have a user UUID, we can't proceed.
if (not $user_uuid)
{
@ -422,7 +421,8 @@ sub logout
# If the host_uuid is 'all', we're logging out all sessions.
# Delete the user's session salt.
# Delete the user's session salt. We don't use Database->insert_or_update_sessions() to not
# complicate handling 'all' hosts.
my $query = "
UPDATE
sessions

@ -29,6 +29,7 @@ my $THIS_FILE = "Database.pm";
# insert_or_update_ip_addresses
# insert_or_update_jobs
# insert_or_update_network_interfaces
# insert_or_update_sessions
# insert_or_update_states
# insert_or_update_users
# insert_or_update_variables
@ -1749,6 +1750,12 @@ WHERE
results => $results,
count => $count,
}});
if (not $count)
{
# I have a bridge_uuid but no matching record. Probably an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0216", variables => { uuid_name => "bridge_uuid", uuid => $bridge_uuid }});
return("");
}
foreach my $row (@{$results})
{
my $old_bridge_host_uuid = $row->[0];
@ -2043,6 +2050,12 @@ WHERE
results => $results,
count => $count,
}});
if (not $count)
{
# I have a bond_uuid but no matching record. Probably an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0216", variables => { uuid_name => "bond_uuid", uuid => $bond_uuid }});
return("");
}
foreach my $row (@{$results})
{
my $old_bond_host_uuid = $row->[0];
@ -2487,6 +2500,12 @@ WHERE
results => $results,
count => $count,
}});
if (not $count)
{
# I have an ip_address_uuid but no matching record. Probably an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0216", variables => { uuid_name => "ip_address_uuid", uuid => $ip_address_uuid }});
return("");
}
foreach my $row (@{$results})
{
my $old_ip_address_host_uuid = $row->[0];
@ -2853,6 +2872,12 @@ WHERE
results => $results,
count => $count,
}});
if (not $count)
{
# I have a job_uuid but no matching record. Probably an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0216", variables => { uuid_name => "job_uuid", uuid => $job_uuid }});
return("");
}
foreach my $row (@{$results})
{
my $old_job_host_uuid = $row->[0];
@ -3139,6 +3164,12 @@ WHERE
results => $results,
count => $count,
}});
if (not $count)
{
# I have a network_interface_uuid but no matching record. Probably an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0216", variables => { uuid_name => "network_interface_uuid", uuid => $network_interface_uuid }});
return("");
}
foreach my $row (@{$results})
{
my $old_network_interface_host_uuid = $row->[0];
@ -3256,6 +3287,195 @@ INSERT INTO
return($network_interface_uuid);
}
=head2 insert_or_update_sessions
This updates (or inserts) a record in the 'sessions' table. The C<< session_uuid >> referencing the database row will be returned.
If there is an error, an empty string is returned.
Parameters;
=head3 session_uuid (optional)
If passed, the column with that specific C<< session_uuid >> will be updated, if it exists.
=head3 session_host_uuid (optional, default Get->host_uuid)
This is the host connected to the user's session.
=head3 session_user_uuid (optional, default 'cookie::anvil_user_uuid')
This is the user whose session is being manipulated. If this is not passed and C<< cookie::anvil_user_uuid >> is not set, this method will fail and return an empty string. This is only optional in so far as, most times, the appropriate cookie data is available.
=head3 session_salt (optional)
The session salt is appended to a session hash stored on the user's browser and used to authenticate a user session. If this is not passed, the existing salt will be removed, effectively (and literally) logging the user out of the host.
=head3 session_user_agent (optional, default '$ENV{HTTP_USER_AGENT})
This is the browser user agent string to record. If nothing is passed, and the C<< HTTP_USER_AGENT >> environment variable is set, that is used.
=cut
sub insert_or_update_sessions
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->insert_or_update_states()" }});
my $uuid = defined $parameter->{uuid} ? $parameter->{uuid} : "";
my $file = defined $parameter->{file} ? $parameter->{file} : "";
my $line = defined $parameter->{line} ? $parameter->{line} : "";
my $session_uuid = defined $parameter->{session_uuid} ? $parameter->{session_uuid} : "";
my $session_host_uuid = defined $parameter->{session_host_uuid} ? $parameter->{session_host_uuid} : $anvil->Get->host_uuid;
my $session_user_uuid = defined $parameter->{session_user_uuid} ? $parameter->{session_user_uuid} : $anvil->data->{cookie}{anvil_user_uuid};
my $session_salt = defined $parameter->{session_salt} ? $parameter->{session_salt} : "";
my $session_user_agent = defined $parameter->{session_user_agent} ? $parameter->{session_user_agent} : $ENV{HTTP_USER_AGENT};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
file => $file,
line => $line,
session_uuid => $session_uuid,
session_host_uuid => $session_host_uuid,
session_user_uuid => $session_user_uuid,
session_salt => $session_salt,
session_user_agent => $session_user_agent,
}});
if (not $session_user_uuid)
{
# No user_uuid Throw an error and return.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_sessions()", parameter => "session_user_uuid" }});
return("");
}
# If we don't have a session UUID, look for one using the host and user UUID.
if (not $session_uuid)
{
my $query = "
SELECT
session_uuid
FROM
sessions
WHERE
session_user_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($session_user_uuid)."
AND
session_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($session_host_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if ($count)
{
$session_uuid = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { session_uuid => $session_uuid }});
}
}
# If we have a session UUID, check for changes before updating. If we still don't have a session
# UUID, we're INSERT'ing.
if ($session_uuid)
{
# Read back the old data
my $query = "
SELECT
session_host_uuid,
session_user_uuid,
session_salt,
session_user_agent
FROM
sessions
WHERE
session_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($session_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if (not $count)
{
# I have a session_uuid but no matching record. Probably an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0216", variables => { uuid_name => "session_uuid", uuid => $session_uuid }});
return("");
}
foreach my $row (@{$results})
{
my $old_session_host_uuid = $row->[0];
my $old_session_user_uuid = $row->[1];
my $old_session_salt = $row->[2];
my $old_session_user_agent = defined $row->[3] ? $row->[3] : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_session_host_uuid => $old_session_host_uuid,
old_session_user_uuid => $old_session_user_uuid,
old_session_salt => $old_session_salt,
old_session_user_agent => $old_session_user_agent,
}});
# Anything change?
if (($old_session_host_uuid ne $session_host_uuid) or
($old_session_user_uuid ne $session_user_uuid) or
($old_session_salt ne $session_salt) or
($old_session_user_agent ne $session_user_agent))
{
# Something changed, save.
my $query = "
UPDATE
sessions
SET
session_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($session_host_uuid).",
session_user_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($session_user_uuid).",
session_salt = ".$anvil->data->{sys}{database}{use_handle}->quote($session_salt).",
session_user_agent = ".$anvil->data->{sys}{database}{use_handle}->quote($session_user_agent).",
modified_date = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
session_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($session_uuid)."
";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
}
}
else
{
$session_uuid = $anvil->Get->uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { session_uuid => $session_uuid }});
my $query = "
INSERT INTO
sessions
(
session_uuid,
session_host_uuid,
session_user_uuid,
session_salt,
session_user_agent,
modified_date
) VALUES (
".$anvil->data->{sys}{database}{use_handle}->quote($session_uuid).",
".$anvil->data->{sys}{database}{use_handle}->quote($session_host_uuid).",
".$anvil->data->{sys}{database}{use_handle}->quote($session_user_uuid).",
".$anvil->data->{sys}{database}{use_handle}->quote($session_salt).",
".$anvil->data->{sys}{database}{use_handle}->quote($session_user_agent).",
".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{database}{timestamp})."
);
";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, uuid => $uuid, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
return($session_uuid);
}
=head2 insert_or_update_states
@ -3429,6 +3649,12 @@ WHERE
results => $results,
count => $count,
}});
if (not $count)
{
# I have a state_uuid but no matching record. Probably an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0216", variables => { uuid_name => "state_uuid", uuid => $state_uuid }});
return("");
}
foreach my $row (@{$results})
{
my $old_state_name = $row->[0];
@ -3541,7 +3767,6 @@ sub insert_or_update_users
my $user_name = defined $parameter->{user_name} ? $parameter->{user_name} : "";
my $user_password_hash = defined $parameter->{user_password_hash} ? $parameter->{user_password_hash} : "";
my $user_salt = defined $parameter->{user_salt} ? $parameter->{user_salt} : "";
my $user_session_salt = defined $parameter->{user_session_salt} ? $parameter->{user_session_salt} : "";
my $user_algorithm = defined $parameter->{user_algorithm} ? $parameter->{user_algorithm} : "";
my $user_hash_count = defined $parameter->{user_hash_count} ? $parameter->{user_hash_count} : "";
my $user_language = defined $parameter->{user_language} ? $parameter->{user_language} : $anvil->data->{sys}{language};
@ -3685,7 +3910,6 @@ INSERT INTO
user_is_admin,
user_is_experienced,
user_is_trusted,
user_session_salt,
modified_date
) VALUES (
".$anvil->data->{sys}{database}{use_handle}->quote($user_uuid).",
@ -3698,7 +3922,6 @@ INSERT INTO
".$anvil->data->{sys}{database}{use_handle}->quote($user_is_admin).",
".$anvil->data->{sys}{database}{use_handle}->quote($user_is_experienced).",
".$anvil->data->{sys}{database}{use_handle}->quote($user_is_trusted).",
".$anvil->data->{sys}{database}{use_handle}->quote($user_session_salt).",
".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{database}{timestamp})."
);
";
@ -3718,8 +3941,7 @@ SELECT
user_language,
user_is_admin,
user_is_experienced,
user_is_trusted,
user_session_salt
user_is_trusted
FROM
users
WHERE
@ -3733,6 +3955,12 @@ WHERE
results => $results,
count => $count,
}});
if (not $count)
{
# I have a user_uuid but no matching record. Probably an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0216", variables => { uuid_name => "user_uuid", uuid => $user_uuid }});
return("");
}
foreach my $row (@{$results})
{
my $old_user_name = $row->[0];
@ -3744,7 +3972,6 @@ WHERE
my $old_user_is_admin = $row->[6];
my $old_user_is_experienced = $row->[7];
my $old_user_is_trusted = $row->[8];
my $old_user_session_salt = $row->[9];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_user_name => $old_user_name,
old_user_password_hash => $old_user_password_hash,
@ -3755,7 +3982,6 @@ WHERE
old_user_is_admin => $old_user_is_admin,
old_user_is_experienced => $old_user_is_experienced,
old_user_is_trusted => $old_user_is_trusted,
old_user_session_salt => $old_user_session_salt
}});
# Anything change?
@ -3768,8 +3994,7 @@ WHERE
($old_user_language ne $user_language) or
($old_user_is_admin ne $user_is_admin) or
($old_user_is_experienced ne $user_is_experienced) or
($old_user_is_trusted ne $user_is_trusted) or
($old_user_session_salt ne $user_session_salt))
($old_user_is_trusted ne $user_is_trusted))
{
# Something changed, save.
my $query = "
@ -3785,7 +4010,6 @@ SET
user_is_admin = ".$anvil->data->{sys}{database}{use_handle}->quote($user_is_admin).",
user_is_experienced = ".$anvil->data->{sys}{database}{use_handle}->quote($user_is_experienced).",
user_is_trusted = ".$anvil->data->{sys}{database}{use_handle}->quote($user_is_trusted).",
user_session_salt = ".$anvil->data->{sys}{database}{use_handle}->quote($user_session_salt).",
modified_date = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
user_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($user_uuid)."
@ -4008,10 +4232,10 @@ WHERE
if (($variable_source_uuid ne "") && ($variable_source_table ne ""))
{
$query .= "
AND
variable_source_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($variable_source_uuid)."
AND
variable_source_table = ".$anvil->data->{sys}{database}{use_handle}->quote($variable_source_table)."
AND
variable_source_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($variable_source_uuid)."
";
}
$query .= ";";
@ -4023,6 +4247,16 @@ AND
results => $results,
count => $count,
}});
if (not $count)
{
# I have a variable_uuid, source table and source uuid but no matching record. Probably an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0217", variables => {
variable_uuid => $variable_uuid,
variable_source_table => $variable_source_table,
variable_source_uuid => $variable_source_uuid,
}});
return("");
}
foreach my $row (@{$results})
{
my $old_variable_value = $row->[0];
@ -4079,6 +4313,12 @@ WHERE
results => $results,
count => $count,
}});
if (not $count)
{
# I have a variable_uuid but no matching record. Probably an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0216", variables => { uuid_name => "variable_uuid", uuid => $variable_uuid }});
return("");
}
foreach my $row (@{$results})
{
my $old_variable_name = $row->[0];

@ -56,6 +56,8 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure =
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
print $anvil->Template->get({file => "shared.html", name => "http_headers"})."\n";
print $anvil->Template->get({file => "main.html", name => "header", variables => { language => $anvil->Words->language }});
print $anvil->Words->string({key => "error_0003"});
$anvil->nice_exit({exit_code => 2});
}
@ -178,7 +180,7 @@ sub process_task
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::login::value" => $anvil->data->{cgi}{login}{value} }});
# Woot!
my $failed = $anvil->Account->login();
my $failed = $anvil->Account->login({debug => 2});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { failed => $failed }});
if (not $failed)
{
@ -191,7 +193,7 @@ sub process_task
# Bye now!
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::logout::value" => $anvil->data->{cgi}{logout}{value} }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0215"});
$anvil->Account->logout();
$anvil->Account->logout({debug => 2});
}
else
{
@ -202,7 +204,7 @@ sub process_task
# cookies were deleted (via C<< Account->logout() >>. The user needs to log back in.
# 3 - There user's hash is invalid, it is probably expired. The user has been logged out and
# needs to log back in.
my $cookie_problem = $anvil->Account->read_cookies();
my $cookie_problem = $anvil->Account->read_cookies({debug => 2});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { cookie_problem => $cookie_problem }});
if (not $cookie_problem)
{
@ -321,7 +323,7 @@ sub process_power
# Log the user out, just to be safe.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0215"});
$anvil->Account->logout();
$anvil->Account->logout({debug => 2});
}
else
{

@ -475,7 +475,7 @@
#!string!striker_0071!# <input type="checkbox" id="#!variable!access!#_ping" name="#!variable!access!#_ping" #!variable!ping_checked!# />
</td>
<td width="25%" class="padded_cell" align="center">
<a href="striker=true&task=sync&delete=#!variable!access!#" id="#!variable!access!#_delete" class="button">#!string!striker_0068!#"<a/>
<a href="striker=true&task=sync&delete=#!variable!access!#" id="#!variable!access!#_delete" class="button">#!string!striker_0068!#<a/>
</td>
</tr>
<!-- end striker-sync-entry -->

61
notes

@ -506,3 +506,64 @@ pcs resource manage srv01-c7
====
BEGIN TRANSACTION;
DROP FUNCTION history_sessions() CASCADE;
DROP TABLE history.sessions;
DROP TABLE sessions;
CREATE TABLE sessions (
session_uuid uuid not null primary key, -- This is the single most important record in Anvil!. Everything links back to here.
session_host_uuid uuid not null, -- This is the host uuid for this session.
session_user_uuid uuid not null, -- This is the user uuid for the user logging in.
session_salt text not null, -- This is used when generating a session hash for a session when they log in.
session_user_agent text,
modified_date timestamp with time zone not null,
FOREIGN KEY(session_host_uuid) REFERENCES hosts(host_uuid),
FOREIGN KEY(session_user_uuid) REFERENCES users(user_uuid)
);
ALTER TABLE sessions OWNER TO admin;
CREATE TABLE history.sessions (
history_id bigserial,
session_uuid uuid,
session_host_uuid uuid,
session_user_uuid uuid,
session_salt text,
session_user_agent text,
modified_date timestamp with time zone not null
);
ALTER TABLE history.sessions OWNER TO admin;
CREATE FUNCTION history_sessions() RETURNS trigger
AS $$
DECLARE
history_sessions RECORD;
BEGIN
SELECT INTO history_sessions * FROM sessions WHERE session_uuid = new.session_uuid;
INSERT INTO history.sessions
(session_uuid,
session_host_uuid,
session_user_uuid,
session_salt,
session_user_agent,
modified_date)
VALUES
(history_sessions.session_uuid,
history_sessions.session_host_uuid,
history_sessions.session_user_uuid,
history_sessions.session_salt,
history_sessions.session_user_agent,
history_sessions.modified_date);
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
ALTER FUNCTION history_sessions() OWNER TO admin;
CREATE TRIGGER trigger_sessions
AFTER INSERT OR UPDATE ON sessions
FOR EACH ROW EXECUTE PROCEDURE history_sessions();
COMMIT;

@ -112,63 +112,6 @@ CREATE TRIGGER trigger_users
FOR EACH ROW EXECUTE PROCEDURE history_users();
-- This stores user session information on a per-dashboard basis.
CREATE TABLE sessions (
session_uuid uuid not null primary key, -- This is the single most important record in Anvil!. Everything links back to here.
session_host_uuid uuid not null, -- This is the host uuid for this session.
session_user_uuid uuid not null, -- This is the user uuid for the user logging in.
session_session_salt text not null, -- This is used when generating a session hash for a session when they log in.
session_user_agent text,
modified_date timestamp with time zone not null
FOREIGN KEY(session_host_uuid) REFERENCES hosts(host_uuid),
FOREIGN KEY(session_user_uuid) REFERENCES users(user_uuid)
);
ALTER TABLE sessions OWNER TO #!variable!session!#;
CREATE TABLE history.sessions (
history_id bigserial,
session_uuid uuid,
session_host_uuid uuid,
session_user_uuid uuid,
session_session_salt text,
session_user_agent text,
modified_date timestamp with time zone not null
);
ALTER TABLE history.sessions OWNER TO #!variable!session!#;
CREATE FUNCTION history_sessions() RETURNS trigger
AS $$
DECLARE
history_sessions RECORD;
BEGIN
SELECT INTO history_sessions * FROM sessions WHERE session_uuid = new.session_uuid;
INSERT INTO history.sessions
(session_uuid,
session_host_uuid,
session_user_uuid,
session_session_salt,
session_user_agent,
modified_date)
VALUES
(history_sessions.session_uuid,
history_sessions.session_host_uuid,
history_sessions.session_user_uuid,
history_sessions.session_session_salt,
history_sessions.session_user_agent,
history_sessions.modified_date);
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
ALTER FUNCTION history_sessions() OWNER TO #!variable!session!#;
CREATE TRIGGER trigger_sessions
AFTER INSERT OR UPDATE ON sessions
FOR EACH ROW EXECUTE PROCEDURE history_sessions();
-- This stores information about the host machine. This is the master table that everything will be linked
-- to.
CREATE TABLE hosts (
@ -264,6 +207,62 @@ CREATE TRIGGER trigger_host_variable
FOR EACH ROW EXECUTE PROCEDURE history_host_variable();
-- This stores user session information on a per-dashboard basis.
CREATE TABLE sessions (
session_uuid uuid not null primary key, -- This is the single most important record in Anvil!. Everything links back to here.
session_host_uuid uuid not null, -- This is the host uuid for this session.
session_user_uuid uuid not null, -- This is the user uuid for the user logging in.
session_salt text not null, -- This is used when generating a session hash for a session when they log in.
session_user_agent text,
modified_date timestamp with time zone not null,
FOREIGN KEY(session_host_uuid) REFERENCES hosts(host_uuid),
FOREIGN KEY(session_user_uuid) REFERENCES users(user_uuid)
);
ALTER TABLE sessions OWNER TO #!variable!user!#;
CREATE TABLE history.sessions (
history_id bigserial,
session_uuid uuid,
session_host_uuid uuid,
session_user_uuid uuid,
session_salt text,
session_user_agent text,
modified_date timestamp with time zone not null
);
ALTER TABLE history.sessions OWNER TO #!variable!user!#;
CREATE FUNCTION history_sessions() RETURNS trigger
AS $$
DECLARE
history_sessions RECORD;
BEGIN
SELECT INTO history_sessions * FROM sessions WHERE session_uuid = new.session_uuid;
INSERT INTO history.sessions
(session_uuid,
session_host_uuid,
session_user_uuid,
session_salt,
session_user_agent,
modified_date)
VALUES
(history_sessions.session_uuid,
history_sessions.session_host_uuid,
history_sessions.session_user_uuid,
history_sessions.session_salt,
history_sessions.session_user_agent,
history_sessions.modified_date);
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
ALTER FUNCTION history_sessions() OWNER TO #!variable!user!#;
CREATE TRIGGER trigger_sessions
AFTER INSERT OR UPDATE ON sessions
FOR EACH ROW EXECUTE PROCEDURE history_sessions();
-- This stores alerts coming in from various sources
CREATE TABLE alerts (
alert_uuid uuid not null primary key,

@ -364,6 +364,8 @@ The database connection error was:
<key name="log_0213">The peer: [#!variable!peer_uuid!#] is not yet in 'hosts', continuing to wait.</key>
<key name="log_0214">The peer: [#!variable!peer_name!#] is now in 'hosts', proceeding.</key>
<key name="log_0215">Logging the user: [#!data!sys::users::user_name!#] out.</key>
<key name="log_0216">The #!variable!uuid_name!#: [#!variable!uuid!#] was passed in, but no record with that UUID was found in the database.</key>
<key name="log_0217">The variable with variable_uuid: [#!variable!variable_uuid!#], variable_source_table: [#!variable!variable_source_table!#] and variable_source_uuid: [#!variable!variable_source_uuid!#] was not found in the database, so unable to update.</key>
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
<key name="t_0000">Test</key>
@ -534,7 +536,7 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<!-- Errors -->
<key name="error_0001">There are not enough network interfaces on this machine. You have: [#!variable!interface_count!#] interface(s), and you need at least: [#!variable!required_interfaces_for_single!#] interfaces to connect to the requested networks (one for Back-Channel and one for each Internet-Facing network).</key>
<key name="error_0002">The local system UUID can't be read yet. This might be because the system is brand new and/or ScanCore hasn't run yet. Please try again in a minute.</key>
<key name="error_0003">None of the databases are accessible, unable to proceed.</key>
<key name="error_0003">None of the databases are accessible, unable to proceed. Please be sure that 'anvil-daemon' is enabled and running on the database machine(s).</key>
<key name="error_0004">The gateway address doesn't match any of your networks.</key>
<key name="error_0005">This program must run with 'root' level privileges.</key>
<key name="error_0006">No password was given, exiting.</key>

@ -29,7 +29,7 @@ $| = 1;
$< = $>;
$( = $);
my $anvil = Anvil::Tools->new({log_level => 1, log_secure => 0});
my $anvil = Anvil::Tools->new({log_level => 1, log_secure => 1});
# Read switches
$anvil->Get->switches;
@ -178,7 +178,7 @@ sub update_local_passwords
user_is_trusted => 1,
});
# Log out any Striker sessions.
$anvil->Account->logout{host_uuid => "all"});
$anvil->Account->logout({host_uuid => "all"});
print $anvil->Words->string({key => "message_0025"})."\n";
# Validate

@ -94,7 +94,7 @@ if (not $anvil->data->{switches}{'no-reboot'})
# jobs.json. We'll also log the user out, in case we were re-configuring.
sleep 5;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0215"});
$anvil->Account->logout;
$anvil->Account->logout({debug => 2});
$anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{'anvil-manage-power'}." --reboot -y"});
}
@ -136,15 +136,15 @@ sub update_passwords
else
{
my $return_code = "";
my $output = $anvil->System->call({debug => 3, 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 => 3, secure => 0, list => { output => $output }});
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)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, list => { line => $line }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { line => $line }});
if ($line =~ /return_code:(\d+)$/)
{
$return_code = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, list => { return_code => $return_code }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { return_code => $return_code }});
}
}

@ -42,9 +42,11 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure =
# Connect to the database(s). If we have no connections, we'll proceed anyway as one of the 'run_once' tasks
# is to setup the database server.
$anvil->Database->connect();
$anvil->Database->connect({debug => 2});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
exit;
# If I have no databases, sleep for a second and then exit (systemd will restart us).
if (not $anvil->data->{sys}{database}{connections})
{

Loading…
Cancel
Save