watermint.org - Takayuki Okazaki's note

Google AnalyticsとAmazon Affiliateのトラッキングを削除しました

本ブログではGoogle AnalyticsとAmazon Affiliateのリンクをいくつか利用していましたが、それらを削除しました。これにより、本サイトにお越しいただいた方を追跡することはなくなりました。また、過去のGoogle Analyticsログについても削除いたしました。

クッキーについては現在は、配信サーバであるCloudflareのクッキーのみでこちらは主に配信制御用のものです。

今回は特に何か問題があったための対処ではなく、もともと分析やアフィリエイトも活用していなかったことと、プライバシー保護は今後基本的なものとなるだろうとの考えからです。

PageSpeedで100点になりました

もっと良い作用としてはサイトの表示スピードが速くなりました。WordPressからTumblrへ移行し、TumblrからGithub Pagesへ移行したことで数秒かかっていた表示が1秒台ぐらいに改善していました。今回配信インフラをGithub PagesからCloudflare Workersに変更したことが大きいですが、最後の一押しとしてGoogle Analyticsの削除でさらに高速化され表示時間は0.3秒程度になり、PageSpeedによる評価も無事100点をいただけました。

Dropbox/Dropbox Business: 共有リンクを操作するCLI - watermint toolbox

watermint toolboxではDropboxまたはDropbox Business用のコマンドを各種揃えています。今回はDropboxの個人アカウントまたはDropbox Businessチーム全体に対する共有リンクを操作するコマンドを紹介します。

共有リンクの一覧

チーム内の共有リンクをすべてレポートとして出力することで、監査や管理上の資料として利用できます。なお、このコマンドではチームメンバー全員の共有リンクを取得して一覧を作成しますので、チームメンバー数が多い場合には相応の時間がかかります。

詳細はマニュアルに記載していますが、最新版のプログラムをダウンロードして解凍し、次のようなコマンドを実行します。なお、例ではプログラムをデスクトップに解凍したことを想定しています。

WindowsではまずPowerShellを起動し、次のようなコマンドを実行します。(なお、PowerShellへの依存関係はなくコマンドプロンプトやバッチファイルからの起動でも動作します)

まずデスクトップフォルダに移動します。

cd Desktop

続いてプログラムを実行します。

.\tbx.exe team sharedlink list

これでしばらく待つとレポートが作成されます。レポートファイルはCSV、xlsx、JSON形式の3種類出力され、画面上にレポートが作成されたパスが表示されます。レポートの書式についてはマニュアルを参照してください。

全体のチーム内の共有リンク有効期限を上書きする

このコマンドでは共有設定で、リンクを知っている人全員となっているチーム内の共有リンクに対して有効期限を上書きすることで実質的には公開リンクを削除できます。有効期限の指定方法は現時点からの日数、または指定した日時です。

たとえば有効期限を30日後に設定したい場合には次のように実行します。

.\tbx.exe team sharedlink update expiry -days 30

これで全ての公開共有リンクの有効期限を30日に上書きします。なお、有効期限が30日以内であるばあいには上書きしませんので、定期的にこのコマンドを実行してチーム全体の有効期限を管理することも可能です。

また、指定日時での有効期限指定も可能です。たとえば、年度末を有効期限としたい場合には次のように実行します。

.\tbx.exe team sharedlink update expiry -at 2021-04-01

このように -at オプションに続けて日時を指定するとその日時で上書きします。 詳細はマニュアルをご参照ください。

WIFIルーター評: NETGEAR RAX120

NETGEAR AX12 RAX120というWifiルーターを新しく導入しました。

少し前までSynology MR2200acというルーターを使っていましたが、頻繁にインターネット接続が切れてしまい、またルーターを再起動しないと復元しませんでした。ルーターのログや統計情報を見てみるとうまくいかない状況下ではルーターのCPU使用率がかなり上がっており、Load averageで4〜5 (いつもは1未満)になっているようでした。 このことから、おそらくCPUスペックが不足しているだろうということでより強力なCPUをもつルーターを探して入れ替えることにしました。

消去法にて

自宅ネットワーク環境はIIJmioひかりのIPoEオプションを契約しています。DS-Liteに対応したルーターを選ぶことになりました。探してみるとまだあまり対応製品は多くないようで、Wifi 6に対応したものに狭めるとまた選択肢が狭まりました。さらにアンテナがあまりトゲトゲと飛び出していないものにしたかったので消去法にてNETGEAR AX12 RAX120に決定しました。

評価

電波強度は申し分ないのですが、どちらかというとSynology MR2200acと比べ劣ると感じる部分がいくつかありますのでそちらを紹介していきます。

ログが使い物にならない

ログ

管理画面からログを取得できますが、このログはほとんど使い物になりません。まず、ログに時刻が含まれない。さらに、ログ1行の長さが128バイトを超えると超過分は無視され記録され全文は読み取れません。ログをメールで送信する設定をした際もエラーが全文読み取れず、原因はついに分からずじまいでした。

iPhoneなどからの接続が時々切れているように見え、iPhone側からは接続ができているように見えていたのでDHCP問題かと思い調べようとしたところ、それに繋がりそうなログは一切表示されませんでした。DS-Liteの設定時も接続画面ではエラーと表示されるが具体的に何が失敗したのかはわかりませんでした。

実用上、本機にログ取得・表示機能は無いと考えた方が良いでしょう。このあたりは是非改善していただきたいところです。

Web GUIは貧弱

スマートフォンアプリにて管理機能がありますがこちらはなかなか項目もシンプルで表示も見やすく、よくできていると思います。

一方、Web GUIについてはSynologyのGUIは非常に良くできているのでこの2機種で対比するとNETGEAR側がかなり見劣りすると言わざるを得ないでしょう。CPUやメモリ利用の統計情報も時系列情報はありませんし、ログとしても取り出せないようです。

GUIは初期設定と、トラブル対応時くらいしか利用しませんからトラブルさえなければこの評価の重要性は状況によって大きく変わります。今回引き続きネットワーク接続の問題が出ているので手がかりがほぼゼロと言えるNETGEARのGUIは満足度を酷く低下させるものでした。

Synologyでもネットワーク接続断の問題は最終的に問題解決には至りませんでしたが、統計情報やエラーなど情報が見えることによる安心感があったように思います。

NETGEAR ARMOR

NETGEAR ARMORというBitdefenderによる脆弱性スキャン、脅威の自動ブロック、アンチマルウエアソフトウエアが年間サブスクリプションでの追加オプションとして利用できます。

幸いなことにまだ脅威となるインシデントは発生していないのでどの程度の安心かは未知数ですが、テストなどのために古いiPhoneやAndroidを接続してテストするときには一定の安心感が得られそうです。

総評

セットアップもお任せモードが比較的良くできているので、すべてお任せという状態で動けばとても素直なルーターと言えると思います。一方で、何かトラブルが発生したときにはその原因にたどり着くの難しく、賭けの要素が強い製品です。

Batch Gmail filter creation CLI - watermint toolbox

New Gmail-related commands have been added to the watermint toolbox. This allows you to get a list of emails from the command line, add/remove/rename labels, and add/remove filters.

% tbx services google mail label list

watermint toolbox 72.4.544
==========================

© 2016-2020 Takayuki Okazaki
Licensed under open source licenses. Use the `license` command for more detail.

Testing network connection...
Done

Opening the authorization URL:
https://accounts.google.com/o/oauth2/auth?client_id=xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A7800%2Fconnect%2Fauth&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.labels&state=xxxxxxxx

Please press ENTER to open the auth page on the browser.

| name                         | type   |
|------------------------------|--------|
| CHAT                         | system |
| SENT                         | system |
| INBOX                        | system |
| IMPORTANT                    | system |
| TRASH                        | system |
| DRAFT                        | system |
| SPAM                         | system |
| CATEGORY_FORUMS              | system |
| CATEGORY_UPDATES             | system |
| CATEGORY_PERSONAL            | system |
| CATEGORY_PROMOTIONS          | system |
| CATEGORY_SOCIAL              | system |
| STARRED                      | system |
| UNREAD                       | system |
| services/google.com          | user   |
| services/accounts.google.com | user   |
| services/youtube.com         | user   |


The report generated: /xxxxx/xxxxxxxx/.toolbox/jobs/20200727-074430.001/report/labels.csv
The report generated: /xxxxx/xxxxxxxx/.toolbox/jobs/20200727-074430.001/report/labels.json
The report generated: /xxxxx/xxxxxxxx/.toolbox/jobs/20200727-074430.001/report/labels.xlsx

If you want to use it, please use Release 72 or later.

I label and manage each source to some extent as I process a variety of emails. This is also a bit of a hassle when the number of source types increases, and I counted the number of labels in the command I created this time, and there are already 343 labels.

% tbx services google mail label list -output json | jq 'select(.type == "user") | .id ' | wc -l
     343

I checked the number of filters created in the same way and found 474.

% tbx services google mail filter list -output json | wc -l
     474

I have been making labels and filters by hand for several years now, but it’s getting tedious, so I made it possible to create labels and filters in batches based on certain conditions. So far, it’s not fully automated, but semi-automated once the CSV data file is created.

Create the source data for the label/filter you want to create.

There are two types of Gmail labels. (1) system labels that are automatically assigned by Gmail, such as INBOX and SPAM, and (2) user-defined user labels. In this time, I’m going to get the list of emails in INBOX and get the data with no user labels attached. In this case, I will add label conditions based on the destination address and source address of the email.

First of all, get the email data, get the source address, and make rules for each domain. I’ve omitted quite a bit, but I get the mail data in JSON format, process it with the jq command and output it as CSV. The first column is the query, the second column is the label to be added, and the third column is the label to be removed. The third column is not specified. If you want to archive automatically, you can do so by deleting INBOX.

% tbx services google mail message processed list -output json | jq -r 'select(.label_type_user | length ==0) | .from.address | ["from:"+., "services/"+capture("@(?<d>\\b([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,}\\b)").d] | @csv' | sort -u
"from:families-noreply@google.com","services/google.com"
"from:googlecommunityteam-noreply@google.com","services/google.com"
"from:no-reply@accounts.google.com","services/accounts.google.com"
"from:no-reply@google.com","services/google.com"
"from:noreply-purchases@youtube.com","services/youtube.com"

Create a batch filter based on this data. It also automatically creates any missing labels and applies them to the messages in the INBOX.

% tbx services google mail filter batch add -add-label-if-not-exist -apply-to-inbox-messages -peer waterlandpier -file ~/filters.csv

watermint toolbox `dev`
=======================

© 2016-2020 Takayuki Okazaki
Licensed under open source licenses. Use the `license` command for more detail.

Creating a filter: from:families-noreply@google.com
from:families-noreply@google.com: Updating message 1
from:families-noreply@google.com: Updating message 2
Creating a filter: from:googlecommunityteam-noreply@google.com
from:googlecommunityteam-noreply@google.com: Updating message 1
Creating a filter: from:no-reply@accounts.google.com
from:no-reply@accounts.google.com: Updating message 1
from:no-reply@accounts.google.com: Updating message 2
from:no-reply@accounts.google.com: Updating message 3
from:no-reply@accounts.google.com: Updating message 4
from:no-reply@accounts.google.com: Updating message 5
from:no-reply@accounts.google.com: Updating message 6
from:no-reply@accounts.google.com: Updating message 7
Creating a filter: from:no-reply@google.com
Creating a filter: from:noreply-purchases@youtube.com
from:noreply-purchases@youtube.com: Updating message 1

| status | reason | input.query                                 | input.add_labels             | input.delete_labels | result.id                              | result.criteria_from | result.criteria_to | result.criteria_subject | result.criteria_query                       | result.criteria_negated_query |
|--------|--------|---------------------------------------------|------------------------------|---------------------|----------------------------------------|----------------------|--------------------|-------------------------|---------------------------------------------|-------------------------------|
| 成功   |        | from:families-noreply@google.com            | services/google.com          |                     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |                      |                    |                         | from:families-noreply@google.com            |                               |
| 成功   |        | from:googlecommunityteam-noreply@google.com | services/google.com          |                     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |                      |                    |                         | from:googlecommunityteam-noreply@google.com |                               |
| 成功   |        | from:no-reply@accounts.google.com           | services/accounts.google.com |                     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |                      |                    |                         | from:no-reply@accounts.google.com           |                               |
| 成功   |        | from:no-reply@google.com                    | services/google.com          |                     | xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxx |                      |                    |                         | from:no-reply@google.com                    |                               |
| 成功   |        | from:noreply-purchases@youtube.com          | services/youtube.com         |                     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |                      |                    |                         | from:noreply-purchases@youtube.com          |                               |


The report generated: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/filters.csv
The report generated: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/filters.json
The report generated: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/filters.xlsx
The report generated: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/messages.csv
The report generated: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/messages.json
The report generated: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/messages.xlsx

I don’t usually have time to create filters in batches, so I’m hoping this will make my email processing a little more efficient.

Gmailのフィルタを一括作成するCLI - watermint toolbox

watermint toolboxに新しくGmail関連のコマンドを追加しました。これにより、コマンドラインからメール一覧を取得したり、ラベルを追加・削除・名前変更したり、フィルタを追加・削除できるようになりました。

% tbx services google mail label list

watermint toolbox 72.4.544
==========================

© 2016-2020 Takayuki Okazaki
オープンソースライセンスのもと配布されています. 詳細は`license`コマンドでご覧ください.

ネットワーク接続をテストしています...
完了

認可URLを開きます:
https://accounts.google.com/o/oauth2/auth?client_id=xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A7800%2Fconnect%2Fauth&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.labels&state=xxxxxxxx

ENTERを押してブラウザ上で認証ページを開いてください


| name                         | type   |
|------------------------------|--------|
| CHAT                         | system |
| SENT                         | system |
| INBOX                        | system |
| IMPORTANT                    | system |
| TRASH                        | system |
| DRAFT                        | system |
| SPAM                         | system |
| CATEGORY_FORUMS              | system |
| CATEGORY_UPDATES             | system |
| CATEGORY_PERSONAL            | system |
| CATEGORY_PROMOTIONS          | system |
| CATEGORY_SOCIAL              | system |
| STARRED                      | system |
| UNREAD                       | system |
| services/google.com          | user   |
| services/accounts.google.com | user   |
| services/youtube.com         | user   |


レポートが作成されました: /xxxxx/xxxxxxxx/.toolbox/jobs/20200727-072609.001/report/labels.csv
レポートが作成されました: /xxxxx/xxxxxxxx/.toolbox/jobs/20200727-072609.001/report/labels.json
レポートが作成されました: /xxxxx/xxxxxxxx/.toolbox/jobs/20200727-072609.001/report/labels.xlsx

お試しになりたい場合はRelease 72以降をお使いください。

このコマンド群はおもにメールの整理整頓用に整備したもので、今回早速このコマンドを使ってメールを整理してみました。

私は様々なメールを処理する中である程度送信元ごとにラベルをつけて管理しています。これも送信元の種別が増えてくるとなかなか手間を感じてくるもので、今回作成したコマンドで数えてみたところラベル数は343個すでにあるようです。

% tbx services google mail label list -output json | jq 'select(.type == "user") | .id ' | wc -l
     343

同様に作成済みフィルタ数を調べてみたところ474個ありました。

% tbx services google mail filter list -output json | wc -l
     474

これまで数年かけてコツコツ手作業で作ってきましたが、流石にそろそろ面倒になってきたのでラベルやフィルタを一定の条件をもとに一括作成できるようにしました。今のところ、完全自動作成ではなく一度CSVデータファイルを作成した上での半自動化となっています。

作りたいラベル・フィルタの元データを作る

Gmailのラベルには2種類あります。(1) INBOXやSPAMなどGmailが自動的に付与するシステムラベル、(2) ユーザー定義のユーザーラベルです。今回はINBOXに入っているメール一覧を取得して、ユーザーラベルが付与されていないデータを取得します。今回はメールの宛先アドレスや送信元アドレスからラベル条件をつけていきます。

まずはメールデータを取得して送信元アドレスを取得し、ドメインごとにルールを作ることにしましょう。かなり省略してしまいましたが、メールデータをJSON形式で取得しjqコマンドで加工の上CSVとして出力しています。1列目がクエリ条件、2列目が追加するラベル、3列目が削除するラベルです。3列目は今回指定していませんが、たとえば自動的にアーカイブ処理したい場合はINBOXを削除すれば実現できます。

% tbx services google mail message processed list -output json | jq -r 'select(.label_type_user | length ==0) | .from.address | ["from:"+., "services/"+capture("@(?<d>\\b([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,}\\b)").d] | @csv' | sort -u
"from:families-noreply@google.com","services/google.com"
"from:googlecommunityteam-noreply@google.com","services/google.com"
"from:no-reply@accounts.google.com","services/accounts.google.com"
"from:no-reply@google.com","services/google.com"
"from:noreply-purchases@youtube.com","services/youtube.com"

このデータをもとにフィルタを一括作成します。また、不足しているラベルは自動作成し、INBOX内のメッセージにもラベルを適用します。

% tbx services google mail filter batch add -add-label-if-not-exist -apply-to-inbox-messages -peer waterlandpier -file ~/filters.csv

watermint toolbox 72.4.544
==========================

© 2016-2020 Takayuki Okazaki
オープンソースライセンスのもと配布されています. 詳細は`license`コマンドでご覧ください.

フィルタを作成しています: from:families-noreply@google.com
from:families-noreply@google.com: メッセージ 1を更新しています。
from:families-noreply@google.com: メッセージ 2を更新しています。
フィルタを作成しています: from:googlecommunityteam-noreply@google.com
from:googlecommunityteam-noreply@google.com: メッセージ 1を更新しています。
フィルタを作成しています: from:no-reply@accounts.google.com
from:no-reply@accounts.google.com: メッセージ 1を更新しています。
from:no-reply@accounts.google.com: メッセージ 2を更新しています。
from:no-reply@accounts.google.com: メッセージ 3を更新しています。
from:no-reply@accounts.google.com: メッセージ 4を更新しています。
from:no-reply@accounts.google.com: メッセージ 5を更新しています。
from:no-reply@accounts.google.com: メッセージ 6を更新しています。
from:no-reply@accounts.google.com: メッセージ 7を更新しています。
フィルタを作成しています: from:no-reply@google.com
フィルタを作成しています: from:noreply-purchases@youtube.com
from:noreply-purchases@youtube.com: メッセージ 1を更新しています。

| status | reason | input.query                                 | input.add_labels             | input.delete_labels | result.id                              | result.criteria_from | result.criteria_to | result.criteria_subject | result.criteria_query                       | result.criteria_negated_query |
|--------|--------|---------------------------------------------|------------------------------|---------------------|----------------------------------------|----------------------|--------------------|-------------------------|---------------------------------------------|-------------------------------|
| 成功   |        | from:families-noreply@google.com            | services/google.com          |                     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |                      |                    |                         | from:families-noreply@google.com            |                               |
| 成功   |        | from:googlecommunityteam-noreply@google.com | services/google.com          |                     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |                      |                    |                         | from:googlecommunityteam-noreply@google.com |                               |
| 成功   |        | from:no-reply@accounts.google.com           | services/accounts.google.com |                     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |                      |                    |                         | from:no-reply@accounts.google.com           |                               |
| 成功   |        | from:no-reply@google.com                    | services/google.com          |                     | xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxx |                      |                    |                         | from:no-reply@google.com                    |                               |
| 成功   |        | from:noreply-purchases@youtube.com          | services/youtube.com         |                     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |                      |                    |                         | from:noreply-purchases@youtube.com          |                               |


レポートが作成されました: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/filters.csv
レポートが作成されました: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/filters.json
レポートが作成されました: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/filters.xlsx
レポートが作成されました: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/messages.csv
レポートが作成されました: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/messages.json
レポートが作成されました: /xxxxx/xxxxxxxx/.toolbox/jobs/20200726-223228.001/report/messages.xlsx

フィルタを一括作成したいようなときは大抵時間がないので、これで少しでもメール処理の効率が上がればと思っています。