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