개정판 b2a8c21a
issue #700: 라이센스 타입2 처리
Change-Id: Ib958880f225dd5360bfb56f4d3eedf2dc86179c4
DTI_PID/DTI_PID/License.py | ||
---|---|---|
1 | 1 |
# coding: utf-8 |
2 |
""" |
|
3 |
This is license module |
|
4 |
""" |
|
2 |
""" This is license module """ |
|
5 | 3 |
|
6 | 4 |
import sys |
7 | 5 |
import os |
... | ... | |
25 | 23 |
def __init__(self, parent): |
26 | 24 |
QDialog.__init__(self, parent) |
27 | 25 |
|
28 |
self.ui = License_UI.Ui_DialogLicense() |
|
29 |
self.ui.setupUi(self) |
|
30 |
self.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint) |
|
31 |
self.setFixedSize(self.size()) |
|
26 |
try: |
|
27 |
self.ui = License_UI.Ui_LicenseDialog() |
|
28 |
self.ui.setupUi(self) |
|
29 |
self.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint) |
|
30 |
self.setFixedSize(self.size()) |
|
31 |
|
|
32 |
self.ui.textEditMessage.setTextColor(Qt.red) |
|
33 |
self.ui.lineEditMacAddress.setText(QLicenseDialog.get_mac_address()) |
|
34 |
except Exception as ex: |
|
35 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
36 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
37 |
|
|
38 |
self.ui.textEditMessage.setText(message) |
|
32 | 39 |
|
33 | 40 |
@property |
34 | 41 |
def license(self): |
... | ... | |
81 | 88 |
""" check license key with computer name """ |
82 | 89 |
from AppDocData import AppDocData |
83 | 90 |
from datetime import datetime, timedelta |
91 |
import jwt |
|
92 |
import requests |
|
84 | 93 |
|
85 | 94 |
try: |
86 | 95 |
internal = False |
... | ... | |
89 | 98 |
appDocData = AppDocData.instance() |
90 | 99 |
configs = appDocData.getAppConfigs('app', 'license') |
91 | 100 |
configs2 = appDocData.getAppConfigs('app', 'expiration') |
92 |
if configs and 1 == len(configs): |
|
101 |
if configs and 1 == len(configs) and 3 == len(configs[0].value.split('.')): |
|
102 |
"""license type 2""" |
|
103 |
payload = jwt.decode(configs[0].value, QLicenseDialog.KEY, 'HS256') |
|
104 |
if payload['mac'] == QLicenseDialog.get_mac_address(): |
|
105 |
# check if license key is valid through server |
|
106 |
api, headers = payload['api'], \ |
|
107 |
{'Content-Type': 'application/json; charset=utf-8', 'x-auth-token': configs[0].value} |
|
108 |
response = requests.get(api, headers=headers) |
|
109 |
stuff = response.json() |
|
110 |
if not stuff['success']: |
|
111 |
QMessageBox.critical(None, 'Error', stuff['msg']) |
|
112 |
return False |
|
113 |
|
|
114 |
return True |
|
115 |
elif configs and 1 == len(configs) and configs[0].value: |
|
93 | 116 |
# check doftech user |
94 | 117 |
if 'DOFTECH' in configs[0].value: |
95 | 118 |
# user |
... | ... | |
128 | 151 |
dialog = QLicenseDialog(None) |
129 | 152 |
dialog.exec_() |
130 | 153 |
if dialog.isAccepted: return True |
154 |
except jwt.ExpiredSignatureError: |
|
155 |
message = f"License has expired" |
|
156 |
QMessageBox.critical(None, 'Error', message) |
|
131 | 157 |
except Exception as ex: |
132 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
133 |
sys.exc_info()[-1].tb_lineno)
|
|
158 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
|
|
159 |
f"{sys.exc_info()[-1].tb_lineno}"
|
|
134 | 160 |
print(message) |
135 | 161 |
|
136 | 162 |
return False |
... | ... | |
159 | 185 |
|
160 | 186 |
return "".join(dec) |
161 | 187 |
|
188 |
@staticmethod |
|
189 |
def get_mac_address(remote_server="smartfeedweb.azurewebsites.net") -> str: |
|
190 |
""" Return the/a network-facing mac-address of device for this system. """ |
|
191 |
import getmac |
|
192 |
import socket |
|
193 |
|
|
194 |
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: |
|
195 |
s.connect((remote_server, 80)) |
|
196 |
ip = s.getsockname()[0] |
|
197 |
return getmac.get_mac_address(ip=ip) |
|
198 |
|
|
162 | 199 |
def accept(self): |
163 | 200 |
from AppDocData import AppDocData |
164 | 201 |
from AppDocData import Config |
DTI_PID/DTI_PID/License_UI.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
|
3 |
# Form implementation generated from reading ui file '.\ui\License.ui'
|
|
3 |
# Form implementation generated from reading ui file '.\UI\License.ui'
|
|
4 | 4 |
# |
5 |
# Created by: PyQt5 UI code generator 5.11.3
|
|
5 |
# Created by: PyQt5 UI code generator 5.13.1
|
|
6 | 6 |
# |
7 | 7 |
# WARNING! All changes made in this file will be lost! |
8 | 8 |
|
9 |
|
|
9 | 10 |
from PyQt5 import QtCore, QtGui, QtWidgets |
10 | 11 |
|
11 |
class Ui_DialogLicense(object): |
|
12 |
def setupUi(self, DialogLicense): |
|
13 |
DialogLicense.setObjectName("DialogLicense") |
|
14 |
DialogLicense.resize(400, 87) |
|
15 |
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) |
|
16 |
sizePolicy.setHorizontalStretch(0) |
|
17 |
sizePolicy.setVerticalStretch(0) |
|
18 |
sizePolicy.setHeightForWidth(DialogLicense.sizePolicy().hasHeightForWidth()) |
|
19 |
DialogLicense.setSizePolicy(sizePolicy) |
|
20 |
DialogLicense.setMaximumSize(QtCore.QSize(16777215, 16777215)) |
|
21 |
font = QtGui.QFont() |
|
22 |
font.setFamily("맑은 고딕") |
|
23 |
DialogLicense.setFont(font) |
|
24 |
self.gridLayout = QtWidgets.QGridLayout(DialogLicense) |
|
12 |
|
|
13 |
class Ui_LicenseDialog(object): |
|
14 |
def setupUi(self, LicenseDialog): |
|
15 |
LicenseDialog.setObjectName("LicenseDialog") |
|
16 |
LicenseDialog.resize(643, 172) |
|
17 |
icon = QtGui.QIcon() |
|
18 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/ID2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
|
19 |
LicenseDialog.setWindowIcon(icon) |
|
20 |
LicenseDialog.setSizeGripEnabled(True) |
|
21 |
self.gridLayout_2 = QtWidgets.QGridLayout(LicenseDialog) |
|
22 |
self.gridLayout_2.setObjectName("gridLayout_2") |
|
23 |
self.gridLayout = QtWidgets.QGridLayout() |
|
25 | 24 |
self.gridLayout.setObjectName("gridLayout") |
26 |
self.horizontalLayout = QtWidgets.QHBoxLayout() |
|
27 |
self.horizontalLayout.setObjectName("horizontalLayout") |
|
28 |
self.label = QtWidgets.QLabel(DialogLicense) |
|
25 |
self.label = QtWidgets.QLabel(LicenseDialog) |
|
29 | 26 |
self.label.setObjectName("label") |
30 |
self.horizontalLayout.addWidget(self.label)
|
|
31 |
self.lineEditLicense = QtWidgets.QLineEdit(DialogLicense)
|
|
27 |
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
|
|
28 |
self.lineEditLicense = QtWidgets.QLineEdit(LicenseDialog)
|
|
32 | 29 |
self.lineEditLicense.setObjectName("lineEditLicense") |
33 |
self.horizontalLayout.addWidget(self.lineEditLicense) |
|
34 |
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1) |
|
35 |
self.buttonBox = QtWidgets.QDialogButtonBox(DialogLicense) |
|
30 |
self.gridLayout.addWidget(self.lineEditLicense, 0, 1, 1, 1) |
|
31 |
self.label_2 = QtWidgets.QLabel(LicenseDialog) |
|
32 |
self.label_2.setObjectName("label_2") |
|
33 |
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) |
|
34 |
self.lineEditMacAddress = QtWidgets.QLineEdit(LicenseDialog) |
|
35 |
self.lineEditMacAddress.setReadOnly(True) |
|
36 |
self.lineEditMacAddress.setObjectName("lineEditMacAddress") |
|
37 |
self.gridLayout.addWidget(self.lineEditMacAddress, 1, 1, 1, 1) |
|
38 |
self.textEditMessage = QtWidgets.QTextEdit(LicenseDialog) |
|
39 |
self.textEditMessage.setReadOnly(True) |
|
40 |
self.textEditMessage.setObjectName("textEditMessage") |
|
41 |
self.gridLayout.addWidget(self.textEditMessage, 2, 1, 1, 1) |
|
42 |
self.label_3 = QtWidgets.QLabel(LicenseDialog) |
|
43 |
self.label_3.setObjectName("label_3") |
|
44 |
self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) |
|
45 |
self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1) |
|
46 |
self.buttonBox = QtWidgets.QDialogButtonBox(LicenseDialog) |
|
36 | 47 |
self.buttonBox.setOrientation(QtCore.Qt.Horizontal) |
37 | 48 |
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) |
38 | 49 |
self.buttonBox.setObjectName("buttonBox") |
39 |
self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1) |
|
50 |
self.gridLayout_2.addWidget(self.buttonBox, 1, 0, 1, 1)
|
|
40 | 51 |
|
41 |
self.retranslateUi(DialogLicense)
|
|
42 |
self.buttonBox.accepted.connect(DialogLicense.accept)
|
|
43 |
self.buttonBox.rejected.connect(DialogLicense.reject)
|
|
44 |
QtCore.QMetaObject.connectSlotsByName(DialogLicense)
|
|
52 |
self.retranslateUi(LicenseDialog)
|
|
53 |
self.buttonBox.accepted.connect(LicenseDialog.accept)
|
|
54 |
self.buttonBox.rejected.connect(LicenseDialog.reject)
|
|
55 |
QtCore.QMetaObject.connectSlotsByName(LicenseDialog)
|
|
45 | 56 |
|
46 |
def retranslateUi(self, DialogLicense):
|
|
57 |
def retranslateUi(self, LicenseDialog):
|
|
47 | 58 |
_translate = QtCore.QCoreApplication.translate |
48 |
DialogLicense.setWindowTitle(_translate("DialogLicense", "License")) |
|
49 |
self.label.setText(_translate("DialogLicense", "License Key : ")) |
|
50 |
|
|
59 |
LicenseDialog.setWindowTitle(_translate("LicenseDialog", "License")) |
|
60 |
self.label.setText(_translate("LicenseDialog", "License : ")) |
|
61 |
self.label_2.setText(_translate("LicenseDialog", "MAC : ")) |
|
62 |
self.label_3.setText(_translate("LicenseDialog", "Message : ")) |
|
63 |
import MainWindow_rc |
DTI_PID/DTI_PID/UI/License.ui | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<ui version="4.0"> |
|
3 |
<class>LicenseDialog</class> |
|
4 |
<widget class="QDialog" name="LicenseDialog"> |
|
5 |
<property name="geometry"> |
|
6 |
<rect> |
|
7 |
<x>0</x> |
|
8 |
<y>0</y> |
|
9 |
<width>643</width> |
|
10 |
<height>172</height> |
|
11 |
</rect> |
|
12 |
</property> |
|
13 |
<property name="windowTitle"> |
|
14 |
<string>License</string> |
|
15 |
</property> |
|
16 |
<property name="windowIcon"> |
|
17 |
<iconset resource="../res/MainWindow.qrc"> |
|
18 |
<normaloff>:/newPrefix/ID2.png</normaloff>:/newPrefix/ID2.png</iconset> |
|
19 |
</property> |
|
20 |
<property name="sizeGripEnabled"> |
|
21 |
<bool>true</bool> |
|
22 |
</property> |
|
23 |
<layout class="QGridLayout" name="gridLayout_2"> |
|
24 |
<item row="0" column="0"> |
|
25 |
<layout class="QGridLayout" name="gridLayout"> |
|
26 |
<item row="0" column="0"> |
|
27 |
<widget class="QLabel" name="label"> |
|
28 |
<property name="text"> |
|
29 |
<string>License : </string> |
|
30 |
</property> |
|
31 |
</widget> |
|
32 |
</item> |
|
33 |
<item row="0" column="1"> |
|
34 |
<widget class="QLineEdit" name="lineEditLicense"/> |
|
35 |
</item> |
|
36 |
<item row="1" column="0"> |
|
37 |
<widget class="QLabel" name="label_2"> |
|
38 |
<property name="text"> |
|
39 |
<string>MAC : </string> |
|
40 |
</property> |
|
41 |
</widget> |
|
42 |
</item> |
|
43 |
<item row="1" column="1"> |
|
44 |
<widget class="QLineEdit" name="lineEditMacAddress"> |
|
45 |
<property name="readOnly"> |
|
46 |
<bool>true</bool> |
|
47 |
</property> |
|
48 |
</widget> |
|
49 |
</item> |
|
50 |
<item row="2" column="1"> |
|
51 |
<widget class="QTextEdit" name="textEditMessage"> |
|
52 |
<property name="readOnly"> |
|
53 |
<bool>true</bool> |
|
54 |
</property> |
|
55 |
</widget> |
|
56 |
</item> |
|
57 |
<item row="2" column="0"> |
|
58 |
<widget class="QLabel" name="label_3"> |
|
59 |
<property name="text"> |
|
60 |
<string>Message : </string> |
|
61 |
</property> |
|
62 |
</widget> |
|
63 |
</item> |
|
64 |
</layout> |
|
65 |
</item> |
|
66 |
<item row="1" column="0"> |
|
67 |
<widget class="QDialogButtonBox" name="buttonBox"> |
|
68 |
<property name="orientation"> |
|
69 |
<enum>Qt::Horizontal</enum> |
|
70 |
</property> |
|
71 |
<property name="standardButtons"> |
|
72 |
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> |
|
73 |
</property> |
|
74 |
</widget> |
|
75 |
</item> |
|
76 |
</layout> |
|
77 |
</widget> |
|
78 |
<resources> |
|
79 |
<include location="../res/MainWindow.qrc"/> |
|
80 |
</resources> |
|
81 |
<connections> |
|
82 |
<connection> |
|
83 |
<sender>buttonBox</sender> |
|
84 |
<signal>accepted()</signal> |
|
85 |
<receiver>LicenseDialog</receiver> |
|
86 |
<slot>accept()</slot> |
|
87 |
<hints> |
|
88 |
<hint type="sourcelabel"> |
|
89 |
<x>248</x> |
|
90 |
<y>254</y> |
|
91 |
</hint> |
|
92 |
<hint type="destinationlabel"> |
|
93 |
<x>157</x> |
|
94 |
<y>274</y> |
|
95 |
</hint> |
|
96 |
</hints> |
|
97 |
</connection> |
|
98 |
<connection> |
|
99 |
<sender>buttonBox</sender> |
|
100 |
<signal>rejected()</signal> |
|
101 |
<receiver>LicenseDialog</receiver> |
|
102 |
<slot>reject()</slot> |
|
103 |
<hints> |
|
104 |
<hint type="sourcelabel"> |
|
105 |
<x>316</x> |
|
106 |
<y>260</y> |
|
107 |
</hint> |
|
108 |
<hint type="destinationlabel"> |
|
109 |
<x>286</x> |
|
110 |
<y>274</y> |
|
111 |
</hint> |
|
112 |
</hints> |
|
113 |
</connection> |
|
114 |
</connections> |
|
115 |
</ui> |
내보내기 Unified diff