union methods, time optimization

develop
Спиридонов Денис 12 years ago
parent 11b51a83a7
commit 6a9fcb9ff0

@ -18,7 +18,6 @@ import os, pwd
import sys, subprocess import sys, subprocess
import socket, time import socket, time
import urllib2 import urllib2
from sid_func import client_sid
from function import get_sid, get_ip_mac_type from function import get_sid, get_ip_mac_type
import OpenSSL, hashlib import OpenSSL, hashlib
from client_class import HTTPSClientCertTransport from client_class import HTTPSClientCertTransport
@ -28,15 +27,18 @@ from calculate.lib.cl_lang import setLocalTranslate
from calculate.lib.utils.common import getpass from calculate.lib.utils.common import getpass
from calculate.lib.utils.files import listDirectory from calculate.lib.utils.files import listDirectory
setLocalTranslate('calculate_console',sys.modules[__name__]) setLocalTranslate('calculate_console',sys.modules[__name__])
VERSION = 0.11 VERSION = 0.11
def client_post_cert (client, clVars, show_info = False): def client_post_cert (client, clVars, show_info = False):
""" send a certificate server for check """ """ send a certificate server for check """
sid = get_sid(client.SID_FILE) sid = get_sid(client.SID_FILE)
results = client.service.post_cert()
if results[0][0] == -4: lang = os.environ['LANG'][:2]
_result_post_cert, _result_sid = client.service.init_session(sid, lang)
result_post_cert = _result_post_cert[1].integer
result_sid = _result_sid[1].integer
if result_post_cert[0] == -4:
print _("Certificate not found in Server Database!") print _("Certificate not found in Server Database!")
print _('Add certificate to server Database...') print _('Add certificate to server Database...')
ip, mac, client_type = get_ip_mac_type() ip, mac, client_type = get_ip_mac_type()
@ -44,22 +46,34 @@ def client_post_cert (client, clVars, show_info = False):
cert_id = client.service.cert_add(mac, client_type) cert_id = client.service.cert_add(mac, client_type)
print _("Your certificate ID = %s") %cert_id print _("Your certificate ID = %s") %cert_id
raise Exception(1) raise Exception(1)
client_sid(sid, client, cert_id = results[0][0], clVars = clVars)
if results[0][0] == -3: # client_sid(sid, client, cert_id = results[0][0], clVars = clVars)
if result_post_cert[0] == -3:
print _("Certificate not send!") print _("Certificate not send!")
else: else:
if show_info: if show_info:
print _(" Your certifitate id = %d") %(results[0][0]) print _(" Your certifitate id = %d") %(result_post_cert[0])
try: try:
if results[0][1] == -2: if result_post_cert[1] == -2:
print _("expiry date certificate has passed") print _("expiry date certificate has passed")
elif results[0][1] > 0: elif result_post_cert[1] > 0:
if show_info: if show_info:
print _("shelf life expires after %d days") \ print _("shelf life expires after %d days") \
%(results[0][1]) %(result_post_cert[1])
except: except:
pass pass
# work with sid
fi = open(client.SID_FILE, 'w')
sid = str(result_sid[0])
fi.write(sid)
fi.close()
if show_info:
if result_sid[1] == 1:
print _(" New Session")
else: print _(" Old Session")
print _(" Your session id = %s") %sid
#Creation of secret key of the client #Creation of secret key of the client
def new_key_req(key, cert_path, server_host_name, private_key_passwd = None, \ def new_key_req(key, cert_path, server_host_name, private_key_passwd = None, \
auto = False): auto = False):

@ -21,7 +21,7 @@ from sudsds.transport import TransportError
from client_class import Client_suds from client_class import Client_suds
import traceback as tb import traceback as tb
import time, logging import time, logging
import os, sys, datetime import os, sys
import threading, urllib2 import threading, urllib2
from function import analysis, clear, get_entire_frame from function import analysis, clear, get_entire_frame
from pid_information import client_list_methods from pid_information import client_list_methods
@ -121,15 +121,11 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread):
return 1 return 1
elif args.method and args.help: elif args.method and args.help:
# now = datetime.datetime.now()
# print '6 ===> %ds %dms' %(now.second, now.microsecond)
method_parser, view = get_method_argparser(client, args) method_parser, view = get_method_argparser(client, args)
wait_thread.stop() wait_thread.stop()
sys.stdout.write("\b") sys.stdout.write("\b")
sys.stdout.flush() sys.stdout.flush()
method_parser.print_help() method_parser.print_help()
# now = datetime.datetime.now()
# print '7 ===> %ds %dms' %(now.second, now.microsecond)
else: else:
try: try:
@ -276,8 +272,6 @@ def add_server_hostname(host, path_to_cert, server_hostname):
return False return False
def main(): def main():
# now = datetime.datetime.now()
# print '1 ===> %ds %dms' %(now.second, now.microsecond)
parser = parse() parser = parse()
args, unknown_args = parser.parse_known_args() args, unknown_args = parser.parse_known_args()
wait_thread = StoppableThread() wait_thread = StoppableThread()
@ -287,8 +281,6 @@ def main():
sys.stdout.write('\r') sys.stdout.write('\r')
sys.stdout.flush() sys.stdout.flush()
parser.print_help() parser.print_help()
# now = datetime.datetime.now()
# print '1/2 ===> %ds %dms' %(now.second, now.microsecond)
return 0 return 0
if os.path.basename(sys.argv[0]) != 'cl-console': if os.path.basename(sys.argv[0]) != 'cl-console':
@ -358,8 +350,8 @@ def main():
Connect_Error = 1 Connect_Error = 1
crypto_Error = 0 crypto_Error = 0
client, Connect_Error, crypto_Error, passwd_flag, e = \ client, Connect_Error, crypto_Error, passwd_flag, e = \
connect_with_cert (serv_hostname, path_to_cert, url, args, connect_with_cert (serv_hostname, path_to_cert, url, args,
wait_thread, clVarsCore, crypto_Error, Connect_Error) wait_thread, clVarsCore, crypto_Error, Connect_Error)
get_name_flag = True get_name_flag = True
if Connect_Error: if Connect_Error:
if crypto_Error and passwd_flag: if crypto_Error and passwd_flag:
@ -429,8 +421,6 @@ def main():
fit_cert_list.sort(key = len) fit_cert_list.sort(key = len)
Connect_Error = 1 Connect_Error = 1
crypto_Error = 0 crypto_Error = 0
# now = datetime.datetime.now()
# print '3 ===> %ds %dms' %(now.second, now.microsecond)
for i in range (0, len(fit_cert_list)): for i in range (0, len(fit_cert_list)):
cert_name = fit_cert_list.pop() cert_name = fit_cert_list.pop()
client, Connect_Error, crypto_Error, passwd_flag, e = \ client, Connect_Error, crypto_Error, passwd_flag, e = \
@ -461,8 +451,6 @@ def main():
client.set_parameters (path_to_cert, CERT_FILE, CERT_KEY) client.set_parameters (path_to_cert, CERT_FILE, CERT_KEY)
client.port = port client.port = port
# now = datetime.datetime.now()
# print '5 ===> %ds %dms' %(now.second, now.microsecond)
return_val = 1 return_val = 1
try: try:
return_val = https_server(client, args, unknown_args, url, \ return_val = https_server(client, args, unknown_args, url, \
@ -477,8 +465,6 @@ def main():
else: else:
print e print e
return 1 return 1
# now = datetime.datetime.now()
# print 'END ===> %ds %dms' %(now.second, now.microsecond)
wait_thread.stop() wait_thread.stop()
return return_val return return_val
#---------------------------------------------------- #----------------------------------------------------

@ -19,20 +19,20 @@ from function import get_sid
from calculate.lib.cl_lang import setLocalTranslate from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('calculate_console',sys.modules[__name__]) setLocalTranslate('calculate_console',sys.modules[__name__])
def client_sid(sid, client, cert_id, clVars, show_info = False): #def client_sid(sid, client, cert_id, clVars, show_info = False):
""" get number session from server and write this in file """ # """ get number session from server and write this in file """
lang = os.environ['LANG'][:2] # lang = os.environ['LANG'][:2]
#
new_sid = client.service.post_sid(sid=sid, cert_id=cert_id, lang=lang) # new_sid = client.service.post_sid(sid=sid, cert_id=cert_id, lang=lang)
fi = open(client.SID_FILE, 'w') # fi = open(client.SID_FILE, 'w')
sid = str(new_sid[0][0]) # sid = str(new_sid[0][0])
fi.write(sid) # fi.write(sid)
fi.close() # fi.close()
if show_info: # if show_info:
if new_sid[0][1] == 1: # if new_sid[0][1] == 1:
print _(" New Session") # print _(" New Session")
else: print _(" Old Session") # else: print _(" Old Session")
print _(" Your session id = %s") %sid # print _(" Your session id = %s") %sid
def client_del_sid(client): def client_del_sid(client):
""" delete this session """ """ delete this session """

Loading…
Cancel
Save