westferry.conf.sample
westferry_PYTHON = \
- src/westferry/__init__.py
+ src/westferry/__init__.py \
+ src/westferry/application.py \
+ src/westferry/services.py
westferrydir = $(pythondir)/westferry
westferry_backenddir = $(pythondir)/westferry/backend
+westferry_handlers_PYTHON = \
+ src/westferry/handlers/__init__.py \
+ src/westferry/handlers/base.py \
+ src/westferry/handlers/index.py
+
+westferry_handlersdir = $(pythondir)/westferry/handlers
+
+westferry_ui_PYTHON = \
+ src/westferry/ui/__init__.py \
+ src/westferry/ui/base.py
+
+westferry_uidir = $(pythondir)/westferry/ui
+
# ------------------------------------------------------------------------------
if ENABLE_MANPAGES
src/westferry/backend/__version__.py
+src/westferry/handlers/base.py
src/westferry/__init__.py
+#!/usr/bin/python3
+###############################################################################
+# #
+# Westferry - The IPFire web user interface #
+# Copyright (C) 2015 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+import westferry
+
+s = westferry.services.WebService()
+s.run()
+#!/usr/bin/python3
+###############################################################################
+# #
+# Westferry - The IPFire web user interface #
+# Copyright (C) 2015 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+from . import services
--- /dev/null
+#!/usr/bin/python3
+###############################################################################
+# #
+# Westferry - The IPFire web user interface #
+# Copyright (C) 2015 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+import tornado.web
+
+from . import handlers
+from . import ui
+
+class WebApplication(tornado.web.Application):
+ def __init__(self, **kwargs):
+ settings = {
+ # Enable compressed output
+ "compress_response" : True,
+
+ # Use Cross-Site-Request-Forgery protection
+ "xsrf_cookies" : True,
+ }
+ settings.update(kwargs)
+
+ # Get handlers
+ h = [(h.url, h) for h in handlers.get_handlers()]
+
+ # Get UI modules and methods
+ settings.update({
+ "ui_methods" : ui.get_ui_methods(),
+ "ui_modules" : ui.get_ui_modules(),
+ })
+
+ # Initialise the web application
+ tornado.web.Application.__init__(self, handlers=h, **settings)
--- /dev/null
+#!/usr/bin/python3
+###############################################################################
+# #
+# Westferry - The IPFire web user interface #
+# Copyright (C) 2015 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+from . import base
+from . import index
+
+def get_handlers():
+ """
+ Returns a list of all registered handlers
+ """
+ return base.HandlerRegistration.get_handlers()
--- /dev/null
+#!/usr/bin/python3
+###############################################################################
+# #
+# Westferry - The IPFire web user interface #
+# Copyright (C) 2015 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+import tornado.web
+
+_handlers = []
+
+class HandlerRegistration(type):
+ def __init__(handler, name, bases, dict):
+ type.__init__(handler, name, bases, dict)
+
+ # The main class from which is inherited is not registered
+ # as a plugin
+ if name.endswith("BaseHandler"):
+ return
+
+ if handler.url is None:
+ raise RuntimeError(_("Handler %s is improperly configured") % handler)
+
+ _handlers.append(handler)
+
+ @staticmethod
+ def get_handlers():
+ return _handlers
+
+
+class BaseHandler(tornado.web.RequestHandler, metaclass=HandlerRegistration):
+ url = None
--- /dev/null
+#!/usr/bin/python3
+###############################################################################
+# #
+# Westferry - The IPFire web user interface #
+# Copyright (C) 2015 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+from . import base
+
+class IndexHandler(base.BaseHandler):
+ url = r"/"
+
+ def get(self):
+ self.finish("Hello World")
--- /dev/null
+#!/usr/bin/python3
+###############################################################################
+# #
+# Westferry - The IPFire web user interface #
+# Copyright (C) 2015 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+import tornado.httpserver
+import tornado.ioloop
+
+from . import application
+
+class Service(object):
+ pass
+
+
+class WebService(Service):
+ def __init__(self, port=80):
+ self.port = port
+
+ def make_application(self, **kwargs):
+ return application.WebApplication(**kwargs)
+
+ @property
+ def ioloop(self):
+ return tornado.ioloop.IOLoop.instance()
+
+ def run(self, **kwargs):
+ app = self.make_application(**kwargs)
+
+ # Create a HTTP server instance
+ server = tornado.httpserver.HTTPServer(app)
+ server.bind(self.port)
+
+ # Launch the server
+ server.start()
+
+ # Launch the IOLoop
+ self.ioloop.start()
--- /dev/null
+#!/usr/bin/python3
+###############################################################################
+# #
+# Westferry - The IPFire web user interface #
+# Copyright (C) 2015 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+from . import base
+
+def get_ui_methods():
+ """
+ Returns all registered UI methods.
+ """
+ return base.UIMethodsRegistration.get_ui_methods()
+
+def get_ui_modules():
+ """
+ Returns all registered UI modules.
+ """
+ return base.UIModulesRegistration.get_ui_modules()
--- /dev/null
+#!/usr/bin/python3
+###############################################################################
+# #
+# Westferry - The IPFire web user interface #
+# Copyright (C) 2015 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+import tornado.web
+
+_ui_methods = {}
+_ui_modules = {}
+
+class UIMethodsRegistration(type):
+ def __init__(ui_method, name, bases, dict):
+ type.__init__(ui_method, name, bases, dict)
+
+ # The main class from which is inherited is not registered
+ # as a plugin
+ if name == "BaseUIMethod":
+ return
+
+ if ui_method.handle is None:
+ raise RuntimeError
+
+ _ui_methods[name] = ui_method()
+
+ @staticmethod
+ def get_ui_methods():
+ return _ui_methods
+
+
+class UIModulesRegistration(type):
+ def __init__(ui_module, name, bases, dict):
+ type.__init__(ui_module, name, bases, dict)
+
+ # The main class from which is inherited is not registered
+ # as a plugin
+ if name == "BaseUIModule":
+ return
+
+ if name.endswith("Module"):
+ name = name[:-6]
+
+ _ui_modules[name] = ui_module
+
+ @staticmethod
+ def get_ui_modules():
+ return _ui_modules
+
+
+class BaseUIMethod(object, metaclass=UIMethodsRegistration):
+ handle = None
+
+ def __call__(self, *args, **kwargs):
+ raise NotImplementedError
+
+
+class BaseUIModule(tornado.web.UIModule, metaclass=UIModulesRegistration):
+ pass