diff --git a/README.md b/README.md index 0094beabe4..2fbeb3272a 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,6 @@ following copyright: All rights reserved ``` -The design material and the "i-MSCP" trademark stay the property of their +The design material and the "i-MSCP" trademark is the property of their authors. Reuse of them without prior consent of their respective authors is strictly prohibited. diff --git a/autoinstaller/Functions.pm b/autoinstaller/Functions.pm index eb068a7063..8aff534b5e 100644 --- a/autoinstaller/Functions.pm +++ b/autoinstaller/Functions.pm @@ -354,10 +354,10 @@ i-MSCP was designed for professional Hosting Service Providers (HSPs), Internet Unless otherwise stated all source code and material is licensed under LGPL 2.1 and has the following copyright: - \\Zb© 2010-@{[ (localtime)[5]+1900 ]}, Laurent Declercq (i-MSCP™) - All rights reserved\\ZB + \\Zb© 2010-@{[ (localtime)[5]+1900 ]}, Laurent Declercq (i-MSCP™) + All rights reserved\\ZB -The design material and the "i-MSCP" trademark stay the property of their authors. Reuse of them without prior consent of their respective authors is strictly prohibited. +The design material and the "i-MSCP" trademark is the property of their authors. Reuse of them without prior consent of their respective authors is strictly prohibited. EOF } diff --git a/configs/debian/apache/00_nameserver.conf b/configs/debian/apache/00_nameserver.conf index 95649b359c..59e83168b5 100644 --- a/configs/debian/apache/00_nameserver.conf +++ b/configs/debian/apache/00_nameserver.conf @@ -57,8 +57,7 @@ ErrorDocument 503 /errors/503.html ## Error logging LogLevel warn -LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" vlogger -CustomLog "|/usr/local/sbin/vlogger -i -n -t access.log -d {VLOGGER_CONF} {HTTPD_LOG_DIR}" vlogger +CustomLog "|{ENGINE_ROOT_DIR}/bin/imscp-vlogger -i -n -t access.log -d {VLOGGER_CONF} {HTTPD_LOG_DIR}" "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" # SECTION custom BEGIN. # SECTION custom END. diff --git a/configs/debian/apache/vlogger.conf.tpl b/configs/debian/apache/imscp-vlogger.conf.tpl similarity index 100% rename from configs/debian/apache/vlogger.conf.tpl rename to configs/debian/apache/imscp-vlogger.conf.tpl diff --git a/configs/debian/apache/vlogger.sql b/configs/debian/apache/imscp-vlogger.sql similarity index 100% rename from configs/debian/apache/vlogger.sql rename to configs/debian/apache/imscp-vlogger.sql diff --git a/configs/debian/apache/install.xml b/configs/debian/apache/install.xml index f4f9636e3d..86ab5b3857 100644 --- a/configs/debian/apache/install.xml +++ b/configs/debian/apache/install.xml @@ -8,8 +8,7 @@ ${SYSTEM_CONF}/apache/00_imscp.conf ${SYSTEM_CONF}/apache/00_nameserver.conf ${SYSTEM_CONF}/apache/apache.data.dist + ${SYSTEM_CONF}/apache/imscp-vlogger.conf.tpl + ${SYSTEM_CONF}/apache/imscp-vlogger.sql ${SYSTEM_CONF}/apache/logrotate.conf - /usr/local/sbin/vlogger - ${SYSTEM_CONF}/apache/vlogger.conf.tpl - ${SYSTEM_CONF}/apache/vlogger.sql diff --git a/configs/debian/cron/imscp b/configs/debian/cron/imscp index 0386378a1a..61827cb39f 100644 --- a/configs/debian/cron/imscp +++ b/configs/debian/cron/imscp @@ -1,23 +1,23 @@ # CRON(8) configuration file - auto-generated by i-MSCP # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN -PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:{ENGINE_ROOT_DIR}/bin # Traffic accounting -0,30 * * * * root nice -n 10 ionice -c2 -n5 perl {ENGINE_ROOT_DIR}/bin/imscp-server-traffic >/dev/null 2>&1 -0,30 * * * * root nice -n 10 ionice -c2 -n5 perl {ENGINE_ROOT_DIR}/bin/imscp-clients-traffic >/dev/null 2>&1 +0,30 * * * * root nice -n 10 ionice -c2 -n5 imscp-server-traffic >/dev/null 2>&1 +0,30 * * * * root nice -n 10 ionice -c2 -n5 imscp-clients-traffic >/dev/null 2>&1 # Quota accounting -@daily root nice -n 10 ionice -c2 -n5 perl {ENGINE_ROOT_DIR}/bin/imscp-disk-quota > /dev/null 2>&1 +@daily root nice -n 10 ionice -c2 -n5 imscp-disk-quota > /dev/null 2>&1 # Automatic client accounts suspension -@daily root nice -n 10 ionice -c2 -n5 perl {ENGINE_ROOT_DIR}/bin/imscp-clients-suspend >/dev/null 2>&1 +@daily root nice -n 10 ionice -c2 -n5 imscp-clients-suspend >/dev/null 2>&1 # Backup CP configuration files and database -{BACKUP_CP_MINUTE} {BACKUP_CP_HOUR} * * * root nice -n 10 ionice -c2 -n5 perl {ENGINE_ROOT_DIR}/bin/imscp-cp-backup >/dev/null 2>&1 +{BACKUP_CP_MINUTE} {BACKUP_CP_HOUR} * * * root nice -n 10 ionice -c2 -n5 imscp-cp-backup >/dev/null 2>&1 # Backup client data (Web data, mail data, databases) -{BACKUP_CLIENTS_MINUTE} {BACKUP_CLIENTS_HOUR} * * * root nice -n 10 ionice -c2 -n5 perl {ENGINE_ROOT_DIR}/bin/imscp-clients-backup >/dev/null 2>&1 +{BACKUP_CLIENTS_MINUTE} {BACKUP_CLIENTS_HOUR} * * * root nice -n 10 ionice -c2 -n5 imscp-clients-backup >/dev/null 2>&1 # Remove backup and log files which are older than 7 days @weekly root find {CONF_DIR}/*/backup -maxdepth 0 -type f -mtime +7 -regextype sed -regex '.*/.*[0-9]\{10\}$' -exec rm -- {} + diff --git a/configs/debian/dpkg/90imscp b/configs/debian/dpkg/90imscp index 939462303f..5f7378b035 100644 --- a/configs/debian/dpkg/90imscp +++ b/configs/debian/dpkg/90imscp @@ -1,5 +1,5 @@ # dpkg(1) configuration file - auto-generated by i-MSCP # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN DPkg::Post-Invoke { - "if [ -f /var/www/imscp/engine/bin/imscp-dpkg-post-invoke -a ${IMSCP_SETUP:=0} -eq 0 ]; then /usr/bin/perl /var/www/imscp/engine/bin/imscp-dpkg-post-invoke -d; fi"; + "if [ -x /var/www/imscp/engine/bin/imscp-dpkg-post-invoke -a ${IMSCP_SETUP:=0} -eq 0 ]; then /var/www/imscp/engine/bin/imscp-dpkg-post-invoke -d; fi"; }; diff --git a/configs/debian/php/fpm/pool.conf.default b/configs/debian/php/fpm/pool.conf.default index 639ab6d62f..829772e6dd 100644 --- a/configs/debian/php/fpm/pool.conf.default +++ b/configs/debian/php/fpm/pool.conf.default @@ -12,5 +12,5 @@ listen.group = {HTTPD_GROUP} listen.mode = 0660 pm = ondemand pm.max_children = 1 -pm.process_idle_timeout = 10s; +pm.process_idle_timeout = 10s pm.max_requests = 1000 diff --git a/configs/debian/systemd/imscp_mountall.service b/configs/debian/systemd/imscp_mountall.service index 0bfa219a59..daad28fe2d 100644 --- a/configs/debian/systemd/imscp_mountall.service +++ b/configs/debian/systemd/imscp_mountall.service @@ -10,8 +10,8 @@ ConditionPathExists=/etc/imscp/mounts/mounts.conf [Service] Type=oneshot RemainAfterExit=yes -ExecStart=/usr/bin/perl /var/www/imscp/engine/bin/imscp-mountall start -ExecStop=/usr/bin/perl /var/www/imscp/engine/bin/imscp-mountall stop +ExecStart=/var/www/imscp/engine/bin/imscp-mountall start +ExecStop=/var/www/imscp/engine/bin/imscp-mountall stop [Install] WantedBy=multi-user.target diff --git a/configs/debian/systemd/imscp_traffic.service b/configs/debian/systemd/imscp_traffic.service index 85002159cb..c28560d1aa 100644 --- a/configs/debian/systemd/imscp_traffic.service +++ b/configs/debian/systemd/imscp_traffic.service @@ -7,8 +7,8 @@ After=local-fs.target [Service] Type=oneshot RemainAfterExit=yes -ExecStart=/usr/bin/perl /var/www/imscp/engine/bin/imscp-net-traffic add -ExecStop=/usr/bin/perl /var/www/imscp/engine/bin/imscp-net-traffic remove +ExecStart=/var/www/imscp/engine/bin/imscp-net-traffic add +ExecStop=/var/www/imscp/engine/bin/imscp-net-traffic remove [Install] WantedBy=multi-user.target diff --git a/configs/debian/sysvinit/imscp_mountall b/configs/debian/sysvinit/imscp_mountall index dd26cab74a..da90316c65 100644 --- a/configs/debian/sysvinit/imscp_mountall +++ b/configs/debian/sysvinit/imscp_mountall @@ -35,13 +35,13 @@ check_for_upstart() do_start() { - perl ${BINDIR}/imscp-mountall start 2>/dev/null + ${BINDIR}/imscp-mountall start 2>/dev/null touch $LFILE } do_stop() { - perl ${BINDIR}/imscp-mountall stop 2>/dev/null + ${BINDIR}/imscp-mountall stop 2>/dev/null rm -f $LFILE } diff --git a/configs/debian/sysvinit/imscp_traffic b/configs/debian/sysvinit/imscp_traffic index 760af7aca0..a36c801aba 100755 --- a/configs/debian/sysvinit/imscp_traffic +++ b/configs/debian/sysvinit/imscp_traffic @@ -36,13 +36,13 @@ check_for_upstart() do_start() { - perl ${BINDIR}/imscp-net-traffic add 2>/dev/null + ${BINDIR}/imscp-net-traffic add 2>/dev/null touch $LFILE } do_stop() { - perl ${BINDIR}/imscp-net-traffic remove 2>/dev/null + ${BINDIR}/imscp-net-traffic remove 2>/dev/null rm -f $LFILE } diff --git a/configs/debian/upstart/imscp_mountall.conf b/configs/debian/upstart/imscp_mountall.conf index 8ffa4779d4..c2e8f741a9 100644 --- a/configs/debian/upstart/imscp_mountall.conf +++ b/configs/debian/upstart/imscp_mountall.conf @@ -6,5 +6,5 @@ author "Laurent Declercq " start on filesystem stop on runlevel [016] -pre-start exec /usr/bin/perl /var/www/imscp/engine/bin/imscp-mountall start -post-stop exec /usr/bin/perl /var/www/imscp/engine/bin/imscp-mountall stop +pre-start exec /var/www/imscp/engine/bin/imscp-mountall start +post-stop exec /var/www/imscp/engine/bin/imscp-mountall stop diff --git a/configs/debian/upstart/imscp_traffic.conf b/configs/debian/upstart/imscp_traffic.conf index 3e0141eb3c..3b6ae6f437 100644 --- a/configs/debian/upstart/imscp_traffic.conf +++ b/configs/debian/upstart/imscp_traffic.conf @@ -6,5 +6,5 @@ author "Laurent Declercq " start on runlevel [2345] stop on runlevel [016] -pre-start exec /usr/bin/perl /var/www/imscp/engine/bin/imscp-net-traffic add -post-stop exec /usr/bin/perl /var/www/imscp/engine/bin/imscp-net-traffic remove +pre-start exec /var/www/imscp/engine/bin/imscp-net-traffic add +post-stop exec /var/www/imscp/engine/bin/imscp-net-traffic remove diff --git a/contrib/Listeners/Backup/10_backup_storage_outsourcing.pl b/contrib/Listeners/Backup/10_backup_storage_outsourcing.pl index 59633f082d..7773f0ec94 100644 --- a/contrib/Listeners/Backup/10_backup_storage_outsourcing.pl +++ b/contrib/Listeners/Backup/10_backup_storage_outsourcing.pl @@ -23,7 +23,7 @@ package Listener::Backup::Storage::Outsourcing; # 1. Upload that listener file into the /etc/imscp/listeners.d directory # 2. Edit the /etc/imscp/listeners.d/10_backup_storage_outsourcing.pl file # and set the $STORAGE_ROOT_PATH variable below according your needs -# 3. Trigger an i-MSCP reconfiguration: perl /var/www/imscp/engine/bin/imscp-reconfigure -danv +# 3. Trigger an i-MSCP reconfiguration: /var/www/imscp/engine/bin/imscp-reconfigure -danv use strict; use warnings; diff --git a/contrib/Listeners/Named/10_named_global_ns.pl b/contrib/Listeners/Named/10_named_global_ns.pl index e479eb1b5a..07257f0186 100644 --- a/contrib/Listeners/Named/10_named_global_ns.pl +++ b/contrib/Listeners/Named/10_named_global_ns.pl @@ -23,7 +23,7 @@ # Don't forget also to activate IPv6 support if needed. All this can # be done by reconfiguring the named service as follow: # -# perl /var/www/imscp/engine/bin/imscp-reconfigure -dr named +# /var/www/imscp/engine/bin/imscp-reconfigure -dr named # package Listener::Named::Global::NS; diff --git a/contrib/Listeners/PHP/10_php_confoptions_override.pl b/contrib/Listeners/PHP/10_php_confoptions_override.pl index dc638e6677..1d1cde996a 100644 --- a/contrib/Listeners/PHP/10_php_confoptions_override.pl +++ b/contrib/Listeners/PHP/10_php_confoptions_override.pl @@ -20,7 +20,7 @@ ## ## Be aware that only Fcgid and PHP-FPM Apache2 httpd server implementations are supported. ## Note: When you want operate on a per domain basis, don't forget to set the PHP configuration level to 'per_site'. -## You can do this by running: perl /var/www/imscp/engine/bin/imscp-reconfigure -dar php +## You can do this by running: /var/www/imscp/engine/bin/imscp-reconfigure -dar php # package Listener::Php::ConfOptions::Override; diff --git a/contrib/Listeners/PHP/10_phpfpm_settings_override.pl b/contrib/Listeners/PHP/10_phpfpm_settings_override.pl index 422f65f16d..5ba78c167c 100644 --- a/contrib/Listeners/PHP/10_phpfpm_settings_override.pl +++ b/contrib/Listeners/PHP/10_phpfpm_settings_override.pl @@ -19,7 +19,7 @@ ## Allows to override PHP-FPM settings in pool configuration files ## ## Note: When you want operate on a per domain basis, don't forget to set the PHP configuration level to 'per_site'. -## You can do this by running: perl /var/www/imscp/engine/bin/imscp-reconfigure -dar php +## You can do this by running: /var/www/imscp/engine/bin/imscp-reconfigure -dar php # package Listener::PhpFpm::Settings::Override; diff --git a/contrib/Listeners/README.md b/contrib/Listeners/README.md index c9e85f3471..8abe61f560 100644 --- a/contrib/Listeners/README.md +++ b/contrib/Listeners/README.md @@ -86,7 +86,7 @@ Listener file that allows to set identical NS entries in all zones support if needed. All this can be done by reconfiguring the `named` service as follow: ``` - perl /var/www/imscp/engine/setup/imscp-reconfigure -dr named +# /var/www/imscp/engine/setup/imscp-reconfigure -dr named ``` If you don't do so, zone transfers to your slave DNS servers won't be allowed. @@ -136,7 +136,7 @@ Note: When you want operate on a per domain basis, don't forget to set the PHP c can do this by running: ``` -# perl /var/www/imscp/engine/setup/imscp-reconfigure -dar php +# /var/www/imscp/engine/setup/imscp-reconfigure -dar php ``` ### 10_phpfpm_settings_override.pl @@ -147,7 +147,7 @@ Note: When you want operate on a per domain basis, don't forget to set the PHP c can do this by running: ``` -# perl /var/www/imscp/engine/setup/imscp-reconfigure -dar php +# /var/www/imscp/engine/setup/imscp-reconfigure -dar php ``` ## PhpMyAdmin listener files diff --git a/engine/PerlLib/Package/AntiRootkits.pm b/engine/PerlLib/Package/AntiRootkits.pm index 4c0dfcdfb7..3117746fcc 100644 --- a/engine/PerlLib/Package/AntiRootkits.pm +++ b/engine/PerlLib/Package/AntiRootkits.pm @@ -304,9 +304,6 @@ sub setEnginePermissions my ( $self ) = @_; try { - my $rs = $self->{'eventManager'}->trigger( 'beforeAntiRootkisSetGuiPermissions' ); - return $rs if $rs; - my %selectedPackages; @{selectedPackages}{ split ',', $::imscpConfig{'ANTI_ROOTKITS_PACKAGES'} } = (); @@ -315,11 +312,9 @@ sub setEnginePermissions $package = "Package::AntiRootkits::${package}::${package}"; eval "require $package" or die; ( my $subref = $package->can( 'setEnginePermissions' ) ) or next; - $rs = $subref->( $package->getInstance()); + my $rs = $subref->( $package->getInstance()); return $rs if $rs; } - - $self->{'eventManager'}->trigger( 'afterAntiRootkisSetGuiPermissions' ); } catch { error( $_ ); 1; diff --git a/engine/PerlLib/Package/AntiRootkits/Chkrootkit/Chkrootkit.pm b/engine/PerlLib/Package/AntiRootkits/Chkrootkit/Chkrootkit.pm index 22063d88d1..a0067a4eb6 100644 --- a/engine/PerlLib/Package/AntiRootkits/Chkrootkit/Chkrootkit.pm +++ b/engine/PerlLib/Package/AntiRootkits/Chkrootkit/Chkrootkit.pm @@ -89,6 +89,8 @@ sub uninstall sub setEnginePermissions { + return 0 unless -f $::imscpConfig{'CHKROOTKIT_LOG'}; + setRights( $::imscpConfig{'CHKROOTKIT_LOG'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'IMSCP_GROUP'}, diff --git a/engine/PerlLib/Package/AntiRootkits/Rkhunter/Installer.pm b/engine/PerlLib/Package/AntiRootkits/Rkhunter/Installer.pm index 82b9f6cf0b..4d9bec0d1a 100644 --- a/engine/PerlLib/Package/AntiRootkits/Rkhunter/Installer.pm +++ b/engine/PerlLib/Package/AntiRootkits/Rkhunter/Installer.pm @@ -135,7 +135,7 @@ sub _addCronTask MONTH => '', DWEEK => '', USER => $::imscpConfig{'ROOT_USER'}, - COMMAND => "nice -n 10 ionice -c2 -n5 perl $::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/AntiRootkits/Rkhunter/bin/imscp-rkhunter > /dev/null 2>&1" + COMMAND => "nice -n 10 ionice -c2 -n5 $::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/AntiRootkits/Rkhunter/bin/imscp-rkhunter > /dev/null 2>&1" } ); } @@ -159,7 +159,7 @@ sub _scheduleCheck return $rs if $rs; $rs = execute( - "echo 'perl $main::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/AntiRootkits/Rkhunter/bin/imscp-rkhunter > /dev/null 2>&1' | at now + 10 minutes", + "echo '$main::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/AntiRootkits/Rkhunter/bin/imscp-rkhunter > /dev/null 2>&1' | at now + 10 minutes", \my $stdout, \my $stderr ); diff --git a/engine/PerlLib/Package/AntiRootkits/Rkhunter/Rkhunter.pm b/engine/PerlLib/Package/AntiRootkits/Rkhunter/Rkhunter.pm index 2744684ecb..5464f4156d 100644 --- a/engine/PerlLib/Package/AntiRootkits/Rkhunter/Rkhunter.pm +++ b/engine/PerlLib/Package/AntiRootkits/Rkhunter/Rkhunter.pm @@ -89,7 +89,7 @@ sub setEnginePermissions my $rs = setRights( "$::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/AntiRootkits/Rkhunter/bin/imscp-rkhunter", { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_USER'}, - mode => '0700' + mode => '0750' } ); return $rs if $rs || !-f $::imscpConfig{'RKHUNTER_LOG'}; diff --git a/engine/PerlLib/Package/AntiRootkits/Rkhunter/bin/imscp-rkhunter b/engine/PerlLib/Package/AntiRootkits/Rkhunter/bin/imscp-rkhunter index abf5eda489..0bffeb28ff 100644 --- a/engine/PerlLib/Package/AntiRootkits/Rkhunter/bin/imscp-rkhunter +++ b/engine/PerlLib/Package/AntiRootkits/Rkhunter/bin/imscp-rkhunter @@ -43,7 +43,7 @@ use Try::Tiny; newDebug( 'imscp-rkhunter.log' ); -iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: perl %s [OPTION]...', basename( $0 )) . qq{ +iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: %s [OPTION]...', basename( $0 )) . qq{ Process rkhunter(8) checks. diff --git a/engine/PerlLib/Package/FrontEnd.pm b/engine/PerlLib/Package/FrontEnd.pm index 6980a8541a..257e9ef2d0 100644 --- a/engine/PerlLib/Package/FrontEnd.pm +++ b/engine/PerlLib/Package/FrontEnd.pm @@ -191,9 +191,7 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeFrontEndSetEnginePermissions' ); - - $rs ||= setRights( $self->{'config'}->{'HTTPD_CONF_DIR'}, { + my $rs = setRights( $self->{'config'}->{'HTTPD_CONF_DIR'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, dirmode => '0755', @@ -260,7 +258,7 @@ sub setEnginePermissions } } - $self->{'eventManager'}->trigger( 'afterFrontEndSetEnginePermissions' ); + 0; } =item setGuiPermissions( ) diff --git a/engine/PerlLib/Package/Webstats/Awstats/Awstats.pm b/engine/PerlLib/Package/Webstats/Awstats/Awstats.pm index 4b44bd45c4..b89c92d8a1 100644 --- a/engine/PerlLib/Package/Webstats/Awstats/Awstats.pm +++ b/engine/PerlLib/Package/Webstats/Awstats/Awstats.pm @@ -109,15 +109,16 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = setRights( "$::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/Webstats/Awstats/Scripts/awstats_updateall.pl", { - user => $::imscpConfig{'ROOT_USER'}, - group => $::imscpConfig{'ROOT_USER'}, - mode => '0700' + my $rs = setRights( "$::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/Webstats/Awstats/bin", { + user => $::imscpConfig{'ROOT_USER'}, + group => $::imscpConfig{'ROOT_USER'}, + mode => '0750', + recursive => TRUE } ); $rs ||= setRights( $::imscpConfig{'AWSTATS_CACHE_DIR'}, { user => $::imscpConfig{'ROOT_USER'}, group => $self->{'httpd'}->getRunningGroup(), - dirmode => '02750', + dirmode => '2750', filemode => '0640', recursive => iMSCP::Getopt->fixPermissions } @@ -361,8 +362,8 @@ sub _addAwstatsConfig my ( $self, $data ) = @_; try { - my $awstatsPackageRootDir = "$::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/Webstats/Awstats"; - my $fileC = iMSCP::File->new( filename => "$awstatsPackageRootDir/Config/awstats.imscp_tpl.conf" )->getAsRef(); + my $packageDir = "$::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/Webstats/Awstats"; + my $fileC = iMSCP::File->new( filename => "$packageDir/config/awstats.imscp_tpl.conf" )->getAsRef(); return 1 unless defined $fileC; my ( $adminName ) = iMSCP::Database->factory()->getConnector()->run( fixup => sub { @@ -374,18 +375,19 @@ sub _addAwstatsConfig return 1; } - my $tags = { - ALIAS => $data->{'ALIAS'}, - AUTH_USER => $adminName, - AWSTATS_CACHE_DIR => $::imscpConfig{'AWSTATS_CACHE_DIR'}, - AWSTATS_ENGINE_DIR => $::imscpConfig{'AWSTATS_ENGINE_DIR'}, - AWSTATS_WEB_DIR => $::imscpConfig{'AWSTATS_WEB_DIR'}, - CMD_LOGRESOLVEMERGE => "perl $awstatsPackageRootDir/Scripts/logresolvemerge.pl", - DOMAIN_NAME => $data->{'DOMAIN_NAME'}, - LOG_DIR => "$self->{'httpd'}->{'config'}->{'HTTPD_LOG_DIR'}/$data->{'DOMAIN_NAME'}" - }; - - ${ $fileC } = process( $tags, ${ $fileC } ); + ${ $fileC } = process( + { + ALIAS => $data->{'ALIAS'}, + AUTH_USER => $adminName, + AWSTATS_CACHE_DIR => $::imscpConfig{'AWSTATS_CACHE_DIR'}, + AWSTATS_ENGINE_DIR => $::imscpConfig{'AWSTATS_ENGINE_DIR'}, + AWSTATS_WEB_DIR => $::imscpConfig{'AWSTATS_WEB_DIR'}, + CMD_LOGRESOLVEMERGE => "$packageDir/bin/logresolvemerge.pl", + DOMAIN_NAME => $data->{'DOMAIN_NAME'}, + LOG_DIR => "$self->{'httpd'}->{'config'}->{'HTTPD_LOG_DIR'}/$data->{'DOMAIN_NAME'}" + }, + ${ $fileC } + ); my $file = iMSCP::File->new( filename => "$::imscpConfig{'AWSTATS_CONFIG_DIR'}/awstats.$data->{'DOMAIN_NAME'}.conf" ); my $rs = $file->save(); diff --git a/engine/PerlLib/Package/Webstats/Awstats/Installer.pm b/engine/PerlLib/Package/Webstats/Awstats/Installer.pm index d0cc52e5a1..106d947560 100644 --- a/engine/PerlLib/Package/Webstats/Awstats/Installer.pm +++ b/engine/PerlLib/Package/Webstats/Awstats/Installer.pm @@ -152,7 +152,7 @@ sub _setupApache2 AWSTATS_ENGINE_DIR => $::imscpConfig{'AWSTATS_ENGINE_DIR'}, AWSTATS_WEB_DIR => $::imscpConfig{'AWSTATS_WEB_DIR'} } ); - $rs = $self->{'httpd'}->buildConfFile( "$::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/Webstats/Awstats/Config/01_awstats.conf" ); + $rs = $self->{'httpd'}->buildConfFile( "$::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/Webstats/Awstats/config/01_awstats.conf" ); $rs ||= $self->{'httpd'}->enableSites( '01_awstats.conf' ); } @@ -166,7 +166,6 @@ sub _setupApache2 sub _disableDefaultConfig { - if ( -f "$::imscpConfig{'AWSTATS_CONFIG_DIR'}/awstats.conf" ) { my $rs = iMSCP::File->new( filename => "$::imscpConfig{'AWSTATS_CONFIG_DIR'}/awstats.conf" )->moveFile( "$::imscpConfig{'AWSTATS_CONFIG_DIR'}/awstats.conf.disabled" @@ -202,7 +201,7 @@ sub _addAwstatsCronTask DWEEK => '*', USER => $::imscpConfig{'ROOT_USER'}, COMMAND => 'nice -n 10 ionice -c2 -n5 ' . - "perl $::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/Webstats/Awstats/Scripts/awstats_updateall.pl now " . + "$::imscpConfig{'ENGINE_ROOT_DIR'}/PerlLib/Package/Webstats/Awstats/bin/awstats_updateall.pl now " . "-awstatsprog=$::imscpConfig{'AWSTATS_ENGINE_DIR'}/awstats.pl > /dev/null 2>&1" } ); } diff --git a/engine/PerlLib/Package/Webstats/Awstats/Scripts/awstats_updateall.pl b/engine/PerlLib/Package/Webstats/Awstats/bin/awstats_updateall.pl similarity index 100% rename from engine/PerlLib/Package/Webstats/Awstats/Scripts/awstats_updateall.pl rename to engine/PerlLib/Package/Webstats/Awstats/bin/awstats_updateall.pl diff --git a/engine/PerlLib/Package/Webstats/Awstats/Scripts/logresolvemerge.pl b/engine/PerlLib/Package/Webstats/Awstats/bin/logresolvemerge.pl similarity index 100% rename from engine/PerlLib/Package/Webstats/Awstats/Scripts/logresolvemerge.pl rename to engine/PerlLib/Package/Webstats/Awstats/bin/logresolvemerge.pl diff --git a/engine/PerlLib/Package/Webstats/Awstats/Config/01_awstats.conf b/engine/PerlLib/Package/Webstats/Awstats/config/01_awstats.conf similarity index 100% rename from engine/PerlLib/Package/Webstats/Awstats/Config/01_awstats.conf rename to engine/PerlLib/Package/Webstats/Awstats/config/01_awstats.conf diff --git a/engine/PerlLib/Package/Webstats/Awstats/Config/awstats.imscp_tpl.conf b/engine/PerlLib/Package/Webstats/Awstats/config/awstats.imscp_tpl.conf similarity index 100% rename from engine/PerlLib/Package/Webstats/Awstats/Config/awstats.imscp_tpl.conf rename to engine/PerlLib/Package/Webstats/Awstats/config/awstats.imscp_tpl.conf diff --git a/engine/PerlLib/Servers/cron/cron.pm b/engine/PerlLib/Servers/cron/cron.pm index 00d2f1ce2b..e4e6ddda7e 100644 --- a/engine/PerlLib/Servers/cron/cron.pm +++ b/engine/PerlLib/Servers/cron/cron.pm @@ -295,15 +295,13 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeCronSetEnginePermissions' ); - return $rs if $rs || !-f "$self->{'config'}->{'CRON_D_DIR'}/imscp"; + return 0 unless -f "$self->{'config'}->{'CRON_D_DIR'}/imscp"; - $rs = setRights( "$self->{'config'}->{'CRON_D_DIR'}/imscp", { + setRights( "$self->{'config'}->{'CRON_D_DIR'}/imscp", { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, mode => '0640' } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterCronSetEnginePermissions' ); } =back diff --git a/engine/PerlLib/Servers/ftpd/proftpd.pm b/engine/PerlLib/Servers/ftpd/proftpd.pm index 19b4a18f18..f1b953e9b4 100644 --- a/engine/PerlLib/Servers/ftpd/proftpd.pm +++ b/engine/PerlLib/Servers/ftpd/proftpd.pm @@ -168,13 +168,11 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeFtpdSetEnginePermissions' ); - $rs ||= setRights( $self->{'config'}->{'FTPD_CONF_FILE'}, { + setRights( $self->{'config'}->{'FTPD_CONF_FILE'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, mode => '0640' } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterFtpdSetEnginePermissions' ); } =item addUser( \%data ) diff --git a/engine/PerlLib/Servers/ftpd/vsftpd.pm b/engine/PerlLib/Servers/ftpd/vsftpd.pm index 811bcc655e..e64b474ff7 100644 --- a/engine/PerlLib/Servers/ftpd/vsftpd.pm +++ b/engine/PerlLib/Servers/ftpd/vsftpd.pm @@ -168,8 +168,7 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeFtpdSetEnginePermissions' ); - $rs ||= setRights( $self->{'config'}->{'FTPD_USER_CONF_DIR'}, { + my $rs = setRights( $self->{'config'}->{'FTPD_USER_CONF_DIR'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, dirmode => '0750', @@ -181,7 +180,6 @@ sub setEnginePermissions group => $::imscpConfig{'ROOT_GROUP'}, mode => '0640' } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterFtpdSetEnginePermissions' ); } =item addUser( \%data ) diff --git a/engine/PerlLib/Servers/httpd/apache_fcgid.pm b/engine/PerlLib/Servers/httpd/apache_fcgid.pm index 276e7aed1d..90e8331866 100644 --- a/engine/PerlLib/Servers/httpd/apache_fcgid.pm +++ b/engine/PerlLib/Servers/httpd/apache_fcgid.pm @@ -180,17 +180,11 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeHttpdSetEnginePermissions' ); - $rs ||= setRights( $self->{'phpConfig'}->{'PHP_FCGI_STARTER_DIR'}, { + my $rs = setRights( $self->{'phpConfig'}->{'PHP_FCGI_STARTER_DIR'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, mode => '0555' } ); - $rs ||= setRights( '/usr/local/sbin/vlogger', { - user => $::imscpConfig{'ROOT_USER'}, - group => $::imscpConfig{'ROOT_GROUP'}, - mode => '0750' - } ); $rs ||= setRights( $self->{'config'}->{'HTTPD_LOG_DIR'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, @@ -210,7 +204,6 @@ sub setEnginePermissions filemode => '0440', recursive => iMSCP::Getopt->fixPermissions } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterHttpdSetEnginePermissions' ); } =item addUser( \%data ) @@ -901,12 +894,13 @@ sub buildConfFile } my $rs = $self->{'eventManager'}->trigger( 'beforeHttpdBuildConfFile', $cfgTpl, $file, $data, $options ); - $rs || ( ${ $cfgTpl } = $self->buildConf( $cfgTpl, $file, $data ) ); - $rs = $self->{'eventManager'}->trigger( 'afterHttpdBuildConfFile', $cfgTpl, $file, $data, $options ); + $rs || $self->buildConf( $cfgTpl, $file, $data ); + $rs ||= $self->{'eventManager'}->trigger( 'afterHttpdBuildConfFile', $cfgTpl, $file, $data, $options ); $rs == 0 or die( getMessageByType( 'error', { amount => 1, remove => TRUE } )); local $UMASK = 022; $file = iMSCP::File->new( filename => $options->{'destination'} // "$self->{'config'}->{'HTTPD_SITES_AVAILABLE_DIR'}/$file" ); + $file->set( ${ $cfgTpl } ); $rs ||= $file->save(); $rs == 0 or die( getMessageByType( 'error', { amount => 1, remove => TRUE } )); @@ -1740,7 +1734,7 @@ sub _addFiles $rs = setRights( "$data->{'WEB_DIR'}/logs", { user => $::imscpConfig{'ROOT_USER'}, group => $data->{'GROUP'}, - mode => '02750' + mode => '2750' } ); return $rs if $rs; diff --git a/engine/PerlLib/Servers/httpd/apache_fcgid/installer.pm b/engine/PerlLib/Servers/httpd/apache_fcgid/installer.pm index 34159c14db..0676be2669 100644 --- a/engine/PerlLib/Servers/httpd/apache_fcgid/installer.pm +++ b/engine/PerlLib/Servers/httpd/apache_fcgid/installer.pm @@ -373,10 +373,11 @@ sub _buildApacheConfFiles } $self->{'httpd'}->setData( { + ENGINE_ROOT_DIR => $::imscpConfig{'ENGINE_ROOT_DIR'}, HTTPD_CUSTOM_SITES_DIR => $self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}, HTTPD_LOG_DIR => $self->{'config'}->{'HTTPD_LOG_DIR'}, HTTPD_ROOT_DIR => $self->{'config'}->{'HTTPD_ROOT_DIR'}, - VLOGGER_CONF => "$self->{'apacheCfgDir'}/vlogger.conf" + VLOGGER_CONF => "$self->{'apacheCfgDir'}/imscp-vlogger.conf" } ); $rs ||= $self->{'httpd'}->buildConfFile( '00_nameserver.conf' ); $rs ||= $self->{'httpd'}->buildConfFile( '00_imscp.conf', {}, { @@ -429,44 +430,42 @@ sub _setupVlogger try { my $dbHost = ::setupGetQuestion( 'DATABASE_HOST' ); - $dbHost = $dbHost eq 'localhost' ? '127.0.0.1' : $dbHost; - my $dbPort = ::setupGetQuestion( 'DATABASE_PORT' ); - my $dbName = ::setupGetQuestion( 'DATABASE_NAME' ); - my $dbUser = 'vlogger_user'; + my $dbUserHost = ::setupGetQuestion( 'DATABASE_USER_HOST' ); + my $dbPass = randomStr( 16, ALNUM ); - my $dbHost = ::setupGetQuestion( 'DATABASE_USER_HOST' ); - $userHost = '127.0.0.1' if $userHost eq 'localhost'; - - my $pass = randomStr( 16, ALNUM ); + # Because imscp-vlogger script call CHROOT(2), it cannot access MySQL server through UDS + # Thus, we need force connection through TCP + $dbHost = '127.0.0.1' if $dbHost eq 'localhost'; + $dbUserHost = '127.0.0.1' if $dbUserHost eq 'localhost'; - my $db = iMSCP::Database->factory(); - my $rs = ::setupImportSqlSchema( $db, "$self->{'apacheCfgDir'}/vlogger.sql" ); + my $rs = ::setupImportSqlSchema( iMSCP::Database->factory(), "$self->{'apacheCfgDir'}/imscp-vlogger.sql" ); return $rs if $rs; - for my $oldHost ( $userHost, $::imscpOldConfig{'DATABASE_USER_HOST'}, 'localhost' ) { - next unless length $oldHost; - Servers::sqld->factory()->dropUser( 'vlogger_user', $oldHost ); + if ( length $::imscpOldConfig{'DATABASE_USER_HOST'} && $dbUserHost ne $::imscpOldConfig{'DATABASE_USER_HOST'} ) { + Servers::sqld->factory()->dropUser( $dbUser, $::imscpOldConfig{'DATABASE_USER_HOST'} ); } - Servers::sqld->factory()->createUser( 'vlogger_user', $userHost, $pass ); + Servers::sqld->factory()->createUser( $dbUser, $dbUserHost, $dbPass ); - $db->getConnector()->run( fixup => sub { + iMSCP::Database->factory()->getConnector()->run( fixup => sub { # No need to escape wildcard characters. See https://bugs.mysql.com/bug.php?id=18660 - $_->do( "GRANT SELECT, INSERT, UPDATE ON @{ [ $_->quote_identifier( $dbName ) ] }.httpd_vlogger TO ?\@?", undef, 'vlogger_user', $userHost ); + $_->do( + "GRANT SELECT, INSERT, UPDATE ON @{ [ $_->quote_identifier( $dbName ) ] }.httpd_vlogger TO ?\@?", undef, $dbUser, $dbUserHost + ); } ); $self->{'httpd'}->setData( { - DATABASE_NAME => $dbName, - DATABASE_HOST => $dbHost, DATABASE_PORT => $dbPort, + DATABASE_HOST => $dbHost, + DATABASE_NAME => $dbName, DATABASE_USER => $dbUser, - DATABASE_PASSWORD => 'vlogger_user' + DATABASE_PASSWORD => $dbPass } ); - $self->{'httpd'}->buildConfFile( "$self->{'apacheCfgDir'}/vlogger.conf.tpl", { SKIP_TEMPLATE_CLEANER => TRUE }, { - destination => "$self->{'apacheCfgDir'}/vlogger.conf" + $self->{'httpd'}->buildConfFile( "$self->{'apacheCfgDir'}/imscp-vlogger.conf.tpl", { SKIP_TEMPLATE_CLEANER => TRUE }, { + destination => "$self->{'apacheCfgDir'}/imscp-vlogger.conf" } ); } catch { error( $_ ); diff --git a/engine/PerlLib/Servers/httpd/apache_itk.pm b/engine/PerlLib/Servers/httpd/apache_itk.pm index f8e7e035f1..ae963418d1 100644 --- a/engine/PerlLib/Servers/httpd/apache_itk.pm +++ b/engine/PerlLib/Servers/httpd/apache_itk.pm @@ -180,14 +180,7 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeHttpdSetEnginePermissions' ); - $rs ||= setRights( '/usr/local/sbin/vlogger', { - user => $::imscpConfig{'ROOT_USER'}, - group => $::imscpConfig{'ROOT_GROUP'}, - mode => '0750' - } - ); - $rs ||= setRights( $self->{'config'}->{'HTTPD_LOG_DIR'}, { + my $rs = setRights( $self->{'config'}->{'HTTPD_LOG_DIR'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, dirmode => '0755', @@ -205,7 +198,6 @@ sub setEnginePermissions filemode => '0440', recursive => iMSCP::Getopt->fixPermissions } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterHttpdSetEnginePermissions' ); } =item addUser( \%data ) @@ -894,12 +886,13 @@ sub buildConfFile } my $rs = $self->{'eventManager'}->trigger( 'beforeHttpdBuildConfFile', $cfgTpl, $file, $data, $options ); - $rs || ( ${ $cfgTpl } = $self->buildConf( $cfgTpl, $file, $data ) ); - $rs = $self->{'eventManager'}->trigger( 'afterHttpdBuildConfFile', $cfgTpl, $file, $data, $options ); + $rs || $self->buildConf( $cfgTpl, $file, $data ); + $rs ||= $self->{'eventManager'}->trigger( 'afterHttpdBuildConfFile', $cfgTpl, $file, $data, $options ); $rs == 0 or die( getMessageByType( 'error', { amount => 1, remove => TRUE } )); local $UMASK = 022; $file = iMSCP::File->new( filename => $options->{'destination'} // "$self->{'config'}->{'HTTPD_SITES_AVAILABLE_DIR'}/$file" ); + $file->set( ${ $cfgTpl } ); $rs ||= $file->save(); $rs == 0 or die( getMessageByType( 'error', { amount => 1, remove => TRUE } )); @@ -1737,7 +1730,7 @@ sub _addFiles $rs = setRights( "$data->{'WEB_DIR'}/logs", { user => $::imscpConfig{'ROOT_USER'}, group => $data->{'GROUP'}, - mode => '02750' + mode => '2750' } ); return $rs if $rs; diff --git a/engine/PerlLib/Servers/httpd/apache_itk/installer.pm b/engine/PerlLib/Servers/httpd/apache_itk/installer.pm index 326ed8075a..9bbcbf5b46 100644 --- a/engine/PerlLib/Servers/httpd/apache_itk/installer.pm +++ b/engine/PerlLib/Servers/httpd/apache_itk/installer.pm @@ -364,10 +364,11 @@ sub _buildApacheConfFiles } $self->{'httpd'}->setData( { + ENGINE_ROOT_DIR => $::imscpConfig{'ENGINE_ROOT_DIR'}, HTTPD_CUSTOM_SITES_DIR => $self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}, HTTPD_LOG_DIR => $self->{'config'}->{'HTTPD_LOG_DIR'}, HTTPD_ROOT_DIR => $self->{'config'}->{'HTTPD_ROOT_DIR'}, - VLOGGER_CONF => "$self->{'apacheCfgDir'}/vlogger.conf" + VLOGGER_CONF => "$self->{'apacheCfgDir'}/imscp-vlogger.conf" } ); $rs ||= $self->{'httpd'}->buildConfFile( '00_nameserver.conf', ); $rs ||= $self->{'httpd'}->buildConfFile( '00_imscp.conf', {}, { @@ -421,40 +422,43 @@ sub _setupVlogger my ( $self ) = @_; try { - my $host = ::setupGetQuestion( 'DATABASE_HOST' ); - $host = $host eq 'localhost' ? '127.0.0.1' : $host; - my $port = ::setupGetQuestion( 'DATABASE_PORT' ); + my $dbHost = ::setupGetQuestion( 'DATABASE_HOST' ); + my $dbPort = ::setupGetQuestion( 'DATABASE_PORT' ); my $dbName = ::setupGetQuestion( 'DATABASE_NAME' ); - my $user = 'vlogger_user'; - my $userHost = ::setupGetQuestion( 'DATABASE_USER_HOST' ); - $userHost = '127.0.0.1' if $userHost eq 'localhost'; - my $pass = randomStr( 16, ALNUM ); + my $dbUser = 'vlogger_user'; + my $dbUserHost = ::setupGetQuestion( 'DATABASE_USER_HOST' ); + my $dbPass = randomStr( 16, ALNUM ); - my $db = iMSCP::Database->factory(); - my $rs = ::setupImportSqlSchema( $db, "$self->{'apacheCfgDir'}/vlogger.sql" ); + # Because imscp-vlogger script call CHROOT(2), it cannot access MySQL server through UDS + # Thus, we need force connection through TCP + $dbHost = '127.0.0.1' if $dbHost eq 'localhost'; + $dbUserHost = '127.0.0.1' if $dbUserHost eq 'localhost'; + + my $rs = ::setupImportSqlSchema( iMSCP::Database->factory(), "$self->{'apacheCfgDir'}/imscp-vlogger.sql" ); return $rs if $rs; - for my $oldHost ( $userHost, $::imscpOldConfig{'DATABASE_USER_HOST'}, 'localhost' ) { - next unless length $oldHost; - Servers::sqld->factory()->dropUser( $user, $oldHost ); + if ( length $::imscpOldConfig{'DATABASE_USER_HOST'} && $dbUserHost ne $::imscpOldConfig{'DATABASE_USER_HOST'} ) { + Servers::sqld->factory()->dropUser( $dbUser, $::imscpOldConfig{'DATABASE_USER_HOST'} ); } - Servers::sqld->factory()->createUser( $user, $userHost, $pass ); + Servers::sqld->factory()->createUser( $dbUser, $dbUserHost, $dbPass ); - $db->getConnector()->run( fixup => sub { + iMSCP::Database->factory()->getConnector()->run( fixup => sub { # No need to escape wildcard characters. See https://bugs.mysql.com/bug.php?id=18660 - $_->do( "GRANT SELECT, INSERT, UPDATE ON @{ [ $_->quote_identifier( $dbName ) ] }.httpd_vlogger TO ?\@?", undef, $user, $userHost ); + $_->do( + "GRANT SELECT, INSERT, UPDATE ON @{ [ $_->quote_identifier( $dbName ) ] }.httpd_vlogger TO ?\@?", undef, $dbUser, $dbUserHost + ); } ); $self->{'httpd'}->setData( { + DATABASE_HOST => $dbHost, + DATABASE_PORT => $dbPort, DATABASE_NAME => $dbName, - DATABASE_HOST => $host, - DATABASE_PORT => $port, - DATABASE_USER => $user, - DATABASE_PASSWORD => $pass + DATABASE_USER => $dbUser, + DATABASE_PASSWORD => $dbPass } ); - $self->{'httpd'}->buildConfFile( "$self->{'apacheCfgDir'}/vlogger.conf.tpl", { SKIP_TEMPLATE_CLEANER => TRUE }, { - destination => "$self->{'apacheCfgDir'}/vlogger.conf" + $self->{'httpd'}->buildConfFile( "$self->{'apacheCfgDir'}/imscp-vlogger.conf.tpl", { SKIP_TEMPLATE_CLEANER => TRUE }, { + destination => "$self->{'apacheCfgDir'}/imscp-vlogger.conf" } ); } catch { error( $_ ); diff --git a/engine/PerlLib/Servers/httpd/apache_php_fpm.pm b/engine/PerlLib/Servers/httpd/apache_php_fpm.pm index f50ad2760a..eb15b5c002 100644 --- a/engine/PerlLib/Servers/httpd/apache_php_fpm.pm +++ b/engine/PerlLib/Servers/httpd/apache_php_fpm.pm @@ -181,13 +181,7 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeHttpdSetEnginePermissions' ); - $rs ||= setRights( '/usr/local/sbin/vlogger', { - user => $::imscpConfig{'ROOT_USER'}, - group => $::imscpConfig{'ROOT_GROUP'}, - mode => '0750' - } ); - $rs ||= setRights( $self->{'config'}->{'HTTPD_LOG_DIR'}, { + my $rs = setRights( $self->{'config'}->{'HTTPD_LOG_DIR'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, dirmode => '0755', @@ -205,7 +199,6 @@ sub setEnginePermissions filemode => '0440', recursive => iMSCP::Getopt->fixPermissions } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterHttpdSetEnginePermissions' ); } =item addUser( \%data ) @@ -835,12 +828,12 @@ sub buildConf ${ $cfgTpl } = replaceBloc( "# SECTION fwd BEGIN.\n", "# SECTION fwd END.\n", '', ${ $cfgTpl } ); } elsif ( grep ( $_ eq $data->{'VHOST_TYPE'}, 'domain_fwd', 'domain_ssl_fwd', 'domain_disabled_fwd' ) ) { # Remove ssl section if needed - $cfgTpl = replaceBloc( "# SECTION ssl BEGIN.\n", "# SECTION ssl END.\n", '', ${ $cfgTpl } ) unless $data->{'VHOST_TYPE'} eq 'domain_ssl_fwd'; + ${ $cfgTpl } = replaceBloc( "# SECTION ssl BEGIN.\n", "# SECTION ssl END.\n", '', ${ $cfgTpl } ) unless $data->{'VHOST_TYPE'} eq 'domain_ssl_fwd'; # Remove domain section - $cfgTpl = replaceBloc( "# SECTION dmn BEGIN.\n", "# SECTION dmn END.\n", '', ${ $cfgTpl } ); + ${ $cfgTpl } = replaceBloc( "# SECTION dmn BEGIN.\n", "# SECTION dmn END.\n", '', ${ $cfgTpl } ); } elsif ( grep ( $_ eq $data->{'VHOST_TYPE'}, 'domain_ssl', 'domain_disabled_ssl' ) ) { # Remove forward section - $cfgTpl = replaceBloc( "# SECTION fwd BEGIN.\n", "# SECTION fwd END.\n", '', ${ $cfgTpl } ); + ${ $cfgTpl } = replaceBloc( "# SECTION fwd BEGIN.\n", "# SECTION fwd END.\n", '', ${ $cfgTpl } ); } } @@ -896,12 +889,13 @@ sub buildConfFile } my $rs = $self->{'eventManager'}->trigger( 'beforeHttpdBuildConfFile', $cfgTpl, $file, $data, $options ); - $rs || ( ${ $cfgTpl } = $self->buildConf( $cfgTpl, $file, $data ) ); - $rs = $self->{'eventManager'}->trigger( 'afterHttpdBuildConfFile', $cfgTpl, $file, $data, $options ); + $rs || $self->buildConf( $cfgTpl, $file, $data ); + $rs ||= $self->{'eventManager'}->trigger( 'afterHttpdBuildConfFile', $cfgTpl, $file, $data, $options ); $rs == 0 or die( getMessageByType( 'error', { amount => 1, remove => TRUE } )); local $UMASK = 022; $file = iMSCP::File->new( filename => $options->{'destination'} // "$self->{'config'}->{'HTTPD_SITES_AVAILABLE_DIR'}/$file" ); + $file->set( ${ $cfgTpl } ); $rs ||= $file->save(); $rs == 0 or die( getMessageByType( 'error', { amount => 1, remove => TRUE } )); @@ -1758,7 +1752,7 @@ sub _addFiles $rs = setRights( "$data->{'WEB_DIR'}/logs", { user => $::imscpConfig{'ROOT_USER'}, group => $data->{'GROUP'}, - mode => '02750' + mode => '2750' } ); return $rs if $rs; diff --git a/engine/PerlLib/Servers/httpd/apache_php_fpm/installer.pm b/engine/PerlLib/Servers/httpd/apache_php_fpm/installer.pm index 6ef3aac2f2..2b6b6d7d65 100644 --- a/engine/PerlLib/Servers/httpd/apache_php_fpm/installer.pm +++ b/engine/PerlLib/Servers/httpd/apache_php_fpm/installer.pm @@ -434,10 +434,11 @@ sub _buildApacheConfFiles } $self->{'httpd'}->setData( { + ENGINE_ROOT_DIR => $::imscpConfig{'ENGINE_ROOT_DIR'}, HTTPD_CUSTOM_SITES_DIR => $self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}, HTTPD_LOG_DIR => $self->{'config'}->{'HTTPD_LOG_DIR'}, HTTPD_ROOT_DIR => $self->{'config'}->{'HTTPD_ROOT_DIR'}, - VLOGGER_CONF => "$self->{'apacheCfgDir'}/vlogger.conf" + VLOGGER_CONF => "$self->{'apacheCfgDir'}/imscp-vlogger.conf" } ); $rs ||= $self->{'httpd'}->buildConfFile( '00_nameserver.conf' ); $rs ||= $self->{'httpd'}->buildConfFile( '00_imscp.conf', {}, { @@ -501,40 +502,43 @@ sub _setupVlogger my ( $self ) = @_; try { - my $host = ::setupGetQuestion( 'DATABASE_HOST' ); - $host = $host eq 'localhost' ? '127.0.0.1' : $host; - my $port = ::setupGetQuestion( 'DATABASE_PORT' ); + my $dbHost = ::setupGetQuestion( 'DATABASE_HOST' ); + my $dbPort = ::setupGetQuestion( 'DATABASE_PORT' ); my $dbName = ::setupGetQuestion( 'DATABASE_NAME' ); - my $user = 'vlogger_user'; - my $userHost = ::setupGetQuestion( 'DATABASE_USER_HOST' ); - $userHost = '127.0.0.1' if $userHost eq 'localhost'; - my $pass = randomStr( 16, ALNUM ); + my $dbUser = 'vlogger_user'; + my $dbUserHost = ::setupGetQuestion( 'DATABASE_USER_HOST' ); + my $dbPass = randomStr( 16, ALNUM ); - my $db = iMSCP::Database->factory(); - my $rs = ::setupImportSqlSchema( $db, "$self->{'apacheCfgDir'}/vlogger.sql" ); + # Because imscp-vlogger script call CHROOT(2), it cannot access MySQL server through UDS + # Thus, we need force connection through TCP + $dbHost = '127.0.0.1' if $dbHost eq 'localhost'; + $dbUserHost = '127.0.0.1' if $dbUserHost eq 'localhost'; + + my $rs = ::setupImportSqlSchema( iMSCP::Database->factory(), "$self->{'apacheCfgDir'}/imscp-vlogger.sql" ); return $rs if $rs; - for my $oldHost ( $userHost, $::imscpOldConfig{'DATABASE_USER_HOST'}, 'localhost' ) { - next unless length $oldHost; - Servers::sqld->factory()->dropUser( $user, $oldHost ); + if ( length $::imscpOldConfig{'DATABASE_USER_HOST'} && $dbUserHost ne $::imscpOldConfig{'DATABASE_USER_HOST'} ) { + Servers::sqld->factory()->dropUser( $dbUser, $::imscpOldConfig{'DATABASE_USER_HOST'} ); } - Servers::sqld->factory()->createUser( $user, $userHost, $pass ); + Servers::sqld->factory()->createUser( $dbUser, $dbUserHost, $dbPass ); - $db->getConnector()->run( fixup => sub { + iMSCP::Database->factory()->getConnector()->run( fixup => sub { # No need to escape wildcard characters. See https://bugs.mysql.com/bug.php?id=18660 - $_->do( "GRANT SELECT, INSERT, UPDATE ON @{ [ $_->quote_identifier( $dbName ) ] }.httpd_vlogger TO ?\@?", undef, $user, $userHost ); + $_->do( + "GRANT SELECT, INSERT, UPDATE ON @{ [ $_->quote_identifier( $dbName ) ] }.httpd_vlogger TO ?\@?", undef, $dbUser, $dbUserHost + ); } ); $self->{'httpd'}->setData( { + DATABASE_HOST => $dbHost, + DATABASE_PORT => $dbPort, DATABASE_NAME => $dbName, - DATABASE_HOST => $host, - DATABASE_PORT => $port, - DATABASE_USER => $user, - DATABASE_PASSWORD => $pass + DATABASE_USER => $dbUser, + DATABASE_PASSWORD => $dbPass } ); - $self->{'httpd'}->buildConfFile( "$self->{'apacheCfgDir'}/vlogger.conf.tpl", { SKIP_TEMPLATE_CLEANER => TRUE }, { - destination => "$self->{'apacheCfgDir'}/vlogger.conf" + $self->{'httpd'}->buildConfFile( "$self->{'apacheCfgDir'}/imscp-vlogger.conf.tpl", { SKIP_TEMPLATE_CLEANER => TRUE }, { + destination => "$self->{'apacheCfgDir'}/imscp-vlogger.conf" } ); } catch { error( $_ ); diff --git a/engine/PerlLib/Servers/mta/postfix.pm b/engine/PerlLib/Servers/mta/postfix.pm index 3988dda875..066041605a 100644 --- a/engine/PerlLib/Servers/mta/postfix.pm +++ b/engine/PerlLib/Servers/mta/postfix.pm @@ -173,8 +173,7 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeMtaSetEnginePermissions' ); - $rs ||= setRights( $self->{'config'}->{'POSTFIX_CONF_FILE'}, { + my $rs = setRights( $self->{'config'}->{'POSTFIX_CONF_FILE'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, mode => '0644' @@ -188,8 +187,7 @@ sub setEnginePermissions user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, mode => '0644' - } - ); + } ); $rs ||= setRights( $self->{'config'}->{'MTA_VIRTUAL_CONF_DIR'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, @@ -198,11 +196,10 @@ sub setEnginePermissions recursive => TRUE } ); $rs ||= setRights( "$main::imscpConfig{'ENGINE_ROOT_DIR'}/bin/imscp-vacation", { - user => $::imscpConfig{'ROOT_USER'}, - group => $::imscpConfig{'IMSCP_GROUP'}, - mode => '0750', - } - ); + user => $::imscpConfig{'ROOT_USER'}, + group => $::imscpConfig{'IMSCP_GROUP'}, + mode => '0750', + } ); $rs ||= setRights( $self->{'config'}->{'MTA_VIRTUAL_MAIL_DIR'}, { user => $self->{'config'}->{'MTA_MAILBOX_UID_NAME'}, group => $self->{'config'}->{'MTA_MAILBOX_GID_NAME'}, @@ -215,7 +212,6 @@ sub setEnginePermissions group => $main::imscpConfig{'ROOT_GROUP'}, mode => '0750' } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterMtaSetEnginePermissions' ); } =item start( ) @@ -1038,7 +1034,7 @@ sub _getMapFileObject my $file = iMSCP::File->new( filename => $mapPath ); unless ( -f $mapPath ) { - $file->set( <<"EOF"); + $file->set( <<"EOF" ); # Postfix @{ [ basename( $mapPath ) ] } map - auto-generated by i-MSCP # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN diff --git a/engine/PerlLib/Servers/named/bind.pm b/engine/PerlLib/Servers/named/bind.pm index bf993a355f..4754324606 100644 --- a/engine/PerlLib/Servers/named/bind.pm +++ b/engine/PerlLib/Servers/named/bind.pm @@ -170,8 +170,7 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeNamedSetEnginePermissions' ); - $rs ||= setRights( $self->{'config'}->{'BIND_CONF_DIR'}, { + my $rs = setRights( $self->{'config'}->{'BIND_CONF_DIR'}, { user => $::imscpConfig{'ROOT_USER'}, group => $self->{'config'}->{'BIND_GROUP'}, dirmode => '2750', @@ -181,7 +180,7 @@ sub setEnginePermissions return $rs if $rs; if ( -f "$self->{'config'}->{'BIND_CONF_DIR'}/rndc.key" ) { - $rs ||= setRights( "$self->{'config'}->{'BIND_CONF_DIR'}/rndc.key", { + $rs = setRights( "$self->{'config'}->{'BIND_CONF_DIR'}/rndc.key", { user => $self->{'config'}->{'BIND_USER'}, group => $self->{'config'}->{'BIND_GROUP'}, } ); @@ -202,7 +201,6 @@ sub setEnginePermissions filemode => '0640', recursive => TRUE } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterNamedSetEnginePermissions' ); } =item addDmn( \%data ) diff --git a/engine/PerlLib/Servers/po/courier.pm b/engine/PerlLib/Servers/po/courier.pm index bd60f566e0..60d4508687 100644 --- a/engine/PerlLib/Servers/po/courier.pm +++ b/engine/PerlLib/Servers/po/courier.pm @@ -187,11 +187,8 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforePoSetEnginePermissions' ); - return $rs if $rs; - if ( -d $self->{'config'}->{'AUTHLIB_SOCKET_DIR'} ) { - $rs ||= setRights( $self->{'config'}->{'AUTHLIB_SOCKET_DIR'}, { + my $rs ||= setRights( $self->{'config'}->{'AUTHLIB_SOCKET_DIR'}, { user => $self->{'config'}->{'AUTHDAEMON_USER'}, group => $self->{'mta'}->{'config'}->{'MTA_MAILBOX_GID_NAME'}, mode => '0750' @@ -199,7 +196,7 @@ sub setEnginePermissions return $rs if $rs; } - $rs = setRights( "$self->{'config'}->{'AUTHLIB_CONF_DIR'}/authmysqlrc", { + my $rs = setRights( "$self->{'config'}->{'AUTHLIB_CONF_DIR'}/authmysqlrc", { user => $self->{'config'}->{'AUTHDAEMON_USER'}, group => $self->{'config'}->{'AUTHDAEMON_GROUP'}, mode => '0660' @@ -220,7 +217,7 @@ sub setEnginePermissions return $rs if $rs; } - $self->{'eventManager'}->trigger( 'afterPoSetEnginePermissions' ); + 0; } =item addMail( \%data ) diff --git a/engine/PerlLib/Servers/po/dovecot.pm b/engine/PerlLib/Servers/po/dovecot.pm index 117904b6ec..a44faa6354 100644 --- a/engine/PerlLib/Servers/po/dovecot.pm +++ b/engine/PerlLib/Servers/po/dovecot.pm @@ -274,8 +274,7 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforePoSetEnginePermissions' ); - $rs ||= setRights( $self->{'config'}->{'DOVECOT_CONF_DIR'}, { + my $rs = setRights( $self->{'config'}->{'DOVECOT_CONF_DIR'}, { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, mode => '0755' @@ -295,7 +294,6 @@ sub setEnginePermissions group => $self->{'mta'}->{'config'}->{'MTA_MAILBOX_GID_NAME'}, mode => '0750' } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterPoSetEnginePermissions' ); } =item start( ) diff --git a/engine/PerlLib/Servers/sqld/mysql.pm b/engine/PerlLib/Servers/sqld/mysql.pm index c2c74fd270..464cc33e31 100644 --- a/engine/PerlLib/Servers/sqld/mysql.pm +++ b/engine/PerlLib/Servers/sqld/mysql.pm @@ -143,8 +143,7 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeSqldSetEnginePermissions' ); - $rs ||= setRights( "$self->{'config'}->{'SQLD_CONF_DIR'}/my.cnf", { + my $rs = setRights( "$self->{'config'}->{'SQLD_CONF_DIR'}/my.cnf", { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, mode => '0644' @@ -154,7 +153,6 @@ sub setEnginePermissions group => $self->{'config'}->{'SQLD_GROUP'}, mode => '0640' } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterSqldSetEnginePermissions' ); } =item restart( ) diff --git a/engine/PerlLib/Servers/sqld/remote.pm b/engine/PerlLib/Servers/sqld/remote.pm index e808c409cd..42283fa50e 100644 --- a/engine/PerlLib/Servers/sqld/remote.pm +++ b/engine/PerlLib/Servers/sqld/remote.pm @@ -116,8 +116,7 @@ sub setEnginePermissions { my ( $self ) = @_; - my $rs = $self->{'eventManager'}->trigger( 'beforeSqldSetEnginePermissions' ); - $rs ||= setRights( "$self->{'config'}->{'SQLD_CONF_DIR'}/my.cnf", { + my $rs = setRights( "$self->{'config'}->{'SQLD_CONF_DIR'}/my.cnf", { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'ROOT_GROUP'}, mode => '0644' @@ -127,7 +126,6 @@ sub setEnginePermissions group => $::imscpConfig{'ROOT_GROUP'}, mode => '0640' } ); - $rs ||= $self->{'eventManager'}->trigger( 'afterSqldSetEnginePermissions' ); } =item createUser( $user, $host, $password ) diff --git a/engine/PerlLib/iMSCP/DbTasksProcessor.pm b/engine/PerlLib/iMSCP/DbTasksProcessor.pm index 0574217727..b68b23c6ca 100644 --- a/engine/PerlLib/iMSCP/DbTasksProcessor.pm +++ b/engine/PerlLib/iMSCP/DbTasksProcessor.pm @@ -30,7 +30,7 @@ use Encode 'encode_utf8'; use iMSCP::Boolean; use iMSCP::Database; use iMSCP::Debug qw/ debug getMessageByType newDebug endDebug /; -use iMSCP::Execute qw/ escapeShell execute /; +use iMSCP::Execute 'execute'; use iMSCP::Stepper 'step'; use JSON; use MIME::Base64 qw/ encode_base64 /; @@ -376,7 +376,7 @@ sub processDbTasks ); my ( $stdout, $stderr ); - execute( "perl $::imscpConfig{'ENGINE_ROOT_DIR'}/imscp-sw-mngr " . escapeShell( $pushString ), \$stdout, \$stderr ) == 0 or die( + execute( [ "$::imscpConfig{'ENGINE_ROOT_DIR'}/imscp-sw-mngr", $pushString ], \$stdout, \$stderr ) == 0 or die( $stderr || 'Unknown error' ); debug( $stdout ) if $stdout; @@ -410,13 +410,11 @@ sub processDbTasks ); my ( $stdout, $stderr ); - execute( "perl $::imscpConfig{'ENGINE_ROOT_DIR'}/imscp-pkt-mngr " . escapeShell( $pushString ), \$stdout, \$stderr ) == 0 or die( + execute( [ "$::imscpConfig{'ENGINE_ROOT_DIR'}/imscp-pkt-mngr", $pushString ], \$stdout, \$stderr ) == 0 or die( $stderr || 'Unknown error' ); debug( $stdout ) if $stdout; - execute( "rm -fR /tmp/sw-$_->{'software_archive'}-$_->{'software_id'}", \$stdout, \$stderr ) == 0 or die( - $stderr || 'Unknown error' - ); + execute( "rm -fR /tmp/sw-$_->{'software_archive'}-$_->{'software_id'}", \$stdout, \$stderr ) == 0 or die( $stderr || 'Unknown error' ); debug( $stdout ) if $stdout; } diff --git a/engine/bin/imscp-backend-rqst b/engine/bin/imscp-backend-rqst index 66147cca40..014275d939 100755 --- a/engine/bin/imscp-backend-rqst +++ b/engine/bin/imscp-backend-rqst @@ -47,7 +47,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( "Usage: perl %s [OPTIONS]...", $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( "Usage: %s [OPTIONS]...", $basename ) . qq{ Execute backend requests. diff --git a/engine/bin/imscp-clients-backup b/engine/bin/imscp-clients-backup index d812b2f140..622d0562bf 100755 --- a/engine/bin/imscp-clients-backup +++ b/engine/bin/imscp-clients-backup @@ -257,7 +257,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( "Usage: perl %s [OPTION]...", $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( "Usage: %s [OPTION]...", $basename ) . qq{ Backup client data (Web data, mail data and databases) diff --git a/engine/bin/imscp-clients-suspend b/engine/bin/imscp-clients-suspend index 602da3d90b..d0c2816e3e 100755 --- a/engine/bin/imscp-clients-suspend +++ b/engine/bin/imscp-clients-suspend @@ -49,7 +49,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: perl %s [OPTION]...', $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: %s [OPTION]...', $basename ) . qq{ Suspend expired client accounts diff --git a/engine/bin/imscp-clients-traffic b/engine/bin/imscp-clients-traffic index ce1287d14d..e2456a9db4 100755 --- a/engine/bin/imscp-clients-traffic +++ b/engine/bin/imscp-clients-traffic @@ -52,7 +52,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: perl %s [OPTION]...', $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: %s [OPTION]...', $basename ) . qq{ Update i-MSCP clients' HTTP, FTP, IMAP/POP and SMTP traffic data. diff --git a/engine/bin/imscp-cp-backup b/engine/bin/imscp-cp-backup index ec50049378..b74773e4c5 100755 --- a/engine/bin/imscp-cp-backup +++ b/engine/bin/imscp-cp-backup @@ -152,7 +152,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( "Usage: perl %s [OPTION]...", $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( "Usage: %s [OPTION]...", $basename ) . qq{ Backup control panel data (configuration files and database). diff --git a/engine/bin/imscp-disk-quota b/engine/bin/imscp-disk-quota index 1a150854f6..024437265c 100755 --- a/engine/bin/imscp-disk-quota +++ b/engine/bin/imscp-disk-quota @@ -195,7 +195,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: perl %s [OPTION]...', $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: %s [OPTION]...', $basename ) . qq{ Update quota data for all domain aggregates. diff --git a/engine/bin/imscp-dpkg-post-invoke b/engine/bin/imscp-dpkg-post-invoke index 070662f5fc..97e9ae9c40 100644 --- a/engine/bin/imscp-dpkg-post-invoke +++ b/engine/bin/imscp-dpkg-post-invoke @@ -48,7 +48,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: perl %s [OPTION]...', $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: %s [OPTION]...', $basename ) . qq{ Process dpkg post invoke tasks. diff --git a/engine/bin/imscp-maillogconvert b/engine/bin/imscp-maillogconvert index 8ec7d41333..6c2772c7d0 100755 --- a/engine/bin/imscp-maillogconvert +++ b/engine/bin/imscp-maillogconvert @@ -192,7 +192,7 @@ postfix, sendmail or qmail servers) into a human readable format. The output format is also ready to be used by a log analyzer, like AWStats. Usage: - perl imscp-maillogconvert [standard|vadmin] [year] < logfile > output + imscp-maillogconvert [standard|vadmin] [year] < logfile > output The first parameter specifies what format the mail logfile is : standard - logfile is standard postfix,sendmail,qmail or mdaemon log format diff --git a/engine/bin/imscp-mountall b/engine/bin/imscp-mountall index f45d65047f..34632abd01 100644 --- a/engine/bin/imscp-mountall +++ b/engine/bin/imscp-mountall @@ -47,7 +47,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: perl %s [OPTION]... start|stop', $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: %s [OPTION]... start|stop', $basename ) . qq{ Mount or umount filesystems by reading entries from i-MSCP fstab-like file. diff --git a/engine/bin/imscp-net-traffic b/engine/bin/imscp-net-traffic index a3369ff54f..3d68d15530 100644 --- a/engine/bin/imscp-net-traffic +++ b/engine/bin/imscp-net-traffic @@ -176,7 +176,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: perl %s [OPTION]... add|remove', $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: %s [OPTION]... add|remove', $basename ) . qq{ Add/Remove IPv4 and IPv6 packet filter rules to track incoming/outgoing traffic. diff --git a/engine/bin/imscp-reconfigure b/engine/bin/imscp-reconfigure index 8663610ba0..b5aed1449c 100755 --- a/engine/bin/imscp-reconfigure +++ b/engine/bin/imscp-reconfigure @@ -54,7 +54,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parse( sprintf( 'Usage: perl %s [OPTION]...', $basename )); + iMSCP::Getopt->parse( sprintf( 'Usage: %s [OPTION]...', $basename )); setDebug( iMSCP::Getopt->debug ); setVerbose( iMSCP::Getopt->noprompt && iMSCP::Getopt->verbose ); diff --git a/engine/bin/imscp-server-traffic b/engine/bin/imscp-server-traffic index d6884c110e..09e901c74a 100755 --- a/engine/bin/imscp-server-traffic +++ b/engine/bin/imscp-server-traffic @@ -112,7 +112,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: perl %s [OPTION]...', $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: %s [OPTION]...', $basename ) . qq{ Update server' traffic data. diff --git a/engine/bin/imscp-set-engine-permissions b/engine/bin/imscp-set-engine-permissions index 41cd91b8bc..fb56edcac8 100755 --- a/engine/bin/imscp-set-engine-permissions +++ b/engine/bin/imscp-set-engine-permissions @@ -52,7 +52,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: perl %s [OPTION]...', $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: %s [OPTION]...', $basename ) . qq{ Sets i-MSCP engine permissions. @@ -112,13 +112,21 @@ OPTIONS: group => $::imscpConfig{'IMSCP_GROUP'}, mode => '0750', recursive => TRUE - } - ); + } ); # e.g: /var/www/imscp/engine setRights( "$::imscpConfig{'ROOT_DIR'}/engine", { user => $::imscpConfig{'ROOT_USER'}, group => $::imscpConfig{'IMSCP_GROUP'}, - mode => '0750', + dirmode => '0750', + filemode => '0640', + recursive => TRUE + } ); + # e.g: /var/www/imscp/engine/bin + setRights( "$::imscpConfig{'ROOT_DIR'}/engine/bin", { + user => $::imscpConfig{'ROOT_USER'}, + group => $::imscpConfig{'IMSCP_GROUP'}, + dirmode => '0750', + filemode => '0750', recursive => TRUE } ); # e.g: /var/www/virtual diff --git a/engine/bin/imscp-set-gui-permissions b/engine/bin/imscp-set-gui-permissions index 665655fffa..f12b03163d 100755 --- a/engine/bin/imscp-set-gui-permissions +++ b/engine/bin/imscp-set-gui-permissions @@ -53,7 +53,7 @@ try { my $basename = basename( $0 ); newDebug( $basename . '.log' ); - iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: perl %s [OPTION]...', $basename ) . qq{ + iMSCP::Getopt->parseNoDefault( sprintf( 'Usage: %s [OPTION]...', $basename ) . qq{ Sets i-MSCP GUI permissions. diff --git a/configs/debian/apache/vlogger b/engine/bin/imscp-vlogger similarity index 53% rename from configs/debian/apache/vlogger rename to engine/bin/imscp-vlogger index 2571a0a896..0897d5ad03 100644 --- a/configs/debian/apache/vlogger +++ b/engine/bin/imscp-vlogger @@ -1,11 +1,11 @@ #!/usr/bin/perl -T # -# vlogger - smarter logging for apache +# imscp-vlogger - smarter logging for apache # Laurent Declercq # steve j. kondik # # This script will take piped logs in STDIN, break off the first component -# and log the line into the proper directory under $LOGDIR. it will roll the +# and log the line into the proper directory under $LOG_DIR. it will roll the # logs over at midnight on-the-fly and maintain a symlink to the most recent log. # # @@ -46,103 +46,88 @@ # - vlogger process not terminated (unpredictable context), leading to high CPU load $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin'; -my $VERSION = '1.11'; +my $VERSION = '1.12'; =head1 NAME -vlogger - flexible log rotation and usage tracking in perl +imscp-vlogger - flexible log rotation and usage tracking in perl =head1 SYNOPSIS -vlogger [OPTIONS]... [LOGDIR] +imscp-vlogger [OPTIONS]... [LOGDIR] =head1 DESCRIPTION -Vlogger is designed to make webserver log rotation simple and easy to manage. -It deals with VirtualHost logs automatically, so only one directive is required -to manage all hosts on a webserver. Vlogger takes piped output from Apache or -another webserver, splits off the first field, and writes the logs to logfiles -in subdirectories. It uses a filehandle cache to avoid resource limitations. -It will start a new logfile at the beginning of a new day, and optionally start -new files when a certain filesize is reached. It can maintain a symlink to -the most recent log for easy access. Optionally, host parsing can be disabled -for use in ErrorLog directives. + imscp-Vlogger is designed to make webserver log rotation simple and easy to manage. + It deals with VirtualHost logs automatically, so only one directive is required + to manage all hosts on a webserver. imscp-Vlogger takes piped output from Apache + or another webserver, splits off the first field, and writes the logs to logfiles + in subdirectories. It uses a filehandle cache to avoid resource limitations. + It will start a new logfile at the beginning of a new day, and optionally start + new files when a certain filesize is reached. It can maintain a symlink to + the most recent log for easy access. Optionally, host parsing can be disabled + for use in ErrorLog directives. -To use vlogger, you need to add a "%v" to the first part of your LogFormat: + To use imscp-vlogger, you need to add a "%v" to the first part of your LogFormat: -LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined + LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined -Then call it from a customlog: + Then call it from a customlog: -CustomLog "| /usr/local/sbin/vlogger -s access.log -u www-logs -g www-logs /var/log/apache" combined + CustomLog "| /imscp-vlogger -s access.log -u www-logs -g www-logs /var/log/apache" combined =head1 OPTIONS -Options are given in short format on the command line. + Options are given in short format on the command line. --a + -a Do not autoflush files. This may improve performance but may break logfile -analyzers that depend on full entries in the logs. + analyzers that depend on full entries in the logs. --e + -e ErrorLog mode. In this mode, the host parsing is disabled, and the file is -written out using the template under the specified LOGDIR. + written out using the template under the specified LOGDIR. --n + -n Disables rotation. This option disables rotation altogether. --f MAXFILES + -f MAXFILES Maximum number of filehandles to keep open. Defaults to 70. Setting this -value too high may result in the system running out of file descriptors. -Setting it too low may affect performance. + value too high may result in the system running out of file descriptors. + Setting it too low may affect performance. --u UID + -u UID Change user to UID when running as root. --g GID + -g GID Change group to GID when running as root. --t TEMPLATE + -t TEMPLATE Filename template using Date::Format codes. Default is "%m%d%Y-access.log", -or "%m%d%Y-error.log". When using the -r option, the default becomes -"%m%d%Y-%T-access.log" or "%m%d%Y-%T-error.log". + or "%m%d%Y-error.log". When using the -r option, the default becomes + "%m%d%Y-%T-access.log" or "%m%d%Y-%T-error.log". --s SYMLINK + -s SYMLINK Specifies the name of a symlink to the current file. --r SIZE + -r SIZE Rotate files when they reach SIZE. SIZE is given in bytes. --d CONFIG + -d CONFIG Use the DBI usage tracker. --i + -i Extract mod_logio instead of filesize. For this to work, you must add the -mod_logio variables at the end in your LogFormat: + mod_logio variables at the end in your LogFormat: LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combined --h + -h Displays help. --v + -v Prints version information. -=head1 DBI USAGE TRACKER - - vlogger can automatically keep track of per-virtualhost usage statistics in a -MySQL database. DBI and the relevant DBD::mysql needs to be installed for this to work. -Create a table in your database to hold the data. A "vlogger.sql" script is provided for -using this feature with MySQL. Configure the dsn, user, pass and dump values in the -vlogger-dbi.conf file. The "dump" parameter controls how often vlogger will dump its stats -into the database (the default is 60 seconds). Copy this file to somewhere convienient on -your filesystem ( like /etc/apache/vlogger-dbi.conf ) and start vlogger with -"-d /etc/apache/vlogger-dbi.conf". You might want to use this feature to easily bill -customers on a daily/weekly/monthly basis for bandwidth usage. - -This feature is safe. This mean that even if the MySQL connection fails for any reason, -vlogger will continue to do its main job. - =head1 AUTHORS Laurent Declercq @@ -163,13 +148,13 @@ use IO::Handle; # get command line options our %OPTS; -getopts('f:t:s:h?u:g:aeivr:d:n', \%OPTS); +getopts( 'f:t:s:h?u:g:aeivr:d:n', \%OPTS ); # print out version -if ($OPTS{'v'}) { +if ( $OPTS{'v'} ) { print <<"EOF"; -vlogger $VERSION (apache logfile parser) +imscp-vlogger $VERSION (apache logfile parser) Written by Steve J. Kondik Re-written by Laurent Declercq for i-MSCP project. @@ -181,56 +166,56 @@ EOF } # print help -if ($OPTS{'h'} || $OPTS{'?'} || !$ARGV[0]) { +if ( $OPTS{'h'} || $OPTS{'?'} || !$ARGV[0] ) { usage(); exit; } # log directory -my $LOGDIR; -if ($ARGV[0]) { - unless (-d $ARGV[0]) { - logs('fatal', sprintf('target directory does not exists', $ARGV[0])); +my $LOG_DIR; +if ( $ARGV[0] ) { + unless ( -d $ARGV[0] ) { + logs( 'fatal', sprintf( 'target directory does not exists', $ARGV[0] )); exit 1; } - $LOGDIR = $ARGV[0]; + $LOG_DIR = $ARGV[0]; } -$LOGDIR =~ /(.*)/; -$LOGDIR = $1; +$LOG_DIR =~ /(.*)/; +$LOG_DIR = $1; # change uid/gid if requested (and running as root) -if ($> == 0) { - if ($OPTS{'g'}) { - my $guid = getgrnam($OPTS{'g'}); +if ( $> == 0 ) { + if ( $OPTS{'g'} ) { + my $guid = getgrnam( $OPTS{'g'} ); - unless (defined $guid && $guid != 0) { - logs('fatal', 'cannot run as root or nonexistant group'); + unless ( defined $guid && $guid != 0 ) { + logs( 'fatal', 'cannot run as root or non-existent group' ); exit 1; } $) = $guid; $( = $guid; - if ($) != $guid and $) != ($guid - 2**32)) { - logs('fatal', sprintf("couldn't setgid to gid %s", $guid)); + if ( $) != $guid and $) != ( $guid-2 ** 32 ) ) { + logs( 'fatal', sprintf( "couldn't setgid to gid %s", $guid )); exit 1; } } - if ($OPTS{'u'}) { - my $uuid = getpwnam($OPTS{'u'}); + if ( $OPTS{'u'} ) { + my $uuid = getpwnam( $OPTS{'u'} ); - unless (defined $uuid && $uuid != 0) { - logs('fatal', "couldn't run as root or nonexistant user"); + unless ( defined $uuid && $uuid != 0 ) { + logs( 'fatal', "couldn't run as root or non-existent user" ); exit 1; } $> = $uuid; $< = $uuid; - if ($> != $uuid and $> != ($uuid - 2**32)) { - logs('fatal', sprintf("couldn't setuid to uid %s", $uuid)); + if ( $> != $uuid and $> != ( $uuid-2 ** 32 ) ) { + logs( 'fatal', sprintf( "couldn't setuid to uid %s", $uuid )); exit 1; } } @@ -241,99 +226,99 @@ my $DBI_DSN; my $DBI_USER; my $DBI_PASS; my $DBI_DUMP = 60; -if ($OPTS{'d'}) { - if ($OPTS{'e'}) { - logs('fatal', '-d option not valid with -e option'); +if ( $OPTS{'d'} ) { + if ( $OPTS{'e'} ) { + logs( 'fatal', '-d option not valid with -e option' ); exit 1; } eval 'use DBI'; - unless ($@) { - if(-f $OPTS{'d'}) { - if(open CONF, '<', $OPTS{'d'}) { - while () { + unless ( $@ ) { + if ( -f $OPTS{'d'} ) { + if ( open CONF, '<', $OPTS{'d'} ) { + while ( ) { next if /^(#|$)/; # Ignore comment and empty lines chomp; my @conf = split; next if scalar @conf < 2; - if ($conf[0] eq 'dsn') { + if ( $conf[0] eq 'dsn' ) { $DBI_DSN = $conf[1]; - } elsif ($conf[0] eq 'user') { + } elsif ( $conf[0] eq 'user' ) { $DBI_USER = $conf[1]; - } elsif ($conf[0] eq 'pass') { + } elsif ( $conf[0] eq 'pass' ) { $DBI_PASS = $conf[1]; - } elsif ($conf[0] eq 'dump' && $conf[1] =~ /^\d+$/) { + } elsif ( $conf[0] eq 'dump' && $conf[1] =~ /^\d+$/ ) { $DBI_DUMP = $conf[1]; } } close CONF; - unless ($DBI_DSN && $DBI_USER && $DBI_PASS) { - logs('alert', 'all values for DBI usage tracker configuration are not properly defined'); + unless ( $DBI_DSN && $DBI_USER && $DBI_PASS ) { + logs( 'alert', 'all values for DBI usage tracker configuration are not properly defined' ); delete $OPTS{'d'}; } else { # test DB connection - my $dbh = eval { DBI->connect($DBI_DSN, $DBI_USER, $DBI_PASS, { PrintError => 0, RaiseError => 1 }); }; - unless($@) { + my $dbh = eval { DBI->connect( $DBI_DSN, $DBI_USER, $DBI_PASS, { PrintError => 0, RaiseError => 1 } ); }; + unless ( $@ ) { # SIGALRM dumps the tracker hash - $SIG{ALRM} = \&dumpTracker; + $SIG{'ALRM'} = \&dumpTracker; alarm $DBI_DUMP; - logs('notice', sprintf('DBI usage tracker dump interval set to %d seconds', $DBI_DUMP)); + logs( 'notice', sprintf( 'DBI usage tracker dump interval set to %d seconds', $DBI_DUMP )); $dbh->disconnect() } else { - logs('alert', sprintf("couldn't connect to SQL server: %s", $@)); + logs( 'alert', sprintf( "couldn't connect to SQL server: %s", $@ )); delete $OPTS{'d'}; } undef $dbh; } } else { - logs('alert', sprintf("couldn't open %s file: %s", $OPTS{'d'}, $!)); + logs( 'alert', sprintf( "couldn't open %s file: %s", $OPTS{'d'}, $! )); delete $OPTS{'d'}; } } else { - logs('alert', sprintf('file %s not found', $OPTS{'d'})); + logs( 'alert', sprintf( 'file %s not found', $OPTS{'d'} )); delete $OPTS{'d'}; } } else { - logs('alert', sprintf("couldn't load DBI module: %s", $@)); + logs( 'alert', sprintf( "couldn't load DBI module: %s", $@ )); delete $OPTS{'d'}; } - logs('notice', 'DBI usage tracker feature turned off') unless $OPTS{'d'}; + logs( 'notice', 'DBI usage tracker feature turned off' ) unless $OPTS{'d'}; } # max files to keep open -my $MAXFILES; -if ($OPTS{'f'}) { - $MAXFILES = $OPTS{'f'}; +my $MAX_FILES; +if ( $OPTS{'f'} ) { + $MAX_FILES = $OPTS{'f'}; } else { - $MAXFILES = '100'; + $MAX_FILES = '100'; } # filesize rotation -my $MAXSIZE; -if ($OPTS{'r'}) { - $MAXSIZE = $OPTS{'r'}; +my $MAX_SIZE; +if ( $OPTS{'r'} ) { + $MAX_SIZE = $OPTS{'r'}; } # filename template my $TEMPLATE; -if ($OPTS{'t'}) { +if ( $OPTS{'t'} ) { $TEMPLATE = $OPTS{'t'}; $TEMPLATE =~ /(.*)/; $TEMPLATE = $1; -} elsif ($OPTS{'e'}) { - if ($OPTS{'r'}) { +} elsif ( $OPTS{'e'} ) { + if ( $OPTS{'r'} ) { $TEMPLATE = '%m%d%Y-%T-error.log'; } else { $TEMPLATE = '%m%d%Y-error.log'; } } else { - if ($OPTS{'r'}) { + if ( $OPTS{'r'} ) { $TEMPLATE = '%m%d%Y-%T-access.log'; } else { $TEMPLATE = '%m%d%Y-access.log'; @@ -341,90 +326,90 @@ if ($OPTS{'t'}) { } # symlink -if ($OPTS{'s'}) { +if ( $OPTS{'s'} ) { $OPTS{'s'} =~ /(.*)/; $OPTS{'s'} = $1; } -chdir($LOGDIR); +chdir( $LOG_DIR ); # Temporarely disabled. Once chroot() has been called, SQL server hostname # cannot longer be resolved, leading to `Unknown MySQL server host' error. # FIXME: Retrieve SQL server hostname and resolve it before the chroot() call, # then use the resulting IP for connection. -#chroot('.'); +#chroot('.'); my %logs = (); my %tracker = (); my $dumpMaxAttempts = 0; # pick a mode -if ($OPTS{'e'}) { +if ( $OPTS{'e'} ) { my $initLogTime = time(); $0 = 'vlogger (error log)'; - if(open ELOG, '>>' . time2str($TEMPLATE, $initLogTime)) { - ELOG->autoflush(1) unless $OPTS{'a'}; + if ( open ELOG, '>>' . time2str( $TEMPLATE, $initLogTime ) ) { + ELOG->autoflush( 1 ) unless $OPTS{'a'}; - if ($OPTS{'s'}) { - unlink($OPTS{'s'}) if -l $OPTS{'s'}; - symlink(time2str($TEMPLATE, $initLogTime), $OPTS{'s'}); + if ( $OPTS{'s'} ) { + unlink( $OPTS{'s'} ) if -l $OPTS{'s'}; + symlink( time2str( $TEMPLATE, $initLogTime ), $OPTS{'s'} ); } - my $LASTWRITE = $initLogTime; + my $LAST_WRITE = $initLogTime; - logs('notice', 'started ErrorLog Handler -- resuming normal operations'); + logs( 'notice', 'started ErrorLog Handler -- resuming normal operations' ); - while (my $logLine = ) { + while ( my $logLine = ) { my $logTime = time(); - unless ($OPTS{'n'}) { - if (time2str( '%Y%m%d', $logTime) > time2str('%Y%m%d', $LASTWRITE)) { + unless ( $OPTS{'n'} ) { + if ( time2str( '%Y%m%d', $logTime ) > time2str( '%Y%m%d', $LAST_WRITE ) ) { # open a new file close ELOG; - next unless openErrorLog($logTime); - } elsif ($OPTS{'r'}) { + next unless openErrorLog( $logTime ); + } elsif ( $OPTS{'r'} ) { # check the size my @filesize = ELOG->stat; print $filesize[7] . "\n"; - if ($filesize[7] > $MAXSIZE) { + if ( $filesize[7] > $MAX_SIZE ) { close ELOG; - next unless openErrorLog($logTime); + next unless openErrorLog( $logTime ); } } - $LASTWRITE = $logTime; + $LAST_WRITE = $logTime; } # we dont need to do any other parsing at all, so write the line. print ELOG $logLine; } } else { - logs('alert', sprintf("couldn't open %s/%s file", $LOGDIR, time2str($TEMPLATE, $initLogTime))); + logs( 'alert', sprintf( "couldn't open %s/%s file", $LOG_DIR, time2str( $TEMPLATE, $initLogTime ))); } } else { - $0 = 'vlogger (access log)'; - logs('notice', 'started CustomLog Handler -- resuming normal operations'); + $0 = 'imscp-vlogger (access log)'; + logs( 'notice', 'started CustomLog Handler -- resuming normal operations' ); - while () { + while ( ) { my @logLine = split /\s/; my $vhost = shift @logLine; - $vhost = lc($vhost) || 'default'; + $vhost = lc( $vhost ) || 'default'; $vhost = 'default' if $vhost =~ m%[/\\]%; $vhost =~ /(.*)/o; $vhost = $1; - my $reqSize = $OPTS{'i'} ? pop(@logLine) + pop(@logLine) : $logLine[9]; + my $reqSize = $OPTS{'i'} ? pop( @logLine )+pop( @logLine ) : $logLine[9]; - if (!$OPTS{'n'} && $logs{$vhost}) { + if ( !$OPTS{'n'} && $logs{$vhost} ) { my $logTime = time(); # if we're writing to a log, and it rolls to a new day, close all files. - if (time2str('%Y%m%d', $logTime) > time2str('%Y%m%d', $logs{$vhost})) { + if ( time2str( '%Y%m%d', $logTime ) > time2str( '%Y%m%d', $logs{$vhost} ) ) { close $_ for keys %logs; %logs = (); - } elsif ($OPTS{'r'}) { - if (($vhost->stat)[7] > $MAXSIZE) { + } elsif ( $OPTS{'r'} ) { + if ( ( $vhost->stat )[7] > $MAX_SIZE ) { close $vhost; delete $logs{$vhost}; } @@ -432,28 +417,28 @@ if ($OPTS{'e'}) { } # open a new log if needed - unless ($logs{$vhost}) { + unless ( $logs{$vhost} ) { my $logTime = time(); # check how many files we have open, close the oldest one - if (keys(%logs) > $MAXFILES) { - my ($key, $value) = sort { $logs{$a} <=> $logs{$b} } keys %logs; + if ( keys( %logs ) > $MAX_FILES ) { + my ( $key ) = sort { $logs{$a} <=> $logs{$b} } keys %logs; close $key; delete $logs{$key}; } - mkdir($vhost) unless -d $vhost; + mkdir( $vhost ) unless -d $vhost; - if(open $vhost, '>>', "$vhost/" . time2str($TEMPLATE, $logTime)) { - $vhost->autoflush(1) unless $OPTS{'a'}; + if ( open $vhost, '>>', "$vhost/" . time2str( $TEMPLATE, $logTime ) ) { + $vhost->autoflush( 1 ) unless $OPTS{'a'}; - if ($OPTS{'s'}) { - chdir($vhost); - unlink($OPTS{'s'}) if -l $OPTS{'s'}; - symlink(time2str($TEMPLATE, $logTime), $OPTS{'s'}); - chdir('..'); + if ( $OPTS{'s'} ) { + chdir( $vhost ); + unlink( $OPTS{'s'} ) if -l $OPTS{'s'}; + symlink( time2str( $TEMPLATE, $logTime ), $OPTS{'s'} ); + chdir( '..' ); } } else { - logs('alert', sprintf("couldn't open %s/%s/%s file", $LOGDIR, $vhost, time2str($TEMPLATE, $logTime))); + logs( 'alert', sprintf( "couldn't open %s/%s/%s file", $LOG_DIR, $vhost, time2str( $TEMPLATE, $logTime ))); } } @@ -465,12 +450,12 @@ if ($OPTS{'e'}) { sub logs { - print STDERR sprintf("[%s] [%s] vlogger: %s\n", scalar localtime, shift, shift); + print STDERR sprintf( "[%s] [%s] imscp-vlogger: %s\n", scalar localtime, shift, shift ); } sub closeFiles { - if ($OPTS{'e'}) { + if ( $OPTS{'e'} ) { close ELOG; return; } @@ -483,68 +468,68 @@ sub openErrorLog { my $logTime = shift; - unless(open ELOG, '>>', time2str($TEMPLATE, $logTime)) { - logs('alert', sprintf("couldn't open %s/%s file", $LOGDIR, time2str($TEMPLATE, $logTime))); + unless ( open ELOG, '>>', time2str( $TEMPLATE, $logTime ) ) { + logs( 'alert', sprintf( "couldn't open %s/%s file", $LOG_DIR, time2str( $TEMPLATE, $logTime ))); return; } - if ($OPTS{'s'}) { - unlink($OPTS{'s'}) if -l $OPTS{'s'}; - symlink(time2str($TEMPLATE, $logTime), $OPTS{'s'}); + if ( $OPTS{'s'} ) { + unlink( $OPTS{'s'} ) if -l $OPTS{'s'}; + symlink( time2str( $TEMPLATE, $logTime ), $OPTS{'s'} ); } - ELOG->autoflush(1) unless $OPTS{'a'}; + ELOG->autoflush( 1 ) unless $OPTS{'a'}; 1; } sub dumpTracker { - unless(keys(%tracker) > 0) { - alarm($DBI_DUMP); + unless ( keys( %tracker ) > 0 ) { + alarm( $DBI_DUMP ); return; } eval { - my $date = time2str('%Y%m%d', time()); - my $dbh = DBI->connect($DBI_DSN, $DBI_USER, $DBI_PASS, { PrintError => 0, RaiseError => 1 }); + my $date = time2str( '%Y%m%d', time()); + my $dbh = DBI->connect( $DBI_DSN, $DBI_USER, $DBI_PASS, { PrintError => 0, RaiseError => 1 } ); my $sth = $dbh->prepare( 'INSERT INTO httpd_vlogger (vhost, ldate, bytes) VALUE (?, ?, ?) ON DUPLICATE KEY UPDATE bytes = bytes + ?' ); - while(my($vhost, $bytes) = each(%tracker)) { + while ( my ( $vhost, $bytes ) = each( %tracker ) ) { next unless defined $vhost; - $sth->execute($vhost, $date, $bytes, $bytes); + $sth->execute( $vhost, $date, $bytes, $bytes ); } - + $dbh->disconnect(); %tracker = (); }; - unless($@) { + unless ( $@ ) { $dumpMaxAttempts = 0 if $dumpMaxAttempts; - alarm($DBI_DUMP); + alarm( $DBI_DUMP ); return; } - logs('alert', sprintf('error while DBI usage tracker dump: %s', $@)); + logs( 'alert', sprintf( 'error while DBI usage tracker dump: %s', $@ )); - if($dumpMaxAttempts < 3) { - logs('notice', 'a new DBI usage tracker dump attempt will be made in 2 minutes' ); - alarm(120); + if ( $dumpMaxAttempts < 3 ) { + logs( 'notice', 'a new DBI usage tracker dump attempt will be made in 2 minutes' ); + alarm( 120 ); return; } $dumpMaxAttempts++; %tracker = (); delete $OPTS{'d'}; - logs('notice', 'maximum number of dump attempts has been reached. DBI usage tracker feature turned off' ); + logs( 'notice', 'maximum number of dump attempts has been reached. DBI usage tracker feature turned off' ); } sub shutdown { - logs('notice', sprintf('caught %s, shutting down', shift)); + logs( 'notice', sprintf( 'caught %s, shutting down', shift )); closeFiles(); - dumpTracker() if($OPTS{'d'}); + dumpTracker() if $OPTS{'d'}; exit; } @@ -552,7 +537,7 @@ sub usage { print <<'EOF'; -Usage: vlogger [OPTIONS]... [LOGDIR] +Usage: imscp-vlogger [OPTIONS]... [LOGDIR] Handles a piped logfile from a webserver, splitting it into it's host components, and rotates the files daily. @@ -565,7 +550,7 @@ host components, and rotates the files daily. -t TEMPLATE Filename template (see perldoc Date::Format) -s SYMLINK Maintain a symlink to most recent file -r SIZE Rotate when file reaches SIZE - -d CONFIG Use DBI usage tracker (see perldoc vlogger) + -d CONFIG Use DBI usage tracker -i Extract mod_logio instead of filesize -h,? Display this help -v Output version information diff --git a/imscp-autoinstall b/imscp-autoinstall index 9c920abe54..fcef4325b9 100755 --- a/imscp-autoinstall +++ b/imscp-autoinstall @@ -65,7 +65,7 @@ $::buildonly = FALSE; $::forcereinstall = FALSE; $::skippackages = FALSE; -iMSCP::Getopt->parse( sprintf( 'Usage: perl %s [OPTION]...', basename( $0 )) . qq{ +iMSCP::Getopt->parse( sprintf( 'Usage: %s [OPTION]...', basename( $0 )) . qq{ -b, --build-only Process build steps only. -f, --force-reinstall Force re-installation of distro packages. -s, --skip-distro-packages Do not install/update distro packages.}, @@ -139,7 +139,7 @@ Please run the following commands from your console: # rm -fR $::imscpConfig{'ROOT_DIR'}/{daemon,engine,gui} # cp -fR $::{'INST_PREF'}/* / # rm -fR $::{'INST_PREF'} - # perl $::imscpConfig{'ROOT_DIR'}/engine/bin/imscp-reconfigure -d + # $::imscpConfig{'ROOT_DIR'}/engine/bin/imscp-reconfigure -d For any problem, have a look at https://i-mscp.net