Friday 23 August 2013

MSSQL Last Resort Recovery Method

After attempting every type of restore / backup of a handful of MSSQL databases from a failed server I came upon a couple of commands that managed to bring the database back to life.

**WARNING**
This method can result in data loss especially if the database died while being written too.... obviously the more transactions you have going through the database the greater the chance of data loss. This method is the absolute last method you should try.

Here is the command to attempt data recovery and bring the database up in single user mode.

Use master
go
sp_configure 'allow updates', 1
reconfigure with override
go
sp_dboption 'DATABASENAME', 'single_user', 'true'
go
alter database DATABASENAME set EMERGENCY
go
DBCC CHECKDB('DATABASENAME', REPAIR_ALLOW_DATA_LOSS)
Go
 
 
Once this is complete you can view tables and data to check what is recovered. (NOTE - This can take a very long time to complete on large databases)
 
When you are happy to bring the database back online you just need to use this command
 
Use master
go
sp_dboption 'DATABASENAME', 'single_user', 'false'
go
 
 
 

iCloud Beta

Woo Hoo! Just got the iCloud Numbers & Pages Beta, Thank you Apple. :-) #icloud

Thursday 22 August 2013

How to enable Gzip compression in IIS6.0 for ASP.NET 2.0 websites.


Introduction


This step by step guide will show you how to enable Gzip compression to work with ASP.NET 2.0. Compressing the output should make your websites faster, especially when being viewed via a slow connection.

Step 1: Enable Compression Using the IIS Manager


Expand IIS Manager. Right click on Websites. Click Properties. Click the Service tab. Check the boxes to enable compression.
 
Step 2: Install IIS 6.0 Resource Kit Tools

You can download the free tool from Microsoft here.

Step 3: Edit IIS Meta Database


Open the IIS Metabase Explorer. It is part of the resource kit you just installed. Expand LM>W3SVC>Filters>Compression. You will need to edit bothgzip and deflate. Find the item with the name HcScriptFileExtensions. Add the values aspx, axd, asmx, and css. Repeat process for gzip anddeflate. Find HcDynamicCompressionLevel and set it to something higher than 0.
 
 
Step 4: Do IISReset

That's it. To verify that you have everything working correctly, you can use the free tool YSlow for Fire Bug.

Thanks Cloudflare

Thanks for the stickers Cloudflare. Keep up the great work with your amazing services. :-)

Useful IP Tables commands


Blocking IP’s using IP Tables

iptables -I INPUT -s xxx.xxx.xxx.xxx -j DROP
 
 

OR just for port 80

Iptables –A INPUT –src xxx.xxx.xxx.xxx –p tcp --dport 80 –j REJECT
 
 

Block PING

iptables -A INPUT -p icmp -m state --state NEW -j DROP



Port Redirection
This is useful if you need to access email on a different port due to ISP restrictions.
 

# Allow incoming port 587 (tcp) SMTP traffic, and redirect it to port 25

/sbin/iptables -A INPUT -p tcp --dport 587 -j ACCEPT

/sbin/iptables -A PREROUTING -t nat -p tcp --dport 587 -j REDIRECT --to-port 25

View connections to Linux server by IP


This command will output the list of unique IP's currently connected to your Linux server. This is really helpful in identifying someone who is trying to DDoS your server.
 
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Showing currently running mysql queries


Login to mysql (mysql -uroot -p)

show full processlist;

Create a mysql database & user


mysql -u root -p

##create the database

create database DATABASENAME;

##create the user and password

grant all privileges on DATABASENAME.* to 'USERNAME'@'localhost' IDENTIFIED BY 'PASSWORD' with grant option;

#grant access for that user to their database

grant all privileges on DATABASENAME.* to 'USERNAME'@'%';

Restoring a backup with SSH


mysql -uUSERNAME -p DBNAME < /PATH/TO/DUMP.SQL

USERNAME - this username which you use to access MySQL.

DBNAME - the name of the database used for MyBB.

/PATH/TO/DUMP.SQL - this is the path to the backup file that you have on the server. You will have to upload it to the server since you used phpMyAdmin to back it up.

Backing up your database using SSH


Not all hosting accounts have this, you'll have to ask your host if you have SSH access.

1. Log into your SSH account.

2. Type mysqldump --opt -Q -uUSERNAME -p DATABASENAME > /PATH/TO/DUMP.SQL

USERNAME  this is the username you use to access MySQL. You can find it out by looking in inc/config.php

DATABASENAME  the name of the database that MyBB is installed on.

/PATH/TO/DUMP.SQL  this is the path to the file that will be stored. If you don't know where to put it, use mybb_backup.sql or something like that.

Install DDoS-Deflate


DDoS-Deflate


DDoS-Deflate is a couple of bash scripts, that is run every X minutes, analyze the total number of connections to your server from every IP address using netstats command and temporarily blacklist IPs, that have more than Y active connections to your server at the moment, script runs. Blacklisting is done using either iptables or APF whichever you have installed. Simple!

Installation


To install ddos protection scripts just execute the following commands from console:

cd /usr/local

mkdir mytmp

wget http://www.inetbase.com/scripts/ddos/install.sh

chmod 0700 install.sh

./install.sh

That’s all…

Configuration


To configure DDOS-Deflate (that’s the name of this script) do the following:

cd /usr/local/ddos

edit ddos.conf

Last line opens ddos.conf file in editor. You can use vi if you like. I chose edit because I am a Windows user and Edit has an interface familiar to me.

Let’s consider all available settings one by one:

PROGDIR="/usr/local/ddos"

PROG="/usr/local/ddos/ddos.sh"

IGNORE_IP_LIST="/usr/local/ddos/ignore.ip.list"

CRON="/etc/cron.d/ddos.cron"

APF="/etc/apf/apf"

IPT="/sbin/iptables"

These above are about various software locations. I recommend you leave them as is. They should suite the majority of systems. BTW, if your system doesn’t have APF, it is ok. Script can work with iptables also.

FREQ=1

This setting affects how often (in minutes) you need to execute ddos protection script. After changing this param, please execute command

ddos –cron

to update cron sheduler.

NO_OF_CONNECTIONS=150

This is the maximum number of connections acceptable for your server. I recommend to set this value to about 20-40 depending on your server.

BTW, don’t repeat my mistake  Should you decide to use softwares, that open really many connections to your server, like FileZilla FTP client (it spawns many FTP connections to upload your folder ASAP), you will get blocked

APF_BAN=1

If you have AFP, then set this to 1. If you have not, script will use iptables. To check if you have AFP or not, just execute command

afp

If you want to use IPTables, don’t forget to start service by

service iptables start

and to have it autoloading at system startup by\

chkconfig iptables on

KILL=1

If you just testing your script, set this to 0. In this case, IPs will not get banned.

EMAIL_TO="root"

This email address will have messages about blacklisted IPs. Leave it to root to skip emailing.

BAN_PERIOD=600

Set this to a number of seconds, for how long to block entruder. I recommend to set this to 1800-3600 (30-60 minutes).

You can also add IPs to /usr/local/ddos/ignore.ip.list to whitelist them.

Uninstallation


You can always uninstall DDoS-Deflate by executing

cd /usr/local/mytmp

wget http://www.inetbase.com/scripts/ddos/uninstall.ddos

chmod 0700 uninstall.ddos

./uninstall.ddos

That’s all!

Adding a Pinterest button to Prestashop Version 1.5.4

If you want to add a pinterest button to your products page so your visitors can add it to a collection then you just need to add this piece of code to the page.

You need to add this to your themes product.tpl file where you want the button to show.

Here is the code you need. (Don't forget to have this on 1 single line)


<a href="http://pinterest.com/pin/create/button/?url={$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}&media={$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')}&description={$product->name|escape:'htmlall':'UTF-8'}" class="pin-it-button" count-layout="horizontal">Pin It</a><script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>

Wednesday 21 August 2013

Woo Hoo

Finally decided to put some of my old stored useful data online and decided that blogger would be the best place to share it.