Oct 28

将保存的连续图片拷贝到 Linux 上,通过 mencoder 就可以合并成视频文件:

$ sudo apt-get install mencoder
$ cd imagin //先进入图像所在目录
$ mencoder mf://*.jpg -mf w=320:h=240:fps=24:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi

关于命令参数的说明:

mencoder一行表示将当前目录下的所有.jpg图片转换成一个.avi视频
w=320:h=240 – 图像的尺寸是320×240,根据实际情况可更改
fps=24:type=jpg – 每秒24帧,文件的类型是jpg,根据实际情况可更改
-ovc – 指定视频编码
-oac – 指定音频编码

Sep 27

获得domain_id:

curl -k https://dnsapi.cn/Domain.List -d "login_email=xxx&login_password=xxx"

获得record_id:

curl -k https://dnsapi.cn/Record.List -d "login_email=xxx&login_password=xxx&domain_id=xxx"

在下面的Python脚本中替换上你的Email,密码,域名ID,记录ID等参数,就可以了。

#!/usr/bin/env python
#-*- coding:utf-8 -*-
 
import httplib, urllib
import socket
import time
 
params = dict(
    login_email="email", # replace with your email
    login_password="password", # replace with your password
    format="json",
    domain_id=100, # replace with your domain_od, can get it by API Domain.List
    record_id=100, # replace with your record_id, can get it by API Record.List
    sub_domain="www", # replace with your sub_domain
    record_line="默认",
)
current_ip = None
 
def ddns(ip):
    params.update(dict(value=ip))
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json"}
    conn = httplib.HTTPSConnection("dnsapi.cn")
    conn.request("POST", "/Record.Ddns", urllib.urlencode(params), headers)
     
    response = conn.getresponse()
    print response.status, response.reason
    data = response.read()
    print data
    conn.close()
    return response.status == 200
 
def getip():
    sock = socket.create_connection(('ns1.dnspod.net', 6666))
    ip = sock.recv(16)
    sock.close()
    return ip
 
if __name__ == '__main__':
    while True:
        try:
            ip = getip()
            print ip
            if current_ip != ip:
                if ddns(ip):
                    current_ip = ip
        except Exception, e:
            print e
            pass
        time.sleep(30)

我是将pypod.py文件放在/usr/local/bin/目录下的,注意修改自己的路径。

加入开机自动运行的方法:
编辑/etc/rc.local文件,在“exit 0”那一行前面加上一行:

su root -c "python /usr/local/bin/pypod.py >/tmp/dnspod.log 2>&1"

更好的方法就是添加cron任务,每两分钟检查一次:

sudo crontab -e
*/2 * * * * python /usr/local/bin/pypod.py >/tmp/dnspod.log 2>&1

转自:http://shumeipai.nxez.com/2013/09/17/dnspod-update-dynamic-ip-resolution.html

Jul 19

1.安装CUPS软件,”CUPS“是linux下可以用通用打印系统

 sudo apt-get install cups

2.允许pi用户配置CUPS,

 sudo usermod -a -G lpadmin pi

3.备份替换CUPS配置:
关闭服务

 sudo service cups stop

备份配置文件

 sudo cp /etc/cups/cupsd.conf /etc/cups/cupsd.conf.bak

修改配置文件

 sudo vim /etc/cups/cupsd.conf

全部配置文件如下:

 
#
# "$Id: cupsd.conf.in 9407 2010-12-09 21:24:51Z mike $"
#
# Sample configuration file for the CUPS scheduler.  See "man cupsd.conf" for a
# complete description of this file.
#

# Log general information in error_log - change "warn" to "debug"
# for troubleshooting...
LogLevel warn

# Deactivate CUPS' internal logrotating, as we provide a better one, especially
# LogLevel debug2 gets usable now
MaxLogSize 10m

# Only listen for connections from the local machine.
#Listen localhost:631
Port 631
Listen /var/run/cups/cups.sock

# Show shared printers on the local network.
Browsing On
BrowseOrder allow,deny
BrowseAllow all
BrowseRemoteProtocols cups
BrowseAddress @LOCAL
BrowseLocalProtocols CUPS dnssd

# Default authentication type, when authentication is required...
DefaultAuthType Basic

# Web interface setting...
WebInterface Yes

# Restrict access to the server...

  Order allow,deny
  Allow @Local


# Restrict access to the admin pages...

  Order allow,deny
  Allow @Local


# Restrict access to configuration files...

  AuthType Default
  Require user @SYSTEM
  Order allow,deny


# Set the default printer/job policies...

  # Job/subscription privacy...
  
    Order deny,allow
  

  
    Require user @OWNER @SYSTEM
    Order deny,allow
  

  # All administration operations require an administrator to authenticate...
  
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  

  # All printer operations require a printer operator to authenticate...
  
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  

  # Only the owner or an administrator can cancel or authenticate a job...
  
    Require user @OWNER @SYSTEM
    Order deny,allow
  

  
    Order deny,allow
  


# Set the authenticated printer/job policies...

  # Job/subscription privacy...
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default

  # Job-related operations must be done by the owner or an administrator...
  
    AuthType Default
    Order deny,allow
  

  
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  

  # All administration operations require an administrator to authenticate...
  
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  

  # All printer operations require a printer operator to authenticate...
  
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  

  # Only the owner or an administrator can cancel or authenticate a job...
  
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  

  
    Order deny,allow
  


BrowseWebIF Yes

#
# End of "$Id: cupsd.conf.in 9407 2010-12-09 21:24:51Z mike $".
#

参考的配置文件
(1)http://jxeeno.tk/local–files/blog:raspberry-pi:print-server/cupsd.conf
(2)https://github.com/bostoneboy/raspberry_pi_stuff/blob/master/cups/cupsd.conf

将Listen localhost:631行注释掉,并在其下方增加一行Port 631以监听来自网络的位置。
在Location /上方增加一行ServerAlias *以接受来自网络的请求。
在Location /与Location /admin区块内增加Allow @Local字段,以实现通过网络访问控制面板。

启动cups服务

 sudo service cups restart

4.编译开源foo2zjs驱动
foo2zjs是一款开源的打印驱动,支持部分打印机,安装该驱动需要下载其官方网站上的源码包进行编译安装。先查询一下自己的打印机是否在支持之列。

如果以前安装过foo2zjs驱动需要先卸载

 sudo apt-get remove --purge foo2zjs

安装基本的编译环境

 sudo apt-get install build-essential

wget -O foo2zjs.tar.gz http://foo2zjs.rkkda.com/foo2zjs.tar.gz
tar -xzvf foo2zjs.tar.gz
cd foo2zjs
make

编辑完成后需要下载相应的打印机的固件

 ./getweb P1505

安装编译好的驱动

 sudo make install
sudo make install-hotplug
sudo make cups

5.向CUPS添加共享打印机
PC端用浏览器打开网站”https://树莓派ip:631/”,点击”Administrator”界面添加对应的打印机,登录帐号和密码是树莓派的pi用户的密码;在local printers中找到usb连接的打印机,(寻找到你自己的打印机),修改打印机名,勾选”共享该打印机”的复选框,进入驱动选择界面。在列表中选择对应的驱动,所有foo2zjs驱动会注明footmatic/foo2zjs字样。再点击”添加打印机”按钮即完成打印机的添加。

6.安装samba服务
要使Windows系统能在局域网内发现树莓派共享的打印机,最好安装samba服务。

 sudo apt-get install samba

7.网络打印机的地址”http://树莓派ip:631/printers/HPPrinter”,PC端按照此地址添加网络打印机和驱动,或者搜索”HPPrinter on RASPBERRYPI”。

8.添加允许打印的用户

 sudo service cups stop
sudo vim /etc/cups/printers.conf
sudo vim /etc/cups/printers.conf.0
添加AllowUser Administrator用户
sudo service cups restart

9.实现iOS6兼容的AirPrint打印共享
这个是没有成功过,不知道是什么原因。
已添加的打印机会自动加入Avahi广播列表,使用苹果Bonjour协议向网络进行广播。所有苹果设备,包括手机、平板电脑和笔记本电脑均可直接发现打印机设备,并实现远程打印。然而为了使其支持iOS6系统,还需增加两个文件。

 # /usr/share/cups/mime/airprint.types image/urf      
urf string(0,UNIRAST)

# /usr/share/cups/mime/airprint.convs image/urf      
application/pdf         100     pdftoraster

参考文献:
1.http://bbs.feng.com/read-htm-tid-7523777.html
2.http://www.maojunliang.com/?p=394
3.http://blog.chinaunix.net/uid-13327770-id-2902327.html
4.https://linuxtechie.wordpress.com/2009/08/11/hp-laserjet-p1505-on-ubuntu/
5.http://foo2zjs.rkkda.com/

Nov 09

最近发现教育网拨号后是独立ip,而且80还没有被封,就萌生了在Raspberry Pi搭建博客的念头,搭建WordPress的教程很多,以前也搭建成功过,所以没有问题,但是DDNS解析的问题一直没有解决。

先是在OpenWrt下设置端口映射成功后,发现在的TP Link这样垃圾的路由器下也能设置,当然不是使用花生壳,但是不能自动更新DDNS。

先后参考了一下项目,这些别人运行起来都没有问题,但是我这里就是不能运行,出现的错误也各不相同,最主要的问题是连接超时。

1.dnspod-ddns
https://github.com/ohsc/dnspod-ddns
2.lixin-dnspod-ddns
https://github.com/topdogs/lixin-dnspod-ddns
3.Python dynamic DNSPod DNS Script
https://gist.github.com/chuangbo/833369
4.dnspod-client
https://github.com/lapause/dnspod-client
5.dnspod_inter_ddns
https://github.com/jenson-shi/dnspod_inter_ddns

现将自己的方法如下:

1.编辑ddns.sh文件

vim ddns.sh
#!/bin/sh
curl -X POST https://dnsapi.cn/Record.Ddns -d 'login_email=xxxx#qq.com&login_password=xxx&format=json&domain_id=2895571&record_id=85355459&sub_domain=blog&record_line=%E9%BB%98%E8%AE%A4'

增加执行权限

chmod +x /home/pi/ddns.sh

2.编辑autoddns.sh文件

vim autoddns.sh
#!/bin/bsh
bash /home/pi/ddns.sh >/dev/null 2>&1

增加执行权限

chmod +x /home/pi/autoddns.sh

3.修改crontab默认编辑器为vim

sudo update-alternatives --config editor

输入/usr/vim/vim.basic的编号,回车。vim.tiny与vim.basic的区别是vim.basic为完全的vim,而vim.tiny为简化版,功能上有所区别,如不支持高亮等。

4.添加crontab任务

sudo crontab -u root -e
*/3 * * * * bash /home/pi/autoddns.sh

5.重启cron服务
添加crontab任务

sudo /etc/init.d/cron restart

发现Raspberry Pi下需要以root才能执行cron任务,因此绕了很大的弯。另外cron的需要用绝对地址。

参考资料:
1.http://www.cnblogs.com/colipso/p/3536361.html
2.http://blog.csdn.net/w6611415/article/category/2302447
3.http://www.bttme.com/117.html
4.http://blog.csdn.net/ithomer/article/details/6817019
5.http://shixf.com/dnspod-inter-ddns-cn/

Oct 26
openssl genrsa -aes256 -out chun.pro-encrypted.key 2048 -sha256  

openssl rsa -in chun.pro-encrypted.key -out chun.pro-decrypted.key 

openssl req -new -key chun.pro-decrypted.key -out chun.pro.csr

参考资料:
1.http://www-01.ibm.com/support/knowledgecenter/SSBM85_9.0.0/com.ibm.tivoli.tem.doc_9.0/SUA_9.0/com.ibm.license.mgmt.doc/security/t_generate_certificate_CA.html?lang=zh
2.http://blog.csdn.net/zzxian/article/details/7739673