-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from technikamateur/beta
Beta
- Loading branch information
Showing
17 changed files
with
429 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,160 @@ | ||
from dirkules.models import Pool | ||
|
||
from dirkules.config import staticDir | ||
|
||
from dirkules import db, app_version | ||
from dirkules import db, app_version, app | ||
|
||
from dirkules.samba.models import SambaGlobal, SambaShare, SambaOption | ||
|
||
|
||
def get_pools(): | ||
""" | ||
This function returns suitable pools for a share. | ||
:return: List of tuples (id, label) of pools | ||
""" | ||
pools = Pool.query.all() | ||
choices = [(str(pool.id), pool.label + ": " + pool.drives + " mounted on " + pool.mountpoint) for pool in pools] | ||
return choices | ||
|
||
from dirkules.samba.models import SambaGlobal | ||
|
||
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 | ||
""" | ||
path = Pool.query.get(int(path)).mountpoint + "/{}".format(name) | ||
share = SambaShare(name, path, btrfs=btrfs, recycle=recycling) | ||
user = SambaOption("valid users", user) | ||
if dir_mask is None: | ||
dir_mask = "0700" | ||
if create_mask is None: | ||
create_mask = "0600" | ||
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): | ||
""" | ||
Sets the variables for the [global] part in smb.conf | ||
:param workgroup: Workgroup name | ||
:type workgroup: string | ||
:param name: Smbd server name | ||
:type name: string | ||
:return: nothing | ||
:rtype: None | ||
""" | ||
SambaGlobal.query.delete() | ||
workgroup = SambaGlobal("workgroup", workgroup) | ||
name = SambaGlobal("server string", "%h {}".format(name)) | ||
name = SambaGlobal("server string", "{}".format(name)) | ||
db.session.add(workgroup) | ||
db.session.add(name) | ||
db.session.commit() | ||
|
||
|
||
def generate_smb(): | ||
""" | ||
Function is used to generate a new smb.conf file | ||
:return: nothing | ||
:rtype: None | ||
""" | ||
if SambaGlobal.query.first() is None: | ||
app.logger.warning("Samba not configured. Using default fallback.") | ||
workgroup = 'WORKGROUP' | ||
server_string = '%h dirkules' | ||
else: | ||
workgroup = SambaGlobal.query.get(1) | ||
server_string = SambaGlobal.query.get(2) | ||
workgroup = SambaGlobal.query.get(1).value | ||
server_string = "%h " + str(SambaGlobal.query.get(2).value) | ||
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(app_version)) | ||
f.write() | ||
f.write("# Global Config") | ||
f.write("server string = {}".format(server_string)) | ||
f.write("workgroup = {}".format(workgroup)) | ||
samba_share = open(staticDir + "/conf/samba_share.conf", "r") | ||
samba_recycle = open(staticDir + "/conf/samba_recycle.conf", "r") | ||
f.write("# This file was generated by dirkules v{}\n\n".format(app_version)) | ||
f.write("server string = {}\n".format(server_string)) | ||
f.write("workgroup = {}\n".format(workgroup)) | ||
f.write(samba_global.read()) | ||
f.write("\n\n") | ||
for share in SambaShare.query.all(): | ||
if share.enabled: | ||
f.write("[{}]\n".format(share.name)) | ||
f.write("path = {}\n".format(share.path)) | ||
if share.recycle or share.btrfs: | ||
vfs_obj = "" | ||
if share.recycle: | ||
vfs_obj = vfs_obj + "recycle " | ||
if share.btrfs: | ||
vfs_obj = vfs_obj + "btrfs" | ||
f.write("vfs objects = {}\n".format(vfs_obj)) | ||
f.write(samba_share.read()) | ||
# reset file pointer | ||
samba_share.seek(0) | ||
f.write("\n") | ||
for entry in share.options: | ||
f.write("{} = {}\n".format(entry.option, entry.value)) | ||
if share.recycle: | ||
f.write(samba_recycle.read()) | ||
samba_recycle.seek(0) | ||
f.write("\n\n") | ||
f.close() | ||
samba_global.close() | ||
samba_share.close() | ||
samba_recycle.close() | ||
app.logger.info("Generated new samba config.") | ||
|
||
|
||
def disable_share(share): | ||
""" | ||
Disables a given share object. | ||
:param share: share object | ||
:return: nothing | ||
""" | ||
try: | ||
share.enabled = False | ||
db.session.commit() | ||
except: | ||
db.session.rollback() | ||
|
||
|
||
def enable_share(share): | ||
""" | ||
Enables a given share object. | ||
:param share: share object | ||
:return: nothing | ||
""" | ||
try: | ||
share.enabled = True | ||
db.session.commit() | ||
except: | ||
db.session.rollback() | ||
|
||
|
||
def remove_share(share, remove_data=False): | ||
# TODO: Handling of remove_data. Not implemented because removing of share folder is a future thing. | ||
try: | ||
db.session.delete(share) | ||
db.session.commit() | ||
except: | ||
db.session.rollback() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{% extends "base.html" %} | ||
{% block title %}Freigabe entfernen{% endblock %} | ||
{% block body %} | ||
<div class="topspacer"></div> | ||
<div class="ui container"> | ||
<h2 class="ui center aligned icon header"> | ||
<i class="circular trash icon"></i> | ||
<div class="content"> | ||
Freigabe entfernen | ||
<div class="sub header">Sie möchten die Samba Freigabe mit dem Namen "{{ name }}" entfernen. Bitte | ||
konkretisieren und bestätigen. | ||
</div> | ||
</div> | ||
</h2> | ||
{% from "_formhelpers.html" import render_field %} | ||
{% if form.errors %} | ||
<form method=post class="ui form error"> | ||
{% else %} | ||
<form method=post class="ui form"> | ||
{% endif %} | ||
{{ form.hidden_tag() }} | ||
{{ render_field(form.remove_data) }} | ||
{% if show_modal %} | ||
<div class="ui segment"> | ||
{{ render_field(form.okay) }} | ||
</div> | ||
<div class="ui error message"> | ||
<i class="close icon"></i> | ||
<div class="header"> | ||
Verletzung der Sicherheitsprotokolle | ||
</div> | ||
Die Sicherheitsprotokolle verhindern die automatische Ausführung.<br> | ||
Für das Ausführen der gewünschten Aktion, ist eine Überbrückung der Sicherheitsprotokolle nötig. | ||
Bitte bestätigen. | ||
</div> | ||
{% endif %} | ||
{{ render_field(form.submit) }} | ||
</form> | ||
</div> | ||
{% endblock %} | ||
|
Oops, something went wrong.