Table of Contents
1 WebDAVをインストールする
- この記事ではhttpsの為にデフォルトのSSL/TLS証明書を使っています。別にSSL/TLS証明書を用意している場合はそちらをお使いください。
- SSLを利用するのでhttpsやdavsで接続してください。
- Digest認証を使用します。ユーザ名はWEBDAV_USERNAMEの値で、パスワードはWEBDAV_PASSWORDの値です。
#!/bin/shset -e[ -z “${WEBDAV_USERNAME}” ] && WEBDAV_USERNAME=webdav[ -z “${WEBDAV_PASSWORD}” ] && WEBDAV_PASSWORD=webdavsudo zypper -n in apache2sudo gensslcertcat <<EOF | sudo tee /etc/apache2/conf.d/webdav.confAlias /webdav /srv/www/webdavDAVLockDB /var/lib/webdav/DAVLock<VirtualHost _default_:443> SSLEngine on SSLCertificateFile /etc/apache2/ssl.crt/server.crt SSLCertificateKeyFile /etc/apache2/ssl.key/server.key</VirtualHost><Location /webdav> DAV On SSLRequireSSL AuthType Digest AuthName webdav AuthUserFile /etc/apache2/.webdav Require valid-user</Location>EOFsudo mkdir /srv/www/webdavsudo chown wwwrun:www /srv/www/webdavsudo mkdir /var/lib/webdavsudo chown wwwrun:www /var/lib/webdavfor t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do sudo sed -e “s/^${t}=”(.*)”/${t}=”1 apache2-ssl”/g” -i /etc/sysconfig/SuSEfirewall2donesudo systemctl restart SuSEfirewall2sudo a2enflag SSLfor mod in ssl dav dav_fs auth_digest; do sudo a2enmod ${mod}donesudo systemctl enable apache2sudo systemctl restart apache2# Create digest password file with expect command.sudo zypper -n in expectexpect -c “set timeout -1spawn sudo htdigest -c /etc/apache2/.webdav webdav ${WEBDAV_USERNAME}expect “New password: “send “${WEBDAV_PASSWORD}n”expect “Re-type new password: “send “${WEBDAV_PASSWORD}n”expect eof”
2 WebDAVへアクセスする
davfsのマウントを可能にするdavfs2パッケージをインストールします。
> O=http://download.opensuse.org> A=${O}/repositories/filesystems/openSUSE_Leap_42.2/> sudo zypper ar -f -n filesystems ${A} filesystems> sudo zypper -n –gpg-auto-import-keys ref> sudo zypper -n in davfs2
mount -t davfsでマウントします。証明書を組み込んでいないので警告がでます。
> sudo mount -t davfs https://localhost/webdav /mntPlease enter the username to authenticate with serverhttps://localhost/webdav or hit enter for none. Username: webdavPlease enter the password to authenticate user webdav with serverhttps://localhost/webdav or hit enter for none. Password:/sbin/mount.davfs: the server certificate does not match the server name/sbin/mount.davfs: the server certificate is not trusted issuer: CA, SUSE Linux Web Server, unknown, unknown, XY subject: web server, SUSE Linux Web Server, unknown, unknown, XY identity: opensuse-14.hiroom2.com fingerprint: cc:46:1a:43:3b:b2:ec:55:37:81:83:b6:61:54:91:46:23:67:e8:2fYou only should accept this certificate, if you canverify the fingerprint! The server might be fakedor there might be a man-in-the-middle-attack.Accept certificate for this session? [y,N] y
/mnt/hello.txtを書き込みます。
> echo hello | sudo tee /mnt/hello.txt
即座にファイルを反映させる為にアンマウントします。
> sudo umount /mnt
WebDAVのディレクトリにファイルが反映されています。
> sudo cat /var/www/webdav/hello.txthello