Общие сессии для cl-console-gui и cl-console

master-3.5 3.5.0_alpha5
parent c193eee22b
commit afee23a4c8

@ -23,7 +23,6 @@ import time
import urllib2
from calculate.console.application.function import _print
from function import get_ip_mac_type
from calculate.console.application.sid_func import get_sid
import OpenSSL
import hashlib
from client_class import HTTPSClientCertTransport
@ -41,7 +40,7 @@ VERSION = 0.11
def client_post_cert(client, clVars, show_info=False):
""" send a certificate server for check """
sid = get_sid(client.SID_FILE)
sid = client.get_sid()
lang = os.environ['LANG'][:2]
_result_post_cert, _result_sid = client.service.init_session(sid, lang)
@ -72,16 +71,14 @@ def client_post_cert(client, clVars, show_info=False):
print _("The certificate has expired")
elif result_post_cert[1] > 0:
if show_info:
print _("The certificate expires after %d days") \
% (result_post_cert[1])
print _("The certificate expires after %d days") % (
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()
client.write_sid(result_sid[0])
if show_info:
if result_sid[1] == 1:
print _(" New Session")
@ -337,7 +334,7 @@ def client_get_cert(cert_path, args):
def client_post_auth(client):
""" authorization client or post request """
sid = get_sid(client.SID_FILE)
sid = client.get_sid()
client.sid = int(sid)
try:
if os.path.exists(client.CERT_FILE):

@ -161,7 +161,7 @@ def get_CRL(path_to_cert):
url, transport=HTTPSClientCertTransport(None, None,
path_to_cert))
client.set_parameters(path_to_cert, None, None)
client.set_parameters(path_to_cert, None, None, None)
new_crl = client.service.get_crl()
except VerifyError, e:
_print(e.value)

@ -33,7 +33,8 @@ from cert_func import (client_post_auth, client_post_request, client_get_cert,
from sid_func import session_clean, client_session_info, client_session_list
from cert_verify import get_CRL, VerifyError
import M2Crypto, OpenSSL
import M2Crypto
import OpenSSL
from calculate.core.datavars import DataVarsCore
from client_class import HTTPSClientCertTransport
from methods_func import call_method, get_method_argparser, parse, get_view
@ -64,13 +65,7 @@ def client_signal(client):
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
sid = int(client.get_sid())
try:
client.service.active_client(sid)
except:
@ -150,7 +145,7 @@ def connect_with_cert(cert, path_to_cert, url, args, wait_thread, clVarsCore,
flag_thread_start = True
wait_thread.start()
client.wsdl.services[0].setlocation(url)
client.set_parameters(path_to_cert, CERT_FILE, CERT_KEY)
client.set_parameters(path_to_cert, CERT_FILE, CERT_KEY, args.host)
wait_thread.stop()
client_post_cert(client, clVarsCore)
Connect_Error = 0
@ -236,16 +231,10 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread):
client_session_list(client)
return 0
if args.list_pid:
if args.pid_res == "list":
from pid_information import client_pid_info
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)
client_pid_info(client, wait_thread)
return 0
try:
@ -255,11 +244,14 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread):
if args.pid_res:
wait_thread.stop()
mr = get_entire_message_receiver(client, args.pid_res)
if not args.pid_res.isdigit():
print _("Wrong PID")
return 1
mr = get_entire_message_receiver(client, int(args.pid_res))
if mr:
mr.get_messages()
if not args.keep_result:
client.service.clear_pid_cache(client.sid, args.pid_res)
client.service.clear_pid_cache(client.sid, int(args.pid_res))
return 0
else:
return 1
@ -569,7 +561,7 @@ def main(wait_thread):
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.set_parameters(path_to_cert, CERT_FILE, CERT_KEY, args.host)
client.port = port
return_val = 1

@ -39,6 +39,7 @@ from cookielib import CookieJar, DefaultCookiePolicy
from logging import getLogger
from calculate.console.datavars import DataVarsConsole
from calculate.lib.cl_lang import setLocalTranslate
from calculate.console.application.sid_func import SessionId
_ = lambda x: x
setLocalTranslate('cl_console3', sys.modules[__name__])
@ -46,20 +47,23 @@ log = getLogger(__name__)
flag = 0
class Client_suds(Client):
def set_parameters(self, path_to_cert, CERT_FILE, PKEY_FILE):
class Client_suds(SessionId, Client):
def set_parameters(self, path_to_cert, CERT_FILE, PKEY_FILE, HOST):
self.path_to_cert = path_to_cert
if not CERT_FILE:
CERT_FILE = ''
self.CERT_FILE = CERT_FILE
self.REQ_FILE = path_to_cert + 'client.csr'
self.PKEY_FILE = PKEY_FILE
self.SID_FILE = path_to_cert + 'sid.int'
self.SID_FILE = path_to_cert + 'sids'
self.SID_LOCK = path_to_cert + 'sids.lock'
self.CRL_PATH = path_to_cert + 'ca/crl/'
self.HOST = HOST
if not os.path.exists(self.CRL_PATH):
os.makedirs(self.CRL_PATH)
class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
"""based on httplib.HTTPSConnection code - extended to support
server certificate verification and client certificate authorization"""

@ -28,8 +28,6 @@ from calculate.core.server.local_call import print_brief_group
from calculate.lib.cl_lang import setLocalTranslate
from sudsds import MethodNotFound
from calculate.console.application.sid_func import get_sid
_ = lambda x: x
setLocalTranslate('cl_console3', sys.modules[__name__])
@ -158,7 +156,7 @@ class MessageReceiver(object):
@classmethod
def from_entire(cls, client, pid, message_dispatcher=None, display=None):
sid = get_sid(client.SID_FILE)
sid = client.get_sid()
list_pid = client.service.list_pid(sid=sid)
if hasattr(list_pid, 'integer'):
if pid not in list_pid.integer:

@ -39,9 +39,6 @@ def parse():
dest='help', help=_("show this help message and exit"))
parser.add_argument(
'--method', type=str, dest='method', help=_('call method'))
parser.add_argument(
'--translate-language', type=str, dest='lang',
help=_('translation language'))
parser.add_argument(
'--port', type=int, dest='port',
help=_('port number'))
@ -58,20 +55,16 @@ def parse():
'--cert-path', type=str, dest='path_to_cert', metavar='PATH',
help=_('path to the cert and key files'))
parser.add_argument(
'--list-pid', action='store_true', default=False,
dest='list_pid', help=_("view the list of running processes"))
parser.add_argument(
'--dump', action='store_true', default=False, dest='dump',
help=_('dump (to be used with option --list-pid)'))
parser.add_argument(
'--pid-result', type=int, metavar='PID',
dest='pid_res', help=_("view the result of the process"))
'--attach', metavar='PID',
dest='pid_res', help="%s (%s)" % (
_("attach to the process"),
_("'list' for displaying possible values")))
parser.add_argument(
'--keep-result', action='store_true', default=False,
'--keep', action='store_true', default=False,
dest='keep_result', help=_("keep the cache of the "
"process results"))
parser.add_argument(
'--pid-kill', type=int, metavar='PID',
'--kill', type=int, metavar='PID',
dest='pid_kill', help=_("kill the selected process"))
parser.add_argument(
'--session-clean', action='store_true', default=False,
@ -80,7 +73,7 @@ def parse():
'--session-info', action='store_true', default=False,
dest='session_info', help=_("view the session information"))
parser.add_argument(
'--session-num-info', type=int, metavar='SID',
'--session', type=int, metavar='SID',
dest='session_num_info',
help=_("view information about session = SID"))
parser.add_argument(

@ -15,8 +15,9 @@
# limitations under the License.
from calculate.console.application.function import _print
from calculate.console.application.sid_func import get_sid
import sys
import datetime
from calculate.lib.utils.tools import classificate
_ = lambda x: x
from calculate.lib.cl_lang import setLocalTranslate
@ -25,10 +26,14 @@ setLocalTranslate('cl_console3', sys.modules[__name__])
client_types = "console"
def pid_inf(client, sid, pids):
def pid_inf(client, sid, pids, wait_thread=None):
""" get and show information about process """
for pid in pids:
for mark, pid in classificate(pids):
s = client.service.pid_info(sid, pid)
if wait_thread:
wait_thread.stop()
sys.stdout.write("\b")
sys.stdout.flush()
if s == "":
print _("PID not found")
return 1
@ -36,21 +41,24 @@ def pid_inf(client, sid, pids):
print _("Permission denied")
return 1
_print('\n', _(u"Process name: %s") % s[0][4])
print _(u"Process ID: %s") % s[0][0]
_print(_(u"%s: process started") % s[0][2])
_print(_(u"Process name: %s") % s[0][4])
print _(u"ID: %s") % s[0][0]
_print(_(u"Start time: %s") % s[0][2].partition(".")[0])
if s[0][1] == '1':
print _(u"Process active")
status = _(u"Active")
elif s[0][1] == '0':
print _(u"Process completed")
status = _(u"Completed")
else:
print _(u"Process killed")
status = _(u"Killed")
print _(u"Status: %s") % status
if not mark.last:
print
return 0
def client_list_pid(client):
""" get all process id for this session """
sid = get_sid(client.SID_FILE)
sid = client.get_sid()
red = '\033[31m * \033[0m'
green = '\033[32m * \033[0m'
@ -70,7 +78,7 @@ def client_list_pid(client):
def gen_pid_ls(client):
""" generation list with pid for this session """
sid = get_sid(client.SID_FILE)
sid = client.get_sid()
pid_ls = []
try:
list_pid = client.service.list_pid(sid=sid)
@ -86,20 +94,18 @@ def gen_pid_ls(client):
return pid_ls
def client_pid_info(client):
def client_pid_info(client, wait_thread=None):
""" get information about selected process (or about all) """
# try:
sid = get_sid(client.SID_FILE)
sid = client.get_sid()
pid_ls = gen_pid_ls(client)
if wait_thread:
wait_thread.stop()
sys.stdout.write("\b")
sys.stdout.flush()
if pid_ls:
pid_inf(client, sid, pid_ls)
pid_inf(client, sid, pid_ls, wait_thread=wait_thread)
# except:
# print _("Error get data")
# return 1
# return 0
def client_list_methods(client):
""" get & show all available methods for this certificate """
DAT = 0 # Access to data soap structure
@ -131,7 +137,7 @@ def client_list_methods(client):
def client_pid_kill(client, pid):
sid = get_sid(client.SID_FILE)
sid = client.get_sid()
result = client.service.pid_kill(pid, sid)
if result == 0:

@ -16,6 +16,8 @@
import os
import sys
from calculate.lib.utils.files import readLinesFile, readFile, writeFile
from calculate.lib.utils.tools import Locker
_ = lambda x: x
from calculate.lib.cl_lang import setLocalTranslate
@ -23,37 +25,10 @@ from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_console3', sys.modules[__name__])
def client_del_sid(client):
""" delete this session """
sid = get_sid(client.SID_FILE)
try:
s = client.service.del_sid(sid)
if s[0][0] == "-1":
print _("No access to the file!")
return -1
if s[0][0] == "1":
print _("Failed to obtain certificate data!")
return -2
if s[0][0] == "Permission denied":
print _("%s: permission denied") % s[1][1]
return -3
if s[0][0] == '0':
fi = open(client.SID_FILE, 'w')
fi.write('0')
fi.close()
print _("SID deleted!")
except Exception:
print _("SID deletion error on the server")
return 1
return 0
def sid_inf(client, sid):
""" get information about selected session """
red = '\033[31m * \033[0m'
green = '\033[32m * \033[0m'
""" get information about selected session """
s = client.service.sid_info(sid)
if s[0][0] == "-1":
print red + _("Session non registered on the server!")
@ -66,11 +41,11 @@ def sid_inf(client, sid):
return -3
print _('Session information: ')
print green + _(u"Session number: %s") % sid
print green + _(u"ID: %s") % sid
print green + _(u"Certificate number: %s") % s[0][0]
print green + _(u"Certificate issued on %s") % s[0][1]
print green + "ip - %s" % s[0][2]
print green + "MAC - %s\n" % s[0][3]
print green + _(u"Certificate issued: %s") % s[0][1].partition(".")[0]
print green + "IP: %s" % s[0][2]
print green + "MAC: %s\n" % s[0][3]
return 0
@ -125,14 +100,41 @@ def session_clean(client):
print e
def get_sid(sid_file):
if not os.path.exists(sid_file):
fi = open(sid_file, 'w')
fi.write('0')
fi.close()
sid = 0
else:
fi = open(sid_file, 'r')
sid = fi.read()
fi.close()
return sid
class SessionId(object):
SID_FILE = None
HOST = None
SID_LOCK = None
def get_sid(self):
if not os.path.exists(self.SID_FILE):
return "0"
else:
with Locker(fn=self.SID_LOCK):
for line in readLinesFile(self.SID_FILE):
data = line.split()
if len(data) == 2:
host, sid = data
if self.host_alias(self.HOST) == host:
return sid
return "0"
def host_alias(self, host):
if host == "localhost":
return "127.0.0.1"
return host
def write_sid(self, sid):
with Locker(fn=self.SID_LOCK):
sid_data = readFile(self.SID_FILE)
added = False
with writeFile(self.SID_FILE) as f:
for line in sid_data.split('\n'):
data = line.split()
if len(data) == 2:
host, oldsid = data
if self.host_alias(self.HOST) == host:
oldsid = str(sid)
added = True
f.write("%s %s\n" % (host, oldsid))
if not added:
f.write("%s %s" % (self.host_alias(self.HOST), str(sid)))

Loading…
Cancel
Save