h4x3d.com

- h4x3d.com

Archive
code

Here is a simple cheatsheet for the .htaccess file:

Enable Directory Browsing

Options +Indexes
## block a few types of files from showing
IndexIgnore *.wmv *.mp4 *.aviDisable Directory Browsing

Options All -IndexesCustomize Error Messages

ErrorDocument 403 /forbidden.html
ErrorDocument 404 /notfound.html
ErrorDocument 500 /servererror.htmlGet SSI working with HTML/SHTML

AddType text/html .html
AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml
# AddHandler server-parsed .htmChange Default Page (order is followed!)

DirectoryIndex myhome.htm index.htm index.php Block Users from accessing the site
order deny,allow
deny from 202.54.122.33
deny from 8.70.44.53
deny from .spammers.com
allow from all Allow only LAN usersorder deny,allow
deny from all
allow from 192.168.0.0/24Redirect Visitors to New Page/Directory

Redirect oldpage.html
Redirect /olddir site from specific referrers

RewriteEngine on
RewriteCond %{HTTP_REFERER} site-to-block\.com [NC]
RewriteCond %{HTTP_REFERER} site-to-block-2\.com [NC]
RewriteRule .* – [F]Block Hot Linking/Bandwidth hogging

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ – [F]Want to show a ?Stealing is Bad? message too?

Add this below the Hot Link Blocking code:

RewriteRule \.(gif|jpg)$ [R,L]Stop .htaccess (or any other file) from being viewed

order allow,deny
deny from all
Avoid the 500 Error

# Avoid 500 error by passing charset
AddDefaultCharset utf-8Grant CGI Access in a directory

Options +ExecCGI
AddHandler cgi-script cgi pl
# To enable all scripts in a directory use the following
# SetHandler cgi-scriptSave Bandwidth

# Only if you use PHP

php_value zlib.output_compression 16386
Password Protecting Directories

Use the .htaccess Password Generator and follow the brief instructions!

The CheckSpelling Directive

From Jens Meiert: CheckSpelling corrects simple spelling errors (for example, if someone forgets a letter or if any character is just wrong). Just add CheckSpelling On to your htaccess file.

The ContentDigest Directive

As the Apache core features documentation says: ?This directive enables the generation of Content-MD5 headers as defined in RFC1864 respectively RFC2068. The Content-MD5 header provides an end-to-end message integrity check (MIC) of the entity-body. A proxy or client may check this header for detecting accidental modification of the entity-body in transit.

Note that this can cause performance problems on your server since the message digest is computed on every request (the values are not cached). Content-MD5 is only sent for documents served by the core, and not by any module. For example, SSI documents, output from CGI scripts, and byte range responses do not have this header.?

To turn this on, just add Content Digest On.

Source: the net / google

Read More

Listing Directory Contents

To list all directories and files within a current directory, type:

ls

To list a detailed list of all directories and files sorted by creation date, type:

ls -lrt

Locations of Files and Directories

To work with a file or directory, it is important to tell Linux where to find it. There are several ways to tell Linux where to look:

./ = the current directory
../ = the parent directory of ./ (one directory up)
/ = the root directory (top directory)

When no location is specified, Linux assumes we mean “./”. So we can copy “fileX” from the current directory to its parent directory using either:
cp /whole/path/from/root/directory/fileX ../

or:
cp ./fileX ../

or:
cp fileX ../

Viewing Files

There are many ways to view a text file. For viewing and editing, see the section below on text editors. One way for simple viewing is to type:

less

This displays as much of the file as can fit onto the screen. To scroll up and down within the document, use the arrow keys. Hitting the space bar will bring a new screen-full of information.

To search forward in the file for a given pattern, press:

/pattern

To exit less, press:

q

Creating and Editing Files

There are several text editors that create plain text files. We have emacs and vi available from the terminals. Unless you are already familiar with vi, we strongly recommend that you use emacs. We strongly recommend you study the emacs tutorial, which you can easily start in any emacs session. To open and edit a file in emacs, simply type

emacs myfile

To create and edit a new file, type

emacs newfile

To edit a file in emacs and still be able to use the command prompt, type

emacs myfile &

If you forgot to type the “&” and you want to return to the command prompt mode, type

Control-Z

This command will suspend the emacs application, but will not kill it. Then type:

bg

to have emacs working in the background.

***User home directories are set at a maximum storage space of 3 gigabytes. Should you exceed your storage space, you will be warned that you are at your maximum storage space. Contact the Workshop computer staff before the grace period on this expires and anything of yours is possibly lost.***

Moving Files

Because of the way files are accessed in UNIX/Linux, moving a file is the same as renaming it. The command mv works like:
mv file1 file2

For example:

mv fileformats.html index.html

takes fileformats.html and renames it index.html.
Files can be moved from one location to another:

mv location/file1 location/file2

For example:

mv /home/mwaring/to-do-list /home/mwaring/Tasks/

This command moves the file to-do-list from /home/mwaring/ to /home/mwaring/Tasks/. To move a file and also rename it, specify a name after the second location. For example:
mv /home/mwaring/more-stuff /home/mwaring/Tasks/additional-tasks

Copying Files

To copy a file using a terminal, use
cp

For example:

cp template.html course-schedule.html

This makes a new file that contains the same information as the first file with the name indicated. In the example above, cp takes the contents of template.html and makes a file called course-schedule.html that contains all the information in template.html.

cp can also be used to copy a file from one directory to another. For example:

cp /home/tmp/mbl.color.logo.jpg /home/mwaring/images/MBL.jpg

This command will take MBL.color.logo.jpg in /home/tmp and copy it to /home/mwaring/images. It names the copy MBL.jpg. If a name is not specified for the file, a copy with the same name as the original is made. For example:

cp /home/tmp/mbl.color.logo.jpg /home/mwaring/images

To copy an entire directory, use the -R flag.

cp -R dir-to-copy/ new-dir/

For example:

cp -R /home/tmp/images/ /home/mwaring/temp-images

copies the directory in /home/tmp called images into the temp-images directory in /home/mwaring. Note: on some computers, cp -R does not copy dot-files (files that start with ‘.’, for example .bashrc).

You may run into trouble copying files from or to directories which you do not have permission to read or execute.

Removing Files

rm is the command to remove a file. There are flags (options) that can be used with rm. To delete a file, type:

rm filename

For example, to delete a file called coi.nex, type:

rm coi.nex

A prompt will ask if you really want to delete it. If so, type:

y

To delete a file from a different directory, supply rm with the pathname. For example:

rm /home/mwaring/coi.nex

Creating Directories

To create a new directory, type:

mkdir directory1

This will create a directory called directory1.

Changing Directories

To view the pathway of the current directory, type:

pwd

This will show output such as

/home/mwaring/directory1

To go “up” one directory (in this example, to go from directory1 to mwaring), type:

cd ..

To go “down” one directory (in this example, to go from mwaring to directory1), type:

cd directory1

To go “back” to your home directory, type:

cd

Deleting Directories

To delete a directory, type:

rm -r directory1

This will remove the directory and all the files in it so use this command carefully.

Viewing PDF files

PDF files can be accessed by either downloading and saving or reading files directly. To view files that have been downloaded, go to the terminal window and type:

acroread file1

This will open the pdf file in acrobat reader.

Getting Help

While the workshop is in session, one of your best sources of help are the teaching assistants and support staff.

This page will still be accessible after the course, but contains help on only a few basic UNIX commands. Some material may not apply to your home systems. On most systems, typing

man command

invokes information about commands.

For example, to learn how cp works, type:

man cp

To exit the man page, hit:

q

Note: man pages are often a bit obtuse, but are worth reading nevertheless.

ssh

ssh is a program to connect to another computer. For Linux and Mac OS X, there are two ways of using ssh from a terminal:

ssh user@computer

or

ssh computer -l user

For example:

ssh mwaring@gcg.workshop.priv

or

ssh gcg.workshop.priv -l mwaring

You will then be asked for your password.

If you are using a notebook computer and it does not already have an ssh client program, you can get one for free. For MacOS 9, visit Nifty Telnet-SSH and download the client. Windows users can download Putty, a free ssh client.

Note: Your home directory (and all of /home) is available for you on every machine in the lab.

Copying Files between Machines (File Transfer)

Some of you may be familiar with ftp (File Transfer Protocol). We do not have ftp here because it is a relatively insecure method of transferring files between computers. To transfer files between machines, you need to use:

scp

This command works very similarly to cp, except that the files you are copying reside on different machines.

To copy a file from a remote computer to the computer you are working at, you type:

scp user@remote-computer:/remote/path/remote-file /local/path/local-file

You will then be prompted for the user’s password on the remote computer. After you enter it, the file will be copied. For example:

scp molly@bigbox.university.edu:/home/molly/Info/info /home/mwaring/facts

If I am working on nixon (for example), this command will copy the file called info that lives on bigbox.university.edu at /home/molly/Info to /home/mwaring on nixon and will name it ‘facts’. For those of you familiar with ftp, this is like ‘get remote-file local-file’. Note: if you do not specify a local name, scp will name the file the same name as the remote file.

To copy a local file onto a remote computer, you type:

scp /local/path/local-file user@remote-computer:/remote/path/remote-file

For those of you familiar with ftp, this is like ‘put local-file remote-file’.Note: As with cp, you need to have read/execute permissions on the two files. Also, you should only specify one computer name (either the local host or the remote host).

As with the cp command, you can specify the -r flag to recursively copy entire directories.

Note: This does not work with Windows machines. scp works only between UNIX/Linux machines.

Read More

the php tutorials got lost in the server moval, sorry about that!

Read More