diff -urN smeserver-shared-folders-0.3.old/root/usr/share/smanager/lib/SrvMngr/Controller/Shared_folders.pm smeserver-shared-folders-0.3/root/usr/share/smanager/lib/SrvMngr/Controller/Shared_folders.pm
--- smeserver-shared-folders-0.3.old/root/usr/share/smanager/lib/SrvMngr/Controller/Shared_folders.pm 1970-01-01 01:00:00.000000000 +0100
+++ smeserver-shared-folders-0.3/root/usr/share/smanager/lib/SrvMngr/Controller/Shared_folders.pm 2020-07-31 17:14:00.000000000 +0100
@@ -0,0 +1,337 @@
+package SrvMngr::Controller::Shared_folders;
+
+#----------------------------------------------------------------------
+# heading : Collaboration
+# description : Shared Folders
+# navigation : 2000 2600
+#
+# name : shared_foldersget, method : get, url : /shared_folders, ctlact : Shared_folders#main
+# name : shared_folderss, method : post, url : /shared_folders, ctlact : Shared_folders#do_save
+# name : shared_foldersc, method : get, url : /shared_foldersc, ctlact : Shared_folders#do_create_modify
+# name : shared_foldersc, method : post, url : /shared_foldersc, ctlact : Shared_folders#do_create_modify
+# name : shared_foldersd, method : get, url : /shared_foldersd, ctlact : Shared_folders#do_delete
+# name : shared_foldersp, method : get, url : /shared_foldersp, ctlact : Shared_folders#do_permissions
+# name : shared_folderse, method : get, url : /shared_folderse, ctlact : Shared_folders#do_encrypt
+# routes : end
+#
+# Documentation : https://wiki.contribs.org/SharedFolders
+#----------------------------------------------------------------------
+
+use strict;
+use warnings;
+use Mojo::Base 'Mojolicious::Controller';
+
+use Locale::gettext;
+use SrvMngr::I18N;
+use SrvMngr qw(theme_list init_session);
+
+use Data::Dumper;
+use esmith::util;
+use esmith::HostsDB;
+use esmith::AccountsDB;
+
+our $db = esmith::ConfigDB->open();
+our $adb = esmith::AccountsDB->open();
+
+our $user = 'admin';
+#$ENV{'REMOTE_USER'};
+$user = $1 if ( $user =~ /^([a-z][\-a-z0-9]*)$/ );
+our @usergroups = $adb->user_group_list($user);
+
+use constant FALSE => 0;
+use constant TRUE => 1;
+
+my %shf_datas = ();
+
+sub main {
+ #
+ # Main Panel
+ #
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+ $shf_datas{first} = 'shf_FIRSTPAGE_DESC';
+ do_display($c);
+}
+
+sub do_display {
+ my $c = shift;
+ my $title = $c->l('shf_FORM_TITLE');
+ my $modul = '';
+ my @shares = get_all_shares($c);
+ my @encryptedfolders = get_all_encrypted_shares($c);
+ $shf_datas{trt} = 'LIST';
+
+ $c->stash(
+ title => $title,
+ modul => $modul,
+ shf_datas => \%shf_datas,
+ sharedfolders => \@shares,
+ encryptedfolders => \@encryptedfolders,
+ empty => ( scalar @shares == 0 ),
+ emptye => ( scalar @encryptedfolders == 0 )
+ );
+
+ $c->render( template => 'shared_folders' );
+}
+
+sub get_all_shares {
+ my $c = shift;
+ my @sharesdb = $adb->get_all_by_prop( type => 'share' );
+ my @shares = ();
+ foreach my $sharerec (@sharesdb) {
+ next if ( ( $sharerec->prop('Hide') || 'no' ) eq 'yes' );
+ my $removable = $sharerec->prop('Removable') || 'yes';
+ my %row = (
+ "Name" => $sharerec->key,
+ "Description" => $sharerec->prop("Name"),
+ "Removeable" => $removable
+ );
+ push( @shares, \%row );
+ }
+ return @shares;
+}
+
+sub get_all_encrypted_shares {
+
+ my $c = shift;
+ my @shares = $adb->get_all_by_prop( type => 'share' );
+ my @encfs = ();
+ foreach (@shares) {
+ my @sharegroups = split( /[,;]/,
+ ( $_->prop('WriteGroups') || '' ) . ','
+ . ( $_->prop('ReadGroups') || '' ) );
+ my @shareusers = split( /[,;]/,
+ ( $_->prop('WriteUsers') || '' ) . ','
+ . ( $_->prop('ReadUsers') || '' ) );
+ @sharegroups = keys %{ { map { $_ => 1 } @sharegroups } };
+
+ my %count = ();
+ my @intersection = ();
+ foreach my $element ( @sharegroups, @usergroups ) { $count{$element}++ }
+ foreach my $element ( keys %count ) {
+ push @intersection, $element if ( $count{$element} > 1 );
+ }
+
+ # Only display the share in the list if encryption is enabled
+ # and the user has at least read access
+ if (
+ ( ( $_->prop('Encryption') || 'disabled' ) eq 'enabled' )
+ && ( ( scalar @intersection > 0 )
+ || ( grep { $_ eq $user } @shareusers )
+ || ( $user eq 'admin' ) )
+ )
+ {
+ push @encfs, $_;
+ }
+ }
+ unless ( scalar @encfs > 0 ) {
+ return ();
+ }
+
+ my @encrypted_shares = ();
+ foreach my $i (@encfs) {
+ my $sharename = $i->key();
+ my $sharedesc = $i->prop('Name');
+
+ my $mountstatus =
+`/bin/mount | /bin/grep /home/e-smith/files/shares/$sharename/ | grep -c fuse`;
+ chomp($mountstatus);
+ my $sharestatus =
+ ( $mountstatus eq '1' )
+ ? $c->l('shf_ENCRYPT_MOUNTED')
+ : $c->l('shf_ENCRYPT_NOT_MOUNTED');
+
+ my $actionMount = "shf_ENCRYPT_MOUNT"
+ ; #$q->a({href => "${href}Mount&name=$sharename"},$self->localise('MOUNT')). ' ';
+
+ my $actionUmount = 'shf_ENCRYPT_UNMOUNT'
+ ; #$q->a({href => "${href}Umount&name=$sharename"}, $self->localise('UMOUNT')). ' ';
+
+ my $action = ( $mountstatus eq '1' ) ? $actionUmount : $actionMount;
+
+ my %row = (
+ "Name" => $sharename,
+ "Description" => $sharedesc,
+ "Status" => $sharestatus,
+ "Action" => $action
+ );
+ push( @encrypted_shares, \%row );
+ }
+ return @encrypted_shares;
+}
+
+sub do_encrypt {
+ #
+ # Enable/disable encrypt share clicked
+ #
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+ my $title = $c->l('shf_main_title');
+ my $modul = '';
+ my $mode = $c->param("mode");
+
+ #etc....
+
+ do_display($c); #If no errors
+}
+
+sub do_save {
+ #
+ # Save pressed
+ #
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+
+ my $title = $c->l('shf_main_title');
+ my $modul = '';
+ my $mode = $c->param("mode");
+
+ #etc....
+ if ( $mode = "DEL" ) {
+ my $name = $c->param("name");
+ my $msg = remove_share( $c, $name );
+ if ( $msg eq "ok" ) {
+ $shf_datas{success} = "shf_SUCCESSFULLY_DELETED_SHARE";
+ }
+ else {
+ $shf_datas{error} = $msg;
+ }
+ }
+ do_display($c);
+
+}
+
+sub do_delete {
+ #
+ # Delete/Remove clicked
+ #
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+
+ my $title = $c->l('shf_REMOVE_TITLE');
+ my $modul = '';
+
+ #etc.....
+ $shf_datas{trt} = 'DEL';
+ $c->stash(
+ title => $title,
+ modul => $modul,
+ shf_datas => \%shf_datas,
+ );
+ $c->render( template => 'shared_folders' );
+}
+
+sub do_create_modify {
+ #
+ # Delete/Remove clicked
+ #
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+
+ my $title = $c->l('shf_create_modify_title');
+ my $modul = '';
+ my $empty;
+
+ #Selection options
+ $shf_datas{disable_enable} =
+ [ [ $c->l(''), 'disabled' ], [ $c->l(''), 'enabled' ] ];
+ $shf_datas{recyclebin} = [
+ [ $c->l('shf_DISABLED'), 'disabled' ],
+ [ $c->l('shf_DONT_KEEP_VERSIONS'), 'enabled' ],
+ [ $c->l('shf_KEEP_VERSIONS'), 'keep-versions' ]
+ ];
+ $shf_datas{SMBaccess} = [
+ [ $c->l('shf_ENABLED_BROWSEABLE'), 'browseable' ],
+ [ $c->l('shf_ENABLED_NON_BROWSEABLE'), 'non-browseable' ],
+ [ 'No access', 'none' ]
+ ];
+ $shf_datas{webaccess} = [
+ [ $c->l('shf_ENTIRE_INTERNET_NO_PASSWORD'), 'global' ],
+ [ $c->l('shf_ENTIRE_INTERNET_PASSWORD'), 'global-pw' ],
+ [ $c->l('shf_ENTIRE_INTERNET_PASSWORD_REMOTE'), 'global-pw-remote' ],
+ [ $c->l('shf_LOCAL_NETWORK_NO_PASSWORD'), 'local' ],
+ [ $c->l('shf_LOCAL_NETWORK_PASSWORD'), 'local-pw' ],
+ [ $c->l('shf_NO_ACCESS'), 'None' ]
+ ];
+ $shf_datas{retention} = [
+ [ $c->l('shf_UNLIMITED'), 'unlimited' ],
+ [ $c->l('shf_ONE_WEEK'), 7 ],
+ [ $c->l('shf_ONE_MONTH'), 30 ],
+ [ $c->l('shf_SIX_MONTHS'), 180 ],
+ [ $c->l('shf_ONE_YEAR'), 365 ]
+ ];
+ my $name = $c->param("name") || '';
+ my @params = ();
+ if ($name ne ''){
+ my $namedb = $adb->get($name);
+ my @params = ('SMBaccess' => $namedb->get_value("SMBaccess") || '',
+ );
+ }
+
+ $shf_datas{param_details} = \@params;
+
+ #etc.....
+
+ $shf_datas{trt} = 'CR_MOD';
+ $c->stash(
+ title => $title,
+ modul => $modul,
+ shf_datas => \%shf_datas,
+ empty => $empty
+ );
+ $c->render( template => 'shared_folders' );
+}
+
+sub do_permisssions {
+ #
+ # Delete/Remove clicked
+ #
+ my $c = shift;
+ $c->app->log->info( $c->log_req );
+
+ my $title = $c->l('shf_permissions_title');
+ my $modul = '';
+
+ #etc.....
+
+ $shf_datas{trt} = 'PERM';
+ $c->stash(
+ title => $title,
+ modul => $modul,
+ shf_datas => \%shf_datas,
+ );
+ $c->render( template => 'shared_folders' );
+}
+
+# Remove a share
+sub remove_share {
+ my $c = shift;
+ my $name = shift;
+ my $acct = $adb->get($name);
+
+ #return $self->error('CANCELED','First') if ($c->param('cancel'));
+ return 'shf_CANT_FIND_SHARE'
+ unless ( $acct && $acct->prop('type') eq 'share' );
+
+ # Untaint $name before use in system()
+ $name =~ /(.+)/;
+ $name = $1;
+ my $encryption = $acct->prop('Encryption') || 'disabled';
+ my $mountstatus =
+ `/bin/mount | grep /home/e-smith/files/shares/$name/ | grep -c fuse`;
+ chomp($mountstatus);
+
+ if ( ( $encryption eq 'enabled' ) && ( $mountstatus eq '1' ) ) {
+ return "shf_ERROR_ENCRYPTED_ENABLED";
+ }
+ $acct->set_prop( 'type', 'share-deleted' );
+ if ( system( "/sbin/e-smith/signal-event", "share-delete", $name ) == 0 ) {
+ $acct->delete();
+ }
+ else {
+ return "shf_ERROR_WHILE_DELETING_SHARE";
+ }
+ return "ok";
+}
+
+1;
diff -urN smeserver-shared-folders-0.3.old/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Shared_folders/en.pm smeserver-shared-folders-0.3/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Shared_folders/en.pm
--- smeserver-shared-folders-0.3.old/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Shared_folders/en.pm 1970-01-01 01:00:00.000000000 +0100
+++ smeserver-shared-folders-0.3/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Shared_folders/en.pm 2020-07-31 08:47:00.000000000 +0100
@@ -0,0 +1,125 @@
+package SrvMngr::I18N::Modules::Shared_folders::en;
+use strict;
+use warnings;
+use utf8;
+use Mojo::Base 'SrvMngr::I18N';
+
+use SrvMngr::I18N::Modules::General::en;
+
+my %lexicon = (
+
+'shf_title' => 'Shared Folders',
+'shf_FORM_TITLE' => ' Create, modify, or remove shared folders',
+'shf_FIRSTPAGE_DESC' => ' You can remove any shared folder by clicking on the corresponding command next to the shared folder.',
+'shf_ADD_TITLE' => ' Create or modify a shared folder',
+'shf_NAME_FIELD_DESC' => ' The share name should contain only lower-case letters, numbers, periods, hyphens and underscores, and should start with a lower-case letter. For example "johnson", "intra", and "cust3.prj12" are all valid names, but "3associates", "John Smith" and "Bus!Partner" are not. The name is limited to [_1] characters.',
+'shf_NAME_LABEL' => ' Shared folder name',
+'shf_REMOVE_TITLE' => ' Remove shared folder',
+'shf_REMOVE_DESC' => '
+ You are about to remove the following shared folder
+ All files belonging to this shared folder will be deleted.
+ Are you sure you wish to remove it ?
+ ',
+'shf_ERROR_WHILE_CREATING_SHARE' => ' An error occurred while creating the shared folder.',
+'shf_SUCCESSFULLY_CREATED_SHARE' => ' Successfully created shared folder.',
+'shf_NO_SHARES' => ' There are no shared folders currently configured.',
+'shf_CANT_FIND_SHARE' => ' Can\'t find account for [_1] (does it exist?)',
+'shf_CANT_CREATE_SHARE' => ' Can\'t create new account for [_1] (does it already exist?)',
+'shf_ERROR_WHILE_MODIFYING_SHARE' => ' An error occurred while modifying the shared folder.',
+'shf_SUCCESSFULLY_MODIFIED_SHARE' => ' Successfully modified shared folder.',
+'shf_SUCCESSFULLY_DELETED_SHARE' => ' Successfully deleted shared folder.',
+'shf_ERROR_WHILE_DELETING_SHARE' => ' An error occurred while deleting the share.',
+'shf_Shares' =>
+'Shares',
+'shf_INVALID_SHARE_DESCRIPTION' =>
+'Error: unexpected or missing characters in share description',
+'shf_ACCT_NAME_HAS_INVALID_CHARS' =>
+'The shared folder name "[_1]" contains invalid characters. Shared folder names must start with a lower case letter and contain only lower case letters, numbers, and hyphens.',
+'shf_MAX_SHARE_NAME_LENGTH_ERROR' => ' The shared folder name "[_1]" is too long. The maximum is [_1] characters.',
+'shf_ACCT_CLASHES_WITH_PSEUDONYM' => '
+ The account "[_1]" clashes with pseudonym details for [_2] account "[_3]".
[_2] is a pseudonym for [_1].
+ ', +'shf_ACCOUNT_EXISTS' => ' The account "[_1]" is an existing [_2] account.', +'shf_LABEL_ADD_SHARE_BUTTON' => ' Create a new shared folder', +'shf_DESC_PERMISSIONS' => ' You can use this matrix to define groups and users access permissions.', +'shf_DESC_SMB_SETTINGS' => ' The following settings control the access of this shared folder from the local network, using the SMB/CIFS protocol. ', +'shf_LABEL_SMB_ACCESS' => ' SMB Access', +'shf_LABEL_RECYCLEBIN' => ' Recycle bin', +'shf_LABEL_RETENTION' => ' Retention time', +'shf_UNLIMITED' => ' unlimited', +'shf_ONE_WEEK' => ' one week', +'shf_ONE_MONTH' => ' one month', +'shf_SIX_MONTHS' => ' six months', +'shf_ONE_YEAR' => ' one year', +'shf_DESC_HTTP_SETTINGS' => ' The following settings control the access of this shared folder using the HTTP/HTTPS protocol.', +'shf_LABEL_HTTP_ACCESS' => ' Web Access', +'shf_LABEL_WEBDAV' => ' WebDav support', +'shf_LABEL_REQUIRE_SSL' => ' Force secure connections', +'shf_LABEL_INDEXES' => ' Indexes', +'shf_LABEL_DYNAMIC_CONTENT' => ' Dynamic content execution (PHP, CGI, SSI)', +'shf_LOCAL_NETWORK_NO_PASSWORD' => 'Local network (no password required)', +'shf_LOCAL_NETWORK_PASSWORD' => 'Local network (password required)', +'shf_ENTIRE_INTERNET_NO_PASSWORD' => 'Entire Internet (no password required)', +'shf_ENTIRE_INTERNET_PASSWORD' => 'Entire Internet (password required)', +'shf_ENTIRE_INTERNET_PASSWORD_REMOTE' => 'Entire Internet (password required outside local network)', +'shf_NONE' => 'No access', +'shf_ENABLED_BROWSEABLE' => 'Enabled, browseable', +'shf_ENABLED_NON_BROWSEABLE' => 'Enabled, hidden', +'shf_DONT_KEEP_VERSIONS' => 'Enabled, keep only the latest version', +'shf_KEEP_VERSIONS' => 'Enabled, keep a copy of all versions', +'shf_PERMISSIONS' => ' Permissions', +'shf_WRITE_PERM' => ' Read / Write', +'shf_READ_PERM' => ' Read Only', +'shf_ENABLED' => ' enabled', +'shf_DISABLED' => ' disabled', +'shf_YES' => ' yes', +'shf_NO' => ' no', +'shf_NAME' => 'Name', +'shf_DESCRIPTION' => 'Description', +'shf_ACTION' => ' Action', +'shf_MODIFY' => ' Modify', +'shf_REMOVE' => ' Remove', +'shf_CANCELED' => ' Cancelled', +'shf_MANUAL_PERMS' => ' Permissions on this shared folder are managed manually, modifications will only affect web access if a password is required.+ %=l 'NAME' + | ++ %=l 'DESCRIPTION' + | ++ %=l 'shf_ACTION' + | +||
---|---|---|---|---|
+ "><%=l 'shf_PERMISSIONS'%> + | ++ "><%=l 'MODIFY'%> + | + % ++ &desc=<%= $sharedfolder->{"Description"}%>"><%=l 'REMOVE'%> + | +
+ %=l 'NAME' + | ++ %=l 'DESCRIPTION' + | ++ %=l 'shf_ENCRYPT_STATUS' + | ++ %=l 'shf_ACTION' + | +||
---|---|---|---|---|---|
<%=$actiondesc%> | +
+ %=l 'shf_Pseudonyms' + | ++ %=l 'shf_Local_User' + | ++ | ++ | +
---|
+ %= dumper $c->current_route +
+ % } + +