프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / WebServer / app / license / index.py @ 1677dee5

이력 | 보기 | 이력해설 | 다운로드 (1.61 KB)

1
# file name : index.py
2
# pwd : /project_name/app/license/index.py
3

    
4
from flask import Blueprint, request, render_template, flash, redirect, url_for
5
from flask_wtf import FlaskForm
6
from wtforms import *
7
from wtforms.validators import *
8
from flask import current_app as app
9

    
10
license_service = Blueprint('license', __name__, url_prefix='/license')
11

    
12

    
13
class LicenseForm(FlaskForm):
14
    csrf_token = 'id2 web service'
15
    authorization = PasswordField('Authorization :')
16
    computer_name = StringField('Computer Name :')
17
    submit = SubmitField('Submit')
18

    
19
    @staticmethod
20
    def generate_license_key(pw: str, clear: str) -> str:
21
        import base64
22

    
23
        key = 'Image Drawing to Intelligent Drawing'
24

    
25
        if pw != 'admin':
26
            return 'Invalid Authorization'
27

    
28
        enc = []
29
        for i in range(len(clear)):
30
            key_c = key[i % len(key)]
31
            enc_c = (ord(clear[i]) + ord(key_c)) % 256
32
            enc.append(enc_c)
33

    
34
        new_key = base64.urlsafe_b64encode(bytes(enc))
35

    
36
        return new_key.decode('utf-8')
37

    
38

    
39
@license_service.route('/', methods=['GET', 'POST'])
40
def index():
41
    authorization = None
42
    computer_name = None
43
    code = None
44

    
45
    form = LicenseForm()
46
    if form.validate_on_submit():
47
        authorization = form.authorization.data
48
        computer_name = form.computer_name.data
49
        code = LicenseForm.generate_license_key(authorization, computer_name)
50
        form.authorization.data = ''
51
        form.computer_name.data = ''
52

    
53
    return render_template("/license/index.html", form=form, authorization=authorization, computer_name=computer_name,
54
                           code=code)
55

    
클립보드 이미지 추가 (최대 크기: 500 MB)