| 1 | package App::Spoor::Installer; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use v5.10; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 1 | ▶ | use YAML::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 1 | ▶ | use App::Spoor::LoginUnitFile; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 1 | ▶ | use App::Spoor::AccessUnitFile; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 1 | ▶ | use App::Spoor::ErrorUnitFile; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | ▶ | use App::Spoor::TransmitterUnitFile; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 1 | ▶ | use App::Spoor::CpanelHookFile; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | =head1 NAME | ||||||||||||
| 16 | |||||||||||||
| 17 | App::Spoor::Installer | ||||||||||||
| 18 | |||||||||||||
| 19 | =head1 VERSION | ||||||||||||
| 20 | |||||||||||||
| 21 | Version 0.01 | ||||||||||||
| 22 | |||||||||||||
| 23 | =cut | ||||||||||||
| 24 | |||||||||||||
| 25 | 1 | our $VERSION = '0.01'; | |||||||||||
| 26 | |||||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||||
| 28 | |||||||||||||
| 29 | Creates directories, config file, systemd unit files as well as the package that will be added to forward-related hooks in CPanel. | ||||||||||||
| 30 | |||||||||||||
| 31 | =head1 SUBROUTINES | ||||||||||||
| 32 | |||||||||||||
| 33 | =head2 install | ||||||||||||
| 34 | |||||||||||||
| 35 | my %installation_config =( | ||||||||||||
| 36 | login_log_path => '/var/log/login', | ||||||||||||
| 37 | access_log_path => '/var/log/access', | ||||||||||||
| 38 | error_log_path => '/var/log/error', | ||||||||||||
| 39 | api_identifier => 'ABC123', | ||||||||||||
| 40 | api_secret => 'secret456' | ||||||||||||
| 41 | ); | ||||||||||||
| 42 | |||||||||||||
| 43 | App::Spoor::Installer::install(\%installation_config); | ||||||||||||
| 44 | |||||||||||||
| 45 | # Optionally, you can pass in an alternative to the root path '/' which is used when building the path | ||||||||||||
| 46 | # to the config file. In the code snippet below, the method will create any directories and files relative to the | ||||||||||||
| 47 | # provided root path. For example, in the snippet below, the method will create the spoor config file in | ||||||||||||
| 48 | # /tmp/etc/spoor rather than /etc/spoor. This is primarily used to support testing. | ||||||||||||
| 49 | |||||||||||||
| 50 | App::Spoor::Installer::install(\%installation_config, '/tmp'); | ||||||||||||
| 51 | =cut | ||||||||||||
| 52 | |||||||||||||
| 53 | 8 | ▶ | sub install { | ||||||||||
|
Subroutine
install: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||
| 54 | 8 | my $install_parameters = shift; | |||||||||||
| 55 | 8 | ▶ | my $root_path = shift @_ // '/'; | ||||||||||
|
Condition50%1/2
shift @_ // "/"
MC/DC0%0/1
shift @_ // "/"
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||
| 56 | 8 | mkdir("$root_path/etc/spoor", 0700); | |||||||||||
| 57 | |||||||||||||
| 58 | my $config = YAML::Tiny->new({ | ||||||||||||
| 59 | followers => { | ||||||||||||
| 60 | login => { | ||||||||||||
| 61 | name => $install_parameters->{'login_log_path'}, | ||||||||||||
| 62 | maxinterval => 10, | ||||||||||||
| 63 | debug => 1, | ||||||||||||
| 64 | transformer => 'bin/login_log_transformer.pl', | ||||||||||||
| 65 | }, | ||||||||||||
| 66 | access => { | ||||||||||||
| 67 | name => $install_parameters->{'access_log_path'}, | ||||||||||||
| 68 | maxinterval => 10, | ||||||||||||
| 69 | debug => 1, | ||||||||||||
| 70 | transformer => 'bin/login_log_transformer.pl', | ||||||||||||
| 71 | }, | ||||||||||||
| 72 | error => { | ||||||||||||
| 73 | name => $install_parameters->{'error_log_path'}, | ||||||||||||
| 74 | maxinterval => 10, | ||||||||||||
| 75 | debug => 1, | ||||||||||||
| 76 | transformer => 'bin/login_log_transformer.pl', | ||||||||||||
| 77 | }, | ||||||||||||
| 78 | }, | ||||||||||||
| 79 | transmission => { | ||||||||||||
| 80 | credentials => { | ||||||||||||
| 81 | api_identifier => $install_parameters->{'api_identifier'}, | ||||||||||||
| 82 | 8 | api_secret => $install_parameters->{'api_secret'}, | |||||||||||
| 83 | }, | ||||||||||||
| 84 | host => 'https://spoor.capefox.co', | ||||||||||||
| 85 | endpoints => { | ||||||||||||
| 86 | report => '/api/reports', | ||||||||||||
| 87 | } | ||||||||||||
| 88 | } | ||||||||||||
| 89 | }); | ||||||||||||
| 90 | |||||||||||||
| 91 | 8 | $config->write("$root_path/etc/spoor/spoor.yml"); | |||||||||||
| 92 | 8 | chmod(0600, "$root_path/etc/spoor/spoor.yml"); | |||||||||||
| 93 | |||||||||||||
| 94 | 8 | mkdir("$root_path/var/lib/spoor", 0700); | |||||||||||
| 95 | 8 | mkdir("$root_path/var/lib/spoor/parsed", 0700); | |||||||||||
| 96 | 8 | mkdir("$root_path/var/lib/spoor/transmitted", 0700); | |||||||||||
| 97 | 8 | mkdir("$root_path/var/lib/spoor/transmission_failed", 0700); | |||||||||||
| 98 | |||||||||||||
| 99 | 8 | ▶ | open(my $login_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-login-follower.service") or die("Could not open: $!"); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 100 | 8 | print $login_handle App::Spoor::LoginUnitFile::contents(); | |||||||||||
| 101 | 8 | close $login_handle; | |||||||||||
| 102 | 8 | chmod(0644, "$root_path/etc/systemd/system/spoor-login-follower.service"); | |||||||||||
| 103 | |||||||||||||
| 104 | 8 | ▶ | open(my $access_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-access-follower.service") or die("Could not open: $!"); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | 8 | print $access_handle App::Spoor::AccessUnitFile::contents(); | |||||||||||
| 106 | 8 | close $access_handle; | |||||||||||
| 107 | 8 | chmod(0644, "$root_path/etc/systemd/system/spoor-access-follower.service"); | |||||||||||
| 108 | |||||||||||||
| 109 | 8 | ▶ | open(my $error_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-error-follower.service") or die("Could not open: $!"); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 110 | 8 | print $error_handle App::Spoor::ErrorUnitFile::contents(); | |||||||||||
| 111 | 8 | close $error_handle; | |||||||||||
| 112 | 8 | chmod(0644, "$root_path/etc/systemd/system/spoor-error-follower.service"); | |||||||||||
| 113 | |||||||||||||
| 114 | 8 | ▶ | open(my $transmitter_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-transmitter.service") or die("Could not open: $!"); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 115 | 8 | print $transmitter_handle App::Spoor::TransmitterUnitFile::contents(); | |||||||||||
| 116 | 8 | close $transmitter_handle; | |||||||||||
| 117 | 8 | chmod(0644, "$root_path/etc/systemd/system/spoor-transmitter.service"); | |||||||||||
| 118 | |||||||||||||
| 119 | 8 | mkdir("$root_path/var/cpanel/perl5", 0755); | |||||||||||
| 120 | 8 | mkdir("$root_path/var/cpanel/perl5/lib", 0755); | |||||||||||
| 121 | 8 | ▶ | open(my $hook_file_handle, '>:encoding(UTF-8)', "$root_path/var/cpanel/perl5/lib/SpoorForwardHook.pm") or die("Could not open; $!"); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 122 | 8 | print $hook_file_handle App::Spoor::CpanelHookFile::contents(); | |||||||||||
| 123 | 8 | close $hook_file_handle; | |||||||||||
| 124 | 8 | chmod(0644, "$root_path/var/cpanel/perl5/lib/SpoorForwardHook.pm"); | |||||||||||
| 125 | } | ||||||||||||
| 126 | |||||||||||||
| 127 | =head1 AUTHOR | ||||||||||||
| 128 | |||||||||||||
| 129 | Rory McKinley, C<< <rorymckinley at capefox.co> >> | ||||||||||||
| 130 | |||||||||||||
| 131 | =head1 BUGS | ||||||||||||
| 132 | |||||||||||||
| 133 | Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through | ||||||||||||
| 134 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll | ||||||||||||
| 135 | automatically be notified of progress on your bug as I make changes. | ||||||||||||
| 136 | |||||||||||||
| 137 | =head1 SUPPORT | ||||||||||||
| 138 | |||||||||||||
| 139 | You can find documentation for this module with the perldoc command. | ||||||||||||
| 140 | |||||||||||||
| 141 | perldoc App::Spoor::Installer | ||||||||||||
| 142 | |||||||||||||
| 143 | |||||||||||||
| 144 | You can also look for information at: | ||||||||||||
| 145 | |||||||||||||
| 146 | =over 4 | ||||||||||||
| 147 | |||||||||||||
| 148 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||
| 149 | |||||||||||||
| 150 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=.> | ||||||||||||
| 151 | |||||||||||||
| 152 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||
| 153 | |||||||||||||
| 154 | L<http://annocpan.org/dist/.> | ||||||||||||
| 155 | |||||||||||||
| 156 | =item * CPAN Ratings | ||||||||||||
| 157 | |||||||||||||
| 158 | L<https://cpanratings.perl.org/d/.> | ||||||||||||
| 159 | |||||||||||||
| 160 | =item * Search CPAN | ||||||||||||
| 161 | |||||||||||||
| 162 | L<https://metacpan.org/release/.> | ||||||||||||
| 163 | |||||||||||||
| 164 | =back | ||||||||||||
| 165 | |||||||||||||
| 166 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 167 | |||||||||||||
| 168 | Copyright 2019 Rory McKinley. | ||||||||||||
| 169 | |||||||||||||
| 170 | This program is free software; you can redistribute it and/or modify it | ||||||||||||
| 171 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||
| 172 | copy of the full license at: | ||||||||||||
| 173 | |||||||||||||
| 174 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||
| 175 | |||||||||||||
| 176 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||
| 177 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||
| 178 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||
| 179 | or distribute the Package, if you do not accept this license. | ||||||||||||
| 180 | |||||||||||||
| 181 | If your Modified Version has been derived from a Modified Version made | ||||||||||||
| 182 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||
| 183 | your Modified Version complies with the requirements of this license. | ||||||||||||
| 184 | |||||||||||||
| 185 | This license does not grant you the right to use any trademark, service | ||||||||||||
| 186 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||
| 187 | |||||||||||||
| 188 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||
| 189 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||
| 190 | otherwise transfer the Package with respect to any patent claims | ||||||||||||
| 191 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||
| 192 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||
| 193 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||
| 194 | direct or contributory patent infringement, then this Artistic License | ||||||||||||
| 195 | to you shall terminate on the date that such litigation is filed. | ||||||||||||
| 196 | |||||||||||||
| 197 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||
| 198 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||
| 199 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||
| 200 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||
| 201 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||
| 202 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||
| 203 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||
| 204 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||
| 205 | |||||||||||||
| 206 | =cut | ||||||||||||
| 207 | |||||||||||||
| 208 | 1 | 1; # End of App::Spoor::Installer | |||||||||||