Jul 14

As we already know if you use sysmlink on your ftp directory the proftpd will not recognized it, soft link won’t work if your link target is not share out in proftpd. Besides, chroot in proftpd will mess up your soft link path if you use full path.

here is some example

# ftp localhost
Connected to localhost (127.0.0.1).
220 FTP Server ready.
Name (localhost:root): test
331 Password required for test
Password:
230 User test logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (127,0,0,1,195,10).
150 Opening ASCII mode data connection for file list
drwx——   3 test     test         4096 Jul 13 18:15 .
drwx——   3 test     test         4096 Jul 13 18:15 ..
-rw——-   1 test     test          246 Jul  5 03:11 .bash_history
-rw-r–r–   1 test     test           33 Jun 24 19:38 .bash_logout
-rw-r–r–   1 test     test          176 Jun 24 19:38 .bash_profile
-rw-r–r–   1 test     test          124 Jun 24 19:38 .bashrc
lrwxrwxrwx   1 0        0              13 Jul 13 18:15 adit -> /home/adityo/
drwx——   3 test     test         4096 Jun 24 19:50 mail
226 Transfer complete
ftp> cd adit
550 adit: No such file or directory
ftp> quit
221 Goodbye.

How Links Work

There are two types of links in Unix: hard and symbolic.

A hard link is a file that is, for all intents and purposes, the file to which it is linked. The difference between a hardlink and the linked file is one of placement in the filesystem. Editing the hardlink edits the linked file. One limitation of hard links is that linked files cannot reside on different filesystems. This means that if /var and /home are two different mount points in /etc/fstab (or /etc/vfstab), then a file in /var/tmp cannot be hardlinked with a file in /home:

> pwd
/var/tmp
  > ln /home/tj/tmp/tmpfile tmplink
ln: cannot create hard link `tmplink' to `/home/tj/tmp/tmpfile': Invalid cross-device link

A symbolic link (also referred to as a “symlink”) is a file whose contents contain the name of the file to which the symbolic link points. For example:

lrwxrwxrwx   1 root     root           11 Mar  2  2000 rmt -> /sbin/rmt

The file rmt contains the nine characters /sbin/rmt. The reason symbolic links fail when chroot(2) is used to change the position of the root (/)of the filesystem is that, once / is moved, the pointed-to file path changes. If, for example, if chroot(2) is used to change the filesystem root to /ftp, then the symlink above would be actually be pointing to /ftp/sbin/rmt. Chances that that link, if chroot(2) is used, now points to a path that does not exist. Symbolic links that point to nonexistent files are known as dangling symbolic links. Note that symbolic links to files underneath the new root, such as symlinks to a file in the same directory:

> pwd
/var/ftp
  > ls -l
-rw-r--r--   1 root     root            0 Jan 16 11:50 tmpfile
  lrwxrwxrwx   1 root     root            7 Jan 16 11:50 tmplink -> tmpfile

will be unaffected; only paths that point outside/above the new root will be affected.

Filesystem Tricks

A typical scenario is one where “DefaultRoot ~” is used to restrict users to their home directories, and where the administrator would like to have a shared upload directory, say /var/ftp/incoming, in each user’s home directory. Symbolic links would normally be used to provide an arrangement like this. As mentioned above, though, when chroot(2) is used (which is what the DefaultRoot directive does), symlinks that point outside the new root (the user’s home directory in this case) will not work. To get around this apparent limitation, it is possible on modern operating systems to mount directories at several locations in the filesystem.

To have an exact duplicate of the /var/ftp/incoming directory available in /home/bob/incoming and /home/adityo/incoming, use one of these commands:

    * Linux (as of the 2.4.0 kernel):

mount --bind /var/ftp/incoming /home/adityo/incoming
  mount -o bind /home2/test.com/ /home/domains/test.com/

    * BSD (as of 4.4BSD):

mount_null /var/ftp/incoming /home/adityo/incoming

    * Solaris:

mount -F lofs /var/ftp/incoming /home/adityo/incoming

set it on fstab
/var/ftp/incoming /home/bob/incoming ext3 --bind 0 0

referer :
- http://www.proftpd.org/localsite/Userguide/linked/chroot-symlinks.html
Sep 17

url referer : – http://www.howtoforge.com/how-to-log-emails-sent-with-phps-mail-function-to-detect-form-spam

After sometimes it occur to me that me how to get log of mail that was sent from formmail on my web because i always wonderring who sent the email is it spam or not, then i found this artickel http://www.howtoforge.com/how-to-log-emails-sent-with-phps-mail-function-to-detect-form-spam 🙂

Okay let’s start the installation

1. Installing the Log  script

Create new file /usr/local/bin/phpsendmail

vi /usr/local/bin/phpsendmail

Then paste this

#!/usr/bin/php

<?php

$sendmail_bin = ‘/usr/sbin/sendmail.postfix’; // i use postfix and postfix sendmail bin was located on /usr/sbin/sendmail.postfix , it depend on your mail system

$logfile = ‘/var/log/mail.form’;

//* Get the email content

$logline = ”;

while ($line = fgets(STDIN)) {

if(stristr($line,’to:’) || stristr($line,’from:’)) $logline .= trim($line).’ ‘;

$mail .= $line;

}

//* compose the sendmail command

$command = ‘echo “‘.$mail.'” | ‘.$sendmail_bin.’ -t’;

for ($i = 1; $i < $_SERVER[‘argc’]; $i++) {

$command .= $_SERVER[‘argv’][$i].’ ‘;

}

//* rotate log if it gets too big

if(is_file($logfile) && filesize($logfile) > 10000000) {

if(is_file($logfile.’.old’)) unlink($logfile.’.old’);

exec(‘cp -pf ‘.$logfile.’ ‘.$logfile.’.old’);

exec(‘cat /dev/null > ‘.$logfile);

}

//* Write the log

system(‘echo “‘.date(“Y-m-d H:i:s”).’ ‘.$_ENV[‘PWD’].’ ‘.$logline.'” >> ‘.$logfile);

//* Execute the command

return shell_exec($command);

?>

Now make the script executable…

chmod +x /usr/local/bin/phpsendmail

… and create the logfile and make it writable:

touch /var/log/mail.form
chmod 777 /var/log/mail.form

2. Modifying the main.cf

Again it depend on your mail system , on my ssystem i use postfix to send the email from my formmail, in other system usually the email send from sendmail or from the php itself in that case you need to edit php.ini. In my system i need to modify postfix main.cf

go to your main.cf on /etc/postfix/main.cf and changes this

vi /etc/postfix/main.cf

sendmail_path = /usr/local/bin/phpsendmail

then relaod your postfix

# /etc/init.d/postfix reload

3 Test the setup

To test this setup, create a new php file with the name mailtest.php in one of your websites with the content:

<?php
mail('yourname@yourdomain.com','This is a test message subject','This is a test message body');
echo 'Mail sent.'; 
?>
to see the log  you can use
# tail /var/log/mail.form -f
2009-09-17 15:49:30 /home/test/public_html To: test@yahoo.com From: test <test@yahoo.com> 
2009-09-17 16:12:01 /home/test/public_html To: test2@bi.edu From: test <test2@bi.edu>