星期四, 十二月 01, 2016

letsencrypt + strongswan 配置的IKEv2 VPN

系统环境:
1.  安装 strongswan 5.5.1
./configure --enable-dnscert --enable-ccm --enable-chapoly --enable-ctr --enable-gcm --enable-rdrand --enable-aesni --enable-vici --enable-swanctl --disable-ikev1 --enable-newhope --enable-mgf1 --enable-sha3 --enable-eap-identity --enable-eap-mschapv2 --enable-md4
make
make install

2.  letsencypt
使用acme.sh 来获取letsencypt 的证书
#  ./acme.sh --issue --standalone -d vpn.mydomain.com  --keylength 4096
会在当前目录下生成目录 vpn.mydomain.com ,有几个重要的文件
1. ca.cer   LetsEncypt中间证书  
2. fullchain.cer   签发的域名证书
3. vpn.mydomain.com.key  跟域名证书对应的密钥文件

安装相关文件到对应目录
# cp ca.cert    /etc/ipsec.d/cacerts/acme.ca.cer
# cp fullchain.cer  /etc/ipsec.d/certs/
# cp vpn.mydomain.com.key  /etc/ipsec.d/private/

3.  配置strongswan
1. /etc/ipsec.conf
config setup
  uniqueids=never

conn myvpn
  keyexchange=ikev2
  left=%defaultroute
  leftauth=pubkey
  leftsubnet=0.0.0.0/0
  leftfirewall=yes
  leftcert=fullchain.cer
  leftid=vpn.mydomain.com
  leftsendcert=always
  right=%any
  rightauth=eap-mschapv2
  rightsourceip=10.8.0.0/24
  rightsendcert=never
  eap_identity=%any
  mobike=yes
  compress=yes
  auto=add

2.  /etc/ipsec.secrets
: RSA vpn.mydomain.com.key
user : EAP "userpasswd"

3.  /etc/sysctl.conf
net.ipv4.ip_forward = 1  
net.ipv4.conf.all.accept_redirects = 0  
net.ipv4.conf.all.send_redirects = 0  

4. 启用strongswan
应用sysctl 规则
#  sysctl -p  
启动strongswan
# ipsec start

5. 配置VPN 客户端
android 版本的strongswan
新建一个Profile
Server:  vpn.mydomain.com
VPN Type: IKEv2 EAP(Username / Password)
Username 和 Password 填 ipsec.secrets里的内容

测试下,能否正常
NOTE: 必须保证对应的服务器上打开了 500 和 4500 UDP 端口
还需要应用以下iptable 规则
iptables -A INPUT -p udp --dport 500 --j ACCEPT
iptables -A INPUT -p udp --dport 4500 --j ACCEPT
iptables -A INPUT -p esp -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE






星期三, 五月 16, 2007

Linux下使用Window的共享打印机

先在机子上安装好samba 和 cups 软件。
1)添加打印机,名字为winprinter
lpadmin -p winprinter -v smb://WORKGROUP/192.168.168.10/HPLaserJ -P HP_LaserJet_1020.ppd
2)把winprinter 设置为Default Printer
lpadmin -d winprinter

修改/etc/cups/printer.conf文件

Info winprinter
DeviceURI smb://NJG/192.168.168.10/HPLaserJ1020
State Idle
StateMessage
StateTime 1179293367
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy retry-job

3)重启cups服务
/etc/init.d/cupsys restart
4)打印测试
lp test.txt

星期二, 五月 15, 2007

使用ffmpeg做屏幕录像

ffmpeg里的x11grab模块是专门处理屏幕录像的,所以在编译的时候要特别加上--enable-x11grab
我的configure参数是: ./configuration --prefix=/usr --enable-gpl --enable-libfaad --enable-libmp3lame --enable-libogg --enable-libvorbis --enable-xvid --enable-amr-nb --enable-amr-wb --disable-ipv6 --disable-debug --enable-x11grab --extra-cflags=-I/usr/X11R6/include --extra-ldflags=-L/usr/X11R6/lib

编译完成后,用ffmpeg就可以做屏幕录像了。
ffmpeg -f x11grab -s 320x240 -i :0.0+10,10 output.mpg
320x240是视频的大小
0.0 是X11 Screen
10,10是偏移量

蓝牙pincode设置

在/usr/var/lib/bluetooth/xx:xx:xx:xx:xx:xx/pincode里记录每个设备的pincode
格式如下:
00:03:89:AB:4D:9B 0000
00:19:86:00:38:0C 0000

注意:需要把/etc/bluetooth/hcid.conf 里的 security 设置为 auto
options {
# Automatically initialize new devices
autoinit yes;

# Security Manager mode
# none - Security manager disabled
# auto - Use local PIN for incoming connections
# user - Always ask user for a PIN
#
security auto;

# Pairing mode
# none - Pairing disabled
# multi - Allow pairing with already paired devices
# once - Pair once and deny successive attempts
pairing multi;
}

星期四, 一月 25, 2007

TAB Shortcur for VIM7

j今天真高兴,我搞定vim7中的TAB快捷键设置。
在.vimrc中加入以下就可以用 ALT+num来切换TAB页了。
map 1gt
map 2gt
map 3gt
map 4gt
map 5gt
好记性不如烂笔头,记一下吧,省得以后忘记了。

星期二, 一月 09, 2007

组建Linux下的个人蓝牙局域网

用bluetooth 来组建个人的无线局域网,方便,实用而灵活。
首先需要安装bluez-libs、bluez-utils,还有内核中的bnep模块。
1: 启动蓝牙hciconfig hci0 up piscan
2: modprobe bnep
*以上步骤,在主机和和客户机上都要操作

3: 在主机上,运行pand --listen --role NAP --master
在客户机上,运行pand --connect 00:11:67:46:4E:4E --role NAPU
4: 当用pand -l 能看到
bnep0 00:11:67:46:4E:4E PANU
说明连接成功
5: 在主机上设置ifconfig bnep0 10.10.106.1
在客户机上设置ifconfig bnep0 10.10.106.2

至此,你就可以从10.10.106.2 ping 到10.10.106.1

若需要共享上网,则需要在主机上用iptable来设置一下。
客户机要添加route
route add -net default gw 10.10.106.1

以下是我的iptable的脚本。
#!/bin/bash
IPTABLES='/usr/sbin/iptables'
# Set interface values
EXTIF='ppp0'
INTIF1='bnep0'
# enable ip forwarding in the kernel
/bin/echo 1 > /proc/sys/net/ipv4/ip_forward
# flush rules and delete chains
$IPTABLES -F
$IPTABLES -X
# enable masquerading to allow LAN internet access
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE
# forward LAN traffic from $INTIF1 to Internet interface $EXTIF
$IPTABLES -A FORWARD -i $INTIF1 -o $EXTIF -m state --state NEW,ESTABLISHED -j ACCEPT
#echo -e " - Allowing access to the SSH server"
$IPTABLES -A INPUT --protocol tcp --dport 22 -j ACCEPT
#echo -e " - Allowing access to the HTTP server"
$IPTABLES -A INPUT --protocol tcp --dport 80 -j ACCEPT

星期日, 一月 07, 2007

iBook G4 与 Nokia5500 蓝牙数据传输

由于本人近日买了个带蓝牙的Nokia5500,正好可以跟我的iBook G4上的蓝牙进行通讯了,Happying
所以本人近日一直在研究bluetooth,并将一些心得与大家分享。
linux的主要是通过bluez蓝牙协议栈来支持bluetooth device,大部分的蓝牙设备都得到了很好的支持。
iBook G4里用的是CSR BlueCore 4的蓝牙芯片,可以支持Bluetooth V2.0。
需要先下载、编译bluez.org上的bluez-libs和bluez-utils两个软件包

1: modprobe bluetooth rfcomm 加载 bluetooth 和rfcomm内核模块。
hid2hci *这个可能就是在iBook G4上的linux要运行一下,不然 hciconfig -a 看不到hci 设备。
2: hciconfig hci0 up piscan ,开启蓝牙设备
* hcitool hci0 scan可以扫描到Nokia5500手机,可以看到手机的地址
3: 编译openobex, obexftp,这些软件可以在openobex网站上下到。
4: 在root 用户下,运行sdpd
sdpd * Service Disvovery Protocol Daemon
5: sdptool add --channel=10 OPUSH
* Nokia 系列用的是通道10,其他手机可能是别的通道号。
*你可以用sdptool browse 00:18:12:3A:3D:DD看到手机提供的Service和相应的Channel

6: 运行obexftpd -b , 启动基于obex的ftp服务器程序,以接受文件。

然后在Nokia5500的手机上可以通过蓝牙给iBook G4发送东西了。
[多媒体==>图像===>选项===>发送===>通过蓝牙]

从iBook G4发文件到Nokia5500的手机上,只需要用obexftp 就可以了
obexftp -b 00:18:12:3A:3D:DD -B 9 -U none -p demo.jpg
你就可以在信息的收件箱里看到。

星期三, 十一月 22, 2006

XMMS中文显示(使用文泉驿字体)

由于XMMS是Gtk1.2的程序,对中文的支持不是很理想。
下面我通过修改gtkrc来实现对XMMS的中文支持。
1: 下载文泉驿字体,最好是pcf格式的。
2: 修改Xorg.conf/XF86Config-4,添加字体路径
Section "Files"
...
FontPath "WenQuanYi Font Path"
...
EndSection
重新启动XServer, 可以用xlsfonts | grep "wen" 可以看到
...
-wenquanyi-wenquanyi bitmap song-bold-r-normal--13-130-75-75-p-80-iso10646-1
3: 在用户目录下,创建.gtkrc(gtk-1.2默认的配置文件),添加以下内容:
style "gtk-default" {
fontset ="-wenquanyi-wenquanyi bitmap song-medium-r-normal-*-*-130-*-*-p-*-iso10646-1"
}
class "GtkWidget" style "gtk-default"

[技术共享]TV Card(saa7134)+遥控支持 for linux

现在的linux的2.6内核里,对saa713x和bttv系列的电视卡提供了很不错的支持。
经本人好几天,辛苦捣鼓,终于把我的电视精灵2(芯片:saa7130HL)弄到linux上了。
特将本人心得与大家分享。
我的环境是2.6.16,最新的kernel。
一般的PCI电视卡,在2.6.x系列的kernel上,均可以自己认出。不过你需要就是在insmod的时候,指定card=xxx,tuner=xxx
这很重要的,默认的值都不大对的,需要自己手工调的。
这几个值,可以参照linux内核的Documents/video4linux/CARDLIST.xxxx文档。
假如我们要在开机的时候,自己让系统insmod你的模块,只需在创建/etc/modprobe.d/saa7134文件,把你的设置写进去就可以了。我的saa7134内容:
options saa7134 card=21 tuner=38 i2c_scan=1
*NOTE* 在2.6.18以后的内核最好加上i2c_scan=1
install saa7134 /sbin/modprobe --ignore-install saa7134; /sbin/modprobe saa7134-alsa
options saa7134-alsa
这样你的linux重启后,就可以用tvtime来看电视了。这很简单哦,呵呵。
由于遥控器都是厂家自己定制的,所以处理起来比较累。像我的天敏出品的就没有支持的,只好自己动手了。
How to add remote control support to a card (GPIO remotes)

The operation is as follows (at least it is how i did it):

1. you make detinitions of your board to have remote control (in saa7134-cards.c).
2. in saa7134-input.c, you add a case for it into the switch statement, with mask_keycode=0. Use any ir_codes array for the start. Well, you should also determine whenever polling is needed, too.
**NOTE** 你没有gpio数据输出的时候,则加上polling
3. Load saa7134 module with ir_debug=1 parameter.
4. press the keys on your remote control and watch syslog (dmesg). You will see something like

build_key gpio=0x12345 mask=0x0 data=0

in dmesg output after each key press/release.

Pay attention to gpio=0x... stuff. You will see some bits which does not change, and some which do. The ones which changes should be in your mask_keycode and mask_keydown (mask_keycode should contain not more than 8 bits set to 1, others should be set to 0). Mask_keyup and mask_keydown - those are easy to determine if you see some bit is always on when you press a key and off when you release it, or the reverse.

Ie, you will have to determine which bits in gpio value represents the key# pressed/released, and which indicate whenever it is the press or release.

After this, recompile saa7134 module with correct mask_* stuff in your saa7134_input_init1() routine. Now, the dmesg output should look like

build_key gpio=0x12345 mask=0x data=5

Ensure the data= value is different for each key, if not, you'll have to modify mask_keycode again.

Next, build the key table, by writing a file with one line for every of your key, with two fields -- key name and the data=value assotiated with it.

Try to find existing table matching your one. If there's one, use it. If none is found, build your own.

That's basically it.
以上内容来自V4L的Wiki,很有帮助的。
主要是调整mask_keycode和mask_keyup这几个值,比较累。没有厂家的资料,我们自己猜,呵呵。
修改好,make modules; make modules_install即可。
吴汝旭 于2006.05.03凌晨