Java の .class ファイルを一括で逆コンパイルする

環境
jad のインストール

Mac OS X で Homebrew の場合

$ brew install homebrew/binary/jad
コンパイル

classes 以下に展開されているとすると、以下のコマンドで src ディレクトリ以下に .java ファイルとして一括で逆コンパイルできる。

$ jad -o -r -sjava -dsrc 'classes/**/*.class'

Zendesk で独自ドメインのサポートアドレスを使用する設定の SPF レコードチェックでエラーが出た

Zendesk のサポートアドレスに独自ドメインを使用する場合は SPF レコードに mail.zendesk.com を指定すると、メールから Zendesk という文字が消えるので顧客は Zendesk を意識せずにサポートを受けることができる。

自社のメールドメインを使用してメールをZendeskから代理送信する方法

設定しようとしたドメインでは、Google Appsドメインの所有チェックの認証コードも TXT レコードに入れていたので、以下のように設定した。

"v=spf1 +include:_spf.google.com +include:mail.zendesk.com -all" "google-site-verification=XXXXXXXXXXXXXXXXX"

しかし、上記では Zendesk のチェックを通らなかった。

いくつかの SPF レコードのチェッカをためしたところ allgoogle-site-verification という引数は駄目だというようなメッセージが出ていたので、 試しに all の後ろに空白文字を入れたら通った。

"v=spf1 +include:_spf.google.com +include:mail.zendesk.com -all " "google-site-verification=XXXXXXXXXXXXXXXXX"

正しい対処では無い気がする。

SimpleSAMLphp で開発用の SAML ID Provider を立てる

SAML によるシングルサインオンに対応したアプリを作るときに、開発環境としてお手軽に試せる ID Provider があると便利なので、SimpleSAMLphp でタダで作る。

OneLogin のアカウントを持っている場合は、 "SAML Test Connector (IdP)" を使えば簡単に作れる。

確認環境

インストール

simpleSAMLphp Installation and Configuration を参考にインストールする。

ダウンロードした SimpleSAMLphp のアーカイブを /var/simplesamlphp に展開し、Apache の設定で

Alias /simplesaml /var/simplesamlphp/www

PHP などが正しくインストールされていれば http://hostname/simplesaml/ で以下の様な画面が見える。

f:id:suer:20151120140055p:plain

設定

admin ユーザのログインパスワード

// config/config.php
'auth.adminpassword' => 'test',

Web 画面でログインできるか確認する。

saml20-idp モジュールを有効化

// config/config.php
'enable.saml20-idp' => true,

Web 画面の設定タブの "SAML 2.0 IdP" が有効化されているか確認する。

認証方法を設定する(exampleauth)

### 有効化
$ touch modules/exampleauth/enable

ID = suerパスワード = test でログインできるようにしておく。

// config/authsources.php 
<?php
$config = array(
    'example-userpass' => array(
        'exampleauth:UserPass',
        'suer:test' => array(
            'uid' => array('suer'),
            'eduPersonAffiliation' => array('member', 'employee'),
        ),
    ),

自己証明書を作成

$ mkdir -p cert
$ cd cert
$ openssl req -newkey rsa:2048 -new -x509 -days 3652 -nodes -out server.crt -keyout server.pem

設定は

// metadata/saml20-idp-hosted.php 
        'privatekey' => 'server.pem',
        'certificate' => 'server.crt',

Service Provider の準備

ここでは確認のため、 GitHub - onelogin/java-saml: Java SAML toolkit の Sample アプリを使う。

$ git clone https://github.com/onelogin/java-saml.git
$ cd java-saml
$ mvn package -Dmaven.test.skip=true
$ cd sample
$ mvn jetty:run

Service Provider の登録

// metadata/saml20-sp-remote.php
$metadata['http://localhost:8080/index.jsp'] = array(
        'AssertionConsumerService' => 'http://localhost:8080/consume.jsp',
        'SingleLogoutService' => '',
        'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
        'simplesaml.nameidattribute' => 'uid',
        'simplesaml.attributes' => FALSE,
);

http://localhost:8080/index.jsphttp://localhost:8080/consume.jspjava-saml のサンプルアプリのアドレス。

Service Provider に登録する情報

Web ページの "連携" タブ > SAML 2.0 IdP メタデータの表示から確認

  • ID Provider の URL: md:SingleSignOnService#Location の値(http://xxxxxx/xxxxxx/saml2/idp/SSOService.php)
  • 証明書: ds:X509Certificate の値 をコピーするか、同ページからダウンロードすることもできる

java-saml のサンプルアプリに ID Provider を設定する

修正するのは以下の2箇所。

// src/main/webapp/index.jsp
accSettings.setIdpSsoTargetUrl("ID Provider の URL");
// src/main/webapp/consume.jsp
String certificateS = "証明書の内容";

確認

java-saml の sample フォルダで、

$ mvn jetty:run

ブラウザで http://localhost:8080/ にアクセスして、 SimpleSAMLphp 経由でシングルサインオンできれば成功。

一度目はログイン画面が表示される。 f:id:suer:20151120141659p:plain

ログインに成功した場合もしくは既にログイン済みの場合、consume.jsp 転送されて ID が表示される。 f:id:suer:20151120141829p:plain

Atom の Markdown Preview の中国語フォントを日本語フォントにする

環境

Atom 1.1.0

GitHub.com のスタイルに変更

  • Packages > Settings View > Open (もしくは ctrl+ ,)
  • packages タブから markdown-preview を検索して Settings ボタンをクリック
  • Use GitHub.com style をチェック

f:id:suer:20151109114035j:plain

プレビューのフォントを変更

  • Packages > Settings View > Open (もしくは ctrl+ ,)
  • Themes タブを開き your stylesheet をクリック

f:id:suer:20151109114254j:plain

  • style.less が開くので末尾に以下を追加
.markdown-preview, .markdown-preview[data-use-github-style] {
  font-family: "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

Redmine で Github のように草を生やすプラグインを作った

Redmine 内での活動を Github のように表示するプラグインです。

「活動」タブで見れる情報が対象となります。

プロジェクト全体の活動が見れるほか、担当者毎の活動も可視化できます。

環境

Redmine 3.0.x

インストール

1. 以下のようにプラグインをインストールする。

$ cd $RAILS_ROOT/plugins
$ git clone https://github.com/suer/redmine_glanceyear.git

2. Redmine を再起動

CentOS 5 32bit で fluent-agent-hydra を無理やり動かす

環境

  • CentOS 5.5 (Linux kernel 2.6.18)
  • Go 1.4.2
  • fluent-agent-hydra v0.1.3

問題

Go は CentOS 5 をサポートしていないせいか、 CentOS 5 32bit (Linux kernel 2.6.18) 上で fujiwara/fluent-agent-hydra · GitHub の32bit バイナリを動かすと以下のエラーを吐いて死ぬ。

# /usr/local/bin/fluent-agent-hydra -c /etc/fluent-agent-hydra.toml
2015/06/24 15:14:47 [info] Loading config file: /etc/fluent-agent-hydra.toml
2015/06/24 15:14:47 [info] set ReadBufferSize 1048576
2015/06/24 15:14:47 [info] Server localhost:24224 connected
2015/06/24 15:14:47 [info] ServerRoundRobin enabled
2015/06/24 15:14:47 [error] Couldn't create file watcher function not implemented
2015/06/24 15:14:47 [error] function not implemented
2015/06/24 15:14:47 [info] watching events of directory /var/log/httpd
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x80b3f01]

goroutine 1 [running]:
github.com/fujiwara/fluent-agent-hydra/hydra.(*Watcher).WatchFile(0x0, 0x1894a690, 0x1e, 0x1e, 0x0, 0x0)
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/hydra/in_tail.go:71 +0x151
github.com/fujiwara/fluent-agent-hydra/hydra.NewInTail(0x18944b40, 0x0, 0x18944c40, 0x18944c80, 0x18944c80, 0x0, 0x0)
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/hydra/in_tail.go:105 +0x94
main.run(0x18944880)
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/cmd/fluent-agent-hydra/main.go:127 +0x525
main.main()
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/cmd/fluent-agent-hydra/main.go:69 +0x869

goroutine 6 [syscall]:
os/signal.loop()
        /usr/local/Cellar/go/1.4.2/libexec/src/os/signal/signal_unix.go:21 +0x21
created by os/signal.init·1
        /usr/local/Cellar/go/1.4.2/libexec/src/os/signal/signal_unix.go:27 +0x34

goroutine 7 [chan receive]:
github.com/fujiwara/fluent-agent-hydra/hydra.(*Stats).Run(0x189a0580, 0x18944c80)
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/hydra/monitor.go:115 +0x48
created by github.com/fujiwara/fluent-agent-hydra/hydra.NewMonitor
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/hydra/monitor.go:134 +0x17b

goroutine 14 [runnable]:
github.com/fujiwara/fluent-agent-hydra/hydra.(*OutForward).Run(0x189a1360)
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/hydra/out_forward.go:44
created by main.run
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/cmd/fluent-agent-hydra/main.go:117 +0x96d

goroutine 13 [sleep]:
net.func·019()
        /usr/local/Cellar/go/1.4.2/libexec/src/net/dnsclient_unix.go:240 +0x54
created by net.loadConfig
        /usr/local/Cellar/go/1.4.2/libexec/src/net/dnsclient_unix.go:269 +0x1aa

問題の箇所

[error] Couldn't create file watcher function not implemented というエラーメッセージを頼りに追っていくと fsnotify が以下の箇所で syscall.Pipe2 を呼んでいるところでエラーが発生していることを突き止めた。

https://github.com/go-fsnotify/fsnotify/blob/6549b98005f3e4026ad9f50ef7d5011f40ba1397/inotify_poller.go#L47

修正

  • (注意1) Go の流儀をよく理解しないまま対応しているので、もっと良い方法があるかもしれない。
  • (注意2) NONBLOCK でなくなっているので性能が落ちる可能性がある

$GOPATH/src/gopkg.in/fsnotify.v1/inotify_poller.go

diff --git a/inotify_poller.go b/inotify_poller.go
index 3b41784..9f2b172 100644
--- a/inotify_poller.go
+++ b/inotify_poller.go
@@ -44,7 +44,7 @@ func newFdPoller(fd int) (*fdPoller, error) {
                return nil, errno
        }
        // Create pipe; pipe[0] is the read end, pipe[1] the write end.
-       errno = syscall.Pipe2(poller.pipe[:], syscall.O_NONBLOCK)
+       errno = syscall.Pipe(poller.pipe[:])
        if errno != nil {
                return nil, errno
        }

まとめ

さっさと CentOS 6 以上に上げよう。