#!/usr/bin/perl

#    Copyright (c) 2008 Dominique Dumont.
#
#    This file is part of Config-Model-OpenSsh.
#
#    Config-Model is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Lesser Public License as
#    published by the Free Software Foundation; either version 2.1 of
#    the License, or (at your option) any later version.
#
#    Config-Model 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
#    Lesser Public License for more details.
#
#    You should have received a copy of the GNU Lesser Public License
#    along with Config-Model; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
#    02110-1301 USA

use strict ;
use warnings ;

my @command = (qw/config-edit -model Sshd/, @ARGV) ;

# print "Calling @command\n";

# workaround Augeas locale bug
if ($ENV{LC_ALL} ne 'C' or $ENV{LANG} ne 'C') {
  $ENV{LC_ALL} = $ENV{LANG} = 'C';
}

exec(@command)
  or die "Cannot call config-edit: $!\nIs Config::Model installed ?\n";

__END__

=head1 NAME

config-edit-sshd - Edit data of /etc/ssh/sshd_config

=head1 SYNOPSIS

  # most users will want to run
  config-edit-sshd [options] [ commands  ... ]

  # if you don't have a X server
  config-edit-sshd -ui curses [options] [ commands  ... ]

  # if you don't like curses
  config-edit-sshd -ui shell [options] [ commands  ... ]

  # if you are a sys admin
  config-edit-sshd -ui none [options]  commands  ... 

  # example:
  config-edit-sshd -ui none -write_conf_dir /tmp AllowUsers=foo,bar,baz
  cat /tmp/sshd_config

=head1 DESCRIPTION

This program will edit the configuration data contained in
F</etc/ssh/sshd_config>.

You can specify commands as arguments that will be run on the
configuration root before launching the UI. These command follow the
syntax defined in L<Config::Model::Loader>.

=head1 Options

=over

=item -ui

Specify the user interface type. 

=over

=item *

C<tk>: provides a Tk graphical interface (If L<Config::Model::TkUI> is
installed).

=item *

C<curses>: provides a curses user interface (If
L<Config::Model::CursesUI> is installed).

=item *

C<shell>: provides a shell like interface.  See L<Config::Model::TermUI>
for details.

=item *

C<none>: No UI provided. Only command line arguments are handled.

=back

=item -write_conf_dir

Specify where to write the configuration files. By default
F</etc/ssh/sshd_config> will be written.

=item -read_conf_dir

Specify where to read the configuration files. F</etc/ssh/sshd_config>
by default.

=item -verbose

Be (very) verbose

=item -debug

Provide debug infos.

=item -trace

Provides a full stack trace when exiting on error.

=item -force-load

Load file even if error are found in data. Bad data are discarded

=item -backend

Read/Write backend to use. Currently 2 backends are possible:

=over

=item *

C<custom> backend. Supported, but this backend will discard all
comments in F<sshd_config>

=item *

C<augeas>: Will keep comments. Requires
Config::Model::Backend::Augeas.

=back

=back

=cut

=head1 CAVEATS

Original structure and comments of F</etc/sshd/config> are lost during
edition if Config::Model::Backend::Augeas and its dependencies are
not installed.

=head1 BUGS

Augeas backend will probably fail with C<sshd> Match blocks.

=head1 SUPPORT

For support, please check the following ressources:

=over

=item *

The config-model wiki: L<http://config-model.wiki.sourceforge.net/>

=item *

The config-model users mailing list:
L<http://lists.sourceforge.net/mailman/listinfo/config-model-users>

=back

=head1 AUTHOR

Dominique Dumont, ddumont at cpan dot org

=head1 SEE ALSO

L<config-edit>, L<Config::Model>

=cut




