Your Ad Here

Wednesday, August 20, 2014

A Simple Way to Protect Images from ‘Casual Copying’

If you don’t want other people to download images from your website, don’t put them online because – the way the web works – it is almost impossible to prevent someone from copying or saving your images.


However there’s one little trick that may discourage the less-technical people from casually copying, or even hot-linking, to your web images. To give you an example, try saving the following image to your computer using the standard “save as” option.
The “save picture” option under right-click is still available for the above image but instead of downloading the actual photograph, all it would save is a blank image. Also, the URL for the image (under Properties) would appear as some junk characters (it’s called a data URI) and thus would deter the non-techies from hotlinking to that image.
Here’s how you may implement something similar for your own images:
The standard embed code for an image looks something like this:
<img src="photograph.jpg" width="500" height="250">
What you need to do is change the value of the src attribute to point to a blank image and then add a new style attribute to render the actual image. Also make sure that the value of the height and the width parameters are exactly the same as the actual image.
<img style="background-image:url(photograph.jpg);" 
     src="data:image/gif;base64,
     R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
     width="500" height="250">
This is like overlaying a completely transparent screen over your photograph and anyone trying to save the image will end up downloading that screen instead of the image.

Obviously, there are simple workarounds to get around the above method. For instance, a copy of the full image will still be available in your browser’s cache. You may look at the HTML source or may even save the image using screen capture but again, these techniques may not always be known to the non-technical users of your website.

Host your Podcasts on Google Drive for Free

If you are looking to publish your own audio or video podcasts, you’ll need space on a public web server to host the MP3 or MP4 files of your podcast. When a user subscribes to your podcast feed in iTunes, or another podcatcher app, the podcast files will be downloaded from this server to the user’s computer (or mobile phone).


Where do you host the podcast files? If you have signed up for a web hosting account, you can use the rented space to host the podcast files else you may consider using Google Drive – it is free, you can host both audio and video podcast files and there are no known bandwidth restrictions.
Host Podcast on Google Drive

Free Podcast Hosting on Google Drive

Here’s how you can use your Google Drive to host your podcast in two minutes.
We will first create a Podcast folder in Google Drive to store the podcast files and then make this folder public so anyone can download the episodes stored in this Google Drive folder. Any video file that you upload to this folder in Drive will have a public URL that you can use in your Podcast XML feed.
  1. Click here and authorize the script to access to your Google Drive. The script will create a new public folder in your Google Drive for hosting the files.
  2. Go to drive.google.com in your desktop browser and upload one or more podcast files in the new Podcasts folder that you created in Step #1.
  3. Once the files have been uploaded, open that folder link in your browser (see example) and you should see a list of all the uploaded podcast files.
  4. Right-click any podcast file (see the above screenshot) to copy the file’s URL which you can then paste in your podcast RSS feed – see example).
The podcasts will be served from googledrive.com.

Other than the actual podcast episodes, you may also upload art work, logos and other image files that may be required for submitting your Podcast into the iTunes store.

Embed Images from Google Maps In Emails & Blogs Without Using Screen Capture Software



It is now possible to embed live images of Google Maps in emails and other websites (like MySpace, Facebook or WordPress.com) that do not allow JavaScript.

Earlier you had to take a screenshot of the Google Maps and save that as an image file but that’s no longer necessary as this Static Maps Wizard will let you create a still but dynamic image of any location on Google Maps.
For instance, the map of Hyderabad above is not a screenshot but a live image served from Google Maps using this URL.

You can place the Google Maps image in any web page using the standard <img> tag. For embedding maps in web emails (like Gmail), simply compose a new message and drag the Google Map on to the email body. Thanks Tom Manshreck.

Tuesday, August 19, 2014

scp command line to securely copy files over ssh, between Linux, Mac or Windows

SCP Introduction

scp stands for secure cp (copy), which means you can copy files across ssh connection. That connection will be securely encrypted, it is a very secure way to copy files between computers
You can use scp to copy files from or to a remote server. You can also copy files from one remote server to another remote server, without passing traffic through your PC.
You can use scp on Linux, Mac and Windows (using WinSCP).

SCP Usage

scp [[user@]from-host:]source-file [[user@]to-host:][destination-file]
from-host
Is the name or IP of the host where the source file is, this can be omitted if the from-host is the host where you are actually issuing the command
user
Is the user which have the right to access the file and directory, that is supposed to be copied in the case of the from-host, and the user who has the rights to write in the to-host
source-file
Is the file or files that are going to be copied to the destination host, it can be a directory but in that case you need to specify the -r option to copy the contents of the directory
destination-file
Is the name that the copied file is going to take in the to-host, if none is given all copied files are going to keep its names

SCP Options

-p
Preserves the modification and access times, as well as the permissions of the source-file in the destination-file
-q
Do not display the progress bar
-r
Recursive, so it copies the contents of the source-file (directory in this case) recursively
-v
Displays debugging messages

SCP Examples

scp *.txt user@remote.server.com:/home/user/
That is going to copy all files with .txt extension to the folder /home/user in the remote.server.com host
scp -r miguel@10.1.2.2:/home/miguel/ miguel@10.1.2.3:/home/miguel/
That is going to recursively copy all files from Miguel’s home directory on 10.1.2.2 to his home folder in 10.1.2.3 host.
As have been told before, scp copies files between computers using ssh, and there are three types of usage:
Copy files from a local computer to a remote computer
scp somefile username@server:/home/username/
Copy files from a remote server to your local computer
scp username@server:/home/username/file_name /home/local-username/file-name
Copy files from a remote server to another remote computer
This is really interesting and very useful, as the files copied from one server to the other, are not going to pass through your computer. The traffic is going to pass from one server to the other directly.
scp user_name1@server1:/home/user_name1/file_name user_name2@server2:/home/user_name2/

SCP Tricks

Bandwidth limit
You may limit the bandwidth used by scp command
scp -l limit username@server:/home/uername/* .
Where limit is specified in Kbit/s.
Increase scp speed
scp uses AES-128 to encrypt data, this is very secure, but also a litle bit slow. If you need more speed and still have security, you can use Blowfish or RC4.
To increase scp speed change chipher from the default AES-128 to Blowfish
scp -c blowfish user@server:/home/user/file .
Or use RC4 which seems to be the fastest
scp -c arcfour user@server:/home/user/file .
This last one is not very secure, and it may not be used if security is really an issue for you. You can also increase security while decreasing speed. Everything has its cost.
scp -c 3des user@server:/home/user/file .
That is maybe the slowest, but also maybe the more secure one (I may be wrong, I’m not an expert in encryption).

Final notes

It is very important to consider that scp encrypts the data before sending it over the internet. So, if you can use it over ftp or rcp, you better use it.

Finally, as I said before, you can use WinSCP to copy to and from Windows to Linux or Mac. For the Mac OS X scp is supported by default, just like with Linux.

Export and import MySQL databases through command line

command line

This method works for all database sizes, including very large ones.

You must be able to log into your server with SSH.

 Export

  1. Log into your server via SSH.
  2. Use the command cd to navigate to a directory where your user has write access. Example:
    cd /var/www/vhosts/example.com/httpdocs
  3. Export the database by executing the following command:
    mysqldump --add-drop-table -u admin -p`cat /etc/psa/.psa.shadow` dbname > dbname.sql
    Once you execute this command, you will be prompted for your database password. Type in the password and hit enter. Your database will now start exporting. When it is done, you will see the command prompt again. If it is a large database, this may take a few minutes.
    NOTE:
    The following variables need to be replaced with your own information:
    • -u admin specifies the database username.
      • Username is "admin" and the password is a hashed version of your Plesk admin password.
    • dbname is the name of the database you are trying to export.
    • dbname.sql is the name you want to give your backup file, and can be whatever you want.
    • Omit the --add-drop-table argument if you plan to merge this backup with an existing database when you import it. This option means the backup will totally replace the old database when it is imported.
  4. You can now download the resulting SQL file. Connect to your server with FTP, navigate to the directory where you created the dump file, and download it.
  5. Remove the SQL file from your web-accessible directory, if you created it in a public folder. Otherwise, anyone can download it from the web.

 Import

  1. Use FTP to upload your SQL file to your server. You can upload it to your default FTP directory. See Step 1 in the "Export" instructions above for another suggestion. Alternately, you can use scp to upload your file via SSH.
  2. Log into your server via SSH.
  3. Use the command cd to navigate into the directory where you uploaded your backup file in Step 1. If you uploaded the backup into your public htttpdocs directory, go here:
    cd /var/www/vhosts/example.com/httpdocs/
  4. Import the database by executing the following command:
    mysql -u admin -p`cat /etc/psa/.psa.shadow` dbname < dbname.sql
    OR:
    mysql -u admin -p`cat /etc/psa/.psa.shadow` dbname -e 'source dbname.sql'
    Once you execute this command, you will be prompted for your database password. Type it in and hit enter. Your database will now import. It may take a few minutes if you have a large database. When the import is done, you will be returned to the command prompt.
     
    NOTE:
    • Variables are the same as in Step 3 from the Export section above. Please check Step 3 in the "Export" section to make sure you are correctly replacing the example code with your own information.
    • dbname.sql is the actual name of your SQL file.
    • If you have a gzipped backup of your database, you can use this line instead:
    gunzip < dbname.gz | mysql -u admin -p`cat /etc/psa/.psa.shadow` dbname
    You can enter in your own username, database name, and backup file name, as before. dbname.gz is the name of your gzipped backup file. Use "unzip" instead of "gunzip" for zipped files.
  5. Remove the SQL file from your web-accessible directory, if you uploaded it to a public folder. Otherwise, anyone can download it from the web.
If you get an error that looks like this:
Got Error: 1045: Access denied for user 'admin@example.com' (using password: YES) when trying to connect
You have entered an incorrect password. Please retype it carefully, or reset your password in the AccountCenter. See How can I change my Plesk admin password? for instructions.
If you get an SQL error during the import, you can force it to finish by adding "-f" to the command, which stands for "force." For example:
mysql -f -u admin -p`cat /etc/psa/.psa.shadow` dbname < dbname.sql
This can help you finish an import if you have a few corrupt tables, but need to get the database as a whole imported before you do anything else.   
   

Monday, August 18, 2014

Solving reindex issues with Product Flat Data in Magento

Check your exception.log file And find :

1
2
3
4
5
6
7
Product Flat Data index process unknown error:
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`DATABASE_NAME`.<result 2 when explaining filename '#sql-1803_1aa01'>, CONSTRAINT `FK_CAT_PRD_FLAT_2_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` ()' in /app/magento_oneline/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /app/magento_oneline/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /app/magento_oneline/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /app/magento_oneline/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /app/magento_oneline/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)


That error for 

The key is here:
?
1
FK_CAT_PRD_FLAT_2_ENTT_ID_CAT_PRD_ENTT_ENTT_ID
That is telling you which table is failing. This exception tells that the referential integrity between: catalog_product_flat_2.entity_id and catalog_product_entity.entity_id is corrupted. This usually means some record(s) contain(s) null in the field catalog_product_entity.entity_id, where they are expected to contain existing entity_ids.

Fixing this

In order to fix this issue, you need to find what the corrupted entries are. This is easy. In this case, you’ll need to create a query to get the empty registers:
?
1
SELECT a.entity_id FROM catalog_product_flat_2 AS a LEFT JOIN catalog_product_entity AS b ON a.entity_id = b.entity_id WHERE ISNULL(b.entity_id);
This will display the corrupted entities. You only need to delete them and that’s all.
?
1
2
3
4
5
6
7
+-----------+
| entity_id |
+-----------+
|     35427 |
|     35428 |
+-----------+
2 rows in set (0.04 sec)
As example:
?
1
DELETE FROM catalog_product_flat_2 where entity_id = '35427';