1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | |
3 | | | # $Id: setup.pl,v 1.10 2004/07/12 07:50:14 bernisys Exp $ |
4 | | | |
5 | | | # include PERL libraries |
6 | | | use strict; |
7 | | | use warnings; |
8 | | | use diagnostics; |
9 | | | |
10 | | | # include HotSaNIC libraries |
11 | | | use lib "../../lib"; |
12 | | | use lib "./platform"; |
13 | | | use HotSaNICparser; |
14 | | | use HotSaNICshellio; |
15 | | | use HotSaNIClog; |
16 | | | use common; |
17 | | | |
18 | | | $|=1; |
19 | | | |
20 | | | (my $VERSION = '$Revision: 1.10 $') =~ s/.*(\d+\.\d+).*/$1/; |
21 | | | (my $IDENTIFIER = '$Id: setup.pl,v 1.10 2004/07/12 07:50:14 bernisys Exp $') =~ s/.*,v (.*) \$/$1/; |
22 | | | |
23 | | | my $MODNAME=HotSaNICparser::get_module_name(); |
24 | | | my %MODCONF=HotSaNICmod::common::configure(); |
25 | | | my $OUTFILE="settings.new"; |
26 | | | if ( ! -e "settings" ) { $OUTFILE="settings"; } |
27 | | | open OUTFILE,">$OUTFILE" || die "could not open ".HotSaNICparser::get_module_name()." settings file for writing.\n"; |
28 | | | |
29 | | | if ( ($MODCONF{INTIF} eq "") or ($MODCONF{EXTIF} eq "") ) { ($MODCONF{INTIF},$MODCONF{EXTIF})=get_interfaces(); } |
30 | | | if (@{$MODCONF{DEVINT}}) { $MODCONF{DEVINT}="DEVINT=\"".join("\"\nDEVINT=\"",@{$MODCONF{DEVINT}})."\""; } |
31 | | | if (@{$MODCONF{DEVEXT}}) { $MODCONF{DEVEXT}="DEVEXT=\"".join("\"\nDEVEXT=\"",@{$MODCONF{DEVEXT}})."\""; } |
32 | | | |
33 | | | print OUTFILE "# SHORT DESCRIPTION |
34 | | | # |
35 | | | # path to iptables or ipchains command |
36 | | | # |
37 | | | IPTABLES=\"$MODCONF{IPTABLES}\" |
38 | | | |
39 | | | # Which kind of legend shall be used |
40 | | | # set GRAPH_BASE=\"bytes\" to display all values in bytes/s |
41 | | | # set GRAPH_BASE=\"bits\" to display all values in bits/s |
42 | | | # |
43 | | | # This item was previously named \"STYLE\" |
44 | | | # |
45 | | | GRAPH_BASE=\"$MODCONF{GRAPH_BASE}\" |
46 | | | |
47 | | | # list of interfaces for internal / external hosts |
48 | | | # INTIF=<interfaces connected to your local network (intranet)> |
49 | | | # EXTIF=<interfaces connected to the internet> |
50 | | | # |
51 | | | INTIF=\"$MODCONF{INTIF}\" |
52 | | | EXTIF=\"$MODCONF{EXTIF}\" |
53 | | | |
54 | | | # list hosts on INTERNAL devices here, multiple lines of the form: |
55 | | | # DEVINT=\"<host>,<description>\" |
56 | | | # DEVINT=\"!<host>,<description>\" |
57 | | | # DEVINT=\"<network>/<netmask>,<description>\" |
58 | | | # DEVINT=\"!<network>/<netmask>,<description>\" |
59 | | | # |
60 | | | $MODCONF{DEVINT} |
61 | | | |
62 | | | # list hosts on EXTERNAL devices here, multiple lines of the form: |
63 | | | # DEVEXT=\"<host>,<description>\" |
64 | | | # DEVEXT=\"!<host>,<description>\" |
65 | | | # DEVEXT=\"<network>/<netmask>,<description>\" |
66 | | | # DEVEXT=\"!<network>/<netmask>,<description>\" |
67 | | | # |
68 | | | $MODCONF{DEVEXT} |
69 | | | "; |
70 | | | |
71 | | | close OUTFILE; |
72 | | | |
73 | | | if ($OUTFILE eq "settings.new") { |
74 | | | HotSaNICparser::backup_file("settings"); |
75 | | | rename "settings.new","settings"; |
76 | | | } |
77 | | | |
78 | | | print "Please check the settings file and adapt it to satisfy your needs.\n"; |
79 | | | |
80 | | | sub get_interfaces { |
81 | | | my $INT=""; |
82 | | | my $EXT=""; |
83 | | | print "Configuring local interfaces. |
84 | | | (i)nternal means an interface pointiong to your local machines (intranet) |
85 | | | (e)xternal means an interface connecten with the internet |
86 | | | (n)one means you don't want to account this interface.\n"; |
87 | | | open LIST,"ifconfig|"; |
88 | | | while (<LIST>) { |
89 | | | if (/^[^\s]/) { |
90 | | | my ($interface)=split; |
91 | | | print "found $interface - (i)nternal, (e)xternal or (n)one?"; |
92 | | | my $input=lc HotSaNICshellio::readkey_list("ien","n"); |
93 | | | if ($input eq "i") { |
94 | | | if ($INT ne "") { $INT=$INT.",$interface"; } |
95 | | | else { $INT=$interface; } |
96 | | | } |
97 | | | elsif ($input eq "e") { |
98 | | | if ($EXT ne "") { $EXT=$EXT.",$interface"; } |
99 | | | else { $EXT=$interface; } |
100 | | | } |
101 | | | } |
102 | | | } |
103 | | | return ($INT,$EXT); |
104 | | | } |
105 | | | |
106 | | | |