fix get lang, add key --session-num-info

master3.3
Спиридонов Денис 13 years ago
parent 07fe8cc11d
commit 77f4152ceb

@ -30,7 +30,7 @@ setLocalTranslate('calculate_console',sys.modules[__name__])
VERSION = 0.11
def client_post_cert (client, show_info = False):
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()
@ -43,7 +43,7 @@ def client_post_cert (client, show_info = False):
cert_id = client.service.cert_add(mac, client_type)
print _("Your certificate ID = %s") %cert_id
sys.exit(1)
client_sid(sid, client, cert_id = results[0][0])
client_sid(sid, client, cert_id = results[0][0], clVars = clVars)
if results[0][0] == -3:
print _("Certificate not send!")
else:

@ -170,6 +170,10 @@ def parse():
parser.add_argument(
'--session-info', action='store_true', default=False,
dest='session_info', help=_("view session information"))
parser.add_argument(
'--session-num-info', type=int, metavar = 'SID',
dest='session_num_info', help=_("view information about session "
"with sid = SID"))
parser.add_argument(
'--session-list', action='store_true', default=False,
dest='session_list', help=_("view list active session on server"))
@ -184,8 +188,8 @@ def https_server(client, args, unknown_args, url, clVarsCore):
if args.session_clean:
session_clean(client)
if args.session_info:
client_session_info(client)
if args.session_info or args.session_num_info:
client_session_info(client, args.session_num_info)
if args.session_list:
client_session_list(client)
@ -342,7 +346,7 @@ def main():
transport = HTTPSClientCertTransport(CERT_KEY, CERT_FILE,\
path_to_cert, password=store_passwd))
client.set_parameters (path_to_cert, CERT_FILE, CERT_KEY)
client_post_cert(client)
client_post_cert(client, clVarsCore)
Connect_Error = 0
except VerifyError, e:
# print e.value

@ -216,72 +216,6 @@ class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
else:
print _("Certificate not added to trusted")
sys.exit()
#def add_ca_cert(self, cert, list_ca_certs, prev_host = None):
#certobj = OpenSSL.crypto.load_certificate \
#(OpenSSL.SSL.FILETYPE_PEM, cert)
#Issuer = certobj.get_issuer().get_components()
#for item in Issuer:
#if item[0] == 'L':
#print '\nNetwork adress : ', item[1]
#current_host = item[1]
##print prev_host, item[1]
#try:
#host, port = item[1].split(':')
#port = int(port)
#except:
#print _("Network adress must be host:port. port must be int")
#return 1
#try:
#ca_cert = ssl.get_server_certificate(addr = (host, port))
#except:
#print _("Connection aborted!")
#sys.exit()
#certobj = OpenSSL.crypto.load_certificate \
#(OpenSSL.SSL.FILETYPE_PEM, ca_cert)
#print _("\nFingerprint = %s") % certobj.digest('SHA1')
#print _("Serial Number = "), certobj.get_serial_number()
#Issuer = certobj.get_issuer().get_components()
#print _("\nIssuer")
#for i in Issuer:
#print "%s : %s" %(i[0], i[1])
#Subject = certobj.get_subject().get_components()
#print _("\nSubject")
#for subj in Subject:
#print "%s : %s" %(subj[0], subj[1])
#if prev_host == item[1]:
#'''
#получить корневой сертификат и проверить его на рутовость
#'''
#print _("\nThis is root certificate!")
#print _("Add all CA certificates to trusted?\n"
#"ATTENTION! It allows access to all those who "
#"signed these certificates.\n"
#"This may affect your safety!")
#ans = raw_input (_("Add all CA certificates to trusted? "
#"y/[n]:"))
#if ans.lower() in ['y','yes']:
#self.add_all_ca_cert(list_ca_certs)
#else:
#print _("Certificate not added to trusted")
#sys.exit()
#ans = raw_input (_("\nNext? y/[n]: "))
#if not ans.lower() in ['y','yes']:
#print _("Exit")
#sys.exit()
#list_ca_certs.append(ca_cert)
#self.add_ca_cert(cert, self.list_ca_certs, current_host)
#print _("In this certificate not found field 'L' (Network adress)")
# add certificate server in trusted
def add_server_cert(self, cert):
@ -421,7 +355,6 @@ class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
add['certfile'] = self.cert_file
else:
wrap_class = ssl.SSLSocket
# print 'HHHHHHHHHHHHHHHHHHHHHH'
self.sock = wrap_class(sock, ca_certs=self.ca_certs, **add)
return 0

@ -19,10 +19,10 @@ 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, show_info = False):
def client_sid(sid, client, cert_id, clVars, show_info = False):
""" get number session from server and write this in file """
#lang = raw_input ("Enter language (ru, en, de, fr): ")
lang = "ru"
lang = clVars.Get('os_locale_locale')[: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])
@ -39,7 +39,7 @@ def client_del_sid(client):
sid = get_sid(client.SID_FILE)
try:
s = client.service.del_sid(sid)
if s[0][0] == "-1":
print _("No access to file!")
return -1
@ -49,7 +49,7 @@ def client_del_sid(client):
if s[0][0] == "Permission denied":
print _("Permission denied %s") % s[1][1]
return -3
if s[0][0] == '0':
fi = open(client.SID_FILE, 'w')
fi.write('0')
@ -83,10 +83,11 @@ def sid_inf(client, sid):
print green + "MAC - %s\n" %s[0][3]
return 0
def client_session_info(client):
def client_session_info(client, sid = None):
""" select session for get information """
try:
sid_inf(client, client.sid)
select_sid = sid if sid else client.sid
sid_inf(client, select_sid)
except Exception, e:
print e
return 1

Loading…
Cancel
Save