From 22512d154ed649b8399ffc34cf7d05c4ee150bec Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 25 Sep 2019 19:30:44 +0200 Subject: [PATCH 01/15] fixed samba html --- dirkules/templates/samba.html | 63 ++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/dirkules/templates/samba.html b/dirkules/templates/samba.html index 1f71f07..15dc80d 100644 --- a/dirkules/templates/samba.html +++ b/dirkules/templates/samba.html @@ -1,39 +1,42 @@ {% extends "base.html" %} -{% block title %}Dashboard{% endblock %} +{% block title %}Samba{% endblock %} {% block head %} {{ super() }} {% endblock %} {% block body %} - -
- Samba Global conf -
-
- -
- Samba add -
-
- - - - - - - - - - - - {% for share in shares %} +
+
+ +
+ Samba global +
+
+ +
+ Samba add +
+
+
NameSchreibzugriffPapierkorbBtrFS Optimierungen
+ - - - - + + + + + - {% endfor %} - -
{{ share.name }}{{ share.writeable }}{{ share.recycling }}{{ share.btrfs }}NameSchreibzugriffPapierkorbBtrFS Optimierungen
+ + {% for share in shares %} + + {{ share.name }} + {{ share.writeable }} + {{ share.recycling }} + {{ share.btrfs }} + + + {% endfor %} + + + {% endblock %} From 52170f0212f97272da4ab63ad810e64fa9848c5a Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 26 Sep 2019 16:26:45 +0200 Subject: [PATCH 02/15] created samba blueprint --- dirkules/__init__.py | 4 ++ dirkules/models.py | 21 ---------- dirkules/samba/__init__.py | 4 ++ dirkules/samba/models.py | 34 ++++++++++++++++ .../templates/samba/add.html} | 0 .../templates/samba/config.html} | 0 .../templates/samba/index.html} | 13 ++++-- dirkules/samba/views.py | 40 +++++++++++++++++++ dirkules/templates/base.html | 2 +- dirkules/views.py | 35 +--------------- 10 files changed, 93 insertions(+), 60 deletions(-) create mode 100644 dirkules/samba/__init__.py create mode 100644 dirkules/samba/models.py rename dirkules/{templates/samba_add.html => samba/templates/samba/add.html} (100%) rename dirkules/{templates/samba_global.html => samba/templates/samba/config.html} (100%) rename dirkules/{templates/samba.html => samba/templates/samba/index.html} (72%) create mode 100644 dirkules/samba/views.py diff --git a/dirkules/__init__.py b/dirkules/__init__.py index 24b8768..6f9df35 100644 --- a/dirkules/__init__.py +++ b/dirkules/__init__.py @@ -12,6 +12,7 @@ csrf.init_app(app) app_version = app.config["VERSION"] import dirkules.models +import dirkules.samba.models # create db if not exists db.create_all() @@ -21,3 +22,6 @@ scheduler.init_app(app) scheduler.start() # import views import dirkules.views + +from dirkules.samba import bp_samba as bp_samba +app.register_blueprint(bp_samba, url_prefix='/samba') diff --git a/dirkules/models.py b/dirkules/models.py index fe5a95d..258e5fc 100644 --- a/dirkules/models.py +++ b/dirkules/models.py @@ -118,24 +118,3 @@ class Cleaning(db.Model): self.path = path self.state = state - -class SambaShare(db.Model): - id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String, nullable=False) - writeable = db.Column(db.Boolean) - recycling = db.Column(db.Boolean) - btrfs = db.Column(db.Boolean) - options = db.relationship('SambaOptions', order_by="SambaOptions.id", backref="samba_share", lazy="select") - - def __init__(self, name, writeable=False, recycling=False, btrfs=False): - self.name = name - self.writeable = writeable - self.recycling = recycling - self.btrfs = btrfs - - -class SambaOptions(db.Model): - id = db.Column(db.Integer, primary_key=True) - option = db.Column(db.String, nullable=False) - value = db.Column(db.String, nullable=False) - sambashare_id = db.Column(db.Integer, db.ForeignKey('samba_share.id'), nullable=False) diff --git a/dirkules/samba/__init__.py b/dirkules/samba/__init__.py new file mode 100644 index 0000000..3fce82e --- /dev/null +++ b/dirkules/samba/__init__.py @@ -0,0 +1,4 @@ +from flask import Blueprint + +bp_samba = Blueprint('samba', __name__, template_folder='templates') +from dirkules.samba import views diff --git a/dirkules/samba/models.py b/dirkules/samba/models.py new file mode 100644 index 0000000..da1bf13 --- /dev/null +++ b/dirkules/samba/models.py @@ -0,0 +1,34 @@ +from dirkules import db + + +class SambaGlobal(db.Model): + id = db.Column(db.Integer, primary_key=True) + element = db.Column(db.String) + value = db.Column(db.String) + + def __init__(self, element, value): + self.element = element + self.value = value + + +class SambaShare(db.Model): + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String, nullable=False) + writeable = db.Column(db.Boolean) + recycling = db.Column(db.Boolean) + btrfs = db.Column(db.Boolean) + options = db.relationship('SambaOptions', order_by="SambaOptions.id", backref="samba_share", lazy="select", + cascade="all, delete-orphan") + + def __init__(self, name, writeable=False, recycling=False, btrfs=False): + self.name = name + self.writeable = writeable + self.recycling = recycling + self.btrfs = btrfs + + +class SambaOptions(db.Model): + id = db.Column(db.Integer, primary_key=True) + option = db.Column(db.String, nullable=False) + value = db.Column(db.String, nullable=False) + sambashare_id = db.Column(db.Integer, db.ForeignKey('samba_share.id'), nullable=False) diff --git a/dirkules/templates/samba_add.html b/dirkules/samba/templates/samba/add.html similarity index 100% rename from dirkules/templates/samba_add.html rename to dirkules/samba/templates/samba/add.html diff --git a/dirkules/templates/samba_global.html b/dirkules/samba/templates/samba/config.html similarity index 100% rename from dirkules/templates/samba_global.html rename to dirkules/samba/templates/samba/config.html diff --git a/dirkules/templates/samba.html b/dirkules/samba/templates/samba/index.html similarity index 72% rename from dirkules/templates/samba.html rename to dirkules/samba/templates/samba/index.html index 15dc80d..ac5732f 100644 --- a/dirkules/templates/samba.html +++ b/dirkules/samba/templates/samba/index.html @@ -6,14 +6,19 @@ {% block body %}
- +
- Samba global + Konfigurieren
- +
- Samba add + Freigabe hinzufügen +
+
+ +
+ Generieren
diff --git a/dirkules/samba/views.py b/dirkules/samba/views.py new file mode 100644 index 0000000..8cf5293 --- /dev/null +++ b/dirkules/samba/views.py @@ -0,0 +1,40 @@ +from dirkules import db + +from dirkules.config import staticDir +from flask import render_template, url_for, request, redirect +from dirkules.samba import bp_samba +from dirkules.samba.models import SambaShare +from dirkules.validation.validators import SambaCleaningForm, SambaAddForm + + +@bp_samba.route('/', methods=['GET']) +def index(): + shares = SambaShare.query.order_by(db.asc(db.collate(SambaShare.name, 'NOCASE'))).all() + return render_template('samba/index.html', shares=shares) + + +@bp_samba.route('/config', methods=['GET', 'POST']) +def config(): + form = SambaCleaningForm(request.form) + if request.method == 'POST' and form.validate(): + print("Input:") + print(form.workgroup.data) + print(form.server_string.data) + return redirect(url_for('samba_global')) + file = open(staticDir + "/conf/samba_global.conf") + conf = list() + while True: + line = file.readline() + if line != '': + conf.append(line.rstrip()) + else: + break + return render_template('samba/config.html', form=form, conf=conf) + + +@bp_samba.route('/add', methods=['GET', 'POST']) +def add(): + form = SambaAddForm(request.form) + if request.method == 'POST' and form.validate(): + return redirect(url_for('samba')) + return render_template('samba/add.html', form=form) diff --git a/dirkules/templates/base.html b/dirkules/templates/base.html index 331e0b2..38567b1 100644 --- a/dirkules/templates/base.html +++ b/dirkules/templates/base.html @@ -23,7 +23,7 @@ Festplatten Pools Cleaning - Samba + Samba diff --git a/dirkules/views.py b/dirkules/views.py index bb6d434..4b10342 100644 --- a/dirkules/views.py +++ b/dirkules/views.py @@ -6,7 +6,7 @@ from dirkules import app, db, scheduler, app_version import dirkules.manager.serviceManager as servMan import dirkules.manager.driveManager as driveMan import dirkules.manager.cleaning as cleaningMan -from dirkules.models import Drive, Cleaning, SambaShare, Pool +from dirkules.models import Drive, Cleaning, Pool import dirkules.manager.viewManager as viewManager from dirkules.validation.validators import CleaningForm, SambaCleaningForm, SambaAddForm, PoolAddForm from dirkules.config import staticDir @@ -146,36 +146,3 @@ def add_cleaning(): viewManager.create_cleaning_obj(form.jobname.data, form.path.data, form.active.data) return redirect(url_for('cleaning')) return render_template('add_cleaning.html', form=form) - - -@app.route('/samba', methods=['GET']) -def samba(): - shares = SambaShare.query.order_by(db.asc(db.collate(SambaShare.name, 'NOCASE'))).all() - return render_template('samba.html', shares=shares) - - -@app.route('/samba/global', methods=['GET', 'POST']) -def samba_global(): - form = SambaCleaningForm(request.form) - if request.method == 'POST' and form.validate(): - print("Input:") - print(form.workgroup.data) - print(form.server_string.data) - return redirect(url_for('samba_global')) - file = open(staticDir + "/conf/samba_global.conf") - conf = list() - while True: - line = file.readline() - if line != '': - conf.append(line.rstrip()) - else: - break - return render_template('samba_global.html', form=form, conf=conf) - - -@app.route('/samba/add', methods=['GET', 'POST']) -def samba_add(): - form = SambaAddForm(request.form) - if request.method == 'POST' and form.validate(): - return redirect(url_for('samba')) - return render_template('samba_add.html', form=form) From 919365251512c6c24af33788a0846207af823751 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 26 Sep 2019 18:14:39 +0200 Subject: [PATCH 03/15] more blueprint --- dirkules/samba/templates/samba/config.html | 2 +- dirkules/samba/validation.py | 38 ++++++++++++++++++++++ dirkules/samba/views.py | 4 +-- dirkules/validation/validators.py | 36 -------------------- dirkules/views.py | 3 +- 5 files changed, 42 insertions(+), 41 deletions(-) create mode 100644 dirkules/samba/validation.py diff --git a/dirkules/samba/templates/samba/config.html b/dirkules/samba/templates/samba/config.html index ab8dcff..31c7e54 100644 --- a/dirkules/samba/templates/samba/config.html +++ b/dirkules/samba/templates/samba/config.html @@ -16,7 +16,7 @@
{{ render_field(form.workgroup) }} {{ render_field(form.server_string) }} - + {{ render_field(form.submit) }} {% endblock %} diff --git a/dirkules/samba/validation.py b/dirkules/samba/validation.py new file mode 100644 index 0000000..a7c8623 --- /dev/null +++ b/dirkules/samba/validation.py @@ -0,0 +1,38 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, BooleanField, SelectField, IntegerField, RadioField, validators, SubmitField + + +class SambaConfigForm(FlaskForm): + workgroup = StringField("workgroup", [validators.required(message="Bitte Feld ausfüllen!"), + validators.Regexp('^[a-z]+$', message="Bitte nur Kleinbuchstaben eingeben."), + validators.Length(max=255, message="Eingabe zu lang")], + render_kw={"placeholder": "Nichts..."}) + server_string = StringField("server string", [validators.required(message="Bitte Feld ausfüllen!"), + validators.Regexp('^[a-z]+$', + message="Bitte nur Kleinbuchstaben eingeben."), + validators.Length(max=255, message="Eingabe zu lang")], + render_kw={"placeholder": "Nichts..."}) + submit = SubmitField("Speichern") + + +class SambaAddForm(FlaskForm): + name = StringField("Name der Freigabe", [validators.required(message="Bitte Feld ausfüllen!"), + validators.Length(max=255, message="Eingabe zu lang")], + render_kw={"placeholder": "Bilder"}) + writeable = BooleanField("Schreibzugriff") + recycling = BooleanField("Papierkorb") + btrfs = BooleanField("BtrFS Optimierungen (Vorsicht!)") + # additional + path = SelectField("Pfad", choices=[("Value1", "Label1"), ("Value2", "Label2")]) + user = StringField("Berechtigte Nutzer", [validators.required(message="Bitte Feld ausfüllen!"), + validators.Length(max=255, message="Eingabe zu lang")], + render_kw={"placeholder": "sambadaniel"}) + create_mask = IntegerField("Dateimaske", [validators.Optional(), + validators.NumberRange(min=4, max=4, + message="Bitte 4 Zahlen eingeben!")], + render_kw={"placeholder": "0600"}) + dir_mask = IntegerField("Ordnermaske", [validators.Optional(), + validators.NumberRange(min=4, max=4, + message="Bitte 4 Zahlen eingeben!")], + render_kw={"placeholder": "0700"}) + submit = SubmitField("Speichern") \ No newline at end of file diff --git a/dirkules/samba/views.py b/dirkules/samba/views.py index 8cf5293..0fc64d1 100644 --- a/dirkules/samba/views.py +++ b/dirkules/samba/views.py @@ -4,7 +4,7 @@ from dirkules.config import staticDir from flask import render_template, url_for, request, redirect from dirkules.samba import bp_samba from dirkules.samba.models import SambaShare -from dirkules.validation.validators import SambaCleaningForm, SambaAddForm +from dirkules.samba.validation import SambaConfigForm, SambaAddForm @bp_samba.route('/', methods=['GET']) @@ -15,7 +15,7 @@ def index(): @bp_samba.route('/config', methods=['GET', 'POST']) def config(): - form = SambaCleaningForm(request.form) + form = SambaConfigForm(request.form) if request.method == 'POST' and form.validate(): print("Input:") print(form.workgroup.data) diff --git a/dirkules/validation/validators.py b/dirkules/validation/validators.py index 5ffe6b3..8193050 100644 --- a/dirkules/validation/validators.py +++ b/dirkules/validation/validators.py @@ -17,42 +17,6 @@ class CleaningForm(FlaskForm): submit = SubmitField("Job speichern") -class SambaCleaningForm(FlaskForm): - workgroup = StringField("workgroup", [validators.required(message="Bitte Feld ausfüllen!"), - validators.Regexp('^[a-z]+$', message="Bitte nur Kleinbuchstaben eingeben."), - validators.Length(max=255, message="Eingabe zu lang")], - render_kw={"placeholder": "Nichts..."}) - server_string = StringField("server string", [validators.required(message="Bitte Feld ausfüllen!"), - validators.Regexp('^[a-z]+$', - message="Bitte nur Kleinbuchstaben eingeben."), - validators.Length(max=255, message="Eingabe zu lang")], - render_kw={"placeholder": "Nichts..."}) - - -class SambaAddForm(FlaskForm): - name = StringField("Name der Freigabe", [validators.required(message="Bitte Feld ausfüllen!"), - validators.Length(max=255, message="Eingabe zu lang")], - render_kw={"placeholder": "Bilder"}) - writeable = BooleanField("Schreibzugriff") - recycling = BooleanField("Papierkorb") - btrfs = BooleanField("BtrFS Optimierungen (Vorsicht!)") - # additional - path = SelectField("Pfad", choices=[("Value1", "Label1"), ("Value2", "Label2")]) - user = StringField("Berechtigte Nutzer", [validators.required(message="Bitte Feld ausfüllen!"), - validators.Length(max=255, message="Eingabe zu lang")], - render_kw={"placeholder": "sambadaniel"}) - create_mask = IntegerField("Dateimaske", [validators.Optional(), - validators.NumberRange(min=4, max=4, - message="Bitte 4 Zahlen eingeben!")], - render_kw={"placeholder": "0600"}) - dir_mask = IntegerField("Ordnermaske", [validators.Optional(), - validators.NumberRange(min=4, max=4, - message="Bitte 4 Zahlen eingeben!")], - render_kw={"placeholder": "0700"}) - - - - class SemanticMultiSelectField(SelectField): def pre_validate(self, form): if self.choices is not None: diff --git a/dirkules/views.py b/dirkules/views.py index 4b10342..92b6447 100644 --- a/dirkules/views.py +++ b/dirkules/views.py @@ -8,8 +8,7 @@ import dirkules.manager.driveManager as driveMan import dirkules.manager.cleaning as cleaningMan from dirkules.models import Drive, Cleaning, Pool import dirkules.manager.viewManager as viewManager -from dirkules.validation.validators import CleaningForm, SambaCleaningForm, SambaAddForm, PoolAddForm -from dirkules.config import staticDir +from dirkules.validation.validators import CleaningForm, PoolAddForm @app.errorhandler(404) From 0534b387a5365ca0eb52a1976c299a3ca79e2a06 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 1 Oct 2019 16:20:56 +0200 Subject: [PATCH 04/15] samba config additions --- dirkules/samba/manager.py | 12 ++++++++++++ dirkules/samba/templates/samba/config.html | 11 ++++++----- dirkules/samba/views.py | 7 +++---- 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 dirkules/samba/manager.py diff --git a/dirkules/samba/manager.py b/dirkules/samba/manager.py new file mode 100644 index 0000000..7b8f1a6 --- /dev/null +++ b/dirkules/samba/manager.py @@ -0,0 +1,12 @@ +from dirkules import db + +from dirkules.samba.models import SambaGlobal + + +def set_samba_global(workgroup, name): + SambaGlobal.query.delete() + workgroup = SambaGlobal("workgroup", workgroup) + name = SambaGlobal("server string", "%h {}".format(name)) + db.session.add(workgroup) + db.session.add(name) + db.session.commit() diff --git a/dirkules/samba/templates/samba/config.html b/dirkules/samba/templates/samba/config.html index 31c7e54..331d3b4 100644 --- a/dirkules/samba/templates/samba/config.html +++ b/dirkules/samba/templates/samba/config.html @@ -5,18 +5,19 @@ {% endblock %} {% block body %}
- Feste Bestandteile der Samba global conf + Feste Bestandteile der Samba global conf
{% for line in conf %} {{ line }}
{% endfor %}
- Veränderbare Bestandteile der Samba global conf - {% from "_formhelpers.html" import render_field %} -
+ Veränderbare Bestandteile der Samba global conf + {% from "_formhelpers.html" import render_field %} + + {{ form.hidden_tag() }} {{ render_field(form.workgroup) }} {{ render_field(form.server_string) }} {{ render_field(form.submit) }} - +
{% endblock %} diff --git a/dirkules/samba/views.py b/dirkules/samba/views.py index 0fc64d1..0c23bd1 100644 --- a/dirkules/samba/views.py +++ b/dirkules/samba/views.py @@ -3,6 +3,7 @@ from dirkules import db from dirkules.config import staticDir from flask import render_template, url_for, request, redirect from dirkules.samba import bp_samba +from dirkules.samba.manager import set_samba_global from dirkules.samba.models import SambaShare from dirkules.samba.validation import SambaConfigForm, SambaAddForm @@ -17,10 +18,8 @@ def index(): def config(): form = SambaConfigForm(request.form) if request.method == 'POST' and form.validate(): - print("Input:") - print(form.workgroup.data) - print(form.server_string.data) - return redirect(url_for('samba_global')) + set_samba_global(form.workgroup.data, form.server_string.data) + return redirect(url_for('.index')) file = open(staticDir + "/conf/samba_global.conf") conf = list() while True: From cbb4b0ea9713a54257f13ba5fea24e193ea97049 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 4 Oct 2019 18:40:41 +0200 Subject: [PATCH 05/15] pool is now critical if drives are absent --- dirkules/manager/driveManager.py | 26 +++++++++++++++++++--- dirkules/models.py | 4 +++- dirkules/templates/pool.html | 37 +++++++++++++++++++++----------- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/dirkules/manager/driveManager.py b/dirkules/manager/driveManager.py index 1412967..86e70fd 100644 --- a/dirkules/manager/driveManager.py +++ b/dirkules/manager/driveManager.py @@ -80,6 +80,7 @@ def get_drives(): def pool_gen(): part_dict = dict() + Pool.query.delete() # creates map uuid is key, partitions are values for part in Partitions.query.all(): if part.uuid in part_dict: @@ -97,7 +98,9 @@ def pool_gen(): drives = drives + str(Drive.query.get(part.drive_id)) + "," drives = drives[:-1] value = value[0] - Pool.query.delete() + missing = absent_drive(drives) + if missing is not None: + missing = ",".join(str(x.name) for x in missing) if value.fs == "btrfs": if value.mountpoint: memory_map = btrfsTools.get_space(value.mountpoint) @@ -108,7 +111,7 @@ def pool_gen(): ['unbekannt', '1.00', 'unbekannt', '1.00']))) pool_obj = Pool(value.label, memory_map.get("total"), memory_map.get("free"), raid_map.get("data_raid"), raid_map.get("data_ratio"), raid_map.get("meta_raid"), raid_map.get("meta_ratio"), value.fs, - value.mountpoint, "not implemented", drives, get_pool_health(drives)) + value.mountpoint, "not implemented", drives, get_pool_health(drives), missing) db.session.add(pool_obj) elif value.fs == "ext4": @@ -117,7 +120,7 @@ def pool_gen(): else: free_space = 2 pool_obj = Pool(value.label, value.size, free_space, raid, 1.00, raid, 1.00, value.fs, value.mountpoint, - "not implemented", drives) + "not implemented", drives, get_pool_health(drives), missing) db.session.add(pool_obj) db.session.commit() @@ -137,6 +140,23 @@ def get_pool_health(drive_list): return True +def absent_drive(drive_list): + """ + :param drive_list: contains drives which belongs to pool + :return: List of absent drives or None + """ + missing = list() + drive_split = drive_list.split(",") + for drive in drive_split: + db_drive = db.session.query(Drive).filter(Drive.name == drive).scalar() + if db_drive.missing: + missing.append(db_drive) + if not missing: + return None + else: + return missing + + def delete_drive(drive): """ removes a given drive object (including cascades) from db diff --git a/dirkules/models.py b/dirkules/models.py index 258e5fc..be9fac0 100644 --- a/dirkules/models.py +++ b/dirkules/models.py @@ -78,9 +78,10 @@ class Pool(db.Model): mountopt = db.Column(db.String) drives = db.Column(db.String) healthy = db.Column(db.Boolean) + missing = db.Column(db.String) def __init__(self, label, size, free, data_raid, data_ratio, meta_raid, meta_ratio, fs, mountpoint, mountopt, - drives, healthy): + drives, healthy, missing): self.label = label self.size = size self.free = free @@ -93,6 +94,7 @@ class Pool(db.Model): self.mountopt = mountopt self.drives = drives self.healthy = healthy + self.missing = missing class Time(db.Model): diff --git a/dirkules/templates/pool.html b/dirkules/templates/pool.html index d57385d..6effbf1 100644 --- a/dirkules/templates/pool.html +++ b/dirkules/templates/pool.html @@ -81,7 +81,7 @@
- {% if pool.healthy %} + {% if pool.healthy and pool.missing is none %} {% else %} @@ -99,13 +99,14 @@

Die RAID Level von Data und Metadata unterscheiden sich. Normalerweise sollten beide gleich - konfiguriert werden, da es sonst unter Umständen zu Datenverlust kommen kann, wenn ein + konfiguriert werden, da es sonst unter Umständen zu Datenverlust kommen kann, wenn + ein Laufwerk ausfällt.
Solltest du einen guten Grund dafür haben, ignoriere einfach diese Meldung.

{% endif %} - {% if pool.healthy %} + {% if pool.healthy and pool.missing is none %}
@@ -116,16 +117,28 @@

{% else %} -
- -
- Kritischer Zustand + {% if not pool.healthy %} +
+ +
+ Kritischer Zustand +
+

+ Mindetstens ein Laufwerk befindet sich in einem schlechten Zustand! Du solltest + dieses schnellstmöglich tauschen. +

-

- Mindetstens ein Laufwerk befindet sich in einem schlechten Zustand! Du solltest - dieses schnellstmöglich tauschen. -

-
+ {% else %} +
+ +
+ Kritischer Zustand +
+

+ Folgende Laufwerke wurden nicht gefunden: {{ pool.missing }} +

+
+ {% endif %} {% endif %}
From 4d1a62597d1ca14087587a7e20060fa5568a3ae5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 11 Oct 2019 16:55:00 +0200 Subject: [PATCH 06/15] prepared function for generation --- dirkules/samba/templates/samba/index.html | 2 +- dirkules/samba/views.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dirkules/samba/templates/samba/index.html b/dirkules/samba/templates/samba/index.html index ac5732f..20ff1a0 100644 --- a/dirkules/samba/templates/samba/index.html +++ b/dirkules/samba/templates/samba/index.html @@ -16,7 +16,7 @@ Freigabe hinzufügen - +
Generieren
diff --git a/dirkules/samba/views.py b/dirkules/samba/views.py index 0c23bd1..1dcd7ec 100644 --- a/dirkules/samba/views.py +++ b/dirkules/samba/views.py @@ -35,5 +35,10 @@ def config(): def add(): form = SambaAddForm(request.form) if request.method == 'POST' and form.validate(): - return redirect(url_for('samba')) + return redirect(url_for('.index')) return render_template('samba/add.html', form=form) + + +@bp_samba.route('/generate') +def generate(): + return redirect(url_for('.index')) From e79b3e6dfb473f46da01c98a7c4f924a85c3b4a5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 11 Oct 2019 20:19:55 +0200 Subject: [PATCH 07/15] prepared smb.conf generation --- dirkules/__init__.py | 2 +- dirkules/config.py | 2 +- dirkules/samba/manager.py | 20 ++++++++++++++++++++ dirkules/samba/views.py | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dirkules/__init__.py b/dirkules/__init__.py index 6f9df35..30fdab7 100644 --- a/dirkules/__init__.py +++ b/dirkules/__init__.py @@ -9,7 +9,7 @@ app.config.from_object(config) db = SQLAlchemy(app) csrf = CSRFProtect() csrf.init_app(app) -app_version = app.config["VERSION"] +app_version = app.config["version"] import dirkules.models import dirkules.samba.models diff --git a/dirkules/config.py b/dirkules/config.py index 501638c..2b6d2d7 100644 --- a/dirkules/config.py +++ b/dirkules/config.py @@ -5,7 +5,7 @@ from logging.config import dictConfig from apscheduler.jobstores.base import ConflictingIdError from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore -VERSION = "1.0" +version = "1.0.1" baseDir = os.path.abspath(os.path.dirname(__file__)) staticDir = os.path.join(baseDir, 'static') diff --git a/dirkules/samba/manager.py b/dirkules/samba/manager.py index 7b8f1a6..5646b37 100644 --- a/dirkules/samba/manager.py +++ b/dirkules/samba/manager.py @@ -1,3 +1,5 @@ +from dirkules.config import staticDir, version + from dirkules import db from dirkules.samba.models import SambaGlobal @@ -10,3 +12,21 @@ def set_samba_global(workgroup, name): db.session.add(workgroup) db.session.add(name) db.session.commit() + + +def generate_smb(): + if SambaGlobal.query.first() is None: + workgroup = 'WORKGROUP' + server_string = '%h dirkules' + else: + workgroup = SambaGlobal.query.get(1) + server_string = SambaGlobal.query.get(2) + f = open("smb.conf.txt", "w") + samba_global = open(staticDir + "/conf/samba_global.conf", "r") + f.write("# This file was generated by dirkules v{}".format(version)) + f.write() + f.write("# Global Config") + f.write("server string = {}".format(server_string)) + f.write("workgroup = {}".format(workgroup)) + f.write(samba_global.read()) + f.close() diff --git a/dirkules/samba/views.py b/dirkules/samba/views.py index 1dcd7ec..8675b6d 100644 --- a/dirkules/samba/views.py +++ b/dirkules/samba/views.py @@ -20,7 +20,7 @@ def config(): if request.method == 'POST' and form.validate(): set_samba_global(form.workgroup.data, form.server_string.data) return redirect(url_for('.index')) - file = open(staticDir + "/conf/samba_global.conf") + file = open(staticDir + "/conf/samba_global.conf", "r") conf = list() while True: line = file.readline() From 447ccccb30db408a8ad1b8cb6023c3924f7e10c0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 16 Oct 2019 20:51:25 +0200 Subject: [PATCH 08/15] fixed size bug --- dirkules/__init__.py | 2 +- dirkules/config.py | 2 +- dirkules/hardware/drive.py | 17 ++++++----------- dirkules/samba/manager.py | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/dirkules/__init__.py b/dirkules/__init__.py index 30fdab7..6f9df35 100644 --- a/dirkules/__init__.py +++ b/dirkules/__init__.py @@ -9,7 +9,7 @@ app.config.from_object(config) db = SQLAlchemy(app) csrf = CSRFProtect() csrf.init_app(app) -app_version = app.config["version"] +app_version = app.config["VERSION"] import dirkules.models import dirkules.samba.models diff --git a/dirkules/config.py b/dirkules/config.py index 2b6d2d7..6372d93 100644 --- a/dirkules/config.py +++ b/dirkules/config.py @@ -5,7 +5,7 @@ from logging.config import dictConfig from apscheduler.jobstores.base import ConflictingIdError from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore -version = "1.0.1" +VERSION = "1.0.1" baseDir = os.path.abspath(os.path.dirname(__file__)) staticDir = os.path.join(baseDir, 'static') diff --git a/dirkules/hardware/drive.py b/dirkules/hardware/drive.py index 125acf0..3f883dc 100644 --- a/dirkules/hardware/drive.py +++ b/dirkules/hardware/drive.py @@ -66,10 +66,10 @@ def part_for_disk(device): # lsblk /dev/sdd -b -o NAME,LABEL,FSTYPE,SIZE,UUID,MOUNTPOINT parts = [] part_dict = list() - keys = ['name', 'label', 'fs', 'size', 'uuid', 'mount'] + keys = ['size', 'name', 'label', 'fs', 'uuid', 'mount'] device = "/dev/" + device lsblk = subprocess.Popen( - ["sudo lsblk " + device + " -l -b -o NAME,LABEL,FSTYPE,SIZE,UUID,MOUNTPOINT"], + ["sudo lsblk " + device + " -l -b -o SIZE,NAME,LABEL,FSTYPE,UUID,MOUNTPOINT"], stdout=subprocess.PIPE, shell=True, universal_newlines=True) @@ -83,20 +83,15 @@ def part_for_disk(device): del parts[1] element_length = list() counter = 0 - last_letter = 0 pre_value = " " for char in parts[0]: if char != " " and pre_value == " ": - element_length.append(counter) + if len(element_length) == 0: + element_length.append(0) + else: + element_length.append(counter) counter += 1 pre_value = char - # size ist rechtsbuendig. Extra Behandlung - # TODO: Besser machen - if char == "S" and parts[0][last_letter] == "E": - del element_length[-1] - element_length.append((last_letter + 2)) - if char != " ": - last_letter = counter - 1 element_length.append(len(parts[0])) del parts[0] for part in parts: diff --git a/dirkules/samba/manager.py b/dirkules/samba/manager.py index 5646b37..89af950 100644 --- a/dirkules/samba/manager.py +++ b/dirkules/samba/manager.py @@ -1,4 +1,4 @@ -from dirkules.config import staticDir, version +from dirkules.config import staticDir, VERSION from dirkules import db From ea6e63c356bb55bdd280fd336cb994f29a6dd5c8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 16 Oct 2019 21:38:12 +0200 Subject: [PATCH 09/15] fixed a bug which caused wrong mountpoints --- dirkules/hardware/drive.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dirkules/hardware/drive.py b/dirkules/hardware/drive.py index 3f883dc..2acf8c3 100644 --- a/dirkules/hardware/drive.py +++ b/dirkules/hardware/drive.py @@ -97,7 +97,10 @@ def part_for_disk(device): for part in parts: values = list() for start, end in zip(element_length, element_length[1:]): - values.append(part[start:(end - 1)].strip()) + if end == element_length[-1:]: + values.append(part[start:len(part)].strip()) + else: + values.append(part[start:(end - 1)].strip()) part_dict.append(dict(zip(keys, values))) return part_dict From ff412823832c320f69429dc7edbee5f5d0177b07 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 17 Oct 2019 17:25:24 +0200 Subject: [PATCH 10/15] drives not refreshed bug fixed --- dirkules/__init__.py | 11 ++++++++++- dirkules/samba/manager.py | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dirkules/__init__.py b/dirkules/__init__.py index 6f9df35..4885b93 100644 --- a/dirkules/__init__.py +++ b/dirkules/__init__.py @@ -1,4 +1,6 @@ -from flask_wtf import csrf, CSRFProtect +import datetime + +from flask_wtf import CSRFProtect import dirkules.config as config from flask import Flask from flask_sqlalchemy import SQLAlchemy @@ -24,4 +26,11 @@ scheduler.start() import dirkules.views from dirkules.samba import bp_samba as bp_samba + app.register_blueprint(bp_samba, url_prefix='/samba') + + +@app.before_request +def check_drives(): + if db.query("Drive").first() is None: + scheduler.get_job("refresh_disks").modify(next_run_time=datetime.datetime.now()) diff --git a/dirkules/samba/manager.py b/dirkules/samba/manager.py index 89af950..4c6baaa 100644 --- a/dirkules/samba/manager.py +++ b/dirkules/samba/manager.py @@ -1,6 +1,6 @@ -from dirkules.config import staticDir, VERSION +from dirkules.config import staticDir -from dirkules import db +from dirkules import db, app_version from dirkules.samba.models import SambaGlobal @@ -23,7 +23,7 @@ def generate_smb(): server_string = SambaGlobal.query.get(2) f = open("smb.conf.txt", "w") samba_global = open(staticDir + "/conf/samba_global.conf", "r") - f.write("# This file was generated by dirkules v{}".format(version)) + f.write("# This file was generated by dirkules v{}".format(app_version)) f.write() f.write("# Global Config") f.write("server string = {}".format(server_string)) From 1c810f2293ae80a6e710ac1c3f90c5b3fcf0a309 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 17 Oct 2019 17:27:29 +0200 Subject: [PATCH 11/15] typo --- dirkules/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dirkules/__init__.py b/dirkules/__init__.py index 4885b93..159f3e1 100644 --- a/dirkules/__init__.py +++ b/dirkules/__init__.py @@ -32,5 +32,5 @@ app.register_blueprint(bp_samba, url_prefix='/samba') @app.before_request def check_drives(): - if db.query("Drive").first() is None: + if db.session.query("Drive").first() is None: scheduler.get_job("refresh_disks").modify(next_run_time=datetime.datetime.now()) From a712abee38f20d32626c4ff2548c25d5b4a04db3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 17 Oct 2019 17:29:42 +0200 Subject: [PATCH 12/15] fixmas --- dirkules/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dirkules/__init__.py b/dirkules/__init__.py index 159f3e1..1057222 100644 --- a/dirkules/__init__.py +++ b/dirkules/__init__.py @@ -29,8 +29,10 @@ from dirkules.samba import bp_samba as bp_samba app.register_blueprint(bp_samba, url_prefix='/samba') +from dirkules.models import Drive + @app.before_request def check_drives(): - if db.session.query("Drive").first() is None: + if Drive.query.first() is None: scheduler.get_job("refresh_disks").modify(next_run_time=datetime.datetime.now()) From 3b85a90956d3753a0d63cddca8e6b9c95aa88005 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 17 Oct 2019 18:27:56 +0200 Subject: [PATCH 13/15] fixed bug long mountpoints --- dirkules/hardware/drive.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dirkules/hardware/drive.py b/dirkules/hardware/drive.py index 2acf8c3..73fc536 100644 --- a/dirkules/hardware/drive.py +++ b/dirkules/hardware/drive.py @@ -96,11 +96,11 @@ def part_for_disk(device): del parts[0] for part in parts: values = list() - for start, end in zip(element_length, element_length[1:]): - if end == element_length[-1:]: + for start, next_start in zip(element_length, element_length[1:]): + if next_start == element_length[-1:][0]: values.append(part[start:len(part)].strip()) else: - values.append(part[start:(end - 1)].strip()) + values.append(part[start:(next_start - 1)].strip()) part_dict.append(dict(zip(keys, values))) return part_dict From 97b707a0079f1cf7a9e178e64fb404eea9a69706 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 17 Oct 2019 22:50:14 +0200 Subject: [PATCH 14/15] Fixed a bug with ext4 an luks --- dirkules/hardware/ext4Tools.py | 2 +- dirkules/manager/driveManager.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dirkules/hardware/ext4Tools.py b/dirkules/hardware/ext4Tools.py index 278f995..4dc9f0d 100644 --- a/dirkules/hardware/ext4Tools.py +++ b/dirkules/hardware/ext4Tools.py @@ -8,7 +8,7 @@ import subprocess def get_free_space(name): lines = list() df = subprocess.Popen( - ["df -B K /dev/" + name], + ["df -B K " + name], stdout=subprocess.PIPE, shell=True, universal_newlines=True) diff --git a/dirkules/manager/driveManager.py b/dirkules/manager/driveManager.py index 86e70fd..5adb96b 100644 --- a/dirkules/manager/driveManager.py +++ b/dirkules/manager/driveManager.py @@ -116,7 +116,7 @@ def pool_gen(): elif value.fs == "ext4": if value.mountpoint: - free_space = ext4Tools.get_free_space(value.name) + free_space = ext4Tools.get_free_space(value.mountpoint) else: free_space = 2 pool_obj = Pool(value.label, value.size, free_space, raid, 1.00, raid, 1.00, value.fs, value.mountpoint, From fe6348316bd8e2f84699d7205c08a93229b759ae Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 17 Oct 2019 23:22:04 +0200 Subject: [PATCH 15/15] fixed ext4 luks bug hopefully forever --- dirkules/hardware/ext4Tools.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/dirkules/hardware/ext4Tools.py b/dirkules/hardware/ext4Tools.py index 4dc9f0d..6166df1 100644 --- a/dirkules/hardware/ext4Tools.py +++ b/dirkules/hardware/ext4Tools.py @@ -2,13 +2,10 @@ import subprocess -# This file should read btrfs pools -# Storage: sudo btrfs fi usage -b -T /media/data-raid - -def get_free_space(name): +def get_free_space(mount_point): lines = list() df = subprocess.Popen( - ["df -B K " + name], + ["df -B K " + mount_point], stdout=subprocess.PIPE, shell=True, universal_newlines=True) @@ -20,7 +17,7 @@ def get_free_space(name): break df.stdout.close() for line in lines: - newLine = ' '.join(line.split()) - newLine = newLine.split(" ") - if name in newLine[0]: - return int(newLine[3][:-1]) * 1024 + new_line = ' '.join(line.split()) + new_line = new_line.split(" ") + if mount_point in new_line: + return int(new_line[3][:-1]) * 1024
GesundheitGesundKritisch