Add SM2 panels - WIP
This commit is contained in:
@@ -1,337 +0,0 @@
|
||||
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;
|
942
root/usr/share/smanager/lib/SrvMngr/Controller/Shares-Custom.pm
Normal file
942
root/usr/share/smanager/lib/SrvMngr/Controller/Shares-Custom.pm
Normal file
@@ -0,0 +1,942 @@
|
||||
#
|
||||
# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-05-21 08:46:42
|
||||
#
|
||||
#
|
||||
# Routines to be edited by the developer to provide content and validation for parameters
|
||||
# and provison of the control data for table(s)
|
||||
#
|
||||
use esmith::util;
|
||||
use esmith::util::network;
|
||||
use esmith::ConfigDB;
|
||||
use esmith::HostsDB;
|
||||
use esmith::AccountsDB;
|
||||
use esmith::NetworksDB;
|
||||
use esmith::DomainsDB;
|
||||
|
||||
use constant FALSE => 0;
|
||||
use constant TRUE => 1;
|
||||
|
||||
|
||||
#The most common ones - open DB when required.
|
||||
my $cdb;
|
||||
my $adb;
|
||||
my $ndb;
|
||||
my $hdb;
|
||||
my $ddb;
|
||||
|
||||
# Validation routines - parameters for each panel
|
||||
|
||||
sub validate_LIST {
|
||||
my $c = shift;
|
||||
my $sf_data = shift; #Data hash as parameter
|
||||
# Validation for each field
|
||||
my $ret = "";
|
||||
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub validate_MODIFY {
|
||||
my $c = shift;
|
||||
my $sf_data = shift; #Data hash as parameter
|
||||
# Validation for each field
|
||||
my $ret = "";
|
||||
|
||||
if (! TRUE) #validate $c->param('description')
|
||||
{$ret .= 'Validation for description failed';}
|
||||
if (! TRUE) #validate $c->param('smbaccess')
|
||||
{$ret .= 'Validation for smbaccess failed';}
|
||||
if (! TRUE) #validate $c->param('recyclebin')
|
||||
{$ret .= 'Validation for recyclebin failed';}
|
||||
if (! TRUE) #validate $c->param('retention')
|
||||
{$ret .= 'Validation for retention failed';}
|
||||
if (! TRUE) #validate $c->param('httpaccess')
|
||||
{$ret .= 'Validation for httpaccess failed';}
|
||||
if (! TRUE) #validate $c->param('webdav')
|
||||
{$ret .= 'Validation for webdav failed';}
|
||||
if (! TRUE) #validate $c->param('requireSSL')
|
||||
{$ret .= 'Validation for requireSSL failed';}
|
||||
if (! TRUE) #validate $c->param('indexes')
|
||||
{$ret .= 'Validation for indexes failed';}
|
||||
if (! TRUE) #validate $c->param('dynamic')
|
||||
{$ret .= 'Validation for dynamic failed';}
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub validate_PERMISSIONS {
|
||||
my $c = shift;
|
||||
my $sf_data = shift; #Data hash as parameter
|
||||
# Validation for each field
|
||||
my $ret = "";
|
||||
|
||||
if (! TRUE) #validate $c->param('writegroup')
|
||||
{$ret .= 'Validation for writegroup failed';}
|
||||
if (! TRUE) #validate $c->param('readgroup')
|
||||
{$ret .= 'Validation for readgroup failed';}
|
||||
if (! TRUE) #validate $c->param('writegroup')
|
||||
{$ret .= 'Validation for writegroup failed';}
|
||||
if (! TRUE) #validate $c->param('readgroup')
|
||||
{$ret .= 'Validation for readgroup failed';}
|
||||
if (! TRUE) #validate $c->param('writegroup')
|
||||
{$ret .= 'Validation for writegroup failed';}
|
||||
if (! TRUE) #validate $c->param('readgroup')
|
||||
{$ret .= 'Validation for readgroup failed';}
|
||||
if (! TRUE) #validate $c->param('writegroup')
|
||||
{$ret .= 'Validation for writegroup failed';}
|
||||
if (! TRUE) #validate $c->param('readgroup')
|
||||
{$ret .= 'Validation for readgroup failed';}
|
||||
if (! TRUE) #validate $c->param('writegroup')
|
||||
{$ret .= 'Validation for writegroup failed';}
|
||||
if (! TRUE) #validate $c->param('readgroup')
|
||||
{$ret .= 'Validation for readgroup failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if (! TRUE) #validate $c->param('writeuser')
|
||||
{$ret .= 'Validation for writeuser failed';}
|
||||
if (! TRUE) #validate $c->param('readuser')
|
||||
{$ret .= 'Validation for readuser failed';}
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub validate_REMOVE {
|
||||
my $c = shift;
|
||||
my $sf_data = shift; #Data hash as parameter
|
||||
# Validation for each field
|
||||
my $ret = "";
|
||||
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
# Get singleton data for each panel
|
||||
|
||||
sub get_data_for_panel_LIST {
|
||||
# Return a hash with the fields required which will be loaded into the shared data
|
||||
my $c = shift;
|
||||
my %ret = (
|
||||
'Data1'=>'Data for LIST', #Example
|
||||
# fields from Inputs in LIST $fields['LIST']
|
||||
|
||||
);
|
||||
return %ret;
|
||||
}
|
||||
|
||||
sub get_data_for_panel_MODIFY {
|
||||
# Return a hash with the fields required which will be loaded into the shared data
|
||||
my $c = shift;
|
||||
my $name = $c->param('Selected');
|
||||
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
my $rec = $adb->get($name) || die("Share $name is not in DB ");
|
||||
my %ret = (
|
||||
'Data1'=>'Data for MODIFY', #Example
|
||||
# fields from Inputs in MODIFY $fields['MODIFY']
|
||||
'name' => $name,
|
||||
'description'=>$rec->prop('Name'),
|
||||
'smbaccess'=>$rec->prop('smbAccess'),
|
||||
'recyclebin'=>$rec->prop('RecycleBin'),
|
||||
'retention'=>$rec->prop('RecycleBinRetention'),
|
||||
'httpaccess'=>$rec->prop('httpAccess'),
|
||||
'webdav'=>$rec->prop('WebDav'),
|
||||
'requireSSL'=>$rec->prop('RequireSSL'),
|
||||
'indexes'=>$rec->prop('Indexes'),
|
||||
'dynamic'=>$rec->prop('DynamicContent'),
|
||||
|
||||
);
|
||||
return %ret;
|
||||
}
|
||||
|
||||
sub get_data_for_panel_PERMISSIONS {
|
||||
# Return a hash with the fields required which will be loaded into the shared data
|
||||
my $c = shift;
|
||||
my %ret = (
|
||||
'Data1'=>'Data for PERMISSIONS', #Example
|
||||
# fields from Inputs in PERMISSIONS $fields['PERMISSIONS']
|
||||
'writegroup'=>'writegroup contents',
|
||||
'readgroup'=>'readgroup contents',
|
||||
'writegroup'=>'writegroup contents',
|
||||
'readgroup'=>'readgroup contents',
|
||||
'writegroup'=>'writegroup contents',
|
||||
'readgroup'=>'readgroup contents',
|
||||
'writegroup'=>'writegroup contents',
|
||||
'readgroup'=>'readgroup contents',
|
||||
'writegroup'=>'writegroup contents',
|
||||
'readgroup'=>'readgroup contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
'writeuser'=>'writeuser contents',
|
||||
'readuser'=>'readuser contents',
|
||||
|
||||
);
|
||||
return %ret;
|
||||
}
|
||||
|
||||
sub get_data_for_panel_REMOVE {
|
||||
# Return a hash with the fields required which will be loaded into the shared data
|
||||
my $c = shift;
|
||||
my $name = $c->param('Selected');
|
||||
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
my $rec = $adb->get($name) || die("Share $name is not in DB ");
|
||||
my %ret = (
|
||||
'Data1'=>'Data for MODIFY', #Example
|
||||
# fields from Inputs in MODIFY $fields['MODIFY']
|
||||
'name' => $name,
|
||||
'description'=>$rec->prop('Name'),
|
||||
);
|
||||
return %ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Get control data for table(s)
|
||||
|
||||
# Define a constant hash for field name mapping
|
||||
use constant Table1_FIELD_MAPPING => (
|
||||
'Table1_Name' => 'Table1_Name',
|
||||
'Table1_Description' => 'Table1_Description',
|
||||
'Table1_Actionp' => 'Table1_Actionp',
|
||||
'Table1_Actionm' => 'Table1_Actionm',
|
||||
'Table1_Actionr' => 'Table1_Actionr',
|
||||
);
|
||||
|
||||
sub actual_Table1 {
|
||||
my $c = shift;
|
||||
my @ret = ();
|
||||
# Actual code for extracting Table1
|
||||
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
my @shares = $adb->get_all_by_prop(type => 'share');
|
||||
foreach my $share (@shares) {
|
||||
my $sharename = $share->key();
|
||||
my $sharedesc = $share->prop('Name');
|
||||
$c->app->log->info("$sharename : $sharedesc");
|
||||
next if (($share->prop('Hide') || 'no') eq 'yes');
|
||||
my $removable = $share->prop('Removable') || 'yes';
|
||||
my $actionModify = '<a href="sharesd?trt=MODIFY&Selected='.$sharename.'">'.$c->l('sf_Modify').'</a>';
|
||||
my $actionPerm = '<a href="sharesd?trt=PERMISSIONS&Selected='.$sharename.'">'.$c->l('sf_Permisssions').'</a>';
|
||||
my $actionRemove = ($removable ne 'no') ?'<a href="sharesd?trt=REMOVE&Selected='.$sharename.'">'.$c->l('sf_Remove').'</a>': '';
|
||||
push @ret,
|
||||
{ Table1_Name => $sharename,
|
||||
Table1_Description => $sharedesc,
|
||||
Table1_Actionp => $actionPerm,
|
||||
Table1_Actionm => $actionModify,
|
||||
Table1_Actionr => $actionRemove,
|
||||
};
|
||||
}
|
||||
return @ret;
|
||||
}
|
||||
|
||||
sub get_Table1 {
|
||||
# Return an array of hashes of the contents for each row and column for Table1
|
||||
my $c = shift;
|
||||
my @source_records = $c->actual_Table1();
|
||||
my @transformed_records;
|
||||
my %Field_Mapping = Table1_FIELD_MAPPING();
|
||||
# Iterate over each record in the source array
|
||||
for my $source_record (@source_records) {
|
||||
my %transformed_record;
|
||||
# Iterate over each key-value pair in the $Field_Mapping constant
|
||||
while (my ($target, $source) = each %Field_Mapping) {
|
||||
# Check if the source field exists in the source record
|
||||
if (exists $source_record->{$source}) {
|
||||
# Assign the source field value to the target field in the transformed record
|
||||
$transformed_record{$target} = $source_record->{$source};
|
||||
}
|
||||
}
|
||||
# Add transformed record to the array if it's not empty
|
||||
push @transformed_records, \%transformed_record if %transformed_record;
|
||||
}
|
||||
return \@transformed_records;
|
||||
}
|
||||
|
||||
# Define a constant hash for field name mapping
|
||||
use constant Table2_FIELD_MAPPING => (
|
||||
'Table2-Groups' => 'Source-for-Table2-Groups',
|
||||
'Table2-Description' => 'Source-for-Table2-Description',
|
||||
'Table2-Read / Write' => 'Source-for-Table2-Read / Write',
|
||||
'Table2-Read Only' => 'Source-for-Table2-Read Only'
|
||||
#'target_field2' => 'source_field2',
|
||||
# Add more mappings as needed
|
||||
);
|
||||
|
||||
sub actual_Table2 {
|
||||
my $c = shift;
|
||||
my @ret = ();
|
||||
# Actual code for extracting Table2
|
||||
return @ret;
|
||||
}
|
||||
|
||||
sub get_Table2 {
|
||||
# Return an array of hashes of the contents for each row and column for Table2
|
||||
my $c = shift;
|
||||
my @source_records = $c->actual_Table2();
|
||||
my @transformed_records;
|
||||
my %Field_Mapping = Table2_FIELD_MAPPING();
|
||||
# Iterate over each record in the source array
|
||||
for my $source_record (@source_records) {
|
||||
my %transformed_record;
|
||||
# Iterate over each key-value pair in the $Field_Mapping constant
|
||||
while (my ($target, $source) = each %Field_Mapping) {
|
||||
# Check if the source field exists in the source record
|
||||
if (exists $source_record->{$source}) {
|
||||
# Assign the source field value to the target field in the transformed record
|
||||
$transformed_record{$target} = $source_record->{$source};
|
||||
}
|
||||
}
|
||||
# Add transformed record to the array if it's not empty
|
||||
push @transformed_records, \%transformed_record if %transformed_record;
|
||||
}
|
||||
return \@transformed_records;
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Return hash with values from row in which link clicked on table
|
||||
|
||||
sub get_selected_LIST {
|
||||
my $c = shift;
|
||||
my $selected = shift; #Parameter is name of selected row.
|
||||
my $is_new_record = shift; #Indicates new record required (defaults)
|
||||
my %ret = {};
|
||||
return %ret;
|
||||
}
|
||||
|
||||
sub get_selected_MODIFY {
|
||||
my $c = shift;
|
||||
my $selected = shift; #Parameter is name of selected row.
|
||||
my $is_new_record = shift; #Indicates new record required (defaults)
|
||||
my %ret = {};
|
||||
return %ret;
|
||||
}
|
||||
|
||||
sub get_selected_PERMISSIONS {
|
||||
my $c = shift;
|
||||
my $selected = shift; #Parameter is name of selected row.
|
||||
my $is_new_record = shift; #Indicates new record required (defaults)
|
||||
my %ret = {};
|
||||
return %ret;
|
||||
}
|
||||
|
||||
sub get_selected_REMOVE {
|
||||
my $c = shift;
|
||||
my $selected = shift; #Parameter is name of selected row.
|
||||
my $is_new_record = shift; #Indicates new record required (defaults)
|
||||
my %ret = {};
|
||||
return %ret;
|
||||
}
|
||||
|
||||
|
||||
#after sucessful modify or create or whatever and submit then perfom (if the params validate)
|
||||
|
||||
sub perform_LIST {
|
||||
my $c = shift;
|
||||
my $sf_data = shift; #Data hash as parameter
|
||||
my $ret = "";
|
||||
my $db = $cdb; #maybe one of the others
|
||||
my $dbkey = 'ChangeThis';
|
||||
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
|
||||
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub perform_MODIFY {
|
||||
my $c = shift;
|
||||
my $sf_data = shift; #Data hash as parameter
|
||||
my $ret = "";
|
||||
#my $db = $cdb; #maybe one of the others
|
||||
#my $dbkey = 'ChangeThis';
|
||||
## To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
|
||||
|
||||
#if (! TRUE) #copy or perform with value: description e.g. $db->set_prop($dbkey,'description',$c->param('description'),type=>'service'))
|
||||
#{$ret .= 'Perform/save failed for description';}
|
||||
#if (! TRUE) #copy or perform with value: smbaccess e.g. $db->set_prop($dbkey,'smbaccess',$c->param('smbaccess'),type=>'service'))
|
||||
#{$ret .= 'Perform/save failed for smbaccess';}
|
||||
#if (! TRUE) #copy or perform with value: recyclebin e.g. $db->set_prop($dbkey,'recyclebin',$c->param('recyclebin'),type=>'service'))
|
||||
#{$ret .= 'Perform/save failed for recyclebin';}
|
||||
#if (! TRUE) #copy or perform with value: retention e.g. $db->set_prop($dbkey,'retention',$c->param('retention'),type=>'service'))
|
||||
#{$ret .= 'Perform/save failed for retention';}
|
||||
#if (! TRUE) #copy or perform with value: httpaccess e.g. $db->set_prop($dbkey,'httpaccess',$c->param('httpaccess'),type=>'service'))
|
||||
#{$ret .= 'Perform/save failed for httpaccess';}
|
||||
#if (! TRUE) #copy or perform with value: webdav e.g. $db->set_prop($dbkey,'webdav',$c->param('webdav'),type=>'service'))
|
||||
#{$ret .= 'Perform/save failed for webdav';}
|
||||
#if (! TRUE) #copy or perform with value: requireSSL e.g. $db->set_prop($dbkey,'requireSSL',$c->param('requireSSL'),type=>'service'))
|
||||
#{$ret .= 'Perform/save failed for requireSSL';}
|
||||
#if (! TRUE) #copy or perform with value: indexes e.g. $db->set_prop($dbkey,'indexes',$c->param('indexes'),type=>'service'))
|
||||
#{$ret .= 'Perform/save failed for indexes';}
|
||||
#if (! TRUE) #copy or perform with value: dynamic e.g. $db->set_prop($dbkey,'dynamic',$c->param('dynamic'),type=>'service'))
|
||||
#{$ret .= 'Perform/save failed for dynamic';}
|
||||
$ret = $c->save_share();
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub perform_PERMISSIONS {
|
||||
my $c = shift;
|
||||
my $sf_data = shift; #Data hash as parameter
|
||||
my $ret = "";
|
||||
my $db = $cdb; #maybe one of the others
|
||||
my $dbkey = 'ChangeThis';
|
||||
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
|
||||
|
||||
if (! TRUE) #copy or perform with value: writegroup e.g. $db->set_prop($dbkey,'writegroup',$c->param('writegroup'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writegroup';}
|
||||
if (! TRUE) #copy or perform with value: readgroup e.g. $db->set_prop($dbkey,'readgroup',$c->param('readgroup'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readgroup';}
|
||||
if (! TRUE) #copy or perform with value: writegroup e.g. $db->set_prop($dbkey,'writegroup',$c->param('writegroup'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writegroup';}
|
||||
if (! TRUE) #copy or perform with value: readgroup e.g. $db->set_prop($dbkey,'readgroup',$c->param('readgroup'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readgroup';}
|
||||
if (! TRUE) #copy or perform with value: writegroup e.g. $db->set_prop($dbkey,'writegroup',$c->param('writegroup'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writegroup';}
|
||||
if (! TRUE) #copy or perform with value: readgroup e.g. $db->set_prop($dbkey,'readgroup',$c->param('readgroup'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readgroup';}
|
||||
if (! TRUE) #copy or perform with value: writegroup e.g. $db->set_prop($dbkey,'writegroup',$c->param('writegroup'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writegroup';}
|
||||
if (! TRUE) #copy or perform with value: readgroup e.g. $db->set_prop($dbkey,'readgroup',$c->param('readgroup'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readgroup';}
|
||||
if (! TRUE) #copy or perform with value: writegroup e.g. $db->set_prop($dbkey,'writegroup',$c->param('writegroup'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writegroup';}
|
||||
if (! TRUE) #copy or perform with value: readgroup e.g. $db->set_prop($dbkey,'readgroup',$c->param('readgroup'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readgroup';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if (! TRUE) #copy or perform with value: writeuser e.g. $db->set_prop($dbkey,'writeuser',$c->param('writeuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for writeuser';}
|
||||
if (! TRUE) #copy or perform with value: readuser e.g. $db->set_prop($dbkey,'readuser',$c->param('readuser'),type=>'service'))
|
||||
{$ret .= 'Perform/save failed for readuser';}
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub perform_REMOVE {
|
||||
my $c = shift;
|
||||
my $sf_data = shift; #Data hash as parameter
|
||||
my $ret = "";
|
||||
my $db = $cdb; #maybe one of the others
|
||||
my $dbkey = 'ChangeThis';
|
||||
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
|
||||
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
sub create_link{
|
||||
# WIP
|
||||
my ($c,$route, $panel, $index) = @_;
|
||||
my $link = "$route?trt=$panel&Selected=$index";
|
||||
return $link;
|
||||
}
|
||||
|
||||
# Create a new shared folder
|
||||
|
||||
#sub create_share {
|
||||
#my $c = shift;
|
||||
#my $name = $c->param('name');
|
||||
#my $encryption = $c->param('encryption') || 'disabled';
|
||||
#my $password = $c->param('password');
|
||||
#my $password2 = $c->param('password2');
|
||||
|
||||
#my $msg = $c->validate_name($name);
|
||||
|
||||
#unless ($msg eq "OK") {
|
||||
#return $c->error($msg);
|
||||
#}
|
||||
|
||||
#$msg = $c->max_share_name_length($name);
|
||||
|
||||
#unless ($msg eq "OK") {
|
||||
#return $c->error($msg);
|
||||
#}
|
||||
|
||||
#$msg = $c->conflict_check($name);
|
||||
#unless ($msg eq "OK") {
|
||||
#return $c->error($msg);
|
||||
#}
|
||||
|
||||
#$msg = ($encryption eq 'enabled') ? $c->confirm_password($password,$password2) : 'OK';
|
||||
#unless ($msg eq "OK") {
|
||||
#return $c->error($msg);
|
||||
#}
|
||||
|
||||
#if (my $acct = $a->new_record($name, {
|
||||
#Name => $c->param('description'),
|
||||
#Encryption => $encryption,
|
||||
#InactivityTimeOut => ($c->param('inactivity') || ''),
|
||||
#RecycleBin => $c->param('recyclebin'),
|
||||
#RecycleBinRetention => $c->param('retention'),
|
||||
#smbAccess => $c->param('smbaccess'),
|
||||
#httpAccess => $c->param('httpaccess'),
|
||||
#WebDav => $c->param('webdav'),
|
||||
#Pydio => ($c->param('pydio') || 'disabled'),
|
||||
#RequireSSL => $c->param('requireSSL'),
|
||||
#Indexes => $c->param('indexes'),
|
||||
#DynamicContent => $c->param('dynamic'),
|
||||
#type => 'share',
|
||||
#}) ) {
|
||||
## Untaint $name before use in system()
|
||||
#$name =~ /(.+)/; $name = $1;
|
||||
|
||||
#if ($encryption eq 'enabled') {
|
||||
#my $source = '/home/e-smith/files/shares/' . $name . '/.store';
|
||||
#my $dest = '/home/e-smith/files/shares/' . $name . '/files';
|
||||
#File::Path::mkpath ($source);
|
||||
#mkdir $dest;
|
||||
#open(DIR, "| /usr/bin/encfs -S --public -o nonempty,umask=000 $source $dest > /dev/null 2>&1");
|
||||
#print DIR "\n$password";
|
||||
#close DIR;
|
||||
#$c->error("ERROR_WITH_ENCRYPTION") unless(
|
||||
#system("/bin/fusermount -uz $dest") == 0
|
||||
#);
|
||||
#}
|
||||
|
||||
#if (system ("/sbin/e-smith/signal-event", "share-create", $name) == 0) {
|
||||
#$c->success("SUCCESSFULLY_CREATED_SHARE", "Permissions");
|
||||
#}
|
||||
#else {
|
||||
#$c->error("ERROR_WHILE_CREATING_SHARE");
|
||||
#}
|
||||
#}
|
||||
#else {
|
||||
#$c->error('CANT_CREATE_SHARE');
|
||||
#}
|
||||
#}
|
||||
|
||||
## Modify a share.
|
||||
## This sub shares a lot of code with create share
|
||||
## It should be merged
|
||||
#sub modify_share {
|
||||
#my $c = shift;
|
||||
#my $name = $c->param('name');
|
||||
#my $acct = $a->get($name);
|
||||
|
||||
#return $c->error('CANT_FIND_SHARE') unless($acct && $acct->prop('type') eq 'share');
|
||||
|
||||
#$acct->merge_props(
|
||||
#Name => $c->param('description'),
|
||||
#InactivityTimeOut => ($c->param('inactivity') || ''),
|
||||
#RecycleBin => $c->param('recyclebin'),
|
||||
#RecycleBinRetention => $c->param('retention'),
|
||||
#smbAccess => $c->param('smbaccess'),
|
||||
#httpAccess => $c->param('httpaccess'),
|
||||
#WebDav => $c->param('webdav'),
|
||||
#Pydio => ($c->param('pydio') || 'disabled'),
|
||||
#RequireSSL => $c->param('requireSSL'),
|
||||
#Indexes => $c->param('indexes'),
|
||||
#DynamicContent => $c->param('dynamic'),
|
||||
#);
|
||||
|
||||
## Untaint $name before use in system()
|
||||
#$name =~ /(.+)/; $name = $1;
|
||||
#if (system ("/sbin/e-smith/signal-event", "share-modify", $name) == 0) {
|
||||
#$c->success("SUCCESSFULLY_MODIFIED_SHARE");
|
||||
#}
|
||||
#else {
|
||||
#$c->error("ERROR_WHILE_MODIFYING_SHARE");
|
||||
#}
|
||||
#return undef;
|
||||
#}
|
||||
|
||||
sub save_share {
|
||||
#
|
||||
# Merged the two subs
|
||||
#
|
||||
my $c = shift;
|
||||
my $name = $c->param('name');
|
||||
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
my $acct = $adb->get($name);
|
||||
my $is_create = !$acct;
|
||||
|
||||
if ($is_create) {
|
||||
# Validate new share parameters
|
||||
my $msg = $c->validate_name($name);
|
||||
return $c->l($msg) unless $msg eq 'ok';
|
||||
|
||||
$msg = $c->max_share_name_length($name);
|
||||
return $c->l($msg) unless $msg eq 'ok';
|
||||
|
||||
$msg = $c->conflict_check($name);
|
||||
return $c->l($msg) unless $msg eq 'ok';
|
||||
|
||||
# Handle encryption parameters
|
||||
my $encryption = $c->param('encryption') || 'disabled';
|
||||
my $password;
|
||||
if ($encryption eq 'enabled') {
|
||||
$password = $c->param('password');
|
||||
my $password2 = $c->param('password2');
|
||||
$msg = $c->confirm_password($password, $password2);
|
||||
return $c->l($msg) unless $msg eq 'ok';
|
||||
}
|
||||
|
||||
# Create new share record
|
||||
$acct = $adb->new_record($name, {
|
||||
Name => $c->param('description'),
|
||||
Encryption => $encryption,
|
||||
InactivityTimeOut => ($c->param('inactivity') || ''),
|
||||
RecycleBin => $c->param('recyclebin'),
|
||||
RecycleBinRetention => $c->param('retention'),
|
||||
smbAccess => $c->param('smbaccess'),
|
||||
httpAccess => $c->param('httpaccess'),
|
||||
WebDav => $c->param('webdav'),
|
||||
Pydio => ($c->param('pydio') || 'disabled'),
|
||||
RequireSSL => $c->param('requireSSL'),
|
||||
Indexes => $c->param('indexes'),
|
||||
DynamicContent => $c->param('dynamic'),
|
||||
type => 'share',
|
||||
}) or return $c->l('sf_CANT_CREATE_SHARE');
|
||||
|
||||
# Set up encrypted filesystem if needed
|
||||
if ($encryption eq 'enabled') {
|
||||
my $source = "/home/e-smith/files/shares/$name/.store";
|
||||
my $dest = "/home/e-smith/files/shares/$name/files";
|
||||
File::Path::mkpath($source);
|
||||
mkdir $dest;
|
||||
|
||||
open(my $dir, "| /usr/bin/encfs -S --public -o nonempty,umask=000 $source $dest > /dev/null 2>&1")
|
||||
or die "Failed to open encfs command: $!";
|
||||
print $dir "\n$password";
|
||||
close $dir;
|
||||
|
||||
return $c->l("sf_ERROR_WITH_ENCRYPTION") unless(
|
||||
system("/bin/fusermount -uz $dest") == 0
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
# Validate existing share
|
||||
return $c->l('sf_CANT_FIND_SHARE') unless $acct->prop('type') eq 'share';
|
||||
|
||||
# Update share properties
|
||||
$acct->merge_props(
|
||||
Name => $c->param('description'),
|
||||
InactivityTimeOut => ($c->param('inactivity') || ''),
|
||||
RecycleBin => $c->param('recyclebin'),
|
||||
RecycleBinRetention => $c->param('retention'),
|
||||
smbAccess => $c->param('smbaccess'),
|
||||
httpAccess => $c->param('httpaccess'),
|
||||
WebDav => $c->param('webdav'),
|
||||
Pydio => ($c->param('pydio') || 'disabled'),
|
||||
RequireSSL => $c->param('requireSSL'),
|
||||
Indexes => $c->param('indexes'),
|
||||
DynamicContent => $c->param('dynamic'),
|
||||
);
|
||||
}
|
||||
|
||||
# Untaint and execute system command
|
||||
$name =~ /(.+)/ && ($name = $1);
|
||||
my $event = $is_create ? "share-create" : "share-modify";
|
||||
|
||||
if (system("/sbin/e-smith/signal-event", $event, $name) == 0) {
|
||||
return $c->l('ok')
|
||||
# $is_create ? "SUCCESSFULLY_CREATED_SHARE" : "SUCCESSFULLY_MODIFIED_SHARE",
|
||||
# $is_create ? "Permissions" : ()
|
||||
# );
|
||||
}
|
||||
else {
|
||||
$c->l($is_create ? "sf_ERROR_WHILE_CREATING_SHARE" : "sf_ERROR_WHILE_MODIFYING_SHARE");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
sub modify_perm {
|
||||
my $c = shift;
|
||||
my $name = $c->param('name');
|
||||
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
my $acct = $adb->get($name);
|
||||
|
||||
return $c->l('sf_CANT_FIND_SHARE') unless($acct && $acct->prop('type') eq 'share');
|
||||
|
||||
my $encryption = $acct->prop('Encryption') || 'disabled';
|
||||
|
||||
my $WriteGroups = join(",", $c->param('writegroup'));
|
||||
my $WriteUsers = join(",", $c->param('writeuser'));
|
||||
|
||||
my @CleanReadGroups = ();
|
||||
my @CleanReadUsers = ();
|
||||
|
||||
# EncFS doesn't expose underlying ACLs
|
||||
# So, just remove any read only groups
|
||||
# Read Only is not supported with encryption
|
||||
if ($encryption ne 'enabled'){
|
||||
# No need to have read access if write is already granted
|
||||
foreach my $group ($c->param('readgroup')){
|
||||
push (@CleanReadGroups, $group) unless (grep { $_ eq $group } $c->param('writegroup'));
|
||||
}
|
||||
foreach my $user ($c->param('readuser')){
|
||||
push (@CleanReadUsers, $user) unless (grep { $_ eq $user } $c->param('writeuser'));
|
||||
}
|
||||
}
|
||||
my $ReadGroups = join(",",@CleanReadGroups);
|
||||
my $ReadUsers = join(",",@CleanReadUsers);
|
||||
|
||||
$acct->merge_props(
|
||||
WriteGroups => $WriteGroups,
|
||||
ReadGroups => $ReadGroups,
|
||||
WriteUsers => $WriteUsers,
|
||||
ReadUsers => $ReadUsers,
|
||||
);
|
||||
|
||||
# Untaint $name before use in system()
|
||||
$name =~ /(.+)/; $name = $1;
|
||||
if (system ("/sbin/e-smith/signal-event", "share-modify", $name) == 0) {
|
||||
return 'ok'; #$c->success("sf_SUCCESSFULLY_MODIFIED_SHARE");
|
||||
}
|
||||
else {
|
||||
return $c->l("sf_ERROR_WHILE_MODIFYING_SHARE");
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
# Remove a share
|
||||
sub remove_share {
|
||||
my $c = shift;
|
||||
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
my $name = $c->param('name');
|
||||
my $acct = $adb->get($name);
|
||||
return $c->l('sf_CANCELED','First') if ($c->param('cancel'));
|
||||
return $c->l('sf_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')){
|
||||
$c->l("sf_ERROR_ENCRYPTED_ENABLED");
|
||||
return undef;
|
||||
}
|
||||
|
||||
$acct->set_prop('type', 'share-deleted');
|
||||
|
||||
if (system ("/sbin/e-smith/signal-event", "share-delete", $name) == 0) {
|
||||
return 'ok'; #$c->success("SUCCESSFULLY_DELETED_SHARE");
|
||||
$acct->delete();
|
||||
}
|
||||
else {
|
||||
$c->l("sf_ERROR_WHILE_DELETING_SHARE");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
# Check the proposed name for clashes with existing pseudonyms or other
|
||||
# accounts of any type.
|
||||
|
||||
sub conflict_check {
|
||||
my ($c, $name) = @_;
|
||||
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
my $rec = $adb->get($name);
|
||||
|
||||
my $type;
|
||||
if (defined $rec){
|
||||
my $type = $rec->prop('type');
|
||||
if ($type eq "pseudonym"){
|
||||
my $acct = $rec->prop("Account");
|
||||
my $acct_type = $adb->get($acct)->prop('type');
|
||||
|
||||
return $c->l('sf_ACCT_CLASHES_WITH_PSEUDONYM',
|
||||
{acctName => $name, acctType => $acct_type, acct => $acct});
|
||||
}
|
||||
}
|
||||
elsif (defined getpwnam($name) || defined getgrnam($name)){
|
||||
$type = 'system';
|
||||
}
|
||||
else{
|
||||
# No account record and no account
|
||||
return 'ok';
|
||||
}
|
||||
return $c->l('sf_ACCOUNT_EXISTS',
|
||||
{acctName => $name, acctType => $type});
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Checks that the name supplied does not contain any unacceptable chars.
|
||||
# Returns OK on success or a localised error message otherwise.
|
||||
sub validate_name {
|
||||
my ($c, $acctName) = @_;
|
||||
|
||||
unless ($acctName =~ /^([a-z0-9][\_\.\-a-z0-9]*)\$?$/){
|
||||
return $c->l('sf_ACCT_NAME_HAS_INVALID_CHARS',
|
||||
{acctName => $acctName});
|
||||
}
|
||||
return 'ok';
|
||||
}
|
||||
|
||||
# Check if inactivity is a number
|
||||
sub validate_inactivity {
|
||||
my ($c, $inac) = @_;
|
||||
|
||||
unless ($inac =~ /^\d+$/){
|
||||
return $c->l('sf_INVALID_INACTIVITY',
|
||||
{inactivity => $inac});
|
||||
}
|
||||
return 'ok';
|
||||
}
|
||||
|
||||
# Check if both passwords match
|
||||
# and are more than 8 chars
|
||||
sub confirm_password {
|
||||
|
||||
my ($c, $pass1, $pass2) = @_;
|
||||
|
||||
return 'ok' if ($c->{cgi}->param('encryption') eq 'disabled');
|
||||
|
||||
my @num = split(//,$pass1);
|
||||
unless (scalar (@num) >= 8){
|
||||
return $c->l('sf_PASSWORD_TOO_SHORT');
|
||||
}
|
||||
|
||||
unless ($pass1 eq $pass2){
|
||||
return $c->l('sf_PASSWORD_MISMATCH');
|
||||
}
|
||||
return 'ok';
|
||||
}
|
||||
|
||||
sub max_share_name_length {
|
||||
my ($c, $data) = @_;
|
||||
$cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
|
||||
my $rec = $cdb->get('maxShareNameLength');
|
||||
my $max = (defined $rec ? $rec->value : '12');
|
||||
|
||||
if (length($data) <= $max) {
|
||||
return "ok";
|
||||
}
|
||||
else {
|
||||
return $c->l("sf_MAX_SHARE_NAME_LENGTH_ERROR",
|
||||
{acctName => $data,
|
||||
maxShareNameLength => $max,
|
||||
maxLength => $max});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
398
root/usr/share/smanager/lib/SrvMngr/Controller/Shares.pm
Normal file
398
root/usr/share/smanager/lib/SrvMngr/Controller/Shares.pm
Normal file
@@ -0,0 +1,398 @@
|
||||
package SrvMngr::Controller::Shares;
|
||||
#
|
||||
# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-05-21 08:46:42
|
||||
# Remember that each route must be unique (else they just overwrite each other).
|
||||
# you cannot have get and post on the same name and url.
|
||||
#
|
||||
#----------------------------------------------------------------------
|
||||
# heading : Network
|
||||
# description : Shared Folders
|
||||
# navigation : 7000 400
|
||||
#
|
||||
# name : shares, method : get, url : /shares, ctlact : Shares#main
|
||||
# name : sharesu, method : post, url : /sharesu, ctlact : Shares#do_update
|
||||
# name : sharesd, method : get, url : /sharesd, ctlact : Shares#do_display
|
||||
#
|
||||
# routes : end
|
||||
#
|
||||
# Documentation: https://wiki.contribs.org/Shares
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# Scheme of things:
|
||||
#
|
||||
# TBA!!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
|
||||
use constant FALSE => 0;
|
||||
use constant TRUE => 1;
|
||||
|
||||
use Locale::gettext;
|
||||
use SrvMngr::I18N;
|
||||
use SrvMngr qw(theme_list init_session);
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
use esmith::util;
|
||||
use esmith::util::network;
|
||||
use esmith::ConfigDB;
|
||||
use esmith::AccountsDB;
|
||||
use esmith::NetworksDB;
|
||||
use esmith::HostsDB;
|
||||
use esmith::DomainsDB;
|
||||
|
||||
my $cdb;
|
||||
my $adb;
|
||||
my $ndb;
|
||||
my $hdb;
|
||||
my $ddb;
|
||||
|
||||
my %sf_data;
|
||||
|
||||
require '/usr/share/smanager/lib/SrvMngr/Controller/Shares-Custom.pm'; #The code that is to be added by the developer
|
||||
|
||||
sub main {
|
||||
#
|
||||
# Initial entry - route is "/<whatever>"
|
||||
#
|
||||
#set initial panel
|
||||
#for initial panel:
|
||||
#Specifiy panel to enter
|
||||
#load up _data hash with DB fields
|
||||
#load up stash with pointer(s) to control fields hash(= get-))
|
||||
#and a pointer to the prefix_data hash
|
||||
#render initial panel
|
||||
|
||||
my $c = shift;
|
||||
$c->app->log->info( $c->log_req );
|
||||
|
||||
#The most common ones
|
||||
$cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
|
||||
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
$ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
|
||||
$hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
|
||||
$ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
|
||||
%sf_data = ();
|
||||
my $title = $c->l('sf_Shared_Folders');
|
||||
my $modul = '';
|
||||
|
||||
$sf_data{'trt'} = 'LIST';
|
||||
|
||||
#Load any DB entries into the <prefix>_data area so as they are preset in the form
|
||||
# which DB - this only really works if the initial panel is a PARAMS type panel and not a TABLE
|
||||
my $db = $cdb; #pickup local or global db or Default to config
|
||||
|
||||
|
||||
$c->do_display($sf_data{'trt'});
|
||||
|
||||
}
|
||||
|
||||
# Post request with params - submit from the form
|
||||
sub do_update {
|
||||
#
|
||||
# Return after submit pushed on panel (this is a post) - route is "/<whatever>u"
|
||||
# parameters in the params hash.
|
||||
#
|
||||
#load up all params into prefix_data hash:
|
||||
#By panel (series of if statements - only one executed):
|
||||
#call validate-PANEL() - return ret = ok or error message
|
||||
|
||||
#if validation not ok:
|
||||
#render back to current panel with error message in stash
|
||||
#otherwise:
|
||||
#By panel (series of if statements - only one executed):
|
||||
#do whatever is required: call perform-PANEL() - return "ok" or Error Message
|
||||
#call signal-event for any global actions specified (check it exists - error and continue?)
|
||||
#if action smeserver-<whatever>-update exists
|
||||
#signal_event smeserver-<whatever>-update
|
||||
#call signal-event for any specific actions for thids panel (check it exists first - error and continue)
|
||||
#set success in stash
|
||||
#if no "nextpanel" entry:
|
||||
#set firstpanel
|
||||
#else
|
||||
#set nextpanel
|
||||
#call render
|
||||
|
||||
my $c = shift;
|
||||
$c->app->log->info($c->log_req);
|
||||
my $modul = '';
|
||||
|
||||
#The most common ones - you might want to comment out any not used.
|
||||
$cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
|
||||
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
$ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
|
||||
$hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
|
||||
$ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
|
||||
my $title = $c->l('sf_Shared_Folders');
|
||||
|
||||
# Accessing all POST/GET parameters
|
||||
my $params = $c->req->params->to_hash;
|
||||
|
||||
# Get number of POST parameters
|
||||
#my $num_params = keys scaler %$params;
|
||||
|
||||
#Params are available in the hash "params" - copy to the prefix_data hash
|
||||
#while (my ($key, $value) = each %{$c->req->params->to_hash}) {
|
||||
# $sf_data{$key} = $value;
|
||||
#}
|
||||
|
||||
# the value of trt will tell you which panel has returned
|
||||
my $trt = $c->param('trt') || 'LIST'; #hidden control on every form.
|
||||
my $ret = 'ok';
|
||||
|
||||
#Validate the parameters in a custom sub one for each panel (although only one of these will be executed)
|
||||
my $thispanel;
|
||||
|
||||
if ($trt eq 'LIST'){
|
||||
#Validate form parameters for panel LIST
|
||||
$ret = $c->validate_LIST(\%sf_data);
|
||||
$thispanel = 'LIST';
|
||||
}
|
||||
|
||||
if ($trt eq 'MODIFY'){
|
||||
#Validate form parameters for panel MODIFY
|
||||
$ret = $c->validate_MODIFY(\%sf_data);
|
||||
$thispanel = 'MODIFY';
|
||||
}
|
||||
|
||||
if ($trt eq 'PERMISSIONS'){
|
||||
#Validate form parameters for panel PERMISSIONS
|
||||
$ret = $c->validate_PERMISSIONS(\%sf_data);
|
||||
$thispanel = 'PERMISSIONS';
|
||||
}
|
||||
|
||||
if ($trt eq 'REMOVE'){
|
||||
#Validate form parameters for panel REMOVE
|
||||
$ret = $c->validate_REMOVE(\%sf_data);
|
||||
$thispanel = 'REMOVE';
|
||||
}
|
||||
|
||||
if ($ret ne "ok"){
|
||||
$c->stash(error => $c->l($ret));
|
||||
$c->do_display($thispanel);
|
||||
} else {
|
||||
#Do whatever is needed, including writing values to the DB
|
||||
|
||||
|
||||
if ($trt eq 'LIST'){
|
||||
#do whatever is required ...
|
||||
$ret = $c->perform_LIST(\%sf_data);
|
||||
if ($ret ne "ok") {
|
||||
# return to the panel with error message
|
||||
$c->stash(error => $c->l($ret));
|
||||
$c->stash(
|
||||
title => $title,
|
||||
modul => $modul,
|
||||
sf_data => \%sf_data
|
||||
);
|
||||
$c->render(template => "shares");
|
||||
} else {
|
||||
$c->stash( success => $c->l('sf_LIST_panel_action_was_successful')); #A bit bland - edit it in the lex file
|
||||
}
|
||||
}
|
||||
|
||||
if ($trt eq 'MODIFY'){
|
||||
#do whatever is required ...
|
||||
$ret = $c->perform_MODIFY(\%sf_data);
|
||||
if ($ret ne "ok") {
|
||||
# return to the panel with error message
|
||||
$c->stash(error => $c->l($ret));
|
||||
$c->stash(
|
||||
title => $title,
|
||||
modul => $modul,
|
||||
sf_data => \%sf_data
|
||||
);
|
||||
$c->render(template => "shares");
|
||||
} else {
|
||||
$c->stash( success => $c->l('sf_MODIFY_panel_action_was_successful')); #A bit bland - edit it in the lex file
|
||||
}
|
||||
}
|
||||
|
||||
if ($trt eq 'PERMISSIONS'){
|
||||
#do whatever is required ...
|
||||
$ret = $c->perform_PERMISSIONS(\%sf_data);
|
||||
if ($ret ne "ok") {
|
||||
# return to the panel with error message
|
||||
$c->stash(error => $c->l($ret));
|
||||
$c->stash(
|
||||
title => $title,
|
||||
modul => $modul,
|
||||
sf_data => \%sf_data
|
||||
);
|
||||
$c->render(template => "shares");
|
||||
} else {
|
||||
$c->stash( success => $c->l('sf_PERMISSIONS_panel_action_was_successful')); #A bit bland - edit it in the lex file
|
||||
}
|
||||
}
|
||||
|
||||
if ($trt eq 'REMOVE'){
|
||||
#do whatever is required ...
|
||||
$ret = $c->perform_REMOVE(\%sf_data);
|
||||
if ($ret ne "ok") {
|
||||
# return to the panel with error message
|
||||
$c->stash(error => $c->l($ret));
|
||||
$c->stash(
|
||||
title => $title,
|
||||
modul => $modul,
|
||||
sf_data => \%sf_data
|
||||
);
|
||||
$c->render(template => "shares");
|
||||
} else {
|
||||
$c->stash( success => $c->l('sf_REMOVE_panel_action_was_successful')); #A bit bland - edit it in the lex file
|
||||
}
|
||||
}
|
||||
|
||||
# and call any signal-events needed
|
||||
#TBD
|
||||
# Setup shared data and call panel
|
||||
if ('none' eq 'none') {
|
||||
$sf_data{'trt'} = 'LIST';
|
||||
} else {
|
||||
$sf_data{'trt'} = 'none';
|
||||
}
|
||||
$c->do_display($sf_data{'trt'});
|
||||
}
|
||||
}
|
||||
|
||||
sub do_display {
|
||||
#
|
||||
# Return after link clicked in table (this is a get) - route is "/<whatever>d"
|
||||
# Expects ?trt=PANEL&selected="TableRowName" plus any other required
|
||||
#
|
||||
# OR it maybe a post from the main panel to add a new record
|
||||
#
|
||||
#load up all supplied params into prefix_data hash
|
||||
#call get-selected-PANEL() - returns hash of all relevent parameters
|
||||
#load up returned hash into prefix_data
|
||||
#render - to called panel
|
||||
|
||||
my ($c,$trt) = @_;
|
||||
$c->app->log->info($c->log_req);
|
||||
|
||||
#The most common ones - you might want to comment out any not used.
|
||||
$cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
|
||||
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
$ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
|
||||
$hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
|
||||
$ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
|
||||
my $title = $c->l('sf_Shared_Folders');
|
||||
my $modul = "";
|
||||
|
||||
# Accessing all parameters
|
||||
my $params = $c->req->params->to_hash;
|
||||
|
||||
# Get number of parameters
|
||||
my $num_params = keys %$params;
|
||||
|
||||
#Tag as Post or Get (ie. create new entry or edit existing one
|
||||
my $is_new_record = ($c->req->method() eq 'POST');
|
||||
|
||||
#Params are available in the hash "params" - copy to the prefix_data hash
|
||||
#while (my ($key, $value) = each %{$c->req->params->to_hash}) {
|
||||
# $sf_data{$key} = $value;
|
||||
#}
|
||||
|
||||
# the value of trt will tell you which panel has returned
|
||||
if (! $trt){
|
||||
$trt = $c->param('trt') || 'LIST'; #Indicates where to go now
|
||||
}
|
||||
|
||||
# Now add in the params from the selected row from the table
|
||||
|
||||
my %selectedrow;
|
||||
|
||||
if ($trt eq 'LIST'){
|
||||
#Validate Get selected row (if applicable) LIST
|
||||
%selectedrow = $c->get_selected_LIST($sf_data{'Selected'},$is_new_record);
|
||||
}
|
||||
|
||||
if ($trt eq 'MODIFY'){
|
||||
#Validate Get selected row (if applicable) MODIFY
|
||||
%selectedrow = $c->get_selected_MODIFY($sf_data{'Selected'},$is_new_record);
|
||||
}
|
||||
|
||||
if ($trt eq 'PERMISSIONS'){
|
||||
#Validate Get selected row (if applicable) PERMISSIONS
|
||||
%selectedrow = $c->get_selected_PERMISSIONS($sf_data{'Selected'},$is_new_record);
|
||||
}
|
||||
|
||||
if ($trt eq 'REMOVE'){
|
||||
#Validate Get selected row (if applicable) REMOVE
|
||||
%selectedrow = $c->get_selected_REMOVE($sf_data{'Selected'},$is_new_record);
|
||||
}
|
||||
|
||||
|
||||
#Copy in the selected row params to the prefix_data hash to pass to the panel
|
||||
while (my ($key, $value) = each %selectedrow){
|
||||
$sf_data{$key} = $value;
|
||||
}
|
||||
# Where to go now
|
||||
$sf_data{'trt'} = $trt;
|
||||
|
||||
# Set up other shared data according to the panel to go to
|
||||
|
||||
if ($trt eq 'LIST'){
|
||||
# pickup any other contents needed and load them into hash shared with panel
|
||||
my %returned_hash;
|
||||
# subroutine returns a hash directly
|
||||
%returned_hash = $c->get_data_for_panel_LIST();
|
||||
# Copy each key-value pair from the returned hash to the prefix data hash
|
||||
while (my ($key, $value) = each %returned_hash) {
|
||||
$sf_data{$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ($trt eq 'MODIFY'){
|
||||
# pickup any other contents needed and load them into hash shared with panel
|
||||
my %returned_hash;
|
||||
# subroutine returns a hash directly
|
||||
%returned_hash = $c->get_data_for_panel_MODIFY();
|
||||
# Copy each key-value pair from the returned hash to the prefix data hash
|
||||
while (my ($key, $value) = each %returned_hash) {
|
||||
$sf_data{$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ($trt eq 'PERMISSIONS'){
|
||||
# pickup any other contents needed and load them into hash shared with panel
|
||||
my %returned_hash;
|
||||
# subroutine returns a hash directly
|
||||
%returned_hash = $c->get_data_for_panel_PERMISSIONS();
|
||||
# Copy each key-value pair from the returned hash to the prefix data hash
|
||||
while (my ($key, $value) = each %returned_hash) {
|
||||
$sf_data{$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ($trt eq 'REMOVE'){
|
||||
# pickup any other contents needed and load them into hash shared with panel
|
||||
my %returned_hash;
|
||||
# subroutine returns a hash directly
|
||||
%returned_hash = $c->get_data_for_panel_REMOVE();
|
||||
# Copy each key-value pair from the returned hash to the prefix data hash
|
||||
while (my ($key, $value) = each %returned_hash) {
|
||||
$sf_data{$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# and table control fields
|
||||
$c->stash(Table1=>$c->get_Table1());
|
||||
$c->stash(Table2=>$c->get_Table2());
|
||||
|
||||
|
||||
# Data for panel
|
||||
$c->stash(
|
||||
title => $title,
|
||||
modul => $modul,
|
||||
sf_data => \%sf_data
|
||||
);
|
||||
$c->render(template => "shares");
|
||||
}
|
||||
1;
|
Reference in New Issue
Block a user