From 6a9fcb9ff0b901b241653abc23116a10bafbd0da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BF=D0=B8=D1=80=D0=B8=D0=B4=D0=BE=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81?= Date: Fri, 15 Jun 2012 13:54:12 +0400 Subject: [PATCH] union methods, time optimization --- console/application/cert_func.py | 34 ++++++++++++++++++++++---------- console/application/cl_client.py | 20 +++---------------- console/application/sid_func.py | 28 +++++++++++++------------- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/console/application/cert_func.py b/console/application/cert_func.py index 84334a1..994aa9d 100644 --- a/console/application/cert_func.py +++ b/console/application/cert_func.py @@ -18,7 +18,6 @@ import os, pwd import sys, subprocess import socket, time import urllib2 -from sid_func import client_sid from function import get_sid, get_ip_mac_type import OpenSSL, hashlib 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.files import listDirectory setLocalTranslate('calculate_console',sys.modules[__name__]) - VERSION = 0.11 def client_post_cert (client, clVars, show_info = False): """ send a certificate server for check """ 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 _('Add certificate to server Database...') 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) print _("Your certificate ID = %s") %cert_id 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!") else: if show_info: - print _(" Your certifitate id = %d") %(results[0][0]) + print _(" Your certifitate id = %d") %(result_post_cert[0]) try: - if results[0][1] == -2: + if result_post_cert[1] == -2: print _("expiry date certificate has passed") - elif results[0][1] > 0: + elif result_post_cert[1] > 0: if show_info: print _("shelf life expires after %d days") \ - %(results[0][1]) + %(result_post_cert[1]) except: 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 def new_key_req(key, cert_path, server_host_name, private_key_passwd = None, \ auto = False): diff --git a/console/application/cl_client.py b/console/application/cl_client.py index cb811fd..6c95554 100644 --- a/console/application/cl_client.py +++ b/console/application/cl_client.py @@ -21,7 +21,7 @@ from sudsds.transport import TransportError from client_class import Client_suds import traceback as tb import time, logging -import os, sys, datetime +import os, sys import threading, urllib2 from function import analysis, clear, get_entire_frame from pid_information import client_list_methods @@ -121,15 +121,11 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread): return 1 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) wait_thread.stop() sys.stdout.write("\b") sys.stdout.flush() method_parser.print_help() -# now = datetime.datetime.now() -# print '7 ===> %ds %dms' %(now.second, now.microsecond) else: try: @@ -276,8 +272,6 @@ def add_server_hostname(host, path_to_cert, server_hostname): return False def main(): -# now = datetime.datetime.now() -# print '1 ===> %ds %dms' %(now.second, now.microsecond) parser = parse() args, unknown_args = parser.parse_known_args() wait_thread = StoppableThread() @@ -287,8 +281,6 @@ def main(): sys.stdout.write('\r') sys.stdout.flush() parser.print_help() -# now = datetime.datetime.now() -# print '1/2 ===> %ds %dms' %(now.second, now.microsecond) return 0 if os.path.basename(sys.argv[0]) != 'cl-console': @@ -358,8 +350,8 @@ def main(): Connect_Error = 1 crypto_Error = 0 client, Connect_Error, crypto_Error, passwd_flag, e = \ - connect_with_cert (serv_hostname, path_to_cert, url, args, - wait_thread, clVarsCore, crypto_Error, Connect_Error) + connect_with_cert (serv_hostname, path_to_cert, url, args, + wait_thread, clVarsCore, crypto_Error, Connect_Error) get_name_flag = True if Connect_Error: if crypto_Error and passwd_flag: @@ -429,8 +421,6 @@ def main(): fit_cert_list.sort(key = len) Connect_Error = 1 crypto_Error = 0 -# now = datetime.datetime.now() -# print '3 ===> %ds %dms' %(now.second, now.microsecond) for i in range (0, len(fit_cert_list)): cert_name = fit_cert_list.pop() 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.port = port -# now = datetime.datetime.now() -# print '5 ===> %ds %dms' %(now.second, now.microsecond) return_val = 1 try: return_val = https_server(client, args, unknown_args, url, \ @@ -477,8 +465,6 @@ def main(): else: print e return 1 -# now = datetime.datetime.now() -# print 'END ===> %ds %dms' %(now.second, now.microsecond) wait_thread.stop() return return_val #---------------------------------------------------- diff --git a/console/application/sid_func.py b/console/application/sid_func.py index 787c4ac..00f9096 100644 --- a/console/application/sid_func.py +++ b/console/application/sid_func.py @@ -19,20 +19,20 @@ from function import get_sid from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('calculate_console',sys.modules[__name__]) -def client_sid(sid, client, cert_id, clVars, show_info = False): - """ get number session from server and write this in file """ - lang = os.environ['LANG'][:2] - - 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 show_info: - if new_sid[0][1] == 1: - print _(" New Session") - else: print _(" Old Session") - print _(" Your session id = %s") %sid +#def client_sid(sid, client, cert_id, clVars, show_info = False): +# """ get number session from server and write this in file """ +# lang = os.environ['LANG'][:2] +# +# 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 show_info: +# if new_sid[0][1] == 1: +# print _(" New Session") +# else: print _(" Old Session") +# print _(" Your session id = %s") %sid def client_del_sid(client): """ delete this session """