mirror of
https://github.com/vale981/dirkules
synced 2025-03-04 17:01:40 -05:00
prepared db for share creation
This commit is contained in:
parent
0d66084586
commit
f655a1113c
6 changed files with 58 additions and 16 deletions
|
@ -2,7 +2,42 @@ from dirkules.config import staticDir
|
|||
|
||||
from dirkules import db, app_version, app
|
||||
|
||||
from dirkules.samba.models import SambaGlobal
|
||||
from dirkules.samba.models import SambaGlobal, SambaShare, SambaOption
|
||||
|
||||
|
||||
def create_share(name, path, user, dir_mask, create_mask, writeable, btrfs, recycling):
|
||||
"""
|
||||
Creates a samba share in db with all needed options for proper generation.
|
||||
:param name: Share name
|
||||
:type name: String
|
||||
:param path: Path to share. might change in later versions.
|
||||
:type path: String
|
||||
:param user: User which is allowed to access
|
||||
:type user: String
|
||||
:param dir_mask: The UNIX octal mask for directories in share
|
||||
:type dir_mask: Integer
|
||||
:param create_mask: The UNIX octal mask for files in share
|
||||
:type create_mask: Integer
|
||||
:param writeable: Defines whether share is writeable or not
|
||||
:type writeable: Boolean
|
||||
:param btrfs: Defines the btrfs vfs_object
|
||||
:type btrfs: Boolean
|
||||
:param recycling: Defines the recycle vfs_object
|
||||
:type recycling: Boolean
|
||||
:return: Nothing
|
||||
:rtype: None
|
||||
"""
|
||||
share = SambaShare(name, path, btrfs=btrfs, recycle=recycling)
|
||||
user = SambaOption("valid users", user)
|
||||
dir_mask = SambaOption("directory mask", dir_mask)
|
||||
create_mask = SambaOption("create mask", create_mask)
|
||||
if writeable:
|
||||
writeable = SambaOption("writeable", "yes")
|
||||
else:
|
||||
writeable = SambaOption("writeable", "no")
|
||||
share.options.extend([user, dir_mask, create_mask, writeable])
|
||||
db.session.add(share)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def set_samba_global(workgroup, name):
|
||||
|
|
|
@ -14,21 +14,22 @@ class SambaGlobal(db.Model):
|
|||
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)
|
||||
path = db.Column(db.String, nullable=False)
|
||||
recycle = db.Column(db.Boolean)
|
||||
btrfs = db.Column(db.Boolean)
|
||||
options = db.relationship('SambaOptions', order_by="SambaOptions.id", backref="samba_share", lazy="select",
|
||||
options = db.relationship('SambaOption', order_by="SambaOption.id", backref="samba_share", lazy="select",
|
||||
cascade="all, delete-orphan")
|
||||
|
||||
def __init__(self, name, writeable=False, recycling=False, btrfs=False):
|
||||
def __init__(self, name, path, recycle=False, btrfs=False):
|
||||
self.name = name
|
||||
self.writeable = writeable
|
||||
self.recycling = recycling
|
||||
self.path = path
|
||||
self.recycle = recycle
|
||||
self.btrfs = btrfs
|
||||
|
||||
|
||||
class SambaOptions(db.Model):
|
||||
class SambaOption(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
sambashare_id = db.Column(db.Integer, db.ForeignKey('samba_share.id'))
|
||||
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)
|
||||
|
||||
|
|
|
@ -27,12 +27,8 @@ class SambaAddForm(FlaskForm):
|
|||
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!")],
|
||||
create_mask = IntegerField("Dateimaske", [validators.Optional()],
|
||||
render_kw={"placeholder": "0600"})
|
||||
dir_mask = IntegerField("Ordnermaske", [validators.Optional(),
|
||||
validators.NumberRange(min=4, max=4,
|
||||
message="Bitte 4 Zahlen eingeben!")],
|
||||
dir_mask = IntegerField("Ordnermaske", [validators.Optional()],
|
||||
render_kw={"placeholder": "0700"})
|
||||
submit = SubmitField("Freigabe hinzufügen")
|
|
@ -3,7 +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, generate_smb
|
||||
from dirkules.samba.manager import set_samba_global, generate_smb, create_share
|
||||
from dirkules.samba.models import SambaShare
|
||||
from dirkules.samba.validation import SambaConfigForm, SambaAddForm
|
||||
|
||||
|
@ -35,6 +35,8 @@ def config():
|
|||
def add():
|
||||
form = SambaAddForm(request.form)
|
||||
if request.method == 'POST' and form.validate():
|
||||
create_share(form.name.data, form.path.data, form.user.data, form.dir_mask.data, form.create_mask.data,
|
||||
form.writeable.data, form.btrfs.data, form.recycling.data)
|
||||
return redirect(url_for('.index'))
|
||||
return render_template('samba/add.html', form=form)
|
||||
|
||||
|
|
6
dirkules/static/conf/samba_recycle.conf
Normal file
6
dirkules/static/conf/samba_recycle.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
recycle:repository = .recycle
|
||||
recycle:touch_mtime = Yes
|
||||
recycle:keeptree = Yes
|
||||
recycle:versions = Yes
|
||||
recycle:directory_mode = 0700
|
||||
recycle:exclude = *.TMP | *.tmp | ~$*.doc | ~$*.docx | ~$*.xls | ~$*.xlsx | ~$*.xlsm | ~$*.pptx | ~$*.xlam | .~lock.*.odt# | .~lock.*.odp# | .~lock.*.ods#
|
2
dirkules/static/conf/samba_share.conf
Normal file
2
dirkules/static/conf/samba_share.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
browseable = no
|
||||
guest ok = no
|
Loading…
Add table
Reference in a new issue