diff -urN smeserver-manager-0.1.0.old/root/usr/share/smanager/lib/SrvMngr/Controller/Datetime.pm smeserver-manager-0.1.0/root/usr/share/smanager/lib/SrvMngr/Controller/Datetime.pm --- smeserver-manager-0.1.0.old/root/usr/share/smanager/lib/SrvMngr/Controller/Datetime.pm 2020-07-01 16:03:45.268785684 +0200 +++ smeserver-manager-0.1.0/root/usr/share/smanager/lib/SrvMngr/Controller/Datetime.pm 2020-07-05 19:59:27.000000000 +0200 @@ -17,7 +17,7 @@ use SrvMngr qw(theme_list init_session); use esmith::FormMagick; -#use esmith::FormMagick::Panel::datetime; +use esmith::util; our $cdb = esmith::ConfigDB->open() || die "Couldn't open config db"; @@ -29,9 +29,27 @@ my $title = $c->l('dat_FORM_TITLE'); my $modul = $c->l('dat_INITIAL_DESC'); -# more complicated for ntpstatus - $dat_datas{'ntpstatus'} = ($cdb->get_prop('ntpd','status')) || ''; - $dat_datas{'ntpserver'} = ($cdb->get_prop('ntpd','NTPServer')) || ''; + + $dat_datas{ntpstatus} = 'disabled'; + + my $rec = $cdb->get('ntpd'); + if ($rec) { + $dat_datas{'ntpserver'} = $rec->prop('NTPServer') || ''; + if ( $rec->prop('status') eq 'enabled' ) { + $dat_datas{ntpstatus} = 'enabled' + unless ($rec->prop('SyncToHWClockSupported') || 'yes') eq 'yes' and $dat_datas{ntpserver} =~ m#^\s*$#; + } + } + + ($dat_datas{weekday}, $dat_datas{monthname}, + $dat_datas{month}, $dat_datas{day}, $dat_datas{year}, + $dat_datas{hour}, $dat_datas{minute}, $dat_datas{second}, + $dat_datas{ampm}) = split /\|/, + `/bin/date '+%A|%B|%-m|%-d|%Y|%-I|%M|%S|%p'`; + + # get rid of trailing carriage return on last field + chop ($dat_datas{ampm}); + $dat_datas{'now_string'} = esmith::FormMagick->gen_locale_date_string(); $c->stash( title => $title, modul => $modul, dat_datas => \%dat_datas ); @@ -40,53 +58,342 @@ sub do_update { + my $c = shift; - $c->app->log->info($c->log_req); my %dat_datas = (); my $title = $c->l('dat_FORM_TITLE'); - my $result = ''; + my $modul = $c->l('dat_INITIAL_DESC'); + my $result; + my $success; + + my $old_ntpstatus = $c->param('Old_ntpstatus'); + $dat_datas{ntpstatus} = $c->param('Ntpstatus'); + + + if ( $dat_datas{ntpstatus} ne $old_ntpstatus) { + + if ( $dat_datas{ntpstatus} eq 'disabled' ) { + ($dat_datas{weekday}, + $dat_datas{monthname}, + $dat_datas{month}, + $dat_datas{day}, + $dat_datas{year}, + $dat_datas{hour}, + $dat_datas{minute}, + $dat_datas{second}, + $dat_datas{ampm}) = split /\|/, + `/bin/date '+%A|%B|%-m|%-d|%Y|%-I|%M|%S|%p'`; - my $old_ntpstatus = $c->param('old_ntpstatus'); - $dat_datas{ntpstatus} = $c->param('ntpstatus'); + # get rid of trailing carriage return on last field + chop ($dat_datas{ampm}); + + } else { + + $dat_datas{ntpserver} = ($cdb->get_prop('ntpd','NTPServer')) || ''; + } - if ($dat_datas{ntpstatus} ne $old_ntpstatus) { - my $modul = $c->l('dat_INITIAL_DESC'); - $dat_datas{ntpserver} = ($cdb->get_prop('ntpd','NTPServer')) || ''; $dat_datas{now_string} = esmith::FormMagick->gen_locale_date_string(); + $c->stash( title => $title, modul => $modul, dat_datas => \%dat_datas ); return $c->render('datetime'); } - if ($dat_datas{ntpstatus} eq 'enabled') { - $dat_datas{ntpserver} = $c->param('ntpserver'); - $cdb->get('ntpd')->set_prop('NTPServer', $dat_datas{'ntpserver'}); + if ( $dat_datas{ntpstatus} eq 'enabled' ) { + + # update ntpserver + + $dat_datas{ntpserver} = $c->param('Ntpserver') || ''; + + if ( $dat_datas{ntpserver} eq "pool.ntp.org" ) { + $result .= $c->l('dat_INVALID_NTP_ADDR'); + } elsif ( $dat_datas{ntpserver} =~ /^([a-zA-Z0-9\.\-]+)$/ ) { + $dat_datas{ntpserver} = $1; +# } elsif ( $dat_datas{ntpserver} =~ /^\s*$/ ) { +# $dat_datas{ntpserver} = ""; + } else { + $result .= $c->l('dat_INVALID_NTP_ADDR'); + } + + if ( ! $result ) { + $success = update_ntpserver( $c, $dat_datas{ntpserver} ); + } + } else { + + # set Locale time & clean ntpserver + #my $servername = ($c->param('ServerName') || 'WS'); + if ( ! $result ) { + $result = validate_change_datetime( $c ); + if ( $result eq 'OK' ) { + $success = $c->l('dat_UPDATING_CLOCK'); + $result = ''; + disable_ntp(); + $success .= '
'. $c->l('dat_SERVER_DISABLED_DESC'); + } + } } - # controls - # - # Update the system - # - system ("/sbin/e-smith/signal-event", "datetime-update") == 0 - or $result = $c->l('ERROR_UPDATING_CONFIGURATION'); if ( $result ) { $c->stash( error => $result ); - $c->stash( title => $title, dat_datas => \%dat_datas ); + $c->stash( title => $title, modul => $modul, dat_datas => \%dat_datas ); return $c->render('datetime'); - #$c->flash( error => $result . '- f l a s h' ); - #$c->redirect_to('/datetime'); } - $result = $c->l('dat_SUCCESS'); + #$result = $c->l('dat_SUCCESS'); my $message = "'Datetime' update DONE"; $c->app->log->info($message); - $c->flash( success => $result ); + $c->flash( success => $success ); $c->redirect_to('/datetime'); }; +sub validate_change_datetime { + + my $c = shift; + + #-------------------------------------------------- + # Untaint parameters and check for validity + #-------------------------------------------------- + + my $timezone = $c->param ('Timezone'); + if ($timezone =~ /^(.*)$/) { + $timezone = $1; + } else { + $timezone = "US/Eastern"; + } + + my $month = $c->param ('Month'); + if ($month =~ /^(.*)$/) { + $month = $1; + } else { + $month = "1"; + } + + my $day = $c->param ('Day'); + if ($day =~ /^(.*)$/) { + $day = $1; + } else { + $day = "1"; + } + if (($day < 1) || ($day > 31)) { + return $c->l('dat_INVALID_DAY')." $day. ". $c->l('dat_BETWEEN_1_AND_31'); + } + + my $year = $c->param ('Year'); + if ($year =~ /^(.*)$/) { + $year = $1; + } else { + $year = "2000"; + } + + if (($year < 1900) || ($year > 2200)) { + return $c->l('dat_INVALID_YEAR')." $year. ". $c->l('dat_FOUR_DIGIT_YEAR'); + } + + my $hour = $c->param ('Hour'); + if ($hour =~ /^(.*)$/) { + $hour = $1; + } else { + $hour = "12"; + } + if (($hour < 1) || ($hour > 12)) { + return $c->l('dat_INVALID_HOUR')." $hour. ". $c->l('dat_BETWEEN_1_AND_12'); + } + + my $minute = $c->param ('Minute'); + if ($minute =~ /^(.*)$/) { + $minute = $1; + } else { + $minute = "0"; + } + + if (($minute < 0) || ($minute > 59)) { + return $c->l('datINVALID_MINUTE')." $minute. ".$c->l('dat_BETWEEN_0_AND_59'); + } + + my $second = $c->param ('Second'); + if ($second =~ /^(.*)$/) { + $second = $1; + } else { + $second = "0"; + } + + if (($second < 0) || ($second > 59)) { + return $c->l('dat_INVALID_SECOND')." $second. ". $c->l('dat_BETWEEN_0_AND_59'); + } + + my $ampm = $c->param ('Ampm'); + if ($ampm =~ /^(.*)$/) { + $ampm = $1; + } else { + $ampm = "AM"; + } + + # convert to 24 hour time + + $hour = $hour % 12; + if ($ampm eq "PM") { + $hour = $hour + 12; + } + + #-------------------------------------------------- + # Store time zone in configuration database + #-------------------------------------------------- + + my $conf = esmith::ConfigDB->open(); + my $old = $conf->get('UnsavedChanges')->value; + my $rec = $conf->get('TimeZone'); + unless ($rec) { + $rec = $conf->new_record('TimeZone',undef); + } + $rec->set_value($timezone); + $conf->get('UnsavedChanges')->set_value($old); + + #-------------------------------------------------- + # Signal event to change time zone, system time + # and hardware clock + #-------------------------------------------------- + + my $newdate = sprintf "%02d%02d%02d%02d%04d.%02d", + $month, $day, $hour, $minute, $year, $second; + + esmith::util::backgroundCommand(2, + "/sbin/e-smith/signal-event","timezone-update",$newdate); + + return 'OK'; +} + + +sub update_ntpserver { + + my $c = shift; + my $ntpserver = shift; + + my $msg; + #------------------------------------------------------------ + # Looks good; go ahead and change the parameters. + #------------------------------------------------------------ + + my $old = $cdb->get('UnsavedChanges')->value; + my $rec = $cdb->get('ntpd'); + if ($rec) { + $rec->set_prop('status','enabled'); + $rec->set_prop('NTPServer',$ntpserver); + } else { + $rec = $cdb->new_record( 'ntpd', + { type=>'service', status=>'enabled', SyncToHWClockSupported => 'yes', NTPServer=>$ntpserver } ); + } + $cdb->get('UnsavedChanges')->set_value($old); + + $msg = $c->l('dat_SETTINGS_CHANGED'); + + if ( $ntpserver =~ /^\s*$/ ) { + $rec->set_prop('status', ($rec->prop('SyncToHWClockSupported') || 'yes') eq 'yes' ? 'enabled' : 'disabled'); + $rec->set_prop('NTPServer', ''); + $msg = $c->l('dat_INVALID_NTP_SERVER') if ($rec->prop('SyncToHWClockSupported') || 'yes') ne 'yes'; + } + + esmith::util::backgroundCommand( 2, "/sbin/e-smith/signal-event", "timeserver-update" ); + + return $msg; +} + + +sub disable_ntp { + + # make sure that the parameters are set for disabled + + my $old = $cdb->get('UnsavedChanges')->value; + my $rec = $cdb->get('ntpd'); + + if ($rec) { + $rec->set_prop('status', ($rec->prop('SyncToHWClockSupported') || 'yes') eq 'yes' ? 'enabled' : 'disabled'); + $rec->set_prop('NTPServer',''); + } else { + $rec = $cdb->new_record('ntpd', + {type=>'service', status=>'enabled', SyncToHWClockSupported => 'yes', NTPServer=>''}); + } + + $cdb->get('UnsavedChanges')->set_value($old); + +} + + +sub getTimezone { + + #-------------------------------------------------- + # Figure out time zone by looking first looking at + # the configuration database value of TimeZone. + # If that is not defined, try and get it from /etc/localtime. + # If that doesn't work, default to US/Eastern. + #-------------------------------------------------- + + my $localtime; + my $timezonedefault = "US/Eastern"; + + if (defined $cdb->get('TimeZone')) { + $timezonedefault = $cdb->get('TimeZone')->value; + } else { + if (defined ($localtime = readlink '/etc/localtime')) { + my $pos = index $localtime, 'zoneinfo/'; + if ( $pos > -1 ) { + $timezonedefault = substr $localtime, ($pos + 9); + } + } + } + return $timezonedefault; +} + + +sub getZone_list { + + my $c = shift; + + #-------------------------------------------------- + # Get a sorted list of time zones + #-------------------------------------------------- + + $ENV{BASH_ENV} = ''; + if (! open (ZONES, "cd /usr/share/zoneinfo; /usr/bin/find . -type f -or -type l | /bin/grep '^./[A-Z]' |")) + { + warn ( $c->l('COULD_NOT_OPEN_TZ_FILE').$!.'.' ); + return undef; + } + my $zone; + my @zones = (); + + while (defined ($zone = )) + { + chop ($zone); + $zone =~ s/^.\///; + push @zones, $zone; + } + close ZONES; + my @zt = sort @zones; + return \@zt; +} + + +sub getMonth_list { + + my $c = shift; + return [[ $c->l('dat_JANUARY') => '1'], + [ $c->l('dat_FEBRUARY') => '2'], + [ $c->l('dat_MARCH') => '3'], + [ $c->l('dat_APRIL') => '4'], + [ $c->l('dat_MAY') => '5'], + [ $c->l('dat_JUNE') => '6'], + [ $c->l('dat_JULY') => '7'], + [ $c->l('dat_AUGUST') => '8'], + [ $c->l('dat_SEPTEMBER') => '9'], + [ $c->l('dat_OCTOBER') => '10'], + [ $c->l('dat_NOVEMBER') => '11'], + [ $c->l('dat_DECEMBER') => '12']]; +} + + 1; diff -urN smeserver-manager-0.1.0.old/root/usr/share/smanager/lib/SrvMngr/Controller/Quota.pm smeserver-manager-0.1.0/root/usr/share/smanager/lib/SrvMngr/Controller/Quota.pm --- smeserver-manager-0.1.0.old/root/usr/share/smanager/lib/SrvMngr/Controller/Quota.pm 2020-06-28 16:50:36.433935049 +0200 +++ smeserver-manager-0.1.0/root/usr/share/smanager/lib/SrvMngr/Controller/Quota.pm 2020-07-05 21:02:49.000000000 +0200 @@ -33,17 +33,15 @@ my %quo_datas = (); my $title = $c->l('quo_FORM_TITLE'); - my $modul = ''; $quo_datas{'trt'} = 'LIST'; my @userAccounts; - if ($adb) - { + if ($adb) { @userAccounts = $adb->users(); } - $c->stash( title => $title, modul => $modul, quo_datas => \%quo_datas, userAccounts => \@userAccounts ); + $c->stash( title => $title, quo_datas => \%quo_datas, userAccounts => \@userAccounts ); $c->render(template => 'quota'); }; @@ -61,7 +59,6 @@ my %quo_datas = (); my $title = $c->l('quo_FORM_TITLE'); - my $modul = ''; $quo_datas{'trt'} = $trt; @@ -79,7 +76,7 @@ } - $c->stash( title => $title, modul => $modul, quo_datas => \%quo_datas ); + $c->stash( title => $title, quo_datas => \%quo_datas ); $c->render( template => 'quota' ); }; @@ -90,30 +87,46 @@ my $c = shift; $c->app->log->info($c->log_req); + my $title = $c->l('quo_FORM_TITLE'); + my %quo_datas = (); + my $rt = $c->current_route; my $trt = ($c->param('trt') || 'LIST'); + $quo_datas{trt} = $trt; my $result = ''; + my $res; if ( $trt eq 'UPD' ) { - my $acct = ($c->param('user') || ''); - my $soft = ($c->param('Soft') || ''); - my $hard = ($c->param('Hard') || ''); + $quo_datas{user} = ($c->param('user') || ''); + $quo_datas{softlim} = ($c->param('Soft') || ''); + $quo_datas{hardlim} = ($c->param('Hard') || ''); # controls - my $res = validate_quota( $c, $acct, $soft, $hard ); + $res = validate_quota( $c, $quo_datas{user}, $quo_datas{softlim}, $quo_datas{hardlim} ); $result .= $res unless $res eq 'OK'; if ( ! $result ) { - $result = $c->l('quo_SUCCESSFULLY_MODIFIED') . ' ' . $acct; + $result = $c->l('quo_SUCCESSFULLY_MODIFIED') . ' ' . $quo_datas{user}; + } else { + $quo_datas{userRec} = $adb->get($quo_datas{user}) || undef; } } - my $title = $c->l('quo_FORM_TITLE'); + # common parts + + if ($res ne 'OK') { + $c->stash( error => $result ); + $c->stash( title => $title, quo_datas => \%quo_datas ); + return $c->render('quota'); + } + + my $message = "'Quota' updates ($trt) DONE"; + $c->app->log->info($message); + $c->flash( success => $result ); - $c->stash( title => $title, modul => $result ); - $c->render(template => 'module'); + $c->redirect_to('/quota'); }; diff -urN smeserver-manager-0.1.0.old/root/usr/share/smanager/themes/default/templates/datetime.html.ep smeserver-manager-0.1.0/root/usr/share/smanager/themes/default/templates/datetime.html.ep --- smeserver-manager-0.1.0.old/root/usr/share/smanager/themes/default/templates/datetime.html.ep 2020-07-05 22:56:57.000000000 +0200 +++ smeserver-manager-0.1.0/root/usr/share/smanager/themes/default/templates/datetime.html.ep 2020-07-05 19:21:53.000000000 +0200 @@ -22,10 +22,10 @@ %= form_for '/datetime' => (method => 'POST') => begin

- %= hidden_field 'old_ntpstatus' => $dat_datas->{ntpstatus}; + %= hidden_field 'Old_ntpstatus' => $dat_datas->{ntpstatus}; - % param 'ntpstatus' => $dat_datas->{ntpstatus} unless param 'ntpstatus'; - %= radio_button ntpstatus => 'enabled' + % param 'Ntpstatus' => $dat_datas->{ntpstatus} unless param 'Ntpstatus'; + %= radio_button Ntpstatus => 'enabled' %=l 'dat_NTP_CONFIGURE_TITLE' @@ -46,12 +46,12 @@ %=l 'dat_NTP_SERVER' - %= text_field 'ntpServer' => $dat_datas->{ntpserver}, class => 'input' + %= text_field 'Ntpserver' => $dat_datas->{ntpserver}, class => 'input'

% }

- %= radio_button ntpstatus => 'disabled' + %= radio_button Ntpstatus => 'disabled' %=l 'dat_NTP_DISABLE_TITLE' @@ -66,36 +66,44 @@

%=l 'dat_CURRENT_SETTING' - + %= $dat_datas->{now_string}
%=l 'dat_NEW_M/D/Y' - %= text_field 'month' => $dat_datas->{month}, size => '2', class => 'input' + % param 'Month' => $dat_datas->{month} unless param 'Month'; + %= select_field 'Month' => $c->getMonth_list(), class => 'input' - %= text_field 'day' => $dat_datas->{day}, size => '2', class => 'input' + % param 'Day' => $dat_datas->{day} unless param 'Day'; + %= text_field 'Day', size => '2', class => 'input' - %= text_field 'year' => $dat_datas->{year}, size => '2', class => 'input' + % param 'Year' => $dat_datas->{year} unless param 'Year'; + %= text_field 'Year', size => '4', class => 'input'
%=l 'dat_NEW_H/M/S' - %= text_field 'hour' => $dat_datas->{hour}, size => '2', class => 'input' + % param 'Hour' => $dat_datas->{hour} unless param 'Hour'; + %= text_field 'Hour', size => '2', class => 'input' - %= text_field 'minute' => $dat_datas->{minute}, size => '2', class => 'input' + % param 'Minute' => $dat_datas->{minute} unless param 'Minute'; + %= text_field 'Minute', size => '2', class => 'input' - %= text_field 'second' => $dat_datas->{second}, size => '2', class => 'input' + % param 'Second' => $dat_datas->{second} unless param 'Second'; + %= text_field 'Second', size => '2', class => 'input'
%=l 'dat_AM/PM_AND_TZ' - %= select_field 'ampm' => [[AM => 'am'],[PM => 'pm']], class => 'input' + % param 'Ampm' => $dat_datas->{ampm} unless param 'Ampm'; + %= select_field 'Ampm' => ['AM', 'PM'], class => 'input' - %= text_field 'timezone' => $dat_datas->{timezone}, class => 'input' + % param 'Timezone' => $c->getTimezone() unless param 'Timezone'; + %= select_field 'Timezone' => $c->getZone_list(), class => 'input'

% } diff -urN smeserver-manager-0.1.0.old/root/usr/share/smanager/themes/default/templates/quota.html.ep smeserver-manager-0.1.0/root/usr/share/smanager/themes/default/templates/quota.html.ep --- smeserver-manager-0.1.0.old/root/usr/share/smanager/themes/default/templates/quota.html.ep 2020-04-26 11:00:06.000000000 +0200 +++ smeserver-manager-0.1.0/root/usr/share/smanager/themes/default/templates/quota.html.ep 2020-07-05 21:03:24.000000000 +0200 @@ -5,18 +5,18 @@ % if ($config->{debug} == 1) {

- (DBG)route: %= dumper $c->current_route -
- (DBG)datas: %= dumper $quo_datas - -->

% } -

<%= $title%>

+ % if ( stash 'error' ) { +
+ %= $c->render_to_string(inline => stash 'error') +
+ %} - %= $modul +

<%= $title%>

% if ($quo_datas->{trt} eq 'UPD') { %= include 'partials/_quo_upd'