#!/usr/bin/perl # Drakwizard # Copyright (C) 2002,2005 Mandriva # # Authors: antoine Ginies # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package MDK::Wizard::Sshd; use strict; use common; use services; use MDK::Wizard::Wizcommon; use Libconf::Templates; use Libconf::Glueconf::Networking::Sshd_config; my $wiz = new MDK::Wizard::Wizcommon; my $conf = "/etc/ssh/sshd_config"; my $DOMAINNAME = chomp_(`dnsdomainname`); my $SHORTHOSTNAME = chomp_(`hostname -s`); # we ask glueconf to give us the structure representing /etc/ssh/sshd_config my $sshd = new Libconf::Glueconf::Networking::Sshd_config({ filename => '/etc/ssh/sshd_config' }); # ------ debug use Data::Dumper; print Dumper($sshd); my $o = { name => 'SSH wizard', var => { wiz_port => '', }, init => sub { test_host_domain($SHORTHOSTNAME, $DOMAINNAME); }, needed_rpm => [ 'openssh-server' ], defaultimage => "/usr/share/wizards/sshd_wizard/images/sshd.png" }; $::Wizard_pix_up = "/usr/share/wizards/sshd_wizard/images/IC-Dssh-48.png"; my @yesorno = qw(yes no); push @yesorno, ""; my @yesnoother = qw(yes no without-password forced-commands-only); push @yesnoother, ""; my @syslog = qw(DAEMON USER AUTH LOCAL0 LOCAL1 LOCAL2 LOCAL3 LOCAL4 LOCAL5 LOCAL6 LOCAL7); push @syslog, ""; my @loglevel = qw(QUIET FATAL ERROR INFO VERBOSE DEBUG DEBUG1 DEBUG2 DEBUG3); push @loglevel, ""; my %type = ( 1 => N('Newbie - classical options'), 2 => N('Expert - advanced ssh options'), ); $o->{pages} = { welcome => { name => N('OpenSSH daemon configuration') . "\n\n" . N("Which type of configuration do you want to do:"), data => [ { label => "", type => 'list', val => \$o->{var}{wiz_type}, list => [ keys %type ], format => sub { $type{$_[0]} } }, ], next => 'config_step1', no_back => 1, }, config_step1 => { name => N('SSH server, classical options'), pre => sub { $sshd->{ListenAddress} and $o->{var}{ListenAddress} = $sshd->{ListenAddress} or $o->{var}{ListenAddress} = "0.0.0.0"; $sshd->{Port} and $o->{var}{Port} = $sshd->{Port} or $o->{var}{Port} = "22"; $o->{var}{PermitRootLogin} ||= $sshd->{PermitRootLogin}; }, data => [ { label => N('Permit root login:'), val => \$o->{var}{PermitRootLogin}, fixed_list => \@yesnoother }, { label => N('Listen address:'), val => \$o->{var}{ListenAddress}, help => N('Specifies the local addresses sshd should listen on.') }, { label => N('Port number:'), val => \$o->{var}{Port}, help => N('Specifies the port number that sshd listens on. The default is 22.') }, ], complete => sub { if ($o->{var}{Port} !~ /^\d+$/) { $::in->ask_warn(N('Error'), N('Port should be a number')); return 1; } }, post => sub { if ($o->{var}{wiz_type} == 2) { return 'auth_options' } elsif ($o->{var}{wiz_type} == 1) { return 'summary' } }, next => 'auth_options', }, auth_options => { name => N('Authentication Method'), pre => sub { $o->{var}{RSAAuthentication} ||= $sshd->{RSAAuthentication}; $o->{var}{PubkeyAuthentication} ||= $sshd->{PubkeyAuthentication}; $sshd->{AuthorizedKeysFile} and $o->{var}{AuthorizedKeysFile} = $sshd->{AuthorizedKeysFile} or $o->{var}{AuthorizedKeysFile} = ".ssh/authorized_keys2"; $o->{var}{PasswordAuthentication} ||= $sshd->{PasswordAuthentication}; $o->{var}{IgnoreRhosts} ||= $sshd->{IgnoreRhosts}; $o->{var}{PermitEmptyPasswords} ||= $sshd->{PermitEmptyPasswords}; }, data => [ { label => N('RSA auth:'), val => \$o->{var}{RSAAuthentication}, fixed_list => \@yesorno }, { label => N('PubKey auth:'), val => \$o->{var}{PubkeyAuthentication}, fixed_list => \@yesorno }, { label => N('Auth key file:'), val => \$o->{var}{AuthorizedKeysFile} }, { label => N('Password auth:'), val => \$o->{var}{PasswordAuthentication}, fixed_list => \@yesorno }, { label => N('Ignore rhosts file:'), val => \$o->{var}{IgnoreRhosts}, fixed_list => \@yesorno }, { label => N('Permit empty password:'), val => \$o->{var}{PermitEmptyPasswords}, fixed_list => \@yesorno }, ], next => 'log_options', }, log_options => { name => N('Log') . "\n\n" . N('Syslog facility: gives the facility code that is used when logging messages from sshd') . "\n" . N('Log level: gives the verbosity level that is used when logging messages from sshd.'), pre => sub { $o->{var}{SyslogFacility} ||= $sshd->{SyslogFacility}; $o->{var}{LogLevel} ||= $sshd->{LogLevel}; }, data => [ { label => N('Syslog facility:'), val => \$o->{var}{SyslogFacility}, fixed_list => \@syslog }, { label => N('Log level:'), val => \$o->{var}{LogLevel}, fixed_list => \@loglevel }, ], next => 'login_options', }, login_options => { name => N('Login options') . "\n\n" . N('Print last log: whether sshd should print the date and time when the user last logged in'), pre => sub { $o->{var}{LoginGraceTime} ||= $sshd->{LoginGraceTime}; $o->{var}{KeepAlive} ||= $sshd->{KeepAlive}; $o->{var}{PrintMotd} ||= $sshd->{PrintMotd}; $o->{var}{PrintLastLog} ||= $sshd->{PrintLastLog}; }, data => [ { label => N('Login Grace time:'), val => \$o->{var}{LoginGraceTime}, help => N('The server disconnects after this time if the user has not successfully logged in. If the value is 0, there is no time limit. The default is 120 seconds.') }, { label => N('Keep alive:'), val => \$o->{var}{KeepAlive}, fixed_list => \@yesorno }, { label => N('Print motd:'), val => \$o->{var}{PrintMotd}, fixed_list => \@yesorno }, { label => N('Print last log:'), val => \$o->{var}{PrintLastLog}, fixed_list => \@yesorno }, ], complete => sub { if ($o->{var}{LoginGraceTime} !~ /^\d+$/ and $o->{var}{LoginGraceTime}) { $::in->ask_warn(N('Error'), N('Login grace time should be a number')); return 1; } }, next => 'user_login', }, user_login => { name => N('User Login options') . "\n\n" . N('Strict modes: specifies whether sshd should check file modes and ownership of the user\'s files and home directory before accepting login. This is normally desirable because novices sometimes accidentally leave their directory or files world-writable'), pre => sub { $o->{var}{StrictModes} ||= $sshd->{StrictModes}; $o->{var}{AllowUsers} ||= $sshd->{AllowUsers}; $o->{var}{DenyUsers} ||= $sshd->{DenyUsers}; }, data => [ { label => N('Strict modes:'), val => \$o->{var}{StrictModes}, fixed_list => \@yesorno }, { label => N('Allow users:'), val => \$o->{var}{AllowUsers}, help => N('If specified, login is allowed only for user names that match one of the patterns. ie: erwan aginies guibo') }, { label => N('Deny users:'), val => \$o->{var}{DenyUsers}, help => N('Login is disallowed for user names that match one of the patterns. ie: pirate guillomovitch') }, ], next => 'other', }, other => { name => N('Compression: Specifies whether compression is allowed.') . "\n" . N('X11 forwarding: specifies whether X11 forwarding is permitted. Note that disabling X11 forwarding does not prevent users from forwarding X11 traffic, as users can always install their own forwarders.'), pre => sub { $o->{var}{Compression} ||= $sshd->{Compression}; $o->{var}{X11Forwarding} ||= $sshd->{X11Forwarding}; }, data => [ { label => N('Compression:'), val => \$o->{var}{Compression}, fixed_list => \@yesorno }, { label => N('X11 forwarding:'), val => \$o->{var}{X11Forwarding}, fixed_list => \@yesorno }, ], next => 'summary', }, summary => { name => N('Summary of OpenSSH configuration.'), data => [ { label => N('Permit root login:'), fixed_val => \$o->{var}{PermitRootLogin} }, { label => N('Listen address:'), fixed_val => \$o->{var}{ListenAddress} }, { label => N('Port number:'), fixed_val => \$o->{var}{Port} }, ], post => \&do_it, next => 'end', }, end => { name => N('Congratulations') . "\n\n" . N('The wizard successfully configured your SSH server.'), no_back => 1, end => 1, next => 0 }, error_end => { name => N("Failed"), data => [ { label => N("Please relaunch drakwizard, and try to change some parameters.") } ], no_back => 1, end => 1, next => 0, }, }; sub new { my ($class, $conf) = @_; bless $o, $class; } sub write_conf_restart_ssh { $sshd->write_conf($conf); if (services::is_service_running('sshd')) { services::restart('sshd') } else { services::start('sshd') } } sub global_config { $sshd->{Port} = $o->{var}{Port}; # force sshd protocol 2 $sshd->{Protocol} and $o->{var}{Protocol} = $sshd->{Protocol} or $o->{var}{Protocol} = "2"; $o->{var}{ListenAddress} and $sshd->{ListenAddress} = $o->{var}{ListenAddress}; $o->{var}{SyslogFacility} and $sshd->{SyslogFacility} = $o->{var}{SyslogFacility}; $o->{var}{LogLevel} and $sshd->{LogLevel} = $o->{var}{LogLevel}; $o->{var}{PermitRootLogin} and $sshd->{PermitRootLogin} = $o->{var}{PermitRootLogin}; $o->{var}{StrictModes} and $sshd->{StrictModes} = $o->{var}{StrictModes}; $o->{var}{AllowUsers} and $sshd->{AllowUsers} = $o->{var}{AllowUsers}; $o->{var}{DenyUsers} and $sshd->{DenyUsers} = $o->{var}{DenyUsers}; $o->{var}{LoginGraceTime} and $sshd->{LoginGraceTime} = $o->{var}{LoginGraceTime}; $o->{var}{KeepAlive} and $sshd->{KeepAlive} = $o->{var}{KeepAlive}; $o->{var}{PrintMotd} and $sshd->{PrintMotd} = $o->{var}{PrintMotd}; $o->{var}{PrintLastLog} and $sshd->{PrintLastLog} = $o->{var}{PrintLastLog}; $o->{var}{RSAAuthentication} and $sshd->{RSAAuthentication} = $o->{var}{RSAAuthentication}; $o->{var}{PubkeyAuthentication} and $sshd->{PubkeyAuthentication} = $o->{var}{PubkeyAuthentication}; $o->{var}{AuthorizedKeysFile} and $sshd->{AuthorizedKeysFile} = $o->{var}{AuthorizedKeysFile}; $o->{var}{PasswordAuthentication} and $sshd->{PasswordAuthentication} = $o->{var}{PasswordAuthentication}; $o->{var}{IgnoreRhosts} and $sshd->{IgnoreRhosts} = $o->{var}{IgnoreRhosts}; $o->{var}{PermitEmptyPasswords} and $sshd->{PermitEmptyPasswords} = $o->{var}{PermitEmptyPasswords}; $o->{var}{X11Forwarding} and $sshd->{X11Forwarding} = $o->{var}{X11Forwarding}; $o->{var}{Compression} and $sshd->{Compression} = $o->{var}{Compression}; #$sshd->{UsePrivilegeSeparation} yes } sub do_it { $::testing and return; # display a wait dialog box my $in = 'interactive'->vnew('su', 'SSH'); my $w = $in->wait_message(N("OpenSSH server"), N("Configuring your OpenSSH server...")); global_config(); write_conf_restart_ssh(); # remove wait message undef $w; check_started('sshd'); } 1;