Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | magnus | 1 | #!/usr/bin/perl -w |
2 | # |
||
3 | # debconf config script for lsh-server |
||
4 | # |
||
5 | # Copyright (c) 2000, 2001, 2002 Timshel Knoll <timshel@debian.org> |
||
6 | # This program is free software; you can redistribute it and/or modify |
||
7 | # it under the terms of the GNU General Public License as published by |
||
8 | # the Free Software Foundation; either version 2 of the License, or |
||
9 | # (at your option) any later version. |
||
10 | # |
||
11 | # This program is distributed in the hope that it will be useful, |
||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | # GNU General Public License for more details. |
||
15 | # |
||
16 | # You should have received a copy of the GNU General Public License |
||
17 | # along with this program; if not, write to the Free Software |
||
18 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
19 | # |
||
20 | # On Debian systems, see /usr/share/common-licenses/GPL for the GNU GPL. |
||
21 | # |
||
22 | use strict; |
||
23 | use Debconf::Client::ConfModule ':all'; |
||
24 | |||
25 | |||
26 | sub ask_whether_to_purge_hostkey { |
||
27 | &input ("medium", "lsh-server/purge_hostkey"); |
||
28 | my @ret = &go (); |
||
29 | |||
30 | return ($ret[0] == 30 ? -1 : 1); |
||
31 | } |
||
32 | |||
33 | |||
34 | sub get_lshd_port { |
||
35 | &input ("medium", "lsh-server/lshd_port"); |
||
36 | my @ret = &go (); |
||
37 | |||
38 | my $port = &get ("lsh-server/lshd_port"); |
||
39 | |||
40 | if ($port and $port !~ m/^\d+$/) { |
||
41 | $port = (getservbyname ($port, "tcp"))[2]; |
||
42 | } |
||
43 | |||
44 | unless ($port) { |
||
45 | # invalid service entered: wasn't a number, and |
||
46 | # getservbyname failed, try again ... |
||
47 | # FIXME: try putting some sort of error message here? |
||
48 | &reset ("lsh-server/lshd_port"); |
||
49 | return 0; |
||
50 | } |
||
51 | |||
52 | return ($ret[0] == 30 ? -1 : 1); |
||
53 | } |
||
54 | |||
55 | |||
56 | |||
57 | sub ask_whether_to_enable_sftp { |
||
58 | &input ("medium", "lsh-server/sftp"); |
||
59 | my @ret = &go (); |
||
60 | |||
61 | return ($ret[0] == 30 ? -1 : 1); |
||
62 | } |
||
63 | |||
64 | |||
65 | sub configure () { |
||
66 | my $state = 0; |
||
67 | |||
68 | # The list of things to do, in order |
||
69 | # Aren't really long, descriptive function names fun ;-) |
||
70 | my @states = ( |
||
71 | \&ask_whether_to_purge_hostkey, |
||
72 | \&get_lshd_port, |
||
73 | \&ask_whether_to_enable_sftp |
||
74 | ); |
||
75 | |||
76 | # This is 1 or -1, depending on whether we're going forward or backward |
||
77 | # Required because otherwise when we back up to a question doesn't need |
||
78 | # to be asked, the engine will go forward again :-( |
||
79 | my $step = 1; |
||
80 | |||
81 | until ($state > $#states) { |
||
82 | if ($state < 0) { |
||
83 | $state = 0; |
||
84 | # We may have got here because of "backing up" to a question which |
||
85 | # was skipped, so make sure we're going forward from here to avoid |
||
86 | # an infinite loop |
||
87 | $step = 1; |
||
88 | } |
||
89 | |||
90 | $step = &{ $states[$state] } ($step); |
||
91 | |||
92 | $state += $step; |
||
93 | } |
||
94 | } |
||
95 | |||
96 | |||
97 | |||
98 | die "Syntax error: no argument" if (@ARGV <= 0); |
||
99 | |||
100 | version ('2.0'); |
||
101 | |||
102 | my $capb = &capb ('backup'); |
||
103 | |||
104 | if ($ARGV[0] eq "configure" || $ARGV[0] eq "reconfigure") { |
||
105 | &configure (); |
||
106 | } |
||
107 | |||
108 | |||
109 |