Many py3 related changes, cherryPy swaped for cheroot

master
idziubenko 3 years ago
parent d8ba586edc
commit e4342187eb

@ -596,10 +596,8 @@ class Backup(MethodsInterface):
if (x.endswith('site-packages') and
x.startswith('/usr/lib'))]
ret_list = []
for module, modDir in chain(
*map(lambda x: map(lambda y: (path.basename(y), y),
listDirectory(x, True, True)),
site_packages)):
for module, modDir in chain(*(((path.basename(y), y) for y
in listDirectory(x, True, True)) for x in site_packages)):
if path.exists(path.join(modDir, "backup_%s.py" % module)):
if not "calculate-%s" % module in ret_list:
ret_list.append("calculate-%s" % module)

@ -88,11 +88,11 @@ def client_post_request(cert_path, by_host):
if os.path.exists(cert_path + 'req_id'):
print(_("You already sent a certificate signature request."))
print(_("Request ID = %s") % readFile(cert_path + 'req_id'))
ans = raw_input(_("Send a new request? y/[n]: "))
ans = input(_("Send a new request? y/[n]: "))
if not ans.lower() in ['y', 'yes']:
return 0
port = raw_input(_("Enter the port number: "))
port = input(_("Enter the port number: "))
try:
port = int(port)
except ValueError:
@ -115,7 +115,7 @@ def client_post_request(cert_path, by_host):
csr_file = cert_path + server_host_name + '.csr'
if os.path.exists(key) and os.path.exists(csr_file):
print(_("the private key and request now exist"))
ask = raw_input(_("Create a new private key and request? y/[n]: "))
ask = input(_("Create a new private key and request? y/[n]: "))
if ask.lower() in ['y', 'yes']:
new_key_req(key, cert_path, server_host_name)
else:
@ -145,7 +145,7 @@ def client_get_cert(cert_path, args):
print('\n' + _("the URL looks like"), "https://%s:[port]/?wsdl" \
% args.from_host)
port = raw_input(_("Enter the port number: "))
port = input(_("Enter the port number: "))
try:
port = int(port)
except ValueError:
@ -171,7 +171,7 @@ def client_get_cert(cert_path, args):
return 1
request = readFile(cert_path + server_host_name + '.csr')
md5 = hashlib.md5()
md5.update(request)
md5.update(request.encode("UTF-8"))
md5sum = md5.hexdigest()
result = client.service.get_client_cert(req_id, md5sum)
@ -212,7 +212,7 @@ def client_get_cert(cert_path, args):
root_cert_md5 = cl_client_cert_dir + "/ca/cert_list"
md5 = hashlib.md5()
md5.update(ca_root)
md5.update(ca_root.encode("UTF-8"))
md5sum = md5.hexdigest()
if not os.path.exists(root_cert_md5):
@ -300,7 +300,7 @@ def cert_right_inf(client, sid, cert_id):
# Viewing rights of any certificate on server by its id
def client_view_cert_right(client):
cert_id = raw_input(_("Certificate ID: "))
cert_id = input(_("Certificate ID: "))
try:
cert_id = int(cert_id)
except ValueError:

@ -244,7 +244,7 @@ def rm_ca_from_trusted(ca_cert):
import hashlib
md5 = hashlib.md5()
md5.update(ca_cert)
md5.update(ca_cert.encode("UTF-8"))
md5sum = md5.hexdigest()
# search ca certificate in user ca list

@ -139,7 +139,7 @@ class clientHTTPSConnection(httplib.HTTPSConnection):
root_cert_md5 = cl_client_cert_dir + "/ca/cert_list"
md5 = hashlib.md5()
md5.update(cert)
md5.update(cert.encode("UTF-8"))
md5sum = md5.hexdigest()
print("\n=================================================")
print("md5sum = ", md5sum)
@ -217,7 +217,7 @@ class clientHTTPSConnection(httplib.HTTPSConnection):
print('\n' + _("Subject"))
for subj in Subject:
print("%s : %s" % (subj[0], subj[1]))
ans = raw_input(_("Add the CA certificate to trusted? y/[n]:"))
ans = input(_("Add the CA certificate to trusted? y/[n]:"))
if ans.lower() in ['y', 'yes']:
list_ca_certs.append(cert)
self.add_all_ca_cert(list_ca_certs)
@ -245,7 +245,7 @@ class clientHTTPSConnection(httplib.HTTPSConnection):
print('\n' + _('Add this server certificate to trusted (s) or'))
print(_('Try to add the CA and root certificates to trusted (c) or'))
choice = raw_input(_("Quit (q)? s/c/[q]: "))
choice = input(_("Quit (q)? s/c/[q]: "))
if choice.lower() in ['s', 'c']:
# self.sock = ssl.wrap_socket(sock)
ca_certs = self.trusted_path + "cert.list"

@ -49,7 +49,7 @@ def makeRequest(pubkey, pkey, serv_host, auto=False):
if auto:
c = 'n'
else:
c = raw_input(_("Enter the certificate date manually? y/[n]: "))
c = input(_("Enter the certificate date manually? y/[n]: "))
# Get HostName
host_name = socket.getfqdn()
list_host_name = host_name.split('.')
@ -69,20 +69,20 @@ def makeRequest(pubkey, pkey, serv_host, auto=False):
# list_host_name[len(list_host_name)-1]+"@"+serv_host
# else:
# host_name = socket.getfqdn()
_CN = raw_input(_('Hostname [%s] : ') % result_host_name)
_CN = input(_('Hostname [%s] : ') % result_host_name)
name.CN = _CN or result_host_name or ""
_OU = raw_input(_('Username [%s]: ') % username)
_OU = input(_('Username [%s]: ') % username)
name.OU = _OU or username or ""
_O = raw_input(_('Organization name: '))
_O = input(_('Organization name: '))
name.O = _O or ""
_L = raw_input(_('Network address (hostname or IP) [%s]: ')
_L = input(_('Network address (hostname or IP) [%s]: ')
% host_name)
name.L = _L or ""
_ST = raw_input(_('City: '))
_ST = input(_('City: '))
name.ST = _ST or ""
_C = raw_input(_('Country: [%s]') % lang)
_C = input(_('Country: [%s]') % lang)
name.C = _C or lang or "C"
else:
name.CN = result_host_name or "" # Имя сертификата (Common Name);

@ -90,7 +90,7 @@ def gen_pid_ls(client, pid_ls):
def client_pid_info(client):
""" get information about selected process (or about all) """
pid = raw_input(_("PID") + _(": "))
pid = input(_("PID") + _(": "))
try:
pid = int(pid)
except ValueError:
@ -149,7 +149,7 @@ def client_list_sessions(client):
def client_pid_kill(client):
""" kill process on server """
pid = raw_input(_("PID to be killed: "))
pid = input(_("PID to be killed: "))
try:
pid = int(pid)
except ValueError:

@ -27,7 +27,7 @@ setLocalTranslate('cl_core3', sys.modules[__name__])
def client_sid(sid, client, cert_id):
""" get number session from server and write this in file """
# lang = raw_input ("Enter language (ru, en, de, fr): ")
# lang = input ("Enter language (ru, en, de, fr): ")
lang = "ru"
new_sid = client.service.post_sid(sid=sid, cert_id=cert_id, lang=lang)
fi = open(client.SID_FILE, 'w')
@ -98,7 +98,7 @@ def sid_inf(client, sid):
def client_session_info(client):
""" select session for get information """
sid = raw_input("SID: ")
sid = input("SID: ")
try:
sid = int(sid)
except ValueError:

@ -231,7 +231,7 @@ class TaskState(object):
yes = _print.foreground(yes_color)("Yes")
no = _print.foreground(no_color)("No")
white_message = _print.foreground(Colors.WHITE)(message)
ask = raw_input(white_message + ' (%s/%s): ' % (yes, no))
ask = input(white_message + ' (%s/%s): ' % (yes, no))
except (EOFError, KeyboardInterrupt):
ask = 'no'
print()
@ -281,7 +281,7 @@ class TaskState(object):
raise KeyboardInterrupt
else:
try:
ask = raw_input(full_message)
ask = input(full_message)
except (EOFError, KeyboardInterrupt):
printer("\n")
raise KeyboardInterrupt
@ -293,14 +293,13 @@ class TaskState(object):
if len(like_answers) == 1:
return like_answers[i_value][firstletter]
else:
self.state.printERROR(_('Ambiguous answer:') +
",".join(map(lambda x: x[i_comment],
like_answers)))
self.state.printERROR(_('Ambiguous answer:') +
",".join((x[i_comment] for x in like_answers)))
@echo_on
def askQuestion(self, message):
self.parent.printer("\n")
return raw_input(message + _(":"))
return input(message + _(":"))
def askPassword(self, message, twice):
from calculate.lib.utils.common import getpass

@ -462,9 +462,6 @@ class ViewInfo(DataVarsSerializer):
def stepGroup(self, groupInfo, brief_label, help_value=None,
next_value=None, image_value=""):
"""Step group"""
# print("DEBUG what are you doing stepGroup")
# print(groupInfo)
# print(brief_label)
return GroupField(fields=[
Field(name="Steps",
element="table",
@ -529,10 +526,10 @@ class Message(ComplexModel):
onlyShow = String(default=None, min_occurs=1)
default = String(default=None, min_occurs=1)
def __init__(self, type='normal', message=None, id=None,
def __init__(self, message_type='normal', message=None, id=None,
result=None, onlyShow=None, default=None):
super(Message, self).__init__()
self.type = type
self.type = message_type
self.message = message
self.id = id
self.result = result
@ -561,7 +558,7 @@ class Frame(ComplexModel):
# get and send client messages
class CoreWsdl(CoreServiceInterface):
perm_denied = [Message(type='error', message='403 Forbidden')]
perm_denied = [Message(message_type='error', message='403 Forbiddennnn')]
@staticmethod
def callAction(cls, sid, info, logicClass=None,
method_name=None, actionClass=None,
@ -675,7 +672,7 @@ class CoreWsdl(CoreServiceInterface):
check = 0
try:
fd = open(cls.sids_file, 'r')
fd = open(cls.sids_file, 'rb')
except IOError:
return 0
while 1:
@ -691,7 +688,7 @@ class CoreWsdl(CoreServiceInterface):
if check == 0:
return 0
fd = open(cls.sids_pids, 'r')
fd = open(cls.sids_pids, 'rb')
while 1:
try:
# read out on 1 record
@ -756,7 +753,7 @@ class CoreWsdl(CoreServiceInterface):
def client_send_message(cls, sid, pid, text):
if cls.check_cert_pid(cls, sid, pid):
cls.glob_process_dict[pid]['answer'] = text
return Message(type='normal', message="")
return Message(message_type='normal', message="")
return CoreWsdl.perm_denied

@ -371,7 +371,7 @@ class Basic(Service, CoreServiceInterface):
for subj in subject:
if subj[0] == 'CN':
return subj[1]
return ''
return b'No server host name provided'
@rpc(_returns=String)
def get_ca(ctx):

@ -321,7 +321,7 @@ def get_certificate(cert_path, data_path, certbase, client_cert_path,
return 1
request = readFile(req_file)
md5 = hashlib.md5()
md5.update(request)
md5.update(request.encode("UTF-8"))
md5sum = md5.hexdigest()
result = post_request.serv_get_client_cert(
@ -380,7 +380,7 @@ def get_certificate(cert_path, data_path, certbase, client_cert_path,
root_cert_md5 = os.path.join(ca_dir, "cert_list")
md5 = hashlib.md5()
md5.update(ca_root)
md5.update(ca_root.encode("UTF-8"))
md5sum = md5.hexdigest()
if not os.path.exists(root_cert_md5):
@ -476,7 +476,7 @@ def get_certificate(cert_path, data_path, certbase, client_cert_path,
def key_force(cert_path, data_path):
while True:
try:
resp = raw_input(_('Do you really want to remove all '
resp = input(_('Do you really want to remove all '
'certificates, requests and config files from '
'the server?') + ' (yes/no): ')
except KeyboardInterrupt:

@ -64,7 +64,7 @@ def check_server_certificate(cert, key, cert_path, args, port, auto=False):
if auto:
c = 'n'
else:
c = raw_input(_("Enter the certificate date manually? [y]/n: "))
c = input(_("Enter the certificate date manually? [y]/n: "))
from M2Crypto import X509
name = X509.X509_Name()
@ -101,29 +101,29 @@ def check_server_certificate(cert, key, cert_path, args, port, auto=False):
else:
print(_('Do not use spaces or tabs.'))
host_name = socket.getfqdn()
name['CN'] = raw_input(_('Hostname [%s] : ') % host_name)
name['CN'] = input(_('Hostname [%s] : ') % host_name)
if name['CN'] in ['', None]:
name['CN'] = host_name
name['OU'] = raw_input(_('Organization unit: '))
name['OU'] = input(_('Organization unit: '))
if not name['OU']:
name['OU'] = ''
else:
name['OU'] = name['OU'].replace(' ', '_').replace('\t', '_')
name['O'] = raw_input(_('Organization name: '))
name['O'] = input(_('Organization name: '))
if not name['O']:
name['O'] = ''
else:
name['O'] = name['O'].replace(' ', '_').replace('\t', '_')
network = _('Full network address (host:port)')
name['L'] = raw_input(network + ' [%s:%d]: ' % (host_name, port))
name['L'] = input(network + ' [%s:%d]: ' % (host_name, port))
if name['L'] in ['', None]:
name['L'] = host_name + ':' + str(port)
name['ST'] = raw_input(_('City: '))
name['ST'] = input(_('City: '))
if not name['ST']:
name['ST'] = ''
else:
name['ST'] = name['ST'].replace(' ', '_').replace('\t', '_')
name['C'] = raw_input(_('Country (two letters only!) [%s]: ') % lang)
name['C'] = input(_('Country (two letters only!) [%s]: ') % lang)
if not name['C']:
name['C'] = lang
@ -188,7 +188,7 @@ def check_server_certificate(cert, key, cert_path, args, port, auto=False):
if os.path.exists(key) and os.path.exists(cert_path + '/server.csr'):
print(_("the private key and request now exist"))
ask = raw_input(_("Create a new private key and request?") +
ask = input(_("Create a new private key and request?") +
" y/[n]: ")
if ask.lower() in ['y', 'yes']:
new_key_req(key, cert_path, serv_host_name, port)
@ -232,7 +232,7 @@ def check_server_certificate(cert, key, cert_path, args, port, auto=False):
request = readFile(cert_path + '/server.csr')
md5 = hashlib.md5()
md5.update(request)
md5.update(request.encode("UTF-8"))
md5sum = md5.hexdigest()
result = client.service.get_server_cert(req_id, md5sum)
@ -341,7 +341,7 @@ def find_cert_id(certificate, data_path, certbase):
cert_path = data_path + '/client_certs/'
for certId in cert_id:
if os.path.isfile(cert_path + certId + '.crt'):
fp = open(cert_path + certId + '.crt', 'r')
fp = open(cert_path + certId + '.crt', 'rb')
cert = fp.read()
fp.close()
else:
@ -650,7 +650,7 @@ def view_cert(args, certbase, data_path, rights, group_rights):
print(_("Total: %d certificates.") % count)
if remove:
answer = raw_input(
answer = input(
_("Are you sure? Delete all client certificates?") + ' y/[n]: ')
if answer.lower() in ['y', 'yes']:
fc = open(certbase, "w")
@ -673,7 +673,7 @@ def view_cert(args, certbase, data_path, rights, group_rights):
view_cert_info(cert, cert_id, rights, group_rights)
if remove:
answer = raw_input(
answer = input(
_("Delete the client certificate with ID %d? y/[n]: ") % cert_id)
if answer.lower() in ['y', 'yes']:
del_cert(certbase, data_path, cert_id)
@ -706,7 +706,7 @@ def sing_req_by_server(id_client_req, cert_path, data_path, auto=False,
if not auto:
group_name = ""
while not group_name.split():
group_name = "%s" % raw_input(
group_name = "%s" % input(
_("Enter the group of the new certificate "
"(group name or 'all'): "))
config = data_path + '/client_certs/ssl-client.cfg'
@ -1000,7 +1000,7 @@ def del_request(id_del_serv_req, id_del_client_req, serv_certbase,
if os.path.exists(cert):
print(_("Request duly signed"))
ask = raw_input(
ask = input(
_("Delete the certificate and the signature request? y/[n]: "))
if not ask.lower() in ['y', 'yes']:
print(_("Not deleted"))

@ -44,9 +44,8 @@ _('No module named %s')
@clearDataVars
def main(*args, **keywords):
_args = list(unpack_single_opts(sys.argv[1:]))
#TODO change back
# if os.path.basename(sys.argv[0]) != 'cl-core':
if False:
caller = os.path.basename(sys.argv[0])
if not (caller == 'cl-core' or caller == 'cl-core_py3'):
parser = cert_cmd.parse(full=False)
args, unknown_args = parser.parse_known_args(_args)
args.method = '_temp_'
@ -254,7 +253,6 @@ def main(*args, **keywords):
return local_method(tc, args, unknown_args)
ClService = make_service(Basic, core_wsdl_classes, outer_wsdl_classes, "ClService")
from .server_class import ClApplication, OpenSSLAdapter
#do we even need this anymore?
tc = ClService()

@ -104,8 +104,8 @@ def monitor(certbase, sid_file):
# check session
try:
sid_file_t = sid_file + '_temp'
fd = open(sid_file, 'r')
ft = open(sid_file_t, 'w')
fd = open(sid_file, 'rb')
ft = open(sid_file_t, 'wb')
while 1:
try:
# read all on one record
@ -146,7 +146,7 @@ def sid_monitor(sid_fn, sids_dn, cls):
sids = []
# create, if file not exists
if not os.path.exists(sid_fn):
temp = open(sid_fn, 'w')
temp = open(sid_fn, 'wb')
temp.close()
fd = open(sid_fn, 'rb')
while 1:
@ -169,7 +169,7 @@ def sid_monitor(sid_fn, sids_dn, cls):
sid_path = sids_dn + "/%d.sid" % filename
with cls.sid_locker:
if os.path.isfile(sid_path):
with open(sid_path) as fd:
with open(sid_path, "rb") as fd:
# read information about session
sid_inf = pickle.load(fd)
# if number of missed inspections more 3
@ -180,7 +180,7 @@ def sid_monitor(sid_fn, sids_dn, cls):
if os.path.isfile(sid_path):
# add to digit missed inspections
# client constantly nulls this value!
ft = open(sid_path, 'w')
ft = open(sid_path, 'wb')
if sid_inf[1] < 4:
sid_inf[1] += 1
pickle.dump(sid_inf, ft)

@ -95,7 +95,7 @@ class clientHTTPSConnection(HTTPSConnection):
for item in Subject:
print("%s : %s" % (item[0], item[1]))
choice = raw_input(
choice = input(
_("add this certificate to trusted and continue? y/[n]: "))
if choice in ['y', 'yes', 'Y', 'YES']:
ca_certs = self.ca_path + "cert.list"

@ -24,7 +24,7 @@ from calculate.lib.utils.text import _u8
from M2Crypto import m2
from M2Crypto.X509 import X509_Extension
from calculate.lib.utils.files import writeFile, readFile
from calculate.lib.utils.files import writeFileBin, readFile
from ctypes import *
@ -53,7 +53,7 @@ def makeRequest(pubkey, pkey, serv_host, port):
req.set_version(req.get_version())
req.set_pubkey(pkey)
name = X509.X509_Name()
c = raw_input(_("Enter the certificate date manually? [y]/n: "))
c = input(_("Enter the certificate date manually? [y]/n: "))
if c.lower() in ['n', 'no']:
name.CN = 'root_cert' # (Common Name);
name.OU = 'www.calculate-linux.ru' # (Organization Unit);
@ -86,18 +86,18 @@ def makeRequest(pubkey, pkey, serv_host, port):
return x.replace(' ', '_').replace('\t', '_')
return ""
_CN = raw_input(_('Hostname [%s] : ') % _u8(result_host_name))
_CN = input(_('Hostname [%s] : ') % _u8(result_host_name))
name.CN = _CN or result_host_name or ""
_OU = raw_input(_('Organization unit: '))
_OU = input(_('Organization unit: '))
name.OU = cleardata(_OU)
_O = raw_input(_('Organization name: '))
_O = input(_('Organization name: '))
name.O = cleardata(_O)
network = _('Full network address (host:port)')
_L = raw_input(network + ' [%s:%d]: ' % (_u8(host_name), port))
_L = input(network + ' [%s:%d]: ' % (_u8(host_name), port))
name.L = cleardata(_L) or (_u8(host_name) + ':' + str(port))
_ST = raw_input(_('City: '))
_ST = input(_('City: '))
name.ST = cleardata(_ST)
_C = raw_input(_('Country (two letters only!): '))
_C = input(_('Country (two letters only!): '))
name.C = _C or "C"
req.set_subject_name(name)
@ -142,7 +142,7 @@ def create_selfsigned_ca(dn_data, keyfile, certfile):
ca.add_extensions([crypto.X509Extension(b'authorityKeyIdentifier', False, b'keyid:always',issuer=ca)])
ca.sign(pkey, 'sha1')
with writeFile(certfile) as f:
with writeFileBin(certfile) as f:
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, ca))
except crypto.Error as e:
raise CreateCertError(str(e))
@ -180,11 +180,11 @@ def sign_client_certifacation_request(ca_keyfile, ca_certfile, requestfile, out_
crypto.X509Extension(b'nsCertType', False, b'client'),
crypto.X509Extension(b'keyUsage', False, b'digitalSignature, keyEncipherment'),
crypto.X509Extension(b'extendedKeyUsage', False, b'clientAuth'),
crypto.X509Extension(b'nsComment', False, 'group:{}'.format(group)),
crypto.X509Extension(b'nsComment', False, 'group:{}'.format(group).encode("UTF-8")),
])
cert.sign(pkey, 'sha1')
with writeFile(out_cert) as f:
with writeFileBin(out_cert) as f:
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
except crypto.Error as e:
raise CreateCertError(str(e))

@ -916,7 +916,7 @@ class CoreWsdl(CoreServiceInterface):
pass
return ActiveClientStatus.Failed
with cls.sid_locker:
with open(sid_file) as fd:
with open(sid_file, "rb") as fd:
# read information about session
sid_inf = pickle.load(fd)
# reset counters
@ -925,7 +925,7 @@ class CoreWsdl(CoreServiceInterface):
fd.close()
if not os.path.isfile(sid_file):
return ActiveClientStatus.Failed
fd = open(sid_file, "w")
fd = open(sid_file, "wb")
pickle.dump(sid_inf, fd)
fd.close()
return ActiveClientStatus.Success
@ -984,7 +984,6 @@ class CoreWsdl(CoreServiceInterface):
@staticmethod
def return_guiMethod():
from .loaded_methods import LoadedMethods
results = []
dv = DataVars()
dv.importVariables()
@ -1007,7 +1006,7 @@ class CoreWsdl(CoreServiceInterface):
@staticmethod
def serv_get_sessions(cls):
result = []
fd = open(cls.sids_file, 'r')
fd = open(cls.sids_file, 'rb')
while 1:
try:
# read all on one record
@ -1026,7 +1025,7 @@ class CoreWsdl(CoreServiceInterface):
if not os.path.isfile(sid_path):
return 1
with cls.sid_locker:
with open(sid_path) as fd:
with open(sid_path, "rb") as fd:
# read information about session
sid_inf = pickle.load(fd)
# flag absence client
@ -1080,7 +1079,7 @@ class CoreWsdl(CoreServiceInterface):
pid_file = path.join(Basic.pids, '%d.pid' % self.pid)
try:
with open(pid_file, 'w') as f:
with open(pid_file, 'wb') as f:
d = {'name': self.process_dict['method_name'],
'mode': ProcessMode.CoreDaemon,
'os_pid': os.getpid(),
@ -1138,7 +1137,7 @@ class CoreWsdl(CoreServiceInterface):
id = random.randint(1, self.Num)
self.progress_dict['id'] = id
self.progress_dict[id] = ReturnProgress(0, '', '')
self.addMessage(type='progress', id=id)
self.addMessage(message_type='progress', id=id)
def printTable(self, table_name, head, body, fields=None,
onClick=None, addAction=None, step=None,
@ -1154,18 +1153,19 @@ class CoreWsdl(CoreServiceInterface):
onClick=onClick, addAction=addAction, step=step,
values=None, records=records)
self.table_dict[id] = table
self.addMessage(type='table', message=table_name, id=id)
self.addMessage(message_type='table', message=table_name, id=id)
def addMessage(self, type='normal', message=None, id=None,
def addMessage(self, message_type='normal', message=None, id=None,
onlyShow='', default=None):
from .api_types import Message
re_clean = re.compile(r'\[(?:\d+;)?\d+m')
messageObj = Message(
type=type,
message_type=message_type,
message=(
None if message in (None, True, False)
else re_clean.sub('', [x for x in message if x >= ' '])),
# else re_clean.sub('', [x for x in message if x >= ' '])),
else re_clean.sub('', message)),
result=message if message in (True, False) else None,
id=id, onlyShow=onlyShow, default=default)
try:
@ -1173,7 +1173,7 @@ class CoreWsdl(CoreServiceInterface):
except BaseException as e:
if isinstance(e, KeyboardInterrupt):
raise
print(_(("%s:" % type) + str(message)))
print(_(("%s:" % message_type) + str(message)))
def dropProgress(self):
perc = self.getProgress()
@ -1187,45 +1187,45 @@ class CoreWsdl(CoreServiceInterface):
def printSUCCESS(self, message='', onlyShow=None):
self.dropProgress()
self.addMessage(type='normal', message=message,
self.addMessage(message_type='normal', message=message,
onlyShow=onlyShow)
def printPre(self, message='', onlyShow=None):
self.dropProgress()
self.addMessage(type='pre', message=message,
self.addMessage(message_type='pre', message=message,
onlyShow=onlyShow)
def printDefault(self, message='', onlyShow=None):
self.dropProgress()
self.addMessage(type='plain', message=message,
self.addMessage(message_type='plain', message=message,
onlyShow=onlyShow)
def printWARNING(self, message, onlyShow=None):
self.dropProgress()
self.addMessage(type='warning', message=message,
self.addMessage(message_type='warning', message=message,
onlyShow=onlyShow)
def printERROR(self, message='', onlyShow=None):
self.dropProgress()
self.addMessage(type='error', message=message,
self.addMessage(message_type='error', message=message,
onlyShow=onlyShow)
def startTask(self, message, progress=False, num=1):
if progress:
self.addMessage(type='startTask', message=message, id=num)
self.addMessage(message_type='startTask', message=message, id=num)
self.addProgress()
else:
self.addMessage(type='startTask', message=message, id=num)
self.addMessage(message_type='startTask', message=message, id=num)
def setTaskNumber(self, number=None):
self.addMessage(type='taskNumber', message=str(number))
self.addMessage(message_type='taskNumber', message=str(number))
def endTask(self, result=None, progress_message=None):
self.addMessage(type='endTask', message=result)
self.addMessage(message_type='endTask', message=result)
self.setProgress(100, progress_message)
def askConfirm(self, message, default="yes"):
self.addMessage(type='confirm', message=message, default=default)
self.addMessage(message_type='confirm', message=message, default=default)
ret = self.getAnswer()
if ret == "":
return default
@ -1235,32 +1235,32 @@ class CoreWsdl(CoreServiceInterface):
return True
def askChoice(self, message, answers=(("yes", "Yes"), ("no", "No"))):
self.addMessage(type='choice', message="%s|%s" % (
self.addMessage(message_type='choice', message="%s|%s" % (
message,
",".join(map(lambda x: "%s(%s)" % (x[0], x[1]), answers))))
",".join(("%s(%s)" % (x[0], x[1]) for x in answers))))
return self.getAnswer()
def askQuestion(self, message):
self.addMessage(type='question', message=message)
self.addMessage(message_type='question', message=message)
return self.getAnswer()
def askPassword(self, message, twice=False):
pas_repeat = 2 if twice else 1
self.addMessage(type='password', message=message,
self.addMessage(message_type='password', message=message,
id=pas_repeat)
return self.getAnswer()
def beginFrame(self, message=None):
self.addMessage(type='beginFrame', message=message)
self.addMessage(message_type='beginFrame', message=message)
def endFrame(self):
self.addMessage(type='endFrame')
self.addMessage(message_type='endFrame')
def startGroup(self, message):
self.addMessage(type='startGroup', message=message)
self.addMessage(message_type='startGroup', message=message)
def endGroup(self):
self.addMessage(type='endGroup')
self.addMessage(message_type='endGroup')
# def cache(self, param):
# sid = self.process_dict['sid']
@ -1395,7 +1395,7 @@ class CoreWsdl(CoreServiceInterface):
OpenSSL.SSL.FILETYPE_PEM, cert)
com = certobj.get_extension(
certobj.get_extension_count() - 1).get_data()
groups = com.split(':')[1]
groups = com.split(b':')[1].decode("UTF-8")
groups_list = groups.split(',')
# except:
# return ['-1']
@ -1491,7 +1491,7 @@ class CoreWsdl(CoreServiceInterface):
if os.path.exists(sid_file):
# fd = open(sid_file, 'r')
with open(sid_file, 'r') as fd:
with open(sid_file, 'rb') as fd:
try:
list_sid = pickle.load(fd)
list_sid_sid = int(list_sid[0])
@ -1733,7 +1733,7 @@ class WsdlMeta(type):
if callable(v):
v = v(dv)
else:
if isinstance(v, (str, unicode)):
if isinstance(v, (str)):
v = Variable._value_formatter.format(v, dv.Get)
dv.Set(k.strip('!'), v, force=k.endswith('!'))
@ -1748,9 +1748,9 @@ class WsdlMeta(type):
lang_changed = False
if kwargs["groups"]:
def group(*args, **kwargs):
if isinstance(kwargs.get('normal', ()), (unicode, str)):
if isinstance(kwargs.get('normal', ()), (str)):
raise DataVarsError(_("Wrong normal varaiables list"))
if isinstance(kwargs.get('expert', ()), (unicode, str)):
if isinstance(kwargs.get('expert', ()), (str)):
raise DataVarsError(_("Wrong expert varaiables list"))
for gr in kwargs['groups']:
@ -1847,11 +1847,11 @@ class WsdlMeta(type):
return wrapper
class WsdlBase(object):
class WsdlBase(metaclass=WsdlMeta):
"""
Базовый класс для автосоздания методов по описанию methods
"""
__metaclass__ = WsdlMeta
# __metaclass__ = WsdlMeta
def clearDataVars(func):

@ -68,7 +68,7 @@ def search_worked_process(method_name, clVars,
pids = clVars.Get('core.cl_core_pids_path')
for pidfile in listDirectory(pids, fullPath=True):
try:
status = pickle.load(open(pidfile))
status = pickle.load(open(pidfile, "rb"))
if ((method_name is None or status['name'] == method_name) and
status['status'] in statuses):
pid_path = path.join("/proc", str(status['os_pid']))
@ -91,7 +91,7 @@ def search_worked_process2(clVars, filter_func=lambda x: True,
pids = clVars.Get('core.cl_core_pids_path')
for pidfile in listDirectory(pids, fullPath=True):
try:
status = pickle.load(open(pidfile))
status = pickle.load(open(pidfile), "rb")
if status_filter(status) and filter_func(status):
pid_path = path.join("/proc", str(status['os_pid']))
if path.exists(pid_path):
@ -112,7 +112,7 @@ def get_pid_info(clVars, statuses=(ProcessStatus.Worked,)):
pids = clVars.Get('core.cl_core_pids_path')
for pidfile in listDirectory(pids, fullPath=True):
try:
status = pickle.load(open(pidfile))
status = pickle.load(open(pidfile), "rb")
if status['status'] in statuses:
if path.exists(path.join("/proc", str(status['os_pid']))):
yield status
@ -123,7 +123,7 @@ def get_pid_info(clVars, statuses=(ProcessStatus.Worked,)):
# try:
# pidfile = path.join(pids,str(pid))
# status = pickle.load(open(pidfile))
# status = pickle.load(open(pidfile), "rb")
# return status
# except (socket.error, ValueError, IOError, KeyError, EOFError, OSError):
# return None
@ -136,7 +136,7 @@ def clear_finished_pids(clVars):
pids = clVars.Get('core.cl_core_pids_path')
for pidfile in listDirectory(pids, fullPath=True):
try:
d = pickle.load(open(pidfile))
d = pickle.load(open(pidfile), "rb")
if path.exists(path.join("/proc", str(d['os_pid']))):
continue
except Exception:
@ -242,7 +242,7 @@ class CoreWsdl(CoreServiceInterface):
return 0
# temp = open(cls.sids_file, 'w')
# temp.close()
fd = open(cls.sids_file, 'r')
fd = open(cls.sids_file, 'rb')
while 1:
try:
# read all on one record

@ -38,8 +38,8 @@ class CoreWsdl(CoreServiceInterface):
sid_file_t = sid_file + 'temp'
with cls.sid_locker:
fd = open(sid_file, 'r')
ft = open(sid_file_t, 'w')
fd = open(sid_file, 'rb')
ft = open(sid_file_t, 'wb')
while True:
try:
# read all on one record
@ -72,9 +72,9 @@ class CoreWsdl(CoreServiceInterface):
# create, if file not exists
with cls.sid_locker:
if not os.path.exists(sid_file):
temp = open(sid_file, 'w')
temp = open(sid_file, 'wb')
temp.close()
fd = open(sid_file, 'r')
fd = open(sid_file, 'rb')
while True:
try:
# read all on one record
@ -101,13 +101,13 @@ class CoreWsdl(CoreServiceInterface):
# create session's file
with cls.sid_locker:
fp = open(sid_file, 'w')
fp = open(sid_file, 'wb')
sid_list = [sid, 0, 0, lang]
pickle.dump(sid_list, fp)
fp.close()
# add session in list sessions
fd = open(cls.sids_file, 'a')
fd = open(cls.sids_file, 'ab')
pickle.dump(list_sid, fd)
fd.close()
return 0
@ -118,16 +118,16 @@ class CoreWsdl(CoreServiceInterface):
sid_file = os.path.join(sids_dir, "%d.sid" % sid)
with cls.sid_locker:
if not os.path.isfile(sid_file):
fp = open(sid_file, 'w')
fp = open(sid_file, 'wb')
fp.close()
fd = open(sid_file, 'r')
fd = open(sid_file, 'rb')
try:
list_sid = pickle.load(fd)
except (EOFError, KeyError, IOError):
list_sid = [sid, 0, 0, lang]
fd.close()
fp = open(sid_file, 'w')
fp = open(sid_file, 'wb')
list_sid[3] = lang
pickle.dump(list_sid, fp)
fp.close()
@ -212,7 +212,7 @@ class CoreWsdl(CoreServiceInterface):
results = []
sid_file = cls.sids_file
with cls.sid_locker:
fd = open(sid_file, 'r')
fd = open(sid_file, 'rb')
while 1:
try:
# read all on one record
@ -250,7 +250,7 @@ class CoreWsdl(CoreServiceInterface):
if not os.path.exists(cls.sids):
os.makedirs(cls.sids)
sid_path = cls.sids + "/%d.sid" % sid
with open(sid_path) as fs:
with open(sid_path, "rb") as fs:
# read info about session
sid_inf = pickle.load(fs)
# flag absence client

@ -147,7 +147,7 @@ class LocalCall(object):
makeDirectory(pids)
pid_file = path.join(pids, '%d.pid' % pid)
try:
with open(pid_file, 'w') as f:
with open(pid_file, 'wb') as f:
d = {'name': self.method_name,
'mode': ProcessMode.LocalCall,
'os_pid': pid,
@ -630,11 +630,11 @@ def print_brief_group(Fields, group_name):
display = Display()
show_group = True
try:
for element in filter(None,
(InformationElement.from_field(
FieldAdapter.from_detect(x),
display)
for x in Fields if not x.uncompatible)):
for element in (x for x
in (InformationElement.from_field(FieldAdapter.from_detect(y),display) for y
in Fields
if not y.uncompatible)
if x):
if show_group:
display.print_group(group_name)
show_group = False

@ -84,7 +84,7 @@ class BoolAutoAction(BoolAction):
available_values = ("on", "off", "yes", "no", "auto")
def _print(*args):
print(" ".join(map(lambda x: _u8(x), args)))
print(" ".join((_u8(x) for x in args)))
def get_password(text1=None, text2=None, getfromstdin=False,
@ -212,9 +212,9 @@ def get_method_argparser(view, args, cl_core=False):
if "choice" in field.type and hasattr(field.opt, "syntax") and \
field.opt.syntax and "{" in field.opt.syntax:
lgroup = group.add_mutually_exclusive_group()
help = dict(map(lambda x: (x[0].strip("'"), x[2]),
map(lambda x: x.partition(' - '),
field.help.split(',\n'))))
help = dict(((x[0].strip("'"), x[2]) for x
in (y.partition(' - ') for y
in field.help.split(',\n'))))
choice = field.choice
if not type(choice) in (list, tuple):
choice = choice.string
@ -425,9 +425,8 @@ def display_error(error, args, groups):
else:
if field.opt.shortopt or field.opt.longopt:
params_text += _('Wrong option ')
params_text += ' ' + ', '.join(
filter(None, [field.opt.shortopt,
field.opt.longopt])) + '. %s'
params_text += ' ' + ', '.join((x for x
in [field.opt.shortopt,field.opt.longopt] if x)) + '. %s'
if list_answer:
__print = get_terminal_print(colorPrint.defaultPrint)
__print.foreground(TextState.Colors.WHITE)(

@ -62,7 +62,7 @@ def serv_post_client_request(request, data_path,
f.write(request)
md5 = hashlib.md5()
md5.update(request)
md5.update(request.encode("UTF-8"))
md5sum = md5.hexdigest()
date = datetime.datetime.now()
@ -95,7 +95,7 @@ def serv_get_client_cert(req_id, request, data_path, client_certbase,
fp.close()
md5 = hashlib.md5()
md5.update(cert)
md5.update(cert.encode("UTF-8"))
md5sum = md5.hexdigest()
date = datetime.datetime.now()
@ -193,7 +193,7 @@ def serv_post_server_request(request, data_path,
f.write(request)
md5 = hashlib.md5()
md5.update(request)
md5.update(request.encode("UTF-8"))
md5sum = md5.hexdigest()
date = datetime.datetime.now()
@ -227,7 +227,7 @@ def serv_get_server_request(req_id, request, data_path, serv_certbase,
fp.close()
md5 = hashlib.md5()
md5.update(cert)
md5.update(cert.encode("UTF-8"))
md5sum = md5.hexdigest()
date = datetime.datetime.now()

@ -41,7 +41,7 @@ def add_cert(mac, client_type, client_counter, client_certname,
f.write(cert)
md5 = hashlib.md5()
md5.update(cert)
md5.update(cert.encode("UTF-8"))
md5sum = md5.hexdigest()
date = datetime.datetime.now()

@ -56,7 +56,6 @@ class ClApplication(WsgiApplication):
#verification of compliance certificate and session (sid)
def check_cert_sid(self, sid, server):
import threading
curthread = threading.currentThread()
cert = curthread.client_cert
from .cert_cmd import find_cert_id
@ -71,8 +70,8 @@ class ClApplication(WsgiApplication):
os.system('mkdir %s' % server.sids)
if not os.path.isfile(server.sids_file):
open(server.sids_file, 'w').close()
with open(server.sids_file, 'r') as fd:
open(server.sids_file, 'wb').close()
with open(server.sids_file, 'rb') as fd:
while 1:
try:
# read all on one record
@ -115,22 +114,23 @@ class ClApplication(WsgiApplication):
return 0
return 1
if (sid and
if (sid is not None and
(method_name in LoadedMethods.rightsMethods or
method_name.endswith('_view') and
method_name[:-5] in LoadedMethods.rightsMethods)):
if not self.check_cert_sid(sid, curthread.server):
return 0
with open(server_cert, 'r') as f:
with open(server_cert, 'rb') as f:
data_server_cert = f.read()
certobj = OpenSSL.crypto.load_certificate(
OpenSSL.SSL.FILETYPE_PEM, data_server_cert)
with open(server_key, 'r') as f:
with open(server_key, 'rb') as f:
data_server_key = f.read()
Pkey = OpenSSL.crypto.load_privatekey(OpenSSL.SSL.FILETYPE_PEM,
data_server_key, 'qqqq')
data_server_key, b'qqqq')
signature = OpenSSL.crypto.sign(Pkey, cert, 'SHA1')
try:
OpenSSL.crypto.verify(certobj, signature, cert, 'SHA1')
@ -143,10 +143,11 @@ class ClApplication(WsgiApplication):
OpenSSL.SSL.FILETYPE_PEM, cert)
try:
com = certobj_cl.get_extension(certobj_cl.get_extension_count() - 1)
groups = com.get_data().split(':')[1]
groups = com.get_data().split(b':')[1].decode("UTF-8")
except IndexError:
groups = ""
except Exception:
except Exception as e:
print(e)
return 0
groups_list = groups.split(',')
# open certificates database
@ -303,9 +304,14 @@ class ClApplication(WsgiApplication):
"""
if (not "wsgi.input" in http_req_env):
return None
# print("DEBUG")
# print(http_req_env)
length = http_req_env.get("CONTENT_LENGTH")
if(not length):
return None
input = http_req_env["wsgi.input"]
body = input.read(int(length))
print(body)
res = re.search(b"<ns.:sid>(.*?)<\/ns.:sid>", body)
#horrbile hack:
#cherrypy provides rfile in req_env which is consumed upon .read() without
@ -336,8 +342,11 @@ class ClApplication(WsgiApplication):
self.create_path()
sid = self.get_sid_from_soap(req_env)
method_name = self.get_method_name_from_http(req_env)
print("DDEBUG")
print("Method name: ", method_name)
print("Sid: ", sid)
if method_name is None:
resp = "Could not extract method name from the request!"
resp = b"Could not extract method name from the request!"
http_resp_headers['Content-Length'] = str(len(resp))
start_response(HTTP_500, http_resp_headers.items())
return [resp]
@ -351,6 +360,7 @@ class ClApplication(WsgiApplication):
curthread.client_cert = None
# check rights client certificate for the method
check = self.check_rights(method_name, req_env, sid)
print("CHECK RIGHT STATUS: ", check)
if not check:
if curthread.client_cert:
certobj = OpenSSL.crypto.load_certificate(
@ -361,13 +371,13 @@ class ClApplication(WsgiApplication):
% (datetime.datetime.now().__str__(),
finger, ip,
method_name[5:]))
resp = "Permission denied: " + method_name
resp = b"Permission denied: " + method_name.encode("UTF-8")
http_resp_headers['Content-Length'] = str(len(resp))
start_response(HTTP_403, http_resp_headers.items())
return [resp]
if sid:
if sid is not None:
curthread.lang = service.get_lang(service, sid, method_name)
if curthread.client_cert:
certobj = OpenSSL.crypto.load_certificate(

@ -35,8 +35,8 @@ class CoreWsdl(CoreServiceInterface):
sid_pid_t = cls.sids_pids + '_temp'
with cls.sid_pid_locker:
fd = open(cls.sids_pids, 'r')
ft = open(sid_pid_t, 'w')
fd = open(cls.sids_pids, 'rb')
ft = open(sid_pid_t, 'wb')
while 1:
try:
# read out on 1 record
@ -47,7 +47,7 @@ class CoreWsdl(CoreServiceInterface):
pickle.dump(list_sid, ft)
else:
# end process pid = list_sid[1]
cls.serv_pid_kill(list_sid[1], sid)
cls.serv_pid_kill(cls, list_sid[1], sid)
# delete this of process file
while cls.glob_process_dict[list_sid[1]]['status'] == 1:
time.sleep(0.1)
@ -83,8 +83,8 @@ class CoreWsdl(CoreServiceInterface):
sid_pid_t = cls.sids_pids + '_temp'
with cls.sid_pid_locker:
fd = open(cls.sids_pids, 'r')
ft = open(sid_pid_t, 'w')
fd = open(cls.sids_pids, 'rb')
ft = open(sid_pid_t, 'wb')
while 1:
try:
# read out on 1 record
@ -112,9 +112,9 @@ class CoreWsdl(CoreServiceInterface):
results = []
with cls.sid_pid_locker:
if not os.path.exists(cls.sids_pids):
temp = open(cls.sids_pids, 'w')
temp = open(cls.sids_pids, 'wb')
temp.close()
fd = open(cls.sids_pids, 'r')
fd = open(cls.sids_pids, 'rb')
while 1:
try:
# read out on 1 record
@ -135,7 +135,7 @@ class CoreWsdl(CoreServiceInterface):
# Check pid presence and conformity sid
with cls.sid_pid_locker:
fd = open(cls.sids_pids, 'r')
fd = open(cls.sids_pids, 'rb')
while 1:
try:
# read out on 1 record
@ -169,10 +169,10 @@ class CoreWsdl(CoreServiceInterface):
"""
with cls.sid_pid_locker:
if not os.path.exists(cls.sids_pids):
with open(cls.sids_pids, 'w'):
with open(cls.sids_pids, 'wb'):
pass
try:
with open(cls.sids_pids, 'a') as fd:
with open(cls.sids_pids, 'ab') as fd:
pickle.dump([sid, pid], fd)
return 0
except (OSError, IOError, KeyError, EOFError):

@ -85,7 +85,6 @@ def make_service(basic_class, wsdl_core_class_list, outer_wsdl_class_list, servi
#for outer wsdl classes, we have to add stateless wrap methods on our own
saved_pub_methods = basic_class.public_methods
functions_to_add = {}
for klass in outer_wsdl_class_list:
for meth in klass.__dict__:

@ -82,7 +82,7 @@ def dbus_stop(process_dict, sids_dn, base_obj):
with base_obj.sid_locker:
for fn in glob.glob("%s/*.sid" % sids_dn):
if os.path.isfile(fn):
with open(fn) as fd:
with open(fn, "rb") as fd:
sid_inf = pickle.load(fd)
# обнаружена рабочая сессия
if sid_inf[2] != 1:

@ -202,7 +202,7 @@ class VariableClCertGroups(Variable):
certobj = OpenSSL.crypto.load_certificate(
OpenSSL.SSL.FILETYPE_PEM, cert)
com = certobj.get_extension(
certobj.get_extension_count() - 1).get_data()
certobj.get_extension_count() - 1).get_data().decode("UTF-8")
groups = com.rpartition(':')[2]
groups_list = groups.split(',')
return groups_list

@ -57,14 +57,18 @@ class VariableClCorePkgName(Variable):
def choice(self):
if self.Get('cl_ebuild_phase'):
return [""]
return [""] + ["all"] + sorted(
set(chain(*map(lambda x: map(
lambda y: (y[0].rpartition('-')[0]
if y[2].startswith('r') else y[0]),
map(lambda y: y.rpartition('-'),
listDirectory(x))),
listDirectory('/var/db/pkg', onlyDir=True,
fullPath=True)))))
# return [""] + ["all"] + sorted(
# set(chain(*map(lambda x: map(
# lambda y: (y[0].rpartition('-')[0]
# if y[2].startswith('r') else y[0]),
# map(lambda y: y.rpartition('-'),
# listDirectory(x))),
# listDirectory('/var/db/pkg', onlyDir=True,
# fullPath=True)))))
return [""] + ["all"] + sorted(set(chain(*(((y[0].rpartition('-')[0]
if y[2].startswith('r') else y[0]) for y
in (z.rpartition('-') for z in listDirectory(x))) for x
in listDirectory('/var/db/pkg', onlyDir=True,fullPath=True)))))
class VariableClCorePkgVersionOpt(Variable):

@ -36,7 +36,7 @@ class VarHelper(object):
'importConsolegui': 'importGui'}
mapObject = {'DataVarsLib': 'DataVars',
'DataVarsConsolegui': 'DataVarsGui'}
mapSection = dict(map(lambda x: (x[1], x[0]), aliases))
mapSection = dict(((x[1], x[0]) for x in aliases))
class VariableClVariableData(TableVariable):
@ -80,6 +80,7 @@ class VariableClVariableData(TableVariable):
res = list(starmap(fix_value_for_append,
starmap(fix_cmdline_params,
value)))
return res
def init(self):
@ -108,13 +109,12 @@ class VariableClVariableModuleName(ReadonlyVariable):
site_packages = [path.join(x, "calculate") for x in sys.path
if (x.endswith('site-packages') and x.startswith('/usr/lib'))]
retlist = []
for module, modDir in chain(
*map(lambda x: map(lambda y: (path.basename(y), y),
listDirectory(x, True, True)),
site_packages)):
for module, modDir in chain(*(((path.basename(y), y) for y
in listDirectory(x, True, True)) for x
in site_packages)):
if path.exists(path.join(modDir, "datavars.py")):
retlist.append(module)
mod_map = {'lib': 0, 'install': 1, 'core': 2}
mod_map = {'lib': "0", 'install': "1", 'core': "2"}
return sorted(retlist, key=lambda x: mod_map.get(x, x))

Loading…
Cancel
Save