Using blackbox to change multiple dns records for account

browse to https://clouddns.dcx.rackspace.com/zones/search

Enter the account number and click Exact Search

copy the lines from the console to a file called domainlist.txt

domainlist.txt===================

1 View accidentlawyerny.net
2 View acnestories.com
3 View acnewonders.com
4 View aromatherapyrecipe.com
5 View attorneyny.us
6 View attorneynyc.org
7 View bankruptcylawyerny.org
8 View bbbeauty.com

end domainlist.txt===============

browse to https://clouddns.dcx.rackspace.com/scripts/new

click the command you wish to run to get the exact command

for instance edit mx records uses ‘edit_mx_record zone fqdn priority mail_server’

Change the values by running the following command:

perl -pi -e ‘s/^[0-9]+\s+View\s+(.*?)$/edit_mx_record $1 $1 10 mx1.emailsrvr.com/’ domainlist.txt

This will result in a file with the commands to copy into https://clouddns.dcx.rackspace.com/scripts/new. Change the DDI and hit execute, and you should be golden.

Posted in Linux | Comments Off on Using blackbox to change multiple dns records for account

Make fail2ban send emails

Edit /etc/fail2ban/jail.conf as follows:

action = %(action_)s

gets changed to

action = %(action_mw)s

which causes fail2ban to execute an action shortcut that sends mail:

#########section of jail.conf############################################
# Action shortcuts. To be used to define action parameter

# The simplest action to take: ban only
action_ = %(banaction)s[name=%(__name__)s, port=”%(port)s”, protocol=”%(protocol)s”, chain=”%(chain)s”]

# ban & send an e-mail with whois report to the destemail.
action_mw = %(banaction)s[name=%(__name__)s, port=”%(port)s”, protocol=”%(protocol)s”, chain=”%(chain)s”]
%(mta)s-whois[name=%(__name__)s, dest=”%(destemail)s”, protocol=”%(protocol)s”, chain=”%(chain)s”]

# ban & send an e-mail with whois report and relevant log lines
# to the destemail.
action_mwl = %(banaction)s[name=%(__name__)s, port=”%(port)s”, protocol=”%(protocol)s”, chain=”%(chain)s”]
%(mta)s-whois-lines[name=%(__name__)s, dest=”%(destemail)s”, logpath=%(logpath)s, chain=”%(chain)s”]

# Choose default action. To change, just override value of ‘action’ with the
# interpolation to the chosen action shortcut (e.g. action_mw, action_mwl, etc) in jail.local
# globally (section [DEFAULT]) or per specific section
action = %(action_)s

Posted in Linux | Comments Off on Make fail2ban send emails

Changing munin password

To change the serverinfo password for munin,

htpasswd /etc/munin/munin-htpasswd serverinfo

To test, go to http://IP/munin

Posted in Linux | Comments Off on Changing munin password

Adding usb device to qemu in kvm

HOWTO: Use USB devices in Virtual Machine Manager with QEMU

Posted in Linux | Comments Off on Adding usb device to qemu in kvm

Deny POST to a site in .htaccess

 <limit POST OPTIONS>
  Order deny,allow
  Deny from all
 </limit>
Posted in Linux | Comments Off on Deny POST to a site in .htaccess

Useful find Commands

The find command is very verstile, and I use it all the time. Here are the parameters that I use most often:
-name <string> Finds files in specified directory whose name matches (case-sensitive) string
-iname <string> Finds files in specified directory whose name matches (case-insensitive) string
-exec Executes a command on the files found (see ls -l example below)
-perm <mode> Finds files in specified directory that match the permission mode
-size Finds files in specified directory
-print Finds the files and prints out the filename. This is useful in a find . -exec grep
-regex<pattern> Finds files in specified directory with name that matches regular expression pattern.
-atime <+-><n> Finds files in specified directory that were accessed less than, more than, or exactly n minutes ago
-amin <+-><n> Finds files in the specified directory that were accessed less than, more than, or exactly n minutes ago
-mmin <+-><n> Finds files in specified directory that were last modified less than, more than, or exactly n minutes ago
-mtime <+-><n> Finds files in specified directory that were last modified less than, more than, or exactly n*24 hours ago
-type <filetype> Find files in the specified directory of type:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option
or the -follow option is in effect, unless the
symbolic link is broken. If you want to search for
symbolic links when -L is in effect, use -xtype.
s socket

Examples:
Find files in current directory that end in .txt:
find . -name "*.txt"

Find files in current directory that were created within the last hour:
find . -ctime -60

Find files in current directory not owned by root:
find . \! -user root -print

Find files in current directory with 0777 permissions and chmod them to 644:
find . -type f -perm 0777 -print -exec chmod 644 {} \;

Find files in current directory with owner apache and change to www-data:
find . -user apache -exec chown www-data {} \;

Find all files in current directory that contain string and output their names:
find . -exec grep string {} \; -print

Find files in the current directory with ACLs set:
find . -type f -exec ls -l {} \; | grep -v "\+"

Find files older than 7 days matching string “vicki_test2 and move to new directory
mkdir -p /var/mitto/data/vicki_dir && find /var/mitto/data/ -regextype posix-extended -regex '^.*vicki_test2.*\.[^.]+$' -mtime +7 -exec mv {} /var/mitto/data/vicki_dir \;


Posted in Linux | Comments Off on Useful find Commands

Method to keep private libraries private

One method I have seen programmers (including myself) use to keep folks out of private libraries / include modules is to put a check in there.

Easiest example:

in index.php (or any script with permission to be called directly), this line, immediately after the “

Posted in Linux | Comments Off on Method to keep private libraries private

Recovering Corrupted InnoDB Table

Corrupted MySQL database:

If you suspect data corruption in a MySQL database,

First make a copy of the database for safe keeping:

mysqldump –user=root post_planner > /tmp/post_plannerdb.sql

Prove it:

To prove that the database is corrupted, do:

mysql> check database

Find the table:

To detemine which table has corruption, do this for each table that you suspect:

mysql> check table post_planner.posted;
+—————————-+—————-+
| Table | Op | Msg_type | Msg_text |
+—————————-+—————-+
| post_planner.posted | check | Error | Can’t open table |
| post_planner.posted | check | error | Corrupt |
+—————————-+—————-+
2 rows in set (0.01 sec)

Once you know that the table is corrupt, you need to recover it. This is easy in MyISAM tables with the CHECK TABLEand REPAIR TABLE, but that doesn’t work with InnoDB. InnoDB tables can be checked with CHECK TABLE, but not repaired with REPAIR TABLE.

Copying over the good data to a new databases:

Here is what I did to fix it:

I created a second table called posted2 like this:

create table posted2 like posted;

SO that gets you the structure. Now lets see what we can do about getting the data:

mysql> insert ignore into posted2 select * from posted limit 1000000;
Query OK, 1000000 rows affected (0.00 sec)
Records: 1000000 Duplicates: 0 Warnings: 0

Keep increasing the limit until you see that the number of Records is fewer than the number you requested. At this point, do the following:

select max(id) from posted2;

This will give you how many records were successfully imported before it encountered corruption. Then you increment through with a the rest of the data using the first record that is not corrupted. You might have to try skipping one by selecting all records that are greater than the last known good record +1. It that fails, skip two on the next attempt. The command to skip the records basically looks like this:

mysql> insert ignore into posted2 select * from posted where ID>1000001;
Query OK, 9999999 rows affected (0.00 sec)

If you encounter more corruption, lather, rinse, repeat

Posted in Linux | Comments Off on Recovering Corrupted InnoDB Table

Restricting sshd by username

Step # 1: Open sshd_config file

# vi /etc/ssh/sshd_config

Step # 2: Specify a user

Only allow user king to login by adding following line:
AllowUsers king

Step # 3: Restart sshd

Save and close the file. In the above example, user vivek has already been created on the system. Now just restart sshd:
# service sshd restart

Posted in Linux | Comments Off on Restricting sshd by username

Changing the MySQL timezone via PHP

If you don’t have root access in your mysql instance and want to change the time_zone, you’ll have to change it in the code:

To have the time zone setup as you would like, you would you need to execute the following command each time you make a connection:
SET time_zone=’-3:00′

Here is an example of how to achieve that in PHP:

$offset = ‘-3:00’
$db = new \PDO(‘mysql:host=localhost;dbname=test’, ‘dbuser’, ‘dbpassword’);
$db->exec(“SET time_zone=’$offset’;”);

To verify:

mysql> select now()

Posted in Linux | Comments Off on Changing the MySQL timezone via PHP