parent
78bac1e35c
commit
aced1c4eab
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/python
|
||||
#-*- coding: utf-8 -*-
|
||||
from calculate.lib.cl_datavars import DataVars
|
||||
from calculate.api.cl_api import DataVarsApi
|
||||
|
||||
class ApiClient:
|
||||
def __init__(self):
|
||||
# Initialization of system variables
|
||||
Vars = DataVarsApi()
|
||||
Vars.importApi()
|
||||
Vars.flIniFile()
|
||||
clVars = DataVars()
|
||||
clVars.flIniFile()
|
||||
|
||||
# Initialization other variables
|
||||
self.homePath = clVars.Get('ur_home_path')
|
||||
path_to_cert = '~/.calculate/client_cert/'
|
||||
self.path_to_cert = path_to_cert.replace("~",self.homePath)
|
||||
|
||||
self.WindowTitle = 'cl-api-client'
|
||||
self.default_host = 'localhost'
|
||||
self.default_port = '8888'
|
||||
|
||||
self.client = None
|
@ -0,0 +1,159 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PySide import QtGui, QtCore
|
||||
from calculate.api.client.client_class import Client_suds
|
||||
from calculate.api.client.client_class import HTTPSClientCertTransport
|
||||
from suds import WebFault
|
||||
from suds.transport import TransportError, Request
|
||||
from calculate.api.cl_api import DataVarsApi
|
||||
|
||||
from calculate.api.client.function import *
|
||||
from calculate.api.client.pid_information import *
|
||||
from calculate.api.client.cert_func import *
|
||||
from calculate.api.client.cert_verify import get_CRL, VerifyError
|
||||
from calculate.api.client.sid_func import *
|
||||
|
||||
import soap
|
||||
from soap.more import https_server, client_signal, show_msg, test
|
||||
|
||||
class Conn(QtGui.QWidget):
|
||||
|
||||
def __init__(self, ClientObj):
|
||||
super(Conn, self).__init__()
|
||||
self.ClientObj = ClientObj
|
||||
self.initUI()
|
||||
|
||||
def initUI(self):
|
||||
grid = QtGui.QGridLayout()
|
||||
grid.setSpacing(10)
|
||||
|
||||
self.lbl_host = QtGui.QLabel("Host: ")
|
||||
self.lbl_port = QtGui.QLabel("Port: ")
|
||||
self.text_host = QtGui.QLineEdit(self.ClientObj.default_host)
|
||||
self.text_port = QtGui.QLineEdit(self.ClientObj.default_port)
|
||||
|
||||
grid.setRowMinimumHeight(0,20)
|
||||
grid.setColumnMinimumWidth(0,30)
|
||||
# grid.addWidget(QtGui.QSpacerItem(10,10),0,0)
|
||||
|
||||
grid.addWidget(self.lbl_host, 1, 1)
|
||||
grid.addWidget(self.lbl_port, 2, 1)
|
||||
grid.addWidget(self.text_host, 1, 2)
|
||||
grid.addWidget(self.text_port, 2, 2)
|
||||
|
||||
|
||||
self.cmd_connect = QtGui.QPushButton('Connect')
|
||||
grid.addWidget(self.cmd_connect, 3, 2)
|
||||
|
||||
self.cmd_connect.connect \
|
||||
(self.cmd_connect, QtCore.SIGNAL('clicked()'), self.onClick)
|
||||
|
||||
self.setLayout(grid)
|
||||
self.setGeometry(0, 0, 150, 180)
|
||||
self.show()
|
||||
|
||||
# establish a connection
|
||||
def onClick(self):
|
||||
# write parameters
|
||||
self.str_host = self.text_host.text()
|
||||
self.str_port = self.text_port.text()
|
||||
self.lbl_host.setText(self.str_host)
|
||||
self.lbl_port.setText(self.str_port)
|
||||
|
||||
try:
|
||||
int_port = int(self.str_port)
|
||||
except:
|
||||
show_msg("Enter correctly port!")
|
||||
return 1
|
||||
|
||||
# get server hostname
|
||||
url = "https://%s:%d/?wsdl" %(self.str_host, int_port)
|
||||
path_to_cert = self.ClientObj.path_to_cert
|
||||
try:
|
||||
client = Client_suds(url, transport = \
|
||||
HTTPSClientCertTransport(None,None, path_to_cert))
|
||||
except:
|
||||
show_msg("Not connected!")
|
||||
return 1
|
||||
server_host_name = client.service.get_server_host_name()
|
||||
del (client)
|
||||
self.lbl_port.setText(server_host_name)
|
||||
|
||||
try:
|
||||
import glob
|
||||
all_cert_list = glob.glob(path_to_cert + '*.crt')
|
||||
fit_cert_list = []
|
||||
|
||||
for client_cert_path in all_cert_list:
|
||||
client_cert = client_cert_path.replace(path_to_cert, '')
|
||||
client_cert_name = client_cert.replace('.crt', '')
|
||||
if server_host_name.endswith(client_cert_name):
|
||||
fit_cert_list.append(client_cert_name)
|
||||
fit_cert_list.sort(key = len)
|
||||
Connect_Error = 1
|
||||
for i in range (0, len(fit_cert_list)):
|
||||
#print 'fit_cert_list = ',fit_cert_list
|
||||
cert_name = fit_cert_list.pop()
|
||||
CERT_FILE = path_to_cert + cert_name + '.crt'
|
||||
CERT_KEY = path_to_cert + cert_name + '.key'
|
||||
# print "cert_name = ",cert_name
|
||||
try:
|
||||
self.ClientObj.client = Client_suds(url,\
|
||||
transport = HTTPSClientCertTransport(CERT_KEY, \
|
||||
CERT_FILE, path_to_cert))
|
||||
self.ClientObj.client.set_parameters \
|
||||
(path_to_cert, CERT_FILE, CERT_KEY)
|
||||
client_post_cert(self.ClientObj.client)
|
||||
Connect_Error = 0
|
||||
except VerifyError, e:
|
||||
show_msg (e.value)
|
||||
Connect_Error = 1
|
||||
except Exception, e:
|
||||
print 1111111
|
||||
print dir(e)
|
||||
show_msg (e.message)
|
||||
Connect_Error = 1
|
||||
#sys.exit()
|
||||
if Connect_Error == 0:
|
||||
break
|
||||
#If the certificate file misses
|
||||
if Connect_Error:
|
||||
CERT_FILE = None
|
||||
CERT_KEY = None
|
||||
self.ClientObj.client = Client_suds(url,\
|
||||
transport = HTTPSClientCertTransport(CERT_KEY, CERT_FILE,\
|
||||
path_to_cert))
|
||||
|
||||
self.ClientObj.client.set_parameters (path_to_cert, CERT_FILE, CERT_KEY)
|
||||
|
||||
Vars = DataVarsApi()
|
||||
Vars.importApi()
|
||||
Vars.flIniFile()
|
||||
try:
|
||||
self.ClientObj.client.frame_period = Vars.Get('cl_api_get_frame_period')
|
||||
except:
|
||||
self.ClientObj.client.frame_period = 2
|
||||
|
||||
signaling = threading.Thread(target=client_signal, args = (self.ClientObj.client, ))
|
||||
signaling.setDaemon(True)
|
||||
https_server(self.ClientObj.client, signaling)
|
||||
#----------------------------------------------------
|
||||
except WebFault, f:
|
||||
show_msg ("Exception: %s" %f)
|
||||
print f.fault
|
||||
except TransportError, te:
|
||||
show_msg ("Exception: %s" %te)
|
||||
except Exception, e:
|
||||
show_msg ("Exception: %s" %e)
|
||||
# tb.print_exc()
|
||||
|
||||
|
||||
class FrameConnection (QtGui.QScrollArea):
|
||||
def __init__(self, parent, ClientObj):
|
||||
self.ClientObj = ClientObj
|
||||
QtGui.QScrollArea.__init__(self)
|
||||
# верхнее правое
|
||||
connection = Conn(self.ClientObj)
|
||||
self.setWidget(connection)
|
||||
# self.resize(700,900)
|
@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PySide import QtGui, QtCore
|
||||
|
||||
class HelpWgt(QtGui.QWidget):
|
||||
def __init__(self, parent):
|
||||
QtGui.QWidget.__init__(self)
|
||||
|
||||
helpLabel = QtGui.QLabel('about calculate Inc.')
|
||||
helpQuit = QtGui.QPushButton("Quit")
|
||||
|
||||
layout = QtGui.QVBoxLayout()
|
||||
layout.addWidget(helpLabel)
|
||||
layout.addWidget(helpQuit)
|
||||
self.setLayout(layout)
|
||||
self.connect(helpQuit, QtCore.SIGNAL("clicked()"),
|
||||
self, QtCore.SLOT("close()"))
|
||||
|
||||
self.move(100+parent.frameGeometry().x(), \
|
||||
100+parent.frameGeometry().y())
|
||||
self.resize(200,200)
|
||||
# self.show()
|
@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PySide import QtGui
|
||||
|
||||
class MainMenu():
|
||||
def __init__(self, parent):
|
||||
exitAction = QtGui.QAction(QtGui.QIcon('image/Exit.png'), \
|
||||
'&Exit', parent)
|
||||
exitAction.setShortcut('Ctrl+Q')
|
||||
exitAction.setStatusTip('Exit application')
|
||||
exitAction.triggered.connect(parent.close)
|
||||
|
||||
toolAction = QtGui.QAction(QtGui.QIcon('image/tool.png'), \
|
||||
'&Tool', parent)
|
||||
toolAction.setShortcut('Ctrl+T')
|
||||
toolAction.setStatusTip('Tool application')
|
||||
toolAction.triggered.connect(parent.tools)
|
||||
|
||||
helpAction = QtGui.QAction(QtGui.QIcon('image/help.png'), \
|
||||
'&Help', parent)
|
||||
helpAction.setShortcut('Ctrl+H')
|
||||
helpAction.setStatusTip('Help')
|
||||
helpAction.triggered.connect(parent.help)
|
||||
|
||||
parent.toolbar = parent.addToolBar('Main')
|
||||
|
||||
parent.toolbar.addAction(toolAction)
|
||||
parent.toolbar.addAction(helpAction)
|
||||
parent.toolbar.addAction(exitAction)
|
||||
|
||||
# menubar = parent.menuBar()
|
||||
# fileMenu = menubar.addMenu('&File')
|
||||
# fileMenu.addAction(exitAction)
|
@ -0,0 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from PySide import QtGui
|
||||
|
||||
class ToolsWidget (QtGui.QWidget):
|
||||
def __init__(self, parent):
|
||||
|
||||
QtGui.QWidget.__init__(self)
|
||||
helpLabel = QtGui.QLabel('about calculate Inc.')
|
||||
helpQuit = QtGui.QPushButton("Quit")
|
||||
|
||||
layout = QtGui.QVBoxLayout()
|
||||
layout.addWidget(helpLabel)
|
||||
layout.addWidget(helpQuit)
|
||||
self.setLayout(layout)
|
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 2.4 KiB |
@ -1,16 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PySide import QtGui
|
||||
|
||||
class MainMenu():
|
||||
def __init__(self, parent):
|
||||
exitAction = QtGui.QAction(QtGui.QIcon('image/Exit.png'), '&Exit', parent)
|
||||
exitAction.setShortcut('Ctrl+Q')
|
||||
exitAction.setStatusTip('Exit application')
|
||||
exitAction.triggered.connect(parent.close)
|
||||
|
||||
parent.toolbar = parent.addToolBar('Exit')
|
||||
parent.toolbar.addAction(exitAction)
|
||||
# menubar = parent.menuBar()
|
||||
# fileMenu = menubar.addMenu('&File')
|
||||
# fileMenu.addAction(exitAction)
|
@ -0,0 +1,216 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PySide import QtGui, QtCore
|
||||
import os, time, sys
|
||||
|
||||
from calculate.api.client.cert_func import client_post_auth
|
||||
from calculate.api.cl_api import DataVarsApi
|
||||
from calculate.api.client.pid_information import client_list_methods, \
|
||||
client_list_pid
|
||||
from calculate.api.client.function import get_entire_frame, create_obj, \
|
||||
get_sid, analysis
|
||||
from calculate.api.client.sid_func import client_del_sid
|
||||
|
||||
def _(s):
|
||||
return s
|
||||
|
||||
def show_msg(text):
|
||||
msgBox = QtGui.QMessageBox()
|
||||
msgBox.setText(text)
|
||||
msgBox.setStandardButtons(QtGui.QMessageBox.Ok)
|
||||
msgBox.exec_()
|
||||
|
||||
def client_signal(client):
|
||||
Vars = DataVarsApi()
|
||||
Vars.importApi()
|
||||
Vars.flIniFile()
|
||||
try:
|
||||
client_active = Vars.Get('cl_api_client_active_period')
|
||||
except:
|
||||
client_active = 15
|
||||
while True:
|
||||
if os.path.exists(client.SID_FILE) :
|
||||
fi = open(client.SID_FILE, 'r')
|
||||
temp = fi.read()
|
||||
fi.close()
|
||||
sid = int(temp)
|
||||
else:
|
||||
sid = 0
|
||||
try:
|
||||
reply = client.service.active_client(sid)
|
||||
except:
|
||||
print _('no connection to server!')
|
||||
sys.exit()
|
||||
print 1111111111
|
||||
time.sleep(float(client_active))
|
||||
|
||||
def https_server(client, signaling):
|
||||
global url
|
||||
client_post_auth(client)
|
||||
signaling.start()
|
||||
client_list_methods(client)
|
||||
|
||||
get_entire_frame(client)
|
||||
#create_obj(client, "install_system")
|
||||
|
||||
show_msg("Connection OK!")
|
||||
|
||||
# while True:
|
||||
# try:
|
||||
# command = raw_input ("\nCommand: ")
|
||||
# except KeyboardInterrupt, e:
|
||||
# print
|
||||
# sys.exit()
|
||||
# if (command == 'halt' or command == 'server_shutdown'):
|
||||
# client_shut(client)
|
||||
#
|
||||
# #elif (command == 'say_hello' or command == 'say'):
|
||||
# #client_say_hello(client)
|
||||
#
|
||||
# #elif (command == 'say_hello2' or command == 'say2'):
|
||||
# #client_say_hello2(client)
|
||||
#
|
||||
# elif (command == 'server_start' or command == 'run'):
|
||||
# if os.path.exists(client.CERT_KEY) and\
|
||||
# os.path.exists(client.CERT_FILE) :
|
||||
# client = Client_suds(url,\
|
||||
# transport = HTTPSClientCertTransport(client.CERT_KEY,\
|
||||
# client.CERT_FILE))
|
||||
# #If the certificate file misses
|
||||
# else:
|
||||
# CERT_FILE = None
|
||||
# CERT_KEY = None
|
||||
# client = Client_suds(url,\
|
||||
# transport = HTTPSClientCertTransport(CERT_KEY, CERT_FILE))
|
||||
#
|
||||
# elif (command == 'login' or command == 'cl-login'):
|
||||
# client_login(client)
|
||||
#
|
||||
# elif (command == 'useradd' or command == 'cl-unix-useradd'):
|
||||
# client_useradd(client)
|
||||
#
|
||||
# elif (command == 'sid-del' or command == 'del-sid'):
|
||||
# client_del_sid(client)
|
||||
#
|
||||
# elif (command == 'lsp' or command == 'list-pid'):
|
||||
# client_list_pid(client)
|
||||
#
|
||||
# elif (command == 'ins' or command == 'install'):
|
||||
# client_install(client)
|
||||
#
|
||||
# elif (command == 'lsr' or command == 'list-method'\
|
||||
# or command == 'list-right'):
|
||||
# client_list_methods(client)
|
||||
#
|
||||
# elif (command == 'lss' or command == 'list-session'\
|
||||
# or command == 'sls'):
|
||||
# client_list_sessions(client)
|
||||
#
|
||||
# elif (command == 'pi' or command == 'pid-info'):
|
||||
# client_pid_info(client)
|
||||
#
|
||||
# elif (command == 'si' or command == 'session-info'):
|
||||
# client_session_info(client)
|
||||
#
|
||||
# elif (command == 'kill' or command == 'pid-kill'):
|
||||
# client_pid_kill(client)
|
||||
#
|
||||
# elif (command == 'userdel' or command == 'cl-unix-userdel'):
|
||||
# client_userdel(client)
|
||||
#
|
||||
# elif (command == 'vcr' or command == 'view-cert-right'):
|
||||
# client_view_cert_right(client)
|
||||
#
|
||||
# elif command.split(' ',1)[0] in ['t', 'template', 'cl-template']:
|
||||
# #client_template(client, command)
|
||||
# test(client, 'cl_template')
|
||||
#
|
||||
# elif command.lower() in ['test']:
|
||||
# test(client)
|
||||
#
|
||||
# elif (command == 'help' or command == 'h'):
|
||||
# print help_
|
||||
#
|
||||
# elif command in ['q', 'quit', 'exit']:
|
||||
# print _("Closing\n")
|
||||
# signaling._Thread__stop()
|
||||
# time.sleep(0.3)
|
||||
# num = client_list_pid(client)
|
||||
# if num:
|
||||
# print _('at closing session, '
|
||||
# 'data %d processes will be deleted!' %num)
|
||||
# c = raw_input (_("Close your session y/[n]: "))
|
||||
# if c in ['y', 'yes', 'Y', 'YES']:
|
||||
# client_del_sid(client)
|
||||
# #signaling.killed = True
|
||||
## client_shut(client)
|
||||
# return 0
|
||||
# else:
|
||||
# print _("Input Error")
|
||||
|
||||
def test(client, com=None):
|
||||
if not com:
|
||||
method_name = 'test'
|
||||
else:
|
||||
method_name = com
|
||||
view = client.service[0][method_name + '_view']()
|
||||
#print '==>', view
|
||||
|
||||
cr = create_obj(client, method_name)
|
||||
#print 'ddd',cr
|
||||
#print type (cr)
|
||||
list_param = dir (cr)
|
||||
|
||||
param_list = []
|
||||
for param in list_param:
|
||||
if not param.startswith('_'):
|
||||
param_list.append(param)
|
||||
|
||||
for Group in view.groups.GroupField:
|
||||
print "GroupField name : ", Group.name
|
||||
|
||||
for field in Group.fields.Field:
|
||||
if field.element == 'input':
|
||||
if field.type == 'str':
|
||||
cr[field.name] = raw_input(field.label)
|
||||
if field.type == 'int':
|
||||
while True:
|
||||
try:
|
||||
var = raw_input(field.label)
|
||||
cr[field.name] = int (var)
|
||||
break
|
||||
except (TypeError, ValueError):
|
||||
print _('Это не целое число')
|
||||
elif field.element == 'bool':
|
||||
while 1:
|
||||
bool_var = raw_input(field.label+' (y/n): ')
|
||||
if bool_var.lower() in ['y','yes']:
|
||||
cr[field.name] = True
|
||||
break
|
||||
if bool_var.lower() in ['n','no']:
|
||||
cr[field.name] = False
|
||||
break
|
||||
print _('Enter "Yes" or "No"!')
|
||||
|
||||
elif field.element == 'check':
|
||||
choice = field.choice[0]
|
||||
while 1:
|
||||
print _('Select one: ')
|
||||
for i in range(1,len(choice)+1):
|
||||
print choice[i-1], ' - %d' %i
|
||||
try:
|
||||
bool_var = int (raw_input(field.label))
|
||||
if bool_var > 0:
|
||||
cr[field.name] = choice[bool_var - 1]
|
||||
print 'your choice %s' %cr[field.name]
|
||||
break
|
||||
except:
|
||||
pass
|
||||
|
||||
#field.choice
|
||||
#print field.help
|
||||
|
||||
sid = get_sid(client.SID_FILE)
|
||||
s = client.service[0][method_name](sid, cr)
|
||||
analysis(client, sid, s)
|
Loading…
Reference in new issue