diff -urN smeserver-vacation-1.1.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Uservacations.pm smeserver-vacation-1.1/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Uservacations.pm --- smeserver-vacation-1.1.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Uservacations.pm 2020-06-11 06:33:21.401187446 +0100 +++ smeserver-vacation-1.1/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Uservacations.pm 1970-01-01 01:00:00.000000000 +0100 @@ -1,379 +0,0 @@ -package SrvMngr::Controller::Uservacations; -#---------------------------------------------------------------------- -# heading : Collaboration -# description : User Vacations -# navigation : 3000 3150 -# -# name : Uservacationsget, method : get, url : /uservacations, ctlact : Uservacations#main -# name : Uservacationspost,method : post, url : /Uservacations, ctlact : Uservacations#do_display -# name : Uservacations1, method : get, url : /Uservacations1, ctlact : Uservacations#do_display -# name : Uservacations2, method : post, url : /Uservacations2, ctlact : Uservacations#do_display -# routes : end -#---------------------------------------------------------------------- - -use strict; -use warnings; -use Mojo::Base 'Mojolicious::Controller'; - -#use DateTime; #Not part of SME10 mix -use POSIX; - -use Locale::gettext; -use SrvMngr::I18N; -use SrvMngr qw(theme_list init_session_cgi); - -use Data::Dumper; -use esmith::util; -use esmith::HostsDB; -use esmith::AccountsDB; - -our $db = esmith::ConfigDB->open(); -our $adb = esmith::AccountsDB->open(); - -our $PanelUser = $ENV{'REMOTE_USER'} ||''; -$PanelUser = $1 if ($PanelUser =~ /^([a-z][\.\-a-z0-9]*)$/); - -our %delegatedVacations; - -use constant FALSE => 0; -use constant TRUE => 1; - -sub main { - - my $c = shift; - $c->app->log->info( $c->log_req ); - - my %vac_datas = (); - my $title = $c->l('vac_FORM_TITLE'); - my $modul = ''; - - $vac_datas{trt} = 'LIST'; - - my @vacations = get_vacation_table($c); - my $empty = (scalar @vacations == 0); - - $vac_datas{"first"} = 'vac_MODIFY_DESCRIPTION'; - - $c->stash( - title => $title, - modul => $modul, - vac_datas => \%vac_datas, - vacations =>\@vacations, - empty => $empty - ); - $c->render( template => 'uservacations' ); -} - -sub do_display { - - my $c = shift; - $c->app->log->info( $c->log_req ); - - my $rt = $c->current_route; - my $trt = ( $c->param('trt') || 'LIST' ); - - $trt = 'ADD' if ( $rt eq 'Uservacations1' ); - $trt = 'ADD1' if ( $rt eq 'Uservacations2' ); - - my %vac_datas = (); - my $title = $c->l('vac_FORM_TITLE'); - my $modul = ''; - - - if ( $trt eq 'ADD' ) { - # Add or change a vacation message - called from the list panel - # Get the data and pass it across. - my $account = $c->param("account"); - my $user = $adb->get($account); - my $username = $user->prop("FirstName")." ".$user->prop("LastName"); - my $EmailVacation = $user->prop('EmailVacation') || ''; - my $EmailVacationFrom = $user->prop('EmailVacationFrom') || ''; - my $EmailVacationTo = $user->prop('EmailVacationTo') || ''; - my $VacText = get_vacation_text($c); - $c->stash(account=>$account, - username=>$username, - EmailVacation=>$EmailVacation, - EmailVacationFrom=>$EmailVacationFrom, - EmailVacationTo=>$EmailVacationTo, - VacText=>$VacText - ); - } - - if ( $trt eq 'ADD1' ) { - #Add or edit vacation message. - my $ret = add_vac_message($c); - #Return to list page if success - if ($ret eq "OK") { - $trt = "LIST"; - $vac_datas{success} = "vac_SUCCESS"; - - } else { - my $account = $c->param("account"); - my $user = $adb->get($account); - my $username = $user->prop("FirstName")." ".$user->prop("LastName"); - my $EmailVacationFrom = $c->param('EmailVacationFrom') || ''; - my $EmailVacationTo = $c->param('EmailVacationTo') || ''; - my $EmailVacation = $c->param('EmailVacation') || ''; - my $VacText = $c->param("VacText"); - $c->stash(account=>$account, - username=>$username, - EmailVacation=>$EmailVacation, - EmailVacationFrom=>$EmailVacationFrom, - EmailVacationTo=>$EmailVacationTo, - VacText=>$VacText - ); - #Error - return to Add page - $trt = "ADD"; - $vac_datas{error} = $ret; - } - } - - if ( $trt eq 'LIST' ) { - - #List all the users and vacation message details. - my @vacations = get_vacation_table($c); - my $empty = (scalar @vacations == 0); - $c->stash( - empty => $empty, - vacations =>\@vacations - ); - } - - - $vac_datas{'trt'} = $trt; - $c->stash( title => $title, modul => $modul, vac_datas => \%vac_datas ); - $c->render( template => 'uservacations' ); -} - -sub user_accounts_exist -{ - my $q = shift; - #return scalar $adb->users; - if (scalar $adb->users) - { return $q->l('vac_DESCRIPTION'); } -} - -sub get_vacation_table -{ - my $self = shift; - #my $q = $self->{cgi}; - -#We want to retrieve granted group from DB, and retrieve users of groups - my $record = $adb->get($PanelUser); - my $dg=$record->prop('delegatedVacations')||''; - $dg =~ s/ //g; - my @g = split(/,/, $dg); - my @visiblemembers = (); - - foreach my $g (@g) { - my $members = $adb->get_prop("$g",'Members'); - next unless defined $members; - $members =~ s/ //g; - my @members = split(/,/, $members); - push @visiblemembers , @members ; - } - - foreach my $k ( @visiblemembers ) - { - $delegatedVacations{$k}=1; - } - - - my @users = $adb->users; - return () if (@users == 0); ##$self->l("ACCOUNT_USER_NONE") - return () if (@visiblemembers == 0 && $dg ne '');#; #$self->l("NO_USERS_IN_GRANTED_GROUPS") - - my @data = (); - - for my $user (@users) - { - next if %delegatedVacations and not $delegatedVacations{$user->key}; - # make it clearer which uses have vacation - my $EmailVacation = $user->prop('EmailVacation') || ''; - my $EmailVacationFrom = $user->prop('EmailVacationFrom') || ''; - my $EmailVacationTo = $user->prop('EmailVacationTo') || ''; - my $status = $user->prop('EmailVacation') || ''; - if ($status eq 'yes') { $status = 'YES'; } else { $status = ''; } - - push @data, - { User => $user->key, - FullName => $user->prop('FirstName') . " " .$user->prop('LastName'), - status => $self->l($status), - EmailVacation => $EmailVacation, - EmailVacationFrom => showDate($EmailVacationFrom), - EmailVacationTo => showDate($EmailVacationTo), - Modify => $self->l('vac_MODIFY'), - } - } - return @data; -} - -sub showDate -{ - my $strDate = shift; - my ($Year,$Month,$Day) = ($strDate =~ /(\d{4})(\d{2})(\d{2})/); - #my $Unix = mktime(0,0,0,$Day,$Month,$Year); - return "$Year-$Month-$Day"; -} - - -sub modify_link -{ - my ($data_item, $row, $field) = @_; - - return "uservacations?" . - join("&", - "page=0", - "page_stack=", - "Next=Next", - "User=" . $row->{User}, - "FullName=" . $row->{FullName}, - "EmailVacation=" . $row->{EmailVacation}, - "EmailVacationFrom=" . $row->{EmailVacationFrom}, - "EmailVacationTo=" . $row->{EmailVacationTo}, - "wherenext=VACATION_PAGE_MODIFY"); -} - -# this formats the text to display on screen -sub get_vacation_text -{ - my $q = shift; - my $domain = $db->get_value('DomainName'); - my $user = $q->param('account'); - - my $fullname = $adb->get_prop($user, "FirstName") . " " . - $adb->get_prop($user, "LastName"); - - my $vfile = "/home/e-smith/files/users/$user/.vacation.msg"; - - my $from = $q->l('vac_FROM'); - my $Subject = $q->l('vac_SUBJECT'); - my $away = $q->l('vac_AWAY_FROM_MAIL'); - my $return = $q->l('vac_ANSWER_TO_OBJECT_SENDER'); - - my $ExistingMessage = "$from $fullname <\;$user\@$domain>\;\n"."$Subject $return\n". - "\n$away\n"."\n--\n$fullname"; - - # if exists and is not empty - if (( -e $vfile ) && (! -z $vfile )) - { - open (VACATION, "<$vfile") - or die "Error: Could not open file: $vfile\n"; - my @vacationTemp; - - #reformat so email address isn't hidden inside < > - while () - { - $_ =~ s//>\;/; - push (@vacationTemp, $_); - } - - $ExistingMessage = join ("", @vacationTemp); - - close VACATION; - } - return $ExistingMessage; -} - -# saves the text to .vacation.msg -sub add_vac_message -{ - my $q = shift; - - my $domain = $db->get_value('DomainName'); - my $user = $q->param('account'); - - my $EmailVacation = $q->param('EmailVacation')||"no"; - #die($EmailVacation); - #if ($EmailVacation eq "yes") {$EmailVacation = "yes";} else {$EmailVacation = "no";} - - #Decode To and FROM to standard format - comes over in html5 iso format yyyy-mm-dd - my $EmailVacationFrom = trim($q->param('EmailVacationFrom')); - my ($fromYear,$fromMonth,$fromDay) = ($EmailVacationFrom =~ /(\d{4})-(\d{2})-(\d{2})/); - $EmailVacationFrom = $fromYear.$fromMonth.$fromDay; - if ($EmailVacationFrom !~ m/^2[0-9]{3}[0|1][0-9][0-3][0-9]$/ and $EmailVacationFrom ne "") {return "vac_FROM_DATE_INCORRECT";} - my $EmailVacationTo = trim($q->param('EmailVacationTo')); - my ($toYear,$toMonth,$toDay) = ($EmailVacationTo =~ /(\d{4})-(\d{2})-(\d{2})/); - $EmailVacationTo = $toYear.$toMonth.$toDay; -# $EmailVacationTo =~ s/-//g; #Just take out "-". - if ($EmailVacationTo !~ m/^2[0-9]{3}[0|1][0-9][0-3][0-9]$/ and $EmailVacationFrom ne "") {return "vac_TO_DATE_INCORRECT";} - #Check not the same or From follows To. - if ($EmailVacationTo ne "" and $EmailVacationTo eq $EmailVacationFrom) {return "vac_DATES_THE_SAME";} - my $UnixFrom = mktime(0,0,0,$fromDay,$fromMonth,$fromYear); - my $UnixTo = mktime(0,0,0,$toDay,$toMonth,$toYear); - if ($UnixTo < $UnixFrom) {return "vac_TO_DATE_MUST_BE_LATER";} - - - my $new_message = $q->param('VacText'); - my $vfile = "/home/e-smith/files/users/$user/.vacation.msg"; - - my $fullname = $adb->get_prop($user, "FirstName") . " " . - $adb->get_prop($user, "LastName"); - - my $from = 'From:'; - my $away = $q->l('vac_AWAY_FROM_MAIL'); - my $return = $q->l('vac_ANSWER_TO_OBJECT_SENDER'); - - my $vacation_text = "$from $fullname \<$user\@$domain\>\n"."Subject: $return\n". - "\n$away \n"."\n--\n$fullname"; - - my $reset = $vacation_text; - - # if exists and is not empty - if (( -e $vfile ) && (! -z $vfile )) - { - open (VACATION, "<$vfile") - or die "Error: Could not open file: $vfile\n"; - my @vacationTemp = ; - $vacation_text = join ("", @vacationTemp); - - close VACATION; - } - - chomp $new_message; - - # reset msg to default, - if ($new_message =~ /reset/) - { $vacation_text = $reset; } - else - { - #or save new_message - unless ($new_message eq "") - { $vacation_text = $new_message; } - } - - # Strip out DOS Carriage Returns (CR) - $vacation_text =~ s/\r//g; - - unlink $vfile; - open (VACATION, ">$vfile") - or die ("Error opening vacation message.\n"); - - print VACATION "$vacation_text"; - close VACATION; - - esmith::util::chownFile($user, $user, - "/home/e-smith/files/users/$user/.vacation.msg"); - - $adb->set_prop($user, 'EmailVacation', $EmailVacation); - $adb->set_prop($user, 'EmailVacationFrom', $EmailVacationFrom); - $adb->set_prop($user, 'EmailVacationTo', $EmailVacationTo); - - #the first is more correct but is slower - #system ("/sbin/e-smith/signal-event", "email-update", $user) == 0 - system ("/etc/e-smith/events/actions/qmail-update-user event $user") == 0 - or die ("Error occurred updating .qmail\n"); - - if (($EmailVacation eq 'no') && ( -e "/home/e-smith/files/users/$user/.vacation")) - { - system ("/bin/rm /home/e-smith/files/users/$user/.vacation") == 0 - or die ("Error resetting vacation db.\n"); - } - - return "OK"; -} - -sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s }; - -1; diff -urN smeserver-vacation-1.1.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/I18N/Modules/Uservacations/en.pm smeserver-vacation-1.1/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/I18N/Modules/Uservacations/en.pm --- smeserver-vacation-1.1.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/I18N/Modules/Uservacations/en.pm 2020-06-11 06:33:21.401187446 +0100 +++ smeserver-vacation-1.1/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/I18N/Modules/Uservacations/en.pm 1970-01-01 01:00:00.000000000 +0100 @@ -1,63 +0,0 @@ -package SrvMngr::I18N::Modules::Uservacations::en; -use strict; -use warnings; -use utf8; -use Mojo::Base 'SrvMngr::I18N'; - -use SrvMngr::I18N::Modules::General::en; - -my %lexicon = ( -'vac_User vacations' =>'User vacations', -'vac_Vacation Message' =>'Vacation Message', -'vac_FORM_TITLE' =>'Change user vacation settings', -'vac_DESCRIPTION' =>' You can modify a users vacation message by clicking - on the link to the right of their name below. -', -'vac_LABEL_VACATION' =>'Vacation', -'vac_NO_FORWARDS'=>'No users found for forwarding', -'vac_VACATION_FROM' =>'Vacation starts on
(YYYY-MM-DD)', -'vac_VACATION_TO' =>'Vacation finishes on
(YYYY-MM-DD)', -'vac_VACATION_FROM1' =>'Vacation starts on', -'vac_VACATION_TO1' =>'Vacation finishes on', -'vac_MESSAGE' =>'Vacation message', -'vac_VACATION_STATUS' =>'Enable vacation messages', -'vac_FROM' =>'From:', -'vac_SUBJECT' =>'Subject:', -'vac_AWAY_FROM_MAIL' =>'I will not be reading my mail for a while. Your mail regarding $SUBJECT will be read when I return.', -'vac_NO_USERS_IN_GRANTED_GROUPS' =>'There are no users in the group(s) that you are granted to manage.', -'vac_ANSWER_TO_OBJECT_SENDER' => 'Re: $SUBJECT - Away from my email ', -'vac_FROM_DATE_INCORRECT'=>'From date must have YYYYMMDD format', -'vac_TO_DATE_INCORRECT'=>'To date must have YYYYMMDD format', -'vac_DATES_THE_SAME'=>"The Start and Finish dates cannot be the same", -'vac_TO_DATE_MUST_BE_LATER'=>"The Finish dates cannot be earlier than the Start date", -'vac_SUCCESS'=>'Vacation message saved sucessfully', -'vac_MODIFY_DESCRIPTION' =>' -

- Enter a vacation message here. You can use $SUBJECT - anywhere in the text to be replaced with the subject line - from the email that activated the auto-reply.

- -

- This message must be composed of two parts separated by a blank line. - The first will be integrated into the headings of the email reply, - you must thus ensure you leave at least a blank line before typing your message. - The primary domain is added to the address automatically,or you can insert a virtual domain by replacing the domain part of the sender address - in the first line of the message with the virtual domain name (eg. replace the default From: user@primary.domain with From: user@virtual.domain). - To change the vacation message back to the default type reset.

-

- You can also fill out the Enable vacation on and Disable vacation on fields in order to - automatically enable and disable sending of the vacation message for this user account on the given dates. -

-

- The dates in the two fields must not be the same.
- If you want to use this functionality, leave the Enable vacation messages setting at No - it will be automatically activated based on the date given. -

' -); - -our %Lexicon = ( - %{ SrvMngr::I18N::Modules::General::en::Lexicon }, - %lexicon -); - - -1; diff -urN smeserver-vacation-1.1.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_vac_add.html.ep smeserver-vacation-1.1/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_vac_add.html.ep --- smeserver-vacation-1.1.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_vac_add.html.ep 2020-06-11 06:33:21.397187406 +0100 +++ smeserver-vacation-1.1/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_vac_add.html.ep 1970-01-01 01:00:00.000000000 +0100 @@ -1,54 +0,0 @@ -
- - % my $btn = l('ADD'); - - % if ($config->{debug} == 1) { -

- %= dumper $c->current_route - %= dumper $EmailVacation -

- % } - - %= form_for '/Uservacations2' => (method => 'POST') => begin - - - %=l 'ACCOUNT' - - %= $account -

- - %=l 'USER_NAME' - - %=$username -

- - %=$c->render_to_string(inline =>$c->l('vac_VACATION_FROM1')) - - - %=date_field 'EmailVacationFrom' =>$EmailVacationFrom -

- - %=$c->render_to_string(inline =>$c->l('vac_VACATION_TO1')) - - - %=date_field 'EmailVacationTo' =>$EmailVacationTo -

- - %=l 'vac_MESSAGE' - - - %=text_area 'VacText' => $VacText, cols=>55, rows=>15 -

- - %=l 'vac_VACATION_STATUS' - - - % param EmailVacation => "$EmailVacation"; - %=select_field EmailVacation =>[['Yes'=>'yes'],['No'=>'no']] -

- %= hidden_field 'account' => $account - - %= submit_button "$btn", class => 'action' - %end - -
diff -urN smeserver-vacation-1.1.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_vac_list.html.ep smeserver-vacation-1.1/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_vac_list.html.ep --- smeserver-vacation-1.1.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_vac_list.html.ep 2020-06-11 06:33:21.397187406 +0100 +++ smeserver-vacation-1.1/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_vac_list.html.ep 1970-01-01 01:00:00.000000000 +0100 @@ -1,50 +0,0 @@ -
- - %# my $btn = l('vac_CREATE_RULE'); - - %= form_for '/Uservacations1' => (method => 'POST') => begin -

- - % if ($empty){ -
- %=l 'vac_NO_FORWARDS' - % } else { - - - - - - - - - - - % foreach my $vacation (@$vacations) { - - %= t td => (class => 'sme-border') => $vacation->{"User"} - %= t td => (class => 'sme-border') => $vacation->{"FullName"} - %= t td => (class => 'sme-border') => $vacation->{"status"} - %= t td => (class => 'sme-border') => $vacation->{"EmailVacationFrom"} - %= t td => (class => 'sme-border') => $vacation->{"EmailVacationTo"} - - - %} - -
- %=l 'ACCOUNT' - - %=l 'USER_NAME' - - %=l 'vac_LABEL_VACATION' - - %=$c->render_to_string(inline =>l('vac_VACATION_FROM')) - - %=$c->render_to_string(inline =>l('vac_VACATION_TO')) - - %=l 'ACTION' -
- "><%=l 'MODIFY'%> -
- %} - % end -
diff -urN smeserver-vacation-1.1.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/uservacations.html.ep smeserver-vacation-1.1/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/uservacations.html.ep --- smeserver-vacation-1.1.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/uservacations.html.ep 2020-06-11 06:33:21.397187406 +0100 +++ smeserver-vacation-1.1/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/uservacations.html.ep 1970-01-01 01:00:00.000000000 +0100 @@ -1,42 +0,0 @@ -% layout 'default', title => "Sme server 2 - User Vacations", share_dir => './'; - -% content_for 'module' => begin -
- - % if ($config->{debug} == 1) { -

- %= dumper $c->current_route -

- % } - -

<%=$title%>

- %= $modul - - %if ($vac_datas->{first}) { -
- %=$c->render_to_string(inline =>$c->l($vac_datas->{first})) - - %} elsif ($vac_datas->{success}) { -
-

Operation Status Report

- %= $c->l($vac_datas->{success}); -
- - %} elsif ($vac_datas->{error}) { -
-

Operation Status Report - error

- %= $c->l($vac_datas->{error}); -
- %} - - - % if ($vac_datas->{trt} eq 'ADD') { - %= include 'partials/_vac_add' - %} elsif ($vac_datas->{trt} eq 'ADD1') { - %= include 'partials/_vac_add' - %} else { - %= include 'partials/_vac_list' - %} - -
-%end diff -urN smeserver-vacation-1.1.old/root/usr/share/smanager/lib/SrvMngr/Controller/Uservacations.pm smeserver-vacation-1.1/root/usr/share/smanager/lib/SrvMngr/Controller/Uservacations.pm --- smeserver-vacation-1.1.old/root/usr/share/smanager/lib/SrvMngr/Controller/Uservacations.pm 1970-01-01 01:00:00.000000000 +0100 +++ smeserver-vacation-1.1/root/usr/share/smanager/lib/SrvMngr/Controller/Uservacations.pm 2020-06-10 18:28:00.000000000 +0100 @@ -0,0 +1,380 @@ +package SrvMngr::Controller::Uservacations; +#---------------------------------------------------------------------- +# heading : Collaboration +# description : User Vacations +# navigation : 3000 3150 +# +# name : Uservacationsget, method : get, url : /uservacations, ctlact : Uservacations#main +# name : Uservacationspost,method : post, url : /Uservacations, ctlact : Uservacations#do_display +# name : Uservacations1, method : get, url : /Uservacations1, ctlact : Uservacations#do_display +# name : Uservacations2, method : post, url : /Uservacations2, ctlact : Uservacations#do_display +# routes : end +#---------------------------------------------------------------------- + +use strict; +use warnings; +use Mojo::Base 'Mojolicious::Controller'; + +#use DateTime; #Not part of SME10 mix +use POSIX; + +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 $PanelUser = $ENV{'REMOTE_USER'} ||''; +$PanelUser = $1 if ($PanelUser =~ /^([a-z][\.\-a-z0-9]*)$/); + +our %delegatedVacations; + +use constant FALSE => 0; +use constant TRUE => 1; + +sub main { + + my $c = shift; + $c->app->log->info( $c->log_req ); + + my %vac_datas = (); + my $title = $c->l('vac_FORM_TITLE'); + my $modul = ''; + + $vac_datas{trt} = 'LIST'; + + my @vacations = get_vacation_table($c); + my $empty = (scalar @vacations == 0); + + $vac_datas{"first"} = 'vac_MODIFY_DESCRIPTION'; + + $c->stash( + title => $title, + modul => $modul, + vac_datas => \%vac_datas, + vacations =>\@vacations, + empty => $empty + ); + $c->render( template => 'uservacations' ); +} + +sub do_display { + + my $c = shift; + $c->app->log->info( $c->log_req ); + + my $rt = $c->current_route; + my $trt = ( $c->param('trt') || 'LIST' ); + + $trt = 'ADD' if ( $rt eq 'Uservacations1' ); + $trt = 'ADD1' if ( $rt eq 'Uservacations2' ); + + my %vac_datas = (); + my $title = $c->l('vac_FORM_TITLE'); + my $modul = ''; + + + if ( $trt eq 'ADD' ) { + # Add or change a vacation message - called from the list panel + # Get the data and pass it across. + my $account = $c->param("account"); + my $user = $adb->get($account); + my $username = $user->prop("FirstName")." ".$user->prop("LastName"); + my $EmailVacation = $user->prop('EmailVacation') || ''; + my $EmailVacationFrom = $user->prop('EmailVacationFrom') || ''; + my $EmailVacationTo = $user->prop('EmailVacationTo') || ''; + my $VacText = get_vacation_text($c); + $c->stash(account=>$account, + username=>$username, + EmailVacation=>$EmailVacation, + EmailVacationFrom=>$EmailVacationFrom, + EmailVacationTo=>$EmailVacationTo, + VacText=>$VacText + ); + } + + if ( $trt eq 'ADD1' ) { + #Add or edit vacation message. + my $ret = add_vac_message($c); + #Return to list page if success + if ($ret eq "OK") { + $trt = "LIST"; + $vac_datas{success} = "vac_SUCCESS"; + + } else { + my $account = $c->param("account"); + my $user = $adb->get($account); + my $username = $user->prop("FirstName")." ".$user->prop("LastName"); + my $EmailVacationFrom = $c->param('EmailVacationFrom') || ''; + my $EmailVacationTo = $c->param('EmailVacationTo') || ''; + my $EmailVacation = $c->param('EmailVacation') || ''; + my $VacText = $c->param("VacText"); + $c->stash(account=>$account, + username=>$username, + EmailVacation=>$EmailVacation, + EmailVacationFrom=>$EmailVacationFrom, + EmailVacationTo=>$EmailVacationTo, + VacText=>$VacText + ); + #Error - return to Add page + $trt = "ADD"; + $vac_datas{error} = $ret; + } + } + + if ( $trt eq 'LIST' ) { + + #List all the users and vacation message details. + my @vacations = get_vacation_table($c); + my $empty = (scalar @vacations == 0); + $c->stash( + empty => $empty, + vacations =>\@vacations + ); + } + + + $vac_datas{'trt'} = $trt; + $c->stash( title => $title, modul => $modul, vac_datas => \%vac_datas ); + $c->render( template => 'uservacations' ); +} + +sub user_accounts_exist +{ + my $q = shift; + #return scalar $adb->users; + if (scalar $adb->users) + { return $q->l('vac_DESCRIPTION'); } +} + +sub get_vacation_table +{ + my $self = shift; + +#We want to retrieve granted group from DB, and retrieve users of groups + my $record = $adb->get($PanelUser); + my $dg; + if ($record) {$dg=$record->prop('delegatedVacations')||'';} + else {$dg = '';} + $dg =~ s/ //g; + my @g = split(/,/, $dg); + my @visiblemembers = (); + + foreach my $g (@g) { + my $members = $adb->get_prop("$g",'Members'); + next unless defined $members; + $members =~ s/ //g; + my @members = split(/,/, $members); + push @visiblemembers , @members ; + } + + foreach my $k ( @visiblemembers ) + { + $delegatedVacations{$k}=1; + } + + + my @users = $adb->users; + return () if (@users == 0); ##$self->l("ACCOUNT_USER_NONE") + return () if (@visiblemembers == 0 && $dg ne '');#; #$self->l("NO_USERS_IN_GRANTED_GROUPS") + + my @data = (); + + for my $user (@users) + { + next if %delegatedVacations and not $delegatedVacations{$user->key}; + # make it clearer which uses have vacation + my $EmailVacation = $user->prop('EmailVacation') || ''; + my $EmailVacationFrom = $user->prop('EmailVacationFrom') || ''; + my $EmailVacationTo = $user->prop('EmailVacationTo') || ''; + my $status = $user->prop('EmailVacation') || ''; + if ($status eq 'yes') { $status = 'YES'; } else { $status = ''; } + + push @data, + { User => $user->key, + FullName => $user->prop('FirstName') . " " .$user->prop('LastName'), + status => $self->l($status), + EmailVacation => $EmailVacation, + EmailVacationFrom => showDate($EmailVacationFrom), + EmailVacationTo => showDate($EmailVacationTo), + Modify => $self->l('vac_MODIFY'), + } + } + return @data; +} + +sub showDate +{ + my $strDate = shift; + my ($Year,$Month,$Day) = ($strDate =~ /(\d{4})(\d{2})(\d{2})/); + #my $Unix = mktime(0,0,0,$Day,$Month,$Year); + return "$Year-$Month-$Day"; +} + + +sub modify_link +{ + my ($data_item, $row, $field) = @_; + + return "uservacations?" . + join("&", + "page=0", + "page_stack=", + "Next=Next", + "User=" . $row->{User}, + "FullName=" . $row->{FullName}, + "EmailVacation=" . $row->{EmailVacation}, + "EmailVacationFrom=" . $row->{EmailVacationFrom}, + "EmailVacationTo=" . $row->{EmailVacationTo}, + "wherenext=VACATION_PAGE_MODIFY"); +} + +# this formats the text to display on screen +sub get_vacation_text +{ + my $q = shift; + my $domain = $db->get_value('DomainName'); + my $user = $q->param('account'); + + my $fullname = $adb->get_prop($user, "FirstName") . " " . + $adb->get_prop($user, "LastName"); + + my $vfile = "/home/e-smith/files/users/$user/.vacation.msg"; + + my $from = $q->l('vac_FROM'); + my $Subject = $q->l('vac_SUBJECT'); + my $away = $q->l('vac_AWAY_FROM_MAIL'); + my $return = $q->l('vac_ANSWER_TO_OBJECT_SENDER'); + + my $ExistingMessage = "$from $fullname <\;$user\@$domain>\;\n"."$Subject $return\n". + "\n$away\n"."\n--\n$fullname"; + + # if exists and is not empty + if (( -e $vfile ) && (! -z $vfile )) + { + open (VACATION, "<$vfile") + or die "Error: Could not open file: $vfile\n"; + my @vacationTemp; + + #reformat so email address isn't hidden inside < > + while () + { + $_ =~ s//>\;/; + push (@vacationTemp, $_); + } + + $ExistingMessage = join ("", @vacationTemp); + + close VACATION; + } + return $ExistingMessage; +} + +# saves the text to .vacation.msg +sub add_vac_message +{ + my $q = shift; + + my $domain = $db->get_value('DomainName'); + my $user = $q->param('account'); + + my $EmailVacation = $q->param('EmailVacation')||"no"; + #die($EmailVacation); + #if ($EmailVacation eq "yes") {$EmailVacation = "yes";} else {$EmailVacation = "no";} + + #Decode To and FROM to standard format - comes over in html5 iso format yyyy-mm-dd + my $EmailVacationFrom = trim($q->param('EmailVacationFrom')); + my ($fromYear,$fromMonth,$fromDay) = ($EmailVacationFrom =~ /(\d{4})-(\d{2})-(\d{2})/); + $EmailVacationFrom = $fromYear.$fromMonth.$fromDay; + if ($EmailVacationFrom !~ m/^2[0-9]{3}[0|1][0-9][0-3][0-9]$/ and $EmailVacationFrom ne "") {return "vac_FROM_DATE_INCORRECT";} + my $EmailVacationTo = trim($q->param('EmailVacationTo')); + my ($toYear,$toMonth,$toDay) = ($EmailVacationTo =~ /(\d{4})-(\d{2})-(\d{2})/); + $EmailVacationTo = $toYear.$toMonth.$toDay; +# $EmailVacationTo =~ s/-//g; #Just take out "-". + if ($EmailVacationTo !~ m/^2[0-9]{3}[0|1][0-9][0-3][0-9]$/ and $EmailVacationFrom ne "") {return "vac_TO_DATE_INCORRECT";} + #Check not the same or From follows To. + if ($EmailVacationTo ne "" and $EmailVacationTo eq $EmailVacationFrom) {return "vac_DATES_THE_SAME";} + my $UnixFrom = mktime(0,0,0,$fromDay,$fromMonth,$fromYear); + my $UnixTo = mktime(0,0,0,$toDay,$toMonth,$toYear); + if ($UnixTo < $UnixFrom) {return "vac_TO_DATE_MUST_BE_LATER";} + + + my $new_message = $q->param('VacText'); + my $vfile = "/home/e-smith/files/users/$user/.vacation.msg"; + + my $fullname = $adb->get_prop($user, "FirstName") . " " . + $adb->get_prop($user, "LastName"); + + my $from = 'From:'; + my $away = $q->l('vac_AWAY_FROM_MAIL'); + my $return = $q->l('vac_ANSWER_TO_OBJECT_SENDER'); + + my $vacation_text = "$from $fullname \<$user\@$domain\>\n"."Subject: $return\n". + "\n$away \n"."\n--\n$fullname"; + + my $reset = $vacation_text; + + # if exists and is not empty + if (( -e $vfile ) && (! -z $vfile )) + { + open (VACATION, "<$vfile") + or die "Error: Could not open file: $vfile\n"; + my @vacationTemp = ; + $vacation_text = join ("", @vacationTemp); + + close VACATION; + } + + chomp $new_message; + + # reset msg to default, + if ($new_message =~ /reset/) + { $vacation_text = $reset; } + else + { + #or save new_message + unless ($new_message eq "") + { $vacation_text = $new_message; } + } + + # Strip out DOS Carriage Returns (CR) + $vacation_text =~ s/\r//g; + + unlink $vfile; + open (VACATION, ">$vfile") + or die ("Error opening vacation message.\n"); + + print VACATION "$vacation_text"; + close VACATION; + + esmith::util::chownFile($user, $user, + "/home/e-smith/files/users/$user/.vacation.msg"); + + $adb->set_prop($user, 'EmailVacation', $EmailVacation); + $adb->set_prop($user, 'EmailVacationFrom', $EmailVacationFrom); + $adb->set_prop($user, 'EmailVacationTo', $EmailVacationTo); + + #the first is more correct but is slower + #system ("/sbin/e-smith/signal-event", "email-update", $user) == 0 + system ("/etc/e-smith/events/actions/qmail-update-user event $user") == 0 + or die ("Error occurred updating .qmail\n"); + + if (($EmailVacation eq 'no') && ( -e "/home/e-smith/files/users/$user/.vacation")) + { + system ("/bin/rm /home/e-smith/files/users/$user/.vacation") == 0 + or die ("Error resetting vacation db.\n"); + } + + return "OK"; +} + +sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s }; + +1; diff -urN smeserver-vacation-1.1.old/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/en.pm smeserver-vacation-1.1/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/en.pm --- smeserver-vacation-1.1.old/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/en.pm 1970-01-01 01:00:00.000000000 +0100 +++ smeserver-vacation-1.1/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/en.pm 2020-05-19 15:36:00.000000000 +0100 @@ -0,0 +1,63 @@ +package SrvMngr::I18N::Modules::Uservacations::en; +use strict; +use warnings; +use utf8; +use Mojo::Base 'SrvMngr::I18N'; + +use SrvMngr::I18N::Modules::General::en; + +my %lexicon = ( +'vac_User vacations' =>'User vacations', +'vac_Vacation Message' =>'Vacation Message', +'vac_FORM_TITLE' =>'Change user vacation settings', +'vac_DESCRIPTION' =>' You can modify a users vacation message by clicking + on the link to the right of their name below. +', +'vac_LABEL_VACATION' =>'Vacation', +'vac_NO_FORWARDS'=>'No users found for forwarding', +'vac_VACATION_FROM' =>'Vacation starts on
(YYYY-MM-DD)', +'vac_VACATION_TO' =>'Vacation finishes on
(YYYY-MM-DD)', +'vac_VACATION_FROM1' =>'Vacation starts on', +'vac_VACATION_TO1' =>'Vacation finishes on', +'vac_MESSAGE' =>'Vacation message', +'vac_VACATION_STATUS' =>'Enable vacation messages', +'vac_FROM' =>'From:', +'vac_SUBJECT' =>'Subject:', +'vac_AWAY_FROM_MAIL' =>'I will not be reading my mail for a while. Your mail regarding $SUBJECT will be read when I return.', +'vac_NO_USERS_IN_GRANTED_GROUPS' =>'There are no users in the group(s) that you are granted to manage.', +'vac_ANSWER_TO_OBJECT_SENDER' => 'Re: $SUBJECT - Away from my email ', +'vac_FROM_DATE_INCORRECT'=>'From date must have YYYYMMDD format', +'vac_TO_DATE_INCORRECT'=>'To date must have YYYYMMDD format', +'vac_DATES_THE_SAME'=>"The Start and Finish dates cannot be the same", +'vac_TO_DATE_MUST_BE_LATER'=>"The Finish dates cannot be earlier than the Start date", +'vac_SUCCESS'=>'Vacation message saved sucessfully', +'vac_MODIFY_DESCRIPTION' =>' +

+ Enter a vacation message here. You can use $SUBJECT + anywhere in the text to be replaced with the subject line + from the email that activated the auto-reply.

+ +

+ This message must be composed of two parts separated by a blank line. + The first will be integrated into the headings of the email reply, + you must thus ensure you leave at least a blank line before typing your message. + The primary domain is added to the address automatically,or you can insert a virtual domain by replacing the domain part of the sender address + in the first line of the message with the virtual domain name (eg. replace the default From: user@primary.domain with From: user@virtual.domain). + To change the vacation message back to the default type reset.

+

+ You can also fill out the Enable vacation on and Disable vacation on fields in order to + automatically enable and disable sending of the vacation message for this user account on the given dates. +

+

+ The dates in the two fields must not be the same.
+ If you want to use this functionality, leave the Enable vacation messages setting at No - it will be automatically activated based on the date given. +

' +); + +our %Lexicon = ( + %{ SrvMngr::I18N::Modules::General::en::Lexicon }, + %lexicon +); + + +1; diff -urN smeserver-vacation-1.1.old/root/usr/share/smanager/themes/default/templates/partials/_vac_add.html.ep smeserver-vacation-1.1/root/usr/share/smanager/themes/default/templates/partials/_vac_add.html.ep --- smeserver-vacation-1.1.old/root/usr/share/smanager/themes/default/templates/partials/_vac_add.html.ep 1970-01-01 01:00:00.000000000 +0100 +++ smeserver-vacation-1.1/root/usr/share/smanager/themes/default/templates/partials/_vac_add.html.ep 2020-05-19 15:36:00.000000000 +0100 @@ -0,0 +1,54 @@ +
+ + % my $btn = l('ADD'); + + % if ($config->{debug} == 1) { +

+ %= dumper $c->current_route + %= dumper $EmailVacation +

+ % } + + %= form_for '/Uservacations2' => (method => 'POST') => begin + + + %=l 'ACCOUNT' + + %= $account +

+ + %=l 'USER_NAME' + + %=$username +

+ + %=$c->render_to_string(inline =>$c->l('vac_VACATION_FROM1')) + + + %=date_field 'EmailVacationFrom' =>$EmailVacationFrom +

+ + %=$c->render_to_string(inline =>$c->l('vac_VACATION_TO1')) + + + %=date_field 'EmailVacationTo' =>$EmailVacationTo +

+ + %=l 'vac_MESSAGE' + + + %=text_area 'VacText' => $VacText, cols=>55, rows=>15 +

+ + %=l 'vac_VACATION_STATUS' + + + % param EmailVacation => "$EmailVacation"; + %=select_field EmailVacation =>[['Yes'=>'yes'],['No'=>'no']] +

+ %= hidden_field 'account' => $account + + %= submit_button "$btn", class => 'action' + %end + +
diff -urN smeserver-vacation-1.1.old/root/usr/share/smanager/themes/default/templates/partials/_vac_list.html.ep smeserver-vacation-1.1/root/usr/share/smanager/themes/default/templates/partials/_vac_list.html.ep --- smeserver-vacation-1.1.old/root/usr/share/smanager/themes/default/templates/partials/_vac_list.html.ep 1970-01-01 01:00:00.000000000 +0100 +++ smeserver-vacation-1.1/root/usr/share/smanager/themes/default/templates/partials/_vac_list.html.ep 2020-06-10 18:22:00.000000000 +0100 @@ -0,0 +1,50 @@ +
+ + %# my $btn = l('vac_CREATE_RULE'); + + %= form_for '/Uservacations1' => (method => 'POST') => begin +

+ + % if ($empty){ +
+ %=l 'vac_NO_FORWARDS' + % } else { + + + + + + + + + + + % foreach my $vacation (@$vacations) { + + %= t td => (class => 'sme-border') => $vacation->{"User"} + %= t td => (class => 'sme-border') => $vacation->{"FullName"} + %= t td => (class => 'sme-border') => $vacation->{"status"} + %= t td => (class => 'sme-border') => $vacation->{"EmailVacationFrom"} + %= t td => (class => 'sme-border') => $vacation->{"EmailVacationTo"} + + + %} + +
+ %=l 'ACCOUNT' + + %=l 'USER_NAME' + + %=l 'vac_LABEL_VACATION' + + %=$c->render_to_string(inline =>l('vac_VACATION_FROM')) + + %=$c->render_to_string(inline =>l('vac_VACATION_TO')) + + %=l 'ACTION' +
+ "><%=l 'MODIFY'%> +
+ %} + % end +
diff -urN smeserver-vacation-1.1.old/root/usr/share/smanager/themes/default/templates/uservacations.html.ep smeserver-vacation-1.1/root/usr/share/smanager/themes/default/templates/uservacations.html.ep --- smeserver-vacation-1.1.old/root/usr/share/smanager/themes/default/templates/uservacations.html.ep 1970-01-01 01:00:00.000000000 +0100 +++ smeserver-vacation-1.1/root/usr/share/smanager/themes/default/templates/uservacations.html.ep 2020-05-19 15:36:00.000000000 +0100 @@ -0,0 +1,42 @@ +% layout 'default', title => "Sme server 2 - User Vacations", share_dir => './'; + +% content_for 'module' => begin +
+ + % if ($config->{debug} == 1) { +

+ %= dumper $c->current_route +

+ % } + +

<%=$title%>

+ %= $modul + + %if ($vac_datas->{first}) { +
+ %=$c->render_to_string(inline =>$c->l($vac_datas->{first})) + + %} elsif ($vac_datas->{success}) { +
+

Operation Status Report

+ %= $c->l($vac_datas->{success}); +
+ + %} elsif ($vac_datas->{error}) { +
+

Operation Status Report - error

+ %= $c->l($vac_datas->{error}); +
+ %} + + + % if ($vac_datas->{trt} eq 'ADD') { + %= include 'partials/_vac_add' + %} elsif ($vac_datas->{trt} eq 'ADD1') { + %= include 'partials/_vac_add' + %} else { + %= include 'partials/_vac_list' + %} + +
+%end