gallery.zhenglei.net is online

The personal photo gallery is online at the end of 2022.

The open source piwigo suite is used to build the gallery, same as the blog site, the whole software stack, except the linux kernel layer, is built from souce, i.e, LFS (linux from scratch)

Thanks to the LFS technology, the who software image can be run on almost any linux X64 enviroment. keep the file level compability, and cloned to the other machine with rsync, backup and restore with easy.

Creating udev rule for USB DAC

Target:

Create a new udev rule which will:

Stop the Jack Daemon if DAC power off

Start the Jack Daemon if DAC power on

Identify USB DAC Card:

Power on USB DAC

Check the name of USB DAC

ls -l /proc/asound/
lrwxrwxrwx 1 root root 5 11月 22 17:55 AUDIO -> card2
dr-xr-xr-x 3 root root 0 11月 16 18:43 card0
dr-xr-xr-x 4 root root 0 11月 16 18:43 card1
dr-xr-xr-x 4 root root 0 11月 22 17:55 card2
-r–r–r– 1 root root 0 11月 16 16:36 cards
-r–r–r– 1 root root 0 11月 16 18:43 devices
lrwxrwxrwx 1 root root 5 11月 16 18:43 Generic -> card0
-r–r–r– 1 root root 0 11月 16 18:43 hwdep
-r–r–r– 1 root root 0 11月 16 18:43 modules
dr-xr-xr-x 2 root root 0 11月 16 18:43 oss
-r–r–r– 1 root root 0 11月 16 18:43 pcm

card2 is the name of DAC Card

ls  /sys/class/sound
card0  card2      controlC1  hwC0D0  pcmC0D3p  pcmC1D0p  pcmC2D0p
card1  controlC0  controlC2  hwC1D0  pcmC1D0c  pcmC2D0c  timer


Get the Attr List of card2

udevadm info /sys/class/sound/card2
P: /devices/pci0000:00/0000:00:12.0/usb2/2-4/2-4:1.0/sound/card2
L: 0
E: DEVPATH=/devices/pci0000:00/0000:00:12.0/usb2/2-4/2-4:1.0/sound/card2
E: SUBSYSTEM=sound
E: USEC_INITIALIZED=523137960408
E: ID_PATH=pci-0000:00:12.0-usb-0:4:1.0
E: ID_PATH_TAG=pci-0000_00_12_0-usb-0_4_1_0
E: ID_FOR_SEAT=sound-pci-0000_00_12_0-usb-0_4_1_0
E: SOUND_INITIALIZED=1
E: ID_VENDOR_FROM_DATABASE=Actions Semiconductor Co., Ltd
E: ID_VENDOR=ACTIONS
E: ID_VENDOR_ENC=ACTIONS
E: ID_VENDOR_ID=10d6
E: ID_MODEL=USB_AUDIO
E: ID_MODEL_ENC=USB\x20AUDIO
E: ID_MODEL_ID=dd01
E: ID_REVISION=0100
E: ID_SERIAL=ACTIONS_USB_AUDIO_4512482ADF0FEEEE
E: ID_SERIAL_SHORT=4512482ADF0FEEEE
E: ID_TYPE=audio
E: ID_BUS=usb
E: ID_USB_INTERFACES=:010100:010200:030000:
E: ID_USB_INTERFACE_NUM=00
E: ID_USB_DRIVER=snd-usb-audio
E: ID_ID=usb-ACTIONS_USB_AUDIO_4512482ADF0FEEEE-00
E: SYSTEMD_WANTS=sound.target
E: TAGS=:systemd:seat:
udevadm info --path=/sys/class/sound/card2 --attribute-walk

looking at device '/devices/pci0000:00/0000:00:12.0/usb2/2-4/2-4:1.0/sound/card2':
    KERNEL=="card2"
    SUBSYSTEM=="sound"
    DRIVER==""
    ATTR{number}=="2"
    ATTR{id}=="AUDIO"

  looking at parent device '/devices/pci0000:00/0000:00:12.0/usb2/2-4/2-4:1.0':
    KERNELS=="2-4:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="snd-usb-audio"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{authorized}=="1"
    ATTRS{bNumEndpoints}=="00"
    ATTRS{bInterfaceClass}=="01"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bInterfaceSubClass}=="01"
    ATTRS{bAlternateSetting}==" 0"

  looking at parent device '/devices/pci0000:00/0000:00:12.0/usb2/2-4':
    KERNELS=="2-4"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{devpath}=="4"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bmAttributes}=="c0"
    ATTRS{quirks}=="0x0"
    ATTRS{tx_lanes}=="1"
    ATTRS{product}=="USB AUDIO"
    ATTRS{busnum}=="2"
    ATTRS{bcdDevice}=="0100"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{manufacturer}=="ACTIONS"
    ATTRS{bNumInterfaces}==" 4"
    ATTRS{bDeviceClass}=="00"
    ATTRS{configuration}==""
    ATTRS{maxchild}=="0"
    ATTRS{devnum}=="20"
    ATTRS{serial}=="4512482ADF0FEEEE"
    ATTRS{bMaxPower}=="300mA"
    ATTRS{idVendor}=="10d6"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{urbnum}=="25748"
    ATTRS{idProduct}=="dd01"
    ATTRS{version}==" 1.00"
    ATTRS{removable}=="unknown"
    ATTRS{authorized}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="12"
    ATTRS{rx_lanes}=="1"
    ATTRS{lATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:12.0/usb2':
    KERNELS=="usb2"
    SUBSYSTEMS=="usb"DRIVERS=="usb"
    ATTRS{configuration}==""
    ATTRS{idProduct}=="0001"
    ATTRS{version}==" 1.10"
    ATTRS{tx_lanes}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{removable}=="unknown"
    ATTRS{authorized_default}=="1"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{busnum}=="2"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{quirks}=="0x0"
    ATTRS{speed}=="12"
    ATTRS{bcdDevice}=="0419"
    ATTRS{maxchild}=="5"
    ATTRS{idVendor}=="1d6b"
    ATTRS{devpath}=="0"
    ATTRS{manufacturer}=="Linux 4.19.0-9-amd64 ohci_hcd"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{rx_lanes}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{urbnum}=="511"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{product}=="OHCI PCI host controller"
    ATTRS{serial}=="0000:00:12.0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{devnum}=="1"
    ATTRS{authorized}=="1"

    
# Get kernel prop
udevadm monitor --kernel --property --subsystem-match=usb
monitor will print the received events for:
KERNEL - the kernel uevent

KERNEL[1083.319560] add      /devices/pci0000:00/0000:00:12.0/usb2/2-4 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:12.0/usb2/2-4
SUBSYSTEM=usb
DEVNAME=/dev/bus/usb/002/002
DEVTYPE=usb_device
PRODUCT=10d6/dd01/100
TYPE=0/0/0
BUSNUM=002
DEVNUM=002
SEQNUM=2112
MAJOR=189
MINOR=129

Write your udev rule based on selected attrs

cat /opt/local/libexec/udev/rules.d/99-AD-86d.rules

ACTION=="add",SUBSYSTEM=="sound",ATTR{id}=="AUDIO",RUN+="/opt/local/bin/add_ad_86d.sh"
ACTION=="remove",SUBSYSTEM=="usb",ATTRS{idVendor}=="10d6",ATTRS{idProduct}=="dd01",RUN+="/opt/local/bin/remove_ad_86d.sh"

Linux Application From Scratch

The new wordpress platform is based on Linux Application From Scratch.

The mysql server, php, nginx (openresty), and all dependency, including gcc and C library, any code in User Space, are build from source code, and installed into /opt/local as root directory.

The benefit of LAFS (LFS for wordpress application):

Could be running on any linux platform, as long as same mode (x86-64),  and support the selected basic instruction set (Sandy Bridge). The software is binary compatible,to run it on a new linux machine,  just the copy the image to the /opt/local.

Thanks to the linux kernel API backword compability,  the kernel version have no side impacts for most of application.

 

With the help of LAFS implementation, we can build blog platform, modification blog contents locally, and push to the remote public vps with easy:

      Just the file level sync (rsync):

 

Dev Machine   ==>   Local Production Env   ==>  Remote Public Production Env

  ( Intel E3 )                  ( Vmware ESXi )                         (VPS)      

 

 

 

 

 

setup reverse tunnel with stunnel

Unlike ssh,  stunnel dosen’t support the reverse tunnel by it’s self.

With the help of tgcd ( TCP/IP Gender Changer Daemon ), we are able to setup a reverse tunnel by chain the tgcd and stunnel:

For example:

We try to access the corp server from home,  but due to the NAT firewall of the corp, only out going 80/443 port are opened:

client  ==> tgcd LL node (home server)  ==> tgcd CC node (corp agent) ==> corp server:

Home Server:

Launching tgcd daemon in LL mode:

   tgcd -L -q 2222 -p 22222

Listen on port 2222 for client access

Listen on port 22222 for tgcd CC access

 

Launching stunnel in server mode:

       /usr/local/bin/stunnel /etc/stunnel/stunnel_server.conf

Listen on port 443 for incoming ssl connection

Forward link with sni=tgcd to port 2222

cat /etc/stunnel/stunnel_server.conf

[tls]
accept = 0.0.0.0:443
connect = 127.0.0.1:1080

[tgcd]
sni = tls:tgcd
connect = 127.0.0.1:2222

 

Corp Agent Server:

Launching tgcd daemon in CC mode:

tgcd -C -s 127.0.0.1:222 -c 127.0.0.227:2222

Connect to tgcd LL node at:   127.0.0.227:2222

Connect to sshd server at:     127.0.0.1:222

Launching stunnel in client mode:

/usr/local/bin/stunnel /etc/stunnel/stunnel_client.conf

Listen on port 127.0.0.227:2222 from tgcd CC, and

Access Home server via port 443 behind NAT and http proxy

cat /etc/stunnel/stunnel_client.conf

 

[ssh-tgcd-home]
accept = 127.0.0.227:2222
protocolHost = home.serverip:443

connect = http_proxy_ip:http_proxy_port
protocol = connect
sni = tgcd

 

******************************************

With such configuration, we can login into the corp server by means of:

ssh -p 22222   home.server.ip

Config Godaddy Smtp Realy

Config 3rd (Godaddy)  SMTP server as the relay of your smtp server

 

Godaddy:

MX records:

0 smtp.secureserver.net
10 mailstore1.secureserver.net

 

Host Names (CNAME)

POP pop.secureserver.net
IMAP imap.secureserver.net
SMTP smtpout.secureserver.net

 

Port:

  • Without SSL
    • Incoming Port
      IMAP – 143
      POP – 110
    • Outgoing (SMTP) port
      One of the following: 25, 80, 3535
  • With SSL
    • Incoming Port
      IMAP – 993
      POP – 995
    • Outgoing (SMTP) port
      465

 

 

Install Postfix

sudo apt-get install mailutils
sudo apt-get install postfix

Config Postfix

sudo nano /etc/postfix/main.cf

Test Postfix SMTP Server Can Send Email

echo "This is the body of the email" | 
mail -s "This is the subject line" xxx@gmail.com

Forward System Mail via the Postfix SMTP Server

cat /etc/aliases

# /etc/aliases
mailer-daemon: postmaster
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
root:  account@yourdomain

Send  Mail via external (Godaddy) smtp server

Configuring  Usernames and Passwords

sudo nano    /etc/postfix/sasl/passwd
[smtpout.secureserver.net]:80 account@yourdomain:passwd
sudo postmap /etc/postfix/sasl/passwd

Configuring Relay

sudo nano    /etc/postfix/main.cf

# specify SMTP relay host 
relayhost = [smtpout.secureserver.net]:80

At the end of the file, add the following parameters to enable authentication:

cat /etc/postfix/main.cf

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd

Test Postfix SMTP Relay

echo "email via godaddy smtp" | 
mail -s "smtp relay" "From: account@yourdomain" xxx@dest

Config email  alias From header in Postfix

 Add the line into /etc/postfix/main.cf

smtp_generic_maps = hash:/etc/postfix/generic

cat /etc/postfix/generic

other-email  account@yourdomain

sudo postmap /etc/postfix/generic