master3.3
Спиридонов Денис 12 years ago
parent 19386c3011
commit 2dbe431bde

@ -347,13 +347,13 @@ class ApiWsdl:
import threading
curThread = threading.currentThread()
cert = curThread.client_cert
from cert_cmd import find_cert_id
cert_id = find_cert_id(cert, self.data_path, self.certbase)
cert_id = int(cert_id)
if cert_id == 0:
return 0
# session file
if not os.path.exists(self.sids):
os.system('mkdir %s' %self.sids)
@ -370,7 +370,7 @@ class ApiWsdl:
if cert_id == list_sid[1]:
if sid == list_sid[0]:
check = 1
if check == 0:
return 0
fd = open(self.sids_pids, 'r')
@ -392,7 +392,7 @@ class ApiWsdl:
result = []
while len(self.glob_frame_list[pid]) > \
self.glob_process_dict[pid]['counter']:
item = self.glob_process_dict[pid]['counter']
result.append(self.glob_frame_list[pid][item])
self.glob_process_dict[pid]['counter'] += 1
@ -403,7 +403,7 @@ class ApiWsdl:
if self.check_cert_pid(sid, pid):
return self.process_messages(pid)
return self.perm_denied
# send to client new message from frame
def client_get_entire_frame(self, sid, pid):
if self.check_cert_pid(sid, pid):
@ -415,12 +415,12 @@ class ApiWsdl:
len(self.glob_frame_list[pid])
return results
return self.perm_denied
def client_get_table (self, sid, pid, id):
if self.check_cert_pid(sid, pid):
return self.glob_table_dict[pid][id]
return self.perm_denied
def client_get_progress (self, sid, pid, id):
if self.check_cert_pid(sid, pid):
return self.glob_progress_dict[pid][id]
@ -432,7 +432,7 @@ class ApiWsdl:
self.glob_process_dict[pid]['answer'] = text
return Message (type = 'normal', message = "Password send")
return self.perm_denied
@rpc(Integer, Integer, _returns = Array(Message))
#@Dec.check_permissions()
def get_frame (self, sid, pid):
@ -441,7 +441,7 @@ class ApiWsdl:
@rpc(Integer, Integer, _returns = Array(Message))
def get_entire_frame(self, sid, pid):
return self.client_get_entire_frame (sid, pid)
@rpc(Integer, Integer, Integer, _returns = ReturnProgress)
#@Dec.check_permissions()
def get_progress ( self, sid, pid, id):

@ -66,8 +66,6 @@ import post_cert, cl_unix_useradd, post_request, send_cert, cl_unix_userdel, \
#return self.f(selfobj, *args, **kwargs)
#return wrapper
class Basic (DefinitionBase) :
""" Basic server class """
SERV_VERS = 0.11
@ -77,7 +75,7 @@ class Basic (DefinitionBase) :
glob_progress_dict = {}
glob_table_dict = {}
glob_frame_list = {}
data_path = None
certbase = None
rights = None
@ -87,7 +85,7 @@ class Basic (DefinitionBase) :
ssl_certificate = None
ssl_private_key = None
cachedict = {}
## function getting object from cache
#def get_cache(self, sid, meth_name, obj):
#if sid in self.cachedict:
@ -99,7 +97,7 @@ class Basic (DefinitionBase) :
#setattr(obj, var_name, var_value)
#return obj
#return None
## function placing object in cache
#def set_cache(self, sid, meth_name, obj):
@ -114,7 +112,7 @@ class Basic (DefinitionBase) :
#return True
#except:
#return False
# function getting object from cache
def get_cache(self, sid, meth_name, obj_name):
if sid in self.cachedict:
@ -122,7 +120,7 @@ class Basic (DefinitionBase) :
if obj_name in self.cachedict[sid][meth_name]:
return self.cachedict[sid][meth_name][obj_name]
return None
# function placing object in cache
def set_cache(self, sid, meth_name, obj_name, obj, smart = True):
@ -144,14 +142,14 @@ class Basic (DefinitionBase) :
return True
except:
return False
def clear_cache(self, sid, meth_name = None, obj_name = None):
if not sid in self.cachedict:
return True
if meth_name:
if not meth_name in self.cachedict[sid]:
return True
if obj_name:
if not obj_name in self.cachedict[sid][meth_name]:
return True
@ -167,7 +165,7 @@ class Basic (DefinitionBase) :
obj = self.cachedict.pop(sid, None)
if hasattr (obj, 'close'):
obj.close()
def set_paths (cls, data_path, certbase, serv_certbase, rights, \
group_rights, sids, pids, \
sids_pids, sids_file, pids_file, max_sid, \
@ -188,7 +186,7 @@ class Basic (DefinitionBase) :
Basic.cert_path = cert_path
Basic.max_sid = int(max_sid)
Basic.max_pid = int(max_pid)
#start monitor and sid_monitor threads
monitoring = threading.Thread(target=monitor,\
args = (Basic.certbase, Basic.sids_file))
@ -220,7 +218,7 @@ class Basic (DefinitionBase) :
for pid in self.process_pid.keys():
if self.process_pid[pid].is_alive():
num_active_process += 1
if num_active_process:
sys.stdout.write('.')
sys.stdout.flush()
@ -228,7 +226,7 @@ class Basic (DefinitionBase) :
print '\n' + _('All processes are closed.')
return 0
time.sleep(0.5)
## Cache parameters
#class cache_old:
#def __init__(self,func):
@ -254,7 +252,7 @@ class Basic (DefinitionBase) :
#+list(self.func.func_defaults)):
#self.args[sid][varname] = varvalue
#newargs = []
## addition list of None values
#args = list(args)
@ -271,7 +269,7 @@ class Basic (DefinitionBase) :
#newargs.append(newarg)
#else:
#newargs.append(cachearg[1])
#return self.func(*newargs)
@rpc(String, _returns = String)
@ -284,7 +282,7 @@ class Basic (DefinitionBase) :
#import post_cert
returns = post_cert.serv_post_cert (self)
return returns
@rpc(Integer, _returns = Integer)
def clear_session_cache (self, sid) :
check_sid = self.check_sid_cert(sid)
@ -293,12 +291,12 @@ class Basic (DefinitionBase) :
# clear cache
self.clear_cache(sid)
return 0
@rpc(Integer, Integer, _returns = Integer)
def clear_pid_cache (self, sid, pid) :
if not self.check_sid_cert(sid):
return 1
if pid in self.find_sid_pid_file(sid):
# clear pid cache
self._delete_pid(pid)
@ -325,9 +323,9 @@ class Basic (DefinitionBase) :
@rpc(Integer, _returns = Array(Integer))
def list_pid ( self, sid):
return self.find_sid_pid_file (sid)
@rpc(String, _returns = Array(Array(String)))
def get_methods ( self, client_type) :
def get_methods ( self, client_type):
return self.serv_get_methods (client_type)
@rpc(_returns = Array(String))
@ -340,23 +338,23 @@ class Basic (DefinitionBase) :
#@Dec.check_permissions(["pid_info"])
def pid_info ( self, sid, pid) :
return self.serv_pid_info (sid, pid)
@rpc(Integer, _returns = Array(String))
#@Dec.check_permissions(['sid_info'])
def sid_info ( self, sid) :
return self.serv_sid_info (sid)
@rpc(Integer, _returns = Array(String))
@Dec.check_permissions(["view_cert_right"])
#@Dec.console('view-cert-right')
#@Dec.gui('System')
def view_cert_right ( self, cert_id) :
return self.serv_view_cert_right (cert_id, self.data_path)
@rpc(Integer, _returns = Integer)
def active_client ( self, sid) :
return self.active_clients (sid)
#@rpc(String, String, String, String, \
#_returns = Array( String ))
#def post_client_request ( self, request, ip, mac, client_type) :
@ -369,7 +367,6 @@ class Basic (DefinitionBase) :
#results.append (temp)
#results.append (send_cert.serv_send_cert (num, self.data_path))
#return results
@rpc(String, String, String, String, _returns = String)
def post_client_request ( self, request, ip, mac, client_type) :
@ -382,7 +379,7 @@ class Basic (DefinitionBase) :
res = post_request.serv_get_client_cert (req_id, request,\
self.data_path, self.certbase, self.cert_path)
return res
@rpc(String, String, String, _returns = String)
def post_server_request ( self, request, ip, mac) :
res = post_request.serv_post_server_request (request, self.data_path,\
@ -394,7 +391,7 @@ class Basic (DefinitionBase) :
res = post_request.serv_get_server_request (req_id, request,\
self.data_path, self.serv_certbase, self.cert_path)
return res
@rpc( _returns = String)
def get_crl (self):
if os.path.exists(self.data_path + '/server_certs/ca.crl'):
@ -416,11 +413,11 @@ class Basic (DefinitionBase) :
if subj[0] == 'CN':
return subj[1]
return ''
@rpc(_returns = String)
def get_ca (self):
return send_cert.get_ca(self.cert_path)
@rpc(String, _returns = String)
def cl_unix_userdel ( self, param) :

@ -41,7 +41,7 @@ def init(cert, key, cert_path, data_path, certbase, args, port, user_name):
new_serv_cert = True
else:
print 'Server certificate already exists'
if new_serv_cert or not check_client_cert(user_name):
print 'Generate Client Certificate'
create_client_cert(cert, cert_path, data_path, certbase, user_name)
@ -62,8 +62,7 @@ def check_client_cert(user_name):
path.isfile (client_cert_path + server_host_name + '.key'):
return True
return False
def change_args(args, step = None):
if step == 0:
args.host = False
@ -75,10 +74,10 @@ def change_args(args, step = None):
args.use_root_cert = True
return args
def create_server_cert(cert, key, cert_path, args, port):
cert_cmd.check_server_certificate(cert, key, cert_path, args, port, auto = True)
def create_client_cert(server_cert, cert_path, data_path, certbase, user_name):
client_cert_path = check_user_path(user_name)
if not client_cert_path:
@ -88,7 +87,7 @@ def create_client_cert(server_cert, cert_path, data_path, certbase, user_name):
client_cert_path)
sign_certificate(req_id, cert_path, data_path)
get_certificate(cert_path, data_path, certbase, client_cert_path)
def check_user_path(user_name):
if user_name == 'root':
home_dir = '/root'
@ -104,7 +103,7 @@ def check_user_path(user_name):
if not path.isdir(client_cert_path):
os.makedirs(client_cert_path)
return client_cert_path
def create_request(server_cert, cert_path, data_path, certbase,client_cert_path):
server_host_name = socket.getfqdn()
@ -116,7 +115,7 @@ def create_request(server_cert, cert_path, data_path, certbase,client_cert_path)
ip, mac, client_type = get_ip_mac_type()
data = open(client_req_file).read()
req_id = post_request.serv_post_client_request (data, data_path, ip, mac, \
client_type, certbase, cert_path)
@ -124,14 +123,14 @@ def create_request(server_cert, cert_path, data_path, certbase,client_cert_path)
fc.write(req_id)
fc.close()
return req_id
def sign_certificate(req_id, cert_path, data_path):
cert_cmd.sing_req_by_server(req_id, cert_path, data_path, auto = True)
def get_ip_mac_type():
ip, mac, client_type = get_ip_mac_type('gui')
return (ip, mac, client_type)
def get_certificate(cert_path, data_path, certbase, client_cert_path):
if not os.path.exists(client_cert_path + 'req_id'):
print _("request was not sent or deleted file %s") \
@ -142,7 +141,7 @@ def get_certificate(cert_path, data_path, certbase, client_cert_path):
fc.close()
server_host_name = socket.getfqdn()
if not os.path.exists(client_cert_path + server_host_name + '.csr'):
print _('Request %s not found') %(client_cert_path + server_host_name + '.csr')
return 1
@ -150,7 +149,7 @@ def get_certificate(cert_path, data_path, certbase, client_cert_path):
md5 = hashlib.md5()
md5.update(request)
md5sum = md5.hexdigest()
result = post_request.serv_get_client_cert (req_id, md5sum, data_path, \
certbase, cert_path)
@ -174,7 +173,7 @@ def get_certificate(cert_path, data_path, certbase, client_cert_path):
fc.close()
os.unlink(client_cert_path + 'req_id')
print 'OK. Certificate save. Your certificate id = %s' %req_id
if ca_root:
clVars = DataVarsApi()
clVars.importApi()
@ -183,7 +182,7 @@ def get_certificate(cert_path, data_path, certbase, client_cert_path):
if os.path.exists(system_ca_db):
if ca_root in open(system_ca_db, 'r').read():
return 0
if not path.isdir (client_cert_path + 'ca'):
os.makedirs(client_cert_path + 'ca')
root_cert_md5 = client_cert_path + "ca/cert_list"
@ -193,11 +192,11 @@ def get_certificate(cert_path, data_path, certbase, client_cert_path):
md5sum = md5.hexdigest()
print "\n================================================="
print "md5sum = ", md5sum
if not os.path.exists(root_cert_md5):
fc = open(root_cert_md5,"w")
fc.close()
filename = None
with open(root_cert_md5) as fd:
t = fd.read()
@ -214,20 +213,19 @@ def get_certificate(cert_path, data_path, certbase, client_cert_path):
for item in Issuer:
if item[0] == 'CN':
filename = item[1]
fc = open(root_cert_md5,"a")
fc.write('%s %s\n' %(md5sum, filename))
fc.close()
if not filename:
print _('Not found field "CN" in certificate!')
return 1
fd = open(client_cert_path + 'ca/' + filename, 'w')
fd.write(ca_root)
fd.close()
user_root_cert = client_cert_path + "ca/ca_root.crt"
fa = open(user_root_cert, 'a')
fa.write(ca_root)
@ -243,7 +241,7 @@ def change_owner(pwdObj, user_name):
return 1
else:
home_dir = '/home/' + user_name
for path in os.walk(home_dir + '/.calculate'):
os.chown(path[0], pwdObj.pw_uid, pwdObj.pw_gid)
for file in path[2]:

@ -274,7 +274,9 @@ def main(*args, **keywords):
print _('use cl-api-server with key --gen-cert-by HOST '
'(--get-cert-from HOST) '
'or --use-root-as-server)')
except KeyboardInterrupt:
pass
server.stop()
sys.exit(0)

@ -20,9 +20,9 @@ from soaplib.serializers.primitive import String, Integer, Any, Boolean
from soaplib.serializers.clazz import Array, ClassSerializer
from soaplib.service import rpc, DefinitionBase
from calculate.api.server.api_types import ReturnedMessage
from calculate.api.server.api_types import ChoiceValue, Table, Field, \
GroupField, ViewInfo
GroupField, ViewInfo, ViewParams, \
ReturnedMessage
from calculate.api.server.baseClass import Basic
@ -186,6 +186,12 @@ class ApiWsdl:
errors.append(ReturnedMessage(type = 'error', field = 'boolvariable', \
message = 'Choose this!'))
return errors
if rrr.radiovariable == 'Piter':
errors = []
errors.append(ReturnedMessage(type = 'error', field = 'radiovariable', \
message = 'Do not input "Piter"!'))
return errors
if rrr.CheckOnly:
returnmess = ReturnedMessage(type = '', message = None)
return [returnmess]
@ -230,13 +236,15 @@ class ApiWsdl:
#returnmess.message = pid
return [returnmess]
@rpc(Integer, Integer, Boolean, _returns = ViewInfo)
def test_view (self, sid, step, expert):
print '%%%%%% test_view, step', step
print "expert = ", expert
@rpc(Integer, ViewParams, _returns = ViewInfo)
def test_view (self, sid, vp):
print '%%%%%% test_view, step', vp.step
print "expert = ", vp.expert
step = vp.step
expert = vp.expert
if step == 7:
step = None
if step == 0 or step == -1:
if step in [0, None]:
view = ViewInfo(groups=[])
group = GroupField(name=_("TEST_METHOD"),nextlabel="To step 2",last=False)
@ -293,19 +301,28 @@ class ApiWsdl:
values = [ChoiceValue(
typefield = 'combo',
values = ['/dev/sda1','/dev/sda2','/dev/sda3'],
onChanged = ['nothing',None,'get_body','get_body','get_body','get_body']),
comments = ['disk1','disk2','disk3']),
#onChanged = ['nothing',None,'get_body','get_body',\
#'get_body','get_body']),
ChoiceValue(
typefield = 'comboEdit',
values = ['/','swap','/var/calculate']),
values = ['/','swap','/var/calculate'],
comments = ['root','swap','calc']),
ChoiceValue(
typefield = 'multichoice_add',
values = ['swap','reiserfs','ext4']),
values = ['swap','reiserfs','ext4'],
comments = ['swap1','reiserfs1','ext41']),
ChoiceValue(
typefield = 'check',
values = ['on','off'])]
values = ['on','off']),
ChoiceValue(
typefield = 'text',
values = ['/dev/sda1','/dev/sda2','/dev/sda3'],
comments = ['3Gb','','disk3'])],
)))
group.fields.append(Field(
name = "Steps",
@ -318,7 +335,7 @@ class ApiWsdl:
listvalue = ['go-previous',' ','system-log-out'],
tablevalue = Table(
head = ['Табличка','Второй шаг','Завершение'],
fields = ['calculate','cl-install-gui','calculate'],
fields = ['install','','welcome'],
body = [['times','name','isopath','Partition_table','',\
'boolvariable2','boolvariable', 'combovariable', \
'combovariable2'],\
@ -418,7 +435,7 @@ class ApiWsdl:
#value = 'test_view',
#element = "button"))
if step == 1 or step == -1:
if step in [1, None]:
if not 'view' in locals():
view = ViewInfo(groups=[])
else:
@ -432,7 +449,7 @@ class ApiWsdl:
label = "check city: ",
choice = ['Moscow','Piter','New York','London'],
type = "str",
#value = 'London',
value = 'London',
help = \
"you not human? This is a anti-bot test",
element = "radio"))
@ -465,16 +482,6 @@ class ApiWsdl:
help = \
_("you not human? This is a anti-bot test"),
element = "combo"))
group.fields.append(Field(
name = "multichoice_add",
label = _("check population: "),
choice = ['aa','bb','cc','dd'],
comments = ['America','Bosniya','Chine','Denmark'],
type = "str",
listvalue = ['bb','cc'],
help = \
_("you not human? This is a anti-bot test"),
element = "multichoice_add"))
group.fields.append(Field(
name = "multichoice",
label = _("check population: "),
@ -526,6 +533,17 @@ class ApiWsdl:
"you not human? This is a anti-bot test",
value = 'open',
element = "expert"))
group.fields.append(Field(
name = "multichoice_add",
label = _("check population: "),
choice = ['aa','bb','cc','dd'],
comments = ['America','Bosniya','Chine','Denmark'],
type = "str",
listvalue = ['bb','cc'],
default = True,
help = \
_("you not human? This is a anti-bot test"),
element = "selecttable_add"))
else:
group.fields.append(Field(
name = "expert_close",
@ -535,7 +553,7 @@ class ApiWsdl:
"you not human? This is a anti-bot test",
value = 'close',
element = "expert"))
if step == 2 or step == -1:
if step in [2, None]:
if not 'view' in locals():
view = ViewInfo(groups=[])
else:
@ -566,7 +584,15 @@ class ApiWsdl:
help = \
"you not human? This is a anti-bot test",
element = "combo"))
if step == None:
if not 'view' in locals():
view = ViewInfo(groups=[])
else:
view.groups.append(group)
group = GroupField(name=_("Empty group"),last=True)
group.fields = []
view.groups.append(group)
return view

Loading…
Cancel
Save