* Created Log->language that sets/returns the active log language. * Created Log->variables that takes a hash reference and logs their variable: [$value] pairs. * Created the new /usr/sbin/striker/ directory which is added to the list of search directories. We will store our tools here. * Created the scancore-daemon and scancore-daemon.unit files which will handle all the things we used to use crontab for, minus ScanCore itself. * Created the scancore-update-states that will eventually store some machine state information in a file that the web browser can read. * Created the cgi-bin/home script that will be the main landing page for the Striker UI. * Added some of the initial html files. Signed-off-by: Digimer <digimer@alteeve.ca>main
parent
e49d5285c0
commit
753d7a3ba6
15 changed files with 10785 additions and 23 deletions
@ -0,0 +1,126 @@ |
|||||||
|
package AN::Tools::System; |
||||||
|
# |
||||||
|
# This module contains methods used to handle common system tasks. |
||||||
|
# |
||||||
|
|
||||||
|
use strict; |
||||||
|
use warnings; |
||||||
|
use Data::Dumper; |
||||||
|
|
||||||
|
our $VERSION = "3.0.0"; |
||||||
|
my $THIS_FILE = "System.pm"; |
||||||
|
|
||||||
|
### Methods; |
||||||
|
# read_file |
||||||
|
|
||||||
|
=pod |
||||||
|
|
||||||
|
=encoding utf8 |
||||||
|
|
||||||
|
=head1 NAME |
||||||
|
|
||||||
|
AN::Tools::System |
||||||
|
|
||||||
|
Provides all methods related to storage on a system. |
||||||
|
|
||||||
|
=head1 SYNOPSIS |
||||||
|
|
||||||
|
use AN::Tools; |
||||||
|
|
||||||
|
# Get a common object handle on all AN::Tools modules. |
||||||
|
my $an = AN::Tools->new(); |
||||||
|
|
||||||
|
# Access to methods using '$an->System->X'. |
||||||
|
# |
||||||
|
# Example using 'read_file()'; |
||||||
|
my $data = $an->System->read_file({file => "/tmp/foo"}); |
||||||
|
|
||||||
|
=head1 METHODS |
||||||
|
|
||||||
|
Methods in this module; |
||||||
|
|
||||||
|
=cut |
||||||
|
sub new |
||||||
|
{ |
||||||
|
my $class = shift; |
||||||
|
my $self = {}; |
||||||
|
|
||||||
|
bless $self, $class; |
||||||
|
|
||||||
|
return ($self); |
||||||
|
} |
||||||
|
|
||||||
|
# Get a handle on the AN::Tools object. I know that technically that is a sibling module, but it makes more |
||||||
|
# sense in this case to think of it as a parent. |
||||||
|
sub parent |
||||||
|
{ |
||||||
|
my $self = shift; |
||||||
|
my $parent = shift; |
||||||
|
|
||||||
|
$self->{HANDLE}{TOOLS} = $parent if $parent; |
||||||
|
|
||||||
|
return ($self->{HANDLE}{TOOLS}); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
############################################################################################################# |
||||||
|
# Public methods # |
||||||
|
############################################################################################################# |
||||||
|
|
||||||
|
|
||||||
|
=head2 read_file |
||||||
|
|
||||||
|
This reads in a file and returns the contents of the file as a single string variable. |
||||||
|
|
||||||
|
$an->System->read_file({file => "/tmp/foo"}); |
||||||
|
|
||||||
|
If it fails to find the file, or the file is not readable, 'C<< undef >>' is returned. |
||||||
|
|
||||||
|
Parameters; |
||||||
|
|
||||||
|
=head3 file (required) |
||||||
|
|
||||||
|
This is the name of the file to read. |
||||||
|
|
||||||
|
=cut |
||||||
|
sub read_file |
||||||
|
{ |
||||||
|
my $self = shift; |
||||||
|
my $parameter = shift; |
||||||
|
my $an = $self->parent; |
||||||
|
|
||||||
|
my $body = ""; |
||||||
|
my $file = defined $parameter->{file} ? $parameter->{file} : ""; |
||||||
|
|
||||||
|
if (not $file) |
||||||
|
{ |
||||||
|
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020"}); |
||||||
|
return(undef); |
||||||
|
} |
||||||
|
elsif (not -e $file) |
||||||
|
{ |
||||||
|
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0021", variables => { file => $file }}); |
||||||
|
return(undef); |
||||||
|
} |
||||||
|
elsif (not -r $file) |
||||||
|
{ |
||||||
|
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0022", variables => { file => $file }}); |
||||||
|
return(undef); |
||||||
|
} |
||||||
|
|
||||||
|
my $shell_call = $file; |
||||||
|
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0012", variables => { shell_call => $shell_call }}); |
||||||
|
open (my $file_handle, "<", $shell_call) or $an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0015", variables => { shell_call => $shell_call, error => $! }}); |
||||||
|
while(<$file_handle>) |
||||||
|
{ |
||||||
|
chomp; |
||||||
|
my $line = $_; |
||||||
|
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0023", variables => { line => $line }}); |
||||||
|
$body .= $line."\n"; |
||||||
|
} |
||||||
|
close $file_handle; |
||||||
|
$body =~ s/\n$//s; |
||||||
|
|
||||||
|
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { body => $body }}); |
||||||
|
return($body); |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
|
||||||
|
<!-- |
||||||
|
Company: Alteeve's Niche, Inc. |
||||||
|
License: GPL v2+ |
||||||
|
Author: Madison Kelly <mkelly@alteeve.ca> |
||||||
|
|
||||||
|
This is the AN::Tools master 'words' file. |
||||||
|
--> |
||||||
|
|
||||||
|
<words> |
||||||
|
<meta version="3.0.0" languages="en_CA,jp"/> |
||||||
|
<!-- Canadian English --> |
||||||
|
<language name="en_CA" long_name="Canadian English" description="Striker/ScanCore language file."> |
||||||
|
|
||||||
|
<key name="brand_0001">Alteeve</key> |
||||||
|
<key name="brand_0002">Anvil!</key> |
||||||
|
<key name="brand_0003">Striker</key> |
||||||
|
<key name="brand_0004">ScanCore</key> |
||||||
|
|
||||||
|
</language> |
||||||
|
<!-- 日本語 --> |
||||||
|
<language name="jp" long_name="日本語" description="Striker/ScanCore language file."> |
||||||
|
|
||||||
|
<key name="brand_0001">アルティーブ</key> |
||||||
|
<key name="brand_0002">Anvil!</key> |
||||||
|
<key name="brand_0003">ストライカ</key> |
||||||
|
<key name="brand_0004">スカンコア</key> |
||||||
|
|
||||||
|
</language> |
||||||
|
</words> |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@ |
|||||||
|
jquery-3.2.1.js |
@ -0,0 +1,14 @@ |
|||||||
|
/* |
||||||
|
Colours; |
||||||
|
- Darkest Gray: #343434 |
||||||
|
- Logo Gray: #9ba0a5 |
||||||
|
- Lightest Gray: #f7f7f7 |
||||||
|
- Font Dark Gray: #444444 |
||||||
|
- Font Light Gray: #f2f2f2 |
||||||
|
- Alteeve Red: #d02724 |
||||||
|
*/ |
||||||
|
|
||||||
|
body { |
||||||
|
background-image: url("skins/alteeve/images/Texture.jpg"); |
||||||
|
background-repeat: repeat-y; |
||||||
|
} |
@ -1,38 +1,49 @@ |
|||||||
<!-- start master --> |
<!-- start master --> |
||||||
#!replace!header!# |
#!variable!header!# |
||||||
|
|
||||||
<table> |
<table> |
||||||
<tr> |
<tr> |
||||||
<td> |
<td> |
||||||
#!replace!left_top_bar!# |
#!variable!left_top_bar!# |
||||||
</td> |
</td> |
||||||
<td> |
<td> |
||||||
#!replace!center_top_bar!# |
#!variable!center_top_bar!# |
||||||
</td> |
</td> |
||||||
<td> |
<td> |
||||||
#!replace!right_top_bar!# |
#!variable!right_top_bar!# |
||||||
</td> |
</td> |
||||||
</tr> |
</tr> |
||||||
<tr> |
<tr> |
||||||
<td colspan="3"> |
<td colspan="3"> |
||||||
#!replace!center_body!# |
#!variable!center_body!# |
||||||
</td> |
</td> |
||||||
</tr> |
</tr> |
||||||
<tr> |
<tr> |
||||||
<td> |
<td> |
||||||
#!replace!left_bottom_bar!# |
#!variable!left_bottom_bar!# |
||||||
</td> |
</td> |
||||||
<td> |
<td> |
||||||
#!replace!center_bottom_bar!# |
#!variable!center_bottom_bar!# |
||||||
</td> |
</td> |
||||||
<td> |
<td> |
||||||
#!replace!right_bottom_bar!# |
#!variable!right_bottom_bar!# |
||||||
</td> |
</td> |
||||||
</tr> |
</tr> |
||||||
</table> |
</table> |
||||||
|
|
||||||
#!replace!footer!# |
#!variable!footer!# |
||||||
<!-- end master --> |
<!-- end master --> |
||||||
|
|
||||||
|
<!-- start header --> |
||||||
|
<!DOCTYPE html> |
||||||
|
<html lang="#!variable!language!#"> |
||||||
|
<head> |
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
||||||
|
<title>#!string!brand_0001!# - #!string!brand_0003!#</title> |
||||||
|
<link rel="stylesheet" href="#!variable!skin_directory!#/main.css" media="screen" /> |
||||||
|
<script type="text/javascript" src="#!variable!html_directory!#/jquery-latest.js"></script> |
||||||
|
</head> |
||||||
|
<!-- end header --> |
||||||
|
|
||||||
<!-- start button_bar --> |
<!-- start button_bar --> |
||||||
<!--end button_bar --> |
<!--end button_bar --> |
||||||
|
@ -0,0 +1,53 @@ |
|||||||
|
#!/usr/bin/perl |
||||||
|
# |
||||||
|
# This is the master daemon that manages all periodically run processes on Striker dashboards and Anvil! |
||||||
|
# nodes. |
||||||
|
# |
||||||
|
use strict; |
||||||
|
use warnings; |
||||||
|
use AN::Tools; |
||||||
|
|
||||||
|
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
||||||
|
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
||||||
|
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
||||||
|
{ |
||||||
|
$running_directory =~ s/^\./$ENV{PWD}/; |
||||||
|
} |
||||||
|
|
||||||
|
my $an = AN::Tools->new(); |
||||||
|
$an->Log->level(2); |
||||||
|
|
||||||
|
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete. |
||||||
|
$| = 1; |
||||||
|
|
||||||
|
while(1) |
||||||
|
{ |
||||||
|
update_state_file($an); |
||||||
|
|
||||||
|
sleep 10; |
||||||
|
} |
||||||
|
|
||||||
|
exit(0); |
||||||
|
|
||||||
|
############################################################################################################# |
||||||
|
# Functions # |
||||||
|
############################################################################################################# |
||||||
|
|
||||||
|
# This calls 'scancore-update-states' which will scan the local machine's state (hardware and software) and |
||||||
|
# record write it out to an HTML file |
||||||
|
sub update_state_file |
||||||
|
{ |
||||||
|
my ($an) = @_; |
||||||
|
|
||||||
|
my $shell_call = $an->data->{path}{tools}{'scancore-update-states'}; |
||||||
|
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0011", variables => { shell_call => $shell_call }}); |
||||||
|
open (my $file_handle, $shell_call." 2>&1 |") or $an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }}); |
||||||
|
while(<$file_handle>) |
||||||
|
{ |
||||||
|
chomp; |
||||||
|
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0017", variables => { output => $_ }}); |
||||||
|
} |
||||||
|
close $file_handle; |
||||||
|
|
||||||
|
return(0); |
||||||
|
} |
@ -0,0 +1,84 @@ |
|||||||
|
#!/usr/bin/perl |
||||||
|
# |
||||||
|
# This is the master daemon that manages all periodically run processes on Striker dashboards and Anvil! |
||||||
|
# nodes. |
||||||
|
# |
||||||
|
use strict; |
||||||
|
use warnings; |
||||||
|
use AN::Tools; |
||||||
|
|
||||||
|
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
||||||
|
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
||||||
|
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
||||||
|
{ |
||||||
|
$running_directory =~ s/^\./$ENV{PWD}/; |
||||||
|
} |
||||||
|
|
||||||
|
my $an = AN::Tools->new(); |
||||||
|
$an->Log->level(2); |
||||||
|
|
||||||
|
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete. |
||||||
|
$| = 1; |
||||||
|
|
||||||
|
|
||||||
|
# my $shell_call = "/sys/class/net/ens11/address"; |
||||||
|
# $an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0012", variables => { shell_call => $shell_call }}); |
||||||
|
# open (my $file_handle, "<$shell_call") or $an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0015", variables => { shell_call => $shell_call, error => $! }});; |
||||||
|
# while(<$file_handle>) |
||||||
|
# { |
||||||
|
# chomp; |
||||||
|
# my $line = $_; |
||||||
|
# $an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0023", variables => { output => $line }}); |
||||||
|
# print "line: [$line]\n"; |
||||||
|
# } |
||||||
|
# close |
||||||
|
|
||||||
|
report_network($an); |
||||||
|
|
||||||
|
exit(0); |
||||||
|
|
||||||
|
############################################################################################################# |
||||||
|
# Functions # |
||||||
|
############################################################################################################# |
||||||
|
|
||||||
|
# This reports the current network interface states, tracked by the MAC address. |
||||||
|
sub report_network |
||||||
|
{ |
||||||
|
my ($an) = @_; |
||||||
|
|
||||||
|
my $directory = $an->data->{path}{sysfs}{network_interfaces}; |
||||||
|
local(*DIRECTORY); |
||||||
|
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0018", variables => { directory => $directory }}); |
||||||
|
opendir(DIRECTORY, $directory); |
||||||
|
while(my $file = readdir(DIRECTORY)) |
||||||
|
{ |
||||||
|
next if $file eq "."; |
||||||
|
next if $file eq ".."; |
||||||
|
next if $file eq "lo"; |
||||||
|
my $full_path = "$directory/$file"; |
||||||
|
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { full_path => $full_path }}); |
||||||
|
if (-d $full_path) |
||||||
|
{ |
||||||
|
# Pull out the data I want. |
||||||
|
my $interface = $file; |
||||||
|
my $mac_address = $an->System->read_file({file => $full_path."/address"}); |
||||||
|
my $link_state = $an->System->read_file({file => $full_path."/carrier"}); |
||||||
|
my $mtu = $an->System->read_file({file => $full_path."/mtu"}); |
||||||
|
my $duplex = $an->System->read_file({file => $full_path."/duplex"}); # full or half? |
||||||
|
my $operational = $an->System->read_file({file => $full_path."/operstate"}); # up or down |
||||||
|
my $speed = $an->System->read_file({file => $full_path."/speed"}); # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link |
||||||
|
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||||
|
interface => $interface, |
||||||
|
mac_address => $mac_address, |
||||||
|
link_state => $link_state, |
||||||
|
mtu => $mtu, |
||||||
|
duplex => $duplex, |
||||||
|
operational => $operational, |
||||||
|
speed => $speed, |
||||||
|
}}); |
||||||
|
} |
||||||
|
} |
||||||
|
closedir(DIRECTORY); |
||||||
|
|
||||||
|
return(0); |
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
[Unit] |
||||||
|
Description=ScanCore daemon used to handle several jobs as part of the Anvil! IA suite |
||||||
|
Wants=network.target |
||||||
|
|
||||||
|
[Service] |
||||||
|
Type=simple |
||||||
|
ExecStart=/usr/sbin/striker-daemon |
||||||
|
ExecStop=/bin/kill -WINCH ${MAINPID} |
||||||
|
PrivateTmp=true |
||||||
|
|
||||||
|
[Install] |
||||||
|
WantedBy=multi-user.target |
Loading…
Reference in new issue