parent
9bf96abf76
commit
a605747786
@ -0,0 +1,480 @@
|
||||
#!/usr/bin/python
|
||||
#-*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2012 Calculate Ltd. http://www.calculate-linux.org
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from suds import WebFault
|
||||
from suds.transport import TransportError
|
||||
|
||||
from calculate.api.client.client_class import Client_suds
|
||||
import traceback as tb
|
||||
import time, logging
|
||||
import os
|
||||
import re, threading
|
||||
from calculate.api.client.function import *
|
||||
from calculate.api.client.pid_information import *
|
||||
from calculate.api.client.cert_func import *
|
||||
from calculate.api.client.cert_verify import get_CRL
|
||||
from calculate.api.client.sid_func import *
|
||||
|
||||
from calculate.lib.cl_datavars import ClDataVars
|
||||
from calculate.api.cl_api import DataVarsApi
|
||||
|
||||
from calculate.api.client.client_class import HTTPSClientCertTransport
|
||||
|
||||
t = time
|
||||
|
||||
help_ = '''
|
||||
useradd, cl-unix-useradd - add unix user
|
||||
|
||||
template, cl_template - overlay templates
|
||||
|
||||
halt, server_shutdown - shutdown server
|
||||
|
||||
run, server_start - start server
|
||||
|
||||
---- process methods ----
|
||||
|
||||
lsp, list-pid - listing all pids for this session
|
||||
|
||||
pi, pid-info - get information about select pid (0 for all)
|
||||
|
||||
kill, pid-kill - kill select pid
|
||||
|
||||
---- sessions methods ----
|
||||
|
||||
lss, list-session - listing all sessions in server
|
||||
|
||||
si, session-info - get information about select session (sid)
|
||||
|
||||
lsr, list-method - listing all accessible methods
|
||||
|
||||
q, quit - exit
|
||||
|
||||
h, help - display this help and exit
|
||||
|
||||
v, version - output version information and exit'''
|
||||
|
||||
def client_login (client):
|
||||
login = raw_input ("Login: ")
|
||||
password = raw_input ("password: ")
|
||||
try:
|
||||
name_re = re.compile("[^a-zA-Z_]")
|
||||
if name_re.findall(login):
|
||||
print _("input error")
|
||||
return 2
|
||||
print client.service.cl_login(login = login, password = password)
|
||||
except (Exception) , e:
|
||||
sys.stdout.flush()
|
||||
for i in e.message:
|
||||
sys.stdout.write(str(i) + ' ')
|
||||
|
||||
def client_useradd (client):
|
||||
user_name = raw_input ("User name: ")
|
||||
try:
|
||||
name_re = re.compile("[^a-zA-Z_]")
|
||||
if name_re.findall(user_name):
|
||||
print _("input error")
|
||||
return 2
|
||||
print client.service.cl_unix_useradd(param = user_name)
|
||||
except:
|
||||
print _("create error")
|
||||
|
||||
def client_userdel (client):
|
||||
user_name = raw_input ("User name: ")
|
||||
try:
|
||||
name_re = re.compile("[^a-zA-Z_]")
|
||||
if name_re.findall(user_name):
|
||||
print _("input error")
|
||||
return 2
|
||||
print client.service.cl_unix_userdel(param = user_name)
|
||||
except:
|
||||
print _("deleted error")
|
||||
|
||||
def client_shut (client):
|
||||
try:
|
||||
temp = client.service.server_shutdown()
|
||||
if ( temp == 1):
|
||||
print _("Server shutting down...")
|
||||
except:
|
||||
print _("Connection error! ")
|
||||
return 1
|
||||
|
||||
def client_signal(client):
|
||||
Vars = DataVarsApi()
|
||||
Vars.importApi()
|
||||
Vars.flIniFile()
|
||||
try:
|
||||
client_active = Vars.Get('cl_api_client_active_period')
|
||||
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
|
||||
try:
|
||||
reply = client.service.active_client(sid)
|
||||
except:
|
||||
print _('no connection to server!')
|
||||
sys.exit()
|
||||
time.sleep(float(client_active))
|
||||
|
||||
|
||||
#url = 'http://localhost:8888/TestService/?wsdl'
|
||||
def test(client, com=None):
|
||||
if not com:
|
||||
method_name = 'test'
|
||||
else:
|
||||
method_name = com
|
||||
view = client.service[0][method_name + '_view']()
|
||||
#print '==>', view
|
||||
|
||||
cr = create_obj(client, method_name)
|
||||
#print 'ddd',cr
|
||||
#print type (cr)
|
||||
list_param = dir (cr)
|
||||
|
||||
param_list = []
|
||||
for param in list_param:
|
||||
if not param.startswith('_'):
|
||||
param_list.append(param)
|
||||
|
||||
for Group in view.groups.GroupField:
|
||||
print "GroupField name : ", Group.name
|
||||
|
||||
for field in Group.fields.Field:
|
||||
if field.element == 'input':
|
||||
if field.type == 'str':
|
||||
cr[field.name] = raw_input(field.label)
|
||||
if field.type == 'int':
|
||||
while True:
|
||||
try:
|
||||
var = raw_input(field.label)
|
||||
cr[field.name] = int (var)
|
||||
break
|
||||
except (TypeError, ValueError):
|
||||
print 'Это не целое число'
|
||||
elif field.element == 'bool':
|
||||
while 1:
|
||||
bool_var = raw_input(field.label+' (y/n): ')
|
||||
if bool_var.lower() in ['y','yes']:
|
||||
cr[field.name] = True
|
||||
break
|
||||
if bool_var.lower() in ['n','no']:
|
||||
cr[field.name] = False
|
||||
break
|
||||
print _('Enter "Yes" or "No"!')
|
||||
|
||||
elif field.element == 'check':
|
||||
choice = field.choice[0]
|
||||
while 1:
|
||||
print _('Select one: ')
|
||||
for i in range(1,len(choice)+1):
|
||||
print choice[i-1], ' - %d' %i
|
||||
try:
|
||||
bool_var = int (raw_input(field.label))
|
||||
if bool_var > 0:
|
||||
cr[field.name] = choice[bool_var - 1]
|
||||
print 'your choice %s' %cr[field.name]
|
||||
break
|
||||
except:
|
||||
pass
|
||||
|
||||
#field.choice
|
||||
#print field.help
|
||||
|
||||
sid = get_sid(client.SID_FILE)
|
||||
s = client.service[0][method_name](sid, cr)
|
||||
analysis(client, sid, s)
|
||||
|
||||
import argparse
|
||||
|
||||
def parse():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'-l', '--lang', type=str, dest='lang',
|
||||
help=_('language for translate'))
|
||||
parser.add_argument(
|
||||
'-p', '--port', type=int, default = '8888', dest='port',
|
||||
help=_('port number'))
|
||||
#parser.add_argument(
|
||||
#'--script', type=str, default = '/Server', dest='script_name',
|
||||
#help='name script in server')
|
||||
parser.add_argument(
|
||||
'--host', type=str, default = 'localhost', dest='host',
|
||||
help=_('host destination'))
|
||||
parser.add_argument(
|
||||
'--gen-cert-by', type=str, dest='by_host',
|
||||
help=_('post request a signed certificate by server'))
|
||||
parser.add_argument(
|
||||
'--get-cert-from', type=str, dest='from_host',
|
||||
help=_('get signed certificate from server'))
|
||||
parser.add_argument(
|
||||
'--cert-path', type=str,
|
||||
default = '~/.calculate/client_cert/',
|
||||
nargs ='?', dest='path_to_cert',
|
||||
help=_('path to cert and key file'))
|
||||
return parser.parse_args()
|
||||
|
||||
def https_server(client, signaling):
|
||||
global url
|
||||
client_post_auth(client)
|
||||
signaling.start()
|
||||
client_list_methods(client)
|
||||
|
||||
get_entire_frame(client)
|
||||
#create_obj(client, "install_system")
|
||||
while True:
|
||||
try:
|
||||
command = raw_input ('\n'+_("Command: "))
|
||||
except KeyboardInterrupt, e:
|
||||
print
|
||||
sys.exit()
|
||||
if (command == 'halt' or command == 'server_shutdown'):
|
||||
client_shut(client)
|
||||
|
||||
#elif (command == 'say_hello' or command == 'say'):
|
||||
#client_say_hello(client)
|
||||
|
||||
#elif (command == 'say_hello2' or command == 'say2'):
|
||||
#client_say_hello2(client)
|
||||
|
||||
elif (command == 'server_start' or command == 'run'):
|
||||
if os.path.exists(client.CERT_KEY) and\
|
||||
os.path.exists(client.CERT_FILE) :
|
||||
client = Client_suds(url,\
|
||||
transport = HTTPSClientCertTransport(client.CERT_KEY,\
|
||||
client.CERT_FILE))
|
||||
#If the certificate file misses
|
||||
else:
|
||||
CERT_FILE = None
|
||||
CERT_KEY = None
|
||||
client = Client_suds(url,\
|
||||
transport = HTTPSClientCertTransport(CERT_KEY, CERT_FILE))
|
||||
|
||||
elif (command == 'login' or command == 'cl-login'):
|
||||
client_login(client)
|
||||
|
||||
elif (command == 'useradd' or command == 'cl-unix-useradd'):
|
||||
client_useradd(client)
|
||||
|
||||
elif (command == 'sid-del' or command == 'del-sid'):
|
||||
client_del_sid(client)
|
||||
|
||||
elif (command == 'lsp' or command == 'list-pid'):
|
||||
client_list_pid(client)
|
||||
|
||||
elif (command == 'ins' or command == 'install'):
|
||||
client_install(client)
|
||||
|
||||
elif (command == 'lsr' or command == 'list-method'\
|
||||
or command == 'list-right'):
|
||||
client_list_methods(client)
|
||||
|
||||
elif (command == 'lss' or command == 'list-session'\
|
||||
or command == 'sls'):
|
||||
client_list_sessions(client)
|
||||
|
||||
elif (command == 'pi' or command == 'pid-info'):
|
||||
client_pid_info(client)
|
||||
|
||||
elif (command == 'si' or command == 'session-info'):
|
||||
client_session_info(client)
|
||||
|
||||
elif (command == 'kill' or command == 'pid-kill'):
|
||||
client_pid_kill(client)
|
||||
|
||||
elif (command == 'userdel' or command == 'cl-unix-userdel'):
|
||||
client_userdel(client)
|
||||
|
||||
elif (command == 'vcr' or command == 'view-cert-right'):
|
||||
client_view_cert_right(client)
|
||||
|
||||
elif command.split(' ',1)[0] in ['t', 'template', 'cl-template']:
|
||||
#client_template(client, command)
|
||||
test(client, 'cl_template')
|
||||
|
||||
elif command.lower() in ['test']:
|
||||
test(client)
|
||||
|
||||
elif (command == 'help' or command == 'h'):
|
||||
print help_
|
||||
|
||||
elif command in ['q', 'quit', 'exit']:
|
||||
print _("Closing\n")
|
||||
signaling._Thread__stop()
|
||||
time.sleep(0.3)
|
||||
num = client_list_pid(client)
|
||||
if num:
|
||||
print _('at closing session, '
|
||||
'data %d processes will be deleted!' %num)
|
||||
c = raw_input (_("Close your session y/[n]: "))
|
||||
if c in ['y', 'yes', 'Y', 'YES']:
|
||||
client_del_sid(client)
|
||||
#signaling.killed = True
|
||||
# client_shut(client)
|
||||
return 0
|
||||
else:
|
||||
print _("Input Error")
|
||||
#t.sleep(1)
|
||||
|
||||
#def http_server(client):
|
||||
#pass
|
||||
|
||||
def translate(lang = None):
|
||||
import locale
|
||||
import gettext
|
||||
|
||||
if lang:
|
||||
try:
|
||||
language = gettext.translation ('calculate_api', languages = [lang])
|
||||
language.install()
|
||||
return 0
|
||||
except:
|
||||
print _("lang %s not supported!") %str(lang)
|
||||
|
||||
try:
|
||||
current_locale, encoding = locale.getdefaultlocale()
|
||||
|
||||
language = gettext.translation ('calculate_api', \
|
||||
languages = [current_locale] )
|
||||
language.install()
|
||||
|
||||
print "set translate", current_locale
|
||||
return 0
|
||||
except:
|
||||
language = gettext.translation ('calculate_api', languages = ['en'] )
|
||||
language.install()
|
||||
return 0
|
||||
|
||||
def main():
|
||||
clear()
|
||||
#password = getpass(prompt="Password: ")
|
||||
logging.basicConfig(level=logging.FATAL)
|
||||
logging.getLogger('suds.client').setLevel(logging.FATAL)
|
||||
logging.getLogger('suds.transport').setLevel(logging.FATAL)
|
||||
logging.getLogger('suds.transport.http').setLevel(logging.FATAL)
|
||||
|
||||
#fmt = '%(asctime)s [%(levelname)s] %(funcName)s() @%(filename)s:%(lineno)d\n%(message)s\n'
|
||||
#logging.basicConfig(level=logging.INFO, format=fmt)
|
||||
|
||||
logging.getLogger('suds.umx.typed').setLevel(logging.ERROR)
|
||||
|
||||
|
||||
clVars = ClDataVars()
|
||||
clVars.flIniFile()
|
||||
homePath = clVars.Get('ur_home_path')
|
||||
|
||||
print _('path to cert and key file')
|
||||
args = parse()
|
||||
|
||||
# translate
|
||||
if args.lang:
|
||||
translate(args.lang)
|
||||
|
||||
port = args.port
|
||||
host = args.host
|
||||
path_to_cert = args.path_to_cert
|
||||
path_to_cert = path_to_cert.replace("~",homePath)
|
||||
|
||||
getCRL = threading.Thread(target=get_CRL, args = (path_to_cert, ))
|
||||
getCRL.start()
|
||||
|
||||
if args.by_host:
|
||||
client_post_request (path_to_cert, args)
|
||||
return 0
|
||||
if args.from_host:
|
||||
client_get_cert (path_to_cert, args)
|
||||
return 0
|
||||
|
||||
url = "https://%s:%d/?wsdl" %(host, port)
|
||||
print "url = %s" %url
|
||||
#try:
|
||||
client = Client_suds(url, \
|
||||
transport = HTTPSClientCertTransport(None,None, path_to_cert))
|
||||
server_host_name = client.service.get_server_host_name()
|
||||
del (client)
|
||||
#except Exception, e:
|
||||
#print 'get host name error', e
|
||||
##print _("Connection Error. Failure verification server.")
|
||||
#sys.exit()
|
||||
try:
|
||||
import glob
|
||||
all_cert_list = glob.glob(path_to_cert + '*.crt')
|
||||
fit_cert_list = []
|
||||
|
||||
for client_cert_path in all_cert_list:
|
||||
client_cert = client_cert_path.replace(path_to_cert, '')
|
||||
client_cert_name = client_cert.replace('.crt', '')
|
||||
if server_host_name.endswith(client_cert_name):
|
||||
fit_cert_list.append(client_cert_name)
|
||||
fit_cert_list.sort(key = len)
|
||||
Connect_Error = 1
|
||||
for i in range (0, len(fit_cert_list)):
|
||||
#print 'fit_cert_list = ',fit_cert_list
|
||||
cert_name = fit_cert_list.pop()
|
||||
CERT_FILE = path_to_cert + cert_name + '.crt'
|
||||
CERT_KEY = path_to_cert + cert_name + '.key'
|
||||
print "cert_name = ",cert_name
|
||||
try:
|
||||
client = Client_suds(url,\
|
||||
transport = HTTPSClientCertTransport(CERT_KEY, CERT_FILE,\
|
||||
path_to_cert))
|
||||
client.set_parameters (path_to_cert, CERT_FILE, CERT_KEY)
|
||||
client_post_cert(client)
|
||||
Connect_Error = 0
|
||||
except VerifyError, e:
|
||||
print e.value
|
||||
Connect_Error = 1
|
||||
except Exception, e:
|
||||
print e
|
||||
Connect_Error = 1
|
||||
#sys.exit()
|
||||
if Connect_Error == 0:
|
||||
break
|
||||
#If the certificate file misses
|
||||
if Connect_Error:
|
||||
CERT_FILE = None
|
||||
CERT_KEY = None
|
||||
client = Client_suds(url,\
|
||||
transport = HTTPSClientCertTransport(CERT_KEY, CERT_FILE,\
|
||||
path_to_cert))
|
||||
|
||||
client.set_parameters (path_to_cert, CERT_FILE, CERT_KEY)
|
||||
|
||||
Vars = DataVarsApi()
|
||||
Vars.importApi()
|
||||
Vars.flIniFile()
|
||||
try:
|
||||
client.frame_period = Vars.Get('cl_api_get_frame_period')
|
||||
except:
|
||||
client.frame_period = 2
|
||||
|
||||
signaling = threading.Thread(target=client_signal, args = (client, ))
|
||||
signaling.setDaemon(True)
|
||||
https_server(client, signaling)
|
||||
#----------------------------------------------------
|
||||
except WebFault, f:
|
||||
print _("Exception: %s") %f
|
||||
print f.fault
|
||||
except TransportError, te:
|
||||
print _("Exception: %s") %te
|
||||
except Exception, e:
|
||||
print _("Exception: %s") %e
|
||||
tb.print_exc()
|
@ -0,0 +1,288 @@
|
||||
#!/usr/bin/python
|
||||
#-*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2012 Calculate Ltd. http://www.calculate-linux.org
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys, os
|
||||
import socket, ssl
|
||||
from cherrypy.wsgiserver import CherryPyWSGIServer, WSGIPathInfoDispatcher
|
||||
from cherrypy.wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter
|
||||
from OpenSSL.SSL import Error as SSLError
|
||||
from OpenSSL import SSL
|
||||
import OpenSSL
|
||||
import importlib
|
||||
from signal import SIGTERM
|
||||
import threading
|
||||
|
||||
from calculate.lib.cl_datavars import ClDataVars
|
||||
from calculate.api.cl_api import DataVarsApi
|
||||
|
||||
from calculate.api.server.clean import clean
|
||||
import calculate.api.server.cert_cmd as cert_cmd
|
||||
|
||||
from calculate.api.server.func import initialization
|
||||
from calculate.api.server.server_class import ClApplication
|
||||
|
||||
class OpenSSLAdapter (pyOpenSSLAdapter):
|
||||
|
||||
#def check_cert(self, cert):
|
||||
#if cert == None:
|
||||
#return -1
|
||||
#cert_id = 0
|
||||
|
||||
#from func import find_cert_id
|
||||
#find_cert_id(cert, self.data_path, self.certbase)
|
||||
## open database with certificates
|
||||
|
||||
#if not os.path.exists(self.certbase):
|
||||
#fc = open(self.certbase,"w")
|
||||
#fc.close()
|
||||
#fc = open(self.certbase,"r")
|
||||
|
||||
#while 1:
|
||||
#try:
|
||||
## read all on one record
|
||||
#cert_dict = pickle.load(fc)
|
||||
#except:
|
||||
#break
|
||||
## if input and cert from database equal
|
||||
#if cert == cert_dict["cert"]:
|
||||
## get certificate id
|
||||
#cert_id = cert_dict["Id"]
|
||||
#fc.close()
|
||||
#return cert_id
|
||||
|
||||
def verify_func(self, connection, x509, errnum, errdepth, ok):
|
||||
# get client certificate
|
||||
curThread = threading.currentThread()
|
||||
#print '#######################',errdepth,'####################################'
|
||||
#if not OpenSSL.crypto.dump_certificate \
|
||||
#(OpenSSL.crypto.FILETYPE_PEM, x509) in self.ca_certs:
|
||||
#print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
|
||||
#return 0
|
||||
if errdepth == 0:
|
||||
curThread.client_cert = OpenSSL.crypto.dump_certificate \
|
||||
(OpenSSL.crypto.FILETYPE_PEM, x509)
|
||||
cert = OpenSSL.crypto.load_certificate(OpenSSL.SSL.FILETYPE_PEM,
|
||||
curThread.client_cert)
|
||||
subject = cert.get_subject()
|
||||
|
||||
if ok:
|
||||
try:
|
||||
country = len (subject.get_components()) - 1
|
||||
language = 1
|
||||
curThread.lang = subject.get_components()[country][language]
|
||||
except:
|
||||
curThread.lang = "En"
|
||||
return ok
|
||||
|
||||
def get_context(self):
|
||||
"""Return an SSL.Context from self attributes."""
|
||||
# See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442473
|
||||
|
||||
c = SSL.Context(SSL.SSLv23_METHOD)
|
||||
c.use_privatekey_file(self.private_key)
|
||||
c.set_verify(SSL.VERIFY_PEER, self.verify_func)
|
||||
#self.ca_certs = open('/etc/calculate/ca/ca_root.crt','r').read()
|
||||
|
||||
if self.certificate_chain:
|
||||
c.load_verify_locations(self.certificate_chain)
|
||||
|
||||
c.use_certificate_file(self.certificate)
|
||||
return c
|
||||
|
||||
def main(*args, **keywords):
|
||||
# For cleaning of sessions at server reboot
|
||||
args = cert_cmd.parse()
|
||||
|
||||
# translate
|
||||
if args.lang:
|
||||
translate(args.lang)
|
||||
|
||||
debug = args.debug
|
||||
|
||||
import logging
|
||||
import logging.handlers
|
||||
|
||||
if not os.path.exists('/var/log/calculate'):
|
||||
os.makedirs('/var/log/calculate')
|
||||
LOG_FILENAME = '/var/log/calculate/logging_cl_api_server.out'
|
||||
file_logger = logging.getLogger('MyLogger')
|
||||
file_logger.setLevel(logging.DEBUG)
|
||||
|
||||
# Add the log message handler to the logger
|
||||
handler = logging.handlers.RotatingFileHandler(
|
||||
LOG_FILENAME, maxBytes=10000000, backupCount=3)
|
||||
|
||||
file_logger.addHandler(handler)
|
||||
|
||||
# debug
|
||||
if debug:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger('soaplib.wsgi')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
port = args.port
|
||||
ob = DataVarsApi()
|
||||
ob.importApi()
|
||||
|
||||
# set var env
|
||||
ob.flIniFile()
|
||||
cl_wsdl = ob.Get('cl_wsdl')
|
||||
data_path = ob.Get('cl_api_data')
|
||||
certbase = ob.Get('cl_api_database')
|
||||
serv_certbase = ob.Get('cl_api_serv_database')
|
||||
rights = ob.Get('cl_api_rights')
|
||||
group_rights = ob.Get('cl_api_group_rights')
|
||||
sids = ob.Get('cl_api_sids_path')
|
||||
pids = ob.Get('cl_api_pids_path')
|
||||
sids_pids = ob.Get('cl_api_sids_pids')
|
||||
sids_file = ob.Get('cl_api_sids_file')
|
||||
pids_file = ob.Get('cl_api_pids_file')
|
||||
max_sid = ob.Get('cl_api_max_sid')
|
||||
max_pid = ob.Get('cl_api_max_pid')
|
||||
cert_path = ob.Get('cl_api_cert_path')
|
||||
cert = ob.Get('cl_api_cert')
|
||||
key = ob.Get('cl_api_key')
|
||||
|
||||
# delete all sid and pid informations file
|
||||
clean(sids_file, pids_file, sids_pids, sids, pids)
|
||||
|
||||
cert_cmd.create_path(data_path, certbase)
|
||||
#####################
|
||||
''' view information about client certificates '''
|
||||
if args.revoke_cert_id:
|
||||
cert_cmd.revoke_signed_cert(args.revoke_cert_id, data_path, cert_path)
|
||||
return 0
|
||||
if args.host or args.gen_root_cert or args.root_host or args.use_root_cert:
|
||||
cert_cmd.check_server_certificate(cert, key, cert_path, args, port)
|
||||
return 0
|
||||
if args.id_client_req:
|
||||
cert_cmd.sing_req_by_server(args, cert_path, data_path)
|
||||
return 0
|
||||
if args.Id:
|
||||
cert_cmd.view_cert(args, certbase, data_path, rights, group_rights)
|
||||
return 0
|
||||
if args.cert_id:
|
||||
cert_cmd.view_signed_cert(args, serv_certbase, data_path)
|
||||
return 0
|
||||
if args.req_id:
|
||||
cert_cmd.view_client_request(args, certbase, data_path)
|
||||
return 0
|
||||
# Sign request by root certificate
|
||||
if args.id_server_req:
|
||||
cert_cmd.sing_req_by_root(args, cert_path, data_path)
|
||||
return 0
|
||||
if args.id_del_req:
|
||||
cert_cmd.del_request(args, serv_certbase, data_path)
|
||||
return 0
|
||||
|
||||
#####################
|
||||
|
||||
# importing other modules
|
||||
other_mod = initialization(cl_wsdl)
|
||||
#try:
|
||||
pack = "calculate.api.server"
|
||||
func_metaclass = importlib.import_module('%s.func_metaclass' %pack)
|
||||
|
||||
other_mod.append(func_metaclass.Func_MetaClass)
|
||||
|
||||
from calculate.api.server.cl_vers_api import VERS
|
||||
other_mod.append(VERS)
|
||||
|
||||
from calculate.api.server.baseClass import Basic
|
||||
other_mod.append(Basic)
|
||||
other_mod.append(object)
|
||||
# make server metaclass
|
||||
CombinedServerClass = type ("CombinedServerClass", tuple(other_mod), {})
|
||||
|
||||
App = ClApplication([CombinedServerClass],'tns', log = file_logger)
|
||||
tc = App.get_service(CombinedServerClass)
|
||||
# set all path
|
||||
tc.set_paths (data_path, certbase, serv_certbase, rights, group_rights, \
|
||||
sids, pids, sids_pids, sids_file, pids_file, max_sid, \
|
||||
max_pid, cert_path, cert, key)
|
||||
|
||||
max_num = 99999999
|
||||
dispatcher = WSGIPathInfoDispatcher( { '' : App } )
|
||||
server = CherryPyWSGIServer(('0.0.0.0', port), dispatcher,\
|
||||
numthreads = 10, max = max_num, request_queue_size = max_num)
|
||||
|
||||
print _("listening to https://0.0.0.0:%d") % (port)
|
||||
print _("wsdl is at: https://0.0.0.0:%d/?wsdl") %(port)
|
||||
|
||||
ca_cert = "/etc/calculate/ca/ca_root.crt"
|
||||
if not os.path.exists (ca_cert):
|
||||
ca_cert = None
|
||||
|
||||
#sslAdapter = OpenSSLAdapter(cert, key, cert)#"/etc/calculate/ca/ca_root.crt")
|
||||
sslAdapter = OpenSSLAdapter(cert, key, ca_cert)
|
||||
|
||||
sslAdapter.certbase = certbase
|
||||
#sslAdapter.App = App
|
||||
#sslAdapter.ClApplication = ClApplication
|
||||
|
||||
server.ssl_adapter = sslAdapter
|
||||
server.certbase = certbase
|
||||
server.serv_certbase = serv_certbase
|
||||
server.rights = rights
|
||||
server.group_rights = group_rights
|
||||
server.sids = sids
|
||||
server.pids = pids
|
||||
server.data_path = data_path
|
||||
server.cert_path = cert_path
|
||||
|
||||
server.ssl_certificate = cert
|
||||
server.ssl_private_key = key
|
||||
|
||||
try:
|
||||
print _("Server start")
|
||||
server.start()
|
||||
except KeyboardInterrupt, SIGTERM:
|
||||
print _("\nServer stopping")
|
||||
server.stop()
|
||||
sys.exit(0)
|
||||
except socket.error, e:
|
||||
print e
|
||||
except SSLError, e:
|
||||
print '\n',_('Server certificate not found')#, e
|
||||
print _('use cl-api-server with key --gen-cert-by HOST '
|
||||
'(--get-cert-from HOST) '
|
||||
'or --use-root-as-server)')
|
||||
|
||||
def translate(lang = None):
|
||||
import locale
|
||||
import gettext
|
||||
|
||||
if lang:
|
||||
try:
|
||||
language = gettext.translation ('calculate_api', languages = [lang])
|
||||
language.install()
|
||||
return 0
|
||||
except:
|
||||
print "lang %s not supported!" %str(lang)
|
||||
|
||||
try:
|
||||
current_locale, encoding = locale.getdefaultlocale()
|
||||
|
||||
language = gettext.translation ('calculate_api', \
|
||||
languages = [current_locale] )
|
||||
language.install()
|
||||
return 0
|
||||
except:
|
||||
language = gettext.translation ('calculate_api', languages = ['en'] )
|
||||
language.install()
|
||||
return 0
|
||||
#print _("set locale"), current_locale
|
Binary file not shown.
Loading…
Reference in new issue