pull/109/head
midoks 7 years ago
parent d4d8426258
commit 180a1ec948
  1. BIN
      class/fonts/2.ttf
  2. 130
      class/vilidate.py
  3. 25
      route/dashboard.py
  4. 2
      route/files.py
  5. 60
      templates/default/login.html

Binary file not shown.

@ -0,0 +1,130 @@
#!/usr/bin/env python
# coding: utf-8
# +-------------------------------------------------------------------
# | 宝塔Linux面板
# +-------------------------------------------------------------------
# | Copyright (c) 2015-2099 宝塔(http://bt.cn) All rights reserved.
# +-------------------------------------------------------------------
# | Author: 黄文良 <287962566@qq.com>
# +-------------------------------------------------------------------
import random, math
from PIL import Image, ImageDraw, ImageFont, ImageFilter
class vieCode:
__fontSize = 20 #字体大小
__width = 120 #画布宽度
__heigth = 45 #画布高度
__length = 4 #验证码长度
__draw = None #画布
__img = None #图片资源
__code = None #验证码字符
__str = None #自定义验证码字符集
__inCurve = True #是否画干扰线
__inNoise = True #是否画干扰点
__type = 2 #验证码类型 1、纯字母 2、数字字母混合
__fontPatn = 'class/fonts/2.ttf' #字体
def GetCodeImage(self,size = 80,length = 4):
'''获取验证码图片
@param int size 验证码大小
@param int length 验证码长度
'''
#准备基础数据
self.__length = length
self.__fontSize = size
self.__width = self.__fontSize * self.__length
self.__heigth = int(self.__fontSize * 1.5)
#生成验证码图片
self.__createCode()
self.__createImage()
self.__createNoise()
self.__printString()
self.__cerateFilter()
return self.__img,self.__code
def __cerateFilter(self):
'''模糊处理'''
self.__img = self.__img.filter(ImageFilter.BLUR)
filter = ImageFilter.ModeFilter(8)
self.__img = self.__img.filter(filter)
def __createCode(self):
'''创建验证码字符'''
#是否自定义字符集合
if not self.__str:
#源文本
number = "3456789"
srcLetter = "qwertyuipasdfghjkzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
srcUpper = srcLetter.upper()
if self.__type == 1:
self.__str = number
else:
self.__str = srcLetter + srcUpper + number
#构造验证码
self.__code = random.sample(self.__str,self.__length)
def __createImage(self):
'''创建画布'''
bgColor = (random.randint(200,255),random.randint(200,255),random.randint(200,255))
self.__img = Image.new('RGB', (self.__width,self.__heigth), bgColor)
self.__draw = ImageDraw.Draw(self.__img)
def __createNoise(self):
'''画干扰点'''
if not self.__inNoise:
return
font = ImageFont.truetype(self.__fontPatn, int(self.__fontSize / 1.5))
for i in xrange(5):
#杂点颜色
noiseColor = (random.randint(150,200), random.randint(150,200), random.randint(150,200))
putStr = random.sample(self.__str,2)
for j in range(2):
#绘杂点
size = (random.randint(-10,self.__width), random.randint(-10,self.__heigth))
self.__draw.text(size,putStr[j], font=font,fill=noiseColor)
pass
def __createCurve(self):
'''画干扰线'''
if not self.__inCurve:
return
x = y = 0;
#计算曲线系数
a = random.uniform(1, self.__heigth / 2)
b = random.uniform(-self.__width / 4, self.__heigth / 4)
f = random.uniform(-self.__heigth / 4, self.__heigth / 4)
t = random.uniform(self.__heigth, self.__width * 2)
xend = random.randint(self.__width / 2, self.__width * 2)
w = (2 * math.pi) / t
#画曲线
color = (random.randint(30, 150), random.randint(30, 150), random.randint(30, 150))
for x in xrange(xend):
if w!=0:
for k in xrange(int(self.__heigth / 10)):
y = a * math.sin(w * x + f)+ b + self.__heigth / 2
i = int(self.__fontSize / 5)
while i > 0:
px = x + i
py = y + i + k
self.__draw.point((px , py), color)
i -= i
def __printString(self):
'''打印验证码字符串'''
font = ImageFont.truetype(self.__fontPatn, self.__fontSize)
x = 0;
#打印字符到画板
for i in xrange(self.__length):
#设置字体随机颜色
color = (random.randint(30, 150), random.randint(30, 150), random.randint(30, 150))
#计算座标
x = random.uniform(self.__fontSize*i*0.95,self.__fontSize*i*1.1);
y = self.__fontSize * random.uniform(0.3,0.5);
#打印字符
self.__draw.text((x, y),self.__code[i], font=font, fill=color)

@ -3,8 +3,15 @@
from flask import Flask from flask import Flask
from flask import Blueprint, render_template from flask import Blueprint, render_template
from flask import jsonify from flask import jsonify
from flask import request
import psutil import psutil
import time import time
import os
import sys
sys.path.append(os.getcwd() + "/class/")
dashboard = Blueprint('dashboard', __name__, template_folder='templates') dashboard = Blueprint('dashboard', __name__, template_folder='templates')
@ -15,6 +22,24 @@ def index():
return render_template('default/index.html') return render_template('default/index.html')
@dashboard.route("/code")
def code():
pass
# import vilidate
# vie = vilidate.vieCode()
# codeImage = vie.GetCodeImage(80, 4)
# try:
# from cStringIO import StringIO
# except:
# from StringIO import StringIO
# out = StringIO()
# print out
# codeImage[0].save(out, "png")
# return out.getvalue()
@dashboard.route("/login") @dashboard.route("/login")
def login(): def login():
return render_template('default/login.html') return render_template('default/login.html')

@ -24,7 +24,7 @@ def GetDiskInfo():
@files.route('/get_exec_log', methods=['POST']) @files.route('/get_exec_log', methods=['POST'])
def GetExecLog(): def get_exec_log():
file = os.getcwd() + "/tmp/panelExec.log" file = os.getcwd() + "/tmp/panelExec.log"
v = public.getLastLine(file, 100) v = public.getLastLine(file, 100)
return v return v

@ -7,9 +7,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="icon" href="/static/favicon.ico" type="image/x-icon" /> <link rel="icon" href="/static/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon" />
<title>$session.webname</title> <title>mdserver-web</title>
<link rel="stylesheet" type="text/css" href="/static/css/site.css?date=20180523"> <link rel="stylesheet" type="text/css" href="/static/css/site.css?v={{config.version}}">
<link rel="stylesheet" type="text/css" href="/static/css/login.css?date=20180404"> <link rel="stylesheet" type="text/css" href="/static/css/login.css?v={{config.version}}">
</head> </head>
@ -139,55 +139,29 @@
<div class="login"> <div class="login">
<div class="account"> <div class="account">
<form class="loginform" method="post" action="/login" onsubmit="return false;"> <form class="loginform" method="post" action="/login" onsubmit="return false;">
<div class="rlogo">$session.webname</div> <div class="rlogo">mdserver-web</div>
<div class="line"><input class="inputtxt" value="" name="username" datatype="*" nullmsg="$tData['lan']['N1']" errormsg="$tData['lan']['N2']" placeholder="$tData['lan']['N3']" type="text"><div class="Validform_checktip"></div></div> <div class="line"><input class="inputtxt" value="" name="username" datatype="*" nullmsg="账户" errormsg="$tData['lan']['N2']" placeholder="账户" type="text"><div class="Validform_checktip"></div></div>
<div class="line"><input class="inputtxt" name="password" value="" datatype="*" nullmsg="$tData['lan']['N4']" errormsg="$tData['lan']['N5']" placeholder="$tData['lan']['N6']" type="password"><div class="Validform_checktip"></div></div> <div class="line"><input class="inputtxt" name="password" value="" datatype="*" nullmsg="密码" errormsg="$tData['lan']['N5']" placeholder="密码" type="password"><div class="Validform_checktip"></div></div>
<div style="color: red;position: relative;top: -14px;" id="errorStr"></div> <div style="color: red;position: relative;top: -14px;" id="errorStr"></div>
<div class="line yzm" style="top: -5px; <div class="line yzm" style="top: -5px;display:block;">
$if web.ctx.session.code: <input type="text" class="inputtxt" name="code" nullmsg="$tData['lan']['N7']" errormsg="验证码" datatype="*" placeholder="验证码">
display:block;
$else:
display:none;
">
<input type="text" class="inputtxt" name="code" nullmsg="$tData['lan']['N7']" errormsg="$tData['lan']['N8']" datatype="*" placeholder="$tData['lan']['N9']">
<div class="Validform_checktip"></div> <div class="Validform_checktip"></div>
<img width="100" height="40" class="passcode" onClick="this.src=this.src.split('?')[0] + '?'+new Date().getTime()" src="/code" style="border: 1px solid #ccc; float: right;" title="$tData['lan']['N10']" > <img width="100" height="40" class="passcode" onClick="this.src=this.src.split('?')[0] + '?'+new Date().getTime()" src="/code" style="border: 1px solid #ccc; float: right;" title="" >
</div> </div>
<div class="login_btn"><input id="login-button" value="$tData['lan']['N11']" type="submit"></div> <div class="login_btn"><input id="login-button" value="登录" type="submit"></div>
<p class="pwinfo" style="display:none">$tData['lan']['N12']</p> <p class="pwinfo" style="display:none">$tData['lan']['N12']</p>
<a class="resetpw" href="http://www.bt.cn/bbs/thread-1172-1-1.html" target="_blank">$tData['lan']['N13']</a> <a class="resetpw" href="http://www.bt.cn/bbs/thread-1172-1-1.html" target="_blank">$tData['lan']['N13']</a>
</form> </form>
</div> </div>
<div class="scanCode" style="display: none;">
<div class="titles"><span>宝塔小程序扫码登录</span></div>
<div class="qrCode" id="qrcode"></div>
<div class="scanTip">
<div class="list_scan">
<img src="/static/img/sCan.png" />
<span>打开
<a href="javascript:;" class="btlink" >宝塔小程序
<div class="weChatSamll"><img src="https://app.bt.cn/static/app.png"><em></em></div>
</a>
</span>
<span>扫一扫登录</span>
</div>
</div>
</div>
<div class="entrance" style="display: none;">
<div class="bg_img"></div>
<div class="tips">
<span><img src="/static/img/safety_ico.png"><span>扫码登录更安全</span></span>
<em></em>
</div>
</div>
</div> </div>
</div> </div>
<script type="text/javascript" src="/static/js/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="/static/js/jquery-1.10.2.min.js?v={{config.version}}"></script>
<script src="/static/language/zh-cn.js"></script> <script src="/static/language/zh-cn.js?v={{config.version}}"></script>
<script src="/static/language/$web.ctx.session.lan/lan.js?date=20170920"></script> <script src="/static/language//lan.js?v={{config.version}}"></script>
<script type="text/javascript" src="/static/layer/layer.js"></script> <script type="text/javascript" src="/static/layer/layer.js?v={{config.version}}"></script>
<script type="text/javascript" src="/static/js/jquery.qrcode.min.js"></script> <script type="text/javascript" src="/static/js/jquery.qrcode.min.js?v={{config.version}}"></script>
<script type="text/javascript" src="/static/js/Validform_v5.3.2_min.js"></script> <script type="text/javascript" src="/static/js/Validform_v5.3.2_min.js?v={{config.version}}"></script>
<script type="text/javascript"> <script type="text/javascript">
function Wreset(){ function Wreset(){
var w = $$(window).width(); var w = $$(window).width();

Loading…
Cancel
Save