mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
sharing: Allow directories to be publicly shared
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
d0ed538bfa
commit
1eec1cf9ce
4 files changed
+54
-20
No files matched your search
+25
-7
@@ -43,6 +43,8 @@ def parse_arguments():
|
||||
add_parser.add_argument('--path', required=True, help='Disk path to share')
|
||||
add_parser.add_argument('--groups', nargs='*',
|
||||
help='List of groups that can access the share')
|
||||
add_parser.add_argument('--is-public', default=False, required=False,
|
||||
help='1 if public share else 0')
|
||||
|
||||
remove_parser = subparsers.add_parser('remove',
|
||||
help='Remove an existing share')
|
||||
@@ -71,6 +73,7 @@ def subcommand_add(arguments):
|
||||
name = arguments.name
|
||||
path = arguments.path
|
||||
groups = arguments.groups
|
||||
is_public = arguments.is_public
|
||||
url = '/share/' + name
|
||||
|
||||
if not os.path.exists(APACHE_CONFIGURATION):
|
||||
@@ -90,15 +93,22 @@ def subcommand_add(arguments):
|
||||
aug.set('$conf/Location[last()]/directive[last() + 1]', 'Include')
|
||||
aug.set('$conf/Location[last()]/directive[last()]/arg',
|
||||
'includes/freedombox-sharing.conf')
|
||||
aug.set('$conf/Location[last()]/directive[last() + 1]', 'Include')
|
||||
aug.set('$conf/Location[last()]/directive[last()]/arg',
|
||||
'includes/freedombox-single-sign-on.conf')
|
||||
|
||||
aug.set('$conf/Location[last()]/IfModule/arg', 'mod_auth_pubtkt.c')
|
||||
aug.set('$conf/Location[last()]/IfModule/directive[1]', 'TKTAuthToken')
|
||||
for group_name in groups:
|
||||
aug.set('$conf/Location[last()]/IfModule/directive[1]/arg[last() + 1]',
|
||||
if is_public != "true":
|
||||
aug.set('$conf/Location[last()]/directive[last() + 1]', 'Include')
|
||||
aug.set('$conf/Location[last()]/directive[last()]/arg',
|
||||
'includes/freedombox-single-sign-on.conf')
|
||||
|
||||
aug.set('$conf/Location[last()]/IfModule/arg', 'mod_auth_pubtkt.c')
|
||||
aug.set('$conf/Location[last()]/IfModule/directive[1]', 'TKTAuthToken')
|
||||
for group_name in groups:
|
||||
aug.set(
|
||||
'$conf/Location[last()]/IfModule/directive[1]/arg[last() + 1]',
|
||||
group_name)
|
||||
else:
|
||||
aug.set('$conf/Location[last()]/directive[last() + 1]', 'Require')
|
||||
aug.set('$conf/Location[last()]/directive[last()]/arg[1]', 'all')
|
||||
aug.set('$conf/Location[last()]/directive[last()]/arg[2]', 'granted')
|
||||
|
||||
aug.save()
|
||||
|
||||
@@ -176,9 +186,17 @@ def _list(aug=None):
|
||||
for group in aug.match(location + '//directive["TKTAuthToken"]/arg'):
|
||||
groups.append(aug.get(group))
|
||||
|
||||
def _is_public():
|
||||
"""Must contain the line 'Require all granted'."""
|
||||
require = location + '//directive["Require"]'
|
||||
return bool(aug.match(require)) and aug.get(
|
||||
require + '/arg[1]') == 'all' and aug.get(
|
||||
require + '/arg[2]') == 'granted'
|
||||
|
||||
for share in shares:
|
||||
if share['name'] == name:
|
||||
share['groups'] = groups
|
||||
share['is_public'] = _is_public()
|
||||
|
||||
return shares
|
||||
|
||||
|
||||
Reference in new issue
Block a user