if [ ! "`iptables-save | grep 'dport 21'`" ]; then iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT;fiProbably not the most elegant solution, but it works.
if [ ! "`iptables-save | grep 'dport 22'`" ]; then iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT;fi
if [ ! "`iptables-save | grep 'dport 80'`" ]; then iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT;fi
service iptables save
Saturday, April 6, 2013
Quickly add rules to IPTABLES on CentOS/RHEL 5.x using a script
Older iptables lack the -C switch so you have to use bash to check whether a rule already exists before appending it. Works like this:
Quickly disable SELinux in a setup script
So we all know how to disable SELinux manually, but what about doing so as part of a setup script?
Easy, got to love sed!
Easy, got to love sed!
Setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/sysconfig/selinux && cat /etc/sysconfig/selinux
Repeat on /etc/selinux/config for Centos 7
Wednesday, February 20, 2013
Key exchange for passwordless rsync, scp, ssh...
There are so many answers out there but this is probably the best one I've seen:
http://troy.jdmz.net/rsync
http://troy.jdmz.net/rsync
Wednesday, February 6, 2013
phpMyAdmin - Error
Don't you just love them errors? They make you stress your mind, check everything all over again, force to communicate with people around you and basically waste your time.
One such lovely error is:
One such lovely error is:
Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.There are quite a few answers online for fixing this problem but sometimes, especially if there's a chance you did something silly along the way, it just won't help. So, yet another solution if everything else fails:
# chmod 0777 /var/lib/php/session
Monday, February 4, 2013
Apache cluster active server
So you have Apache running in a cluster and you want to know which server is active right now. PHP can help you there.
Put this line of code in whoami.php
Put this line of code in whoami.php
<?php system('hostname', $retval); ?>
Wednesday, January 16, 2013
Exiftool, quick and easy for RHEL/CentOS 5.x
Almost the latest version as of now, the one most 'production ready'.
Be root, cut and paste into your terminal and voila!
Be root, cut and paste into your terminal and voila!
mkdir extra_packages
cd extra_packages/
wget http://owl.phy.queensu.ca/~phil/exiftool/Image-ExifTool-9.04.tar.gz
tar xvzf Image-ExifTool-9.04.tar.gz
cd Image-ExifTool-9.04
perl Makefile.PL
make
make test
make install
Tuesday, January 15, 2013
Wordpress & Varnish
Basic configuration, tiny bit of security and avoiding error 405 on post. This server runs other things as well, so configurations are not as aggressive as they might be in other places.
backend default {
.host = "127.0.0.1";
.port = "8080";
}
acl purge {
"localhost";
}
sub vcl_recv {
/* Before anything else we need to fix gzip compression */
if (req.http.Accept-Encoding) {
if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|mp4)$") {
# No point in compressing these
remove req.http.Accept-Encoding;
} else if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
# unknown algorithm
remove req.http.Accept-Encoding;
}
}
# Login, administration and posting comments are to be completely and utterly left alone, no caching, no nothing.
if (req.http.host == "my.blog.com") {
if (req.url ~ "wp-(login|admin|comments-post)") {
set req.backend = default;
return(pipe);
}
# Drop any cookies sent to Wordpress.
unset req.http.cookie;
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
}
set req.backend = default;
return (lookup);
}
if (req.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|txt|gz|zip|rar|bz2|tgz|tbz|html|htm|pdf|mp4)$") {
unset req.http.cookie;
set req.grace = 5m;
return(lookup);
}
return(pass);
}
sub vcl_fetch {
if (beresp.status == 302) {
set beresp.http.X-Magic-Redirect = "1";
return(deliver);
}
if (req.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|txt|gz|zip|rar|bz2|tgz|tbz|html|htm|pdf|mp4)$") {
unset beresp.http.set-cookie;
}
set beresp.do_stream = true;
if (req.http.Authorization) {
return (hit_for_pass);
}
}
sub vcl_hit {
if (obj.http.X-Magic-Redirect == "1") {
set req.url = obj.http.Location;
return (restart);
}
if (req.request == "PURGE") {
set obj.ttl = 0s;
error 200 "Purged.";
}
}
sub vcl_deliver {
if (resp.http.X-Magic-Redirect == "1") {
unset resp.http.X-Magic-Redirect;
return(restart);
}
return(deliver);
}
Subscribe to:
Posts (Atom)