Zane C. B-H 8 months ago
parent
commit
533f9d8376
  1. 37
      bin/stoaster
  2. 66
      lib/Server/Toaster.pm
  3. 43
      lib/Server/Toaster/Defaults.pm
  4. 42
      lib/Server/Toaster/Modules/Apache.pm
  5. 78
      lib/Server/Toaster/Modules/Base.pm
  6. 0
      t/stoaster/.exists

37
bin/stoaster

@ -0,0 +1,37 @@
#!/usr/bin/env perl
#
#This software is Copyright (c) 2021 by Zane C. Bowers-Hadley.
#
#This is free software, licensed under:
#
# The Artistic License 2.0 (GPL Compatible)
use strict;
use warnings;
use Server::Toaster;
use Getopt::Long qw(:config pass_through);
use Data::Dumper;
my $stoaster_dir;
my $templates_dir;
my $output_dir;
my $module;
my $action;
GetOptions(
's=s' => \$stoaster_dir,
't=s' => \$templates_dir,
'o=s' => \$output_dir,
'm=s' => \$module,
'a=s' => \$action,
);
my $stoaster = Server::Toaster->new(
dir => $stoaster_dir,
templates => $templates_dir,
output => $output_dir,
);
if ($action eq 'get_files') {
my %returned=$stoaster->get_files($module);
print Dumper( \%returned );
}

66
lib/Server/Toaster.pm

@ -49,7 +49,6 @@ This initiates the module.
$templates and $output will be created as needed, but $dir must
exist upon module init or it will die.
=cut
sub new {
@ -75,12 +74,14 @@ sub new {
$opts{templates} = $opts{dir} . '/templates';
}
my %defaults = Server::Toaster::Defaults->get;
# init the object
my $self = {
dir => $opts{dir},
output => $opts{output},
templates => $opts{templates},
defaults=>Server::Toaster::Defaults->get,
templates => $opts{templates},
defaults => \%defaults,
share => dist_dir('Server-Toaster'),
};
bless $self;
@ -110,39 +111,44 @@ sub fill_in {
my ( $self, %opts ) = @_;
# make sure we have a module specified
if (!defined( $opts{module} )) {
die( 'No module defined' );
if ( !defined( $opts{module} ) ) {
die('No module defined');
}
# make sure we have a hostname
if (!defined( $opts{hostname} )) {
die( 'No hostname defined' );
if ( !defined( $opts{hostname} ) ) {
die('No hostname defined');
}
# make sure we have a config to use
if (!defined( $opts{config} )) {
die( 'No config defined' );
if ( !defined( $opts{config} ) ) {
die('No config defined');
}
# do a very basic check to make sure we have something that appears to atleast be sane
# for the name of the module
if ($opts{module}!~/^[A-Za-z0-9\_\:]+$/) {
die('"'.$opts{module}.'" does not appear to be a valid module name');
if ( $opts{module} !~ /^[A-Za-z0-9\_\:]+$/ ) {
die( '"' . $opts{module} . '" does not appear to be a valid module name' );
}
my $merger=Hash::Merge->new('LEFT_PRECEDENT');
my $merger = Hash::Merge->new('LEFT_PRECEDENT');
my $config=$merger->merge( $opts{config}, $self->{defaults} );
my $config = $merger->merge( $opts{config}, $self->{defaults} );
my $to_eval='use Server::Toaster::Modules::'.$opts{module}.'; '.
'my $st_module=Server::Toaster::Modules::'.$opts{module}.'->new(',
'dir=>$self->{dir}, '.
'output=>$self->{output}, '.
'templates=>$self->{templates} );'.
'$st_module->fill_in(%opts);';
my $to_eval
= 'use Server::Toaster::Modules::'
. $opts{module} . '; '
. 'my $st_module=Server::Toaster::Modules::'
. $opts{module}
. '->new('.
'dir=>$self->{dir}, '
. 'output=>$self->{output}, '
. 'templates=>$self->{templates} );'
. '$st_module->fill_in(%opts);';
eval($to_eval);
}
=head2 get_files
@ -161,7 +167,7 @@ Sever::Toaster::Modules. So 'Sever::Toaster::Modules::Apache' becomes
=cut
sub get_files {
my ( $blank, $module ) = @_;
my ( $self, $module ) = @_;
# make sure we have a module defined
if ( !defined($module) ) {
@ -170,12 +176,20 @@ sub get_files {
my %returned;
my $to_eval
= 'use Server::Toaster::Modules::'
. $module
. '; %returned=Server::Toaster::Modules::'
= 'use Server::Toaster::Modules::'
. $module . '; '
. 'my $st_module=Server::Toaster::Modules::'
. $module
. '->get_files;';
eval( $to_eval );
. '->new('.
'dir=>$self->{dir}, '
. 'output=>$self->{output}, '
. 'templates=>$self->{templates} );'
. '%returned=$st_module->get_files;';
eval($to_eval);
if ($@) {
print "Evaled... ".$to_eval."\n";
die "Eval failed... ".$@;
}
return %returned;
}

43
lib/Server/Toaster/Defaults.pm

@ -46,7 +46,7 @@ sub get {
ssl_honor_cipher_order => '0',
server_admin_email => 'you@foo.bar',
server_admin_name => 'Who Ever',
ssl_cert_path => '/usr/local/etc/letsencrypt/live/%%%DOMAN%%%/',
ssl_cert_path => '/usr/local/etc/letsencrypt/live/%%%DOMAIN%%%/',
Apache => {
listen => [],
http_port => '80',
@ -54,8 +54,9 @@ sub get {
server_root => '/usr/local',
default_https_redirect => '0',
enable_https => '0',
include_optional => 1,
include_optional => '0',
ssl_stapling => '1',
version => '2.4',
ssl_stapling_cache => 'shmcb:logs/ssl_stapling(32768)',
modules => {
mpm_prefork => '1',
@ -152,33 +153,33 @@ sub get {
wsgi => "1",
auth_openidc => "1",
},
modules_d => 1,
modules_d => '0',
user => 'www',
group => 'www',
doc_root => '/usr/local/www/apache24/data',
cgi => 0,
cgi => '0',
mpm_event => {
StartServers => 3,
MinSpareThreads => 75,
MaxSpareThreads => 250,
ThreadsPerChild => 25,
MaxRequestWorkers => 400,
MaxConnectionsPerChild => 0
StartServers => '3',
MinSpareThreads => '75',
MaxSpareThreads => '250',
ThreadsPerChild => '25',
MaxRequestWorkers => '400',
MaxConnectionsPerChild => '0'
},
mpm_prefork => {
StartServers => 5,
MinSpareServers => 5,
MaxSpareServers => 10,
MaxRequestWorkers => 250,
MaxConnectionsPerChild => 0,
StartServers => '5',
MinSpareServers => '5',
MaxSpareServers => '10',
MaxRequestWorkers => '250',
MaxConnectionsPerChild => '0',
},
mpm_worker => {
StartServers => 3,
MinSpareThreads => 75,
MaxSpareThreads => 250,
ThreadsPerChild => 25,
MaxRequestWorkers => 400,
MaxConnectionsPerChild => 0,
StartServers => '3',
MinSpareThreads => '75',
MaxSpareThreads => '250',
ThreadsPerChild => '25',
MaxRequestWorkers => '400',
MaxConnectionsPerChild => '0',
}
}

42
lib/Server/Toaster/Modules/Apache.pm

@ -3,11 +3,12 @@ package Server::Toaster::Modules::Apache;
use 5.006;
use strict;
use warnings;
use base 'Server::Toaster::Modules::Base';
use Moose;
extends 'Server::Toaster::Modules::Base';
=head1 NAME
Server::Toaster::Modules::Apache - Apache helper for Server::Toaster
Server::Toaster::Modules::Apache - Apache module for Server::Toaster
=head1 VERSION
@ -49,24 +50,24 @@ sub fill_in {
my ( $self, %opts ) = @_;
# make sure we have a hostname
if (!defined( $opts{hostname} )) {
die( 'No hostname defined' );
if ( !defined( $opts{hostname} ) ) {
die('No hostname defined');
}
# make sure we have a config to use
if (!defined( $opts{config} )) {
die( 'No config defined' );
if ( !defined( $opts{config} ) ) {
die('No config defined');
}
my $vars={
hostname=>$opts{hostname},
d=>Server::Toaster::Defaults->get,
c=>%opts{config},
}
my $vars = {
hostname => $opts{hostname},
d => Server::Toaster::Defaults->get,
c => %opts{config},
};
}
=head2 get_files
=head2 get_files_module
Fetches a list of templates a module uses.
@ -75,18 +76,11 @@ and the value being the full path to the file.
=cut
sub get_files {
my ( $self ) = @_;
my $dir=dist_dir('Server-Toaster');
my %returned=(
'Apache/domain.tt'=>$dir.'/Apache/domain.tt',
'Apache/httpd.conf.tt'=>$dir.'/Apache/httpd.conf.tt',
'Apache/doc_root.conf.tt'=>$dir.'/Apache/doc_root.conf.tt',
);
return %returned;
sub get_files_module {
return (
'Apache/domain.tt',
'Apache/httpd.conf.tt'
);
}
=head1 AUTHOR

78
lib/Server/Toaster/Modules/Base.pm

@ -6,6 +6,8 @@ use warnings;
use Template;
use Server::Toaster::Defaults;
use File::ShareDir ':ALL';
use File::Spec::Functions;
use Moose;
=head1 NAME
@ -28,8 +30,6 @@ Perhaps a little code snippet.
use Server::Toaster::Modules::Apache;
my $st = Server::Toaster->new();
=head1 METHODS
@ -49,7 +49,6 @@ This initiates the module.
$templates and $output will be created as needed, but $dir must
exist upon module init or it will die.
=cut
sub new {
@ -67,12 +66,12 @@ sub new {
# set the default output dir if non is specified
if ( !defined( $opts{output} ) ) {
$opts{output} = $opts{dir} . '/output';
$opts{output} = catdir( $opts{dir}, 'output' );
}
# set the default template dir if non is specified
if ( !defined( $opts{templates} ) ) {
$opts{templates} = $opts{dir} . '/templates';
$opts{templates} = catdir($opts{dir} , 'templates');
}
# init the object
@ -87,42 +86,7 @@ sub new {
return $self;
}
=head2 fill_in
This filles in the templates.
The required values are as below.
hostname - The hostname of the system being processed.
config - The config hash ref for the use with filling the templates.
This will die upon error.
=cut
sub fill_in {
my ( $self, %opts ) = @_;
# make sure we have a hostname
if (!defined( $opts{hostname} )) {
die( 'No hostname defined' );
}
# make sure we have a config to use
if (!defined( $opts{config} )) {
die( 'No config defined' );
}
my $vars={
hostname=>$opts{hostname},
d=>Server::Toaster::Defaults->get,
c=>%opts{config},
}
}
=head2 get_files
=head2 get_files_module
Fetches a list of templates a module uses.
@ -132,17 +96,29 @@ and the value being the full path to the file.
=cut
sub get_files {
my ( $self ) = @_;
my $dir=dist_dir('Server-Toaster');
my %returned=(
'Apache/domain.tt'=>$dir.'/Apache/domain.tt',
'Apache/httpd.conf.tt'=>$dir.'/Apache/httpd.conf.tt',
'Apache/doc_root.conf.tt'=>$dir.'/Apache/doc_root.conf.tt',
);
my ($self) = @_;
my @files=$self->get_files_module;
my $share_dir = dist_dir('Server-Toaster');
my %to_return;
foreach my $file (@files) {
my @split_path=split(/\//, $file);
$to_return{$file}={
rel=>catfile(@split_path),
share=>catfile($share_dir, @split_path),
};
my $use_test=catfile( $self->{templates}, @split_path );
if (-f $use_test ) {
$to_return{$file}{use}=$use_test;
}else {
$to_return{$file}{use}=$to_return{$file}{share};
}
}
return %returned;
return %to_return;
}
=head1 AUTHOR

0
t/stoaster/.exists

Loading…
Cancel
Save