jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [networks/] [setup.pl] - Blame information for rev 27

 

Line No. Rev Author Line
11simandl#!/usr/bin/env perl
2 
3use warnings;
4use diagnostics;
5 
6use lib "../../lib";
7use HotSaNICparser;
8use HotSaNICshellio;
9 
10my @CONFmod=HotSaNICparser::read_settings(".",$MODNAME);
11 
12if ( ! -e "settings" ) { $OUTFILE="settings"; } else { $OUTFILE="settings.new"; }
13 
14open OUTFILE,">$OUTFILE" || die "could not open $MODNAME settings file for writing.\n";
15 
16print OUTFILE "# SHORT DESCRIPTION
17#
18# path to iptables or ipchains command
19#
20";
21 
22if ($OUTFILE eq "settings.new") {
23 for (@CONFmod) { print OUTFILE $_,"\n" if /^IPTABLES/; }
24 }
25else {
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 
34print 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 
41if ($OUTFILE eq "settings.new") {
42 for (@CONFmod) { print OUTFILE $_,"\n" if /^STYLE/; }
43 }
44else {
45 print OUTFILE "STYLE=bytes\n";
46 }
47 
48print 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 
55if ($OUTFILE eq "settings.new") {
56 for (@CONFmod) { print OUTFILE $_,"\n" if /^EXTIF/; }
57 for (@CONFmod) { print OUTFILE $_,"\n" if /^INTIF/; }
58 }
59else {
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 
86print 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 
94if ($OUTFILE eq "settings.new") {
95 for (@CONFmod) { print OUTFILE $_,"\n" if /^DEVINT/; }
96}
97 
98print 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 
106if ($OUTFILE eq "settings.new") {
107 for (@CONFmod) { print OUTFILE $_,"\n" if /^DEVEXT/; }
108}
109 
110close OUTFILE;
111 
112if ($OUTFILE eq "settings.new") {
113 HotSaNICparser::backup_file("settings");
114 rename "settings.new","settings";
115 }
116 
117print "Please check the settings file and adapt it to satisfy your needs.\n";
118 

Powered by WebSVN 2.2.1