@ -20,12 +20,16 @@ from sudsds.transport import TransportError
from client_class import Client_suds
import traceback as tb
import time , logging
import os , sys
import threading , urllib2
import time
import logging
import os
import sys
import threading
import urllib2
from pid_information import client_list_methods
from cert_func import client_post_auth , client_post_request , client_get_cert , \
client_post_cert , get_password_from_daemon , clear_password
from cert_func import ( client_post_auth , client_post_request , client_get_cert ,
client_post_cert , get_password_from_daemon ,
clear_password )
from sid_func import session_clean , client_session_info , client_session_list
from cert_verify import get_CRL , VerifyError
@ -33,10 +37,12 @@ import M2Crypto, OpenSSL
from calculate . core . datavars import DataVarsCore
from client_class import HTTPSClientCertTransport
from methods_func import call_method , get_method_argparser , parse , get_view
from function import MessageReceiver , MessageDispatcher , clear , _print , \
get_view_params
from function import ( MessageReceiver , MessageDispatcher , clear , _print ,
get_view_params )
from calculate . lib . utils . files import makeDirectory , readLinesFile
from calculate . lib . cl_lang import setLocalTranslate
_ = lambda x : x
setLocalTranslate ( ' cl_console3 ' , sys . modules [ __name__ ] )
@ -48,6 +54,7 @@ def get_entire_message_receiver(client, pid):
return MessageReceiver . from_entire ( client , pid ,
MessageDispatcher ( Methods ( ) ) , Display ( ) )
def client_signal ( client ) :
Vars = DataVarsCore ( )
Vars . importCore ( )
@ -71,6 +78,7 @@ def client_signal(client):
raise Exception ( 1 )
time . sleep ( float ( client_active ) )
class StoppableThread ( threading . Thread ) :
def __init__ ( self ) :
super ( StoppableThread , self ) . __init__ ( )
@ -80,7 +88,6 @@ class StoppableThread(threading.Thread):
def run ( self ) :
l = [ ' | ' , ' / ' , ' - ' , ' \\ ' , ' | ' , ' / ' , ' - ' , ' \\ ' ]
i = 0
while True :
for i in l :
sys . stdout . write ( " \r \r " + i )
@ -93,7 +100,6 @@ class StoppableThread(threading.Thread):
sys . stdout . flush ( )
return 0
def pause ( self ) :
self . _pause . set ( )
while not self . _paused . is_set ( ) :
@ -113,6 +119,7 @@ class StoppableThread(threading.Thread):
def paused ( self ) :
return self . _pause . isSet ( )
def connect_with_cert ( cert , path_to_cert , url , args , wait_thread , clVarsCore ,
crypto_Error , Connect_Error ) :
flag_thread_start = False
@ -121,23 +128,22 @@ def connect_with_cert(cert, path_to_cert, url, args, wait_thread, clVarsCore,
CERT_KEY = os . path . join ( path_to_cert , cert_name + ' .key ' )
if not os . path . isfile ( CERT_FILE ) or not os . path . isfile ( CERT_KEY ) :
Connect_Error = 1
return ( None , 1 , crypto_Error , False , None )
return None , 1 , crypto_Error , False , None
client = None
bio = M2Crypto . BIO . openfile ( CERT_KEY )
rsa = M2Crypto . m2 . rsa_read_key ( bio . _ptr ( ) , lambda * unused : None )
store_passwd = None
if not rsa :
port = args . port or clVarsCore . Get ( ' core.cl_core_port ' )
store_passwd = get_password_from_daemon ( args . host , args . port ,
wait_thread )
if ' store_passwd ' in locals ( ) :
store_passwd = get_password_from_daemon ( args . host , port , wait_thread )
key_passwd = store_passwd
else :
key_passwd = None
er = None
try :
ca_certs = os . path . join ( path_to_cert , ' ca/ca_root.crt ' )
client = Client_suds ( url , transport = HTTPSClientCertTransport \
( CERT_KEY , CERT_FILE , path_to_cert , password = key_passwd ,
client = Client_suds (
url , transport = HTTPSClientCertTransport (
CERT_KEY , CERT_FILE , path_to_cert , password = key_passwd ,
ca_certs = ca_certs , wait_thread = wait_thread ) )
if not wait_thread . isAlive ( ) :
wait_thread = StoppableThread ( )
@ -150,12 +156,16 @@ def connect_with_cert(cert, path_to_cert, url, args, wait_thread, clVarsCore,
Connect_Error = 0
except VerifyError , e :
Connect_Error = 1
er = e
except OpenSSL . crypto . Error , e :
Connect_Error = 1
crypto_Error = 1
er = e
except urllib2 . URLError , e :
Connect_Error = 1
except Exception , e :
er = e
except Exception as e :
er = e
if e . message == 3 :
wait_thread . stop ( )
sys . exit ( 1 )
@ -163,8 +173,8 @@ def connect_with_cert(cert, path_to_cert, url, args, wait_thread, clVarsCore,
if flag_thread_start :
wait_thread . stop ( )
return ( client , Connect_Error , crypto_Error ,
True if ' store_passwd ' in locals ( ) else False ,
e if ' e ' in locals ( ) else None )
True if store_passwd is not None else False , er )
def get_server_hostname ( host , path_to_cert ) :
compliance_file = os . path . join ( path_to_cert , ' compliance_server_names ' )
@ -177,6 +187,7 @@ def get_server_hostname(host, path_to_cert):
return server_hostname
return None
def add_server_hostname ( host , path_to_cert , server_hostname ) :
try :
compliance_file = os . path . join ( path_to_cert , ' compliance_server_names ' )
@ -202,23 +213,10 @@ def add_server_hostname(host, path_to_cert, server_hostname):
print e
return False
def https_server ( client , args , unknown_args , url , clVarsCore , wait_thread ) :
client_post_auth ( client )
# sym_link = os.path.basename(sys.argv[0])
# if sym_link != 'cl-console':
# wait_thread.stop()
# results = client.service.get_methods(client.sid, 'console')
# find_flag = False
# if hasattr (results, 'stringArray'):
# for _array in results.stringArray:
# if _array.string[0] == sym_link:
# args.method = _array.string[1]
# find_flag = True
# break
# if not find_flag:
# _print (_('Method not found for %s') %sym_link)
if args . stop_consoled :
wait_thread . stop ( )
os . system ( ' cl-consoled --stop ' )
@ -242,9 +240,11 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread):
wait_thread . stop ( )
if args . dump :
from pid_information import client_pid_info
client_pid_info ( client )
else :
from pid_information import client_list_pid
client_list_pid ( client )
return 0
@ -267,6 +267,7 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread):
if args . pid_kill :
wait_thread . stop ( )
from pid_information import client_pid_kill
return client_pid_kill ( client , args . pid_kill )
retCode = 0
@ -289,7 +290,8 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread):
_unknown_args = method_parser . fixBoolVariables ( unknown_args )
_args , _unknown_args = method_parser . parse_known_args ( _unknown_args )
_args , _unknown_args = method_parser . parse_known_args (
_unknown_args )
if dispatch_usenew == _args . no_questions :
method_parser . print_help ( )
@ -334,14 +336,15 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread):
pid = int ( mess . message )
except :
return 1
retCode = \
1 if int ( client . service . pid_info ( client . sid , pid ) [ 0 ] [ 1 ] ) else 0
retCode = 1 if int (
client . service . pid_info ( client . sid , pid ) [ 0 ] [ 1 ] ) else 0
if not args . keep_result :
client . service . clear_pid_cache ( client . sid , pid )
client . service . clear_method_cache ( client . sid , args . method )
wait_thread . stop ( )
return retCode
def main ( wait_thread ) :
parser = parse ( )
args , unknown_args = parser . parse_known_args ( )
@ -361,6 +364,7 @@ def main(wait_thread):
cl_wsdl = ob . Get ( ' cl_wsdl_available ' )
# создать симлинки на команды
from calculate . core . server . func import initialization
initialization ( cl_wsdl )
ob . close ( )
if sym_link in loaded_methods . LoadedMethods . conMethods . keys ( ) :
@ -432,12 +436,14 @@ def main(wait_thread):
clear ( )
serv_hostname = get_server_hostname ( host , path_to_cert )
get_name_flag = False
client = None
if serv_hostname :
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 )
wait_thread , clVarsCore , crypto_Error ,
Connect_Error )
if not wait_thread . isAlive ( ) :
wait_thread = StoppableThread ( )
wait_thread . start ( )
@ -457,11 +463,12 @@ def main(wait_thread):
get_name_flag = False
if get_name_flag :
if client :
try :
client . port = port
return_val = 1
try :
return_val = https_server ( client , args , unknown_args , url , \
return_val = https_server ( client , args , unknown_args , url ,
clVarsCore , wait_thread )
except urllib2 . URLError , e :
print _ ( ' Error: ' ) , e
@ -476,7 +483,6 @@ def main(wait_thread):
print e . message
elif e . args :
print e
# tb.print_exc()
return 1
wait_thread . stop ( )
return return_val
@ -494,14 +500,15 @@ def main(wait_thread):
tb . print_exc ( )
wait_thread . stop ( )
server_host_name = " "
try :
client = Client_suds ( url , \
transport = HTTPSClientCertTransport ( None , None , path_to_cert ) )
client = Client_suds (
url, transport= HTTPSClientCertTransport ( None , None , path_to_cert ) )
client . wsdl . services [ 0 ] . setlocation ( url )
server_host_name = client . service . get_server_host_name ( )
if not add_server_hostname ( host , path_to_cert , server_host_name ) :
print ' compliance_file write error! '
del ( client )
del client
except urllib2 . URLError , e :
wait_thread . stop ( )
print ' \b ' + _ ( ' Failed to connect ' ) + ' : ' , e
@ -513,6 +520,7 @@ def main(wait_thread):
try :
import glob
all_cert_list = glob . glob ( os . path . join ( path_to_cert , ' *.crt ' ) )
fit_cert_list = [ ]
for client_cert_path in all_cert_list :
@ -524,12 +532,14 @@ def main(wait_thread):
Connect_Error = 1
crypto_Error = 0
e = None
passwd_flag = False
for i in range ( 0 , len ( fit_cert_list ) ) :
cert_name = fit_cert_list . pop ( )
client , Connect_Error , crypto_Error , passwd_flag , e = \
connect_with_cert ( cert_name , path_to_cert , url , args ,
wait_thread , clVarsCore , crypto_Error , Connect_Error )
wait_thread , clVarsCore , crypto_Error ,
Connect_Error )
if not wait_thread . isAlive ( ) :
wait_thread = StoppableThread ( )
wait_thread . start ( )
@ -555,15 +565,16 @@ def main(wait_thread):
CERT_FILE = None
CERT_KEY = None
client = Client_suds ( url , transport = HTTPSClientCertTransport \
( CERT_KEY , CERT_FILE , path_to_cert ) )
client = Client_suds (
url , transport = HTTPSClientCertTransport ( CERT_KEY , CERT_FILE ,
path_to_cert ) )
client . wsdl . services [ 0 ] . setlocation ( url )
client . set_parameters ( path_to_cert , CERT_FILE , CERT_KEY )
client . port = port
return_val = 1
try :
return_val = https_server ( client , args , unknown_args , url , \
return_val = https_server ( client , args , unknown_args , url ,
clVarsCore , wait_thread )
except urllib2 . URLError , e :
print _ ( ' Error: ' ) , e