System Administration

Quicktip: Read from stdin in PHP

0

Quicktip: Random string in unix

nas:~# echo `</dev/urandom tr -dc A-Za-z0-9 | head -c8`
8vxeuIfi
0

Backing Up XenServer VMs via Command Line

Quick and easy steps to backup a vm via the command line.

On your host server:

[root@xenhost ~]# xe vm-list
-- Note your vm's uuid here (you can use tab completion to autofill in the uuid so no need to copy entirely) --
[root@xenhost ~]# xe vm-shutdown uuid=x
[root@xenhost ~]# xe vm-export uuid=x filename=/backup/vmfile.xva

It’s that simple.

0

Automating MySQL Database Backups on the Command Line via mysqldump

Are you tired of manually running backups when you remember to?

If you are running your own server, or have access to the shell and cron jobs this tip is for you!

First off for a better understanding of mysqldump check out the MySQL reference manual. All mysqldump really does is output the necessary queries to rebuild your database to the current state it is at when run.

First I’m going to create a test database and some tables as examples:

Read more

2

Apache: How to redirect all root domain traffic to www subdomain

Problem: Traffic comes to http://aknosis.com/something/ but they really need to go to http://www.aknosis.com/something/.

Solution: 301 Redirect via Apache with mod_rewrite.

Simple easy addition to your httpd.conf or .htaccess, I placed mine right above my wordpress mod_rewrite rules. If you are using .htaccess just dump it in that file above the wordpress redirect, if you having your rewrite rules in your httpd.conf then it needs to go inside the container:

<Directory /www/mydir/>
        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^www\.aknosis\.com$ [NC]
        RewriteRule ^(.*)$ http://www.aknosis.com/$1 [R=301,L]
#Wordpress Here
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
</Directory>

Breakdown:

RewriteCond %{HTTP_HOST} !^www\.aknosis\.com$ [NC]
If the HTTP_HOST header doesn't equal www.aknosis.com then :
RewriteRule ^(.*)$ http://www.aknosis.com/$1 [R=301,L]
Use the rewrite rule to push the request to http://www.aknosis.com/
^ - Beginning of request uri
() - Means group this into $1
$ - End of request uri
http://www.aknosis.com/$1 - Rewrite to this ($1 = the request uri)
[R=301 - Use a 301 Redirect
,L] - Make this the final rewrite rule and go

Try it out, go here (http://aknosis.com/) and you end up here (http://www.aknosis.com/). You can see the actual redirect in firebug’s net tab:

firebug-redirect

0

Hiding Unnecessary Response Headers Apache/PHP

One way to help protect your website/server is to not tell everyone what platform and app versions everything is running on. If you were to request a php file from my site you see some response headers that could be useful to people looking to break in, cause havoc etc…

Here is my request to aknosis.com (I’m viewing all of this in Firebug, if you don’t have it get it, best web development tool in my arsenal)

Date Wed, 14 Oct 2009 05:59:59 GMT
Server Apache/2.2.3 (CentOS) PHP/5.2.9 mod_ssl/2.2.3 OpenSSL/0.9.8b
X-Powered-By PHP/5.2.9
X-Pingback http://www.aknosis.com/akwp/xmlrpc.php
Expires Wed, 11 Jan 1984 05:00:00 GMT
Last-Modified Wed, 14 Oct 2009 06:00:00 GMT
Cache-Control no-cache, must-revalidate, max-age=0
Pragma no-cache
Vary Accept-Encoding,User-Agent
Content-Encoding gzip
Content-Length 10636
Keep-Alive timeout=2, max=100
Connection Keep-Alive
Content-Type text/html; charset=UTF-8

So if I was running a known insecure version of php, apache, or any other out of date software exposed in the response headers, an attacker has to look no further to determine what you are using and how best to attack you.

Apache

Read more

1

Quick Tip: Managing Linux Processes

Quick tip on managing linux processes, I always end up asking myself this and having to research how to do such things. So here are some quick tips to help you manage your linux processes. This is all done in bash, I’m not sure what is different with the other shells so ymmv.

Here is my sample script, just something that doesn’t end right away so I can use it for proof of concept:

#!/bin/bash
while [ 1 ]
do
        date
        echo "Sleeping 5 seconds"
        sleep 5
done

Sending a process to the background

Read more

0