Create a file at /etc/httpd/conf.d/deflate.conf with the following contents:
SetOutputFilter DEFLATE
# Don't compress picture files
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \ no-gzip dont-vary
# Don't compress compressed files
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary
# Don't compress pdf's
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
A "here document" is a method for specifying a multi-line string literal in many programming languages. Here are some examples:
Perl
print <<"END";
MULTIPLE LINES OF TEXT HERE
END
PHP
echo <<<EOF
MULTIPLE LINES OF TEXT HERE
EOF;Bash
cat << EOF
MULTIPLE LINES OF TEXT HERE
EOFEvery time I need a PHP class to handle sending email I turn to Swift Mailer at:
It's feature rich and easy to use.
Only downside is it doesn't work for PHP4.
To view trusted networks as the zimbra user:
/opt/zimbra/bin/zmprov gs {servername} zimbraMtaMyNetworks
To set trusted networks as the zimbra user do:
/opt/zimbra/bin/zmprov ms {servername} zimbraMtaMyNetworks {space delimited list of address and/or cidr ranges}
If the traditional "pecl install APC" style command is not working for some reason, here is the manual procedure:
wget http://pecl.php.net/get/APC-3.0.19.tgz
tar -xvzf APC-3.0.19.tgz
cd APC-3.0.19
phpize
./configure
make
make install
With procmail, vacation and forward files do not work if the user's home directory is group writable. Here's a script that will locate all group writable home directories:
#!/usr/bin/perl
my %users;
open(P,"/etc/passwd");
while() {
chomp();
my ($uname,$pass,$uid,$gid,$gecos,$home,$shell) = split(/\:/,$_);
$users{$uname} = $home;
};
close P;
LINE: foreach $user (sort keys %users) {
$home = $users{$user};
next LINE if ($user eq "dbus");
next LINE if ($user eq "distcache");
next LINE if ($user eq "haldaemon");
next LINE if ($user eq "nobody");
next LINE if ($user eq "rpc");
$test = `find $home -maxdepth 0 -perm -g=w -type d 2>&1`;
chomp($test);
if ($test ne "") {
if ($test =~ /No such file or directory/) {
$msg = "NOT FOUND";
} else {
print $user . " : " . $home . "\n";
};
};
};
Here's a patched source RPM for the vsftpd package included with RHEL5. It fixes this bug:
https://bugzilla.redhat.com/show_bug.cgi?id=486524
The bug limits user names to 32 characters. The patch raises the limit to 128 characters.
To build and install do:
rpm -i vsftpd-2.0.5-12longuser.src.rpm
rpmbuild -ba /usr/src/redhat/SPECS/vsftpd.spec
rpm -U /usr/src/redhat/SPECS/{ARCH}/vsftpd-2.0.5-12longuser.src.rpm
You can download the patched source file here:
http://blogs.reliablepenguin.com/files/vsftpd-2.0.5-12longuser.src.rpm
First get the yum-utils package if you don't already have it:
yum install yum-utils
Next just do:
yumdownloader --source mypkg
where mypkg is the package that you want source for.
Here's an alpha sort of the values of the associative array named "myarray":
foreach my $key (sort {$myarray{$a} cmp $myarray{$b}} keys %myarray) {
print "$key : " . $myarray{$key} . "\n";
};
And here's the same sort numerically:
foreach my $key (sort {$myarray{$a} <=> $myarray{$b}} keys %myarray) {
print "$key : " . $myarray{$key} . "\n";
};
And if you want numeric descending:
foreach my $key (sort {$myarray{$b} <=> $myarray{$a}} keys %myarray) {
print "$key : " . $myarray{$key} . "\n";
};
When using SMTP AUTH, the username and password are base64 encoded. Here's a snip of perl that will encode a string:
perl -MMIME::Base64 -e 'print encode_base64("username");'
This will produce something like this:
dXNlcm5hbWU=
And here's the decode:
perl -MMIME::Base64 -e 'print encode_base64("dXNlcm5hbWU=");'
which of course yields:
username
Came across a handy configuration setting for mysql:
expire_logs_days = 7
Controls how many days of binary log files should be retained. Very good way to keep the binary logs from over flowing available storage.
This Unison program is great. It neatly handles syncing between two servers where changes are occurring on both sides. On one client site it takes about 30 seconds to compare/sync a 23GB /var/www/html/ structure with about 100 sites.
1) Install unison (http://www.cis.upenn.edu/~bcpierce/unison/). Requires "ocaml" compiler (http://caml.inria.fr/), and needs the "etags" command from emacs (so "yum install emacs", whatever)
2) Set up a "/root/.unison/profile-name.prf" file. See example pasted below. Comment out "batch=true" and "silent=true" for initial test runs. Uncomment them for running from a cron job.
3) Run manually to test: unison profile-name
4) If you leave the logging turned on, make an /etc/logrotate.d/unison file, something like this:
/var/log/unison.log {
notifempty
daily
rotate 7
missingok
compress
}
5) Set up cron job(s). Create multiple profiles if specific paths need more frequent syncing. With silent=true, the jobs should produce no output (silent=true automatically sets batch=true).
Sample profile (/root/.unison/profile-name.prf)
# Reasonable defaults
auto=true
confirmbigdeletes=true
contactquietly=true
fastcheck=true
group=true
maxthreads=20
numericids=true
owner=true
times=true
# Dump an archive listing to ~/unison.dump
#dumparchives=true
# Skip confirmation
batch=true
# Suppress output (sets batch=true)
silent=true
# Run in a loop, repeating every X seconds (sort of daemon mode)
#repeat=60
# Log all sync operations
log=true
logfile=/var/log/unison.log
# Backup deleted files
backup=Name *
backuplocation=central
backupdir=/var/www/unison-backups
# Local root
root=/var/www/html/
# Remote root (the double forward-slash between IP and remote path is correct)
root=ssh://1.2.3.4//var/www/html/
# Resolve conflicts in favor of local root
prefer=/var/www/html/
# Limit to specific relative path (can specify multiple path= params)
#path=somepath/
# Don't sync (can specify multiple ignore lines)
ignore=Path */var/cache
Edit the file at:
/opt/zimbra/libexec/zmdisklog
Look for these lines:
my $DISK_CRIT_THRESHOLD = 90;
my $DISK_WARN_THRESHOLD = 80;
Change them as desired to give different warning/critical levels.
In one case that we worked on, the server had multiple partitions. We wanted different thresholds on each partition which was accomplished with the following patch:
--- zmdisklog.orig 2009-03-08 15:10:26.000000000 -0400
+++ zmdisklog 2009-03-08 15:13:21.000000000 -0400
@@ -77,8 +77,12 @@
my (undef, $total, $used, $avail) = split(/\s+/, $df[0]);
my $pct=int(($used/$total)*100) if ($total > 0);
my $lvl = "info";
+if ($dev eq "/dev/sdb1") {
+ $lvl = "err" if ($pct > 95);
+} else {
$lvl = "err" if ($pct > $DISK_WARN_THRESHOLD);
$lvl = "crit" if ($pct > $DISK_CRIT_THRESHOLD);
+};
if ($lvl eq "info") {
Zimbra::Mon::Logger::Log( "$lvl", "$dt, DISK: ${hostname}: dev: $dev, mp: $mp, tot: $total, avail: $avail" );
} else {
To cleanly handle double bounces:
1. Create a dot-qmail file at /var/qmail/mailnames/yourdomain.com/.qmail-doublebounce containing:
|exit 0
2. Route double bounces to this file:
echo yourdomain.com > /var/qmail/control/doublebouncehost
echo doublebounce > /var/qmail/control/doublebounceto
On a server, if outgoing email is being blocked by spam filters, I can sometimes get around the problem by using an IPTables rule to force the email out through a different IP address like this:
/sbin/iptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source w.x.y.x
I'm a big fan of the "replace" utility included in the mysql client package. With this utility you can search/replace a string of text across multiple files like this:
replace 'from-string' 'to-string' -- start-folder/*.pl
Quick and easy!
But on occasion I'm on a system that doesn't have the mysql client package so here's a similar function using find and sed:
find start-folder/ -name '*.pl' -exec sed -iorig 's/from-string/to-string/' {} \;
To export the mailbox for user@acme.com as a zip file use this command:
/opt/zimbra/bin/zmmailbox -z -m user@acme.com getRestURL \
'//?fmt=zip&query=is:anywhere' > user_at_acme_com.zip
Here is the same as a tgz file:
/opt/zimbra/bin/zmmailbox -z -m user@domain.com getRestURL \
“//?fmt=tgz” > /tmp/account.tgz
And here's a restore of the tgz file:
/opt/zimbra/bin/zmmailbox -z -m user@domain.com postRestURL \
“//?fmt=tgz&resolve=reset” /tmp/account.tgz
To numerically sort @myarray by the second column do this:
@myarray = sort { $a->[1] <=> $b->[1] } @myarray;
Here is an alpha sort of @myarray on the third column:
@myarray = sort { $a->[2] cmp $b->[2] } @myarray;
Here's a simple script that will provide a report on mailbox size for every mailbox on a Zimbra server. The report is sorted by box size in descending order:
#!/usr/bin/perl
my $all_accounts=`zmprov gaa`;
my @accounts = split(/\n/,$all_accounts);
my @sizes;
foreach $account (@accounts) {
my $mb_size=`zmmailbox -z -m $account gms`;
chomp($mb_size);
my $size;
if ($mb_size =~ /(.+)\ GB/) {
$size = $1 * 1024 * 1024;
} elsif ($mb_size =~ /(.+)\ MB/) {
$size = $1 * 1024;
} elsif ($mb_size =~ /(.+)\ KB/) {
$size = $1;
} elsif ($mb_size =~ /(.+)\ B/) {
$nsize = $1;
if ($nsize eq 0) {
$size = 0;
} else {
$size = abs(1024/$1);
};
};
$next = scalar(@sizes);
$sizes[$next][0] = $account;
$sizes[$next][1] = $size;
};
@sizes = sort { $a->[1] <=> $b->[1] } @sizes;
my $D=`date +'%m/%d/%y %H:%M'`; chomp($D);
print "==========================================================\n";
print " Zimbra Mailbox Report\n";
print " \n";
print " All sizes in KB.";
print " Generated on: $D\n";
print "==========================================================\n";
for (my $i = $#sizes-1; $i >= 0; $i--) {
printf ("%15.2f %s\n",$sizes[$i][1], $sizes[$i][0]);
};