Commit f3bcf511 authored by Gero Müller's avatar Gero Müller
Browse files

fix configuration

parent c2e5ea8e
[global]
# local access only : 127.0.0.1
# local and global access : 0.0.0.0
server.socket_host: "0.0.0.0"
server.socket_port: 4282
server.thread_pool: 10
# reloads the program on script changes
engine.autoreload_on: True
[global]
# solves the redirect-problem when running as a proxy
tools.proxy.on: False
# use base when running in subdirectory
#base: '/vispa'
# set dynamic part seperatly
#base.dynamic: '/vispa'
#base.static: 'http://localhost:8080/'
# local access only : 127.0.0.1
# local and global access : 0.0.0.0
server.socket_host: "0.0.0.0"
server.socket_port: 4282
server.thread_pool: 10
# reloads the program on script changes
engine.autoreload_on: True
# rpc settings
rpc.on: True
rpc.server.verbose: False
rpc.client.verbose: False
# define default workspace id to use.
#rpc.default_workspace_id: 1
# command line to start rpc process. use the variables:
# - $PYTHONPATH
# - $username
# - $userid
# - $python
# - $file
#rpc.wrapper: ['/usr/bin/sudo', 'PYTHONPATH=$PYTHONPATH', '-E', '-u', '$username', '$python', '-u', '$file']
# user registration
# use $username and $userid variables
#user.registration.hook: ['useradd', '$username']
user.registration.autoactive: True
user.registration.mail_hosts: []
user.registration.sendmail: False
user.registration.activation: "http://localhost/activate"
user.registration.forgot: "http://localhost/forgot"
user.registration.smpt_host: "localhost"
#user.registration.smpt_port: 25
extension.ignore: ['workspace']
\ No newline at end of file
......@@ -12,6 +12,12 @@ welcome_text = <center>Welcome to VISPA!</center>
forgot_text = A mail with further instructions will be sent to your mail account!
use_forgot = False
# use base when running in subdirectory
#base: '/vispa'
# set dynamic part seperatly
#base.dynamic: '/vispa'
#base.static: 'http://localhost:8080/'
[websockets]
use_websockets = False
secure_websockets = False
......@@ -27,4 +33,35 @@ post_command_options = -p
[BatchSystem]
# BatchSystem used for submission of jobs
manager = local
#manager = condor
\ No newline at end of file
#manager = condor
[rpc]
verbose: False
# define default workspace id to use.
#default_workspace_id: 1
# command line to start rpc process. use the variables:
# - $PYTHONPATH
# - $username
# - $userid
# - $python
# - $file
#wrapper: ['/usr/bin/sudo', 'PYTHONPATH=$PYTHONPATH', '-E', '-u', '$username', '$python', '-u', '$file']
[user]
# user registration
# use $username and $userid variables
#registration.hook: ['useradd', '$username']
registration.autoactive: True
registration.mail_hosts: []
registration.sendmail: False
registration.activation: "http://localhost/activate"
registration.forgot: "http://localhost/forgot"
registration.smpt_host: "localhost"
#registration.smpt_port: 25
[extensions]
ignore: ['workspace']
# -*- coding: utf-8 -*-
# imports
import os
from optparse import OptionParser
import vispa
from vispa.server import Server
......@@ -16,7 +15,7 @@ def parse_commandline():
"is launched (default: CURRENT_DIR)")
parser.set_defaults(basedir=vispa.abspath())
options, args = parser.parse_args()
options, _args = parser.parse_args()
return options
def run():
......@@ -25,4 +24,4 @@ def run():
if __name__ == "__main__":
run()
\ No newline at end of file
run()
......@@ -5,34 +5,34 @@ import os
import sys
import traceback
try:
import ConfigParser as cp
import ConfigParser as cp
except:
import configparser as cp
import configparser as cp
# returns the absolute dir of files in the project folder
def abspath(*args):
head, tail = os.path.split(__path__[0])
head, _tail = os.path.split(__path__[0])
return os.path.join(head, *args)
class _ConfigParser(cp.SafeConfigParser):
def __call__(self, section, option, default=None):
if config.has_option(section, option):
value = config.get(section, option)
# try to cast boolean values
if value == "True":
return True
elif value == "False":
return False
else:
return value
else:
return default
# setup a config parser for "vispa.ini"
config = cp.SafeConfigParser()
config = _ConfigParser()
config.read(abspath("conf/vispa.ini"))
# provide a better "get" method that doesn't throw errors
# but instead uses the default value directly
def get_entry(section, option, default=""):
if config.has_section(section) and config.has_option(section, option):
value = config.get(section, option)
# try to cast boolean values
if value == "True":
return True
if value == "False":
return False
return value
return default
config.get_entry = get_entry
# a little publish/subscribe system
_callbacks = {}
......
......@@ -8,7 +8,7 @@ from threading import Thread
import json
# use websockets?
USE_SOCKETS = vispa.config.get_entry("websockets", "use_websockets", False)
USE_SOCKETS = vispa.config("websockets", "use_websockets", False)
# subscribers stored as {sessionid: Publisher}
SUBSCRIBERS = {}
# a dict, userid -> sessionids (list)
......
......@@ -54,8 +54,8 @@ class PlatformController(AbstractController):
def index(self, *args, **kwargs):
db = cherrypy.request.db
username = cherrypy.request.user.name
use_websockets = vispa.config.get_entry('websockets', 'use_websockets', False)
secure_websockets = vispa.config.get_entry('websockets', 'secure_websockets', False)
use_websockets = vispa.config('websockets', 'use_websockets', False)
secure_websockets = vispa.config('websockets', 'secure_websockets', False)
profile_id = self.get('profile_id')
preferences = Profile.get_preferences(db, profile_id, create=True)
data = {'username' : username,
......@@ -75,11 +75,11 @@ class PlatformController(AbstractController):
@cherrypy.tools.render(template='sites/login.html')
def login(self, *args, **kwargs):
path = self.requested_path()
welcome_text = vispa.config.get_entry('web', 'welcome_text')
login_text = vispa.config.get_entry('web', 'login_text')
registration_text = vispa.config.get_entry('web', 'registration_text')
forgot_text = vispa.config.get_entry('web', 'forgot_text')
use_forgot = vispa.config.get_entry('web', 'use_forgot', False)
welcome_text = vispa.config('web', 'welcome_text')
login_text = vispa.config('web', 'login_text')
registration_text = vispa.config('web', 'registration_text')
forgot_text = vispa.config('web', 'forgot_text')
use_forgot = vispa.config('web', 'use_forgot', False)
return {'requested_path' : path,
'welcome_text' : welcome_text,
'login_text' : login_text,
......
......@@ -10,7 +10,6 @@ import cherrypy
import vispa
from vispa.models import Base
class User(Base):
INACTIVE = 0
......@@ -112,9 +111,7 @@ class User(Base):
# email valid?
email = email.lower()
valid_hosts = []
if "user.registration.mail_hosts" in cherrypy.config.keys():
valid_hosts = cherrypy.config["user.registration.mail_hosts"]
valid_hosts = vispa.config('user', 'registration.mail_hosts', [])
emailvalid = True
emailparts = email.split("@")
if len(emailparts) != 2:
......@@ -147,14 +144,13 @@ class User(Base):
hash = User.generate_hash(32)
# => register the user
status = User.ACTIVE
if "user.registration.autoactive" in cherrypy.config.keys():
status = User.ACTIVE if cherrypy.config["user.registration.autoactive"] else User.INACTIVE
autoactive = vispa.config('user', 'registration.autoactive', True)
status = User.ACTIVE if autoactive else User.INACTIVE
user = User(name=name, password=password, email=email, hash=hash, status=status)
session.add(user)
# send the registration mail?
if "user.registration.sendmail" in cherrypy.config.keys() and cherrypy.config["user.registration.sendmail"]:
if vispa.config('user', 'registration.sendmail', False):
User.send_registration_mail(name, email, hash)
# we need a commit this time
......@@ -173,9 +169,7 @@ class User(Base):
to_addr = email
subject = "Your Vispa Registration"
response_host = "http://localhost"
if "user.registration.activation" in cherrypy.config.keys():
response_host = cherrypy.config["user.registration.activation"]
response_host = vispa.config('user', 'registration.activation', 'http://localhost')
link = os.path.join(response_host, "?hash=%s" % hash)
msg = "Hi %s!\n\nTo finish your registration for Vispa, click on the link below:\n\n%s\n\nYour Vispa-Team!" % (name, link)
......@@ -183,17 +177,9 @@ class User(Base):
@staticmethod
def send_mail(from_addr, to_addr, subject="", content=""):
smtp_host = "localhost"
if "user.registration.smtp_host" in cherrypy.config.keys():
smtp_host = cherrypy.config["user.registration.smtp_host"]
smtp_port = None
if "user.registration.smtp_port" in cherrypy.config.keys():
smtp_port = cherrypy.config["user.registration.smtp_port"]
if smtp_port:
server = smtplib.SMTP(smtp_host, smtp_port)
else:
server = smtplib.SMTP(smtp_host)
smtp_host = vispa.config('user', 'registration.smtp_host', '127.0.0.1')
smtp_port = vispa.config('user', 'registration.smtp_port', 25)
server = smtplib.SMTP(smtp_host, smtp_port)
head = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (from_addr, to_addr, subject)
......@@ -218,9 +204,7 @@ class User(Base):
to_addr = user.email
subject = "Your Vispa Password"
response_host = "http://localhost"
if "user.registration.forgot" in cherrypy.config.keys():
response_host = cherrypy.config["user.registration.forgot"]
response_host = vispa.config('user', 'registration.forgot', 'http://localhost')
link = os.path.join(response_host, "?hash=%s" % hash)
msg = "Hi %s!\n\nYou requested a password change.\nClick on the link below to select a new one:\n\n%s\n\nYour Vispa-Team!" % (user.name, link)
......
......@@ -51,8 +51,8 @@ class ServerProcess(xmlrpclib.ServerProxy):
host = self._start_local()
else:
host = self._start_remote(workspace_id)
verbose_ = cherrypy.config["rpc.server.verbose"]
xmlrpclib.ServerProxy.__init__(self, host, verbose=False, allow_none=True)
verbose = vispa.config("rpc", "verbose", False)
xmlrpclib.ServerProxy.__init__(self, host, verbose=verbose, allow_none=True)
self.server_address = (self._host, self._port)
def __del__(self):
......@@ -67,10 +67,10 @@ class ServerProcess(xmlrpclib.ServerProxy):
env = os.environ.copy()
env['PYTHONPATH'] = os.pathsep.join(sys.path)
if 'rpc.wrapper' in cherrypy.config:
if vispa.config.has_option('rpc', 'wrapper'):
user = User.get_by_uid(cherrypy.request.db, self.uid)
cmd = []
for arg in cherrypy.config['rpc.wrapper']:
for arg in vispa.config.get('rpc', 'wrapper'):
cmd.append(Template(arg).substitute(username=user.name, userid=user.id, python=python, file=file, PYTHONPATH=env['PYTHONPATH']))
else:
cmd = [python, "-u", file]
......
......@@ -46,27 +46,36 @@ class Server(object):
self.conf_dir = os.path.join(self.base_dir, "conf")
# setup the logging
try:
loggingcfg.fileConfig(os.path.join(self.conf_dir, "logging.conf"))
logging_conf = vispa.abspath("conf", "logging.ini")
if os.path.isfile(logging_conf):
loggingcfg.fileConfig(logging_conf)
cherrypy.log = vispa.log.CherrypyToPythonLogger()
systemlog = logging.getLogger("SYSTEM")
except Exception:
e = sys.exc_info()[1]
cherrypy.log("Error in Logging startup: %s" % str(e))
cherrypy.log("Could not setup logging with 'conf/logging.conf'")
cherrypy.log("Abort startup ...")
sys.exit()
else:
cherrypy.log("No logging.conf found, using default logging.", "SERVER")
# update the global settings for the HTTP server and engine
cherrypy.config.update(os.path.join(self.conf_dir, "server.conf"))
if 'base' in cherrypy.config:
vispa.url.base_dynamic = cherrypy.config['base']
vispa.url.base_static = cherrypy.config['base']
if 'base.dynamic' in cherrypy.config:
vispa.url.base_dynamic = cherrypy.config['base.dynamic']
if 'base.static' in cherrypy.config:
vispa.url.base_static = cherrypy.config['base.static']
server_config = {
'tools.proxy.on': False,
'server.socket_host': '127.0.0.1',
'server.socket_port': 4282,
'server.thread_pool': 10,
'engine.autoreload_on': False
}
cherrypy.config.update(server_config)
cherrypy_conf = vispa.abspath("conf", "cherrypy.ini")
if os.path.isfile(cherrypy_conf):
cherrypy.config.update(cherrypy_conf)
# setup base
if vispa.config.has_option('web', 'base'):
vispa.url.base_dynamic = vispa.config.get('web', 'base')
vispa.url.base_static = vispa.config.get('web', 'base')
if vispa.config.has_option('web', 'base.static'):
vispa.url.base_static = vispa.config.get('web', 'base.static')
if vispa.config.has_option('web', 'base.dynamic'):
vispa.url.base_dynamic = vispa.config.get('web', 'base.dynamic')
if len(vispa.url.base_dynamic) and not vispa.url.base_dynamic.endswith('/'):
vispa.url.base_dynamic += '/'
......@@ -112,7 +121,7 @@ class Server(object):
cherrypy.tools.stats = StatsTool()
# the websocket tool
use_websockets = vispa.config.get_entry("websockets", "use_websockets", False)
use_websockets = vispa.config("websockets", "use_websockets", False)
if use_websockets:
from vispa.tools.socket import WSTool
cherrypy.tools.websocket = WSTool()
......@@ -133,7 +142,7 @@ class Server(object):
'tools.encode.on': False,
'tools.sessions.on': True,
'tools.sessions.storage_type': "file",
'tools.sessions.storage_path': os.path.join(vispa.abspath('var/sessions')),
'tools.sessions.storage_path': vispa.abspath('var', 'sessions'),
'tools.sessions.timeout': 1440,
'tools.staticdir.root': vispa.abspath('static'),
'tools.gzip.on': True,
......@@ -159,9 +168,11 @@ class Server(object):
'tools.staticdir.dir': 'img',
}
}
app = cherrypy.tree.mount(platform.controller, vispa.url.base_dynamic, platform_config)
#self.make_rotate_logs(app)
if os.path.isfile(cherrypy_conf):
app.merge(cherrypy_conf)
# self.make_rotate_logs(app)
# template engine plugin
from vispa.plugins.template import MakoPlugin
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment