What to do if site gets hacked on shared hosting (hostgator or UnIX)

For hostgator, immediately send email to security@hostgator.com

  1. If you have smaller site, they usually back it up. So talk to someone on chat and ask for a restore
  2. If no restore, then you should ask security to change all your FTP and mySQL user passwords to new one
  3. Find just files from 1 day ago and delete them using single command: find . -mtime -7  -exec rm -f {} \;
    http://www.unix.com/unix-dummies-questions-answers/50465-create-list-files-were-modified-after-given-date.html 
  4. OR Find both directories/files from 1 day ago and delete them: find . -mtime -7  -exec rm -rf {} \;
    http://www.cyberciti.biz/faq/linux-unix-how-to-find-and-remove-files/ 
  5. Make sure you protect your images directory from php scripts running inside. Put this in .htaccess file inside images directory.
    <Files ~ “(php\.ini|\.htaccess|\.php.?|\.pl|\.cgi)$”>
    order deny,allow
    deny from all
    </Files>
    http://forum.powweb.com/archive/index.php/t-62384.html
    http://mysql-apache-php.com/fileupload-security.htm 
  6. You can make it easier to copy the above htaccess file to all iamges directory using this command:
    find . -type d -name “images” -exec cp /.htaccess {} \;
  7. Modify all your directories back to safe permissions
    find -name “*.php” -type f -exec chmod 644 \{\} \;  //for php files
    find . -type d -exec chmod 755 \{\} \;  // for directories
    http://www.cyberciti.biz/faq/linux-list-just-directories-or-directory-names/ 
  8. Check for hidden directories
    find /path/to/dest/ -iname “.*” -type d 
  9. Disable dangerous PHP functions
    http://www.eukhost.com/forums/f42/disabling-dangerous-php-functions-6020/ 
  10. To find strings inside PHP files, do this: find . -iname ‘*php’ | xargs grep ‘string’ -sl
    http://www.netsupportchat.com/2010/10/find-in-files-for-unix-linux-freebsd-find-string-in-files/ 
  11. http://www.uno-code.com/?q=node/93 to fix PHP permissions
  12. You can replace files using find . -type d -name “maker.php” -exec cp newmaker.php  {} \;
  13. Find recently changed files with find . -mmin -1 (find files changed less than 1 minute ago) or find . -mtime +1 (find files more than 48 hours ago) or find . -mmin +5 -mmin -10 find files modified between 6 and 9 minutes ago

Easiest way to backup your mysql databases to Amazon S3

Do all databases at once.

Automatic MySQL Database Backups

 

To get started, create a folder db_backup. For this tutorial I’ve placed db_backupin my home folder. In db_backup create a directory named backups and a text file named backup.bin with the following code replacing the DB and S3 variables at the top with your own information

#!/bin/sh
 
DATE=`date +%y-%m-%d`#current date
DIR=`dirname "$0"`/ #current directory
 
#MySQL vars
DB_USER=root
DB_PASS=password
DB_HOST=localhost
 
#Backup directory vars
BACKUP_DIR=${DIR}backups/
 
#S3 vars
S3=0 #Set to 1 to back db up to S3
S3_KEY=Your S3 Key
S3_SEC_KEY=Your S3 Secret Key
S3_BUCKET=db_backups
 
#Get list of dbs
LIST=`mysql -u${DB_USER} -p${DB_PASS} -h${DB_HOST} INFORMATION_SCHEMA -e "SELECT SCHEMA_NAME FROM SCHEMATA WHERE SCHEMA_NAME !='information_schema';"`
 
#Loop through list ignoring result table name
for each in $LIST; do
 if [ "$each" != "SCHEMA_NAME" ]; then
 mysqldump -u${DB_USER} -p${DB_PASS} -h${DB_HOST} --opt --single-transaction $each > ${BACKUP_DIR}${DATE}_${each}.sql
 fi
done
 
#Zip and remove SQL dumps
zip -qj ${BACKUP_DIR}dbBackup_${DATE} ${BACKUP_DIR}${DATE}_*.sql
rm ${BACKUP_DIR}${DATE}_*.sql
 
#Back up to S3
if [ ${S3} != 0 ]; then
 php5 -f "${DIR}S3/backup.php" "${S3_KEY}" "${S3_SEC_KEY}" "${S3_BUCKET}" "${BACKUP_DIR}dbBackup_${DATE}.zip"
fi

We’ll be executing this script so we’ll need to set the backup.bin file to be executable and while we’re at it give the script a test run. If you wish to use S3 you’ll also need to add the S3 directory from the tutorial download below.

 

Useful jQuery reference for selectors

http://www.pamaya.com/jquery-selectors-and-attribute-selectors-reference-and-examples/

 

jQuery selectors and attribute selectors reference and examples

jQuery Selectors and Attribute Selectors
Selector Example Description
List accurate as of jQuery 1.3
* $(‘*’); This selector is a wild card method and will select all elements in a document.
#id $(‘#id’); This selector selects an element with the given ID.
.class $(‘.class’) The class selector will gather all elements in the document with the given class name
element $(‘element’) This selector will collect all elements in a document with the given tag name i.e. table, ul, li, a etc.
a, b, c. … n $(‘th, td, .class, #id’) This method can use multiple selection patterns to collect elements.
parent child $(‘li a’) This will select all “a” elements that are a descendant of “li”
a > b $(‘table > tr’); This will select all b elements which are a child element of a or in our example all tr elements in a table or tables.
a + b $(‘li + a’); This will select all “a” elements that are an immediate descendant of “li” in our example.
a ~ b $(‘p ~ ul’); This selector will select all “ul” elements that are a sibling of “p”
:first $(‘ul li:first’); Returns the first element in a result set
:first-child $(‘ul li:first-child’); Returns the first child element of the parent element.
:last $(‘ul li:last’); Returns the last element in a result set
:last-child $(‘ul li:last-child’); Returns the last child element of the parent element.
:o nly-child $(‘div p:only-child’); Returns elements which are the only child of the parent element.
:not(a) $(‘input:not(:checked)’); Returns all elements that are not “a” on in our example all input elements that are not checked
:has(a) $(‘div:has(p)’); Returns all elements with a descendant that matches a in out example a “div” that contains a “p”.
:o dd $(‘ul li:odd’); Returns all odd elements in a result set (zero based)
:even $(‘ul li:even’); Returns all even elements in a result set (zero based)
:eq(n) $(‘ul li:eq(n)’); Returns a numbered element identified by n (zero based)
:gt(n) $(‘ul li:gt(n)’); Returns all elements in a result set greater than n (zero based)
:lt(n) $(‘ul li:lt(n)’); Returns all elements in a result set less than n (zero based)
:nth-child(n) $(‘ul li:nth-child(n)’); Returns the nth child in a result set (one based)
:nth-child(odd) $(‘ul li:nth-child(odd)’); Returns all odd numbered elements in a result set (one based)
:nth-child(even) $(‘ul li:nth-child(even)’); Returns all even numbered elements in a result set (one based)
:nth-child(formula) $(‘ul li:nth-child(3n)’); Returns every nth child in a result set. In our example every third child (one based)
:header $(‘:header’); Returns all heading elements e.g. h1, h2, etc.
:animated $(‘ul:animated’); Returns elements with an animation currently in progress
:contains(text) $(‘:contains(hello)’); Returns all elements containing the passed string
:empty $(‘:empty’); Returns all elements that contain no child nodes
:parent $(‘li:parent’); Returns all elements that a parent nodes to any other DOM element including text nodes.
:hidden $(‘ul:hidden’); Returns all hidden elements that are hidden with CSS or input fields of the type “hidden”
:visible $(‘ul:visible’); Returns all visible elements
[attribute] $(‘[href]‘); Returns all elements that contain the passed attribute in our example any element with a “href” attribute
[attribute=value] $(‘[rel=external]‘); Returns all elements that the passed attribute value is equal to the passed value. In our example ant element with a “rel” attribute equal to “external”
[‘attribute!=value’] $(‘[rel!=external]‘); Returns all elements that the passed attribute value is not equal to the passed value. In our example ant element with a “rel” attribute that is not equal to “external”
[attribute!=value] $(‘[class^=open]‘); Returns all elements that the passed attribute value start with the passed value. In our example any element thats “class” attribute value begins with “open”
[attribute$=value] $(‘[id$=-wrapper]‘); Returns all elements that the passed attribute value ends with the passed value. In our example any element whos “id” ends with “-wrapper”
[attribute*=value] $(‘[class*=offer]‘); Returns all elements that the passed attribute value contains the passed value. In our example any element whos “class” contains the string “offer”
:input $(‘:input’); Returns only input elements of the tag name input, select, textarea and button
:text $(‘:text’); Returns only input elements of the type “text”
:password $(‘:password’); Returns only input elements of the type “password”
:radio $(‘:radio’); Returns only input elements of the type “radio”
:checkbox $(‘:checkbox’); Returns only input elements of the type “checkbox”
:submit $(‘:submit’); Returns only input elements of the type “submit”
:image $(‘:image’); Returns only input elements of the type “image”
:reset $(‘:reset’); Returns only input elements of the type “reset”
:file $(‘:file’); Returns only input elements of the type “file”
:button $(‘:button’); Returns only input elements of the type “button”
:enabled $(‘:enabled’); Returns all enabled input elements
:selected $(‘:selected’); Returns the selected element in a select list.
:disabled $(‘:disabled’); Returns disabled input elements
:checked $(‘:checked’); Returns checked input elements of the type radio or checkbox.

TinyMCE callback once loaded up

http://stackoverflow.com/questions/2581893/jquery-plugin-for-tinymce-callback

You can specify javascript once TinyMCE has finished loading up.

 

Is the oninit an option? Looking at the minified source, the oninit runs after the ajax call comeback and the init runs.

$('textarea.tinymce').tinymce({
    script_url : '../js/libraries/tiny_mce/tiny_mce.js',
    oninit: function() { alert("Loaded"); }
});

Getting Galleria jQuery photo gallery to work using AJAX

I put this as part of my AJAX response: Notice I had to put the sizes there during my AJAX.

 

<script>

$(document).ready(function() { 
$(‘#gallery’).galleria({
width: $imageFrame_width,
height: $imageFrame_height
});
});

</script>

 

 

Then in my JS file, I make sure to run this only ONCE:

Galleria.loadTheme(‘js/galleria/themes/classic/galleria.classic.min.js’);

That’s about it. 

 

AJAX indicator using jQuery

http://jquery-howto.blogspot.com/2009/04/display-loading-gif-image-while-loading.html

 

$("#btnLoad").click(function(){
    // Make AJAX call
    $("#content").load("http://example.com");
});

The above code loads contents from http://example.com into the <div id="content">. While the page is being loaded we want to display our animated GIF image in the “content”. So we could further improve our code like so:

$("#btnLoad").click(function(){

  // Put an animated GIF image insight of content
  $("#content").empty().html('<img src="loading.gif" />');

  // Make AJAX call
  $("#content").load("http://example.com");
});

Add or Install Facebook Comments on your website

http://developers.facebook.com/docs/reference/plugins/comments/

<div id=”fb-root”></div>
<script src=”http://connect.facebook.net/en_US/all.js#appId=<appID>&amp;xfbml=1″></script><fb:comments href=”http://www.fastmockup.com?uid=http://www.example.com/test/theh” num_posts=”20″ width=”500″></fb:comments>