Archive for July, 2012

Installing DenyHosts

Compiling and installing DenyHosts from source code on Centos 6.

[root@new denyhosts]# mkdir -p /root/Downloads/denyhosts
[root@new denyhosts]# cd $_
[root@new denyhosts]# wget http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fdenyhosts%2Ffiles%2Fdenyhosts%2F&ts=1343373868&use_mirror=freefr
[root@new denyhosts]# tar xzf DenyHosts-2.6.tar.gz
[root@new denyhosts]# cd DenyHosts-2.6
[root@new denyhosts]# python setup.py install
[root@new denyhosts]# cd /usr/share/denyhosts/
[root@new denyhosts]# cp -a denyhosts.cfg-dist denyhosts.cfg
[root@new denyhosts]# vi denyhosts.cfg
[root@new denyhosts]# cp -a daemon-control-dist daemon-control
[root@new denyhosts]# chmod 700 daemon-control*
[root@new denyhosts]# cd /etc/init.d
[root@new denyhosts]# ln -a /usr/share/denyhosts/daemon-control denyhosts
[root@new denyhosts]# dir
[root@new denyhosts]# service denyhosts
[root@new denyhosts]# service denyhosts start
[root@new denyhosts]# chkconfig denyhosts on
[root@new denyhosts]# tail -a /etc/hosts.deny
[root@new denyhosts]# vi /etc/hosts.deny
[root@new denyhosts]# tail -a /etc/hosts.deny
[root@new denyhosts]# vi /etc/hosts.deny
[root@new denyhosts]# vi /etc/denyhosts.conf ; service denyhosts restart
[root@new denyhosts]# cd /usr/share/denyhosts/
[root@new denyhosts]# dir
[root@new denyhosts]# ln -a /usr/share/denyhosts/denyhosts.cfg /etc/denyhosts.conf
[root@new denyhosts]# vi /etc/denyhosts.conf ; service denyhosts restart

http://www.linuxvadapav.com/security/how-to-install-denyhosts-on-centos-5-x-ubuntu-rhel-fedora.html

Javascript get GET variables from URL

function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}

Usage

Example URL: http://www.example.com/index.php?id=1&image=awesome.jpg

Calling getQueryVariable(“id”) – would return “1”.
Calling getQueryVariable(“image”) – would return “awesome.jpg”.

Backup database and rsync to offsite server

This is the current bash script for exporting the databases from each web server and sending them to the backup server.

#!/bin/bash
# db.sh
# Backup of database to offsite server
# Jason Bickley, Web Manager EWEA
# 9 JULY 2013

#==== RECEIVE VARIABLES FROM COMMAND LINE ====#
FREQ=$1
SERVER=$2

#==== SCRIPT OPTIONS ====#
USER=backup
PASS="mwbubCEsxCU6XVsW"
DIR=/root/backup/mysql/
FILE=localhost.sql.gz
DEST=backup.ewea.org
DATE=$(date +"%Y%m%d %T")
LOG=/var/log/backupDB_log

#==== EXCUTION OF COMMANDS ====#
# Change operating directory
cd $DIR

#==== Export database ====#
mysqldump -u$USER -p$PASS --all-databases --lock-all-tables | gzip > $SERVER.$FREQ.$FILE
chmod 600 $SERVER.$FREQ.$FILE

#==== rsync the export to offsite server ====#
rsync -aze "ssh -p 10022 -i /root/.ssh/"$SERVER"_prv_key" $SERVER.$FREQ.$FILE root@$DEST:/backups/$FREQ/$SERVER/db/

#==== delete the exported file ====#
rm -f $SERVER.$FREQ.$FILE

#==== Confirm success in log file ====#
echo $DATE Backup successful! $DEST:/backups/$FREQ/$SERVER/db/$SERVER.$FREQ.$FILE >> $LOG

To use it, you just have to run: db.sh {freq} {servername} {option}

cd /root/Scripts/backup/
./db.sh daily main

Changing a WordPress password with PhpMyAdmin

Stolen from http://codex.wordpress.org/Resetting_Your_Password

This article is for those who have phpMyAdmin access to their database. Note: use phpMyAdmin at your own risk. If you doubt your ability to use it, seek further advice. WordPress is not responsible for loss of data.

Begin by logging into phpMyAdmin and click databases.

Image #2

  • A list of databases will appear. Click your WordPress database.

Image #3

  • All the tables in your database will appear. If not, click Structure.
  • Look for wp_users.
  • Click on the icon for browse.
  • Locate your Username under user_login
  • Click edit

Image #4

  • Your user_id will be shown, click on Edit
  • Next to the user_pass is a long list of numbers and letters.
  • Select and delete these and type in your new password.
  • Type in the password you want to use. Just type it in normally, but remember, it is case-sensitive.
  • In this example, the new password will be ‘rabbitseatcarrots’
  • Once you have done that, click the dropdown menu indicated, and select MD5 from the menu.

Image #5

  • Check that your password is actually correct, and that MD5 is in the box.
  • Click the ‘Go’ button to the bottom right.
  • Test the new password on the login screen. If it doesn’t work, check that you’ve followed these instructions exactly.