summaryrefslogtreecommitdiffstats
path: root/server_wizard.pl
blob: c6365a59b9170c1d04ae73d9b000749615d785f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/perl
#
#
#
# Copyright (c) 2002 ...
#

use lib qw(/usr/lib/libDrakX);
use strict;
use vars qw($wizard_title $lib_script %variable $in);

use XML::Parser;

use standalone;
use interactive;

sub translate { $_[0] }

sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 }

sub get_parameter {
    my ($o, $tree, $tag ,$page) = @_;
    foreach my $leaf (@$tree) {
	if (ref($leaf) eq 'ARRAY') {
	    get_parameter($o, $leaf, $tag, $page);
	} elsif (ref($leaf) eq 'HASH') {
	   my $common_freetext_chooser;
	   my %actions = (Wizard => sub {
			       ($wizard_title, $lib_script) = @{$leaf}{qw(wizardTitle libScript)};
			   },
			   Variable => sub {
			       $variable{$leaf->{name}} = $leaf->{shellVariable};
			       $ENV{$leaf->{shellVariable}} = $leaf->{defaultValue};
			   },
			   Page => sub {
			       my $old_page = $page;
			       push @$o, $page = { %$leaf };
			       $old_page->{next_page} = $page;
			   },
			   Target => sub {
			       $page->{$leaf->{jumpIndex} > 3 ? 'targetOK' : 'targetNOK'} = $leaf->{targetName};
			   },
			   Info => sub {
			       $page->{info} = $leaf->{helpText} ? "$page->{info} $leaf->{helpText}" : "$page->{info}\n";
			   },
			   Freetext => $common_freetext_chooser = sub { 
			       push @{$page->{freetext}}, { %$leaf, main_order => ($tag eq 'Chooser') ? 'combo' : 'entry' };
			   },
			   Chooser => \&$common_freetext_chooser);
	    $actions{$tag} and &{$actions{$tag}};
	    undef $tag;
	} else {
	    $tag = $leaf;
	}
    }
}


sub find_page {
    my ($o, $name) = @_;
    $_->{name} eq $name and return $_ foreach @$o;
}

sub display {
    my ($o, $page) = @_;
    
    if (member($page->{name}, qw(error_need_root done))) {   
	$in->ask_okcancel(translate($page->{name}),
			  translate($page->{info}), 1) or quit_global($in, 0);
	exit 0;
    } elsif (!$page->{main_order}) {
	$in->ask_okcancel(translate($page->{name}),
			  translate($page->{info}), 1) or navigation($o, $page->{old_page});
    } else {
	my @data = map {
	    for ($_->{fillScript}) {
		m,^\s*echo|/,  and system("source $lib_script ; $_");
		/^(\S*) (.*)$/ and system("source $lib_script ; $1($2)");
	    }
	    { label => translate($_->{helpText}),
		val => \$ENV{$variable{$_->{variableName}}}, type => $_->{main_order} };
	} @{$page->{freetext}};

	$in->ask_from(translate($page->{name}), translate($page->{info}), \@data)
	  or navigation($o, $page->{old_page});
    }
    undef $::Wizard_no_previous;
}

sub navigation {
    my ($o, $page, $previous_page) = @_;
    $page->{old_page} ||= $previous_page;
    if ($page->{jumpPage}) {
	navigation($o, $page->{jumpPage}, $page->{old_page});
    } else {
	display($o, $page);

	my ($next, $prev) = do {
	    if($page->{jumpScript}) {
		system("source $lib_script ; $page->{jumpScript}");
		if ($page->{targetOK} && $page->{targetNOK}) {
		    find_page($o, $? == 256 ? $page->{targetNOK} : $page->{targetOK}), $page;
		} else {
		    $page->{next_page}, $page->{old_page};
		}
	    } else {
		$page->{next_page}, $page;
	    }
	};
	navigation($o, $next, $prev);
    }
}

my $o = [];
get_parameter($o, XML::Parser->new(Style => 'Tree')->parsefile("server.wiz"));

$in = 'interactive'->vnew;

!$::isEmbedded && $in->isa('interactive_gtk') and $::isWizard=1;
$::Wizard_title = translate($wizard_title);
$::Wizard_pix_up = "wiz_draknet.png";
$::direct = /-direct/;
$::Wizard_no_previous = 1;

navigation($o, $o->[0]);