2013年11月30日土曜日

CentOS 6.x Nmapをyumではなくrpmでインストールする

nmapをyumではなくrpmでインストールする場合。

多機能スキャナ(セキュリティスキャナ)のnmapを、yumコマンドではなくrpmコマンドでインストールします。

下の例では、5.51のバージョンのNmapを使用しました。

[root@centos6 ~]# cd /src/
[root@centos6 src]# wget ftp://rpmfind.net/linux/centos/6.4/os/i386/Packages/nmap-5.51-2.el6.i686.rpm
--2013-12-31 23:59:59--  ftp://rpmfind.net/linux/centos/6.4/os/i386/Packages/nmap-5.51-2.el6.i686.rpm
           => `nmap-5.51-2.el6.i686.rpm.1'
rpmfind.net をDNSに問いあわせています... 195.220.108.108
rpmfind.net|195.220.108.108|:21 に接続しています... 接続しました。
anonymous としてログインしています... ログインしました!
==> SYST ... 完了しました。    ==> PWD ... 完了しました。
==> TYPE I ... 完了しました。  ==> CWD (1) /linux/centos/6.4/os/i386/Packages ... 完了しました。
==> SIZE nmap-5.51-2.el6.i686.rpm ... 2871012
==> PASV ... 完了しました。    ==> RETR nmap-5.51-2.el6.i686.rpm ... 完了しました。
長さ: 2871012 (2.7M) (確証はありません)

100%[===============================================================================>] 2,871,012    658K/s 時間 4.3s

2013-12-31 23:59:59 (658 KB/s) - `nmap-5.51-2.el6.i686.rpm.1' へ保存終了 [2871012]
[root@centos6 src]# rpm -K ./nmap-5.51-2.el6.i686.rpm
./nmap-5.51-2.el6.i686.rpm: rsa sha1 (md5) pgp md5 OK
[root@centos6 src]# rpm -ihv ./nmap-5.51-2.el6.i686.rpm
エラー: 依存性の欠如:
        libpcap.so.1 は nmap-2:5.51-2.el6.i686 に必要とされています

rpmパッケージをダウンロードし、Kオプションで電子署名を確認後、インストールを実行。

依存性エラー「libpcap.so.1 は nmap-2:5.51-2.el6.i686 に必要とされています
と表示されました。 (´・ω・`)
(libpcapが無いはずがないのですが……。)


取り敢えず確認してみましたが、しっかり存在されていますね。

[root@centos6 src]# rpm -qa 'libpcap'
libpcap-1.0.0-6.20091201git117cb5.el6.i686
[root@centos6 src]# ls -l /usr/lib/libpcap.so.1*
lrwxrwxrwx.  1 root root      16 11月 10 20:33 2013 libpcap.so.1 -> libpcap.so.1.0.0
-rwxr-xr-x.  1 root root  218484 11月 12 04:46 2010 libpcap.so.1.0.0

libpcapを再インストールすることで解決させます。

[root@centos6 src]# wget ftp://rpmfind.net/linux/centos/6.4/os/i386/Packages/libpcap-1.0.0-6.20091201git117cb5.el6.i686.rpm
--2013-12-31 23:59:59--  ftp://rpmfind.net/linux/centos/6.4/os/i386/Packages/libpcap-1.0.0-6.20091201git117cb5.el6.i686.rpm
           => `libpcap-1.0.0-6.20091201git117cb5.el6.i686.rpm'
rpmfind.net をDNSに問いあわせています... 195.220.108.108
rpmfind.net|195.220.108.108|:21 に接続しています... 接続しました。
anonymous としてログインしています... ログインしました!
==> SYST ... 完了しました。    ==> PWD ... 完了しました。
==> TYPE I ... 完了しました。  ==> CWD (1) /linux/centos/6.4/os/i386/Packages ... 完了しました。
==> SIZE libpcap-1.0.0-6.20091201git117cb5.el6.i686.rpm ... 127496
==> PASV ... 完了しました。    ==> RETR libpcap-1.0.0-6.20091201git117cb5.el6.i686.rpm ... 完了しました。
長さ: 127496 (125K) (確証はありません)

100%[===============================================================================>] 127,496      130K/s 時間 1.0s

2013-12-31 23:59:59 (130 KB/s) - `libpcap-1.0.0-6.20091201git117cb5.el6.i686.rpm' へ保存終了 [127496]

[root@centos6 src]# rpm -K ./libpcap-1.0.0-6.20091201git117cb5.el6.i686.rpm
./libpcap-1.0.0-6.20091201git117cb5.el6.i686.rpm: rsa sha1 (md5) pgp md5 OK
[root@centos6 src]# rpm -ihv --force ./libpcap-1.0.0-6.20091201git117cb5.el6.i686.rpm
準備中...                ########################################### [100%]
   1:libpcap                ########################################### [100%]
[root@centos6 src]# rpm -ihv ./nmap-5.51-2.el6.i686.rpm
準備中...                ########################################### [100%]
   1:nmap                   ########################################### [100%]
[root@centos6 src]# yum list installed | grep 'nmap'
nmap.i686               2:5.51-2.el6      installed

無事にインストール出来ました。

最後に、簡単なポートスキャンを行うことで動作確認とし、終了とします。

[root@centos6 src]# nmap -sS -p 1-500 xxx.xxx.xxx.xxx

Starting Nmap 5.51 ( http://nmap.org ) at 2013-12-31 23:59 JST
Nmap scan report for xxx.xxx.xxx.xxx
Host is up (0.0021s latency).
Not shown: 496 closed ports
PORT   STATE SERVICE
21/tcp open  ftp
22/tcp open  ssh
25/tcp open  smtp
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 0.20 seconds



余談ですが……。

anonymous としてログインしています... ログインしました!

「!」というのが、元気な感じですね……。

2013年11月29日金曜日

historyコマンドに日時(時刻)を表示させる。

historyコマンドで表示されるコマンド実行履歴に、実行時のタイムスタンプ情報を付加する。

historyコマンドは、デフォルトでコマンドの実行日時情報が記録されません。

[root@1803-zm05 ~]# history
    1  13/12/31 23:59:56  cd ~
    2  ls -la
    3  du -h /home
    4  fdisk -l

これにコマンドの実行日時情報を付加する場合は、HISTTIMEFORMAT環境変数を設定します。

[root@1803-zm05 ~]# touch /etc/profile.d/history.sh
[root@1803-zm05 ~]# cat <<EOF >> /etc/profile.d/history.sh
> HISTSIZE=10000
> HISTFILESIZE=10000
> HISTTIMEFORMAT='%y/%m/%d %H:%M:%S  '
> HISTIGNORE=history
> EOF

例では/etc/profile.d/ディレクトリにhistory.shファイルを作成しました。
設定した環境変数は以下

HISTSIZE
記録される実行コマンドの最大値
HISTFILESIZE
記録される実行コマンドの最大値(基本的にHISTSIZEと同値を指定します)
HISTTIMEFORMAT
今回の題材でもある実行日時の書式設定
HISTIGNORE
履歴から除外するコマンド(例では、history。複数指定の場合は:で区切り指定します。 =history:whoami)

他にもHISTCONTROLなどを設定可能です。


上記の設定通りの場合は、/etc/profile.d/history.shファイルは以下のように設定されているはずです。

[root@1803-zm05 ~]# cat /etc/profile.d/history.sh
HISTSIZE=10000
HISTFILESIZE=10000
HISTTIMEFORMAT='%y/%m/%d %H:%M:%S  '
HISTIGNORE=ls:history

HISTTIMEFORMATの値の末尾に半角スペースで間を設けているのは、historyの履歴追記時に実行コマンドと実行日時がくっついてしまわないようとの調整です。(*≧∀≦*)



上記の設定以降のhistory表示フォーマットは次のように表示されます。

[user@1803-zm05 ~]# history
    1  14/01/01 23:59:56  cd ~
    2  14/01/01 23:59:57  ls -la
    3  14/01/01 23:59:58  du -h /home
    4  14/01/01 23:59:59  fdisk -l

2013年11月28日木曜日

Ubuntu 12.x Postfixとmailコマンドのインストール

Postfixのインストール

下記の例では、apt-getコマンドを使用してPostfixをインストールしています。

root@Ubuntu12:~# apt-get install postfix
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  ssl-cert
Suggested packages:
  procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre sasl2-bin dovecot-common postfix-cdb mail-reader postfix-doc openssl-blacklist
The following NEW packages will be installed:
  postfix ssl-cert
0 upgraded, 2 newly installed, 0 to remove and 65 not upgraded.
Need to get 1,287 kB of archives.
After this operation, 3,278 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://jp.archive.ubuntu.com/ubuntu/ precise-updates/main ssl-cert all 1.0.28ubuntu0.1 [12.3 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu/ precise-updates/main postfix i386 2.9.6-1~12.04.1 [1,274 kB]
Fetched 1,287 kB in 1s (1,021 kB/s)
Preconfiguring packages ...
~中略~
/etc/aliases does not exist, creating it.
WARNING: /etc/aliases exists, but does not have a root alias.

Postfix is now set up with a default configuration.  If you need to make
changes, edit
/etc/postfix/main.cf (and others) as needed.  To view Postfix configuration
values, see postconf(1).

After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.

Running newaliases
 * Stopping Postfix Mail Transport Agent postfix   [ OK ]
 * Starting Postfix Mail Transport Agent postfix   [ OK ]
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
root@Ubuntu12:~# /etc/init.d/postfix status
 * postfix is running

mailコマンドのインストール (mailutils)

root@Ubuntu12:~# mail -s "Mail Testing" user@ubuntu.xxx
The program 'mail' is currently not installed.  You can install it by typing:
apt-get install mailutils

標準では、mailコマンドが存在しないのでインストールします。
mailコマンドは、mailutilsから取得出来ます。
apt-getまたはaptitudeコマンドでインストールして下さい。

root@Ubuntu12:~# apt-get install mailutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  guile-1.8-libs libgsasl7 libltdl7 libmailutils2 libmysqlclient18 libntlm0 mysql-common
Suggested packages:
  mailutils-mh
The following NEW packages will be installed:
  guile-1.8-libs libgsasl7 libltdl7 libmailutils2 libmysqlclient18 libntlm0 mailutils mysql-common
0 upgraded, 8 newly installed, 0 to remove and 65 not upgraded.
Need to get 3,153 kB of archives.
After this operation, 11.5 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://jp.archive.ubuntu.com/ubuntu/ precise/main libltdl7 i386 2.4.2-1ubuntu1 [38.1 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu/ precise-updates/main mysql-common all 5.5.34-0ubuntu0.12.04.1 [13.3 kB]
Get:3 http://jp.archive.ubuntu.com/ubuntu/ precise-updates/main libmysqlclient18 i386 5.5.34-0ubuntu0.12.04.1 [922 kB]
Get:4 http://jp.archive.ubuntu.com/ubuntu/ precise/main guile-1.8-libs i386 1.8.8+1-6ubuntu2 [755 kB]
Get:5 http://jp.archive.ubuntu.com/ubuntu/ precise/universe libntlm0 i386 1.2-1 [18.4 kB]
Get:6 http://jp.archive.ubuntu.com/ubuntu/ precise/universe libgsasl7 i386 1.6.1-1 [133 kB]
Get:7 http://jp.archive.ubuntu.com/ubuntu/ precise/universe libmailutils2 i386 1:2.2+dfsg1-5 [872 kB]
Get:8 http://jp.archive.ubuntu.com/ubuntu/ precise/universe mailutils i386 1:2.2+dfsg1-5 [401 kB]
Fetched 3,153 kB in 2s (1,212 kB/s)
Selecting previously unselected package libltdl7.
(Reading database ... 51954 files and directories currently installed.)
Unpacking libltdl7 (from .../libltdl7_2.4.2-1ubuntu1_i386.deb) ...
Selecting previously unselected package mysql-common.
Unpacking mysql-common (from .../mysql-common_5.5.34-0ubuntu0.12.04.1_all.deb) ...
Selecting previously unselected package libmysqlclient18.
Unpacking libmysqlclient18 (from .../libmysqlclient18_5.5.34-0ubuntu0.12.04.1_i386.deb) ...
Selecting previously unselected package guile-1.8-libs.
Unpacking guile-1.8-libs (from .../guile-1.8-libs_1.8.8+1-6ubuntu2_i386.deb) ...
Selecting previously unselected package libntlm0.
Unpacking libntlm0 (from .../libntlm0_1.2-1_i386.deb) ...
Selecting previously unselected package libgsasl7.
Unpacking libgsasl7 (from .../libgsasl7_1.6.1-1_i386.deb) ...
Selecting previously unselected package libmailutils2.
Unpacking libmailutils2 (from .../libmailutils2_1%3a2.2+dfsg1-5_i386.deb) ...
Selecting previously unselected package mailutils.
Unpacking mailutils (from .../mailutils_1%3a2.2+dfsg1-5_i386.deb) ...
Processing triggers for man-db ...
Setting up libltdl7 (2.4.2-1ubuntu1) ...
Setting up mysql-common (5.5.34-0ubuntu0.12.04.1) ...
Setting up libmysqlclient18 (5.5.34-0ubuntu0.12.04.1) ...
Setting up guile-1.8-libs (1.8.8+1-6ubuntu2) ...
Setting up libntlm0 (1.2-1) ...
Setting up libgsasl7 (1.6.1-1) ...
Setting up libmailutils2 (1:2.2+dfsg1-5) ...
Setting up mailutils (1:2.2+dfsg1-5) ...
update-alternatives: using /usr/bin/frm.mailutils to provide /usr/bin/frm (frm) in auto mode.
update-alternatives: using /usr/bin/from.mailutils to provide /usr/bin/from (from) in auto mode.
update-alternatives: using /usr/bin/messages.mailutils to provide /usr/bin/messages (messages) in auto mode.
update-alternatives: using /usr/bin/movemail.mailutils to provide /usr/bin/movemail (movemail) in auto mode.
update-alternatives: using /usr/bin/readmsg.mailutils to provide /usr/bin/readmsg (readmsg) in auto mode.
update-alternatives: using /usr/bin/dotlock.mailutils to provide /usr/bin/dotlock (dotlock) in auto mode.
update-alternatives: using /usr/bin/mail.mailutils to provide /usr/bin/mailx (mailx) in auto mode.
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
root@Ubuntu12:~# mail -s 'Email Testing' user@ubuntu.xxx
Cc:
Null message body; hope that's ok

2013年11月27日水曜日

動的に共通のクラス名を持つ要素の高さを揃える

動的に横で配置されているボックスの高さを揃える際に、作成したコードをjQueryプラグイン化してみました。
下記がコードになります。

(function(jQuery) {
  jQuery.fn.height_trim = function(options) {
    var target = options['target'];
    var max_height = 0;

    jQuery(target).each(function() {
      jQuery(this).height("auto");
      var box_height = jQuery(this).height();
      if (max_height < box_height) {
        max_height = box_height;
      }
    });
    jQuery(target).height(max_height);
  }
})(jQuery);

処理内容としては最大の高さを保持する変数し、指定されたクラスが指定されているボックスの高さをループで比べていきループの処理終了後に、指定されているクラスの高さを変更します。
動的に変更するため、ループの最初に「jQuery(this).height("auto")」を指定することで全てのボックスの高さを初期化(自動)に合わせています。

使い方

<script type="text/javascript">
jQuery(function() {
  jQuery(document).height_trim({"target" : "クラス名セレクタ"});
});
</script>

CentOS 5.x wkhtmltoimage, wkhtmltopdf (ウェブサイトキャプチャー)

WebKitのレンダリングエンジンを使用してPDFや画像に変換するための簡単なシェル·ユーティリティー。

wkhtmltoimage, wkhtmltopdfは、指定されたWebサイトをキャプチャーし、画像またはPDFなどで保存することが可能です。

wkhtmltoimageのインストール

[root@centos5 ~]# /usr/bin/php -i | grep 'GD Support'
GD Support => enabled
[root@centos5 ~]# cd /usr/local/src/
[root@centos5 src]# wget http://wkhtmltopdf.googlecode.com/files/wkhtmltoimage-0.11.0_rc1-static-i386.tar.bz2
--2013-12-31 23:23:59--  http://wkhtmltopdf.googlecode.com/files/wkhtmltoimage-0.11.0_rc1-static-i386.tar.bz2
wkhtmltopdf.googlecode.com をDNSに問いあわせています... 74.125.128.82, 2404:6800:4005:c00::52
wkhtmltopdf.googlecode.com|74.125.128.82|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 11393207 (11M) [application/octet-stream]
`wkhtmltoimage-0.11.0_rc1-static-i386.tar.bz2' に保存中

100%[=====================================>] 11,393,207  3.10M/s 時間 3.5s

2013-12-31 23:23:59 (3.10 MB/s) - `wkhtmltoimage-0.11.0_rc1-static-i386.tar.bz2' へ保存完了 [11393207/11393207]

[root@centos5 src]# tar -jxvf ./wkhtmltoimage-0.11.0_rc1-static-i386.tar.bz2
wkhtmltoimage-i386
[root@centos5 src]# mv wkhtmltoimage-i386 /usr/local/bin/wkhtmltoimage
[root@centos5 src]# chown root:root /usr/local/bin/wkhtmltoimage
[root@centos5 src]# ls -l /usr/local/bin/wkhtmltoimage
-rwxr-xr-x 1 root root 11424736 10月  3  2011 /usr/local/bin/wkhtmltoimage
[root@centos5 src]# cd ~
[root@centos5 ~]# wkhtmltoimage -h
Name:
  wkhtmltoimage 0.11.0 rc1

Synopsis:
  wkhtmltoimage [OPTIONS]... <input file> <output filegt;

Description:
  Converts an HTML page into an image,

General Options:
      --crop-h <int>                  Set height for croping
      --crop-w <int>                  Set width for croping
      --crop-x <int>                  Set x coordinate for croping
      --crop-y <int>                  Set y coordinate for croping
  -H, --extended-help                 Display more extensive help, detailing
                                      less common command switches
  -f, --format <format>               Output file format
      --height <int>                  Set screen height (default is calculated
                                      from page content) (default 0)
  -h, --help                          Display help
      --quality <int>                 Output image quality (between 0 and 100)
                                      (default 94)
  -V, --version                       Output version information an exit
      --width <int>                   Set screen width, note that this is used
                                      only as a guide line. Use
                                      --disable-smart-width to make it strict.
                                      (default 1024)

Contact:
  If you experience bugs or want to request new features please visit
  <http://code.google.com/p/wkhtmltopdf/issues/list>, if you have any problems
  or comments please feel free to contact me: <uuf6429@gmail.com>

[root@centos5 ~]# wkhtmltoimage --quality 100 http://google.co.jp/ /var/www/html/google.co.jpg
Loading page (1/2)
Rendering (2/2)
QPixmap: Cannot create a QPixmap when no GUI is being used   ] 25%
~中略~
QPixmap: Cannot create a QPixmap when no GUI is being used
QPainter::begin: Paint device returned engine == 0, type: 2
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::translate: Painter not active
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::setOpacity: Painter not active
QPainter::setFont: Painter not active
セグメンテーション違反です

セグメンテーション違反です
セグメンテーション違反です
セグメンテーション違反です
セグメンテーション違反です
(。A。)

情報を収集してみたところ、最新版でこの問題が発生している様子でした。
既存ファイルのパーミッション状態が原因でも発生する様ですね。
 (解決が大変そう)なので、ここは旧バージョンをインストールすることにしました。

[root@centos5 ~]# cd /usr/local/src/
[root@centos5 src]# wget http://wkhtmltopdf.googlecode.com/files/wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2
--2013-12-31 23:23:59--  http://wkhtmltopdf.googlecode.com/files/wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2
wkhtmltopdf.googlecode.com をDNSに問いあわせています... 74.125.128.82, 2404:6800:4005:c00::52
wkhtmltopdf.googlecode.com|74.125.128.82|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 11217033 (11M) [application/x-bzip2]
`wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2' に保存中

100%[==========================================================================>] 11,217,033  2.71M/s 時間 4.6s

2013-12-31 23:23:59 (2.30 MB/s) - `wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2' へ保存完了 [11217033/11217033]

[root@centos5 src]# tar -jxvf ./wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2
wkhtmltoimage-i386
[root@centos5 src]# chown root:root ./wkhtmltoimage-i386
[root@centos5 src]# mv ./wkhtmltoimage-i386 /usr/local/bin/wkhtmltoimage
[root@centos5 src]# cd ~
[root@centos5 ~]# wkhtmltoimage http://yahoo.co.jp /var/www/html/yahoo.co.jpg
[root@centos5 ~]# wkhtmltoimage --quality 100 http://google.co.jp/ /var/www/html/google.co.jpg

wkhtmltoimageのインストール

前項のwkhtmltoimageでの反省を踏まえ、こちらも旧バージョンをインストールしています。

[root@centos5 ~]# cd /usr/local/src/
[root@centos5 src]# wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2
--2013-12-31 23:23:59--  http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2
wkhtmltopdf.googlecode.com をDNSに問いあわせています... 74.125.128.82, 2404:6800:4005:c00::52
wkhtmltopdf.googlecode.com|74.125.128.82|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 11240983 (11M) [application/x-bzip2]
`wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2' に保存中

100%[==========================================================================>] 11,240,983  4.55M/s 時間 2.4s

2013-12-31 23:23:59 (4.55 MB/s) - `wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2' へ保存完了 [11240983/11240983]

[root@centos5 src]# tar -jxvf ./wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2
wkhtmltopdf-i386
[root@centos5 src]# chown root:root ./wkhtmltopdf-i386
[root@centos5 src]# mv ./wkhtmltopdf-i386 /usr/local/bin/wkhtmltopdf
[root@centos5 src]# ls -l /usr/local/bin/wkhtmltopdf
-rwxr-xr-x 1 root root 11272224  1月 31  2011 /usr/local/bin/wkhtmltopdf
[root@centos5 src]# cd ~
[root@centos5 ~]# wkhtmltopdf -h
Name:
  wkhtmltopdf 0.10.0 rc2

Synopsis:
  wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>

Description:
  Converts one or more HTML pages into a PDF document, using wkhtmltopdf patched
  qt.

Global Options:
      --collate                       Collate when printing multiple copies
                                      (default)
      --no-collate                    Do not collate when printing multiple
                                      copies
      --copies <number>               Number of copies to print into the pdf
                                      file (default 1)
  -H, --extended-help                 Display more extensive help, detailing
                                      less common command switches
  -g, --grayscale                     PDF will be generated in grayscale
  -h, --help                          Display help
  -l, --lowquality                    Generates lower quality pdf/ps. Useful to
                                      shrink the result document space
  -O, --orientation <orientation>     Set orientation to Landscape or Portrait
                                      (default Portrait)
  -s, --page-size <Size>              Set paper size to: A4, Letter, etc.
                                      (default A4)
  -q, --quiet                         Be less verbose
      --read-args-from-stdin          Read command line arguments from stdin
      --title <text>                  The title of the generated pdf file (The
                                      title of the first document is used if not
                                      specified)
  -V, --version                       Output version information an exit

Contact:
  If you experience bugs or want to request new features please visit
  <http://code.google.com/p/wkhtmltopdf/issues/list>, if you have any problems
  or comments please feel free to contact me: see
  <http://www.madalgo.au.dk/~jakobt/#about>

[root@centos5 ~]# wkhtmltopdf http://google.co.jp/ /var/www/html/google.co.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

2013年11月19日火曜日

CentOS 5.x ImageMagickのインストール

ImageMagickをインストールする。

yumからのインストールでは取得可能なバージョンが古い為、rpmパッケージからインストールを試ます。

[root@centos5 ~]# wget http://www.imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-6.8.7-7.x86_64.rpm
[root@centos5 ~]# mv ./ImageMagick-6.8.7-7.x86_64.rpm /usr/local/src/ImageMagick-6.8.7-7.x86_64.rpm
[root@centos5 ~]# rpm --install --test /usr/local/src/ImageMagick-6.8.7-7.x86_64.rpm
エラー: 依存性の欠如:
        libHalf.so.4()(64bit) は ImageMagick-6.8.7-7.x86_64 に必要とされています
        libIex.so.4()(64bit) は ImageMagick-6.8.7-7.x86_64 に必要とされています
        libIlmImf.so.4()(64bit) は ImageMagick-6.8.7-7.x86_64 に必要とされています
        libImath.so.4()(64bit) は ImageMagick-6.8.7-7.x86_64 に必要とされています
        libjasper.so.1()(64bit) は ImageMagick-6.8.7-7.x86_64 に必要とされています
        liblqr-1.so.0()(64bit) は ImageMagick-6.8.7-7.x86_64 に必要とされています
        liblzma.so.0()(64bit) は ImageMagick-6.8.7-7.x86_64 に必要とされています
        libwebp.so.4()(64bit) は ImageMagick-6.8.7-7.x86_64 に必要とされています

多数の依存性エラーが吐かれた事によって心折れましたので、ソースからインストールをさせて頂きます。c(・ω・`c⌒っ

[root@centos5 ~]# wget http://www.imagemagick.org/download/ImageMagick.tar.gz
[root@centos5 ~]# mv ./ImageMagick.tar.gz /usr/local/src/
[root@centos5 ~]# cd /usr/local/src/
[root@centos5 src]# tar xfz ./ImageMagick.tar.gz
[root@centos5 src]# cd ImageMagick-6.8.7-7
[root@centos5 ImageMagick-6.8.7-7]# ./configure
[root@centos5 ImageMagick-6.8.7-7]# make
[root@centos5 ImageMagick-6.8.7-7]# make install
[root@centos5 ImageMagick-6.8.7-7]# convert -list format | egrep "GIF|JPEG|PNG"
           see part 5 which describes the image encoding (RLE, JPEG, JPEG-LS),
           and supplement 61 which adds JPEG-2000 encoding.
      GIF* rw+   CompuServe graphics interchange format
    GIF87* rw-   CompuServe graphics interchange format (version 87a)
      JNG* rw-   JPEG Network Graphics
     JPEG* rw-   Joint Photographic Experts Group JFIF format (62)
    PJPEG* rw-   Joint Photographic Experts Group JFIF format (62)
      PNG* rw-   Portable Network Graphics (libpng 1.2.10)
           See http://www.libpng.org/ for details about the PNG format.
    PNG00* rw-   PNG inheriting bit-depth and color-type from original
    PNG24* rw-   opaque or binary transparent 24-bit RGB (zlib 1.2.3)
    PNG32* rw-   opaque or transparent 32-bit RGBA
    PNG48* rw-   opaque or binary transparent 48-bit RGB
    PNG64* rw-   opaque or transparent 64-bit RGBA
     PNG8* rw-   8-bit indexed with optional binary transparency
[root@centos5 ImageMagick-6.8.7-7]# convert -resize x100 -quality 80 /var/www/html/test.jpg /var/www/html/test.png

wgetコマンドを使用し、imagemagickの公式サイトから最新版のソースコード配布パッケージを取得します。
makeファイルを作成し、インストールを実行。

インストール後にconvertコマンドを実行し、対応フォーマットの確認を行っています。
最後の行では実際にconvertコマンドを実行し、画像のリサイズ試験を行っています。

-resize
(画像サイズ変更オプション)
x100
(横幅100px指定。この場合、縦幅は自動調整。 縦幅指定の場合は 100x などと指定可能)
-quality
(画像変換のクオリティ値。1-100を指定可能)
80
(指定された変換クオリティ値)


phpのimagickをインストールする。

[root@centos5 ~]# /usr/bin/php -i | grep 'imagick'
[root@centos5 ~]# pecl install 'imagick'
downloading imagick-3.1.2.tgz ...
Starting to download imagick-3.1.2.tgz (94,657 bytes)
.....................done: 94,657 bytes
~中略~
/php/extensions/no-debug-non-zts-20090626/imagick.so

Build process completed successfully
Installing '/usr/local/include/php/ext/imagick/php_imagick.h'
Installing '/usr/local/include/php/ext/imagick/php_imagick_shared.h'
Installing '/usr/local/include/php/ext/imagick/php_imagick_defs.h'
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/imagick.so'
install ok: channel://pecl.php.net/imagick-3.1.2
configuration option "php_ini" is not set to php.ini location
You should add "extension=imagick.so" to php.ini

[root@centos5 ~]# vi /etc/php.d/imagick.ini      ← 作成
; Enable imagick extension module
extension=imagick.so

[root@centos5 ~]# ln -s /usr/local/lib/php/extensions/no-debug-non-zts-20090626/imagick.so /usr/lib64/php/modules/imagick.so
[root@centos5 ~]# /etc/init.d/httpd configtest
Syntax OK
[root@centos5 ~]# /etc/init.d/httpd reload
httpd を再読み込み中:                                      [  OK  ]
[root@centos5 ~]# /usr/bin/php -i | grep 'imagick'
/etc/php.d/imagick.ini,
imagick
imagick module => enabled
imagick module version => 3.1.2
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0

imagickが未インストールであることを確認したら、peclコマンドにてimagickのインストールを実行します。
インストール完了のメッセージにて「You should add "extension=imagick.so" to php.ini」と表示されているので、それに従います。
この場合は、拡張の設定ディレクトリ/etc/php.d/内にファイル(imagick.ini)を作成し、そこに拡張モジュール読み込み記述を追記しました。
imagick.soへの参照パスが通っていない場合は必要に応じてリンクを張って下さい。
上記の例では ln -s /usr/local/lib/php/extensions/no-debug-non-zts-20090626/imagick.so /usr/lib64/php/modules/imagick.so

設定に問題が無いか確認し、apacheを再読み込みさせます。
最後に、phpにてimagickが有効になったかを確認して終了します。

SyntaxHighlighterをBloggerで使用する

SyntaxHighlighterサイトよりホスティングされているjsファイルやcssファイルを下記のようにBloggerのテンプレートにセットします。
※その他の言語にSyntaxHighlighterを使用する場合は、別途必要なファイルを追加してください。

<head>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/>
<script type='text/javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = "http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf";
SyntaxHighlighter.all();
</script>
</head>

上記で実装は完了です。

SyntaxHighlihgterを記事で使用するには下記のような記述で使用できます。
エスケープ必要記述

<pre class="brush: plain">
エスケープした内容を記述
</pre>

エスケープ不要記述
<script type='syntaxhighlighter' class='brush: plain'><![CDATA[
内容を記述
]]></script>