Skip to content

Commit

Permalink
web - prettified service handling, added letsencrypt flag in server-c…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
superstes committed Jan 2, 2022
1 parent 2ece537 commit ddc7d7c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
28 changes: 18 additions & 10 deletions code/web/base/ga/config/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@
'path_log': 'Log path',
'path_web': 'Webserver root path',
'path_web_static': 'Webserver static-files directory',
'sql_server': 'SQL server',
'sql_port': 'SQL server port',
'sql_user': 'SQL user',
'sql_secret': 'SQL password',
'sql_database': 'SQL database',
'sql_server': 'Database server',
'sql_port': 'Database server port',
'sql_user': 'Database user',
'sql_secret': 'Database password',
'sql_database': 'Database name',
'sql_service': 'Database service',
'sql_socket': 'Database socket (local database connection)',
'sql_config': 'Database config file',
'log_level': 'Log level',
'security': 'Security mode',
'timezone': 'Timezone',
Expand All @@ -62,6 +65,7 @@
'ga_cloud': 'GrowAutomation Cloud Services',
'ga_cloud_uuid': 'GrowAutomation Cloud ID',
'ga_cloud_ddns': 'GrowAutomation Cloud Dynamic DNS',
'letsencrypt': 'LetsEncrypt certificate provider', # todo: add scripting to implement letsencrypt on running systems (after setup)

# dashboard
'chart_type': 'Chart type',
Expand Down Expand Up @@ -140,11 +144,14 @@
'path_web_static': 'Directory to save the webserver static-files in [max length 255]',
'path_log': 'Directory to save the logs in [max length 255]',
'path_home': 'Path to use as a home directory for the service-user [max length 255]',
'sql_server': 'IP/Hostname of the SQL server (mariadb/mysql) that should be used [max length 50]',
'sql_port': 'SQL server port to connect to [1-65535]',
'sql_user': 'SQL user used for connecting to the sql server [max length 50]',
'sql_secret': 'Password for the SQL user [max length 100]',
'sql_database': 'SQL database that should be used [max length 50]',
'sql_server': 'IP/Hostname of the database server (mariadb/mysql) that should be used [max length 50]',
'sql_port': 'Database server port to connect to [1-65535]',
'sql_user': 'Database user used for connecting to the sql server [max length 50]',
'sql_secret': 'Password for the database user [max length 100]',
'sql_database': 'Database that should be used [max length 50]',
'sql_service': 'Name of the database systemd service [max length 50]',
'sql_socket': 'Path to the database socket-file used to connect locally [max length 255]',
'sql_config': 'Path to the database config-file [max length 255]',
'log_level': 'How detailed should the logs be?',
'security': 'If the advanced security mode should be enabled',
'timezone': 'Timezone used for conditions and core [max length 50]',
Expand All @@ -165,6 +172,7 @@
'ga_cloud': 'If the use of GrowAutomation Cloud-Services should be enabled',
'ga_cloud_uuid': 'This is the unique Cloud-ID of your system',
'ga_cloud_ddns': 'If this system should register itself to the GrowAutomation DynDNS Service. For more information => see the documentation!',
'letsencrypt': 'If the system uses letsencrypt as certificate provider',

# dashboard
'chart_type': 'Chart.js chart-type => DISCLAIMER: The GA config was only optimized for line charts',
Expand Down
2 changes: 2 additions & 0 deletions code/web/base/ga/config/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
VERSION = 0.9
SQL_CONFIG_FILE = f'{settings.BASE_DIR}/database.cnf'
NONE_RESULTS = ['', 'None', None, ' ']
CORE_SERVICE = 'ga_core.service'
LE_RENEWAL_SERVICE = 'ga_web_certRenewal.service'

# privileges
LOGIN_URL = '/accounts/login/'
Expand Down
4 changes: 3 additions & 1 deletion code/web/base/ga/submodels/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SystemAgentModel(BaseModel):
class SystemServerModel(BaseModel):
field_list = [
'name', 'description', 'sql_server', 'sql_port', 'sql_user', 'sql_secret', 'sql_database', 'log_level', 'debug', 'security', 'timezone', 'web_cdn', 'web_warn', 'ga_cloud',
'ga_cloud_ddns', 'sql_service',
'ga_cloud_ddns', 'sql_service', 'letsencrypt'
]

version = models.FloatField()
Expand Down Expand Up @@ -89,6 +89,8 @@ class SystemServerModel(BaseModel):
ga_cloud_token = models.TextField(max_length=16384, blank=True, null=True, default=None)
ga_cloud_ddns = models.BooleanField(choices=BOOLEAN_CHOICES, default=False)

letsencrypt = models.BooleanField(choices=BOOLEAN_CHOICES, default=False)


class ObjectTaskModel(BaseModel):
field_list = ['name', 'description', 'timer', 'enabled', 'target', 'interval']
Expand Down
12 changes: 7 additions & 5 deletions code/web/base/ga/subviews/system/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ def LogView(request):

log_type_options = ['Service', 'Service journal', 'GrowAutomation']
log_service_options = {
'GrowAutomation': 'ga_core.service',
'Apache webserver': 'apache2.service',
'Mariadb database': 'mariadb.service',
'LetsEncrypt renewal': 'ga_web_certRenewal.service',
'GrowAutomation Update': 'ga_update.service',
'GrowAutomation': config.CORE_SERVICE,
'Webserver': 'apache2.service',
'Database': get_server_config(setting='sql_service'),
'GrowAutomation Update': config.UPDATE_SERVICE,
}

if get_server_config(setting='letsencrypt'):
log_service_options.update({'Certificate renewal': config.LE_RENEWAL_SERVICE})

if develop:
device_log_list = ['02_device_test1.log', '02_device_earth_humidity.log', '']

Expand Down
14 changes: 7 additions & 7 deletions code/web/base/ga/subviews/system/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ...user import authorized_to_read, authorized_to_write
from ...utils.basic import get_time_difference
from ...utils.helper import develop_subprocess, develop_log
from ...utils.helper import develop_subprocess, develop_log, get_server_config
from ..handlers import Pseudo404
from ...config import shared as config

Expand All @@ -21,13 +21,13 @@
@user_passes_test(authorized_to_read, login_url=config.DENIED_URL)
def ServiceView(request):
service_name_options = {
'GrowAutomation': 'ga_core.service',
'Apache webserver': 'apache2.service',
'Mariadb database': 'mariadb.service',
'LetsEncrypt renewal': 'ga_web_certRenewal.timer',
'GrowAutomation Update': config.UPDATE_SERVICE,
'GrowAutomation': config.CORE_SERVICE,
'Webserver': 'apache2.service',
'Database': get_server_config(setting='sql_service'),
}
non_stop_services = ['Apache webserver', 'Mariadb database']
non_stop_services = ['Webserver', 'Database']
if get_server_config(setting='letsencrypt'):
service_name_options.update({'Certificate renewal': config.LE_RENEWAL_SERVICE})

service_name = 'GrowAutomation'
service_status = None
Expand Down
4 changes: 2 additions & 2 deletions setup/roles/web/tasks/init_db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
path_web_static, path_home_core, path_home_web, path_log, sql_server, sql_port, sql_user,
sql_secret, sql_database,
log_level, debug, security, timezone, web_cdn, web_warn, ga_cloud,
ga_cloud_uuid, ga_cloud_token, ga_cloud_ddns, version, version_detail, sql_service)
ga_cloud_uuid, ga_cloud_token, ga_cloud_ddns, version, version_detail, sql_service, letsencrypt)
VALUES
(NOW(), NOW(), '{{ ga_core_controller_name }}', 'Server created by setup at {{ ansible_date_time.iso8601_basic_short }}', '{{ ga_core_path }}', '{{ ga_web_path }}',
'{{ ga_web_path_static }}', '{{ ga_core_path_home }}', '{{ ga_web_path_home }}', '{{ ga_path_log }}', '{{ ga_sql_server }}', {{ ga_sql_port }}, '{{ ga_sql_user_web }}',
'{{ ga_sql_pwd_web_encrypted.stdout }}', '{{ ga_sql_db }}', {{ ga_log_level }}, 0, {% if ga_security_mode %}1{% else %}0{% endif %}, '{{ ga_timezone }}', 0, 1, 0,
NULL, NULL, 0, '{{ ga_setup_release }}', '{{ ga_setup_commit }}', '{{ ga_sql_service }}')"
NULL, NULL, 0, '{{ ga_setup_release }}', '{{ ga_setup_commit }}', '{{ ga_sql_service }}', {% if ga_web_ssl_mode == 'letsencrypt' %}1{% else %}0{% endif %})"

- "INSERT IGNORE INTO {{ ga_sql_db }}.ga_systemagentmodel
(created, updated, name, description, path_root, path_home, path_log, sql_server,
Expand Down

0 comments on commit ddc7d7c

Please sign in to comment.