mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
- Basic information about each service is available for consumers - Information about whether service is enabled or disabled is available - Interested parties may listen to enabling/disabling of a service - Information about some core services are made available
74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
#
|
|
# This file is part of Plinth.
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
"""
|
|
Framework for working with servers and theirs services
|
|
"""
|
|
|
|
from gettext import gettext as _
|
|
|
|
import django.dispatch
|
|
|
|
ENABLED = django.dispatch.Signal(providing_args=['service_id', 'enabled'])
|
|
|
|
SERVICES = {}
|
|
|
|
|
|
class Service(object):
|
|
"""
|
|
Representation of an application service provided by the machine
|
|
containing information such as current status and ports required
|
|
for operation.
|
|
"""
|
|
|
|
def __init__(self, service_id, name, ports=None, enabled=True):
|
|
if not ports:
|
|
ports = [service_id]
|
|
|
|
self.service_id = service_id
|
|
self.name = name
|
|
self.ports = ports
|
|
self._enabled = enabled
|
|
|
|
# Maintain a complete list of services
|
|
SERVICES[service_id] = self
|
|
|
|
def is_enabled(self):
|
|
"""Return whether the service is enabled"""
|
|
if callable(self._enabled):
|
|
return self._enabled()
|
|
|
|
return self._enabled
|
|
|
|
def notify_enabled(self, sender, enabled):
|
|
"""Notify observers about change in state of service"""
|
|
if not callable(self._enabled):
|
|
self._enabled = enabled
|
|
|
|
ENABLED.send_robust(sender=sender, service_id=self.service_id,
|
|
enabled=enabled)
|
|
|
|
|
|
def init():
|
|
"""Register some misc. services that don't fit elsewhere"""
|
|
Service('http', _('Web Server'), ['http'], True)
|
|
Service('https', _('Web Server over Secure Socket Layer'),
|
|
['https'], True)
|
|
Service('ssh', _('Secure Shell (SSH) Server'), ['ssh'], True)
|
|
Service('plinth', _('FreedomBox Web Interface (Plinth)'),
|
|
['https'], True)
|