Archive for the ‘LAMP’ Category

Rename file extention in Linux

Saturday, July 12th, 2008

This script is useful when dealing with a large volume of filename extensions. This script renames all files in a directory and its subdirectories with an ‘extension’ of sorts with the description of the file type. Other search techniques and batch renamers can then look after restoring these to common three letter extensions.

ren.sh

t="/tmp/ren"
find -type f > "$t"
while read record[n]
do
mv "${record[n]}" "${record[n]}.$(file -b "${record[n]}")"
let "n+=1"
done < "$t"
rm "$t"

then, for example, to correctly name all JPG files run (the complete list of files is too large to embed every option), where "JPG" begins the description and "jpg" is the new extension:

find -name "*.JPG" -print0 | xargs -0 rename .JPG .jpg

How to gernerate a CSR for Apache 2.x

Monday, June 9th, 2008

Follow the below instructions to generate a CSR for your Web site. When you have completed generating your CSR, cut/copy and paste it into the CSR field on the SSL certificate-request page.

CSR-Generation Instructions
To generate a triple-DES encrypted key pair and a Certificate Signing Request (CSR):

Enter the following commands:

  1. cd /usr/bin/ (/your path to openssl/)
    Enter a passphrase when prompted to.
  2. openssl genrsa -des3 -out <name of your certificate>.key 1024
  3. openssl req -new -key <name of your certificate>.key -out <name of your certificate>.csr

Please enter the information as prompted. If you are requesting a Wildcard certificate, please add an asterisk (*) on the left side of the Common Name (e.g., "*.domainnamegoes.com" or "www*.domainnamegoeshere.com"). This will secure all subdomains of the Common Name.

Now you should have:
domain.com.key and domain.com.csr

Make a backup copy of your private key! If you lose it, you have to purchase a new cert!

You should NOT generate the RSA private key with a passphrase if you have scripts that restart apache automatically. If you have, then apache just sit there and wait for the script to input the passphrase! 

There is a method that you can disable the passphrase to prompt when you restart apache.

# mv MYdomain.com.key MYdomain.com.key.has-passphrase
# openssl rsa -in MYdomain.com.key.has-passphrase -out MYdomain.com.key

And then restart apache.

To ensure your SSL works, you should have something like this in your httpd.conf

<VirtualHost 123.456.789.123:443>
… some config like DocumentRoot , etc..
SSLEngine  on
SSLCertificateFile /etc/httpd/conf/ssl.crt/MYdomain.com.crt
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/MYdomain.com.key
</VirtualHost>

 

Unix FTP Command Reference

Thursday, September 20th, 2007

Common FTP Commands 

? to request help or information about the FTP commands
ascii to set the mode of file transfer to ASCII
(this is the default and transmits seven bits per character)
binary to set the mode of file transfer to binary
(the binary mode transmits all eight bits per byte and thus provides less chance of a transmission error and must be used to transmit files other than ASCII files)
bye to exit the FTP environment (same as quit)
cd to change directory on the remote machine
close to terminate a connection with another computer
  close brubeck closes the current FTP connection with brubeck,
  but still leaves you within the FTP environment.
delete to delete (remove) a file in the current remote directory (same as rm in UNIX)
get to copy one file from the remote machine to the local machine
  get ABC DEF copies file ABC in the current remote directory to (or on top of) a file named DEF in your current local directory.
  get ABC copies file ABC in the current remote directory to (or on top of) a file with the same name, ABC, in your current local directory.
help to request a list of all available FTP commands
lcd to change directory on your local machine (same as UNIX cd)
ls to list the names of the files in the current remote directory
mkdir to make a new directory within the current remote directory
mget to copy multiple files from the remote machine to the local machine;
  you are prompted for a y/n answer before transferring each file
  mget * copies all the files in the current remote directory to your current local directory, using the same filenames. Notice the use of the wild card character, *.
mput to copy multiple files from the local machine to the remote machine;
  you are prompted for a y/n answer before transferring each file
open to open a connection with another computer
  open brubeck opens a new FTP connection with brubeck;
  you must enter a username and password for a brubeck account
      (unless it is to be an anonymous connection).
put to copy one file from the local machine to the remote machine
pwd to find out the pathname of the current directory on the remote machine
quit to exit the FTP environment (same as bye)
rmdir to to remove (delete) a directory in the current remote directory

.htaccess Tutorial - Customized Error Message

Wednesday, August 8th, 2007

If you want to customize the error message to a vistor for a page was not found on your server, you can do it by adding following page to the .htaccess file.

ErrorDocument 404 /index.php

this line will redirect visitors to the /index.php on your server.

.htaccess Tutorial - Protect Images

Wednesday, August 8th, 2007

To prevent people from linking to the images on your server that abusing your bandwidth, you can use the mod_rewrite module to filter the unauthorized requests.

1. Activate Protection

Add the following lines to your .htaccess file to stop people from hotlinking to your .gif and .jpg files.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?your_domain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
 

Replace your_domain.com with your domain name.

This starts by turning on the rewrite engine. Next, it checks the referer (where the request comes from).

If it did not come from your domain name and it is a request for a .gif or .jpg file, it will output an error message. Otherwise it will display the image as usual.

You can apply this with other file extension.

.htaccess Tutorial - Directory Listing

Wednesday, August 8th, 2007

When a web browser is pointed to a directory on your web site which does not have an index.html file in it, the files in that directory can be listed on a web page.

1. Enable/Disable Directory Listing

To have the web server produce a list of files for such directories, use this line,

Options +Indexes  

To have an error (403) returned instead, use this line.

Options -Indexes 
 

2. Listing Style

You can list file in  basic list style or fancy list style. A ‘fancy’ list including icons, file size, modification date and more. Following line is used for ‘fancy’ list style in the .htaccess file,

IndexOptions +FancyIndexing  

Use following line if you prefer a basic file list.

IndexOptions -FancyIndexing  

3. Ignore Files

If you don’t want the web server to list files with exention such as *.txt,*.jpg. Add this line to your .htaccess,

IndexIgnore *.txt *.jpg  

4. Modify Index File

To change the default index file, use this line

DirectoryIndex home.html