sendmailを止めることに

MTAへ激しく攻撃されっぱなしで,止めるというのはなんか残念な気もしますが,今sendmailが本来のメール送受信のために動くのは日に2回+不定期的なWordpressからのupdate案内しかなく,それに対して日に千回近い攻撃にさらすのはバカバカしくもあります.

先に書きましたように,攻撃による実害はあまり大したことはないのですが,iptablesでDROPするipアドレスを約1万個登録してあってこれがRaspberry Piの貴重な実メモリーに展開されているのが一番バカバカしいです.

sendmailとは長い付き合いでした.使い始めた1990年代半ばには,ほとんどのLinux distroに標準でついていて,デフォルトで動くような設定だったと思います.

自前でメーリングリスト(ML)を立ち上げるのに使ったり,またアマチュア無線のパケット通信のメールのゲートウェーにも使ったりしていました.

その後SPAMが社会問題化して,個人の動かしているsendmailをはじめとしたMTAからのメール送信を受け付けるサイトがほとんどなくなりました.MLも自分で動かしていると,サーバーがダウンしたりメンテする時にやっかいなので,もうずいぶん前に大手IT会社のサービスに移行しました.

あと,自前のMTAの大きなメリットは,メールアドレスを好きなだけ作れるということです.怪しいサイトや,有名だけど関わりたくない会社のサイトにアカウントをとりあえず作る時に,

適当な名前@ホスト.ドメイン

の形で作ったメールアドレスをIDとして使用します. “適当な名前” はそれこそなんでもいいので無数に作れます.確認メールの受信などの用が済んだらIDを消すか,/dev/nullに転送するようにすればよいです.

これも,使い捨てメールアカウントを提供するサービスでたいてい足りますが,自前でできるというのがミソでした.

現在受信しているメールは,一つは手動で,もう一つは自動的にメールが発せられ,それを大手IT会社を経由してこちらのsendmailが受けていますが,これらもあえて自前のMTAを介する必要はなく,生存確認のためのようなもんです

ということで,1日に2通のメールを受けるため,何百何千の攻撃を避ける運用を続けながらおよぞ30年の長きにわたり使用してきたsendmailを近々止めることにします.

現在は大手IT会社数社に認証したうえでメールを送り出しています.
技術的に面倒だろうと現時点で考えられるのはWordpressが不定期的に発するメールをどうやって外に出すかということです.

MTAへの激しい攻撃

2024年2月15日(木)あたりから,管理しているサーバーへMTAの認証を求める “攻撃” が続いています.攻めてきたIPアドレスをiptablesに登録してアクセスできないようにしていますが,次から次へと新しいIPアドレスを使って攻めてきます.今回の攻撃だけですでに1000近い数のIPアドレスが使われています.

同種の攻撃はこれまでもさんざんありました.目的はSPAMやPhishing, 脅迫などの犯罪行為のメールを拡散するための踏み台にすることだと思います.

実害はほとんどないし,認証を破られることもないとは思いますが,気持ち悪いのでしばらくはいつも以上に気をつけてみていこうと思います.

ネットの若干のバンド幅,サーバーのCPU使用,ログファイルのためのデータ領域とiptablesのための主記憶等の占有が実害といえば実害です.

RTSPの視聴が不調 (2) マクドもffplay

関東ではマックといいますが,フランスではマクドというらしいです.

VLC macOS版の3.0.20 (Intel 64bit版)も,うちのカメラのRTSPを表示してくれなくなりました.ずっとこのバージョンのままのような気もするので,カメラ側の仕様が変更になってコンパチビリティーが失われたのかもしれません(少し前にカメラのfirmwareのupdateがありました).

Raspberry Pi OS版のVLCも含めて症状は同じで,カメラに接続したその時の画像が静止したままです.システムもVLCも生きていて,

killall vlc

で止められます.

それでマクドミニの方でもffplayを試してみようかと思ったら,当然ですがX用しかなく,まずXQuartzをupdateしてからMacPortsでFFMPEGをインストールしました.

その結果大きな問題なく動きました.

正常に動いた場合のVLCと比較して,Raspberry Pi OS版と同様に小さいブロックノイズが時々出ます.また時間遅れがかなりあります

VLCでは出ません.
遅れが蓄積していくかは検証してません.

クリーンインストールが楽 (Raspberry Pi OS Bookworm UG)

Raspberry Pi 3 (Raspberry Pi OS Bullseye)でRTSPを見るのはffplayが楽だと記事を書いた翌日に,Raspberry Pi OS Bookwormがリリースされました.Debian Bookwormは随分前にリリースされ,Raspberry Pi OS Bookwormも近々リリースされると聞いてはいましたが,翌日とはなんというめぐり合わせでしょう.

それで,早速Raspberry Pi 3 Model Bと同Model B+にインストールしてあるRaspberry Pi OSをBullseyeからBookwormにupgradeしてみましたが,結構手間と時間がかかるうえ,ちょっとしたトラブルにも巻き込まれてしまいました.

もし,Raspberry PiをRTSPを見るなど単機能のみに使用するのでしたら,クリーンインストールのほうがずっと楽だし時間もかかかりませんし,トラブルも起きにくいです.

Upgradeしてだめならクリーンインストールという方が時間を潰すには適していますが😅

ところで,Raspberry Pi OS Bookwormもデフォルトのインストールでは,swapにファイルを使うdphys-swapfileでした.SDカードをswapに使うのは全くメリットがないので,デフォルトでZRAMを採用してほしかったですが,まあたぶん開発元ではいろんな議論があったのでょう.

書き込みが遅いし書き込みを繰り返すと寿命が来る.

How to View RTSP by Raspberry Pi 3 Using ffplay (FFMPEG)

The following article is outdated. For the Raspberry Pi OS only, you can use VLC to watch RTSP as of 3 November 2023.

Original Article follows;

For Raspberry Pis, there are many outdated or sometimes harmful guides to watching video streams (RTSP) generated by webcams. The biggest issue obstructing the approach is that Debian removed RTSP capability from the VLC media player. People who want to simply watch RTSP on the Raspberry Pi are straying.

The goal of this article is to run ffplay on the Raspberry Pi OS automatically.

Disclaimer

The first purpose of this article is to record what I did. However, I am happy if this will be helpful to someone, no matter how much or little. I would like to state this article is based on GPLv3. No warranty at all.

Prior Information

  • The information in this article is tested on Raspberry Pi 3 Model B (RPi3) and Raspberry Pi 3 Model B+ (RPi3+) both of them have 1GB RAM. Raspberry Pi 4 Model B is not tested but may work as well.
  • URL to webcam is in the form of “rtsp://user_id:password@ipaddress/designated_string”
  • Used OS is Raspberry Pi OS bullseye. The next generation, bookworm, will be released soon. This article will or will not be updated after bookworm release.

Raspberry Pi OS installation

Details of the OS installation are omitted in this article because there are many guides, including official and unofficial ones. It is lucky if you find one that suits to you. The installation is not difficult, so you can manage to install it even if the guide you found is not friendly.

The recommendable points are as follows:

  • Install Raspberry Pi OS (64bit) full version, not the LITE version.
  • Enable auto-login (just according to the default).
  • Disable screen blanking.
  • Enable the ssh server (sshd).

The following section assumes the WiFi setup is finished and that all packages have been updated.

Recommended Option: Zram

This is not a must, but I strongly recommend installing ZRAM. Many distros enable ZRAM on their default installation today, but Raspberry Pi OS bullseye doesn’t.

Installation is not difficult. Just install zram-tools with an apt command like,

sudo apt install zram-tools

then swap on the RAM with compression starts functioning. ZRAM has extremely high priority, so the bullseye default, swap-on-file, will never work again. Because the swap file remains just a huge, redundant file, you may want to remove it. It is removed as follows:

sudo systemctl stop dphys-swapfile
sudo systemctl disable dphys-swapfile
sudo rm -v /var/swap

Test ffplay

During the OS installation, you have a mouse, a keyboard, and a monitor connected to the RPi3(+). Keep them connected until the set-up finishes.

The program to view RTSP, ffplay, is included in the FFMPEG package that comes with the Raspberry Pi OS. Open a terminal and execute the next command as a user.

ffplay -fs -loglevel quiet rtsp://user_id:password@ip_address/designated_string

where use_id, password, ip_address, and designated_string are those of the corresponding webcam.

If you get a full-screen video stream, you are one step closer. If you can’t, I can just say “It depends.”

Type “q” to quit the video.

Next, create a shell script file as a user with your favorite editor. You can name it whatever you like. For simplicity, it is named “run_ffplay.sh” here. Inside, it is like,

#!/bin/sh
sleep 20
/usr/bin/ffplay -fs -loglevel quiet rtsp://user_id:password@ip_address/designated_string >/dev/null 2>&1 &

This script sleeps 20 seconds before the execution of ffplay. I don’t know if 20 seconds is optimum. Please trim it if you like.

You can place the script file wherever you want, but your home directory is safe. Then give it execute permission.

chmod a+x run_ffplay.sh

Just run the script to see if you get a full-screen video again.

./run_ffplay.sh

Again, type “q” to quit.

Autostart

You need to create an autostart configuration file in the directory "~/.config/autostart/". By the default of bullseye installation, "~/.config" has been created then you will need,

mkdir ~/.config/autostart

Then create a file named “ffplay.desktop” in the directory with your editor. The contents will like,

[Desktop Entry]
Type=Application
Name=ffplay
Exec=/THE/PATH/TO/run_ffplay.sh

I know I’m being nosy, but /THE/PATH/TO should be the path to run_ffplay.sh. All done; just cross-finger and sudo reboot; exit.

If success, you can remove the mouse and the keyboard.

Shutdown

Unfortunately, there is no smart shutdown method provided without a keyboard and a mouse. Login to the box via ssh from another PC, then execute the command sudo poweroff. Installing an electrical switch on the GPIO and configuring it will be fun. LIRC will be a smarter alternative.

Conclusion

Since Debian removed RTSP capability from the VLC media player, many people are struggling. You can use ffplay of the FFMPEG package as an alternative.

; exit may be redundant.
Or simply poweroff may work.