svn做好,最基础的使用方法。将来用户要修改密码或忘记密码总要来问还是挺麻烦。不想处理这种简单问题。所以在python+tornado的框架上写了个页面,直接python跑起来。省了自己不少的事。
#!/bin/python
#-*- coding:utf-8 -*-
# Filename: websvn.py
# Revision:
# Date: 2014-03-27
# Author: simonzhang
# web: www.simonzhang.net
# Email: simon-zzm@163.com
### END INIT INFO
import tornado.ioloop
import tornado.web
import smtplib
from email.mime.text import MIMEText
from string import strip
# base set
webport = '88'
passfile = '/program/svn/conf/passwd'
# svn start comm
svn_start_comm = '/program/svn/bin/svnserve -d -r /program/svn/ --listen-port 59999'
# use send user info
mail_host = 'smtp.simonzhang.net'
mail_user = 'test@simonzhang.net'
mail_pwd = '123456'
def mail_send(content, mailto):
msg = MIMEText(content.encode('utf8'), _subtype='html', _charset='utf8')
msg['From'] = mail_user
msg['Subject'] = u'svninfo'
msg['To'] = mailto
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pwd)
s.sendmail(mail_user,[mailto],msg.as_string())
s.close()
except Exception ,e:
print e
class MainHandler(tornado.web.RequestHandler):
def get(self):
index_html = '''
'''
self.write(index_html)
class EditPassHandler(tornado.web.RequestHandler):
def get(self):
# 清理临时文件
try:
import os
os.remove('%s.tmp' % passfile)
except:
pass
# 是否重启的状态
reboot_status = 0
user = strip(self.get_argument('user'))
oldpass = strip(self.get_argument('oldpass'))
newpass1 = strip(self.get_argument('newpass'))
newpass2 = strip(self.get_argument('newpass2'))
if (len(user) == 0) or (len(oldpass) == 0) or \
(len(newpass1) == 0) or (len(newpass2) == 0):
html = '输入信息错误'
else:
user_info_list = open(passfile, 'rb').readlines()
tmp_file = open('%s.tmp' % passfile, 'wb')
# 如果是用户配置则查看是否为用户,如果不是直接写入临时文件
for li in xrange(len(user_info_list)):
if user_info_list[li].find('=') > 0 :
u = strip(user_info_list[li].split('=')[0])
p = strip(user_info_list[li].split('=')[1])
#e = strip(user_info_list[li+1].split('#')[1])
if (u == user) and (p == oldpass):
tmp_file.write('%s=%s\n' % (u, newpass1))
# tmp_file.write('#%s\n' % (e))
reboot_status = 1
# li = li+1
else:
tmp_file.write(user_info_list[li])
else:
tmp_file.write(user_info_list[li])
if reboot_status == 1:
import os
import shutil
shutil.move('%s.tmp' % passfile, passfile)
os.system("killall svnserve && %s" % svn_start_comm)
html = '处理完成请重试'
self.write(html)
class SendUserInfoHandler(tornado.web.RequestHandler):
def get(self):
email = self.get_argument('email')
user_info_list = open(passfile, 'rb').readlines()
# 循环读取每一行
html = '没有找到相关信息'
for li in xrange(len(user_info_list)):
context = user_info_list[li][:-1]
# 如果有用户配置的则分解
if context.find('=') > 0 :
u = strip(user_info_list[li].split('=')[0])
p = strip(user_info_list[li].split('=')[1])
e = strip(user_info_list[li+1].split('#')[1])
# 如果用户邮箱与输入邮箱相同则发邮件
if e == strip(email):
mail_send("user:%s. passwd:%s" % (u, p), email)
html = '邮件发送注意查收'
self.write(html)
application = tornado.web.Application([
(r"/", MainHandler),
(r"/editpass/", EditPassHandler),
(r"/senduserinfo/", SendUserInfoHandler),
])
if __name__ == "__main__":
application.listen(webport)
tornado.ioloop.IOLoop.instance().start()
源码包websvn
发表评论