buster – matoken's blog https://matoken.org/blog Is there no plan B? Wed, 10 Aug 2022 04:58:53 +0000 ja hourly 1 https://wordpress.org/?v=6.8.1 https://matoken.org/blog/wp-content/uploads/2025/03/cropped-1865f695c4eecc844385acef2f078255036adccd42c254580ea3844543ab56d9-32x32.jpeg buster – matoken's blog https://matoken.org/blog 32 32 WordPressをTwo-Factorで2要素認証を有効にする https://matoken.org/blog/2022/08/10/enable-wordpress-for-two-factor-authentication-with-two-factor/ https://matoken.org/blog/2022/08/10/enable-wordpress-for-two-factor-authentication-with-two-factor/#respond Wed, 10 Aug 2022 12:58:03 +0000 http://matoken.org/blog/?p=3763

このサイトは現在WordPressで管理されています.メジャーなアプリケーションなので攻撃も多いです.パスワードを少し長く二十数文字にしていますが少し不安.ということで多要素認証を使うことにしました.

一般的なTOTPとバックアップコードに対応しているものを探してみました.

TOTPで検索すると沢山出てきます.よく使われていそうなTwo-Factor を試してみます.

WordPressにログインした状態で,「サイトネットワーク管理者」→「プラグイン」でプラグインページに移動.
「新規追加」を押してプラグイン検索画面に遷移するのでキーワードに「TOTP」と入れて検索して「Two-Factor」を「今すぐインストール」ボタンで導入.導入が終わるとボタンが「ネットワークで有効化」になるのでこれも押して有効にします.

自サイトのPluginページで「Two Factor」が有効になっているのを確認,「ユーザー」→「あなたのプロフィール」の「Two-Factor 設定」でTOTPのコードを自分の利用しているアプリに登録してコードを登録して有効にします.TOTPの他にメールとバックアップコード(保存しておきます)も有効にしました.

wordpress 2fa setting01
wordpress 2fa setting02
wordpress 2fa login

別のブラウザでTOTPとメール,バックアップコードでログインできるのを確認.とりあえずOKそうです.

TOTPの計算にはoathtoolを使った自作scriptを利用しています.KEYは暗号化して実行時に一時的に復号しています.

$ oathtool --totp -b FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
346419
$ 2auth-cli.sh blog
Password:
matoken@matoken.org/blog : 590604

パスワードのみよりは安心になったかな?

Note
管理画面をlocalhostのみアクセス可能にしてポート転送にしてしまってもいいかな?
環境
$ dpkg-query -W wordpress
wordpress       5.0.15+dfsg1-0+deb10u1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/08/10/enable-wordpress-for-two-factor-authentication-with-two-factor/feed/ 0
Nextcloudが要件以上のPHPバージョンを求めてきて動かなくなった https://matoken.org/blog/2022/07/20/nextcloud-stopped-working-asking-for-a-php-version-that-exceeded-the-requirements/ https://matoken.org/blog/2022/07/20/nextcloud-stopped-working-asking-for-a-php-version-that-exceeded-the-requirements/#respond Tue, 19 Jul 2022 21:24:06 +0000 http://matoken.org/blog/?p=3725

Nextcloudが動かなくなりました.
アクセスすると以下のようなエラーメッセージが表示されて動きません.

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.4.0".

Nextcloud
内部サーバーエラー
サーバーは要求を完了できませんでした。

再びこのようなことが起こった場合は、以下の技術情報をサーバー管理者に送ってください。

詳細は、サーバーのログを確認してください。

技術詳細
リモートアドレス: 180.131.110.140
リクエスト ID: QkMNcL7xRrQwxESLUU9Y

nextcloud php7.4

Nextcloudのバージョンアップはしていません.sourceを少し見ると7.3以上で大丈夫そうです.

lib/versioncheck.php:
if (PHP_VERSION_ID < 70300) {
        http_response_code(500);
        echo 'This version of Nextcloud requires at least PHP 7.3<br/>';
        echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.';
        exit(1);
}

NextcloudのISSUEを探すと以下のようなものを見つけました.

ここでは,Pollsを3.5に上げるとPHP 7.4以上を求めるようになってしまう,PHPを7.4以上にするかPollsをダウングレードすると直るという感じのようです.
そういえばNextcloudのメンテとしてアプリケーション更新はしていたのでこのレが当てはまっていそうです.この環境はDebian busterでphpは7.3です.Bullseyeに上げるとphp 7.4になりますが未だ準備が出来ていません.

$ rmadison php
php        | 1:7.0+49      | oldoldstable | all
php        | 2:7.3+69      | oldstable    | all
php        | 2:7.4+76      | stable       | all
php        | 2:8.1+92      | testing      | all
php        | 2:8.1+92      | unstable     | all
php        | 2:8.2+93~exp1 | experimental | all

ということでアプリケーションのダウングレードを行いました.

$ sudo -u www-data php ./occ app:disable polls (1)
$ sudo -u www-data php ./occ app:remove polls (2)
$ wget https://github.com/nextcloud/polls/releases/download/v3.4.2/polls.tar.gz -O /tmp/polls.tar.gz (3)
$ sudo -u www-data tar xvf /tmp/polls.tar.gz -C ./apps/ (4)
$ sudo -u www-data php ./occ app:enable polls (5)
$ rm /tmp/polls.tar.gz
  1. pullsを無効化
  2. pullsを削除
  3. pulls 3.4.2をダウンロード
  4. pulls 3.4.2を展開
  5. pullsを有効化

自分の環境ではこれだけでは治らなかったです.
以下のようにアプリケーション中から7.4を求めるものを探して同様に無効化,削除,旧バーションのダウンロードと展開,有効化を行い治りました.

$ sudo -u www-data find ./apps -type f -iname "*.php" -print0 | xargs -0 grep "70400"

Nextcloudの要件以上をアプリケーションで求め,インストールできてしまうというのは初めて遭遇しました.少し気をつけないといけませんね.
そして早めにDebian Bullesyeに上げてPHPを7.4にしたいところです.

Note

PHPのsiteから7.4を入手して設定も有りかもですがメンテナンスコストが上がってしまいますね…….

環境
$ sudo -u www-data php ./occ --version
Nextcloud 23.0.7
$ php -v
PHP 7.3.31-1~deb10u1 (cli) (built: Oct 24 2021 15:18:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.31, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.31-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/07/20/nextcloud-stopped-working-asking-for-a-php-version-that-exceeded-the-requirements/feed/ 0
moshに繋がらなくなった(localeが不足していた) https://matoken.org/blog/2022/07/12/not-connected-to-mosh/ https://matoken.org/blog/2022/07/12/not-connected-to-mosh/#respond Tue, 12 Jul 2022 14:49:26 +0000 http://matoken.org/blog/?p=3718

リモートのmoshに繋がらなくなってしまいました.sshの認証後に失敗しています.
sshでは繋がります.

以下はmoshでssh認証以降のメッセージです.接続元で ja_JP.UTF-8 を使っているのでmoshサーバでもそれを使おうとして見つからずに失敗していそうです.

Authenticated to 192.0.2.5 (via proxy) using "publickey".
bash: warning: setlocale: LC_ALL: cannot change locale (ja_JP.UTF-8)
The locale requested by LC_ALL=ja_JP.UTF-8 isn't available here.
Running `locale-gen ja_JP.UTF-8' may be necessary.

The locale requested by LC_ALL=ja_JP.UTF-8 isn't available here.
Running `locale-gen ja_JP.UTF-8' may be necessary.

mosh-server needs a UTF-8 native locale to run.

Unfortunately, the local environment (LC_ALL=ja_JP.UTF-8) specifies
the character set "US-ASCII",

The client-supplied environment (LC_ALL=ja_JP.UTF-8) specifies
the character set "US-ASCII".

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=ja_JP.UTF-8
LANGUAGE=
LC_CTYPE="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.UTF-8"
LC_COLLATE="ja_JP.UTF-8"
LC_MONETARY="ja_JP.UTF-8"
LC_MESSAGES="ja_JP.UTF-8"
LC_PAPER="ja_JP.UTF-8"
LC_NAME="ja_JP.UTF-8"
LC_ADDRESS="ja_JP.UTF-8"
LC_TELEPHONE="ja_JP.UTF-8"
LC_MEASUREMENT="ja_JP.UTF-8"
LC_IDENTIFICATION="ja_JP.UTF-8"
LC_ALL=ja_JP.UTF-8
Connection to 192.0.2.5 closed.
Transferred: sent 3232, received 4688 bytes, in 3.3 seconds
Bytes per second: sent 975.2, received 1414.6
/usr/bin/mosh: Did not find mosh server startup message. (Have you installed mosh on your server?)

試しに LC_ALL=en_US.UTF-8 を渡すと接続できました.

$ LC_ALL=en_US.UTF-8 mosh $SERVER

sshで接続して確認すると en_US.UTF-8 しか設定されていません.

$ grep -v ^# /etc/locale.gen


en_US.UTF-8 UTF-8

ja_JP.UTF-8 とついでに ja_JP.EUC-JP を追加して, locale-gen コマンドでlocaleを生成しました.

$ sudo vi /etc/locale.gen
$ sudo git diff /etc/locale.gen
diff --git a/locale.gen b/locale.gen
index afb6141..0f91c36 100644
--- a/locale.gen
+++ b/locale.gen
@@ -286,7 +286,7 @@ en_US.UTF-8 UTF-8
 # it_IT.UTF-8 UTF-8
 # it_IT@euro ISO-8859-15
 # iu_CA UTF-8
-# ja_JP.EUC-JP EUC-JP
-#  ja_JP.UTF-8 UTF-8
+ja_JP.EUC-JP EUC-JP
+ja_JP.UTF-8 UTF-8
 # ka_GE GEORGIAN-PS
 # ka_GE.UTF-8 UTF-8
 # kab_DZ UTF-8
$ sudo locale-gen
Generating locales (this might take a while)...
  en_US.UTF-8... done
  ja_JP.EUC-JP... done
  ja_JP.UTF-8... done
Generation complete.

この状態で再度 LC_ALL=ja_JP.UTF-8 の状態でmoshで接続してみるとうまく接続できるようになりました :)
以前は繋げていたのでいつの間にか /etc/locale.gen を書き換えてしまっていた?

/etc はetckeeperでgit管理しているので探してみると,locales 2.28-10locales 2.28-10+deb10u1 の更新時に ja_JP.UTF-8 UTF-8 がコメントアウトされていました.確認不足ですね><

環境
$ dpkg-query -W mosh locales
locales 2.28-10+deb10u1
mosh    1.3.2-2.1+b1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/07/12/not-connected-to-mosh/feed/ 0
Apache httpd 2.4でも503を返すようにする https://matoken.org/blog/2022/07/12/apache-httpd-2-4-return-503/ https://matoken.org/blog/2022/07/12/apache-httpd-2-4-return-503/#respond Tue, 12 Jul 2022 14:15:27 +0000 http://matoken.org/blog/?p=3715

自宅サーバが起動しなくなったのでLighttpdで全ページ503を返すようにしました.

思ったよりアクセスが多いのでアクセスの多いドメインのDNSを変更して外のサーバに向けることにしました.
このサーバはApache httpdが動いているのでLighttpdと同じ設定は使えないので少し調べて設定してみました.

対象ドメインの設定を作成.ここでは「 sub1.example.org 」としています.

`/etc/apache2/sites-enabled/090-sub1.example.org.conf
<VirtualHost *:80>
        ServerName sub1.example.org
        Redirect permanent / https://sub1.example.org/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName sub1.example.org
        ServerAdmin webmaster@example.org
        DocumentRoot /var/www/sub1.example.org/
        RedirectMatch 503 ^/(?!503\.html) (1)
        ErrorDocument 503 /503.html
        ErrorLog ${APACHE_LOG_DIR}/error_sub1.example.org.log
        CustomLog ${APACHE_LOG_DIR}/access_sub1.example.org.log combined
        SSLCertificateFile /etc/letsencrypt/live/sub1.example.org/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/sub1.example.org/privkey.pem
</VirtualHost>
</IfModule>
  1. すべてのURLを /503.html に転送します.

対象ドメインの証明書を旧サーバからコピーしておきます.

ディレクトリ作成
$ sudo mkdir -p /etc/letsencrypt/tmp/sub1.example.org/

リモートサーバの /etc/letsencrypt/live/sub1.example.org/fullchain.pem/etc/letsencrypt/live/sub1.example.org/privkey.pem/etc/letsencrypt/tmp/sub1.example.org/ 以下に置く.

権限設定してリンクを貼ります.
$ sudo chown -R root.ssl-cert /etc/letsencrypt
$ sudo ln -s /etc/letsencrypt/tmp/sub1.example.org/fullchain.pem /etc/letsencrypt/live/sub1.example.org/fullchain.pem
$ sudo ln -s /etc/letsencrypt/tmp/sub1.example.org/privkey.pem /etc/letsencrypt/live/sub1.example.org/privkey.pem

503用のhtmlを用意しておきます.

$ sudo -u www-data mkdir /var/www/sub1.example.org
$ sudo -u www-data vi /var/www/sub1.example.org/503.html

apache httpd再起動

$ sudo service apache2 restart

DNS書き換え前に検証の行えるローカルのPCのhosts書き換えて動作テスト.

$ echo "192.0.2.5 sub1.example.org" | sudo tee -a /etc/hosts (1)
$ w3m -dump_head head http://sub1.example.org/piyo | grep ^HTTP/ (2)
HTTP/1.1 503 Service Unavailable
$ w3m -dump_extra head http://sub1.example.org/piyo | lv (3)
  1. 新しいサーバのIPアドレスを指定する.
  2. 503が帰ってくることを確認
  3. 証明書も確認

動作確認が出来たら /etc/hosts を戻しておく.

この後,DNS書き換えを行いDNSが伝播してから再度動作確認を行う.

対象ドメインのSSL証明書更新もしておく.

$ sudo certbot certonly -d sub1.example.org

という感じでサーバ移行しました.
それまで自宅に9000アクセスほど有りましたが8500程は外のサーバに行くようになりました.

環境
$ dpkg-query -W apache2 certbot
apache2 2.4.38-3+deb10u7
certbot 0.31.0-1+deb10u1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/07/12/apache-httpd-2-4-return-503/feed/ 0
YouTube動画をダウンロードして無音部分をカットしたオーディオデータにして聞く https://matoken.org/blog/2022/03/13/ownload-youtube-video-and-listen-to-it-as-audio-data-with-silence-cut/ https://matoken.org/blog/2022/03/13/ownload-youtube-video-and-listen-to-it-as-audio-data-with-silence-cut/#respond Sun, 13 Mar 2022 14:40:28 +0000 http://matoken.org/blog/?p=3531

オープンソースカンファレンス2022 Online Springに参加しました.

ビデオミーティングソフトウェアのZoomとYouTube Liveを使っています.セッションは複数トラックあって同時に参加するのは難しいです.ほとんどのセッションは後日YouTubeで公開されますが,YouTube Liveの動画をリモートのサーバで録画しておいたのでこれをスマートフォンで移動中などに聞けるようにしてみました.

YouTubeの動画ダウンロードにはyoutube-dlやyt-dlpが便利です.セッション毎に起動しておきました.

$ youtube-dl ${URL}
$ yt-dlp ${URL}

今回ダウンロードした動画はvp9+aacのようです.

$ ffprobe -i ./YOUTUBEFILE.mkv 2>&1 | grep ^Input -A99
Input #0, matroska,webm, from './YOUTUBEFILE.mkv':
  Metadata:
    HTTP://YOUTUBE.COM/STREAMING/OTF/DURATIONS/112015: Segment-Count: 6109
                    : Segment-Durations-Ms: 5067,5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),5066,5067(r=1),506
                    :
                    :
    ENCODER         : Lavf58.20.100
  Duration: 08:35:50.04, start: 0.000000, bitrate: 551 kb/s
    Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709/unknown/unknown), 1280x720, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      DURATION        : 08:35:49.996000000
    Stream #0:1(eng): Audio: aac (LC), 44100 Hz, stereo, fltp (default)
    Metadata:
      HANDLER_NAME    : ISO Media file produced by Google Inc.
      DURATION        : 08:35:50.040000000

ffmpegで音声だけを抜き出してみます.

$ ffmpeg -i ./YOUTUBEFILE.mkv -vn -acodec copy ./YOUTUBEFILE.aac

元ファイルが2GBほどに対して500MBほどのファイルになりました.
ちょっと大きいのでコーデックをopusに変更してみます.

$ ffmpeg -i ./YOUTUBEFILE.mkv -vn -acodec libopus -b:a 64k ./YOUTUBEFILE.opus

213MB程になりました.
これをローカルにダウンロードして再生してみるとセッション間の無音部分が気になります.無音部分をカットできないかなと探すと,ffmpegのフィルタにそれらしい silenceremove というフィルタがあったので試してみました.

とりあえずexampleを真似して,先頭から最後までの間の1秒以上の無音部分をカットします.ついでにビットレートも32kに下げました.

$ ffmpeg -i ./YOUTUBEFILE.mkv -vn -af silenceremove=stop_periods=-1:stop_duration=1:stop_threshold=-90dB -acodec libopus -b:a 32k ./YOUTUBEFILE.opus

動画ファイルの長さが 08:35:50.040000000 から 07:55:03.66 になりました.ファイルサイズは107MB程です.

ついでにもう少し低いビットレートも試しました.

ビットレート 容量

32k

107324kB

24k

82484kB

16k

56380kB

少し聞いた感じでは16kでも問題無さそうな感じです.大本のZoomが確か24kなので24k以上はあまり意味がない気がします.

追記)高音質化機能があるようなので動画によって変わりそうです:

High Fidelity Audio mode – Windows, macOS
This option in Advanced Audio enhances “Original Audio” mode, allowing for disabling echo cancellation & post-processing, while raising audio codec quality to 48Khz, 96Kbps mono/192kbps stereo for professional audio transmis
sion in music education and performance applications. Professional audio interface, microphone, and headphones required.

Release notes for September 1
2020 – Zoom Support https://support.zoom.us/hc/en-us/articles/360048388632-New-Updates-for-September-1-2020

ということで他のセッションも同様に変換してAndroidスマートフォンに転送してVLCで1.5倍再生してみて画面スリープで再生できるのを確認しました.これで空き時間に聞けるようになりました :)

youtube2audio

応用としてYouTubeのRSSから動画をダウンロードして音声のみにしてその音声をRSSに埋め込んで公開するとPodcastアグリゲーターで購読できるので便利かもしれません.人の動画を勝手に一般公開するとまずいでしょうが.

環境
$ youtube-dl --version
2021.12.17
$ yt-dlp --version
2022.03.08.1
$ dpkg-query -W ffmpeg
ffmpeg  7:4.1.8-0+deb10u1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/03/13/ownload-youtube-video-and-listen-to-it-as-audio-data-with-silence-cut/feed/ 0
nitterのアップグレードメモ(2022-03) https://matoken.org/blog/2022/03/11/nitter-upgrade-note2022-03/ https://matoken.org/blog/2022/03/11/nitter-upgrade-note2022-03/#respond Fri, 11 Mar 2022 14:24:21 +0000 http://matoken.org/blog/?p=3524

Nitterをセルフホストしています.

最新に追従しているのですが,以前と少し手順が変わっているので上の記事に補足する形でメモしておきます.

sourceの更新とビルド準備
$ sudo su - nitter	(1)
$ cd ~/nitter	(2)
$ git pull	(3)
$ pandoc ./README.md -o - | w3m -T text/htm
$ export PATH=~/nim-1.6.4/bin:${PATH}	(4)
$ echo $PATH
/home/nitter/nim-1.6.4/bin:/home/nitter/bin:/usr/local/bin:/usr/bin:/bin
$ nim -v	(5)
Nim Compiler Version 1.6.4 [Linux: amd64]
Compiled at 2022-02-09
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 7994556f3804c217035c44b453a3feec64405758
active boot switches: -d:release
  1. nitter アカウントに変更
  2. nitter のsourceディレクトリへ移動
  3. nitter のsourceをpull
  4. 一時的に nim の PATH を通す
  5. nim が使いたいバージョンに向いているのを確認
nitterのbuildと設定
$ nimble build -d:release
$ nimble scss
$ vi public/md/about.md	(1)
$ nimble md	(2)
$ diff -u ./nitter.example.conf ./nitter.conf	(3)
--- ./nitter.example.conf       2022-02-15 00:03:01.628730418 +0900
+++ ./nitter.conf       2022-03-11 22:53:41.944448701 +0900
@@ -1,11 +1,11 @@
 [Server]
-address = "0.0.0.0"
-port = 8080
-https = false  # disable to enable cookies when not using https
+address = "localhost"
+port = 8081
+https = true  # disable to enable cookies when not using https
 httpMaxConnections = 100
 staticDir = "./public"
 title = "nitter"
-hostname = "nitter.net"
+hostname = "nitter.matoken.org"

 [Cache]
 listMinutes = 240  # how long to cache list info (not the tweets, so keep it high)
@@ -25,6 +25,7 @@
 enableRSS = true  # set this to false to disable RSS feeds
 enableDebug = false  # enable request logs and debug endpoints
 proxy = ""  # http/https url, SOCKS proxies are not supported
+#proxy = "http://153.121.44.87:8888"  # http/https url, SOCKS proxies are not supported
 proxyAuth = ""
 tokenCount = 10
 # minimum amount of usable tokens. tokens are used to authorize API requests,
@@ -42,4 +43,4 @@
 replaceInstagram = ""
 proxyVideos = true
 hlsPlayback = false
-infiniteScroll = false
+infiniteScroll = true
$ vi ./nitter.conf
$ exit
$ sudo service nitter restart
  1. 必要なら ${NITTER_URL}/about の元になる about.md を編集
  2. markdownをhtmlに変換(about.md以外のファイルをおいても変換されるが表示は出来ない?)
  3. nitter.conf を確認して設定の増減があったら追従する

以前はなかったabout.mdはこのインスタンスは誰が管理していますと書いておくのもいいかなと思います.
設定のproxyを使うと,Twitterにアクセス制限されたときに簡単に切り替えることができそうです.

環境
$ git -C ~nitter/nitter log -1
commit 2dc91f8453ce904d1b07a933e8a1dc970d788c41 (HEAD -> master, origin/master, origin/HEAD)
Merge: ecb6fe4 9b97ddc
Author: Zed <zedeus@pm.me>
Date:   Thu Mar 10 16:46:14 2022 +0100

    Merge pull request #571 from jackyzy823/fix-listmember

     Fix list members not displaying
$ w3m -dump http://localhost:8081/about | grep ^Version\
Version 2022.03.10-2dc91f8
$ nim -v
Nim Compiler Version 1.6.4 [Linux: amd64]
Compiled at 2022-02-09
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 7994556f3804c217035c44b453a3feec64405758
active boot switches: -d:release
$ dpkg-query -W apache2 redis* libsass-dev certbot
apache2 2.4.38-3+deb10u7
certbot 0.31.0-1+deb10u1
libsass-dev:amd64       3.5.5-4
redis-server    5:5.0.14-1+deb10u2
redis-tools     5:5.0.14-1+deb10u2
 lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/03/11/nitter-upgrade-note2022-03/feed/ 0
Nextcloud 21のセキュリティ&セットアップ警告の修正 default_phone_region(電話地域)を設定 https://matoken.org/blog/2021/07/09/nextcloud-21-default-phone-region-setting/ https://matoken.org/blog/2021/07/09/nextcloud-21-default-phone-region-setting/#comments Thu, 08 Jul 2021 22:34:38 +0000 http://matoken.org/blog/?p=3296

Nextcloud 21でセキュリティ&セットアップ警告を確認して修正しました.

管理者アカウントで「設定」→「管理」の「概要」から「セキュリティ&セットアップ警告」を確認します.

今回は1件の警告がありました.

NC21 setup warning01

セットアップに関して警告がいくつかあります。
ご使用のシステムには、デフォルトの電話地域が設定されていません。これは、国コードなしでプロファイル設定の電話番号を検証するために必要です。国コードなしで番号を許可するには、地域のそれぞれの ISO3166-1コード↗とともに “default_phone_region” を設定ファイルに追加してください。

新しい設定項目が増えたようです. config.php に電話地域の設定( default_phone_region )が必要になったようです.

まずは,以下のページを参考に自分の設定したい地域の地域コードを確認します.自分はジホンに設定したいので,Japanのところを見ました. JP のようです.

JP Japan 1974 .jp ISO 3166-2:JP

次に以下の文章を参考に,${NEXTCLOUDPATH}/config/config.php$CONFIG = array の中の適当な部分に 'default_phone_region' ⇒ 'JP', を追記します.

再度「セキュリティ&セットアップ警告」を再読込して警告が消えていたらOKです.

NC21 setup warning02

環境
$ sudo -u www-data php ${NEXTCLOUDPATH}/occ --version
Nextcloud 21.0.3
$ dpkg-query -W php apache2 mariadb-server
apache2 2.4.38-3+deb10u4
mariadb-server  1:10.3.29-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2021/07/09/nextcloud-21-default-phone-region-setting/feed/ 1
Nextcloud 21のアップデートに失敗(非対応アプリの無効化) https://matoken.org/blog/2021/07/09/nextcloud-21-update-fail/ https://matoken.org/blog/2021/07/09/nextcloud-21-update-fail/#respond Thu, 08 Jul 2021 22:16:37 +0000 http://matoken.org/blog/?p=3292

Nextcloud 21.02から21.0.3にアップデートしました.
しかしアップデート終了後に動作しなくなってしまいました.非対応アプリがあったせいだったのでそれを無効化して復活しました.

いつものように occ コマンドでアップデートを行いました.

$ sudo -u www-data php ${NEXTCLOUDPATH}/updater/updater.phar
Nextcloud Updater - version: v20.0.0beta4-11-g68fa0d4

Current version is 21.0.2.

Update to Nextcloud 21.0.3 available. (channel: "stable")
Following file will be downloaded automatically: https://download.nextcloud.com/server/releases/nextcloud-21.0.3.zip
Open changelog ↗

Steps that will be executed:
[ ] Check for expected files
[ ] Check for write permissions
[ ] Create backup
[ ] Downloading
[ ] Verify integrity
[ ] Extracting
[ ] Enable maintenance mode
[ ] Replace entry points
[ ] Delete old files
[ ] Move new files in place
[ ] Done

Start update? [y/N] y

Info: Pressing Ctrl-C will finish the currently running step and then stops the updater.

[✔] Check for expected files
[✔] Check for write permissions
[✔] Create backup
[✔] Downloading
[✔] Verify integrity
[✔] Extracting
[✔] Enable maintenance mode
[✔] Replace entry points
[✔] Delete old files
[✔] Move new files in place
[✔] Done

Update of code successful.

Should the "occ upgrade" command be executed? [Y/n]
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade

  : (1)

2021-07-07T13:51:49+00:00 Starting code integrity check...
2021-07-07T13:52:09+00:00 Finished code integrity check
2021-07-07T13:52:09+00:00 Update successful
2021-07-07T13:52:09+00:00 Maintenance mode is kept active
2021-07-07T13:52:09+00:00 Resetting log level

Keep maintenance mode active? [y/N]
Maintenance mode disabled

Maintenance mode is disabled
  1. 中略

するとNextcloudが動作しなくなりました.occコマンドも使えなくなっています.files_external_dropbox アプリが怪しそうなのでこれを無効化したいのですが,occコマンド自体が動かなくなっているしWebも動作しないので無効化できません.

$ sudo -u www-data php /var/www/files.matoken.org/occ app:disable files_external_dropbox
An unhandled exception has been thrown:
Error: Undefined class constant 'MAJOR_VERSION' in /var/www/files.matoken.org/3rdparty/guzzlehttp/guzzle/src/Utils.php:118
Stack trace:
#0 /var/www/files.matoken.org/3rdparty/guzzlehttp/guzzle/src/functions.php(71): GuzzleHttp\Utils::defaultUserAgent()
#1 /var/www/files.matoken.org/apps/files_external_dropbox/vendor/guzzlehttp/guzzle/src/Client.php(194): GuzzleHttp\default_user_agent()
#2 /var/www/files.matoken.org/apps/files_external_dropbox/vendor/guzzlehttp/guzzle/src/Client.php(75): GuzzleHttp\Client->configureDefaults(Array)
#3 /var/www/files.matoken.org/lib/private/Http/Client/ClientService.php(62): GuzzleHttp\Client->__construct()
#4 /var/www/files.matoken.org/lib/private/OCS/DiscoveryService.php(55): OC\Http\Client\ClientService->newClient()
#5 /var/www/files.matoken.org/lib/private/Server.php(1264): OC\OCS\DiscoveryService->__construct(Object(OC\Memcache\Factory), Object(OC\Http\Client\ClientService))
#6 /var/www/files.matoken.org/lib/private/AppFramework/Utility/SimpleContainer.php(155): OC\Server->OC\{closure}(Object(OC\Server))
#7 /var/www/files.matoken.org/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#8 /var/www/files.matoken.org/lib/private/AppFramework/Utility/SimpleContainer.php(122): Pimple\Container->offsetGet('OCP\\OCS\\IDiscov...')
#9 /var/www/files.matoken.org/lib/private/ServerContainer.php(137): OC\AppFramework\Utility\SimpleContainer->query('OCP\\OCS\\IDiscov...', false)
#10 /var/www/files.matoken.org/lib/private/AppFramework/DependencyInjection/DIContainer.php(434): OC\ServerContainer->query('OCP\\OCS\\IDiscov...', true)
#11 /var/www/files.matoken.org/lib/private/AppFramework/Utility/SimpleContainer.php(87): OC\AppFramework\DependencyInjection\DIContainer->query('OCP\\OCS\\IDiscov...', true)
#12 [internal function]: OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(ReflectionParameter))
#13 /var/www/files.matoken.org/lib/private/AppFramework/Utility/SimpleContainer.php(101): array_map(Object(Closure), Array)
#14 /var/www/files.matoken.org/lib/private/AppFramework/Utility/SimpleContainer.php(109): OC\AppFramework\Utility\SimpleContainer->buildClass(Object(ReflectionClass))
#15 /var/www/files.matoken.org/lib/private/AppFramework/Utility/SimpleContainer.php(126): OC\AppFramework\Utility\SimpleContainer->resolve('OCA\\Federation\\...')
#16 /var/www/files.matoken.org/lib/private/AppFramework/DependencyInjection/DIContainer.php(459): OC\AppFramework\Utility\SimpleContainer->query('OCA\\Federation\\...')
#17 /var/www/files.matoken.org/lib/private/AppFramework/DependencyInjection/DIContainer.php(431): OC\AppFramework\DependencyInjection\DIContainer->queryNoFallback('OCA\\Federation\\...')
#18 /var/www/files.matoken.org/lib/private/AppFramework/Utility/SimpleContainer.php(87): OC\AppFramework\DependencyInjection\DIContainer->query('OCA\\Federation\\...', true)
#19 [internal function]: OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(ReflectionParameter))
#20 /var/www/files.matoken.org/lib/private/AppFramework/Utility/SimpleContainer.php(101): array_map(Object(Closure), Array)
#21 /var/www/files.matoken.org/lib/private/AppFramework/Utility/SimpleContainer.php(109): OC\AppFramework\Utility\SimpleContainer->buildClass(Object(ReflectionClass))
#22 /var/www/files.matoken.org/lib/private/AppFramework/Utility/SimpleContainer.php(126): OC\AppFramework\Utility\SimpleContainer->resolve('OCA\\Federation\\...')
#23 /var/www/files.matoken.org/lib/private/AppFramework/DependencyInjection/DIContainer.php(459): OC\AppFramework\Utility\SimpleContainer->query('OCA\\Federation\\...')
#24 /var/www/files.matoken.org/lib/private/ServerContainer.php(146): OC\AppFramework\DependencyInjection\DIContainer->queryNoFallback('OCA\\Federation\\...')
#25 /var/www/files.matoken.org/lib/private/Console/Application.php(221): OC\ServerContainer->query('OCA\\Federation\\...')
#26 /var/www/files.matoken.org/lib/private/Console/Application.php(136): OC\Console\Application->loadCommandsFromInfoXml(Array)
#27 /var/www/files.matoken.org/console.php(99): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 /var/www/files.matoken.org/occ(11): require_once('/var/www/files....')

ということで,乱暴ですが files_external_dropbox をディレクトリごと退避しました.

$ sudo mv ${NEXTCLOUDPATH}apps/files_external_dropbox ~/tmp/

occコマンドもWebも動作するようになりました.

今回自動的に無効にならなかった原因は調べていませんが,config.php に今回のアプリの記述があったのでそのせいかもしれません.

$ sudo -u www-data php ${NEXTCLOUDPATH}/occ --version
Nextcloud 21.0.3
環境
$ sudo -u www-data php ${NEXTCLOUDPATH}/occ --version
Nextcloud 21.0.3
$ dpkg-query -W php apache2 mariadb-server
apache2 2.4.38-3+deb10u4
mariadb-server  1:10.3.29-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2021/07/09/nextcloud-21-update-fail/feed/ 0
Nitterにrobots.txtを設定(Apache httpdのreverse proxy環境でAlias設定) https://matoken.org/blog/2021/05/31/set-robots-txt-in-nitter-alias-setting-in-reverse-proxy-environment-of-apache-httpd/ https://matoken.org/blog/2021/05/31/set-robots-txt-in-nitter-alias-setting-in-reverse-proxy-environment-of-apache-httpd/#comments Sun, 30 May 2021 22:39:20 +0000 http://matoken.org/blog/?p=3253

以前軽量TwitterフロントエンドのNitter をセルフホストしました.

最近アクセスが増えていて少しサーバが重くなったり自分が使うときに調子が悪かったりしています.クローラなんかが多いようなのでこれを robots.txt で拒否すると大分アクセスが減るのではと思い設定してみました.

まずは適当な robots.txtNitter の Root に置いてみましたが,対応していないようでアクセスできません.
Nitter の前段に置いてある Apache2 httpd でAlias を設定すればと思ってApache httpd のNitter の設定の VirtualHost の中に以下の設定を追加してみました.

/etc/apache2/sites-available/nitter.matoken.org.conf
        Alias /robots.txt /home/nitter/robots.txt
        <Location "/robots.txt">
                Require all granted
        </Location>

追加したあと設定を確認して設定を再読込します.

$ sudo a2ensite nitter.matoken.org.conf
$ sudo apache2ctl configtest
$ sudo systemctl reload apache2

しかしこの状態で /robots.txt にアクセスするとhttp ステータスコード 404 が帰ってきてアクセスできません.Proxy の方が優先のようです.

検索してみると以下のpageを見つけました. ProxyPass! を指定して指定したURLをProxy で無視するようにできるようです.

ということでこのように設定してみました.

        Alias /robots.txt /home/nitter/robots.txt
        <Location "/robots.txt">
                ProxyPass !
                Require all granted
        </Location>

再度設定チェックして再読込すると動作しました :)

$ w3m -dump_head https://nitter.matoken.org/robots.txt
HTTP/1.1 200 OK
Date: Sun, 30 May 2021 15:26:17 GMT
Server: Apache/2.4.38 (Debian) OpenSSL/1.1.1d
Last-Modified: Mon, 12 Apr 2021 23:19:53 GMT
ETag: "32c8-5bfcec03dd840-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 2938
Connection: close
Content-Type: text/plain

1日ほど待ってからアクセスの変化を見てみようと思います.

環境
$ dpkg-query -W apache2
apache2 2.4.38-3+deb10u4
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2021/05/31/set-robots-txt-in-nitter-alias-setting-in-reverse-proxy-environment-of-apache-httpd/feed/ 1
WordPressのページ分けメモ✍ https://matoken.org/blog/2021/04/07/wordpress-split-page/ https://matoken.org/blog/2021/04/07/wordpress-split-page/#respond Wed, 07 Apr 2021 13:35:12 +0000 http://matoken.org/blog/?p=3207

ページが長くなったり,画像を多用するとWordPressのトップページが重くなります.
確か以前は編集画面に分割する機能が合ったはずと思ったのですが見当たりません.恐らく編集画面を変更すればでてくると思いますがよくわかりません.少し調べてみました.

「続きを読む」でトップページから隠す

以下のページを見ると, <!--more-→ を書くとそこから下は「続きを読む」を押すか,個別ページに行かないと表示されなくなるようです.↑の 「続きを読む」でトップページから隠す の上で分割しています.

リンクの文字列は既定値では「続きを読む」ですが, <!--more 任意のテキスト-→ のようにして任意の文字列に変更することも出来るようです.

ページ分割

これは自分ではあまり使う機会がないかなと思っていますが,ページ分割も出来るようです.

ページ内に <!‐‐nextpage‐‐> を挟むとそこでページが分割でされるようです.
複数挟むとその都度ページ分割されます.

AutoPagerizeの出番です??

ちなみにページ分けしたエントリーを1ページで読むことが出来るリンクとページを作ってくれるプラグインもあるようです.(動作未確認)

環境

$ dpkg-query -W wordpress*
wordpress       5.0.11+dfsg1-0+deb10u1
wordpress-l10n  5.0.11+dfsg1-0+deb10u1
wordpress-shibboleth    1.8-1
wordpress-theme-twentynineteen  5.0.11+dfsg1-0+deb10u1
wordpress-xrds-simple   1.2-1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2021/04/07/wordpress-split-page/feed/ 0
カレンダーをWebhooksでDiscordに投稿 https://matoken.org/blog/2021/03/31/post-your-calendar-to-discord-with-webhooks/ https://matoken.org/blog/2021/03/31/post-your-calendar-to-discord-with-webhooks/#respond Wed, 31 Mar 2021 11:38:22 +0000 http://matoken.org/blog/?p=3163

以下の記事でDavCalやGoogleカレンダーをコマンドラインで閲覧できるようになりました.

せっかくなのでDiscordにも毎朝その日のイベントを投稿するようにしてみます.

DiscordはWebhooksを使ってかんたんにメッセージを投稿することが出来ます.

投稿したいチャンネルの⚙アイコン「チャンネルの編集」から「連携サービス」→「ウェブフック」から操作できます.
新しいウェブフックを作成し,投稿チャンネルを確認して「ウェブフックURLをコピー」でWebhooks URLを入手します.

curlで投稿テストをしてみます.

$ curl -X POST -H "Content-Type: application/json" \
  -d '{"username": "ボット", "content": "こんにちは🤖"}' \
  'https://ptb.discord.com/api/webhooks/826777625053495306/QZoG2LLZOFlsKO_Auf1IQcXHVFozlgU37EGO9bhQKAifzZ0VAkyIYuQjRSzuOvC7U1gR'

Discord bot

これで投稿できました :)

Discordにメッセージを投稿できるようになったので,以下のエントリで書いた khal コマンドで今日1日分の予定タイトルを入手してDiscordに投稿するようにしてみます.

以下の適当なScriptを用意しました.

2021-04-01 編集)
イベントがない日にも投稿してしまっていたのを修正&Bashismだったのをshで動くよう修正

#!/bin/sh
# khalコマンドで今日の予定を入手してDiscordにpostする
# https://matoken.org/blog/2021/03/31/post-your-calendar-to-discord-with-webhooks/

# DiscordのWebhook URL
# 以下のURLを参考に入手して設定する
# https://support.discord.com/hc/ja/articles/228383668-%E3%82%BF%E3%82%A4%E3%83%88%E3%83%AB-Webhooks%E3%81%B8%E3%81%AE%E5%BA%8F%E7%AB%A0
DISCORD_WEBHOOK='https://ptb.discord.com/api/webhooks/…………'

# khal
#   list -> 一覧表示
#   --format "{title}" -> タイトルだけ表示
#   today -> 今日から
#   today -> 今日まで
# sed -> jsonの改行形式に変換
CAL=$(khal list --format "{title}" today today | sed -z -e "s/\n/\\\\\\\\n/g")

# イベントのない日は投稿せず終了
if [ "${CAL}" = 'No events\\n' ]
then
  echo "${CAL}"
  exit
fi

MSG=$(printf '{"username": "今日のイベント📅", "content": "%s"}\n' "${CAL}")
echo "$MSG"

# Discord WebHock でKagolug の#random へpost
curl -X POST -H "Content-Type: application/json" \
	-d "${MSG}" \
	"${DISCORD_WEBHOOK}"

試しに実行すると投稿されました.

手動で叩くのは面倒すぎるので自動実行するようにcrontabに登録しておきます.

$ crontab -l | grep calpost
58 4 * * *      /home/matoken/bin/calpost.sh 2>&1 > /home/matoken/tmp/cron/calpost.sh.log

毎日04:58に実行するようにしました.

環境
$ dpkg-query -W vdirsyncer khal curl bash
bash    5.0-4
curl    7.64.0-4+deb10u1
khal    1:0.9.10-1.1
vdirsyncer      0.16.7-2
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/31/post-your-calendar-to-discord-with-webhooks/feed/ 0
カレンダーのDavCalをコマンドラインに出力したい https://matoken.org/blog/2021/03/31/output-the-calendar-davcal-to-the-command-line/ https://matoken.org/blog/2021/03/31/output-the-calendar-davcal-to-the-command-line/#comments Wed, 31 Mar 2021 11:02:13 +0000 http://matoken.org/blog/?p=3160

何らかの日程を決めるときに未来の日程を見ながら決めたいことがあります.
Webベースでいいかと思ったのですが,特に低解像度だとタイトルの一部しか表示されずよくわかりません.コピーペーストしてEtherPadなどに貼るといいですが時間がかかるし面倒です.
DavCalなどの情報を範囲指定して表示出来ると便利そうだなと思いました.

はじめはコマンドを叩いて範囲指定して表示するようなものがないかと思ったのですが見つかりませんでした.少し面倒ですが, vdirsyncer でリモートのカレンダーをローカルにコピーして khal コマンドで表示するようにしてみました.

Vdirsyncer の導入と設定

Vdirsyncer はカレンダーとコンタクトをローカルと同期できるソフトウェアです.これでリモートのDavCal の情報をローカルに同期します.

$ sudo apt install vdirsyncer (1)
$ mkdir ~/.config/vdirsyncer
$ vi ~/.config/vdirsyncer/config (2)
$ cat ~/.config/vdirsyncer/config
[general]
status_path = "~/.vdirsyncer/status/"

[pair my_calendars]
a = "my_calendars_local"
b = "my_calendars_remote"
collections = null
metadata = ["color"]

[storage my_calendars_local]
type = "filesystem"
path = "~/.calendars/"
fileext = ".ics"

[storage my_calendars_remote]
type = "caldav"
url = "https://files.matoken.org/remote.php/dav/public-calendars/YW5gc6gMG8tC63AH?export"
  1. Vdirsyncer の導入
  2. 設定ファイル作成

これでとりあえず Vdirsyncer を導入して,リモートの CalDav 形式のカレンダーをローカルのストレージに同期できます.
設定ファイルは以下のページを参考にしました.相互同期はせず,リモートのデータをローカルに同期するだけの動作のつもりです.

$ vdirsyncer discover my_calendars (1)
Discovering collections for pair my_calendars
my_calendars_local:
my_calendars_remote:
  - "YW5gc6gMG8tC63AH" ("onlin_event (matoken)")
warning: No collection "YW5gc6gMG8tC63AH" found for storage my_calendars_local.
Should vdirsyncer attempt to create it? [y/N]: y
Saved for my_calendars: collections = ["YW5gc6gMG8tC63AH"]
$ vdirsyncer sync (2)
Syncing my_calendars/YW5gc6gMG8tC63AH
Copying (uploading) item 05f764a4-8c30-46ed-a0fe-62c67d3975a8 to my_calendars_local/YW5gc6gMG8tC63AH
Copying (uploading) item 1acc3691-a12b-4534-a4e2-6ee6213ecff1 to my_calendars_local/YW5gc6gMG8tC63AH
Copying (uploading) item 202e727b-0431-40b5-8008-9ada1269c7c8 to my_calendars_local/YW5gc6gMG8tC63AH
Copying (uploading) item 2312a403-b2e6-4716-9c6f-45aa94519654 to my_calendars_local/YW5gc6gMG8tC63AH
  :
$ ls ~/.calendars/YW5gc6gMG8tC63AH/ | head (3)
05f764a4-8c30-46ed-a0fe-62c67d3975a8.ics
1acc3691-a12b-4534-a4e2-6ee6213ecff1.ics
202e727b-0431-40b5-8008-9ada1269c7c8.ics
2312a403-b2e6-4716-9c6f-45aa94519654.ics
263c2df9-ad9b-40d5-a946-614af7bc10ae.ics
29cbecc8-0b88-41da-b7d0-0c71062eb6b4.ics
2c66d40f-f5bd-4a67-bfb9-9bbb0258a966.ics
2e81f5bd-1aad-435a-bfa4-4a3ebe75e489.ics
30d41952-4dc3-4f10-bb6d-3311593f1d25.ics
3335be8d-9dd6-4b5e-81e9-a292d56fa17e.ics
  1. 設定を探索して初期化.設定を作ったときに実行.
  2. カレンダーを同期.定期的に実行.
  3. 同期されたデータが .ics ファイルとして作られているのを確認.

カレンダーがローカルに同期されました :)
vdirsyncer sync は定期的に実行して同期するようにします.

$ crontab -l | grep 'vdirsyncer sync'
4 4 * * *       chronic vdirsyncer sync

crontab に設定して1日1回同期するようにしました.
chronic を挟んでいますが,これはmoreutils のコマンドの1つで,正常終了時にはメッセージを出力しないというものです.エラー時だけメールが飛ぶはず.

khalの導入と設定

カレンダーの同期は出来ましたが,icsファイルがあるだけなので閲覧が不便です.閲覧するために khal コマンドを利用します.

$ sudo sudo apt install khal
$ mkdir ~/.config/khal
$ vi ~/.config/khal/config
$ cat ~/.config/khal/config
[calendars]
  [[event]]

    path = ~/.calendars/YW5gc6gMG8tC63AH/
    readonly = True

[locale]
timeformat = %H:%M
dateformat = %Y-%m-%d
longdateformat = %Y-%m-%d
datetimeformat = %Y-%m-%d %H:%M
longdatetimeformat = %Y-%m-%d %H:%M

khalを導入して設定を書いてみました.pathは Vdirsyncer で同期された場所を指定します.
この状態でkhalを叩くとこんな感じで表示されました.

$ khal
    Mo Tu We Th Fr Sa Su     Tomorrow, 2021-03-31
Mar  1  2  3  4  5  6  7     20:00-21:30 TechLION vol.37 〜TechLION出演者に聞く、この1年とこの10年。そして未来〜 :: # 視聴方法  本イベントはYouTubeにて配信します  視聴URLは決まり次第掲載します  #
     8  9 10 11 12 13 14     プログラム  2011年3月に旗揚げしたTechLIONが10周年を迎えるにあたり、記念試合をオンラインイベントとして行います。   ト
ークセッションでは、これまでTechLIONに出演してくださった皆さんに、IT業界の最近の状況、
    15 16 17 18 19 20 21     10年間の変化、今後の予想などをお聞きします。事前に実施したアンケート結果を見ながらMCの2名が進行しますが、回答によっ
ては出演者の方もトークにご参加いただきます。
    22 23 24 25 26 27 28     TechLION旗揚げ記念日でもある3月31日の夜、お酒を片手にお楽しみください!    * 出演:これまでのTechLIONにご出演の皆さ
ん   * MC:法林浩之、馮富久  # 開催概要    * 名称:TechLION
Apr 29 30 31  1  2  3  4     vol.37 〜TechLION出演者に聞く、この1年とこの10年。そして未来〜   * 主催:チームTechLION   * 協賛:USP研究所、技術評
論社   * 後援:日本UNIXユーザ会   *
     5  6  7  8  9 10 11     日時:2021年3月31日(水) 20:00開演、21:30終了予定   * 場所:オンライン (YouTubeにて配信)   * 料金:無料   * 公式タグ
:techlion   * 問い合わせ先:チームTechLION
    12 13 14 15 16 17 18     (E-mail:staff[at]techlion.jp)  # イベント詳細  https://techlion.jp/vol37
    19 20 21 22 23 24 25     https://techlion.connpass.com/event/205623/
May 26 27 28 29 30  1  2
     3  4  5  6  7  8  9
    10 11 12 13 14 15 16
    17 18 19 20 21 22 23
    24 25 26 27 28 29 30
Jun 31  1  2  3  4  5  6

ikhalコマンドを使うとダンプではなく,tuiのhalが起動してインタラクティブに操作できます.

ikhal

ちょっと冗長なので --format "title}" でタイトルだけ表示するようにしてみました.

$ khal list --format "{title}"
Tomorrow, 2021-03-31
TechLION vol.37 〜TechLION出演者に聞く、この1年とこの10年。そして未来〜

今日だけや,今日から7日間など範囲指定も出来ます.

$ khal list --format "{title}" today today (1)
$ khal list --format "{title}" today 7days (2)
$ khal list --format "{title}" 2021-03-01 2021-03-31 (3)
$ faketime 2021-03-03 khal list --format "{title}" today (4)
  1. 今日から今日まで表示
  2. 今日から7日間表示
  3. 03/01〜03/31まで表示
  4. faketimeで03/03としてkhalを実行

URLも表示したいけど,あっても.icsのDiscriptionの中などなのでちょっと面倒そうなので今回は諦めました.必要なときはカレンダーを参照することにします.

複数のカレンダーの設定

2つ目のカレンダーを登録してみます.次は日本の休日カレンダーを登録してみます.

~/.config/vdirsyncer/config に以下の設定を追記します.

[pair holiday_calendars]
a = "holiday_calendars_local"
b = "holiday_calendars_remote"
collections = null
metadata = ["color"]

[storage holiday_calendars_local]
type = "filesystem"
path = "~/.calendars/holiday_calendars/"
fileext = ".ics"

[storage holiday_calendars_remote]
type = "http"
url = "https://www.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics"

設定反映してカレンダーを同期します.

$ vdirsyncer discover holiday_calendars
$ vdirsyncer sync holiday_calendars

次にkhalの設定です.
~/.config/khal/config[calendars] セクションに以下の設定を追記します.

  [[holiday]]
    path = ~/.calendars/holiday_calendars/
    readonly = True

この状態でkhalを実行してみると祝日も表示されるようになりました :)

$ khal list --format "{title}" 2021-03-20 1days
Saturday, 2021-03-20
春分の日
NBUG 2021年3月例会[第250回例会]
Kernel/VM探検隊online part2

ということで当初思っていたより少し面倒でしたが,とりあえずやりたいことが出来るようになりました :)

環境

$ dpkg-query -W vdirsyncer khal faketime
faketime        0.9.7-3
khal    1:0.9.10-1.1
vdirsyncer      0.16.7-2
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/31/output-the-calendar-davcal-to-the-command-line/feed/ 1
Nextcloudでurl共有したpdfをwebに埋め込みたい その2 https://matoken.org/blog/2021/03/17/i-want-to-embed-nextcloud-pdf-shared-url-on-the-web-part-2/ https://matoken.org/blog/2021/03/17/i-want-to-embed-nextcloud-pdf-shared-url-on-the-web-part-2/#comments Wed, 17 Mar 2021 12:48:59 +0000 http://matoken.org/blog/?p=3111

ドキュメント共有サイトの無料枠を使うのが辛くなったのでNextcloudのURL共有でどうにかならないかなと思っています.
まずはpdfファイルをobjectタグで埋め込む方法を試しました.

この方法のデメリットはcgiを用意しないといけない,pdfを読む気がなくてもページを読み込むとpdfファイルがダウンロードされてしまいページ容量が大きくなってしまう.そしてNextcloudに「<pdfファイル名> が公開リンクからダウンロードされました」という通知がたくさん届いてしまいちょっとうるさいといった感じです.

途中のcgiでキャッシュしてプレビュー用の画像を用意してwebにはそのプレビュー画像を表示しておけばいいのではとcgiを書き換えていました.headで引っ張ってもダウンロードされた扱いになるしdbから実ファイルの場所を探してそこからダウンロードするように,サムネイルもdbから引っ張ってこれるかな?とかやってましたがふとそれだと標準の機能で出来るのではと気づいたので試してみました.

pdf共有URLの末尾に /preview を付けるとプレビュー画像が表示されます.(標準では50MB以下のファイルの場合)

これを利用してこんな感じに書くと,

AsciiDocでの例
[quote,'link:https://files.matoken.org/index.php/s/r7jEJdjiSRzb4nZ[https://files.matoken.org/index.php/s/r7jEJdjiSRzb4nZ]']
link:https://files.matoken.org/index.php/s/r7jEJdjiSRzb4nZ[image:https://files.matoken.org/index.php/s/r7jEJdjiSRzb4nZ/preview[width=100%]]
htmlへ変換した例
<div class="quoteblock">
<blockquote>
<a href="https://files.matoken.org/index.php/s/r7jEJdjiSRzb4nZ"><span class="image"><img src="https://files.matoken.org/index.php/s/r7jEJdjiSRzb4
nZ/preview" alt="preview" width="100%"></span></a>
<div class="attribution">
&#8212; <a href="https://files.matoken.org/index.php/s/r7jEJdjiSRzb4nZ">https://files.matoken.org/index.php/s/r7jEJdjiSRzb4nZ</a>
</div>
</blockquote>
</div>

こういうふうになりました.クリックするとNextcloudのpdfファイルプレビュー画面が開かれ,最近のモダンウェブブラウザではそのまま閲覧できます.

SpeakerDeckなんかでは埋め込んだページでそのまま読むことも出来ますがとりあえずこれならcgiも必要なくNextcloudの標準機能だけ(恐らくNC13以降で可能)でいけるのでそこそこいい感じではないかなと思います.

環境
$ sudo -u www-data php occ --version
Nextcloud 20.0.8
$ dpkg-query -W php mariadb-server apache2
apache2 2.4.38-3+deb10u4
mariadb-server  1:10.3.27-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/17/i-want-to-embed-nextcloud-pdf-shared-url-on-the-web-part-2/feed/ 1
ImageMagickでpdfファイルの1ページ目だけをjpegにする https://matoken.org/blog/2021/03/16/make-the-first-page-of-the-pdf-file-jpeg-with-imagemagick/ https://matoken.org/blog/2021/03/16/make-the-first-page-of-the-pdf-file-jpeg-with-imagemagick/#respond Tue, 16 Mar 2021 14:25:28 +0000 http://matoken.org/blog/?p=3104

ImagemMgickのconvertコマンドでpdfをjpegにしようとするとエラーになってしまいました.でもこれは見覚えのあるエラー……どこかにメモした気がするのですが見当たらないのでblogにしてみました.

ImageMagickのセキュリティポリシーを変更してpdfファイルを変換できるようにする

$ convert -geometry 640 /var/tmp/Nextcloud2pdf_cache/HQeSTL5TgcgAPtS.pdf[0] /tmp/HQeSTL5TgcgAPtS.jpg
convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.
convert-im6.q16: no images defined `/tmp/HQeSTL5TgcgAPtS.jpg' @ error/convert.c/ConvertImageCommand/3258.

セキュリティの問題でImageMagickの設定で無効にしてあるのでこれを有効にします.

$ sudo git -C /etc diff /etc/ImageMagick-6/policy.xml
diff --git a/ImageMagick-6/policy.xml b/ImageMagick-6/policy.xml
index 82a3d0b..0953557 100644
--- a/ImageMagick-6/policy.xml
+++ b/ImageMagick-6/policy.xml
@@ -91,6 +91,6 @@
   <policy domain="coder" rights="none" pattern="PS2" />
   <policy domain="coder" rights="none" pattern="PS3" />
   <policy domain="coder" rights="none" pattern="EPS" />
-  <policy domain="coder" rights="none" pattern="PDF" />
+  <policy domain="coder" rights="read|write" pattern="PDF" />
   <policy domain="coder" rights="none" pattern="XPS" />
 </policymap>

設定を編集後実行するとうまく動きました :)

$ convert -geometry 640 /var/tmp/Nextcloud2pdf_cache/HQeSTL5TgcgAPtS.pdf[0] /tmp/HQeSTL5TgcgAPtS.jpg

pdfファイルの指定ページだけを変換する

ソースファイル名を普通に指定すると, ファイル名-%d.jpg のようなファイルが連番で作成されます.
今回は1ページめだけが欲しいので不必要なファイルがたくさん出来てしまいます.

1ページだけが欲しい場合, ソースファイル名.pdf[0] というようにページ指定して実現できます.この添字は1ページ目が0,2ページめが1のように指定します.

存在しないページ番号を指定するとエラーになります.

$ convert -geometry 640 /var/tmp/Nextcloud2pdf_cache/HQeSTL5TgcgAPtS.pdf[99] /tmp/HQeSTL5TgcgAPtS-99.jpg

Requested FirstPage is greater than the number of pages in the file: 33
   No pages will be processed (FirstPage > LastPage).
convert-im6.q16: no images defined `./HQeSTL5TgcgAPtS-1.jpg' @ error/convert.c/ConvertImageCommand/3258.
環境
$ dpkg-query -W imagemagick
imagemagick     8:6.9.10.23+dfsg-2.1+deb10u1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/16/make-the-first-page-of-the-pdf-file-jpeg-with-imagemagick/feed/ 0
Nextcloudの2要素認証が出来ないときに管理者が1度限りのワンタイムコードを発行できる「Two-Factor Admin Support」 https://matoken.org/blog/2021/03/13/two-factor-admin-support-that-allows-the-administrator-to-issue-a-one-time-code-when-nextclouds-two-factor-authentication-is-not-possible/ https://matoken.org/blog/2021/03/13/two-factor-admin-support-that-allows-the-administrator-to-issue-a-one-time-code-when-nextclouds-two-factor-authentication-is-not-possible/#respond Sat, 13 Mar 2021 12:22:55 +0000 http://matoken.org/blog/?p=3081

Nextcloudユーザが2要素認証を出来ないときにNextcloud管理者が48時間有効な1度限りのワンタイムコードを作成することができる「Two-Factor Admin Support」を試してみました.

「Two-Factor Admin Support」install
$ sudo -u www-data php occ app:install twofactor_admin

occコマンドで導入しました.WebインターフェイスからでもOKです.

nextcloud towfactor admin01

導入後,管理者アカウントで「設定」→「管理」→「セキュリティ」の「Two-Factor Admin」が出来ています.この「User ID」のテキストボックスにワンタイムコードを発行したいユーザIDを入力して「Generate」を押すと48時間有効なワンタイムコードが発行されます.このコードをユーザに伝えてログインしてもらいます.

occコマンドでのワンタイムコードの発行
$ sudo -u www-data php occ twofactorauth:admin:generate-code $USERID
There is an existing code that will be overwritten.

Generated new one-time code for test01: 163929
This code is valid for 48 hours.

occコマンドでも発行できます.

nextcloud towfactor admin02

該当ユーザはユーザID/パスワードを入力した後の2要素認証で「Admin code」という選択肢が増えるのでそれを選びます.

nextcloud towfactor admin03

管理者に教えてもらったワンタイムコードを入力してログインします.

TOTPのデバイスを壊してしまったり家に忘れてきたとかいったときに便利そうです.(数が少なければ)

環境
$ sudo -u www-data php /var/www/files.matoken.org/occ app:list | grep twofactor_admin:
  - twofactor_admin: 3.0.0
$ sudo -u www-data php occ --version
Nextcloud 20.0.8
$ dpkg-query -W php mariadb-server apache2
apache2 2.4.38-3+deb10u4
mariadb-server  1:10.3.27-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/13/two-factor-admin-support-that-allows-the-administrator-to-issue-a-one-time-code-when-nextclouds-two-factor-authentication-is-not-possible/feed/ 0
Nextcloudのmailアプリのアップデートに失敗してNextcloudが使えなくなって困る https://matoken.org/blog/2021/03/12/im-having-trouble-updating-nextclouds-mail-app-and-not-being-able-to-use-nextcloud/ https://matoken.org/blog/2021/03/12/im-having-trouble-updating-nextclouds-mail-app-and-not-being-able-to-use-nextcloud/#respond Fri, 12 Mar 2021 14:32:38 +0000 http://matoken.org/blog/?p=3078

Nextcloudアプリのアップデートを行ったところmailの処理中にコケてしまったようです.

$ sudo -u www-data php occ app:update --all
richdocuments new version available: 3.7.17
richdocuments updated
forms new version available: 2.2.1
forms updated
mail new version available: 1.9.2
An unhandled exception has been thrown:
Error: Call to undefined method OCA\Mail\Db\MessageMapper::findWithEmptyMessageId() in /var/www/files.matoken.org/apps/mail/lib/Migration/AddMissingMessageIds.
php:55
Stack trace:
#0 /var/www/files.matoken.org/lib/private/Repair.php(112): OCA\Mail\Migration\AddMissingMessageIds->run(Object(OC\Repair))
#1 /var/www/files.matoken.org/lib/private/legacy/OC_App.php(1042): OC\Repair->run()
#2 /var/www/files.matoken.org/lib/private/legacy/OC_App.php(979): OC_App::executeRepairSteps('mail', Array)
#3 /var/www/files.matoken.org/lib/private/Installer.php(206): OC_App::updateApp('mail')
#4 /var/www/files.matoken.org/core/Command/App/Update.php(116): OC\Installer->updateAppstoreApp('mail', false)
#5 /var/www/files.matoken.org/3rdparty/symfony/console/Command/Command.php(255): OC\Core\Command\App\Update->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /var/www/files.matoken.org/3rdparty/symfony/console/Application.php(1000): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /var/www/files.matoken.org/3rdparty/symfony/console/Application.php(271): Symfony\Component\Console\Application->doRunCommand(Object(OC\Core\Command\App\Update), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /var/www/files.matoken.org/3rdparty/symfony/console/Application.php(147): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /var/www/files.matoken.org/lib/private/Console/Application.php(215): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 /var/www/files.matoken.org/console.php(100): OC\Console\Application->run()
#11 /var/www/files.matoken.org/occ(11): require_once('/var/www/files....')
#12 {main}mk@www6073uo:/var/www/files.matoken.org

再度実行すると処理は進んだようですが,縮退モードのような感じになっています.この状態でNextcloudのWebにアクセスするとアップデートを求められて利用できません.

$ sudo -u www-data php occ app:update --all
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
files_linkeditor new version available: 1.1.4
files_linkeditor updated

どうしたもんかととりあえず原因であろうmailをアップデートしようとするとすでに最新のようです.
次にmailを無効化してみました.するとNextcloud Webが利用できるようになりました.
一旦削除してインストールし直したほうが確実だろうなと思いつつmailを有効化するとNextcloudもmailも利用できるようになりました.

$ sudo -u www-data php occ app:update mail (1)
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
$ sudo -u www-data php occ app:disable mail (2)
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
mail 1.9.2 disabled
$ sudo -u www-data php occ app:enable mail (3)
mail 1.9.2 enabled
  1. mailアプリをアップデートしても反応はない
  2. mailアプリを無効化してNextcloud復旧
  3. mailアプリを有効化

occ app:disable mail の後 occ app:remove mail && occ app:install mail したほうが確実だと思います.

ちなみにNextcloud Hub以外のあまりメジャーでないアプリなどをインストールしてうまく動かないときにもNextcloudが動かなくなることがあります.そういうときも occ app:disable で復旧できるので覚えておくと助かります.

環境
$ sudo -u www-data php occ app:list | grep \ mail:
  - mail: 1.9.2
$ sudo -u www-data php occ --version
Nextcloud 20.0.8
$ dpkg-query -W php mariadb-server apache2
apache2 2.4.38-3+deb10u4
mariadb-server  1:10.3.27-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/12/im-having-trouble-updating-nextclouds-mail-app-and-not-being-able-to-use-nextcloud/feed/ 0
Nextcloudの電子メール2要素認証の「Two Factor e-mail provider」 https://matoken.org/blog/2021/03/12/nextcloud-email-two-factor-authentication-two-factor-e-mail-provider/ https://matoken.org/blog/2021/03/12/nextcloud-email-two-factor-authentication-two-factor-e-mail-provider/#respond Fri, 12 Mar 2021 11:03:17 +0000 http://matoken.org/blog/?p=3075

Nextcloudアプリの「A Two-Factor-Auth Provider for e-mail」を試してみました.これはNextcloud認証時にユーザID/パスワードで認証した後設定されたメールアドレスにワンタイムトークンが届いて,それを使って2要素目の認証ができるようになるものです.

$ sudo -u www-data php occ app:install twofactor_admin
twofactor_admin 3.0.0 installed
twofactor_admin enabled

まずは導入.occ コマンドでインストールしました.WebIFからでもOKです.

nextcloud towfactor email01

2要素認証を有効にしたいユーザでNextcloud Webにログインして,「右上のアイコン」→「設定」→「個人情報」の「メール」に正しいメールアドレスが設定されているのを確認して,「セキュリティ」→「二要素認証」→「Email verification」の「Enable」を押して有効にします.

Note
電子メールアドレスが未登録だと以下のようなメッセージとなりました.
Could not generate a code: user hoge does not exist

nextcloud towfactor email02

するとトークンがNextcloudに設定したメールアドレスに送信されるのでメールを確認してトークンをテキストボックスに入力して,「Veryfi」を押して確認します.

nextcloud towfactor email03

うまく行きました.
一旦ログアウトしてログインしてみます.

nextcloud towfactor email04

ユーザID/パスワードで認証した後,「Email verification」の画面になります.メールが送信されているはずかので確認してそこに書かれているトークンを入力してログインします.

2要素認証ではTOTP以外にもSMS, Telegram, Signalなどもありますがそれぞれ設定が面倒です.電子メールであればユーザの設定は少ないので良さそうです.

環境
$ sudo -u www-data php occ app:list | grep previewgenerator:
  - previewgenerator: 3.1.1
$ sudo -u www-data php occ --version
Nextcloud 20.0.8
$ dpkg-query -W php mariadb-server apache2
apache2 2.4.38-3+deb10u4
mariadb-server  1:10.3.27-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/12/nextcloud-email-two-factor-authentication-two-factor-e-mail-provider/feed/ 0
Nextcloudのファイルプレビューを少しカスタマイズ https://matoken.org/blog/2021/03/12/customized-file-preview-for-nextcloud/ https://matoken.org/blog/2021/03/12/customized-file-preview-for-nextcloud/#respond Thu, 11 Mar 2021 22:36:08 +0000 http://matoken.org/blog/?p=3073

Nextcloudでは画像ファイル,MP3ファイルのカバー,テキストファイルのプレビューを生成できます.既定値ではこの機能は有効になっていて,アクセス時にプレビューが生成されます.
Nextcloudを軽く出来ないかと config/config.php ファイルに 'enable_previews' ⇒ false, を設定して無効にしてみましたが不便です.

nextcloud preview false

ということで再度プレビューを有効にしました.ついでにプレビューサイズを4096から1024に小さくしてプロバイダーを少し増やしてみました.

config/config.php
  'enable_previews' => true, (1)
  'preview_max_x'  =>  1024, (2)
  'preview_max_y'  =>  1024, (3)
  'preview_max_filesize_image'  =>  50, (4)
  'enabledPreviewProviders' => [ (5)
        'OC\Preview\PNG',
        'OC\Preview\JPEG',
        'OC\Preview\GIF',
        'OC\Preview\HEIC',
        'OC\Preview\BMP',
        'OC\Preview\XBitmap',
        'OC\Preview\MP3',
        'OC\Preview\TXT',
        'OC\Preview\MarkDown',
        'OC\Preview\OpenDocument',
        'OC\Preview\Krita',
        'OC\Preview\PDF',
        'OC\Preview\Postscript',
        'OC\Preview\SVG',
        'OC\Preview\TIFF',
        'OC\Preview\Font',
  ],
  1. プレビューを有効にする,既定値 true
  2. プレビュー横サイズ,既定値 4096
  3. プレビュー縦サイズ,既定値 4096
  4. プレビュー対象の最大ファイルサイズ,これ以上のサイズのファイルはプレビューが作られない,単位はMB,既定値 50
  5. プレビューファイルプロバイダー,既定値は '' で内容は,

edit 2021-03-17)
スマホ写真やpdfはあらかた1MBを超えるので preview_max_filesize_image は1MBから規定値の50MBに戻しました.

OC\Preview\BMP
OC\Preview\GIF
OC\Preview\HEIC
OC\Preview\JPEG
OC\Preview\MarkDown
OC\Preview\MP3
OC\Preview\PNG
OC\Preview\TXT
OC\Preview\XBitmap
OC\Preview\OpenDocument
OC\Preview\Krita

その他の既定値以外のプロバイダー

OC\Preview\Illustrator
OC\Preview\Movie
OC\Preview\MSOffice2003
OC\Preview\MSOffice2007
OC\Preview\MSOfficeDoc
OC\Preview\PDF
OC\Preview\Photoshop
OC\Preview\Postscript
OC\Preview\StarOffice
OC\Preview\SVG
OC\Preview\TIFF
OC\Preview\Font

そして Preview Generator というプレビューを事前生成してくれるアプリを試してみようとしましたが,暗号化を有効にしていると利用できませんでした.パスワード入力してプレビュー生成ができると便利かもですがなんにせよ自分以外のデータは触れないので微妙ですね.

Known issues
The app does not work with encryption enabled

— https://github.com/rullzer/previewgenerator#known-issues
$ sudo -u www-data php occ app:install previewgenerator (1)
previewgenerator 3.1.1 installed
previewgenerator enabled
$ sudo -u www-data php /var/www/files.matoken.org/occ | grep preview$ -A4 (2)
 preview
  preview:delete_old                      Delete old preview folder (pre NC11)
  preview:generate-all                    Generate previews
  preview:pre-generate                    Pre generate previews
  preview:repair                          distributes the existing previews into subfolders
$ sudo -u www-data php occ preview:generate-all (3)
Encryption is enabled. Aborted.
$ sudo -u www-data php occ app:remove previewgenerator (4)
previewgenerator disabled
previewgenerator 3.1.1 removed
  1. Preview Generatorをインストール
  2. usage
  3. 暗号化が有効だとプレビューの手動生成に失敗する
  4. Preview Generatorを削除
環境
$ sudo -u www-data php occ app:list | grep previewgenerator:
  - previewgenerator: 3.1.1
$ sudo -u www-data php occ --version
Nextcloud 20.0.8
$ dpkg-query -W php mariadb-server apache2
apache2 2.4.38-3+deb10u4
mariadb-server  1:10.3.27-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/12/customized-file-preview-for-nextcloud/feed/ 0
Nextcloudで画像ファイルをURL共有してWebに埋め込んで利用したい https://matoken.org/blog/2021/03/11/i-want-to-share-an-image-file-with-nextcloud-and-embed-it-on-the-web/ https://matoken.org/blog/2021/03/11/i-want-to-share-an-image-file-with-nextcloud-and-embed-it-on-the-web/#respond Thu, 11 Mar 2021 11:34:45 +0000 http://matoken.org/blog/?p=3067

NextcloudでURL共有した画像をblogなどに埋め込む方法のメモです.今回はNextcloud 20.0.8ですが,Nextcloud 13.0.0から可能になった機能のようです.
共有単位は画像ファイル単体はOKですが,画像ファイルを含むディレクトリ共有ではうまく動かないようです.

20210311 18:03:55 252379

共有したい画像を共有

20210311 18:03:42 228558

「URLで共有」の右の「+」で共有

20210311 18:03:55 228828

URL共有されてURLがコピーされる

20210311 18:03:19 229349

既定値では共有有効期限が1週間に設定されているのでずっと公開したい場合は「有効期限を設定」のチェックを外す

20210311 18:03:02 234008

共有されたURLを開くとプレビューになる

画像をクリックすると,画像が開ける.
若しくは共有URLに /preview を追加する.
拡張子がないとうまく動作しないsiteなどの場合は,/preview?dummy.jpg などのように /preview の後ろにさらにそれらしい文字列を追加すると開けたりする.

https://files.matoken.org/index.php/s/bsaAdtxp8WgXLXE (1)
https://files.matoken.org/index.php/s/bsaAdtxp8WgXLXE/preview (2)
https://files.matoken.org/index.php/s/bsaAdtxp8WgXLXE/preview?/dummy.jpg (3)
  1. 共有URL(プレビューURL)
  2. URL末尾に /preview をつけると画像が表示される
  3. /preview の後ろにダミーファイル名をつける

後は普通に静的画像URLのようにして使えます.

$ wget -o /dev/null -O - https://files.matoken.org/index.php/s/bsaAdtxp8WgXLXE/preview | pee "file -" display
/dev/stdin: JPEG image data, JFIF standard 1.01, resolution (DPI), density 96x96, segment length 16, comment: "CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90", baseline, precision 8, 512x342, components 3
preview

blogに貼り付けもできる :)

環境
$ sudo -u www-data php occ --version
Nextcloud 20.0.8
$ dpkg-query -W php mariadb-server apache2
apache2 2.4.38-3+deb10u4
mariadb-server  1:10.3.27-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/11/i-want-to-share-an-image-file-with-nextcloud-and-embed-it-on-the-web/feed/ 0
TTY TwitterクライアントのTTYtterからOysttyerに乗り換え https://matoken.org/blog/2021/02/19/switch-from-ttytter-a-tty-twitter-client-to-oysttyer/ https://matoken.org/blog/2021/02/19/switch-from-ttytter-a-tty-twitter-client-to-oysttyer/#respond Fri, 19 Feb 2021 13:05:37 +0000 http://matoken.org/blog/?p=3012

TTYtterというPerl製でcliで動作するTwitter clientがあります.自作Twitter投稿scriptがアカウントをBANされてAPI keyが使えなくなった後これを使って自動投稿などをしていたのですが,Debian busterから無くなっています.
開発元を見るとOysttyerというものが変わりに存在するようなのでそちらに乗り換えました.

TTYtterからOysttyerに乗り換えるには認証鍵などを作り直す必要があるようです.
-oauthwizard オプションで認証ができるようです.
既定値では認証情報は ~/.oysttyerkey に保存されますが,複数のTwitterアカウントで利用したいので -key=認証情報格納ファイル オプションを付けて区別します.

Note
-keyf のパスに ~ を使うとエラーになるようです.今回は代わりに $HOME を使いました.
$ oysttyer -keyf=$HOME/.oysttyerkey_kagolug_ml -oauthwizard (1)
-- using SSL for default URLs.
trying to find cURL ... /usr/bin/curl
-- Streaming API disabled (no -dostream) (oysttyer will use REST API only)
-- no version check performed (use /vcheck, or -vcheck to check on startup)

+------------------------------------------------------------------------------+
|| WELCOME TO oysttyer: Authorize oysttyer by signing into Twitter with OAuth ||
+------------------------------------------------------------------------------+
Looks like you're starting oysttyer for the first time, and/or creating a
keyfile. Welcome to the most user-hostile, highly obfuscated, spaghetti code
infested and obscenely obscure Twitter client that's out there. You'll love it.

oysttyer generates a keyfile that contains credentials for you, including your
access tokens. This needs to be done JUST ONCE. You can take this keyfile with
you to other systems. If you revoke oysttyer's access, you must remove the
keyfile and start again with a new token. You need to do this once per account
you use with oysttyer; only one account token can be stored per keyfile. If you
have multiple accounts, use -keyf=... to specify different keyfiles. KEEP THESE
FILES SECRET.

** This wizard will overwrite ~/.oysttyerkey_kagolug_ml
Press RETURN/ENTER to continue or CTRL-C NOW! to abort.
(2)
Request from https://api.twitter.com/oauth/request_token ... SUCCEEDED!

1. Visit, in your browser, ALL ON ONE LINE,

https://api.twitter.com/oauth/authorize?oauth_token=lfqqTgAAAAAAixnPABABd7YG56I (3)

2. If you are not already signed in, fill in your username and password.

3. Verify that oysttyer is the requesting application, and that its permissions
are as you expect (read your timeline, see who you follow and follow new
people, update your profile, post tweets on your behalf and access your
direct messages). IF THIS IS NOT CORRECT, PRESS CTRL-C NOW!

4. Click Authorize app.

5. A PIN will appear. Enter it below.

Enter PIN> 0901765 (4)

Request from https://api.twitter.com/oauth/access_token ... SUCCEEDED!
Written keyfile /home/mk/.oysttyerkey_kagolug_ml

Now, restart oysttyer to use this keyfile.
(To choose between multiple keyfiles other than the default .oysttyerkey,
tell oysttyer where the key is using -keyf=... .)
  1. 認証ファイルを指定して認証処理実行
  2. Enterで続行
  3. URLをコピーしてウェブブラウザにて認証したいTwitterアカウントで許可する
  4. ウェブブラウザに表示されるPINを入力してEnter

これで認証情報が指定ファイルに格納されます.

TTYtterではScript中から以下のようにして投稿を行っていました.

ttytter -keyf=/home/mk/.ttytterkey-kagolug_ml -location -lat=31.5775639 -long=130.6667937 -status="$MESSAGE"

Oysttyerのユーザガイドのコマンドラインオプションを確認するとそのまま使えそうです.

コマンドと認証鍵ファイルを変更するだけで動作しました.

$ oysttyer -keyf=/home/mk/.oysttyerkey_kagolug_ml -location -lat=31.5775639 -long=130.6667937 -status="投稿テスト📮"
-- using SSL for default URLs.
trying to find cURL ... /usr/bin/curl
test-login SUCCEEDED!
post attempt -- using lat/long: (31.5775639, 130.6667937)
SUCCEEDED!

Scriptも同様にコマンドと鍵ファイルを書き換えました.これでbuster以降でも大丈夫なはずです :)

環境
$ dpkg-query -W oysttyer chromium
chromium        88.0.4324.146-1~deb10u1
oysttyer        2.10.0-1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/02/19/switch-from-ttytter-a-tty-twitter-client-to-oysttyer/feed/ 0
軽量TwitterフロントエンドのNitterをセルフホスト https://matoken.org/blog/2021/02/17/self-hosting-the-lightweight-twitter-front-end-nitter/ https://matoken.org/blog/2021/02/17/self-hosting-the-lightweight-twitter-front-end-nitter/#comments Wed, 17 Feb 2021 13:34:23 +0000 http://matoken.org/blog/?p=3007

NitterというTwitterのフロントエンドがあります.最近はTwitterが重くてなにか検索しようと思っても待ち長かったり画像読み込み失敗したりといったこともよくあります(PCのスペックと回線が細いせいも大きいですが).軽量ブラウザを使ったりもしてみましたがそうすると見た目や使い勝手がいまいち.

そして現在そういった軽量ブラウザは利用もできなくなりました.

This browser is no longer supported.
Please switch to a supported browser to continue using twitter.com. You can see a list of supported browsers in our Help Center.

そこで Nitter を試してみたところ軽くていい感じです.

現在ログイン機能はないので,投稿や非公開Tweetや非公開リストなどは使えませんが,イベントのハッシュタグを追ったり,過去のtweetを検索といったことをするのに便利です.

RSS形式での出力にも対応しています.

軽量で便利なのでロカールマシンでNitterを動かして外にURLを共有するときは https://nitter.net/ を利用していました.

という話を以前オープンソースカンファレンス2020福岡内の鹿児島らぐのコマで発表しました.

しかし,最近は https://nitter.net/ がTwitterの制限に掛かって利用できないことが多くなってきました.なので自分のVPS上にホストしてみました.

Note
同じ手順で Raspberry Pi OS buster armhf や Debian sid(nimはDebinaパッケージのもの利用)でも動作しました.

Nitterのインストール環境の用意

Nitterが依存している Redislibsass を導入しておきます.

$ sudo apt install redis-server libsass-dev

Nitterを専用アカウントで動かしたいので nitter ユーザ,グループを作ってそのユーザで操作します.

$ sudo groupadd nitter (1)
$ sudo useradd -m -g nitter nitter (2)
$ sudo -iu nitter (3)
  1. nitter グループを作成
  2. nitter ユーザを作成
  3. nitter ユーザのシェルを開く

nimの用意

Nitterはnim-langで出来ています.Nitterのコンパイルにはnim 1.2.0以上が必要ですが,Debian busterのパッケージ版のnimは 0.19.4 でコンパイル出来ません.buster-backports も 1.0.4-1~bpo10+1 と対応していません.(bullseyeは1.4.2)

$ nimble build -d:release
  Verifying dependencies for nitter@0.1.0
       Tip: 2 messages have been suppressed, use --verbose to show them.
     Error: Unsatisfied dependency: nim (>= 1.2.0)
$ dpkg-query -W nim
nim     0.19.4-1

とりあえずnimの公式サイトのバイナリを利用してコンパイルすることにします.

$ wget https://nim-lang.org/download/nim-1.4.2-linux_x64.tar.xz \
https://nim-lang.org/download/nim-1.4.2-linux_x64.tar.xz.sha256 (1)
$ sha256sum -c ./nim-1.4.2-linux_x64.tar.xz.sha256 (2)
nim-1.4.2-linux_x64.tar.xz: OK
$ tar tvf nim-1.4.2-linux_x64.tar.xz | lv (3)
$ tar xvf nim-1.4.2-linux_x64.tar.xz (4)
  1. nimのバイナリをダウンロード
  2. hash確認
  3. アーカイブ確認
  4. アーカイブ展開

Nitterのコンパイル

Nitterのsourceをcloneしてさっきダウンロードして展開したnimでコンパイルします.

$ git clone https://github.com/zedeus/nitter
$ cd nitter
$ PATH=~/nim-1.4.2/bin:$PATH nimble build -d:release
$ PATH=~/nim-1.4.2/bin:$PATH nimble scss
$ mkdir ./tmp

Redis が起動しているのを確認して nitter を起動してみます.この状態で 8080 ポートにアクセスして Nitter が利用できるのを確認します.ポート番号などは nitter.conf で変更できます.

$ ps -ef|grep -i redis (1)
redis    11786     1  0 Feb11 ?        00:15:28 /usr/bin/redis-server 127.0.0.1:6379
$ ./nitter & (2)
$ w3m http://localhost:8080/ (3)
$ kill %1 (4)
$ exit (5)
  1. Redisが動いているのを確認
  2. Nitterを起動
  3. Nitterの動作を確認
  4. Nitterを終了
  5. nitter アカウントから抜ける

Nitterの起動設定

次にNitterに起動設定を行います.Systemd環境なので以下のようなサービスファイルを用意しました.

/etc/systemd/system/nitter.service
[Unit]
Description=Nitter (An alternative Twitter front-end)
After=syslog.target
After=network.target

[Service]
Type=simple

# set user and group
User=nitter
Group=nitter

# configure location
WorkingDirectory=/home/nitter/nitter
ExecStart=/home/nitter/nitter/nitter

Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target

サービスを有効にしてNitterを起動します.

$ sudo systemctl enable --now nitter.service
$ systemctl status nitter
● nitter.service - Nitter (An alternative Twitter front-end)
   Loaded: loaded (/etc/systemd/system/nitter.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2021-02-17 01:13:07 JST; 34s ago
 Main PID: 19702 (nitter)
    Tasks: 1 (limit: 4696)
   Memory: 3.6M
   CGroup: /system.slice/nitter.service
           └─19702 /home/nitter/nitter/nitter
$ w3m http://localhost:8080/

外に公開せず,ローカルで動作させる場合はここまでの手順でOKです.

ドメインとSSL証明書の用意

※この手順はローカルで動かす場合は必要ありません.

今回はサブドメインを用意しました.DNSを設定して nitter.matoken.org を用意しました.設定ミスしたときにリカバリしやすいようにTTlを短く設定してうまく行ったらいつもの長さにします.

証明書はcertbotを使いLet’s encryptで作成しました.

$ sudo certbot certonly -d nitter.matoken.org

apache httpdの用意

※この手順はローカルで動かす場合は必要ありません.

Nitterをそのまま外に公開するのはセキュリティ的に良くないということで,apache httpdでhttpdの処理をしてNitterの8080に転送するようにしました.

Nitter用のapache httpd設定ファイルを用意します.

/etc/apache2/sites-available/nitter.matoken.org.conf
<VirtualHost *:80>
        ServerName nitter.matoken.org
        Redirect permanent / https://nitter.matoken.org/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName nitter.matoken.org
        ServerAdmin webmaster@matoken.org

        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>

        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8080/ nocanon
        ProxyPassReverse / http://127.0.0.1:8080/
        AllowEncodedSlashes On

        ErrorLog ${APACHE_LOG_DIR}/error.nitter.matoken.org.log
        CustomLog ${APACHE_LOG_DIR}/access.nitter.matoken.org.log combined

        SSLCertificateFile /etc/letsencrypt/live/nitter.matoken.org/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/nitter.matoken.org/privkey.pem

</VirtualHost>
</IfModule>

設定を有効にしてテスト後反映します.

$ sudo a2ensite nitter.matoken.org.conf (1)
$ sudo apache2ctl configtest (2)
$ sudo systemctl reload apache2 (3)
  1. 設定ファイルを有効にする
  2. 設定ファイルのテスト
  3. apache httpdの設定反映

この状態で http://nitter.matoken.org/ 及び https://nitter.matoken.org/ にアクセスしてみて Nitter が利用できたらOKです.

とりあえず一般公開しておきますが,今の https://nitter.net みたいにアクセス制限がしょっちゅうかかるようになったら制限するかもしれません.

環境

$ git -C ~nitter/nitter log -1
commit f392b6ca37e66c7c759aa98db23e0bdc62b39c3d (HEAD -> master, origin/master, origin/HEAD)
Author: Lukas Winkler <github@lw1.at>
Date:   Sun Feb 14 12:49:09 2021 +0100

    run optipng -o 9 on all images (#337)
$ dpkg-query -W apache2 redis* libsass-dev certbot
apache2 2.4.38-3+deb10u4
certbot 0.31.0-1+deb10u1
libsass-dev:amd64       3.5.5-4
redis-server    5:5.0.3-4+deb10u2
redis-tools     5:5.0.3-4+deb10u2
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/02/17/self-hosting-the-lightweight-twitter-front-end-nitter/feed/ 3
Nextcloudが Internal Server Error を返すようになって困った https://matoken.org/blog/2021/01/19/im-having-trouble-getting-nextcloud-to-return-an-internal-server-error/ https://matoken.org/blog/2021/01/19/im-having-trouble-getting-nextcloud-to-return-an-internal-server-error/#respond Mon, 18 Jan 2021 23:42:49 +0000 http://matoken.org/blog/?p=2924

NextcloudのWeb版にアクセスすると Internal Server Error が帰ってくるようになっていました.

20210119 00:01:55 1076844

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

別のユーザで試すとログイン画面は表示されて認証機能は動作します.しかしログイン後同じように Internal Server Error このときAndroid版アプリでは普通に利用できていそうです.

よくあるのがサポート対象外になったレガシーなアプリを導入すると同じような状態になることがあります.
しかし,前回利用できていたときと現在の間に特にディストリビューション, Nextcloud, Nextcloudアプリ共にアップデートはしていないはずです.

ログを確認するとhttpdのaccess/errorのlogは特に問題なさそう.
nextcloud.logでそれらしいのは file_put_contents failed でしょうか?

logはNextcloudの設定ファイルの config.php で確認できる.
$ grep log config/config.php
  'log_type' => 'file',
  'logfile' => '/var/log/nextcloud.log',
  'loglevel' => 0,
$ tail -f /var/log/nextcloud.log | jq .
errorっぽいところ?
{
  "reqId": "DVQsgBekfOCY3dvjYO6w",
  "level": 3,
  "time": "2021-01-18T14:59:53+00:00",
  "remoteAddr": "180.131.110.140",
  "user": "matoken",
  "app": "core",
  "method": "GET",
  "url": "/index.php/apps/files/",
  "message": {
    "Exception": "OCP\\Files\\GenericFileException",
    "Message": "file_put_contents failed",
    "Code": 0,
    "Trace": [
      {

まずは手動でファイルとデータベースのバックアップを取っておきます.

バックアップ例
$ sudo -u www-data php /var/www/files.matoken.org/occ maintenance:mode --on (1)
$ sudo -u www-data tar cvf - ${NEXTCLOUD_PATH} | xz > ${BACKUP_PATH}/nextcloud-`date +%F_%T`.tar.xz (2)
$ sudo -u www-data tar cvf - ${NEXTCLOUD_DATA_PATH} | xz > ${BACKUP_PATH}/nextcloud-data-`date +%F_%T`.tar.xz (3)
$ mysqldump --opt --all-databases --events | xz > ${BACKUP_PATH}/nextcloud-`date +%F_%T`.sql.xz (4)
$ sudo -u www-data php /var/www/files.matoken.org/occ maintenance:mode --off (5)
1 メンテナンスモードにする
2 Nextcloud自体のバックアップ
3 Nextcloudデータのバックアップ
4 データベースのバックアップ
5 メンテンスモードを終了

occmaintenance:repair コマンドを試します.

$ sudo -u www-data php ${NEXTCLOUD_PATH}/occ maintenance:repair
 - Repair MySQL collation
     - All tables already have the correct collation -> nothing to do
 - Repair mime types
  : 以下略

コマンド終了後webを再読込するとエラーは解消されました. :)

しかしファイルの一覧が表示されません.最新ファイルは表示されるのでそのファイルを確認すると表示されます.

次に occ files:scan を試してみました.

$ sudo -u www-data php ${NEXTCLOUD_PATH}/occ files:scan --all
Starting scan for user 1 out of 7 (user1)
  : ※省略
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 20752   | 34164 | 00:04:33     |
+---------+-------+--------------+

これでは変わらなかったようです.多分必要なかった.

次に occ files:scan-app-data を試します.

$ sudo -u www-data php ${NEXTCLOUD_PATH}/occ files:scan-app-data
Scanning AppData for files

+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 84      | 97    | 00:00:01     |
+---------+-------+--------------+

これが当たりだったようで復活しました!

ログを見るとこの問題が発生している間も他のNextcloudアプリは動作していたようだし,Androidアプリ版ではファイルの自動アップロードも動いていたようなので恐らくNextcloud Web版の部分が壊れていたのではないかと思います.

しかし治ったのはいいけどなぜこれが起こったかが謎なのが気持ち悪いです…….

環境
$ sudo -u www-data php /var/www/files.matoken.org/occ -V
Nextcloud 20.0.5
$ dpkg-query -W php mariadb-server
mariadb-server  1:10.3.27-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64

]]>
https://matoken.org/blog/2021/01/19/im-having-trouble-getting-nextcloud-to-return-an-internal-server-error/feed/ 0
Nextcloud 20.0.4のセキュリティ&セットアップ警告に対応 https://matoken.org/blog/2021/01/11/fixed-nextcloud-20-0-4-security-setup-warnings/ https://matoken.org/blog/2021/01/11/fixed-nextcloud-20-0-4-security-setup-warnings/#respond Mon, 11 Jan 2021 11:48:33 +0000 http://matoken.org/blog/?p=2916

先日 Nextcloud 19.0.6 から 20.0.4 にアップデートしました.
すると「セキュリティ&セットアップ警告」画面にいくつか警告が出てきたのでその対応メモです.

20201227 19:12:04 2470200

セキュリティ&セットアップ警告
サーバーのセキュリティとパフォーマンスにとって重要なことは、すべてが正確に設定されていることです。あなたの助けとなるよう、Nextcloudでは一部の自動チェックを行っています。詳細な情報は、リンク先のドキュメントを参照してください。

セットアップに関して警告がいくつかあります。
The old server-side-encryption format is enabled. We recommend disabling this. For more details see the documentation.
データベースにいくつかのインデックスがありません。 大きなテーブルにインデックスを追加すると、自動的に追加されないまでに時間がかかる可能性があるためです。 "occ db:add-missing-indices"を実行することによって、インスタンスが実行し続けている間にそれらの欠けているインデックスを手動で追加することができます。 インデックスが追加されると、それらのテーブルへのクエリは通常はるかに速くなります。
テーブル "oc_cards"のインデックス "cards_abiduri"が見つかりません。
The database is missing some primary keys. Due to the fact that adding primary keys on big tables could take some time they were not added automatically. By running "occ db:add-missing-primary-keys" those missing primary keys could be added manually while the instance keeps running.
Missing primary key on table "oc_federated_reshares".
Missing primary key on table "oc_systemtag_object_mapping".
Missing primary key on table "oc_comments_read_markers".
Missing primary key on table "oc_collres_resources".
Missing primary key on table "oc_collres_accesscache".
Missing primary key on table "oc_filecache_extended".
データベース内のいくつかの列で、big intへの変換が行われていません。 大きなテーブルでカラムタイプを変更すると時間がかかることがあるため、自動的には変更されませんでした。 'occ db:convert-filecache-bigint'を実行することによって、それらの保留中の変更は手動で適用できます。 この操作は、インスタンスがオフラインの間に行う必要があります。 詳細についてはこれに関するドキュメントページを読んでください。
federated_reshares.share_id
filecache_extended.fileid
share_external.id
share_external.parent
インストールガイド ↗を再確認して、 ログ にあるすべてのエラーや警告を確認してください。

データベースにいくつかのインデックスがありません。

データベースから修正していきます.まあ書いてあるコマンドを叩くだけですが.

$ sudo -u www-data php ${NEXTCLOUDPATH}/occ db:add-missing-indices
Check indices of the share table.
Check indices of the filecache table.
Check indices of the twofactor_providers table.
Check indices of the login_flow_v2 table.
Check indices of the whats_new table.
Check indices of the cards table.
Adding cards_abiduri index to the cards table, this can take some time...
cards table updated successfully.
Check indices of the cards_properties table.
Check indices of the calendarobjects_props table.
Check indices of the schedulingobjects table.
Check indices of the oc_properties table.

The database is missing some primary keys.

The database is missing some primary keys. Due to the fact that adding primary keys on big tables could take some time they were not added automatically. By running “occ db:add-missing-primary-keys” those missing primary keys could be added manually while the instance keeps running.
Missing primary key on table “oc_federated_reshares”.
Missing primary key on table “oc_systemtag_object_mapping”.
Missing primary key on table “oc_comments_read_markers”.
Missing primary key on table “oc_collres_resources”.
Missing primary key on table “oc_collres_accesscache”.
Missing primary key on table “oc_filecache_extended”.

$ sudo -u www-data php ${NEXTCLOUDPATH}/occ db:add-missing-primary-keys
Check primary keys.
Adding primary key to the federated_reshares table, this can take some time...
federated_reshares table updated successfully.
Adding primary key to the systemtag_object_mapping table, this can take some time...
systemtag_object_mapping table updated successfully.
Adding primary key to the comments_read_markers table, this can take some time...
comments_read_markers table updated successfully.
Adding primary key to the collres_resources table, this can take some time...
collres_resources table updated successfully.
Adding primary key to the collres_accesscache table, this can take some time...
collres_accesscache table updated successfully.
Adding primary key to the filecache_extended table, this can take some time...
filecache_extended table updated successfully.

データベース内のいくつかの列で、big intへの変換が行われていません。

データベース内のいくつかの列で、big intへの変換が行われていません。 大きなテーブルでカラムタイプを変更すると時間がかかることがあるため、自動的には変更されませんでした。 ‘occ db:convert-filecache-bigint’を実行することによって、それらの保留中の変更は手動で適用できます。 この操作は、インスタンスがオフラインの間に行う必要があります。

$ sudo -u www-data php ${NEXTCLOUDPATH}/occ db:convert-filecache-bigint
Following columns will be updated:

* federated_reshares.share_id
* filecache_extended.fileid
* share_external.id
* share_external.parent

This can take up to hours, depending on the number of files in your instance!
Continue with the conversion (y/n)? [n] y

The old server-side-encryption format is enabled. We recommend disabling this.

ここはE2EEで使うサーバサイドの暗号化形式で古い形式が有効になっているのを無効にしたほうがいいよって警告のようです.

The old server-side-encryption format is enabled. We recommend disabling this. For more details see the documentation.

古い形式が使われているかを確認します.

$ sudo -u www-data php ${NEXTCLOUDPATH}/occ encryption:scan:legacy-format
Scanning all files for legacy encryption
Scanning all files for matoken
Scanning all files for hoge
  :

encryption:scan:legacy-format

古い形式は使われていなかったので設定( ${NEXTCLOUDPATH/config/config.php )で明示的に無効にしてしまいます.

-  'encryption.legacy_format_support' => false,
+  'encryption.legacy_format_support' => true,

もし古い形式が残っていて移行したいでもマスターキーを設定していないという場合は該当ファイルの所持ユーザーにデータをコピーし直してもらう必要がありそうです.あまりやりたくない作業ですね.(以下のページを見るとクライアントがアップロードし直しをしてくれるのかもしれない)

これで再読込するとすべてのチェックに合格しました :)

20201227 19:12:47 2533788

環境
$ sudo -u www-data php /var/www/files.matoken.org/occ -V
Nextcloud 20.0.4
$ dpkg-query -W php mariadb-server
mariadb-server  1:10.3.27-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -vm
#1 SMP Debian 4.19.160-2 (2020-11-28) x86_64

]]>
https://matoken.org/blog/2021/01/11/fixed-nextcloud-20-0-4-security-setup-warnings/feed/ 0
Nextcloud 19からのNextcloudアプリ化したCollabora Online を試す https://matoken.org/blog/2020/06/05/the-nextcloud-app-ified-collabora-from-nextcloud-19-try-online/ https://matoken.org/blog/2020/06/05/the-nextcloud-app-ified-collabora-from-nextcloud-19-try-online/#comments Fri, 05 Jun 2020 14:14:10 +0000 http://matoken.org/blog/?p=2787

Nextcloud 19がリリースされました.

今回の新機能にCollabora Online がNextcloud Hub に含まれるようになり,簡単にすべてのユーザが利用できるようになったそうです.

Easy to install for every user
Collabora Online will be shipped out of the box with the new Nextcloud 19 Hub. A special community server has been developed, that can easily be installed with a single click by every user, and so avoiding web server and docker containers installation and configuration.

少し前にもデモサーバーを用意してくれてお手軽に試せるようにしてくれていましたが今回は自分の環境でとても簡単に動くようになったようです.

ということでNextcloud 19 にアップデートして試してみました.

Nextcloud 19環境管理者権限で https://$NEXTCLOUDURL/index.php/settings/admin/richdocuments にアクセスして設定を見てみます.

NC19 CODE 01

Use the built-in CODE という設定が増えています.がグレーアウトしています.

Use the built-in CODE – Collabora Online Development Edition
Easy to install, for personal use or for small teams. A bit slower than a standalone server and without the advanced scalability features.

てことで,以下のNextcloud アプリを導入します.

NC19 CODE 02

導入は本当に簡単で「ダウンロードして有効にする」を押すだけです.

コマンドラインではこんな感じで導入できます.

$ sudo -u www-data php ./occ app:install richdocumentscode
richdocumentscode installed
richdocumentscode enabled

導入されると Built-in CODE が選べるようになっているので選択します.後はファイルでオフィス文章を開いたり新規作成すれば自動的に起動して利用できます.

NC19 CODE 03

初回はちょっと時間がかかります.これはCODEが裏で起動する時間がかかるからみたいです.
後は普通に利用できます :)
Demoサーバと違って制限もないので普通に使えます.NextcloudでURL共有をするとGoogleDoc のようにみんなで同時にドキュメントを編集したりも出来ます.(Nextcloudの指定ユーザだけ編集可能とかURLを知ってる人は誰でも編集できるとかも出来ます.)

少し使っていて気になったのは以下のメッセージがたまに出ます.ディスク空き容量が 4GBで出るときと出ないときがありぎりぎり動いているのかなと思いましたが,空き容量を6GBに空けても出たり出なかったりします.もしかしたらバグかも?

NC19 CODE 04

そしてこちらの画面はセッションが数個(2個のつもり)でも出ます.セッションのカウントがおかしいのか他のバグなのか?

NC19 CODE 05

今回のCollabora Online はどんな仕組みなのかなとディレクトリを覗くと,Collabora Online がAppImage 化されてごろっと置かれているようです.

$ ls -l apps/richdocumentscode/collabora/
total 339320
-rwxr--r-- 1 www-data www-data 347455528 Jun  5 01:27 Collabora_Online.AppImage

これが文章を閉じてもずっと起動しているようです.RAMが少ないのでちょっと辛い.

$ ps aux | pee "head -1" "grep Collabora_OnlineAppImage"
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
mk       29361  0.0  0.0   2272   752 pts/2    S+   23:04   0:00 pee head -1 grep Collabora_OnlineAppImage

このマシンはリモートのサーバで日本語フォントがほとんど入っていないのでCollabora Online でもフォントがあまり選べません.システムにフォントを導入します.今回はNoto CJK を導入してみました.

$ sudo apt install fonts-noto-cjk

導入してもそのままではCollabora Online には反映されませんでした.文章を閉じて,AppImage のプロセスをkill して再度文章を開くとまた AppImage が起動して反映されました.

ということでとても簡単にWebだけでNextcloud からCollabora Online が導入できるようになりました.
とても便利なのでおすすめです.

環境
$ sudo -u www-data php ./occ app:list | grep richdocuments
  - richdocuments: 3.7.0
  - richdocumentscode: 4.2.403
$ sudo -u www-data php ./occ status
  - installed: true
  - version: 19.0.0.12
  - versionstring: 19.0.0
  - edition:
$ dpkg-query -W php apache2
apache2 2.4.38-3+deb10u3
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64
]]>
https://matoken.org/blog/2020/06/05/the-nextcloud-app-ified-collabora-from-nextcloud-19-try-online/feed/ 3
Nextcloud 18から19にbeta channel でアップグレード https://matoken.org/blog/2020/06/05/upgrade-from-nextcloud-18-to-19-with-beta-channel/ https://matoken.org/blog/2020/06/05/upgrade-from-nextcloud-18-to-19-with-beta-channel/#comments Fri, 05 Jun 2020 10:59:30 +0000 http://matoken.org/blog/?p=2783

Nextcloud 19が06/03にリリースされました.

未だ18からのアップデートは来ていませんが一時的に beta channel にして 19 にアップグレードしてみました.

$ sudo -u www-data php ./updater/updater.phar
Nextcloud Updater - version: v16.0.3-3-ga0c2b25 dirty

Current version is 18.0.5.

No update available.

Nothing to do.

先ずはバックアップをとっておきます.Nextcloudのディレクトリ以下とデータベースをバックアップしておけば最悪データが壊れたり消えてしまって復元できます.データが多いと時間がかかるので日頃取得して差分バックアップするようにしておくといいです.

次にscript コマンド等でログを取っておきます.リモートでssh経由の場合などはGNU screen やtmux などで切断されても復帰出来るようにしておきます.

準備が出来たら先ずは Nextcloud を18 の最新にしておきます.

$ cd $(NEXTCLOUDPATH}
$ sudo -u www-data php ./occ app:update --all
$ sudo -u www-data php ./updater/updater.phar
$ sudo -u www-data php ./occ app:update --all

Nextcloud の update channel を stable から beta にします.

$ sudo -u www-data php ./occ config:system:set updater.release.channel --value 'beta'
System config value updater.release.channel set to string beta

channel はすぐには反映されません.今回は20分ほどで反映されました数時間掛かることもあるよう.
19 が降りてきたら後は普通にアップグレードします.

$ sudo -u www-data php ./updater/updater.phar
Nextcloud Updater - version: v16.0.3-3-ga0c2b25 dirty

Current version is 18.0.5.

Update to Nextcloud 19.0.0 available. (channel: "beta")
Following file will be downloaded automatically: https://download.nextcloud.com/server/releases/nextcloud-19.0.0.zip
Open changelog ↗

Steps that will be executed:
[ ] Check for expected files
[ ] Check for write permissions
[ ] Create backup
[ ] Downloading
[ ] Verify integrity
[ ] Extracting
[ ] Enable maintenance mode
[ ] Replace entry points
[ ] Delete old files
[ ] Move new files in place
[ ] Done

Start update? [y/N] y
Info: Pressing Ctrl-C will finish the currently running step and then stops the updater.

[✔] Check for expected files
[✔] Check for write permissions
[✔] Create backup
[✔] Downloading
[✔] Verify integrity
[✔] Extracting
[✔] Enable maintenance mode
[✔] Replace entry points
[✔] Delete old files
[✔] Move new files in place
[✔] Done

Update of code successful.

Should the "occ upgrade" command be executed? [Y/n]
  :
  :
Keep maintenance mode active? [y/N]
Maintenance mode disabled

Maintenance mode is disabled

Nextcloud 19 になりました :)

Nextcloud19 00

$ sudo -u www-data php /var/www/files.matoken.org/updater/updater.phar
Nextcloud Updater - version: v16.0.3-3-ga0c2b25 dirty

Current version is 19.0.0.

No update available.

Nothing to do.

channel を stable に戻しておきます.一旦19に上げていれば18に戻りません.

$ sudo -u www-data php /var/www/files.matoken.org/occ config:system:set updater.release.channel --value 'stable'
System config value updater.release.channel set to string stable
$ sudo -u www-data php /var/www/files.matoken.org/updater/updater.phar
Nextcloud Updater - version: v16.0.3-3-ga0c2b25 dirty

Current version is 19.0.0.

No update available.

Nothing to do.

https://$NEXTCLOUDURL/index.php/settings/admin/overview の「セキュリティ&セットアップ警告」を確認するといくつかメッセージが出ているので修正します.

Nextcloud19 01

セキュリティ&セットアップ警告
サーバーのセキュリティとパフォーマンスにとって重要なことは、すべてが正確に設定されていることです。あなたの助けとなるよう、Nextcloudでは一部の自動チェックを行っています。詳細な情報は、リンク先のドキュメントを参照してください。

セットアップに関して警告がいくつかあります。
データベースにいくつかのインデックスがありません。 大きなテーブルにインデックスを追加すると、自動的に追加されないまでに時間がかかる可能性があるためです。 “occ db:add-missing-indices”を実行することによって、インスタンスが実行し続けている間にそれらの欠けているインデックスを手動で追加することができます。 インデックスが追加されると、それらのテーブルへのクエリは通常はるかに速くなります。
テーブル “oc_properties”のインデックス “properties_path_index”が見つかりません。
データベースにはオプションのカラムがいくつかありません。大きなテーブルにカラムを追加するには時間がかかるため、オプションのカラムは自動的に追加されませんでした。”occ db:add-missing-columns”を実行することで、不足しているカラムはインスタンスの実行中に手動で追加することができます。カラムが追加されると、応答性や使い勝手が改善される可能性があります。
テーブル “oc_comments” にオプションのカラム “reference_id” が存在しません。
このインスタンスには推奨されるPHPモジュールがいくつかありません。 パフォーマンスの向上と互換性の向上のために、それらをインストールすることを強くお勧めします。
bcmath
gmp
インストールガイド ↗を再確認して、 ログ にあるすべてのエラーや警告を確認してください。

Nextcloudのセキュリティは、セキュリティスキャン ↗でチェックしてください。

と言っても基本的にメッセージに従うだけです.

データベースにいくつかのインデックスがありません。
$ sudo -u www-data php ./occ db:add-missing-indices
Check indices of the share table.
Check indices of the filecache table.
Check indices of the twofactor_providers table.
Check indices of the login_flow_v2 table.
Check indices of the whats_new table.
Check indices of the cards table.
Check indices of the cards_properties table.
Check indices of the calendarobjects_props table.
Check indices of the schedulingobjects table.
Check indices of the oc_properties table.
Adding properties_path_index index to the oc_properties table, this can take some time...
oc_properties table updated successfully.
データベースにはオプションのカラムがいくつかありません。
$ sudo -u www-data php ./occ db:add-missing-columns
Check columns of the comments table.
Adding additional reference_id column to the comments table, this can take some time...
Comments table updated successfully.
このインスタンスには推奨されるPHPモジュールがいくつかありません。

これは環境によって少し代わります.対応パッケージを導入してhttpdを再起動して反映します.以下はDebian Buster amd64 でのパッケージ名.そしてApache httpd でホストしている場合の例です.

$ sudo apt install php7.3-bcmath php7.3-gmp
$ sudo service apache2 reload

これで「セキュリティ&セットアップ警告」ページを再読込すると,「すべてのチェックに合格しました。」となりました :)

Nextcloud19 02

古いバックアップの削除

これは必須ではないのですが,この環境はディスクの空き領域が少ないのでリモートにバックアップした上で最新以外のバックアップは削除しています.以下の updater-ocws62au2wl3 部分は環境によって変わると思います.

$ rm -rf ./data/updater-ocws62au2wl3/backups/nextcloud-18.0.4.2
環境
$ dpkg-query -W php7.3 php7.3-bcmath php7.3-gmp apache2
apache2 2.4.38-3+deb10u3
php7.3  7.3.14-1~deb10u1
php7.3-bcmath   7.3.14-1~deb10u1
php7.3-gmp      7.3.14-1~deb10u1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64

]]>
https://matoken.org/blog/2020/06/05/upgrade-from-nextcloud-18-to-19-with-beta-channel/feed/ 1