diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Backup.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Backup.pm index 30328ec..0c95a00 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Backup.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Backup.pm @@ -7,50 +7,38 @@ package SrvMngr::Controller::Backup; # Copyright (C) 2002 Mitel Networks Corporation #---------------------------------------------------------------------- # routes : end - # for information - routes # $if_admin->get('/backup')->to('backup#main')->name('backup'); # $if_admin->post('/backup')->to('backup#do_display')->name('backupd'); # $if_admin->get('/backupd')->to('backup#do_display')->name('backupc'); # $if_admin->post('/backupd')->to('backup#do_update')->name('backupu'); - use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; use utf8; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session ip_number_or_blank); - use Quota; use esmith::ConfigDB; use esmith::AccountsDB; - use esmith::util; use File::Basename; use File::Find; use File::Path qw(make_path remove_tree); - use esmith::Backup; use esmith::BackupHistoryDB; use esmith::util; use esmith::lockfile; - use esmith::BlockDevices; - use constant DEBUG => $ENV{MOJO_SMANAGER_DEBUG} || 0; - -our $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; +our $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; our $adb = esmith::AccountsDB->open || die "Couldn't open accounts db"; our $rdb = esmith::ConfigDB->open('/etc/e-smith/restore') - || die "Couldn't open restore db"; - + || die "Couldn't open restore db"; my $es_backup = new esmith::Backup or die "Couldn't create Backup object\n"; - my @directories = $es_backup->restore_list; @directories = grep { -e "/$_" } @directories; - my @backup_excludes = $es_backup->excludes; # Unbuffer standard output so that files and directories are listed as @@ -60,724 +48,647 @@ $| = 1; # Store away current gid of 'www' group. my $www_gid = getgrnam("www"); - sub main { - my $c = shift; $c->app->log->info($c->log_req); - my %bac_datas = (); - my $title = $c->l('bac_BACKUP_TITLE'); + my $title = $c->l('bac_BACKUP_TITLE'); my $notif; - $bac_datas{'function'} = 'desktop_backup'; my ($tarsize, $dumpsize, undef, undef) = $c->CalculateSizes(); - my $module = $cdb->get('backup'); + if ($module) { - $module = $module->prop('Program'); + $module = $module->prop('Program'); } # The default e-smith backup program is flexbackup. unless (defined $module) { - $module = "flexbackup"; + $module = "flexbackup"; } elsif ($module eq '') { - $module = "flexbackup"; + $module = "flexbackup"; } - - $bac_datas{'tarsize'} = $tarsize; + $bac_datas{'tarsize'} = $tarsize; $bac_datas{'dumpsize'} = $dumpsize; - $bac_datas{'module'} = $module; + $bac_datas{'module'} = $module; if ($tarsize =~ /Tb/ or $tarsize =~ /(\d+)Gb/ and $1 >= 2) { - $notif = $c->l("bac_BACKUP_DESKTOP_TOO_BIG").' : '.$tarsize; + $notif = $c->l("bac_BACKUP_DESKTOP_TOO_BIG") . ' : ' . $tarsize; } - my $rec = $cdb->get('backup'); my ($backup_status, $backupwk_status) = 'disabled'; if ($rec) { - $backup_status = $rec->prop('status') || 'disabled'; + $backup_status = $rec->prop('status') || 'disabled'; } if ($backup_status eq "enabled") { - $bac_datas{'backupTime'} = $rec->prop('backupTime'); - $bac_datas{'reminderTime'} = $rec->prop('reminderTime'); + $bac_datas{'backupTime'} = $rec->prop('backupTime'); + $bac_datas{'reminderTime'} = $rec->prop('reminderTime'); } - $rec = $cdb->get('backupwk'); + if ($rec) { - $backupwk_status = $rec->prop('status') || 'disabled'; + $backupwk_status = $rec->prop('status') || 'disabled'; } if ($backupwk_status eq "enabled") { - $bac_datas{'backupwkTime'} = $rec->prop('BackupTime'); + $bac_datas{'backupwkTime'} = $rec->prop('BackupTime'); } - - $bac_datas{'backupStatus'} = $backup_status; + $bac_datas{'backupStatus'} = $backup_status; $bac_datas{'backupwkStatus'} = $backupwk_status; - - $c->stash( warning => $notif ) if ( $notif ); - $c->stash( title => $title, bac_datas => \%bac_datas ); + $c->stash(warning => $notif) if ($notif); + $c->stash(title => $title, bac_datas => \%bac_datas); $c->render(template => 'backup'); - -}; - +} ## end sub main sub do_display { - my $c = shift; $c->app->log->info($c->log_req); - my $rt = $c->current_route; my ($res, $result) = ''; - my $function = $c->param('Function'); if ($function =~ /^(\S+)$/) { - $function = $1; + $function = $1; } elsif ($function =~ /^\s*$/) { - $function = "zoverall"; - } else { - $result = $c->l('bac_INVALID_FUNCTION') . $function; - $function = undef; + $function = "zoverall"; + } else { + $result = $c->l('bac_INVALID_FUNCTION') . $function; + $function = undef; } - - DEBUG && warn("do_display $function"); - + DEBUG && warn("do_display $function"); my %bac_datas = (); $bac_datas{'function'} = $function; - my $title = $c->l('bac_BACKUP_TITLE'); - my $dest = ''; + my $dest = ''; + if ($function eq 'desktop_backup') { + my $CompressionLevel = $cdb->get_prop("backupconsole", "CompressionLevel") || "-6"; + my @exclude = map (" --exclude=$_", @backup_excludes); + $c->stash(compressionlevel => $CompressionLevel, exclude => \@exclude, directories => \@directories); - if ( $function eq 'desktop_backup' ) { + # streaming download in template + return $c->render("/backdown"); + } ## end if ($function eq 'desktop_backup') - my $CompressionLevel = $cdb->get_prop("backupconsole", "CompressionLevel") || "-6"; - my @exclude = map (" --exclude=$_",@backup_excludes); + if ($function eq 'tape_configure') { + $bac_datas{'status'} = 'unchecked'; + my $backupTime = "2:00"; + my $rec = $cdb->get('backup'); - $c->stash( compressionlevel => $CompressionLevel, exclude => \@exclude, directories => \@directories ); + if ($rec) { + $backupTime = $rec->prop('backupTime') || "2:00"; + my $backup_status = $rec->prop('status'); - # streaming download in template - return $c->render("/backdown"); - } + if (defined $backup_status && $backup_status eq "enabled") { + $bac_datas{'status'} = "checked"; + } + } ## end if ($rec) + ($bac_datas{backupAMPM}, $bac_datas{reminderAMPM}) = 'AM'; + ($bac_datas{backupHour}, $bac_datas{backupMin}) = split(":", $backupTime, -1); - - if ( $function eq 'tape_configure' ) { - - $bac_datas{'status'} = 'unchecked'; - my $backupTime = "2:00"; - - my $rec = $cdb->get('backup'); - if ($rec) { - $backupTime = $rec->prop('backupTime') || "2:00"; - - my $backup_status = $rec->prop('status'); - if (defined $backup_status && $backup_status eq "enabled") { - $bac_datas{'status'} = "checked"; - } - } - ($bac_datas{backupAMPM}, $bac_datas{reminderAMPM}) = 'AM'; - - ($bac_datas{backupHour}, $bac_datas{backupMin}) = split (":", $backupTime, -1); - if ($bac_datas{backupHour} > 11) { - if ($bac_datas{backupHour} > 12) { - $bac_datas{backupHour} -= 12; - } - $bac_datas{backupAMPM} = 'PM'; - } + if ($bac_datas{backupHour} > 11) { + if ($bac_datas{backupHour} > 12) { + $bac_datas{backupHour} -= 12; + } + $bac_datas{backupAMPM} = 'PM'; + } ## end if ($bac_datas{backupHour...}) # Obtain time for reminder notice from the backup cron template my $reminderTime = "14:00"; - if ($rec) { - $reminderTime = $rec->prop('reminderTime') || "14:00"; - } - ($bac_datas{reminderHour}, $bac_datas{reminderMin}) = split (":", $reminderTime, -1); + if ($rec) { + $reminderTime = $rec->prop('reminderTime') || "14:00"; + } + ($bac_datas{reminderHour}, $bac_datas{reminderMin}) = split(":", $reminderTime, -1); + if ($bac_datas{reminderHour} > 12) { - $bac_datas{reminderHour} -= 12; - $bac_datas{reminderAMPM} = 'PM'; - } - } + $bac_datas{reminderHour} -= 12; + $bac_datas{reminderAMPM} = 'PM'; + } + } ## end if ($function eq 'tape_configure') - - if ( $function eq 'workstn_configure' ) { - - my $rec = $cdb->get('backupwk'); - $bac_datas{vfstype} = $rec->prop('VFSType') || 'cifs'; - $bac_datas{status} = $rec->prop('status'); - } - - - if ( $function eq 'workstn_configure1' ) { - - $bac_datas{vfstype} = $c->param('VFSType'); - $bac_datas{'status'} = ''; - $bac_datas{ampm} = 'AM'; - $bac_datas{min} = ''; - $bac_datas{hour} = ''; - $bac_datas{login} = 'backup'; - $bac_datas{password} = 'backup'; - $bac_datas{station} = 'host'; - $bac_datas{folder} = 'share'; - $bac_datas{mount} = ''; - $bac_datas{setsNumber} = ''; - $bac_datas{filesinset} = ''; - $bac_datas{timeout} = ''; - $bac_datas{incOnlyTimeout} = ''; - $bac_datas{compression} = ''; - $bac_datas{dof} = ''; - - # Obtain backup informations from configuration + if ($function eq 'workstn_configure') { my $rec = $cdb->get('backupwk'); - my $Time = '2:00'; + $bac_datas{vfstype} = $rec->prop('VFSType') || 'cifs'; + $bac_datas{status} = $rec->prop('status'); + } ## end if ($function eq 'workstn_configure') + + if ($function eq 'workstn_configure1') { + $bac_datas{vfstype} = $c->param('VFSType'); + $bac_datas{'status'} = ''; + $bac_datas{ampm} = 'AM'; + $bac_datas{min} = ''; + $bac_datas{hour} = ''; + $bac_datas{login} = 'backup'; + $bac_datas{password} = 'backup'; + $bac_datas{station} = 'host'; + $bac_datas{folder} = 'share'; + $bac_datas{mount} = ''; + $bac_datas{setsNumber} = ''; + $bac_datas{filesinset} = ''; + $bac_datas{timeout} = ''; + $bac_datas{incOnlyTimeout} = ''; + $bac_datas{compression} = ''; + $bac_datas{dof} = ''; + + # Obtain backup informations from configuration + my $rec = $cdb->get('backupwk'); + my $Time = '2:00'; + if ($rec) { - $Time = $rec->prop('BackupTime') || '2:00'; - $bac_datas{login} = $rec->prop('Login') || 'backup'; - $bac_datas{password} = $rec->prop('Password') || 'backup'; - $bac_datas{station} = $rec->prop('SmbHost') || 'host'; - $bac_datas{folder} = $rec->prop('SmbShare') || 'share'; - $bac_datas{mount} = $rec->prop('Mount') || ''; - $bac_datas{setsNumber} = $rec->prop('SetsMax') || '1'; - $bac_datas{filesinset} = $rec->prop('DaysInSet') || '1'; - $bac_datas{timeout} = $rec->prop('Timeout') || '12'; - $bac_datas{incOnlyTimeout} = $rec->prop('IncOnlyTimeout') || 'yes'; - $bac_datas{compression} = $rec->prop('Compression') || '0'; - $bac_datas{dof} = (defined $rec->prop('FullDay')) ? $rec->prop('FullDay') : '7'; - } + $Time = $rec->prop('BackupTime') || '2:00'; + $bac_datas{login} = $rec->prop('Login') || 'backup'; + $bac_datas{password} = $rec->prop('Password') || 'backup'; + $bac_datas{station} = $rec->prop('SmbHost') || 'host'; + $bac_datas{folder} = $rec->prop('SmbShare') || 'share'; + $bac_datas{mount} = $rec->prop('Mount') || ''; + $bac_datas{setsNumber} = $rec->prop('SetsMax') || '1'; + $bac_datas{filesinset} = $rec->prop('DaysInSet') || '1'; + $bac_datas{timeout} = $rec->prop('Timeout') || '12'; + $bac_datas{incOnlyTimeout} = $rec->prop('IncOnlyTimeout') || 'yes'; + $bac_datas{compression} = $rec->prop('Compression') || '0'; + $bac_datas{dof} = (defined $rec->prop('FullDay')) ? $rec->prop('FullDay') : '7'; + } ## end if ($rec) + ($bac_datas{hour}, $bac_datas{min}) = split(':', $Time, -1); - ($bac_datas{hour}, $bac_datas{min}) = split (':', $Time, -1); - if ( $bac_datas{hour} > 12 ) { - $bac_datas{hour} -= 12; - $bac_datas{ampm} = 'PM'; - } + if ($bac_datas{hour} > 12) { + $bac_datas{hour} -= 12; + $bac_datas{ampm} = 'PM'; + } + my $backupwk_status; - my $backupwk_status; - if ($rec) { - $backupwk_status = $rec->prop('status'); - } + if ($rec) { + $backupwk_status = $rec->prop('status'); + } - if (defined $backupwk_status && $backupwk_status eq 'enabled') { - $bac_datas{status} = 'checked'; - } + if (defined $backupwk_status && $backupwk_status eq 'enabled') { + $bac_datas{status} = 'checked'; + } - if (defined $bac_datas{incOnlyTimeout} && $bac_datas{incOnlyTimeout} eq 'yes') { - $bac_datas{incOnlyTimeout} = 'checked'; - } - } + if (defined $bac_datas{incOnlyTimeout} && $bac_datas{incOnlyTimeout} eq 'yes') { + $bac_datas{incOnlyTimeout} = 'checked'; + } + } ## end if ($function eq 'workstn_configure1') + if ($function eq 'workstn_verify') { + my $rec = $cdb->get('backupwk'); - if ( $function eq 'workstn_verify' ) { + if ($rec) { + $bac_datas{status} = $rec->prop('status') || 'disabled'; + } + } ## end if ($function eq 'workstn_verify') - my $rec = $cdb->get('backupwk'); - if ( $rec) { - $bac_datas{status} = $rec->prop('status') || 'disabled'; - } - } + if ($function eq 'workstn_verify1') { + $res = ''; + if (!$result) { + $bac_datas{function} = $function; + } + } ## end if ($function eq 'workstn_verify1') - if ( $function eq 'workstn_verify1' ) { - - $res = ''; - if ( ! $result ) { - $bac_datas{function} = $function; - } - - } - - - if ( $function eq 'workstn_restore' ) { - - my $rec = $cdb->get('backupwk'); - if ( $rec) { - $bac_datas{status} = $rec->prop('status') || 'disabled'; - } - } - + if ($function eq 'workstn_restore') { + my $rec = $cdb->get('backupwk'); + if ($rec) { + $bac_datas{status} = $rec->prop('status') || 'disabled'; + } + } ## end if ($function eq 'workstn_restore') $dest = "back_$function"; - - $c->stash( error => $result ); - - $c->stash( title => $title, bac_datas => \%bac_datas ); - return $c->render( template => $dest ); - -}; - + $c->stash(error => $result); + $c->stash(title => $title, bac_datas => \%bac_datas); + return $c->render(template => $dest); +} ## end sub do_display sub do_update { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; + my $rt = $c->current_route; my $function = $c->param('Function'); - - DEBUG && warn("do_update $function"); - + DEBUG && warn("do_update $function"); my %bac_datas = (); - $bac_datas{function} = $function; my $title = $c->l('bac_BACKUP_TITLE'); my ($dest, $res, $result) = ''; + if ($function eq 'desktop_backup') { - if ( $function eq 'desktop_backup' ) { - # should not happen !! no desktop_backup template !! - $result .= ' ** Function error for desktop backup ** !'; - } + # should not happen !! no desktop_backup template !! + $result .= ' ** Function error for desktop backup ** !'; + } ## end if ($function eq 'desktop_backup') + if ($function eq 'tape_configure') { + my $status = $c->param('Tapebackup'); + my $backupHour = $c->param('BackupHour'); + my $backupMin = $c->param('BackupMin'); + my $bampm = $c->param('BackupAMPM'); + my $reminderHour = $c->param('ReminderHour'); + my $reminderMin = $c->param('ReminderMin'); + my $rampm = $c->param('ReminderAMPM'); - if ( $function eq 'tape_configure' ) { + if (defined $status && $status eq "on") { + if ($backupHour =~ /^(.*)$/) { + $backupHour = $1; + } else { + $backupHour = "12"; + } - my $status = $c->param('Tapebackup'); - my $backupHour = $c->param('BackupHour'); - my $backupMin = $c->param('BackupMin'); - my $bampm = $c->param('BackupAMPM'); - my $reminderHour = $c->param('ReminderHour'); - my $reminderMin = $c->param('ReminderMin'); - my $rampm = $c->param('ReminderAMPM'); + if (($backupHour < 1) || ($backupHour > 12)) { + $result .= $c->l('bac_ERR_INVALID_HOUR') . $backupHour . ' ' . $c->l('bac_BETWEEN_0_AND_12') . ' '; + } - if (defined $status && $status eq "on") { - - if ($backupHour =~ /^(.*)$/) { - $backupHour = $1; - } else { - $backupHour = "12"; - } - if (($backupHour < 1) || ($backupHour > 12)) { - $result .= $c->l('bac_ERR_INVALID_HOUR').$backupHour. - ' '.$c->l('bac_BETWEEN_0_AND_12').' '; - } + if ($backupMin =~ /^(.*)$/) { + $backupMin = $1; + } else { + $backupMin = "0"; + } - if ($backupMin =~ /^(.*)$/) { - $backupMin = $1; - } else { - $backupMin = "0"; - } - if (($backupMin < 0) || ($backupMin > 59)) { - $result .= $c->l('bac_ERR_INVALID_MINUTE').$backupMin. - ' '.$c->l('bac_BETWEEN_0_AND_59').' '; - } + if (($backupMin < 0) || ($backupMin > 59)) { + $result .= $c->l('bac_ERR_INVALID_MINUTE') . $backupMin . ' ' . $c->l('bac_BETWEEN_0_AND_59') . ' '; + } - if ($reminderHour =~ /^(.*)$/) { - $reminderHour = $1; - } else { - $reminderHour = "12"; - } - if (($reminderHour < 1) || ($reminderHour > 12)) { - $result .= $c->l('bac_ERR_INVALID_REMINDER_HOUR').$reminderHour. - ' '.$c->l('bac_BETWEEN_0_AND_12').' '; - } + if ($reminderHour =~ /^(.*)$/) { + $reminderHour = $1; + } else { + $reminderHour = "12"; + } - if ($reminderMin =~ /^(.*)$/) { - $reminderMin = $1; - } else { - $reminderMin = "0"; - } - if (($reminderMin < 0) || ($reminderMin > 59)) { - $result .= $c->l('bac_ERR_INVALID_REMINDER_MINUTE').$reminderMin. - ' '.$c->l('bac_BETWEEN_0_AND_59').' '; - } - } else { - # service disabled no controls - } + if (($reminderHour < 1) || ($reminderHour > 12)) { + $result + .= $c->l('bac_ERR_INVALID_REMINDER_HOUR') + . $reminderHour . ' ' + . $c->l('bac_BETWEEN_0_AND_12') . ' '; + } ## end if (($reminderHour < 1...)) - ##$result .= ' ** Blocked for testing ** !'; + if ($reminderMin =~ /^(.*)$/) { + $reminderMin = $1; + } else { + $reminderMin = "0"; + } - $res = ''; - if ( ! $result ) { - $res = $c->tapeBackupConfig($status, $backupHour, - $backupMin, $bampm, $reminderHour, $reminderMin, $rampm); + if (($reminderMin < 0) || ($reminderMin > 59)) { + $result + .= $c->l('bac_ERR_INVALID_REMINDER_MINUTE') + . $reminderMin . ' ' + . $c->l('bac_BETWEEN_0_AND_59') . ' '; + } ## end if (($reminderMin < 0)...) + } else { - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - if (defined $status && $status eq "on") { - $result .= ($c->l('bac_SUCCESSFULLY_ENABLED_TAPE').' '. - $c->l('bac_WITH_BACKUP_TIME')."$backupHour:$backupMin".' '. - $c->l('bac_WITH_REMINDER_TIME')."$reminderHour:$reminderMin"); - } else { - $result .= $c->l('bac_SUCCESSFULLY_DISABLED'); - } - $cdb->reload; - } - } - } + # service disabled no controls + } + ##$result .= ' ** Blocked for testing ** !'; + $res = ''; + if (!$result) { + $res = $c->tapeBackupConfig($status, $backupHour, $backupMin, $bampm, $reminderHour, $reminderMin, $rampm); + $result .= $res unless $res eq 'OK'; - if ( $function eq 'tape_restore' ) { + if (!$result) { + if (defined $status && $status eq "on") { + $result + .= ( $c->l('bac_SUCCESSFULLY_ENABLED_TAPE') . ' ' + . $c->l('bac_WITH_BACKUP_TIME') + . "$backupHour:$backupMin" . ' ' + . $c->l('bac_WITH_REMINDER_TIME') + . "$reminderHour:$reminderMin"); + } else { + $result .= $c->l('bac_SUCCESSFULLY_DISABLED'); + } + $cdb->reload; + } ## end if (!$result) + } ## end if (!$result) + } ## end if ($function eq 'tape_configure') - my $lock_file = "/var/lock/subsys/e-smith-restore"; + if ($function eq 'tape_restore') { + my $lock_file = "/var/lock/subsys/e-smith-restore"; my $file_handle = &esmith::lockfile::LockFileOrReturn($lock_file); unless ($file_handle) { - $result .= $c->l('bac_UNABLE_TO_RESTORE_CONF').' '. - $c->l('bac_ANOTHER_RESTORE_IN_PROGRESS'); - } - - ##$result .= ' ** Blocked for testing ** !'; + $result .= $c->l('bac_UNABLE_TO_RESTORE_CONF') . ' ' . $c->l('bac_ANOTHER_RESTORE_IN_PROGRESS'); + } + ##$result .= ' ** Blocked for testing ** !'; + $res = ''; - $res = ''; - if ( ! $result ) { - $res = $c->tapeRestore( $lock_file, $file_handle ); - $result .= $res unless $res eq 'OK'; - #if ( ! $result ) { - #$result = $c->l('bac_SUCCESS'); - #} - } - } + if (!$result) { + $res = $c->tapeRestore($lock_file, $file_handle); + $result .= $res unless $res eq 'OK'; + #if ( ! $result ) { + #$result = $c->l('bac_SUCCESS'); + #} + } ## end if (!$result) + } ## end if ($function eq 'tape_restore') - if ( $function eq 'workstn_configure' ) { + if ($function eq 'workstn_configure') { - # should not happen !! - $result .= ' ** Function error for workstation configure *** !'; - } + # should not happen !! + $result .= ' ** Function error for workstation configure *** !'; + } ## end if ($function eq 'workstn_configure') + if ($function eq 'workstn_configure1') { - if ( $function eq 'workstn_configure1' ) { + #$result .= ' ** Blocked for testing ** !'; + $res = ''; - #$result .= ' ** Blocked for testing ** !'; + if (!$result) { + $res = $c->updateWorkstnBackupConfig(); - $res = ''; - if ( ! $result ) { - $res = $c->updateWorkstnBackupConfig(); - if ( ($result = $res) =~ s|^#OK#|| ) { - $res = 'OK'; - $cdb->reload; - } - } - } + if (($result = $res) =~ s|^#OK#||) { + $res = 'OK'; + $cdb->reload; + } + } ## end if (!$result) + } ## end if ($function eq 'workstn_configure1') + if ($function eq 'workstn_verify') { - if ( $function eq 'workstn_verify' ) { + # should not happen !! + $result .= ' ** Function error for workstation verify *** !'; + } ## end if ($function eq 'workstn_verify') - # should not happen !! - $result .= ' ** Function error for workstation verify *** !'; - } + if ($function eq 'workstn_verify1') { + ##$result .= ' ** Blocked for testing ** !'; + $res = 'OK'; + $result = ''; + } ## end if ($function eq 'workstn_verify1') + if ($function eq 'workstn_restore') { + ##$result .= ' ** Blocked for testing ** !'; + $res = 'NOK'; - if ( $function eq 'workstn_verify1' ) { + if (!$result) { + $res = $c->workstnRestore(); - ##$result .= ' ** Blocked for testing ** !'; + if (($result = $res) =~ s|^#OK#||) { + $bac_datas{restore_log} = $result; + $res = 'OK'; + } else { + $c->stash(error => $result); + } + $bac_datas{function} = 'workstn_restore1'; + $res = 'NEXT'; + } ## end if (!$result) + } ## end if ($function eq 'workstn_restore') - $res = 'OK'; - $result = ''; - } + if ($function eq 'workstn_restore1') { + my $state = 'unknown'; + my $rec = $rdb->get('restore'); + if ($rec) { + $state = $rec->prop('state') || 'unknown'; + } + $result .= "Restore state unexpected: $state" if ($state ne 'complete'); + $res = 'NOK'; - if ( $function eq 'workstn_restore' ) { + if (!$result) { + $res = $c->performReboot(); - ##$result .= ' ** Blocked for testing ** !'; + if (($result = $res) =~ s|^#OK#||) { + $res = 'OK'; + } else { + $c->stash(error => $result); + } + } ## end if (!$result) + } ## end if ($function eq 'workstn_restore1') - $res = 'NOK'; - if ( ! $result ) { - $res = $c->workstnRestore(); - if ( ($result = $res) =~ s|^#OK#|| ) { - $bac_datas{restore_log} = $result; - $res = 'OK'; - } else { - $c->stash( error => $result ); - } - $bac_datas{function} = 'workstn_restore1'; - $res = 'NEXT'; - } - } + if ($function eq 'workstn_sel_restore') { + my $backupset = $c->param('Backupset'); + my $filterexp = $c->param('Filterexp'); - - if ( $function eq 'workstn_restore1' ) { - - my $state = 'unknown'; - my $rec = $rdb->get('restore'); - if ($rec) { - $state = $rec->prop('state') || 'unknown'; - } - - $result .= "Restore state unexpected: $state" if ($state ne 'complete'); - - $res = 'NOK'; - if ( ! $result ) { - $res = $c->performReboot(); - if ( ($result = $res) =~ s|^#OK#|| ) { - $res = 'OK'; - } else { - $c->stash( error => $result ); - } - } - } - - - if ( $function eq 'workstn_sel_restore' ) { - - my $backupset = $c->param('Backupset'); - my $filterexp = $c->param('Filterexp'); if ($filterexp =~ /^(.*)$/) { $filterexp = $1; - } else { - $filterexp = ''; - } - - #$result .= ' ** Blocked for testing 1 ** !'; - - $res = ''; - if ( ! $result ) { - $bac_datas{function} = 'workstn_sel_restore1'; - $bac_datas{backupset} = $backupset; - $bac_datas{filterexp} = $filterexp; - $res = 'NEXT'; - } - } - - - if ( $function eq 'workstn_sel_restore1' ) { - - $bac_datas{backupset} = $c->param('Backupset'); - $bac_datas{filterexp} = $c->param('Filterexp'); - - my @restorefiles = @{$c->every_param('Restorefiles')}; - - my $seldatebefore = $c->param('Seldatebefore'); - if ($seldatebefore =~ /^(.*)$/) { - $seldatebefore = $1; } else { - $result .= 'Unsecure data : ' . $seldatebefore; + $filterexp = ''; } - my $tymd = - qr/((19|20)\d\d\/(?=\d\d\/\d\d-))?((0?[1-9]|1[0-2])\/(?=\d\d-))?((31|[123]0|[012]?[1-9])-)?/; - my $thms = - qr/([01]?[0-9]|2[0-3]):([0-5][0-9])(:[0-5][0-9])?/; + #$result .= ' ** Blocked for testing 1 ** !'; + $res = ''; - $result .= " $seldatebefore : " . $c->l('bac_ERR_INVALID_SELDATE') - unless (($seldatebefore =~ m/^$tymd$thms$/) || ($seldatebefore eq "")); + if (!$result) { + $bac_datas{function} = 'workstn_sel_restore1'; + $bac_datas{backupset} = $backupset; + $bac_datas{filterexp} = $filterexp; + $res = 'NEXT'; + } ## end if (!$result) + } ## end if ($function eq 'workstn_sel_restore') - ##$result .= ' ** Blocked for testing 2 ** !'; + if ($function eq 'workstn_sel_restore1') { + $bac_datas{backupset} = $c->param('Backupset'); + $bac_datas{filterexp} = $c->param('Filterexp'); + my @restorefiles = @{ $c->every_param('Restorefiles') }; + my $seldatebefore = $c->param('Seldatebefore'); - $res = ''; - if ( ! $result ) { - $res = $c->performWorkstnSelRestore( $seldatebefore, \@restorefiles ); # restore log returned - if ( ($result = $res) =~ s|^#OK#|| ) { - $bac_datas{restore_log} = $result; - $res = 'OK'; - } else { - $c->stash( error => $result ); - } - $bac_datas{function} = 'workstn_sel_restore2'; - $res = 'NEXT'; - } - } + if ($seldatebefore =~ /^(.*)$/) { + $seldatebefore = $1; + } else { + $result .= 'Unsecure data : ' . $seldatebefore; + } + my $tymd = qr/((19|20)\d\d\/(?=\d\d\/\d\d-))?((0?[1-9]|1[0-2])\/(?=\d\d-))?((31|[123]0|[012]?[1-9])-)?/; + my $thms = qr/([01]?[0-9]|2[0-3]):([0-5][0-9])(:[0-5][0-9])?/; + $result .= " $seldatebefore : " . $c->l('bac_ERR_INVALID_SELDATE') + unless (($seldatebefore =~ m/^$tymd$thms$/) || ($seldatebefore eq "")); + ##$result .= ' ** Blocked for testing 2 ** !'; + $res = ''; + if (!$result) { + $res = $c->performWorkstnSelRestore($seldatebefore, \@restorefiles); # restore log returned - if ( $function eq 'workstn_sel_restore2' ) { - - ##$result .= ' ** Blocked for testing 3 ** !'; - - $res = 'OK'; - $result = ''; - } + if (($result = $res) =~ s|^#OK#||) { + $bac_datas{restore_log} = $result; + $res = 'OK'; + } else { + $c->stash(error => $result); + } + $bac_datas{function} = 'workstn_sel_restore2'; + $res = 'NEXT'; + } ## end if (!$result) + } ## end if ($function eq 'workstn_sel_restore1') + if ($function eq 'workstn_sel_restore2') { + ##$result .= ' ** Blocked for testing 3 ** !'; + $res = 'OK'; + $result = ''; + } ## end if ($function eq 'workstn_sel_restore2') # common part for all functions if ($res ne 'OK') { - if ($res eq 'NEXT') { - $dest = 'back_' . $bac_datas{"function"}; - } else { - $c->stash( error => $result ); - $dest = "back_$function"; - } - $c->stash( title => $title, bac_datas => \%bac_datas ); - return $c->render($dest); - } - + if ($res eq 'NEXT') { + $dest = 'back_' . $bac_datas{"function"}; + } else { + $c->stash(error => $result); + $dest = "back_$function"; + } + $c->stash(title => $title, bac_datas => \%bac_datas); + return $c->render($dest); + } ## end if ($res ne 'OK') my $message = "'Backup' $function updates DONE"; $c->app->log->info($message); $c->flash(success => $result); - $c->redirect_to('backup'); - -}; - +} ## end sub do_update sub tapeBackupConfig { - - my ($c, $status, $backupHour, $backupMin, $bampm, - $reminderHour, $reminderMin, $rampm) = @_; + my ($c, $status, $backupHour, $backupMin, $bampm, $reminderHour, $reminderMin, $rampm) = @_; if (defined $status && $status eq "on") { + $backupMin = sprintf("%02d", $backupMin); - $backupMin = sprintf("%02d", $backupMin); + if ($bampm =~ /^(.*)$/) { + $bampm = $1; + } else { + $bampm = "AM"; + } - if ($bampm =~ /^(.*)$/) { - $bampm = $1; - } else { - $bampm = "AM"; - } - # convert to 24 hour time - $backupHour = $backupHour % 12; - if ($bampm eq "PM") { - $backupHour = $backupHour + 12; - } + # convert to 24 hour time + $backupHour = $backupHour % 12; - $reminderMin = sprintf("%02d", $reminderMin); + if ($bampm eq "PM") { + $backupHour = $backupHour + 12; + } + $reminderMin = sprintf("%02d", $reminderMin); - if ($rampm =~ /^(.*)$/) { - $rampm = $1; - } else { - $rampm = "AM"; - } - # convert to 24 hour time - $reminderHour = $reminderHour % 12; - if ($rampm eq "PM") { - $reminderHour = $reminderHour + 12; - } + if ($rampm =~ /^(.*)$/) { + $rampm = $1; + } else { + $rampm = "AM"; + } - # variables passed validity checks, set configuration database values - my $oldUnsav = $cdb->get('UnsavedChanges')->value; + # convert to 24 hour time + $reminderHour = $reminderHour % 12; - my $rec = $cdb->get('backup'); - unless (defined $rec) { - $rec = $cdb->new_record('backup', {type=>'service'}); - } + if ($rampm eq "PM") { + $reminderHour = $reminderHour + 12; + } - $rec->set_prop('status', 'enabled'); + # variables passed validity checks, set configuration database values + my $oldUnsav = $cdb->get('UnsavedChanges')->value; + my $rec = $cdb->get('backup'); - my $module = $rec->prop('Program'); + unless (defined $rec) { + $rec = $cdb->new_record('backup', { type => 'service' }); + } + $rec->set_prop('status', 'enabled'); + my $module = $rec->prop('Program'); - # The default e-smith backup program is flexbackup. - - unless (defined $module) { - $module = "flexbackup"; - } elsif ($module eq '') { - $module = "flexbackup"; - } - - $rec->set_prop('Program', $module); - $rec->set_prop('backupTime', "$backupHour:$backupMin"); - $rec->set_prop('reminderTime', "$reminderHour:$reminderMin"); - - $cdb->get('UnsavedChanges')->set_value($oldUnsav); - - system("/sbin/e-smith/signal-event", "conf-backup") == 0 - or return ($c->l('bac_ERR_CONF_BACKUP'),"\n"); - - return 'OK'; + # The default e-smith backup program is flexbackup. + unless (defined $module) { + $module = "flexbackup"; + } elsif ($module eq '') { + $module = "flexbackup"; + } + $rec->set_prop('Program', $module); + $rec->set_prop('backupTime', "$backupHour:$backupMin"); + $rec->set_prop('reminderTime', "$reminderHour:$reminderMin"); + $cdb->get('UnsavedChanges')->set_value($oldUnsav); + system("/sbin/e-smith/signal-event", "conf-backup") == 0 + or return ($c->l('bac_ERR_CONF_BACKUP'), "\n"); + return 'OK'; } else { - # set service to disabled - my $oldUnsav = $cdb->get('UnsavedChanges')->value; - my $rec = $cdb->get('backup'); - unless ($rec) { - $rec = $cdb->new_record('backup', {type=>'service'}); - } + # set service to disabled + my $oldUnsav = $cdb->get('UnsavedChanges')->value; + my $rec = $cdb->get('backup'); - $rec->set_prop('status', 'disabled'); - $cdb->get('UnsavedChanges')->set_value($oldUnsav); - - system("/sbin/e-smith/signal-event", "conf-backup") == 0 - or return ($c->l('bac_ERR_CONF_BACKUP')."\n"); - - return 'OK'; - } + unless ($rec) { + $rec = $cdb->new_record('backup', { type => 'service' }); + } + $rec->set_prop('status', 'disabled'); + $cdb->get('UnsavedChanges')->set_value($oldUnsav); + system("/sbin/e-smith/signal-event", "conf-backup") == 0 + or return ($c->l('bac_ERR_CONF_BACKUP') . "\n"); + return 'OK'; + } ## end else [ if (defined $status &&...)] return undef; -} - +} ## end sub tapeBackupConfig sub tapeRestore { - my ($c, $lock_file, $file_handle) = @_; - my $rec = $rdb->get('restore'); $rec->set_prop('state', 'running'); $rec->set_prop('start', time); - my $child; if ($child = fork) { - # Parent - $SIG{'CHLD'} = 'IGNORE'; - &esmith::lockfile::UnlockFile($file_handle); - return 'OK'; + + # Parent + $SIG{'CHLD'} = 'IGNORE'; + &esmith::lockfile::UnlockFile($file_handle); + return 'OK'; } elsif (defined $child) { - # Child - # Re-establish the lock. Wait till it is relinquished by the parent. - $file_handle = &esmith::lockfile::LockFileOrWait($lock_file); + # Child + # Re-establish the lock. Wait till it is relinquished by the parent. + $file_handle = &esmith::lockfile::LockFileOrWait($lock_file); - # Close STDOUT so that the web server connection is closed. - close STDOUT; + # Close STDOUT so that the web server connection is closed. + close STDOUT; - # Now reopen STDOUT for the child. Redirect it to STDERR. - open(STDOUT, ">&STDERR"); + # Now reopen STDOUT for the child. Redirect it to STDERR. + open(STDOUT, ">&STDERR"); - unless(system("/sbin/e-smith/signal-event", "pre-restore") == 0) { - $rec->set_prop('errmsg', $c->l('bac_ERR_PRE_RESTORE')); - $rec->delete_prop('state'); - die ($c->l('bac_ERR_PRE_RESTORE'),"\n"); - } + unless (system("/sbin/e-smith/signal-event", "pre-restore") == 0) { + $rec->set_prop('errmsg', $c->l('bac_ERR_PRE_RESTORE')); + $rec->delete_prop('state'); + die($c->l('bac_ERR_PRE_RESTORE'), "\n"); + } ## end unless (system("/sbin/e-smith/signal-event"...)) - unless(system("/sbin/e-smith/signal-event", "restore-tape") == 0) { - $rec->set_prop('errmsg', $c->l('bac_ERR_RESTORING_FROM_TAPE')); - $rec->delete_prop('state'); - die ($c->l('bac_ERR_RESTORING_FROM_TAPE')."\n"); - } + unless (system("/sbin/e-smith/signal-event", "restore-tape") == 0) { + $rec->set_prop('errmsg', $c->l('bac_ERR_RESTORING_FROM_TAPE')); + $rec->delete_prop('state'); + die($c->l('bac_ERR_RESTORING_FROM_TAPE') . "\n"); + } ## end unless (system("/sbin/e-smith/signal-event"...)) - #---------------------------------------- - # regenerate configuration files - #---------------------------------------- - unless(system("/usr/sbin/groupmod", "-g", "$www_gid", "www") == 0) { - $rec->set_prop('errmsg', $rec->prop('errmsg').', '. - $c->l('bac_ERR_RESTORING_GID')); - warn ($c->l('bac_ERR_RESTORING_GID')."\n"); - } - unless(system("/usr/sbin/usermod", "-g", "$www_gid", "www") == 0) { - $rec->set_prop('errmsg', $rec->prop('errmsg').', '. - $c->l('bac_ERR_RESTORING_INITIAL_GRP')); - warn ($c->l('bac_ERR_RESTORING_INITIAL_GRP')."\n"); - } - esmith::util::backgroundCommand(0, - "/sbin/e-smith/signal-event", "post-upgrade"); - #unless(system("/sbin/e-smith/signal-event", "post-upgrade") == 0) { - # $rec->set_prop('errmsg', $rec->prop('errmsg').', '. - # $c->l('bac_ERR_UPDATING_CONF_AFTER_TAPE_RESTORE')); - # $rec->delete_prop('state'); - # die ($c->l('bac_ERR_UPDATING_CONF_AFTER_TAPE_RESTORE')); - #} + #---------------------------------------- + # regenerate configuration files + #---------------------------------------- + unless (system("/usr/sbin/groupmod", "-g", "$www_gid", "www") == 0) { + $rec->set_prop('errmsg', $rec->prop('errmsg') . ', ' . $c->l('bac_ERR_RESTORING_GID')); + warn($c->l('bac_ERR_RESTORING_GID') . "\n"); + } - my $finish = time; - $rec->set_prop('state', 'complete'); - $rec->set_prop('finish', $finish); + unless (system("/usr/sbin/usermod", "-g", "$www_gid", "www") == 0) { + $rec->set_prop('errmsg', $rec->prop('errmsg') . ', ' . $c->l('bac_ERR_RESTORING_INITIAL_GRP')); + warn($c->l('bac_ERR_RESTORING_INITIAL_GRP') . "\n"); + } + esmith::util::backgroundCommand(0, "/sbin/e-smith/signal-event", "post-upgrade"); - my $start = $rec->prop('start'); - $start = scalar localtime($start); - $finish = scalar localtime($finish); - - &esmith::lockfile::UnlockFile($file_handle); - - exit; + #unless(system("/sbin/e-smith/signal-event", "post-upgrade") == 0) { + # $rec->set_prop('errmsg', $rec->prop('errmsg').', '. + # $c->l('bac_ERR_UPDATING_CONF_AFTER_TAPE_RESTORE')); + # $rec->delete_prop('state'); + # die ($c->l('bac_ERR_UPDATING_CONF_AFTER_TAPE_RESTORE')); + #} + my $finish = time; + $rec->set_prop('state', 'complete'); + $rec->set_prop('finish', $finish); + my $start = $rec->prop('start'); + $start = scalar localtime($start); + $finish = scalar localtime($finish); + &esmith::lockfile::UnlockFile($file_handle); + exit; } else { - # Error - $rec->delete_prop('state'); - $rec->set_prop('errmsg', $c->l('bac_COULD_NOT_FORK')); - die ($c->l("bac_COULD_NOT_FORK")." $!\n"); - } -} + # Error + $rec->delete_prop('state'); + $rec->set_prop('errmsg', $c->l('bac_COULD_NOT_FORK')); + die($c->l("bac_COULD_NOT_FORK") . " $!\n"); + } ## end else [ if ($child = fork) ] +} ## end sub tapeRestore sub workstnBackupConfig { # called by template my ($c) = @_; my $out; - my $backupwk_status; my $enabledIncOnlyTimeout = ""; - my $backupwkLogin = 'backup'; - my $backupwkPassword = 'backup'; - my $backupwkStation = 'host'; - my $backupwkFolder = 'share'; - my $backupwkMount = '/mnt/smb'; + my $backupwkLogin = 'backup'; + my $backupwkPassword = 'backup'; + my $backupwkStation = 'host'; + my $backupwkFolder = 'share'; + my $backupwkMount = '/mnt/smb'; my $setsNumber; my $filesinset; my $backupwkTime; @@ -790,692 +701,678 @@ sub workstnBackupConfig { # Obtain backup informations from configuration my $rec = $cdb->get('backupwk'); + if ($rec) { - $backupwkTime = $rec->prop('BackupTime') || '2:00'; - $backupwkLogin = $rec->prop('Login') || 'backup'; - $backupwkPassword = $rec->prop('Password') || 'backup'; - $backupwkStation = $rec->prop('SmbHost') || 'host'; - $backupwkFolder = $rec->prop('SmbShare') || 'share'; - $backupwkMount = $rec->prop('Mount') || '/mnt/smb'; - $VFSType = $rec->prop('VFSType') || 'cifs'; - $setsNumber = $rec->prop('SetsMax') || '1'; - $filesinset = $rec->prop('DaysInSet') || '1'; - $backupwkTimeout = $rec->prop('Timeout') || '12'; - $backupwkIncOnlyTimeout = $rec->prop('IncOnlyTimeout') || 'yes'; - $compression = $rec->prop('Compression') || '0'; - $dof = (defined $rec->prop('FullDay')) ? $rec->prop('FullDay') : '7'; - $backupwk_status = $rec->prop('status'); - } + $backupwkTime = $rec->prop('BackupTime') || '2:00'; + $backupwkLogin = $rec->prop('Login') || 'backup'; + $backupwkPassword = $rec->prop('Password') || 'backup'; + $backupwkStation = $rec->prop('SmbHost') || 'host'; + $backupwkFolder = $rec->prop('SmbShare') || 'share'; + $backupwkMount = $rec->prop('Mount') || '/mnt/smb'; + $VFSType = $rec->prop('VFSType') || 'cifs'; + $setsNumber = $rec->prop('SetsMax') || '1'; + $filesinset = $rec->prop('DaysInSet') || '1'; + $backupwkTimeout = $rec->prop('Timeout') || '12'; + $backupwkIncOnlyTimeout = $rec->prop('IncOnlyTimeout') || 'yes'; + $compression = $rec->prop('Compression') || '0'; + $dof = (defined $rec->prop('FullDay')) ? $rec->prop('FullDay') : '7'; + $backupwk_status = $rec->prop('status'); + } ## end if ($rec) if ($rec) { if ($VFSType eq 'usb') { - $out .= $c->l('bac_WORKSTN_BACKUP_USB').' '.$backupwkFolder.'
'; + $out .= $c->l('bac_WORKSTN_BACKUP_USB') . ' ' . $backupwkFolder . '
'; } elsif ($VFSType eq 'mnt') { - $out .= $c->l('bac_WORKSTN_BACKUP_MNT').' '.$backupwkMount.'
'; + $out .= $c->l('bac_WORKSTN_BACKUP_MNT') . ' ' . $backupwkMount . '
'; } else { - $out .= $c->l('bac_WORKSTN_BACKUP_HOST').' '.$backupwkStation.' '; - $out .= $c->l('bac_WORKSTN_BACKUP_VFSTYPE').' '.$VFSType.'
'; - $out .= $c->l('bac_WORKSTN_BACKUP_SHARE').' '.$backupwkFolder.'
'; + $out .= $c->l('bac_WORKSTN_BACKUP_HOST') . ' ' . $backupwkStation . ' '; + $out .= $c->l('bac_WORKSTN_BACKUP_VFSTYPE') . ' ' . $VFSType . '
'; + $out .= $c->l('bac_WORKSTN_BACKUP_SHARE') . ' ' . $backupwkFolder . '
'; } - if ($VFSType eq 'cifs') { - $out .= $c->l('bac_LOGIN').' '.$backupwkLogin.'
'; - $out .= $c->l('PASSWORD').' ********
'; - } - $out .= $c->l('bac_WORKSTN_BACKUP_SETSNUM').' '.$setsNumber.'
'; - $out .= $c->l('bac_WORKSTN_BACKUP_DAYSINSET').' '.$filesinset.'
'; - $out .= $c->l('bac_WORKSTN_BACKUP_COMPRESSION').' '.$compression.'
'; - $out .= $c->l('bac_WORKSTN_BACKUP_TOD').' '.$backupwkTime.'
'; - $out .= $c->l('bac_WORKSTN_BACKUP_TIMEOUT').' '.$backupwkTimeout.' '.$c->l('bac_HOURS'); - if ( $backupwkIncOnlyTimeout eq 'yes' ) { - $out .= $c->l('bac_WORKSTN_BACKUP_INCONLY_TIMEOUT') + if ($VFSType eq 'cifs') { + $out .= $c->l('bac_LOGIN') . ' ' . $backupwkLogin . '
'; + $out .= $c->l('PASSWORD') . ' ********
'; + } + $out .= $c->l('bac_WORKSTN_BACKUP_SETSNUM') . ' ' . $setsNumber . '
'; + $out .= $c->l('bac_WORKSTN_BACKUP_DAYSINSET') . ' ' . $filesinset . '
'; + $out .= $c->l('bac_WORKSTN_BACKUP_COMPRESSION') . ' ' . $compression . '
'; + $out .= $c->l('bac_WORKSTN_BACKUP_TOD') . ' ' . $backupwkTime . '
'; + $out .= $c->l('bac_WORKSTN_BACKUP_TIMEOUT') . ' ' . $backupwkTimeout . ' ' . $c->l('bac_HOURS'); + + if ($backupwkIncOnlyTimeout eq 'yes') { + $out .= $c->l('bac_WORKSTN_BACKUP_INCONLY_TIMEOUT'); } $out .= '
'; - if ( $dof eq '7' ) { - $out .= $c->l('bac_WORKSTN_FULL_BACKUP_EVERYDAY').'
'; + if ($dof eq '7') { + $out .= $c->l('bac_WORKSTN_FULL_BACKUP_EVERYDAY') . '
'; } else { - $out .= $c->l('bac_WORKSTN_FULL_BACKUP_DAY').' '.$dlabels[$dof].'
'; + $out .= $c->l('bac_WORKSTN_FULL_BACKUP_DAY') . ' ' . $dlabels[$dof] . '
'; } } else { - $out = $c->l('bac_WORKSTN_BACKUP_NOT_CONFIGURED'); + $out = $c->l('bac_WORKSTN_BACKUP_NOT_CONFIGURED'); } return $out; -} - +} ## end sub workstnBackupConfig sub workstnVerify { - my ($c) = @_; my $out; - my $backupwkrec = $cdb->get('backupwk'); - my $smbhost = $backupwkrec->prop('SmbHost'); - my $smbshare = $backupwkrec->prop('SmbShare'); - my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb'; + my $smbhost = $backupwkrec->prop('SmbHost'); + my $smbshare = $backupwkrec->prop('SmbShare'); + my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb'; my $key; my $error_message; - my $id = $backupwkrec->prop('Id') || - $cdb->get('SystemName')->value .'.'. $cdb->get('DomainName')->value; + my $id = $backupwkrec->prop('Id') + || $cdb->get('SystemName')->value . '.' . $cdb->get('DomainName')->value; my $err; my $VFSType = $backupwkrec->prop('VFSType') || 'cifs'; - my $verifyref = $c->param ('Backupset'); - $mntdir = "/$smbshare" if ( $VFSType eq 'usb' ); + my $verifyref = $c->param('Backupset'); + $mntdir = "/$smbshare" if ($VFSType eq 'usb'); # Mounting backup shared folder - $error_message = $c->bmount($mntdir,$smbhost,$smbshare,$VFSType); + $error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType); + if ($error_message) { - return $error_message .' '. $id; + return $error_message . ' ' . $id; } # Test if backup subdirectory for our server my $mntbkdir = $mntdir . "/$id"; - unless (-d $mntbkdir) { - $error_message = $c->l('bac_ERR_NO_HOST_DIR')."\n"; - $error_message .= $c->bunmount($mntdir,$VFSType); - return $error_message .' '. $id; - } + unless (-d $mntbkdir) { + $error_message = $c->l('bac_ERR_NO_HOST_DIR') . "\n"; + $error_message .= $c->bunmount($mntdir, $VFSType); + return $error_message . ' ' . $id; + } ## end unless (-d $mntbkdir) my $fullverify = $c->param('Verifyall') || ''; - if ( $fullverify eq "on" ) { - # Test all backups needed to full restore + if ($fullverify eq "on") { + + # Test all backups needed to full restore my %backupsetfiles = (); - my @restorefiles; + my @restorefiles; my $set = $verifyref; $set =~ s/\/[^\/]*$//; my $backupsetlist = sub { - if ( $_ =~ /\.dar/ ) { - my $backupref = $File::Find::name; - $backupref =~ s/\.[0-9]+\.dar//; - $_ =~ s/\..*\.dar//; - $_ =~ s/.*-//; - $backupsetfiles{$_} = $backupref; - } - }; - # find list of available backups and verify - # it contains all backups needed for full restore - find { wanted => \&$backupsetlist, untaint => 1, untaint_pattern => qr|^([-+@\w\s./]+)$| }, $set ; + if ($_ =~ /\.dar/) { + my $backupref = $File::Find::name; + $backupref =~ s/\.[0-9]+\.dar//; + $_ =~ s/\..*\.dar//; + $_ =~ s/.*-//; + $backupsetfiles{$_} = $backupref; + } ## end if ($_ =~ /\.dar/) + }; - my $key; - my $num = 0; - foreach $key (sort keys %backupsetfiles) - { - push @restorefiles, $backupsetfiles{$key}; - if ( $num == 0 ) { - unless ( $backupsetfiles{$key} =~ /\/full-/ ) { - $out .= $c->l('bac_ERR_NO_FULL_BACKUP'); - return $out; - } - } else { - my $numf = sprintf("%03d", $num); - unless ( $backupsetfiles{$key} =~ /\/inc-$numf-/ ) { - $out .= $c->l('bac_ERR_NO_INC_BACKUP') . " " . $numf; - return $out; - } - } - $num++; - last if ( $backupsetfiles{$key} eq $verifyref ); - } - - if (open(RD, "-|")) { + # find list of available backups and verify + # it contains all backups needed for full restore + find { wanted => \&$backupsetlist, untaint => 1, untaint_pattern => qr|^([-+@\w\s./]+)$| }, $set; + my $key; + my $num = 0; - $out .= ''.$c->l('bac_TESTING_NEEDED_BACKUPS_FOR_RESTORE').''; + foreach $key (sort keys %backupsetfiles) { + push @restorefiles, $backupsetfiles{$key}; - my $message; - $out .= ''; - if (!close RD) { - $out .= $c->l('bac_RESTORE_VERIFY_FAILED'); - } else { - $out .= $c->l('bac_VERIFY_COMPLETE'); - } - $out .= ''; - } else { - select(STDOUT); - $| = 1; + if ($num == 0) { + unless ($backupsetfiles{$key} =~ /\/full-/) { + $out .= $c->l('bac_ERR_NO_FULL_BACKUP'); + return $out; + } + } else { + my $numf = sprintf("%03d", $num); - my $file; - foreach $file (@restorefiles) { - if ($file =~ /^(.*)$/) { - $file = $1; - } else { - $error_message = "Unsecure data : $file\n"; - $error_message .= $c->bunmount($mntdir,$VFSType); - die ($error_message); - } - print $c->l('bac_TESTED_BACKUP') .' '. $file; - system ("/usr/bin/dar", "-Q", "--test", "$file", "--noconf"); - } + unless ($backupsetfiles{$key} =~ /\/inc-$numf-/) { + $out .= $c->l('bac_ERR_NO_INC_BACKUP') . " " . $numf; + return $out; + } + } ## end else [ if ($num == 0) ] + $num++; + last if ($backupsetfiles{$key} eq $verifyref); + } ## end foreach $key (sort keys %backupsetfiles) - $error_message = $c->bunmount($mntdir,$VFSType); - die($error_message) if $error_message; + if (open(RD, "-|")) { + $out .= '' . $c->l('bac_TESTING_NEEDED_BACKUPS_FOR_RESTORE') . ''; + my $message; + $out .= ''; + if (!close RD) { + $out .= $c->l('bac_RESTORE_VERIFY_FAILED'); + } else { + $out .= $c->l('bac_VERIFY_COMPLETE'); + } + $out .= ''; + } else { + select(STDOUT); + $| = 1; + my $file; + + foreach $file (@restorefiles) { + if ($file =~ /^(.*)$/) { + $file = $1; + } else { + $error_message = "Unsecure data : $file\n"; + $error_message .= $c->bunmount($mntdir, $VFSType); + die($error_message); + } + print $c->l('bac_TESTED_BACKUP') . ' ' . $file; + system("/usr/bin/dar", "-Q", "--test", "$file", "--noconf"); + } ## end foreach $file (@restorefiles) + $error_message = $c->bunmount($mntdir, $VFSType); + die($error_message) if $error_message; + exit(0); + } ## end else [ if (open(RD, "-|")) ] + + #return; } else { # verify selected backup only # and display files saved in the backup - my $backupkey = $verifyref; + if ($backupkey =~ /^(.*)$/) { $backupkey = $1; } else { - $error_message = "Unsecure data : $backupkey\n"; - $error_message .= $c->bunmount($mntdir,$VFSType); - die ($error_message); + $error_message = "Unsecure data : $backupkey\n"; + $error_message .= $c->bunmount($mntdir, $VFSType); + die($error_message); } - if (open(RD, "-|")) { - $out .= ''.$c->l('bac_FILES_IN_BACKUP').''; + if (open(RD, "-|")) { + $out .= '' . $c->l('bac_FILES_IN_BACKUP') . ''; + my $status + = close RD + ? ( + $complete + ? $c->l('bac_VERIFY_COMPLETE') + : $c->l('bac_BACKUP_FILE_INCOMPLETE') + ) + : ($c->l('bac_ERROR_READING_FILE') . ' : ' . $backupkey); + $out .= " $status "; } else { select(STDOUT); $| = 1; - - system ("/usr/bin/dar", "-Q", "--list", "$backupkey", "--noconf") == 0 - or die ($c->l('bac_ERR_EXTRACT')." : ".$!); - - $error_message = $c->bunmount($mntdir,$VFSType); + system("/usr/bin/dar", "-Q", "--list", "$backupkey", "--noconf") == 0 + or die($c->l('bac_ERR_EXTRACT') . " : " . $!); + $error_message = $c->bunmount($mntdir, $VFSType); die($error_message) if $error_message; exit(0); - } - } - $error_message .= $c->bunmount($mntdir,$VFSType); + } ## end else [ if (open(RD, "-|")) ] + } ## end else [ if ($fullverify eq "on")] + $error_message .= $c->bunmount($mntdir, $VFSType); return $out; -} - +} ## end sub workstnVerify sub workstnRestore { - my ($c) = @_; - my $out; my $restoreref = $c->param('Backupset'); - my $set = $restoreref; + my $set = $restoreref; $set =~ s/\/[^\/]*$//; my %backupsetfiles = (); my @restorefiles; - my $backupsetlist = sub { - if ( $_ =~ /\.dar/ ) { - my $backupref = $File::Find::name; + + if ($_ =~ /\.dar/) { + my $backupref = $File::Find::name; $backupref =~ s/\.[0-9]+\.dar//; $_ =~ s/\..*\.dar//; - $_ =~ s/.*-//; - $backupsetfiles{$_} = $backupref; - } + $_ =~ s/.*-//; + $backupsetfiles{$_} = $backupref; + } ## end if ($_ =~ /\.dar/) }; - - my $lock_file = "/var/lock/subsys/e-smith-restore"; + my $lock_file = "/var/lock/subsys/e-smith-restore"; my $file_handle = &esmith::lockfile::LockFileOrReturn($lock_file); unless ($file_handle) { return "$c->l('bac_RESTORE_CANNOT_PROCEED')
($c->l('bac_ANOTHER_RESTORE_IN_PROGRESS')"; } - my $backupwkrec = $cdb->get('backupwk'); - my $id = $backupwkrec->prop('Id') - || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; - my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb'; + my $id = $backupwkrec->prop('Id') + || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; + my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb'; my $VFSType = $backupwkrec->prop('VFSType') || 'cifs'; my $smbhost = $backupwkrec->prop('SmbHost'); my $smbshare = $backupwkrec->prop('SmbShare'); - $mntdir = "/$smbshare" if ( $VFSType eq 'usb' ); + $mntdir = "/$smbshare" if ($VFSType eq 'usb'); my $err; my $error_message; # Mounting backup shared folder - $error_message = $c->bmount($mntdir,$smbhost,$smbshare,$VFSType); + $error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType); + if ($error_message) { return "$c->l('bac_RESTORE_CANNOT_PROCEED') $error_message : $id"; } + # Test if backup subdirectory for our server my $mntbkdir = $mntdir . "/$id"; + unless (-d $mntbkdir) { - $error_message = $c->l('bac_ERR_NO_HOST_DIR')."\n"; - $error_message .= $c->bunmount($mntdir,$VFSType); + $error_message = $c->l('bac_ERR_NO_HOST_DIR') . "\n"; + $error_message .= $c->bunmount($mntdir, $VFSType); return "$c->l('bac_RESTORE_CANNOT_PROCEED') $error_message : $id"; - } - # finding list of available backups + } ## end unless (-d $mntbkdir) + + # finding list of available backups # and verifying all needed backup files are available - - find { wanted => \&$backupsetlist, untaint => 1, untaint_pattern => qr|^([-+@\w\s./]+)$| }, $set ; - + find { wanted => \&$backupsetlist, untaint => 1, untaint_pattern => qr|^([-+@\w\s./]+)$| }, $set; my $key; my $num = 0; - foreach $key (sort keys %backupsetfiles) { - push @restorefiles, $backupsetfiles{$key}; - if ( $num == 0 ) { - unless ( $backupsetfiles{$key} =~ /\/full-/ ) { - return "$c->l('bac_RESTORE_CANNOT_PROCEED') $c->l('bac_ERR_NO_FULL_BACKUP')"; - } - } else { - my $numf = sprintf("%03d", $num); - unless ( $backupsetfiles{$key} =~ /\/inc-$numf-/ ) { - return "$c->l('bac_RESTORE_CANNOT_PROCEED') $c->l('bac_ERR_NO_INC_BACKUP') . $numf"; - } - } - $num++; - last if ( $backupsetfiles{$key} eq $restoreref ); - } - # backup is online, restoring now + foreach $key (sort keys %backupsetfiles) { + push @restorefiles, $backupsetfiles{$key}; + + if ($num == 0) { + unless ($backupsetfiles{$key} =~ /\/full-/) { + return "$c->l('bac_RESTORE_CANNOT_PROCEED') $c->l('bac_ERR_NO_FULL_BACKUP')"; + } + } else { + my $numf = sprintf("%03d", $num); + + unless ($backupsetfiles{$key} =~ /\/inc-$numf-/) { + return "$c->l('bac_RESTORE_CANNOT_PROCEED') $c->l('bac_ERR_NO_INC_BACKUP') . $numf"; + } + } ## end else [ if ($num == 0) ] + $num++; + last if ($backupsetfiles{$key} eq $restoreref); + } ## end foreach $key (sort keys %backupsetfiles) + + # backup is online, restoring now my $rec = $rdb->get('restore'); - $rec->set_prop('state','running'); + $rec->set_prop('state', 'running'); $rec->set_prop('start', time); $cdb->get('bootstrap-console')->set_prop('Run', 'yes'); unless (system("/sbin/e-smith/signal-event", "pre-restore") == 0) { - return "$c->l('bac_OPERATION_STATUS_REPORT') $c->l('bac_ERR_PRE_RESTORE')"; + return "$c->l('bac_OPERATION_STATUS_REPORT') $c->l('bac_ERR_PRE_RESTORE')"; } - $| = 1; + if (open(RD, "-|")) { - #----------------------------------------------------- - # restore system from uploaded workstation backup file - #----------------------------------------------------- - $out .= $c->l('bac_FILES_HAVE_BEEN_RESTORED')."\n"; - $out .= ''; - my $message; + #----------------------------------------------------- + # restore system from uploaded workstation backup file + #----------------------------------------------------- + $out .= $c->l('bac_FILES_HAVE_BEEN_RESTORED') . "\n"; + $out .= ''; + my $message; - if ($complete) { - $out .= $c->l('bac_RESTORE_COMPLETE'); - system("/usr/sbin/groupmod", "-g", "$www_gid", "www") == 0 - or warn ($c->l('bac_ERR_RESTORING_GID')."\n"); - system("/usr/sbin/usermod", "-g", "$www_gid", "www") == 0 - or warn ($c->l('bac_ERR_RESTORING_INITIAL_GRP')."\n"); - esmith::util::backgroundCommand(0, - "/sbin/e-smith/signal-event", "post-upgrade"); - # system("/sbin/e-smith/signal-event", "post-upgrade") == 0 - # or die ($c->l('bac_ERROR_UPDATING_CONFIGURATION')."\n"); - } else { - $message = $c->l('bac_RESTORE_FAILED'); - } - } - return $message if $message; + if (!close RD) { + $message = $c->l('bac_RESTORE_FAILED_MSG'); + } else { - $rec->set_prop('state', 'complete'); - $rec->set_prop('finish', time); - - &esmith::lockfile::UnlockFile($file_handle); + #----------------------------------------------------- + # if restore completed, regenerate configuration files + #----------------------------------------------------- + if ($complete) { + $out .= $c->l('bac_RESTORE_COMPLETE'); + system("/usr/sbin/groupmod", "-g", "$www_gid", "www") == 0 + or warn($c->l('bac_ERR_RESTORING_GID') . "\n"); + system("/usr/sbin/usermod", "-g", "$www_gid", "www") == 0 + or warn($c->l('bac_ERR_RESTORING_INITIAL_GRP') . "\n"); + esmith::util::backgroundCommand(0, "/sbin/e-smith/signal-event", "post-upgrade"); + # system("/sbin/e-smith/signal-event", "post-upgrade") == 0 + # or die ($c->l('bac_ERROR_UPDATING_CONFIGURATION')."\n"); + } else { + $message = $c->l('bac_RESTORE_FAILED'); + } + } ## end else [ if (!close RD) ] + return $message if $message; + $rec->set_prop('state', 'complete'); + $rec->set_prop('finish', time); + &esmith::lockfile::UnlockFile($file_handle); } else { + select(STDOUT); + $| = 1; + my $file; - select(STDOUT); - $| = 1; - - my $file; - foreach $file (@restorefiles) { - if ($file =~ /^(.*)$/) { - $file = $1; - } else { - $error_message = "Unsecure data : $file\n"; - $error_message .= $c->bunmount($mntdir,$VFSType); - die ($error_message); - } - system ("/usr/bin/dar", "-Q", "-x", "$file", "-v", "-N", "-R", "/", "-wa"); - } - $error_message = $c->bunmount($mntdir,$VFSType); - die($error_message) if $error_message; - exit(0); - } - + foreach $file (@restorefiles) { + if ($file =~ /^(.*)$/) { + $file = $1; + } else { + $error_message = "Unsecure data : $file\n"; + $error_message .= $c->bunmount($mntdir, $VFSType); + die($error_message); + } + system("/usr/bin/dar", "-Q", "-x", "$file", "-v", "-N", "-R", "/", "-wa"); + } ## end foreach $file (@restorefiles) + $error_message = $c->bunmount($mntdir, $VFSType); + die($error_message) if $error_message; + exit(0); + } ## end else [ if (open(RD, "-|")) ] $rdb->reload; - - $error_message .= $c->bunmount($mntdir,$VFSType); + $error_message .= $c->bunmount($mntdir, $VFSType); return '#OK#' . $out; -} - +} ## end sub workstnRestore sub workstnSelRestore() { - - my $c = shift; - - my $rec = $cdb->get('backupwk'); - + my $c = shift; + my $rec = $cdb->get('backupwk'); my %backupfiles = (); - my $mntdir = $rec->prop('Mount') || '/mnt/smb'; + my $mntdir = $rec->prop('Mount') || '/mnt/smb'; my $mntbkdir; my $key; - my $id = $rec->prop('Id') || - $cdb->get('SystemName')->value . '.' . $cdb->get('DomainName')->value; + my $id = $rec->prop('Id') + || $cdb->get('SystemName')->value . '.' . $cdb->get('DomainName')->value; my %blabels = (); my @blabels; my $backups = 0; my $filterexp; - my $VFSType = $rec->prop('VFSType') || 'cifs'; - my $smbhost = $rec->prop('SmbHost'); + my $VFSType = $rec->prop('VFSType') || 'cifs'; + my $smbhost = $rec->prop('SmbHost'); my $smbshare = $rec->prop('SmbShare'); - $mntdir = "/$smbshare" if ( $VFSType eq 'usb' ); + $mntdir = "/$smbshare" if ($VFSType eq 'usb'); my $err; my $error_message; - my $setbackuplist = sub { - if ( $_ =~ /\.dar/ ) - { - my $dir = $File::Find::dir; - my $backupref; - $dir =~ s/$mntbkdir\///; + + if ($_ =~ /\.dar/) { + my $dir = $File::Find::dir; + my $backupref; + $dir =~ s/$mntbkdir\///; $_ =~ s/\..*\.dar//; - $backupref = $_; - $_ =~ s/.*-//; - @{$backupfiles{$_}}[0] = $dir; - @{$backupfiles{$_}}[1] = $backupref; - } + $backupref = $_; + $_ =~ s/.*-//; + @{ $backupfiles{$_} }[0] = $dir; + @{ $backupfiles{$_} }[1] = $backupref; + } ## end if ($_ =~ /\.dar/) }; # Mounting backup shared folder - $error_message = $c->bmount($mntdir,$smbhost,$smbshare,$VFSType); + $error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType); + if ($error_message) { return ($error_message, $id); } # Test if backup subdirectory for our server $mntbkdir = $mntdir . "/$id"; - unless (-d $mntbkdir) { - $error_message = $c->l('bac_ERR_NO_HOST_DIR')."\n"; - $error_message .= $c->bunmount($mntdir,$VFSType); - return ($error_message, $id); - } + unless (-d $mntbkdir) { + $error_message = $c->l('bac_ERR_NO_HOST_DIR') . "\n"; + $error_message .= $c->bunmount($mntdir, $VFSType); + return ($error_message, $id); + } ## end unless (-d $mntbkdir) my $catalog = "$mntbkdir/dar-catalog"; - my $i = 0; - my $j = 0; + my $i = 0; + my $j = 0; my @bknum; my @setd; my @bkname; - - # update backups list from current catalog - - open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |") ; - + # update backups list from current catalog + open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |"); $i = 0; - while () - { - next unless m/set/; - chomp; - ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); - $i++; - } - close (DAR_LIST); + + while () { + next unless m/set/; + chomp; + ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); + $i++; + } ## end while () + close(DAR_LIST); # set drop down list of backups push @blabels, "0"; $blabels{"0"} = $c->l('ALL_BACKUPS'); $j = 0; - while ($j < $i) - { - push @blabels, $bknum[$j]; - $blabels{$bknum[$j]} = $bkname[$j]; - $j++ - } - -} + while ($j < $i) { + push @blabels, $bknum[$j]; + $blabels{ $bknum[$j] } = $bkname[$j]; + $j++; + } ## end while ($j < $i) +} ## end sub workstnSelRestore sub updateWorkstnBackupConfig { - my ($c) = @_; - - my $status = $c->param('Workstnbackup') || ""; + my $status = $c->param('Workstnbackup') || ""; my $inconly = $c->param('IncOnlyTimeout'); - my $dof = $c->param('Dof'); + my $dof = $c->param('Dof'); my $ampm; my $incOnlyTimeout; - my $rec = $cdb->get('backupwk'); + unless (defined $rec) { - $rec = $cdb->new_record('backupwk', {type=>'service'}); + $rec = $cdb->new_record('backupwk', { type => 'service' }); } my $backupwkMount = $rec->prop('Mount') || '/mnt/smb'; - unless ( $status eq 'on') { + unless ($status eq 'on') { + # set service to disabled my $old = $cdb->get('UnsavedChanges')->value; - $rec->set_prop('status', 'disabled'); $cdb->get('UnsavedChanges')->set_value($old); - system("/sbin/e-smith/signal-event", "conf-backup") == 0 - or die($c->l('bac_ERR_CONF_BACKUP')."\n"); - - return '#OK#'.$c->l('bac_SUCCESSFULLY_DISABLED_WORKSTN'); - } - - #-------------------------------------------------- - # Untaint parameters and check for validity - #-------------------------------------------------- + or die($c->l('bac_ERR_CONF_BACKUP') . "\n"); + return '#OK#' . $c->l('bac_SUCCESSFULLY_DISABLED_WORKSTN'); + } ## end unless ($status eq 'on') + #-------------------------------------------------- + # Untaint parameters and check for validity + #-------------------------------------------------- my $VFSType = $c->param('VFSType'); - if ( $VFSType eq 'nousb') { - return $c->l('bac_ERR_NO_USB_DISK') - } - if ( $VFSType eq 'nomnt') { - return $c->l('bac_ERR_NO_MOUNTED_DISK') + + if ($VFSType eq 'nousb') { + return $c->l('bac_ERR_NO_USB_DISK'); } + if ($VFSType eq 'nomnt') { + return $c->l('bac_ERR_NO_MOUNTED_DISK'); + } my $backupwkStation = $c->param('BackupwkStation'); - if ( $VFSType =~ m/usb|mnt/s) { $backupwkStation = 'localhost' } + if ($VFSType =~ m/usb|mnt/s) { $backupwkStation = 'localhost' } + if ($backupwkStation =~ /^\s*(\S+)\s*$/) { - $backupwkStation = $1; + $backupwkStation = $1; } else { $backupwkStation = ""; } - if ( $backupwkStation eq "" ) { - return $c->l('bac_ERR_INVALID_WORKSTN') - } + if ($backupwkStation eq "") { + return $c->l('bac_ERR_INVALID_WORKSTN'); + } my $backupwkFolder = $c->param('BackupwkFolder'); + if ($backupwkFolder =~ /^(.*)$/) { $backupwkFolder = $1; } else { $backupwkFolder = ''; } - if ( $VFSType eq 'usb' ) { + + if ($VFSType eq 'usb') { $backupwkFolder = 'media/' . $backupwkFolder; } - if ( $VFSType eq 'mnt' ) { - $backupwkMount = $backupwkFolder; - if (checkMount ($backupwkMount)){$backupwkFolder = '';} + + if ($VFSType eq 'mnt') { + $backupwkMount = $backupwkFolder; + if (checkMount($backupwkMount)) { $backupwkFolder = ''; } } else { - $backupwkFolder =~ s/^\///; # remove leading / - } - if ( $backupwkFolder eq '') { - return $c->l('bac_ERR_INVALID_FOLDER') + $backupwkFolder =~ s/^\///; # remove leading / } + if ($backupwkFolder eq '') { + return $c->l('bac_ERR_INVALID_FOLDER'); + } my $backupwkLogin = $c->param('BackupwkLogin') || ''; + if ($backupwkLogin =~ /^(.*)$/) { $backupwkLogin = $1; } else { $backupwkLogin = ""; } - if ( ( $backupwkLogin eq "" ) && ( $VFSType eq 'cifs' ) ) { - return $c->l('bac_ERR_INVALID_LOGIN') - } + if (($backupwkLogin eq "") && ($VFSType eq 'cifs')) { + return $c->l('bac_ERR_INVALID_LOGIN'); + } my $backupwkPassword = $c->param('BackupwkPassword') || ''; + if ($backupwkPassword =~ /^(.*)$/) { $backupwkPassword = $1; } else { $backupwkPassword = ""; } - if ( ( $backupwkPassword eq "" ) && ( $VFSType eq 'cifs' ) ) { - return $c->l('bac_ERR_INVALID_PASSWORD') - } + if (($backupwkPassword eq "") && ($VFSType eq 'cifs')) { + return $c->l('bac_ERR_INVALID_PASSWORD'); + } my $setsNumber = $c->param('SetsNumber'); - unless ( $setsNumber > 0 ) { - return $c->l('bac_ERR_INVALID_SETS_NUMBERFOLDER') - } + unless ($setsNumber > 0) { + return $c->l('bac_ERR_INVALID_SETS_NUMBERFOLDER'); + } my $filesinset = $c->param('Filesinset'); - unless ( $filesinset > 0 ) { - return $c->l('bac_ERR_INVALID_FILES_IN_SET_NUMBER') - } + unless ($filesinset > 0) { + return $c->l('bac_ERR_INVALID_FILES_IN_SET_NUMBER'); + } my $timeout = $c->param('BackupwkTimeout'); - if (( $timeout eq '') || ( $timeout == 0 )) {$timeout = 24 } - if (( $timeout < 1 ) || ( $timeout > 24 )) { - return $c->l('bac_ERR_INVALID_TIMEOUT') + if (($timeout eq '') || ($timeout == 0)) { $timeout = 24 } + + if (($timeout < 1) || ($timeout > 24)) { + return $c->l('bac_ERR_INVALID_TIMEOUT'); } if (defined $inconly && $inconly eq 'on') { - $incOnlyTimeout = 'yes'; + $incOnlyTimeout = 'yes'; } else { - $incOnlyTimeout = 'no'; + $incOnlyTimeout = 'no'; } - my $compression = $c->param('Compression'); - if (( $compression < 0 ) || ( $compression > 9 )) { - return $c->l('bac_ERR_INVALID_COMPRESSION') - } - $rec->set_prop('SmbHost', $backupwkStation); - $rec->set_prop('SmbShare', $backupwkFolder); - $rec->set_prop('Mount', $backupwkMount); - $rec->set_prop('Login', $backupwkLogin); - $rec->set_prop('Password', $backupwkPassword); - $rec->set_prop('SetsMax', $setsNumber); - $rec->set_prop('DaysInSet', $filesinset); - $rec->set_prop('Timeout', $timeout); + if (($compression < 0) || ($compression > 9)) { + return $c->l('bac_ERR_INVALID_COMPRESSION'); + } + $rec->set_prop('SmbHost', $backupwkStation); + $rec->set_prop('SmbShare', $backupwkFolder); + $rec->set_prop('Mount', $backupwkMount); + $rec->set_prop('Login', $backupwkLogin); + $rec->set_prop('Password', $backupwkPassword); + $rec->set_prop('SetsMax', $setsNumber); + $rec->set_prop('DaysInSet', $filesinset); + $rec->set_prop('Timeout', $timeout); $rec->set_prop('IncOnlyTimeout', $incOnlyTimeout); - $rec->set_prop('Compression', $compression); - $rec->set_prop('FullDay', $dof); - $rec->set_prop('VFSType', $VFSType); - + $rec->set_prop('Compression', $compression); + $rec->set_prop('FullDay', $dof); + $rec->set_prop('VFSType', $VFSType); my $module = $rec->prop('Program'); # The default workstation backup program is dar. - unless (defined $module) { $module = 'dar'; } elsif ($module eq '') { $module = 'dar'; } - $rec->set_prop('Program', $module); + my $backupwkHour = $c->param('BackupwkHour'); - my $backupwkHour = $c->param('BackupwkHour'); - if ($backupwkHour =~ /^(.*)$/) { - $backupwkHour = $1; - } else { - $backupwkHour = '12'; - } - if (($backupwkHour < 0) || ($backupwkHour > 12)) { - return $c->l('bac_ERR_INVALID_HOUR').$backupwkHour. - $c->l('bac_BETWEEN_0_AND_12') - } - - my $backupwkMin = $c->param('BackupwkMin'); - if ($backupwkMin =~ /^(.*)$/) { - $backupwkMin = $1; - } else { - $backupwkMin = '0'; - } - if (($backupwkMin < 0) || ($backupwkMin > 59)) { - return $c->l('bac_ERR_INVALID_MINUTE').$backupwkMin. - $c->l('bac_BETWEEN_0_AND_59'); - } - - $backupwkMin = sprintf("%02d", $backupwkMin); - - $ampm = $c->param('BackupwkAMPM'); - if ($ampm =~ /^(.*)$/) { - $ampm = $1; - } else { - $ampm = 'AM'; - } - - # convert to 24 hour time - $backupwkHour = $backupwkHour % 12; - if ($ampm eq 'PM') { - $backupwkHour = $backupwkHour + 12; - } - - # variables passed validity checks, set configuration database values - my $old = $cdb->get('UnsavedChanges')->value; - $rec->set_prop('status', 'enabled'); - $rec->set_prop('BackupTime', "$backupwkHour:$backupwkMin"); - $cdb->get('UnsavedChanges')->set_value($old); - - system("/sbin/e-smith/signal-event", "conf-backup") == 0 - or die($c->l('bac_ERR_CONF_BACKUP'),"\n"); - - # we test if the remote host is reachable, else we simply display a warning - if ( $VFSType =~ m/cifs|nfs/s ) { - my $error_message = vmount($backupwkStation,$backupwkFolder,$backupwkMount,$VFSType); - if (! $error_message) { - $c->bunmount($backupwkMount,$VFSType); - } elsif ($error_message) { - return $c->l('bac_ERROR_WHEN_TESTING_REMOTE_SERVER'). "
$error_message"; - } + if ($backupwkHour =~ /^(.*)$/) { + $backupwkHour = $1; + } else { + $backupwkHour = '12'; } - return '#OK#'.$c->l('bac_SUCCESSFULLY_ENABLED_WORKSTN'). '
'. - $c->l('bac_WITH_BACKUP_TIME')." $backupwkHour:$backupwkMin"; -} + if (($backupwkHour < 0) || ($backupwkHour > 12)) { + return $c->l('bac_ERR_INVALID_HOUR') . $backupwkHour . $c->l('bac_BETWEEN_0_AND_12'); + } + my $backupwkMin = $c->param('BackupwkMin'); + if ($backupwkMin =~ /^(.*)$/) { + $backupwkMin = $1; + } else { + $backupwkMin = '0'; + } + + if (($backupwkMin < 0) || ($backupwkMin > 59)) { + return $c->l('bac_ERR_INVALID_MINUTE') . $backupwkMin . $c->l('bac_BETWEEN_0_AND_59'); + } + $backupwkMin = sprintf("%02d", $backupwkMin); + $ampm = $c->param('BackupwkAMPM'); + + if ($ampm =~ /^(.*)$/) { + $ampm = $1; + } else { + $ampm = 'AM'; + } + + # convert to 24 hour time + $backupwkHour = $backupwkHour % 12; + + if ($ampm eq 'PM') { + $backupwkHour = $backupwkHour + 12; + } + + # variables passed validity checks, set configuration database values + my $old = $cdb->get('UnsavedChanges')->value; + $rec->set_prop('status', 'enabled'); + $rec->set_prop('BackupTime', "$backupwkHour:$backupwkMin"); + $cdb->get('UnsavedChanges')->set_value($old); + system("/sbin/e-smith/signal-event", "conf-backup") == 0 + or die($c->l('bac_ERR_CONF_BACKUP'), "\n"); + + # we test if the remote host is reachable, else we simply display a warning + if ($VFSType =~ m/cifs|nfs/s) { + my $error_message = vmount($backupwkStation, $backupwkFolder, $backupwkMount, $VFSType); + + if (!$error_message) { + $c->bunmount($backupwkMount, $VFSType); + } elsif ($error_message) { + return $c->l('bac_ERROR_WHEN_TESTING_REMOTE_SERVER') . "
$error_message"; + } + } ## end if ($VFSType =~ m/cifs|nfs/s) + return + '#OK#' + . $c->l('bac_SUCCESSFULLY_ENABLED_WORKSTN') . '
' + . $c->l('bac_WITH_BACKUP_TIME') + . " $backupwkHour:$backupwkMin"; +} ## end sub updateWorkstnBackupConfig sub performWorkstnSelRestore { - my ($c, $seldatebefore, $restorefiles) = @_; - my $out; my @restorelist; - foreach ( @{$restorefiles} ) { - push @restorelist, "\"".$1."\"" if ($_ =~ /^(.*)$/); + foreach (@{$restorefiles}) { + push @restorelist, "\"" . $1 . "\"" if ($_ =~ /^(.*)$/); } - my $backupwkrec = $cdb->get('backupwk'); - my $id = $backupwkrec->prop('Id') || - $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; - my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb'; + my $id = $backupwkrec->prop('Id') + || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; + my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb'; my $VFSType = $backupwkrec->prop('VFSType') || 'cifs'; my $smbhost = $backupwkrec->prop('SmbHost'); my $smbshare = $backupwkrec->prop('SmbShare'); my $err; my $error_message; - $mntdir = "/$smbshare" if ( $VFSType eq 'usb' ); + $mntdir = "/$smbshare" if ($VFSType eq 'usb'); # Mounting backup shared folder - $error_message = $c->bmount($mntdir,$smbhost,$smbshare,$VFSType); + $error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType); + if ($error_message) { $error_message .= " : $id"; return $error_message; @@ -1483,335 +1380,322 @@ sub performWorkstnSelRestore { # Test if backup subdirectory for our server my $mntbkdir = $mntdir . "/$id"; + unless (-d $mntbkdir) { - $error_message = $c->l('bac_ERR_NO_HOST_DIR')."\n"; - $error_message .= $c->bunmount($mntdir,$VFSType); + $error_message = $c->l('bac_ERR_NO_HOST_DIR') . "\n"; + $error_message .= $c->bunmount($mntdir, $VFSType); $error_message .= " : $id"; return $error_message; - } + } ## end unless (-d $mntbkdir) # backup is online, restoring now $| = 1; my $restorerr; if (open(RD, "-|")) { - #----------------------------------------------------- - # restore system from uploaded workstation backup file - #----------------------------------------------------- - $out .= "". $c->l('bac_FILES_HAVE_BEEN_RESTORED') ." \n"; - $out .= '
    '; - while () { - $out .= "
  • $_
  • \n"; - } - $out .= '
'; - my $message; - if (!close RD) { - $message = $c->l('bac_RESTORE_FAILED_MSG'); - } else { - if ($restorerr) { - $message = $c->l('bac_RESTORE_FAILED'); - } else { - $message = $c->l('bac_RESTORE_COMPLETE'); - } - } - $out .= "$message \n"; - } else { - select(STDOUT); - $| = 1; - if ($seldatebefore) { - $restorerr = system("/usr/bin/dar_manager -B \"$mntbkdir/dar-catalog\" -Q -w $seldatebefore -e '-v -N -R / -w' -r @restorelist"); - } else { - $restorerr = system("/usr/bin/dar_manager -B \"$mntbkdir/dar-catalog\" -Q -k -e '-v -N -R / -w' -r @restorelist"); - } - $error_message = $c->bunmount($mntdir,$VFSType); - die($error_message) if $error_message; - exit(0); - } - return "#OK#" . $out; -} + #----------------------------------------------------- + # restore system from uploaded workstation backup file + #----------------------------------------------------- + $out .= "" . $c->l('bac_FILES_HAVE_BEEN_RESTORED') . " \n"; + $out .= '
    '; + + while () { + $out .= "
  • $_
  • \n"; + } + $out .= '
'; + my $message; + + if (!close RD) { + $message = $c->l('bac_RESTORE_FAILED_MSG'); + } else { + + if ($restorerr) { + $message = $c->l('bac_RESTORE_FAILED'); + } else { + $message = $c->l('bac_RESTORE_COMPLETE'); + } + } ## end else [ if (!close RD) ] + $out .= "$message \n"; + } else { + select(STDOUT); + $| = 1; + + if ($seldatebefore) { + $restorerr + = system( + "/usr/bin/dar_manager -B \"$mntbkdir/dar-catalog\" -Q -w $seldatebefore -e '-v -N -R / -w' -r @restorelist" + ); + } else { + $restorerr + = system("/usr/bin/dar_manager -B \"$mntbkdir/dar-catalog\" -Q -k -e '-v -N -R / -w' -r @restorelist"); + } + $error_message = $c->bunmount($mntdir, $VFSType); + die($error_message) if $error_message; + exit(0); + } ## end else [ if (open(RD, "-|")) ] + return "#OK#" . $out; +} ## end sub performWorkstnSelRestore sub performReboot { - my ($c) = @_; #print "$c->l('bac_SERVER_REBOOT')"; #print "$c->l('bac_SERVER_WILL_REBOOT')"; - - esmith::util::backgroundCommand( 2, "/sbin/e-smith/signal-event", "reboot" ); + esmith::util::backgroundCommand(2, "/sbin/e-smith/signal-event", "reboot"); return "#OK#" . $c->l('bac_SERVER_WILL_REBOOT'); -} - +} ## end sub performReboot sub get_VFSType_options { - my $c = shift; - return [[ $c->l('cifs') => 'cifs' ], [ $c->l('nfs') => 'nfs' ], - [ $c->l('local removable disk') => 'usb' ], [ $c->l('Mounted disk') => 'mnt' ]]; -} - + return [ + [ $c->l('cifs') => 'cifs' ], + [ $c->l('nfs') => 'nfs' ], + [ $c->l('local removable disk') => 'usb' ], + [ $c->l('Mounted disk') => 'mnt' ] + ]; +} ## end sub get_VFSType_options sub get_dow_list { - - my $c = shift; - - my @list = (); + my $c = shift; + my @list = (); my @dlabels = split(' ', $c->l('bac_DOW')); + my $i = 0; - my $i = 0; foreach (@dlabels) { - push @list, [ "$_" => "$i" ]; - $i++; + push @list, [ "$_" => "$i" ]; + $i++; } -# put 'everyday' first + # put 'everyday' first my $lastr = pop @list; unshift @list, $lastr; - return \@list; -} - +} ## end sub get_dow_list sub get_BackupwkDest_options { - my ($c, $VFSType) = @_; my @usbdisks = (); - if ( $VFSType eq 'usb' ) { - my $devices = esmith::BlockDevices->new ('allowmount' => 'disabled'); + if ($VFSType eq 'usb') { + my $devices = esmith::BlockDevices->new('allowmount' => 'disabled'); my ($valid, $invalid) = $devices->checkBackupDrives(0); - if ( ${$valid}[0] ) { - foreach ( @{$valid} ) { + if (${$valid}[0]) { + foreach (@{$valid}) { push @usbdisks, $devices->label($_); } + } ## end if (${$valid}[0]) + + if (!$usbdisks[0]) { + push(@usbdisks, $c->l('bac_No suitable local devices found')); } - - if (!$usbdisks[0]){ - push (@usbdisks,$c->l('bac_No suitable local devices found')); - } $devices->destroy; - #foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { - #$udi =~ m/^(\S+)/; - - #my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); - - #if ($is_mounted eq "false\n") { - #my $vollbl = qx(hal-get-property --udi $1 --key volume.label); - #$vollbl =~ m/^(\S+)/; - #if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} - #chomp $vollbl; - #push @usbdisks, $vollbl; - #} + #foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { + #$udi =~ m/^(\S+)/; + #my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); + #if ($is_mounted eq "false\n") { + #my $vollbl = qx(hal-get-property --udi $1 --key volume.label); + #$vollbl =~ m/^(\S+)/; + #if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} + #chomp $vollbl; + #push @usbdisks, $vollbl; #} - # return undef unless ($usbdisks[0]); - } + #} + # return undef unless ($usbdisks[0]); + } ## end if ($VFSType eq 'usb') - if ( $VFSType eq 'mnt' ) { - @usbdisks = findmnt (); - # return undef unless ($usbdisks[0]); - } - return \@usbdisks -} + if ($VFSType eq 'mnt') { + @usbdisks = findmnt(); + # return undef unless ($usbdisks[0]); + } ## end if ($VFSType eq 'mnt') + return \@usbdisks; +} ## end sub get_BackupwkDest_options sub get_function_options { - my $c = shift; - - return [[ $c->l('bac_DESKTOP_BACKUP') => 'desktop_backup' ], - [ $c->l('bac_TAPE_CONFIGURE') => 'tape_configure' ], - [ $c->l('bac_TAPE_RESTORE') => 'tape_restore' ], - [ $c->l('bac_WORKSTN_CONFIGURE') => 'workstn_configure' ], - [ $c->l('bac_WORKSTN_VERIFY') => 'workstn_verify' ], - [ $c->l('bac_WORKSTN_RESTORE') => 'workstn_restore' ], - [ $c->l('bac_WORKSTN_SEL_RESTORE') => 'workstn_sel_restore']]; - -} - + return [ + [ $c->l('bac_DESKTOP_BACKUP') => 'desktop_backup' ], + [ $c->l('bac_TAPE_CONFIGURE') => 'tape_configure' ], + [ $c->l('bac_TAPE_RESTORE') => 'tape_restore' ], + [ $c->l('bac_WORKSTN_CONFIGURE') => 'workstn_configure' ], + [ $c->l('bac_WORKSTN_VERIFY') => 'workstn_verify' ], + [ $c->l('bac_WORKSTN_RESTORE') => 'workstn_restore' ], + [ $c->l('bac_WORKSTN_SEL_RESTORE') => 'workstn_sel_restore' ] + ]; +} ## end sub get_function_options sub get_shared_folder_to_verify () { - my ($c) = @_; - my $rec = $cdb->get('backupwk'); return undef unless $rec; - - my $id = $rec->prop('Id') || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; - my $smbhost = $rec->prop('SmbHost'); + my $id = $rec->prop('Id') || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; + my $smbhost = $rec->prop('SmbHost'); my $smbshare = $rec->prop('SmbShare'); - return "$smbhost/$smbshare/$id"; -} - +} ## end sub get_shared_folder_to_verify sub get_Backupset_options () { - my ($c) = @_; - my $rec = $cdb->get('backupwk'); return undef unless $rec; - my %backupfiles = (); - my $mntdir = $rec->prop('Mount') || '/mnt/smb'; - my $id = $rec->prop('Id') || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; - my $smbhost = $rec->prop('SmbHost'); - my $smbshare = $rec->prop('SmbShare'); + my $mntdir = $rec->prop('Mount') || '/mnt/smb'; + my $id = $rec->prop('Id') || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; + my $smbhost = $rec->prop('SmbHost'); + my $smbshare = $rec->prop('SmbShare'); my $mntbkdir; my $key; my $VFSType = $rec->prop('VFSType') || 'cifs'; my $err; - $mntdir = "/$smbshare" if ( $VFSType eq 'usb' ); - + $mntdir = "/$smbshare" if ($VFSType eq 'usb'); my $setbackuplist = sub { - if ( $_ =~ /\.dar/ ) { - my $dir = $File::Find::dir; - my $backupref; - $dir =~ s/$mntbkdir\///; + + if ($_ =~ /\.dar/) { + my $dir = $File::Find::dir; + my $backupref; + $dir =~ s/$mntbkdir\///; $_ =~ s/\..*\.dar//; - $backupref = $_; - $_ =~ s/.*-//; - @{$backupfiles{$_}}[0] = $dir; - @{$backupfiles{$_}}[1] = $backupref; - } + $backupref = $_; + $_ =~ s/.*-//; + @{ $backupfiles{$_} }[0] = $dir; + @{ $backupfiles{$_} }[1] = $backupref; + } ## end if ($_ =~ /\.dar/) }; - # Mounting backup shared folder - my $error_message = $c->bmount($mntdir,$smbhost,$smbshare,$VFSType); + my $error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType); return [] if $error_message; # Test if backup subdirectory for our server $mntbkdir = $mntdir . "/$id"; + unless (-d $mntbkdir) { - $error_message .= $c->bunmount($mntdir,$VFSType); + $error_message .= $c->bunmount($mntdir, $VFSType); return []; } # Finding existing backups - find { wanted => \&$setbackuplist, untaint => 1, untaint_pattern => qr|^([-+@\w\s./]+)$|}, $mntbkdir ; - + find { wanted => \&$setbackuplist, untaint => 1, untaint_pattern => qr|^([-+@\w\s./]+)$| }, $mntbkdir; my %blabels = (); my @list; foreach $key (sort keys %backupfiles) { - my $labkey = $mntbkdir . '/' . $backupfiles{$key}[0] . '/' . $backupfiles{$key}[1]; - $blabels{$labkey} = $backupfiles{$key}[1] . " (" . $backupfiles{$key}[0] . ")"; - push @list, [ "$blabels{$labkey}" => "$labkey" ]; - } - - $error_message .= $c->bunmount($mntdir,$VFSType); + my $labkey = $mntbkdir . '/' . $backupfiles{$key}[0] . '/' . $backupfiles{$key}[1]; + $blabels{$labkey} = $backupfiles{$key}[1] . " (" . $backupfiles{$key}[0] . ")"; + push @list, [ "$blabels{$labkey}" => "$labkey" ]; + } ## end foreach $key (sort keys %backupfiles) + $error_message .= $c->bunmount($mntdir, $VFSType); return \@list; -} - +} ## end sub get_Backupset_options sub get_Restoreset_options () { - my ($c) = @_; - my $rec = $cdb->get('backupwk'); return [] unless $rec; - my %backupfiles = (); - my $mntdir = $rec->prop('Mount') || '/mnt/smb'; - my $id = $rec->prop('Id') || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; - my $smbhost = $rec->prop('SmbHost'); - my $smbshare = $rec->prop('SmbShare'); + my $mntdir = $rec->prop('Mount') || '/mnt/smb'; + my $id = $rec->prop('Id') || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; + my $smbhost = $rec->prop('SmbHost'); + my $smbshare = $rec->prop('SmbShare'); my $mntbkdir; my $key; my $VFSType = $rec->prop('VFSType') || 'cifs'; my $err; - $mntdir = "/$smbshare" if ( $VFSType eq 'usb' ); - + $mntdir = "/$smbshare" if ($VFSType eq 'usb'); my $setbackuplist = sub { - if ( $_ =~ /\.dar/ ) { - my $dir = $File::Find::dir; - my $backupref; - $dir =~ s/$mntbkdir\///; + + if ($_ =~ /\.dar/) { + my $dir = $File::Find::dir; + my $backupref; + $dir =~ s/$mntbkdir\///; $_ =~ s/\..*\.dar//; - $backupref = $_; - $_ =~ s/.*-//; - @{$backupfiles{$_}}[0] = $dir; - @{$backupfiles{$_}}[1] = $backupref; - } + $backupref = $_; + $_ =~ s/.*-//; + @{ $backupfiles{$_} }[0] = $dir; + @{ $backupfiles{$_} }[1] = $backupref; + } ## end if ($_ =~ /\.dar/) }; # Mounting backup shared folder - my $error_message = $c->bmount($mntdir,$smbhost,$smbshare,$VFSType); + my $error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType); return [] if $error_message; # Test if backup subdirectory for our server $mntbkdir = $mntdir . "/$id"; + unless (-d $mntbkdir) { - $error_message .= $c->bunmount($mntdir,$VFSType); + $error_message .= $c->bunmount($mntdir, $VFSType); return []; } - my $catalog = "$mntbkdir/dar-catalog"; - my $i = 0; my $j = 0; - my @bknum; my @setd; my @bkname; + my $i = 0; + my $j = 0; + my @bknum; + my @setd; + my @bkname; - # update backups list from current catalog - open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |") ; + # update backups list from current catalog + open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |"); $i = 0; - while () { - next unless m/set/; - chomp; - ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); - $i++; - } - close (DAR_LIST); + while () { + next unless m/set/; + chomp; + ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); + $i++; + } ## end while () + close(DAR_LIST); my @list; # set drop down list of backups push @list, [ $c->l('bac_ALL_BACKUPS') => "0" ]; $j = 0; + while ($j < $i) { - push @list, [ $bkname[$j] => "$bknum[$j]" ]; - $j++ + push @list, [ $bkname[$j] => "$bknum[$j]" ]; + $j++; } - - $error_message .= $c->bunmount($mntdir,$VFSType); + $error_message .= $c->bunmount($mntdir, $VFSType); return \@list; -} - +} ## end sub get_Restoreset_options sub get_Restorefiles_options { - my ($c, $filterexp, $backupkey) = @_; - my $rgfilter; + if ($filterexp =~ /^(.*)$/) { - $filterexp = $1; - $rgfilter = qr/$filterexp/; + $filterexp = $1; + $rgfilter = qr/$filterexp/; } else { $filterexp = ""; } + if ($backupkey =~ /^(.*)$/) { - $backupkey = $1; + $backupkey = $1; } else { - die('Unsecure data : ' . $backupkey); + die('Unsecure data : ' . $backupkey); } my $seldatebf; - my $backupwkrec = $cdb->get('backupwk'); - my $smbhost = $backupwkrec->prop('SmbHost'); - my $smbshare = $backupwkrec->prop('SmbShare'); - my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb'; + my $smbhost = $backupwkrec->prop('SmbHost'); + my $smbshare = $backupwkrec->prop('SmbShare'); + my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb'; my $key; - my $id = $backupwkrec->prop('Id') || - $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; + my $id = $backupwkrec->prop('Id') + || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value; my @flabels; my %flabels = (); my $VFSType = $backupwkrec->prop('VFSType') || 'cifs'; my $err; my $error_message; - $mntdir = "/$smbshare" if ( $VFSType eq 'usb' ); + $mntdir = "/$smbshare" if ($VFSType eq 'usb'); # Mounting backup shared folder - $error_message = $c->bmount($mntdir,$smbhost,$smbshare,$VFSType); + $error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType); + if ($error_message) { warn "Backup - restore files: $error_message, $id \n"; return undef; @@ -1819,308 +1703,280 @@ sub get_Restorefiles_options { # Test if backup subdirectory for our server my $mntbkdir = $mntdir . "/$id"; + unless (-d $mntbkdir) { - $error_message = $c->l('bac_ERR_NO_HOST_DIR')."\n"; - $error_message .= $c->bunmount($mntdir,$VFSType); + $error_message = $c->l('bac_ERR_NO_HOST_DIR') . "\n"; + $error_message .= $c->bunmount($mntdir, $VFSType); warn "Backup - restore files: $error_message, $id \n"; return undef; - } + } ## end unless (-d $mntbkdir) # Read wanted file list from selected backup if (open(RD, "-|")) { - my $regex = qr/\[.*\] */; - while () { - chomp; - $_ =~ s/$regex//; - if ($filterexp) {next unless m/$rgfilter/}; - push @flabels, $_; - } - my $status = close RD ? - $c->l('bac_READ_COMPLETE') - : ($c->l('bac_ERROR_READING_FILE').' : '.$backupkey); + my $regex = qr/\[.*\] */; + + while () { + chomp; + $_ =~ s/$regex//; + if ($filterexp) { next unless m/$rgfilter/ } + push @flabels, $_; + } ## end while () + my $status + = close RD + ? $c->l('bac_READ_COMPLETE') + : ($c->l('bac_ERROR_READING_FILE') . ' : ' . $backupkey); } else { select(STDOUT); $| = 1; - system("/usr/bin/dar_manager", "-B", "$mntbkdir/dar-catalog", "-u", "$backupkey") == 0 - or die ($c->l('bac_ERR_EXTRACT')." : ".$!); - - $error_message = $c->bunmount($mntdir,$VFSType); + or die($c->l('bac_ERR_EXTRACT') . " : " . $!); + $error_message = $c->bunmount($mntdir, $VFSType); die($error_message) if $error_message; exit(0); - } - - $error_message .= $c->bunmount($mntdir,$VFSType); + } ## end else [ if (open(RD, "-|")) ] + $error_message .= $c->bunmount($mntdir, $VFSType); return \@flabels; -} - +} ## end sub get_Restorefiles_options sub CalculateSizes () { - my $c = shift; #------------------------------------------------------------ # figure out the size of the tar file. #------------------------------------------------------------ - my $tarsize = 0; # It takes way too much time to do a du on /home/e-smith. So we'll # estimate the current size. # We do this by checking the quota used by each user on the system. - # Get a $dev value appropriate for use in Quota::query call. my $dev = Quota::getqcarg("/home/e-smith/files"); - foreach my $user ($adb->users()) - { - my $name = $user->key; - my $uid = getpwnam($name); - unless ($uid) - { - warn ($c->l('bac_NO_UID_FOR_NAME').$name."\n"); - # We shouldn't ever get here. If we do, we can't get - # the quota value for this user, so we just skip to - # the next one. - next; - } + foreach my $user ($adb->users()) { + my $name = $user->key; + my $uid = getpwnam($name); - # Get current quota settings. - my ($blocks) = Quota::query($dev, $uid, 0); - $tarsize += $blocks; - } + unless ($uid) { + warn($c->l('bac_NO_UID_FOR_NAME') . $name . "\n"); + + # We shouldn't ever get here. If we do, we can't get + # the quota value for this user, so we just skip to + # the next one. + next; + } ## end unless ($uid) + + # Get current quota settings. + my ($blocks) = Quota::query($dev, $uid, 0); + $tarsize += $blocks; + } ## end foreach my $user ($adb->users...) # We add to this the size of root owned firectories, estimated using du. # If this takes too long, then the admin only has his or # herself to blame! - # Remove /home/e-smith from backup list, and make paths absolute - my @list = map { "/$_" } grep { !/home\/e-smith/ } @directories; + my @list = map {"/$_"} grep { !/home\/e-smith/ } @directories; open(DU, "-|") - or exec '/usr/bin/du', '-s', @list; + or exec '/usr/bin/du', '-s', @list; - while () { - my ($du) = split(/\s+/); - $tarsize += $du; + while () { + my ($du) = split(/\s+/); + $tarsize += $du; } close DU; - $tarsize = showSize($tarsize); + #------------------------------------------------------------ # figure out the size of the dump files #------------------------------------------------------------ my $dumpsize = 0; - open(DF, "-|") - or exec '/bin/df', '-P', '-t', 'ext4', '-t', 'xfs'; + or exec '/bin/df', '-P', '-t', 'ext4', '-t', 'xfs'; while () { - next unless (/^\//); - (undef, undef, my $s, undef) = split(/\s+/, $_); - $dumpsize += $s; - } + next unless (/^\//); + (undef, undef, my $s, undef) = split(/\s+/, $_); + $dumpsize += $s; + } ## end while () + # increase size by 10% to cope with dump overhead. $dumpsize *= 1.1; - close DF; $dumpsize = showSize($dumpsize); #------------------------------------------------------------ # how much free space is in /tmp #------------------------------------------------------------ - my $tmpfree = 0; + my $tmpfree = 0; my $halffree = 0; - open(DF, "-|") - or exec '/bin/df', '-P', '-t', 'ext4', '-t', 'xfs', '/tmp'; + or exec '/bin/df', '-P', '-t', 'ext4', '-t', 'xfs', '/tmp'; while () { - next unless (/^\//); - (undef, undef, undef, my $s) = split(/\s+/, $_); - $tmpfree += $s; - } - + next unless (/^\//); + (undef, undef, undef, my $s) = split(/\s+/, $_); + $tmpfree += $s; + } ## end while () close DF; $halffree = $tmpfree / 2; - $tmpfree = showSize($tmpfree); + $tmpfree = showSize($tmpfree); $halffree = showSize($halffree); - return ($tarsize, $dumpsize, $tmpfree, $halffree); -} - +} ## end sub CalculateSizes sub showSize { # convert size to Mb or Gb or Tb :) Remember, df reports in kb. my $size = shift; - - my $Mb = 1024; - my $Gb = $Mb * $Mb; - my $Tb = $Mb * $Mb * $Mb; + my $Mb = 1024; + my $Gb = $Mb * $Mb; + my $Tb = $Mb * $Mb * $Mb; if ($size >= $Tb) { - $size /= $Tb; - $size = int($size) . "Tb"; + $size /= $Tb; + $size = int($size) . "Tb"; } elsif ($size >= $Gb) { - $size /= $Gb; - $size = int($size) . "Gb"; + $size /= $Gb; + $size = int($size) . "Gb"; } elsif ($size >= $Mb) { - $size /= $Mb; - $size = int($size) . "Mb"; + $size /= $Mb; + $size = int($size) . "Mb"; } else { - $size .= "kb"; + $size .= "kb"; } - return $size; -} - +} ## end sub showSize sub desktopBackupRecordStatus { - my ($backup, $phase, $status) = @_; my $now = time(); - warn("Backup terminated: $phase failed - status: $status\n"); $backup->set_prop('EndEpochTime', "$now"); - $backup->set_prop('Result', "$phase:$status"); -} - + $backup->set_prop('Result', "$phase:$status"); +} ## end sub desktopBackupRecordStatus sub dmount { # mount dar unit according to dar-workstation configuration # return nothing if mount successfull + my ($host, $share, $mountdir, $login, $password, $VFSType) = @_; - my ($host,$share,$mountdir,$login,$password,$VFSType) = @_; - - if ($VFSType eq 'cifs') - { - return ( qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1) ); - } - elsif ($VFSType eq 'nfs') { - return ( qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1) ); - } - elsif ($VFSType eq 'usb') { - my $device = ""; - my $vollbl = ""; - - my $devices = esmith::BlockDevices->new ('allowmount' => 'disabled'); + if ($VFSType eq 'cifs') { + return (qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1)); + } elsif ($VFSType eq 'nfs') { + return (qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1)); + } elsif ($VFSType eq 'usb') { + my $device = ""; + my $vollbl = ""; + my $devices = esmith::BlockDevices->new('allowmount' => 'disabled'); my ($valid, $invalid) = $devices->checkBackupDrives(0); - if ( ${$valid}[0] ) { - foreach ( @{$valid} ) { + if (${$valid}[0]) { + foreach (@{$valid}) { $vollbl = $devices->label($_); - if ( $share eq "media/$vollbl" ) { + + if ($share eq "media/$vollbl") { $device = "/dev/$_"; } - } - } + } ## end foreach (@{$valid}) + } ## end if (${$valid}[0]) $devices->destroy; - return ( qx (mount $device /$share 2>&1) ); - -#------------------------------------------------------------------------------------------------------- + return (qx (mount $device /$share 2>&1)); + + #------------------------------------------------------------------------------------------------------- #my $device = ""; #my $blkdev = ""; #my $vollbl = ""; #foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { - #$udi =~ m/^(\S+)/; - #my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); - - #if ($is_mounted eq "false\n") { - #$blkdev = qx(hal-get-property --udi $1 --key block.device); - #if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} - #} - #if ($is_mounted eq "false\n") { - #$vollbl = qx(hal-get-property --udi $1 --key volume.label); - #$vollbl =~ m/^(\S+)/; - #if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} - #} - - #chomp $vollbl; - #chomp $blkdev; - #$vollbl = "media/$vollbl"; - #if ($vollbl eq $share) { - #$device = $blkdev; - #} + #$udi =~ m/^(\S+)/; + #my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); + #if ($is_mounted eq "false\n") { + #$blkdev = qx(hal-get-property --udi $1 --key block.device); + #if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} #} - #return ( qx(/bin/mount $device "/$share" 2>&1) ); -#------------------------------------------------------------------------------------------------------- + #if ($is_mounted eq "false\n") { + #$vollbl = qx(hal-get-property --udi $1 --key volume.label); + #$vollbl =~ m/^(\S+)/; + #if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} + #} + #chomp $vollbl; + #chomp $blkdev; + #$vollbl = "media/$vollbl"; + #if ($vollbl eq $share) { + #$device = $blkdev; + #} + #} + #return ( qx(/bin/mount $device "/$share" 2>&1) ); + #------------------------------------------------------------------------------------------------------- } else { - return ("Error while mounting $host/$share : $VFSType not supported.\n"); + return ("Error while mounting $host/$share : $VFSType not supported.\n"); } -} - +} ## end sub dmount sub checkMount { # check if $mountdir is mounted my $mountdir = shift; - $|=1; # Auto-flush + $| = 1; # Auto-flush # copy STDOUT to another filehandle - open (my $STDOLD, '>&', STDOUT); - + open(my $STDOLD, '>&', STDOUT); open(STDOUT, ">/dev/null"); - if ( open(MOUNTDIR, "|-", "/bin/findmnt", $mountdir)){;} + if (open(MOUNTDIR, "|-", "/bin/findmnt", $mountdir)) {;} # restore STDOUT - open (STDOUT, '>&', $STDOLD); - - return (!close(MOUNTDIR)); -} - + open(STDOUT, '>&', $STDOLD); + return (!close(MOUNTDIR)); +} ## end sub checkMount sub bmount { - my ($c, $mntdir, $host, $share, $VFSType) = @_; - # verify backup directory not already mounted - if (!checkMount ($mntdir)) { + # verify backup directory not already mounted + if (!checkMount($mntdir)) { return if ($VFSType eq 'mnt'); return ($c->l('bac_ERR_ALREADY_MOUNTED')); } else { + if ($VFSType eq 'mnt') { return ($c->l('bac_ERR_NOT_MOUNTED')); } - } + } ## end else [ if (!checkMount($mntdir...))] # create the directory mount point if it does not exist - my $err = createTree ($mntdir); + my $err = createTree($mntdir); return ($c->l('bac_ERR_MOUNTING_SMBSHARE') . "\n" . $err) if $err; # mount the backup directory - $err = dmount($host,$share,$mntdir,'','',$VFSType); + $err = dmount($host, $share, $mntdir, '', '', $VFSType); return ($c->l('bac_ERR_MOUNTING_SMBSHARE') . "\n" . $err) if $err; # verify $mntdir is mounted - if (checkMount ($mntdir)) { - # The mount should have suceeded, but sometimes it needs more time, + if (checkMount($mntdir)) { + + # The mount should have suceeded, but sometimes it needs more time, # so sleep and then check again. sleep 5; - if (checkMount ($mntdir)) { + + if (checkMount($mntdir)) { return ($c->l('bac_ERR_NOT_MOUNTED')); } - } + } ## end if (checkMount($mntdir...)) return; -} - +} ## end sub bmount sub bunmount { - my ($c, $mount, $type) = @_; - return if ($type eq 'mnt'); # Don't unmount for type 'mnt' + return if ($type eq 'mnt'); # Don't unmount for type 'mnt' - if (!checkMount ($mount)) { + if (!checkMount($mount)) { system('/bin/umount', '-f', $mount) == 0 or return ($c->l('bac_ERR_WHILE_UNMOUNTING')); } return; -} - +} ## end sub bunmount sub findmnt { - - my @mntin = qx( findmnt -n -l -o TARGET ); + my @mntin = qx( findmnt -n -l -o TARGET ); my @mntout; foreach my $mount (@mntin) { @@ -2128,37 +1984,31 @@ sub findmnt { chomp $mount; next if ($mount eq '/'); push @mntout, $mount; - } + } ## end foreach my $mount (@mntin) return @mntout; -} - +} ## end sub findmnt sub createTree { - my $tree = shift; - if (! -d "$tree") { - eval {make_path("$tree")}; + if (!-d "$tree") { + eval { make_path("$tree") }; return ("Error while creating $tree : $@. Maybe insufficient rights directory.\n") if $@; } return; -} - +} ## end sub createTree sub vmount { #Used to test if the remote share is mountable when you save settings in database # mount dar unit according to dar-workstation configuration in order to test the remote host # return nothing if mount successfull - - my ($host,$share,$mountdir,$VFSType) = @_; + my ($host, $share, $mountdir, $VFSType) = @_; if ($VFSType eq 'cifs') { - return ( qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1) ); + return (qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1)); } elsif ($VFSType eq 'nfs') { - return ( qx(/bin/mount -t nfs -o nolock,timeo=30,retrans=1,retry=0 "$host:/$share" $mountdir 2>&1) ); + return (qx(/bin/mount -t nfs -o nolock,timeo=30,retrans=1,retry=0 "$host:/$share" $mountdir 2>&1)); } -} - - +} ## end sub vmount 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Bugreport.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Bugreport.pm index 9fbbb53..5bfd3f4 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Bugreport.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Bugreport.pm @@ -4,172 +4,143 @@ package SrvMngr::Controller::Bugreport; # heading : Investigation # description : Report a bug # navigation : 7000 500 - # routes : end #------------------------------ use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session); - use Text::Template; use File::Basename; use esmith::FormMagick qw( gen_locale_date_string ); - our $cdb = esmith::ConfigDB->open or die "Couldn't open ConfigDB\n"; # Get some basic info on the current SME install -our $sysconfig = $cdb->get('sysconfig'); -our $systemmode = $cdb->get('SystemMode')->value; +our $sysconfig = $cdb->get('sysconfig'); +our $systemmode = $cdb->get('SystemMode')->value; our $previoussystemmode = $sysconfig->prop('PreviousSystemMode'); -our $releaseversion = $sysconfig->prop('ReleaseVersion'); +our $releaseversion = $sysconfig->prop('ReleaseVersion'); # Prepare some filehandles for templates and reports -our $templatefile = '/tmp/bugreport_template.txt'; +our $templatefile = '/tmp/bugreport_template.txt'; our $configreportfile = '/tmp/configreport.txt'; - sub main { my $c = shift; $c->app->log->info($c->log_req); - my %bugr_datas = (); - - my $title = $c->l('bugr_FORM_TITLE'); - my $modul = $c->render_to_string( inline => $c->l('bugr_DESCRIPTION')); - + my $title = $c->l('bugr_FORM_TITLE'); + my $modul = $c->render_to_string(inline => $c->l('bugr_DESCRIPTION')); $bugr_datas{'trt'} = 'SHOW'; - $c->stash(title => $title, modul => $modul, bugr_datas => \%bugr_datas); $c->render(template => 'bugreport'); -}; - +} ## end sub main sub do_report { my $c = shift; $c->app->log->info($c->log_req); - - my $title = $c->l('bugr_FORM_TITLE'); - - my $trt = $c->param('trt') || 'SHOW'; - + my $title = $c->l('bugr_FORM_TITLE'); + my $trt = $c->param('trt') || 'SHOW'; my %bugr_datas = (); $bugr_datas{'trt'} = $trt; - if ( $trt eq 'SHOW' ) { - create_configuration_report(); - + if ($trt eq 'SHOW') { + create_configuration_report(); my $out = $c->render_to_string(inline => show_config_report()); + $bugr_datas{'trt'} = 'DOWN'; + $c->stash(title => $title, modul => $out, bugr_datas => \%bugr_datas); + $c->render(template => 'bugreport2'); + } ## end if ($trt eq 'SHOW') - $bugr_datas{'trt'} = 'DOWN'; - - $c->stash(title => $title, modul => $out, bugr_datas => \%bugr_datas); - $c->render(template => 'bugreport2'); - } - - if ( $trt eq 'DOWN' ) { - - my $modul = 'Bug report download'; - -# $c->render_file( -# 'filepath' => "$configreportfile", -# 'format' => 'x-download', -# 'content_disposition' => 'attachment', -# 'cleanup' => 1, -# ); - - # the following in this sub will not be used !!! -# $bugr_datas{'trt'} = 'DOWN'; - -# $c->stash(title => $title, modul => $modul, bugr_datas => \%bugr_datas); -# $c->render(template => 'bugreport'); - } -}; + if ($trt eq 'DOWN') { + my $modul = 'Bug report download'; + # $c->render_file( + # 'filepath' => "$configreportfile", + # 'format' => 'x-download', + # 'content_disposition' => 'attachment', + # 'cleanup' => 1, + # ); + # the following in this sub will not be used !!! + # $bugr_datas{'trt'} = 'DOWN'; + # $c->stash(title => $title, modul => $modul, bugr_datas => \%bugr_datas); + # $c->render(template => 'bugreport'); + } ## end if ($trt eq 'DOWN') +} ## end sub do_report sub create_configuration_report { - my $c = shift; # TBD: possibly check $q for a boolean value eg. from a checkbox # indicating the user has read privacy warning etc. - # create the reporting template - my $configreport_template = Text::Template->new(TYPE => 'FILE', SOURCE => '/etc/e-smith/web/common/configuration_report.tmpl', UNTAINT => 1); + my $configreport_template = Text::Template->new( + TYPE => 'FILE', + SOURCE => '/etc/e-smith/web/common/configuration_report.tmpl', + UNTAINT => 1 + ); my $report_creation_time = gen_locale_date_string; # curent kernel my $curkernel = `uname -r`; - + # get additional RPMs my @newrpms = `/sbin/e-smith/audittools/newrpms`; - + # get additional Repositories my @repositories = `/sbin/e-smith/audittools/repositories`; - #print @repositories; + #print @repositories; # get templates my @templates = `/sbin/e-smith/audittools/templates`; # get events my @events = `/sbin/e-smith/audittools/events`; - - + # set template variables - my %vars = (report_creation_time => \$report_creation_time, - releaseversion => \$releaseversion, - curkernel => \$curkernel, - systemmode => \$systemmode, - previoussystemmode => \$previoussystemmode, - newrpms => \@newrpms, - templates => \@templates, - events => \@events, - repositories => \@repositories, - ); + my %vars = ( + report_creation_time => \$report_creation_time, + releaseversion => \$releaseversion, + curkernel => \$curkernel, + systemmode => \$systemmode, + previoussystemmode => \$previoussystemmode, + newrpms => \@newrpms, + templates => \@templates, + events => \@events, + repositories => \@repositories, + ); # prcess template my $result = $configreport_template->fill_in(HASH => \%vars); # write processed template to file - open (my $cfgrep, '>', $configreportfile) or die "Could not create temporary file for config report!"; + open(my $cfgrep, '>', $configreportfile) or die "Could not create temporary file for config report!"; print $cfgrep $result; close $cfgrep; -} - +} ## end sub create_configuration_report sub show_config_report { - my $c = shift; - + my $c = shift; my $out = ''; $out .= sprintf "
";
-
-    open (my $cfgrep, '<', $configreportfile) or die "Could not find temporary config report file!";
+    open(my $cfgrep, '<', $configreportfile) or die "Could not find temporary config report file!";
 
     while (<$cfgrep>) {
-	$out .= sprintf("%s", $_);
+        $out .= sprintf("%s", $_);
     }
-
     $out .= sprintf "
"; - return $out; - -} - +} ## end sub show_config_report sub download_config_report { my $c = shift; - $c->render_file( - 'filepath' => "$configreportfile", - 'format' => 'x-download', - 'content_disposition' => 'attachment', - 'cleanup' => 1, + 'filepath' => "$configreportfile", + 'format' => 'x-download', + 'content_disposition' => 'attachment', + 'cleanup' => 1, ); -} - - +} ## end sub download_config_report 1; - diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Clamav.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Clamav.pm index d458573..4fa374d 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Clamav.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Clamav.pm @@ -7,107 +7,84 @@ package SrvMngr::Controller::Clamav; # # routes : end #------------------------------ - use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session); #package esmith::FormMagick::Panel::clamav; - our $db = esmith::ConfigDB->open() || die "Couldn't open config db"; sub main { my $c = shift; $c->app->log->info($c->log_req); - my %clm_datas = (); - my $title = $c->l('clm_FORM_TITLE'); - my $modul = $c->render_to_string(inline => $c->l('clm_DESC_FILESYSTEM_SCAN_PERIOD')); - - $clm_datas{'FilesystemScan'} = ($db->get_prop('clamav','FilesystemScan')) || 'disabled'; - $clm_datas{'Quarantine'} = ($db->get_prop('clamav','Quarantine')) || 'disabled'; - - $clm_datas{'clam_versions'} = get_clam_versions(); - - $c->stash( title => $title, modul => $modul, clm_datas => \%clm_datas ); + my $title = $c->l('clm_FORM_TITLE'); + my $modul = $c->render_to_string(inline => $c->l('clm_DESC_FILESYSTEM_SCAN_PERIOD')); + $clm_datas{'FilesystemScan'} = ($db->get_prop('clamav', 'FilesystemScan')) || 'disabled'; + $clm_datas{'Quarantine'} = ($db->get_prop('clamav', 'Quarantine')) || 'disabled'; + $clm_datas{'clam_versions'} = get_clam_versions(); + $c->stash(title => $title, modul => $modul, clm_datas => \%clm_datas); $c->render(template => 'clamav'); -}; - +} ## end sub main sub do_update { my $c = shift; $c->app->log->info($c->log_req); - my $http_clamav_status = $c->param('http_clamav_status') || 'disabled'; my $smtp_clamav_status = $c->param('smtp_clamav_status') || ''; - - my $result = ""; - + my $result = ""; $c->change_settings(); # Update the system system("/sbin/e-smith/signal-event clamav-update") == 0 or $result = $c->l('clm_ERROR_UPDATING_CONFIGURATION'); - if ( ! $result ) { - $result = $c->l('clm_SUCCESS') ; - $c->flash( success => $result ); + if (!$result) { + $result = $c->l('clm_SUCCESS'); + $c->flash(success => $result); } else { - $c->flash( error => $result ); + $c->flash(error => $result); } - $c->redirect_to('/clamav'); -}; - +} ## end sub do_update sub change_settings { - my $c = shift; - - my $status = $c->param('status'); - - my $FilesystemScan = ( $c->param('FilesystemScan') || 'disabled' ); - my $Quarantine = ( $c->param('Quarantine') || 'disabled' ); - - my $DatabaseMirror = ( $c->param('DatabaseMirror') || 'db.us.clamav.net' ); - my $UpdateOfficeHrs = ( $c->param('UpdateOfficeHrs') || 'disabled' ); - my $UpdateNonOfficeHrs = ( $c->param('UpdateNonOfficeHrs') || 'disabled' ); - my $UpdateWeekend = ( $c->param('UpdateWeekend') || 'disabled' ); - - my $HTTPProxyServer = ( $c->param('HTTPProxyServer') || '' ); - my $HTTPProxyPort = ( $c->param('HTTPProxyPort') || '' ); - my $HTTPProxyUsername = ( $c->param('HTTPProxyUsername') || '' ); - my $HTTPProxyPassword = ( $c->param('HTTPProxyPassword') || '' ); - - my $clamav = $db->get('clamav') || $db->new_record('clamav', {type=>'service'}); + my $c = shift; + my $status = $c->param('status'); + my $FilesystemScan = ($c->param('FilesystemScan') || 'disabled'); + my $Quarantine = ($c->param('Quarantine') || 'disabled'); + my $DatabaseMirror = ($c->param('DatabaseMirror') || 'db.us.clamav.net'); + my $UpdateOfficeHrs = ($c->param('UpdateOfficeHrs') || 'disabled'); + my $UpdateNonOfficeHrs = ($c->param('UpdateNonOfficeHrs') || 'disabled'); + my $UpdateWeekend = ($c->param('UpdateWeekend') || 'disabled'); + my $HTTPProxyServer = ($c->param('HTTPProxyServer') || ''); + my $HTTPProxyPort = ($c->param('HTTPProxyPort') || ''); + my $HTTPProxyUsername = ($c->param('HTTPProxyUsername') || ''); + my $HTTPProxyPassword = ($c->param('HTTPProxyPassword') || ''); + my $clamav = $db->get('clamav') || $db->new_record('clamav', { type => 'service' }); $status ||= $clamav->prop('status'); - $clamav->merge_props( - status => $status, - FilesystemScan => $FilesystemScan, - Quarantine => $Quarantine, - DatabaseMirror => $DatabaseMirror, - UpdateOfficeHrs => $UpdateOfficeHrs, - UpdateNonOfficeHrs => $UpdateNonOfficeHrs, - UpdateWeekend => $UpdateWeekend, - HTTPProxyServer => $HTTPProxyServer, - HTTPProxyPort => $HTTPProxyPort, - HTTPProxyUsername => $HTTPProxyUsername, - HTTPProxyPassword => $HTTPProxyPassword, - ); + status => $status, + FilesystemScan => $FilesystemScan, + Quarantine => $Quarantine, + DatabaseMirror => $DatabaseMirror, + UpdateOfficeHrs => $UpdateOfficeHrs, + UpdateNonOfficeHrs => $UpdateNonOfficeHrs, + UpdateWeekend => $UpdateWeekend, + HTTPProxyServer => $HTTPProxyServer, + HTTPProxyPort => $HTTPProxyPort, + HTTPProxyUsername => $HTTPProxyUsername, + HTTPProxyPassword => $HTTPProxyPassword, + ); +} ## end sub change_settings - -} - -sub get_clam_versions -{ +sub get_clam_versions { my $version = `/usr/bin/freshclam -V`; chomp $version; $version =~ s/^ClamAV //; - return $version; -} +} ## end sub get_clam_versions 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Datetime.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Datetime.pm index 32a180a..8e8b69b 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Datetime.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Datetime.pm @@ -4,191 +4,162 @@ package SrvMngr::Controller::Datetime; # heading : System # description : Date and time # navigation : 4000 400 - # routes : end #------------------------------ - use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session); - use esmith::FormMagick; use esmith::util; - our $cdb = esmith::ConfigDB->open() || die "Couldn't open config db"; sub main { my $c = shift; $c->app->log->info($c->log_req); - my %dat_datas = (); - my $title = $c->l('dat_FORM_TITLE'); - my $modul = $c->l('dat_INITIAL_DESC'); - - + my $title = $c->l('dat_FORM_TITLE'); + my $modul = $c->l('dat_INITIAL_DESC'); $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'`; + if ($rec->prop('status') eq 'enabled') { + $dat_datas{ntpstatus} = 'enabled' + unless ($rec->prop('SyncToHWClockSupported') || 'yes') eq 'yes' and $dat_datas{ntpserver} =~ m#^\s*$#; + } + } ## end if ($rec) + ( $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}); - + chop($dat_datas{ampm}); $dat_datas{'now_string'} = esmith::FormMagick->gen_locale_date_string(); - - $c->stash( title => $title, modul => $modul, dat_datas => \%dat_datas ); + $c->stash(title => $title, modul => $modul, dat_datas => \%dat_datas); $c->render('datetime'); -}; - +} ## end sub main sub do_update { - - my $c = shift; - + my $c = shift; my %dat_datas = (); - my $title = $c->l('dat_FORM_TITLE'); - my $modul = $c->l('dat_INITIAL_DESC'); + my $title = $c->l('dat_FORM_TITLE'); + 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'`; - if ( $dat_datas{ntpstatus} ne $old_ntpstatus) { + # get rid of trailing carriage return on last field + chop($dat_datas{ampm}); + } else { + $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'); + } ## end if ($dat_datas{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'`; - - # get rid of trailing carriage return on last field - chop ($dat_datas{ampm}); - - } else { - - $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' ) { - - # update ntpserver + if ($dat_datas{ntpstatus} eq 'enabled') { + # update ntpserver $dat_datas{ntpserver} = $c->param('Ntpserver') || ''; - if ( $dat_datas{ntpserver} eq "pool.ntp.org" ) { + if ($dat_datas{ntpserver} eq "pool.ntp.org") { $result .= $c->l('dat_INVALID_NTP_ADDR'); - } elsif ( $dat_datas{ntpserver} =~ /^([a-zA-Z0-9\.\-]+)$/ ) { + } elsif ($dat_datas{ntpserver} =~ /^([a-zA-Z0-9\.\-]+)$/) { $dat_datas{ntpserver} = $1; -# } elsif ( $dat_datas{ntpserver} =~ /^\s*$/ ) { -# $dat_datas{ntpserver} = ""; + + # } 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} ); - } - + if (!$result) { + $success = update_ntpserver($c, $dat_datas{ntpserver}); + } } else { - # set Locale time & clean ntpserver + # set Locale time & clean ntpserver + #my $servername = ($c->param('ServerName') || 'WS'); + if (!$result) { + $result = validate_change_datetime($c); - #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'); - } - } - } + if ($result eq 'OK') { + $success = $c->l('dat_UPDATING_CLOCK'); + $result = ''; + disable_ntp(); + $success .= '
' . $c->l('dat_SERVER_DISABLED_DESC'); + } ## end if ($result eq 'OK') + } ## end if (!$result) + } ## end else [ if ($dat_datas{ntpstatus...})] + if ($result) { + $c->stash(error => $result); + $c->stash(title => $title, modul => $modul, dat_datas => \%dat_datas); + return $c->render('datetime'); + } ## end if ($result) - if ( $result ) { - $c->stash( error => $result ); - $c->stash( title => $title, modul => $modul, dat_datas => \%dat_datas ); - return $c->render('datetime'); - } #$result = $c->l('dat_SUCCESS'); - my $message = "'Datetime' update DONE"; $c->app->log->info($message); - $c->flash( success => $success ); - + $c->flash(success => $success); $c->redirect_to('/datetime'); -}; - +} ## end sub do_update sub validate_change_datetime { - my $c = shift; #-------------------------------------------------- # Untaint parameters and check for validity #-------------------------------------------------- + my $timezone = $c->param('Timezone'); - my $timezone = $c->param ('Timezone'); if ($timezone =~ /^([\w\-]+\/?[\w\-+]*)$/) { $timezone = $1; } else { $timezone = "US/Eastern"; } - - my $month = $c->param ('Month'); + my $month = $c->param('Month'); if ($month =~ /^(\d{1,2})$/) { $month = $1; } else { $month = "1"; } - if (($month < 1) || ($month > 12)) { - return $c->l('dat_INVALID_MONTH')." $month. ". $c->l('dat_MONTH_BETWEEN_1_AND_12'); - } - my $day = $c->param ('Day'); + if (($month < 1) || ($month > 12)) { + return $c->l('dat_INVALID_MONTH') . " $month. " . $c->l('dat_MONTH_BETWEEN_1_AND_12'); + } + my $day = $c->param('Day'); if ($day =~ /^(\d{1,2})$/) { $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 (($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 =~ /^(\d{4})$/) { $year = $1; } else { @@ -196,20 +167,21 @@ sub validate_change_datetime { } if (($year < 1900) || ($year > 2200)) { - return $c->l('dat_INVALID_YEAR')." $year. ". $c->l('dat_FOUR_DIGIT_YEAR'); + return $c->l('dat_INVALID_YEAR') . " $year. " . $c->l('dat_FOUR_DIGIT_YEAR'); } + my $hour = $c->param('Hour'); - my $hour = $c->param ('Hour'); if ($hour =~ /^(\d{1,2})$/) { $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 (($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 =~ /^(\d{1,2})$/) { $minute = $1; } else { @@ -217,10 +189,10 @@ sub validate_change_datetime { } if (($minute < 0) || ($minute > 59)) { - return $c->l('datINVALID_MINUTE')." $minute. ".$c->l('dat_BETWEEN_0_AND_59'); + return $c->l('datINVALID_MINUTE') . " $minute. " . $c->l('dat_BETWEEN_0_AND_59'); } - - my $second = $c->param ('Second'); + my $second = $c->param('Second'); + if ($second =~ /^(\d{1,2})$/) { $second = $1; } else { @@ -228,10 +200,10 @@ sub validate_change_datetime { } if (($second < 0) || ($second > 59)) { - return $c->l('dat_INVALID_SECOND')." $second. ". $c->l('dat_BETWEEN_0_AND_59'); + return $c->l('dat_INVALID_SECOND') . " $second. " . $c->l('dat_BETWEEN_0_AND_59'); } + my $ampm = $c->param('Ampm'); - my $ampm = $c->param ('Ampm'); if ($ampm =~ /^(AM|PM)$/) { $ampm = $1; } else { @@ -239,8 +211,8 @@ sub validate_change_datetime { } # convert to 24 hour time - $hour = $hour % 12; + if ($ampm eq "PM") { $hour = $hour + 12; } @@ -248,12 +220,12 @@ sub validate_change_datetime { #-------------------------------------------------- # Store time zone in configuration database #-------------------------------------------------- - my $conf = esmith::ConfigDB->open(); - my $old = $conf->get('UnsavedChanges')->value; - my $rec = $conf->get('TimeZone'); + my $old = $conf->get('UnsavedChanges')->value; + my $rec = $conf->get('TimeZone'); + unless ($rec) { - $rec = $conf->new_record('TimeZone',undef); + $rec = $conf->new_record('TimeZone', undef); } $rec->set_value($timezone); $conf->get('UnsavedChanges')->set_value($old); @@ -262,71 +234,56 @@ sub validate_change_datetime { # 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); - + 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'; -} - +} ## end sub validate_change_datetime sub update_ntpserver { - - my $c = shift; + my $c = shift; my $ntpserver = shift; - my $msg; - #------------------------------------------------------------ - # Looks good; go ahead and change the parameters. - #------------------------------------------------------------ + #------------------------------------------------------------ + # 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); + $rec->set_prop('status', 'enabled'); + $rec->set_prop('NTPServer', $ntpserver); } else { - $rec = $cdb->new_record( 'ntpd', - { type=>'service', status=>'enabled', SyncToHWClockSupported => 'yes', NTPServer=>$ntpserver } ); + $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*$/ ) { + 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" ); - + } ## end if ($ntpserver =~ /^\s*$/) + esmith::util::backgroundCommand(2, "/sbin/e-smith/signal-event", "timeserver-update"); return $msg; -} - +} ## end sub update_ntpserver 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',''); + $rec->set_prop('NTPServer', ''); } else { - $rec = $cdb->new_record('ntpd', - {type=>'service', status=>'enabled', SyncToHWClockSupported => 'yes', NTPServer=>''}); + $rec = $cdb->new_record('ntpd', + { type => 'service', status => 'enabled', SyncToHWClockSupported => 'yes', NTPServer => '' }); } - $cdb->get('UnsavedChanges')->set_value($old); - -} - +} ## end sub disable_ntp sub getTimezone { @@ -336,69 +293,64 @@ sub getTimezone { # 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; + $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; -} + if (defined($localtime = readlink '/etc/localtime')) { + my $pos = index $localtime, 'zoneinfo/'; + + if ($pos > -1) { + $timezonedefault = substr $localtime, ($pos + 9); + } + } ## end if (defined($localtime...)) + } ## end else [ if (defined $cdb->get(...))] + return $timezonedefault; +} ## end sub getTimezone 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').$!.'.' ); + + 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 $zone; my @zones = (); - while (defined ($zone = )) - { - chop ($zone); + while (defined($zone = )) { + chop($zone); $zone =~ s/^.\///; push @zones, $zone; - } + } ## end while (defined($zone = ...)) close ZONES; my @zt = sort @zones; return \@zt; -} - +} ## end sub getZone_list 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']]; -} - - + 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' ] + ]; +} ## end sub getMonth_list 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Directory.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Directory.pm index ce0ff4c..0767982 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Directory.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Directory.pm @@ -7,91 +7,72 @@ package SrvMngr::Controller::Directory; # # routes : end #---------------------------------------------------------------------- - use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session); #use esmith::util qw(ldapBase); use esmith::FormMagick::Panel::directory; - our $db = esmith::ConfigDB->open() || die "Couldn't open config db"; sub main { - my $c = shift; $c->app->log->info($c->log_req); - my %dir_datas = (); - my $title = $c->l('dir_FORM_TITLE'); - my $modul = $c->render_to_string(inline => $c->l('dir_DESCRIPTION')); - - $dir_datas{'root'} = get_ldap_base(); - - $dir_datas{'access'} = ($db->get_prop('ldap','access')) || 'private'; - $dir_datas{'department'} = ($db->get_prop('ldap','defaultDepartment')) || ''; - $dir_datas{'company'} = ($db->get_prop('ldap','defaultCompany')) || ''; - $dir_datas{'street'} = ($db->get_prop('ldap','defaultStreet')) || ''; - $dir_datas{'city'} = ($db->get_prop('ldap','defaultCity')) || ''; - $dir_datas{'phonenumber'} = ($db->get_prop('ldap','defaultPhoneNumber')) || ''; - - $c->stash( title => $title, modul => $modul, dir_datas => \%dir_datas ); + my $title = $c->l('dir_FORM_TITLE'); + my $modul = $c->render_to_string(inline => $c->l('dir_DESCRIPTION')); + $dir_datas{'root'} = get_ldap_base(); + $dir_datas{'access'} = ($db->get_prop('ldap', 'access')) || 'private'; + $dir_datas{'department'} = ($db->get_prop('ldap', 'defaultDepartment')) || ''; + $dir_datas{'company'} = ($db->get_prop('ldap', 'defaultCompany')) || ''; + $dir_datas{'street'} = ($db->get_prop('ldap', 'defaultStreet')) || ''; + $dir_datas{'city'} = ($db->get_prop('ldap', 'defaultCity')) || ''; + $dir_datas{'phonenumber'} = ($db->get_prop('ldap', 'defaultPhoneNumber')) || ''; + $c->stash(title => $title, modul => $modul, dir_datas => \%dir_datas); $c->render(template => 'directory'); -}; - +} ## end sub main sub do_update { my $c = shift; $c->app->log->info($c->log_req); - - my $access = $c->param('access'); - my $department = $c->param('department'); - my $company = $c->param('company'); - my $street = $c->param('street'); - my $city = $c->param('city'); + my $access = $c->param('access'); + my $department = $c->param('department'); + my $company = $c->param('company'); + my $street = $c->param('street'); + my $city = $c->param('city'); my $phonenumber = $c->param('phonenumber'); - my $existing = $c->param('existing'); - - my $result = ""; - - $db->get('ldap')->set_prop('access', $access); - $db->get('ldap')->set_prop('defaultDepartment', $department); - $db->get('ldap')->set_prop('defaultCompany', $company); - $db->get('ldap')->set_prop('defaultStreet', $street); - $db->get('ldap')->set_prop('defaultCity', $city); + my $existing = $c->param('existing'); + my $result = ""; + $db->get('ldap')->set_prop('access', $access); + $db->get('ldap')->set_prop('defaultDepartment', $department); + $db->get('ldap')->set_prop('defaultCompany', $company); + $db->get('ldap')->set_prop('defaultStreet', $street); + $db->get('ldap')->set_prop('defaultCity', $city); $db->get('ldap')->set_prop('defaultPhoneNumber', $phonenumber); if ($existing eq 'update') { - my $ac = esmith::AccountsDB->open() || die "Couldn't open accounts db"; - my @users = $ac->users(); - - foreach my $user (@users) { - $user->set_prop('Phone', $phonenumber); - $user->set_prop('Company', $company); - $user->set_prop('Dept', $department); - $user->set_prop('City', $city); - $user->set_prop('Street', $street); - } - } + my $ac = esmith::AccountsDB->open() || die "Couldn't open accounts db"; + my @users = $ac->users(); + + foreach my $user (@users) { + $user->set_prop('Phone', $phonenumber); + $user->set_prop('Company', $company); + $user->set_prop('Dept', $department); + $user->set_prop('City', $city); + $user->set_prop('Street', $street); + } ## end foreach my $user (@users) + } ## end if ($existing eq 'update') # # Update the system # - - system ("/sbin/e-smith/signal-event ldap-update") == 0 - or $result = $c->l('ERROR_UPDATING_CONFIGURATION'); - + system("/sbin/e-smith/signal-event ldap-update") == 0 + or $result = $c->l('ERROR_UPDATING_CONFIGURATION'); my $title = $c->l('dir_FORM_TITLE'); - - if ( $result eq '' ) { $result = $c->l('dir_SUCCESS'); } - - $c->stash( title => $title, modul => $result ); + if ($result eq '') { $result = $c->l('dir_SUCCESS'); } + $c->stash(title => $title, modul => $result); $c->render(template => 'module'); - -}; - - +} ## end sub do_update 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Domains.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Domains.pm index 6bbabcf..63c6c7d 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Domains.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Domains.pm @@ -10,493 +10,412 @@ package SrvMngr::Controller::Domains; 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::FormMagick::Panel::domains; - use esmith::DomainsDB; use esmith::AccountsDB; + #use URI::Escape; - - -our $ddb = esmith::DomainsDB->open || die "Couldn't open domains db"; -our $cdb = esmith::ConfigDB->open || die "Couldn't open configuration db"; +our $ddb = esmith::DomainsDB->open || die "Couldn't open domains db"; +our $cdb = esmith::ConfigDB->open || die "Couldn't open configuration db"; our $adb = esmith::AccountsDB->open || die "Couldn't open accounts db"; - our $REGEXP_DOMAIN = qq([a-zA-Z0-9\-\.]+); - sub main { - my $c = shift; $c->app->log->info($c->log_req); - my %dom_datas = (); - my $title = $c->l('dom_FORM_TITLE'); - + my $title = $c->l('dom_FORM_TITLE'); $dom_datas{trt} = 'LST'; - my @domains; - for ($ddb->domains()) - { + + for ($ddb->domains()) { my $ns = $_->prop('Nameservers') || 'internet'; - - push @domains, - { Domain => $_->key, $_->props, - Nameservers => $ns, - } - } - $dom_datas{forwarder} = $cdb->get_prop('dnscache', 'Forwarder'); - $dom_datas{forwarder2} = $cdb->get_prop('dnscache', 'Forwarder2') || ''; - - $c->stash( title => $title, dom_datas => \%dom_datas, domains => \@domains ); + push @domains, + { + Domain => $_->key, + $_->props, + Nameservers => $ns, + }; + } ## end for ($ddb->domains()) + $dom_datas{forwarder} = $cdb->get_prop('dnscache', 'Forwarder'); + $dom_datas{forwarder2} = $cdb->get_prop('dnscache', 'Forwarder2') || ''; + $c->stash(title => $title, dom_datas => \%dom_datas, domains => \@domains); $c->render(template => 'domains'); - -}; - +} ## end sub main sub do_display { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = $c->param('trt'); + my $rt = $c->current_route; + my $trt = $c->param('trt'); my $domain = $c->param('Domain') || ''; #$trt = 'DEL' if ( $rt eq 'domaindel1' ); #$trt = 'UPD' if ( $rt eq 'domainupd1' ); #$trt = 'UP2' if ( $rt eq 'domainup21' ); #$trt = 'ADD' if ( $rt eq 'domainadd1' ); - my %dom_datas = (); - my $title = $c->l('dom_FORM_TITLE'); - my $result = ''; - + my $title = $c->l('dom_FORM_TITLE'); + my $result = ''; $dom_datas{'trt'} = $trt; - if ( $trt ne 'ADD' and $trt ne 'UPD' and $trt ne 'UP2' and $trt ne 'DEL' ) { - $result = "Trt unknown ( $trt ) !" - } - if ( $trt eq 'ADD' ) { - #nothing - } - - if ( $trt eq 'UPD' ) { - - my $rec = $ddb->get($domain); - if ( $rec ) { - $dom_datas{domain} = $domain; - $dom_datas{description} = $rec->prop('Description') || ''; - $dom_datas{content} = $rec->prop('Content') || ''; - $dom_datas{nameservers} = $rec->prop('Nameservers') || 'internet'; - } else { - $result = "Domain $domain not found !" - } - } - - if ( $trt eq 'UP2' ) { - - $dom_datas{forwarder} = $cdb->get_prop('dnscache', 'Forwarder') || ''; - $dom_datas{forwarder2} = $cdb->get_prop('dnscache', 'Forwarder2') || ''; - - } - - if ( $trt eq 'DEL' ) { - - my $rec = $ddb->get($domain); - if ( $rec ) { - $dom_datas{domain} = $domain; - $dom_datas{description} = $rec->prop('Description') || ''; - } - } - - if ( $trt eq 'LST' ) { - my @domains; - if ($adb) { - @domains = $ddb->domains(); - } - $c->stash( domains => \@domains ); - - } - - if ( ! $result ) { - $c->stash( error => $result ); + if ($trt ne 'ADD' and $trt ne 'UPD' and $trt ne 'UP2' and $trt ne 'DEL') { + $result = "Trt unknown ( $trt ) !"; } - $c->stash( title => $title, dom_datas => \%dom_datas ); - $c->render( template => 'domains' ); -}; + if ($trt eq 'ADD') { + #nothing + } + + if ($trt eq 'UPD') { + my $rec = $ddb->get($domain); + + if ($rec) { + $dom_datas{domain} = $domain; + $dom_datas{description} = $rec->prop('Description') || ''; + $dom_datas{content} = $rec->prop('Content') || ''; + $dom_datas{nameservers} = $rec->prop('Nameservers') || 'internet'; + } else { + $result = "Domain $domain not found !"; + } + } ## end if ($trt eq 'UPD') + + if ($trt eq 'UP2') { + $dom_datas{forwarder} = $cdb->get_prop('dnscache', 'Forwarder') || ''; + $dom_datas{forwarder2} = $cdb->get_prop('dnscache', 'Forwarder2') || ''; + } + + if ($trt eq 'DEL') { + my $rec = $ddb->get($domain); + + if ($rec) { + $dom_datas{domain} = $domain; + $dom_datas{description} = $rec->prop('Description') || ''; + } + } ## end if ($trt eq 'DEL') + + if ($trt eq 'LST') { + my @domains; + + if ($adb) { + @domains = $ddb->domains(); + } + $c->stash(domains => \@domains); + } ## end if ($trt eq 'LST') + + if (!$result) { + $c->stash(error => $result); + } + $c->stash(title => $title, dom_datas => \%dom_datas); + $c->render(template => 'domains'); +} ## end sub do_display sub do_update { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = $c->param('trt'); - + my $rt = $c->current_route; + my $trt = $c->param('trt'); my %dom_datas = (); my ($res, $result) = ''; #my $domain = uri_unescape($c->param('domain')); my $domain = $c->param('Domain'); - if ( $trt eq 'ADD' ) { - + if ($trt eq 'ADD') { my $account = $c->param('Account'); - # controls (validate ?????) - #? validate_new_domain_name( $c, $domain, $account ); - #$result .= $res unless $res eq 'OK'; + # controls (validate ?????) + #? validate_new_domain_name( $c, $domain, $account ); + #$result .= $res unless $res eq 'OK'; + #$result .= ' blocked'; + $res = ''; - #$result .= ' blocked'; - - $res = ''; - if ( ! $result ) { - $res = $c->create_modify_domain( 'create', $domain ); - $result .= $res unless $res eq 'OK'; - } - - if ( ! $result ) { - $result = $c->l('dom_SUCCESSFULLY_CREATED') . " $domain"; - } - } + if (!$result) { + $res = $c->create_modify_domain('create', $domain); + $result .= $res unless $res eq 'OK'; + } - if ( $trt eq 'UPD' ) { + if (!$result) { + $result = $c->l('dom_SUCCESSFULLY_CREATED') . " $domain"; + } + } ## end if ($trt eq 'ADD') + if ($trt eq 'UPD') { my $description = $c->param('Description'); - my $content = $c->param('Content'); + my $content = $c->param('Content'); my $nameservers = $c->param('Nameservers'); - # controls - #$res = validate_description( $c, $account ); - #$result .= $res unless $res eq 'OK'; + # controls + #$res = validate_description( $c, $account ); + #$result .= $res unless $res eq 'OK'; + #$result .= 'blocked'; + $res = ''; - #$result .= 'blocked'; + if (!$result) { + $res = $c->create_modify_domain('modify', $domain); + $result .= $res unless $res eq 'OK'; + } - $res = ''; - if ( ! $result ) { - $res = $c->create_modify_domain( 'modify', $domain ); - $result .= $res unless $res eq 'OK'; - } + if (!$result) { + $result = $c->l('dom_SUCCESSFULLY_MODIFIED') . " $domain"; + } + } ## end if ($trt eq 'UPD') - if ( ! $result ) { - $result = $c->l('dom_SUCCESSFULLY_MODIFIED') . " $domain"; - } - } - - - if ( $trt eq 'UP2' ) { - - my $forwarder = $c->param('Forwarder'); + if ($trt eq 'UP2') { + my $forwarder = $c->param('Forwarder'); my $forwarder2 = $c->param('Forwarder2'); - # controls + # controls + $res = $c->ip_number_or_blank($forwarder); + $result .= $res unless $res eq 'OK'; + $res = $c->ip_number_or_blank($forwarder2); + $result .= $res unless $res eq 'OK'; - $res = $c->ip_number_or_blank( $forwarder ); - $result .= $res unless $res eq 'OK'; + #$result .= 'blocked'; + $res = ''; - $res = $c->ip_number_or_blank( $forwarder2 ); - $result .= $res unless $res eq 'OK'; - - #$result .= 'blocked'; - - $res = ''; - if ( ! $result ) { - $res = $c->modify_dns( $forwarder, $forwarder2 ); - $result .= $res unless $res eq 'OK'; - } - if ( ! $result ) { - $result = $c->l('SUCCESS') . " $forwarder $forwarder2"; - } - } + if (!$result) { + $res = $c->modify_dns($forwarder, $forwarder2); + $result .= $res unless $res eq 'OK'; + } + if (!$result) { + $result = $c->l('SUCCESS') . " $forwarder $forwarder2"; + } + } ## end if ($trt eq 'UP2') - if ( $trt eq 'DEL' ) { + if ($trt eq 'DEL') { - # controls - #$res = validate_is_domain($c, $domain); - #$result .= $res unless $res eq 'OK'; - - #$result .= 'blocked'; - - $res = ''; - if ( ! $result ) { - $res = $c->delete_domain( $domain ); - $result .= $res unless $res eq 'OK'; - } - if ( ! $result ) { - $result = $c->l('dom_SUCCESSFULLY_DELETED') . " $domain"; - } - } + # controls + #$res = validate_is_domain($c, $domain); + #$result .= $res unless $res eq 'OK'; + #$result .= 'blocked'; + $res = ''; + + if (!$result) { + $res = $c->delete_domain($domain); + $result .= $res unless $res eq 'OK'; + } + + if (!$result) { + $result = $c->l('dom_SUCCESSFULLY_DELETED') . " $domain"; + } + } ## end if ($trt eq 'DEL') # common parts - if ($res ne 'OK') { - my $title = $c->l('dom_FORM_TITLE'); - $dom_datas{'domain'} = $domain; - $dom_datas{'trt'} = $trt; - - $c->stash( error => $result . "($res)" ); - $c->stash( title => $title, dom_datas => \%dom_datas ); - return $c->render( 'domains' ); - } - + my $title = $c->l('dom_FORM_TITLE'); + $dom_datas{'domain'} = $domain; + $dom_datas{'trt'} = $trt; + $c->stash(error => $result . "($res)"); + $c->stash(title => $title, dom_datas => \%dom_datas); + return $c->render('domains'); + } ## end if ($res ne 'OK') my $message = "'Domains' updates ($trt) DONE"; $c->app->log->info($message); - - $c->flash( success => $result ); + $c->flash(success => $result); $c->redirect_to('/domains'); - -}; - +} ## end sub do_update sub create_modify_domain { - my ($c, $action, $domain) = @_; - $domain = $1 if ($domain =~ /^($REGEXP_DOMAIN)$/); - unless ($domain) { - return ($c->l($action eq 'create' ? 'dom_ERROR_CREATING_DOMAIN' - : 'dom_ERROR_MODIFYING_DOMAIN') . ' Ctl'); - } + unless ($domain) { + return ( + $c->l( + $action eq 'create' + ? 'dom_ERROR_CREATING_DOMAIN' + : 'dom_ERROR_MODIFYING_DOMAIN' + ) + . ' Ctl' + ); + } ## end unless ($domain) my $rec = $ddb->get($domain); + if ($rec and $action eq 'create') { return $c->l('dom_DOMAIN_IN_USE_ERROR'); } + if (not $rec and $action eq 'modify') { return $c->l('dom_NONEXISTENT_DOMAIN_ERROR'); } - $rec ||= $ddb->new_record($domain, { type => 'domain' }); my %props; - $props{$_} = $c->param($_) for ( qw(Content Description Nameservers) ); + $props{$_} = $c->param($_) for (qw(Content Description Nameservers)); $rec->merge_props(%props); - if ( system( "/sbin/e-smith/signal-event", - "domain-$action", "$domain" ) != 0 ) { - return ($c->l($action eq 'create' ? 'dom_ERROR_CREATING_DOMAIN' - : 'dom_ERROR_MODIFYING_DOMAIN') . " Exe $action"); - } - + if (system("/sbin/e-smith/signal-event", "domain-$action", "$domain") != 0) { + return ( + $c->l( + $action eq 'create' + ? 'dom_ERROR_CREATING_DOMAIN' + : 'dom_ERROR_MODIFYING_DOMAIN' + ) + . " Exe $action" + ); + } ## end if (system("/sbin/e-smith/signal-event"...)) return 'OK'; -} - +} ## end sub create_modify_domain sub delete_domain { - my ($c, $domain) = @_; - $domain = $1 if ($domain =~ /^($REGEXP_DOMAIN)$/); return ($c->l('dom_ERROR_WHILE_REMOVING_DOMAIN') . ' Ctl') unless ($domain); - my $rec = $ddb->get($domain); return ($c->l('dom_NONEXISTENT_DOMAIN_ERROR')) if (not $rec); - $rec->set_prop('type', 'domain-deleted'); if (system("/sbin/e-smith/signal-event", "domain-delete", "$domain") != 0) { - return ($c->l('dom_ERROR_WHILE_REMOVING_DOMAIN') . 'Exe'); + return ($c->l('dom_ERROR_WHILE_REMOVING_DOMAIN') . 'Exe'); } - $rec->delete; return 'OK'; -} - +} ## end sub delete_domain sub modify_dns { - my ($c, $forwarder, $forwarder2) = @_; - my $dnscache = $cdb->get('dnscache'); - ($forwarder, $forwarder2) = ($forwarder2, '') if ($forwarder2 and not $forwarder); if ($forwarder) { - $dnscache->set_prop('Forwarder', $forwarder); + $dnscache->set_prop('Forwarder', $forwarder); } else { - $dnscache->delete_prop('Forwarder'); - } - - if ($forwarder2) { - $dnscache->set_prop('Forwarder2', $forwarder2); - } else { - $dnscache->delete_prop('Forwarder2'); + $dnscache->delete_prop('Forwarder'); } - unless ( system( "/sbin/e-smith/signal-event", "dns-update" ) == 0 ) - { + if ($forwarder2) { + $dnscache->set_prop('Forwarder2', $forwarder2); + } else { + $dnscache->delete_prop('Forwarder2'); + } + + unless (system("/sbin/e-smith/signal-event", "dns-update") == 0) { return $c->l('dom_ERROR_UPDATING'); } - return 'OK'; -} - +} ## end sub modify_dns sub existing_accounts_list { - my $c = shift; - - my @existingAccounts = ( ['Administrator' => 'admin']); + my @existingAccounts = ([ 'Administrator' => 'admin' ]); foreach my $a ($adb->get_all) { if ($a->prop('type') =~ /(user|group)/) { push @existingAccounts, [ $a->key => $a->key ]; } + if ($a->prop('type') eq "domain") { my $target = $adb->get($a->prop('Account')); - unless ($target) - { - warn "WARNING: domain (" . $a->key . ") => missing Account(" - . $a->prop('Account') . ")\n"; + unless ($target) { + warn "WARNING: domain (" . $a->key . ") => missing Account(" . $a->prop('Account') . ")\n"; next; } - push @existingAccounts, [ $a->key, $a->key ] unless ($target->prop('type') eq "domain"); - } - } - - return(\@existingAccounts); -} - + } ## end if ($a->prop('type') eq...) + } ## end foreach my $a ($adb->get_all) + return (\@existingAccounts); +} ## end sub existing_accounts_list sub content_options_list { - my $c = shift; - - my @options = ( [ $c->l('dom_PRIMARY_SITE') => 'Primary' ]); + my @options = ([ $c->l('dom_PRIMARY_SITE') => 'Primary' ]); foreach ($adb->ibays) { - push @options, [ $_->prop('Name') => $_->key ] - if ($_->key ne 'Primary'); + push @options, [ $_->prop('Name') => $_->key ] + if ($_->key ne 'Primary'); } + return \@options; +} ## end sub content_options_list - return \@options -} - - -sub get_content_value -{ - my $c = shift; +sub get_content_value { + my $c = shift; my $domain = shift; - return $domain ? $ddb->get_prop($domain, 'Content') : 'Primary'; -} +} ## end sub get_content_value - -sub get_description_value -{ +sub get_description_value { my $c = shift; - my $domain = $c->param('Domain') || undef; - return $ddb->get_prop($domain, 'Description'); -} - +} ## end sub get_description_value sub nameserver_options_list { - - my $c = shift; + my $c = shift; my $domain = $c->param('Domain') || undef; - - my @opts = qw(localhost internet); + my @opts = qw(localhost internet); push @opts, 'corporate' if ($cdb->get_prop('dnscache', 'Forwarder')); my $ns = ($ddb->get_prop($domain, 'Nameservers') || 'internet'); - push @opts, $ns unless scalar grep { /^$ns$/ } @opts; - + push @opts, $ns unless scalar grep {/^$ns$/} @opts; my @options; + foreach (@opts) { - push @options, [ $c->l( "dom_$_" ) => $_ ]; + push @options, [ $c->l("dom_$_") => $_ ]; } - return \@options; -} - +} ## end sub nameserver_options_list sub get_nameserver_value { my $c = shift; - my $domain = $c->param('Domain') || undef; - return ($ddb->get_prop($domain, 'Nameservers') || 'internet'); -} +} ## end sub get_nameserver_value - -sub validate_Domain -{ - my $c = shift; +sub validate_Domain { + my $c = shift; my $domain = lc shift; + return ($domain =~ /^($REGEXP_DOMAIN)$/) + ? 'OK' + : 'DOMAIN_NAME_VALIDATION_ERROR'; +} ## end sub validate_Domain - return ($domain =~ /^($REGEXP_DOMAIN)$/) ? 'OK' : - 'DOMAIN_NAME_VALIDATION_ERROR'; -} +sub validate_Description { - -sub validate_Description -{ # XXX - FIXME - NOTREACHED # We used to use the Description in the Appletalk volume name # which meant it needed validation. I don't see any reason to # do this any more - - my $c = shift; + my $c = shift; my $description = shift; - - return ($description =~ /^([\-\'\w][\-\'\w\s\.]*)$/) ? 'OK' : - 'DOMAIN_DESCRIPTION_VALIDATION_ERROR'; -} - + return ($description =~ /^([\-\'\w][\-\'\w\s\.]*)$/) + ? 'OK' + : 'DOMAIN_DESCRIPTION_VALIDATION_ERROR'; +} ## end sub validate_Description sub ip_number_or_blank { # XXX - FIXME - we should push this down into CGI::FormMagick - - my $c = shift; + my $c = shift; my $ip = shift; - if (!defined($ip) || $ip eq "") - { + if (!defined($ip) || $ip eq "") { return 'OK'; } - - return ip_number( $c, $ip ); -} - + return ip_number($c, $ip); +} ## end sub ip_number_or_blank sub ip_number { -# from CGI::FormMagick::Validator qw( ip_number ); - + # from CGI::FormMagick::Validator qw( ip_number ); my ($c, $data) = @_; - return undef unless defined $data; - return $c->l('FM_IP_NUMBER1') unless $data =~ /^[\d.]+$/; - my @octets = split /\./, $data; my $dots = ($data =~ tr/.//); - return $c->l('FM_IP_NUMBER2') unless (scalar @octets == 4 and $dots == 3); foreach my $octet (@octets) { return $c->l("FM_IP_NUMBER3", $octet) if $octet > 255; } - return 'OK'; -} - - - +} ## end sub ip_number 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings.pm index 1df86a5..2200859 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings.pm @@ -11,909 +11,721 @@ package SrvMngr::Controller::Emailsettings; 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 ip_number_or_blank); - use esmith::ConfigDB; use esmith::AccountsDB; - use esmith::util; use File::Basename; - our $pattern_db = esmith::ConfigDB->open("mailpatterns"); our $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; - sub main { - my $c = shift; $c->app->log->info($c->log_req); - my %mai_datas = (); - my $title = $c->l('mai_FORM_TITLE'); - + my $title = $c->l('mai_FORM_TITLE'); $mai_datas{'trt'} = 'LIST'; $mai_datas{fetchmailmethod} = $c->l($cdb->get_prop('fetchmail', 'Method')); - - $c->stash( title => $title, notif => '', mai_datas => \%mai_datas ); + $c->stash(title => $title, notif => '', mai_datas => \%mai_datas); $c->render(template => 'emailsettings'); - -}; - +} ## end sub main sub do_display { - - my $c = shift; - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LIST'); - + my $c = shift; + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); my %mai_datas = (); - my $title = $c->l('mai_FORM_TITLE'); + my $title = $c->l('mai_FORM_TITLE'); my ($notif, $dest) = ''; - $mai_datas{'trt'} = $trt; - $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; + $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; - if ( $trt eq 'ACC' ) - { - $dest = 'emailaccess'; - $mai_datas{fetchmailmethod} = $cdb->get_prop('fetchmail', 'Method'); + if ($trt eq 'ACC') { + $dest = 'emailaccess'; + $mai_datas{fetchmailmethod} = $cdb->get_prop('fetchmail', 'Method'); } - if ( $trt eq 'FIL' ) - { - $dest = 'emailfilter'; - $mai_datas{'virusstatus'} = $c->get_virus_status(); - $mai_datas{'spamstatus'} = $cdb->get_prop('spamassassin', 'status'); - $mai_datas{'spamsensitivity'} = $cdb->get_prop('spamassassin', 'Sensitivity','medium'); - $mai_datas{'spamtaglevel'} = $cdb->get_prop('spamassassin', 'TagLevel') || '0'; - $mai_datas{'spamrejectlevel'} = $cdb->get_prop('spamassassin', 'RejectLevel') || '0'; - $mai_datas{spamsortspam} = $cdb->get_prop('spamassassin', 'SortSpam'); - $mai_datas{spamsubjecttag} = $cdb->get_prop('spamassassin', 'SubjectTag'); - $mai_datas{spamsubject} = $cdb->get_prop('spamassassin', 'Subject'); - } + if ($trt eq 'FIL') { + $dest = 'emailfilter'; + $mai_datas{'virusstatus'} = $c->get_virus_status(); + $mai_datas{'spamstatus'} = $cdb->get_prop('spamassassin', 'status'); + $mai_datas{'spamsensitivity'} = $cdb->get_prop('spamassassin', 'Sensitivity', 'medium'); + $mai_datas{'spamtaglevel'} = $cdb->get_prop('spamassassin', 'TagLevel') || '0'; + $mai_datas{'spamrejectlevel'} = $cdb->get_prop('spamassassin', 'RejectLevel') || '0'; + $mai_datas{spamsortspam} = $cdb->get_prop('spamassassin', 'SortSpam'); + $mai_datas{spamsubjecttag} = $cdb->get_prop('spamassassin', 'SubjectTag'); + $mai_datas{spamsubject} = $cdb->get_prop('spamassassin', 'Subject'); + } ## end if ($trt eq 'FIL') - if ( $trt eq 'REC' ) - { - $dest = 'emailreceive'; - $mai_datas{fetchmailmethod} = $cdb->get_prop('fetchmail', 'Method'); - $mai_datas{freqoffice} = $cdb->get_prop('fetchmail', 'FreqOffice'); - $mai_datas{freqoutside} = $cdb->get_prop('fetchmail', 'FreqOutside'); - $mai_datas{freqweekend} = $cdb->get_prop('fetchmail', 'FreqWeekend'); - $mai_datas{secondarymailserver} = $cdb->get_prop('fetchmail', 'SecondaryMailServer'); - $mai_datas{secondarymailaccount} = $cdb->get_prop('fetchmail', 'SecondaryMailAccount'); - $mai_datas{secondarymailpassword} = $cdb->get_prop('fetchmail', 'SecondaryMailPassword'); - $mai_datas{specifyheader} = get_secondary_mail_use_envelope(); - $mai_datas{secondarymailenvelope} = $cdb->get_prop('fetchmail', 'SecondaryMailEnvelope'); - - } - - if ( $trt eq 'DEL' ) - { - $dest = 'emaildeliver'; - $mai_datas{emailunknownuser} = $cdb->get_value('EmailUnknownUser') || '"returntosender'; - $mai_datas{delegatemailserver} = $cdb->get_value('DelegateMailServer'); - $mai_datas{smtpsmarthost} = $cdb->get_value('SMTPSmartHost'); - $mai_datas{smtpauthproxystatus} = $cdb->get_prop('smtp-auth-proxy', 'status') || 'disabled'; - $mai_datas{smtpauthproxyuserid} = $cdb->get_prop('smtp-auth-proxy', 'Userid') || ''; - $mai_datas{smtpauthproxypassword} = $cdb->get_prop('smtp-auth-proxy', 'Passwd') || ''; - } - - - $c->stash( title => $title, notif => $notif, mai_datas => \%mai_datas ); - return $c->render( template => $dest ); - -}; + if ($trt eq 'REC') { + $dest = 'emailreceive'; + $mai_datas{fetchmailmethod} = $cdb->get_prop('fetchmail', 'Method'); + $mai_datas{freqoffice} = $cdb->get_prop('fetchmail', 'FreqOffice'); + $mai_datas{freqoutside} = $cdb->get_prop('fetchmail', 'FreqOutside'); + $mai_datas{freqweekend} = $cdb->get_prop('fetchmail', 'FreqWeekend'); + $mai_datas{secondarymailserver} = $cdb->get_prop('fetchmail', 'SecondaryMailServer'); + $mai_datas{secondarymailaccount} = $cdb->get_prop('fetchmail', 'SecondaryMailAccount'); + $mai_datas{secondarymailpassword} = $cdb->get_prop('fetchmail', 'SecondaryMailPassword'); + $mai_datas{specifyheader} = get_secondary_mail_use_envelope(); + $mai_datas{secondarymailenvelope} = $cdb->get_prop('fetchmail', 'SecondaryMailEnvelope'); + } ## end if ($trt eq 'REC') + if ($trt eq 'DEL') { + $dest = 'emaildeliver'; + $mai_datas{emailunknownuser} = $cdb->get_value('EmailUnknownUser') || '"returntosender'; + $mai_datas{delegatemailserver} = $cdb->get_value('DelegateMailServer'); + $mai_datas{smtpsmarthost} = $cdb->get_value('SMTPSmartHost'); + $mai_datas{smtpauthproxystatus} = $cdb->get_prop('smtp-auth-proxy', 'status') || 'disabled'; + $mai_datas{smtpauthproxyuserid} = $cdb->get_prop('smtp-auth-proxy', 'Userid') || ''; + $mai_datas{smtpauthproxypassword} = $cdb->get_prop('smtp-auth-proxy', 'Passwd') || ''; + } ## end if ($trt eq 'DEL') + $c->stash(title => $title, notif => $notif, mai_datas => \%mai_datas); + return $c->render(template => $dest); +} ## end sub do_display sub do_update { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = $c->param('trt'); - + my $rt = $c->current_route; + my $trt = $c->param('trt'); my %mai_datas = (); $mai_datas{trt} = $trt; - $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; - + $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; my $title = $c->l('mai_FORM_TITLE'); - my ($dest, $res, $result) = ''; - if ( $trt eq 'ACC' ) - { - $dest = 'emailaccess'; - # $mai_datas{xxx} = $c->param('XXX'); - - # controls - # $res = xxxxxxx( $c ); - # $result .= $res unless $res eq 'OK'; + if ($trt eq 'ACC') { + $dest = 'emailaccess'; - if ( ! $result ) - { - $res = $c->change_settings_access(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) - { - $result = $c->l('mai_SUCCESS'); - } - } - } + # $mai_datas{xxx} = $c->param('XXX'); + # controls + # $res = xxxxxxx( $c ); + # $result .= $res unless $res eq 'OK'; + if (!$result) { + $res = $c->change_settings_access(); + $result .= $res unless $res eq 'OK'; - if ( $trt eq 'FIL' ) - { - $dest = 'emailfilter'; - # $mai_datas{xxx} = $c->param('XXX'); - - # controls - # $res = zzzzzz( $c ); - # $result .= $res unless $res eq 'OK'; + if (!$result) { + $result = $c->l('mai_SUCCESS'); + } + } ## end if (!$result) + } ## end if ($trt eq 'ACC') - if ( ! $result ) - { - $res = $c->change_settings_filtering(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) - { - $result = $c->l('mai_SUCCESS'); - } - } - } + if ($trt eq 'FIL') { + $dest = 'emailfilter'; - if ( $trt eq 'REC' ) - { - $dest = 'emailreceive'; - # $mai_datas{xxx} = $c->param('XXX'); - - # controls - # $res = yyyyyyyyy( $c ); - # $result .= $res unless $res eq 'OK'; + # $mai_datas{xxx} = $c->param('XXX'); + # controls + # $res = zzzzzz( $c ); + # $result .= $res unless $res eq 'OK'; + if (!$result) { + $res = $c->change_settings_filtering(); + $result .= $res unless $res eq 'OK'; - if ( ! $result ) - { - $res = $c->change_settings_reception(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) - { - $result = $c->l('mai_SUCCESS'); - } - } - } + if (!$result) { + $result = $c->l('mai_SUCCESS'); + } + } ## end if (!$result) + } ## end if ($trt eq 'FIL') - if ( $trt eq 'DEL' ) - { - $dest = 'emaildeliver'; - # $mai_datas{xxx} = $c->param('XXX'); - - # controls - $res = $c->ip_number_or_blank( $c->param('DelegateMailServer') ); - $result .= $res . ' DMS
' unless $res eq 'OK'; + if ($trt eq 'REC') { + $dest = 'emailreceive'; - $res = $c->validate_smarthost( $c->param('SMTPSmartHost') ); - $result .= $res . ' SH
' unless $res eq 'OK'; + # $mai_datas{xxx} = $c->param('XXX'); + # controls + # $res = yyyyyyyyy( $c ); + # $result .= $res unless $res eq 'OK'; + if (!$result) { + $res = $c->change_settings_reception(); + $result .= $res unless $res eq 'OK'; - $res = $c->nonblank_if_smtpauth( $c->param('SMTPSmartHost') ); - $result .= $res . ' SH
' unless $res eq 'OK'; + if (!$result) { + $result = $c->l('mai_SUCCESS'); + } + } ## end if (!$result) + } ## end if ($trt eq 'REC') - $res = $c->nonblank_if_smtpauth( $c->param('SMTPAUTHPROXY_Userid') ); - $result .= $res . ' USR
' unless $res eq 'OK'; + if ($trt eq 'DEL') { + $dest = 'emaildeliver'; - $res = $c->nonblank_if_smtpauth( $c->param('SMTPAUTHPROXY_Passwd') ); - $result .= $res . ' PWD
' unless $res eq 'OK'; + # $mai_datas{xxx} = $c->param('XXX'); + # controls + $res = $c->ip_number_or_blank($c->param('DelegateMailServer')); + $result .= $res . ' DMS
' unless $res eq 'OK'; + $res = $c->validate_smarthost($c->param('SMTPSmartHost')); + $result .= $res . ' SH
' unless $res eq 'OK'; + $res = $c->nonblank_if_smtpauth($c->param('SMTPSmartHost')); + $result .= $res . ' SH
' unless $res eq 'OK'; + $res = $c->nonblank_if_smtpauth($c->param('SMTPAUTHPROXY_Userid')); + $result .= $res . ' USR
' unless $res eq 'OK'; + $res = $c->nonblank_if_smtpauth($c->param('SMTPAUTHPROXY_Passwd')); + $result .= $res . ' PWD
' unless $res eq 'OK'; - if ( ! $result ) - { - $res = $c->change_settings_delivery(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) - { - $result = $c->l('mai_SUCCESS'); - } - } - } + if (!$result) { + $res = $c->change_settings_delivery(); + $result .= $res unless $res eq 'OK'; + if (!$result) { + $result = $c->l('mai_SUCCESS'); + } + } ## end if (!$result) + } ## end if ($trt eq 'DEL') # common part - - if ($res ne 'OK') - { - $c->stash( error => $result ); - $c->stash( title => $title, mai_datas => \%mai_datas ); - return $c->render( $dest ); - } - + if ($res ne 'OK') { + $c->stash(error => $result); + $c->stash(title => $title, mai_datas => \%mai_datas); + return $c->render($dest); + } my $message = "emailsettings updates $trt DONE"; $c->app->log->info($message); - $c->flash( success => $result ); - + $c->flash(success => $result); $c->redirect_to("/emailsettings"); - -}; +} ## end sub do_update sub get_virus_status { - my ($c, $localise) = @_; - my $status = $cdb->get_prop("qpsmtpd", 'VirusScan') || 'disabled'; - return $localise ? $c->localise_status($status) : $status; -} +} ## end sub get_virus_status sub get_spam_status { - my ($c, $localise) = @_; - my $status = $cdb->get_prop('spamassassin', 'status') || 'disabled'; - return $localise ? $c->localise_status($status) : $status; -} - +} ## end sub get_spam_status sub localise_status { - my ($c, $status) = @_; - return $c->l($status eq 'enabled' ? $c->l('ENABLED') : $c->l('DISABLED')); } - sub get_db_prop { - my ($c, $item, $prop, $default) = @_; - return $cdb->get_prop($item, $prop) || $default; } - sub get_value { - - my $c = shift; + my $c = shift; my $item = shift; - return $cdb->get_value($item) || ''; -} - +} ## end sub get_value sub get_emailunknownuser_status { - my ($c, $localise) = @_; - my $options = $c->get_emailunknownuser_options(); - my $val = $cdb->get_value('EmailUnknownUser') || "returntosender"; - return $localise ? $c->l($options->{$val}) : $val; -} - +} ## end sub get_emailunknownuser_status sub get_patterns_status { - my ($c, $localise) = @_; - my $status = $cdb->get_prop("qpsmtpd", 'PatternsScan') || 'disabled'; - return $localise ? $c->localise_status($status) : $status; -} - +} ## end sub get_patterns_status sub adjust_patterns { + my $c = shift; + my @selected = @{ $c->every_param('BlockExecutableContent') }; - my $c = shift; - - my @selected = @{$c->every_param('BlockExecutableContent')}; - - foreach my $pattern ( $pattern_db->get_all_by_prop( type => "pattern") ) - { - my $status = (grep $pattern->key eq $_, @selected) ? 'enabled' - : 'disabled'; + foreach my $pattern ($pattern_db->get_all_by_prop(type => "pattern")) { + my $status + = (grep $pattern->key eq $_, @selected) + ? 'enabled' + : 'disabled'; $pattern->set_prop('Status', $status); - } - + } ## end foreach my $pattern ($pattern_db...) $pattern_db->reload; - return scalar @selected; - -} - +} ## end sub adjust_patterns sub get_current_pop3_access { - my ($c, $localise) = @_; - - my $pop3Status = $cdb->get_prop('pop3', 'status') || 'enabled'; - my $pop3Access = $cdb->get_prop('pop3', 'access') || 'private'; - + my $pop3Status = $cdb->get_prop('pop3', 'status') || 'enabled'; + my $pop3Access = $cdb->get_prop('pop3', 'access') || 'private'; my $pop3sStatus = $cdb->get_prop('pop3s', 'status') || 'enabled'; my $pop3sAccess = $cdb->get_prop('pop3s', 'access') || 'private'; + my $options = get_pop_options(); - my $options = get_pop_options(); - - if ($pop3Status ne 'enabled' && $pop3sStatus ne 'enabled') - { + if ($pop3Status ne 'enabled' && $pop3sStatus ne 'enabled') { return $localise ? $c->l($options->{disabled}) : 'disabled'; - } - elsif ($pop3Status eq 'enabled' && $pop3Access eq 'public') - { + } elsif ($pop3Status eq 'enabled' && $pop3Access eq 'public') { return $localise ? $c->l($options->{public}) : 'public'; - } - elsif ($pop3sStatus eq 'enabled' && $pop3sAccess eq 'public') - { + } elsif ($pop3sStatus eq 'enabled' && $pop3sAccess eq 'public') { return $localise ? $c->l($options->{publicSSL}) : 'publicSSL'; } return $localise ? $c->l($options->{private}) : 'private'; -} - +} ## end sub get_current_pop3_access sub get_current_imap_access { - my ($c, $localise) = @_; - - my $imapStatus = $cdb->get_prop('imap', 'status') || 'enabled'; - my $imapAccess = $cdb->get_prop('imap', 'access') || 'private'; - + my $imapStatus = $cdb->get_prop('imap', 'status') || 'enabled'; + my $imapAccess = $cdb->get_prop('imap', 'access') || 'private'; my $imapsStatus = $cdb->get_prop('imaps', 'status') || 'enabled'; my $imapsAccess = $cdb->get_prop('imaps', 'access') || 'private'; + my $options = get_imap_options(); - my $options = get_imap_options(); - - if (($imapStatus ne 'enabled' || $imapAccess eq 'localhost') && $imapsStatus ne 'enabled') - { + if (($imapStatus ne 'enabled' || $imapAccess eq 'localhost') && $imapsStatus ne 'enabled') { return $localise ? $c->l($options->{disabled}) : 'disabled'; } - if ($imapStatus eq 'enabled' && $imapAccess eq 'public') - { + + if ($imapStatus eq 'enabled' && $imapAccess eq 'public') { return $localise ? $c->l($options->{public}) : 'public'; - } - elsif ($imapsStatus eq 'enabled' && $imapsAccess eq 'public') - { + } elsif ($imapsStatus eq 'enabled' && $imapsAccess eq 'public') { return $localise ? $c->l($options->{publicSSL}) : 'publicSSL'; } return $localise ? $c->l($options->{private}) : 'private'; -} - +} ## end sub get_current_imap_access sub get_current_smtp_ssl_auth { my ($c, $localise, $soru, $debug) = @_; die "Error: \$soru must be either 's' or 'u':$soru.\n" unless $soru eq 's' || $soru eq 'u'; - - $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; + $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; # Initialize variables with default values my $smtpStatus = 'none'; my $smtpAccess = 'none'; - my $smtpAuth = 'disabled'; # assuming 'disabled' as a default - - + my $smtpAuth = 'disabled'; # assuming 'disabled' as a default # Fetch SMTP settings based on the value of `$soru` if ($soru eq "u") { - $smtpStatus = $cdb->get_prop('uqpsmtpd', 'status') || 'enabled'; # Fetch from uqpsmtpd + $smtpStatus = $cdb->get_prop('uqpsmtpd', 'status') || 'enabled'; # Fetch from uqpsmtpd $smtpAccess = $cdb->get_prop('uqpsmtpd', 'access') || 'public'; - $smtpAuth = 'enabled'; # Assuming authentication is enabled in this context - } else { - $smtpStatus = $cdb->get_prop('sqpsmtpd', 'status') || 'enabled'; # Fetch from sqpsmtpd - $smtpAccess = $cdb->get_prop('sqpsmtpd', 'access') || 'public'; - $smtpAuth = 'enabled'; # Assuming authentication is enabled in this context + $smtpAuth = 'enabled'; # Assuming authentication is enabled in this context + } else { + $smtpStatus = $cdb->get_prop('sqpsmtpd', 'status') || 'enabled'; # Fetch from sqpsmtpd + $smtpAccess = $cdb->get_prop('sqpsmtpd', 'access') || 'public'; + $smtpAuth = 'enabled'; # Assuming authentication is enabled in this context } - + # Retrieve SMTP SSL authentication options my $options = $c->get_smtp_ssl_auth_options(); - - if ($soru eq "u" && $debug ) { - $c->stash('smtp'=>[$smtpStatus,$smtpAccess,$smtpAuth,$soru,$options->{$smtpAccess},$c->l($options->{$smtpAccess})]); -# die "Stop $soru in get_current_smtp_ssl_auth"; - } - + if ($soru eq "u" && $debug) { + $c->stash('smtp' => + [ $smtpStatus, $smtpAccess, $smtpAuth, $soru, $options->{$smtpAccess}, $c->l($options->{$smtpAccess}) ] + ); + + # die "Stop $soru in get_current_smtp_ssl_auth"; + } ## end if ($soru eq "u" && $debug) # Return appropriate message based on SMTP settings if ($smtpStatus eq 'enabled' && $smtpAuth eq 'enabled') { return $localise ? $c->l($options->{$smtpAccess}) : $smtpAccess; } - return $localise ? $c->l($options->{disabled}) : 'disabled'; -} +} ## end sub get_current_smtp_ssl_auth sub get_current_smtp_auth { - my ($c, $localise) = @_; + my $smtpStatus = $cdb->get_prop('qpsmtpd', 'status') || 'enabled'; + my $smtpAuth = $cdb->get_prop('qpsmtpd', 'Authentication') || 'enabled'; + my $options = get_smtp_auth_options(); - my $smtpStatus = $cdb->get_prop('qpsmtpd', 'status') || 'enabled'; - my $smtpAuth = $cdb->get_prop('qpsmtpd', 'Authentication') || 'enabled'; - - my $options = get_smtp_auth_options(); - - if ($smtpStatus eq 'enabled' && $smtpAuth eq 'disabled') - { + if ($smtpStatus eq 'enabled' && $smtpAuth eq 'disabled') { return $localise ? $c->l($options->{public}) : 'public'; - } - elsif ($smtpStatus eq 'enabled' && $smtpAuth eq 'enabled') - { + } elsif ($smtpStatus eq 'enabled' && $smtpAuth eq 'enabled') { return $localise ? $c->l($options->{publicSSL}) : 'publicSSL'; } return $localise ? $c->l($options->{disabled}) : 'disabled'; -} - - - +} ## end sub get_current_smtp_auth sub get_current_webmail_status { + my ($c, $localise) = @_; - my ($c, $localise) = @_; + # determine status of webmail + my $WebmailStatus = "disabled"; + my $RoundcubeStatus = $cdb->get_prop('roundcube', 'status') || 'disabled'; + my $MysqlStatus = $cdb->get_prop('mariadb', 'status') || 'disabled'; + my $PHPStatus = $cdb->get_prop('php81-php-fpm', 'status') || 'disabled'; + my $Networkaccess = $cdb->get_prop('roundcube', 'access') || 'disabled'; - # determine status of webmail - my $WebmailStatus = "disabled"; - - my $RoundcubeStatus = $cdb->get_prop('roundcube', 'status') || 'disabled'; - - my $MysqlStatus = $cdb->get_prop('mariadb', 'status') || 'disabled'; - - my $PHPStatus = $cdb->get_prop('php81-php-fpm', 'status') || 'disabled'; - - my $Networkaccess = $cdb->get_prop('roundcube','access') || 'disabled'; - - # all 3 components must be on for webmail to be working - if ( ( $RoundcubeStatus eq "enabled" ) - && ( $MysqlStatus eq "enabled" ) - && ( $PHPStatus eq "enabled" ) - && ( $Networkaccess eq "public")) + # all 3 components must be on for webmail to be working + if ( ($RoundcubeStatus eq "enabled") + && ($MysqlStatus eq "enabled") + && ($PHPStatus eq "enabled") + && ($Networkaccess eq "public")) { - $WebmailStatus = "enabledSSL"; - } - - elsif ( ( $RoundcubeStatus eq "enabled" ) - && ( $MysqlStatus eq "enabled" ) - && ( $PHPStatus eq "enabled" ) - && ( $Networkaccess eq "private" )) + $WebmailStatus = "enabledSSL"; + } elsif (($RoundcubeStatus eq "enabled") + && ($MysqlStatus eq "enabled") + && ($PHPStatus eq "enabled") + && ($Networkaccess eq "private")) { - $WebmailStatus = "localnetworkSSL"; - } - - my $options = get_webmail_options(); - - return $localise ? $c->l($options->{$WebmailStatus}) - : $WebmailStatus; -} - + $WebmailStatus = "localnetworkSSL"; + } ## end elsif (($RoundcubeStatus ...)) + my $options = get_webmail_options(); + return $localise + ? $c->l($options->{$WebmailStatus}) + : $WebmailStatus; +} ## end sub get_current_webmail_status sub get_pop_opt { - - my $c = shift; - - return [[ $c->l('DISABLED') => 'disabled' ], - [ $c->l('NETWORKS_ALLOW_LOCAL') => 'private' ], - [ $c->l('mai_SECURE_POP3') => 'publicSSL' ], - [ $c->l('mai_INSECURE_POP3') => 'public' ]]; - -} - + my $c = shift; + return [ + [ $c->l('DISABLED') => 'disabled' ], + [ $c->l('NETWORKS_ALLOW_LOCAL') => 'private' ], + [ $c->l('mai_SECURE_POP3') => 'publicSSL' ], + [ $c->l('mai_INSECURE_POP3') => 'public' ] + ]; +} ## end sub get_pop_opt sub get_pop_options { - - my $c = @_; - + my $c = @_; my %options = ( - disabled => 'DISABLED', - private => 'NETWORKS_ALLOW_LOCAL', - publicSSL => 'mai_SECURE_POP3' + disabled => 'DISABLED', + private => 'NETWORKS_ALLOW_LOCAL', + publicSSL => 'mai_SECURE_POP3' ); - my $access = $cdb->get_prop('pop3', 'access') || 'private'; - $options{public} = 'mai_INSECURE_POP3' if ($access eq 'public'); - \%options; -} - +} ## end sub get_pop_options sub get_imap_opt { - - my $c = shift; - - return [[ $c->l('DISABLED') => 'disabled' ], - [ $c->l('NETWORKS_ALLOW_LOCAL') => 'private' ], - [ $c->l('mai_SECURE_IMAP') => 'publicSSL' ], - [ $c->l('mai_INSECURE_IMAP') => 'public' ]]; - -} - + my $c = shift; + return [ + [ $c->l('DISABLED') => 'disabled' ], + [ $c->l('NETWORKS_ALLOW_LOCAL') => 'private' ], + [ $c->l('mai_SECURE_IMAP') => 'publicSSL' ], + [ $c->l('mai_INSECURE_IMAP') => 'public' ] + ]; +} ## end sub get_imap_opt sub get_imap_options { - - my $c = shift; - + my $c = shift; my %options = ( - disabled => 'DISABLED', - private => 'NETWORKS_ALLOW_LOCAL', - publicSSL => 'mai_SECURE_IMAP' + disabled => 'DISABLED', + private => 'NETWORKS_ALLOW_LOCAL', + publicSSL => 'mai_SECURE_IMAP' ); - my $access = $cdb->get_prop('imap', 'access') || 'private'; - $options{public} = 'mai_INSECURE_IMAP' if ($access eq 'public'); - \%options; -} - +} ## end sub get_imap_options sub get_smtp_auth_opt { - my $c = shift; - - return [[ $c->l('mai_SECURE_SMTP') => 'publicSSL'], - [ $c->l('Only allow insecure access') => 'public'], - [ $c->l('DISABLED') => 'disabled'] - ]; -} + return [ + [ $c->l('mai_SECURE_SMTP') => 'publicSSL' ], + [ $c->l('Only allow insecure access') => 'public' ], + [ $c->l('DISABLED') => 'disabled' ] + ]; +} ## end sub get_smtp_auth_opt sub get_smtp_auth_options { - my $c = shift; - - my %options = ( publicSSL => 'mai_SECURE_SMTP', public => 'Only allow insecure access',disabled => 'DISABLED'); - + my %options = (publicSSL => 'mai_SECURE_SMTP', public => 'Only allow insecure access', disabled => 'DISABLED'); return \%options; -} - +} ## end sub get_smtp_auth_options sub get_smtp_ssl_auth_options { - my $c = shift; - - my %options = ( public => 'Allow public access', local => 'Allow local access only',disabled => 'DISABLED'); - + my %options = (public => 'Allow public access', local => 'Allow local access only', disabled => 'DISABLED'); return \%options; -} +} ## end sub get_smtp_ssl_auth_options + sub get_smtp_ssl_auth_opt { - my $c = shift; - - return [[ $c->l('Allow public access') => 'public'], - [ $c->l('Allow local access only') => 'local'], - [ $c->l('DISABLED') => 'disabled'] - ]; -} + return [ + [ $c->l('Allow public access') => 'public' ], + [ $c->l('Allow local access only') => 'local' ], + [ $c->l('DISABLED') => 'disabled' ] + ]; +} ## end sub get_smtp_ssl_auth_opt sub get_key_by_value { my ($hash_ref, $target_value) = @_; - + # Iterate over the hash while (my ($key, $value) = each %$hash_ref) { return $key if $value eq $target_value; } - - return undef; # Return undef if no match is found -} + return undef; # Return undef if no match is found +} ## end sub get_key_by_value + sub get_value_by_key { my ($hash_ref, $key) = @_; - - return $hash_ref->{$key}; # Return the value associated with the key + return $hash_ref->{$key}; # Return the value associated with the key } - sub get_webmail_opt { - - my $c = shift; - - return [[ $c->l('DISABLED') => 'disabled' ], - [ $c->l('mai_ENABLED_SECURE_ONLY') => 'enabledSSL' ], - [ $c->l('mai_ONLY_LOCAL_NETWORK_SSL') => 'localnetworkSSL' ]]; - -} - + my $c = shift; + return [ + [ $c->l('DISABLED') => 'disabled' ], + [ $c->l('mai_ENABLED_SECURE_ONLY') => 'enabledSSL' ], + [ $c->l('mai_ONLY_LOCAL_NETWORK_SSL') => 'localnetworkSSL' ] + ]; +} ## end sub get_webmail_opt sub get_webmail_options { - - my $c = shift; - - my %options = ( - disabled => 'DISABLED', - enabledSSL => 'mai_ENABLED_SECURE_ONLY', - localnetworkSSL => 'mai_ONLY_LOCAL_NETWORK_SSL'); - + my $c = shift; + my %options = ( + disabled => 'DISABLED', + enabledSSL => 'mai_ENABLED_SECURE_ONLY', + localnetworkSSL => 'mai_ONLY_LOCAL_NETWORK_SSL' + ); return \%options; -} - +} ## end sub get_webmail_options sub get_retrieval_opt { - - my $c = shift; - + my $c = shift; return $cdb->get("SystemMode")->value eq "servergateway-private" - ? [ $c->l('mai_MULTIDROP') => 'multidrop'] - : [[ $c->l('mai_STANDARD') => 'standard'], - [ $c->l('mai_ETRN') => 'etrn' ], - [ $c->l('mai_MULTIDROP') => 'multidrop']]; -} - - + ? [ $c->l('mai_MULTIDROP') => 'multidrop' ] + : [ + [ $c->l('mai_STANDARD') => 'standard' ], + [ $c->l('mai_ETRN') => 'etrn' ], + [ $c->l('mai_MULTIDROP') => 'multidrop' ] + ]; +} ## end sub get_retrieval_opt sub get_emailunknownuser_options { - - my $c = shift; - my $accounts = esmith::AccountsDB->open_ro(); - my %existingAccounts = ('admin' => $c->l("mai_FORWARD_TO_ADMIN"), - 'returntosender' => $c->l("mai_RETURN_TO_SENDER") ); + my $c = shift; + my $accounts = esmith::AccountsDB->open_ro(); + my %existingAccounts = ( + 'admin' => $c->l("mai_FORWARD_TO_ADMIN"), + 'returntosender' => $c->l("mai_RETURN_TO_SENDER") + ); foreach my $account ($accounts->get_all) { next if $account->key eq 'everyone'; - if ($account->prop('type') =~ /(user|group|pseudonym)/) { - $existingAccounts{$account->key} = $c->l("mai_FORWARD_TO") . " " . $account->key; - } - } - return(\%existingAccounts); -} + if ($account->prop('type') =~ /(user|group|pseudonym)/) { + $existingAccounts{ $account->key } = $c->l("mai_FORWARD_TO") . " " . $account->key; + } + } ## end foreach my $account ($accounts...) + return (\%existingAccounts); +} ## end sub get_emailunknownuser_options sub get_emailunknownuser_opt { - - my $c = shift; + my $c = shift; my $accounts = esmith::AccountsDB->open_ro(); - - my @existingAccounts = ([ $c->l("mai_FORWARD_TO_ADMIN") => 'admin'], - [ $c->l("mai_RETURN_TO_SENDER") => 'returntosender']); + my @existingAccounts + = ([ $c->l("mai_FORWARD_TO_ADMIN") => 'admin' ], [ $c->l("mai_RETURN_TO_SENDER") => 'returntosender' ]); foreach my $account ($accounts->get_all) { next if $account->key eq 'everyone'; - if ($account->prop('type') =~ /(user|group|pseudonym)/) { - push @existingAccounts, [ $c->l("mai_FORWARD_TO") . " " . $account->key => $account->key]; - } - } - return(\@existingAccounts); -} + if ($account->prop('type') =~ /(user|group|pseudonym)/) { + push @existingAccounts, [ $c->l("mai_FORWARD_TO") . " " . $account->key => $account->key ]; + } + } ## end foreach my $account ($accounts...) + return (\@existingAccounts); +} ## end sub get_emailunknownuser_opt sub get_patterns_opt { - my $c = shift; my @options; - foreach my $pattern ( $pattern_db->get_all_by_prop( type => "pattern" ) ) { + foreach my $pattern ($pattern_db->get_all_by_prop(type => "pattern")) { my %props = $pattern->props; push @options, [ $props{'Description'} => $pattern->key ]; } return \@options; -} - +} ## end sub get_patterns_opt sub get_patterns_current_opt { - my $c = shift; my @selected; - foreach my $pattern ( $pattern_db->get_all_by_prop( type => "pattern" ) ) { + foreach my $pattern ($pattern_db->get_all_by_prop(type => "pattern")) { my %props = $pattern->props; push @selected, $pattern->key if ($props{'Status'} eq 'enabled'); } return \@selected; -} +} ## end sub get_patterns_current_opt sub get_spam_level_options { - - return [ 0..20 ]; + return [ 0 .. 20 ]; } - sub get_spam_sensitivity_opt { - - my $c = shift; - - return [[ $c->l('mai_VERYLOW') => 'verylow' ], - [ $c->l('mai_LOW') => 'low' ], - [ $c->l('mai_MEDIUM') => 'medium' ], - [ $c->l('mai_HIGH') => 'high' ], - [ $c->l('mai_VERYHIGH') => 'veryhigh' ], - [ $c->l('mai_CUSTOM') => 'custom' ]]; - -} - + my $c = shift; + return [ + [ $c->l('mai_VERYLOW') => 'verylow' ], + [ $c->l('mai_LOW') => 'low' ], + [ $c->l('mai_MEDIUM') => 'medium' ], + [ $c->l('mai_HIGH') => 'high' ], + [ $c->l('mai_VERYHIGH') => 'veryhigh' ], + [ $c->l('mai_CUSTOM') => 'custom' ] + ]; +} ## end sub get_spam_sensitivity_opt sub fetchmail_freq { - - my $c = shift; - - return [[ $c->l('mai_NEVER') => 'never' ], - [ $c->l('mai_EVERY5MIN') => 'every5min' ], - [ $c->l('mai_EVERY15MIN') => 'every15min' ], - [ $c->l('mai_EVERY30MIN') => 'every30min' ], - [ $c->l('mai_EVERYHOUR') => 'everyhour' ], - [ $c->l('mai_EVERY2HRS') => 'every2hrs' ]]; -} - + my $c = shift; + return [ + [ $c->l('mai_NEVER') => 'never' ], + [ $c->l('mai_EVERY5MIN') => 'every5min' ], + [ $c->l('mai_EVERY15MIN') => 'every15min' ], + [ $c->l('mai_EVERY30MIN') => 'every30min' ], + [ $c->l('mai_EVERYHOUR') => 'everyhour' ], + [ $c->l('mai_EVERY2HRS') => 'every2hrs' ] + ]; +} ## end sub fetchmail_freq sub display_multidrop { - my $status = $cdb->get_prop('fetchmail', 'status') || 'disabled'; - # XXX FIXME - WIP + # XXX FIXME - WIP # Only display ETRN/multidrop settings if relevant # To do this, we need an "Show ETRN/multidrop settings" button # in standard mode. - # return ($status eq 'enabled'); - return 1; -} - + return 1; +} ## end sub display_multidrop sub change_settings_reception { - my $c = shift; $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; + my $FetchmailMethod = ($c->param('FetchmailMethod') || 'standard'); + my $FetchmailFreqOffice = ($c->param('FreqOffice') || 'every15min'); + my $FetchmailFreqOutside = ($c->param('FreqOutside') || 'everyhour'); + my $FetchmailFreqWeekend = ($c->param('FreqWeekend') || 'everyhour'); + my $SpecifyHeader = ($c->param('SpecifyHeader') || 'off'); + my $fetchmail + = $cdb->get('fetchmail') || $cdb->new_record("fetchmail", { type => "service", status => "disabled" }); - my $FetchmailMethod = ( $c->param('FetchmailMethod') || 'standard' ); + if ($FetchmailMethod eq 'standard') { + $fetchmail->set_prop('status', 'disabled'); + $fetchmail->set_prop('Method', $FetchmailMethod); + } else { + $fetchmail->set_prop('status', 'enabled'); + $fetchmail->set_prop('Method', $FetchmailMethod); + $fetchmail->set_prop('SecondaryMailServer', $c->param('SecondaryMailServer')) + unless ($c->param('SecondaryMailServer') eq ''); + $fetchmail->set_prop('FreqOffice', $FetchmailFreqOffice); + $fetchmail->set_prop('FreqOutside', $FetchmailFreqOutside); + $fetchmail->set_prop('FreqWeekend', $FetchmailFreqWeekend); + $fetchmail->set_prop('SecondaryMailAccount', $c->param('SecondaryMailAccount')) + unless ($c->param('SecondaryMailAccount') eq ''); + $fetchmail->set_prop('SecondaryMailPassword', $c->param('SecondaryMailPassword')) + unless ($c->param('SecondaryMailPassword') eq ''); - my $FetchmailFreqOffice = ( $c->param('FreqOffice') || 'every15min' ); - - my $FetchmailFreqOutside = ( $c->param('FreqOutside') || 'everyhour' ); - my $FetchmailFreqWeekend = ( $c->param('FreqWeekend') || 'everyhour' ); - my $SpecifyHeader = ( $c->param('SpecifyHeader') || 'off' ); - - my $fetchmail = $cdb->get('fetchmail') || $cdb->new_record( "fetchmail", - { type => "service", status => "disabled" } ); - - if ( $FetchmailMethod eq 'standard' ) { - $fetchmail->set_prop( 'status', 'disabled' ); - $fetchmail->set_prop( 'Method', $FetchmailMethod ); - } - else { - $fetchmail->set_prop( 'status', 'enabled' ); - $fetchmail->set_prop( 'Method', $FetchmailMethod ); - $fetchmail->set_prop( 'SecondaryMailServer', - $c->param('SecondaryMailServer') ) - unless ( $c->param('SecondaryMailServer') eq '' ); - - $fetchmail->set_prop('FreqOffice', $FetchmailFreqOffice ); - $fetchmail->set_prop('FreqOutside', $FetchmailFreqOutside ); - $fetchmail->set_prop('FreqWeekend', $FetchmailFreqWeekend ); - $fetchmail->set_prop('SecondaryMailAccount', - $c->param('SecondaryMailAccount') ) - unless ( $c->param('SecondaryMailAccount') eq '' ); - - $fetchmail->set_prop( 'SecondaryMailPassword', - $c->param('SecondaryMailPassword') ) - unless ( $c->param('SecondaryMailPassword') eq '' ); - - if ( $SpecifyHeader eq 'on' ) { - $fetchmail->merge_props( - 'SecondaryMailEnvelope' => $c->param('SecondaryMailEnvelope') ); - } - else { + if ($SpecifyHeader eq 'on') { + $fetchmail->merge_props('SecondaryMailEnvelope' => $c->param('SecondaryMailEnvelope')); + } else { $fetchmail->delete_prop('SecondaryMailEnvelope'); } - } + } ## end else [ if ($FetchmailMethod eq...)] - # Need code here for all 3 options - 25, 465 ad 587 - # Options for 25 are enabled and disabled - # for 465 and 587 are (access) public, local and (status) disabled - - + # Need code here for all 3 options - 25, 465 ad 587 + # Options for 25 are enabled and disabled + # for 465 and 587 are (access) public, local and (status) disabled #my $smtpAuth = ($c->param('SMTPAuth') || 'public'); #if ($smtpAuth eq 'public') { - #$cdb->set_prop("qpsmtpd", "Authentication", "enabled" ); - #$cdb->set_prop("sqpsmtpd", "Authentication", "enabled" ); + #$cdb->set_prop("qpsmtpd", "Authentication", "enabled" ); + #$cdb->set_prop("sqpsmtpd", "Authentication", "enabled" ); #} elsif ($smtpAuth eq 'publicSSL') { - #$cdb->set_prop("qpsmtpd", "Authentication", "disabled" ); - #$cdb->set_prop("sqpsmtpd", "Authentication", "enabled" ); + #$cdb->set_prop("qpsmtpd", "Authentication", "disabled" ); + #$cdb->set_prop("sqpsmtpd", "Authentication", "enabled" ); #} else { - #$cdb->set_prop("qpsmtpd", "Authentication", "disabled" ); - #$cdb->set_prop("sqpsmtpd", "Authentication", "disabled" ); + #$cdb->set_prop("qpsmtpd", "Authentication", "disabled" ); + #$cdb->set_prop("sqpsmtpd", "Authentication", "disabled" ); #} + my @keys = qw(qpsmtpd uqpsmtpd sqpsmtpd); - my @keys = qw(qpsmtpd uqpsmtpd sqpsmtpd); + foreach my $key (@keys) { + my $param_name + = $key eq 'qpsmtpd' ? 'SMTPAuth' + : $key eq 'uqpsmtpd' ? 'uSMTPAuth' + : 'sSMTPAuth'; # Defaults to 'sSMTPAuth' for 'sqpsmtpd' + my $SMTPAuth = $c->param($param_name); - foreach my $key (@keys) { - my $param_name = $key eq 'qpsmtpd' ? 'SMTPAuth' - : $key eq 'uqpsmtpd' ? 'uSMTPAuth' - : 'sSMTPAuth'; # Defaults to 'sSMTPAuth' for 'sqpsmtpd' - my $SMTPAuth = $c->param($param_name); - if ($SMTPAuth eq 'disabled') { - $cdb->set_prop($key, 'status', 'disabled'); - $cdb->set_prop($key, 'access', 'disabled'); - } else { - $cdb->set_prop($key, 'status', 'enabled'); - if ($key eq 'qpsmtpd') { - my $auth_status = $SMTPAuth eq 'publicSSL' ? 'enabled' : 'disabled'; - $cdb->set_prop($key, 'Authentication', $auth_status); - $cdb->set_prop($key, 'access', 'public'); - } else { - $cdb->set_prop($key, 'Authentication', 'enabled'); - my $auth_key = ($key eq 'uqpsmtpd') ? 'uSMTPAuth' : 'sSMTPAuth'; - my $access_value = $c->param($auth_key) eq 'public' ? 'public' : 'local'; - $cdb->set_prop($key, 'access', $access_value); - } - } - } - unless ( system( "/sbin/e-smith/signal-event", "email-update" ) == 0 ) - { - return $c->l('mai_ERROR_UPDATING_CONFIGURATION'); + if ($SMTPAuth eq 'disabled') { + $cdb->set_prop($key, 'status', 'disabled'); + $cdb->set_prop($key, 'access', 'disabled'); + } else { + $cdb->set_prop($key, 'status', 'enabled'); + + if ($key eq 'qpsmtpd') { + my $auth_status = $SMTPAuth eq 'publicSSL' ? 'enabled' : 'disabled'; + $cdb->set_prop($key, 'Authentication', $auth_status); + $cdb->set_prop($key, 'access', 'public'); + } else { + $cdb->set_prop($key, 'Authentication', 'enabled'); + my $auth_key = ($key eq 'uqpsmtpd') ? 'uSMTPAuth' : 'sSMTPAuth'; + my $access_value = $c->param($auth_key) eq 'public' ? 'public' : 'local'; + $cdb->set_prop($key, 'access', $access_value); + } ## end else [ if ($key eq 'qpsmtpd')] + } ## end else [ if ($SMTPAuth eq 'disabled')] + } ## end foreach my $key (@keys) + + unless (system("/sbin/e-smith/signal-event", "email-update") == 0) { + return $c->l('mai_ERROR_UPDATING_CONFIGURATION'); } return 'OK'; -} - +} ## end sub change_settings_reception sub change_settings_delivery { - my ($c) = shift; $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; - my $EmailUnknownUser = ($c->param('EmailUnknownUser') || 'returntosender'); - - $cdb->set_value('SMTPSmartHost', $c->param('SMTPSmartHost')); + $cdb->set_value('SMTPSmartHost', $c->param('SMTPSmartHost')); $cdb->set_value('DelegateMailServer', $c->param('DelegateMailServer')); - $cdb->set_value('EmailUnknownUser', $EmailUnknownUser); - + $cdb->set_value('EmailUnknownUser', $EmailUnknownUser); my $proxy = $cdb->get('smtp-auth-proxy'); my %props = $proxy->props; - for ( qw(Userid Passwd status) ) - { + for (qw(Userid Passwd status)) { $props{$_} = $c->param("SMTPAUTHPROXY_$_"); } - $proxy->merge_props(%props); - unless ( system( "/sbin/e-smith/signal-event", "email-update" ) == 0 ) - { - return $c->l('mai_ERROR_UPDATING_CONFIGURATION'); + unless (system("/sbin/e-smith/signal-event", "email-update") == 0) { + return $c->l('mai_ERROR_UPDATING_CONFIGURATION'); } return 'OK'; -} - +} ## end sub change_settings_delivery sub change_settings_access { - my $c = shift; - $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; - + $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; my $pop3Access = ($c->param('POPAccess') || 'private'); + if ($pop3Access eq 'disabled') { - $cdb->set_prop('pop3', "status", "disabled" ); - $cdb->set_prop('pop3s', "status", "disabled" ); + $cdb->set_prop('pop3', "status", "disabled"); + $cdb->set_prop('pop3s', "status", "disabled"); } else { - $cdb->set_prop('pop3', "status", "enabled" ); - $cdb->set_prop('pop3s', "status", "enabled" ); - } - if ($pop3Access eq 'public') { - $cdb->set_prop('pop3', "access", "public" ); - $cdb->set_prop('pop3s', "access", "public" ); - } elsif ($pop3Access eq 'publicSSL') { - $cdb->set_prop('pop3', "access", "private" ); - $cdb->set_prop('pop3s', "access", "public" ); - } else { - $cdb->set_prop('pop3', "access", "private" ); - $cdb->set_prop('pop3s', "access", "private" ); + $cdb->set_prop('pop3', "status", "enabled"); + $cdb->set_prop('pop3s', "status", "enabled"); } - my $imapAccess = ($c->param('IMAPAccess') || 'private'); - if ($imapAccess eq 'disabled') { - $cdb->set_prop('imap', "status", "enabled" ); - $cdb->set_prop('imap', "access", "localhost" ); - $cdb->set_prop('imaps', "status", "disabled" ); - } elsif ($imapAccess eq 'public') { - $cdb->set_prop('imap', "status", "enabled" ); - $cdb->set_prop('imap', "access", "public" ); - $cdb->set_prop('imaps', "status", "enabled" ); - $cdb->set_prop('imaps', "access", "public" ); - } elsif ($imapAccess eq 'publicSSL') { - $cdb->set_prop('imap', "status", "enabled" ); - $cdb->set_prop('imap', "access", "private" ); - $cdb->set_prop('imaps', "status", "enabled" ); - $cdb->set_prop('imaps', "access", "public" ); + if ($pop3Access eq 'public') { + $cdb->set_prop('pop3', "access", "public"); + $cdb->set_prop('pop3s', "access", "public"); + } elsif ($pop3Access eq 'publicSSL') { + $cdb->set_prop('pop3', "access", "private"); + $cdb->set_prop('pop3s', "access", "public"); } else { - $cdb->set_prop('imap', "status", "enabled" ); - $cdb->set_prop('imap', "access", "private" ); - $cdb->set_prop('imaps', "status", "enabled" ); - $cdb->set_prop('imaps', "access", "private" ); + $cdb->set_prop('pop3', "access", "private"); + $cdb->set_prop('pop3s', "access", "private"); } + my $imapAccess = ($c->param('IMAPAccess') || 'private'); + + if ($imapAccess eq 'disabled') { + $cdb->set_prop('imap', "status", "enabled"); + $cdb->set_prop('imap', "access", "localhost"); + $cdb->set_prop('imaps', "status", "disabled"); + } elsif ($imapAccess eq 'public') { + $cdb->set_prop('imap', "status", "enabled"); + $cdb->set_prop('imap', "access", "public"); + $cdb->set_prop('imaps', "status", "enabled"); + $cdb->set_prop('imaps', "access", "public"); + } elsif ($imapAccess eq 'publicSSL') { + $cdb->set_prop('imap', "status", "enabled"); + $cdb->set_prop('imap', "access", "private"); + $cdb->set_prop('imaps', "status", "enabled"); + $cdb->set_prop('imaps', "access", "public"); + } else { + $cdb->set_prop('imap', "status", "enabled"); + $cdb->set_prop('imap', "access", "private"); + $cdb->set_prop('imaps', "status", "enabled"); + $cdb->set_prop('imaps', "access", "private"); + } ## end else [ if ($imapAccess eq 'disabled')] #------------------------------------------------------------ # Set webmail state in configuration database, and access @@ -921,112 +733,83 @@ sub change_settings_access { # PHP and MySQL should always be on, and are enabled by default # We don't do anything with them here. #------------------------------------------------------------ - my $webmail = ($c->param('WebMail') || 'disabled'); - if ( $webmail eq "enabledSSL" ) { - $cdb->set_prop('php81-php-fpm',"status", "enabled" ); - $cdb->set_prop('mariadb',"status", "enabled" ); - $cdb->set_prop('roundcube',"status", 'enabled' ); - $cdb->set_prop('roundcube',"access", "public" ); + + if ($webmail eq "enabledSSL") { + $cdb->set_prop('php81-php-fpm', "status", "enabled"); + $cdb->set_prop('mariadb', "status", "enabled"); + $cdb->set_prop('roundcube', "status", 'enabled'); + $cdb->set_prop('roundcube', "access", "public"); + } elsif ($webmail eq "localnetworkSSL") { + $cdb->set_prop('php81-php-fpm', "status", "enabled"); + $cdb->set_prop('mariadb', "status", "enabled"); + $cdb->set_prop('roundcube', "status", 'enabled'); + $cdb->set_prop('roundcube', "access", "private"); + } else { + $cdb->set_prop('roundcube', "status", 'disabled'); } - elsif ( $webmail eq "localnetworkSSL" ) { - $cdb->set_prop('php81-php-fpm',"status", "enabled" ); - $cdb->set_prop('mariadb',"status", "enabled" ); - $cdb->set_prop('roundcube',"status", 'enabled' ); - $cdb->set_prop('roundcube',"access", "private" ); - } - - else { - $cdb->set_prop('roundcube',"status", 'disabled' ); + unless (system("/sbin/e-smith/signal-event", "email-update") == 0) { + return $c->l('mai_ERROR_UPDATING_CONFIGURATION'); } - - unless ( system( "/sbin/e-smith/signal-event", "email-update" ) == 0 ) { - return $c->l('mai_ERROR_UPDATING_CONFIGURATION'); - } - return 'OK'; -} - +} ## end sub change_settings_access sub change_settings_filtering { - my $c = shift; $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; - - - my $virus_status = ( $c->param('VirusStatus') || 'disabled' ); + my $virus_status = ($c->param('VirusStatus') || 'disabled'); $cdb->set_prop("qpsmtpd", 'VirusScan', $virus_status); - for my $param ( qw( - status - Sensitivity - TagLevel - RejectLevel - SortSpam - Subject - SubjectTag) ) + for my $param ( + qw( + status + Sensitivity + TagLevel + RejectLevel + SortSpam + Subject + SubjectTag) + ) { - $cdb->set_prop('spamassassin', $param, $c->param("Spam$param")); - } - + $cdb->set_prop('spamassassin', $param, $c->param("Spam$param")); + } ## end for my $param (qw( status...)) my $patterns_status = $c->adjust_patterns() ? 'enabled' : 'disabled'; $cdb->set_prop("qpsmtpd", 'PatternsScan', $patterns_status); - unless ( system( "/sbin/e-smith/signal-event", "email-update" ) == 0 ) - { - return $c->l('mai_ERROR_UPDATING_CONFIGURATION'); + unless (system("/sbin/e-smith/signal-event", "email-update") == 0) { + return $c->l('mai_ERROR_UPDATING_CONFIGURATION'); } - return 'OK'; - -} - +} ## end sub change_settings_filtering #sub blank_or_ip_number { - # my ($c, $value) = @_; - # return 'OK' unless (defined $value); # undef is blank # return 'OK' if ($value =~ /^$/); # blank is blank # return $c->call_fm_validation("ip_number",$value,''); # otherwise, validate the input - #} - - sub nonblank_if_smtpauth { - my ($c, $value) = @_; - return "OK" unless ($c->param("SMTPAUTHPROXY_status") eq 'enabled'); - return ($value =~ /\S+/) ? "OK" : $c->l('mai_VALIDATION_SMTPAUTH_NONBLANK'); - } - sub get_secondary_mail_use_envelope { - my $use_envelope = $cdb->get_prop('fetchmail', 'SecondaryMailEnvelope'); - if ( defined $use_envelope ) { + + if (defined $use_envelope) { return ('on'); } else { return ('off'); } -} - +} ## end sub get_secondary_mail_use_envelope sub validate_smarthost { - my $fm = shift; + my $fm = shift; my $smarthost = shift; - - return ('OK') if ( $smarthost =~ /^(\S+\.\S+)$/ ); - - return ('OK') if ( $smarthost eq '' ); - + return ('OK') if ($smarthost =~ /^(\S+\.\S+)$/); + return ('OK') if ($smarthost eq ''); return "INVALID_SMARTHOST"; - -} - - -1; \ No newline at end of file +} ## end sub validate_smarthost +1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Groups.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Groups.pm index 45aa6c4..d3aeb6c 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Groups.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Groups.pm @@ -11,329 +11,252 @@ package SrvMngr::Controller::Groups; 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::FormMagick::Panel::groups; use esmith::AccountsDB; - -our $cdb = esmith::ConfigDB->open || die "Couldn't open configuration db"; +our $cdb = esmith::ConfigDB->open || die "Couldn't open configuration db"; our $adb = esmith::AccountsDB->open || die "Couldn't open accounts db"; sub main { - my $c = shift; $c->app->log->info($c->log_req); - my %grp_datas = (); - my $title = $c->l('grp_FORM_TITLE'); - + my $title = $c->l('grp_FORM_TITLE'); $grp_datas{trt} = 'LST'; - my @groups; + if ($adb) { @groups = $adb->groups(); } - - $c->stash( title => $title, grp_datas => \%grp_datas, groups => \@groups ); + $c->stash(title => $title, grp_datas => \%grp_datas, groups => \@groups); $c->render(template => 'groups'); - -}; - +} ## end sub main sub do_display { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LST'); - my $group = $c->param('group'); - + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LST'); + my $group = $c->param('group'); my %grp_datas = (); - my $title = $c->l('grp_FORM_TITLE'); - + my $title = $c->l('grp_FORM_TITLE'); $grp_datas{'trt'} = $trt; - if ( $trt eq 'ADD' ) { - #nothing - } + if ($trt eq 'ADD') { + #nothing + } - if ( $trt eq 'UPD' ) { - - my %members = (); - my %users = (); + if ($trt eq 'UPD') { + my %members = (); + my %users = (); + my $rec = $adb->get($group); - my $rec = $adb->get($group); - if ($rec and $rec->prop('type') eq 'group') { + if ($rec and $rec->prop('type') eq 'group') { + $grp_datas{group} = $group; + $grp_datas{description} = $rec->prop('Description') || ''; + %members = @{ $c->gen_members_list($group) }; + } ## end if ($rec and $rec->prop...) + $c->stash(members => \%members, users => \%users); + } ## end if ($trt eq 'UPD') - $grp_datas{group} = $group; - $grp_datas{description} = $rec->prop('Description') || ''; + if ($trt eq 'DEL') { + my %members = (); + my %ibays = (); + my $rec = $adb->get($group); - %members = @{$c->gen_members_list( $group )}; - } + if ($rec and $rec->prop('type') eq 'group') { + $grp_datas{group} = $group; + $grp_datas{description} = $rec->prop('Description') || ''; + %members = @{ $c->gen_members_list($group) }; + %ibays = @{ $c->gen_ibays_list($group) }; + } ## end if ($rec and $rec->prop...) + $c->stash(members => \%members, ibays => \%ibays); + } ## end if ($trt eq 'DEL') - $c->stash( members => \%members, users => \%users ); - - } - - - if ( $trt eq 'DEL' ) { - - my %members = (); - my %ibays = (); - - my $rec = $adb->get($group); - if ($rec and $rec->prop('type') eq 'group') { - - $grp_datas{group} = $group; - $grp_datas{description} = $rec->prop('Description') || ''; - - %members = @{$c->gen_members_list($group)}; - - %ibays = @{$c->gen_ibays_list($group)}; - - } - - $c->stash( members => \%members, ibays => \%ibays ); + if ($trt eq 'LST') { + my @groups; + if ($adb) { + @groups = $adb->groups(); } - - - if ( $trt eq 'LST' ) { - my @groups; - if ($adb) { - @groups = $adb->groups(); - } - - $c->stash( groups => \@groups ); - - } - - $c->stash( title => $title, grp_datas => \%grp_datas ); - $c->render( template => 'groups' ); - -}; - + $c->stash(groups => \@groups); + } ## end if ($trt eq 'LST') + $c->stash(title => $title, grp_datas => \%grp_datas); + $c->render(template => 'groups'); +} ## end sub do_display sub do_update { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LST'); + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LST'); my $groupName = $c->param('groupName') || ''; - - my $title = $c->l('grp_FORM_TITLE'); + my $title = $c->l('grp_FORM_TITLE'); my ($res, $result) = ''; - my %grp_datas = (); - $grp_datas{'trt'} = $trt; + $grp_datas{'trt'} = $trt; $grp_datas{'group'} = $groupName; my @members = (); - if ( $trt eq 'ADD' ) { - + if ($trt eq 'ADD') { my $groupDesc = $c->param('groupDesc'); - @members = @{$c->every_param('groupMembers')}; + @members = @{ $c->every_param('groupMembers') }; + my $members = join(",", @members); - my $members = join ( ",", @members ); + # controls + $res = $c->validate_group($groupName); + $result .= $res . '
' unless $res eq 'OK'; + $res = $c->validate_group_length($groupName); + $result .= $res . '
' unless $res eq 'OK'; + $res = $c->validate_group_naming_conflict($groupName); + $result .= $res . '
' unless $res eq 'OK'; + $res = $c->validate_description($groupDesc); + $result .= $res . '
' unless $res eq 'OK'; + $res = $c->validate_group_has_members(@members); + $result .= $res . '
' unless $res eq 'OK'; + my %props = ('type', 'group', 'Description', $groupDesc, 'Members', $members); + $res = ''; - # controls - $res = $c->validate_group( $groupName ); - $result .= $res . '
' unless $res eq 'OK'; + if (!$result) { + $adb->new_record($groupName, \%props); - $res = $c->validate_group_length( $groupName ); - $result .= $res . '
' unless $res eq 'OK'; + # Untaint groupName before use in system() + ($groupName) = ($groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/); + system("/sbin/e-smith/signal-event", "group-create", "$groupName") == 0 + or $result .= $c->l('qgp_CREATE_ERROR') . "\n"; + } ## end if (!$result) - $res = $c->validate_group_naming_conflict( $groupName ); - $result .= $res . '
' unless $res eq 'OK'; - - $res = $c->validate_description( $groupDesc ); - $result .= $res . '
' unless $res eq 'OK'; - - $res = $c->validate_group_has_members( @members ); - $result .= $res . '
' unless $res eq 'OK'; - - my %props = ( - 'type', 'group', 'Description', - $groupDesc, 'Members', $members - ); - - $res = ''; - if ( ! $result ) { - - $adb->new_record( $groupName, \%props ); - - # Untaint groupName before use in system() - ($groupName) = ($groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/); - - system("/sbin/e-smith/signal-event", "group-create", "$groupName") == 0 - or $result .= $c->l('qgp_CREATE_ERROR')."\n"; - } - if ( ! $result ) { - $result = $c->l('grp_CREATED_GROUP') . ' ' . $groupName; - $res = 'OK'; - } - } - - - if ( $trt eq 'UPD' ) { + if (!$result) { + $result = $c->l('grp_CREATED_GROUP') . ' ' . $groupName; + $res = 'OK'; + } + } ## end if ($trt eq 'ADD') + if ($trt eq 'UPD') { my $groupDesc = $c->param('groupDesc'); - @members = @{$c->every_param('groupMembers')}; - my $members = join ( ",", @members ); + @members = @{ $c->every_param('groupMembers') }; + my $members = join(",", @members); - # controls - $res = ''; - $res = validate_description( $c, $groupDesc ); - $result .= $res . '
' unless $res eq 'OK'; + # controls + $res = ''; + $res = validate_description($c, $groupDesc); + $result .= $res . '
' unless $res eq 'OK'; + $res = validate_group_has_members($c, @members); + $result .= $res . '
' unless $res eq 'OK'; + $res = ''; - $res = validate_group_has_members( $c, @members ); - $result .= $res . '
' unless $res eq 'OK'; + if (!$result) { + $adb->get($groupName)->set_prop('Members', $members); + $adb->get($groupName)->set_prop('Description', $groupDesc); - $res = ''; - if ( ! $result ) { + # Untaint groupName before use in system() + ($groupName) = ($groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/); + system("/sbin/e-smith/signal-event", "group-modify", "$groupName") == 0 + or $result .= $c->l('qgp_MODIFY_ERROR') . "\n"; + } ## end if (!$result) - $adb->get($groupName)->set_prop( 'Members', $members ); - $adb->get($groupName)->set_prop( 'Description', $groupDesc ); + if (!$result) { + $result = $c->l('grp_MODIFIED_GROUP') . ' ' . $groupName; + $res = 'OK'; + } + } ## end if ($trt eq 'UPD') - # Untaint groupName before use in system() - ($groupName) = ($groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/); + if ($trt eq 'DEL') { + if ($groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/) { + $groupName = $1; + } else { + $result .= $c->l('grp_ERR_INTERNAL_FAILURE') . ':' . $groupName; + } + my $rec = $adb->get($groupName); + $result .= $c->l('grp_ERR_INTERNAL_FAILURE') . ':' . $groupName unless ($rec); + $res = ''; - system("/sbin/e-smith/signal-event", "group-modify", "$groupName") ==0 - or $result .= $c->l('qgp_MODIFY_ERROR')."\n"; - } + if (!$result) { + $res = delete_group($c, $groupName); + $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('grp_MODIFIED_GROUP') . ' ' . $groupName; - $res = 'OK'; - } - } - - - if ( $trt eq 'DEL' ) { - - if ($groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/) { - $groupName = $1; - } else { - $result .= $c->l('grp_ERR_INTERNAL_FAILURE') . ':' . $groupName; - } - - my $rec = $adb->get($groupName); - $result .= $c->l('grp_ERR_INTERNAL_FAILURE') . ':' . $groupName unless ($rec); - - $res = ''; - if ( ! $result ) { - $res = delete_group( $c, $groupName ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('grp_DELETED_GROUP') . ' ' . $groupName; - $res = 'OK'; - } - } - } + if (!$result) { + $result = $c->l('grp_DELETED_GROUP') . ' ' . $groupName; + $res = 'OK'; + } + } ## end if (!$result) + } ## end if ($trt eq 'DEL') # common parts - if ($res ne 'OK') { - $c->stash( error => $result ); - my %members = @{$c->gen_members_list($groupName)}; - $c->stash( title => $title, members => \%members, grp_datas => \%grp_datas ); - return $c->render('groups'); - } - + $c->stash(error => $result); + my %members = @{ $c->gen_members_list($groupName) }; + $c->stash(title => $title, members => \%members, grp_datas => \%grp_datas); + return $c->render('groups'); + } ## end if ($res ne 'OK') my $message = "'Groups' updates ($trt) DONE"; $c->app->log->info($message); - $c->flash( success => $result ); - + $c->flash(success => $result); $c->redirect_to('/groups'); -}; - - +} ## end sub do_update sub delete_group { - - my ( $c, $groupName ) = @_; + my ($c, $groupName) = @_; # Update the db account (1) $adb->get($groupName)->set_prop('type', 'group-deleted'); # Untaint groupName before use in system() ($groupName) = ($groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/); - - return (system ("/sbin/e-smith/signal-event", "group-delete", "$groupName") || - ! $adb->get($groupName)->delete()) ? - $c->l('DELETE_ERROR') : 'OK'; - -} - + return (system("/sbin/e-smith/signal-event", "group-delete", "$groupName") || !$adb->get($groupName)->delete()) + ? $c->l('DELETE_ERROR') + : 'OK'; +} ## end sub delete_group sub gen_members_list { - - my ( $c, $group ) = @_; - + my ($c, $group) = @_; my @members = (); - my $rec = $adb->get($group); - @members = split ( /,/, $rec->prop('Members') ) if ( $rec ); - + my $rec = $adb->get($group); + @members = split(/,/, $rec->prop('Members')) if ($rec); my %names; + foreach my $m (@members) { my $name; - if ( $m eq 'admin' ) { + + if ($m eq 'admin') { $name = "Administrator"; + } else { + $name = $adb->get($m)->prop('FirstName') . " " . $adb->get($m)->prop('LastName'); } - else { - $name = $adb->get($m)->prop('FirstName') . " " - . $adb->get($m)->prop('LastName'); - } - $names{$m} = $name; - } + $names{$m} = $name; + } ## end foreach my $m (@members) @members = %names; - return \@members; - -} - +} ## end sub gen_members_list sub gen_ibays_list { - - my ( $c, $group ) = @_; - + my ($c, $group) = @_; my %names; - foreach my $ibay ( $adb->ibays ) { - if ( $ibay->prop('Group') eq $group ) { - $names{$ibay->key} = $ibay->prop('Name'); + + foreach my $ibay ($adb->ibays) { + if ($ibay->prop('Group') eq $group) { + $names{ $ibay->key } = $ibay->prop('Name'); } - } + } ## end foreach my $ibay ($adb->ibays) my @ibays = %names; - return \@ibays; - -} - +} ## end sub gen_ibays_list sub gen_users_list { - my $c = shift; - my @users = sort { $a->key() cmp $b->key() } $adb->users(); my %names; - foreach my $user ( @users ) { - $names{$user->key} = $user->prop('FirstName') . " " - . $user->prop('LastName'); + foreach my $user (@users) { + $names{ $user->key } = $user->prop('FirstName') . " " . $user->prop('LastName'); } - return \%names; -} - +} ## end sub gen_users_list =head1 VALIDATION @@ -350,21 +273,17 @@ ok($panel->validate_is_group('ro2ot') eq 'NOT_A_GROUP', "Ro2ot is not a group"); =cut - sub validate_is_group () { - my $c = shift; - my $group = shift; - + my $c = shift; + my $group = shift; my @groups = $adb->groups(); my %groups = map { $_->key => 1 } @groups; - unless ( exists $groups{$group} ) { + unless (exists $groups{$group}) { return ($c->l('grp_NOT_A_GROUP')); } return ("OK"); - -} - +} ## end sub validate_is_group =head2 validate_group_naming_conflict FM GROUPNAME @@ -375,29 +294,21 @@ Returns "NAME_CONFLICT" if this group name conflicts with anything else ok (undef, 'need testing for validate_naming_Conflicts'); =cut - -sub validate_group_naming_conflict -{ - my $c = shift; +sub validate_group_naming_conflict { + my $c = shift; my $groupName = shift; - - my $account = $adb->get($groupName); + my $account = $adb->get($groupName); my $type; - if (defined $account) - { - $type = $account->prop('type'); - } - elsif (defined getpwnam($groupName) || defined getgrnam($groupName)) - { - $type = "system"; - } - else - { - return('OK'); + if (defined $account) { + $type = $account->prop('type'); + } elsif (defined getpwnam($groupName) || defined getgrnam($groupName)) { + $type = "system"; + } else { + return ('OK'); } return ($c->l('grp_ACCOUNT_CONFLICT', $groupName, $type)); -} +} ## end sub validate_group_naming_conflict =head2 validate_group FM groupname @@ -414,14 +325,14 @@ ok(validate_group('','f&oo') eq 'GROUP_CONTAINS_INVALD', 'f&oo is not a valid gr =cut sub validate_group { - my $c = shift; + my $c = shift; my $groupName = shift; - unless ( $groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/ ) { + + unless ($groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/) { return $c->l('grp_GROUP_NAMING'); } return ('OK'); -} - +} ## end sub validate_group =head2 validate_group_length FM GROUPNAME @@ -438,22 +349,21 @@ ok(($panel->validate_group_length('fooooooooooooooooo') eq 'GROUP_TOO_LONG'), "a =cut sub validate_group_length { - my $c = shift; - my $groupName = shift; + my $c = shift; + my $groupName = shift; + my $maxGroupNameLength = ( + $cdb->get('maxGroupNameLength') + ? $cdb->get('maxGroupNameLength')->prop('type') + : "" + ) + || 12; - - my $maxGroupNameLength = ($cdb->get('maxGroupNameLength') - ? $cdb->get('maxGroupNameLength')->prop('type') - : "") || 12; - - if ( length $groupName > $maxGroupNameLength ) { + if (length $groupName > $maxGroupNameLength) { return $c->l('grp_GROUP_TOO_LONG', $maxGroupNameLength); - } - else { + } else { return ('OK'); } -} - +} ## end sub validate_group_length =head2 validate_group_has_members FM MEMBERS @@ -473,17 +383,16 @@ ok(validate_group_has_members('') eq 'NO_MEMBERS', "We do ok with a group with =cut sub validate_group_has_members { - my $c = shift; + my $c = shift; my @members = (@_); my $count = @members; - if ( $count == 0 ) { + + if ($count == 0) { return ($c->l('grp_NO_MEMBERS')); - } - else { + } else { return ('OK'); } -} - +} ## end sub validate_group_has_members =pod @@ -492,16 +401,13 @@ Checks the supplied description. Period is allowed in description =cut -sub validate_description -{ +sub validate_description { my ($c, $description) = @_; - if ( $description =~ /^([\-\'\w][\-\'\w\s\.]*)$/ ) { + + if ($description =~ /^([\-\'\w][\-\'\w\s\.]*)$/) { return ('OK'); - } - else { + } else { return ($c->l('FM_ERR_UNEXPECTED_DESC')); } -} - - +} ## end sub validate_description 1 diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Hostentries.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Hostentries.pm index a828192..7f906a3 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Hostentries.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Hostentries.pm @@ -11,16 +11,12 @@ package SrvMngr::Controller::Hostentries; 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::FormMagick::Panel::hostentries; - use esmith::DomainsDB; use esmith::AccountsDB; use esmith::HostsDB; @@ -29,89 +25,73 @@ use HTML::Entities; use Net::IPv4Addr qw(ipv4_in_network); #use URI::Escape; - our $ddb = esmith::DomainsDB->open || die "Couldn't open hostentries db"; our $cdb = esmith::ConfigDB->open || die "Couldn't open configuration db"; our $hdb = esmith::HostsDB->open || die "Couldn't open hosts db"; our $ndb = esmith::NetworksDB->open || die "Couldn't open networks db"; sub main { - my $c = shift; - $c->app->log->info( $c->log_req ); - + $c->app->log->info($c->log_req); my %hos_datas = (); my $title = $c->l('hos_FORM_TITLE'); my $notif = ''; - $hos_datas{trt} = 'LIST'; - my %dom_hosts = (); - foreach my $d ( @{ domains_list() } ) { + foreach my $d (@{ domains_list() }) { $dom_hosts{$d} = { COUNT => 0, HOSTS => [] }; - if ( my @hosts = $hdb->get_hosts_by_domain($d) ) { + if (my @hosts = $hdb->get_hosts_by_domain($d)) { $dom_hosts{$d}{'COUNT'} = scalar(@hosts); # my @entries; push @{ $dom_hosts{$d}{'HOSTS'} }, host_data($_) foreach (@hosts); - } - } - + } ## end if (my @hosts = $hdb->...) + } ## end foreach my $d (@{ domains_list...}) $c->stash( title => $title, notif => $notif, hos_datas => \%hos_datas, dom_hosts => \%dom_hosts ); - $c->render( template => 'hostentries' ); - -} + $c->render(template => 'hostentries'); +} ## end sub main sub do_display { - my $c = shift; - $c->app->log->info( $c->log_req ); - + $c->app->log->info($c->log_req); my $rt = $c->current_route; my $trt = $c->param('trt') || 'LST'; my $hostname = $c->param('Hostname') || ''; - - $trt = 'ADD' if ( $rt eq 'hostentryadd' ); - $trt = 'LST' if ( $trt ne 'DEL' && $trt ne 'UPD' && $trt ne 'ADD' ); - + $trt = 'ADD' if ($rt eq 'hostentryadd'); + $trt = 'LST' if ($trt ne 'DEL' && $trt ne 'UPD' && $trt ne 'ADD'); my %hos_datas = (); my $title = $c->l('hos_FORM_TITLE'); my $notif = ''; - $hos_datas{'trt'} = $trt; - if ( $trt eq 'ADD' ) { - + if ($trt eq 'ADD') { } - if ( $trt eq 'UPD' or $trt eq 'DEL' ) { - + if ($trt eq 'UPD' or $trt eq 'DEL') { my $rec = $hdb->get($hostname); + if ($rec) { $hos_datas{hostname} = $rec->key; - ( $hos_datas{name}, $hos_datas{domain} ) = - split_hostname($hostname); + ($hos_datas{name}, $hos_datas{domain}) + = split_hostname($hostname); $hos_datas{internalip} = $rec->prop('InternalIP') || ''; $hos_datas{externalip} = $rec->prop('ExternalIP') || ''; $hos_datas{macaddress} = $rec->prop('MACAddress') || ''; $hos_datas{hosttype} = $rec->prop('HostType'); - $hos_datas{comment} = - HTML::Entities::encode( $rec->prop('Comment') ); - } - else { + $hos_datas{comment} = HTML::Entities::encode($rec->prop('Comment')); + } else { $notif = "Hostname $hostname not found !"; } - } + } ## end if ($trt eq 'UPD' or $trt...) #if ( $trt eq 'DEL' ) { - # my $rec = $hdb->get($hostname); # if ( $rec ) { # get_hos_datas( $rec, %hos_datas ); @@ -119,29 +99,21 @@ sub do_display { # $notif = "Hostname $hostname not found !" # } #} - - if ( $trt eq 'LIST' ) { - + if ($trt eq 'LIST') { } - - $c->stash( title => $title, notif => $notif, hos_datas => \%hos_datas ); - $c->render( template => 'hostentries' ); - -} + $c->stash(title => $title, notif => $notif, hos_datas => \%hos_datas); + $c->render(template => 'hostentries'); +} ## end sub do_display sub do_update { - my $c = shift; - $c->app->log->info( $c->log_req ); - - my $rt = $c->current_route; - my $trt = ( $c->param('trt') || 'LIST' ); - + $c->app->log->info($c->log_req); + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); my %hos_datas = (); my $title = $c->l('hos_FORM_TITLE'); my $notif = ''; my $result = ''; - $hos_datas{'name'} = lc $c->param('Name'); $hos_datas{'domain'} = lc $c->param('Domain'); $hos_datas{'hostname'} = $c->param('Hostname'); @@ -151,199 +123,180 @@ sub do_update { $hos_datas{'macaddress'} = $c->param('Macaddress'); $hos_datas{'externalip'} = $c->param('Externalip'); my $hostname = "$hos_datas{'name'}.$hos_datas{'domain'}"; - if ( $trt eq 'ADD' ) { - - $hos_datas{'hostname'} = $hostname; + + if ($trt eq 'ADD') { + $hos_datas{'hostname'} = $hostname; # controls my $res = ''; - unless ( $hos_datas{'name'} =~ /^[a-z0-9][a-z0-9-]*$/ ) { + + unless ($hos_datas{'name'} =~ /^[a-z0-9][a-z0-9-]*$/) { $result .= $c->l('hos_HOSTNAME_VALIDATOR_ERROR') . '
'; } - unless ( $hos_datas{comment} =~ /^([a-zA-Z0-9][\_\.\-,A-Za-z0-9\s]*)$/ - || $hos_datas{comment} eq '' ) + unless ($hos_datas{comment} =~ /^([a-zA-Z0-9][\_\.\-,A-Za-z0-9\s]*)$/ + || $hos_datas{comment} eq '') { $result .= $c->l('hos_HOSTNAME_COMMENT_ERROR') . '
'; - } + } ## end unless ($hos_datas{comment...}) # Look for duplicate hosts. my $hostrec = undef; - if ( $hostrec = $hdb->get($hostname) ) { + + if ($hostrec = $hdb->get($hostname)) { $result .= $c->l( 'hos_HOSTNAME_EXISTS_ERROR', - { - fullHostName => $hostname, + { fullHostName => $hostname, type => $hostrec->prop('HostType') } ) . '
',; - } + } ## end if ($hostrec = $hdb->get...) - if ( !$result and $hos_datas{hosttype} ne 'Self' ) { - if ( $hos_datas{hosttype} eq 'Local' ) { + if (!$result and $hos_datas{hosttype} ne 'Self') { + if ($hos_datas{hosttype} eq 'Local') { $hos_datas{'trt'} = 'ALC'; # ADD/LOCAL - } - else { + } else { $hos_datas{'trt'} = 'ARM'; # ADD/REMOVE } - - $c->stash( title => $title, notif => '', hos_datas => \%hos_datas ); - return $c->render( template => 'hostentries' ); - } + $c->stash(title => $title, notif => '', hos_datas => \%hos_datas); + return $c->render(template => 'hostentries'); + } ## end if (!$result and $hos_datas...) #!#$result .= ' blocked'; - - if ( !$result ) { - $res = create_modify_hostentry( $c, $trt, %hos_datas ); + if (!$result) { + $res = create_modify_hostentry($c, $trt, %hos_datas); $result .= $res unless $res eq 'OK'; } - if ( !$result ) { + + if (!$result) { $result = $c->l('hos_CREATE_OR_MODIFY_SUCCEEDED') . ' ' . $hostname; $trt = 'SUC'; } - } + } ## end if ($trt eq 'ADD') - if ( $trt eq 'UPD' ) { + if ($trt eq 'UPD') { # controls my $res = ''; #$res = validate_description( $c, $account ); #$result .= $res unless $res eq 'OK'; - - unless ( $hos_datas{comment} =~ /^([a-zA-Z0-9][\_\.\-,A-Za-z0-9\s]*)$/ - || $hos_datas{comment} eq '' ) + unless ($hos_datas{comment} =~ /^([a-zA-Z0-9][\_\.\-,A-Za-z0-9\s]*)$/ + || $hos_datas{comment} eq '') { $result .= $c->l('hos_HOSTNAME_COMMENT_ERROR') . '
'; } - if ( !$result and $hos_datas{hosttype} ne 'Self' ) { - if ( $hos_datas{hosttype} eq 'Local' ) { + if (!$result and $hos_datas{hosttype} ne 'Self') { + if ($hos_datas{hosttype} eq 'Local') { $hos_datas{'trt'} = 'ULC'; # UPDATE/LOCAL - } - else { + } else { $hos_datas{'trt'} = 'URM'; # UPDATE/REMOVE } - - $c->stash( title => $title, notif => '', hos_datas => \%hos_datas ); - return $c->render( template => 'hostentries' ); - } + $c->stash(title => $title, notif => '', hos_datas => \%hos_datas); + return $c->render(template => 'hostentries'); + } ## end if (!$result and $hos_datas...) #!#$result .= 'blocked'; - - if ( !$result ) { - $res = create_modify_hostentry( $c, $trt, %hos_datas ); + if (!$result) { + $res = create_modify_hostentry($c, $trt, %hos_datas); $result .= $res unless $res eq 'OK'; } - if ( !$result ) { + if (!$result) { $result = $c->l('hos_MODIFY_SUCCEEDED') . ' ' . $hostname; $trt = 'SUC'; } - } + } ## end if ($trt eq 'UPD') - if ( $trt =~ /^.LC$/ ) { + if ($trt =~ /^.LC$/) { # controls my $res = ''; - $res = ip_number( $c, $hos_datas{internalip} ); + $res = ip_number($c, $hos_datas{internalip}); $result .= $res . ' ' unless $res eq 'OK'; - - $res = not_in_dhcp_range( $c, $hos_datas{internalip} ); + $res = not_in_dhcp_range($c, $hos_datas{internalip}); $result .= $res . ' ' unless $res eq 'OK'; - - $res = not_taken( $c, $hos_datas{internalip} ); + $res = not_taken($c, $hos_datas{internalip}); $result .= $res . ' ' unless $res eq 'OK'; - - $res = must_be_local( $c, $hos_datas{internalip} ); + $res = must_be_local($c, $hos_datas{internalip}); $result .= $res . ' ' unless $res eq 'OK'; - - $res = mac_address_or_blank( $c, $hos_datas{macaddress} ); + $res = mac_address_or_blank($c, $hos_datas{macaddress}); $result .= $res . ' ' unless $res eq 'OK'; #!#$result .= 'blocked'; - - if ( !$result ) { - $res = create_modify_hostentry( $c, $trt, %hos_datas ); + if (!$result) { + $res = create_modify_hostentry($c, $trt, %hos_datas); $result .= $res unless $res eq 'OK'; } - if ( !$result ) { + if (!$result) { $result = $c->l('hos_MODIFY_SUCCEEDED') . ' ' . $hostname; $trt = 'SUC'; } - } + } ## end if ($trt =~ /^.LC$/) - if ( $trt =~ /^.RM$/ ) { + if ($trt =~ /^.RM$/) { # controls my $res = ''; - $res = ip_number_or_blank( $c, $hos_datas{externalip} ); + $res = ip_number_or_blank($c, $hos_datas{externalip}); $result .= $res . '
' unless $res eq 'OK'; #!#$result .= 'blocked'; - - if ( !$result ) { - $res = create_modify_hostentry( $c, $trt, %hos_datas ); + if (!$result) { + $res = create_modify_hostentry($c, $trt, %hos_datas); $result .= $res unless $res eq 'OK'; } - if ( !$result ) { + if (!$result) { $result = $c->l('hos_MODIFY_SUCCEEDED') . ' ' . $hostname; $trt = 'SUC'; } - - } + } ## end if ($trt =~ /^.RM$/) #if ( $trt eq 'ULC' ) { #} - #if ( $trt eq 'URM' ) { #} - - if ( $trt eq 'DEL' ) { + if ($trt eq 'DEL') { # controls my $res = ''; #$res = validate_is_hostentry($c, $hostname); #$result .= $res unless $res eq 'OK'; - #!#$result .= 'blocked'; - - if ( !$result ) { - my $res = delete_hostentry( $c, $hos_datas{hostname} ); + if (!$result) { + my $res = delete_hostentry($c, $hos_datas{hostname}); $result .= $res unless $res eq 'OK'; } - if ( !$result ) { + + if (!$result) { $result = $c->l('hos_REMOVE_SUCCEEDED') . ' ' . $hostname; $trt = 'SUC'; } - } - + } ## end if ($trt eq 'DEL') $hos_datas{'hostname'} = $hostname; $hos_datas{'trt'} = $trt; + $c->stash(title => $title, notif => $result, hos_datas => \%hos_datas); - $c->stash( title => $title, notif => $result, hos_datas => \%hos_datas ); - - if ( $hos_datas{trt} ne 'SUC' ) { - return $c->render( template => 'hostentries' ); + if ($hos_datas{trt} ne 'SUC') { + return $c->render(template => 'hostentries'); } $c->redirect_to('/hostentries'); - -} +} ## end sub do_update sub create_modify_hostentry { - - my ( $c, $trt, %hos_datas ) = @_; - + my ($c, $trt, %hos_datas) = @_; my $hostname = $hos_datas{hostname}; my $action; - if ( $trt eq 'ADD' or $trt eq 'ALC' or $trt eq 'ARM' ) { + if ($trt eq 'ADD' or $trt eq 'ALC' or $trt eq 'ARM') { $action = 'create'; } - if ( $trt eq 'UPD' or $trt eq 'ULC' or $trt eq 'URM' ) { + + if ($trt eq 'UPD' or $trt eq 'ULC' or $trt eq 'URM') { $action = 'modify'; } @@ -353,20 +306,20 @@ sub create_modify_hostentry { ? $c->l('hos_ERROR_CREATING_HOST') : $c->l('hos_ERROR_MODIFYING_HOST') ); - } + } ## end unless ($hostname) # Untaint and lowercase $hostname $hostname =~ /([\w\.-]+)/; $hostname = lc($1); - my $rec = $hdb->get($hostname); - if ( $rec and $action eq 'create' ) { + + if ($rec and $action eq 'create') { return $c->l('hos_HOSTNAME_IN_USE_ERROR'); } - if ( not $rec and $action eq 'modify' ) { + + if (not $rec and $action eq 'modify') { return $c->l('hos_NONEXISTENT_HOSTNAME_ERROR'); } - my %props = ( type => 'host', HostType => $hos_datas{hosttype}, @@ -376,224 +329,178 @@ sub create_modify_hostentry { Comment => $hos_datas{comment}, ); - if ( $action eq 'create' ) { - if ( $hdb->new_record( $hostname, \%props ) ) { - if ( - system( "/sbin/e-smith/signal-event", "host-$action", - $hostname ) != 0 - ) - { + if ($action eq 'create') { + if ($hdb->new_record($hostname, \%props)) { + + if (system("/sbin/e-smith/signal-event", "host-$action", $hostname) != 0) { return $c->l('hos_ERROR_WHILE_CREATING_HOST'); } - } - } + } ## end if ($hdb->new_record($hostname...)) + } ## end if ($action eq 'create') - if ( $action eq 'modify' ) { - if ( $rec->merge_props(%props) ) { - if ( - system( "/sbin/e-smith/signal-event", "host-$action", - $hostname ) != 0 - ) - { + if ($action eq 'modify') { + if ($rec->merge_props(%props)) { + + if (system("/sbin/e-smith/signal-event", "host-$action", $hostname) != 0) { rturn $c->l('hos_ERROR_WHILE_MODIFYING_HOST'); } - } - } + } ## end if ($rec->merge_props(...)) + } ## end if ($action eq 'modify') return 'OK'; - -} +} ## end sub create_modify_hostentry sub delete_hostentry { - - my ( $c, $hostname ) = @_; + my ($c, $hostname) = @_; # Untaint $hostname before use in system() $hostname =~ /([\w\.-]+)/; $hostname = $1; - - return ( $c->l('hos_ERROR_WHILE_REMOVING_HOST') ) unless ($hostname); - + return ($c->l('hos_ERROR_WHILE_REMOVING_HOST')) unless ($hostname); my $rec = $hdb->get($hostname); - return ( $c->l('hos_NONEXISTENT_HOST_ERROR') ) if ( not $rec ); + return ($c->l('hos_NONEXISTENT_HOST_ERROR')) if (not $rec); - if ( $rec->delete() ) { - if ( - system( "/sbin/e-smith/signal-event", "host-delete", "$hostname" ) - == 0 ) - { + if ($rec->delete()) { + if (system("/sbin/e-smith/signal-event", "host-delete", "$hostname") == 0) { return 'OK'; } - } - return ( $c->l('hos_ERROR_WHILE_DELETING_HOST') ); -} + } ## end if ($rec->delete()) + return ($c->l('hos_ERROR_WHILE_DELETING_HOST')); +} ## end sub delete_hostentry sub domains_list { - my $d = esmith::DomainsDB->open_ro() or die "Couldn't open DomainsDB"; my @domains; - for ( $d->domains ) { - my $ns = $_->prop("Nameservers") || 'localhost'; - push @domains, $_->key if ( $ns eq 'localhost' ); - } + for ($d->domains) { + my $ns = $_->prop("Nameservers") || 'localhost'; + push @domains, $_->key if ($ns eq 'localhost'); + } return \@domains; -} +} ## end sub domains_list sub host_data { - my $host_record = shift; - - my $ht = $host_record->prop('HostType'); - my $ip = - ( $ht eq 'Self' ) ? $cdb->get_value('LocalIP') - : ( $ht eq 'Remote' ) ? $host_record->prop('ExternalIP') - : $host_record->prop('InternalIP'); - + my $ht = $host_record->prop('HostType'); + my $ip + = ($ht eq 'Self') ? $cdb->get_value('LocalIP') + : ($ht eq 'Remote') ? $host_record->prop('ExternalIP') + : $host_record->prop('InternalIP'); my %data = ( 'IP' => $ip, 'HostName' => $host_record->key(), 'HostType' => $host_record->prop('HostType'), - 'MACAddress' => ( $host_record->prop('MACAddress') || '' ), - 'Comment' => ( $host_record->prop('Comment') || '' ), - 'static' => ( $host_record->prop('static') || 'no' ) + 'MACAddress' => ($host_record->prop('MACAddress') || ''), + 'Comment' => ($host_record->prop('Comment') || ''), + 'static' => ($host_record->prop('static') || 'no') ); - return \%data - -} + return \%data; +} ## end sub host_data sub hosttype_list { - my $c = shift; - - return [ - [ $c->l('SELF') => 'Self' ], - [ $c->l('LOCAL') => 'Local' ], - [ $c->l('REMOTE') => 'Remote' ] - ]; + return [ [ $c->l('SELF') => 'Self' ], [ $c->l('LOCAL') => 'Local' ], [ $c->l('REMOTE') => 'Remote' ] ]; } sub split_hostname { my $hostname = shift; - return ( $hostname =~ /^([^\.]+)\.(.+)$/ ); + return ($hostname =~ /^([^\.]+)\.(.+)$/); } sub mac_address_or_blank { - my ( $c, $data ) = @_; + my ($c, $data) = @_; return "OK" unless $data; - return mac_address( $c, $data ); -} + return mac_address($c, $data); +} ## end sub mac_address_or_blank sub mac_address { # from CGI::FormMagick::Validator::Network - - my ( $c, $data ) = @_; - + my ($c, $data) = @_; $_ = lc $data; # easier to match on $_ - if ( not defined $_ ) { + + if (not defined $_) { return $c->l('FM_MAC_ADDRESS1'); - } - elsif (/^([0-9a-f][0-9a-f](:[0-9a-f][0-9a-f]){5})$/) { + } elsif (/^([0-9a-f][0-9a-f](:[0-9a-f][0-9a-f]){5})$/) { return "OK"; - } - else { + } else { return $c->l('FM_MAC_ADDRESS2'); } -} +} ## end sub mac_address sub ip_number_or_blank { # XXX - FIXME - we should push this down into CGI::FormMagick - my $c = shift; my $ip = shift; - if ( !defined($ip) || $ip eq "" ) { + if (!defined($ip) || $ip eq "") { return 'OK'; } - - return ip_number( $c, $ip ); -} + return ip_number($c, $ip); +} ## end sub ip_number_or_blank sub ip_number { # from CGI::FormMagick::Validator qw( ip_number ); - - my ( $c, $data ) = @_; - + my ($c, $data) = @_; return undef unless defined $data; - return $c->l('FM_IP_NUMBER1') unless $data =~ /^[\d.]+$/; - my @octets = split /\./, $data; - my $dots = ( $data =~ tr/.// ); - - return $c->l('FM_IP_NUMBER2') unless ( scalar @octets == 4 and $dots == 3 ); + my $dots = ($data =~ tr/.//); + return $c->l('FM_IP_NUMBER2') unless (scalar @octets == 4 and $dots == 3); foreach my $octet (@octets) { - return $c->l( "FM_IP_NUMBER3", $octet ) if $octet > 255; + return $c->l("FM_IP_NUMBER3", $octet) if $octet > 255; } - return 'OK'; -} +} ## end sub ip_number sub not_in_dhcp_range { - my $c = shift; my $address = shift; - - my $status = $cdb->get('dhcpd')->prop('status') || "disabled"; + my $status = $cdb->get('dhcpd')->prop('status') || "disabled"; return 'OK' unless $status eq "enabled"; - my $start = $cdb->get('dhcpd')->prop('start'); my $end = $cdb->get('dhcpd')->prop('end'); - - return ( esmith::util::IPquadToAddr($start) <= - esmith::util::IPquadToAddr($address) - && esmith::util::IPquadToAddr($address) <= - esmith::util::IPquadToAddr($end) ) - ? $c->l('hos_ADDR_IN_DHCP_RANGE') - : 'OK'; -} + return ( esmith::util::IPquadToAddr($start) <= esmith::util::IPquadToAddr($address) + && esmith::util::IPquadToAddr($address) <= esmith::util::IPquadToAddr($end)) + ? $c->l('hos_ADDR_IN_DHCP_RANGE') + : 'OK'; +} ## end sub not_in_dhcp_range sub not_taken { - - my $c = shift; - my $localip = shift; - - my $server_localip = $cdb->get_value('LocalIP') || ''; - my $server_gateway = $cdb->get_value('GatewayIP') || ''; + my $c = shift; + my $localip = shift; + my $server_localip = $cdb->get_value('LocalIP') || ''; + my $server_gateway = $cdb->get_value('GatewayIP') || ''; my $server_extip = $cdb->get_value('ExternalIP') || ''; #$c->debug_msg("\$localip is $localip"); #$c->debug_msg("\$server_localip is $server_localip"); #$c->debug_msg("\$server_gateway is $server_gateway"); #$c->debug_msg("\$server_extip is $server_extip"); - - if ( $localip eq $server_localip ) { + if ($localip eq $server_localip) { return $c->l('hos_ERR_IP_IS_LOCAL_OR_GATEWAY'); } - if ( $localip eq $server_gateway ) { + if ($localip eq $server_gateway) { return $c->l('hos_ERR_IP_IS_LOCAL_OR_GATEWAY'); } - if ( ( $cdb->get_value('SystemMode') ne 'serveronly' ) - && ( $server_extip eq $localip ) ) + if ( ($cdb->get_value('SystemMode') ne 'serveronly') + && ($server_extip eq $localip)) { return $c->l('hos_ERR_IP_IS_LOCAL_OR_GATEWAY'); - } + } ## end if (($cdb->get_value('SystemMode'...))) - if ( $localip eq '127.0.0.1' ) { + if ($localip eq '127.0.0.1') { return $c->l('hos_ERR_IP_IS_LOCAL_OR_GATEWAY'); - } - else { + } else { return 'OK'; } -} +} ## end sub not_taken sub must_be_local { - my $c = shift; my $localip = shift; @@ -603,13 +510,13 @@ sub must_be_local { foreach my $spec (@local_list) { next if $spec eq '127.0.0.1'; - if ( eval { Net::IPv4Addr::ipv4_in_network( $spec, $localip ) } ) { + + if (eval { Net::IPv4Addr::ipv4_in_network($spec, $localip) }) { return 'OK'; } - } + } ## end foreach my $spec (@local_list) # Not OK. The IP is not on any of our local networks. return $c->l('hos_ERR_IP_NOT_LOCAL'); -} - +} ## end sub must_be_local 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Ibays.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Ibays.pm index 90072a0..79a2250 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Ibays.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Ibays.pm @@ -4,289 +4,255 @@ package SrvMngr::Controller::Ibays; # heading : Network # description : Shared areas (was ibays) # navigation : 6000 100 -# +# # # routes : end #---------------------------------------------------------------------- use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw( theme_list init_session is_normal_password ); - use esmith::AccountsDB; use esmith::ConfigDB; use esmith::DomainsDB; #use esmith::FormMagick::Panel::ibays; - our $adb = esmith::AccountsDB->open || die "Couldn't open accounts db"; our $cdb = esmith::ConfigDB->open() || die "Couldn't open config db"; sub main { - my $c = shift; $c->app->log->info($c->log_req); - my %iba_datas = (); - my $title = $c->l('iba_FORM_TITLE'); - + my $title = $c->l('iba_FORM_TITLE'); $iba_datas{'trt'} = 'LIST'; - my @ibays; - if ($adb) - { + + if ($adb) { @ibays = $adb->ibays(); } - - $c->stash( title => $title, iba_datas => \%iba_datas, ibays => \@ibays ); + $c->stash(title => $title, iba_datas => \%iba_datas, ibays => \@ibays); $c->render(template => 'ibays'); - -}; - +} ## end sub main sub do_display { - - my $c = shift; - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LIST'); + my $c = shift; + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); my $ibay = $c->param('ibay') || ''; #$trt = 'DEL' if ( $ibay ); #$trt = 'ADD' if ( $rt eq 'ibayadd' ); - my %iba_datas = (); - my $title = $c->l('iba_FORM_TITLE'); - my $modul = ''; - + my $title = $c->l('iba_FORM_TITLE'); + my $modul = ''; $iba_datas{'trt'} = $trt; - if ( $trt eq 'ADD' ) { + if ($trt eq 'ADD') { + $iba_datas{ibay} = ''; + $iba_datas{description} = ''; + $iba_datas{group} = ''; + $iba_datas{userAccess} = ''; + $iba_datas{publicAccess} = ''; + $iba_datas{CgiBin} = ''; + $iba_datas{SSL} = ''; + } ## end if ($trt eq 'ADD') - $iba_datas{ibay} = ''; - $iba_datas{description} = ''; - $iba_datas{group} = ''; - $iba_datas{userAccess} = ''; - $iba_datas{publicAccess} = ''; - $iba_datas{CgiBin} = ''; - $iba_datas{SSL} = ''; + if ($trt eq 'UPD') { + my $rec = $adb->get($ibay); + if ($rec and $rec->prop('type') eq 'ibay') { + $iba_datas{ibay} = $ibay; + $iba_datas{description} = $rec->prop('Name') || ''; + $iba_datas{group} = $rec->prop('Group') || ''; + $iba_datas{userAccess} = $rec->prop('UserAccess') || ''; + $iba_datas{publicAccess} = $rec->prop('PublicAccess') || ''; + $iba_datas{CgiBin} = $rec->prop('CgiBin') || 'disabled'; + $iba_datas{SSL} = $rec->prop('SSL') || 'disabled'; + } ## end if ($rec and $rec->prop...) + } ## end if ($trt eq 'UPD') + + if ($trt eq 'DEL') { + my $rec = $adb->get($ibay); + + if ($rec and $rec->prop('type') eq 'ibay') { + $iba_datas{ibay} = $ibay; + $iba_datas{description} = $rec->prop('Name') || ''; + $modul .= print_vhost_message($c, $ibay); + } ## end if ($rec and $rec->prop...) + } ## end if ($trt eq 'DEL') + + if ($trt eq 'PWD') { + my $rec = $adb->get($ibay); + + if ($rec and $rec->prop('type') eq 'ibay') { + $iba_datas{ibay} = $ibay; + $iba_datas{description} = $rec->prop('Name') || ''; } + } ## end if ($trt eq 'PWD') - if ( $trt eq 'UPD' ) { + if ($trt eq 'LIST') { + my @ibays; + $adb = esmith::AccountsDB->open || die "Couldn't open accounts db"; - my $rec = $adb->get($ibay); - if ($rec and $rec->prop('type') eq 'ibay') { - $iba_datas{ibay} = $ibay; - $iba_datas{description} = $rec->prop('Name') || ''; - $iba_datas{group} = $rec->prop('Group') || ''; - $iba_datas{userAccess} = $rec->prop('UserAccess') || ''; - $iba_datas{publicAccess} = $rec->prop('PublicAccess') || ''; - $iba_datas{CgiBin} = $rec->prop('CgiBin') || 'disabled'; - $iba_datas{SSL} = $rec->prop('SSL') || 'disabled'; - } + if ($adb) { + @ibays = $adb->ibays(); } - - if ( $trt eq 'DEL' ) { - - my $rec = $adb->get($ibay); - if ($rec and $rec->prop('type') eq 'ibay') { - $iba_datas{ibay} = $ibay; - $iba_datas{description} = $rec->prop('Name') || ''; - $modul .= print_vhost_message( $c, $ibay ); - } - - } - - if ( $trt eq 'PWD' ) { - - my $rec = $adb->get($ibay); - if ($rec and $rec->prop('type') eq 'ibay') { - $iba_datas{ibay} = $ibay; - $iba_datas{description} = $rec->prop('Name') || ''; - } - - } - - if ( $trt eq 'LIST' ) { - my @ibays; - $adb = esmith::AccountsDB->open || die "Couldn't open accounts db"; - if ($adb) - { - @ibays = $adb->ibays(); - } - $c->stash( ibays => \@ibays ); - - } - - $c->stash( title => $title, modul => $modul, iba_datas => \%iba_datas ); - $c->render( template => 'ibays' ); - -}; - + $c->stash(ibays => \@ibays); + } ## end if ($trt eq 'LIST') + $c->stash(title => $title, modul => $modul, iba_datas => \%iba_datas); + $c->render(template => 'ibays'); +} ## end sub do_display sub do_update { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LIST'); - + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); my %iba_datas = (); - my $title = $c->l('iba_FORM_TITLE'); - + my $title = $c->l('iba_FORM_TITLE'); $iba_datas{'trt'} = $trt; - my $result = ''; my $res; - if ( $trt eq 'ADD' ) { + if ($trt eq 'ADD') { + my $name = ($c->param('ibay') || ''); - my $name = ($c->param('ibay') || ''); + # controls + $res = validate_ibay($c, $name); + $result .= $res unless $res eq 'OK'; - # controls - $res = validate_ibay( $c, $name ); - $result .= $res unless $res eq 'OK'; + if (!$result) { + $res = create_ibay($c, $name); + $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $res = create_ibay( $c, $name ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('iba_SUCCESSFULLY_CREATED_IBAY') . ' ' . $name; - $iba_datas{trt} = 'LST'; - } - } - } + if (!$result) { + $result = $c->l('iba_SUCCESSFULLY_CREATED_IBAY') . ' ' . $name; + $iba_datas{trt} = 'LST'; + } + } ## end if (!$result) + } ## end if ($trt eq 'ADD') - if ( $trt eq 'UPD' ) { + if ($trt eq 'UPD') { + my $name = ($c->param('ibay') || ''); - my $name = ($c->param('ibay') || ''); + # controls + $res = ''; - # controls - $res = ''; + if (!$result) { + $res = modify_ibay($c, $name); + $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $res = modify_ibay( $c, $name ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('iba_SUCCESSFULLY_MODIFIED_IBAY') . ' ' . $name; - $iba_datas{trt} = 'LST'; - } - } - } + if (!$result) { + $result = $c->l('iba_SUCCESSFULLY_MODIFIED_IBAY') . ' ' . $name; + $iba_datas{trt} = 'LST'; + } + } ## end if (!$result) + } ## end if ($trt eq 'UPD') - if ( $trt eq 'PWD' ) { - - my $ibay = ($c->param('ibay') || ''); - my $pass1 = ($c->param('newPass') || ''); + if ($trt eq 'PWD') { + my $ibay = ($c->param('ibay') || ''); + my $pass1 = ($c->param('newPass') || ''); my $pass2 = ($c->param('newPassVerify') || ''); - # controls + # controls unless ($pass1 eq $pass2) { $result .= $c->l('iba_IBAY_PASSWD_VERIFY_ERROR') . ' - '; - } + } + $res = check_password($c, $pass1); + $result .= $res unless $res eq 'OK'; - $res = check_password( $c, $pass1 ); - $result .= $res unless $res eq 'OK'; - - if ( ! $result ) { - $res = reset_password( $c, $ibay, $pass1 ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('iba_SUCCESSFULLY_RESET_PASSWORD') . ' ' . $ibay; - $iba_datas{trt} = 'LST'; - } - } - } + if (!$result) { + $res = reset_password($c, $ibay, $pass1); + $result .= $res unless $res eq 'OK'; - if ( $trt eq 'DEL' ) { - - my $ibay = $c->param ('ibay'); + if (!$result) { + $result = $c->l('iba_SUCCESSFULLY_RESET_PASSWORD') . ' ' . $ibay; + $iba_datas{trt} = 'LST'; + } + } ## end if (!$result) + } ## end if ($trt eq 'PWD') - if ($ibay =~ /^([a-z][a-z0-9]*)$/) { - $ibay = $1; - } else { - $result .= $c->l('iba_ERR_INTERNAL_FAILURE') . ':' . $ibay; - } + if ($trt eq 'DEL') { + my $ibay = $c->param('ibay'); - if ( ! $result ) { - $res = remove_ibay( $c, $ibay ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('iba_SUCCESSFULLY_DELETED_IBAY') . ' ' . $ibay; - $iba_datas{trt} = 'LST'; - } - } - } + if ($ibay =~ /^([a-z][a-z0-9]*)$/) { + $ibay = $1; + } else { + $result .= $c->l('iba_ERR_INTERNAL_FAILURE') . ':' . $ibay; + } + + if (!$result) { + $res = remove_ibay($c, $ibay); + $result .= $res unless $res eq 'OK'; + + if (!$result) { + $result = $c->l('iba_SUCCESSFULLY_DELETED_IBAY') . ' ' . $ibay; + $iba_datas{trt} = 'LST'; + } + } ## end if (!$result) + } ## end if ($trt eq 'DEL') # common parts - if ($res ne 'OK') { - $c->stash( error => $result ); - $c->stash( title => $title, iba_datas => \%iba_datas ); - return $c->render('ibays'); + $c->stash(error => $result); + $c->stash(title => $title, iba_datas => \%iba_datas); + return $c->render('ibays'); } - my $message = "'Ibays' updates ($trt) DONE"; $c->app->log->info($message); - $c->flash( success => $result ); - + $c->flash(success => $result); $c->redirect_to('/ibays'); -}; - +} ## end sub do_update sub validate_ibay { - my ($c, $name) = @_; - my $msg = validate_name($c, $name); - unless ($msg eq "OK") - { + + unless ($msg eq "OK") { return ($msg); } - $msg = max_ibay_name_length($c, $name); - unless ($msg eq "OK") - { + + unless ($msg eq "OK") { return ($msg); } - $msg = conflict_check($c, $name); - unless ($msg eq "OK") - { + + unless ($msg eq "OK") { return ($msg); } - return ('OK'); -} - +} ## end sub validate_ibay sub create_ibay { - my ($c, $name) = @_; - my $msg; - my $uid = $adb->get_next_uid(); - if (my $acct = $adb->new_record($name, { - Name => $c->param('ibayDesc'), - CgiBin => $c->param('CgiBin'), - Group => $c->param('group'), - PublicAccess => $c->param('publicAccess'), - SSL => $c->param('SSL'), - UserAccess => $c->param('userAccess'), - Uid => $uid, - Gid => $uid, - PasswordSet => 'no', - type => 'ibay', - }) ) + my $uid = $adb->get_next_uid(); + + if (my $acct = $adb->new_record( + $name, + { Name => $c->param('ibayDesc'), + CgiBin => $c->param('CgiBin'), + Group => $c->param('group'), + PublicAccess => $c->param('publicAccess'), + SSL => $c->param('SSL'), + UserAccess => $c->param('userAccess'), + Uid => $uid, + Gid => $uid, + PasswordSet => 'no', + type => 'ibay', + } + ) + ) { # Untaint $name before use in system() - $name =~ /(.+)/; $name = $1; - if (system ("/sbin/e-smith/signal-event", "ibay-create", $name) == 0) { + $name =~ /(.+)/; + $name = $1; + + if (system("/sbin/e-smith/signal-event", "ibay-create", $name) == 0) { $msg = 'OK'; } else { $msg = $c->l('iba_ERROR_WHILE_CREATING_IBAY'); @@ -295,14 +261,12 @@ sub create_ibay { $msg = $c->l('iba_CANT_CREATE_IBAY'); } return $msg; - -} - +} ## end sub create_ibay sub modify_ibay { my ($c, $name) = @_; - my $msg; + if (my $acct = $adb->get($name)) { if ($acct->prop('type') eq 'ibay') { $acct->merge_props( @@ -315,10 +279,10 @@ sub modify_ibay { ); # Untaint $name before use in system() - $name =~ /(.+)/; $name = $1; - if (system ("/sbin/e-smith/signal-event", "ibay-modify", - $name) == 0) - { + $name =~ /(.+)/; + $name = $1; + + if (system("/sbin/e-smith/signal-event", "ibay-modify", $name) == 0) { $msg = 'OK'; } else { $msg = $c->l('iba_ERROR_WHILE_MODIFYING_IBAY'); @@ -329,53 +293,47 @@ sub modify_ibay { } else { $msg = $c->l('iba_CANT_FIND_IBAY'); } - return $msg; - -} - +} ## end sub modify_ibay sub print_vhost_message { - my $c = shift; - my $name = $c->param('ibay'); + my $c = shift; + my $name = $c->param('ibay'); + my $result = ''; + my $domaindb = esmith::DomainsDB->open(); + my @domains = $domaindb->get_all_by_prop(Content => $name); + my $vhostListItems = join "\n", (map ($_->key . " " . $_->prop('Description'), @domains)); - my $result = ''; - - my $domaindb = esmith::DomainsDB->open(); - my @domains = $domaindb->get_all_by_prop(Content => $name); - my $vhostListItems = join "\n", - (map ($_->key." ".$_->prop('Description'), @domains)); - if ($vhostListItems) - { + if ($vhostListItems) { $result = $c->l('iba_VHOST_MESSAGE') . "
    "; - foreach ( $vhostListItems ) { - $result .= "
  • $_
  • "; - } - $result .= '
' - } - return $result; -} + foreach ($vhostListItems) { + $result .= "
  • $_
  • "; + } + $result .= ''; + } ## end if ($vhostListItems) + return $result; +} ## end sub print_vhost_message sub remove_ibay { my ($c, $name) = @_; - my $msg = ''; + if (my $acct = $adb->get($name)) { if ($acct->prop('type') eq 'ibay') { $acct->set_prop('type', 'ibay-deleted'); - my $domains_db = esmith::DomainsDB->open(); - my @domains = $domains_db->get_all_by_prop(Content=>$name); + my @domains = $domains_db->get_all_by_prop(Content => $name); + foreach my $d (@domains) { $d->set_prop(Content => 'Primary'); } # Untaint $name before use in system() - $name =~ /(.+)/; $name = $1; - if (system ("/sbin/e-smith/signal-event", "ibay-delete", - $name) == 0) - { + $name =~ /(.+)/; + $name = $1; + + if (system("/sbin/e-smith/signal-event", "ibay-delete", $name) == 0) { $msg = 'OK'; $acct->delete(); } else { @@ -384,27 +342,25 @@ sub remove_ibay { } else { $msg = $c->l('iba_CANT_FIND_IBAY'); } - } else { $msg = $c->l('iba_CANT_FIND_IBAY'); } return $msg; -} - +} ## end sub remove_ibay sub reset_password { my ($c, $name, $newPass) = @_; - my ($msg, $acct); - + if (($acct = $adb->get($name)) && ($acct->prop('type') eq 'ibay')) { - esmith::util::setIbayPassword ($acct->key, $newPass); + esmith::util::setIbayPassword($acct->key, $newPass); $acct->set_prop('PasswordSet', 'yes'); + # Untaint $name before use in system() - $name =~ /(.+)/; $name = $1; - if (system ("/sbin/e-smith/signal-event", "password-modify", - $name) == 0) - { + $name =~ /(.+)/; + $name = $1; + + if (system("/sbin/e-smith/signal-event", "password-modify", $name) == 0) { $msg = 'OK'; } else { $msg = $c->l('iba_ERROR_WHILE_RESETTING_PASSWORD'); @@ -413,52 +369,41 @@ sub reset_password { $msg = $c->l('iba_CANT_FIND_IBAY'); } return $msg; -} - +} ## end sub reset_password sub check_password { my ($c, $password) = @_; - my $strength; - my $rec = $cdb->get('passwordstrength'); $strength = ($rec ? ($rec->prop('Ibays') || 'none') : 'none'); - - return validate_password( $c, $strength, $password ); -} - + return validate_password($c, $strength, $password); +} ## end sub check_password sub validate_password { - my ($c, $strength, $pass) = @_; - use Crypt::Cracklib; - my $reason; if ($strength eq "none") { return $c->l("Passwords must be at least 7 characters long") unless (length($pass) > 6); return "OK"; } - $reason = is_normal_password($c, $pass, undef); return $reason unless ($reason eq "OK"); return "OK" unless ($strength eq "strong"); - if ( -f '/usr/lib64/cracklib_dict.pwd' ) { + if (-f '/usr/lib64/cracklib_dict.pwd') { $reason = fascist_check($pass, '/usr/lib64/cracklib_dict'); } else { $reason = fascist_check($pass, '/usr/lib/cracklib_dict'); } $reason ||= "Software error: password check failed"; - return "OK" if ($reason eq "ok"); - - return $c->l("Bad Password Choice") . ": " - . $c->l("The password you have chosen is not a good choice, because") - . " " . $c->($reason) . "."; -} - + return + $c->l("Bad Password Choice") . ": " + . $c->l("The password you have chosen is not a good choice, because") . " " + . $c->($reason) . "."; +} ## end sub validate_password =head2 group_list() @@ -468,18 +413,14 @@ drop down list. =cut sub group_list_m { - my @groups = $adb->groups(); - - my @grps = ( ['Admin' => 'admin'], ['Everyone' => 'shared']); + my @grps = ([ 'Admin' => 'admin' ], [ 'Everyone' => 'shared' ]); foreach my $g (@groups) { - push @grps, [ $g->prop('Description')." (". $g->key.")", $g->key() ]; + push @grps, [ $g->prop('Description') . " (" . $g->key . ")", $g->key() ]; } - return \@grps; -} - +} ## end sub group_list_m =head2 userAccess_list @@ -489,13 +430,13 @@ drop down list. =cut sub userAccess_list_m { - my $c = shift; - return [[ $c->l('WARG') => 'wr-admin-rd-group'], - [ $c->l('WGRE') => 'wr-group-rd-everyone'], - [ $c->l('WGRG') => 'wr-group-rd-group']]; - -} + return [ + [ $c->l('WARG') => 'wr-admin-rd-group' ], + [ $c->l('WGRE') => 'wr-group-rd-everyone' ], + [ $c->l('WGRG') => 'wr-group-rd-group' ] + ]; +} ## end sub userAccess_list_m =head2 publicAccess_list @@ -505,19 +446,18 @@ access drop down list. =cut sub publicAccess_list_m { - my $c = shift; - return [[ $c->l('NONE') => 'none'], - [ $c->l('LOCAL_NETWORK_NO_PASSWORD') => 'local'], - [ $c->l('LOCAL_NETWORK_PASSWORD') => 'local-pw'], - [ $c->l('ENTIRE_INTERNET_NO_PASSWORD') => 'global'], - [ $c->l('ENTIRE_INTERNET_PASSWORD') => 'global-pw'], - [ $c->l('ENTIRE_INTERNET_PASSWORD_REMOTE') => 'global-pw-remote']]; -} - + return [ + [ $c->l('NONE') => 'none' ], + [ $c->l('LOCAL_NETWORK_NO_PASSWORD') => 'local' ], + [ $c->l('LOCAL_NETWORK_PASSWORD') => 'local-pw' ], + [ $c->l('ENTIRE_INTERNET_NO_PASSWORD') => 'global' ], + [ $c->l('ENTIRE_INTERNET_PASSWORD') => 'global-pw' ], + [ $c->l('ENTIRE_INTERNET_PASSWORD_REMOTE') => 'global-pw-remote' ] + ]; +} ## end sub publicAccess_list_m sub max_ibay_name_length { - my ($c, $data) = @_; $cdb->reload(); my $max = $cdb->get('maxIbayNameLength')->value; @@ -526,52 +466,42 @@ sub max_ibay_name_length { return "OK"; } else { return $c->l('iba_MAX_IBAY_NAME_LENGTH_ERROR', $data, $max, $max); - # {acctName => $data, - # maxIbayNameLength => $max, - # maxLength => $max}); - } -} + # {acctName => $data, + # maxIbayNameLength => $max, + # maxLength => $max}); + } ## end else [ if (length($data) <= $max)] +} ## end sub max_ibay_name_length sub conflict_check { - my ($c, $name) = @_; 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('iba_ACCT_CLASHES_WITH_PSEUDONYM', $name, $acct_type, $acct); - } - } - elsif (defined getpwnam($name) || defined getgrnam($name)) - { + 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('iba_ACCT_CLASHES_WITH_PSEUDONYM', $name, $acct_type, $acct); + } ## end if ($type eq "pseudonym") + } elsif (defined getpwnam($name) || defined getgrnam($name)) { $type = 'system'; - } - else - { + } else { + # No account record and no account return 'OK'; } return $c->l('iba_ACCOUNT_EXISTS', $name, $type); -} +} ## end sub conflict_check sub validate_name { - my ($c, $acctName) = @_; - unless ($acctName =~ /^([a-z][\_\.\-a-z0-9]*)$/) - { + unless ($acctName =~ /^([a-z][\_\.\-a-z0-9]*)$/) { return $c->l('iba_ACCT_NAME_HAS_INVALID_CHARS', $acctName); } return "OK"; -} - - +} ## end sub validate_name 1 diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Initial.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Initial.pm index 3cbcf76..cfd1c0a 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Initial.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Initial.pm @@ -9,29 +9,18 @@ package SrvMngr::Controller::Initial; #---------------------------------------------------------------------- use strict; use warnings; - use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session); #use SrvMngr::Model::Main; - - sub main { - my $c = shift; $c->app->log->info($c->log_req); - my $title = $c->l('initial_FORM_TITLE'); my $modul = $c->render_to_string(inline => $c->l('initial_FRAMES_BODY')); - - $c->stash( title => $title, modul => $modul ); - + $c->stash(title => $title, modul => $modul); $c->render(template => 'initial'); - -} - - +} ## end sub main 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Legacypanel.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Legacypanel.pm index 580243b..ed7583b 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Legacypanel.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Legacypanel.pm @@ -10,37 +10,27 @@ package SrvMngr::Controller::Legacypanel; # # routes : end #---------------------------------------------------------------------- - use strict; use warnings; - use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session); #use SrvMngr::Model::Main; - - sub main { - my $c = shift; $c->app->log->info($c->log_req); - - my $title = $c->l('legacy panel'); - my $legacy_url = $c->param('url'); + my $title = $c->l('legacy panel'); + my $legacy_url = $c->param('url'); my $legacy_height = $c->param('height') | 600; - $c->stash( title => $title, modul => $legacy_url, height => $legacy_height ); + $c->stash(title => $title, modul => $legacy_url, height => $legacy_height); $c->render(template => 'embedded'); - -} +} ## end sub main sub getlegacyurl { - my $c = shift; - my $url = shift; - return "/smanager/legacypanel?url=$url"; -} - - + my $c = shift; + my $url = shift; + return "/smanager/legacypanel?url=$url"; +} ## end sub getlegacyurl 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt-Custom.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt-Custom.pm index e6f32d7..8d5b663 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt-Custom.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt-Custom.pm @@ -1,5 +1,5 @@ # -# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-16 10:30:16 +# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-16 10:30:16 # # # Routines to be edited by the developer to provide content and validation for parameters @@ -12,461 +12,555 @@ use esmith::HostsDB; use esmith::AccountsDB; use esmith::NetworksDB; use esmith::DomainsDB; - use constant FALSE => 0; use constant TRUE => 1; - #The most common ones our $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); our $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); our $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db"); -our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); +our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); # Validation routines - parameters for each panel +sub validate_LIST { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + # Validation for each field + my $ret = ""; - sub validate_LIST { - my $c = shift; - my $prefix_data = shift; #Data hash as parameter - # Validation for each field - my $ret = ""; - - if (! TRUE) #validate $c->param('InternalIP') - {$ret .= 'Validation for InternalIP failed';} - if (! TRUE) #validate $c->param('ExternalIP') - {$ret .= 'Validation for ExternalIP failed';} - if (! TRUE) #validate $c->param('InternetIP') - {$ret .= 'Validation for InternetIP failed';} - if (! TRUE) #validate $c->param('Issuer') - {$ret .= 'Validation for Issuer failed';} - if (! TRUE) #validate $c->param('Expiry') - {$ret .= 'Validation for Expiry failed';} - if (! TRUE) #validate $c->param('NotBefore') - {$ret .= 'Validation for NotBefore failed';} - if ($ret eq "") {$ret = 'ok';} - return $ret; - } + if (!TRUE) #validate $c->param('InternalIP') + { + $ret .= 'Validation for InternalIP failed'; + } - sub validate_PARAMS { - my $c = shift; - my $prefix_data = shift; #Data hash as parameter - # Validation for each field - my $ret = ""; - if (! TRUE) #validate $c->param('status') - {$ret .= 'Validation for status failed';} - if (! TRUE) #validate $c->param('hookScript') - {$ret .= 'Validation for hookScript failed';} - if (! TRUE) #validate $c->param('hostOverride') - {$ret .= 'Validation for hostOverride failed';} - if (! TRUE) #validate $c->param('ACCEPT_TERMS') - {$ret .= 'Validation for ACCEPT_TERMS failed';} - if (! TRUE) #validate $c->param('API') - {$ret .= 'Validation for API failed';} - if (! TRUE) #validate $c->param('keysize') - {$ret .= 'Validation for keysize failed';} - if (! TRUE) #validate $c->param('configure') - {$ret .= 'Validation for configure failed';} - if (! TRUE) #validate $c->param('Email') - {$ret .= 'Validation for Email failed';} - if ($ret eq "") {$ret = 'ok';} - return $ret; - } + if (!TRUE) #validate $c->param('ExternalIP') + { + $ret .= 'Validation for ExternalIP failed'; + } - sub validate_CHECKALLDOMAINS { - my $c = shift; - my $prefix_data = shift; #Data hash as parameter - # Validation for each field - my $ret = ""; - - if (! TRUE) #validate $c->param('AllDomainsCheck') - {$ret .= 'Validation for AllDomainsCheck failed';} - if ($ret eq "") {$ret = 'ok';} - return $ret; - } + if (!TRUE) #validate $c->param('InternetIP') + { + $ret .= 'Validation for InternetIP failed'; + } - sub validate_CHECKALLENABLEDDOMAINS { - my $c = shift; - my $prefix_data = shift; #Data hash as parameter - # Validation for each field - my $ret = ""; - - if (! TRUE) #validate $c->param('EnabledDomainsCheck') - {$ret .= 'Validation for EnabledDomainsCheck failed';} - if ($ret eq "") {$ret = 'ok';} - return $ret; - } + if (!TRUE) #validate $c->param('Issuer') + { + $ret .= 'Validation for Issuer failed'; + } - sub validate_CHECKONEDOMAIN { - my $c = shift; - my $prefix_data = shift; #Data hash as parameter - # Validation for each field - my $ret = ""; - - if (! TRUE) #validate $c->param('OneDomainToCheck') - {$ret .= 'Validation for OneDomainToCheck failed';} - if (! TRUE) #validate $c->param('OneDomainsCheck') - {$ret .= 'Validation for OneDomainsCheck failed';} - if ($ret eq "") {$ret = 'ok';} - return $ret; - } + if (!TRUE) #validate $c->param('Expiry') + { + $ret .= 'Validation for Expiry failed'; + } + if (!TRUE) #validate $c->param('NotBefore') + { + $ret .= 'Validation for NotBefore failed'; + } + if ($ret eq "") { $ret = 'ok'; } + return $ret; +} ## end sub validate_LIST + +sub validate_PARAMS { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + # Validation for each field + my $ret = ""; + + if (!TRUE) #validate $c->param('status') + { + $ret .= 'Validation for status failed'; + } + + if (!TRUE) #validate $c->param('hookScript') + { + $ret .= 'Validation for hookScript failed'; + } + + if (!TRUE) #validate $c->param('hostOverride') + { + $ret .= 'Validation for hostOverride failed'; + } + + if (!TRUE) #validate $c->param('ACCEPT_TERMS') + { + $ret .= 'Validation for ACCEPT_TERMS failed'; + } + + if (!TRUE) #validate $c->param('API') + { + $ret .= 'Validation for API failed'; + } + + if (!TRUE) #validate $c->param('keysize') + { + $ret .= 'Validation for keysize failed'; + } + + if (!TRUE) #validate $c->param('configure') + { + $ret .= 'Validation for configure failed'; + } + + if (!TRUE) #validate $c->param('Email') + { + $ret .= 'Validation for Email failed'; + } + if ($ret eq "") { $ret = 'ok'; } + return $ret; +} ## end sub validate_PARAMS + +sub validate_CHECKALLDOMAINS { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + # Validation for each field + my $ret = ""; + + if (!TRUE) #validate $c->param('AllDomainsCheck') + { + $ret .= 'Validation for AllDomainsCheck failed'; + } + if ($ret eq "") { $ret = 'ok'; } + return $ret; +} ## end sub validate_CHECKALLDOMAINS + +sub validate_CHECKALLENABLEDDOMAINS { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + # Validation for each field + my $ret = ""; + + if (!TRUE) #validate $c->param('EnabledDomainsCheck') + { + $ret .= 'Validation for EnabledDomainsCheck failed'; + } + if ($ret eq "") { $ret = 'ok'; } + return $ret; +} ## end sub validate_CHECKALLENABLEDDOMAINS + +sub validate_CHECKONEDOMAIN { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + # Validation for each field + my $ret = ""; + + if (!TRUE) #validate $c->param('OneDomainToCheck') + { + $ret .= 'Validation for OneDomainToCheck failed'; + } + + if (!TRUE) #validate $c->param('OneDomainsCheck') + { + $ret .= 'Validation for OneDomainsCheck failed'; + } + if ($ret eq "") { $ret = 'ok'; } + return $ret; +} ## end sub validate_CHECKONEDOMAIN # Get singleton data for each panel +sub get_data_for_panel_LIST { - 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 ($reply, $err, $server_cert) = Net::SSLeay::sslcat('localhost', 443, '/'); -# my $issuer = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_issuer_name($server_cert)); -# my $before = Net::SSLeay::P_ASN1_TIME_get_isotime(Net::SSLeay::X509_get_notBefore($server_cert)); -# my $expiry = Net::SSLeay::P_ASN1_TIME_get_isotime(Net::SSLeay::X509_get_notAfter($server_cert)); + # 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'] - 'InternalIP'=>$cdb->get_prop('InternalInterface','IPAddress'), - 'ExternalIP'=>$cdb->get_prop('ExternalInterface','IPAddress'), - 'InternetIP'=>$c->get_my_ip(), - 'Issuer'=>'$issuer', - 'Expiry'=>'$expiry', - 'NotBefore'=>'$before', - ); - return %ret; - } + # my ($reply, $err, $server_cert) = Net::SSLeay::sslcat('localhost', 443, '/'); + # my $issuer = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_issuer_name($server_cert)); + # my $before = Net::SSLeay::P_ASN1_TIME_get_isotime(Net::SSLeay::X509_get_notBefore($server_cert)); + # my $expiry = Net::SSLeay::P_ASN1_TIME_get_isotime(Net::SSLeay::X509_get_notAfter($server_cert)); + my %ret = ( + 'Data1' => 'Data for LIST', #Example + # fields from Inputs in LIST $fields['LIST'] + 'InternalIP' => $cdb->get_prop('InternalInterface', 'IPAddress'), + 'ExternalIP' => $cdb->get_prop('ExternalInterface', 'IPAddress'), + 'InternetIP' => $c->get_my_ip(), + 'Issuer' => '$issuer', + 'Expiry' => '$expiry', + 'NotBefore' => '$before', + ); + return %ret; +} ## end sub get_data_for_panel_LIST - sub get_data_for_panel_PARAMS { - # Return a hash with the fields required which will be loaded into the shared data - my $c = shift; - my %ret = ( - 'Data1'=>'Data for PARAMS', #Example - # fields from Inputs in PARAMS $fields['PARAMS'] - 'status'=>$cdb->get_prop('letsencrypt', 'status', 'disabled'), - 'hookScript'=>$cdb->get_prop('letsencrypt', 'hookScript', 'disabled'), - 'hostOverride'=>$cdb->get_prop('letsencrypt', 'hostOverride', 'disabled'), - 'ACCEPT_TERMS'=>$cdb->get_prop('letsencrypt', 'ACCEPT_TERMS', ''), - 'API'=>$cdb->get_prop('letsencrypt', 'API', '2'), - 'keysize'=>$cdb->get_prop('letsencrypt', 'keysize', '4096'), - 'configure'=>$cdb->get_prop('letsencrypt', 'configure', 'none' ), - 'email'=>$cdb->get_prop('letsencrypt', 'email') - ); - return %ret; - } +sub get_data_for_panel_PARAMS { - sub get_data_for_panel_CHECKALLDOMAINS { - # Return a hash with the fields required which will be loaded into the shared data - my $c = shift; - my %ret = ( - 'Data1'=>'Data for CHECKALLDOMAINS', #Example - # fields from Inputs in CHECKALLDOMAINS $fields['CHECKALLDOMAINS'] - 'AllDomainsCheck'=>$c->update_all_domains(), - - ); - return %ret; - } + # Return a hash with the fields required which will be loaded into the shared data + my $c = shift; + my %ret = ( + 'Data1' => 'Data for PARAMS', #Example + # fields from Inputs in PARAMS $fields['PARAMS'] + 'status' => $cdb->get_prop('letsencrypt', 'status', 'disabled'), + 'hookScript' => $cdb->get_prop('letsencrypt', 'hookScript', 'disabled'), + 'hostOverride' => $cdb->get_prop('letsencrypt', 'hostOverride', 'disabled'), + 'ACCEPT_TERMS' => $cdb->get_prop('letsencrypt', 'ACCEPT_TERMS', ''), + 'API' => $cdb->get_prop('letsencrypt', 'API', '2'), + 'keysize' => $cdb->get_prop('letsencrypt', 'keysize', '4096'), + 'configure' => $cdb->get_prop('letsencrypt', 'configure', 'none'), + 'email' => $cdb->get_prop('letsencrypt', 'email') + ); + return %ret; +} ## end sub get_data_for_panel_PARAMS - sub get_data_for_panel_CHECKALLENABLEDDOMAINS { - # Return a hash with the fields required which will be loaded into the shared data - my $c = shift; - my %ret = ( - 'Data1'=>'Data for CHECKALLENABLEDDOMAINS', #Example - # fields from Inputs in CHECKALLENABLEDDOMAINS $fields['CHECKALLENABLEDDOMAINS'] - 'EnabledDomainsCheck'=>$c->update_enabled_domains(), - - ); - return %ret; - } +sub get_data_for_panel_CHECKALLDOMAINS { - sub get_data_for_panel_CHECKONEDOMAIN { - # Return a hash with the fields required which will be loaded into the shared data - my $c = shift; - my %ret = ( - 'Data1'=>'Data for CHECKONEDOMAIN', #Example - # fields from Inputs in CHECKONEDOMAIN $fields['CHECKONEDOMAIN'] - 'OneDomainToCheck'=>$c->param("CHECKONEDOMAIN"), - 'OneDomainsCheck'=>$c->update_one_domain($c->param("CHECKONEDOMAIN")) - ); - return %ret; - } + # Return a hash with the fields required which will be loaded into the shared data + my $c = shift; + my %ret = ( + 'Data1' => 'Data for CHECKALLDOMAINS', #Example + # fields from Inputs in CHECKALLDOMAINS $fields['CHECKALLDOMAINS'] + 'AllDomainsCheck' => $c->update_all_domains(), + ); + return %ret; +} ## end sub get_data_for_panel_CHECKALLDOMAINS +sub get_data_for_panel_CHECKALLENABLEDDOMAINS { + # Return a hash with the fields required which will be loaded into the shared data + my $c = shift; + my %ret = ( + 'Data1' => 'Data for CHECKALLENABLEDDOMAINS', #Example + # fields from Inputs in CHECKALLENABLEDDOMAINS $fields['CHECKALLENABLEDDOMAINS'] + 'EnabledDomainsCheck' => $c->update_enabled_domains(), + ); + return %ret; +} ## end sub get_data_for_panel_CHECKALLENABLEDDOMAINS + +sub get_data_for_panel_CHECKONEDOMAIN { + + # Return a hash with the fields required which will be loaded into the shared data + my $c = shift; + my %ret = ( + 'Data1' => 'Data for CHECKONEDOMAIN', #Example + # fields from Inputs in CHECKONEDOMAIN $fields['CHECKONEDOMAIN'] + 'OneDomainToCheck' => $c->param("CHECKONEDOMAIN"), + 'OneDomainsCheck' => $c->update_one_domain($c->param("CHECKONEDOMAIN")) + ); + return %ret; +} ## end sub get_data_for_panel_CHECKONEDOMAIN # Get control data for table(s) +# Define a constant hash for field name mapping +use constant DomainList_FIELD_MAPPING => ( + 'Table1-Domain name / HOSTNAME' => 'Domain', + 'Table1-Brief description' => 'Description', + 'Table1-Content' => 'Content', + 'Table1-LABEL_NAMESERVERS' => 'Nameservers', + 'Table1-LABEL_POINT' => 'Source-for-Table1-LABEL_POINT', + 'Table1-LABEL_LECERT' => 'letsencryptSSLcert', + 'Table1-IS_IN_CERT' => 'isincert', + 'Table1-CHECK' => 'Check' - # Define a constant hash for field name mapping - use constant DomainList_FIELD_MAPPING => ( - 'Table1-Domain name / HOSTNAME' => 'Domain', - 'Table1-Brief description' => 'Description', - 'Table1-Content' => 'Content', - 'Table1-LABEL_NAMESERVERS' => 'Nameservers', - 'Table1-LABEL_POINT' => 'Source-for-Table1-LABEL_POINT', - 'Table1-LABEL_LECERT' => 'letsencryptSSLcert', - 'Table1-IS_IN_CERT' => 'isincert', - 'Table1-CHECK' => 'Check' - #'target_field2' => 'source_field2', - # Add more mappings as needed - ); - - + #'target_field2' => 'source_field2', + # Add more mappings as needed +); use constant TEST_DOMAIN_LIST => ( - { "domain" => "Domain1","fred" => "fred1" , "description"=>"Description1"}, - { "domain" => "Domain2", "fred" => "fred2", "description"=>"Description2" }, - { "domain" => "Domain3", "fred" => "fred3", "description"=>"Description3" }, + { "domain" => "Domain1", "fred" => "fred1", "description" => "Description1" }, + { "domain" => "Domain2", "fred" => "fred2", "description" => "Description2" }, + { "domain" => "Domain3", "fred" => "fred3", "description" => "Description3" }, + # Add more test entries as needed ); sub actual_DomainList { - my $c = shift; - # Actual code for extracting DomainList - my @list = (); -# my @rv = Net::SSLeay::X509_get_subjectAltNames($server_cert); -# foreach my $element (@rv) { -# next if $element =~ /^\d+$/; ; -# #print $element . "\n"; -# push @list, $element; -# } - my @data = (); - my $check = $c->l('Check Domain'); - for ($ddb->domains) - { - my $ns = $_->prop('Nameservers') || 'internet'; - my $le = $_->prop('letsencryptSSLcert') || 'disabled';#letsencrypt configure all - my $dname= $_->key; - my $isincert = "N"; - my $link = $c->create_link("letsencryptd","CHECKONEDOMAIN",""); - my $checklink = "".$check.""; - #my $checklink = "check"; - $isincert = "Y" if ( $dname ~~ @list); - # domain - push @data, - { Domain => $_->key, - $_->props, - letsencryptSSLcert => $le, - isincert => $isincert, - Check => $checklink, - Nameservers => $ns, - }; - #and hosts - for my $h ($hdb->get_hosts_by_domain($dname)) - { - next if $ddb->get($h->key); - next unless ($h->prop('HostType') eq "Self" || $h->prop('HostType') eq "Local"); - $le = $h->prop('letsencryptSSLcert') || 'disabled';#letsencrypt configure all - $isincert = "N"; - $isincert = "Y" if ( $h->key ~~ @list); - push @data, - { Domain => "--> ". $h->key, - $h->props, - Description=>$h->prop('ExternalIP')|| $h->prop('InternalIP')||"", - Content => $h->prop('HostType'), - isincert => $isincert, - Check => "", #$checklink - Nameservers => $c->l($ns), - } - } - } - return @data; -} + my $c = shift; + + # Actual code for extracting DomainList + my @list = (); + + # my @rv = Net::SSLeay::X509_get_subjectAltNames($server_cert); + # foreach my $element (@rv) { + # next if $element =~ /^\d+$/; ; + # #print $element . "\n"; + # push @list, $element; + # } + my @data = (); + my $check = $c->l('Check Domain'); + + for ($ddb->domains) { + my $ns = $_->prop('Nameservers') || 'internet'; + my $le = $_->prop('letsencryptSSLcert') || 'disabled'; #letsencrypt configure all + my $dname = $_->key; + my $isincert = "N"; + my $link = $c->create_link("letsencryptd", "CHECKONEDOMAIN", ""); + my $checklink = "" . $check . ""; + + #my $checklink = "check"; + $isincert = "Y" if ($dname ~~ @list); + + # domain + push @data, + { + Domain => $_->key, + $_->props, + letsencryptSSLcert => $le, + isincert => $isincert, + Check => $checklink, + Nameservers => $ns, + }; + + #and hosts + for my $h ($hdb->get_hosts_by_domain($dname)) { + next if $ddb->get($h->key); + next unless ($h->prop('HostType') eq "Self" || $h->prop('HostType') eq "Local"); + $le = $h->prop('letsencryptSSLcert') || 'disabled'; #letsencrypt configure all + $isincert = "N"; + $isincert = "Y" if ($h->key ~~ @list); + push @data, { + Domain => "--> " . $h->key, + $h->props, + Description => $h->prop('ExternalIP') || $h->prop('InternalIP') || "", + Content => $h->prop('HostType'), + isincert => $isincert, + Check => "", #$checklink + Nameservers => $c->l($ns), + }; + } ## end for my $h ($hdb->get_hosts_by_domain...) + } ## end for ($ddb->domains) + return @data; +} ## end sub actual_DomainList sub get_DomainList { + # Return an array of hashes of the contents for each row and column for DomainList - my $c = shift; - my @source_records = $c->actual_DomainList(); #TEST_DOMAIN_LIST #Replace by code or call to produce contents of table; + my $c = shift; + my @source_records + = $c->actual_DomainList(); #TEST_DOMAIN_LIST #Replace by code or call to produce contents of table; my @transformed_records; my %Field_Mapping = DomainList_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}; } - } + } ## end while (my ($target, $source...)) + # Add transformed record to the array if it's not empty push @transformed_records, \%transformed_record if %transformed_record; - } + } ## end for my $source_record (...) return \@transformed_records; -} - - +} ## end sub get_DomainList # 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; +} ## end sub get_selected_LIST - 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_PARAMS { + 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; +} ## end sub get_selected_PARAMS - sub get_selected_PARAMS { - 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_CHECKALLDOMAINS { + 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; +} ## end sub get_selected_CHECKALLDOMAINS - sub get_selected_CHECKALLDOMAINS { - 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_CHECKALLENABLEDDOMAINS { - 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_CHECKONEDOMAIN { - 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_CHECKALLENABLEDDOMAINS { + 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; +} ## end sub get_selected_CHECKALLENABLEDDOMAINS +sub get_selected_CHECKONEDOMAIN { + 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; +} ## end sub get_selected_CHECKONEDOMAIN #after sucessful modify or create or whatever and submit then perfom (if the params validate) +sub perform_LIST { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + my $ret = ""; + my $db = $cdb; #maybe one of the others + my $dbkey = 'ChangeThis'; - sub perform_LIST { - my $c = shift; - my $prefix_data = shift; #Data hash as parameter - my $ret = ""; - my $db = $cdb; #maybe one of the others - my $dbkey = 'ChangeThis'; - - if (! TRUE) #copy or perform with value: InternalIP e.g. $db->set_prop($dbkey,'InternalIP',$c->param('InternalIP'),type=>'service')) - {$ret .= 'Perform/save failed for InternalIP';} - if (! TRUE) #copy or perform with value: ExternalIP e.g. $db->set_prop($dbkey,'ExternalIP',$c->param('ExternalIP'),type=>'service')) - {$ret .= 'Perform/save failed for ExternalIP';} - if (! TRUE) #copy or perform with value: InternetIP e.g. $db->set_prop($dbkey,'InternetIP',$c->param('InternetIP'),type=>'service')) - {$ret .= 'Perform/save failed for InternetIP';} - if (! TRUE) #copy or perform with value: Issuer e.g. $db->set_prop($dbkey,'Issuer',$c->param('Issuer'),type=>'service')) - {$ret .= 'Perform/save failed for Issuer';} - if (! TRUE) #copy or perform with value: Expiry e.g. $db->set_prop($dbkey,'Expiry',$c->param('Expiry'),type=>'service')) - {$ret .= 'Perform/save failed for Expiry';} - if (! TRUE) #copy or perform with value: NotBefore e.g. $db->set_prop($dbkey,'NotBefore',$c->param('NotBefore'),type=>'service')) - {$ret .= 'Perform/save failed for NotBefore';} - if ($ret eq "") {$ret = 'ok';} - return $ret; - } + if (!TRUE + ) #copy or perform with value: InternalIP e.g. $db->set_prop($dbkey,'InternalIP',$c->param('InternalIP'),type=>'service')) + { + $ret .= 'Perform/save failed for InternalIP'; + } ## end if (!TRUE) - sub perform_PARAMS { - my $c = shift; - my $prefix_data = shift; #Data hash as parameter - my $ret = ""; - my $db = $cdb; #maybe one of the others - my $dbkey = 'letsencrypt'; - # 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 (! $db->set_prop($dbkey,'status',$c->param('status'),type=>'service')) - {$ret .= 'Perform/save failed for status';} - if (! $db->set_prop($dbkey,'hookScript',$c->param('hookScript'),type=>'service')) - {$ret .= 'Perform/save failed for hookScript';} - if (! $db->set_prop($dbkey,'hostOverride',$c->param('hostOverride'),type=>'service')) - {$ret .= 'Perform/save failed for hostOverride';} - if (! $db->set_prop($dbkey,'ACCEPT_TERMS',$c->param('ACCEPT_TERMS'),type=>'service')) - {$ret .= 'Perform/save failed for ACCEPT_TERMS';} - if (! $db->set_prop($dbkey,'API',$c->param('API'),type=>'service')) - {$ret .= 'Perform/save failed for API';} - if (! $db->set_prop($dbkey,'keysize',$c->param('keysize'),type=>'service')) - {$ret .= 'Perform/save failed for keysize';} - if (! $db->set_prop($dbkey,'configure',$c->param('configure'),type=>'service')) - {$ret .= 'Perform/save failed for configure';} - if (! $db->set_prop($dbkey,'email',$c->param('email'),type=>'service')) - {$ret .= 'Perform/save failed for email';} - if ($ret eq "") {$ret = 'ok';} - return $ret; - } - - sub perform_CHECKALLDOMAINS { - my $c = shift; - my $prefix_data = shift; #Data hash as parameter - my $ret = ""; - my $db = $cdb; #maybe one of the others - my $dbkey = 'ChangeThis'; - - if (! TRUE) #copy or perform with value: AllDomainsCheck e.g. $db->set_prop($dbkey,'AllDomainsCheck',$c->param('AllDomainsCheck'),type=>'service')) - {$ret .= 'Perform/save failed for AllDomainsCheck';} - if ($ret eq "") {$ret = 'ok';} - return $ret; - } + if (!TRUE + ) #copy or perform with value: ExternalIP e.g. $db->set_prop($dbkey,'ExternalIP',$c->param('ExternalIP'),type=>'service')) + { + $ret .= 'Perform/save failed for ExternalIP'; + } ## end if (!TRUE) - sub perform_CHECKALLENABLEDDOMAINS { - my $c = shift; - my $prefix_data = shift; #Data hash as parameter - my $ret = ""; - my $db = $cdb; #maybe one of the others - my $dbkey = 'ChangeThis'; - - if (! TRUE) #copy or perform with value: EnabledDomainsCheck e.g. $db->set_prop($dbkey,'EnabledDomainsCheck',$c->param('EnabledDomainsCheck'),type=>'service')) - {$ret .= 'Perform/save failed for EnabledDomainsCheck';} - if ($ret eq "") {$ret = 'ok';} - return $ret; - } + if (!TRUE + ) #copy or perform with value: InternetIP e.g. $db->set_prop($dbkey,'InternetIP',$c->param('InternetIP'),type=>'service')) + { + $ret .= 'Perform/save failed for InternetIP'; + } ## end if (!TRUE) - sub perform_CHECKONEDOMAIN { - my $c = shift; - my $prefix_data = shift; #Data hash as parameter - my $ret = ""; - my $db = $cdb; #maybe one of the others - my $dbkey = 'ChangeThis'; - - if (! TRUE) #copy or perform with value: OneDomainToCheck e.g. $db->set_prop($dbkey,'OneDomainToCheck',$c->param('OneDomainToCheck'),type=>'service')) - {$ret .= 'Perform/save failed for OneDomainToCheck';} - if (! TRUE) #copy or perform with value: OneDomainsCheck e.g. $db->set_prop($dbkey,'OneDomainsCheck',$c->param('OneDomainsCheck'),type=>'service')) - {$ret .= 'Perform/save failed for OneDomainsCheck';} - if ($ret eq "") {$ret = 'ok';} - return $ret; - } + if (!TRUE + ) #copy or perform with value: Issuer e.g. $db->set_prop($dbkey,'Issuer',$c->param('Issuer'),type=>'service')) + { + $ret .= 'Perform/save failed for Issuer'; + } ## end if (!TRUE) + if (!TRUE + ) #copy or perform with value: Expiry e.g. $db->set_prop($dbkey,'Expiry',$c->param('Expiry'),type=>'service')) + { + $ret .= 'Perform/save failed for Expiry'; + } ## end if (!TRUE) -sub create_link{ - # WIP - my ($c,$route, $panel, $index) = @_; - my $link = "$route?trt=$panel&Selected=$index"; - return $link; -} + if (!TRUE + ) #copy or perform with value: NotBefore e.g. $db->set_prop($dbkey,'NotBefore',$c->param('NotBefore'),type=>'service')) + { + $ret .= 'Perform/save failed for NotBefore'; + } ## end if (!TRUE) + if ($ret eq "") { $ret = 'ok'; } + return $ret; +} ## end sub perform_LIST -sub get_my_ip -{ +sub perform_PARAMS { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + my $ret = ""; + my $db = $cdb; #maybe one of the others + my $dbkey = 'letsencrypt'; + +# 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 (!$db->set_prop($dbkey, 'status', $c->param('status'), type => 'service')) { + $ret .= 'Perform/save failed for status'; + } + + if (!$db->set_prop($dbkey, 'hookScript', $c->param('hookScript'), type => 'service')) { + $ret .= 'Perform/save failed for hookScript'; + } + + if (!$db->set_prop($dbkey, 'hostOverride', $c->param('hostOverride'), type => 'service')) { + $ret .= 'Perform/save failed for hostOverride'; + } + + if (!$db->set_prop($dbkey, 'ACCEPT_TERMS', $c->param('ACCEPT_TERMS'), type => 'service')) { + $ret .= 'Perform/save failed for ACCEPT_TERMS'; + } + if (!$db->set_prop($dbkey, 'API', $c->param('API'), type => 'service')) { $ret .= 'Perform/save failed for API'; } + + if (!$db->set_prop($dbkey, 'keysize', $c->param('keysize'), type => 'service')) { + $ret .= 'Perform/save failed for keysize'; + } + + if (!$db->set_prop($dbkey, 'configure', $c->param('configure'), type => 'service')) { + $ret .= 'Perform/save failed for configure'; + } + + if (!$db->set_prop($dbkey, 'email', $c->param('email'), type => 'service')) { + $ret .= 'Perform/save failed for email'; + } + if ($ret eq "") { $ret = 'ok'; } + return $ret; +} ## end sub perform_PARAMS + +sub perform_CHECKALLDOMAINS { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + my $ret = ""; + my $db = $cdb; #maybe one of the others + my $dbkey = 'ChangeThis'; + + if (!TRUE + ) #copy or perform with value: AllDomainsCheck e.g. $db->set_prop($dbkey,'AllDomainsCheck',$c->param('AllDomainsCheck'),type=>'service')) + { + $ret .= 'Perform/save failed for AllDomainsCheck'; + } ## end if (!TRUE) + if ($ret eq "") { $ret = 'ok'; } + return $ret; +} ## end sub perform_CHECKALLDOMAINS + +sub perform_CHECKALLENABLEDDOMAINS { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + my $ret = ""; + my $db = $cdb; #maybe one of the others + my $dbkey = 'ChangeThis'; + + if (!TRUE + ) #copy or perform with value: EnabledDomainsCheck e.g. $db->set_prop($dbkey,'EnabledDomainsCheck',$c->param('EnabledDomainsCheck'),type=>'service')) + { + $ret .= 'Perform/save failed for EnabledDomainsCheck'; + } ## end if (!TRUE) + if ($ret eq "") { $ret = 'ok'; } + return $ret; +} ## end sub perform_CHECKALLENABLEDDOMAINS + +sub perform_CHECKONEDOMAIN { + my $c = shift; + my $prefix_data = shift; #Data hash as parameter + my $ret = ""; + my $db = $cdb; #maybe one of the others + my $dbkey = 'ChangeThis'; + + if (!TRUE + ) #copy or perform with value: OneDomainToCheck e.g. $db->set_prop($dbkey,'OneDomainToCheck',$c->param('OneDomainToCheck'),type=>'service')) + { + $ret .= 'Perform/save failed for OneDomainToCheck'; + } ## end if (!TRUE) + + if (!TRUE + ) #copy or perform with value: OneDomainsCheck e.g. $db->set_prop($dbkey,'OneDomainsCheck',$c->param('OneDomainsCheck'),type=>'service')) + { + $ret .= 'Perform/save failed for OneDomainsCheck'; + } ## end if (!TRUE) + if ($ret eq "") { $ret = 'ok'; } + return $ret; +} ## end sub perform_CHECKONEDOMAIN + +sub create_link { + + # WIP + my ($c, $route, $panel, $index) = @_; + my $link = "$route?trt=$panel&Selected=$index"; + return $link; +} ## end sub create_link + +sub get_my_ip { my ($self, $item, $prop, $default) = @_; my $output = `/usr/sbin/e-smith/getmyip`; - return $output || "IP"; -} + return $output || "IP"; +} ## end sub get_my_ip -sub update_one_domain -{ - my ($self,$domain) = @_; +sub update_one_domain { + my ($self, $domain) = @_; return "$domain not domain" unless ($ddb->get($domain) || $hdb->get($domain)); - ($domain) = ($domain =~ /([\w\p{L}.]+)/); + ($domain) = ($domain =~ /([\w\p{L}.]+)/); my $output = `/etc/e-smith/events/actions/letsencrypt-setdomains " " $domain `; - return $output || "-empty-"; -} + return $output || "-empty-"; +} ## end sub update_one_domain -sub update_all_domains -{ - my $self = shift; +sub update_all_domains { + my $self = shift; my $output = `/etc/e-smith/events/actions/letsencrypt-setdomains "" "" all `; - return $output || "-empty-"; -} + return $output || "-empty-"; +} ## end sub update_all_domains -sub update_enabled_domains -{ - my $self = shift; +sub update_enabled_domains { + my $self = shift; my $output = `/etc/e-smith/events/actions/letsencrypt-setdomains "" "" enabled `; - return $output || "-empty-"; -} - - -1; \ No newline at end of file + return $output || "-empty-"; +} ## end sub update_enabled_domains +1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt.pm index 220b439..0d3df42 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt.pm @@ -1,6 +1,6 @@ package SrvMngr::Controller::Letsencrypt; # -# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43 +# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-12-01 15:22:43 # #---------------------------------------------------------------------- # heading : Network @@ -15,25 +15,19 @@ package SrvMngr::Controller::Letsencrypt; # # Documentation: https://wiki.contribs.org/Letsencrypt #---------------------------------------------------------------------- - # # 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; @@ -41,389 +35,414 @@ use esmith::AccountsDB; use esmith::NetworksDB; use esmith::HostsDB; use esmith::DomainsDB; - - - -require '/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt-Custom.pm'; #The code that is to be added by the developer +require + '/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt-Custom.pm'; #The code that is to be added by the developer sub main { -# -# Initial entry - route is "/" -# -#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 - my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); - my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); - my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db"); - my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); - my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); - - my %lets_data = (); - my $title = $c->l('lets_Letsencrypt_certificate'); - my $modul = ''; - - $lets_data{'trt'} = 'LIST'; - - #Load any DB entries into the _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($lets_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 "/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--update exists - #signal_event smeserver--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 - + # + # Initial entry - route is "/" + # + #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); - my $modul = ''; - - #The most common ones - you might want to comment out any not used. - my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); - my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); - my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db"); - my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); - my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); + #The most common ones + my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); + my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); + my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db"); + my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); + my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); my %lets_data = (); - my $title = $c->l('lets_Letsencrypt_certificate'); + my $title = $c->l('lets_Letsencrypt_certificate'); + my $modul = ''; + $lets_data{'trt'} = 'LIST'; - # Accessing all POST parameters + #Load any DB entries into the _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($lets_data{'trt'}); +} ## end sub main + +# Post request with params - submit from the form +sub do_update { + # + # Return after submit pushed on panel (this is a post) - route is "/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--update exists + #signal_event smeserver--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. + my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); + my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); + my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db"); + my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); + my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); + my %lets_data = (); + my $title = $c->l('lets_Letsencrypt_certificate'); + + # Accessing all POST parameters my %params = $c->req->params->to_hash; # Get number of POST parameters my $num_params = keys %params; - + #Params are available in the hash "params" - copy to the prefix_data hash #while (my ($key, $value) = each %{$c->req->params->to_hash}) { # $lets_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. + # 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(\%lets_data); - $thispanel = 'LIST'; - } - - if ($trt eq 'PARAMS'){ - #Validate form parameters for panel PARAMS - $ret = $c->validate_PARAMS(\%lets_data); - $thispanel = 'PARAMS'; - } - - if ($trt eq 'CHECKALLDOMAINS'){ - #Validate form parameters for panel CHECKALLDOMAINS - $ret = $c->validate_CHECKALLDOMAINS(\%lets_data); - $thispanel = 'CHECKALLDOMAINS'; - } - - if ($trt eq 'CHECKALLENABLEDDOMAINS'){ - #Validate form parameters for panel CHECKALLENABLEDDOMAINS - $ret = $c->validate_CHECKALLENABLEDDOMAINS(\%lets_data); - $thispanel = 'CHECKALLENABLEDDOMAINS'; - } - - if ($trt eq 'CHECKONEDOMAIN'){ - #Validate form parameters for panel CHECKONEDOMAIN - $ret = $c->validate_CHECKONEDOMAIN(\%lets_data); - $thispanel = 'CHECKONEDOMAIN'; - } - - if ($ret ne "ok"){ - $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(\%lets_data); - if ($ret ne "ok") { - # return to the panel with error message - $c->stash(error => $c->l($ret)); - $c->stash( - title => $title, - modul => $modul, - lets_data => \%lets_data - ); - $c->render(template => "letsencrypt"); - } else { - $c->stash( success => $c->l('lets_LIST_panel_action_was_successful')); #A bit bland - edit it in the lex file - } - } - - if ($trt eq 'PARAMS'){ - #do whatever is required ... - $ret = $c->perform_PARAMS(\%lets_data); - if ($ret ne "ok") { - # return to the panel with error message - $c->stash(error => $c->l($ret)); - $c->stash( - title => $title, - modul => $modul, - lets_data => \%lets_data - ); - $c->render(template => "letsencrypt"); - } else { - $c->stash( success => $c->l('lets_PARAMS_panel_action_was_successful')); #A bit bland - edit it in the lex file - } - } - - if ($trt eq 'CHECKALLDOMAINS'){ - #do whatever is required ... - $ret = $c->perform_CHECKALLDOMAINS(\%lets_data); - if ($ret ne "ok") { - # return to the panel with error message - $c->stash(error => $c->l($ret)); - $c->stash( - title => $title, - modul => $modul, - lets_data => \%lets_data - ); - $c->render(template => "letsencrypt"); - } else { - $c->stash( success => $c->l('lets_CHECKALLDOMAINS_panel_action_was_successful')); #A bit bland - edit it in the lex file - } - } - - if ($trt eq 'CHECKALLENABLEDDOMAINS'){ - #do whatever is required ... - $ret = $c->perform_CHECKALLENABLEDDOMAINS(\%lets_data); - if ($ret ne "ok") { - # return to the panel with error message - $c->stash(error => $c->l($ret)); - $c->stash( - title => $title, - modul => $modul, - lets_data => \%lets_data - ); - $c->render(template => "letsencrypt"); - } else { - $c->stash( success => $c->l('lets_CHECKALLENABLEDDOMAINS_panel_action_was_successful')); #A bit bland - edit it in the lex file - } - } - - if ($trt eq 'CHECKONEDOMAIN'){ - #do whatever is required ... - $ret = $c->perform_CHECKONEDOMAIN(\%lets_data); - if ($ret ne "ok") { - # return to the panel with error message - $c->stash(error => $c->l($ret)); - $c->stash( - title => $title, - modul => $modul, - lets_data => \%lets_data - ); - $c->render(template => "letsencrypt"); - } else { - $c->stash( success => $c->l('lets_CHECKONEDOMAIN_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') { - $lets_data{'trt'} = 'LIST'; - } else { - $lets_data{'trt'} = 'none'; - } - $c->do_display($lets_data{'trt'}); - } -} + + if ($trt eq 'LIST') { + + #Validate form parameters for panel LIST + $ret = $c->validate_LIST(\%lets_data); + $thispanel = 'LIST'; + } ## end if ($trt eq 'LIST') + + if ($trt eq 'PARAMS') { + + #Validate form parameters for panel PARAMS + $ret = $c->validate_PARAMS(\%lets_data); + $thispanel = 'PARAMS'; + } ## end if ($trt eq 'PARAMS') + + if ($trt eq 'CHECKALLDOMAINS') { + + #Validate form parameters for panel CHECKALLDOMAINS + $ret = $c->validate_CHECKALLDOMAINS(\%lets_data); + $thispanel = 'CHECKALLDOMAINS'; + } ## end if ($trt eq 'CHECKALLDOMAINS') + + if ($trt eq 'CHECKALLENABLEDDOMAINS') { + + #Validate form parameters for panel CHECKALLENABLEDDOMAINS + $ret = $c->validate_CHECKALLENABLEDDOMAINS(\%lets_data); + $thispanel = 'CHECKALLENABLEDDOMAINS'; + } ## end if ($trt eq 'CHECKALLENABLEDDOMAINS') + + if ($trt eq 'CHECKONEDOMAIN') { + + #Validate form parameters for panel CHECKONEDOMAIN + $ret = $c->validate_CHECKONEDOMAIN(\%lets_data); + $thispanel = 'CHECKONEDOMAIN'; + } ## end if ($trt eq 'CHECKONEDOMAIN') + + if ($ret ne "ok") { + $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(\%lets_data); + + if ($ret ne "ok") { + + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->stash( + title => $title, + modul => $modul, + lets_data => \%lets_data + ); + $c->render(template => "letsencrypt"); + } else { + $c->stash(success => $c->l('lets_LIST_panel_action_was_successful')) + ; #A bit bland - edit it in the lex file + } + } ## end if ($trt eq 'LIST') + + if ($trt eq 'PARAMS') { + + #do whatever is required ... + $ret = $c->perform_PARAMS(\%lets_data); + + if ($ret ne "ok") { + + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->stash( + title => $title, + modul => $modul, + lets_data => \%lets_data + ); + $c->render(template => "letsencrypt"); + } else { + $c->stash(success => $c->l('lets_PARAMS_panel_action_was_successful')) + ; #A bit bland - edit it in the lex file + } + } ## end if ($trt eq 'PARAMS') + + if ($trt eq 'CHECKALLDOMAINS') { + + #do whatever is required ... + $ret = $c->perform_CHECKALLDOMAINS(\%lets_data); + + if ($ret ne "ok") { + + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->stash( + title => $title, + modul => $modul, + lets_data => \%lets_data + ); + $c->render(template => "letsencrypt"); + } else { + $c->stash(success => $c->l('lets_CHECKALLDOMAINS_panel_action_was_successful')) + ; #A bit bland - edit it in the lex file + } + } ## end if ($trt eq 'CHECKALLDOMAINS') + + if ($trt eq 'CHECKALLENABLEDDOMAINS') { + + #do whatever is required ... + $ret = $c->perform_CHECKALLENABLEDDOMAINS(\%lets_data); + + if ($ret ne "ok") { + + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->stash( + title => $title, + modul => $modul, + lets_data => \%lets_data + ); + $c->render(template => "letsencrypt"); + } else { + $c->stash(success => $c->l('lets_CHECKALLENABLEDDOMAINS_panel_action_was_successful')) + ; #A bit bland - edit it in the lex file + } + } ## end if ($trt eq 'CHECKALLENABLEDDOMAINS') + + if ($trt eq 'CHECKONEDOMAIN') { + + #do whatever is required ... + $ret = $c->perform_CHECKONEDOMAIN(\%lets_data); + + if ($ret ne "ok") { + + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->stash( + title => $title, + modul => $modul, + lets_data => \%lets_data + ); + $c->render(template => "letsencrypt"); + } else { + $c->stash(success => $c->l('lets_CHECKONEDOMAIN_panel_action_was_successful')) + ; #A bit bland - edit it in the lex file + } + } ## end if ($trt eq 'CHECKONEDOMAIN') + + # and call any signal-events needed + #TBD + # Setup shared data and call panel + if ('none' eq 'none') { + $lets_data{'trt'} = 'LIST'; + } else { + $lets_data{'trt'} = 'none'; + } + $c->do_display($lets_data{'trt'}); + } ## end else [ if ($ret ne "ok") ] +} ## end sub do_update sub do_display { -# -# Return after link clicked in table (this is a get) - route is "/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) = @_; + # + # Return after link clicked in table (this is a get) - route is "/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. - my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); - my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); - my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db"); - my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); - my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); - + #The most common ones - you might want to comment out any not used. + my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); + my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); + my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db"); + my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db"); + my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); my %lets_data = (); - my $title = $c->l('lets_Letsencrypt_certificate'); - my $modul = ""; + my $title = $c->l('lets_Letsencrypt_certificate'); + my $modul = ""; - # Accessing all parameters + # 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}) { # $lets_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 + } - # 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($lets_data{'Selected'},$is_new_record); - } - - if ($trt eq 'PARAMS'){ - #Validate Get selected row (if applicable) PARAMS - %selectedrow = $c->get_selected_PARAMS($lets_data{'Selected'},$is_new_record); - } - - if ($trt eq 'CHECKALLDOMAINS'){ - #Validate Get selected row (if applicable) CHECKALLDOMAINS - %selectedrow = $c->get_selected_CHECKALLDOMAINS($lets_data{'Selected'},$is_new_record); - } - - if ($trt eq 'CHECKALLENABLEDDOMAINS'){ - #Validate Get selected row (if applicable) CHECKALLENABLEDDOMAINS - %selectedrow = $c->get_selected_CHECKALLENABLEDDOMAINS($lets_data{'Selected'},$is_new_record); - } - - if ($trt eq 'CHECKONEDOMAIN'){ - #Validate Get selected row (if applicable) CHECKONEDOMAIN - %selectedrow = $c->get_selected_CHECKONEDOMAIN($lets_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){ + + if ($trt eq 'LIST') { + + #Validate Get selected row (if applicable) LIST + %selectedrow = $c->get_selected_LIST($lets_data{'Selected'}, $is_new_record); + } ## end if ($trt eq 'LIST') + + if ($trt eq 'PARAMS') { + + #Validate Get selected row (if applicable) PARAMS + %selectedrow = $c->get_selected_PARAMS($lets_data{'Selected'}, $is_new_record); + } ## end if ($trt eq 'PARAMS') + + if ($trt eq 'CHECKALLDOMAINS') { + + #Validate Get selected row (if applicable) CHECKALLDOMAINS + %selectedrow = $c->get_selected_CHECKALLDOMAINS($lets_data{'Selected'}, $is_new_record); + } ## end if ($trt eq 'CHECKALLDOMAINS') + + if ($trt eq 'CHECKALLENABLEDDOMAINS') { + + #Validate Get selected row (if applicable) CHECKALLENABLEDDOMAINS + %selectedrow = $c->get_selected_CHECKALLENABLEDDOMAINS($lets_data{'Selected'}, $is_new_record); + } ## end if ($trt eq 'CHECKALLENABLEDDOMAINS') + + if ($trt eq 'CHECKONEDOMAIN') { + + #Validate Get selected row (if applicable) CHECKONEDOMAIN + %selectedrow = $c->get_selected_CHECKONEDOMAIN($lets_data{'Selected'}, $is_new_record); + } ## end if ($trt eq 'CHECKONEDOMAIN') + + #Copy in the selected row params to the prefix_data hash to pass to the panel + while (my ($key, $value) = each %selectedrow) { $lets_data{$key} = $value; } - # Where to go now - $lets_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) { - $lets_data{$key} = $value; - } - } - - if ($trt eq 'PARAMS'){ - # 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_PARAMS(); - # Copy each key-value pair from the returned hash to the prefix data hash - while (my ($key, $value) = each %returned_hash) { - $lets_data{$key} = $value; - } - } - - if ($trt eq 'CHECKALLDOMAINS'){ - # 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_CHECKALLDOMAINS(); - # Copy each key-value pair from the returned hash to the prefix data hash - while (my ($key, $value) = each %returned_hash) { - $lets_data{$key} = $value; - } - } - - if ($trt eq 'CHECKALLENABLEDDOMAINS'){ - # 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_CHECKALLENABLEDDOMAINS(); - # Copy each key-value pair from the returned hash to the prefix data hash - while (my ($key, $value) = each %returned_hash) { - $lets_data{$key} = $value; - } - } - - if ($trt eq 'CHECKONEDOMAIN'){ - # 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_CHECKONEDOMAIN(); - # Copy each key-value pair from the returned hash to the prefix data hash - while (my ($key, $value) = each %returned_hash) { - $lets_data{$key} = $value; - } - } - - - # and table control fields - $c->stash(DomainList=>$c->get_DomainList()); - - - # Data for panel - $c->stash( - title => $title, - modul => $modul, - lets_data => \%lets_data - ); - $c->render(template => "letsencrypt"); -} -1; \ No newline at end of file + + # Where to go now + $lets_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) { + $lets_data{$key} = $value; + } + } ## end if ($trt eq 'LIST') + + if ($trt eq 'PARAMS') { + + # 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_PARAMS(); + + # Copy each key-value pair from the returned hash to the prefix data hash + while (my ($key, $value) = each %returned_hash) { + $lets_data{$key} = $value; + } + } ## end if ($trt eq 'PARAMS') + + if ($trt eq 'CHECKALLDOMAINS') { + + # 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_CHECKALLDOMAINS(); + + # Copy each key-value pair from the returned hash to the prefix data hash + while (my ($key, $value) = each %returned_hash) { + $lets_data{$key} = $value; + } + } ## end if ($trt eq 'CHECKALLDOMAINS') + + if ($trt eq 'CHECKALLENABLEDDOMAINS') { + + # 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_CHECKALLENABLEDDOMAINS(); + + # Copy each key-value pair from the returned hash to the prefix data hash + while (my ($key, $value) = each %returned_hash) { + $lets_data{$key} = $value; + } + } ## end if ($trt eq 'CHECKALLENABLEDDOMAINS') + + if ($trt eq 'CHECKONEDOMAIN') { + + # 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_CHECKONEDOMAIN(); + + # Copy each key-value pair from the returned hash to the prefix data hash + while (my ($key, $value) = each %returned_hash) { + $lets_data{$key} = $value; + } + } ## end if ($trt eq 'CHECKONEDOMAIN') + + # and table control fields + $c->stash(DomainList => $c->get_DomainList()); + + # Data for panel + $c->stash( + title => $title, + modul => $modul, + lets_data => \%lets_data + ); + $c->render(template => "letsencrypt"); +} ## end sub do_display +1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Localnetworks.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Localnetworks.pm index cef1763..bb74e5c 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Localnetworks.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Localnetworks.pm @@ -4,13 +4,12 @@ package SrvMngr::Controller::Localnetworks; # heading : Network # description : Local networks # navigation : 6000 500 -# +# # routes : end #---------------------------------------------------------------------- use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session subnet_mask get_reg_mask ip_number); @@ -18,246 +17,223 @@ use SrvMngr qw(theme_list init_session subnet_mask get_reg_mask ip_number); #use Data::Dumper; use esmith::util; use esmith::HostsDB; - my $network_db = esmith::NetworksDB->open() || die("Couldn't open networks db"); my $ret = "OK"; sub main { - my $c = shift; - $c->app->log->info( $c->log_req ); - + $c->app->log->info($c->log_req); my %ln_datas = (); $ln_datas{return} = ""; my $title = $c->l('ln_LOCAL NETWORKS'); my $modul = ''; - $ln_datas{trt} = 'LIST'; - my @localnetworks; - if ($network_db) { - @localnetworks = $network_db->get_all_by_prop( type => 'network' ); - } + if ($network_db) { + @localnetworks = $network_db->get_all_by_prop(type => 'network'); + } $c->stash( title => $title, modul => $modul, ln_datas => \%ln_datas, localnetworks => \@localnetworks ); - $c->render( template => 'localnetworks' ); - -} + $c->render(template => 'localnetworks'); +} ## end sub main 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 = 'DEL' if ( $rt eq 'localnetworksdel' ); - $trt = 'ADD' if ( $rt eq 'localnetworksadd' ); - $trt = 'ADD1' if ( $rt eq 'localnetworksadd1' ); - $trt = 'DEL1' if ( $rt eq 'localnetworksdel1' ); - + $c->app->log->info($c->log_req); + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); + $trt = 'DEL' if ($rt eq 'localnetworksdel'); + $trt = 'ADD' if ($rt eq 'localnetworksadd'); + $trt = 'ADD1' if ($rt eq 'localnetworksadd1'); + $trt = 'DEL1' if ($rt eq 'localnetworksdel1'); my %ln_datas = (); my $title = $c->l('ln_LOCAL NETWORKS'); my $modul = ''; - - if ( $trt eq 'ADD' ) { - #Add a network - called from the list panel - # Nothing to do here...as just need fields to input data. + if ($trt eq 'ADD') { - } + #Add a network - called from the list panel + # Nothing to do here...as just need fields to input data. + } ## end if ($trt eq 'ADD') - if ( $trt eq 'ADD1' ) { - #Add a network - called after new network details filled in - my %ret = add_network($c); - #Return to list page if success - if ((index($ret{ret},"SUCCESS") != -1)) { - $trt = "LIST"; - } else { - #Error - return to Add page - $trt = "ADD"; - } - $network_db = esmith::NetworksDB->open() || die("Failed to open Networkdb-3"); #Refresh the network DB - $c->stash(ret=>\%ret); #stash it away for the template - } + if ($trt eq 'ADD1') { - if ( $trt eq 'DEL1' ) { - #After Remove clicked on Delete network panel - my $network_db = esmith::NetworksDB->open() || die("Failed to open Networkdb-1"); + #Add a network - called after new network details filled in + my %ret = add_network($c); + + #Return to list page if success + if ((index($ret{ret}, "SUCCESS") != -1)) { + $trt = "LIST"; + } else { + + #Error - return to Add page + $trt = "ADD"; + } + $network_db = esmith::NetworksDB->open() || die("Failed to open Networkdb-3"); #Refresh the network DB + $c->stash(ret => \%ret); #stash it away for the template + } ## end if ($trt eq 'ADD1') + + if ($trt eq 'DEL1') { + + #After Remove clicked on Delete network panel + my $network_db = esmith::NetworksDB->open() || die("Failed to open Networkdb-1"); my $localnetwork = $c->param("localnetwork"); - my $delete_hosts = $c->param("deletehost")||"1"; #default to deleting them. - my $rec = $network_db->get($localnetwork)||die("Failed to find network on db:$localnetwork"); - if ( $rec and $rec->prop('type') eq 'localnetwork' ) { + my $delete_hosts = $c->param("deletehost") || "1"; #default to deleting them. + my $rec = $network_db->get($localnetwork) || die("Failed to find network on db:$localnetwork"); + + if ($rec and $rec->prop('type') eq 'localnetwork') { $ln_datas{localnetwork} = $localnetwork; } - my %ret = remove_network($localnetwork,$delete_hosts); - - $network_db = esmith::NetworksDB->open() || die("Failed to open Networkdb-2"); #Refresh the network DB + my %ret = remove_network($localnetwork, $delete_hosts); + $network_db = esmith::NetworksDB->open() || die("Failed to open Networkdb-2"); #Refresh the network DB my @localnetworks; - if ($network_db) { - @localnetworks = $network_db->get_all_by_prop( type => 'network' ); - } - # Load up ln_datas with values need by template - $ln_datas{subnet} = $rec->prop('Mask'); - $ln_datas{router} = $rec->prop('Router'); - $c->stash( ln_datas => \%ln_datas, localnetworks => \@localnetworks ,ret =>\%ret); - } - if ( $trt eq 'DEL' ) { - #Initial delete panel requiring confirmation - my $localnetwork = $c->param("localnetwork") || ''; - $c->stash(localnetwork=>$localnetwork); + if ($network_db) { + @localnetworks = $network_db->get_all_by_prop(type => 'network'); + } + + # Load up ln_datas with values need by template + $ln_datas{subnet} = $rec->prop('Mask'); + $ln_datas{router} = $rec->prop('Router'); + $c->stash(ln_datas => \%ln_datas, localnetworks => \@localnetworks, ret => \%ret); + } ## end if ($trt eq 'DEL1') + + if ($trt eq 'DEL') { + + #Initial delete panel requiring confirmation + my $localnetwork = $c->param("localnetwork") || ''; + $c->stash(localnetwork => $localnetwork); my $rec = $network_db->get($localnetwork) || die("Failed to get local network in db::$localnetwork"); my $subnet = $rec->prop('Mask'); $ln_datas{subnet} = $subnet; $ln_datas{router} = $rec->prop('Router'); - my $numhosts = hosts_on_network($localnetwork,$subnet); + my $numhosts = hosts_on_network($localnetwork, $subnet); $ln_datas{localnetwork} = $localnetwork; - $ln_datas{deletehosts} = $numhosts>0?1:0; - } + $ln_datas{deletehosts} = $numhosts > 0 ? 1 : 0; + } ## end if ($trt eq 'DEL') - if ( $trt eq 'LIST' ) { - #List all the networks + if ($trt eq 'LIST') { + + #List all the networks my @localnetworks; + if ($network_db) { - @localnetworks = $network_db->get_all_by_prop( type => 'network' ); + @localnetworks = $network_db->get_all_by_prop(type => 'network'); } - $c->stash( localnetworks => \@localnetworks ); - ## $c->redirect_to('/localnetworks'); - } - + $c->stash(localnetworks => \@localnetworks); + ## $c->redirect_to('/localnetworks'); + } ## end if ($trt eq 'LIST') $ln_datas{'trt'} = $trt; - $c->stash( title => $title, modul => $modul, ln_datas => \%ln_datas ); - $c->render( template => 'localnetworks' ); - -} + $c->stash(title => $title, modul => $modul, ln_datas => \%ln_datas); + $c->render(template => 'localnetworks'); +} ## end sub do_display sub remove_network { - my $network = shift; - my $network_db = esmith::NetworksDB->open(); - my $record = $network_db->get($network); - my $delete_hosts = shift; + my $network = shift; + my $network_db = esmith::NetworksDB->open(); + my $record = $network_db->get($network); + my $delete_hosts = shift; - if ( my $record = $network_db->get($network) ) { + if (my $record = $network_db->get($network)) { my $subnet = $record->prop('Mask'); my $router = $record->prop('Router'); - $record->set_prop( type => 'network-deleted' ); + $record->set_prop(type => 'network-deleted'); # Untaint $network before use in system() $network =~ /(.+)/; $network = $1; - if ( system( "/sbin/e-smith/signal-event", "network-delete", $network ) == 0 ) { + + if (system("/sbin/e-smith/signal-event", "network-delete", $network) == 0) { if ($delete_hosts) { - my @hosts_to_delete = hosts_on_network( $network, $subnet ); + my @hosts_to_delete = hosts_on_network($network, $subnet); + foreach my $host (@hosts_to_delete) { $host->delete; } - } + } ## end if ($delete_hosts) $record->delete; - return (ret=>'ln_SUCCESS_REMOVED_NETWORK',vars=>"$network,$subnet,$router"); - } - else { - return (ret=>"ln_ERROR_DELETING_NETWORK"); + return (ret => 'ln_SUCCESS_REMOVED_NETWORK', vars => "$network,$subnet,$router"); + } else { + return (ret => "ln_ERROR_DELETING_NETWORK"); } + } else { + return (ret => "ln_NO_SUCH_NETWORK"); } - else { - return (ret=>"ln_NO_SUCH_NETWORK"); - } -} +} ## end sub remove_network sub hosts_on_network { my $network = shift; my $netmask = shift; - die if not $network and $netmask; - - my $cidr = "$network/$netmask"; - my $hosts = esmith::HostsDB->open() || die("Couldn't open hosts db"); - my @localhosts = grep { $_->prop('HostType') eq 'Local' } $hosts->hosts; + my $cidr = "$network/$netmask"; + my $hosts = esmith::HostsDB->open() || die("Couldn't open hosts db"); + my @localhosts = grep { $_->prop('HostType') eq 'Local' } $hosts->hosts; my @hosts_on_network = (); + foreach my $host (@localhosts) { my $ip = $host->prop('InternalIP') || ""; + if ($ip) { - if ( Net::IPv4Addr::ipv4_in_network( $cidr, $ip ) ) { + if (Net::IPv4Addr::ipv4_in_network($cidr, $ip)) { push @hosts_on_network, $host; } - } - } + } ## end if ($ip) + } ## end foreach my $host (@localhosts) return @hosts_on_network if wantarray; return scalar @hosts_on_network; -} +} ## end sub hosts_on_network -sub add_network -{ +sub add_network { my ($fm) = @_; my $networkAddress = $fm->param('networkAddress'); my $networkMask = $fm->param('networkMask'); my $networkRouter = $fm->param('networkRouter'); #Validate Ips and subnet mask - my $res = ip_number($fm, $networkAddress); - return (ret=>'ln_INVALID_IP_ADDRESS', vars=>"Network Address $res") unless $res eq 'OK'; - - $res = subnet_mask( $networkMask ); - return (ret=>'ln_INVALID_SUBNET_MASK', vars=>"$networkMask" ) unless $res eq 'OK'; - + return (ret => 'ln_INVALID_IP_ADDRESS', vars => "Network Address $res") unless $res eq 'OK'; + $res = subnet_mask($networkMask); + return (ret => 'ln_INVALID_SUBNET_MASK', vars => "$networkMask") unless $res eq 'OK'; $res = ip_number($fm, $networkRouter); - return (ret=>'ln_INVALID_IP_ADDRESS' , vars=>"Routeur Address $res") unless $res eq 'OK'; + return (ret => 'ln_INVALID_IP_ADDRESS', vars => "Routeur Address $res") unless $res eq 'OK'; # we transform bit mask to regular mask - $networkMask = get_reg_mask( $networkAddress, $networkMask ); - + $networkMask = get_reg_mask($networkAddress, $networkMask); my $network_db = esmith::NetworksDB->open() - || esmith::NetworksDB->create(); - my $config_db = esmith::ConfigDB->open(); - + || esmith::NetworksDB->create(); + my $config_db = esmith::ConfigDB->open(); my $localIP = $config_db->get('LocalIP'); my $localNetmask = $config_db->get('LocalNetmask'); - - my ( $localNetwork, $localBroadcast ) = - esmith::util::computeNetworkAndBroadcast( $localIP->value(), - $localNetmask->value() ); - - my ( $routerNetwork, $routerBroadcast ) = - esmith::util::computeNetworkAndBroadcast( $networkRouter, - $localNetmask->value() ); + my ($localNetwork, $localBroadcast) + = esmith::util::computeNetworkAndBroadcast($localIP->value(), $localNetmask->value()); + my ($routerNetwork, $routerBroadcast) + = esmith::util::computeNetworkAndBroadcast($networkRouter, $localNetmask->value()); # Note to self or future developers: # the following tests should probably be validation routines # in the form itself, but it just seemed too fiddly to do that # at the moment. -- Skud 2002-04-11 # I agree --bjr 2020-04-18 - - - if ( $routerNetwork ne $localNetwork ) - { - return (ret=>'ln_NOT_ACCESSIBLE_FROM_LOCAL_NETWORK'); + if ($routerNetwork ne $localNetwork) { + return (ret => 'ln_NOT_ACCESSIBLE_FROM_LOCAL_NETWORK'); + } + my ($network, $broadcast) = esmith::util::computeNetworkAndBroadcast($networkAddress, $networkMask); + + if ($network eq $localNetwork) { + return (ret => 'ln_NETWORK_ALREADY_LOCAL'); } - my ( $network, $broadcast ) = - esmith::util::computeNetworkAndBroadcast( $networkAddress, $networkMask ); - - if ( $network eq $localNetwork ) - { - return (ret=>'ln_NETWORK_ALREADY_LOCAL'); + if ($network_db->get($network)) { + return (ret => 'ln_NETWORK_ALREADY_ADDED'); } - - if ( $network_db->get($network) ) - { - return (ret=>'ln_NETWORK_ALREADY_ADDED'); - } - $network_db->new_record( $network, - { - Mask => $networkMask, + { Mask => $networkMask, Router => $networkRouter, type => 'network', } @@ -266,26 +242,26 @@ sub add_network # Untaint $network before use in system() $network =~ /(.+)/; $network = $1; - system( "/sbin/e-smith/signal-event", "network-create", $network ) == 0 - or ( return (ret=>'ln_ERROR_CREATING_NETWORK' )); - - my ( $totalHosts, $firstAddr, $lastAddr ) = - esmith::util::computeHostRange( $network, $networkMask ); - + system("/sbin/e-smith/signal-event", "network-create", $network) == 0 + or (return (ret => 'ln_ERROR_CREATING_NETWORK')); + my ($totalHosts, $firstAddr, $lastAddr) = esmith::util::computeHostRange($network, $networkMask); my $msg; - if ( $totalHosts == 1 ) + + if ($totalHosts == 1) { + return (ret => 'ln_SUCCESS_SINGLE_ADDRESS', vars => "$network,$networkMask,$networkRouter"); + } elsif (($totalHosts == 256) + || ($totalHosts == 65536) + || ($totalHosts == 16777216)) { - return (ret=>'ln_SUCCESS_SINGLE_ADDRESS',vars=>"$network,$networkMask,$networkRouter"); - } - elsif (( $totalHosts == 256 ) - || ( $totalHosts == 65536 ) - || ( $totalHosts == 16777216 ) ) - { - return ( ret=>'ln_SUCCESS_NETWORK_RANGE',vars=>"$network,$networkMask,$networkRouter,$totalHosts,$firstAddr,$lastAddr"); - } - else - { my $simpleMask = esmith::util::computeLocalNetworkPrefix( $network, $networkMask ); - return ( ret => 'ln_SUCCESS_NONSTANDARD_RANGE', - vars=>"$network,$networkMask,$networkRouter,$totalHosts,$firstAddr,$lastAddr,$simpleMask"); - } -} + return ( + ret => 'ln_SUCCESS_NETWORK_RANGE', + vars => "$network,$networkMask,$networkRouter,$totalHosts,$firstAddr,$lastAddr" + ); + } else { + my $simpleMask = esmith::util::computeLocalNetworkPrefix($network, $networkMask); + return ( + ret => 'ln_SUCCESS_NONSTANDARD_RANGE', + vars => "$network,$networkMask,$networkRouter,$totalHosts,$firstAddr,$lastAddr,$simpleMask" + ); + } ## end else [ if ($totalHosts == 1) ] +} ## end sub add_network diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Login.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Login.pm index 1d73f07..38e5f95 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Login.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Login.pm @@ -8,266 +8,215 @@ package SrvMngr::Controller::Login; # # routes : end #---------------------------------------------------------------------- - # for information # $r->get('/login')->to('login#main')->name('login'); # $r->post('/login')->to('login#login')->name('signin'); # $r->get('/login2')->to('login#pwdrescue')->name('pwdresc'); # $r->get('/loginc')->to('login#confpwd')->name('resetpwdconf'); # for information - use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; - use esmith::AccountsDB; use SrvMngr::I18N; use SrvMngr::Model::Main; - use SrvMngr qw( theme_list init_session ); - -my $MAX_LOGIN_ATTEMPTS = 3; -my $DURATION_BLOCKED = 30 * 60; # access blocked for 30 min +my $MAX_LOGIN_ATTEMPTS = 3; +my $DURATION_BLOCKED = 30 * 60; # access blocked for 30 min my $TIMEOUT_FAILED_LOGIN = 1; -my $RESET_DURATION = 2 * 60 * 60; # 2 hours for resetting - +my $RESET_DURATION = 2 * 60 * 60; # 2 hours for resetting our $adb = esmith::AccountsDB->open() or die "Couldn't open DB Accounts\n"; - my $allowed_user_re = qr/^\w{5,10}$/; my %Login_Attempts; - sub main { - - my $c = shift; - $c->stash( trt => 'NORM' ); - $c->render('login'); - -} - + my $c = shift; + $c->stash(trt => 'NORM'); + $c->render('login'); +} ## end sub main sub login { - - my $c = shift; - - my $trt = $c->param('Trt'); + my $c = shift; + my $trt = $c->param('Trt'); # password reset request - if ( $trt eq 'RESET' ) { - my $res = $c->mail_rescue(); - if ( $res ne 'OK' ) { - $c->stash( error => $res, trt => $trt ); - return $c->render('login'); - } - $c->flash( success => $c->l('use_RESET_REGISTERED') ); - record_login_attempt($c, 'RESET'); - return $c->redirect_to( $c->home_page ); - } + if ($trt eq 'RESET') { + my $res = $c->mail_rescue(); + + if ($res ne 'OK') { + $c->stash(error => $res, trt => $trt); + return $c->render('login'); + } + $c->flash(success => $c->l('use_RESET_REGISTERED')); + record_login_attempt($c, 'RESET'); + return $c->redirect_to($c->home_page); + } ## end if ($trt eq 'RESET') # normal loggin - my $name = $c->param('Username'); - my $pass = $c->param('Password'); - my $from = $c->param('From'); + my $name = $c->param('Username'); + my $pass = $c->param('Password'); + my $from = $c->param('From'); - if ( is_denied($c) ) { - $c->stash( error => $c->l('use_TOO_MANY_LOGIN'), trt => 'NORM' ); - return $c->render('login'); - } - -# untaint - unless ( ($name =~ /^([a-z][\-\_\.a-z0-9]*)$/) && ($pass =~ /^([ -~]+)$/) ) { - record_login_attempt($c, 'FAILED'); - $c->stash( error => $c->l('use_INVALID_DATA'), trt => 'NORM' ); - return $c->render('login'); - } - - my $alias = SrvMngr::Model::Main->check_adminalias( $c ); - if ( $alias ) { - if ( $name eq $alias ) { - $name = 'admin'; - } elsif ( $name eq 'admin' ) { - record_login_attempt($c, 'FAILED'); - $c->stash( error => $c->l('use_SORRY'), trt => 'NORM' ); - return $c->render('login'); + if (is_denied($c)) { + $c->stash(error => $c->l('use_TOO_MANY_LOGIN'), trt => 'NORM'); + return $c->render('login'); } - } - if (SrvMngr::Model::Main->check_credentials($name, $pass)) { - $c->session(logged_in => 1); # set the logged_in flag - $c->session(username => $name); # keep a copy of the username -# if ( $name eq 'admin' || $adb->is_user_in_group($name, 'AdmiN') ) # for futur use - if ( $name eq 'admin' ) { - $c->session(is_admin => 1); + # untaint + unless (($name =~ /^([a-z][\-\_\.a-z0-9]*)$/) && ($pass =~ /^([ -~]+)$/)) { + record_login_attempt($c, 'FAILED'); + $c->stash(error => $c->l('use_INVALID_DATA'), trt => 'NORM'); + return $c->render('login'); + } + my $alias = SrvMngr::Model::Main->check_adminalias($c); + + if ($alias) { + if ($name eq $alias) { + $name = 'admin'; + } elsif ($name eq 'admin') { + record_login_attempt($c, 'FAILED'); + $c->stash(error => $c->l('use_SORRY'), trt => 'NORM'); + return $c->render('login'); + } + } ## end if ($alias) + + if (SrvMngr::Model::Main->check_credentials($name, $pass)) { + $c->session(logged_in => 1); # set the logged_in flag + $c->session(username => $name); # keep a copy of the username + + # if ( $name eq 'admin' || $adb->is_user_in_group($name, 'AdmiN') ) # for futur use + if ($name eq 'admin') { + $c->session(is_admin => 1); + } else { + $c->session(is_admin => 0); + } + $c->session(expiration => 600); # expire this session in 10 minutes + $c->flash(success => $c->l('use_WELCOME')); + record_login_attempt($c, 'SUCCESS'); } else { - $c->session(is_admin => 0); - } - $c->session(expiration => 600); # expire this session in 10 minutes - - $c->flash( success => $c->l('use_WELCOME') ); - record_login_attempt($c, 'SUCCESS'); - } else { - record_login_attempt($c, 'FAILED'); - sleep $TIMEOUT_FAILED_LOGIN; - - $c->stash( error => $c->l('use_SORRY'), trt => 'NORM' ); - return $c->render('login'); - } - - $from = $c->home_page if ( $from eq 'login' ); - $c->redirect_to( $from ); - -} - + record_login_attempt($c, 'FAILED'); + sleep $TIMEOUT_FAILED_LOGIN; + $c->stash(error => $c->l('use_SORRY'), trt => 'NORM'); + return $c->render('login'); + } ## end else [ if (SrvMngr::Model::Main...)] + $from = $c->home_page if ($from eq 'login'); + $c->redirect_to($from); +} ## end sub login sub pwdrescue { - - my $c = shift; - - $c->stash( trt => 'RESET' ); - - $c->render('login'); - -} - + my $c = shift; + $c->stash(trt => 'RESET'); + $c->render('login'); +} ## end sub pwdrescue sub mail_rescue { + my $c = shift; + my $name = $c->param('Username'); + my $from = $c->param('From'); + my $res; + $res .= $c->l('use_TOO_MANY_LOGIN') if (is_denied($c)); - my $c = shift; - my $name = $c->param('Username'); - my $from = $c->param('From'); - - my $res; - - $res .= $c->l('use_TOO_MANY_LOGIN') if ( is_denied($c) ); - -# untaint - if ( ! $res && $name !~ /^([a-z][\-\_\.a-z0-9]*)$/ ) { - record_login_attempt($c, 'FAILED'); - $res .= $c->l('use_ERR_NAME'); - } - - if ( ! $res && $name eq 'admin' ) { - $res .= $c->l('use_NOT_THAT_OPER'); - } - -# user exists ? - if ( ! $res ) { - my $acct = $adb->get($name); - if ( ! $acct || $acct->prop('type') ne "user" || $acct->prop('PasswordSet') ne 'yes' ) { - $res .= $c->l('use_NOT_THAT_OPER'); - } + # untaint + if (!$res && $name !~ /^([a-z][\-\_\.a-z0-9]*)$/) { + record_login_attempt($c, 'FAILED'); + $res .= $c->l('use_ERR_NAME'); } + if (!$res && $name eq 'admin') { + $res .= $c->l('use_NOT_THAT_OPER'); + } + + # user exists ? + if (!$res) { + my $acct = $adb->get($name); + + if (!$acct || $acct->prop('type') ne "user" || $acct->prop('PasswordSet') ne 'yes') { + $res .= $c->l('use_NOT_THAT_OPER'); + } + } ## end if (!$res) return $res if $res; -# send email - my $email = $name .'@'. $c->session->{DomainName}; + # send email + my $email = $name . '@' . $c->session->{DomainName}; my $until = time() + $RESET_DURATION; + $c->pwdrst->{$name} = { + email => $email, + date => $until, + confirmed => 0, + }; + my $jwt = $c->jwt->claims({ username => $name })->encode; + my $url = $c->url_for('loginc')->to_abs->query(jwt => $jwt); - $c->pwdrst->{$name} = { - email => $email, - date => $until, - confirmed => 0, - }; - my $jwt = $c->jwt->claims({username => $name})->encode; - my $url = $c->url_for('loginc')->to_abs->query(jwt => $jwt); - -# $c->email( $email, $c->l('use_CONFIRM_RESET'), $c->render_to_string(inline => $c->l('use_GO_TO_URL', $url) ) ); -# directly (without minion) - $c->send_email( $email, $c->l('use_CONFIRM_RESET'), $c->render_to_string(inline => $c->l('use_GO_TO_URL', $url) ) ); - - return 'OK'; - -} - + # $c->email( $email, $c->l('use_CONFIRM_RESET'), $c->render_to_string(inline => $c->l('use_GO_TO_URL', $url) ) ); + # directly (without minion) + $c->send_email($email, $c->l('use_CONFIRM_RESET'), $c->render_to_string(inline => $c->l('use_GO_TO_URL', $url))); + return 'OK'; +} ## end sub mail_rescue sub logout { - - my $c = shift; - $c->app->log->info($c->log_req); - - $c->session( expires => 1 ); - $c->flash( success => $c->l('use_BYE') ); - $c->flash( error => 'Byegood' ); - - $c->redirect_to( $c->home_page ); - -} - + my $c = shift; + $c->app->log->info($c->log_req); + $c->session(expires => 1); + $c->flash(success => $c->l('use_BYE')); + $c->flash(error => 'Byegood'); + $c->redirect_to($c->home_page); +} ## end sub logout sub confpwd { - - my $c = shift; - - my $jwt = $c->param('jwt'); - my $name = $c->jwt->decode($jwt)->{username}; + my $c = shift; + my $jwt = $c->param('jwt'); + my $name = $c->jwt->decode($jwt)->{username}; # request already treated or outdated - if ( $c->pwdrst->{$name}{confirmed} != 0 or $c->pwdrst->{$name}{date} < time() ) { - $c->flash( error => $c->l('use_INVALID_REQUEST')); - return $c->redirect_to( $c->home_page ); - } + if ($c->pwdrst->{$name}{confirmed} != 0 or $c->pwdrst->{$name}{date} < time()) { + $c->flash(error => $c->l('use_INVALID_REQUEST')); + return $c->redirect_to($c->home_page); + } # reset password for this account - $c->pwdrst->{$name}{confirmed} = 1; - - $c->flash( success => $c->l('use_OK_FOR_RESET') ); + $c->pwdrst->{$name}{confirmed} = 1; + $c->flash(success => $c->l('use_OK_FOR_RESET')); # call userpassword with encoded name - my $url = $c->url_for('userpasswordr')->to_abs->query(jwt => $jwt); + my $url = $c->url_for('userpasswordr')->to_abs->query(jwt => $jwt); + # warn "confpwd: " . $url . "\n"; - - return $c->redirect_to( $url ); - -} - + return $c->redirect_to($url); +} ## end sub confpwd sub record_login_attempt { + my ($c, $result) = @_; + my $user = $c->param('Username'); + my $ip_address = $c->tx->remote_address; - my ($c, $result) = @_; - - my $user = $c->param('Username'); - my $ip_address = $c->tx->remote_address; - - if ($result eq 'RESET') { - - $c->app->log->info(join "\t", "Password reset requested for : $user at ", $ip_address); - - } elsif ($result eq 'SUCCESS') { - - $c->app->log->info(join "\t", "Login succeeded: $user", $ip_address); - $Login_Attempts{$ip_address}->{tries} = 0; # reset the number of login attempts - - } else { - - $c->app->log->info(join "\t", "Login FAILED: $user", $ip_address); - $Login_Attempts{$ip_address}->{tries}++; - if ( $Login_Attempts{$ip_address}->{tries} > $MAX_LOGIN_ATTEMPTS ) { - $Login_Attempts{$ip_address}->{denied_until} = time() + $DURATION_BLOCKED; - } - } -} + if ($result eq 'RESET') { + $c->app->log->info(join "\t", "Password reset requested for : $user at ", $ip_address); + } elsif ($result eq 'SUCCESS') { + $c->app->log->info(join "\t", "Login succeeded: $user", $ip_address); + $Login_Attempts{$ip_address}->{tries} = 0; # reset the number of login attempts + } else { + $c->app->log->info(join "\t", "Login FAILED: $user", $ip_address); + $Login_Attempts{$ip_address}->{tries}++; + if ($Login_Attempts{$ip_address}->{tries} > $MAX_LOGIN_ATTEMPTS) { + $Login_Attempts{$ip_address}->{denied_until} = time() + $DURATION_BLOCKED; + } + } ## end else [ if ($result eq 'RESET')] +} ## end sub record_login_attempt sub is_denied { - my ($c) = @_; - - my $ip_address = $c->tx->remote_address; - - return unless exists $Login_Attempts{$ip_address} + my ($c) = @_; + my $ip_address = $c->tx->remote_address; + return + unless exists $Login_Attempts{$ip_address} && exists $Login_Attempts{$ip_address}->{denied_until}; + return 'Denied' + if $Login_Attempts{$ip_address}->{denied_until} > time(); - return 'Denied' - if $Login_Attempts{$ip_address}->{denied_until} > time(); - - # TIMEOUT has expired, reset attempts - delete $Login_Attempts{$ip_address}->{denied_until}; - $Login_Attempts{$ip_address}->{tries} = 0; - - return; -} - - + # TIMEOUT has expired, reset attempts + delete $Login_Attempts{$ip_address}->{denied_until}; + $Login_Attempts{$ip_address}->{tries} = 0; + return; +} ## end sub is_denied 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Logout.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Logout.pm index 64ea49a..db005f7 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Logout.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Logout.pm @@ -8,27 +8,18 @@ package SrvMngr::Controller::Logout; # # routes : end #---------------------------------------------------------------------- - use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw( theme_list init_session ); - sub logout { - - my $c = shift; - $c->app->log->info($c->log_req); - - $c->session( expires => 1 ); - $c->flash( success => 'Goodbye' ); - - $c->redirect_to( $c->home_page ); -} - - + my $c = shift; + $c->app->log->info($c->log_req); + $c->session(expires => 1); + $c->flash(success => 'Goodbye'); + $c->redirect_to($c->home_page); +} ## end sub logout 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Manual.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Manual.pm index f05cfe3..5d2195e 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Manual.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Manual.pm @@ -10,25 +10,17 @@ package SrvMngr::Controller::Manual; #---------------------------------------------------------------------- use strict; use warnings; - use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session); - sub main { my $c = shift; $c->app->log->info($c->log_req); - my $title = $c->l('manual_FORM_TITLE'); my $modul = $c->render_to_string(inline => $c->l('manual_DESCRIPTION')); - - $c->stash( title => $title, modul => $modul); - + $c->stash(title => $title, modul => $modul); $c->render(template => 'manual'); -} - - +} ## end sub main 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Modules.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Modules.pm index 4cd9c0b..d9bbc90 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Modules.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Modules.pm @@ -1,71 +1,57 @@ package SrvMngr::Controller::Modules; - use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; - # # routes : end #---------------------------------------------------------------------- use SrvMngr qw(theme_list init_session); - sub bugreport { my $c = shift; - $c->app->log->info($c->log_req); - - my $modul = $c->render_to_string( inline => "

    # my (\$lang, \$releaseVersion, + my $modul = $c->render_to_string( + inline => "

    # my (\$lang, \$releaseVersion,
    # \$c->stash\(\'lang\', \'releaseVer\' -# \'navigation\'

    "); - - $c->stash( modul => $modul ); - -}; - +# \'navigation\'

    " + ); + $c->stash(modul => $modul); +} ## end sub bugreport sub support { my $c = shift; - $c->app->log->info($c->log_req); my $modul = $c->stash('modul'); $modul .= 'Mail result is 1 + 8.'; - - $c->stash( modul => $modul, PwdSet => '0', Unsafe => '0' ); + $c->stash(modul => $modul, PwdSet => '0', Unsafe => '0'); #$c->render('modules/support'); -}; - +} ## end sub support sub modsearch { - my $c = shift; + my $c = shift; my $module = $c->param('module'); - $c->app->log->info($c->log_req); - my $redirect_url = SrvMngr->get_mod_url($module); - if($redirect_url ne "-1"){ - #$c->render(text => "mod_search: $module to $redirect_url"); + + if ($redirect_url ne "-1") { + + #$c->render(text => "mod_search: $module to $redirect_url"); return $c->redirect_to($redirect_url); + #return $c->redirect_to( url_for($redirect_url) ); - } + } ## end if ($redirect_url ne "-1") + #$c->render(text => "mod_search: $module to 'welcome'"); - return $c->redirect_to( $c->home_page ); - -}; - + return $c->redirect_to($c->home_page); +} ## end sub modsearch sub whatever { - my $c = shift; + my $c = shift; my $whatever = $c->param('whatever'); - $c->app->log->info($c->log_req . ' ' . $whatever); - $c->render(text => "whatever: /$whatever did not match.", status => 404); -}; - - +} ## end sub whatever 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Portforwarding.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Portforwarding.pm index c3254ac..603a2c5 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Portforwarding.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Portforwarding.pm @@ -10,248 +10,246 @@ package SrvMngr::Controller::Portforwarding; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session); -#use Regexp::Common qw /net/; +#use Regexp::Common qw /net/; #use Data::Dumper; use esmith::util; use esmith::HostsDB; - our $db = esmith::ConfigDB->open || die "Can't open configuration database: $!\n"; our $tcp_db = esmith::ConfigDB->open('portforward_tcp') || die "Can't open portforward_tcp database: $!\n"; our $udp_db = esmith::ConfigDB->open('portforward_udp') || die "Can't open portforward_udp database: $!\n"; - - my %ret = (); - use constant FALSE => 0; use constant TRUE => 1; sub main { - my $c = shift; - $c->app->log->info( $c->log_req ); - + $c->app->log->info($c->log_req); my %pf_datas = (); $pf_datas{return} = ""; my $title = $c->l('pf_FORM_TITLE'); my $modul = ''; - $pf_datas{trt} = 'LIST'; - my @tcpforwards = $tcp_db->get_all; my @udpforwards = $udp_db->get_all; - my $empty = 1 if not @tcpforwards and not @udpforwards; - - $c->stash( - title => $title, - modul => $modul, - pf_datas => \%pf_datas, - tcpforwards =>\@tcpforwards, - udpforwards =>\@udpforwards, - empty => $empty + my $empty = 1 if not @tcpforwards and not @udpforwards; + $c->stash( + title => $title, + modul => $modul, + pf_datas => \%pf_datas, + tcpforwards => \@tcpforwards, + udpforwards => \@udpforwards, + empty => $empty ); - $c->render( template => 'portforwarding' ); -} + $c->render(template => 'portforwarding'); +} ## end sub main 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 = 'DEL' if ( $rt eq 'portforwardingdel' ); - $trt = 'ADD' if ( $rt eq 'portforwardingadd' ); - $trt = 'ADD1' if ( $rt eq 'portforwardingadd1' ); - $trt = 'DEL1' if ( $rt eq 'portforwardingdel1' ); - + $c->app->log->info($c->log_req); + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); + $trt = 'DEL' if ($rt eq 'portforwardingdel'); + $trt = 'ADD' if ($rt eq 'portforwardingadd'); + $trt = 'ADD1' if ($rt eq 'portforwardingadd1'); + $trt = 'DEL1' if ($rt eq 'portforwardingdel1'); my %pf_datas = (); my $title = $c->l('pf_FORM_TITLE'); my $modul = ''; - - if ( $trt eq 'ADD' ) { - # Add a portforward- called from the list panel - # Nothing to do here...as just need template to display fields to input data. + if ($trt eq 'ADD') { - } + # Add a portforward- called from the list panel + # Nothing to do here...as just need template to display fields to input data. + } ## end if ($trt eq 'ADD') - if ( $trt eq 'ADD1' ) { - #Add a port forward - called after new pf details filled in - my %ret = add_portforward($c); - #Return to list page if success - if ((index($ret{ret},"SUCCESS") != -1)) { - $trt = "LIST"; - } else { - #Error - return to Add page - $trt = "ADD"; - } - $c->stash(ret=>\%ret); - } + if ($trt eq 'ADD1') { - if ( $trt eq 'DEL1' ) { - ##After Remove clicked on Delete network panel - my $sport = $c->param("sport") || ''; - my $proto = $c->param("proto") || ''; - #work out which protocol + #Add a port forward - called after new pf details filled in + my %ret = add_portforward($c); + + #Return to list page if success + if ((index($ret{ret}, "SUCCESS") != -1)) { + $trt = "LIST"; + } else { + + #Error - return to Add page + $trt = "ADD"; + } + $c->stash(ret => \%ret); + } ## end if ($trt eq 'ADD1') + + if ($trt eq 'DEL1') { + ##After Remove clicked on Delete network panel + my $sport = $c->param("sport") || ''; + my $proto = $c->param("proto") || ''; + + #work out which protocol my $fdb; + if ($proto eq 'TCP') { $fdb = $tcp_db; - } - else { + } else { $fdb = $udp_db; } - #check that the sport is in the db - my $entry = $fdb->get($sport) || die("Unable to find sport and proto $sport $proto"); + + #check that the sport is in the db + my $entry = $fdb->get($sport) || die("Unable to find sport and proto $sport $proto"); $entry->delete; - system( "/sbin/e-smith/signal-event", "portforwarding-update") == 0 - or ( die($c->l('pf_ERR_NONZERO_RETURN_EVENT'))); - $trt = "LIST"; - my %ret = (ret=>"pf_SUCCESS"); - $c->stash(ret=>\%ret); - } + system("/sbin/e-smith/signal-event", "portforwarding-update") == 0 + or (die($c->l('pf_ERR_NONZERO_RETURN_EVENT'))); + $trt = "LIST"; + my %ret = (ret => "pf_SUCCESS"); + $c->stash(ret => \%ret); + } ## end if ($trt eq 'DEL1') - if ( $trt eq 'DEL' ) { - ##Initial delete panel requiring confirmation - my $sport = $c->param("sport") || ''; - my $proto = $c->param("proto") || ''; - $c->stash(sport=>$sport); - #work out which protocol + if ($trt eq 'DEL') { + ##Initial delete panel requiring confirmation + my $sport = $c->param("sport") || ''; + my $proto = $c->param("proto") || ''; + $c->stash(sport => $sport); + + #work out which protocol my $fdb; + if ($proto eq 'TCP') { $fdb = $tcp_db; - } - else { + } else { $fdb = $udp_db; } - #pull out details and pass to template - my $entry = $fdb->get($sport) || die("Unable to find sport and proto $sport $proto"); + + #pull out details and pass to template + my $entry = $fdb->get($sport) || die("Unable to find sport and proto $sport $proto"); $pf_datas{proto} = $proto; $pf_datas{sport} = $sport; $pf_datas{dhost} = $entry->prop('DestHost'); $pf_datas{dport} = $entry->prop('DestPort') || ''; - $pf_datas{cmmnt} = $entry->prop('Comment') || ''; - $pf_datas{allow} = $entry->prop('AllowHosts') || ''; - } + $pf_datas{cmmnt} = $entry->prop('Comment') || ''; + $pf_datas{allow} = $entry->prop('AllowHosts') || ''; + } ## end if ($trt eq 'DEL') - if ( $trt eq 'LIST' ) { - #List all the port forwards - my @tcpforwards = $tcp_db->get_all; - my @udpforwards = $udp_db->get_all; - my $empty = 1 if not @tcpforwards and not @udpforwards; + if ($trt eq 'LIST') { - $c->stash( - tcpforwards =>\@tcpforwards, - udpforwards =>\@udpforwards, - empty => $empty - ); + #List all the port forwards + my @tcpforwards = $tcp_db->get_all; + my @udpforwards = $udp_db->get_all; + my $empty = 1 if not @tcpforwards and not @udpforwards; + $c->stash( + tcpforwards => \@tcpforwards, + udpforwards => \@udpforwards, + empty => $empty + ); - #my %forwards = (TCP=>@tcpforwards,UDP=>@udpforwards); - #$c->stash(portforwarding => %forwards); - } - - $pf_datas{'trt'} = $trt; - $c->stash( title => $title, modul => $modul, pf_datas => \%pf_datas ); - $c->render( template => 'portforwarding' ); -} + #my %forwards = (TCP=>@tcpforwards,UDP=>@udpforwards); + #$c->stash(portforwarding => %forwards); + } ## end if ($trt eq 'LIST') + $pf_datas{'trt'} = $trt; + $c->stash(title => $title, modul => $modul, pf_datas => \%pf_datas); + $c->render(template => 'portforwarding'); +} ## end sub do_display sub add_portforward { - my $c = shift; - my $sport = $c->param("sport") || ''; - my $proto = $c->param("proto") || ''; - #work out which protocol - my $fdb; - if ($proto eq 'TCP') { - $tcp_db = esmith::ConfigDB->open('portforward_tcp') || die "Can't open portforward_tcp database: $!\n"; - $fdb = $tcp_db; - } - else { - $udp_db = esmith::ConfigDB->open('portforward_udp') || die "Can't open portforward_udp database: $!\n"; - $fdb = $udp_db; - } - #Get the other values - my $dport = $c->param("dport"); - my $dhost = get_destination_host($c); - my $cmmnt = $c->param("cmmnt") || ""; - my $allow = $c->param("allow") || ""; - my $deny = (($c->param("allow")) ? "0.0.0.0/0" : ""); - $proto =~ s/^\s+|\s+$//g; - $sport =~ s/^\s+|\s+$//g; - $dport =~ s/^\s+|\s+$//g; - $dhost =~ s/^\s+|\s+$//g; - #Validate the values - %ret=validate_source_port($c) ; unless (index($ret{ret},"SUCCESS")!= -1) {return %ret;} - %ret=validate_allowed_hosts($c) ; if (index($ret{ret},"SUCCESS")== -1) {return %ret;} - %ret=validate_destination_port($c) ; if (index($ret{ret},"SUCCESS")== -1) {return %ret;} - %ret=validate_destination_host($c) ; if (index($ret{ret},"SUCCESS")== -1) {return %ret;} - # and then write it to the DB and tell the exec about it. - my $entry = $fdb->get($sport) || $fdb->new_record($sport, { type => 'forward' }); - $entry->set_prop('DestHost', $dhost); - $entry->set_prop('DestPort', $dport) if $dport; - $entry->set_prop('Comment', $cmmnt); - $entry->set_prop('AllowHosts', $allow); - $entry->set_prop('DenyHosts', $deny); - system( "/sbin/e-smith/signal-event", "portforwarding-update") == 0 - or ( return (ret=>'pf_ERR_NONZERO_RETURN_EVENT' )); - my %ret = (ret=>"pf_SUCCESS"); - return %ret; - -} + my $c = shift; + my $sport = $c->param("sport") || ''; + my $proto = $c->param("proto") || ''; -sub get_destination_host -{ - my $q = shift; - my $dhost = $q->param("dhost"); - my $localip = $db->get_prop('InternalInterface', 'IPAddress'); + #work out which protocol + my $fdb; + + if ($proto eq 'TCP') { + $tcp_db = esmith::ConfigDB->open('portforward_tcp') || die "Can't open portforward_tcp database: $!\n"; + $fdb = $tcp_db; + } else { + $udp_db = esmith::ConfigDB->open('portforward_udp') || die "Can't open portforward_udp database: $!\n"; + $fdb = $udp_db; + } + + #Get the other values + my $dport = $c->param("dport"); + my $dhost = get_destination_host($c); + my $cmmnt = $c->param("cmmnt") || ""; + my $allow = $c->param("allow") || ""; + my $deny = (($c->param("allow")) ? "0.0.0.0/0" : ""); + $proto =~ s/^\s+|\s+$//g; + $sport =~ s/^\s+|\s+$//g; + $dport =~ s/^\s+|\s+$//g; + $dhost =~ s/^\s+|\s+$//g; + + #Validate the values + %ret = validate_source_port($c); + unless (index($ret{ret}, "SUCCESS") != -1) { return %ret; } + %ret = validate_allowed_hosts($c); + if (index($ret{ret}, "SUCCESS") == -1) { return %ret; } + %ret = validate_destination_port($c); + if (index($ret{ret}, "SUCCESS") == -1) { return %ret; } + %ret = validate_destination_host($c); + if (index($ret{ret}, "SUCCESS") == -1) { return %ret; } + + # and then write it to the DB and tell the exec about it. + my $entry = $fdb->get($sport) || $fdb->new_record($sport, { type => 'forward' }); + $entry->set_prop('DestHost', $dhost); + $entry->set_prop('DestPort', $dport) if $dport; + $entry->set_prop('Comment', $cmmnt); + $entry->set_prop('AllowHosts', $allow); + $entry->set_prop('DenyHosts', $deny); + system("/sbin/e-smith/signal-event", "portforwarding-update") == 0 + or (return (ret => 'pf_ERR_NONZERO_RETURN_EVENT')); + my %ret = (ret => "pf_SUCCESS"); + return %ret; +} ## end sub add_portforward + +sub get_destination_host { + my $q = shift; + my $dhost = $q->param("dhost"); + my $localip = $db->get_prop('InternalInterface', 'IPAddress'); my $external_ip = $db->get_prop('ExternalInterface', 'IPAddress') || $localip; - if ($dhost =~ /^(127.0.0.1|$localip|$external_ip)$/i) - { + if ($dhost =~ /^(127.0.0.1|$localip|$external_ip)$/i) { + # localhost token gets expanded at runtime to current external IP $dhost = 'localhost'; - } + } ## end if ($dhost =~ /^(127.0.0.1|$localip|$external_ip)$/i) return $dhost; -} +} ## end sub get_destination_host sub validate_source_port { - my $q = shift; + my $q = shift; my $sport = $q->param('sport'); $sport =~ s/^\s+|\s+$//g; + # If this is a port range, split it up and validate it individually. my @ports = (); - if ($sport =~ /-/) - { + + if ($sport =~ /-/) { @ports = split /-/, $sport; - if (@ports > 2) - { + + if (@ports > 2) { + #$self->debug_msg("found more than 2 ports: @ports"); - return (ret=>'pf_ERR_BADPORT'); - } - } - else - { + return (ret => 'pf_ERR_BADPORT'); + } ## end if (@ports > 2) + } else { push @ports, $sport; } + #$self->debug_msg("the ports array is: @ports"); - foreach my $port (@ports) - { + foreach my $port (@ports) { + #$self->debug_msg("looping on port $port"); - if (! isValidPort($port)) - { + if (!isValidPort($port)) { + #$self->debug_msg("returning: " . $self->localise('ERR_BADPORT')); - return (ret=>'pf_ERR_BADPORT'); + return (ret => 'pf_ERR_BADPORT'); } - } - # Now, lets screen any duplicates. + } ## end foreach my $port (@ports) + + # Now, lets screen any duplicates. my $protocol = $q->param('protocol'); my @forwards = (); @@ -261,152 +259,135 @@ sub validate_source_port { } elsif ($protocol eq 'UDP') { @forwards = map { $_->key } $udp_db->get_all; } - foreach my $psport (@forwards) - { - if (detect_collision($sport, $psport)) - { - return (ret=>'pf_ERR_PORT_COLLISION'); - } - } - return (ret=>"pf_SUCCESS"); -} -sub detect_collision -{ + foreach my $psport (@forwards) { + if (detect_collision($sport, $psport)) { + return (ret => 'pf_ERR_PORT_COLLISION'); + } + } ## end foreach my $psport (@forwards) + return (ret => "pf_SUCCESS"); +} ## end sub validate_source_port + +sub detect_collision { my $port_a = shift; my $port_b = shift; - + # If they're both single ports, see if they're the same. - if (($port_a !~ /-/) && ($port_b !~ /-/)) - { + if (($port_a !~ /-/) && ($port_b !~ /-/)) { return $port_a eq $port_b; } + # If port_a is not a range but port_b is, is a in b? - elsif ($port_a !~ /-/) - { + elsif ($port_a !~ /-/) { my ($b1, $b2) = split /-/, $port_b; return (($port_a >= $b1) && ($port_a <= $b2)); - } - elsif ($port_b !~ /-/) - { + } elsif ($port_b !~ /-/) { my ($a1, $a2) = split /-/, $port_a; return (($port_b >= $a1) && ($port_b <= $a2)); - } - else - { + } else { + # They're both ranges. Do they overlap? my ($a1, $a2) = split /-/, $port_a; my ($b1, $b2) = split /-/, $port_b; + # They can overlap in two ways. Either a1 is in b, or b1 is in a. - if (($a1 >= $b1) && ($a1 <= $b2)) - { + if (($a1 >= $b1) && ($a1 <= $b2)) { return TRUE; - } - elsif (($b1 >= $a1) && ($b1 <= $a2)) - { + } elsif (($b1 >= $a1) && ($b1 <= $a2)) { return TRUE; } return FALSE; - } -} - + } ## end else [ if (($port_a !~ /-/) &&...)] +} ## end sub detect_collision sub validate_destination_port { - my $c = shift; + my $c = shift; my $dport = $c->param('dport'); $dport =~ s/^\s+|\s+$//g; - # If the dport is empty, that's ok. - return (ret=>'pf_SUCCESS') if not $dport; + + # If the dport is empty, that's ok. + return (ret => 'pf_SUCCESS') if not $dport; # If this is a port range, split it up and validate it individually. my @ports = (); - if ($dport =~ /-/) - { + + if ($dport =~ /-/) { @ports = split /-/, $dport; - if (@ports > 2) - { + + if (@ports > 2) { + #$self->debug_msg("found more than 2 ports: @ports"); - return (ret=>'pf_ERR_BADPORT'); - } - } - else - { + return (ret => 'pf_ERR_BADPORT'); + } ## end if (@ports > 2) + } else { push @ports, $dport; } + #$self->debug_msg("the ports array is: @ports"); + foreach my $port (@ports) { - foreach my $port (@ports) - { #$self->debug_msg("looping on port $port"); - if (! isValidPort($port)) - { - #$self->debug_msg("returning: " . $self->localise('ERR_BADPORT')); - return (ret=>'pf_ERR_BADPORT'); - } - } - return (ret=>'pf_SUCCESS'); -} + if (!isValidPort($port)) { + #$self->debug_msg("returning: " . $self->localise('ERR_BADPORT')); + return (ret => 'pf_ERR_BADPORT'); + } + } ## end foreach my $port (@ports) + return (ret => 'pf_SUCCESS'); +} ## end sub validate_destination_port sub isValidPort() { my $port = shift; - return FALSE unless defined $port; - if (($port =~ /^\d+$/) && - ($port > 0) && - ($port < 65536)) + if ( ($port =~ /^\d+$/) + && ($port > 0) + && ($port < 65536)) { return TRUE; - } - else { + } else { return FALSE; } -} +} ## end sub isValidPort sub validate_destination_host { - my $c = shift; + my $c = shift; my $dhost = $c->param('dhost'); $dhost =~ s/^\s+|\s+$//g; - my $localip = $db->get_prop('InternalInterface', 'IPAddress'); my $external_ip = $db->get_prop('ExternalInterface', 'IPAddress') || $localip; - if ($dhost =~ /^(localhost|127.0.0.1|$localip|$external_ip)$/i) - { - # localhost token gets expanded at runtime to current external IP - $c->param(-name=>'dhost', -value=>'localhost'); - return (ret=>'pf_SUCCESS'); - } + if ($dhost =~ /^(localhost|127.0.0.1|$localip|$external_ip)$/i) { + # localhost token gets expanded at runtime to current external IP + $c->param(-name => 'dhost', -value => 'localhost'); + return (ret => 'pf_SUCCESS'); + } ## end if ($dhost =~ /^(localhost|127.0.0.1|$localip|$external_ip)$/i) my $systemmode = $db->get_value('SystemMode'); if ($systemmode eq 'serveronly') { - return (ret=>'pf_IN_SERVERONLY'); + return (ret => 'pf_IN_SERVERONLY'); } if (isValidIP($dhost)) { - return (ret=>'pf_SUCCESS'); + return (ret => 'pf_SUCCESS'); + } else { + return (ret => 'pf_ERR_BADIP'); } - else { - return (ret=>'pf_ERR_BADIP'); - } -} +} ## end sub validate_destination_host sub validate_allowed_hosts { - my $c = shift; + my $c = shift; my $ahost = $c->param('allow'); $ahost =~ s/^\s+|\s+$//g; - - my %valid_ahost_list = (ret=>"pf_SUCCESS"); + my %valid_ahost_list = (ret => "pf_SUCCESS"); foreach (split(/[\s,]+/, $ahost)) { my $valid_ipnet = 0; $valid_ipnet = 1 if ($_ =~ m/^\d+\.\d+\.\d+\.\d+$/); $valid_ipnet = 1 if ($_ =~ m/^\d+\.\d+\.\d+\.\d+\/\d+$/); - %valid_ahost_list = (ret=>"pf_ERR_BADAHOST") if ($valid_ipnet != 1); - } - + %valid_ahost_list = (ret => "pf_ERR_BADAHOST") if ($valid_ipnet != 1); + } ## end foreach (split(/[\s,]+/, $ahost...)) return %valid_ahost_list; -} +} ## end sub validate_allowed_hosts 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Printers.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Printers.pm index b8b70f7..e98e1cc 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Printers.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Printers.pm @@ -11,236 +11,198 @@ package SrvMngr::Controller::Printers; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw(theme_list init_session); - use esmith::FormMagick::Panel::printers; - our $adb = esmith::AccountsDB->open || die "Couldn't open accounts db"; sub main { - my $c = shift; $c->app->log->info($c->log_req); - my %prt_datas = (); - my $title = $c->l('prt_FORM_TITLE'); - + my $title = $c->l('prt_FORM_TITLE'); $prt_datas{'trt'} = 'LIST'; - my @printerDrivers; - if ($adb) - { + + if ($adb) { @printerDrivers = $adb->printers(); } - - $c->stash( title => $title, prt_datas => \%prt_datas, printerDrivers => \@printerDrivers ); + $c->stash(title => $title, prt_datas => \%prt_datas, printerDrivers => \@printerDrivers); $c->render(template => 'printers'); - -}; - +} ## end sub main sub do_display { - - my $c = shift; - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LIST'); + my $c = shift; + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); my $printer = $c->param('printer') || ''; #$trt = 'DEL' if ( $printer ); #$trt = 'ADD' if ( $rt eq 'printeradd' ); - my %prt_datas = (); - my $title = $c->l('prt_FORM_TITLE'); - + my $title = $c->l('prt_FORM_TITLE'); $prt_datas{'trt'} = $trt; - if ( $trt eq 'ADD' ) { + if ($trt eq 'ADD') { - # nothing + # nothing + } + if ($trt eq 'DEL') { + my $rec = $adb->get($printer); + + if ($rec and $rec->prop('type') eq 'printer') { + $prt_datas{printer} = $printer; + $prt_datas{description} = $rec->prop('Description') || ''; } + } ## end if ($trt eq 'DEL') - if ( $trt eq 'DEL' ) { - - my $rec = $adb->get($printer); - if ($rec and $rec->prop('type') eq 'printer') { - $prt_datas{printer} = $printer; - $prt_datas{description} = $rec->prop('Description') || ''; - } + if ($trt eq 'LIST') { + my @printerDrivers; + if ($adb) { + @printerDrivers = $adb->printers(); } - - if ( $trt eq 'LIST' ) { - my @printerDrivers; - if ($adb) - { - @printerDrivers = $adb->printers(); - } - $c->stash( printerDrivers => \@printerDrivers ); - - } - - $c->stash( title => $title, prt_datas => \%prt_datas ); - $c->render( template => 'printers' ); - -}; - + $c->stash(printerDrivers => \@printerDrivers); + } ## end if ($trt eq 'LIST') + $c->stash(title => $title, prt_datas => \%prt_datas); + $c->render(template => 'printers'); +} ## end sub do_display sub do_update { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LIST'); - + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); my %prt_datas = (); - my $title = $c->l('prt_FORM_TITLE'); + my $title = $c->l('prt_FORM_TITLE'); $prt_datas{'trt'} = $trt; - my ($res, $result) = ''; - if ( $trt eq 'ADD' ) { - - my $name = ($c->param('Name') || ''); + if ($trt eq 'ADD') { + my $name = ($c->param('Name') || ''); my $description = ($c->param('Description') || ''); - my $location = ($c->param('Location') || ''); + my $location = ($c->param('Location') || ''); - # controls - $res = $c->validate_printer( $name, $description, $location ); - $result .= $res unless $res eq 'OK'; + # controls + $res = $c->validate_printer($name, $description, $location); + $result .= $res unless $res eq 'OK'; - if ( $location eq 'remote' and ! $result) { - $prt_datas{'trt'} = 'NET'; - $prt_datas{'name'} = $name; - $prt_datas{'description'} = $description; - $prt_datas{'location'} = $location; - $c->stash( title => $title, prt_datas => \%prt_datas ); - return $c->render( template => 'printers' ); - } - - $res = ''; - if ( ! $result ) { - $res = $c->new_printer( $name, $description, $location ); - #$remoteName, $address ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('prt_CREATED_SUCCESSFULLY') . ' ' . $name; - } - } - } + if ($location eq 'remote' and !$result) { + $prt_datas{'trt'} = 'NET'; + $prt_datas{'name'} = $name; + $prt_datas{'description'} = $description; + $prt_datas{'location'} = $location; + $c->stash(title => $title, prt_datas => \%prt_datas); + return $c->render(template => 'printers'); + } ## end if ($location eq 'remote'...) + $res = ''; - if ( $trt eq 'NET' ) { + if (!$result) { + $res = $c->new_printer($name, $description, $location); - my $name = ($c->param('Name') || ''); + #$remoteName, $address ); + $result .= $res unless $res eq 'OK'; + + if (!$result) { + $result = $c->l('prt_CREATED_SUCCESSFULLY') . ' ' . $name; + } + } ## end if (!$result) + } ## end if ($trt eq 'ADD') + + if ($trt eq 'NET') { + my $name = ($c->param('Name') || ''); my $description = ($c->param('Description') || ''); - my $location = ($c->param('Location') || ''); - my $remoteName = ($c->param ('RemoteName') || ''); - my $address = ($c->param ('Address') || ''); + my $location = ($c->param('Location') || ''); + my $remoteName = ($c->param('RemoteName') || ''); + my $address = ($c->param('Address') || ''); + $prt_datas{'name'} = $name; + $prt_datas{'description'} = $description; + $prt_datas{'location'} = $location; - $prt_datas{'name'} = $name; - $prt_datas{'description'} = $description; - $prt_datas{'location'} = $location; + # controls + $res = $c->validate_network($location, $remoteName, $address); + $result .= $res unless $res eq 'OK'; + $res = ''; - # controls - $res = $c->validate_network( $location, $remoteName, $address); - $result .= $res unless $res eq 'OK'; + if (!$result) { + $res = $c->new_printer($name, $description, $location, $remoteName, $address); + $result .= $res unless $res eq 'OK'; - $res = ''; - if ( ! $result ) { - $res = $c->new_printer( $name, $description, $location, $remoteName, $address ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('prt_CREATED_SUCCESSFULLY') . ' ' . $name; - } - } - } + if (!$result) { + $result = $c->l('prt_CREATED_SUCCESSFULLY') . ' ' . $name; + } + } ## end if (!$result) + } ## end if ($trt eq 'NET') - if ( $trt eq 'DEL' ) { - - my $printer = ($c->param ('printer') || ''); + if ($trt eq 'DEL') { + my $printer = ($c->param('printer') || ''); - if ($printer =~ /^([a-z][a-z0-9]*)$/) { - $printer = $1; - } else { - $result .= $c->l('prt_ERR_INTERNAL_FAILURE') . ':' . $printer; - } + if ($printer =~ /^([a-z][a-z0-9]*)$/) { + $printer = $1; + } else { + $result .= $c->l('prt_ERR_INTERNAL_FAILURE') . ':' . $printer; + } + my $rec = $adb->get($printer); + $result .= $c->l('prt_ERR_INTERNAL_FAILURE') . ':' . $printer unless ($rec); + $res = ''; - my $rec = $adb->get($printer); - $result .= $c->l('prt_ERR_INTERNAL_FAILURE') . ':' . $printer unless ($rec); + if (!$result) { + $res = $c->del_printer($printer); + $result .= $res unless $res eq 'OK'; - $res = ''; - if ( ! $result ) { - $res = $c->del_printer( $printer ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('prt_DELETED_SUCCESSFULLY') . ' ' . $printer; - } - } - } + if (!$result) { + $result = $c->l('prt_DELETED_SUCCESSFULLY') . ' ' . $printer; + } + } ## end if (!$result) + } ## end if ($trt eq 'DEL') # common parts - if ($res ne 'OK') { - $c->stash( error => $result ); - $c->stash( title => $title, prt_datas => \%prt_datas ); - return $c->render('printers'); + $c->stash(error => $result); + $c->stash(title => $title, prt_datas => \%prt_datas); + return $c->render('printers'); } - my $message = "'Printers' updates ($trt) DONE"; $c->app->log->info($message); - $c->flash( success => $result ); + $c->flash(success => $result); + #$c->flash( error => 'No changes applied !!' ); # for testing purpose - $c->redirect_to('/printers'); - -}; - +} ## end sub do_update sub del_printer { - - my ( $c, $printer ) = @_; + my ($c, $printer) = @_; # Update the db account (1) my $rec = $adb->get($printer); - $rec->set_prop('type', 'printer-deleted'); - system ("/sbin/e-smith/signal-event printer-delete $printer") == 0 - or return $c->error('ERR_DELETING'); - + system("/sbin/e-smith/signal-event printer-delete $printer") == 0 + or return $c->error('ERR_DELETING'); $rec->delete(); - return 'OK'; - -} - +} ## end sub del_printer sub validate_printer { - - my ($c, $name, $description, $location, $remoteName, $address ) = @_; + my ($c, $name, $description, $location, $remoteName, $address) = @_; #------------------------------------------------------------ # Validate parameters and untaint them #------------------------------------------------------------ - - if ($name =~ /^([a-z][a-z0-9]*)$/) { + if ($name =~ /^([a-z][a-z0-9]*)$/) { $name = $1; - } else { + } else { return $c->l('prt_ERR_UNEXPECTED_NAME') . ': ' . $name; } if ($description =~ /^([\'\w\s]+)$/) { - $description = $1; + $description = $1; } else { return $c->l('prt_ERR_UNEXPECTED_DESC') . ': ' . $description; } - if ($location =~ /^(lp[0-9]+|remote|usb\/lp[0-9]+)$/){ + if ($location =~ /^(lp[0-9]+|remote|usb\/lp[0-9]+)$/) { $location = $1; } else { $location = "lp0"; @@ -249,26 +211,22 @@ sub validate_printer { #------------------------------------------------------------ # Looks good. Find out if this printer has been taken #------------------------------------------------------------ - my $rec = $adb->get($name); my $type; + if ($rec and ($type = $rec->prop('type'))) { return $c->l('prt_ERR_EXISTS') . ' : ' . $name; } - return 'OK'; -} - +} ## end sub validate_printer sub validate_network { - - my ($c, $location, $remoteName, $address ) = @_; + my ($c, $location, $remoteName, $address) = @_; if ($location eq 'remote') { + my $msg = hostname_or_ip2($c, $address); + return $msg unless $msg eq 'OK'; - my $msg = hostname_or_ip2 ( $c, $address ); - return $msg unless $msg eq 'OK'; - if ($address =~ /^([a-zA-Z0-9\.\-]+)$/) { $address = $1; } else { @@ -280,82 +238,63 @@ sub validate_network { } else { return $c->l('prt_ERR_INVALID_REMOTE_NAME') . ' : ' . $remoteName; } - } - + } ## end if ($location eq 'remote') return 'OK'; -} - +} ## end sub validate_network sub new_printer { - - my ($c, $name, $description, $location, $remoteName, $address ) = @_; + my ($c, $name, $description, $location, $remoteName, $address) = @_; #------------------------------------------------------------ - # Printer name is available! Update printers database and + # Printer name is available! Update printers database and # signal the create-printer event. #------------------------------------------------------------ - my $result = ''; - - my $rec = $adb->new_record($name, - {type=>'printer', - Description => $description, - Address => $address, - RemoteName => $remoteName, - Location => $location}); - - system ("/sbin/e-smith/signal-event printer-create $name") == 0 - or return $c->error('ERR_CREATING'); - - return 'OK', -} - + my $rec = $adb->new_record( + $name, + { type => 'printer', + Description => $description, + Address => $address, + RemoteName => $remoteName, + Location => $location + } + ); + system("/sbin/e-smith/signal-event printer-create $name") == 0 + or return $c->error('ERR_CREATING'); + return 'OK',; +} ## end sub new_printer sub hostname_or_ip2 { - my ($fm, $data) = @_; + if ($data =~ /^[\d\.]+$/) { - if (ip_number2($fm, $data) eq "OK") - { + if (ip_number2($fm, $data) eq "OK") { return "OK"; - } - else - { + } else { return $fm->l('prt_MUST_BE_VALID_HOSTNAME_OR_IP'); } - } - elsif ($data =~ /^([a-zA-Z0-9\.\-]+)$/ ) - { + } elsif ($data =~ /^([a-zA-Z0-9\.\-]+)$/) { return "OK"; - } - else - { + } else { return $fm->l('prt_MUST_BE_VALID_HOSTNAME_OR_IP'); } -} - +} ## end sub hostname_or_ip2 sub ip_number2 { + # from CGI::FormMagick::Validator::ip_number($fm, $data) - my ($fm, $data) = @_; - return undef unless defined $data; - return 'FM_IP_NUMBER1' unless $data =~ /^[\d.]+$/; - my @octets = split /\./, $data; my $dots = ($data =~ tr/.//); - return 'FM_IP_NUMBER2' unless (scalar @octets == 4 and $dots == 3); foreach my $octet (@octets) { - return $fm->l("FM_IP_NUMBER3", {octet => $octet}) if $octet > 255; + return $fm->l("FM_IP_NUMBER3", { octet => $octet }) if $octet > 255; } - return 'OK'; -} - +} ## end sub ip_number2 =head2 publicAccess_list @@ -365,15 +304,14 @@ access drop down list. =cut sub printerLocation_list { - my $c = shift; - return [[ $c->l('prt_LOCAL_PRINTER_0') => 'lp0'], - [ $c->l('prt_LOCAL_PRINTER_1') => 'lp1'], - [ $c->l('prt_LOCAL_PRINTER_2') => 'lp2'], - [ $c->l('prt_NET_PRINTER') => 'remote' ], - [ $c->l('prt_FIRST_USB_PRINTER') => 'usb/lp0'], - [ $c->l('prt_SECOND_USB_PRINTER') => 'usb/lp1']]; -} - - + return [ + [ $c->l('prt_LOCAL_PRINTER_0') => 'lp0' ], + [ $c->l('prt_LOCAL_PRINTER_1') => 'lp1' ], + [ $c->l('prt_LOCAL_PRINTER_2') => 'lp2' ], + [ $c->l('prt_NET_PRINTER') => 'remote' ], + [ $c->l('prt_FIRST_USB_PRINTER') => 'usb/lp0' ], + [ $c->l('prt_SECOND_USB_PRINTER') => 'usb/lp1' ] + ]; +} ## end sub printerLocation_list 1 diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Proxy.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Proxy.pm index b15e0e1..21fd76c 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Proxy.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Proxy.pm @@ -11,65 +11,50 @@ package SrvMngr::Controller::Proxy; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw(theme_list init_session); - our $db = esmith::ConfigDB->open || die "Couldn't open config db"; sub main { my $c = shift; $c->app->log->info($c->log_req); - my %prx_datas = (); - my $title = $c->l('prx_TITLE'); - my $modul = $c->render_to_string(inline => $c->l('prx_FIRST_PAGE_DESCRIPTION')); - - $prx_datas{'http_proxy_status'} = ($db->get_prop('squid','status')) || 'disabled'; + my $title = $c->l('prx_TITLE'); + my $modul = $c->render_to_string(inline => $c->l('prx_FIRST_PAGE_DESCRIPTION')); + $prx_datas{'http_proxy_status'} = ($db->get_prop('squid', 'status')) || 'disabled'; #if (system('/bin/rpm -q e-smith-email > /dev/null') == 0) #{ - $prx_datas{'smtp_proxy_status'} = $db->get_prop('qpsmtpd','Proxy') || undef; + $prx_datas{'smtp_proxy_status'} = $db->get_prop('qpsmtpd', 'Proxy') || undef; + #} #(system('/bin/rpm -q e-smith-email > /dev/null') == 0) ? - - $c->stash( title => $title, modul => $modul, prx_datas => \%prx_datas ); + $c->stash(title => $title, modul => $modul, prx_datas => \%prx_datas); $c->render(template => 'proxy'); -}; - +} ## end sub main sub do_update { my $c = shift; $c->app->log->info($c->log_req); - my $http_proxy_status = $c->param('http_proxy_status') || 'disabled'; my $smtp_proxy_status = $c->param('smtp_proxy_status') || ''; - - my $result = ""; - + my $result = ""; my $squid = $db->get('squid') or $result = $c->l('prx_ERR_NO_SQUID_REC'); + # smtpd is allowed to not exist, as the relevant packages may not be # installed. my $smtpd = $db->get('qpsmtpd') || undef; - $squid->set_prop('status', $http_proxy_status); $smtpd->set_prop('Proxy', $smtp_proxy_status) if $smtpd; - # # Update the system # system("/sbin/e-smith/signal-event proxy-update") == 0 or $result = $c->l('prx_ERR_PROXY_UPDATE_FAILED'); - my $title = $c->l('prx_TITLE'); - - if ( $result eq '' ) { $result = $c->l('prx_SUCCESS'); } - - $c->stash( title => $title, modul => $result ); + if ($result eq '') { $result = $c->l('prx_SUCCESS'); } + $c->stash(title => $title, modul => $result); $c->render(template => 'module'); -}; - - -1; \ No newline at end of file +} ## end sub do_update +1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Pseudonyms.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Pseudonyms.pm index a41ada0..0abf80a 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Pseudonyms.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Pseudonyms.pm @@ -11,288 +11,252 @@ package SrvMngr::Controller::Pseudonyms; 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::FormMagick::Panel::pseudonyms; use esmith::AccountsDB; + #use URI::Escape; - - -our $cdb = esmith::ConfigDB->open || die "Couldn't open configuration db"; +our $cdb = esmith::ConfigDB->open || die "Couldn't open configuration db"; our $adb = esmith::AccountsDB->open || die "Couldn't open accounts db"; sub main { - my $c = shift; $c->app->log->info($c->log_req); - my %pse_datas = (); - my $title = $c->l('pse_FORM_TITLE'); - my $notif = ''; - + my $title = $c->l('pse_FORM_TITLE'); + my $notif = ''; $pse_datas{trt} = 'LST'; - my @pseudonyms; - if ($adb) - { + + if ($adb) { @pseudonyms = $adb->pseudonyms(); } - - $c->stash( title => $title, notif => $notif, pse_datas => \%pse_datas, pseudonyms => \@pseudonyms ); + $c->stash(title => $title, notif => $notif, pse_datas => \%pse_datas, pseudonyms => \@pseudonyms); $c->render(template => 'pseudonyms'); - -}; - +} ## end sub main sub do_display { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LST'); + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LST'); my $pseudonym = $c->param('pseudonym') || ''; - - my $title = $c->l('pse_FORM_TITLE'); + my $title = $c->l('pse_FORM_TITLE'); my %pse_datas = (); $pse_datas{'trt'} = $trt; - if ( $trt eq 'ADD' ) { - #nothing - } + if ($trt eq 'ADD') { - if ( $trt eq 'UPD' ) { - - my $rec = $adb->get($pseudonym); - if ($rec and $rec->prop('type') eq 'pseudonym') { + #nothing + } - $pse_datas{pseudonym} = $pseudonym; - $pse_datas{account} = $rec->prop('Account') || ''; - $pse_datas{internal} = is_pseudonym_internal($pseudonym); - } - } + if ($trt eq 'UPD') { + my $rec = $adb->get($pseudonym); - if ( $trt eq 'DEL' ) { + if ($rec and $rec->prop('type') eq 'pseudonym') { + $pse_datas{pseudonym} = $pseudonym; + $pse_datas{account} = $rec->prop('Account') || ''; + $pse_datas{internal} = is_pseudonym_internal($pseudonym); + } ## end if ($rec and $rec->prop...) + } ## end if ($trt eq 'UPD') - my $rec = $adb->get($pseudonym); - if ($rec and $rec->prop('type') eq 'pseudonym') { + if ($trt eq 'DEL') { + my $rec = $adb->get($pseudonym); - $pse_datas{pseudonym} = $pseudonym; - $pse_datas{account} = $rec->prop('Account') || ''; - $pse_datas{internal} = is_pseudonym_internal($pseudonym); + if ($rec and $rec->prop('type') eq 'pseudonym') { + $pse_datas{pseudonym} = $pseudonym; + $pse_datas{account} = $rec->prop('Account') || ''; + $pse_datas{internal} = is_pseudonym_internal($pseudonym); + } ## end if ($rec and $rec->prop...) + } ## end if ($trt eq 'DEL') - } + if ($trt eq 'LST') { + my @pseudonyms; + + if ($adb) { + @pseudonyms = $adb->pseudonyms(); } - - if ( $trt eq 'LST' ) { - my @pseudonyms; - if ($adb) { - @pseudonyms = $adb->pseudonyms(); - } - $c->stash( pseudonyms => \@pseudonyms ); - - } - - $c->stash( title => $title, pse_datas => \%pse_datas ); - $c->render( template => 'pseudonyms' ); - -}; - + $c->stash(pseudonyms => \@pseudonyms); + } ## end if ($trt eq 'LST') + $c->stash(title => $title, pse_datas => \%pse_datas); + $c->render(template => 'pseudonyms'); +} ## end sub do_display sub do_update { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LST'); - - my $title = $c->l('pse_FORM_TITLE'); + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LST'); + my $title = $c->l('pse_FORM_TITLE'); my %pse_datas = (); $pse_datas{'trt'} = $trt; - my ($res, $result) = ''; #my $pseudonym = uri_unescape($c->param('Pseudonym')); my $pseudonym = $c->param('Pseudonym'); $pse_datas{'pseudonym'} = $pseudonym; - if ( $trt eq 'ADD' ) { - + if ($trt eq 'ADD') { my $account = $c->param('Account'); - # controls - $res = $c->validate_new_pseudonym_name( $pseudonym, $account ); - $result .= $res unless $res eq 'OK'; + # controls + $res = $c->validate_new_pseudonym_name($pseudonym, $account); + $result .= $res unless $res eq 'OK'; - #$result .= ' blocked'; - - $res = ''; - if ( ! $result ) { - $adb->new_record( $pseudonym, { type => 'pseudonym', - Account => $account} ) - or $result .= "Error occurred while creating pseudonym in database."; - # Untaint $pseudonym before use in system() - ($pseudonym) = ($pseudonym =~ /(.+)/); - system( "/sbin/e-smith/signal-event", "pseudonym-create", "$pseudonym",) - == 0 or $result .= 'pse_CREATE_ERROR.'; - } - if ( ! $result ) { - $res = 'OK'; - $result = $c->l('pse_CREATE_SUCCEEDED') . ' ' . $pseudonym; - } - } + #$result .= ' blocked'; + $res = ''; - if ( $trt eq 'UPD' ) { + if (!$result) { + $adb->new_record( + $pseudonym, + { type => 'pseudonym', + Account => $account + } + ) or $result .= "Error occurred while creating pseudonym in database."; - my $account = $c->param('Account'); - my $internal = $c->param ('Internal') || 'NO'; - my $removable = $adb->get($pseudonym)->prop('Removable') || 'yes'; + # Untaint $pseudonym before use in system() + ($pseudonym) = ($pseudonym =~ /(.+)/); + system("/sbin/e-smith/signal-event", "pseudonym-create", "$pseudonym",) == 0 + or $result .= 'pse_CREATE_ERROR.'; + } ## end if (!$result) - my %props = ('Account' => $account); + if (!$result) { + $res = 'OK'; + $result = $c->l('pse_CREATE_SUCCEEDED') . ' ' . $pseudonym; + } + } ## end if ($trt eq 'ADD') - if ($removable eq 'yes') { - if ($internal eq "YES") { $props{'Visible'} = 'internal'; } - else { $adb->get($pseudonym)->delete_prop('Visible'); } - } + if ($trt eq 'UPD') { + my $account = $c->param('Account'); + my $internal = $c->param('Internal') || 'NO'; + my $removable = $adb->get($pseudonym)->prop('Removable') || 'yes'; + my %props = ('Account' => $account); - # controls - #$res = ''; - #$res = validate_description( $c, $account ); - #$result .= $res unless $res eq 'OK'; + if ($removable eq 'yes') { + if ($internal eq "YES") { $props{'Visible'} = 'internal'; } + else { $adb->get($pseudonym)->delete_prop('Visible'); } + } - #$result .= 'blocked'; + # controls + #$res = ''; + #$res = validate_description( $c, $account ); + #$result .= $res unless $res eq 'OK'; + #$result .= 'blocked'; + $res = ''; - $res = ''; - if ( ! $result ) { - $adb->get($pseudonym)->merge_props(%props) - or $result .= "Error occurred while modifying pseudonym in database."; - # Untaint $pseudonym before use in system() - ($pseudonym) = ($pseudonym =~ /(.+)/); - system( "/sbin/e-smith/signal-event", "pseudonym-modify", "$pseudonym",) - == 0 or $result .= "Error occurred while modifying pseudonym."; - } - if ( ! $result ) { - $res = 'OK'; - $result = $c->l('pse_MODIFY_SUCCEEDED') . ' ' . $pseudonym; - } - } + if (!$result) { + $adb->get($pseudonym)->merge_props(%props) + or $result .= "Error occurred while modifying pseudonym in database."; - if ( $trt eq 'DEL' ) { + # Untaint $pseudonym before use in system() + ($pseudonym) = ($pseudonym =~ /(.+)/); + system("/sbin/e-smith/signal-event", "pseudonym-modify", "$pseudonym",) == 0 + or $result .= "Error occurred while modifying pseudonym."; + } ## end if (!$result) - # controls - $res = ''; - $res = validate_is_pseudonym($c, $pseudonym); - $result .= $res unless $res eq 'OK'; - - #$result .= 'blocked'; - - $res = ''; - if ( ! $result ) { - $res = $c->delete_pseudonym( $pseudonym ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $res = 'OK'; - $result = $c->l('pse_REMOVE_SUCCEEDED') . ' ' . $pseudonym; - } - } - } + if (!$result) { + $res = 'OK'; + $result = $c->l('pse_MODIFY_SUCCEEDED') . ' ' . $pseudonym; + } + } ## end if ($trt eq 'UPD') + + if ($trt eq 'DEL') { + + # controls + $res = ''; + $res = validate_is_pseudonym($c, $pseudonym); + $result .= $res unless $res eq 'OK'; + + #$result .= 'blocked'; + $res = ''; + + if (!$result) { + $res = $c->delete_pseudonym($pseudonym); + $result .= $res unless $res eq 'OK'; + + if (!$result) { + $res = 'OK'; + $result = $c->l('pse_REMOVE_SUCCEEDED') . ' ' . $pseudonym; + } + } ## end if (!$result) + } ## end if ($trt eq 'DEL') # common parts - - if ( $res ne 'OK' ) { - $c->stash( error => $result); - $c->stash( title => $title, pse_datas => \%pse_datas ); - return $c->render('pseudonyms'); + if ($res ne 'OK') { + $c->stash(error => $result); + $c->stash(title => $title, pse_datas => \%pse_datas); + return $c->render('pseudonyms'); } - my $message = "'Pseudonyms' updates $trt DONE"; $c->app->log->info($message); - $c->flash( success => $result ); - + $c->flash(success => $result); $c->redirect_to('/pseudonyms'); - -}; - +} ## end sub do_update sub delete_pseudonym { - my ($c, $pseudonym) = @_; - my $msg = ''; + #------------------------------------------------------------ # Make the pseudonym inactive, signal pseudonym-delete event # and then delete it #------------------------------------------------------------ - my @pseudonyms = $adb->pseudonyms(); foreach my $p_rec (@pseudonyms) { if ($p_rec->prop("Account") eq $pseudonym) { - $adb->get($p_rec->key)->set_prop('type','pseudonym-deleted') + $adb->get($p_rec->key)->set_prop('type', 'pseudonym-deleted') or $msg .= "Error occurred while changing pseudonym type."; } - } - - $adb->get($pseudonym)->set_prop('type','pseudonym-deleted') + } ## end foreach my $p_rec (@pseudonyms) + $adb->get($pseudonym)->set_prop('type', 'pseudonym-deleted') or $msg .= "Error occurred while changing pseudonym type."; # Untaint $pseudonym before use in system() ($pseudonym) = ($pseudonym =~ /(.+)/); - system( "/sbin/e-smith/signal-event", "pseudonym-delete", "$pseudonym") == 0 + system("/sbin/e-smith/signal-event", "pseudonym-delete", "$pseudonym") == 0 or $msg .= "Error occurred while removing pseudonym."; #TODO: is it ->delete or get()->delete foreach my $p_rec (@pseudonyms) { + if ($p_rec->prop("Account") eq $pseudonym) { $adb->get($p_rec->key)->delete() or $msg .= "Error occurred while deleting pseudonym from database."; } - } - + } ## end foreach my $p_rec (@pseudonyms) $adb->get($pseudonym)->delete() or $msg .= "Error occurred while deleting pseudonym from database."; - - return $msg unless $msg; - + return $msg unless $msg; return 'OK'; -} - - +} ## end sub delete_pseudonym sub existing_accounts_list { my $c = shift; - - my @existingAccounts = ( ['Administrator' => 'admin']); + my @existingAccounts = ([ 'Administrator' => 'admin' ]); foreach my $a ($adb->get_all) { if ($a->prop('type') =~ /(user|group)/) { push @existingAccounts, [ $a->key => $a->key ]; } + if ($a->prop('type') eq "pseudonym") { my $target = $adb->get($a->prop('Account')); - unless ($target) - { - warn "WARNING: pseudonym (" . $a->key . ") => missing Account(" - . $a->prop('Account') . ")\n"; + unless ($target) { + warn "WARNING: pseudonym (" . $a->key . ") => missing Account(" . $a->prop('Account') . ")\n"; next; } - push @existingAccounts, [ $a->key, $a->key ] unless ($target->prop('type') eq "pseudonym"); - } - } - - return(\@existingAccounts); -} - + } ## end if ($a->prop('type') eq...) + } ## end foreach my $a ($adb->get_all) + return (\@existingAccounts); +} ## end sub existing_accounts_list =head2 get_pseudonym_account @@ -301,17 +265,17 @@ Returns the current Account property for this pseudonym =cut sub get_pseudonym_account { - my $c = shift; + my $c = shift; my $pseudonym = shift; + my $a = $adb->get($pseudonym)->prop('Account'); - my $a = $adb->get($pseudonym)->prop('Account'); if ($a eq "admin") { $a = "Administrator"; } elsif ($a eq "shared") { - $a = $c->l("EVERYONE"); + $a = $c->l("EVERYONE"); } - return($a); -} + return ($a); +} ## end sub get_pseudonym_account =head2 is_pseudonym_not_removable @@ -320,13 +284,12 @@ Returns 1 if the current Account is not removable, 0 otherwise =cut sub is_pseudonym_not_removable { - my $c = shift; + my $c = shift; my $pseudonym = shift; - my $removable = $adb->get($pseudonym)->prop('Removable') || 'yes'; - return 1 if ($removable eq 'yes'); + return 1 if ($removable eq 'yes'); return 0; -} +} ## end sub is_pseudonym_not_removable =head2 is_pseudonym_internal @@ -335,13 +298,13 @@ Returns YES if the current Account property Visible is 'internal' =cut sub is_pseudonym_internal { -# my $c = shift; - my $pseudonym = shift; + # my $c = shift; + my $pseudonym = shift; my $visible = $adb->get($pseudonym)->prop('Visible') || ''; - return 'YES' if ($visible eq 'internal'); + return 'YES' if ($visible eq 'internal'); return 'NO'; -} +} ## end sub is_pseudonym_internal =head2 validate_new_pseudonym_name FM PSEUDONYM @@ -355,30 +318,25 @@ Returns "NAME_IN_USE" if this pseudonym is taken. =cut sub validate_new_pseudonym_name { - my ($c, $pseudonym, $account) = @_; - my $acct = $adb->get($pseudonym); if (defined $acct) { - return($c->l('pse_NAME_IN_USE')); - + return ($c->l('pse_NAME_IN_USE')); } elsif ($pseudonym =~ /@/) { use esmith::DomainsDB; my $ddb = esmith::DomainsDB->open_ro - or die "Couldn't open DomainsDB\n"; + or die "Couldn't open DomainsDB\n"; my ($lhs, $rhs) = split /@/, $pseudonym; return ($c->l('pse_PSEUDONYM_INVALID_DOMAIN')) unless ($ddb->get($rhs)); return ($c->l('pse_PSEUDONYM_INVALID_SAMEACCT')) if ($lhs eq $account); - return ('OK'); # p:' . $pseudonym . ' a:' . $account); - - } elsif ( $pseudonym !~ /^([a-z0-9][a-z0-9\.\-_!#\?~\$\^\+&`%\/\*]*)$/ ) { - return($c->l('pse_VALID_PSEUDONYM_NAMES')); + return ('OK'); # p:' . $pseudonym . ' a:' . $account); + } elsif ($pseudonym !~ /^([a-z0-9][a-z0-9\.\-_!#\?~\$\^\+&`%\/\*]*)$/) { + return ($c->l('pse_VALID_PSEUDONYM_NAMES')); } else { - return('OK'); + return ('OK'); } -} - +} ## end sub validate_new_pseudonym_name =head2 validate_is_pseudonym FM NAME @@ -388,19 +346,15 @@ returns "NOT_A_PSEUDONYM" if the name in question isn't an existing pseudonym =cut sub validate_is_pseudonym { - my $c = shift; + my $c = shift; my $pseudonym = shift; - $pseudonym = $adb->get($pseudonym); - return($c->l('pse_NOT_A_PSEUDONYM')) unless $pseudonym; - + return ($c->l('pse_NOT_A_PSEUDONYM')) unless $pseudonym; my $type = $pseudonym->prop('type'); - unless (defined $type && ($type eq 'pseudonym') ) { - return($c->l('NOT_A_PSEUDONYM')); + + unless (defined $type && ($type eq 'pseudonym')) { + return ($c->l('NOT_A_PSEUDONYM')); } - return ('OK'); -} - - +} ## end sub validate_is_pseudonym 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Qmailanalog.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Qmailanalog.pm index b2649a3..723b0c5 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Qmailanalog.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Qmailanalog.pm @@ -10,143 +10,106 @@ package SrvMngr::Controller::Qmailanalog; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use esmith::FormMagick qw(gen_locale_date_string); - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw(theme_list init_session); sub main { my $c = shift; $c->app->log->info($c->log_req); - my $title = $c->l('qma_FORM_TITLE'); my $modul = $c->render_to_string(inline => $c->l('qma_INITIAL_DESC')); - - $c->stash( title => $title, modul => $modul ); + $c->stash(title => $title, modul => $modul); $c->render(template => 'qmailanalog'); -}; - +} ## end sub main sub do_update { my $c = shift; $c->app->log->info($c->log_req); - - my $result = ""; - + my $result = ""; my $report_type = $c->param('report_type'); - if ($report_type =~ /^(\S+)$/) - { - $report_type = $1; + if ($report_type =~ /^(\S+)$/) { + $report_type = $1; + } elsif ($report_type =~ /^\s*$/) { + $report_type = "zoverall"; + } else { + $result = $c->l('INVALID_REPORT_TYPE') . $report_type; + $report_type = undef; } - elsif ($report_type =~ /^\s*$/) - { - $report_type = "zoverall"; - } else { - $result = $c->l('INVALID_REPORT_TYPE') . $report_type; - $report_type = undef; - } - my $title = $c->l('qma_FORM_TITLE'); - $result = $c->render_to_string(inline => generateReport($c, $report_type)) if $report_type; - - $c->stash( title => $title, modul => $result ); + $c->stash(title => $title, modul => $result); $c->render(template => 'module'); -}; - +} ## end sub do_update sub generateReport { + my $c = shift; + my $report_type = shift; + my $out = ''; - my $c = shift; - my $report_type = shift; + #------------------------------------------------------------ + # Looks good; go ahead and generate the report. + #------------------------------------------------------------ + # $| = 1; + my $now_string = $c->gen_locale_date_string(); + $out .= sprintf("

    %s %s

    ", $c->l('REPORT_GENERATED'), $now_string); - my $out = ''; - - #------------------------------------------------------------ - # Looks good; go ahead and generate the report. - #------------------------------------------------------------ + if ($report_type =~ /^qmail-q/) { + open(QMAILQUEUEREPORT, "/var/qmail/bin/$report_type |"); + $out .= sprintf "
    ";
     
    -#	$| = 1;
    +        while () {
    +            $out .= sprintf("%s", $_);
    +        }
    +        close QMAILQUEUEREPORT;
    +        $out .= sprintf "
    "; + $out .= sprintf("

    %s

    ", $c->l('END_OF_REPORT')); + return ''; + } ## end if ($report_type =~ /^qmail-q/) + chdir "/var/log/qmail"; + open(QMAILANALOG, + "/bin/cat \@* current 2>/dev/null" + . "| /usr/local/bin/tai64nunix" + . "| /usr/local/qmailanalog/bin/matchup 5>/dev/null" + . "| /usr/local/qmailanalog/bin/$report_type |"); + $out .= sprintf "
    ";
     
    -	my $now_string = $c->gen_locale_date_string();
    -	$out .= sprintf("

    %s %s

    ", $c->l('REPORT_GENERATED'), $now_string); - - if ($report_type =~ /^qmail-q/) - { - open(QMAILQUEUEREPORT, "/var/qmail/bin/$report_type |"); - - $out .= sprintf "
    ";
    -
    -		while ()
    -		{
    -			$out .= sprintf("%s", $_);
    -		}
    -
    -		close QMAILQUEUEREPORT;
    -		$out .= sprintf "
    "; - - $out .= sprintf("

    %s

    ", $c->l('END_OF_REPORT')); - return ''; - } - - chdir "/var/log/qmail"; - - open(QMAILANALOG, - "/bin/cat \@* current 2>/dev/null" - . "| /usr/local/bin/tai64nunix" - . "| /usr/local/qmailanalog/bin/matchup 5>/dev/null" - . "| /usr/local/qmailanalog/bin/$report_type |" - ); - - $out .= sprintf "
    ";
    -
    -	while ()
    -	{
    -		# Cook any special HTML characters
    -
    -		s/\&/\&/g;
    -		s/\"/\"/g;
    -		s/\>/\>/g;
    -		s/\";
    -
    -
    -	$out .= sprintf("

    %s

    ", $c->l('END_OF_REPORT')); - return $out; - -} + while () { + # Cook any special HTML characters + s/\&/\&/g; + s/\"/\"/g; + s/\>/\>/g; + s/\) + close QMAILANALOG; + $out .= sprintf "
    "; + $out .= sprintf("

    %s

    ", $c->l('END_OF_REPORT')); + return $out; +} ## end sub generateReport sub reportType_list { - - my $c = shift; - + my $c = shift; my @array = ( -# [ $c->l('qma_LIST_OUTGOING') => 'qmail-qread' ], -# [ $c->l('qma_SUMMARIZE_QUEUE') => 'qmail-qstat' ], + + # [ $c->l('qma_LIST_OUTGOING') => 'qmail-qread' ], + # [ $c->l('qma_SUMMARIZE_QUEUE') => 'qmail-qstat' ], [ $c->l('qma_SUCCESSFUL_DELIVERY_DELAY') => 'zddist' ], - [ $c->l('qma_REASONS_DEFERRAL') => 'zdeferrals' ], - [ $c->l('qma_REASONS_FAILURE') => 'zfailures' ], - [ $c->l('qma_BASIC_STATS') => 'zoverall' ], - [ $c->l('qma_RECIP_STATS') => 'zrecipients' ], - [ $c->l('qma_RECIP_HOSTS') => 'zrhosts' ], - [ $c->l('qma_RECIP_ORDERED') => 'zrxdelay' ], - [ $c->l('qma_SENDER_STATS') => 'zsenders' ], - [ $c->l('qma_SENDMAIL_STYLE') => 'zsendmail' ], - [ $c->l('qma_REASONS_SUCCESS') => 'zsuccesses' ], - [ $c->l('qma_SENDER_UIDS') => 'zsuids' ] + [ $c->l('qma_REASONS_DEFERRAL') => 'zdeferrals' ], + [ $c->l('qma_REASONS_FAILURE') => 'zfailures' ], + [ $c->l('qma_BASIC_STATS') => 'zoverall' ], + [ $c->l('qma_RECIP_STATS') => 'zrecipients' ], + [ $c->l('qma_RECIP_HOSTS') => 'zrhosts' ], + [ $c->l('qma_RECIP_ORDERED') => 'zrxdelay' ], + [ $c->l('qma_SENDER_STATS') => 'zsenders' ], + [ $c->l('qma_SENDMAIL_STYLE') => 'zsendmail' ], + [ $c->l('qma_REASONS_SUCCESS') => 'zsuccesses' ], + [ $c->l('qma_SENDER_UIDS') => 'zsuids' ] ); my @sorted_array = sort { $a->[0] cmp $b->[0] } @array; return \@sorted_array; -} - +} ## end sub reportType_list 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Quota.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Quota.pm index 46643b4..f3c7e5c 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Quota.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Quota.pm @@ -11,183 +11,149 @@ package SrvMngr::Controller::Quota; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use esmith::FormMagick::Panel::quota; #use esmith::TestUtils; use Scalar::Util qw(looks_like_number); - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw(theme_list init_session); #our $db = esmith::ConfigDB->open || die "Couldn't open config db"; our $adb = esmith::AccountsDB->open || die "Couldn't open accounts db"; - sub main { - my $c = shift; $c->app->log->info($c->log_req); - my %quo_datas = (); - my $title = $c->l('quo_FORM_TITLE'); - + my $title = $c->l('quo_FORM_TITLE'); $quo_datas{'trt'} = 'LIST'; - my @userAccounts; + if ($adb) { @userAccounts = $adb->users(); } - - $c->stash( title => $title, quo_datas => \%quo_datas, userAccounts => \@userAccounts ); + $c->stash(title => $title, quo_datas => \%quo_datas, userAccounts => \@userAccounts); $c->render(template => 'quota'); - -}; - +} ## end sub main sub do_display { - - my $c = shift; - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LIST'); + my $c = shift; + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); my $user = $c->param('user') || ''; - - $trt = 'UPD' if ( $user ); - + $trt = 'UPD' if ($user); my %quo_datas = (); - my $title = $c->l('quo_FORM_TITLE'); - + my $title = $c->l('quo_FORM_TITLE'); $quo_datas{'trt'} = $trt; - if ( $trt eq 'UPD' ) { - - my $rec = $adb->get($user); - if ($rec and $rec->prop('type') eq 'user') { - $quo_datas{user} = $user; - $quo_datas{userRec} = $rec; - my $max = esmith::FormMagick::Panel::quota->toBestUnit($rec->prop('MaxBlocks')); - $quo_datas{hardlim} = $max; - $max = esmith::FormMagick::Panel::quota->toBestUnit($rec->prop('MaxBlocksSoftLim')); - $quo_datas{softlim} = $max; - } - - } - - $c->stash( title => $title, quo_datas => \%quo_datas ); - $c->render( template => 'quota' ); - -}; + if ($trt eq 'UPD') { + my $rec = $adb->get($user); + if ($rec and $rec->prop('type') eq 'user') { + $quo_datas{user} = $user; + $quo_datas{userRec} = $rec; + my $max = esmith::FormMagick::Panel::quota->toBestUnit($rec->prop('MaxBlocks')); + $quo_datas{hardlim} = $max; + $max = esmith::FormMagick::Panel::quota->toBestUnit($rec->prop('MaxBlocksSoftLim')); + $quo_datas{softlim} = $max; + } ## end if ($rec and $rec->prop...) + } ## end if ($trt eq 'UPD') + $c->stash(title => $title, quo_datas => \%quo_datas); + $c->render(template => 'quota'); +} ## end sub do_display sub do_update { - my $c = shift; $c->app->log->info($c->log_req); - - my $title = $c->l('quo_FORM_TITLE'); + my $title = $c->l('quo_FORM_TITLE'); my %quo_datas = (); - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LIST'); - + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); $quo_datas{trt} = $trt; my $result = ''; my $res; - if ( $trt eq 'UPD' ) { - - $quo_datas{user} = ($c->param('user') || ''); - $quo_datas{softlim} = ($c->param('Soft') || ''); + if ($trt eq 'UPD') { + $quo_datas{user} = ($c->param('user') || ''); + $quo_datas{softlim} = ($c->param('Soft') || ''); $quo_datas{hardlim} = ($c->param('Hard') || ''); - # controls - $res = validate_quota( $c, $quo_datas{user}, $quo_datas{softlim}, $quo_datas{hardlim} ); - $result .= $res unless $res eq 'OK'; + # controls + $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') . ' ' . $quo_datas{user}; - } else { - $quo_datas{userRec} = $adb->get($quo_datas{user}) || undef; - } - } + if (!$result) { + $result = $c->l('quo_SUCCESSFULLY_MODIFIED') . ' ' . $quo_datas{user}; + } else { + $quo_datas{userRec} = $adb->get($quo_datas{user}) || undef; + } + } ## end if ($trt eq 'UPD') # common parts - if ($res ne 'OK') { - $c->stash( error => $result ); - $c->stash( title => $title, quo_datas => \%quo_datas ); - return $c->render('quota'); + $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->flash(success => $result); $c->redirect_to('/quota'); - -}; - +} ## end sub do_update sub validate_quota { - my ($c, $acct, $softlim, $hardlim ) = @_; + my ($c, $acct, $softlim, $hardlim) = @_; my $msg; - my $rec = $adb->get($acct); - return $c->l('quo_ERR_NO_SUCH_ACCT') . ' : ' . $acct unless (defined $rec); - + return $c->l('quo_ERR_NO_SUCH_ACCT') . ' : ' . $acct unless (defined $rec); my $type = $rec->prop('type'); + unless ($type eq "user") { - $msg = $c->l('quo_ERR_NOT_A_USER_ACCT').$acct.$c->l('quo_ACCOUNT_IS_TYPE').$type; - return $msg; + $msg = $c->l('quo_ERR_NOT_A_USER_ACCT') . $acct . $c->l('quo_ACCOUNT_IS_TYPE') . $type; + return $msg; } my $uid = getpwnam($acct); - return $c->l('COULD_NOT_GET_UID').$acct unless ($uid); + return $c->l('COULD_NOT_GET_UID') . $acct unless ($uid); - if (($softlim !~ /^(.+?)\s*([KMGT])?$/ ) || (!looks_like_number ($1))) { - return $c->l('quo_SOFT_VAL_MUST_BE_NUMBER'); + if (($softlim !~ /^(.+?)\s*([KMGT])?$/) || (!looks_like_number($1))) { + return $c->l('quo_SOFT_VAL_MUST_BE_NUMBER'); } - - my $exponent = 1; # Entries with no suffix are assumed to be in megabytes. - if (defined ($2)) { - $exponent = index("KMGT",$2); - } - $softlim = ($1 * 1024 ** $exponent); + my $exponent = 1; # Entries with no suffix are assumed to be in megabytes. - if (($hardlim !~ /^(.+?)\s*([KMGT])?$/ ) || (!looks_like_number ($1))) { - return $c->l('quo_HARD_VAL_MUST_BE_NUMBER'); + if (defined($2)) { + $exponent = index("KMGT", $2); } - $exponent = 1; # Entries with no suffix are assumed to be in megabytes. - if (defined ($2)) - { - $exponent = index("KMGT",$2); - } - $hardlim = ($1 * 1024 ** $exponent); + $softlim = ($1 * 1024**$exponent); + + if (($hardlim !~ /^(.+?)\s*([KMGT])?$/) || (!looks_like_number($1))) { + return $c->l('quo_HARD_VAL_MUST_BE_NUMBER'); + } + $exponent = 1; # Entries with no suffix are assumed to be in megabytes. + + if (defined($2)) { + $exponent = index("KMGT", $2); + } + $hardlim = ($1 * 1024**$exponent); #------------------------------------------------------------ # Make sure that soft limit is less than hard limit. #------------------------------------------------------------ - unless ($hardlim == 0 or $hardlim > $softlim) { - return $c->l('quo_ERR_HARD_LT_SOFT'); + return $c->l('quo_ERR_HARD_LT_SOFT'); } #------------------------------------------------------------ # Update accounts database and signal the user-modify event. #------------------------------------------------------------ - - $rec->set_prop('MaxBlocks', $hardlim); + $rec->set_prop('MaxBlocks', $hardlim); $rec->set_prop('MaxBlocksSoftLim', $softlim); # Untaint $acct before using in system(). - $acct =~ /^(\w[\-\w_\.]*)$/; $acct = $1; - system ("/sbin/e-smith/signal-event", "user-modify", "$acct") == 0 - or die ($c->l('quo_ERR_MODIFYING')."\n"); - + $acct =~ /^(\w[\-\w_\.]*)$/; + $acct = $1; + system("/sbin/e-smith/signal-event", "user-modify", "$acct") == 0 + or die($c->l('quo_ERR_MODIFYING') . "\n"); return 'OK'; -} - - +} ## end sub validate_quota 1 diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Reboot.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Reboot.pm index f1c9a51..60e4029 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Reboot.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Reboot.pm @@ -1,87 +1,77 @@ package SrvMngr::Controller::Reboot; #---------------------------------------------------------------------- -# heading : System +# heading : System # description : Reboot or shutdown -# navigation : 4000 700 +# navigation : 4000 700 # # routes : end #---------------------------------------------------------------------- use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw(theme_list init_session); - sub main { - my $c = shift; $c->app->log->info($c->log_req); - my $title = $c->l('rbo_FORM_TITLE'); my $modul = ''; - - $c->stash( title => $title, modul => $modul ); + $c->stash(title => $title, modul => $modul); $c->render(template => 'reboot'); - -}; - +} ## end sub main sub do_action { - my $c = shift; $c->app->log->info($c->log_req); - - my $title = $c->l('rbo_FORM_TITLE'); - my $result = ""; - - my $function = $c->param ('function'); - - my $debug = $c->param('debug'); + my $title = $c->l('rbo_FORM_TITLE'); + my $result = ""; + my $function = $c->param('function'); + my $debug = $c->param('debug'); if ($function eq "reboot") { - $result = $c->l('rbo_REBOOT_SUCCEEDED') . '
    ' . $c->l('rbo_DESC_REBOOT'); + $result = $c->l('rbo_REBOOT_SUCCEEDED') . '
    ' . $c->l('rbo_DESC_REBOOT'); + unless ($debug) { - esmith::util::backgroundCommand( 1, "/sbin/e-smith/signal-event", "reboot" ); - # system( "/sbin/e-smith/signal-event", "reboot" ) == 0 - # or die ("Error occurred while rebooting.\n"); - } + esmith::util::backgroundCommand(1, "/sbin/e-smith/signal-event", "reboot"); + + # system( "/sbin/e-smith/signal-event", "reboot" ) == 0 + # or die ("Error occurred while rebooting.\n"); + } ## end unless ($debug) } elsif ($function eq 'shutdown') { - $result = $c->l('rbo_SHUTDOWN_SUCCEEDED') . '
    ' . $c->l('rbo_DESC_SHUTDOWN'); + $result = $c->l('rbo_SHUTDOWN_SUCCEEDED') . '
    ' . $c->l('rbo_DESC_SHUTDOWN'); + unless ($debug) { - esmith::util::backgroundCommand( 1, "/sbin/e-smith/signal-event", "halt" ); - # system( "/sbin/e-smith/signal-event", "halt" ) == 0 - # or die ("Error occurred while halting.\n"); - } + esmith::util::backgroundCommand(1, "/sbin/e-smith/signal-event", "halt"); + + # system( "/sbin/e-smith/signal-event", "halt" ) == 0 + # or die ("Error occurred while halting.\n"); + } ## end unless ($debug) } elsif ($function eq 'reconfigure') { - $result = $c->l('rbo_RECONFIGURE_SUCCEEDED') . '
    ' . $c->l('rbo_DESC_RECONFIGURE'); + $result = $c->l('rbo_RECONFIGURE_SUCCEEDED') . '
    ' . $c->l('rbo_DESC_RECONFIGURE'); + unless ($debug) { - # esmith::util::backgroundCommand( 1, "/sbin/e-smith/signal-event", "post-upgrade", - # "; ", "/sbin/e-smith/signal-event", "reboot" ); - system( "/sbin/e-smith/signal-event", "post-upgrade" ) == 0 - or die ("Error occurred while running post-upgrade.\n"); - system( "/sbin/e-smith/signal-event", "reboot" ) == 0 - or die ("Error occurred while rebooting.\n"); - } - } - $c->stash( title => $title, modul => $result ); + # esmith::util::backgroundCommand( 1, "/sbin/e-smith/signal-event", "post-upgrade", + # "; ", "/sbin/e-smith/signal-event", "reboot" ); + system("/sbin/e-smith/signal-event", "post-upgrade") == 0 + or die("Error occurred while running post-upgrade.\n"); + system("/sbin/e-smith/signal-event", "reboot") == 0 + or die("Error occurred while rebooting.\n"); + } ## end unless ($debug) + } ## end elsif ($function eq 'reconfigure') + $c->stash(title => $title, modul => $result); $c->render(template => 'module'); - -}; - +} ## end sub do_action sub rebootFunction_list { - my $c = shift; - return [[ $c->l('rbo_REBOOT') => 'reboot' ], - [ $c->l('RECONFIGURE') => 'reconfigure' ], - [ $c->l('SHUTDOWN') => 'shutdown' ]]; -} - - + return [ + [ $c->l('rbo_REBOOT') => 'reboot' ], + [ $c->l('RECONFIGURE') => 'reconfigure' ], + [ $c->l('SHUTDOWN') => 'shutdown' ] + ]; +} ## end sub rebootFunction_list 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Remoteaccess.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Remoteaccess.pm index 4528444..668b8f2 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Remoteaccess.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Remoteaccess.pm @@ -11,12 +11,9 @@ package SrvMngr::Controller::Remoteaccess; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw(theme_list init_session ip_number subnet_mask get_reg_mask); - use esmith::ConfigDB; use esmith::util; use File::Basename; @@ -25,29 +22,23 @@ use Carp; use Socket qw( inet_aton ); #our @ISA = qw(esmith::FormMagick Exporter); - -our @EXPORT = - qw( networkAccess_list passwordLogin_list get_ssh_permit_root_login get_ssh_access get_telnet_mode - get_ftp_access get_ftp_password_login_access - get_value get_prop get_ssh_password_auth - validate_network_and_mask ip_number_or_blank subnet_mask_or_blank - get_ipsecrw_sessions pptp_and_dhcp_range - ); +our @EXPORT = qw( networkAccess_list passwordLogin_list get_ssh_permit_root_login get_ssh_access get_telnet_mode + get_ftp_access get_ftp_password_login_access + get_value get_prop get_ssh_password_auth + validate_network_and_mask ip_number_or_blank subnet_mask_or_blank + get_ipsecrw_sessions pptp_and_dhcp_range +); # get_pptp_sessions - our $db = esmith::ConfigDB->open || warn "Couldn't open configuration database"; sub main { - my $c = shift; - $c->app->log->info( $c->log_req ); - + $c->app->log->info($c->log_req); my $title = $c->l('rma_FORM_TITLE'); my $notif = ''; my %rma_datas = (); - - $db = esmith::ConfigDB->open || warn "Couldn't open configuration database"; + $db = esmith::ConfigDB->open || warn "Couldn't open configuration database"; #$rma_datas{ipsecrwSess} = $c->get_ipsecrw_sessions(); #$rma_datas{pptpSessions} = $c->get_pptp_sessions(); @@ -59,106 +50,84 @@ sub main { $rma_datas{ftpPasswordAccess} = $c->get_ftp_password_login_access(); #$rma_datas{telnetAccess} = $c->get_telnet_access; - - $c->stash( title => $title, notif => $notif, rma_datas => \%rma_datas ); - $c->render( template => 'remoteaccess' ); - -} + $c->stash(title => $title, notif => $notif, rma_datas => \%rma_datas); + $c->render(template => 'remoteaccess'); +} ## end sub main sub do_action { - my $c = shift; - $c->app->log->info( $c->log_req ); - + $c->app->log->info($c->log_req); my $title = $c->l('rma_FORM_TITLE'); - my ( $result, $res, $trt ) = ''; + my ($result, $res, $trt) = ''; my %rma_datas = (); - - $db = esmith::ConfigDB->open || warn "Couldn't open configuration database"; - - $rma_datas{ipsecrwSess} = ( $c->param('IpsecrwSess') || '' ); - $rma_datas{ipsecrwReset} = ( $c->param('IpsecrwReset') || '' ); + $db = esmith::ConfigDB->open || warn "Couldn't open configuration database"; + $rma_datas{ipsecrwSess} = ($c->param('IpsecrwSess') || ''); + $rma_datas{ipsecrwReset} = ($c->param('IpsecrwReset') || ''); #$rma_datas{pptpSessions} = ($c->param ('PptpSessions') || '0'); - - $rma_datas{validFromNetwork} = ( $c->param('ValidFromNetwork') || '' ); - $rma_datas{validFromMask} = ( $c->param('ValidFromMask') || '' ); + $rma_datas{validFromNetwork} = ($c->param('ValidFromNetwork') || ''); + $rma_datas{validFromMask} = ($c->param('ValidFromMask') || ''); ## my @remove = $q->param('validFromRemove'); ???????? the first one only !! my @vals = $c->param('Remove_nets'); $rma_datas{remove_nets} = join ',', @vals; - - $rma_datas{sshaccess} = ( $c->param('SshAccess') || 'off' ); - $rma_datas{sshPermitRootLogin} = - ( $c->param('SshPermitRootLogin') || 'no' ); - $rma_datas{sshPasswordAuthentication} = - ( $c->param('SshPasswordAuthentication') || 'no' ); - $rma_datas{sshTCPPort} = ( $c->param('SshTCPPort') || '22' ); - - $rma_datas{ftpAccess} = ( $c->param('FtpAccess') || 'off' ); - $rma_datas{ftpPasswordAccess} = - ( $c->param('FtpPasswordAccess') || 'private' ); - - $rma_datas{telnetAccess} = ( $c->param('TelnetAccess') || 'off' ); + $rma_datas{sshaccess} = ($c->param('SshAccess') || 'off'); + $rma_datas{sshPermitRootLogin} = ($c->param('SshPermitRootLogin') || 'no'); + $rma_datas{sshPasswordAuthentication} = ($c->param('SshPasswordAuthentication') || 'no'); + $rma_datas{sshTCPPort} = ($c->param('SshTCPPort') || '22'); + $rma_datas{ftpAccess} = ($c->param('FtpAccess') || 'off'); + $rma_datas{ftpPasswordAccess} = ($c->param('FtpPasswordAccess') || 'private'); + $rma_datas{telnetAccess} = ($c->param('TelnetAccess') || 'off'); # validate my $v = $c->validation; return $c->render('remoteaccess') unless $v->has_data; #$v->optional('PptpSessions')->num(0, 999)->is_valid; - if ( $c->param('ValidFromNetwork') ne "" ) { - $v->optional('ValidFromNetwork')->size( 7, 15 )->is_valid; + if ($c->param('ValidFromNetwork') ne "") { + $v->optional('ValidFromNetwork')->size(7, 15)->is_valid; } - if ( $c->param('ValidFromMask') ne "" ) { - $v->optional('ValidFromMask')->size( 7, 15 )->is_valid; - } - $v->required('SshTCPPort')->num( 1, 65535 )->is_valid; + if ($c->param('ValidFromMask') ne "") { + $v->optional('ValidFromMask')->size(7, 15)->is_valid; + } + $v->required('SshTCPPort')->num(1, 65535)->is_valid; $result .= 'field validation error' if $v->has_error; - if ( !$result ) { + if (!$result) { # controls #$res = pptp_and_dhcp_range( $c, $rma_datas{pptpSessions} ); #$result .= $res . ' ' unless $res eq 'OK'; - - $res = ip_number_or_blank( $c, $rma_datas{validFromNetwork} ); + $res = ip_number_or_blank($c, $rma_datas{validFromNetwork}); $result .= $res . ' ' unless $res eq 'OK'; - - $res = subnet_mask_or_blank( $c, $rma_datas{validFromMask} ); + $res = subnet_mask_or_blank($c, $rma_datas{validFromMask}); $result .= $res . ' ' unless $res eq 'OK'; - - $res = validate_network_and_mask( - $c, - $rma_datas{validFromNetwork}, - $rma_datas{validFromMask} - ); + $res = validate_network_and_mask($c, $rma_datas{validFromNetwork}, $rma_datas{validFromMask}); $result .= $res . ' ' unless $res eq 'OK'; #$result .= ' blocked for testing !' . $rma_datas{remove_nets}; - } + } ## end if (!$result) - if ( !$result ) { - $res = change_settings( $c, %rma_datas ); + if (!$result) { + $res = change_settings($c, %rma_datas); $result .= $res unless $res eq 'OK'; } - - if ( $result eq "" ) { + + if ($result eq "") { $result = $c->l('rma_SUCCESS'); $trt = 'SUC'; } - $c->stash( title => $title, notif => $result, rma_datas => \%rma_datas ); + $c->stash(title => $title, notif => $result, rma_datas => \%rma_datas); #return $c->render( template => 'remoteaccess' ); - - if ( $trt eq 'SUC' ) { - $c->stash( title => $title,modul => $result); - return $c->render( template => 'module' ); + if ($trt eq 'SUC') { + $c->stash(title => $title, modul => $result); + return $c->render(template => 'module'); } + return $c->render(template => 'remoteaccess'); - return $c->render( template => 'remoteaccess' ); #$c->redirect_to('/remoteaccess'); - -} +} ## end sub do_action sub networkAccess_list { my $c = shift; @@ -167,40 +136,33 @@ sub networkAccess_list { [ $c->l('NETWORKS_ALLOW_LOCAL') => 'private' ], [ $c->l('NETWORKS_ALLOW_PUBLIC') => 'public' ] ]; -} +} ## end sub networkAccess_list sub passwordLogin_list { my $c = shift; - return [ - [ $c->l('rma_PASSWORD_LOGIN_PRIVATE') => 'private' ], - [ $c->l('rma_PASSWORD_LOGIN_PUBLIC') => 'public' ] - ]; + return [ [ $c->l('rma_PASSWORD_LOGIN_PRIVATE') => 'private' ], [ $c->l('rma_PASSWORD_LOGIN_PUBLIC') => 'public' ] ]; } sub get_prop { - - my ( $c, $item, $prop ) = @_; + my ($c, $item, $prop) = @_; warn "You must specify a record key" unless $item; warn "You must specify a property name" unless $prop; my $record = $db->get($item) or warn "Couldn't get record for $item"; return $record ? $record->prop($prop) : undef; -} +} ## end sub get_prop sub get_value { - my $c = shift; my $item = shift; - return ( $db->get($item)->value() ); -} + return ($db->get($item)->value()); +} ## end sub get_value sub get_ftp_access { - - my $status = get_prop( '', 'ftp', 'status' ) || 'disabled'; + my $status = get_prop('', 'ftp', 'status') || 'disabled'; return 'off' unless $status eq 'enabled'; - - my $access = get_prop( '', 'ftp', 'access' ) || 'private'; - return ( $access eq 'public' ) ? 'normal' : 'private'; -} + my $access = get_prop('', 'ftp', 'access') || 'private'; + return ($access eq 'public') ? 'normal' : 'private'; +} ## end sub get_ftp_access #sub get_pptp_sessions { # my $status = get_prop('','pptpd','status'); @@ -208,188 +170,160 @@ sub get_ftp_access { # return(get_prop('','pptpd','sessions') || 'no'); # return '0'; #} - sub get_ssh_permit_root_login { - return ( get_prop( '', 'sshd', 'PermitRootLogin' ) || 'no' ); + return (get_prop('', 'sshd', 'PermitRootLogin') || 'no'); } sub get_ssh_password_auth { - return ( get_prop( '', 'sshd', 'PasswordAuthentication' ) || 'yes' ); + return (get_prop('', 'sshd', 'PasswordAuthentication') || 'yes'); } sub get_ssh_access { + my $status = get_prop('', 'sshd', 'status'); - my $status = get_prop( '', 'sshd', 'status' ); - if ( defined($status) && ( $status eq 'enabled' ) ) { - my $access = get_prop( '', 'sshd', 'access' ); - $access = ( $access eq 'public' ) ? 'public' : 'private'; + if (defined($status) && ($status eq 'enabled')) { + my $access = get_prop('', 'sshd', 'access'); + $access = ($access eq 'public') ? 'public' : 'private'; return ($access); - } - else { + } else { return ('off'); } -} +} ## end sub get_ssh_access sub get_ssh_port { - return ( get_prop( '$c', 'sshd', 'TCPPort' ) || '22' ); + return (get_prop('$c', 'sshd', 'TCPPort') || '22'); } sub get_ftp_password_login_access { - - my $status = get_prop( '', 'ftp', 'status' ) || 'disabled'; + my $status = get_prop('', 'ftp', 'status') || 'disabled'; return 'private' unless $status eq 'enabled'; - - my $access = get_prop( '', 'ftp', 'LoginAccess' ) || 'private'; - - return ( $access eq 'public' ) ? 'public' : 'private'; -} + my $access = get_prop('', 'ftp', 'LoginAccess') || 'private'; + return ($access eq 'public') ? 'public' : 'private'; +} ## end sub get_ftp_password_login_access sub get_telnet_mode { - my $telnet = $db->get('telnet'); return ('off') unless $telnet; my $status = $telnet->prop('status') || 'disabled'; return ('off') unless $status eq 'enabled'; my $access = $telnet->prop('access') || 'private'; - return ( $access eq "public" ) ? "public" : "private"; -} + return ($access eq "public") ? "public" : "private"; +} ## end sub get_telnet_mode sub get_ipsecrw_sessions { - my $status = $db->get('ipsec')->prop('RoadWarriorStatus'); - if ( defined($status) && ( $status eq 'enabled' ) ) { - return ( $db->get('ipsec')->prop('RoadWarriorSessions') || '0' ); - } - else { + + if (defined($status) && ($status eq 'enabled')) { + return ($db->get('ipsec')->prop('RoadWarriorSessions') || '0'); + } else { return ('0'); } -} +} ## end sub get_ipsecrw_sessions sub get_ipsecrw_status { - - return undef unless ( $db->get('ipsec') ); + return undef unless ($db->get('ipsec')); return $db->get('ipsec')->prop('RoadWarriorStatus'); - } sub pptp_and_dhcp_range { - my $c = shift; my $val = shift || 0; - my $dhcp_status = $db->get_prop( 'dhcpd', 'status' ) || 'disabled'; - my $dhcp_end = $db->get_prop( 'dhcpd', 'end' ) || ''; - my $dhcp_start = $db->get_prop( 'dhcpd', 'start' ) || ''; + my $dhcp_status = $db->get_prop('dhcpd', 'status') || 'disabled'; + my $dhcp_end = $db->get_prop('dhcpd', 'end') || ''; + my $dhcp_start = $db->get_prop('dhcpd', 'start') || ''; - if ( $dhcp_status eq 'enabled' ) { + if ($dhcp_status eq 'enabled') { my $ip_start = unpack 'N', inet_aton($dhcp_start); my $ip_end = unpack 'N', inet_aton($dhcp_end); my $ip_count = $ip_end - $ip_start; - return 'OK' if ( $val < $ip_count ); - return $c->l( -'rma_NUMBER_OF_PPTP_CLIENTS_MUST_BE_LESSER_THAN_NUMBER_OF_IP_IN_DHCP_RANGE' - ); - } - else { + return 'OK' if ($val < $ip_count); + return $c->l('rma_NUMBER_OF_PPTP_CLIENTS_MUST_BE_LESSER_THAN_NUMBER_OF_IP_IN_DHCP_RANGE'); + } else { return 'OK'; } -} +} ## end sub pptp_and_dhcp_range sub _get_valid_from { - - my $c = shift; - + my $c = shift; my $rec = $db->get('httpd-admin'); return undef unless ($rec); - my @vals = ( split ',', ( $rec->prop('ValidFrom') || '' ) ); + my @vals = (split ',', ($rec->prop('ValidFrom') || '')); return @vals; -} +} ## end sub _get_valid_from sub ip_number_or_blank { - my $c = shift; my $ip = shift; - if ( !defined($ip) || $ip eq "" ) { + if (!defined($ip) || $ip eq "") { return 'OK'; } - return ip_number( $c, $ip ); -} + return ip_number($c, $ip); +} ## end sub ip_number_or_blank sub subnet_mask_or_blank { - my $c = shift; my $mask = shift; - if ( !defined($mask) || $mask eq "" ) { + if (!defined($mask) || $mask eq "") { return "OK"; } - chomp $mask; - - return ( subnet_mask($mask) ne 'OK' ) - ? $c->l('rma_INVALID_SUBNET_MASK') . " (" . $mask . ")" - : 'OK'; -} + return (subnet_mask($mask) ne 'OK') + ? $c->l('rma_INVALID_SUBNET_MASK') . " (" . $mask . ")" + : 'OK'; +} ## end sub subnet_mask_or_blank sub validate_network_and_mask { - my $c = shift; my $net = shift || ""; my $mask = shift || ""; - if ( $net xor $mask ) { - return $c->l( - 'rma_ERR_INVALID_PARAMS' . " (" . $net . "/" . $mask . ")" ); + if ($net xor $mask) { + return $c->l('rma_ERR_INVALID_PARAMS' . " (" . $net . "/" . $mask . ")"); } return 'OK'; -} +} ## end sub validate_network_and_mask sub change_settings { - - my ( $c, %rma_datas ) = @_; + my ($c, %rma_datas) = @_; #------------------------------------------------------------ # good; go ahead and change the access. #------------------------------------------------------------ - my $rec = $db->get('telnet'); + if ($rec) { - if ( $rma_datas{telnetAccess} eq "off" ) { - $rec->set_prop( 'status', 'disabled' ); + if ($rma_datas{telnetAccess} eq "off") { + $rec->set_prop('status', 'disabled'); + } else { + $rec->set_prop('status', 'enabled'); + $rec->set_prop('access', $rma_datas{telnetAccess}); } - else { - $rec->set_prop( 'status', 'enabled' ); - $rec->set_prop( 'access', $rma_datas{telnetAccess} ); - } - } - - $rec = $db->get('sshd') || $db->new_record( 'sshd', { type => 'service' } ); - $rec->set_prop( 'TCPPort', $rma_datas{sshTCPPort} ); - $rec->set_prop( 'status', - ( $rma_datas{sshaccess} eq "off" ? 'disabled' : 'enabled' ) ); - $rec->set_prop( 'access', $rma_datas{sshaccess} ); - $rec->set_prop( 'PermitRootLogin', $rma_datas{sshPermitRootLogin} ); - $rec->set_prop( 'PasswordAuthentication', - $rma_datas{sshPasswordAuthentication} ); - + } ## end if ($rec) + $rec = $db->get('sshd') || $db->new_record('sshd', { type => 'service' }); + $rec->set_prop('TCPPort', $rma_datas{sshTCPPort}); + $rec->set_prop('status', ($rma_datas{sshaccess} eq "off" ? 'disabled' : 'enabled')); + $rec->set_prop('access', $rma_datas{sshaccess}); + $rec->set_prop('PermitRootLogin', $rma_datas{sshPermitRootLogin}); + $rec->set_prop('PasswordAuthentication', $rma_datas{sshPasswordAuthentication}); $rec = $db->get('ftp'); + if ($rec) { - if ( $rma_datas{ftpAccess} eq "off" ) { - $rec->set_prop( 'status', 'disabled' ); - $rec->set_prop( 'access', 'private' ); - $rec->set_prop( 'LoginAccess', 'private' ); + if ($rma_datas{ftpAccess} eq "off") { + $rec->set_prop('status', 'disabled'); + $rec->set_prop('access', 'private'); + $rec->set_prop('LoginAccess', 'private'); + } elsif ($rma_datas{ftpAccess} eq "normal") { + $rec->set_prop('status', 'enabled'); + $rec->set_prop('access', 'public'); + $rec->set_prop('LoginAccess', $rma_datas{ftpPasswordAccess}); + } else { + $rec->set_prop('status', 'enabled'); + $rec->set_prop('access', 'private'); + $rec->set_prop('LoginAccess', $rma_datas{ftpPasswordAccess}); } - elsif ( $rma_datas{ftpAccess} eq "normal" ) { - $rec->set_prop( 'status', 'enabled' ); - $rec->set_prop( 'access', 'public' ); - $rec->set_prop( 'LoginAccess', $rma_datas{ftpPasswordAccess} ); - } - else { - $rec->set_prop( 'status', 'enabled' ); - $rec->set_prop( 'access', 'private' ); - $rec->set_prop( 'LoginAccess', $rma_datas{ftpPasswordAccess} ); - } - } + } ## end if ($rec) # if ($rma_datas{pptpSessions} == 0) { # $db->get('pptpd')->set_prop('status', 'disabled'); @@ -397,107 +331,85 @@ sub change_settings { # $db->get('pptpd')->set_prop('status', 'enabled'); # $db->get('pptpd')->set_prop('sessions', $rma_datas{pptpSessions}); # } + if ($rma_datas{validFromNetwork} && $rma_datas{validFromMask}) { - if ( $rma_datas{validFromNetwork} && $rma_datas{validFromMask} ) { - unless ( - add_new_valid_from( - $c, - $rma_datas{validFromNetwork}, - $rma_datas{validFromMask} - ) - ) - { + unless (add_new_valid_from($c, $rma_datas{validFromNetwork}, $rma_datas{validFromMask})) { return $c->l('rma_ERROR_UPDATING_CONFIGURATION') . 'new net'; } - } + } ## end if ($rma_datas{validFromNetwork...}) - if ( $rma_datas{remove_nets} ) { - unless ( remove_valid_from( $c, $rma_datas{remove_nets} ) ) { + if ($rma_datas{remove_nets}) { + unless (remove_valid_from($c, $rma_datas{remove_nets})) { return $c->l('rma_ERROR_UPDATING_CONFIGURATION') . 'del net'; } - } + } ## end if ($rma_datas{remove_nets...}) # reset ipsec roadwarrior CA,server,client certificates - if ( $rma_datas{ipsecrwReset} ) { - system( '/sbin/e-smith/roadwarrior', 'reset_certs' ) == 0 - or return $c->l('rma_ERROR_UPDATING_CONFIGURATION') . 'rst ipsec'; + if ($rma_datas{ipsecrwReset}) { + system('/sbin/e-smith/roadwarrior', 'reset_certs') == 0 + or return $c->l('rma_ERROR_UPDATING_CONFIGURATION') . 'rst ipsec'; } - if ( $rma_datas{ipsecrwSess} ) { - set_ipsecrw_sessions( $c, $rma_datas{ipsecrwSess} ); + if ($rma_datas{ipsecrwSess}) { + set_ipsecrw_sessions($c, $rma_datas{ipsecrwSess}); } - unless ( - system( "/sbin/e-smith/signal-event", "remoteaccess-update" ) == 0 ) - { + unless (system("/sbin/e-smith/signal-event", "remoteaccess-update") == 0) { return $c->l('rma_ERROR_UPDATING_CONFIGURATION'); } - return 'OK'; -} +} ## end sub change_settings sub set_ipsecrw_sessions { - my $c = shift; my $sessions = shift; - if ( defined $sessions ) { - $db->get('ipsec')->set_prop( 'RoadWarriorSessions', $sessions ); - if ( int($sessions) > 0 ) { - $db->get('ipsec')->set_prop( 'RoadWarriorStatus', 'enabled' ); + if (defined $sessions) { + $db->get('ipsec')->set_prop('RoadWarriorSessions', $sessions); + + if (int($sessions) > 0) { + $db->get('ipsec')->set_prop('RoadWarriorStatus', 'enabled'); } - } + } ## end if (defined $sessions) return ''; -} +} ## end sub set_ipsecrw_sessions sub add_new_valid_from { - my $c = shift; my $net = shift; my $mask = shift; # we transform bit mask to regular mask - $mask = get_reg_mask( $net, $mask ); - + $mask = get_reg_mask($net, $mask); my $rec = $db->get('httpd-admin'); return $c->error('ERR_NO_RECORD') unless $rec; - my $prop = $rec->prop('ValidFrom') || ''; - my @vals = split /,/, $prop; - return '' if ( grep /^$net\/$mask$/, @vals ); # already have this entry + return '' if (grep /^$net\/$mask$/, @vals); # already have this entry - if ( $prop ne '' ) { + if ($prop ne '') { $prop .= ",$net/$mask"; - } - else { + } else { $prop = "$net/$mask"; } - - $rec->set_prop( 'ValidFrom', $prop ); - + $rec->set_prop('ValidFrom', $prop); return 1; -} +} ## end sub add_new_valid_from sub remove_valid_from { - my $c = shift; my $remove_nets = shift; - - my @remove = split /,/, $remove_nets; + my @remove = split /,/, $remove_nets; # my @remove = $c->param('Remove_nets'); my @vals = $c->_get_valid_from(); foreach my $entry (@remove) { - return undef unless $entry; - - my ( $net, $mask ) = split( /\//, $entry ); + my ($net, $mask) = split(/\//, $entry); unless (@vals) { - print STDERR - "ERROR: unable to load ValidFrom property from conf db\n"; + print STDERR "ERROR: unable to load ValidFrom property from conf db\n"; return undef; } @@ -506,20 +418,16 @@ sub remove_valid_from { # added a 32 bit mask, so we don't know for sure if the value in db # is $net alone or $net/255.255.255.255. we have to check for both # in this special case... - @vals = ( grep { $entry ne $_ && $net ne $_ } @vals ); - } - + @vals = (grep { $entry ne $_ && $net ne $_ } @vals); + } ## end foreach my $entry (@remove) my $prop; + if (@vals) { $prop = join ',', @vals; - } - else { + } else { $prop = ''; } - - $db->get('httpd-admin')->set_prop( 'ValidFrom', $prop ); - + $db->get('httpd-admin')->set_prop('ValidFrom', $prop); return 1; -} - -1; \ No newline at end of file +} ## end sub remove_valid_from +1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Request.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Request.pm index e10643a..62e38c5 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Request.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Request.pm @@ -1,56 +1,46 @@ package SrvMngr::Controller::Request; - # # routes : end #---------------------------------------------------------------------- use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw(theme_list init_session); # retrieve a configuration db record sub getconfig { - my $c = shift; + my $c = shift; my $key = $c->param('key'); - $c->app->log->info($c->log_req . ' ' . $key); if ($key) { - use esmith::ConfigDB qw(open_ro); - my $cdb = esmith::ConfigDB->open_ro; - return getdb( $c, $cdb, $key); - } -} - + use esmith::ConfigDB qw(open_ro); + my $cdb = esmith::ConfigDB->open_ro; + return getdb($c, $cdb, $key); + } ## end if ($key) +} ## end sub getconfig # retrieve an accounts db record, given its name sub getaccount { - my $c = shift; + my $c = shift; my $key = $c->param('key'); - $c->app->log->info($c->log_req . ' ' . $key); if ($key) { - use esmith::AccountsDB qw(open_ro); - my $adb = esmith::AccountsDB->open_ro; - return getdb( $c, $adb, $key); - } -} - + use esmith::AccountsDB qw(open_ro); + my $adb = esmith::AccountsDB->open_ro; + return getdb($c, $adb, $key); + } ## end if ($key) +} ## end sub getaccount sub getdb { - my ($c, $db, $key) = @_; - if ( my $rec = $db->get($key) ) { - return $c->render(json => { $key => { $rec->props }} ); + if (my $rec = $db->get($key)) { + return $c->render(json => { $key => { $rec->props } }); } return undef; -} - - +} ## end sub getdb 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Review.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Review.pm index 1132e2d..2209796 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Review.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Review.pm @@ -7,76 +7,59 @@ package SrvMngr::Controller::Review; # menu : N # routes : end #---------------------------------------------------------------------- -# heading-o : Configuration +# heading-o : Configuration # description-o : Review configuration # navigation-o : 6000 6800 - #---------------------------------------------------------------------- use strict; use warnings; - use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw(theme_list init_session); #use SrvMngr::Review_sub qw(print_page); #use smeserver::Panel::review; use esmith::FormMagick::Panel::review; - -our $db = esmith::ConfigDB->open_ro || die "Couldn't open config db"; -our $domains = esmith::DomainsDB->open_ro || die "Couldn't open domains"; +our $db = esmith::ConfigDB->open_ro || die "Couldn't open config db"; +our $domains = esmith::DomainsDB->open_ro || die "Couldn't open domains"; our $networks = esmith::NetworksDB->open_ro || die "Couldn't open networks"; - sub main { my $c = shift; $c->app->log->info($c->log_req); - - my $title = $c->l('rvw_FORM_TITLE'); - my $modul = $c->render_to_string(inline => $c->l('rvw_DESCRIPTION')); + my $title = $c->l('rvw_FORM_TITLE'); + my $modul = $c->render_to_string(inline => $c->l('rvw_DESCRIPTION')); my %rvw_datas = (); - - $rvw_datas{'servermode'} = (get_value('','SystemMode' )|| ''); - $rvw_datas{'localip'} = get_value('$c','LocalIP' ) - .'/'.get_value('$c','LocalNetmask'); - $rvw_datas{'publicip'} = - esmith::FormMagick::Panel::review->get_public_ip_address($c); - $rvw_datas{'gateway'} = - $c->render_to_string(inline => print2_gateway_stanza($c)); - $rvw_datas{'serveronly'} = - $c->render_to_string(inline => print2_serveronly_stanza($c)); + $rvw_datas{'servermode'} = (get_value('', 'SystemMode') || ''); + $rvw_datas{'localip'} = get_value('$c', 'LocalIP') . '/' . get_value('$c', 'LocalNetmask'); + $rvw_datas{'publicip'} = esmith::FormMagick::Panel::review->get_public_ip_address($c); + $rvw_datas{'gateway'} = $c->render_to_string(inline => print2_gateway_stanza($c)); + $rvw_datas{'serveronly'} = $c->render_to_string(inline => print2_serveronly_stanza($c)); $rvw_datas{'addlocalnetworks'} = get_local_networks($c); - $rvw_datas{'dhcpserver'} = - $c->render_to_string(inline => print2_dhcp_stanza($c)); - - $rvw_datas{'dnsserver'} = (get_value('','LocalIP' )|| ''); - $rvw_datas{'webserver'} = 'www.'.(get_local_domain()); + $rvw_datas{'dhcpserver'} = $c->render_to_string(inline => print2_dhcp_stanza($c)); + $rvw_datas{'dnsserver'} = (get_value('', 'LocalIP') || ''); + $rvw_datas{'webserver'} = 'www.' . (get_local_domain()); my $port = $db->get_prop("squid", "TransparentPort") || 3128; - $rvw_datas{'proxyserver'} = 'proxy.'.get_local_domain().":$port"; - $rvw_datas{'ftpserver'} = 'ftp.'.get_local_domain(); - $rvw_datas{'smtpserver'} = 'mail.'.get_local_domain(); - - $rvw_datas{'domainname'} = (get_value('','DomainName' )|| ''); - $rvw_datas{'virtualdomains'} = - $c->render_to_string(inline => gen2_domains($c)); - $rvw_datas{'primarywebsite'} = 'http://www.'.get_value('','DomainName'); - $rvw_datas{'servermanager'} = 'https://'. (get_value('','SystemName') || 'localhost').'/server-manager/'; - $rvw_datas{'usermanager'} = 'https://'. (get_value('','SystemName') || 'localhost').'/user-password/'; - $rvw_datas{'emailaddresses'} = - $c->render_to_string(inline => gen2_email_addresses($c)); + $rvw_datas{'proxyserver'} = 'proxy.' . get_local_domain() . ":$port"; + $rvw_datas{'ftpserver'} = 'ftp.' . get_local_domain(); + $rvw_datas{'smtpserver'} = 'mail.' . get_local_domain(); + $rvw_datas{'domainname'} = (get_value('', 'DomainName') || ''); + $rvw_datas{'virtualdomains'} = $c->render_to_string(inline => gen2_domains($c)); + $rvw_datas{'primarywebsite'} = 'http://www.' . get_value('', 'DomainName'); + $rvw_datas{'servermanager'} = 'https://' . (get_value('', 'SystemName') || 'localhost') . '/server-manager/'; + $rvw_datas{'usermanager'} = 'https://' . (get_value('', 'SystemName') || 'localhost') . '/user-password/'; + $rvw_datas{'emailaddresses'} = $c->render_to_string(inline => gen2_email_addresses($c)); #$c->stash( releaseVersion => $c->session->{releaseVersion}, copyRight => $c->session->{copyRight}, - #PwdSet => $c->session->{PwdSet}, Unsafe => $c->session->{Unsafe}, - $c->stash( title => $title, modul => $modul, rvw_datas => \%rvw_datas, - ); - + #PwdSet => $c->session->{PwdSet}, Unsafe => $c->session->{Unsafe}, + $c->stash( + title => $title, + modul => $modul, + rvw_datas => \%rvw_datas, + ); $c->render(template => 'review'); - -} - +} ## end sub main =head2 gen2_email_addresses @@ -86,20 +69,28 @@ sub main { =cut sub gen2_email_addresses { - my $c = shift; - - my $domain = get_value($c,'DomainName'); + my $c = shift; + my $domain = get_value($c, 'DomainName'); my $useraccount = $c->l("rvw_EMAIL_USERACCOUNT"); - my $firstname = $c->l("rvw_EMAIL_FIRSTNAME"); - my $lastname = $c->l("rvw_EMAIL_LASTNAME"); - - my $out = "" . $useraccount . "\@" . $domain . "
    " - . "" . $firstname . "." . $lastname . "\@" . $domain . "
    " - . "" . $firstname . "_" . $lastname . "\@" . $domain . "
    "; - - return $out; -} - + my $firstname = $c->l("rvw_EMAIL_FIRSTNAME"); + my $lastname = $c->l("rvw_EMAIL_LASTNAME"); + my $out + = "" + . $useraccount + . "\@" + . $domain . "
    " . "" + . $firstname + . "." + . $lastname + . "\@" + . $domain . "
    " . "" + . $firstname + . "_" + . $lastname + . "\@" + . $domain . "
    "; + return $out; +} ## end sub gen2_email_addresses =head2 gen2_domains @@ -109,26 +100,25 @@ sub gen2_email_addresses { =cut sub gen2_domains { - my $c = shift; - - my @virtual = $domains->get_all_by_prop( type => 'domain'); + my $c = shift; + my @virtual = $domains->get_all_by_prop(type => 'domain'); my $numvirtual = @virtual; + if ($numvirtual == 0) { $c->localise("NO_VIRTUAL_DOMAINS"); - } - else { + } else { my $out = ""; my $domain; + foreach $domain (sort @virtual) { if ($out ne "") { $out .= "
    "; } $out .= $domain->key; - } + } ## end foreach $domain (sort @virtual) return $out; - } -} - + } ## end else [ if ($numvirtual == 0) ] +} ## end sub gen2_domains =head2 get2_local_networks @@ -138,33 +128,28 @@ serving. (mojo ver) =cut sub get2_local_networks { - my $c = shift; - - my @nets = $networks->get_all_by_prop('type' => 'network'); - + my $c = shift; + my @nets = $networks->get_all_by_prop('type' => 'network'); my $numNetworks = @nets; + if ($numNetworks == 0) { - return $c->l('rvw_NO_NETWORKS'); - } - else { + return $c->l('rvw_NO_NETWORKS'); + } else { my $out = ""; + foreach my $network (sort @nets) { if ($out ne "") { $out .= "
    "; } + $out .= $network->key . "/" . get_net_prop($c, $network->key, 'Mask'); - $out .= $network->key."/" . get_net_prop($c, $network->key, 'Mask'); - - if ( defined get_net_prop($c, $network->key, 'Router') ) { - $out .= " via " . get_net_prop ($c, $network->key, 'Router'); + if (defined get_net_prop($c, $network->key, 'Router')) { + $out .= " via " . get_net_prop($c, $network->key, 'Router'); } - } + } ## end foreach my $network (sort @nets) return $out; - } - -} - - + } ## end else [ if ($numNetworks == 0)] +} ## end sub get2_local_networks =head2 print2_gateway_stanza @@ -172,28 +157,28 @@ If this system is a server gateway, show the external ip and gateway ip (mojo ve =cut -sub print2_gateway_stanza -{ +sub print2_gateway_stanza { my $c = shift; - if (get_value($c,'SystemMode') =~ /servergateway/) - { - my $ip = get_value($c,'ExternalIP'); - my $static = - (get_value($c, 'AccessType') eq 'dedicated') && - (get_value($c, 'ExternalDHCP') eq 'off') && - (get_prop($c, 'pppoe', 'status') eq 'disabled'); - if ($static) - { - $ip .= "/".get_value($c,'ExternalNetmask'); - } - my $out = $c->l('rvw_EXTERNAL_IP_ADDRESS_SUBNET_MASK').':'.$ip; - if ($static) - { - $out .= $c->l('rvw_GATEWAY').':'.get_value($c,'GatewayIP'); - } - return $out - } -} + + if (get_value($c, 'SystemMode') =~ /servergateway/) { + my $ip = get_value($c, 'ExternalIP'); + my $static + = (get_value($c, 'AccessType') eq 'dedicated') + && (get_value($c, 'ExternalDHCP') eq 'off') + && (get_prop($c, 'pppoe', 'status') eq 'disabled'); + + if ($static) { + $ip .= "/" . get_value($c, 'ExternalNetmask'); + } + my $out = $c->l('rvw_EXTERNAL_IP_ADDRESS_SUBNET_MASK') . ':' . $ip; + + if ($static) { + $out .= $c->l('rvw_GATEWAY') . ':' . get_value($c, 'GatewayIP'); + } + return $out; + } ## end if (get_value($c, 'SystemMode'...)) +} ## end sub print2_gateway_stanza + =head2 print2_serveronly_stanza If this system is a standalone server with net access, show the external @@ -202,14 +187,15 @@ gateway IP (mojo ver) =cut sub print2_serveronly_stanza { - my $c = shift; - if ( (get_value($c,'SystemMode') eq 'serveronly') && - get_value($c,'AccessType') && - (get_value($c,'AccessType') ne "off")) { - return ( get_value($c,'GatewayIP') ); - } - -} + my $c = shift; + + if ( (get_value($c, 'SystemMode') eq 'serveronly') + && get_value($c, 'AccessType') + && (get_value($c, 'AccessType') ne "off")) + { + return (get_value($c, 'GatewayIP')); + } ## end if ((get_value($c, 'SystemMode'...))) +} ## end sub print2_serveronly_stanza =head2 print2_dhcp_stanza @@ -220,16 +206,14 @@ Prints out the current state of dhcp service (mojo ver) sub print2_dhcp_stanza { my $c = shift; - my $out = (get_prop($c,'dhcpd','status') || 'disabled' ); + my $out = (get_prop($c, 'dhcpd', 'status') || 'disabled'); - if (get_prop($c,'dhcpd', 'status') eq 'enabled') { - $out .= '
    '.$c->l('rvw_BEGINNING_OF_DHCP_ADDRESS_RANGE').':'; - $out .= (get_prop($c,'dhcpd','start') || '' ).'
    '; - $out .= $c->l('rvw_END_OF_DHCP_ADDRESS_RANGE').':'; - $out .= (get_prop($c,'dhcpd','end') || '' ); - } + if (get_prop($c, 'dhcpd', 'status') eq 'enabled') { + $out .= '
    ' . $c->l('rvw_BEGINNING_OF_DHCP_ADDRESS_RANGE') . ':'; + $out .= (get_prop($c, 'dhcpd', 'start') || '') . '
    '; + $out .= $c->l('rvw_END_OF_DHCP_ADDRESS_RANGE') . ':'; + $out .= (get_prop($c, 'dhcpd', 'end') || ''); + } ## end if (get_prop($c, 'dhcpd'...)) return $out; -} - - +} ## end sub print2_dhcp_stanza 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Roundcubepanel.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Roundcubepanel.pm index b6d5550..9d3cba3 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Roundcubepanel.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Roundcubepanel.pm @@ -10,37 +10,27 @@ package SrvMngr::Controller::Roundcubepanel; # # routes : end #---------------------------------------------------------------------- - use strict; use warnings; - use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session); #use SrvMngr::Model::Main; - - sub main { - my $c = shift; $c->app->log->info($c->log_req); - - my $title = $c->l('Roundcube Webmail'); - my $roundcube_url = $c->param('url'); + my $title = $c->l('Roundcube Webmail'); + my $roundcube_url = $c->param('url'); my $roundcube_height = $c->param('height') | 600; - $c->stash( title => $title, modul => $roundcube_url, height => $roundcube_height ); + $c->stash(title => $title, modul => $roundcube_url, height => $roundcube_height); $c->render(template => 'roundcube'); - -} +} ## end sub main sub getroundcubeurl { - my $c = shift; - my $url = shift; - return "/smanager/roundcube?url=$url"; -} - - + my $c = shift; + my $url = shift; + return "/smanager/roundcube?url=$url"; +} ## end sub getroundcubeurl 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Support.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Support.pm index 4fad51c..0f73805 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Support.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Support.pm @@ -11,34 +11,25 @@ package SrvMngr::Controller::Support; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use SrvMngr qw(theme_list init_session); - use esmith::util; - sub display_licenses { + my $lang = shift; + my $lic = ''; - my $lang = shift; - - my $lic = ''; - foreach my $license (esmith::util::getLicenses($lang)) { - - $lic .= $license . '
    '; - } - return $lic; -} + foreach my $license (esmith::util::getLicenses($lang)) { + $lic .= $license . '
    '; + } + return $lic; +} ## end sub display_licenses sub main { my $c = shift; $c->app->log->info($c->log_req); - my $title = $c->l('support_FORM_TITLE'); my $modul = $c->render_to_string(inline => display_licenses($c->session->{lang})); - - $c->stash( title => $title, modul => $modul ); + $c->stash(title => $title, modul => $modul); $c->render(template => 'module'); -}; - - +} ## end sub main 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Swttheme.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Swttheme.pm index 2b039a5..5b59755 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Swttheme.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Swttheme.pm @@ -1,51 +1,39 @@ package SrvMngr::Controller::Swttheme; - # # routes : end #---------------------------------------------------------------------- use strict; use warnings; - use Mojo::Base 'Mojolicious::Controller'; #use SrvMngr qw(theme_list init_session); - our $db = esmith::ConfigDB->open() || die "Couldn't open config db"; sub main { - - my $c = shift; - - my $from = $c->param('From') || '/'; + my $c = shift; + my $from = $c->param('From') || '/'; my $theme = $c->param('Theme'); - $c->app->log->info(" swt theme '$from' '$theme' "); - my $oldTheme = $c->session->{CurrentTheme}; - if ( $theme ne $oldTheme ) { -# $c->app->renderer->paths([$c->app->home->rel_file('themes/default/templates')]); -# $c->app->static->paths([$c->app->home->rel_file('themes/default/public')]); -# if ( $theme ne 'default' ) { -# # Put the new theme first -# my $t_path = $c->app->home->rel_file('themes/'.$theme); -# unshift @{$c->app->renderer->paths}, $t_path.'/templates' if -d $t_path.'/templates'; -# unshift @{$c->app->static->paths}, $t_path.'/public' if -d $t_path.'/public'; -# } + if ($theme ne $oldTheme) { + + # $c->app->renderer->paths([$c->app->home->rel_file('themes/default/templates')]); + # $c->app->static->paths([$c->app->home->rel_file('themes/default/public')]); + # if ( $theme ne 'default' ) { + # # Put the new theme first + # my $t_path = $c->app->home->rel_file('themes/'.$theme); + # unshift @{$c->app->renderer->paths}, $t_path.'/templates' if -d $t_path.'/templates'; + # unshift @{$c->app->static->paths}, $t_path.'/public' if -d $t_path.'/public'; + # } $c->session->{CurrentTheme} = $theme; - - $db->get('smanager')->set_prop('Theme', $theme); - system ("/sbin/e-smith/signal-event smanager-theme-change") == 0 - or warn "$c->l('ERROR_UPDATING')"; - } - + $db->get('smanager')->set_prop('Theme', $theme); + system("/sbin/e-smith/signal-event smanager-theme-change") == 0 + or warn "$c->l('ERROR_UPDATING')"; + } ## end if ($theme ne $oldTheme) ## (not sure) $c->flash( warning => $c->l('swt_LOGIN_AGAIN') ); - $from = '/initial' if $from eq '/'; - $from = '/' . $from if ( $from !~ m|^\/| ); - - $c->redirect_to( $from); - -} - - + $from = '/initial' if $from eq '/'; + $from = '/' . $from if ($from !~ m|^\/|); + $c->redirect_to($from); +} ## end sub main 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Useraccounts.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Useraccounts.pm index 5d661ce..968c335 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Useraccounts.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Useraccounts.pm @@ -11,15 +11,13 @@ package SrvMngr::Controller::Useraccounts; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; -use SrvMngr qw(theme_list init_session - is_normal_password email_simple); +use SrvMngr qw(theme_list init_session + is_normal_password email_simple); #use esmith::FormMagick qw( validate_password ); #use CGI::FormMagick::Validator qw( call_fm_validation ); - use esmith::AccountsDB; use esmith::ConfigDB; use esmith::util; @@ -29,415 +27,369 @@ use esmith::util; #use File::Basename; #use Exporter; #use Carp qw(verbose); - #use esmith::FormMagick::Panel::useraccounts; - our $adb = esmith::AccountsDB->open || die "Couldn't open accounts db"; our $cdb = esmith::ConfigDB->open() || die "Couldn't open config db"; sub main { - my $c = shift; $c->app->log->info($c->log_req); - - my $notif = ''; + my $notif = ''; my %usr_datas = (); - my $title = $c->l('usr_FORM_TITLE'); - + my $title = $c->l('usr_FORM_TITLE'); $usr_datas{'trt'} = 'LIST'; - my @users = $adb->get('admin'); push @users, $adb->users(); - - $c->stash( title => $title, notif => $notif, usr_datas => \%usr_datas, users => \@users ); + $c->stash(title => $title, notif => $notif, usr_datas => \%usr_datas, users => \@users); $c->render(template => 'useraccounts'); - -}; - +} ## end sub main sub do_display { - - my $c = shift; - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'ADD'); - my $user = ($c->param('user') || ''); - + my $c = shift; + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'ADD'); + my $user = ($c->param('user') || ''); my %usr_datas = (); - my $title = $c->l('usr_FORM_TITLE'); + my $title = $c->l('usr_FORM_TITLE'); my ($notif, $modul) = ''; - $usr_datas{'trt'} = $trt; - if ( $trt eq 'ADD' ) { + if ($trt eq 'ADD') { + $usr_datas{user} = ''; + $usr_datas{firstname} = ''; + $usr_datas{lastname} = ''; + $usr_datas{dept} = $c->get_ldap_value('Dept'); + $usr_datas{company} = $c->get_ldap_value('Company'); + $usr_datas{street} = $c->get_ldap_value('Street'); + $usr_datas{city} = $c->get_ldap_value('City'); + $usr_datas{phone} = $c->get_ldap_value('Phone'); + } ## end if ($trt eq 'ADD') - $usr_datas{user} = ''; - $usr_datas{firstname} = ''; - $usr_datas{lastname} = ''; - $usr_datas{dept} = $c->get_ldap_value('Dept'); - $usr_datas{company} = $c->get_ldap_value('Company'); - $usr_datas{street} = $c->get_ldap_value('Street'); - $usr_datas{city} = $c->get_ldap_value('City'); - $usr_datas{phone} = $c->get_ldap_value('Phone'); + if ($trt eq 'UPD' or $trt eq 'UPS') { + my $rec = $adb->get($user); + my $type = ($trt eq 'UPS') ? 'system' : 'user'; + + if ($rec and $rec->prop('type') eq $type) { + $usr_datas{user} = $user; + $usr_datas{firstname} = $rec->prop('FirstName'); + $usr_datas{lastname} = $rec->prop('LastName'); + $usr_datas{vpnclientaccess} = $rec->prop('VPNClientAccess'); + $usr_datas{emailforward} = $rec->prop('EmailForward'); + $usr_datas{forwardaddress} = $rec->prop('ForwardAddress'); + + if ($trt eq 'UPD') { + $usr_datas{dept} = $rec->prop('Dept'); + $usr_datas{company} = $rec->prop('Company'); + $usr_datas{street} = $rec->prop('Street'); + $usr_datas{city} = $rec->prop('City'); + $usr_datas{phone} = $rec->prop('Phone'); + } ## end if ($trt eq 'UPD') + } ## end if ($rec and $rec->prop...) + } ## end if ($trt eq 'UPD' or $trt...) + + if ($trt eq 'DEL') { + my $rec = $adb->get($user); + + if ($rec and $rec->prop('type') eq 'user') { + $usr_datas{user} = $user; + $usr_datas{name} = $c->get_user_name($user); } + } ## end if ($trt eq 'DEL') - if ( $trt eq 'UPD' or $trt eq 'UPS' ) { + if ($trt eq 'PWD' or $trt eq 'PWS') { + my $rec = $adb->get($user); + my $type = ($trt eq 'PWS') ? 'system' : 'user'; - my $rec = $adb->get($user); - my $type = ( $trt eq 'UPS' ) ? 'system' : 'user'; - if ($rec and $rec->prop('type') eq $type) { - $usr_datas{user} = $user; - $usr_datas{firstname} = $rec->prop('FirstName'); - $usr_datas{lastname} = $rec->prop('LastName'); - $usr_datas{vpnclientaccess} = $rec->prop('VPNClientAccess'); - $usr_datas{emailforward} = $rec->prop('EmailForward'); - $usr_datas{forwardaddress} = $rec->prop('ForwardAddress'); - if ( $trt eq 'UPD' ) { - $usr_datas{dept} = $rec->prop('Dept'); - $usr_datas{company} = $rec->prop('Company'); - $usr_datas{street} = $rec->prop('Street'); - $usr_datas{city} = $rec->prop('City'); - $usr_datas{phone} = $rec->prop('Phone'); - } - } + if ($rec and $rec->prop('type') eq $type) { + $usr_datas{user} = $user; + $usr_datas{name} = $c->get_user_name($user); } + } ## end if ($trt eq 'PWD' or $trt...) - if ( $trt eq 'DEL' ) { - - my $rec = $adb->get($user); - if ($rec and $rec->prop('type') eq 'user') { - $usr_datas{user} = $user; - $usr_datas{name} = $c->get_user_name($user); - } + if ($trt eq 'LCK') { + my $rec = $adb->get($user); + if ($rec and $rec->prop('type') eq 'user') { + $usr_datas{user} = $user; + $usr_datas{name} = $c->get_user_name($user); } + } ## end if ($trt eq 'LCK') - if ( $trt eq 'PWD' or $trt eq 'PWS' ) { - - my $rec = $adb->get($user); - my $type = ( $trt eq 'PWS' ) ? 'system' : 'user'; - if ($rec and $rec->prop('type') eq $type) { - $usr_datas{user} = $user; - $usr_datas{name} = $c->get_user_name($user); - } + if ($trt eq 'LIST') { + my @useraccounts; + if ($adb) { + @useraccounts = $adb->useraccounts(); } - - if ( $trt eq 'LCK' ) { - - my $rec = $adb->get($user); - if ($rec and $rec->prop('type') eq 'user') { - $usr_datas{user} = $user; - $usr_datas{name} = $c->get_user_name($user); - } - - } - - if ( $trt eq 'LIST' ) { - my @useraccounts; - if ($adb) - { - @useraccounts = $adb->useraccounts(); - } - $c->stash( useraccounts => \@useraccounts ); - - } - - $c->stash( title => $title, notif => $notif, usr_datas => \%usr_datas ); - $c->render( template => 'useraccounts' ); - -}; - + $c->stash(useraccounts => \@useraccounts); + } ## end if ($trt eq 'LIST') + $c->stash(title => $title, notif => $notif, usr_datas => \%usr_datas); + $c->render(template => 'useraccounts'); +} ## end sub do_display sub do_update { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'LIST'); - my $user = ($c->param('user') || ''); - my $name = ($c->param('name') || ''); - + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'LIST'); + my $user = ($c->param('user') || ''); + my $name = ($c->param('name') || ''); my %usr_datas = (); $usr_datas{trt} = $trt; - my $title = $c->l('usr_FORM_TITLE'); - - my ($res, $result) = ''; + if ($trt eq 'ADD') { - if ( $trt eq 'ADD' ) { - - # controls - - my $first = $c->param('FirstName'); - my $last = $c->param('LastName'); - my $mail = $c->param('ForwardAddress'); - - unless ( $first ) { - $result .= $c->l('FM_NONBLANK') . ' - '; - } - unless ( $last ) { - $result .= $c->l('FM_NONBLANK') . ' - '; - } - #unless ( $mail ) { - # $result .= $c->l('FM_NONBLANK') . ' - '; - #} - - $res = $c->validate_acctName( $user ); - $result .= $res unless $res eq 'OK'; - - $res = $c->validate_acctName_length( $user ); - $result .= $res unless $res eq 'OK'; - - $res = $c->validate_acctName_conflict( $user ); - $result .= $res unless $res eq 'OK'; - - $res = $c->pseudonym_clash( $first ); - $result .= $res unless $res eq 'OK'; - - if ( $mail ) { - $res = $c->emailforward( $mail ); - $result .= $res unless $res eq 'OK'; - } - - #$result .= 'Blocked for testing'; - - if ( ! $result ) { - $res = create_user( $c, $user ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('usrUSER_CREATED') . ' ' . $user; - $usr_datas{trt} = 'SUC'; - } - } - } - - - if ( $trt eq 'UPD' or $trt eq 'UPS') { - - # controls - - my $first = $c->param('FirstName'); - my $last = $c->param('LastName'); + # controls + my $first = $c->param('FirstName'); + my $last = $c->param('LastName'); my $mail = $c->param('ForwardAddress'); - unless ( $first ) { + unless ($first) { $result .= $c->l('FM_NONBLANK') . ' - '; - } - unless ( $last ) { + } + + unless ($last) { $result .= $c->l('FM_NONBLANK') . ' - '; - } + } #unless ( $mail ) { # $result .= $c->l('FM_NONBLANK') . ' - '; - #} + #} + $res = $c->validate_acctName($user); + $result .= $res unless $res eq 'OK'; + $res = $c->validate_acctName_length($user); + $result .= $res unless $res eq 'OK'; + $res = $c->validate_acctName_conflict($user); + $result .= $res unless $res eq 'OK'; + $res = $c->pseudonym_clash($first); + $result .= $res unless $res eq 'OK'; - $res = $c->pseudonym_clash( $first ); - $result .= $res unless $res eq 'OK'; + if ($mail) { + $res = $c->emailforward($mail); + $result .= $res unless $res eq 'OK'; + } - if ( $mail ) { - $res = $c->emailforward( $mail ); - $result .= $res unless $res eq 'OK'; - } + #$result .= 'Blocked for testing'; + if (!$result) { + $res = create_user($c, $user); + $result .= $res unless $res eq 'OK'; + if (!$result) { + $result = $c->l('usrUSER_CREATED') . ' ' . $user; + $usr_datas{trt} = 'SUC'; + } + } ## end if (!$result) + } ## end if ($trt eq 'ADD') - - #$result .= 'Blocked for testing'; + if ($trt eq 'UPD' or $trt eq 'UPS') { - if ( ! $result ) { - if ( $trt eq 'UPS' ) { - $res = $c->modify_admin(); - } else { - $res = $c->modify_user( $user ); - } - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('usr_USER_MODIFIED') . ' ' . $user; - $usr_datas{trt} = 'SUC'; - } - } - } + # controls + my $first = $c->param('FirstName'); + my $last = $c->param('LastName'); + my $mail = $c->param('ForwardAddress'); + unless ($first) { + $result .= $c->l('FM_NONBLANK') . ' - '; + } - if ( $trt eq 'PWD' ) { + unless ($last) { + $result .= $c->l('FM_NONBLANK') . ' - '; + } + #unless ( $mail ) { + # $result .= $c->l('FM_NONBLANK') . ' - '; + #} + $res = $c->pseudonym_clash($first); + $result .= $res unless $res eq 'OK'; + + if ($mail) { + $res = $c->emailforward($mail); + $result .= $res unless $res eq 'OK'; + } + + #$result .= 'Blocked for testing'; + if (!$result) { + + if ($trt eq 'UPS') { + $res = $c->modify_admin(); + } else { + $res = $c->modify_user($user); + } + $result .= $res unless $res eq 'OK'; + + if (!$result) { + $result = $c->l('usr_USER_MODIFIED') . ' ' . $user; + $usr_datas{trt} = 'SUC'; + } + } ## end if (!$result) + } ## end if ($trt eq 'UPD' or $trt...) + + if ($trt eq 'PWD') { my $pass1 = $c->param('newPass'); my $pass2 = $c->param('newPassVerify'); - # controls + # controls unless ($pass1) { $result .= $c->l('FM_NONBLANK') . ' - '; - } + } + unless ($pass1 eq $pass2) { $result .= $c->l('PASSWORD_VERIFY_ERROR') . ' - '; - } + } - if ( ! $result ) { - $res = check_password( $c, $pass1 ); - $result .= $res unless $res eq 'OK'; - } + if (!$result) { + $res = check_password($c, $pass1); + $result .= $res unless $res eq 'OK'; + } - if ( $user eq 'admin' ) { - $result .= "System password should not be reset here !"; - } - #$result .= 'Blocked for testing'; - - if ( ! $result ) { - my $res = $c->reset_password( $user, $pass1 ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('usr_PASSWORD_CHANGE_SUCCEEDED', $user); - $usr_datas{trt} = 'SUC'; - } - } - } + if ($user eq 'admin') { + $result .= "System password should not be reset here !"; + } - if ( $trt eq 'PWS' ) { # system password reset (admin) + #$result .= 'Blocked for testing'; + if (!$result) { + my $res = $c->reset_password($user, $pass1); + $result .= $res unless $res eq 'OK'; + if (!$result) { + $result = $c->l('usr_PASSWORD_CHANGE_SUCCEEDED', $user); + $usr_datas{trt} = 'SUC'; + } + } ## end if (!$result) + } ## end if ($trt eq 'PWD') + + if ($trt eq 'PWS') { # system password reset (admin) my $curpass = $c->param('CurPass'); - my $pass1 = $c->param('Pass'); - my $pass2 = $c->param('PassVerify'); + my $pass1 = $c->param('Pass'); + my $pass2 = $c->param('PassVerify'); - # controls + # controls if ($curpass) { - $res = $c->system_authenticate_password( $curpass ); - $result .= $res unless $res eq 'OK'; - } else { + $res = $c->system_authenticate_password($curpass); + $result .= $res unless $res eq 'OK'; + } else { $result .= $c->l('FM_NONBLANK') . ' - '; - } + } unless ($pass1 and $pass2) { $result .= $c->l('FM_NONBLANK') . ' - '; - } + } unless ($pass1 eq $pass2) { $result .= $c->l('usr_SYSTEM_PASSWORD_VERIFY_ERROR') . ' - '; - } + } - if ( ! $result ) { - $res = $c->system_validate_password( $pass1 ); - $result .= $res unless $res eq 'OK'; + if (!$result) { + $res = $c->system_validate_password($pass1); + $result .= $res unless $res eq 'OK'; + $res = $c->system_check_password($pass1); + $result .= $res unless $res eq 'OK'; + } ## end if (!$result) - $res = $c->system_check_password( $pass1 ); - $result .= $res unless $res eq 'OK'; - } + #$result .= 'Blocked for testing'; + if (!$result) { + my $res = $c->system_change_password(); + $result .= $res unless $res eq 'OK'; - #$result .= 'Blocked for testing'; - - if ( ! $result ) { - my $res = $c->system_change_password(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('usr_SYSTEM_PASSWORD_CHANGED', $user); - $usr_datas{trt} = 'SUC'; - } - } - } + if (!$result) { + $result = $c->l('usr_SYSTEM_PASSWORD_CHANGED', $user); + $usr_datas{trt} = 'SUC'; + } + } ## end if (!$result) + } ## end if ($trt eq 'PWS') + if ($trt eq 'LCK') { - if ( $trt eq 'LCK' ) { + # controls + #$res = xxxxxxxxxxx(); + #$result .= $res unless $res eq 'OK'; + #$result .= 'Blocked for testing'; + if (!$result) { + my $res = $c->lock_account($user); + $result .= $res unless $res eq 'OK'; - # controls + if (!$result) { + $result = $c->l('usr_LOCKED_ACCOUNT', $user); + $usr_datas{trt} = 'SUC'; + } + } ## end if (!$result) + } ## end if ($trt eq 'LCK') - #$res = xxxxxxxxxxx(); - #$result .= $res unless $res eq 'OK'; - - #$result .= 'Blocked for testing'; + if ($trt eq 'DEL') { - if ( ! $result ) { - my $res = $c->lock_account( $user ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('usr_LOCKED_ACCOUNT', $user); - $usr_datas{trt} = 'SUC'; - } - } - } - - if ( $trt eq 'DEL' ) { - - # controls - - #$res = xxxxxxxxxxx(); - #$result .= $res unless $res eq 'OK'; - - #$result .= 'Blocked for testing'; - - if ( ! $result ) { - my $res = $c->remove_account( $user ); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('usr_SUCCESSFULLY_DELETED_USER') . ' ' . $user; - $usr_datas{trt} = 'SUC'; - } - } - } + # controls + #$res = xxxxxxxxxxx(); + #$result .= $res unless $res eq 'OK'; + #$result .= 'Blocked for testing'; + if (!$result) { + my $res = $c->remove_account($user); + $result .= $res unless $res eq 'OK'; + if (!$result) { + $result = $c->l('usr_SUCCESSFULLY_DELETED_USER') . ' ' . $user; + $usr_datas{trt} = 'SUC'; + } + } ## end if (!$result) + } ## end if ($trt eq 'DEL') $usr_datas{'user'} = $user; $usr_datas{'name'} = $name; + $c->stash(title => $title, notif => $result, usr_datas => \%usr_datas); - $c->stash( title => $title, notif => $result, usr_datas => \%usr_datas ); if ($usr_datas{trt} ne 'SUC') { - return $c->render(template => 'useraccounts'); + return $c->render(template => 'useraccounts'); } $c->redirect_to('/useraccounts'); - -}; - +} ## end sub do_update sub lock_account { - my $c = shift; - + my $c = shift; my $user = $c->param('user'); my $acct = $adb->get($user); + if ($acct->prop('type') eq "user") { undef $adb; - # Untaint the username before use in system() - $user =~ /^(\w[\-\w_\.]*)$/; - $user = $1; + # Untaint the username before use in system() + $user =~ /^(\w[\-\w_\.]*)$/; + $user = $1; + if (system("/sbin/e-smith/signal-event", "user-lock", $user)) { $adb = esmith::AccountsDB->open(); return $c->l("usr_ERR_OCCURRED_LOCKING"); } $adb = esmith::AccountsDB->open(); - return 'OK'; + return 'OK'; } else { return $c->l('NO_SUCH_USER', $user); } -} - +} ## end sub lock_account sub remove_account { - my ($c) = @_; + my ($c) = @_; my $user = $c->param('user'); - my $acct = $adb->get($user); + if ($acct->prop('type') eq 'user') { $acct->set_prop('type', 'user-deleted'); - undef $adb; - # Untaint the username before use in system() - $user =~ /^(\w[\-\w_\.]*)$/; - $user = $1; - if (system ("/sbin/e-smith/signal-event", "user-delete", $user)) - { + # Untaint the username before use in system() + $user =~ /^(\w[\-\w_\.]*)$/; + $user = $1; + + if (system("/sbin/e-smith/signal-event", "user-delete", $user)) { $adb = esmith::AccountsDB->open(); return $c->l("ERR_OCCURRED_DELETING"); } - $adb = esmith::AccountsDB->open(); $adb->get($user)->delete; - return 'OK'; + return 'OK'; } else { return $c->l('NO_SUCH_USER', $user); } -} - +} ## end sub remove_account sub reset_password { my ($c, $user, $passw1) = @_; @@ -446,87 +398,70 @@ sub reset_password { return $c->l('usr_TAINTED_USER'); } $user = $1; - my $acct = $adb->get($user); - if ( $acct->prop('type') eq "user") { - esmith::util::setUserPassword ($user, $passw1); - + if ($acct->prop('type') eq "user") { + esmith::util::setUserPassword($user, $passw1); $acct->set_prop("PasswordSet", "yes"); undef $adb; - if (system("/sbin/e-smith/signal-event", "password-modify", $user)) - { + if (system("/sbin/e-smith/signal-event", "password-modify", $user)) { $adb = esmith::AccountsDB->open(); return $c->l("usr_ERR_OCCURRED_MODIFYING_PASSWORD"); } $adb = esmith::AccountsDB->open(); - return 'OK'; } else { return $c->l('NO_SUCH_USER', $user); } -} - - +} ## end sub reset_password sub check_password { - my $c = shift; + my $c = shift; my $pass1 = shift; - my $check_type; my $rec = $cdb->get('passwordstrength'); $check_type = ($rec ? ($rec->prop('Users') || 'none') : 'none'); - return validate_password($c, $check_type, $pass1); -} - +} ## end sub check_password sub validate_password { my ($c, $strength, $pass) = @_; - use Crypt::Cracklib; - my $reason; if ($strength eq "none") { return $c->l("Passwords must be at least 7 characters long") unless (length($pass) > 6); return "OK"; } - $reason = is_normal_password($c, $pass, undef); - return $reason unless ($reason eq "OK"); return "OK" unless ($strength eq "strong"); - if ( -f '/usr/lib64/cracklib_dict.pwd' ) { + if (-f '/usr/lib64/cracklib_dict.pwd') { $reason = fascist_check($pass, '/usr/lib64/cracklib_dict'); } else { $reason = fascist_check($pass, '/usr/lib/cracklib_dict'); } $reason ||= "Software error: password check failed"; - return "OK" if ($reason eq "ok"); - - return $c->l("Bad Password Choice") . ": " - . $c->l("The password you have chosen is not a good choice, because") - . " " . $c->($reason) . "."; -} - + return + $c->l("Bad Password Choice") . ": " + . $c->l("The password you have chosen is not a good choice, because") . " " + . $c->($reason) . "."; +} ## end sub validate_password sub emailForward_list { my $c = shift; - - return [[ $c->l('usr_DELIVER_EMAIL_LOCALLY') => 'local'], - [ $c->l('usr_FORWARD_EMAIL') => 'forward'], - [ $c->l('usr_DELIVER_AND_FORWARD') => 'both']]; -} - + return [ + [ $c->l('usr_DELIVER_EMAIL_LOCALLY') => 'local' ], + [ $c->l('usr_FORWARD_EMAIL') => 'forward' ], + [ $c->l('usr_DELIVER_AND_FORWARD') => 'both' ] + ]; +} ## end sub emailForward_list sub max_user_name_length { - my ($c, $data) = @_; - $cdb->reload(); my $max = $cdb->get('maxuserNameLength')->value; @@ -535,40 +470,33 @@ sub max_user_name_length { } else { return $c->l('usr_MAX_user_NAME_LENGTH_ERROR', $data, $max, $max); } -} - +} ## end sub max_user_name_length sub validate_acctName { - my ($c, $acctName) = @_; unless ($adb->validate_account_name($acctName)) { return $c->l('usr_ACCT_NAME_HAS_INVALID_CHARS', $acctName); } return "OK"; -} +} ## end sub validate_acctName sub validate_acctName_length { + my $c = shift; + my $acctName = shift; + my $maxAcctNameLength = ($cdb->get('maxAcctNameLength') ? $cdb->get('maxAcctNameLength')->prop('type') : "") || 12; - my $c = shift; - my $acctName = shift; - - my $maxAcctNameLength = ($cdb->get('maxAcctNameLength') - ? $cdb->get('maxAcctNameLength')->prop('type') : "") || 12; - - if ( length $acctName > $maxAcctNameLength ) { + if (length $acctName > $maxAcctNameLength) { return $c->l('usr_ACCOUNT_TOO_LONG', $maxAcctNameLength); } else { return ('OK'); } -} +} ## end sub validate_acctName_length sub validate_acctName_conflict { - my $c = shift; my $acctName = shift; - - my $account = $adb->get($acctName); + my $account = $adb->get($acctName); my $type; if (defined $account) { @@ -576,26 +504,17 @@ sub validate_acctName_conflict { } elsif (defined getpwnam($acctName) || defined getgrnam($acctName)) { $type = "system"; } else { - return('OK'); + return ('OK'); } return $c->l('usr_ACCOUNT_CONFLICT', $acctName, $type); - -} - - +} ## end sub validate_acctName_conflict sub get_user_name { - my ($c, $acctName) = @_; - my $usr = $adb->get($acctName); - return '' unless $usr; - - return $usr->prop('FirstName') ." ". $usr->prop('LastName'); - -} - + return $usr->prop('FirstName') . " " . $usr->prop('LastName'); +} ## end sub get_user_name sub get_ldap_value { my ($c, $field) = @_; @@ -604,7 +523,6 @@ sub get_ldap_value { if ($c->param('user')) { return $c->param($field); } - my %CGIParam2DBfield = ( Dept => 'defaultDepartment', Company => 'defaultCompany', @@ -612,54 +530,47 @@ sub get_ldap_value { City => 'defaultCity', Phone => 'defaultPhoneNumber' ); - return $cdb->get('ldap')->prop($CGIParam2DBfield{$field}); -} +} ## end sub get_ldap_value sub get_pptp_value { return $cdb->get('pptpd')->prop('AccessDefault') || 'no'; } - sub pseudonym_clash { my ($c, $first) = @_; $first ||= ""; my $last = $c->param('LastName') || ""; - my $acctName = $c->param('user') || ""; - - my $up = "$first $last"; - - $up =~ s/^\s+//; - $up =~ s/\s+$//; - $up =~ s/\s+/ /g; - $up =~ s/\s/_/g; - - my $dp = $up; + my $acctName = $c->param('user') || ""; + my $up = "$first $last"; + $up =~ s/^\s+//; + $up =~ s/\s+$//; + $up =~ s/\s+/ /g; + $up =~ s/\s/_/g; + my $dp = $up; $dp =~ s/_/./g; - $dp = $adb->get($dp); $up = $adb->get($up); - my $da = $dp->prop('Account') if $dp; my $ua = $up->prop('Account') if $up; + if ($dp and $da and $da ne $acctName) { - return $c->l('usr_PSEUDONYM_CLASH', - $acctName, $da, $dp->key); + return $c->l('usr_PSEUDONYM_CLASH', $acctName, $da, $dp->key); } elsif ($up and $ua and $ua ne $acctName) { - return $c->l('usr_PSEUDONYM_CLASH', - $acctName, $ua, $up->key ); + return $c->l('usr_PSEUDONYM_CLASH', $acctName, $ua, $up->key); } else { return "OK"; } -} - +} ## end sub pseudonym_clash sub emailforward { my ($c, $data) = @_; my $response = $c->email_simple($data); + if ($response eq "OK") { return "OK"; } elsif ($data eq "") { + # Blank is ok, only if we're not forwarding, which means that the # EmailForward param must be set to 'local'. my $email_forward = $c->param('EmailForward') || ''; @@ -668,91 +579,75 @@ sub emailforward { return $c->l('usr_CANNOT_CONTAIN_WHITESPACE'); } else { return $c->l('usr_CANNOT_CONTAIN_WHITESPACE') - if ( $data =~ /\s+/ ); + if ($data =~ /\s+/); + # Permit a local address. return "OK" if $data =~ /^[a-zA-Z][a-zA-Z0-9\._\-]*$/; return $c->l('usr_UNACCEPTABLE_CHARS'); - } -} - + } ## end else [ if ($response eq "OK")] +} ## end sub emailforward sub get_groups { my ($c) = shift; - my @groups = $adb->groups(); return \@groups; -} - +} ## end sub get_groups sub ipsec_for_acct { - my $c = shift; # Don't show ipsecrw setting unless the status property exists - return '' unless ($cdb->get('ipsec') + return '' unless ($cdb->get('ipsec') && $cdb->get('ipsec')->prop('RoadWarriorStatus')); # Don't show ipsecrw setting unless /sbin/e-smith/roadwarrior exists return '' unless -x '/sbin/e-smith/roadwarrior'; - my $user = $c->param('user'); return '' unless $user; - my $rec = $adb->get($user); - if ( $rec ) { - my $pwset = $rec->prop('PasswordSet') || 'no'; - my $VPNaccess = $rec->prop('VPNClientAccess') || 'no'; - if ($pwset eq 'yes' and $VPNaccess eq 'yes') { - return 'OK'; - } - } - return ''; -} + if ($rec) { + my $pwset = $rec->prop('PasswordSet') || 'no'; + my $VPNaccess = $rec->prop('VPNClientAccess') || 'no'; + + if ($pwset eq 'yes' and $VPNaccess eq 'yes') { + return 'OK'; + } + } ## end if ($rec) + return ''; +} ## end sub ipsec_for_acct sub is_user_in_group { - - my $c = shift; - my $user = shift || ''; + my $c = shift; + my $user = shift || ''; my $group = shift || ''; - - return '' unless ( $user and $group ); - - return ( $adb->is_user_in_group($user, $group) ) ? 'OK' : ''; - -} - + return '' unless ($user and $group); + return ($adb->is_user_in_group($user, $group)) ? 'OK' : ''; +} ## end sub is_user_in_group sub get_ipsec_client_cert { - my $c = shift; + my $c = shift; my $user = $c->param('user'); ($user) = ($user =~ /^(.*)$/); - die "Invalid user: $user\n" unless getpwnam($user); - - open (KID, "/sbin/e-smith/roadwarrior get_client_cert $user |") + open(KID, "/sbin/e-smith/roadwarrior get_client_cert $user |") or die "Can't fork: $!"; my $certfile = ; close KID; - require File::Basename; my $certname = File::Basename::basename($certfile); - print "Expires: 0\n"; print "Content-type: application/x-pkcs12\n"; print "Content-disposition: inline; filename=$certname\n"; print "\n"; + open(CERT, "<$certfile"); - open (CERT, "<$certfile"); - while () - { + while () { print; } close CERT; - return ''; -} - +} ## end sub get_ipsec_client_cert sub modify_user { my ($c) = @_; @@ -761,193 +656,159 @@ sub modify_user { unless (($acctName) = ($acctName =~ /^(\w[\-\w_\.]*)$/)) { return $c->l('usr_TAINTED_USER', $acctName); } + # Untaint the username before use in system() $acctName = $1; - - my $acct = $adb->get($acctName); + my $acct = $adb->get($acctName); my $acctType = $acct->prop('type'); - if ($acctType eq "user") - { + if ($acctType eq "user") { $adb->remove_user_auto_pseudonyms($acctName); my %newProperties = ( - 'FirstName' => $c->param('FirstName'), - 'LastName' => $c->param('LastName'), - 'Phone' => $c->param('Phone'), - 'Company' => $c->param('Company'), - 'Dept' => $c->param('Dept'), - 'City' => $c->param('City'), - 'Street' => $c->param('Street'), - 'EmailForward' => $c->param('EmailForward'), - 'ForwardAddress' => $c->param('ForwardAddress'), - 'VPNClientAccess'=> $c->param('VPNClientAccess'), + 'FirstName' => $c->param('FirstName'), + 'LastName' => $c->param('LastName'), + 'Phone' => $c->param('Phone'), + 'Company' => $c->param('Company'), + 'Dept' => $c->param('Dept'), + 'City' => $c->param('City'), + 'Street' => $c->param('Street'), + 'EmailForward' => $c->param('EmailForward'), + 'ForwardAddress' => $c->param('ForwardAddress'), + 'VPNClientAccess' => $c->param('VPNClientAccess'), ); - $acct->merge_props(%newProperties); - $adb->create_user_auto_pseudonyms($acctName) - if ( ($cdb->get_prop('pseudonyms','create') || 'enabled') eq 'enabled' ); - + if (($cdb->get_prop('pseudonyms', 'create') || 'enabled') eq 'enabled'); my @old_groups = $adb->user_group_list($acctName); - my @new_groups = @{$c->every_param("groupMemberships")}; - -# $c->app->log->info($c->dumper("groups: Old " . @old_groups .' New '. @new_groups)); + my @new_groups = @{ $c->every_param("groupMemberships") }; + # $c->app->log->info($c->dumper("groups: Old " . @old_groups .' New '. @new_groups)); $adb->remove_user_from_groups($acctName, @old_groups); $adb->add_user_to_groups($acctName, @new_groups); - undef $adb; - unless (system ("/sbin/e-smith/signal-event", "user-modify", - $acctName) == 0) { + unless (system("/sbin/e-smith/signal-event", "user-modify", $acctName) == 0) { $adb = esmith::AccountsDB->open(); return $c->l('usr_CANNOT_MODIFY_USER'); } $adb = esmith::AccountsDB->open(); - } + } ## end if ($acctType eq "user") return 'OK'; -} - +} ## end sub modify_user sub create_user { - - my $c = shift; - + my $c = shift; my $acctName = $c->param('user'); my %userprops; - foreach my $field ( qw( FirstName LastName Phone Company Dept - City Street EmailForward ForwardAddress VPNClientAccess) ) + foreach my $field ( + qw( FirstName LastName Phone Company Dept + City Street EmailForward ForwardAddress VPNClientAccess) + ) { $userprops{$field} = $c->param($field); - } + } ## end foreach my $field (qw( FirstName LastName Phone Company Dept...)) $userprops{'PasswordSet'} = "no"; $userprops{'type'} = 'user'; - my $acct = $adb->new_record($acctName) or warn "Can't create new account for $acctName (does it already exist?)\n"; $acct->reset_props(%userprops); $adb->create_user_auto_pseudonyms($acctName) - if ( ($cdb->get_prop('pseudonyms','create') || 'enabled') eq 'enabled' ); - my @groups = @{$c->every_param("groupMemberships")}; - + if (($cdb->get_prop('pseudonyms', 'create') || 'enabled') eq 'enabled'); + my @groups = @{ $c->every_param("groupMemberships") }; $adb->add_user_to_groups($acctName, @groups); - undef $adb; # Untaint the username before use in system() $acctName =~ /^(\w[\-\w_\.]*)$/; $acctName = $1; - if (system ("/sbin/e-smith/signal-event", "user-create", $acctName)) - { + if (system("/sbin/e-smith/signal-event", "user-create", $acctName)) { $adb = esmith::AccountsDB->open(); return $c->l("usr_ERR_OCCURRED_CREATING"); } - $adb = esmith::AccountsDB->open(); - $c->set_groups(); return 'OK'; - -} - +} ## end sub create_user sub set_groups { - - my $c = shift; - + my $c = shift; my $acctName = $c->param('user'); - - my @groups = @{$c->every_param("groupMemberships")}; - + my @groups = @{ $c->every_param("groupMemberships") }; $adb->set_user_groups($acctName, @groups); - -} - +} ## end sub set_groups sub modify_admin { - - my ($c) = @_; - - my $acct = $adb->get('admin'); - + my ($c) = @_; + my $acct = $adb->get('admin'); my %newProperties = ( - 'FirstName' => $c->param('FirstName'), - 'LastName' => $c->param('LastName'), - 'EmailForward' => $c->param('EmailForward'), - 'ForwardAddress' => $c->param('ForwardAddress'), - 'VPNClientAccess'=> $c->param('VPNClientAccess'), + 'FirstName' => $c->param('FirstName'), + 'LastName' => $c->param('LastName'), + 'EmailForward' => $c->param('EmailForward'), + 'ForwardAddress' => $c->param('ForwardAddress'), + 'VPNClientAccess' => $c->param('VPNClientAccess'), ); - $acct->merge_props(%newProperties); - undef $adb; - - my $status = - system ("/sbin/e-smith/signal-event", "user-modify-admin", 'admin'); - + my $status = system("/sbin/e-smith/signal-event", "user-modify-admin", 'admin'); $adb = esmith::AccountsDB->open(); if ($status == 0) { return 'OK'; } else { - return$c->l('usr_CANNOT_MODIFY_USER', 'First'); + return $c->l('usr_CANNOT_MODIFY_USER', 'First'); } -} - +} ## end sub modify_admin sub system_validate_password { - - my $c = shift; + my $c = shift; my $pass1 = shift; + # If the password contains one or more printable character if ($pass1 =~ /^([ -~]+)$/) { - return('OK'); + return ('OK'); } else { return $c->l('usr_SYSTEM_PASSWORD_UNPRINTABLES_IN_PASS'); } -} - +} ## end sub system_validate_password sub system_check_password { - - my $c = shift; + my $c = shift; my $pass1 = shift; - use esmith::ConfigDB; my $conf = esmith::ConfigDB->open(); my ($check_type, $rec); + if ($conf) { $rec = $conf->get('passwordstrength'); } $check_type = ($rec ? ($rec->prop('Admin') || 'strong') : 'strong'); - return $c->validate_password($check_type, $pass1); -} - +} ## end sub system_check_password sub system_authenticate_password { - - my $c = shift; + my $c = shift; my $pass = shift; - if (esmith::util::authenticateUnixPassword( ($cdb->get_value("AdminIsNotRoot") eq 'enabled') ? 'admin' : 'root', $pass)) { + if (esmith::util::authenticateUnixPassword( + ($cdb->get_value("AdminIsNotRoot") eq 'enabled') ? 'admin' : 'root', $pass + ) + ) + { return "OK"; } else { return $c->l("usr_SYSTEM_PASSWORD_AUTH_ERROR"); } -} - +} ## end sub system_authenticate_password sub system_change_password { - my ($c) = @_; my $pass = $c->param('Pass'); - - ($cdb->get_value("AdminIsNotRoot") eq 'enabled') ? esmith::util::setUnixPassword('admin',$pass) : esmith::util::setUnixSystemPassword($pass); + ($cdb->get_value("AdminIsNotRoot") eq 'enabled') + ? esmith::util::setUnixPassword('admin', $pass) + : esmith::util::setUnixSystemPassword($pass); esmith::util::setServerSystemPassword($pass); - my $result = system("/sbin/e-smith/signal-event password-modify admin"); if ($result == 0) { @@ -955,7 +816,5 @@ sub system_change_password { } else { return $c->l("Error occurred while modifying password for admin.", 'First'); } -} - - +} ## end sub system_change_password 1 diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Userpassword.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Userpassword.pm index 6b4ffd4..5f1d399 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Userpassword.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Userpassword.pm @@ -8,182 +8,165 @@ package SrvMngr::Controller::Userpassword; # # routes : end #---------------------------------------------------------------------- - use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use esmith::util; use esmith::ConfigDB; use esmith::AccountsDB; - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw( theme_list init_session is_normal_password ); - our $cdb = esmith::ConfigDB->open_ro || die "Couldn't open configuration db"; - sub main { - my $c = shift; - + my $c = shift; my %pwd_datas = (); - if ( $c->is_logged_in ) { - $pwd_datas{Account} = $c->session->{username}; - $pwd_datas{trt} = 'NORM'; + if ($c->is_logged_in) { + $pwd_datas{Account} = $c->session->{username}; + $pwd_datas{trt} = 'NORM'; } else { - my $rt = $c->current_route; - my $mess = ''; - my $jwt = $c->param('jwt') || ''; - my $name = $c->jwt->decode($jwt)->{username} || ''; + my $rt = $c->current_route; + my $mess = ''; + my $jwt = $c->param('jwt') || ''; + my $name = $c->jwt->decode($jwt)->{username} || ''; + $mess = 'Invalid state' unless ($jwt and $name and $rt eq 'upwdreset'); - $mess = 'Invalid state' unless ($jwt and $name and $rt eq 'upwdreset'); - # request already treated or outdated - if ( $c->pwdrst->{$name}{confirmed} != 1 or $c->pwdrst->{$name}{date} < time() ) { - $mess = $c->l('use_INVALID_REQUEST').' -step 1-'; - } + if ($c->pwdrst->{$name}{confirmed} != 1 or $c->pwdrst->{$name}{date} < time()) { + $mess = $c->l('use_INVALID_REQUEST') . ' -step 1-'; + } + + if ($mess) { + $c->stash(error => $mess); + return $c->redirect_to($c->home_page); + } - if ( $mess ) { - $c->stash( error => $mess ); - return $c->redirect_to ( $c->home_page ); - } - # ok for reset password for this account - step 2 - $c->pwdrst->{$name}{confirmed} = 2; - $pwd_datas{Account} = $name; - $pwd_datas{trt} = 'RESET'; - $pwd_datas{jwt} = $jwt; - $c->flash( success => $c->l('use_OK_FOR_RESET') ); - } - - $c->stash( pwd_datas => \%pwd_datas ); - $c->render( 'userpassword' ); -} - + $c->pwdrst->{$name}{confirmed} = 2; + $pwd_datas{Account} = $name; + $pwd_datas{trt} = 'RESET'; + $pwd_datas{jwt} = $jwt; + $c->flash(success => $c->l('use_OK_FOR_RESET')); + } ## end else [ if ($c->is_logged_in) ] + $c->stash(pwd_datas => \%pwd_datas); + $c->render('userpassword'); +} ## end sub main sub change_password { my $c = shift; - my $result; my $res; - my %pwd_datas = (); - - my $trt = $c->param('Trt'); - my $acctName = $c->param('User'); - my $oldPass = $c->param('Oldpass') || ''; - my $pass = $c->param('Pass'); + my %pwd_datas = (); + my $trt = $c->param('Trt'); + my $acctName = $c->param('User'); + my $oldPass = $c->param('Oldpass') || ''; + my $pass = $c->param('Pass'); my $passVerify = $c->param('Passverify'); - - my $jwt = $c->param('jwt') || ''; - my $rt = $c->current_route; - my $mess = ''; my $name = ''; + my $jwt = $c->param('jwt') || ''; + my $rt = $c->current_route; + my $mess = ''; + my $name = ''; $name = $c->jwt->decode($jwt)->{username} if $jwt; - if ( $trt eq 'RESET' ) { - $mess = 'Invalid state' unless ($jwt and $name and ($rt eq 'upwdreset2')); - # request already treated or outdated - if ( $c->pwdrst->{$name}{confirmed} != 2 or $c->pwdrst->{$name}{date} < time() ) { - $mess = $c->l('use_INVALID_REQUEST').' -step 2-'; - } - if ( ! $name or $c->is_logged_in or $name ne $acctName ) { - $mess = 'Invalid reset state'; + if ($trt eq 'RESET') { + $mess = 'Invalid state' unless ($jwt and $name and ($rt eq 'upwdreset2')); + + # request already treated or outdated + if ($c->pwdrst->{$name}{confirmed} != 2 or $c->pwdrst->{$name}{date} < time()) { + $mess = $c->l('use_INVALID_REQUEST') . ' -step 2-'; + } + + if (!$name or $c->is_logged_in or $name ne $acctName) { + $mess = 'Invalid reset state'; } } else { - if ( $name or $jwt or ! $c->is_logged_in ) { - $mess = 'Invalid update state'; - } - } - if ( $mess ) { - $c->stash( error => $mess ); - return $c->redirect_to ( $c->home_page ); - } + if ($name or $jwt or !$c->is_logged_in) { + $mess = 'Invalid update state'; + } + } ## end else [ if ($trt eq 'RESET') ] + if ($mess) { + $c->stash(error => $mess); + return $c->redirect_to($c->home_page); + } $pwd_datas{Account} = $acctName; - $pwd_datas{trt} = $trt; + $pwd_datas{trt} = $trt; # common controls - if ( $acctName eq 'admin' ) { + if ($acctName eq 'admin') { $result .= "Admin password should not be reset here !"; } else { - unless ( $pass && $passVerify ) { - $result .= $c->l('pwd_FIELDS_REQUIRED') . "
    "; - } else { - $result .= $c->l('pwd_PASSWORD_INVALID_CHARS') . "
    " unless (($pass) = ($pass =~ /^([ -~]+)$/ )); - $result .= $c->l('pwd_PASSWORD_VERIFY_ERROR') . "
    " unless ( $pass eq $passVerify ); - } - } - if ( $result ne '' ) { - $c->stash( error => $result, pwd_datas => \%pwd_datas ); - return $c->render( 'userpassword' ); + unless ($pass && $passVerify) { + $result .= $c->l('pwd_FIELDS_REQUIRED') . "
    "; + } else { + $result .= $c->l('pwd_PASSWORD_INVALID_CHARS') . "
    " unless (($pass) = ($pass =~ /^([ -~]+)$/)); + $result .= $c->l('pwd_PASSWORD_VERIFY_ERROR') . "
    " unless ($pass eq $passVerify); + } + } ## end else [ if ($acctName eq 'admin')] + + if ($result ne '') { + $c->stash(error => $result, pwd_datas => \%pwd_datas); + return $c->render('userpassword'); } # validate new password - $res = $c->check_password( $pass ); - $result .= $res . "
    " unless ( $res eq 'OK' ); + $res = $c->check_password($pass); + $result .= $res . "
    " unless ($res eq 'OK'); # controls old password - if ( $trt ne 'RESET' ) { - unless ( $oldPass ) { - $result .= $c->l('pwd_FIELDS_REQUIRED') . "
    " unless $trt eq 'RESET'; + if ($trt ne 'RESET') { + + unless ($oldPass) { + $result .= $c->l('pwd_FIELDS_REQUIRED') . "
    " unless $trt eq 'RESET'; } else { - $result .= $c->l('pwd_PASSWORD_OLD_INVALID_CHARS') . "
    " unless (($oldPass) = ($oldPass =~ /^(\S+)$/ )); + $result .= $c->l('pwd_PASSWORD_OLD_INVALID_CHARS') . "
    " unless (($oldPass) = ($oldPass =~ /^(\S+)$/)); } - if ( $result ne '' ) { - $c->stash( error => $result, pwd_datas => \%pwd_datas ); - return $c->render( 'userpassword' ); + if ($result ne '') { + $c->stash(error => $result, pwd_datas => \%pwd_datas); + return $c->render('userpassword'); } # verify old password - if ( $trt ne 'RESET') { - $result .= $c->l('pwd_ERROR_PASSWORD_CHANGE') . "
    " - unless (SrvMngr::Model::Main->check_credentials($acctName, $oldPass)); - } - } + if ($trt ne 'RESET') { + $result .= $c->l('pwd_ERROR_PASSWORD_CHANGE') . "
    " + unless (SrvMngr::Model::Main->check_credentials($acctName, $oldPass)); + } + } ## end if ($trt ne 'RESET') # $result .= 'Blocked for test (prevents updates)
    '; - - if ( ! $result ) { - my $res = $c->reset_password( $trt, $acctName, $pass, $oldPass ); + if (!$result) { + my $res = $c->reset_password($trt, $acctName, $pass, $oldPass); $result .= $res unless $res eq 'OK'; } - if ( $result ) { - record_password_change_attempt($c, 'FAILED'); - $c->stash( error => $result, pwd_datas => \%pwd_datas ); - return $c->render( 'userpassword' ); - } - + if ($result) { + record_password_change_attempt($c, 'FAILED'); + $c->stash(error => $result, pwd_datas => \%pwd_datas); + return $c->render('userpassword'); + } ## end if ($result) $c->pwdrst->{$name}{confirmed} = 9 if $trt eq 'RESET'; record_password_change_attempt($c, 'SUCCESS'); $result .= $c->l('pwd_PASSWORD_CHANGE_SUCCESS'); - $c->flash( success => $result ); - $c->redirect_to( $c->home_page ); -} - + $c->flash(success => $result); + $c->redirect_to($c->home_page); +} ## end sub change_password sub reset_password { - my ($c, $trt, $user, $password, $oldpassword) = @_; my $ret; - return $c->l('usr_TAINTED_USER') unless (($user) = ($user =~ /^(\w[\-\w_\.]*)$/)); $user = $1; - - my $adb = esmith::AccountsDB->open(); - + my $adb = esmith::AccountsDB->open(); my $acct = $adb->get($user); - return $c->l('NO_SUCH_USER', $user) unless ( $acct->prop('type') eq 'user' ); - - $ret = esmith::util::setUserPasswordRequirePrevious( $user, $oldpassword, $password ) if $trt ne 'RESET'; - $ret = esmith::util::setUserPassword( $user, $password ) if $trt eq 'RESET'; - - return $c->l('pwd_ERROR_PASSWORD_CHANGE') .' '. $trt unless $ret; - + return $c->l('NO_SUCH_USER', $user) unless ($acct->prop('type') eq 'user'); + $ret = esmith::util::setUserPasswordRequirePrevious($user, $oldpassword, $password) if $trt ne 'RESET'; + $ret = esmith::util::setUserPassword($user, $password) if $trt eq 'RESET'; + return $c->l('pwd_ERROR_PASSWORD_CHANGE') . ' ' . $trt unless $ret; $acct->set_prop("PasswordSet", "yes"); undef $adb; @@ -192,66 +175,52 @@ sub reset_password { return $c->l("usr_ERR_OCCURRED_MODIFYING_PASSWORD"); } $adb = esmith::AccountsDB->open(); - return 'OK'; -} - +} ## end sub reset_password sub record_password_change_attempt { + my ($c, $result) = @_; + my $user = $c->param('User'); + my $ip_address = $c->tx->remote_address; - my ($c, $result) = @_; - - my $user = $c->param('User'); - my $ip_address = $c->tx->remote_address; - - if ($result eq 'SUCCESS') { - $c->app->log->info(join "\t", "Password change succeeded: $user", $ip_address); - } else { - $c->app->log->info(join "\t", "Password change FAILED: $user", $ip_address); - } -} - + if ($result eq 'SUCCESS') { + $c->app->log->info(join "\t", "Password change succeeded: $user", $ip_address); + } else { + $c->app->log->info(join "\t", "Password change FAILED: $user", $ip_address); + } +} ## end sub record_password_change_attempt sub check_password { - my $c = shift; - my $password = shift; - - my $strength; - my $rec = $cdb->get('passwordstrength'); - $strength = ($rec ? ($rec->prop('Users') || 'none') : 'none'); - - return validate_password( $c, $strength, $password ); -} - + my $c = shift; + my $password = shift; + my $strength; + my $rec = $cdb->get('passwordstrength'); + $strength = ($rec ? ($rec->prop('Users') || 'none') : 'none'); + return validate_password($c, $strength, $password); +} ## end sub check_password sub validate_password { - my ($c, $strength, $pass) = @_; - use Crypt::Cracklib; if ($strength eq "none") { - return $c->l("Passwords must be at least 7 characters long") unless ( length( $pass ) > 6 ); + return $c->l("Passwords must be at least 7 characters long") unless (length($pass) > 6); return "OK"; } - my $reason = is_normal_password($c, $pass, undef); return $reason unless ($reason eq "OK"); return "OK" unless ($strength eq "strong"); - if ( -f '/usr/lib64/cracklib_dict.pwd' ) { + if (-f '/usr/lib64/cracklib_dict.pwd') { $reason = fascist_check($pass, '/usr/lib64/cracklib_dict'); } else { $reason = fascist_check($pass, '/usr/lib/cracklib_dict'); } $reason ||= "Software error: password check failed"; - return "OK" if ($reason eq "ok"); - - return $c->l("Bad Password Choice") . ": " - . $c->l("The password you have chosen is not a good choice, because") - . " " . $c->($reason) . "."; -} - - + return + $c->l("Bad Password Choice") . ": " + . $c->l("The password you have chosen is not a good choice, because") . " " + . $c->($reason) . "."; +} ## end sub validate_password 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Viewlogfiles.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Viewlogfiles.pm index d583b2b..e9ee9e2 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Viewlogfiles.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Viewlogfiles.pm @@ -13,145 +13,121 @@ use warnings; use Mojo::Base 'Mojolicious::Controller'; #use esmith::FormMagick qw(gen_locale_date_string); - use Locale::gettext; use SrvMngr::I18N; use SrvMngr qw(theme_list init_session); - use esmith::ConfigDB; use Time::TAI64; use File::Basename; use HTML::Entities; use esmith::FormMagick qw(gen_locale_date_string); use File::Temp qw(tempfile); - use constant TRUE => 1; use constant FALSE => 0; - our $cdb = esmith::ConfigDB->open() || die "Couldn't open config db"; - -our @logfiles = (); # with array - +our @logfiles = (); # with array sub main { my $c = shift; $c->app->log->info($c->log_req); - my %log_datas = (); - my $title = $c->l('log_FORM_TITLE'); - my $notif = ''; - - $log_datas{default_op} = - ($cdb->get('viewlogfiles')->prop('DefaultOperation')) || 'view'; - - $c->stash( title => $title, notif => $notif, log_datas => \%log_datas); + my $title = $c->l('log_FORM_TITLE'); + my $notif = ''; + $log_datas{default_op} = ($cdb->get('viewlogfiles')->prop('DefaultOperation')) || 'view'; + $c->stash(title => $title, notif => $notif, log_datas => \%log_datas); $c->render(template => 'viewlogfiles'); -}; - +} ## end sub main sub do_action { my $c = shift; $c->app->log->info($c->log_req); - - my $title = $c->l('log_FORM_TITLE'); - my $notif = ''; - my $result = ""; + my $title = $c->l('log_FORM_TITLE'); + my $notif = ''; + my $result = ""; my %log_datas = (); - - $log_datas{filename} = $c->param('Filename'); - $log_datas{matchpattern} = $c->param('Matchpattern'); + $log_datas{filename} = $c->param('Filename'); + $log_datas{matchpattern} = $c->param('Matchpattern'); $log_datas{highlightpattern} = $c->param('Highlightpattern'); - $log_datas{operation} = $c->param('Operation'); - if ($log_datas{operation} eq 'download') { - $log_datas{'trt'} = "DOWN" - } else { - $log_datas{'trt'} = "SHOW" - } + $log_datas{operation} = $c->param('Operation'); + if ($log_datas{operation} eq 'download') { + $log_datas{'trt'} = "DOWN"; + } else { + $log_datas{'trt'} = "SHOW"; + } if ($log_datas{filename} =~ /^([\S\s]+)$/) { - $log_datas{filename} = $1; + $log_datas{filename} = $1; } elsif ($log_datas{filename} =~ /^$/) { - $log_datas{filename} = "messages"; + $log_datas{filename} = "messages"; } else { - $result .= $c->l("log_FILENAME_ERROR", $log_datas{filename} ) - . " "; - } - - if ($log_datas{matchpattern} =~ /^(\S+)$/) { - $log_datas{matchpattern} = $1; - } else { - $log_datas{matchpattern} = "."; - } - - if ($log_datas{highlightpattern} =~ /^(\S+)$/) { - $log_datas{highlightpattern} = $1; - } else { - $log_datas{highlightpattern} = ''; + $result .= $c->l("log_FILENAME_ERROR", $log_datas{filename}) . " "; } + if ($log_datas{matchpattern} =~ /^(\S+)$/) { + $log_datas{matchpattern} = $1; + } else { + $log_datas{matchpattern} = "."; + } + + if ($log_datas{highlightpattern} =~ /^(\S+)$/) { + $log_datas{highlightpattern} = $1; + } else { + $log_datas{highlightpattern} = ''; + } my $fullpath = "/var/log/$log_datas{filename}"; + if (-z $fullpath) { - $result .= $c->l("log_LOG_FILE_EMPTY", "$log_datas{filename}" ); + $result .= $c->l("log_LOG_FILE_EMPTY", "$log_datas{filename}"); } if ($log_datas{trt} eq "SHOW") { - if ( ! $result ) { - $result = $c->render_to_string(inline => showlogFile( $c, %log_datas )); - } + if (!$result) { + $result = $c->render_to_string(inline => showlogFile($c, %log_datas)); + } - if ( $result ) { - $c->stash(title => $title, modul => $result, log_datas => \%log_datas); - return $c->render(template => 'viewlogfiles2'); - } - } + if ($result) { + $c->stash(title => $title, modul => $result, log_datas => \%log_datas); + return $c->render(template => 'viewlogfiles2'); + } + } ## end if ($log_datas{trt} eq...) - - if ( $log_datas{trt} eq 'DOWN' ) { - - my $modul = 'Log file download'; - - $notif = download_logFile( $c, %log_datas ); - return undef unless defined $notif; - } - - $c->stash( title => $title, notif => $notif, log_datas => \%log_datas); + if ($log_datas{trt} eq 'DOWN') { + my $modul = 'Log file download'; + $notif = download_logFile($c, %log_datas); + return undef unless defined $notif; + } ## end if ($log_datas{trt} eq...) + $c->stash(title => $title, notif => $notif, log_datas => \%log_datas); $c->render(template => 'viewlogfiles'); +} ## end sub do_action -}; - - -sub timestamp2local -{ +sub timestamp2local { $_ = shift; - if (/^(\@[0-9a-f]{24})(.*)/s) - { - return Time::TAI64::tai64nlocal($1) . $2; - } - elsif (/^([0-9]{10}\.[0-9]{3})(.*)/s) - { - return localtime($1) . $2; + + if (/^(\@[0-9a-f]{24})(.*)/s) { + return Time::TAI64::tai64nlocal($1) . $2; + } elsif (/^([0-9]{10}\.[0-9]{3})(.*)/s) { + return localtime($1) . $2; } return $_; -} - +} ## end sub timestamp2local sub findlogFiles { - my $c = shift; - use File::Find; - sub findlogfiles - { + + sub findlogfiles { my $path = $File::Find::name; - if (-f) - { + if (-f) { + # Remove leading /var/log/messages $path =~ s:^/var/log/::; + # don't bother to collect files known to be non-text # or not log files - foreach (qw( + foreach ( + qw( lastlog btmp$ wtmp @@ -161,176 +137,160 @@ sub findlogFiles { httpd/ssl_scache.pag httpd/ssl_scache.dir \/config$ - )) + ) + ) { return if $path =~ /$_/; - } - + } ## end foreach (qw( lastlog btmp$ wtmp...)) my ($file_base, $file_path, $file_type) = fileparse($path); - if ( $file_base =~ /@.*/ ) - { + if ($file_base =~ /@.*/) { + #$logfiles{$path} = $file_path . timestamp2local($file_base); - push @logfiles, [ $file_path . timestamp2local($file_base), $path ]; - } - else - { + push @logfiles, [ $file_path . timestamp2local($file_base), $path ]; + } else { + #$logfiles{$path} = $path; - push @logfiles, [ $path, $path ]; + push @logfiles, [ $path, $path ]; } - } - } - + } ## end if (-f) + } ## end sub findlogfiles @logfiles = (); + # Now go and find all the files under /var/log - find({wanted => \&findlogfiles, no_chdir => 1}, '/var/log'); - + find({ wanted => \&findlogfiles, no_chdir => 1 }, '/var/log'); my @logf = sort { $a->[0] cmp $b->[0] } @logfiles; - return \@logf; -} - +} ## end sub findlogFiles sub showlogFile { - my ($c, %log_datas) = @_; - my $fullpath = "/var/log/$log_datas{filename}"; - my $out = ''; - + my $out = ''; $out .= sprintf("$fullpath: \n"); + $out .= sprintf($c->l("log_VIEWING_TIME", $c->gen_locale_date_string())); - $out .= sprintf($c->l("log_VIEWING_TIME", $c->gen_locale_date_string() )); + unless ($log_datas{matchpattern} eq '.') { - unless ( $log_datas{matchpattern} eq '.' ) - { #$out .= sprintf("

    \n"); - $out .= sprintf($c->l("log_MATCH_HEADER", $log_datas{matchpattern} )); - } + $out .= sprintf($c->l("log_MATCH_HEADER", $log_datas{matchpattern})); + } ## end unless ($log_datas{matchpattern...}) + + if ($log_datas{highlightpattern}) { - if ( $log_datas{highlightpattern} ) - { #$out .= sprintf("

    \n"); - $out .= sprintf($c->l("log_HIGHLIGHT_HEADER", "$log_datas{highlightpattern}" )); - } + $out .= sprintf($c->l("log_HIGHLIGHT_HEADER", "$log_datas{highlightpattern}")); + } ## end if ($log_datas{highlightpattern...}) if ($log_datas{filename} =~ /\.gz$/) { my $pid = open(LOGFILE, "-|"); die "Couldn't fork: $!" unless defined $pid; + unless ($pid) { + # Child exec("/bin/zcat", $fullpath) - || die "Can't exec zcat: $!"; + || die "Can't exec zcat: $!"; + # NOTREACHED - } + } ## end unless ($pid) } else { open(LOGFILE, "$fullpath"); } - my $somethingMatched = 0; - my $fileEmpty = 1; + my $fileEmpty = 1; $out .= sprintf("

    ");
    -    while()
    -    {
    +
    +    while () {
             $fileEmpty = 0;
             next unless /$log_datas{matchpattern}/;
             $somethingMatched = 1;
    -
    -        $_ = timestamp2local($_);
    -        $_ = HTML::Entities::encode_entities($_);
    +        $_                = timestamp2local($_);
    +        $_                = HTML::Entities::encode_entities($_);
             ($log_datas{highlightpattern} && /$log_datas{highlightpattern}/)
    -    	    ? $out .= sprintf( "$_" )
    -    	    : $out .= sprintf("$_");
    -    }
    +            ? $out .= sprintf("$_")
    +            : $out .= sprintf("$_");
    +    } ## end while ()
         $out .= sprintf("
    "); if ($fileEmpty) { $out .= sprintf("

    \n"); $out .= sprintf($c->l("log_LOG_FILE_EMPTY")); } else { - unless ($somethingMatched) - { + + unless ($somethingMatched) { $out .= sprintf("

    \n"); $out .= sprintf($c->l("log_NO_MATCHING_LINES")); } - } - + } ## end else [ if ($fileEmpty) ] close LOGFILE; - return $out; -} - +} ## end sub showlogFile sub download_logFile { - my ($c, %log_datas) = @_; - my $fullpath = "/var/log/$log_datas{filename}"; # Save this information for later. - $cdb->get('viewlogfiles')->merge_props('DefaultOperation', $log_datas{operation}); # If the client is on windows, we must handle this a little differently. my $win32 = FALSE; my $mac = FALSE; my $agent = $ENV{HTTP_USER_AGENT} || ""; + if ($agent =~ /win32|windows/i) { $win32 = TRUE; - } elsif ($agent =~ /mac/i) { + } elsif ($agent =~ /mac/i) { $mac = TRUE; } # Check for errors first. Once we start sending the file it's too late to # report them. my $error = ""; - unless (-f $fullpath) { + + unless (-f $fullpath) { $error = $c->l("log_ERR_NOEXIST_FILE") . $fullpath; } - local *FILE; open(FILE, "<$fullpath") or $error = $c->l("log_ERR_NOOPEN_FILE"); - # Put other error checking here. + + # Put other error checking here. return $error if $error; - # Fix the filename, as it might have a directory prefixed to it. + # Fix the filename, as it might have a directory prefixed to it. my $filename = $log_datas{filename}; - if ( $filename =~ m#/# ) { + + if ($filename =~ m#/#) { $filename = (split /\//, $filename)[-1]; } # And send the file. my $nl = "\n"; - if ($win32) { $nl = "\r\n" } - elsif ($mac) { $nl = "\r" } + if ($win32) { $nl = "\r\n" } + elsif ($mac) { $nl = "\r" } # Otherwise, send the file. Start with the headers. # Note: The Content-disposition must be attachment, or IE will view the # file inline like it's told. It ignores the Content-type, but it likes # the Content-disposition (an officially unsupported header) for some # reason. Yay Microsoft. - - my $file2 = new File::Temp( UNLINK => 0 ); + my $file2 = new File::Temp(UNLINK => 0); while (my $line = ) { chomp $line; my $linew = timestamp2local($line) . $nl; print $file2 $linew; - } + } ## end while (my $line = ) close(FILE); - $c->render_file( - 'filepath' => "$file2", - 'filename' => "$filename", - 'format' => 'x-download', - 'content_disposition' => 'attachment', - 'cleanup' => 1, + 'filepath' => "$file2", + 'filename' => "$filename", + 'format' => 'x-download', + 'content_disposition' => 'attachment', + 'cleanup' => 1, ); - return undef; -} - - +} ## end sub download_logFile 1; - diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Workgroup.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Workgroup.pm index 9a073ab..5bdc7b2 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Workgroup.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Workgroup.pm @@ -10,94 +10,71 @@ package SrvMngr::Controller::Workgroup; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw(theme_list init_session); - use esmith::FormMagick::Panel::workgroup; - our $db = esmith::ConfigDB->open || die "Couldn't open config db"; sub main { my $c = shift; $c->app->log->info($c->log_req); - my %wkg_datas = (); - my $title = $c->l('wkg_FORM_TITLE'); - my $modul = ''; - - $wkg_datas{'Workgroup'} = ($db->get_prop('smb','Workgroup')) || ''; - $wkg_datas{'ServerName'} = ($db->get_prop('smb','ServerName')) || ''; - $wkg_datas{'ServerRole'} = ($db->get_prop('smb','ServerRole')) || ''; - $wkg_datas{'RoamingProfiles'} = ($db->get_prop('smb','RoamingProfiles')) || ''; - - $c->stash( title => $title, modul => $modul, wkg_datas => \%wkg_datas ); + my $title = $c->l('wkg_FORM_TITLE'); + my $modul = ''; + $wkg_datas{'Workgroup'} = ($db->get_prop('smb', 'Workgroup')) || ''; + $wkg_datas{'ServerName'} = ($db->get_prop('smb', 'ServerName')) || ''; + $wkg_datas{'ServerRole'} = ($db->get_prop('smb', 'ServerRole')) || ''; + $wkg_datas{'RoamingProfiles'} = ($db->get_prop('smb', 'RoamingProfiles')) || ''; + $c->stash(title => $title, modul => $modul, wkg_datas => \%wkg_datas); $c->render(template => 'workgroup'); -}; - +} ## end sub main sub do_update { my $c = shift; $c->app->log->info($c->log_req); - - my $result = ""; - - my $workgroup = ($c->param('Workgroup') || 'no'); - my $servername = ($c->param('ServerName') || 'WS'); + my $result = ""; + my $workgroup = ($c->param('Workgroup') || 'no'); + my $servername = ($c->param('ServerName') || 'WS'); my $roamingprofiles = ($c->param('RoamingProfiles') || 'no'); - my $serverrole = ($c->param('ServerRole') || 'WS'); + my $serverrole = ($c->param('ServerRole') || 'WS'); # controls my $res = validate2_workgroup($c, $workgroup, $servername); $result .= $res unless $res eq 'OK'; - $res = validate2_servername($c, $servername); $result .= $res unless $res eq 'OK'; if ($result eq '') { - $db->get('smb')->set_prop('Workgroup', $workgroup); - $db->get('smb')->set_prop('ServerRole', $serverrole); - $db->get('smb')->set_prop('ServerName', $servername); + $db->get('smb')->set_prop('Workgroup', $workgroup); + $db->get('smb')->set_prop('ServerRole', $serverrole); + $db->get('smb')->set_prop('ServerName', $servername); $db->get('smb')->set_prop('RoamingProfiles', $roamingprofiles); - } - - system( "/sbin/e-smith/signal-event", "workgroup-update" ) == 0 - or $result = $c->l('ERROR_UPDATING') . " system"; - + } ## end if ($result eq '') + system("/sbin/e-smith/signal-event", "workgroup-update") == 0 + or $result = $c->l('ERROR_UPDATING') . " system"; my $title = $c->l('wkg_FORM_TITLE'); - - if ( $result eq '' ) { $result = $c->l('wkg_SUCCESS'); } - - $c->stash( title => $title, modul => $result ); + if ($result eq '') { $result = $c->l('wkg_SUCCESS'); } + $c->stash(title => $title, modul => $result); $c->render(template => 'module'); - -}; - +} ## end sub do_update sub validate2_servername { - my $c = shift; + my $c = shift; my $servername = shift; - - return ('OK') if ( $servername =~ /^([a-zA-Z][\-\w]*)$/ ); - + return ('OK') if ($servername =~ /^([a-zA-Z][\-\w]*)$/); return $c->l('INVALID_SERVERNAME'); -} - +} ## end sub validate2_servername sub validate2_workgroup { - my $c = shift; - my $workgroup = lc(shift); + my $c = shift; + my $workgroup = lc(shift); my $servername = lc(shift); -# my $workgroup = $c->l(shift); -# my $servername = $c->l(shift); - - return $c->l('INVALID_WORKGROUP') unless ( $workgroup =~ /^([a-zA-Z0-9][\-\w\.]*)$/ ); - return $c->l('INVALID_WORKGROUP_MATCHES_SERVERNAME') if ( $servername eq $workgroup); - return ('OK'); - -} - + # my $workgroup = $c->l(shift); + # my $servername = $c->l(shift); + return $c->l('INVALID_WORKGROUP') unless ($workgroup =~ /^([a-zA-Z0-9][\-\w\.]*)$/); + return $c->l('INVALID_WORKGROUP_MATCHES_SERVERNAME') if ($servername eq $workgroup); + return ('OK'); +} ## end sub validate2_workgroup 1; diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Yum.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Yum.pm index 7a3c8e3..5874864 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Yum.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Yum.pm @@ -10,270 +10,238 @@ package SrvMngr::Controller::Yum; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw(theme_list init_session ip_number_or_blank); - use esmith::ConfigDB; - use esmith::util; use File::Basename; - our $cdb = esmith::ConfigDB->open || die "Couldn't open config db"; - -my $dnf_status_file = '/var/cache/dnf/dnf.status'; +my $dnf_status_file = '/var/cache/dnf/dnf.status'; #use File::stat; - our %dbs; -for ( qw(available installed updates) ) -{ - $dbs{$_} = esmith::ConfigDB->open_ro("dnf_$_") or - die "Couldn't open dnf_$_ DB\n"; +for (qw(available installed updates)) { + $dbs{$_} = esmith::ConfigDB->open_ro("dnf_$_") + or die "Couldn't open dnf_$_ DB\n"; } -for ( qw(repositories) ) -{ - $dbs{$_} = esmith::ConfigDB->open("yum_$_") or - die "Couldn't open yum_$_ DB\n"; +for (qw(repositories)) { + $dbs{$_} = esmith::ConfigDB->open("yum_$_") + or die "Couldn't open yum_$_ DB\n"; } - sub main { - my $c = shift; $c->app->log->info($c->log_req); - my %yum_datas = (); - my $title = $c->l('yum_FORM_TITLE'); - my $dest = 'yum'; - my $notif = ''; - + my $title = $c->l('yum_FORM_TITLE'); + my $dest = 'yum'; + my $notif = ''; $yum_datas{'trt'} = 'STAT'; - - if ( $c->is_dnf_running()) { - $yum_datas{'trt'} = 'LOGF'; - $dest = 'yumlogfile'; + if ($c->is_dnf_running()) { + $yum_datas{'trt'} = 'LOGF'; + $dest = 'yumlogfile'; } elsif ($cdb->get_prop('dnf', 'LogFile')) { - $yum_datas{'trt'} = 'PSTU'; - $yum_datas{'reconf'} = $cdb->get_value('UnsavedChanges', 'yes'); - $dest = 'yumpostupg'; + $yum_datas{'trt'} = 'PSTU'; + $yum_datas{'reconf'} = $cdb->get_value('UnsavedChanges', 'yes'); + $dest = 'yumpostupg'; } else { - # normal other trt + + # normal other trt } - - $c->stash( title => $title, notif => $notif, yum_datas => \%yum_datas ); - return $c->render( template => $dest ); - -} - + $c->stash(title => $title, notif => $notif, yum_datas => \%yum_datas); + return $c->render(template => $dest); +} ## end sub main sub do_display { - - my $c = shift; - - my $rt = $c->current_route; - my $trt = ($c->param('trt') || 'STAT'); - + my $c = shift; + my $rt = $c->current_route; + my $trt = ($c->param('trt') || 'STAT'); my %yum_datas = (); - my $title = $c->l('yum_FORM_TITLE'); + my $title = $c->l('yum_FORM_TITLE'); my ($notif, $dest) = ''; - $yum_datas{'trt'} = $trt; # force $trt if current logfile - if ( $c->is_dnf_running() ) { - $trt = 'LOGF'; + if ($c->is_dnf_running()) { + $trt = 'LOGF'; } elsif ($cdb->get_prop('dnf', 'LogFile')) { - $trt = 'PSTU'; + $trt = 'PSTU'; } - if ( $trt eq 'UPDT' ) { - $dest = 'yumupdate'; + if ($trt eq 'UPDT') { + $dest = 'yumupdate'; + } + + if ($trt eq 'INST') { + $dest = 'yuminstall'; + } + + if ($trt eq 'REMO') { + $dest = 'yumremove'; + } + + if ($trt eq 'CONF') { + $dest = 'yumconfig'; + } + + if ($trt eq 'LOGF') { + if ($c->is_dnf_running()) { + $dest = 'yumlogfile'; } + } ## end if ($trt eq 'LOGF') - if ( $trt eq 'INST' ) { - $dest = 'yuminstall'; + if ($trt eq 'PSTU') { + if ($cdb->get_prop('dnf', 'LogFile')) { + $dest = 'yumpostupg'; + $yum_datas{'reconf'} = $cdb->get_value('UnsavedChanges', 'yes'); } - - if ( $trt eq 'REMO' ) { - $dest = 'yumremove'; - } - - if ( $trt eq 'CONF' ) { - $dest = 'yumconfig'; - } - - if ( $trt eq 'LOGF' ) { - if ($c->is_dnf_running()) { - $dest = 'yumlogfile'; - } - } - - if ( $trt eq 'PSTU') { - if ($cdb->get_prop('dnf', 'LogFile')) { - $dest = 'yumpostupg'; - $yum_datas{'reconf'} = $cdb->get_value('UnsavedChanges', 'yes'); - } - } - - if ( ! $dest ) { $dest = 'yum'; } - - $c->stash( title => $title, notif => $notif, yum_datas => \%yum_datas ); - return $c->render( template => $dest ); - -}; - + } ## end if ($trt eq 'PSTU') + if (!$dest) { $dest = 'yum'; } + $c->stash(title => $title, notif => $notif, yum_datas => \%yum_datas); + return $c->render(template => $dest); +} ## end sub do_display sub do_update { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - my $trt = $c->param('trt'); - + my $rt = $c->current_route; + my $trt = $c->param('trt'); my %yum_datas = (); $yum_datas{trt} = $trt; - my $title = $c->l('yum_FORM_TITLE'); - my ($dest, $res, $result) = ''; - if ( $trt eq 'UPDT' ) { + if ($trt eq 'UPDT') { + $dest = 'yumupdate'; - $dest = 'yumupdate'; + if (!$result) { + $res = $c->do_yum('update'); + $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $res = $c->do_yum('update'); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $yum_datas{trt} = 'SUC'; - #$result = $c->l('yum_SUCCESS'); - } - } - } + if (!$result) { + $yum_datas{trt} = 'SUC'; - if ( $trt eq 'INST' ) { + #$result = $c->l('yum_SUCCESS'); + } ## end if (!$result) + } ## end if (!$result) + } ## end if ($trt eq 'UPDT') - $dest = 'yuminstall'; + if ($trt eq 'INST') { + $dest = 'yuminstall'; - if ( ! $result ) { - $res = $c->do_yum('install'); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $yum_datas{trt} = 'SUC'; - #$result = $c->l('yum_SUCCESS'); - } - } - } + if (!$result) { + $res = $c->do_yum('install'); + $result .= $res unless $res eq 'OK'; - if ( $trt eq 'REMO' ) { + if (!$result) { + $yum_datas{trt} = 'SUC'; - $dest = 'yumremove'; + #$result = $c->l('yum_SUCCESS'); + } ## end if (!$result) + } ## end if (!$result) + } ## end if ($trt eq 'INST') - if ( ! $result ) { - $res = $c->do_yum('remove'); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $yum_datas{trt} = 'SUC'; - #$result = $c->l('yum_SUCCESS'); - } - } - } + if ($trt eq 'REMO') { + $dest = 'yumremove'; - if ( $trt eq 'CONF' ) { + if (!$result) { + $res = $c->do_yum('remove'); + $result .= $res unless $res eq 'OK'; - $dest = 'yumconfig'; + if (!$result) { + $yum_datas{trt} = 'SUC'; - if ( ! $result ) { - $res = $c->change_settings(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $yum_datas{trt} = 'SUC'; - $result = $c->l('yum_SUCCESS'); - } - } - } + #$result = $c->l('yum_SUCCESS'); + } ## end if (!$result) + } ## end if (!$result) + } ## end if ($trt eq 'REMO') + if ($trt eq 'CONF') { + $dest = 'yumconfig'; - if ( $trt eq 'PSTU') { + if (!$result) { + $res = $c->change_settings(); + $result .= $res unless $res eq 'OK'; - my $reconf = $c->param('reconf') || 'yes'; - $dest = 'yumpostupg'; + if (!$result) { + $yum_datas{trt} = 'SUC'; + $result = $c->l('yum_SUCCESS'); + } + } ## end if (!$result) + } ## end if ($trt eq 'CONF') - # effective reconfigure and reboot required - if ( $reconf eq 'yes' ) { - $res = $c->post_upgrade_reboot(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $yum_datas{trt} = 'SUC'; - $result = $c->l('yum_SYSTEM_BEING_RECONFIGURED'); - } - } else { - $yum_datas{trt} = 'SUC'; - $result = $c->l('yum_UPDATE_SUCCESS'); - } - } + if ($trt eq 'PSTU') { + my $reconf = $c->param('reconf') || 'yes'; + $dest = 'yumpostupg'; + # effective reconfigure and reboot required + if ($reconf eq 'yes') { + $res = $c->post_upgrade_reboot(); + $result .= $res unless $res eq 'OK'; - if ( $trt eq 'LOGF' ) { - - $dest = 'yumlogfile'; - if ( ! $c->is_dnf_running()) { - $yum_datas{trt} = 'SUC'; - $result = $c->l('yum_SUCCESS'); + if (!$result) { + $yum_datas{trt} = 'SUC'; + $result = $c->l('yum_SYSTEM_BEING_RECONFIGURED'); + } + } else { + $yum_datas{trt} = 'SUC'; + $result = $c->l('yum_UPDATE_SUCCESS'); } - } + } ## end if ($trt eq 'PSTU') + + if ($trt eq 'LOGF') { + $dest = 'yumlogfile'; + + if (!$c->is_dnf_running()) { + $yum_datas{trt} = 'SUC'; + $result = $c->l('yum_SUCCESS'); + } + } ## end if ($trt eq 'LOGF') # do_yum ended (no message) --> forced to LOGFile - if ( ! $result ) { - $dest = 'yumlogfile'; - $yum_datas{trt} = 'LOGF'; + if (!$result) { + $dest = 'yumlogfile'; + $yum_datas{trt} = 'LOGF'; } + $c->stash(title => $title, notif => $result, yum_datas => \%yum_datas); - - $c->stash( title => $title, notif => $result, yum_datas => \%yum_datas ); if ($yum_datas{trt} ne 'SUC') { - return $c->render(template => $dest); + return $c->render(template => $dest); } - my $message = "'Yum' $trt update DONE"; $c->app->log->info($message); $c->flash(success => $result) if $result; - $c->redirect_to("/yum"); - -}; +} ## end sub do_update sub get_dnf_status { + #interrogate status file created and maintained by smeserver.py plugin for dnf. - my ($c) = @_; + my ($c) = @_; my $file_name = $dnf_status_file; - my $content = "resolved"; - if ( -e "$file_name") { - open my $fh, '<', $file_name or die "Can't open file: $!"; - $content = <$fh>; - close $fh; - } + my $content = "resolved"; + + if (-e "$file_name") { + open my $fh, '<', $file_name or die "Can't open file: $!"; + $content = <$fh>; + close $fh; + } ## end if (-e "$file_name") return $content; -} +} ## end sub get_dnf_status sub is_dnf_running { my ($c) = @_; my $dnf_status = $c->get_dnf_status(); return $dnf_status ne "resolved" && $dnf_status ne "config" && $dnf_status ne "sack"; -} +} ## end sub is_dnf_running sub is_empty { - my ($c, $yumdb) = @_; - - my $groups = $dbs{$yumdb}->get_all_by_prop(type => 'group') || 'none'; + my $groups = $dbs{$yumdb}->get_all_by_prop(type => 'group') || 'none'; my $packages = $dbs{$yumdb}->get_all_by_prop(type => 'package') || 'none'; #Show no updates if both = none @@ -281,283 +249,194 @@ sub is_empty { #else return here return; -} - +} ## end sub is_empty sub non_empty { - my ($c, $yumdb, $type) = @_; - $type ||= 'both'; - return 0 unless (exists $dbs{$yumdb}); - - my $groups = scalar $dbs{$yumdb}->get_all_by_prop(type => 'group'); + my $groups = scalar $dbs{$yumdb}->get_all_by_prop(type => 'group'); return $groups if ($type eq 'group'); - my $packages = scalar $dbs{$yumdb}->get_all_by_prop(type => 'package'); - if ($type eq 'package') - { - return $c->package_functions_enabled ? $packages : 0; + + if ($type eq 'package') { + return $c->package_functions_enabled ? $packages : 0; } - - return ($c->package_functions_enabled or $yumdb eq 'updates') ? - ($groups || $packages) : $groups; -} - + return ($c->package_functions_enabled or $yumdb eq 'updates') ? ($groups || $packages) : $groups; +} ## end sub non_empty sub package_functions_enabled { - my ($c) = @_; - return ($cdb->get_prop("dnf", "PackageFunctions") eq "enabled"); - } - sub get_status { - my ($c, $prop, $localise) = @_; - my $status = $cdb->get_prop("dnf", $prop) || 'disabled'; - return $status unless $localise; - return $c->l($status eq 'enabled' ? 'ENABLED' : 'DISABLED'); -} - +} ## end sub get_status sub get_options { - my ($c, $yumdb, $type) = @_; - my %options; - for ($dbs{$yumdb}->get_all_by_prop(type => $type)) - { - $options{$_->key} = $_->key . " " . $_->prop("Version") . " - " . - $_->prop("Repo"); + for ($dbs{$yumdb}->get_all_by_prop(type => $type)) { + $options{ $_->key } = $_->key . " " . $_->prop("Version") . " - " . $_->prop("Repo"); } - return \%options; -} - +} ## end sub get_options sub get_options2 { - my ($c, $yumdb, $type) = @_; - my @options; - for ($dbs{$yumdb}->get_all_by_prop(type => $type)) - { - push @options, [ $_->key . " " . $_->prop("Version") . " - " . - $_->prop("Repo") => $_->key ]; + for ($dbs{$yumdb}->get_all_by_prop(type => $type)) { + push @options, [ $_->key . " " . $_->prop("Version") . " - " . $_->prop("Repo") => $_->key ]; } - return \@options; -} - +} ## end sub get_options2 sub get_names { - - return [ keys %{get_options(@_)} ]; + return [ keys %{ get_options(@_) } ]; } - sub get_names2 { - my ($c, $yumdb, $type) = @_; my @selected; for ($dbs{$yumdb}->get_all_by_prop(type => $type)) { push @selected, $_->key; } - return \@selected; -# return [ values @{get_options2(@_)} ]; -} + # return [ values @{get_options2(@_)} ]; +} ## end sub get_names2 sub get_repository_options2 { - my $c = shift; - my @options; - foreach my $repos ( - $dbs{repositories}->get_all_by_prop(type => "repository") ) - { - next unless ($repos->prop('Visible') eq 'yes' - or $repos->prop('status') eq 'enabled'); - + foreach my $repos ($dbs{repositories}->get_all_by_prop(type => "repository")) { + next unless ($repos->prop('Visible') eq 'yes' + or $repos->prop('status') eq 'enabled'); push @options, [ $repos->prop('Name') => $repos->key ]; - } - + } ## end foreach my $repos ($dbs{repositories...}) my @opts = sort { $a->[0] cmp $b->[0] } @options; - return \@opts; -} +} ## end sub get_repository_options2 - -sub get_repository_current_options -{ +sub get_repository_current_options { my $c = shift; - my @selected; - foreach my $repos ( - $dbs{repositories}->get_all_by_prop( type => "repository" ) ) - { - next unless ($repos->prop('Visible') eq 'yes' - or $repos->prop('status') eq 'enabled'); - + foreach my $repos ($dbs{repositories}->get_all_by_prop(type => "repository")) { + next unless ($repos->prop('Visible') eq 'yes' + or $repos->prop('status') eq 'enabled'); push @selected, $repos->key if ($repos->prop('status') eq 'enabled'); - } - + } ## end foreach my $repos ($dbs{repositories...}) return \@selected; -} - +} ## end sub get_repository_current_options sub get_avail2 { - my ($c, $yumdb, $type) = @_; - return $c->get_options2("available", "package"); } - sub get_check_freq_opt { - my ($c) = @_; - - return [[ $c->l('DISABLED') => 'disabled'], - [ $c->l('yum_1DAILY') => 'daily'], - [ $c->l('yum_2WEEKLY') => 'weekly'], - [ $c->l('yum_3MONTHLY') => 'monthly']]; -} - + return [ + [ $c->l('DISABLED') => 'disabled' ], + [ $c->l('yum_1DAILY') => 'daily' ], + [ $c->l('yum_2WEEKLY') => 'weekly' ], + [ $c->l('yum_3MONTHLY') => 'monthly' ] + ]; +} ## end sub get_check_freq_opt sub print_skip_header { - my ($c) = shift; - return "\n"; } - sub change_settings { - my ($c) = @_; - for my $param ( qw( - PackageFunctions - ) ) + for my $param ( + qw( + PackageFunctions + ) + ) { - $cdb->set_prop("dnf", $param, $c->param("yum_$param")); - } - + $cdb->set_prop("dnf", $param, $c->param("yum_$param")); + } ## end for my $param (qw( PackageFunctions...)) my $check4updates = $c->param("yum_check4updates"); - my $status = 'disabled'; - + my $status = 'disabled'; if ($check4updates ne 'disabled') { $status = 'enabled'; } - $cdb->set_prop("dnf", 'check4updates', $check4updates); - my $deltarpm = $c->param("yum_DeltaRpmProcess"); $cdb->set_prop("dnf", 'DeltaRpmProcess', $deltarpm); - my $downloadonly = $c->param("yum_DownloadOnly"); if ($downloadonly ne 'disabled') { $status = 'enabled'; } - $cdb->set_prop("dnf", 'DownloadOnly', $downloadonly); - my $AutoInstallUpdates = $c->param("yum_AutoInstallUpdates"); if ($AutoInstallUpdates ne 'disabled') { $status = 'enabled'; } - $cdb->set_prop("dnf", 'AutoInstallUpdates', $AutoInstallUpdates); - $cdb->set_prop("dnf", 'status', $status); - - my %selected = map {$_ => 1} @{$c->every_param('SelectedRepositories')}; - - foreach my $repos ( - $dbs{repositories}->get_all_by_prop(type => "repository") ) - { - $repos->set_prop("status", - exists $selected{$repos->key} ? 'enabled' : 'disabled'); + $cdb->set_prop("dnf", 'status', $status); + my %selected = map { $_ => 1 } @{ $c->every_param('SelectedRepositories') }; + foreach my $repos ($dbs{repositories}->get_all_by_prop(type => "repository")) { + $repos->set_prop("status", exists $selected{ $repos->key } ? 'enabled' : 'disabled'); } - $dbs{repositories}->reload; - unless ( system( "/sbin/e-smith/signal-event", "dnf-modify" ) == 0 ) - { - return $c->l('yum_ERROR_UPDATING_CONFIGURATION'); + unless (system("/sbin/e-smith/signal-event", "dnf-modify") == 0) { + return $c->l('yum_ERROR_UPDATING_CONFIGURATION'); } - return 'OK'; -} - +} ## end sub change_settings sub do_yum { - my ($c, $function) = @_; - for ( qw(SelectedGroups SelectedPackages) ) - { - $cdb->set_prop("dnf", $_, join(',', (@{$c->every_param($_)} ))); + for (qw(SelectedGroups SelectedPackages)) { + $cdb->set_prop("dnf", $_, join(',', (@{ $c->every_param($_) }))); } + esmith::util::backgroundCommand(0, "/sbin/e-smith/signal-event", "dnf-$function"); - esmith::util::backgroundCommand(0, - "/sbin/e-smith/signal-event", "dnf-$function"); - - for ( qw(available installed updates) ) { - $dbs{$_}->reload; + for (qw(available installed updates)) { + $dbs{$_}->reload; } - return 'OK'; -} - +} ## end sub do_yum sub get_yum_status_page { - my ($c) = @_; my $yum_status; - open(YUM_STATUS, "; close(YUM_STATUS); - return $yum_status; -} - +} ## end sub get_yum_status_page sub format_yum_log { - my $c = shift; - $cdb->reload; - my $filepage = $cdb->get_prop('dnf', 'LogFile'); - return '' unless $filepage and ( -e "$filepage" ); - + return '' unless $filepage and (-e "$filepage"); my $out = sprintf "

    ";
    -    open (FILE, "$filepage");
    +    open(FILE, "$filepage");
    +
         while () {
    -	$out .= sprintf("%s", $_);
    +        $out .= sprintf("%s", $_);
         }
         close FILE;
         $out .= sprintf "
    "; - undef $filepage; return $out; -} - +} ## end sub format_yum_log sub post_upgrade_reboot { - my $c = shift; - $cdb->get_prop_and_delete('dnf', 'LogFile'); $cdb->reload; @@ -565,17 +444,13 @@ sub post_upgrade_reboot { exec "/sbin/e-smith/signal-event post-upgrade; /sbin/e-smith/signal-event reboot"; die "Exec failed"; } - - return 'OK' -} - + return 'OK'; +} ## end sub post_upgrade_reboot sub show_yum_log { - my $c = shift; - my $out = $c->format_yum_log(); + my $c = shift; + my $out = $c->format_yum_log(); my $yum_log = $cdb->get_prop_and_delete('dnf', 'LogFile'); return $out; -} - - +} ## end sub show_yum_log 1; diff --git a/smeserver-manager.spec b/smeserver-manager.spec index b11998e..30a2b0e 100644 --- a/smeserver-manager.spec +++ b/smeserver-manager.spec @@ -2,7 +2,7 @@ Summary: Sme server navigation module : manager 2 %define name smeserver-manager Name: %{name} %define version 11.0.0 -%define release 38 +%define release 39 Version: %{version} Release: %{release}%{?dist} License: GPL @@ -115,6 +115,9 @@ true %defattr(-,root,root) %changelog +* Tue Jan 14 2025 Brian Read 11.0.0-39.sme +- Apply perltidy to all Controller files, add .perltidy to directory and .gitignore for .tdy files (just incase) [SME: 12485] + * Sat Jan 11 2025 Brian Read 11.0.0-38.sme - Fix password reset for admin in user panel [SME: 12655]