Subscribe RSS

Tag-Archive for "linux"

Apache Directory Access Control Oct 22

Apache configuration has a Directory directive. It is used like a .htaccess file to control access to said directory.

An example:

Order deny,allow
Deny from all
Allow from my.domain.com

The important bit here is the Order statement. Rules will be processed from right to left (in this case all of the deny rules then all of the allow rules. The LAST rule that is matched will the the rule that is used. We are denying everyone and allowing wo we specify.

If you were to specify allow,deny you will be allowing everyone and denying who you specify.

This is quite a complicated system and some personal experimentation should help you understand.

Category: Apache, Tutorials, Uncategorized  | Tags: ,  | Leave a Comment
MIME Email attachments from command line. Aug 13
marceau marcel

Couldnt resist

I searched for ages to find a half decient example to send mime attachments from the command line that allows you to specify the from and to address. I found some applications however some either didnt let you specify the from address and others didnt let you do multi-part mime messages and the rest suggested to use uuencode. Uuencode is horrible, no just no!

So I wrote my own using sendmail and openssl and it works very well and is incredibly flexible and small.

Here it is:

#!/bin/bash

SENDMAIL="/usr/sbin/sendmail"

FILESPATH="/home/user/"
FILENAME="1.pdf"
FILETOSEND="${FILESPATH}${FILENAME}"

SUBJ="Subject"
SNDR="test@websurfshack.net"
RECP="user@gmail.com"

MIMEBOUNDRY="0016364d261349d0be047105fb55"

(
echo "Mime-version: 1.0"
echo "Subject: $SUBJ"
echo "From: $SNDR"
echo "To: $RECP"
#cc:
#bcc:
echo "Content-Type: multipart/mixed; boundary=${MIMEBOUNDRY}"

echo "--${MIMEBOUNDRY}"
echo "Content-Type: text/plain; charset=ISO-8859-1"
echo "Content-Transfer-Encoding: 7bit"
echo # This echo is important or else you get a mime error
echo INSERT MESSAGE HERE

echo "--${MIMEBOUNDRY}"
echo "Content-Type: application/pdf; name=\"${FILENAME}\""
echo "Content-Disposition: attachment; filename=\"${FILENAME}\""
echo "Content-Transfer-Encoding: base64"
echo # This echo is important or else you get a mime error
openssl enc -base64 -in ${FILETOSEND}
echo "--${MIMEBOUNDRY}--"
) | ${SENDMAIL} -t

There we have it, Simple isnt it. It is very basic but im sure you’ll be able to modify it to suit your needs.

UPDATE: ive since found out that you can specify -t as a sendmail switch to force sendmail to use header data as reciepient information. This then enabled you to specify a BCC field. This works with postfix sendmail… not sure about others.

Category: Linux  | Tags: , , , ,  | Leave a Comment
Sed tricks Aug 11

If you know what Unix Sed is it is a way to use regular expressions to change the contents of a file and then save or display it. Generally sed commands are written like this…

cat filename | sed 's/thsi/this/'

Every occurance of ‘thsi’ will be replaced with this. You can also add on the redirect operator to output to a file ‘>’.

You may also want to use an enviroment variable in your statements. I this case use double quotes instead of single.

cat filename | sed "s/thsi/${MYVAR}/"

Now the problem I ran in to that made me want to write this is that you run in to problems if ${MYVAR} is a path as sed tries to make sense of the slashes in the path name and ofcourse we dont want this so you can use different seperators for example the equals sign eg.

MYVAR="/home/user/file"
cat filename | sed "s=%%path%%=${MYVAR}="

This command will take the variable MYVAR and replace '%%path%%' with the contents of it.

Category: Linux  | Tags: , , , ,  | Leave a Comment
Screen Jul 07
Aww isnt that cute! BUT ITS WRONG!

Hay look another irrelevant picture!

There is a very useful application with plenty of features that can be downloaded easily.

One of the best features is the ability to start a screen session in ssh from one location, disconnect it then reconnect it at a later time from a different session.

Get it now: aptitude install screen

As it is to be used in console and key commands need to be passed to the bash session that it contains the key commands can be quite complex.

As rule of the thumb all commands start with ^A that is control + a then let go followed by a key or combination of keys. You can get a full list of commands available by pressing ^a + ? in screen.

Create window ^a +c
Close window “exit” no prior key seq.
Go to window 0 ^a + 0
Go to window 2 ^a + 2
Go to last window ^a + ^a
View list of windows ^a  + ” (yes quote marks you’ll need to press shift too)

I could go on but this is it in a nutshell.

Category: Linux  | Tags: , , ,  | Leave a Comment