You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-3-console-gui/console/gui/session_function.py

126 lines
4.9 KiB

#-*- coding: utf-8 -*-
# Copyright 2012 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from PySide import QtGui, QtCore
import sys
from calculate.api.client.function import get_sid, get_ip_mac_type
from more import show_msg, LabelWordWrap
def client_sid(sid, client, cert_id, lang):
""" get number session from server and write this in file """
#lang = raw_input ("Enter language (ru, en, de, fr): ")
new_sid = client.service.post_sid(sid = sid, cert_id = cert_id, lang = lang)
fi = open(client.SID_FILE, 'w')
sid = str(new_sid[0][0])
fi.write(sid)
fi.close()
# if new_sid[0][1] == 1:
return [sid, new_sid[0][1]]
def client_post_cert (client, lang):
""" send a certificate server for check """
sid = get_sid(client.SID_FILE)
results = client.service.post_cert()
if results[0][0] == -4:
show_msg ('certificate added to database server',\
"Certificate not found in Server Database!")
#name = raw_input (_(" Delete certificate and Create new? [y]/n: "))
#if name != "n":
#delete_old_cert(client)
#sys.exit()
# print _('Add certificate to server Database...')
ip, mac, client_type = get_ip_mac_type('eth0', 'gui')
print ip, mac, client_type
cert_id = client.service.cert_add(mac, client_type)
print _("Your certificate ID = %s") %cert_id
sys.exit(1)
sid, new_session = client_sid(sid, client, results[0][0], lang)
if new_session:
print _(" New Session")
else: print _(" Old Session")
print _(" Your session id = %s") %sid
if results[0][0] == -3:
print _("Certificate not send!")
else:
print _(" Your certifitate id = %d") %(results[0][0])
try:
if results[0][1] == -2:
print _("expiry date certificate has passed")
elif results[0][1] > 0:
print _("shelf life expires after %d days") \
%(results[0][1])
except:
pass
class ViewSessionInfo (QtGui.QWidget):
def __init__(self, parent, client):
QtGui.QWidget.__init__(self)
self.layout = QtGui.QVBoxLayout()
sid = get_sid(client.SID_FILE)
results = client.service.post_cert()
if results[0][0] == -4:
self.layout.addWidget(LabelWordWrap('Certificate not found in Server Database!'))
self.layout.addWidget(LabelWordWrap('Add certificate to server Database...'))
ip, mac, client_type = get_ip_mac_type('eth0', 'gui')
self.layout.addWidget(LabelWordWrap('Your IP adress - '+ip))
self.layout.addWidget(LabelWordWrap('Your MAC adress - '+mac))
cert_id = client.service.cert_add(mac, client_type)
self.layout.addWidget(LabelWordWrap('Your certificate ID = '+cert_id))
self.setLayout(self.layout)
return 1
sid = get_sid(client.SID_FILE)
self.layout.addWidget(LabelWordWrap('Your session id = '+str(sid)))
if results[0][0] == -3:
self.layout.addWidget(LabelWordWrap('Certificate not send!'))
else:
self.layout.addWidget(LabelWordWrap('Your certifitate id = '+ str(results[0][0])))
try:
if results[0][1] == -2:
self.layout.addWidget(LabelWordWrap('expiry date certificate has passed'))
elif results[0][1] > 0:
self.layout.addWidget(LabelWordWrap('shelf life expires after %d days' %(results[0][1])))
except:
pass
ip, mac, client_type = get_ip_mac_type('eth0', 'gui')
self.layout.addWidget(LabelWordWrap('Your IP adress - '+ip))
self.layout.addWidget(LabelWordWrap('Your MAC adress - '+mac))
Quit_button = QtGui.QPushButton("Quit")
self.layout.addWidget(Quit_button)
self.connect(Quit_button, QtCore.SIGNAL("clicked()"),
self, QtCore.SLOT("close()"))
self.move(100+parent.frameGeometry().x(), \
100+parent.frameGeometry().y())
self.resize(240,200)
self.setLayout(self.layout)
self.setWindowIcon(QtGui.QIcon.fromTheme("document-edit-verify"))
# for clear memory after closed this window
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)