# # 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 # 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; } 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'); next if (($share->prop('Hide') || 'no') eq 'yes'); my $removable = $share->prop('Removable') || 'yes'; my $actionModify = ''.$c->l('sf_Modify').''; my $actionPerm = ''.$c->l('sf_Permisssions').''; my $actionRemove = ($removable ne 'no') ?''.$c->l('sf_Remove').'': ''; 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' => 'Username', 'Table2_Description' => 'Description', 'Table2_Read / Write' => 'WritePerms', 'Table2_Read Only' => 'ReadPerms' #'target_field2' => 'source_field2', # Add more mappings as needed ); sub actual_Table2 { my $c = shift; my @ret = (); # Actual code for extracting Table2, Table3 my $groups_ref = $c->acl_list('groups'); my @groups = @$groups_ref; return @groups; } 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; } # Define a constant hash for field name mapping use constant Table3_FIELD_MAPPING => ( 'Table3_Users' => 'Username', 'Table3_Description' => 'Description', 'Table3_Read / Write' => 'WritePerms', 'Table3_Read Only' => 'ReadPerms' #'target_field3' => 'source_field3', # Add more mappings as needed ); sub actual_Table3 { my $c = shift; my @ret = (); # Actual code for extracting Table3, Table3 - this is called twice - by table 2 and table 3 processiong (!) my $users_ref = $c->acl_list('users'); my @users = @$users_ref; return @users; } sub get_Table3 { # Return an array of hashes of the contents for each row and column for Table3 my $c = shift; my @source_records = $c->actual_Table3(); my @transformed_records; my %Field_Mapping = Table3_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; $ret = $c->modify_perm(); #my $sf_data = shift; #Data hash as parameter #my $ret = ""; #my $db = $cdb; #maybe one of the others #my $dbkey = 'ChangeThis'; if ($ret eq "") {$ret = 'ok';} return $ret; } sub perform_REMOVE { my $c = shift; my $sf_data = shift; #Data hash as parameter my $ret = ""; $ret = $c->remove_share(); 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 save_share { # # Merged the two subs from SM1 # 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 @selected = @{$c->every_param('panelAccess')}; my $AdminPanels = join(',', @selected); my @selectedwritegroups = @{$c->every_param('writegroup')}; my $WriteGroups = join(",", @selectedwritegroups); my @selectedwriteusers = @{$c->every_param('writeuser')}; my $WriteUsers = join(",", @selectedwriteusers); my @CleanReadGroups = (); my @CleanReadUsers = (); # EncFS doesn't expose underlying ACLs # So, just remove any read only groups # Read Only is not supported with encryption my @selectedreadgroups = @{$c->every_param('readgroup')}; my @selectedreadusers = @{$c->every_param('readuser')}; if ($encryption ne 'enabled'){ # No need to have read access if write is already granted foreach my $group (@selectedreadgroups){ push (@CleanReadGroups, $group) unless (grep { $_ eq $group } @selectedwritegroups); } foreach my $user (@selectedreadusers){ push (@CleanReadUsers, $user) unless (grep { $_ eq $user } @selectedwriteusers); } } 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 ""; } # Remove a share sub remove_share { my $c = shift; $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); my $name = $c->param('Selected'); 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}); } } #Get arrays of users and gtroups who have read only or read/write access sub acl_list { my ($c, $which) = @_; my $sharename = $c->param('Selected'); my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); my $share = $adb->get($sharename); return $c->l('sf_SHARE_NOT_FOUND') unless ($share); if ($which eq 'groups') { my $WriteGroups = $share->prop('WriteGroups') || ''; my $ReadGroups = $share->prop('ReadGroups') || ''; my (%WriteGroups, %ReadGroups); $WriteGroups{$_} = 1 for grep { $_ } split /[,;]/, $WriteGroups; $ReadGroups{$_} = 1 for grep { $_ } split /[,;]/, $ReadGroups; my @groups; # The "shared" pseudo-group (Everyone) push @groups, { Username => 'shared', Description => 'Everyone', WritePerms => $WriteGroups{'shared'} ? 1 : 0, ReadPerms => $ReadGroups{'shared'} ? 1 : 0 }; foreach my $group (sort { $a->key cmp $b->key } $adb->groups) { my $name = $group->key; my $desc = $group->prop('Description') || ''; push @groups, { Username => $name, Description => $desc, WritePerms => $WriteGroups{$name} ? 1 : 0, ReadPerms => $ReadGroups{$name} ? 1 : 0 }; } return \@groups; } elsif ($which eq 'users') { my $WriteUsers = $share->prop('WriteUsers') || ''; my $ReadUsers = $share->prop('ReadUsers') || ''; my (%WriteUsers, %ReadUsers); $WriteUsers{$_} = 1 for grep { $_ } split /[,;]/, $WriteUsers; $ReadUsers{$_} = 1 for grep { $_ } split /[,;]/, $ReadUsers; my @users; foreach my $user (sort { $a->key cmp $b->key } $adb->users) { my $name = $user->key; my $desc = join(' ', grep { $_ } ($user->prop('FirstName'), $user->prop('LastName'))); push @users, { Username => $name, Description => $desc, WritePerms => $WriteUsers{$name} ? 1 : 0, ReadPerms => $ReadUsers{$name} ? 1 : 0 }; } return \@users; } else { die "Invalid parameter to acl_list: must be 'groups' or 'users'"; } } 1;