Skip to content

Commit

Permalink
setup - added readme, fixed letsencrypt role; core/web - fixes regard…
Browse files Browse the repository at this point in the history
…ing setup
  • Loading branch information
superstes committed Apr 11, 2021
1 parent 9324337 commit 5913ac8
Show file tree
Hide file tree
Showing 26 changed files with 238 additions and 132 deletions.
2 changes: 1 addition & 1 deletion code/core/config/file/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def go(file: str, encrypted: bool):
decrypted_line = line

try:
key, value = decrypted_line.split('=')
key, value = decrypted_line.split('=', 1)
file_data_dict[key] = value.strip()

except ValueError as error_msg:
Expand Down
18 changes: 11 additions & 7 deletions code/core/utils/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
from core.config.web_shared import init as web_shared_vars

from datetime import datetime
from os import getuid as os_getuid
from os import path as os_path
from pathlib import Path
from os import chmod as os_chmod
from os import chown as os_chown
from grp import getgrnam
from sys import platform as sys_platform

if sys_platform != 'win32':
from os import getuid as os_getuid
from os import chmod as os_chmod
from os import chown as os_chown
from grp import getgrnam


def now(time_format: str):
Expand Down Expand Up @@ -75,10 +78,11 @@ def _check(self) -> bool:
Path(self.log_dir).mkdir(parents=True, exist_ok=True)

with open(self.log_file, 'a+') as logfile:
logfile.write('init')
logfile.write('init\n')

os_chown(path=self.log_file, uid=os_getuid(), gid=getgrnam(shared_vars.GA_GROUP)[2])
os_chmod(path=self.log_file, mode=int(f'{shared_vars.LOG_FILE_PERMS}', base=8))
if sys_platform != 'win32':
os_chown(path=self.log_file, uid=os_getuid(), gid=getgrnam(shared_vars.GA_GROUP)[2])
os_chmod(path=self.log_file, mode=int(f'{shared_vars.LOG_FILE_PERMS}', base=8))

return True

Expand Down
11 changes: 0 additions & 11 deletions code/sudoers.txt

This file was deleted.

7 changes: 4 additions & 3 deletions code/web/base/ga/subviews/system/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ def LogView(request):
date_month = datetime.now().strftime('%m')
path_log = get_controller_setting(request, 'path_log')

log_type_options = ['Service', 'Service journal', 'Growautomation']
log_type_options = ['Service', 'Service journal', 'GrowAutomation']
log_service_options = {
'Growautomation': 'ga.service',
'GrowAutomation': 'ga_core.service',
'Apache webserver': 'apache2.service',
'Mariadb database': 'mariadb.service',
'LetsEncrypt renewal': 'ga_web_certRenewal.service',
}

if develop:
Expand Down Expand Up @@ -104,7 +105,7 @@ def LogView(request):
)
)

if log_type == 'Growautomation':
if log_type == 'GrowAutomation':
log_subtype_options = log_ga_options

if 'log_subtype' in request.GET and request.GET['log_subtype'] in log_ga_options:
Expand Down
1 change: 1 addition & 0 deletions code/web/base/ga/subviews/system/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def ServiceView(request):
'GrowAutomation': 'ga_core.service',
'Apache webserver': 'apache2.service',
'Mariadb database': 'mariadb.service',
'LetsEncrypt renewal': 'ga_web_certRenewal.timer',
}
non_stop_services = ['Apache webserver', 'Mariadb database']

Expand Down
4 changes: 2 additions & 2 deletions code/web/base/ga/templates/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
<br>
<div class="ga-footer-wrapper">
<footer class="ga-footer">
{% if not request|get_login_state %}
{% if not request|get_login_state and demo_mode %}
<div class="alert alert-info">
<strong>You can login with this demo user to get an overview:</strong><br>
<strong>Username:</strong> demo<br>
<strong>Password:</strong> grow2020
<strong>Password:</strong> Grow2021
</div>
{% endif %}
<div class="ga-footer-text">
Expand Down
5 changes: 2 additions & 3 deletions code/web/base/ga/templates/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
<span class="navbar-toggler-icon"></span>
</button>
{% if request|get_login_state %}
{% set_var ''|nav_config as nav_dict %}
{% set_var nav_dict|get_item:'left' as nav_left %}
{% set_var nav_dict|get_item:'right' as nav_right %}
{% set_var 'left'|get_nav as nav_left %}
{% set_var 'right'|get_nav as nav_right %}
<div class="collapse navbar-collapse mr-auto" id="navbarSupportedContent">
<!-- START left navbar -->
<ul class="navbar-nav">
Expand Down
67 changes: 40 additions & 27 deletions code/web/base/ga/templatetags/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime, timedelta
from random import randint
from sys import exc_info as sys_exc_info
from os import environ as os_environ

from ..config.site import GA_USER_GROUP, GA_READ_GROUP, GA_WRITE_GROUP
from ..utils.helper import get_controller_setting, get_client_ip
Expand Down Expand Up @@ -162,31 +163,35 @@ def to_uppercase(data: str) -> str:

@register.filter
def get_return_path(request, typ=None) -> str:
if 'return' in request.GET:
path = request.GET['return']

elif 'return' in request.POST:
path = request.POST['return']

else:
if typ is None:
path = request.META['HTTP_REFERER']

else:
path = f"/config/list/{ typ }/"

if path is None:
path = '/'

return path


@register.filter
def handler500_update(request):
if request.META['HTTP_REFERER'].find('/update') != -1:
return True

return False
# todo: refactor => Ticket#26
return '/'
# path = None
#
# if 'return' in request.GET:
# path = request.GET['return']
#
# elif 'return' in request.POST:
# path = request.POST['return']
#
# # else:
# # if typ is None:
# # path = request.META['HTTP_REFERER']
# #
# # else:
# # path = f"/config/list/{ typ }/"
#
# if path is None:
# path = '/'
#
# return path


# @register.filter
# def handler500_update(request):
# if request.META['HTTP_REFERER'].find('/update') != -1:
# return True
#
# return False


@register.filter
Expand Down Expand Up @@ -263,13 +268,21 @@ def get_last_errors() -> str:


@register.filter
def nav_config(_) -> dict:
def get_nav(key: str) -> dict:
# serves navigation config to template
return nav_dict
return nav_dict[key]


@register.filter
def found(data: str, search: str) -> bool:
if data.find(search) != -1:
return True
return False


@register.simple_tag
def demo_mode() -> bool:
if 'GA_DEMO' in os_environ:
return True

return False
78 changes: 78 additions & 0 deletions setup/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<br>
<p align="center">
<img src="https://www.growautomation.eu/img/svg/ga02c.svg" width="50%"/>
</p>
<br><br>

## Installation

There are basically two ways of installing the GrowAutomation software:

### Setup script

#### Base setup

First you need to go through the basic setup process as described <a href="https://docs.growautomation.eu/en/latest/setup/raspberry.html">here</a>

#### Software setup

The device will need internet access since the setup will download the code for you.

You can just copy the 'setup.sh' file to the target system and run it:

```bash
$ sudo bash setup.sh
```

This script will prepare your system to run the Ansible setup tasks.

It will ask you to modify the configuration before continuing as seen here:

```bash
###################################################################################
##################################### WARNING #####################################
###################################################################################
This is the last time you can modify the config before the installation is started.
You could:
-> send this window to the background (Ctrl+Z)
-> make your modifications and
-> bring it back to the foreground (fg).

###################################### INFO #######################################
The following config files exist:
main: /tmp/ga_2021-04-11/setup/vars/main.yml
remote hosts (if needed):
- /tmp/ga_2021-04-11/setup/inventories/hosts.yml
- /tmp/ga_2021-04-11/setup/inventories/host_vars/$HOSTNAME.yml

Do you want to continue? (yes/any=no)
```

Just put it in the background, change what you want and bring the setup back to the foreground.

Type 'yes' and press enter to start the setup tasks.

##### Post install

If you haven't set custom passwords -> you can find the randomly generated ones like this:

```bash
cat /etc/.ga_setup
# rm /etc/.ga_setup # to delete the file
```

**You should delete this file** after you saved your passwords safely!

Now you can access the web-interface and configure your devices.

More information to the configuration can be found <a href="https://docs.growautomation.eu/en/latest/index.html">here</a>.

### Image

**Currently not available**!

Will be provided for later versions.

You just need to flash the image on the sd-card or ssd for the raspberry and plug it in.

GrowAutomation is pre-installed.
2 changes: 1 addition & 1 deletion setup/roles/core/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---

- name: 'start_core_service'
service:
systemd:
name: 'ga_core.service'
state: started
2 changes: 1 addition & 1 deletion setup/roles/core/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
daemon_reload: yes

- name: GA | Core | Enabling service
service:
systemd:
name: 'ga_core.service'
enabled: yes
notify: 'start_core_service'
Expand Down
2 changes: 1 addition & 1 deletion setup/roles/db/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: 'enable_mariadb'
service:
systemd:
name: 'mariadb.service'
enabled: yes
state: started
8 changes: 3 additions & 5 deletions setup/roles/ssl_letsencrypt/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ letsencrypt_key_size: 4096
letsencrypt_hash_algo: 'sha256'
letsencrypt_dir: '/etc/letsencrypt'

lensencrypt_file_owner: 'root'
lensencrypt_file_group: "{{ ga_web_service_user }}"
lensencrypt_file_owner: "{{ ga_web_service_user }}"
lensencrypt_file_group: "{{ ga_service_group }}"
lensencrypt_file_mode: 0640

certbot_email: "webmaster@{{ ga_web_dns }}"

certbot_renew_timer: 'Mon *-*-* 00:00:00'
certbot_force_renewal: false
certbot_verbosity: 'v'

ga_letsencrypt_live_dir: "{{ letsencrypt_dir }}/{{ ga_web_key }}"
ga_letsencrypt_live_dir: "{{ letsencrypt_dir }}/live/{{ ga_web_key }}"
16 changes: 0 additions & 16 deletions setup/roles/ssl_letsencrypt/handlers/main.yml

This file was deleted.

2 changes: 2 additions & 0 deletions setup/roles/ssl_letsencrypt/meta/SOURCE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/ansibleguy/service-letsencryt
Modified for usage in GrowAutomation
2 changes: 1 addition & 1 deletion setup/roles/ssl_letsencrypt/tasks/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
register: tmp_site_config

- name: GA | Cert LetsEncrypt | Cleanup | Reload apache
service:
systemd:
name: 'apache2.service'
state: reloaded
when: tmp_site_config.changed
2 changes: 1 addition & 1 deletion setup/roles/ssl_letsencrypt/tasks/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
mode: 0644

- name: GA | Cert LetsEncrypt | Dependencies | Reload apache
service:
systemd:
name: 'apache2.service'
state: reloaded

0 comments on commit 5913ac8

Please sign in to comment.