目标:
1. 提供L2TP(VPN)链接服务
2. 可以针对用户进行流量统计与限制
环境:
CentOS5.5 + L2TP/IPSec + FreeRadius
边干边写, 第一天刚刚开始有点想发, 所以啥细节也没有, 只是明确下方向...
Python Pexpect End Of File (EOF) Exception
I have written a simple python script which use pexpect to add a user and set his password.
My code looks like this:
pexpect.run('sudo /usr/sbin/useradd -s /bin/false)
passwd = pexpect.spawn('sudo /usr/bin/passwd ' + name)
for repeat in (1,2):
passwd.expect('password:')
passwd.sendline(password)
time.sleep(0.2)
It works on my own machine(Ubuntu 10.10). But on some other machine(CentOS 5.5), it always get an pexpect.EOF exception. To solve this problem, you should change the second line of the code to:
passwd.expect(['password:',pexpect.EOF])
The exception told you there is and EOF, so the simplest thing is to expect it:)
My code looks like this:
pexpect.run('sudo /usr/sbin/useradd -s /bin/false)
passwd = pexpect.spawn('sudo /usr/bin/passwd ' + name)
for repeat in (1,2):
passwd.expect('password:')
passwd.sendline(password)
time.sleep(0.2)
It works on my own machine(Ubuntu 10.10). But on some other machine(CentOS 5.5), it always get an pexpect.EOF exception. To solve this problem, you should change the second line of the code to:
passwd.expect(['password:',pexpect.EOF])
The exception told you there is and EOF, so the simplest thing is to expect it:)
Win7 自动拨号-- Windows 7 ADSL auto-dial
以前的WIN7是可以自动拨号的, 至于怎么设置我自己也忘了. 重装系统后,不再自动拨号,每次都手动,颇为麻烦,于是设之.
Windows下, 拨号是个rasphone.exe来完成的. 于是简单了, 只要将这个程序加入到自动运行就可以了.
首先拨号的方法是
C:\Windows\System32\rasphone -d "ADSL"
然后就是将其加入到regedit中
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
新建个字符串, 名称随便如: ADSLRun 然后值为
C:\Windows\System32\rasphone -d "ADSL"
注意: "ADSL"是你拨号链接的名称.
Windows下, 拨号是个rasphone.exe来完成的. 于是简单了, 只要将这个程序加入到自动运行就可以了.
首先拨号的方法是
C:\Windows\System32\rasphone -d "ADSL"
然后就是将其加入到regedit中
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
新建个字符串, 名称随便如: ADSLRun 然后值为
C:\Windows\System32\rasphone -d "ADSL"
注意: "ADSL"是你拨号链接的名称.
Django 处理中文, 使用VIM编辑 (LINUX)
前面折腾的Django工程基本功能已经完成,今天想把以前英文的内容全部修改成中文,遇到一个问题,在一个templates页面里写中文时,Django无法识别,报错:UnicodeDecodeError。
只有一个文件有问题,其他没问题。
经google, 发现原来这个文件保存的编码类型非utf-8,而Django默认的编码类型是utf-8, 于是出错。解决方法:
1.在shell 下 file login.html 得到 login.html: UTF-8 Unicode text, with CRLF line terminators
2.如果不是UTF-8 使用 iconv 进行转换
[Look~]# iconv -f ISO- 8859-1 -t utf-8 login.html > new_login.html
[Look~]# cp new_login.html login.html
然后打开网页显示,OK,可以看到熟悉的中文了。不过还是有问题,vim 打开文件,看到所有中文的地方,全是乱码。这个是VIM显示的问题,可以在vimrc中进行如下设置
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
然后,一切就都像传说中那么爽了,HOHO。
只有一个文件有问题,其他没问题。
经google, 发现原来这个文件保存的编码类型非utf-8,而Django默认的编码类型是utf-8, 于是出错。解决方法:
1.在shell 下 file login.html 得到 login.html: UTF-8 Unicode text, with CRLF line terminators
2.如果不是UTF-8 使用 iconv 进行转换
[Look~]# iconv -f ISO-
[Look~]# cp new_login.html login.html
然后打开网页显示,OK,可以看到熟悉的中文了。不过还是有问题,vim 打开文件,看到所有中文的地方,全是乱码。这个是VIM显示的问题,可以在vimrc中进行如下设置
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
然后,一切就都像传说中那么爽了,HOHO。
Subscribe to:
Posts (Atom)