Archive for 4月, 2009

php:Postfixで自動返信メール

メールを受信するサーバにメール受信用ユーザを登録する。

受信するメールアドレスは[ユーザ名]@ホスト名になります。

# adduser [ユーザ名]
# passwd [パスワード]

.forwardに転送設定を記述

/home/[ユーザ名]/.forward
register,”| /usr/bin/php /path/to/autoreply.php

.転送先はphpスクリプト。パイプでメール内容を渡している。

autoreply.php(返信処理の内容)はこんなふうになる。
require_once("Mail/mimeDecode.php"); //REARモジュール
//メールソースを標準入力から読み込み
$source = file_get_contents("php://stdin");
if(!$source) {
    return false;    // 読み込み失敗
}
 
//メール解析
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$decoder = new Mail_mimeDecode($source);
$structure = $decoder->decode($params);
 
// 送信者のメールアドレスを取得する
$from_address = mb_convert_encoding(mb_decode_mimeheader($structure->headers['from'])
                         ,mb_internal_encoding(), "auto");
このスクリプトを標準入力無しで起動すると

$source = file_get_contents(“php://stdin”);

のところで入力待ちになって処理が中断しますが、ヘッダさえもnullなメールを送ることは出来ないので多分気にしなくてもいいはず。

Linux:ssh公開鍵認証

ローカルサーバ(接続元)からリモートサーバ(接続先)にパスワード無しでログインする設定。
以下ローカルサーバのfooユーザがリモートサーバにbarユーザでログインする場合。

ローカルサーバ(接続元)で認証キーを作る

# ssh-keygen -t rsa -N “” -f /home/foo/.ssh/authkey_bar
rsync.pub (公開鍵)をリモートサーバ(接続先)の/bar/.sshにコピーするローカルサーバからSCPで転送
# scp authkey_bar.pub bar@リモートサーバ:/tmp
この時点ではまだパスワードを聞かれるので入力する。

リモートサーバにbarでログインして/home/bar/.sshに移動し、パーミッション変更&authorized_keysに追記

authorized_keysのパーミッションは必ず600でなくてはいけない。644ではパスワードを聞かれます。
# chmod 700 /home/bar/.ssh
# mv /tmp/rsync.pub /home/bar/.ssh
# cat /home/bar/.ssh/authkey_bar.pub >> /root/.ssh/authorized_keys
# chmod 600 /home/bar/.ssh/authorized_keys
# rm /home/bar/.ssh/authkey_bar.pub

Linux:ソースからインストール&パッケージ作成

checkinstallなるものでソースからインストールしつつパッケージを作成できるらしいので試してみた。

まずはcheckinstallをインストールする。

wget http://asic-linux.com.mx/~izto/checkinstall/files/rpm/checkinstall-1.6.1-1.i386.rpm
rpm -ihv checkinstall-1.6.1

どこに入ったかわからなくなったので・・・^^;
rpm -ql checkinstall

どうやら/usr/local/sbin/checkinstall

-h でヘルプ表示
/usr/local/sbin/checkinstall -h

checkinstall 1.6.1, Copyright 2002 Felipe Eduardo Sanchez Diaz Duran
This software is released under the GNU GPL.

Usage: checkinstall [options] [command [command arguments]]
Options:
*Package type selection*
-t,--type= Choose packaging system
-S Build a Slackware package
-R Build a RPM package
-D Build a Debian package
*Install options*
--install= Toggle created package installation
--fstrans= Enable/disable the filesystem translation code
*Scripting options*
-y, --default Accept default answers to all questions
--pkgname= Set name
--pkgversion= Set version
-A, --arch, --pkgarch= Set architecture
--pkgrelease= Set release
--pkglicense= Set license
--pkggroup= Set software group
--pkgsource= Set source location
--pkgaltsource= Set alternate source location
--pakdir= The new package will be saved here
--maintainer= The package maintainer (.deb)
--provides= Features provided by this package (.rpm)
--requires= Features required by this package
--rpmflags= Pass this flags to the rpm installer
--rpmi Use the -i flag for rpm when installing a .rpm
--rpmu Use the -U flag for rpm when installing a .rpm
--dpkgflags= Pass this flags to the dpkg installer
--spec= .spec file location
--nodoc Do not include documentation files

*Info display options*

-d<0|1|2> Set debug level
-si Run an interactive install command
--showinstall= Toggle interactive install command
-ss Run an interactive Slackware installation script
--showslack= Toggle interactive Slackware installation script

*Package tuning options*

--autodoinst= Toggle the creation of a doinst.sh script
--strip= Strip any ELF binaries found inside the package
--stripso= Strip any ELF binary libraries (.so files)
--addso= Search for any shared libs and add
them to /etc/ld.so.conf
--reset-uids= Reset perms for all files/dirs to 755 and
the owner/group for all dirs to root.root
--gzman= Compress any man pages found inside the package
--docdir= Where to put documentation files
--umask= Set the umask value
--exclude= Exclude these files/directories from the package
--include= Force the inclusion in the package of the
files/dirs listed in “listfile”
--inspect Inspect the package” file list
--review-spec Review the spec file before creating a .rpm
--review-control Review the control file before creating a .deb
--newslack Use the new (8.1+) Slackware description format
(“--newslack” implies “-S”)
--with-tar=/path/to/tar Manually set the path to the tar binary
in this system

*Cleanup options*

--deldoc= Delete doc-pak upon termination
--deldesc= Delete description-pak upon termination
--delspec= Delete spec file upon termination
--bk Backup any overwritten files
--backup= Toggle backup

*About CheckInstall*

--help, -h Show this message
--copyright Show Copyright information
--version Show version information

RPMは-Rか。

何かのソースからパッケージを作ってみたい。
今回試すのはsquidにしてみる。

wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE13.tar.gz
tar zxfv squid-3.0.STABLE13.tar.gz
cd squid-3.0.STABLE13
./configure
make
make install
/usr/local/sbin/checkinstall -R

途中の入力は全部パスして進めると、最後にこう表示される。OKか?
**********************************************************************

Done. The new package has been saved to

/usr/src/redhat/RPMS/i386/squid-3.0.STABLE13-1.i386.rpm
You can install it in your system anytime using:

rpm -i squid-3.0.STABLE13-1.i386.rpm

**********************************************************************

とりあえず/usr/src/redhat/RPMS/i386/にrpmができているのは確認した。
しかし、このパッケージからインストールしようとするとgrepの競合というエラーが出る。
ソースからすでにインストールしたからかな?

Windows Vista:右クリックで送る(Send To)の登録方法

SendToフォルダにショートカットを置くとそのアプリに「右クリック→送る」の動作でファイルを渡せます。

VistaはSendToフォルダの場所がわかりにくい・・・。

C:\Users\ユーザ名\AppData\Roaming\Microsoft\Windows\SendTo

« 前ページへ