openSUSEでCalDAV *

スケジューラーとしてGoogle Calendarを使う人は多いが、セキュリティーの観点から自前のスケジュール管理環境を使いたいという人もいる。
そういう人向けのCalDAVとして、"Baïkal" がある。Baikalはwebサーバー経由でスケジュール管理機能を提供するアプリケーションである。
参考:https://github.com/jeromeschneider/Baikal/blob/master/INSTALL.md

必要なパッケージなど **

まず、Baikalのサービスが乗っかるwebサーバーが必要になるが、今回はwebサーバーとしてnginxを使う。
(手元環境はopenSUSE13.1-64bitなので、これを前提に記述 #はrootコンソール)

Baikalはphpで書かれているので、phpのモジュールが必要

php5-iconv-5.4.20-4.1.x86_64
php5-tokenizer-5.4.20-4.1.x86_64
php5-sqlite-5.4.20-4.1.x86_64
php5-ctype-5.4.20-4.1.x86_64
php5-json-5.4.20-4.1.x86_64
php5-fpm-5.4.20-4.1.x86_64 <--これが重要
php5-5.4.20-4.1.x86_64
php5-xmlreader-5.4.20-4.1.x86_64
php5-dom-5.4.20-4.1.x86_64
php5-xmlwriter-5.4.20-4.1.x86_64
php5-pdo-5.4.20-4.1.x86_64
php5-mbstring ※ これが大事 これでハマった

Baikaはデータベースとしてsqliteを使えるので、今回はsqlite3を利用

libsqlite3-0-32bit-3.7.17-2.1.2.x86_64
sqlite3-3.7.17-2.1.2.x86_64
libsqlite3-0-3.7.17-2.1.2.x86_64

php-fpm の設定 **

/etc/php5/fpm/php-fpm.conf を編集

nginxが動かすので稼働ユーザーをnginxに変更
#user = nobody
#group = nobody
user = nginx
group = nginx
listenは以下の2つから択一
稼働条件を指定 9000ポートで稼働
listen = 127.0.0.1:9000
unixドメインでやる場合は、必ず/var/run 以下に作らないとダメ
listen = /var/run/cal.sock <--ソケットファイルの場所※重要
listen.owner = nginx <-- ソケットファイルのオーナーユーザ
listen.group = nginx <-- ソケットファイルのオーナーグループ
listen.mode = 0660

※unixドメインを使う場合、何も考えずに /tmp/cal.sock などとやると永遠に接続できずハマる。
sysvinitからsystemdになって、PrivateTmp という機能が設けられており、nginxにも適用されている。
/usr/lib/systemd/system/nginx.service には PrivateTmp=true の記述がある。
nginxから/tmp に書き込んだとしても、/tmp/systemd-private-Nx4I0K みたいなところに
書き込まれる事になる。
もしphp-fpmの設定に、/tmp/cal.sock と指定した場合、ソケットファイルは /tmp 以下に作成されるが、
nginxからは、永遠に見えない事になる。

Baikal 本体のインストール **

http://baikal-server.com/ からダウンロードするが、Flat packageの方はローカルサーバーしか使えないので、
必ずRegular package の方をダウンロードする。
ダウンロードされたファイルは、baikal-regular-0.2.7.tgz のようなファイルになっている。

# gunzip baikal-regular-0.2.7.tgz
----->baikal-regular-0.2.7.tar 出現
# tar xvf baikal-regular-0.2.7.tar
----->baikal-regula 出現

baikal-regulaフォルダ構成 ***

ChangeLog.md
INSTALL.md
LICENSE.txt
README.md
TROUBLESHOOTING.md
UPGRADE.md
+Core
+html
+vendor
+Specific <=== こいつが重要なフォルダになる!
.htaccess
config.php
config.system.php
+db
+virtualhosts
baikal.apache2
baikal.nginx

Baikalの説明では、解凍したフォルダを、利用したいドメインに変更するように説明されている。(何故だ?)
今回は、cal.example.com というvirtualhostで運用することにして、同名にフォルダを変名する。
また、解凍したフォルダは、webサーバーの管理下に置くために移動させる。

# mv baikal-regular /srv/www/
# cd /srv/www
# mv baikal-regular cal.example.com
# cd cal.example.com

Specific へは、webサーバーの稼働ユーザーがアクセスできる必要がある。
今回はnginxを使うので、オーナーをnginxへ変更する

# chown -Rf nginx:nginx Specific

最初の起動のために・・・・絶対に忘れないでやること! **

Baikalは、Specific 以下に ENABLE_INSTALL というファイルを発見すると
初期設定を行うモードになるので、最初にこれを作成しておく。

# touch /srv/www/cal.example.com/Specific/ENABLE_INSTALL

nginxでの設定 **

Specific/virtualhosts 以下に、baikal.nginx のサンプルがあるので、これを参考にする。
(今回は、cal.example.com という仮想サーバーとして利用する前提)

nginxの設定ファイル /etc/nginx/nginx.conf を編集

http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;

server {
listen 80 default_server;
server_name _;
return 444;
}

server {
listen 80;
#server_name localhost;
server_name localhost
host.example.com;
root /srv/www/htdocs;
index index.html index.htm;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
 
location /* {
root /srv/www/htdocs/;
index index.html index.htm;
autoindex on;
allow 127.0.0.1;
allow 192.168.1.2; <=== 接続許可したい内部クライアントなど指定
allow 192.168.1.3;
deny all;
}

#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
# 
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /srv/www/htdocs/;
}
 
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
# 
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# 
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
# 
location ~ /\.ht {
deny all;
}
}

include vhosts.d/*.conf; <=== これが重要
}

/etc/nginx/vhosts.d/baikal.conf というファイルを作成する **

server {
listen 80;
server_name cal.example.com; <=== 改名したフォルダを指定
root /srv/www/cal.example.com/html; <=== baikaiパッケージフォルダのhtmlフォルダが、仮想ホストのrootになる
index index.php;
rewrite ^/.well-known/caldav /cal.php redirect;
rewrite ^/.well-known/carddav /card.php redirect;
charset utf-8;
 
location ~ /(\.ht|Core|Specific) {
deny all;
return 404;
}

location ~ ^(.+\.php)(.*)$ {
try_files $fastcgi_script_name =404;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000; <=== ここのポートはnginxとbaikalの橋渡しをするポートになる tcpを使うので注意!! 
fastcgi_pass unix:/var/run/cal.sock; <==unixのドメインソケットの場合 (※注意)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include /etc/nginx/fastcgi_params;
}
 
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /srv/www/htdocs/;
}

location /* {
allow 127.0.0.1;
allow 192.168.1.2; <=== 接続許可したい内部クライアントなど指定
allow 192.168.1.3;
deny all;
}

}

稼働させる **

最初に、nginxを稼働させる

# systemctl start nginx.service

次に、 php-fpm.service を稼働させる。
(nginxの稼働は忘れることはないが、こいつは忘れやすいので注意!!)

# systemctl start php-fpm.service

初期設定 **

ここからは、Baikalの初期設定(管理者や利用ユーザーの作成)を行う。
http://cal.example.com/admin/ へブラウザ経由でアクセス

値入力は、以下を参考にして行う。***

Server Time zone: Asia/Tokyo
Enable CalDAV : check!
Enable CardDAV : check!
Admin password : pasword
confirmation : password
Enable Web Interface : check!

次に利用DBの環境構築を聞いてくるが、今回はsqliteを使う ***

そのまま [Save changes] を押す
画面が切り替わり、[Strt using Baikal] ボタンが出たら 押す

再ログイン後、利用ユーザーの追加とカレンダー作成を行う。(ここでは省略)
設定したユーザー名: user0
※ 以下のクライアント設定では、user0で説明するので置き換え必要

クライアント設定**

Thunderbird lightning ***

Baikalは、Thunderbirのlightningプラグインで使うことができる。
Thunderbirdであれば、WindowsでもopenSUSEでも、MacOSXでも使えた。

カレンダー名:好きな名前をつけて良いみたいだ
場所:http://cal.example.com/cal.php/calendars/user0/default
更新:好きな時間
アラーム通知:オン
オフラインサポート:オン(よくわからない)

mac カレンダー ***

アカウントを新規作成

説明:好きな名前
ユーザー:user0
パスワード:パスワード
更新:好きな時間

アドレス:cal.example.com
パス:/cal.php/principals/user0/
ポート:80

※macの場合は、calendarsのところがprincipalsになる点と、defaultの指定がいらないことがポイント

Android ***

androidの場合、Caldav Sync Free Adapter という無料のアプリがあるので、これを使う
https://play.google.com/store/apps/details?id=org.gege.caldavsyncadapter&hl=ja
https://github.com/gggard/AndroidCaldavSyncAdapater
https://github.com/gggard/AndroidCaldavSyncAdapater/wiki/Installation-and-configuration

カレンダーのメニューから、新規アカウントを作成する
メニュー/システム/アカウント/追加
この時、どのタイプのアカウントを作成するか効かれるので、 CalDav Sync Adapter を選択する。

ユーザー定義では

user:user0
pssword: パスワード
URL http://cal.example.com/cal.php/principals/user0

と、macと同じように、principals/usr0 を使ってセットする。
(もしかしたら、ユーザー名で弾かれるかもしれないので、その時は、user0@example.com とメールアドレス風に設定する)


カテゴリ: サーバ

Last-modified: 2018-03-28 (水) 17:59:57 (2219d)