Exemplo n.º 1
0
    def __init__(self, model, *args, **kargs):
        super(controllers.Controller, self).__init__(*args, **kargs)
        self.model = model
        self.services = {}
        base = config.get('services.path')
        ServiceProxy.load_locations(config.get('esb.config.path'))

        esb_services = ServiceProxy.get_locations().keys()

        for d in os.listdir(base):
            if d.startswith('.'):
                continue
            spath = os.path.join(base, d)
            if os.path.isdir(spath):
                try:
                    # TODO: Needs support for directory names like
                    # 'service-0.1'.
                    service = self.import_service(base, d)
                    if not service.name in esb_services:
                        continue
                    if service.model:
                        self.model.__dict__.update(service.model.__dict__)
                    self.services[service.name] = service
                except Exception, e:
                    print "Could not import service %s: %s" % (spath, e.message)
Exemplo n.º 2
0
    def __init__(self,
                 certificate,
                 private_key,
                 certificate_chain=None,
                 client_CA=None):
        if SSL is None:
            raise ImportError("You must install pyOpenSSL to use HTTPS.")

        self.context = None
        self.certificate = certificate
        self.private_key = private_key
        self.certificate_chain = certificate_chain
        self.client_CA = client_CA or config.get("server.ssl_client_CA")
        self._environ = None

        self.check_host = config.get("server.ssl_client_check_host", False)
        check = config.get("server.ssl_client_check", "ignore")
        if check == "ignore":
            self.check = SSL.VERIFY_NONE
        elif check == "optional":
            self.check = SSL.VERIFY_PEER
        elif check == "required":
            self.check = SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT
        else:
            raise ValueError("server.ssl_client_check must be one of 'ignore',"
                             "'optional','required'")
Exemplo n.º 3
0
def setup():
  global host, port, address, originalBase
  server.wait()
  
  originalBase = web.baseMeta
  web.baseMeta = model.createBase(TEST_PICKLES, TEST_TEMPLATE)/'web'
  
  host = config.get('server.socket_host') or '127.0.0.1'
  port = config.get('server.socket_port') or '80'  

  address = "http://%s:%s" % (host, port)
Exemplo n.º 4
0
    def default(self, name__, action=None, *args, **kargs):
        if config.get('server.environment') == 'production':
            ip = request.headers['Remote-Addr']
            if ip not in ['::ffff:127.0.0.1']:
                response.status = 300
                return ''

        start_time = time.time()

        response.status = 200
        response.headers['User-Agent'] = 'Idiles Dragonfly Client 1.0'

        if (not name__ in self.services.keys()):
            response.status = 404
            return dict(error=u'Not found: %s' % name__)

        service = self.services[name__].obj

        if action is None and not kargs:
            return dumps(dict(methods=self.services[name__].methods))

        if not action in self.services[name__].methods:
            response.status = 404
            return dumps(dict(error=u"Action not found: %s" % action))

        method = getattr(service, action)

        try:
            resp = dumps(method(**kargs))
        except ValueError, e:
            import traceback
            traceback.print_exc()
            response.status = 200
            resp = dumps(dict(valueerror_=e.message))
Exemplo n.º 5
0
def main():
	"""docstring for main"""

	config.update("config.ini")
	time_interval = config.get('processor.timeout')
	
	db = create_engine("mysql://%s:%s@localhost/%s" % (authwebdb.AUTHWEB_USER, authwebdb.AUTHWEB_PASSWD, authwebdb.AUTHWEB_DB))
	db.echo = False
	metadata = MetaData(db)

	auth_app_table = Table('auth_app', metadata, autoload=True)
	mapper(authwebdb.AuthApp, auth_app_table)
	
	auth_query_table = Table('auth_query', metadata, autoload=True)
	mapper(authwebdb.AuthQuery, auth_query_table, order_by=auth_query_table.created_time)

	session = create_session()

	query_auth_app = session.query(authwebdb.AuthApp)
	authapp = query_auth_app.selectfirst()
	cur_id = authapp.current_query_id

	

	if cur_id != None:
		query_auth_query = session.query(authwebdb.AuthQuery)
		current_query = query_auth_query.get_by(query_id = cur_id)

		
		if current_query.state == authwebdb.QUERY_STATE_PROCESSING:

			conn = MySQLdb.connect(user=authwebdb.AUTHWEB_USER, passwd=authwebdb.AUTHWEB_PASSWD, db=cur_id)
			cursor = conn.cursor()
			query_string = "select count(*) from article;"
			cursor.execute(query_string)
			first_num = int(cursor.fetchone()[0])
			cursor.close()
		
			time.sleep(time_interval)
			
			conn = MySQLdb.connect(user=authwebdb.AUTHWEB_USER, passwd=authwebdb.AUTHWEB_PASSWD, db=cur_id)
			cursor = conn.cursor()
			query_string = "select count(*) from article;"
			cursor.execute(query_string)
			second_num = int(cursor.fetchone()[0])
			cursor.close()
			conn.close()
			
			if first_num == second_num:
				print "Restarting process."
				os.system("cd %s ; %s > /dev/null 2>&1 &" % (os.getcwd(), COMMAND))
		else:
			time.sleep(time_interval)
	else:
		time.sleep(time_interval)
Exemplo n.º 6
0
    def __init__(self, certificate, private_key, certificate_chain=None,
                 client_CA=None):
        if ssl is None:
            raise ImportError("You must install the ssl module to use HTTPS.")
        self.certificate = certificate
        self.private_key = private_key
        self.certificate_chain = certificate_chain
        self.client_CA = client_CA or config.get("server.ssl_client_CA")

        self.check_host = config.get("server.ssl_client_check_host", False)
        check = config.get("server.ssl_client_check", "ignore")
        if check == "ignore":
            self.check = ssl.CERT_NONE
        elif check == "optional":
            self.check = ssl.CERT_OPTIONAL
        elif check == "required":
            self.check = ssl.CERT_REQUIRED
        else:
            raise ValueError("server.ssl_client_check must be one of 'ignore',"
                             "'optional','required'")
Exemplo n.º 7
0
 def beforeMain(self):
     from cherrypy import config, request
     from cherrypy.lib import cptools
     
     if not config.get('staticFilter.on', False):
         return
     
     regex = config.get('staticFilter.match', '')
     if regex:
         import re
         if not re.search(regex, request.path):
             return
     
     filename = config.get('staticFilter.file')
     if not filename:
         staticDir = config.get('staticFilter.dir')
         section = config.get('staticFilter.dir', returnSection=True)
         if section == 'global':
             section = "/"
         section = section.rstrip(r"\/")
         extraPath = request.path[len(section) + 1:]
         extraPath = extraPath.lstrip(r"\/")
         extraPath = urllib.unquote(extraPath)
         filename = os.path.join(staticDir, extraPath)
     
     # If filename is relative, make absolute using "root".
     if not os.path.isabs(filename):
         root = config.get('staticFilter.root', '').rstrip(r"\/")
         if root:
             filename = os.path.join(root, filename)
     
     cptools.serveFile(filename)
Exemplo n.º 8
0
def get(key, default_value=None, return_section=False, path=None):
    """Return config value with setting name given by 'key'.

    If the config setting is unset, return given 'default_value' instead. If
    'return_section' is specified, return the path to the value, instead of the
    value itself. If 'path' is specified, return the the value of the setting
    in the context of the given URL path or below.

    """
    value = config.get(key, default_value, return_section, path)
    if value and key == 'sqlobject.dburi' and os.name == 'nt':
        value = re.sub('///([A-Za-z]):', r'///\1|', value)
    return value
Exemplo n.º 9
0
    def __init__(self,
                 certificate,
                 private_key,
                 certificate_chain=None,
                 client_CA=None):
        if ssl is None:
            raise ImportError("You must install the ssl module to use HTTPS.")
        self.certificate = certificate
        self.private_key = private_key
        self.certificate_chain = certificate_chain
        self.client_CA = client_CA or config.get("server.ssl_client_CA")

        self.check_host = config.get("server.ssl_client_check_host", False)
        check = config.get("server.ssl_client_check", "ignore")
        if check == "ignore":
            self.check = ssl.CERT_NONE
        elif check == "optional":
            self.check = ssl.CERT_OPTIONAL
        elif check == "required":
            self.check = ssl.CERT_REQUIRED
        else:
            raise ValueError("server.ssl_client_check must be one of 'ignore',"
                             "'optional','required'")
Exemplo n.º 10
0
    def __init__(self, certificate, private_key, certificate_chain=None,
                 client_CA=None):
        if SSL is None:
            raise ImportError("You must install pyOpenSSL to use HTTPS.")

        self.context = None
        self.certificate = certificate
        self.private_key = private_key
        self.certificate_chain = certificate_chain
        self.client_CA = client_CA or config.get("server.ssl_client_CA")
        self._environ = None

        self.check_host = config.get("server.ssl_client_check_host", False)
        check = config.get("server.ssl_client_check", "ignore")
        if check == "ignore":
            self.check = SSL.VERIFY_NONE
        elif check == "optional":
            self.check = SSL.VERIFY_PEER
        elif check == "required":
            self.check = SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT
        else:
            raise ValueError("server.ssl_client_check must be one of 'ignore',"
                             "'optional','required'")
Exemplo n.º 11
0
def get(key, default_value=None, return_section=False, path=None):
    """Retrieves a config value"""
    value = config.get(key, default_value, return_section, path)
    if value and key == 'sqlobject.dburi' and os.name == 'nt':
        value = re.sub('///(\w):', '///\\1|', value)
    return value
Exemplo n.º 12
0
def get(key, default_value=None, return_section=False, path=None):
    """Retrieves a config value"""
    value = config.get(key, default_value, return_section, path)
    if value and key == "sqlobject.dburi" and os.name == "nt":
        value = re.sub("///(\w):", "///\\1|", value)
    return value
Exemplo n.º 13
0
def get(key, default_value=None, return_section=False, path=None):
    """Retrieves a config value"""
    value = config.get(key, default_value, return_section, path)
    if value and key == 'sqlobject.dburi' and os.name == 'nt':
        value = re.sub('///(\w):', '///\\1|', value)
    return value