投げ銭

★当サイトへの投げ銭(PayPal)★

LINK


(無償、寄付歓迎) logo
世界中で使われるISO標準オフィスソフト(MSオフィス互換)

★LibreOfficeの導入事例★
詳細について

人気の投稿(1ヶ月間)

Ad

Ad

投げ銭

★当サイトへの投げ銭(PayPal)★

2019年11月16日土曜日

Thunderbirdで「winmail.dat」を開く方法について


■「winmail.dat」なるファイルの添付されたメールを受け取った。

Thunderbirdでメールを受信している。
稀に、相手先から「winmail.dat」という添付ファイルを受け取ることがある。

そのメールのヘッダーを確認すると、「X-Mailer: Microsoft Outlook 15.0」という文字列が含まれていた。
調べると、これは、Outlook 2013に対応するメーラーなので少し古い。


■「Winmail.dat」とは何か。

Thunderbirdのサポートサイトの情報によれば、
正しく設定されていない「Microsoft Outlook」からメールを送信すると、
「winmail.dat」というファイルが添付されるのだという。

この「winmail.dat」は、TNEF(マイクロソフト独自形式)を用いたメッセージに関する情報を保持している。
その場合、ユーザーによって添付されたファイルも一緒にこの中に納められる。
しかし、マイクロソフト以外のメールクライアントがこのようなメールを受信しても、通常は添付ファイルとして「winmail.dat」というファイルしか確認することができない。


■起こり得る問題について

受信者は相手先があたかも「winmail.dat」というファイルを意図して添付してきたと思うだろう。
そしてなんとか開こうとするが通常の方法では開けない。

そこで、相手先に、添付ファイルが開けないことについて問い合わせることになる。
冒頭で述べたとおり、正しく設定されていない「Microsoft Outlook」が自動的に、
「winmail.dat」というファイルを添付するのである。
送信者自身は、pdfだの通常のファイルを添付して確かに送信しているのであり、「winmail.dat」というファイルは送った覚えがない。

このため、お互いに原因不明のまま、
「開けないから、もう一度送ってほしい」
「送りますよ。開けましたか?」
「あれ、おかしいなあ」
のやりとりが続くことになる。


■Thunderbirdで「winmail.dat」に梱包されたオリジナルの添付ファイルを開く方法

Thunderbirdは、アドオン(追加ソフト)を組込むことによって、「winmail.dat」に対応する。

このアドオンの名前は、”LookOut”と言う。(OutLookではない。)

これは「winmail.dat」の添付されたメールを自動で認識して、
送信者が意図して添付したpdfなりのオリジナルのファイルを直接見せてくれるものである。


○アドオン”LookOut”の導入方法

1、ハンバーガーメニュー「≡」から、「アドオン」を選択する。



2、左欄から拡張機能を選び、双眼鏡アイコンのテキストボックスに、”lookout”と入力し、検索する。

次のイメージのように、アドオン”LookOut”が見つかるので、インストールする。



3、アドオンのインストール後、Thunderbirdを再起動する。

「今すぐ再起動する」をクリックした。



Thunderbirdが再起動した後、当該の「winmail.dat」を含んでいたメールを再び開くと、
今度は、送信者が意図して添付した元々のファイルの一覧を、添付ファイル欄に確認することができるようになった。



<参考>

・What is the winmail.dat attachment?
< https://support.mozilla.org/en-US/kb/what-winmaildat-attachment > 2019年11月16日

・Add-ons / LookOut (fix version) 2.0.0
< https://addons.thunderbird.net/en-US/thunderbird/addon/lookout-fix-version/ > 2019年11月16日

・Opening winmail.dat (TNEF) files in Thunderbird (on Ubuntu)
< https://blog.andrewbeacock.com/2007/07/opening-winmaildat-tnef-files-in.html > 2019年11月16日

・How email message formats affect Internet email messages in Outlook
< https://support.microsoft.com/en-us/help/290809/how-e-mail-message-formats-affect-internet-e-mail-messages-in-outlook > 2019年11月16日

・Outlook versions, build numbers and other trivia
< https://www.msoutlook.info/question/200 > 2019年11月16日

2019年11月15日金曜日

【Raspbian Buster September 2019】ショートカットをメニューに作成しアプリケーションローンチバーに追加する方法について


例えば、次のような組み合わせコマンドのためのショートカットを作成したい。

sudo /usr/bin/gnome-disks

ところで、上記の複合コマンドをパスワードなしで実行する方法については、
次のページを参照してください。
https://akira-arets.blogspot.com/2019/11/raspbian-buster2019sep-polkit.html



■メニューにショートカットを作成した。

○ショートカットで呼び出す。

いちいちターミナルを開かなくても良いように、
メニューにショートカットを登録することにした。

メニューの編集は次のコマンドで行った。
alacarte

NEW ITEMボタンから、アイテムを登録した。


上記のように、Commandのテキストボックスに、次のコマンドを設定した。
ショートカットの名称は適当に決めるとよい。
/usr/bin/sudo /usr/bin/gnome-disks
OKボタンで登録は完了するが、実際のメニューにアイテムを確認するには、
VNC Serverを利用している場合、VNC Serverの再起動が必要になった。

これで、いちいちパスワードを入力しなくても、
ディスクのフォーマットなどができるようになって便利になった。

しかし、この段階では、まだアイコンが表示されず、デフォルトのアイコンになっている。


○メニューショートカットにアイコンを表示させ、カテゴリを設定した。

まず、なぜ、アイコンが表示されないのか調べた。

メニューに表示されるようになったDisksと、Disks(privileged)の両方について、
メニュー上で右クリックして、「Add to desktop」を選び、ショートカットを作成した。

そして、それぞれの中身を次のように確認した。
URLという項目に注目する。
これがどこかリソースを参照することで情報を得ているのだろうと考えられる。
その結果、アイコンなどが表示されるのだと考えられる。
したがって、この参照先リソースを修正すればよいことになる。


(A) これはオリジナル(Disks)のデスクトップに作成したショートカットである。
mynewuser@raspberrypi:~/Desktop $ cat org.gnome.DiskUtility.desktop
[Desktop Entry]
Type=Link
Name=Disks
Icon=gnome-disks
URL=/usr/share/applications/org.gnome.DiskUtility.desktop

(B) 次に、Disks(privilege)のデスクトップに作成したショートカットである。
mynewuser@raspberrypi:~/Desktop $ cat alacarte-made.desktop
[Desktop Entry]
Type=Link
Name=Disks (privileged)
Icon=gnome-panel-launcher
URL=/home/mynewuser/.local/share/applications/alacarte-made.desktop

各々について、URLの参照先をcatコマンドで表示させた。

(a) まず、オリジナル(Disks)のリソースについて
mynewuser@raspberrypi:~/Desktop $ cat /usr/share/applications/org.gnome.DiskUtility.desktop
(略)
Icon=gnome-disks
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Utility;X-GNOME-Utilities;
DBusActivatable=true
上記、オリジナル(Disks)の、Icon項目と、Categories項目に注目した。


(b) 次に、Disks(privilege)のリソースについて
mynewuser@raspberrypi:~/Desktop $ cat /home/mynewuser/.local/share/applications/alacarte-made.desktop
[Desktop Entry]
Comment=
Terminal=false
Name=Disks (privileged)
Exec=/usr/bin/sudo /usr/bin/gnome-disks
Type=Application
Icon=gnome-panel-launcher
NoDisplay=false
先と違ってIcon項目が異なり、Categories項目が存在していないことがわかった。
そこで、Disks(privilege)について、下記のように修正した。
[Desktop Entry]
Comment=
Terminal=false
Name=Disks (privileged)
Exec=/usr/bin/sudo /usr/bin/gnome-disks
Type=Application
Categories=GNOME;GTK;Utility;X-GNOME-Utilities;
Icon=gnome-disks

NoDisplay=false
そして再起動を行った。

すると、次のように、Disks(privileged)にDisksと同じアイコンが表示されるようになった。



○タスクバーランチャーにも追加した。

その上で、ようやくこれをタスクバーのアプリケーションランチャーに登録した。

1、まず、タスクバーで右クリックしてメニューを表示させ、「ADD / Remove Panel Items」を選択した。
すると、「Panel Preferences」というウインドウが開いた。右の「ADD」ボタンをクリックした。
すると、「Add Plugin to panel」ウインドウが開いた。「Application Launch Bar」を選択してから、下欄にある「ADD」をクリックした。



2、すると、次の写真のように、上右端に「+」アイコンが表示された。
これをクリックすると、「Application lauch Bar」というウインドウが開いた。


左側の欄には、「Disks(privileged)」というアイコン付の項目が表示された。
これを選択したうえ「ADD」ボタンを押すことで、+印と同じ同じ位置にディスクのアイコンが表示された。


3、前の「Panel Preferences」というウインドウの「UP」「DOWN」ボタンで、表示位置を変えることもできた。

追加した項目は、欄の下方(=タスクバー左端位置に対応)に存在している。
名前は、「Application Launch Bar」である。これを選択してから、「UP」ボタンで上方へ移動していく。
それにつれて、実際に、タスクバーの右側へと移動していく。



以上

2019年11月14日木曜日

【Raspbian Buster September 2019】リソースモニター「gnome-system-monitor」の導入

Raspbian Buster with desktop and recommended software(September 2019)には、
標準でCPUや動作プロセスを表示するアプリがインストールされていた。

しかし、以前から使用していたリソースモニターが見易いので別途導入することにした。
リソースモニターである「gnome-system-monitor」をインストールした。



○rootユーザーに切り替えてからインストール操作を行った。

# su
# apt-get install gnome-system-monitor
The following additional packages will be installed:
  libatkmm-1.6-1v5 libcairomm-1.0-1v5 libglibmm-2.4-1v5 libgtkmm-3.0-1v5
  libgtop-2.0-11 libgtop2-common libpangomm-1.4-1v5 libsigc++-2.0-0v5
The following NEW packages will be installed:
  gnome-system-monitor libatkmm-1.6-1v5 libcairomm-1.0-1v5 libglibmm-2.4-1v5
  libgtkmm-3.0-1v5 libgtop-2.0-11 libgtop2-common libpangomm-1.4-1v5
  libsigc++-2.0-0v5
0 upgraded, 9 newly installed, 0 to remove and 2 not upgraded.
Need to get 2,616 kB of archives.
After this operation, 11.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

○インストール完了後、デスクトップのターミナルからコマンドを実行し起動した。

user@raspberrypi:~ $ gnome-system-monitor


gnome-system-monitorは見易いが、CPU使用率が5%程度上昇した。
このときは、同時に別に5%程度の使用率を占有するプログラムも動作させていた。



<参考>
・3.2. GNOME および KDE システムモニタ
< https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/6/html/performance_tuning_guide/s-analyzeperf-gnome > 2019年11月14日

・How to Install and Use GNOME System Monitor and Task Manager in Ubuntu
< https://vitux.com/how-to-install-and-use-task-manager-system-monitor-in-ubuntu/ > 2019年11月14日

2019年11月11日月曜日

【Raspbian Buster September 2019】古いタイプのSAMBAサーバーの共有フォルダをマウントする方法


■念の為、次のパッケージを導入しておいた。
(これらは不要かもしれないので、後に示すmount -t cifs コマンドでマウント可能か先に試してみること。)

# apt-get install samba-common smbclient samba-common-bin smbclient  cifs-utils



■Sambaサーバーに接続して、共有フォルダをマウントした。

Raspbian Buster September 2019 から、mount -t cifs を用いて、
CentOS 6のSAMBAサーバー(Ver. 3.6.23 43.el6_9)に接続するためには、
明示的に、vers=1.0と、sec=ntlmssp のオプションを付加しなければならなかった。

さもなければ、次のエラーが発生してサーバーへの接続に失敗した。
mount error(22): Invalid argument
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
あるいは、次のエラーが発生して失敗した。
mount error(2): No such file or directory
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

いずれの場合も、次のように、オプションを指定すると問題なく接続でき、マウントに成功した。
root@raspberrypi:/home/pi# mount -t cifs //my-file-server.example.com/SHARENAME /mnt -o user=USERNAME,pass=PASSWORD,vers=1.0,sec=ntlmssp


Raspbian Buster September 2019 では、カーネルにおいて、SMBはversion 3がデフォルトになったらしい。
そのため、SMB3や、SMB2.1をサポートしていない古いタイプのSAMBAサーバーに接続するには、
上記のようにオプションを指定する必要がある。

エラー発生後に、dmesgコマンドで調べると、次のログが記載され同様の説明が行われていた。
[174413.609298] No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3 (or SMB2.1) specify vers=1.0 on mount.
[174413.653627] CIFS VFS: cifs_mount failed w/return code = -22


<参考>

・Pi 3B+ Samba client mount issues... mount error(22)
< https://www.raspberrypi.org/forums/viewtopic.php?t=209698 > 2019年11月11日

・Access network Samba share from Pi client
< https://raspberrypi.stackexchange.com/questions/40974/access-network-samba-share-from-pi-client > 2019年11月11日

2019年11月8日金曜日

【Raspbian Buster September 2019】(polkit、sudoers)デスクトップ環境でアプリが特権を行使できる方法について

通常ユーザーがroot権限でプログラムを動作させるための方法について

例えば、gnome-disksというGUIアプリケーションを用いれば、
フラッシュメモリーやハードディスク等のディスクに対して、
フォーマット、パーティションの作成など低レベルの操作ができる。

gnome-disksは次のようにパッケージを導入すれば利用ができた。
root@raspberrypi:/home/pi# apt-get install gnome-disk-utility

実際、デフォルトのpiユーザーだと、ログインパスワードの入力で、これらの操作を行うことができた
次の写真のように、piユーザー、rootユーザーのいずれかを選択し、
ログインパスワードを入力することで、特権の必要な操作ができた



(注意)
ただし、RealVNC Serverをsysytemdから利用している場合、
バグがあるようで、この認証機構であるpolkitが機能しなかった。
エラーが発生し、「Not authorized to perform operation (udisks-error-quark, 4)」となった。
tiger vnc serverではこのバグが報告されていた。
この問題を回避するには、最後で述べるように、sudoersを用いて特権動作させるとよかった。
ただし、systemdではなく、手動でvncserverコマンドで起動した場合、
polkitは正常に動作した。

ところが、作成した通常ユーザー(mynewuser)がgnome-disksを起動した場合、
上記写真に示す認証ウインドウのドロップダウンリストには、mynewuserの名称が存在しなかった。
piユーザー、rootユーザーのみであった。

では、いかにしてpiユーザーと同様に、認証ウインドウのドロップダウンリストに新規ユーザーの名称を載せられるのだろうか。



■無駄だったこと

以下のことは無駄だったので、真似をしないように。

そこで、mynewuserが属しているグループについて調べた。
mynewuser@raspberrypi:~ $ id mynewuser
uid=1001(mynewuser) gid=1001(mynewuser) groups=1001(mynewuser)
比較のために、デフォルトのpiユーザーについても調べた。
mynewuser@raspberrypi:~ $ id pi
uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),105(input),109(netdev),999(spi),998(i2c),997(gpio)
ちなみに、rootだとシンプルである。
mynewuser@raspberrypi:~ $ id root
uid=0(root) gid=0(root) groups=0(root)
一方、フラッシュメモリーのデバイスファイルを調べると、diskグループに読み書きが与えられていた。
mynewuser@raspberrypi:~ $ ls /dev/sda -al
brw-rw---- 1 root disk 8, 0 Nov  4 03:54 /dev/sda
そこで、次のようにしてmynewuserをdiskグループに属させたが、
効果がなかった。上記と同じエラーとなった。
root@raspberrypi:/home/pi# usermod -aG disk mynewuser

そこで、グループから解除した。
root@raspberrypi:/home/pi# gpasswd -d mynewuser disk
Removing user mynewuser from group disk
これで元通りである。



■認証用ウインドウのリストに、新規ユーザーが表示されるように設定

次のように専用のファイルを編集して、システムをリブートすることで可能だった。
新規ユーザーもこのように登録さえすれば、polkitを利用することができた。
認証用ウインドウのユーザー一覧にユーザー名が表示されるようになった。

root@raspberrypi:/home/pi# nano /etc/polkit-1/localauthority.conf.d/60-desktop-policy.conf
[Configuration]
AdminIdentities=unix-user:mynewuser;unix-user:pi;unix-user:0
root@raspberrypi:/home/pi# reboot



■polkit以外の方法として、sudoersを用いる

この方法だと、sysytemdからVNC Serverを起動している場合でも、
問題なく、指定済みのアプリケーションを特権で動作させることができた。


○まず、一番最後の行に、次のように特権で動作させたいコマンドについて記述した。
root@raspberrypi:/home/pi# visudo
(略)
mynewuser   ALL=(root) NOPASSWD: /usr/bin/gnome-disks
mynewuser   ALL=(root) NOPASSWD: /sbin/poweroff
mynewuser   ALL=(root) NOPASSWD: /sbin/reboot
そして、システムを再起動した。
root@raspberrypi:/home/pi# reboot


○動作テストを行った。
再起動後、GUIのターミナルで、次のようにコマンド起動すると、
パスワードの入力なしで特権でアプリケーションを動作できた。

$ sudo /usr/bin/gnome-disks


○ショートカット並びに、ランチャーに追加する。

次のページを参照してください。
https://akira-arets.blogspot.com/2019/11/raspbian-alacarte-launcher.html



<参考>

・Enforcing security of your Raspberry PI user accounts
< https://blog.hardcoding.fr/enforcing-security-raspberry-pi-user-accounts/ > 2019年11月7日

・How to create a new user on Raspbian powered Raspberry Pi
< https://blog.gyt.is/2016/03/01/how-to-create-a-new-user-on-raspbian-powered-raspberry-pi/ > 2019年11月7日

・How to Rename the Default Raspberry Pi User
< http://unixetc.co.uk/2016/01/07/how-to-rename-the-default-raspberry-pi-user/ > 2019年11月7日

・after adding a new user the LXTerminal starts without running bash
< https://www.raspberrypi.org/forums/viewtopic.php?t=203669 > 2019年11月7日

・visudoでsudo権限の設定をする際のメモ(sudoersの'ers'って何の略なんですかね?)
< https://qiita.com/kmikmy/items/6a6a086f6415d9b55b96 > 2019年11月8日


2019年11月4日月曜日

【Raspbian Buster September 2019】VNC Server virtualモードで、新規に作成したユーザーのリモートデスクトップ環境を個々に構築する


下記ページでは、デフォルトのpiユーザーのデスクトップをVNC Server Virtual モードで作成し、ヘッドレスで運用ができるようにした。
https://akira-arets.blogspot.com/2019/10/raspberry-pi-4-vncserver-virtual.html

今回は、その追試として、
作成した任意のユーザーでも同様にVNC Server Virtual モードによるデスクトップの構成を行った。
したがって、ほぼ内容は同じである。

結論としては、piユーザーと、以下で作成する新規ユーザーのデスクトップ環境を、
並列して動作させることができた。
また、それぞれのユーザーのデスクトップ環境は、systemctlコマンドを用いて、
独立して制御(start restart stop)できるようにした。



■新しいユーザーを作成した。

まず、rootユーザーに切り替えた。
(sudo passwd root コマンドで予めパスワードを設定している必要がある。)

pi@raspberrypi:~ $ su
Password:
次に、新規ユーザーを作成した。
root@raspberrypi:/home/pi# adduser mynewuser
Adding user `mynewuser' ...
Adding new group `mynewuser' (1001) ...
Adding new user `mynewuser' (1001) with group `mynewuser' ...
Creating home directory `/home/mynewuser' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for mynewuser
Enter the new value, or press ENTER for the default
        Full Name []: ←特に設定する必要がなかったので、空欄のままエンターを押下した。(以下同様)
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y


■VNCでこのユーザー専用のデスクトップにアクセスできるようにする。

○VNC Serverのパッケージについて

Raspbian では、既にVNCサーバーのパッケージはインストール済みだった。
もしもなければ、apt-get install realvnc-vnc-server で導入できる。


○VNCセッションでのマウスカーソルの形状を矢印型になるように設定

(この設定がなければ、×印のカーソルになった。)
nano /etc/vnc/xstartup
(略)
xsetroot -solid grey -cursor_name left_ptr(略)

CTRL+s で上書き保存、CTRL+x で終了する。


○作成したあたらしいユーザーでSSHログインのしなおし

一旦、現在のSSH接続を切断して、
新しく、SSHで新規作成ユーザーでRaspberry pi にログインしなおした。

$ ssh mynewuser@192.168.1.2

(注意)
上記のように、作成した新規ユーザーで新しくSSH接続をしなおすことは重要である。
なぜならもし、su mynewuser などとしてしまえば、以下のプロセスで次のようなエラーとなり、vnc serverの起動に失敗したからだ。

The virtual session failed to start. Session log:
XvncSession start time: 2019-11-03T17:40:33.510Z
pulseaudio not installed
Error: mkDir(/run/user/1000/session-xxxxxxxxxxxxxxxx): Permission denied (13)
[System-13]

○このユーザーのためのVNCパスワードを設定した。(-virtualを指定した。)
mynewuser@raspberrypi:~ $ vncpasswd -virtual
Setting "Password" VNC parameter for Virtual Mode server
Password:
Verify:

○vnc serverを一度だけ起動する。

上記のようにして新しく作成したユーザーでSSHでログイン後、
次のようにコマンドを実行した。
:3 は、ディスプレイ番号である。他のVNCユーザーと重ならないようにすること。

mynewuser@raspberrypi:~ $ /usr/bin/vncserver -Encryption PreferOff -Authentication VncAuth -geometry 1600x900 :3
VNC(R) Server 6.5.0 (r41824) ARMv6 (Aug 16 2019 00:24:44)
Copyright (C) 2002-2019 RealVNC Ltd.
RealVNC and VNC are trademarks of RealVNC Ltd and are protected by trademark
registrations and/or pending trademark applications in the European Union,
United States of America and other jurisdictions.
Protected by UK patent 2481870; US patent 8760366; EU patent 2652951.
See https://www.realvnc.com for information on VNC.
For third party acknowledgements see:
https://www.realvnc.com/docs/6/foss.html
OS: Raspbian GNU/Linux 10, Linux 4.19.75, armv7l
On some distributions (in particular Red Hat), you may get a better experience
by running vncserver-virtual in conjunction with the system Xorg server, rather
than the old version built-in to Xvnc. More desktop environments and
applications will likely be compatible. For more information on this alternative
implementation, please see: https://www.realvnc.com/doclink/kb-546
Running applications in /etc/vnc/xstartup
VNC Server catchphrase: "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
             signature: yy-yy-yy-yy-yy-yy-yy-yy
Log file is /home/mynewuser/.vnc/raspberrypi:3.log
New desktop is raspberrypi:3 (192.168.1.2:3)
(注意)
本当は、おそらく、上記結果中に、
Generating private key... done という情報が表示されるのだろうと思うが、
先に述べているように、su mynewuser などとしてvnc serverの起動をし損ねたときに、
既にそれらの処理が完了したために、ここでは表示されなかったと思う。

○VNCクライアントソフトウェアで接続テスト

ここで、VNCクライアントから接続テストをおこなった。
VNCクライアントの接続先指定において、
上記の最後に記されているアドレスとディスプレイ番号を指定し接続した。
192.168.1.2:3
これで、mynewuser専用のデスクトップにVNCで接続することができた。


○起動したVNCのプロセスをいったん終了

ディスプレイ番号を間違えないように注意すること。

mynewuser@raspberrypi:~ $ /usr/bin/vncserver -kill :3


○システム起動時にVNC Serverが起動するように設定

このユーザー専用のデスクトップがシステム起動時に自動的に準備されるように設定した。

rootユーザーに切り替えた。
pi@raspberrypi:~ $ su
Password:
このユーザー専用のVNC Serverを制御するための設定ファイルを作成した。
root@raspberrypi:/home/mynewuser# nano /usr/lib/systemd/system/vncserver-mynewuser.service
[Unit]
Description=VNC Server for user mynewuser in Virtual Mode daemon
After=network.target

[Service]
User=mynewuser   
Type=forking
#ExecStart=/usr/bin/vncserver -geometry 1600x900 :3
ExecStart=/usr/bin/vncserver -Encryption PreferOff -Authentication VncAuth -geometry 1600x900 :3
ExecStop=/usr/bin/vncserver -kill :3
Restart=on-failure
RestartSec=5
KillMode=process

[Install]
WantedBy=multi-user.target

上記設定ファイルを用いて自動起動されるようにセットした。
root@raspberrypi:/home/mynewuser# systemctl enable vncserver-mynewuser.service
Created symlink /etc/systemd/system/multi-user.target.wants/vncserver-mynewuser.service → /usr/lib/systemd/system/vncserver-mynewuser.service.

手動で、このユーザーのVNC serverを起動した。
(もし、vncserver-mynewuser.service を変更したなら、systemctl daemon-reload を行っておくこと。)
root@raspberrypi:/home/mynewuser# systemctl daemon-reload
root@raspberrypi:/home/mynewuser# systemctl start vncserver-mynewuser.service


ここで、再び、VNCクライアントから接続テストをおこなった。

VNCクライアントの接続先指定において、
上記の最後に記されているアドレスとディスプレイ番号を指定し接続した。
192.168.1.2:3
これで、mynewuser専用のデスクトップにVNCで接続することができた。

下記のように、No session for pid ・・・というエラー表示ウインドウが開いたものの、
特に気になる問題が生じることなく利用することができた。
(最後に注意点を記載した。)



このユーザーのデスクトップ環境は、次のコマンドで、再起動や停止も可能である。
root@raspberrypi:/home/mynewuser# systemctl restart vncserver-mynewuser.service
root@raspberrypi:/home/mynewuser# systemctl stop vncserver-mynewuser.service

(注意)
アプリケーションに特権を与えるpolkitが、
systemd経由でのReal VNC Server(virtualモード)ではうまく動作しなかった。
直接コンソールから、vncserverコマンドを起動する方法では問題なかった。
これを回避するために、sudoersを使った特権を与える方法について次のページに記載した。
https://akira-arets.blogspot.com/2019/11/raspbian-buster2019sep-polkit.html


○rebootコマンドが効くように設定

rebootコマンドを発行したところ、次のエラーが発生した。
mynewuser@raspberrypi:~ $ reboot
User pi is logged in on sshd.
User pi is logged in on tty1.
Please retry operation after closing inhibitors and logging out other users.
Alternatively, ignore inhibitors and users with 'systemctl reboot -i'.

調べると、piユーザーがログインしていた。
これはおそらく自動ログインによるものだと思う。
自動ログインしないように試したが、うまくいかなかった。(多分、やり方がまずかったのだろう。)
mynewuser@raspberrypi:~ $ who
pi       tty1         2019-11-15 02:24


そこで、rebootコマンドをsudoで起動(パスワードなし)できるように設定した。
poweroffコマンドも同様に設定を行った。
下記、ページに記述してある。


次のようにコマンドを発行することで直ちに再起動できた。
$ sudo reboot

次のようにコマンドを発行することで直ちにシャットダウンできた。
$ sudo poweroff



<参考>

・【Raspbian Buster September 2019】VNC Serverを利用してユーザーごとのリモートデスクトップ環境を構築する
< https://akira-arets.blogspot.com/2019/10/raspberry-pi-4-vncserver-virtual.html > 2019年11月4日

2019年11月2日土曜日

【Linux CentOS 6】telnetでPOP3サーバーに接続しメールのタイトルを確認後に一括消去する手順


■fetchmailからSMTP転送された不正なヘッダーを持つメールがPostfixに拒否された

fetchmailを利用してPOP3サーバーからメールを取得して、それをPostfixへ転送する流れとなるはずだった。
しかし下記のログの通り、
fetchmailから転送された際にPostfixにおいて「Illegal address syntax」という警告が発せられ、失敗した。
fetchmaiは、「not flushed」と伝えたきりである。

fetchmaiのエラー「SMTP error: 501 5.1.7 Bad sender address syntax」からわかるように、
メールのヘッダーの送信者アドレスが不正な形式であることがわかった。
実際、調べてみると、xxxxxx@example.comのような形式になっていなかった。
こういうメールが、下記のログの通り、102件にもなっていて、
メールサーバーから削除されずに残存していた。

これでは困るので、処理できなかったメールをPOP3サーバーから一括消去したい。

postfix/smtpd[6510]: warning: Illegal address syntax from localhost[127.0.0.1] in MAIL command: <ここに不正な形式のアドレス>
fetchmail[6583]: reading message example@example.com:1 of 102 (17659 octets) (log message incomplete)
fetchmail[6583]: SMTP error: 501 5.1.7 Bad sender address syntax
fetchmail[6583]:  not flushed
postfix/smtpd[6510]: warning: Illegal address syntax from localhost[127.0.0.1] in MAIL command: <ここに不正な形式のアドレス>
fetchmail[6583]: reading message example@example.com:2 of 102 (8588 octets) (log message incomplete)
fetchmail[6583]: SMTP error: 501 5.1.7 Bad sender address syntax
fetchmail[6583]:  not flushed
postfix/smtpd[6510]: warning: Illegal address syntax from localhost[127.0.0.1] in MAIL command: <ここに不正な形式のアドレス>
fetchmail[6583]: reading message example@example.com:3 of 102 (3479 octets) (log message incomplete)
fetchmail[6583]: SMTP error: 501 5.1.7 Bad sender address syntax
fetchmail[6583]:  not flushed
<略>


■telnetでPOP3サーバーにアクセスし、残存するメールを確認し、削除する手順

方法は、telnetコマンドを利用して、直接POP3サーバーにログインし、
メール一覧を取得して不要なメールであることを確認してから、
一括で削除してしまう。

そこで、スクリプトを作成しtelnetコマンドを通して処理コマンドをPOP3サーバーに送出するようにした。
スクリプトは3種類用意した。以下で順に挙げていく。

1、サーバー内にあるメールのリスト番号を取得するためのコマンドを送出するスクリプト
2、各メールのヘッダーを取得するためのコマンドを送出するスクリプト
3、各メールを全て消去するためのコマンドを送出するスクリプト

ポイントは、これらのスクリプトはパイプでtelnetコマンドと組み合わせて使うことである。

$ script | telnet xxx.example.com 110 という基本の形式で用いるわけだ。

後で述べるように結果をさらにパイプで受けて処理するようなこともする。

telnetは、yum install telnet でインストールできた。



■スクリプトの実装と実際


○先ず、サーバー内にあるメールのリスト番号を取得しメールの件数を確認した。

スクリプト1を実装した。
サーバー内にあるメールのリスト番号を取得するためのコマンドをtelnetコマンドに送出するのに用いるスクリプトである。

$ ./LIST_POP3 | telnet xxx.example.com 110 という様に用いて、パイプでコマンドをtelnetに送る。

最初に、POP3サーバーにアクセスするまでに2秒の待機時間を設定している。
次に、USERコマンド名と、PASSコマンド名と共にログイン情報を送り、
各々処理のために待機時間も2秒設定している。(これは必須である。)
その上で、LISTコマンドを送出している。
全てのメールのリストを受け取るまで待機するように、5秒設定している。
そして、QUITで切断している。

必要に応じて、各待ち時間は調整した方が良い。


$ vi LIST_POP3
#!/bin/bash
username="myusername";
password="HereIsPassword";
sleep 2
echo USER $username
sleep 2
echo PASS $password
sleep 2
# Send LIST Command to Get list of mails
echo LIST

# Wait until all list is retrieved
sleep 5
echo QUIT

スクリプトに実行パーミッションを与えた。

$ chmod +x LIST_POP3


実際に用いると、次のようになった。

$ ./LIST_POP3 | telnet xxx.example.com 110
Trying xxx.xxx.xxx.xxx...
Connected to xxx.example.com.
Escape character is '^]'.
+OK <xxxxx.xxxxx@xxx.xxx.example.com>
+OK
+OK
+OK
1 17659
2 8588
3 3479
4 3376
5 4115
6 4579
7 9360
8 9427
9 8706
10 10263
11 9196
12 10253
13 10322
<略>
98 23229
99 23517
100 23439
101 23263
102 11367
. ←ここで設定した分だけの待ち時間
Connection closed by foreign host.

102通のメールが残存しているとわかった。



○そして、各々のメールの題名を確認した。

同様にしてまず、スクリプト2を実装した。
これはメールヘッダーを取得する。

下記、MAX_MESS=$1 の部分は、スクリプト実行時に指定した「最初の引数」を保存している。
そして、「最初の引数」には処理するべきメールの数を指定する。
ヘッダーを取得するためにループを利用しているのでループの回数として使用している。

(注意)
echo TOP $j 0 のところは、TOPコマンドを受け付けないPOP3サーバの場合には、
echo RETR $j を用いてメール全文を取得しても良い。

$ vi TOP_POP3
#!/bin/bash
username="myusername";
password="HereIsPassword";
MAX_MESS=$1
[ $# -eq 0 ] && exit 1 || :
sleep 2
echo USER $username
sleep 2
echo PASS $password
sleep 2
for (( j = 1 ; j <= $MAX_MESS; j++ ))
do
#Send command to get header of a mail
echo TOP $j 0

sleep 1
done

echo QUIT

スクリプトに実行パーミッションを与えた。

$ chmod +x TOP_POP3

このように作成したスクリプトとtelnetとを組み合わせ、メールサーバーにコマンドを送出し、
そして、さらにその結果をパイプで繋いで、grepで「Subject:」を抽出した。
これにより、メールのタイトルを表示することができた。

指定している102は、前述の通り処理するべきメール数である。

$ ./TOP_POP3 102 | telnet xxx.example.com 110 | grep Subject:
Subject: Wow, what a handsome...
Subject: What are your plans for tomorrow?
Subject: what are we going to do?
Subject: I could not resist and pass by!
Subject: You seem to know how to make a girl turn on...
Subject: God, how many fantasies you awake in my head!
Subject: can you meet me
Subject: I'm asking you
Subject: Interestingly, are you as cool in the conversation as on the photo?
Subject: let's do it tomorrow
Subject: can you meet me tomorrow?
Subject: It's incredibly confusing and drives me on simultaneously. Watch until I removed it from the access.
Subject: Oh, where have you been all my life!
Subject: That's why I love our parties! Just look here
Subject: I would like to ask you
Subject: can you meet me
Subject: Is your character as hard as your muscles?
Subject: What are we going to do today?
Subject: let's do it today
Subject: Remind myself
Subject: =?iso-2022-jp?B?GyRCIVobKEIyMDE5GyRCRy8bKEI1GyRCN24hW0BBNWEzWyROJDRPIk1tGyhC?=
Subject: Me and this bottle of red wine ;)
Subject: can we schedule an appointment for tomorrow?
Subject: could you meet me tomorrow?
Subject: Not sure, it had to be spread in the network, but it's a little late. Rate here
Subject: Wow, what a handsome...
<略>
Subject: what are your plans for the weekend?
Subject: Haven't you seen it yet? Oh hell, and why I have not found it before
Subject: I want to meet you today
Subject: =?utf-8?B?44GC44Gq44Gf44Gv6Ieq55Sx44Gg77yf?=
Connection closed by foreign host.

タイトルがエンコードされて読めない場合は、
次のようにして解読すればよかった。

$ echo "=?iso-2022-jp?B?GyRCIVobKEIyMDE5GyRCRy8bKEI1GyRCN24hW0BBNWEzWyROJDRPIk1tGyhC?="  | nkf -mB
8♡躊桴」、0C【2019年5月】請求額のご連絡
$ echo "=?utf-8?B?44GC44Gq44Gf44Gv6Ieq55Sx44Gg77yf?=" | nkf -w8
あなたは自由だ?
$ echo "=?Shift_JIS?B?gXWJZYu/l82CzINHg2yDi4NNgVuBdoLwjYKC34LpiciKd5NJgsiO6JZAgqqM9opK?=" | nkf -B
「影響力のエネルギー」を高める科学的な手法が公開
$ echo "=?utf-8?B?Y2FuIHlvdSBtZWV0IG1l?=" | nkf -w8
can you meet me

このようにして、メールの題名からサーバ内のメールが全てジャンクメールであることを確認した。

次にこれらを一括して消去する。



○サーバー内のメールを全て消去した。

スクリプト3はメールを指定した件数だけ削除する。

最後のQUITコマンドの送出によって、実際にメールが削除される
そのためQUITコマンドがきちんとPOP3サーバーに伝達するように待ち時間を最後に設定した。

(注意)
最後の待ち時間のsleepを省くと、うまくメールが削除されなかった。

$ vi DELE_POP3
#!/bin/bash
username="myusername";
password="HereIsPassword";
MAX_MESS=$1
[ $# -eq 0 ] && exit 1 || :
sleep 2
echo USER $username
sleep 2
echo PASS $password
sleep 2
for (( j = 1 ; j <= $MAX_MESS; j++ ))
do
# !!!! Send Command to delete a mail !!!!
echo DELE $j
sleep 1
done
echo QUIT
sleep 5

スクリプトに実行パーミッションを与えた。

$ chmod +x DELE_POP3


次のようにして用いる。メールが102件削除された。

# ./DELE_POP3 102 | telnet xxx.example.com 110
Trying xxx.xxx.xxx.xxx...
Connected to xxx.example.com.
Escape character is '^]'.
+OK <xxxxx.xxxxx@xxx.xxx.example.com>
+OK
+OK
+OK
+OK
+OK
+OK
+OK
+OK
+OK
+OK
<略>
+OK
+OK
+OK
+OK
+OK
+OK
+OK
+OK
+OK
Connection closed by foreign host.

削除されたかを確認するには、最初のコマンドをもう一度実行すれば良い。

$ ./LIST_POP3 | telnet xxx.example.com 110
Trying xxx.xxx.xxx.xxx...
Connected to xxx.example.com.
Escape character is '^]'.
+OK <xxxxx.xxxxx@xxx.xxx.example.com>
+OK
+OK
+OK
.
Connection closed by foreign host.

以上



<参考>
・Remove or Delete all emails message from a POP3 server
< https://www.cyberciti.biz/tips/remove-or-delete-all-emails-message-from-a-pop3-server.html > 2019年10月30日

・nkfで文字コード変換したいときはこうする!!
< https://qiita.com/hirohiro77/items/9e57fff12a3ef0907594 > 2019年10月30日

・【Linux CentOS 7 (1511)】nkfコマンドを使って文字化けしたメールの内容を解読する方法
< http://akira-arets.blogspot.com/2016/12/linux-nkf-makes-mojibake-be-right.html > 2019年10月30日

2019年10月30日水曜日

【Raspbian Buster September 2019】VNC Serverを利用してpiユーザーのリモートデスクトップ環境を構築する




■realvnc-vnc-serverというパッケージがインストールされているか確認

○まず、正式なパッケージ名を取得

piユーザーでSSHログインした後、suでrootユーザーになった。

root@raspberrypi:/home/pi# apt-cache search realvnc*
libnet-vnc-perl - Perl module implementing a simple VNC client
realvnc-vnc-server - VNC® Server
realvnc-vnc-viewer - VNC® Viewer

○取得したパッケージ名でインストール操作
すると、既に最新版がインストール済みだとわかった。
root@raspberrypi:/home/pi# apt-get install realvnc-vnc-server
Reading package lists... Done
Building dependency tree     
Reading state information... Done
realvnc-vnc-server is already the newest version (6.5.0.41824).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Raspbian Buster September 2019 with desktop and recommended software には、最初から、realvnc-vnc-serverパッケージがインストールされているとわかった。



■piユーザーでVNCセッションにログインするための設定

ただし、vncserverには三つのモードが存在する。
  -user       Set the password for VNC Server in User Mode.
  -service    Set the password for VNC Server in Service Mode.
  -virtual    Set the password for VNC Server in Virtual Mode.
今回は、VNC ServerをVirtualモードで使いたい。


○まず、piユーザー用に、VNCパスワードを設定した。

piユーザーになった。
root@raspberrypi:/home/pi# su pi

piユーザーのためのVNCパスワードを設定した。(-virtualを指定した。)
pi@raspberrypi:~ $ vncpasswd -virtual
Setting "Password" VNC parameter for Virtual Mode server
Password:
Verify:
Successfully set "Password" VNC parameter in /home/pi/.vnc/config.d/Xvnc
Successfully set "Password" VNC parameter in
/home/pi/.vnc/config.d/vncserver-x11-virtual

○VNCセッションでのマウスカーソルの形状を矢印に設定した。

sudoか、rootユーザーで編集を行うこと。

この設定がなければ、×印のカーソルになった。

CTRL + w で、下記コマンドで設定ファイルを開き、xsetroot を検索して編集箇所を見つけること。

nano /etc/vnc/xstartup
(略)
xsetroot -solid grey -cursor_name left_ptr(略)

CTRL+s で上書き保存、CTRL+x で終了する。


○一度だけ、VNC Serverをpiユーザーで起動した。

piユーザーになった。
root@raspberrypi:/home/pi# su pi

そして、オプションを指定して、VNC Serverを起動した。
(重要)
ここで一度起動しておかないと、必要な設定が自動的にされないようである。また、後の手順に示すように、セッションを終了させることを忘れないように!
オプション最後の、:2はディスプレイ番号である。VNCセッション毎に異なる番号をつける必要がある。
pi@raspberrypi:~ $ /usr/bin/vncserver -Encryption PreferOff -Authentication VncAuth -geometry 1600x900 :2
VNC(R) Server 6.5.0 (r41824) ARMv6 (Aug 16 2019 00:24:44)
Copyright (C) 2002-2019 RealVNC Ltd.
RealVNC and VNC are trademarks of RealVNC Ltd and are protected by trademark
registrations and/or pending trademark applications in the European Union,
United States of America and other jurisdictions.
Protected by UK patent 2481870; US patent 8760366; EU patent 2652951.
See https://www.realvnc.com for information on VNC.
For third party acknowledgements see:
https://www.realvnc.com/docs/6/foss.html
OS: Raspbian GNU/Linux 10, Linux 4.19.75, armv7l
Generating private key... done
On some distributions (in particular Red Hat), you may get a better experience
by running vncserver-virtual in conjunction with the system Xorg server, rather
than the old version built-in to Xvnc. More desktop environments and
applications will likely be compatible. For more information on this alternative
implementation, please see: https://www.realvnc.com/doclink/kb-546
Running applications in /etc/vnc/xstartup
VNC Server catchphrase: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
             signature: xx-xx-xx-xx-xx-xx-xx-xx
Log file is /home/pi/.vnc/raspberrypi:2.log
New desktop is raspberrypi:2 (192.168.1.2:2)

ここで、一度、VNCクライアントソフト(私はTiger VNC Viewerを用いた)から、VNCセッションに接続した。
Raspberry piのIPアドレス:ディスプレイ番号 という書式で、VNC Serverを指定した。
192.168.1.2:2
問題なく、VNCセッションに接続することができた。

★VNCセッションを終了した。(これも忘れないこと!)
pi@raspberrypi:~ $ /usr/bin/vncserver -kill :2



○次に、piユーザーのためのVNC Serverを自動起動するための設定を行った。

(注意)
以下では、systemdを用いてvnc Serverを起動させる設定を行っている。
しかし、systemdからVNC Serverを動作させた場合、polkitが動作しなかった。
そのため、gnome-disksなど特権を必要とするアプリケーションでは権限がないというエラー
「Not authorized to perform operation (udisks-error-quark, 4)」
が表示された。
しかし、上記のように、ユーザーのSSHコンソールからvncserverコマンドを起動する方法では問題は発生しなかった。(←これは重要な回避策
tigervncではこれについてバグが報告されている。
realvncでも同様のバグがあるのではないか。 

rootユーザーになった。
pi@raspberrypi:~ $ su

次のファイルを新規作成して下記のように記述した。
root@raspberrypi:/home/pi# nano /usr/lib/systemd/system/vncserver-pi.service
[Unit]
Description=VNC Server for user pi in Virtual Mode daemon
After=network.target

[Service]
User=pi     
Type=forking
#ExecStart=/usr/bin/vncserver -geometry 1600x900 :2
ExecStart=
/usr/bin/vncserver -Encryption PreferOff -Authentication VncAuth -geometry 1600x900 :2
ExecStop=/usr/bin/vncserver -kill :2
Restart=on-failure
RestartSec=5
KillMode=process

[Install]
WantedBy=multi-user.target

CTRL+s で上書き保存、CTRL+x で終了する。

piユーザーのためのVNC Serverがシステム起動時に自動的に立ち上がるよう設定した。
root@raspberrypi:/home/pi# systemctl enable vncserver-pi.service
Created symlink /etc/systemd/system/multi-user.target.wants/vncserver-pi.service → /usr/lib/systemd/system/vncserver-pi.service.

手動で、VNC Serverを起動した。
root@raspberrypi:/home/pi# systemctl daemon-reload
root@raspberrypi:/home/pi# systemctl start vncserver-pi.service

先程と同様にしてVNCクライアントソフトから、VNCセッションに接続した。
Raspberry piのIPアドレス:ディスプレイ番号 という書式で、VNC Serverを指定した。
192.168.1.2:2
VNCセッションに接続することができた。

手動で、VNC Serverを終了した。
セッション内デスクトップで動作中のプログラムなどは終了するので注意すること!
root@raspberrypi:/home/pi# systemctl stop vncserver-pi.service


これで、システムが再起動すると、自動的に、piユーザーのためのVNC Serverが起動することになる。



○さらに別のユーザーについても同じことを行いたい場合

もし、さらに別のユーザーを追加し各々デスクトップを用意してVNCで接続できるようにしたいなら、次のページを参考にしてください。

【Raspbian Buster September 2019】VNC Server virtualモードで、新規に作成したユーザーのリモートデスクトップ環境を個々に構築する




<参考>

・VNC viewer: "No matching security types"
< https://www.raspberrypi.org/forums/viewtopic.php?t=176408 > 2019年10月25日

・RealVNC server in virtual mode - Enterprise license required?
< https://www.raspberrypi.org/forums/viewtopic.php?t=249124 > 2019年10月25日

・Bug 1633805 - tigervnc-server, when started via systemd produces problems with polokit when DE is Xfce
< https://bugzilla.redhat.com/show_bug.cgi?id=1633805 > 2019年10月25日

・PolicyKit failed over headless VNC
< https://forums.fedoraforum.org/showthread.php?316905-PolicyKit-failed-over-headless-VNC&p=1809280#post1809280 > 2019年10月25日

・Jessie and XRDP
< https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=122386&p=861126 > 2019年10月26日

・Understanding VNC Server Modes
< https://help.realvnc.com/hc/en-us/articles/360002253238-Understanding-VNC-Server-Modes > 2019年10月25日

・VNC Connect and Raspberry Pi
< https://help.realvnc.com/hc/en-us/articles/360002249917-VNC-Connect-and-Raspberry-Pi#creating-and-remoting-a-virtual-desktop-0-5 > 2019年10月25日


2019年10月27日日曜日

【Raspbian Buster September 2019】OSインストールから初期セットアップ(rootユーザー、SSHログイン、システム更新、ヘッドレス運用、microSD丸ごとバックアップ、リストアなど)


以下では、Raspberry pi 4 Model B(4GBタイプ)に、Raspbian をインストールし、
rootユーザーへの切り替え、SSH接続、システムの更新を行うまでの手順を記載したものである。
また、最後に、RaspbianをインストールしたmicroSDXCカードの、
バックアップ方法とリストア方法についても記載した。

インストールには、microSDXCカードへの書き込みで別マシンが必要になる。
ここでは、Linux(CentOS 7)マシンを使用している。


<使用したもの>

○OSインストール段階で使ったもの
Linuxマシン、
SDXCカードリーダー、
空の高速なmicroSDXC(ここでは、ランダムアクセス性能にも優れた64GB、U3タイプを用いた)、

(注意)
microSDXCは、64GBのものを用いた。
容量が大きいことは、ユーザーデータの保存容量が増すだけでなく、
SDカードのコントローラーによって分散書き込みできる領域が増すということだと考えられるので、
SDカードの寿命も長くすることができると考えられる。

○OS初期セットアップ段階で使ったもの
キーボード、
マウス、
HDMI接続モニター、

アップデートのためにインターネットに接続できるネットワーク環境も用いている。



■Raspberry piの公式OSであるRaspbianの導入

ファイルのダウンロードやSDカードへの書き込みなどの準備作業では、
Linuxマシン(CentOS 7 64bit)を用いた。このLinuxマシンではGUIが使える。
この項目では、この準備用マシンでの操作について記載している。

○ダウンロード

以下のページから、Raspbian というOSをダウンロードした。
https://www.raspberrypi.org/downloads/raspbian/

Raspbianには、現在のところ二種類が用意されていた。
いずれも、バージョンは、September 2019 というものである。

一つは、Raspbian Buster with desktop and recommended software で、
デスクトップの環境に追加のお勧めソフトウェアがパッケージされたものである。

もう一つは、Raspbian Buster with desktop で、そういう追加のソフトウェアがないものである。
(必要に応じて、自分で追加ソフトを選択して導入することもできる。)

ここでは、追加ソフトウェア付のデスクトップ環境を選択した。
ダウンロードしたファイルは3GB程で、zipで圧縮されていた。

(注意)
ブラウザを用いてダウンロードした場合、転送速度が非常に遅い場合に、
セッションがタイムアウトになってしまうことがあった。
その場合、wgetコマンドを用いてダウンロードすれば良かった。


○microSDXCカードへのインストール

インストールと言っても、インストーラーがあるわけではない。
ダウンロードしたファイルは、OSのイメージになっているので、
それをSDカードにそのまま書き込むシンプルな方法で良い。

まず、圧縮ファイルを展開した。
# unzip 2019-09-26-raspbian-buster-full.zip

すると、2019-09-26-raspbian-buster-full.img というファイルが得られた。
このファイルをmicroSDXCカードにRAWデータとして書き込めば良い。
次にその方法を示す。

(注意)
ファイルとして書き込むのではない。
imgファイルにはRaspberry piシステムディスクのイメージがそのまま書き込まれている。
RAWデータとして専用のコマンドでmicroSDXCカードに書き込むことによって、
そのディスク構造(パーティションやファイルシステム)ごとmicroSDXCに転写されることになる。
(注意)
Linuxシステムでは、SDXCカードはデバイスファイルと対応づけられる。
即ち、対応づけられたデバイスファイルにデータを放り込むことによって、
そのSDXCカードにデータが転写される。
まず、SDXCカードリーダーに差し込んだSDXCカードが、
Linuxシステム上でどのデバイスファイル名で認識されたかを確認する。
そこで、microSDXCカードを操作するために、gnome-disksを起動した。(GUI必要)
# gnome-disks
このアプリケーションは、gnome-disk-utility というパッケージから導入できる。


そして、ターゲットの空のmicroSDXCカードを、準備用マシンのカードリーダーに差し込んだ。
起動中のgnome-disksにより、microSDXCがどのデバイスファイルに割り当てられたかわかった。
あるいは、下記ページを参考にして、デバイス名を調べることができる。
http://akira-arets.blogspot.com/2010/03/centos54sd.html

ここでは、microSDXCカードが /dev/sdX というデバイスファイルを割り当てられたものとする。


次のフォーマットを参考にして、microSDXCにデータを書き込んだ。(=インストール)
# dd if='2019-09-26-raspbian-buster-full.img' of=/dev/sdX bs=4M
1624+0 レコード入力
1624+0 レコード出力
6811549696 バイト (6.8 GB) コピーされました、 223.274 秒、 30.5 MB/秒
(注意)
この段階では、書き込まれたデータは6.8GBであるが、
Raspberry pi システムを立ち上げてセットアップが完了した段階では、
64GBのSDカードいっぱいにまでファイルシステムが拡張されていた。
以前のより古いRaspbianではこのような自動拡張はなかったと思う。

(注意)
デバイスファイル(/dev/sdX の所)の指定は間違えないようにすること。
さもなければ、意図せずに別のディスクの内容を破壊してしまうことになる。
bsで指定されている4Mというのは一度に書き込み操作するデータの大きさである。
これが小さいとシーケンシャルライトにならずに、書き込み速度が落ちてしまうことがある。
ここで使用したSDXCカードは、U3という書き込みが高速のものである。
Raspberry piでは、SDXCカードがハードディスク代わりとなるので、高速アクセスのタイプを選んだ。
本当はきちんとランダムアクセスの早いSDXCカードを探して選んだ方が良い。

書き込みが完了したら、microSDXCカードに対して予めgnome-disksで「ディスクの取り出し」を行う。
その上で、microSDXCカードをカードリーダーから取り外した。



■Raspberry pi の起動

○先ず初めに

インストール済みのmicroSDXCカードをRaspberry piのカードスロットに差し込んだ。
キーボード、マウス、そしてHDMI端子よりモニターに接続した。
さらに、ローカルネットワーク接続用のLANケーブルを差し込んだ。

その上で、電源供給のためにType-Cを差し込んだ。
これにより、Raspberry piが起動した。

(注意)
デフォルトでは、SSHログインもできないし、
セットアップは、GUIで行うためにマウスも必要だった。
モニターの無いところで起動してしまうと、終了させることもできなくなり、
仕方無く電源断をすればSDのファイルシステムを壊してしまうことになるだろう。

初回起動は、ラズベリーのアイコンが表示されてから、モニターにデスクトップ画面が表示されるまでに時間がかかった。(5分くらい?)
モニターが真っ暗な状態になっていてもじっくり待つ必要があった。

デスクトップが表示されると、セットアップを促すウインドウが開かれた。
地域や言語を選択し、piユーザー(デフォルトユーザー)のパスワードの設定を行った。
WiFi接続の設定もここで行うことができる。

設定が完了すると、再起動が行われた。


○rootユーザーを使用するための設定

rootユーザーは、パスワードを設定するだけで使用できるようになった。
仮想端末を起動した。

rootユーザーのパスワードを設定した。
pi@raspberrypi:~ $ sudo passwd root


○SSHログインできるようにするための設定

続いて、rootユーザーに切り替えた。
(さきほど設定したパスワードを入力した。)
pi@raspberrypi:~ $ su
Password: 
root@raspberrypi:/home/pi#
これでrootユーザーに切り替わった。

SSHという空のファイルをbootディレクトリに作成した。
root@raspberrypi:/home/pi# touch /boot/ssh

これで、再起動を行うと、SSH接続が可能となった。

次回は、SSH接続を行うので、ここでRaspberry piに割り当てられているIPアドレスを確認した。
root@raspberrypi:/home/pi# ip a | grep inet
inet 192.168.1.2/24 brd 192.168.1.255 scope global noprefixroute eth0
192.168.1.2 がそのアドレスである。環境によって当然異なる。

再起動を行った。
root@raspberrypi:/home/pi# reboot



■Raspberry pi システムの更新


○Raspberry pi へのSSHログイン

上記手順で、Raspberry piにリモート接続(SSH接続)ができるようになった。
別マシンから、Raspberry piにSSH接続を行った。
(デフォルトではrootユーザーは直接ログイン不可だった。)

$ ssh pi@192.168.1.2



○システムのアップグレードを行った。

piユーザーでSSHログイン後、rootユーザーに切り替えた
(さきほど設定済みのrootパスワードを入力した。)
pi@raspberrypi:~ $ su
Password: 
これで、rootユーザーに切り替わった。
root@raspberrypi:/home/pi#

不意にSSHセッションが切れることに備えて、仮想端末tmuxを導入した。
root@raspberrypi:/home/pi# apt-get install tmux

仮想端末tmuxを起動した。
root@raspberrypi:/home/pi# tmux

念の為、インストール直後のunameの情報を挙げておく。
root@raspberrypi:/home/pi# uname -a
Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l GNU/Linux
システムの更新を行った。
(updateでパッケージの更新の有無を調べ、upgradeで更新する。)
root@raspberrypi:/home/pi# apt-get update
root@raspberrypi:/home/pi# apt-get upgrade

更新には結構な時間が必要だった。
ネット環境、microSDXCカードの性能にも依るだろうと思う。

完了後、再起動を行った。
root@raspberrypi:/home/pi# reboot


アップデート後のunameの情報
とくに変化は無かった。
root@raspberrypi:/home/pi# uname -a
Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l GNU/Linux


■ディスプレイ不要のヘッドレス運用について

ところで、この段階で、マウスを使うGUIデスクトップ画面をリモートアクセスで利用するための設定ができる準備ができた。

ネットワーク越しに、別のパソコンからリモートアクセスでデスクトップ画面を利用することをヘッドレス運用と言う。
Raspberry pi 専用にディスプレイを接続する必要がないということである。

ヘッドレス運用のための設定が必要な場合は、以下を参照してください。

二つにページを分けていますが、注意点もあるため、順に目を通すことをお勧めします。

・デフォルトpiユーザーでヘッドレス運用をするための設定について
【Raspbian Buster September 2019】VNC Serverを利用してpiユーザーのリモートデスクトップ環境を構築する

・新規にユーザーを作成してヘッドレス運用をするための設定について
【Raspbian Buster September 2019】VNC Server virtualモードで、新規に作成したユーザーのリモートデスクトップ環境を個々に構築する

上記の設定を行う前に、システムのアップグレードを先ず行うことを推奨します。



■システムのバックアップとリストア

初期セットアップが完了した後、いつでも同じ環境に戻せるようにするために、
microSDXCにインストールされているシステム全体のバックアップを作成した。

ここでも、バックアップファイルの保存先はLinux(CentOS 7)とした。


○Raspberry piからmicroSDXCカードの取り出し

まず、Raspberry pi を終了させた。
root@raspberrypi:/home/pi# poweroff

Raspberry piのシャットダウンを確認後、
本体microSDカードスロットから、microSDXCカードを取り出した。


○取り出したmicroSDXCカードのバックアップ

microSDXCカードをバックアップ保存先とするLinuxマシンのカードリーダーに取り付けた。
既に述べた方法を参考にして、デバイスファイル名を確認した。

ここでは、microSDXCカードが /dev/sdX というデバイスファイルを割り当てられたものとする。

# dd if=/dev/sdX | gzip -c > Raspbian_Raspi4_testmachine_20191025.img.gz

ddコマンドにより、microSDXCの内容が全て読み取られて、
gzipコマンドによって圧縮されてから指定したgzファイルに保存される。
圧縮をかけたので、microSDXCは64GB程度あるが、3GB程度に圧縮されて保存できた。


○バックアップファイルからmicroSDXCへリストア

リストアするには次のようにする。
# gzip -dc < Raspbian_Raspi4_testmachine_20191025.img.gz | dd of=/dev/sdX

バックアップのときに発行したコマンドと逆のデータの流れになっている。

(注意)
一つ気になることがある。それは、リストア先のmicroSDXCの容量である。
リストア先のmicroSDXCカードがバックアップ元と全く同じ容量であるか、
あるいはそれよりも大きい場合は問題ないだろう。
しかし、逆に、少しでも容量が小さい場合にはデータを全て書き込みできずに、
エラーになると考えられる。
同じ64GBと表記されたmicroSDXCでもメーカーや型番やロットによって、
容量が同じでない場合があるので注意が必要である。
悩ましさを切り捨てるために、リストアが必要になった際には、
128GBサイズのmicroSDXCカードを使ってみることも手である。


○上記の方法でリストアを試した結果

バックアップしたRaspberry pi 4 のSDカードの容量は、次の通りである。

(parted) unit b                                                         
(parted) p                                                             
Model: SD SA64G (sd/mmc)
Disk /dev/mmcblk0: 61983424512B

そして、リストア先として用いた新しい空のSDカードの容量は、次の通りである。

(parted) unit b                                                         
(parted) p
Model: SD SR64G (sd/mmc)
Disk /dev/mmcblk0: 63864569856B

このように比べると、リストア先のSDカードの容量は同じ64GBタイプでも少し大きいものだとわかる。
これはメーカーや、型番、ロットによって異なるので実際に試してみなければわからない。
したがって既に述べたように、リストア先としてはワンサイズ上のタイプのSDカードを選ぶ手が確実となる。


リストアコマンドの結果は次の通りである。
bs=4M は一度に書き込むデータの量である。
これを省略するとシーケンシャルライトにならずにSDへの書き込みが非常に遅くなる場合がある。

[root@localhost Raspberry]# gzip -dc < Raspbian_Raspi4_testmachine_20191025.img.gz | dd of=/dev/sdX bs=4M
121061376+0 レコード入力
121061376+0 レコード出力
61983424512 バイト (62 GB) コピーされました
リストア先SDカードのサイズは、63864569856バイトあるので、問題なく書き込むことができたわけである。


そして、このリストアしたSDカードを、新規に購入したRaspberry pi 4で用いて、
そのまま起動したところ以前と同じ設定のシステムを得られた。
例えば、前のシステムで設定したVNC SERVERも自動的に起動された。

同じ設定のRaspberry piを増やすことができるのでバックアップ、リストアはとても便利である。
また、SDカードが故障して起動しなくったり、システムがおかしくなった場合でも、リストアは有効である。

以上



<参考>
・ddの進捗を確認
< https://qiita.com/tukiyo3/items/5e3fd748287ffa4b6612 > 2019年10月27日

・gzip - ファイルを圧縮・展開 - Linuxコマンド
< https://webkaru.net/linux/gzip-command/ > 2019年10月27日


新品価格
¥7,800から
(2020/1/19 06:25時点)

2019年9月1日日曜日

【RasPBX 04-04-2018】システムから管理者宛てにエラー通知メールが届く

RasPBX(04-04-2018)をRaspberry pi 2に導入した。
WEBインターフェイスに管理者ログインを済ませ、
またメールも送信できるようにした。

数日使用した後に、システムから大量のエラー通知メールを受信するようになった。
それまでは不具合は発生しなかった。



○不具合のきっかけ

数日使用していると次のような内容の通知メールがRasPBXシステムから管理者宛に届いた。
この管理者メールアドレスは、最初にRasPBXのWEBインターフェイスにアクセスした際に設定したものである。
SECURITY NOTICE:
:
framework has been automatically upgraded to fix security issues:
SEC-2018-001
セキュリティーの問題があったため勝手に更新が為されたらしい。
このRasPBXはLAN内に設置しインターネットから隔離しているので、
勝手にアップグレードはしてほしくなかった。
更新によって、不具合が発生することを心配するからである。

そして、心配していた通り、次のように問題が発生した。
(WEBインターフェイスで、administrator項目から自動更新しないようにも設定できるようである。)


○発生した問題

次のような内容の通知メールが管理者宛に大量に届くようになった。

一種類目(最初に1回だけだった)
PHP Fatal error: Class 'Symfony\Component\Lock\Store\SemaphoreStore' not found in /var/www/html/admin/libraries/BMO/Cron.class.php
on line 301

二種類目(最も多い通知メールで、数分おきに来た。)
UnexpectedValueException: The stream or file "/var/log/asterisk/freepbx.log" could not be opened: failed to open stream: Permission denied in file /var/www/html/admin/libraries/Composer/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php
on line 107

三種類目(二つ目のメールが20通に対して1通くらいの割合で来た。)
PHP Fatal error: Class 'cronmanager' not found in /var/lib/asterisk/bin/freepbx-cron-scheduler.php on line
10
Whoops\Exception\ErrorException: Class 'cronmanager' not found in file /var/lib/asterisk/bin/freepbx-cron-scheduler.php
on line 10

○対処

とりあえず、大量にやってくる二つ目の通知メール記載のエラー情報に記載内容から、
ログファイル(/var/log/asterisk/freepbx.log)の所有者を調べた。

root@raspbx:~# ls /var/log/asterisk/ -all
total 936
drwxrwxr-x 5 asterisk asterisk   4096 Apr  6  2018 .
drwxr-xr-x 8 root     root       4096 Aug 21 06:25 ..
drwxrwxr-x 2 asterisk asterisk   4096 Sep 12  2017 cdr-csv
drwxrwxr-x 2 asterisk asterisk   4096 Sep 12  2017 cdr-custom
drwxrwxr-x 2 asterisk asterisk   4096 Sep 12  2017 cel-custom
-rw-r--r-- 1 root     root       1522 Aug 21 11:24 freepbx.log
-rw-r--r-- 1 asterisk asterisk 929369 Aug 21 11:28 full
-rw-r--r-- 1 asterisk asterisk    114 Aug 21 11:24 queue_log

rootが所有者になっているため、アクセスができないのだろうと考えた。
そこで、他のファイルの所有者に倣って、所有者を変更した。

root@raspbx:~# chown asterisk:asterisk /var/log/asterisk/freepbx.log


修正後、所有者の確認をした。

root@raspbx:~# ls /var/log/asterisk/ -all
total 936
drwxrwxr-x 5 asterisk asterisk   4096 Apr  6  2018 .
drwxr-xr-x 8 root     root       4096 Aug 21 06:25 ..
drwxrwxr-x 2 asterisk asterisk   4096 Sep 12  2017 cdr-csv
drwxrwxr-x 2 asterisk asterisk   4096 Sep 12  2017 cdr-custom
drwxrwxr-x 2 asterisk asterisk   4096 Sep 12  2017 cel-custom
-rw-r--r-- 1 asterisk asterisk   1522 Aug 21 11:24 freepbx.log
-rw-r--r-- 1 asterisk asterisk 929765 Aug 21 11:28 full
-rw-r--r-- 1 asterisk asterisk    114 Aug 21 11:24 queue_log
これによって、大量にやって来ていた二種類目の通知メールはぴたっと来なくなった。

しかし、三種類目の通知メールはまだやって来た。


そこで、システムのアップグレードを行った。

root@raspbx:~# raspbx-upgrade

すると、三種類目のメールも一切発信されることがなくなった。


2019年8月17日土曜日

【RasPBX 04-04-2018】簡易なメールソフトssmtpを導入してメールを送信できるようにした【ssmtp】


raspbx-04-04-2018 でメールを送信できるように設定した。

デフォルトの状態では、exim4というメールサーバーソフトが入っていた。
しかし、ここではこれを削除して、簡易なメール送信ソフトウェア(ssmtp)を導入した。
ssmtpは、設定ファイルにリレー先のSMTPサーバアドレスを指定すると使える。


■exim4の削除とssmtpのインストール

もともと入っているメール関連ソフトウェアexim4を削除した。
root@raspbx:/# apt-get remove exim4

簡易軽量のssmtpをインストールした。
root@raspbx:/# apt-get install ssmtp

サーバーが見つからないなどというエラーが発生したが、
apt-get update を実行した後で再びインストールを試みると解消された。


■ssmtpの設定

オリジナル設定ファイルのバックアップをとった。
root@raspbx:/# cp /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.org

リレー用のメールサーバーを指定した。
root@raspbx:/# nano /etc/ssmtp/ssmtp.conf

以下の例では、認証不要のsmtpサーバーの25番ポートに接続する設定を行っている。
認証が必要な場合、25番以外の設定も可能である。

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.example.com
# Where will the mail seem to come from?
#rewriteDomain=
# The full hostname
hostname=raspbx
# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
#FromLineOverride=YES


■メール送信テスト

root@raspbx:/# echo testtest | sendmail -f from@example.com to@example.com

送信後にログを確認した。
root@raspbx:/# tail /var/log/mail.info 
Aug 16 16:09:48 raspbx sSMTP[1245]: Sent mail for root@raspbx (221 2.0.0 Bye) uid=0 username=root outbytes=248

また、送信先において確かにメールを受信することができた。



<参考>
・Ubuntu 環境で sSMTP を利用して Gmail を送信してみる
< https://qiita.com/chikoboo/items/77d0030c49e0d8b7fd4f > 2019年8月15日

・"404 not found" error
< https://www.raspberrypi.org/forums/viewtopic.php?t=198032 > 2019年8月16日

2019年6月20日木曜日

【Linux CentOS 6】CUPSがレーザープリンタの紙切れを検知したまま復帰しないバグと対応方法について【CUPS 1.4.2】

■CUPSで紙切れのエラーが解消されない問題が発生した。

使用しているCUPSは次の通りである。

名前                : cups
アーキテクチャ      : x86_64
エポック            : 1
バージョン          : 1.4.2
リリース            : 67.el6

CentOS 6 のgnomeデスクトップ環境において、
ネットワーク経由で接続していたCanon製のレーザープリンタ(純正ドライバを使用)について用紙切れのエラーが発生した。
しかし、プリンタには適切な用紙が補充されている。

プリンタに用紙が補充されていることを確認後も、
CUPSが感知しているらしい「用紙切れエラー」は解消されず、プリントアウトできない状体が継続した。
システム全体の再起動も行ったが、同エラーは解消されなかった。


■バグであることが判明し、手動でエラー回避を行った。

これはバグらしい。printers.confを修正する必要があった。
service cups stop でサービスを止めた後、修正した。
以下のように、エラーに関する箇所「Reason」で始まる行を削除した。
そして、service cups start でサービスを開始した。
これにより、通常通りプリンタが使用できるようになった。



○該当個所の削除を行った。

まず、CUPSを停止した。
(あるいは、先に下記につづく編集手順を行った後に、service cups restart でも良い。)

service cups stop

複数プリンタが導入されているときは、該当するプリンタを間違えないこと。
下記のように「Reason」から始まる行を削除した。
(下記にはないが、Reason toner-low-report というエラーを検知することもある。)

# vi /etc/cups/printers.conf
<Printer LBP8710e-LIPSLX>
Info LBP8710e-LIPSLX
MakeModel Canon LBP8720/8710 LIPSLX ver.2.9
DeviceURI lpd://printer.example.com
State Stopped
StateMessage /usr/lib/cups/backend/lpd failed
StateTime 1560727782
Reason media-low-report ←削除
Reason media-empty-warning ←削除
Reason paused ←削除

Type 8402132
Filter application/vnd.cups-raw 0 -
Filter application/vnd.cups-postscript 0 pstoufr2cpca
Filter application/vnd.cups-command 0 commandtops
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy stop-printer
Attribute marker-colors \#000000
Attribute marker-levels 18
Attribute marker-names Canon Cartridge 533/533 H
Attribute marker-types toner
Attribute marker-change-time 1560727752
</Printer>

そして、CUPSを始動した。

service cups start

以上で、プリンタが再び使用できるようになった。


○その後、再び内容を確認した。

# less /etc/cups/printers.conf

<Printer LBP8710e-LIPSLX>
Info LBP8710e-LIPSLX
MakeModel Canon LBP8720/8710 LIPSLX ver.2.9
DeviceURI lpd://printer.example.com
State Idle
StateTime 1560958599
Reason toner-low-report
Type 8402132
Filter application/vnd.cups-raw 0 -
Filter application/vnd.cups-postscript 0 pstoufr2cpca
Filter application/vnd.cups-command 0 commandtops
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy stop-printer
Attribute marker-colors \#000000
Attribute marker-levels 13
Attribute marker-names Canon Cartridge 533/533 H
Attribute marker-types toner
Attribute marker-change-time 1560958599
</Printer>
Reasonから始まる行がまだあるが、
これはプリンタのトナー量が低下していることにリンクしていると思われる。



■考察

おそらく、先ず実際にプリンタで紙切れを起こし、CUPSシステムが検知しただろう。
しかし用紙が充填されても、システムはバグのためにエラーの状態から自動で離脱できなかったのではないかと思う。
そのため、手動で「Reason」で始まる行を削除することによって、エラーから復帰させる必要があったと考えられる。
本来は、これはシステムによって為される一連の作業なのだと思う。
CentOS7以降であれば、このようなバグは解消されているだろうか?



<参考>
・Permanent "Printer-out-of-paper" message.
< https://bugs.launchpad.net/ubuntu/+source/cups/+bug/559331 > 2019年6月20日

2019年4月4日木曜日

【snom D375 / firmware 8.9.3.60】reboot bug について

実際に自分で不具合の場面を確認したわけではないが、
利用者が、このファームウェアバージョン搭載のSnomD375で、使用中に再起動画面が出ると言う。


この件について調べてみると、次のページを発見した。
● SAP-1736 FIX: An LLDP-MED packet with policy: VLAN: 0, DSCP: 0, VLAN Prio: 0 was processed as a new policy initiated a reboot, ultimately led to a reboot-loop, - also perceived as a crash due to the deferred reboot execution
Please note: issue was introduced in 8.9.3.60 May 2017 via SAP-611, - corrections included in SAP-611 remain intact
http://wiki.snom.com/Firmware/V8/Release_Notes

訳してみると、次のようなことだと思う。(間違っていたらすみません。)

 LLDP-MEDというパケット(ベンダーが利用するリンクレイヤープロトコルに関するものらしい)のポリシーが「LAN: 0, DSCP: 0, VLAN Prio: 0」であるものが処理されるとき、再起動を引き起す別物のポリシーとして処理されてしまうらしい。その結果、再起動ループ状態におちいったり、クラッシュしているかのように見えてしまったりするのだという。
 この問題は、ファームウェアバージョン 8.9.3.60 May 2017 に生じたもので、下記、参照番号「SAP-611」の修正を経ている。しかしこの問題が修正されたとしても、「SAP-611」の修正は効いたままであるらしい。
● SAP-611 FIX: LLDP Network-Policy was not adopted if vlan-tagged-status is unchanged
http://wiki.snom.com/Firmware/V8_9_3_60#-.3DNetwork_Protocol.3D-

利用者の訴える再起動云々という内容ととてもよく一致する。そのため、新しいファームウェアを以下のページから導入した。
https://service.snom.com/display/wiki/Firmware+Update+Centre


これでしばらく様子を見てみよう。

2019年3月31日日曜日

【Asterisk 11.17.1】長いエクステンション名でDialを呼び出すとエラーが発生した。【Linux CentOS 6】

長い名前でエラー

なぜかどうしてもエラー「No such extension/context」がでてしまう部分があり、
原因究明に時間がかかってしまったのでメモしておく。

その箇所では、Dialによって、別のコンテクストのエクステンションがダイヤルされている。
CLIでそのエラー箇所を見ていると、「No such extension/context」が現れていた。
Dial("SIP/long_long_sip_device_name-000000ba", "Local/long_long_extension_name@long_long_context_name") in new stack
NOTICE[26014][C-00000024]: chan_local.c:971 local_call: No such extension/context long_long_extension_name@long_long_context_name while calling Local channel
どれだけ調べても、確かにそれらのエクステンションとコンテクストは存在している。
どうも、エラーメッセージの言う問題とは異なる問題が潜んでいるらしい。

試行錯誤していると、エクステンション名か、コンテキスト名か、あるいは、呼出元のSIPデバイス名が長いことが理由だとわかってきた。


○結局、エクステンション名を下記のように短くすることで問題を回避することができた。即ち、26文字では同様にエラーとなった。
・エクステンション名・・・25文字
そのときの、コンテキスト名、SIPデバイス名の長さは次の通りである。
・コンテキスト名・・・47文字
・呼び出し元のSIPデバイス名・・・53文字
もちろん、コンテキスト名などを短くすることによって回避することも可能かもしれないが調べていない。
エクステンション名を短くする代わりに、コンテキスト名を短くすることでもうまく動作するかもしれないということである。
もちろん、エクステンションの必須条件が25文字なのかもしれない。

これは調べていないからわからない。

2019年3月30日土曜日

【Linux CentOS 6】異なるディレクトリに保存された同名ファイルの内容について互いの差異を把握する方法


# cd /etc/asterisk
# for i in `find /tmp/asterisk/ -name "*.conf"`  ; do echo $i ; diff $i ${i##*/} ; done | less

<目的>

/etc/asteriskと、/tmp/asterisk それぞれには同一名のファイルが複数存在している。
互いに比較して、差異を調べる。


<説明>

最初に、/etc/asterisk へカレントディレクトリを移動させておく。

/tmp/asterisk/ には、同一名の比較のためのファイル(*.conf)があり、
一つずつforで取得しながら、diffコマンドで比較作業を行う。

取得したパスは、$i で取り出せる。
echo $i でどのファイルを比較したものか一覧できるようにパスを出力しておく。

${i##*/} は、そのパスからディレクトリ部分を消去してファイル名のみを表す。
カレントディレクトリ内のファイルは、ファイル名のみでアクセスできる。

diffコマンドの結果は差異があれば出力があり、なければ何も出力しない。

結果をlessに渡すことで、どのファイルに差異があるのかわかるようにした。

2019年3月17日日曜日

【Linux CentOS 7】HylaFAXをパッケージでお手軽に導入する【HylaFAX 6.0.7】

以下は、CentOS 7 をベースにした特権dockerコンテナにHylaFAXをインストールしたものである。

しかし、通常のCentOS 7にも、同じやり方でインストールできると思われる。

使用したDockerイメージは次のページで作成したものである。

【Linux CentOS 7】(ベースコンテナの作成)SSH接続可能なDockerコンテナでの日本用ロケールの有効化と検証(man,dateの日本語表示)【Docker-ce 18.06.1.ce】

sshで接続して、以下のようにインストール作業を行った。



○依存パッケージのインストール

# yum install libtiff
Package libtiff-4.0.3-27.el7_3.x86_64 already installed and latest version

Nothing to do

# yum install ghostscript
Updated:
  ghostscript.x86_64 0:9.07-31.el7_6.9

Dependency Updated:
  ghostscript-devel.x86_64 0:9.07-31.el7_6.9

Complete!

# yum install ghostscript-fonts
Package ghostscript-fonts-5.50-32.el7.noarch already installed and latest version

Nothing to do

システムに、mgetty-sendfax パッケージが導入されている場合は削除しておく。



○hylafaxパッケージのダウンロードとインストール

ダウンロードするものは二種類ある。

https://www.hylafax.org/binary-packages/redhat-packages/ からそれぞれダウンロードした。

# wget ftp://ftp.hylafax.org/binary/linux/redhat/6.0.7/hylafax-client-6.0.7-1.el7.x86_64.rpm

# wget ftp://ftp.hylafax.org/binary/linux/redhat/6.0.7/hylafax-server-6.0.7-1.el7.x86_64.rpm


# ls -l
total 1172
-rw-r--r-- 1 root root 378024 Mar  9 18:02 hylafax-client-6.0.7-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 815636 Mar  9 17:49 hylafax-server-6.0.7-1.el7.x86_64.rpm


最初にクライアントパッケージからインストールした。

# yum install hylafax-client-6.0.7-1.el7.x86_64.rpm
Installed:
  hylafax-client.x86_64 0:6.0.7-1.el7

Complete!

次にサーバーパッケージをインストールした。
(依存パッケージがダウンロードされ導入された。)

# yum install hylafax-server-6.0.7-1.el7.x86_64.rpm
Is this ok [y/d/N]: y

Downloading packages:
sharutils-4.13.3-8.el7.x86_64.rpm
                                                                | 252 kB
00:00:00   
Running transaction check
Running transaction test
Transaction test succeeded

Running transaction
  Installing : sharutils-4.13.3-8.el7.x86_64

1/2
install-info: No such file or directory for /usr/share/info/sharutils.info
  Installing : hylafax-server-6.0.7-1.el7.x86_64

2/2
#########################################################
#            HylaFAX installation complete!             #
#                                                       #
#      You should now run /usr/sbin/faxsetup to         #
#       create or update HylaFAX configuration          #
#      before you can begin using the software.         #
#                                                       #
#########################################################

  Verifying  : sharutils-4.13.3-8.el7.x86_64

1/2
  Verifying  : hylafax-server-6.0.7-1.el7.x86_64

2/2
Installed:
  hylafax-server.x86_64 0:6.0.7-1.el7

Dependency Installed:
  sharutils.x86_64 0:4.13.3-8.el7

Complete!

以上でhylafaxがインストールされた。



○systemctlでstatusを確認

# systemctl status hylafax
● hylafax.service - LSB: Starts and stops the HylaFAX
   Loaded: loaded (/etc/rc.d/init.d/hylafax; bad; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)
起動していないことがわかるようになった。



○hylafaxの基本セットアップ

予め、不可欠のパッケージを導入した。

# yum install libtiff-tools
Installed:
  libtiff-tools.x86_64 0:4.0.3-27.el7_3

Complete!

セットアップを行った。
ほとんどデフォルトの回答のままエンターを押すだけにした。
一部、値を設定する必要がある。

# faxsetup
Setup program for HylaFAX (tm) 6.0.7.
Created for x86_64-unknown-linux-gnu on Tue Sep 18 18:56:42 UTC 2018.
Found converter: /bin/tiff2pdf
Found uuencode encoder: /bin/uuencode
Found base64 encoder: /bin/base64
Found Quoted-Printable encoder: qp-encode
Looks like /bin/base64 supports base64 encoding.
Found mimencode for compatibilty: mimencode
Checking system for proper client configuration.
Checking system for proper server configuration.

Warning: /sbin/mgetty does not exist or is not an executable program!
The file:
    /sbin/mgetty
does not exist or this file is not an executable program.  The
HylaFAX software optionally uses this program and the fact that
it does not exist on the system is not a fatal error.  If the
program resides in a different location and you do not want to
install a symbolic link for /sbin/mgetty that points to your program
then you must reconfigure and rebuild HylaFAX from source code.

Warning: /sbin/vgetty does not exist or is not an executable program!
The file:
    /sbin/vgetty
does not exist or this file is not an executable program.  The
HylaFAX software optionally uses this program and the fact that
it does not exist on the system is not a fatal error.  If the
program resides in a different location and you do not want to
install a symbolic link for /sbin/vgetty that points to your program
then you must reconfigure and rebuild HylaFAX from source code.

Warning: /bin/egetty does not exist or is not an executable program!
The file:
    /bin/egetty
does not exist or this file is not an executable program.  The
HylaFAX software optionally uses this program and the fact that
it does not exist on the system is not a fatal error.  If the
program resides in a different location and you do not want to
install a symbolic link for /bin/egetty that points to your program
then you must reconfigure and rebuild HylaFAX from source code.
Searching for a default font.

Generating Fontmap /etc/hylafax/Fontmap.HylaFAX.

Found Courier to use as default font.

Setting font configuration in /etc/hylafax/hyla.conf.

Make /var/spool/hylafax/bin/ps2fax a link to /var/spool/hylafax/bin/ps2fax.gs.

Make /var/spool/hylafax/bin/pdf2fax a link to /var/spool/hylafax/bin/pdf2fax.gs.


There does not appear to be an entry for the FaxMaster either in
the YP/NIS database or in the /etc/aliases file.  The
FaxMaster is the primary point of contact for HylaFAX problems.
The HylaFAX client-server protocol server identifies this alias as
the place to register complaints and HylaFAX directs automatic mail
messages to this user when problems are identified on a server
machine or when the routine server maintainence scripts are run
(e.g. faxcron).
Should an entry be added for the FaxMaster to /etc/aliases [yes]?
Users to receive fax-related mail [root]?
Rebuilt /etc/aliases database.
Update /var/spool/hylafax/status/any.info.
HylaFAX configuration parameters are:
[1] Init script starts faxq: yes
[2] Init script starts hfaxd yes
[3] Start paging protocol: no
Are these ok [yes]?
Modem support functions written to /var/spool/hylafax/etc/setup.modem.
Configuration parameters written to /var/spool/hylafax/etc/setup.cache.
No scheduler config file exists, creating one from scratch.

Country code [1]? 81 ←日本は81である。
Area code []? xx ←市外局番から0を外したものを入力した。
Long distance dialing prefix [1]? 0
International dialing prefix [011]? 010 ←環境に応じたものを適当に入力した。


Dial string rules file (relative to /var/spool/hylafax) ["etc/dialrules"]?
Tracing during normal server operation [1]?
Default tracing during send and receive sessions [0xffffffff]?
Continuation cover page (relative to /var/spool/hylafax) []?
Timeout when converting PostScript documents (secs) [180]?
Maximum number of concurrent jobs to a destination [1]?
Define a group of modems []?
Time of day restrictions for outbound jobs ["Any"]?
Timeout before purging a stale UUCP lock file (secs) [30]?
Max number of pages to permit in an outbound job [0xffffffff]?
Syslog facility name for ServerTracing messages [daemon]?
The non-default scheduler parameters are:
CountryCode: 81
AreaCode: xx
LongDistancePrefix: 0
InternationalPrefix: 010
Are these ok [yes]?
Creating new configuration file /var/spool/hylafax/etc/config...

Restarting HylaFAX server processes.
Should I restart the HylaFAX server processes [yes]?

/etc/rc.d/init.d/hylafax start
Reloading systemd:                                         [  OK  ]
Starting hylafax (via systemctl):                          [  OK  ]

You do not appear to have any modems configured for use.  Modems are
configured for use with HylaFAX with the faxaddmodem(8C) command.
Do you want to run faxaddmodem to configure a modem [yes]? no ←IAXmodemを利用したいのでnoとした。
Done verifying system setup.
セットアップによって、設定ファイルが構成されて、hylafaxがstartされた。



○systemctlでstatusを確認

# systemctl status hylafax
hylafax.service - LSB: Starts and stops the HylaFAX
   Loaded: loaded (/etc/rc.d/init.d/hylafax; bad; vendor preset: disabled)
   Active: active (running) since Sat 2019-03-09 19:13:54 UTC; 3min 3s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 2275 ExecStart=/etc/rc.d/init.d/hylafax start (code=exited, status=0/SUCCESS)
   CGroup: /docker/28a9c6704dba75a8fdd17713c8745eec7d07d4b73608c071a327be787a35e66d/system.slice/hylafax.service
           ├─2282 /usr/sbin/faxq
           └─2287 /usr/sbin/hfaxd -i hylafax
Mar 09 19:13:54 28a9c6704dba systemd[1]: Starting LSB: Starts and stops the HylaFAX...
Mar 09 19:13:54 28a9c6704dba hylafax[2275]: Starting HylaFAX queue manager (faxq): [  OK  ]
Mar 09 19:13:54 28a9c6704dba hylafax[2275]: Starting HylaFAX server (hfaxd): [  OK  ]
Mar 09 19:13:54 28a9c6704dba FaxQueuer[2282]: HylaFAX (tm) Version 6.0.7
Mar 09 19:13:54 28a9c6704dba systemd[1]: Started LSB: Starts and stops the HylaFAX.
Mar 09 19:13:54 28a9c6704dba FaxQueuer[2282]: Copyright (c) 1990-1996 Sam Leffler
Mar 09 19:13:54 28a9c6704dba FaxQueuer[2282]: Copyright (c) 1991-1996 Silicon Graphics, Inc.
Mar 09 19:13:54 28a9c6704dba HylaFAX[2287]: Listening to 0.0.0.0:4559
Mar 09 19:13:54 28a9c6704dba HylaFAX[2287]: HylaFAX INET Protocol Server: restarted.


★IAXmodemのセットアップ方法は、次のページに記述しています。

https://akira-arets.blogspot.com/2019/03/linux-docker-iaxmodem1.3.0-centos7.html

★IAXmodemとHylaFAXの連携方法は、次のページを参照ください。

https://akira-arets.blogspot.com/2011/09/linux-centos56-iaxmodemhylafax.html
https://akira-arets.blogspot.com/2011/09/hylafaxfaxwinprint-hylafax.html



<参考>
・HylaFAX / Binary Package Install
< https://www.hylafax.org/hylafax-handbook/binary-package-install/ > 2019年3月17日

・HylaFAX / HylaFAX packaged in binary RPM and source SRPM format
< https://www.hylafax.org/binary-packages/redhat-packages/ > 2019年3月17日

・hylafax-client(1) - Linux man page
< https://linux.die.net/man/1/hylafax-client > 2019年3月17日

・What is the difference between `yum install` and `yum localinstall`?
< https://ask.fedoraproject.org/en/question/37721/what-is-the-difference-between-yum-install-and-yum-localinstall/ > 2019年3月17日

投げ銭

★当サイトへの投げ銭(PayPal)★

Ad

Ad