#!/usr/bin/perl

# Drakwizard

# Copyright (C) 2003 Mandrakesoft 
#
# Author: Florent Villard <warly@mandrakesoft.com>
#
# 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.

use lib qw(/usr/lib/libDrakX);
use strict;
use wizards;

use standalone;
use interactive;
use common;

#- I18N.
push @::textdomains, 'drakwizard';

$::isWizard = 1;
$::Wizard_no_previous = 1;
$::Wizard_title = "Drakwizard";
$::Wiz_dir = '/usr/share/wizards/';
$::Wiz_more_dir = "/etc/wizard.d/";
my $in = interactive->vnew;

my %all_wizards = (
    apache2 => [ 'Apache', N("Apache2 web server"), { ver => 2 } ],
#    samba => [ 'Samba', N("Samba server") ],
#    sambashare => [ 'Sambashare', N("Manage Samba share") ],
#    sambaprint => [ 'Sambaprint', N("Manage Samba print") ], # user should use draksambashare
#    postfix => [ 'Postfix', N("Mail server") ],
#    if_(member('proxy_wizard', all($::Wiz_dir)),
#        nisautofs => [ 'Nisautofs', N("NIS server autofs map") ],
#        installsrv => [ 'Installsrv', N("Linux Install server") ],
#        ldap => [ 'Ldap', N("ldap server") ],
        squid => [ 'Squid', N("Proxy") ],
        sshd => [ 'Sshd', N("OpenSSH daemon configuration") ],
        ntp => [ 'Ntp', N("Time server") ],
        dhcp => [ 'Dhcp', N("DHCP server") ],
        bind => [ 'Bind', N("DNS server") ],
#        inn => [ 'Inn', N("News server") ],
#        nfs => [ 'NFS', N("NFS server") ],
#        kolab => [ 'Kolab', N("Kolab server") ],
        proftpd => [ 'Proftpd', N("FTP server") ],
);

foreach my $file (glob_("$::Wiz_more_dir/*.conf")) {
	next unless -f $file;
	my %tmp=getVarsFromSh($file);
	$all_wizards{lc($file)} = [ $tmp{NAME}, $tmp{DESCRIPTION} ];
}

@ARGV = grep { ! /^--/ } @ARGV;
if (!defined($all_wizards{$ARGV[0]})) {
    $in->ask_from(
		  N("Drakwizard wizard selection"),
		  N("Please select a wizard"),
		  [ { val => \$ARGV[0], list => [ sort { $all_wizards{$a}[1] cmp $all_wizards{$b}[1] } keys %all_wizards ], format => sub { $all_wizards{$_[0]}[1] } } ]
		 );
    push @ARGV, @{$all_wizards{$ARGV[0]}}[0,2];
}

require "MDK/Wizard/$all_wizards{$ARGV[0]}[0].pm";

my ($wiz, $err) = "MDK::Wizard::$all_wizards{$ARGV[0]}[0]"->new($all_wizards{$ARGV[0]}[2]);
if ($err) {
    $::Wizard_finished = 1;
    $in->ask_okcancel(N("Error"), translate($err));
    $in->exit;
}

my $wizard = wizards->new($wiz);
$wizard->safe_process($in);
$in->exit;