misc
This commit is contained in:
parent
3cc63c7ac7
commit
533f9d8376
|
@ -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 );
|
||||||
|
}
|
|
@ -49,7 +49,6 @@ This initiates the module.
|
||||||
$templates and $output will be created as needed, but $dir must
|
$templates and $output will be created as needed, but $dir must
|
||||||
exist upon module init or it will die.
|
exist upon module init or it will die.
|
||||||
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
|
@ -75,12 +74,14 @@ sub new {
|
||||||
$opts{templates} = $opts{dir} . '/templates';
|
$opts{templates} = $opts{dir} . '/templates';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my %defaults = Server::Toaster::Defaults->get;
|
||||||
|
|
||||||
# init the object
|
# init the object
|
||||||
my $self = {
|
my $self = {
|
||||||
dir => $opts{dir},
|
dir => $opts{dir},
|
||||||
output => $opts{output},
|
output => $opts{output},
|
||||||
templates => $opts{templates},
|
templates => $opts{templates},
|
||||||
defaults=>Server::Toaster::Defaults->get,
|
defaults => \%defaults,
|
||||||
share => dist_dir('Server-Toaster'),
|
share => dist_dir('Server-Toaster'),
|
||||||
};
|
};
|
||||||
bless $self;
|
bless $self;
|
||||||
|
@ -110,39 +111,44 @@ sub fill_in {
|
||||||
my ( $self, %opts ) = @_;
|
my ( $self, %opts ) = @_;
|
||||||
|
|
||||||
# make sure we have a module specified
|
# make sure we have a module specified
|
||||||
if (!defined( $opts{module} )) {
|
if ( !defined( $opts{module} ) ) {
|
||||||
die( 'No module defined' );
|
die('No module defined');
|
||||||
}
|
}
|
||||||
|
|
||||||
# make sure we have a hostname
|
# make sure we have a hostname
|
||||||
if (!defined( $opts{hostname} )) {
|
if ( !defined( $opts{hostname} ) ) {
|
||||||
die( 'No hostname defined' );
|
die('No hostname defined');
|
||||||
}
|
}
|
||||||
|
|
||||||
# make sure we have a config to use
|
# make sure we have a config to use
|
||||||
if (!defined( $opts{config} )) {
|
if ( !defined( $opts{config} ) ) {
|
||||||
die( 'No config defined' );
|
die('No config defined');
|
||||||
}
|
}
|
||||||
|
|
||||||
# do a very basic check to make sure we have something that appears to atleast be sane
|
# do a very basic check to make sure we have something that appears to atleast be sane
|
||||||
# for the name of the module
|
# for the name of the module
|
||||||
if ($opts{module}!~/^[A-Za-z0-9\_\:]+$/) {
|
if ( $opts{module} !~ /^[A-Za-z0-9\_\:]+$/ ) {
|
||||||
die('"'.$opts{module}.'" does not appear to be a valid module name');
|
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 $to_eval
|
||||||
'my $st_module=Server::Toaster::Modules::'.$opts{module}.'->new(',
|
= 'use Server::Toaster::Modules::'
|
||||||
'dir=>$self->{dir}, '.
|
. $opts{module} . '; '
|
||||||
'output=>$self->{output}, '.
|
. 'my $st_module=Server::Toaster::Modules::'
|
||||||
'templates=>$self->{templates} );'.
|
. $opts{module}
|
||||||
'$st_module->fill_in(%opts);';
|
. '->new('.
|
||||||
|
'dir=>$self->{dir}, '
|
||||||
|
. 'output=>$self->{output}, '
|
||||||
|
. 'templates=>$self->{templates} );'
|
||||||
|
. '$st_module->fill_in(%opts);';
|
||||||
|
|
||||||
|
eval($to_eval);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
=head2 get_files
|
=head2 get_files
|
||||||
|
@ -161,7 +167,7 @@ Sever::Toaster::Modules. So 'Sever::Toaster::Modules::Apache' becomes
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub get_files {
|
sub get_files {
|
||||||
my ( $blank, $module ) = @_;
|
my ( $self, $module ) = @_;
|
||||||
|
|
||||||
# make sure we have a module defined
|
# make sure we have a module defined
|
||||||
if ( !defined($module) ) {
|
if ( !defined($module) ) {
|
||||||
|
@ -170,12 +176,20 @@ sub get_files {
|
||||||
|
|
||||||
my %returned;
|
my %returned;
|
||||||
my $to_eval
|
my $to_eval
|
||||||
= 'use Server::Toaster::Modules::'
|
= 'use Server::Toaster::Modules::'
|
||||||
|
. $module . '; '
|
||||||
|
. 'my $st_module=Server::Toaster::Modules::'
|
||||||
. $module
|
. $module
|
||||||
. '; %returned=Server::Toaster::Modules::'
|
. '->new('.
|
||||||
. $module
|
'dir=>$self->{dir}, '
|
||||||
. '->get_files;';
|
. 'output=>$self->{output}, '
|
||||||
eval( $to_eval );
|
. 'templates=>$self->{templates} );'
|
||||||
|
. '%returned=$st_module->get_files;';
|
||||||
|
eval($to_eval);
|
||||||
|
if ($@) {
|
||||||
|
print "Evaled... ".$to_eval."\n";
|
||||||
|
die "Eval failed... ".$@;
|
||||||
|
}
|
||||||
|
|
||||||
return %returned;
|
return %returned;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ sub get {
|
||||||
ssl_honor_cipher_order => '0',
|
ssl_honor_cipher_order => '0',
|
||||||
server_admin_email => 'you@foo.bar',
|
server_admin_email => 'you@foo.bar',
|
||||||
server_admin_name => 'Who Ever',
|
server_admin_name => 'Who Ever',
|
||||||
ssl_cert_path => '/usr/local/etc/letsencrypt/live/%%%DOMAN%%%/',
|
ssl_cert_path => '/usr/local/etc/letsencrypt/live/%%%DOMAIN%%%/',
|
||||||
Apache => {
|
Apache => {
|
||||||
listen => [],
|
listen => [],
|
||||||
http_port => '80',
|
http_port => '80',
|
||||||
|
@ -54,8 +54,9 @@ sub get {
|
||||||
server_root => '/usr/local',
|
server_root => '/usr/local',
|
||||||
default_https_redirect => '0',
|
default_https_redirect => '0',
|
||||||
enable_https => '0',
|
enable_https => '0',
|
||||||
include_optional => 1,
|
include_optional => '0',
|
||||||
ssl_stapling => '1',
|
ssl_stapling => '1',
|
||||||
|
version => '2.4',
|
||||||
ssl_stapling_cache => 'shmcb:logs/ssl_stapling(32768)',
|
ssl_stapling_cache => 'shmcb:logs/ssl_stapling(32768)',
|
||||||
modules => {
|
modules => {
|
||||||
mpm_prefork => '1',
|
mpm_prefork => '1',
|
||||||
|
@ -152,33 +153,33 @@ sub get {
|
||||||
wsgi => "1",
|
wsgi => "1",
|
||||||
auth_openidc => "1",
|
auth_openidc => "1",
|
||||||
},
|
},
|
||||||
modules_d => 1,
|
modules_d => '0',
|
||||||
user => 'www',
|
user => 'www',
|
||||||
group => 'www',
|
group => 'www',
|
||||||
doc_root => '/usr/local/www/apache24/data',
|
doc_root => '/usr/local/www/apache24/data',
|
||||||
cgi => 0,
|
cgi => '0',
|
||||||
mpm_event => {
|
mpm_event => {
|
||||||
StartServers => 3,
|
StartServers => '3',
|
||||||
MinSpareThreads => 75,
|
MinSpareThreads => '75',
|
||||||
MaxSpareThreads => 250,
|
MaxSpareThreads => '250',
|
||||||
ThreadsPerChild => 25,
|
ThreadsPerChild => '25',
|
||||||
MaxRequestWorkers => 400,
|
MaxRequestWorkers => '400',
|
||||||
MaxConnectionsPerChild => 0
|
MaxConnectionsPerChild => '0'
|
||||||
},
|
},
|
||||||
mpm_prefork => {
|
mpm_prefork => {
|
||||||
StartServers => 5,
|
StartServers => '5',
|
||||||
MinSpareServers => 5,
|
MinSpareServers => '5',
|
||||||
MaxSpareServers => 10,
|
MaxSpareServers => '10',
|
||||||
MaxRequestWorkers => 250,
|
MaxRequestWorkers => '250',
|
||||||
MaxConnectionsPerChild => 0,
|
MaxConnectionsPerChild => '0',
|
||||||
},
|
},
|
||||||
mpm_worker => {
|
mpm_worker => {
|
||||||
StartServers => 3,
|
StartServers => '3',
|
||||||
MinSpareThreads => 75,
|
MinSpareThreads => '75',
|
||||||
MaxSpareThreads => 250,
|
MaxSpareThreads => '250',
|
||||||
ThreadsPerChild => 25,
|
ThreadsPerChild => '25',
|
||||||
MaxRequestWorkers => 400,
|
MaxRequestWorkers => '400',
|
||||||
MaxConnectionsPerChild => 0,
|
MaxConnectionsPerChild => '0',
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,12 @@ package Server::Toaster::Modules::Apache;
|
||||||
use 5.006;
|
use 5.006;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use base 'Server::Toaster::Modules::Base';
|
use Moose;
|
||||||
|
extends 'Server::Toaster::Modules::Base';
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
Server::Toaster::Modules::Apache - Apache helper for Server::Toaster
|
Server::Toaster::Modules::Apache - Apache module for Server::Toaster
|
||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
|
@ -49,24 +50,24 @@ sub fill_in {
|
||||||
my ( $self, %opts ) = @_;
|
my ( $self, %opts ) = @_;
|
||||||
|
|
||||||
# make sure we have a hostname
|
# make sure we have a hostname
|
||||||
if (!defined( $opts{hostname} )) {
|
if ( !defined( $opts{hostname} ) ) {
|
||||||
die( 'No hostname defined' );
|
die('No hostname defined');
|
||||||
}
|
}
|
||||||
|
|
||||||
# make sure we have a config to use
|
# make sure we have a config to use
|
||||||
if (!defined( $opts{config} )) {
|
if ( !defined( $opts{config} ) ) {
|
||||||
die( 'No config defined' );
|
die('No config defined');
|
||||||
}
|
}
|
||||||
|
|
||||||
my $vars={
|
my $vars = {
|
||||||
hostname=>$opts{hostname},
|
hostname => $opts{hostname},
|
||||||
d=>Server::Toaster::Defaults->get,
|
d => Server::Toaster::Defaults->get,
|
||||||
c=>%opts{config},
|
c => %opts{config},
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
=head2 get_files
|
=head2 get_files_module
|
||||||
|
|
||||||
Fetches a list of templates a module uses.
|
Fetches a list of templates a module uses.
|
||||||
|
|
||||||
|
@ -75,18 +76,11 @@ and the value being the full path to the file.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub get_files {
|
sub get_files_module {
|
||||||
my ( $self ) = @_;
|
return (
|
||||||
|
'Apache/domain.tt',
|
||||||
my $dir=dist_dir('Server-Toaster');
|
'Apache/httpd.conf.tt'
|
||||||
|
);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
=head1 AUTHOR
|
=head1 AUTHOR
|
||||||
|
|
|
@ -6,6 +6,8 @@ use warnings;
|
||||||
use Template;
|
use Template;
|
||||||
use Server::Toaster::Defaults;
|
use Server::Toaster::Defaults;
|
||||||
use File::ShareDir ':ALL';
|
use File::ShareDir ':ALL';
|
||||||
|
use File::Spec::Functions;
|
||||||
|
use Moose;
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
|
@ -28,8 +30,6 @@ Perhaps a little code snippet.
|
||||||
use Server::Toaster::Modules::Apache;
|
use Server::Toaster::Modules::Apache;
|
||||||
|
|
||||||
my $st = Server::Toaster->new();
|
my $st = Server::Toaster->new();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=head1 METHODS
|
=head1 METHODS
|
||||||
|
|
||||||
|
@ -49,7 +49,6 @@ This initiates the module.
|
||||||
$templates and $output will be created as needed, but $dir must
|
$templates and $output will be created as needed, but $dir must
|
||||||
exist upon module init or it will die.
|
exist upon module init or it will die.
|
||||||
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
|
@ -67,12 +66,12 @@ sub new {
|
||||||
|
|
||||||
# set the default output dir if non is specified
|
# set the default output dir if non is specified
|
||||||
if ( !defined( $opts{output} ) ) {
|
if ( !defined( $opts{output} ) ) {
|
||||||
$opts{output} = $opts{dir} . '/output';
|
$opts{output} = catdir( $opts{dir}, 'output' );
|
||||||
}
|
}
|
||||||
|
|
||||||
# set the default template dir if non is specified
|
# set the default template dir if non is specified
|
||||||
if ( !defined( $opts{templates} ) ) {
|
if ( !defined( $opts{templates} ) ) {
|
||||||
$opts{templates} = $opts{dir} . '/templates';
|
$opts{templates} = catdir($opts{dir} , 'templates');
|
||||||
}
|
}
|
||||||
|
|
||||||
# init the object
|
# init the object
|
||||||
|
@ -87,42 +86,7 @@ sub new {
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
=head2 fill_in
|
=head2 get_files_module
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
Fetches a list of templates a module uses.
|
Fetches a list of templates a module uses.
|
||||||
|
|
||||||
|
@ -132,17 +96,29 @@ and the value being the full path to the file.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub get_files {
|
sub get_files {
|
||||||
my ( $self ) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
my $dir=dist_dir('Server-Toaster');
|
my @files=$self->get_files_module;
|
||||||
|
|
||||||
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;
|
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 %to_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
=head1 AUTHOR
|
=head1 AUTHOR
|
||||||
|
|
Loading…
Reference in New Issue