From 069680acc102ac9bfa6a656ecd75b3bdb65f80d1 Mon Sep 17 00:00:00 2001 From: ms Date: Thu, 21 Dec 2006 18:38:37 +0000 Subject: [PATCH] Netzwerkscript beinahe vollendet. Setup bearbeitet. (Geht schon ganz gut.) Sonstiges wie immer... git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@366 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8 --- config/kernel/kernel.config.i586 | 8 +- config/kernel/kernel.config.i586.smp | 8 +- config/kernel/syslinux.cfg | 12 +- config/rootfiles/common/Net_SSLeay | 4 +- config/rootfiles/common/dhcpcd | 4 +- config/rootfiles/common/gcc | 6 +- config/rootfiles/common/glibc | 2 +- config/rootfiles/common/stage2 | 4 +- html/cgi-bin/connections.cgi | 12 +- lfs/cdrom | 2 +- lfs/configroot | 3 - lfs/dhcpcd | 4 +- lfs/initrd | 1 + lfs/initscripts | 17 +- lfs/ipp2p | 8 +- lfs/iptables | 4 - lfs/strip | 6 +- src/initscripts/helper/getdnsfromdhcpc.pl | 32 + src/initscripts/helper/writeipac.pl | 55 + src/initscripts/init.d/network | 273 +++- src/initscripts/init.d/red | 1169 +++++++++++++++ src/install+setup/install/install2.c | 415 ------ src/install+setup/install/main.c | 2 +- src/install+setup/setup/keymap.c | 334 ++--- src/install+setup/setup/main.c | 32 +- src/install+setup/setup/networking.c | 1620 +++++++++++---------- src/install+setup/setup/passwords.c | 4 +- src/rc.d/helper/writeipac.pl | 2 +- 28 files changed, 2560 insertions(+), 1483 deletions(-) create mode 100644 src/initscripts/helper/getdnsfromdhcpc.pl create mode 100644 src/initscripts/helper/writeipac.pl create mode 100644 src/initscripts/init.d/red delete mode 100644 src/install+setup/install/install2.c diff --git a/config/kernel/kernel.config.i586 b/config/kernel/kernel.config.i586 index 02629151aa..a01c4d2ade 100644 --- a/config/kernel/kernel.config.i586 +++ b/config/kernel/kernel.config.i586 @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Linux kernel version: 2.6.16 -# Wed Nov 29 00:06:35 2006 +# Tue Dec 12 17:10:37 2006 # CONFIG_X86_32=y CONFIG_SEMAPHORE_SLEEPERS=y @@ -191,6 +191,7 @@ CONFIG_HZ=100 # CONFIG_CRASH_DUMP is not set CONFIG_PHYSICAL_START=0x100000 CONFIG_DOUBLEFAULT=y +CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y # # Power management options (ACPI, APM) @@ -460,6 +461,8 @@ CONFIG_IP_NF_ARPTABLES=m CONFIG_IP_NF_ARPFILTER=m CONFIG_IP_NF_ARP_MANGLE=m CONFIG_IP_NF_TARGET_TARPIT=m +CONFIG_IP_NF_NAT_MMS=m +CONFIG_IP_NF_MMS=m CONFIG_IP_NF_NAT_SIP=m CONFIG_IP_NF_SIP=m @@ -518,7 +521,7 @@ CONFIG_LLC=y # CONFIG_LAPB is not set # CONFIG_NET_DIVERT is not set # CONFIG_ECONET is not set -# CONFIG_WAN_ROUTER is not set +CONFIG_WAN_ROUTER=y # # QoS and/or fair queueing @@ -1255,6 +1258,7 @@ CONFIG_DLCI=m CONFIG_DLCI_COUNT=24 CONFIG_DLCI_MAX=8 CONFIG_SDLA=m +# CONFIG_WAN_ROUTER_DRIVERS is not set CONFIG_SBNI=m CONFIG_SBNI_MULTILINE=y diff --git a/config/kernel/kernel.config.i586.smp b/config/kernel/kernel.config.i586.smp index 7fbcfd46e5..1d510d0d90 100644 --- a/config/kernel/kernel.config.i586.smp +++ b/config/kernel/kernel.config.i586.smp @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Linux kernel version: 2.6.16 -# Wed Nov 29 00:35:50 2006 +# Tue Dec 12 17:10:59 2006 # CONFIG_X86_32=y CONFIG_SEMAPHORE_SLEEPERS=y @@ -200,6 +200,7 @@ CONFIG_HZ=100 CONFIG_PHYSICAL_START=0x100000 # CONFIG_HOTPLUG_CPU is not set CONFIG_DOUBLEFAULT=y +CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y # # Power management options (ACPI, APM) @@ -466,6 +467,8 @@ CONFIG_IP_NF_ARPTABLES=m CONFIG_IP_NF_ARPFILTER=m CONFIG_IP_NF_ARP_MANGLE=m CONFIG_IP_NF_TARGET_TARPIT=m +CONFIG_IP_NF_NAT_MMS=m +CONFIG_IP_NF_MMS=m CONFIG_IP_NF_NAT_SIP=m CONFIG_IP_NF_SIP=m @@ -524,7 +527,7 @@ CONFIG_LLC=y # CONFIG_LAPB is not set # CONFIG_NET_DIVERT is not set # CONFIG_ECONET is not set -# CONFIG_WAN_ROUTER is not set +CONFIG_WAN_ROUTER=y # # QoS and/or fair queueing @@ -1255,6 +1258,7 @@ CONFIG_DLCI=m CONFIG_DLCI_COUNT=24 CONFIG_DLCI_MAX=8 CONFIG_SDLA=m +# CONFIG_WAN_ROUTER_DRIVERS is not set CONFIG_SBNI=m CONFIG_SBNI_MULTILINE=y diff --git a/config/kernel/syslinux.cfg b/config/kernel/syslinux.cfg index ba8af552b0..2afc518562 100644 --- a/config/kernel/syslinux.cfg +++ b/config/kernel/syslinux.cfg @@ -2,19 +2,19 @@ TIMEOUT 5000 DISPLAY message PROMPT 1 DEFAULT vmlinuz -APPEND ide=nodma initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 rw +APPEND ide=nodma initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 vga=791 splash=silent rw LABEL unattended KERNEL vmlinuz - APPEND ide=nodma initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 rw unattended + APPEND ide=nodma initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 vga=791 splash=silent rw unattended LABEL nopcmcia KERNEL vmlinuz - APPEND ide=nodma initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 rw nopcmcia + APPEND ide=nodma initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 vga=791 splash=silent rw nopcmcia LABEL nousb KERNEL vmlinuz - APPEND ide=nodma initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 rw nousb + APPEND ide=nodma initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 vga=791 splash=silent rw nousb LABEL nousborpcmcia KERNEL vmlinuz - APPEND ide=nodma initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 rw nousb nopcmcia + APPEND ide=nodma initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 vga=791 splash=silent rw nousb nopcmcia LABEL dma KERNEL vmlinuz - APPEND initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 rw + APPEND initrd=instroot.gz root=/dev/ram0 ramdisk_size=16384 vga=791 splash=silent rw diff --git a/config/rootfiles/common/Net_SSLeay b/config/rootfiles/common/Net_SSLeay index 1cf07487d3..26e7232a3b 100644 --- a/config/rootfiles/common/Net_SSLeay +++ b/config/rootfiles/common/Net_SSLeay @@ -5,8 +5,8 @@ usr/lib/perl5/site_perl/5.8.8/i586-linux/Net/SSLeay/Handle.pm #usr/lib/perl5/site_perl/5.8.8/i586-linux/auto/Net/SSLeay #usr/lib/perl5/site_perl/5.8.8/i586-linux/auto/Net/SSLeay/.packlist #usr/lib/perl5/site_perl/5.8.8/i586-linux/auto/Net/SSLeay/SSLeay.bs -#sr/lib/perl5/site_perl/5.8.8/i586-linux/auto/Net/SSLeay/SSLeay.so -#usr/lib/perl5/site_perl/5.8.8/i586-linux/auto/Net/SSLeay/autosplit.ix +usr/lib/perl5/site_perl/5.8.8/i586-linux/auto/Net/SSLeay/SSLeay.so +usr/lib/perl5/site_perl/5.8.8/i586-linux/auto/Net/SSLeay/autosplit.ix #usr/lib/perl5/site_perl/5.8.8/i586-linux/auto/Net/SSLeay/debug_read.al #usr/lib/perl5/site_perl/5.8.8/i586-linux/auto/Net/SSLeay/do_https.al #usr/lib/perl5/site_perl/5.8.8/i586-linux/auto/Net/SSLeay/do_https2.al diff --git a/config/rootfiles/common/dhcpcd b/config/rootfiles/common/dhcpcd index 66767b872f..1471b8abf2 100644 --- a/config/rootfiles/common/dhcpcd +++ b/config/rootfiles/common/dhcpcd @@ -1,4 +1,4 @@ -#etc/dhcpc -etc/dhcpc/dhcpcd.exe +#var/ipfire/dhcpc +var/ipfire/dhcpc/dhcpcd.exe sbin/dhcpcd #usr/share/man/man8/dhcpcd.8 diff --git a/config/rootfiles/common/gcc b/config/rootfiles/common/gcc index 5930b50b81..a70b639c77 100644 --- a/config/rootfiles/common/gcc +++ b/config/rootfiles/common/gcc @@ -331,9 +331,9 @@ #usr/lib/libmudflapth.so.0.0.0 #usr/lib/libstdc++.a #usr/lib/libstdc++.la -#usr/lib/libstdc++.so -#usr/lib/libstdc++.so.6 -#usr/lib/libstdc++.so.6.0.7 +usr/lib/libstdc++.so +usr/lib/libstdc++.so.6 +usr/lib/libstdc++.so.6.0.7 #usr/lib/libsupc++.a #usr/lib/libsupc++.la #usr/man/man1/cpp.1 diff --git a/config/rootfiles/common/glibc b/config/rootfiles/common/glibc index 23eb0333a6..5b8d3fafd8 100644 --- a/config/rootfiles/common/glibc +++ b/config/rootfiles/common/glibc @@ -1802,7 +1802,7 @@ usr/lib/locale/locale-archive #usr/share/zoneinfo/WET #usr/share/zoneinfo/Zulu #usr/share/zoneinfo/iso3166.tab -#usr/share/zoneinfo/posix +usr/share/zoneinfo/posix #usr/share/zoneinfo/posix/Africa #usr/share/zoneinfo/posix/Africa/Abidjan #usr/share/zoneinfo/posix/Africa/Accra diff --git a/config/rootfiles/common/stage2 b/config/rootfiles/common/stage2 index e226ccd413..d74a546238 100644 --- a/config/rootfiles/common/stage2 +++ b/config/rootfiles/common/stage2 @@ -43,8 +43,8 @@ tmp #usr/bin/perl #usr/include #usr/lib -#usr/lib/libgcc_s.so -#usr/lib/libgcc_s.so.1 +usr/lib/libgcc_s.so +usr/lib/libgcc_s.so.1 usr/local/bin/connscheduler usr/local/bin/hddshutdown usr/local/bin/hddshutdown-state diff --git a/html/cgi-bin/connections.cgi b/html/cgi-bin/connections.cgi index d6d6fae4fc..a331ad3bcc 100644 --- a/html/cgi-bin/connections.cgi +++ b/html/cgi-bin/connections.cgi @@ -321,13 +321,13 @@ foreach my $line (@active) { $marked = $temp[8]; $offset = 1; } else { - $marked = $temp[12]; + $marked = $temp[16]; } - $exsip = substr $temp[8 + $offset], 4; - $exdip = substr $temp[9 + $offset], 4; - $exsp = substr $temp[10 + $offset], 6; - $exdp = substr $temp[11 + $offset], 6; - $use = substr $temp[13], 4; + $exsip = substr $temp[10 + $offset], 4; + $exdip = substr $temp[11 + $offset], 4; + $exsp = substr $temp[12 + $offset], 6; + $exdp = substr $temp[13 + $offset], 6; + $use = substr $temp[18], 4; } if ($temp[0] eq 'unknown') { my $offset = 0; diff --git a/lfs/cdrom b/lfs/cdrom index 0a82f45771..2a92b380b8 100644 --- a/lfs/cdrom +++ b/lfs/cdrom @@ -85,7 +85,7 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) rm -f /tmp/ROOTFILES tar -x -C /tmp -f /$(SNAME).tar rm -f /$(SNAME).tar - mkdir /tmp/sys + @mkdir /tmp/sys cd /tmp && tar jcf /install/cdrom/$(SNAME)-$(VERSION).tbz2 * && rm -rf * # Other files diff --git a/lfs/configroot b/lfs/configroot index 36d01211c6..2a33bc6233 100644 --- a/lfs/configroot +++ b/lfs/configroot @@ -104,9 +104,6 @@ $(TARGET) : echo "nameserver 1.2.3.4" > $(CONFIG_ROOT)/ppp/fake-resolv.conf echo "DISABLEPING=NO" > $(CONFIG_ROOT)/optionsfw/settings - # Symbolic links - ln -sf /etc/rc.d/rc.updatered $(CONFIG_ROOT)/dhcpc/dhcpcd.exe - # Modify variables in header.pl sed -i -e "s+CONFIG_ROOT+$(CONFIG_ROOT)+g" \ -e "s+VERSION+$(VERSION)+g" \ diff --git a/lfs/dhcpcd b/lfs/dhcpcd index b3ddbbd91e..6ad3b46cfa 100644 --- a/lfs/dhcpcd +++ b/lfs/dhcpcd @@ -72,8 +72,10 @@ $(subst %,%_MD5,$(objects)) : $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) @$(PREBUILD) @rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar jxf $(DIR_DL)/$(DL_FILE) - cd $(DIR_APP) && ./configure --prefix="" --mandir=/usr/share/man --disable-nls + cd $(DIR_APP) && ./configure --prefix="" --sysconfdir=$(CONFIG_ROOT) \ + --mandir=/usr/share/man --disable-nls cd $(DIR_APP) && make $(MAKETUNING) cd $(DIR_APP) && make install + ln -sf /etc/rc.d/init.d/network $(CONFIG_ROOT)/dhcpc/dhcpcd.exe @rm -rf $(DIR_APP) @$(POSTBUILD) diff --git a/lfs/initrd b/lfs/initrd index 35da2464ad..c58a25eb9b 100644 --- a/lfs/initrd +++ b/lfs/initrd @@ -141,5 +141,6 @@ $(TARGET) : cd / && umount /install/mnt && \ losetup -d $$LOOPDEV gzip -9 /install/images/cdinitrd + splash -s -f /boot/splash/config/bootsplash-1024x768.cfg >> /install/images/cdinitrd.gz @$(POSTBUILD) diff --git a/lfs/initscripts b/lfs/initscripts index 0e3064c59f..0a2f92d822 100644 --- a/lfs/initscripts +++ b/lfs/initscripts @@ -55,6 +55,7 @@ $(TARGET) : install -d -m 755 /etc/rc.d/rc6.d install -d -m 755 /etc/rc.d/rcsysinit.d install -d -m 755 /etc/rc.d/init.d + install -d -m 755 /etc/rc.d/helper install -d -m 755 /etc/sysconfig for i in $(DIR_SRC)/src/initscripts/init.d/*; do \ @@ -66,6 +67,10 @@ $(TARGET) : install -v -m 644 $$i /etc/sysconfig/; \ done + for i in $(DIR_SRC)/src/initscripts/helper/*; do \ + install -v -m 755 $$i /etc/rc.d/helper/; \ + done + ln -sf ../init.d/sysklogd /etc/rc.d/rc0.d/K90sysklogd ln -sf ../init.d/sendsignals /etc/rc.d/rc0.d/S60sendsignals ln -sf ../init.d/mountfs /etc/rc.d/rc0.d/S70mountfs @@ -105,18 +110,6 @@ $(TARGET) : ln -sf ../init.d/localnet /etc/rc.d/rcsysinit.d/S80localnet ln -sf ../init.d/sysctl /etc/rc.d/rcsysinit.d/S90sysctl -# -mkdir -p /etc/rc.d/helper -# for i in $(DIR_SRC)/src/rc.d/* ; do \ -# if [ -f $$i ]; then \ -# sed "s+CONFIG_ROOT+$(CONFIG_ROOT)+g" $$i > /etc/rc.d/`basename $$i`; \ -# fi; \ -# done -# for i in $(DIR_SRC)/src/rc.d/helper/* ; do \ -# if [ -f $$i ]; then \ -# sed "s+CONFIG_ROOT+$(CONFIG_ROOT)+g" $$i > /etc/rc.d/helper/`basename $$i`; \ -# fi; \ -# done -# chmod -R 755 /etc/rc.d # chgrp nobody /etc/rc.d/rc.red # chmod 4750 /etc/rc.d/rc.red @$(POSTBUILD) diff --git a/lfs/ipp2p b/lfs/ipp2p index af20feff0d..9e805fc927 100644 --- a/lfs/ipp2p +++ b/lfs/ipp2p @@ -62,15 +62,17 @@ $(TARGET) : @rm -rf $(DIR_APP) && mkdir -p $(DIR_APP) @cp -vf $(DIR_SRC)/src/ipp2p/* $(DIR_APP) cd $(DIR_SRC) && rm -rf iptables-* - cd $(DIR_SRC) && tar xfj $(DIR_DL)/iptables-1.3.5.tar.bz2 - cd $(DIR_SRC) && ln -sf iptables-1.3.5 iptables - cd $(DIR_APP) && make + cd $(DIR_SRC) && tar xfz $(DIR_DL)/iptables-fixed.tar.gz + cd $(DIR_SRC) && ln -sf iptables-* iptables ifeq "$(SMP)" "1" + cd $(DIR_APP) && make ipt_ipp2p.ko cp -f $(DIR_APP)/ipt_ipp2p.ko /lib/modules/$(KVER)-smp/kernel/net/ipv4/netfilter else ifeq "$(IPT)" "1" + cd $(DIR_APP) && make cp -f $(DIR_APP)/libipt_ipp2p.o /lib/iptables else + cd $(DIR_APP) && make ipt_ipp2p.ko cp -f $(DIR_APP)/ipt_ipp2p.ko /lib/modules/$(KVER)/kernel/net/ipv4/netfilter endif endif diff --git a/lfs/iptables b/lfs/iptables index 8e92c400e3..107321c99b 100644 --- a/lfs/iptables +++ b/lfs/iptables @@ -81,10 +81,6 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) @rm -rf $(DIR_DL)/netfilter-layer7-v2.1 && cd $(DIR_SRC) && tar zxf $(DIR_DL)/netfilter-layer7-v2.1.tar.gz cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/netfilter-layer7-v2.6/iptables-layer7-2.6.patch -# # Appears that libipt_set/SET maybe a little broken, fix it for now... -# cd $(DIR_APP)/extensions && sed -i -e 's/#include\ \"..\/ipset\/libipt_set.h\"//' libipt_set.c -# cd $(DIR_APP)/extensions && sed -i -e 's/#include\ \"..\/ipset\/libipt_set.h\"//' libipt_SET.c - cd $(DIR_APP) && patch -Np1 < $(DIR_DL)/iptables-1.3.0-imq1.diff chmod +x $(DIR_APP)/extensions/.IMQ-test* $(DIR_APP)/extensions/.layer7-test* diff --git a/lfs/strip b/lfs/strip index c0da4d3df7..7a3bedac19 100644 --- a/lfs/strip +++ b/lfs/strip @@ -65,8 +65,8 @@ ifeq "$(LFS_PASS)" "install" -type f \( -name '*.so' -o -name '*.so[\.0-9]*' \) \ -exec /tools/bin/strip --strip-debug {} \; 2>/dev/null - -/tools/bin/strip --strip-all /{,usr/}{,local/}{bin,sbin}/* /install/{initrd,misc}/bin/* - -/tools/bin/strip --strip-all /usr/lib/awk/{grcat,pwcat} - -/tools/bin/strip --strip-all /usr/lib/gcc/*-linux-gnu/4.0.3/{cc1*,collect2} + -/tools/bin/strip --strip-all /{,usr/}{,local/}{bin,sbin}/* /install/{initrd,misc}/bin/* 2>/dev/null + -/tools/bin/strip --strip-all /usr/lib/awk/{grcat,pwcat} 2>/dev/null + -/tools/bin/strip --strip-all /usr/lib/gcc/*-linux-gnu/4.0.3/{cc1*,collect2} 2>/dev/null endif diff --git a/src/initscripts/helper/getdnsfromdhcpc.pl b/src/initscripts/helper/getdnsfromdhcpc.pl new file mode 100644 index 0000000000..05c5fe7398 --- /dev/null +++ b/src/initscripts/helper/getdnsfromdhcpc.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl +# +# Helper program to get DNS info from dhcpc .info file. +# +# (c) Lawrence Manning, 2001 + +use strict; +require '/var/ipfire/general-functions.pl'; + +my $count = $ARGV[0]; +my ($dhcp, $dns, @alldns, %dhcpc); + +if ($count eq "" || $count < 1) { + die "Bad DNS number given"; } + +if (open(FILE, "${General::swroot}/red/iface")) { + my $iface = ; + close FILE; + chomp ($iface); + if (!&General::readhash("${General::swroot}/dhcpc/dhcpcd-$iface.info", \%dhcpc)) { + die "Could not open dhcpc info file"; + } +} else { + die "Could not open interface file"; +} + + +$dns = $dhcpc{'DNS'}; + +@alldns = split(',', $dns); + +print "$alldns[$count - 1]\n"; diff --git a/src/initscripts/helper/writeipac.pl b/src/initscripts/helper/writeipac.pl new file mode 100644 index 0000000000..ff6792f465 --- /dev/null +++ b/src/initscripts/helper/writeipac.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl +# +# Helper program to write a new IPAC settings file +# +# (c) Lawrence Manning, 2001 +# +# $id +# + +use strict; +require '/var/ipfire/general-functions.pl'; + +my %settings; +my $iface; + +General::readhash("${General::swroot}/ethernet/settings", \%settings); + +if (!open(FILE, '>/etc/ipac-ng/rules.conf')) { + die "Unable to create /etc/ipac-ng/rules.conf"; } + +if (open(IFACE, "${General::swroot}/red/iface")) +{ + $iface = ; + close IFACE; + chomp ($iface); +} + +print FILE "incoming GREEN ($settings{'GREEN_DEV'})|ipac~o|$settings{'GREEN_DEV'}|all|||\n"; +print FILE "outgoing GREEN ($settings{'GREEN_DEV'})|ipac~i|$settings{'GREEN_DEV'}|all|||\n"; +print FILE "forwarded incoming GREEN ($settings{'GREEN_DEV'})|ipac~fi|$settings{'GREEN_DEV'}|all|||\n"; +print FILE "forwarded outgoing GREEN ($settings{'GREEN_DEV'})|ipac~fo|$settings{'GREEN_DEV'}|all|||\n"; + +if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ ) +{ + print FILE "incoming ORANGE ($settings{'ORANGE_DEV'})|ipac~o|$settings{'ORANGE_DEV'}|all|||\n"; + print FILE "outgoing ORANGE ($settings{'ORANGE_DEV'})|ipac~i|$settings{'ORANGE_DEV'}|all|||\n"; + print FILE "forwarded incoming ORANGE ($settings{'ORANGE_DEV'})|ipac~fi|$settings{'ORANGE_DEV'}|all|||\n"; + print FILE "forwarded outgoing ORANGE ($settings{'ORANGE_DEV'})|ipac~fo|$settings{'ORANGE_DEV'}|all|||\n"; +} + +if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ ) +{ + print FILE "incoming BLUE ($settings{'BLUE_DEV'})|ipac~o|$settings{'BLUE_DEV'}|all|||\n"; + print FILE "outgoing BLUE ($settings{'BLUE_DEV'})|ipac~i|$settings{'BLUE_DEV'}|all|||\n"; + print FILE "forwarded incoming BLUE ($settings{'BLUE_DEV'})|ipac~fi|$settings{'BLUE_DEV'}|all|||\n"; + print FILE "forwarded outgoing BLUE ($settings{'BLUE_DEV'})|ipac~fo|$settings{'BLUE_DEV'}|all|||\n"; +} +if ($iface) { + print FILE "incoming RED ($iface)|ipac~o|$iface|all|||\n"; + print FILE "outgoing RED ($iface)|ipac~i|$iface|all|||\n"; + print FILE "forwarded incoming RED ($iface)|ipac~fi|$iface|all|||\n"; + print FILE "forwarded outgoing RED ($iface)|ipac~fo|$iface|all|||\n"; +} + +close FILE; diff --git a/src/initscripts/init.d/network b/src/initscripts/init.d/network index 8c989cc7c2..85ac8e9062 100644 --- a/src/initscripts/init.d/network +++ b/src/initscripts/init.d/network @@ -15,6 +15,14 @@ . /etc/sysconfig/rc . ${rc_functions} . /var/ipfire/ethernet/settings +. /var/ipfire/dhcp/settings +. /var/ipfire/ppp/settings +. /var/ipfire/vpn/settings + +# This is a small wrapper for dhcpcd.exe +if ( echo $0 | /bin/grep -q 'dhcpcd.exe' ); then + /etc/rc.d/init.d/network red update $1 $2 +fi case "${1}" in start) @@ -82,29 +90,34 @@ case "${1}" in fi boot_mesg "Setting up IPFire firewall rules" - /etc/rc.d/init.d/firewall start - evaluate_retval + /etc/rc.d/init.d/firewall start; evaluate_retval + boot_mesg "Setting up IP Accounting" /etc/rc.d/helper/writeipac.pl - /usr/sbin/fetchipac -S - evaluate_retval + /usr/sbin/fetchipac -S; evaluate_retval + boot_mesg "Setting IPFire DMZ pinholes" - /usr/local/bin/setdmzholes - evaluate_retval + /usr/local/bin/setdmzholes; evaluate_retval if [ "$BLUE_DEV" != "" ]; then boot_mesg "Setting up wireless firewall rules" - /usr/local/bin/restartwireless - evaluate_retval + /usr/local/bin/restartwireless; evaluate_retval fi - boot_mesg "Bringing network up..." - . /etc/rc.d/rc.netaddress.up + # Bringing interfaces up... + $0 green up + $0 orange up + $0 blue up + $0 red up ;; stop) - + # Stopping all interfaces... + $0 red down + $0 blue down + $0 orange down + $0 green down ;; restart) @@ -113,8 +126,246 @@ case "${1}" in ${0} start ;; + # + # Every interface has its own context to start/stop/restart. + # + green) + case "${2}" in + up) + boot_mesg "Bringing green network up..." + if [ "$GREEN_DEV" != "" ]; then + ifconfig $GREEN_DEV $GREEN_ADDRESS netmask $GREEN_NETMASK broadcast $GREEN_BROADCAST up + evaluate_retval + else + echo "WARNING: No driver set for GREEN" + fi + ;; + down) + boot_mesg "Bringing green network down..." + ifconfig $GREEN_DEV down 2> /dev/null; evaluate_retval + ;; + esac + ;; + + orange) + case "${2}" in + up) + if [ "$CONFIG_TYPE" = "1" -o "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "5" -o "$CONFIG_TYPE" = "7" ]; then + if [ "$ORANGE_DEV" != "" ]; then + boot_mesg "Bringing orange network up..." + ifconfig $ORANGE_DEV $ORANGE_ADDRESS netmask $ORANGE_NETMASK broadcast $ORANGE_BROADCAST up + evaluate_retval + fi + fi + ;; + down) + if [ "$ORANGE_DEV" != "" ]; then + boot_mesg "Bringing orange network down..." + ifconfig $ORANGE_DEV down 2> /dev/null; evaluate_retval + fi + ;; + esac + ;; + + blue) + case "${2}" in + up) + if [ "$CONFIG_TYPE" = "4" -o "$CONFIG_TYPE" = "5" -o "$CONFIG_TYPE" = "6" -o "$CONFIG_TYPE" = "7" ]; then + if [ "$BLUE_DEV" != "" ]; then + boot_mesg "Bringing blue network up..." + ifconfig $BLUE_DEV $BLUE_ADDRESS netmask $BLUE_NETMASK broadcast $BLUE_BROADCAST up + evaluate_retval + fi + fi + ;; + down) + if [ "$BLUE_DEV" != "" ]; then + boot_mesg "Bringing blue network down..." + ifconfig $BLUE_DEV down 2> /dev/null; evaluate_retval + fi + ;; + esac + ;; + + red) + case "${2}" in + up) + boot_mesg "Bringing red network up..." + # If RED is ethernet then check furthur... + if [ "$CONFIG_TYPE" == "2" -o "$CONFIG_TYPE" == "3" -o "$CONFIG_TYPE" == "6" -o "$CONFIG_TYPE" == "7" ]; then + # If we are DHCP or STATIC we have to start automatically + if [ "$RED_TYPE" == "DHCP" -o "$RED_TYPE" == "STATIC" ]; then + AUTOCONNECT="on" + fi + fi + + # Start DNSMASQ with defaults + if [ "$DOMAIN_NAME_GREEN" == "" ]; then + /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases + else + /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases -s "$DOMAIN_NAME_GREEN" + fi + + # Only when AUTOCONNECT is on + if [ "$AUTOCONNECT" == "on" ]; then + /etc/rc.d/init.d/red start; evaluate_retval + fi + ;; + down) + boot_mesg "Bringing red network down..." + /etc/rc.d/init.d/red stop + sleep 3 + /etc/rc.d/init.d/red clear; evaluate_retval + ;; + update) + if [ ! -e /var/lock/rc.updatered.lock ]; then + /usr/bin/touch /var/lock/rc.updatered.lock + /usr/bin/logger -s -p local0.info -t rc.updatered "$0 locking for $$" + else + count=0 + while [ ! $count = 5 ]; do + sleep 3 + if [ ! -e /var/lock/rc.updatered.lock ]; then + break + else + /usr/bin/logger -s -p local0.info -t rc.updatered "$0 $$ waiting unlock" + fi + ((++count)) + done + fi + + IFACE=`/bin/cat /var/ipfire/red/iface 2>/dev/null | /usr/bin/tr -d '\012'` + REMOTE=`/bin/cat /var/ipfire/red/remote-ipaddress 2>/dev/null | /usr/bin/tr -d '\012'` + + ### + ### Retrieve DHCP Settings + ### + if [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "6" -o "$CONFIG_TYPE" = "7" ]; then + if [ "$RED_TYPE" = "DHCP" ]; then + unset DNS1 DNS2 + eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) + if [ "$DNS1" = "" ]; then + echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var/ipfire/red/dns1 + echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var/ipfire/red/dns2 + else + echo "$DNS1" > /var/ipfire/red/dns1 + echo "$DNS2" > /var/ipfire/red/dns2 + fi + . /var/ipfire/dhcpc/dhcpcd-${RED_DEV}.info + echo "$IPADDR" > /var/ipfire/red/local-ipaddress + echo "$GATEWAY" > /var/ipfire/red/remote-ipaddress + fi + else + if [ "$PROTOCOL" = "RFC1483" -a "$METHOD" = "DHCP" ]; then + unset DNS1 DNS2 + eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) + if [ "$DNS" = "Automatic" ]; then + echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var/ipfire/red/dns1 + echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var/ipfire/red/dns2 + else + echo "$DNS1" > /var/ipfire/red/dns1 + echo "$DNS2" > /var/ipfire/red/dns2 + fi + . /var/ipfire/dhcpc/dhcpcd-${IFACE}.info + echo $IPADDR > /var/ipfire/red/local-ipaddress + echo $GATEWAY > /var/ipfire/red/remote-ipaddress + fi + fi + + ### + ### Retrieve DNS settings + ### + DNS1=`/bin/cat /var/ipfire/red/dns1 2>/dev/null | /usr/bin/tr -d '\012'` + DNS2=`/bin/cat /var/ipfire/red/dns2 2>/dev/null | /usr/bin/tr -d '\012'` + echo > /var/ipfire/red/resolv.conf #clear it + [ "$DNS1" != "" ] && echo "nameserver $DNS1" > /var/ipfire/red/resolv.conf + [ "$DNS2" != "" ] && echo "nameserver $DNS2" >> /var/ipfire/red/resolv.conf + + + ### + ### Restart DNSMASQ + ### + /bin/killall -KILL dnsmasq 2> /dev/null + sleep 1 + + DOMopt="" + [ "$DOMAIN_NAME_GREEN" ] && DOMopt="-s $DOMAIN_NAME_GREEN" + if [ -e "/var/ipfire/red/dial-on-demand" -a "$DIALONDEMANDDNS" == "on" -a ! -e "/var/ipfire/red/active" ]; then + /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $DOMopt -r /var/ipfire/ppp/fake-resolv.conf + else + /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $DOMopt -r /var/ipfire/red/resolv.conf + fi + unset DOMopt + + # Reset default route to ippp0 for dial on demand + if [ -e "/var/ipfire/red/dial-on-demand" -a "$TYPE" == "isdn" -a ! -e "/var/ipfire/red/active" ]; then + /sbin/route del default 2> /dev/null + if [ ! -z "$REMOTE" ]; then + /sbin/route add default gw $REMOTE 2> /dev/null + else + /sbin/route add default dev ippp0 2> /dev/null + fi + fi + + if [ "$3" ]; then + eval $(/usr/local/bin/readhash "$3") + case "$4" in + up) + /usr/bin/logger -s -p local0.info -t dhcpcd.exe "${INTERFACE} has been configured with old IP=${IPADDR}" + if [ "$RED_TYPE" != 'PPTP' ]; then + /usr/bin/touch /var/ipfire/red/active + fi + ;; + new) + /usr/bin/logger -s -p local0.info -t dhcpcd.exe "${INTERFACE} has been configured with new IP=${IPADDR}" + if [ -e "/var/ipfire/red/active" ]; then + /usr/local/bin/setfilters + /usr/local/bin/setportfw + /usr/local/bin/setxtaccess + /usr/local/bin/setddns.pl -f + /usr/local/bin/restartsnort red + sleep $VPN_DELAYED_START && /usr/local/bin/ipsecctrl S & + /bin/rm -f /var/lock/rc.updatered.lock + /usr/bin/logger -s -p local0.info -t rc.updatered "unlocking from $$" + exit 0 + else + if [ "$RED_TYPE" != 'PPTP' ]; then + /usr/bin/touch /var/ipfire/red/active + fi + fi + ;; + down) + /usr/bin/logger -s -p local0.info -t dhcpcd.exe "${INTERFACE} has been brought down" + rm -f /var/ipfire/red/active + ;; + esac + fi + + if [ -e "/var/ipfire/red/active" ]; then + [ "$IFACE" != "" ] && /sbin/ifconfig $IFACE -multicast + /etc/rc.d/init.d/firewall reload + /usr/local/bin/setfilters + /usr/local/bin/restartsnort red + /usr/local/bin/qosctrl restart + /usr/local/bin/setportfw + /usr/local/bin/setxtaccess + /usr/local/bin/setddns.pl -f + /etc/rc.d/helper/writeipac.pl + /usr/sbin/fetchipac -S + sleep $VPN_DELAYED_START && /usr/local/bin/ipsecctrl S & + else + /usr/local/bin/ipsecctrl D + /etc/rc.d/init.d/firewall reload + fi + /bin/rm -f /var/lock/rc.updatered.lock + /usr/bin/logger -s -p local0.info -t rc.updatered "unlocking from $$" + ;; + esac + ;; + *) echo "Usage: ${0} {start|stop|restart}" + echo " or: ${0} {green|orange|blue|red} {up|down}" exit 1 ;; esac diff --git a/src/initscripts/init.d/red b/src/initscripts/init.d/red new file mode 100644 index 0000000000..819adf0f63 --- /dev/null +++ b/src/initscripts/init.d/red @@ -0,0 +1,1169 @@ +#!/usr/bin/perl +# +# This file is part of the IPCop Firewall. +# +# IPCop is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# IPCop is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with IPCop; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# (c) The SmoothWall Team +# +# $Id: rc.red,v 1.29.2.56 2005/12/17 08:49:01 gespinasse Exp $ + + +# Clean up our environment (we're running SUID!) +delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)}; +$< = $>; + +use strict; +require '/var/ipfire/general-functions.pl'; + +my %pppsettings; +my %isdnsettings; +my %netsettings; +my %dhcpsettings; +my $iface; + +# read vars back from file. +&General::readhash("${General::swroot}/ppp/settings", \%pppsettings); +&General::readhash("${General::swroot}/isdn/settings", \%isdnsettings); +&General::readhash("${General::swroot}/ethernet/settings", \%netsettings); +&General::readhash("${General::swroot}/dhcp/settings", \%dhcpsettings); + +sub dodhcpdial($;$) { + my ($iface,$dhcp_name)=@_; + + system ('/sbin/iptables', '-A', 'REDINPUT', '-p', 'tcp', '--source-port', '67', + '--destination-port', '68', '-i', $iface, '-j', 'ACCEPT'); + system ('/sbin/iptables', '-A', 'REDINPUT', '-p', 'udp', '--source-port', '67', + '--destination-port', '68', '-i', $iface, '-j', 'ACCEPT'); + + foreach ("<${General::swroot}/dhcpc/*.info>") { unlink $1 if ( $_ =~ /^([\/\w.-]+)$/ ); } + my @dhcpcommand = ('/sbin/dhcpcd'); + push(@dhcpcommand, ('-N', '-R', "$iface",'-L', "${General::swroot}/dhcpc")); + + #FIXME the only way actually to set debug use is in pppsetup.cgi and 'RED is modem/isdn' interface + if ($pppsettings{'DEBUG'} eq 'on') { + push(@dhcpcommand, ('-d')); + } + + if ($dhcp_name ne '') { push(@dhcpcommand, ('-h', "$dhcp_name")); } + if ($netsettings{'RED_TYPE'} eq 'PPTP') { push(@dhcpcommand, '-G'); } + + if (system (@dhcpcommand)) { + &General::log('dhcpcd fail'); + exit 1; + } else { + &General::log('dhcpcd success'); + } +} + +sub doupdatesettings { + # complete cleanup only if settings were changed or clear is ordered + system('/sbin/modprobe', '-r', 'pppoatm'); + system('/sbin/modprobe', '-r', 'pppoe'); + system('/bin/killall /usr/bin/br2684ctl 2>/dev/null'); + system('/sbin/modprobe', '-r', 'br2684'); + system('/sbin/modprobe', '-r', 'clip'); + + if ($pppsettings{'TYPE'} ne '3cp4218usbadsl') { system('/sbin/modprobe', '-r', '3cp4218');} + if ($pppsettings{'TYPE'} ne 'alcatelusbk') { system('/sbin/modprobe', '-r', 'speedtch');} + if ($pppsettings{'TYPE'} ne 'amedynusbadsl') { system('/sbin/modprobe', '-r', 'amedyn');} + if ($pppsettings{'TYPE'} ne 'bewanadsl') { + system('/sbin/modprobe', '-r', 'unicorn_pci_atm', 'unicorn_usb_atm');} + if ($pppsettings{'TYPE'} ne 'conexantpciadsl') { system('/sbin/modprobe', '-r', 'CnxADSL');} + if ($pppsettings{'TYPE'} ne 'conexantusbadsl') { system('/sbin/modprobe', '-r', 'cxacru');} + if ($pppsettings{'TYPE'} ne 'eagleusbadsl') { system('/sbin/modprobe', '-r', 'eagle-usb');} + if ($pppsettings{'TYPE'} ne 'fritzdsl') { + system('/sbin/modprobe', '-r', 'fcdsl', 'fcdsl2', 'fcdslsl', 'fcdslusb', 'fcdslslusb');} + if ($pppsettings{'TYPE'} ne 'pulsardsl') { system('/sbin/modprobe', '-r', 'pulsar');} + sleep 1; + if ($pppsettings{'TYPE'} !=~ /^(3cp4218usbadsl|alcatelusbk|amedynusbadsl|bewanadsl|conexantpciadsl|pulsardsl)$/) { + system('/sbin/modprobe', '-r', 'atm'); + + # remove existing default route (for static address) if it was been changed from setup or web interface SF1175052 + system ('/sbin/route del default 2>/dev/null'); + + # erase in case it was created once with 'persistent' selected but rc.red stop never used : SF1171610 + unlink ("${General::swroot}/red/iface"); + } +} + +# No output should be sent to the webclient +open STDIN, '/dev/null' or die "Can't write to /dev/null"; + +if ($ARGV[0] eq 'start') { + if (-e "${General::swroot}/red/active" || + -e '/var/run/ppp-ipcop.pid') + { + &General::log ("ERROR: Can't start RED when it's still active"); + exit 1; + } + + if ( ( ( ($netsettings{'RED_TYPE'} =~ /^(PPPOE|PPTP)$/) && ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) ) || + ( ( ($pppsettings{'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) || ($pppsettings{'PROTOCOL'} eq 'RFC2364') ) && + ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/) ) ) && ($pppsettings{'RECONNECTION'} ne 'manual') ) { + system ('/etc/rc.d/rc.connectioncheck start &'); + } + + ### + ### Red device is ethernet + ### + if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) + { + if ($netsettings{'RED_DEV'} ne '') + { + &General::log("Starting RED device $netsettings{'RED_DEV'}."); + + if ( $netsettings{'RED_TYPE'} eq 'DHCP') + { + if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $netsettings{'RED_DEV'}; close FILE; } + dodhcpdial($netsettings{'RED_DEV'},$netsettings{'RED_DHCP_HOSTNAME'}); + exit 0; + } + elsif ( ( $netsettings{'RED_TYPE'} eq 'PPTP') && ( $pppsettings{'METHOD'} eq 'DHCP') ) + { + if (open(FILE, ">${General::swroot}/red/device")) { print FILE $netsettings{'RED_DEV'}; close FILE; } + unlink ("${General::swroot}/red/iface"); + dodhcpdial($netsettings{'RED_DEV'},$netsettings{'RED_DHCP_HOSTNAME'}); + } + elsif ( ( $netsettings{'RED_TYPE'} eq 'STATIC') || + ( $netsettings{'RED_TYPE'} eq 'PPTP') && ( $pppsettings{'METHOD'} ne 'DHCP') ) + { + system ("/sbin/ifconfig", + $netsettings{'RED_DEV'}, $netsettings{'RED_ADDRESS'}, + "netmask", $netsettings{'RED_NETMASK'}, + "broadcast", $netsettings{'RED_BROADCAST'},"up"); + if ( $netsettings{'RED_TYPE'} eq 'STATIC') + { + system("/usr/local/bin/setaliases"); + system("echo $netsettings{'DNS1'} > ${General::swroot}/red/dns1"); + system("echo $netsettings{'DNS2'} > ${General::swroot}/red/dns2"); + system("echo $netsettings{'RED_ADDRESS'} > ${General::swroot}/red/local-ipaddress"); + system("echo $netsettings{'DEFAULT_GATEWAY'} > ${General::swroot}/red/remote-ipaddress"); + } elsif ( $netsettings{'RED_TYPE'} eq 'PPTP' ) { + if (open(FILE, ">${General::swroot}/red/device")) { print FILE $netsettings{'RED_DEV'}; close FILE; } + unlink ("${General::swroot}/red/iface"); + } + if ( $netsettings{'DEFAULT_GATEWAY'} ne '' ) + { + system ("/sbin/route","add","default","gw", + $netsettings{'DEFAULT_GATEWAY'}); + } + } + else + { + # PPPoE + system ("/sbin/ifconfig", $netsettings{'RED_DEV'}, "1.1.1.1", + "netmask", "255.255.255.0", "broadcast", "1.1.1.255", "up"); + } + + if ( $netsettings{'RED_TYPE'} eq 'STATIC') + { + if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $netsettings{'RED_DEV'}; close FILE; } + system ("/bin/touch", "${General::swroot}/red/active"); + system ("/etc/rc.d/init.d/network red update"); + exit 0; + } + } + else + { + &General::log ("ERROR: Can't start RED when RED device not set!"); + exit 1; + } + } + + + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') + { + system ('/bin/touch', "${General::swroot}/red/dial-on-demand"); + } + + if ($pppsettings{'VALID'} ne 'yes') { + &General::log("Profile has errors."); + exit 1; + } + + if (-e "${General::swroot}/ppp/updatesettings") { + &doupdatesettings; + } + + if (( $pppsettings{'METHOD'} eq 'STATIC') && ( $pppsettings{'DNS'} eq 'Manual')) { + system("/usr/local/bin/setaliases"); + if (open(FILE, ">${General::swroot}/red/dns1")) { print FILE $pppsettings{'DNS1'}; close FILE; } + if (open(FILE, ">${General::swroot}/red/dns2")) { print FILE $pppsettings{'DNS2'}; close FILE; } + if (open(FILE, ">${General::swroot}/red/local-ipaddress")) { print FILE $pppsettings{'IP'}; close FILE; } + if (open(FILE, ">${General::swroot}/red/remote-ipaddress")) { print FILE $pppsettings{'GATEWAY'}; close FILE; } + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + &General::log("Dial-on-Demand waiting to dial $pppsettings{'PROFILENAME'}."); + } else { + &General::log("Dialling $pppsettings{'PROFILENAME'}."); + } + + if ($pppsettings{'TYPE'} eq 'modem') { &domodemdial(); } + elsif ($pppsettings{'TYPE'} eq 'serial') { &doserialdial(); } + elsif ($pppsettings{'TYPE'} eq 'isdn') { &doisdndial(); } + elsif ($pppsettings{'TYPE'} eq 'pppoe') { &dopppoedial(); } + elsif ($pppsettings{'TYPE'} eq 'pptp') { &dopptpdial(); } + elsif ($pppsettings{'TYPE'} eq 'alcatelusbk') { &doalcatelusbkdial(); } + elsif ($pppsettings{'TYPE'} eq 'alcatelusb') { &doalcatelusbdial(); } + elsif ($pppsettings{'TYPE'} eq 'pulsardsl') { &dopulsardsldial(); } + elsif ($pppsettings{'TYPE'} eq 'eciadsl') { &doeciadsldial(); } + elsif ($pppsettings{'TYPE'} eq 'fritzdsl') { &dofritzdsldial(); } + elsif ($pppsettings{'TYPE'} eq 'bewanadsl') { &dobewanadsldial(); } + elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') { &doeagleusbadsldial(); } + elsif ($pppsettings{'TYPE'} eq 'conexantusbadsl') { &doconexantusbadsldial(); } + elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') { &doconexantpciadsldial(); } + elsif ($pppsettings{'TYPE'} eq 'amedynusbadsl') { &doamedynusbadsldial(); } + elsif ($pppsettings{'TYPE'} eq '3cp4218usbadsl') { &do3cp4218usbadsldial(); } + + if (-e "${General::swroot}/ppp/updatesettings") { + # erase update mark only after specific script had run, allowing specific script to treat the update + unlink ("${General::swroot}/ppp/updatesettings"); + } + if ( ($pppsettings{'RECONNECTION'} eq 'dialondemand') || ($pppsettings{'METHOD'} eq 'STATIC') ){ + system ("/etc/rc.d/init.d/network red update"); + } +} +elsif ($ARGV[0] eq 'stop') +{ + if (open(IFACE, "${General::swroot}/red/iface")) { + $iface = ; + close IFACE; + chomp ($iface); + $iface =~ /([a-zA-Z0-9]*)/; $iface = $1; + } + + my $device; + if (open(FILE, "${General::swroot}/red/device")) { + $device = ; + close FILE; + chomp ($device); + $device =~ /([a-zA-Z0-9]*)/; $device = $1; + } + + unlink "${General::swroot}/red/dial-on-demand"; + unlink "${General::swroot}/red/active"; + unlink "${General::swroot}/red/local-ipaddress"; + unlink "${General::swroot}/red/remote-ipaddress"; + unlink "${General::swroot}/red/dns1"; + unlink "${General::swroot}/red/dns2"; + unlink "${General::swroot}/red/resolv.conf"; + unlink "${General::swroot}/red/device"; + + # stay with keepconnected during transitional rc.red stop ordered by rc.connectioncheck + if ( ! -e "${General::swroot}/red/redial") { + unlink "${General::swroot}/red/keepconnected"; + } + unlink "${General::swroot}/red/redial"; + + # Kill PPPD + if (open(FILE, "/var/run/ppp-ipcop.pid")) { + my $pid = ; + close FILE; + chomp ($pid); + $pid =~ /(\d*)/; $pid = $1; + system ('/bin/kill', $pid); + } + + # Bring down Ethernet interfaces & Kill DHCPC daemons + if (($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) && ( $netsettings{'RED_TYPE'} eq 'PPPOE') && $iface ) { + system ("/sbin/ifconfig", $iface, "down"); + } + if ($device) { + system ("/sbin/ifconfig", $device, "down"); + } + + my $file; + while (($file = glob("${General::swroot}/dhcpc/dhcpcd-*.pid") )) { + if (open(FILE, $file)) { + my $pid = ; + close FILE; + chomp ($pid); + $pid =~ /(\d*)/; $pid = $1; + system ('/bin/kill', $pid); + } + } + + if (!system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) { + if ($pppsettings{'GATEWAY'} ne '') { + system("/usr/sbin/atmarp -d $pppsettings{'GATEWAY'} 2>/dev/null"); } + system('/bin/killall /usr/sbin/atmarpd 2>/dev/null'); + system ('/sbin/ifconfig', 'atm0', 'down'); + } + + if ($pppsettings{'TYPE'} eq 'isdn') { system('/etc/rc.d/rc.isdn','stop'); } + if ($pppsettings{'TYPE'} eq 'eciadsl') { system('/etc/rc.d/rc.eciadsl', 'stop'); } + if ($pppsettings{'TYPE'} eq 'alcatelusbk') { system('/etc/rc.d/rc.alcatelusbk', 'stop'); } + if ($pppsettings{'TYPE'} eq 'alcatelusb') { system('/etc/rc.d/rc.alcatelusb', 'stop'); } + if ($pppsettings{'TYPE'} eq 'amedynusbadsl') { system('/etc/rc.d/rc.amedynusbadsl', 'stop'); } + if ($pppsettings{'TYPE'} eq 'bewanadsl') { system('/etc/rc.d/rc.bewanadsl', 'stop'); } + if ($pppsettings{'TYPE'} eq 'conexantpciadsl') { system('/etc/rc.d/rc.conexantpciadsl', 'stop'); } + if ($pppsettings{'TYPE'} eq 'conexantusbadsl') { system('/etc/rc.d/rc.conexantusbadsl', 'stop'); } + if ($pppsettings{'TYPE'} eq 'eagleusbadsl') { system('/etc/rc.d/rc.eagleusbadsl', 'stop'); } + if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','stop'); } + if ($pppsettings{'TYPE'} eq 'pulsardsl') { system('/etc/rc.d/rc.pulsardsl', 'stop'); } + if ($pppsettings{'TYPE'} eq '3cp4218usbadsl') { system('/etc/rc.d/rc.3cp4218usbadsl', 'stop'); } + + if ( ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} eq 'STATIC') || + ( $netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'PROTOCOL'} eq 'RFC1483' && + $pppsettings{'METHOD'} eq 'STATIC' ) ) { + system ("/etc/rc.d/init.d/network red update"); + } +} +elsif ($ARGV[0] eq 'clear') +{ + &doupdatesettings(); + &docleanup(); +} + +exit 0; + +sub docleanup +{ + if ($pppsettings{'TYPE'} eq 'alcatelusbk') { system('/etc/rc.d/rc.alcatelusbk', 'cleanup'); } + if ($pppsettings{'TYPE'} eq 'alcatelusb') { system('/etc/rc.d/rc.alcatelusb', 'cleanup'); } + if ($pppsettings{'TYPE'} eq 'eciadsl') { system('/etc/rc.d/rc.eciadsl', 'cleanup'); } + if ($pppsettings{'TYPE'} eq 'pulsardsl') { system('/etc/rc.d/rc.pulsardsl', 'cleanup'); } + if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','cleanup'); } + if ($pppsettings{'TYPE'} eq 'bewanadsl') { system('/etc/rc.d/rc.bewanadsl', 'cleanup'); } + if ($pppsettings{'TYPE'} eq 'eagleusbadsl') { system('/etc/rc.d/rc.eagleusbadsl', 'cleanup'); } + if ($pppsettings{'TYPE'} eq 'conexantusbadsl') { system('/etc/rc.d/rc.conexantusbadsl', 'cleanup'); } + if ($pppsettings{'TYPE'} eq 'conexantpciadsl') { system('/etc/rc.d/rc.conexantpciadsl', 'cleanup'); } + if ($pppsettings{'TYPE'} eq 'amedynusbadsl') { system('/etc/rc.d/rc.amedynusbadsl', 'cleanup'); } + if ($pppsettings{'TYPE'} eq '3cp4218usbadsl') { system('/etc/rc.d/rc.3cp4218usbadsl', 'cleanup'); } +} + +sub domodemdial +{ + my @pppcommand = ('/usr/sbin/pppd'); + my $loginscript = ''; + + if ($pppsettings{'COMPORT'} =~ /ttyACM/) { + system ('/sbin/rmmod acm'); + sleep 1; + system ('/sbin/modprobe acm'); + } + + my $device = "/dev/${pppsettings{'COMPORT'}}"; + + if ($pppsettings{'DNS'} eq 'Automatic') { + push(@pppcommand, ('usepeerdns')); } + + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } elsif ($pppsettings{'AUTH'} eq 'standard-login-script') { + $loginscript = 'standardloginscript'; + } elsif ($pppsettings{'AUTH'} eq 'demon-login-script') { + $loginscript = 'demonloginscript'; + } else { + $loginscript = $pppsettings{'LOGINSCRIPT'}; + } + + if ($pppsettings{'RECONNECTION'} ne 'persistent') { + if ($pppsettings{'TIMEOUT'} != 0) + { + my $seconds = $pppsettings{'TIMEOUT'} * 60; + push (@pppcommand, ('idle', $seconds)); + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + push (@pppcommand, ('demand', 'nopersist')); + } + push (@pppcommand, + ('active-filter', + 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' )); + } + + push (@pppcommand, ('novj', 'novjccomp')); + + push (@pppcommand, ('lock', 'modem', 'crtscts', $device, + $pppsettings{'DTERATE'}, 'noipdefault', + 'defaultroute', 'user', $pppsettings{'USERNAME'}, + 'maxfail', $pppsettings{'MAXRETRIES'}, 'connect', + '/etc/ppp/dialer')); + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + + system @pppcommand; +} + +sub doserialdial +{ + my @pppcommand = ('/usr/sbin/pppd'); + my $loginscript = ''; + + if ($pppsettings{'COMPORT'} =~ /ttyACM/) { + system ('/sbin/rmmod acm'); + sleep 1; + system ('/sbin/modprobe acm'); + } + + my $device = "/dev/${pppsettings{'COMPORT'}}"; + + if ($pppsettings{'DNS'} eq 'Automatic') { + push(@pppcommand, ('usepeerdns')); } + + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } + + if ($pppsettings{'RECONNECTION'} ne 'persistent') { + if ($pppsettings{'TIMEOUT'} != 0) + { + my $seconds = $pppsettings{'TIMEOUT'} * 60; + push (@pppcommand, ('idle', $seconds)); + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + push (@pppcommand, ('demand', 'nopersist')); + } + push (@pppcommand, + ('active-filter', + 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' )); + } + + push (@pppcommand, ('novj', 'novjccomp')); + + push (@pppcommand, ('lock', 'modem', 'crtscts', $device, + $pppsettings{'DTERATE'}, 'noipdefault', + 'defaultroute', 'user', $pppsettings{'USERNAME'}, + 'maxfail', $pppsettings{'MAXRETRIES'}, 'connect', + '/bin/true')); + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + + system @pppcommand; +} + +sub doisdndial +{ + my $pppoptions; + my $seconds; + my $phone; + + if (system ('/etc/rc.d/rc.isdn', 'start')) { + &General::log ("ERROR: ISDN module failed to load"); + exit 1; + } + + $seconds = $pppsettings{'TIMEOUT'} * 60; + if ($pppsettings{'USEDOV'} eq 'on') + { + $phone = 'v' . $pppsettings{'TELEPHONE'}; + } + else + { + $phone = $pppsettings{'TELEPHONE'}; + }; + + if ($pppsettings{'COMPORT'} eq 'isdn2') + { + system('/usr/sbin/isdnctrl','addif','ippp0'); + system('/usr/sbin/isdnctrl','addslave','ippp0','ippp1'); + system('/usr/sbin/isdnctrl','l2_prot','ippp0','hdlc'); + system('/usr/sbin/isdnctrl','l3_prot','ippp0','trans'); + system('/usr/sbin/isdnctrl','encap','ippp0','syncppp'); + system('/usr/sbin/isdnctrl','dialmax','ippp0',$pppsettings{'MAXRETRIES'}); + system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'}); + system('/usr/sbin/isdnctrl','addphone','ippp0','out',$phone); + system('/usr/sbin/isdnctrl','huptimeout','ippp0',$seconds); + system('/usr/sbin/isdnctrl','l2_prot','ippp1','hdlc'); + system('/usr/sbin/isdnctrl','l3_prot','ippp1','trans'); + system('/usr/sbin/isdnctrl','encap','ippp1','syncppp'); + system('/usr/sbin/isdnctrl','dialmax','ippp1',$pppsettings{'MAXRETRIES'}); + system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'}); + system('/usr/sbin/isdnctrl','addphone','ippp1','out',$phone); + system('/usr/sbin/isdnctrl','huptimeout','ippp1',$seconds); + system('/usr/sbin/isdnctrl','dialmode','ippp1','auto'); + + my @pppcommand = ('/usr/sbin/ipppd','ms-get-dns','noipdefault','+mp', + 'defaultroute','user',$pppsettings{'USERNAME'}, + 'name',$pppsettings{'USERNAME'}, + 'active-filter','outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0', + 'pidfile','/var/run/ppp-ipcop.pid','/dev/ippp0','/dev/ippp1'); + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } + system (@pppcommand); + } + else + { + system('/usr/sbin/isdnctrl','addif','ippp0'); + system('/usr/sbin/isdnctrl','l2_prot','ippp0','hdlc'); + system('/usr/sbin/isdnctrl','l3_prot','ippp0','trans'); + system('/usr/sbin/isdnctrl','encap','ippp0','syncppp'); + system('/usr/sbin/isdnctrl','dialmax','ippp0',$pppsettings{'MAXRETRIES'}); + system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'}); + system('/usr/sbin/isdnctrl','addphone','ippp0','out',$phone); + system('/usr/sbin/isdnctrl','huptimeout','ippp0',$seconds); + + my @pppcommand = ('/usr/sbin/ipppd','ms-get-dns','noipdefault', + 'defaultroute','user',$pppsettings{'USERNAME'}, + 'name',$pppsettings{'USERNAME'}, + 'active-filter','outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0', + 'pidfile','/var/run/ppp-ipcop.pid','/dev/ippp0'); + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } + system (@pppcommand); + } + + sleep 1; + + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + system('/usr/sbin/isdnctrl','dialmode','ippp0','auto'); + system('/sbin/ifconfig','ippp0','10.112.112.112','pointopoint','10.112.112.113'); + system('/sbin/ifconfig','ippp0','-arp','-broadcast'); + system('/sbin/route','add','default','dev','ippp0'); + } else { + system('/usr/sbin/isdnctrl', 'dial', 'ippp0'); + + } + + system('/bin/killall', 'ibod'); + if ($pppsettings{'COMPORT'} eq 'isdn2') { + if ($pppsettings{'USEIBOD'} eq 'on') { + system("/usr/sbin/ibod &"); + } else { + system('/usr/sbin/isdnctrl', 'addlink', 'ippp0'); + } + } +} + +sub dopppoedial +{ + if ($pppsettings{'METHOD'} ne 'PPPOE_PLUGIN') { + my @pppcommand = ('/usr/sbin/pppd', 'pty'); + my @pppoecommand = ('/usr/sbin/pppoe', '-p','/var/run/pppoe.pid','-I', + $netsettings{'RED_DEV'}, '-T', '80', '-U', '-m', '1412'); + + if ($pppsettings{'SERVICENAME'}) { + push(@pppoecommand, ('-S', $pppsettings{'SERVICENAME'})); } + if ($pppsettings{'CONCENTRATORNAME'}) { + push(@pppoecommand, ('-C', $pppsettings{'CONCENTRATORNAME'})); } + + push(@pppcommand, "@pppoecommand"); + + if ($pppsettings{'DNS'} eq 'Automatic') { + push(@pppcommand, ('usepeerdns')); + } + + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } + + if ($pppsettings{'RECONNECTION'} ne 'persistent') { + if ($pppsettings{'TIMEOUT'} != 0) { + my $seconds = $pppsettings{'TIMEOUT'} * 60; + push(@pppcommand, ('idle', "$seconds")); + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + push (@pppcommand, ('demand','nopersist','connect','/bin/true')); + } + push (@pppcommand, + ('active-filter', + 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' )); + } + + push(@pppcommand, ('noipdefault', 'default-asyncmap', + 'defaultroute', 'hide-password', 'local', + 'mtu', '1492', 'mru', '1492', 'noaccomp', 'noccp', + 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp', + 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20', + 'lcp-echo-failure', '3', 'lcp-max-configure', '50', + 'maxfail',$pppsettings{'MAXRETRIES'})); + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + + system (@pppcommand); + } else { + # PPPoE plugin + system ('/sbin/modprobe pppoe'); + my @pppcommand = ('/usr/sbin/pppd'); + push(@pppcommand,'plugin','rp-pppoe.so',"$netsettings{'RED_DEV'}"); + if ($pppsettings{'DNS'} eq 'Automatic') { + push(@pppcommand, ('usepeerdns')); + } + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } + if ($pppsettings{'RECONNECTION'} ne 'persistent') { + if ($pppsettings{'TIMEOUT'} != 0) { + my $seconds = $pppsettings{'TIMEOUT'} * 60; + push(@pppcommand, ('idle', "$seconds")); + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + push (@pppcommand, ('demand','nopersist')); + } + push (@pppcommand, + ('active-filter', + 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' )); + } + push(@pppcommand, ('noipdefault', 'defaultroute', 'hide-password', 'ipcp-accept-local', + 'ipcp-accept-remote', 'passive', 'noccp','nopcomp', 'novjccomp', + 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20', + 'lcp-echo-failure', '3', 'lcp-max-configure', '50', + 'maxfail',$pppsettings{'MAXRETRIES'})); + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + + system (@pppcommand); + } +} + +sub dopptpdial +{ + my %pptpdhcpc; + my $routerip = $pppsettings{'ROUTERIP'} ? $pppsettings{'ROUTERIP'} : "10.0.0.138"; + if ( $pppsettings{'METHOD'} eq 'DHCP' && open(FILE, "${General::swroot}/red/device")) { + my $device = ; + close FILE; + chomp ($device); + $device =~ /([a-zA-Z0-9]*)/; $device = $1; + if (&General::readhash("${General::swroot}/dhcpc/dhcpcd-$device.info", \%pptpdhcpc)) { + system("/sbin/route add -host $routerip gw $pptpdhcpc{'GATEWAY'}"); + } else { + system("/sbin/route add -host $routerip dev $device"); + } + } + + my @pppcommand = ('/usr/sbin/pppd', 'pty'); + my @pptpcommand = ('/usr/sbin/pptp', $routerip, '--nobuffer', '--nolaunchpppd', '--sync'); + if ($pppsettings{'PHONEBOOK'}) { + push (@pptpcommand, ('--phone ', $pppsettings{'PHONEBOOK'})); + } + + push(@pppcommand, "@pptpcommand"); + + if ($pppsettings{'DNS'} eq 'Automatic') { + push(@pppcommand, ('usepeerdns')); + } + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } + + if ($pppsettings{'RECONNECTION'} ne 'persistent') { + if ($pppsettings{'TIMEOUT'} != 0) { + my $seconds = $pppsettings{'TIMEOUT'} * 60; + push(@pppcommand, ('idle', "$seconds")); + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + push (@pppcommand, ('demand','nopersist','connect','/bin/true')); + } + push (@pppcommand, + ('active-filter', + 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' )); + } + + push(@pppcommand, ('noipdefault', 'default-asyncmap', + 'defaultroute', 'hide-password', 'local','noaccomp', 'noccp', + 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp', + 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20', + 'lcp-echo-failure', '3', 'lcp-max-configure', '50', + 'maxfail',$pppsettings{'MAXRETRIES'},'sync')); + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + + system (@pppcommand); +} + +sub doalcatelusbdial +{ + if (system ('/etc/rc.d/rc.alcatelusb','start')) { + &General::log( "ERROR: Failed to connect to Alcatel USB modem"); + exit 1; + } + + if ($pppsettings{'PROTOCOL'} eq 'RFC1483') { + if (open(FILE, ">${General::swroot}/red/device")) { print FILE 'tap0'; close FILE; } + $netsettings{'RED_DEV'} = 'tap0'; + &dopppoedial(); + } else { + # PPPoA + my @pppcommand = ('/usr/sbin/pppd', 'pty'); + my @pppoacommand = ('/usr/sbin/pppoa3','-c','-m','1','-vpi',$pppsettings{'VPI'},'-vci',$pppsettings{'VCI'}); + + push(@pppcommand, "@pppoacommand"); + + if ($pppsettings{'DNS'} eq 'Automatic') { + push(@pppcommand, ('usepeerdns')); + } + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } + + if ($pppsettings{'RECONNECTION'} ne 'persistent') { + if ($pppsettings{'TIMEOUT'} != 0) { + my $seconds = $pppsettings{'TIMEOUT'} * 60; + push(@pppcommand, ('idle', "$seconds")); + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + push (@pppcommand, ('demand','nopersist','connect','/bin/true')); + } + push (@pppcommand, + ('active-filter', + 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' )); + } + + push(@pppcommand, ('noipdefault', 'defaultroute', 'sync', 'user', + $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive', + 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp', + 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3', + 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'})); + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + + system (@pppcommand); + } +} + +sub doeciadsldial +{ + if (system ('/etc/rc.d/rc.eciadsl','start')) { + &General::log ("ERROR: ECI ADSL failed to start"); + exit 1; + } + if ($pppsettings {'PROTOCOL'} eq 'RFC1483') { + if ($pppsettings {'ENCAP'} =~ /^(0|1)$/) { + $iface = "tap0"; + } else { + $iface = "tun0"; + } + + if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; } + + if ($pppsettings {'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) { + if (open(FILE, ">${General::swroot}/red/device")) { print FILE $iface; close FILE; } + $netsettings{'RED_DEV'} = $iface; + &dopppoedial(); + } elsif ($pppsettings{'METHOD'} eq 'STATIC') { + my @staticcommand = ('/sbin/ifconfig'); + push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'})); + if ($pppsettings{'BROADCAST'} ne '') { + push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'})); + } + system (@staticcommand); + system ("/sbin/route","add","default","gw",$pppsettings{'GATEWAY'}); + system ("/bin/touch", "${General::swroot}/red/active"); + if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; } + } elsif ($pppsettings {'METHOD'} eq 'DHCP') { + # FIXME dhcp does not support tun0 interface (routed IP) + dodhcpdial($iface,$pppsettings{'DHCP_HOSTNAME'}); + } + } else { + # PPPoA + my ($VID2, $PID2, $CHIP, $ALTP, $ECIMODE); + open (MODEMS, "/etc/eciadsl/modems.db") or die 'Unable to open modems database.'; + while (my $line = ) { + $line =~ s/\s*\t+\s*/|/g; + $line =~ /^(.+)\|(.+)\|(.+)\|(.+)\|(.+)\|(.+)\|(.+)\|(.+)$/; + if ( $1 eq $pppsettings{'MODEM'} ) { + $VID2=$4 ; $PID2=$5; $CHIP=$6; $ALTP=$8; + } + } + close (MODEMS); + if ( $VID2 eq '') { + &General::log("$pppsettings{'MODEM'} not found in modems.db"); + exit 1; + } + if ( $CHIP eq '' ) { + &General::log ("error in modems.db reading for $pppsettings{'MODEM'}"); + exit 1; + } + if ($pppsettings {'ENCAP'} eq '1') { + $ECIMODE = "LLC_RFC2364"; + } else { + $ECIMODE = "VCM_RFC2364"; + } + + my @pppcommand = ('/usr/sbin/pppd', 'pty'); + my @pppoecicommand = ("/usr/sbin/eciadsl-pppoeci",'-alt', "$ALTP",'-vpi',$pppsettings{'VPI'},'-vci',$pppsettings{'VCI'}, + '-vendor',"0x$VID2",'-product',"0x$PID2",'-mode',$ECIMODE); + push(@pppcommand, "@pppoecicommand"); + + if ($pppsettings{'DNS'} eq 'Automatic') { + push(@pppcommand, ('usepeerdns')); + } + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } + + if ($pppsettings{'RECONNECTION'} ne 'persistent') { + if ($pppsettings{'TIMEOUT'} != 0) { + my $seconds = $pppsettings{'TIMEOUT'} * 60; + push(@pppcommand, ('idle', "$seconds")); + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + push (@pppcommand, ('demand','nopersist','connect','/bin/true')); + } + push (@pppcommand, + ('active-filter', + 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' )); + } + + push(@pppcommand, ('noipdefault', 'defaultroute', 'sync', 'user', + $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive', + 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp', + 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3', + 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'})); + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + + system (@pppcommand); + } +} + +sub dofritzdsldial +{ + my $controller; + + if (system ('/etc/rc.d/rc.fritzdsl','start')) { + &General::log ("ERROR: Fritz DSL module failed to load"); + exit 1; + } + + # controller number + if ($pppsettings{'TYPE'} eq 'fritzdsl') { + if ( ! system ('/bin/grep', '1244:2700', '/proc/pci')) { + $controller=1; # fcdslsl + } elsif (! system('/bin/grep', '1244:2900', '/proc/pci')) { + $controller=2; # fcdsl2 + } elsif (! system('/bin/grep', '1131:5402', '/proc/pci')) { + $controller=2; # fdsl + } elsif (! system('/bin/grep', 'Vendor=057c ProdID=2300', '/proc/bus/usb/devices')) { + $controller=1; # fcdslusb + } elsif (! system('/bin/grep', 'Vendor=057c ProdID=3500', '/proc/bus/usb/devices')) { + $controller=1; # fcdslslusb + } + } + my @pppcommand = ('/usr/sbin/pppd'); + my @capiplugin; + + if ($pppsettings{'DNS'} eq 'Automatic') { + push(@pppcommand, ('usepeerdns')); + } + + if ($pppsettings{'RECONNECTION'} ne 'persistent') { + if ($pppsettings{'TIMEOUT'} != 0) { + my $seconds = $pppsettings{'TIMEOUT'} * 60; + push(@pppcommand, ('idle', "$seconds")); + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + push (@pppcommand, ('demand','nopersist','connect','/bin/true')); + } + push (@pppcommand, + ('active-filter', + 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' )); + } + + push(@pppcommand, ('noipdefault', 'defaultroute', 'sync', 'user', + $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive', + 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp', + 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3', + 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'})); + + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + + if ($pppsettings {'PROTOCOL'} eq 'RFC1483') { + @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoe', + 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'}); + } else { + if ($pppsettings {'ENCAP'} eq '1') { + @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoallc', + 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'}); + } else { + @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoa', + 'controller', $controller,'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'}); + } + } + push(@pppcommand, @capiplugin); + push(@pppcommand, '/dev/null'); + + system (@pppcommand); +} + +sub doeagleusbadsldial +{ + if (system ('/etc/rc.d/rc.eagleusbadsl','start')) { + &General::log ("ERROR: EAGLE-USB ADSL MODEM failed to start"); + exit 1; + } + $iface=`/usr/sbin/eaglectrl -i 2>/dev/null | /usr/bin/tr -d '\012'`; + $iface =~ /([a-zA-Z0-9]*)/; $iface = $1; + + if ($pppsettings {'PROTOCOL'} eq 'RFC1483') { + if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; } + if ($pppsettings {'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) { + if (open(FILE, ">${General::swroot}/red/device")) { print FILE $iface; close FILE; } + $netsettings{'RED_DEV'} = $iface; + &dopppoedial(); + } elsif ($pppsettings{'METHOD'} eq 'STATIC') { + my @staticcommand = ('/sbin/ifconfig'); + push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'})); + if ($pppsettings{'BROADCAST'} ne '') { + push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'})); + } + system (@staticcommand); + system ("/sbin/route","add","default","gw",$pppsettings{'GATEWAY'}); + system ("/bin/touch", "${General::swroot}/red/active"); + } elsif ($pppsettings {'METHOD'} eq 'DHCP') { + dodhcpdial($iface,$pppsettings{'DHCP_HOSTNAME'}); + } + } else { + # PPPoA + if (open(FILE, ">${General::swroot}/red/device")) { print FILE $iface; close FILE; } + $netsettings{'RED_DEV'} = $iface; + my @pppcommand = ('/usr/sbin/pppd','pty'); + push(@pppcommand,"/usr/sbin/pppoa -I $iface "); + + if ($pppsettings{'DNS'} eq 'Automatic') { push(@pppcommand, ('usepeerdns'));} + + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } + + if ($pppsettings{'RECONNECTION'} ne 'persistent') { + if ($pppsettings{'TIMEOUT'} != 0) { + my $seconds = $pppsettings{'TIMEOUT'} * 60; + push(@pppcommand, ('idle', "$seconds")); + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + push (@pppcommand, ('demand','nopersist','connect','/bin/true')); + } + push (@pppcommand, + ('active-filter', + 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' )); + } + push(@pppcommand, ('noipdefault', 'defaultroute', 'user', + $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive', + 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp', + 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3', + 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'})); + + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + + system (@pppcommand); + } +} + +sub dopulsardsldial +{ + if (system ('/etc/rc.d/rc.pulsardsl','start')) { + &General::log ("ERROR: PULSAR ADSL modem failed to start"); + exit 1; + } + doatmdial(); +} + +sub dobewanadsldial +{ + if (system ('/etc/rc.d/rc.bewanadsl','start')) { + &General::log ("ERROR: Bewan ADSL MODEM failed to start"); + exit 1; + } + doatmdial(); +} + +sub doalcatelusbkdial +{ + if (system ('/etc/rc.d/rc.alcatelusbk','start')) { + &General::log ("ERROR: Alcatel USB kernel mode driver failed to start"); + exit 1; + } + doatmdial(); +} + +sub doconexantusbadsldial +{ + if (system ('/etc/rc.d/rc.conexantusbadsl','start')) { + &General::log ("ERROR: Conexant USB ADSL modem failed to start"); + exit 1; + } + doatmdial(); + +} + +sub doconexantpciadsldial +{ + if (system ('/etc/rc.d/rc.conexantpciadsl','start')) { + &General::log ("ERROR: Conexant PCI ADSL modem failed to start"); + exit 1; + } + doatmdial(); + +} + +sub doamedynusbadsldial +{ + if (system ('/etc/rc.d/rc.amedynusbadsl','start')) { + &General::log ("ERROR: Zyxel 630-11/Asus AAM6000UG USB ADSL modem failed to start"); + exit 1; + } + doatmdial(); + +} + +sub do3cp4218usbadsldial +{ + if (system ('/etc/rc.d/rc.3cp4218usbadsl','start')) { + &General::log ("ERROR: 3Com USB AccessRunner modem failed to start"); + exit 1; + } + doatmdial(); +} + +sub doatmdial +{ + my $ENCAP; + if ($pppsettings {'PROTOCOL'} eq 'RFC2364') { + system ('/sbin/modprobe pppoatm'); + my @pppcommand = ('/usr/sbin/pppd'); + if ($pppsettings{'ENCAP'} eq '0') { $ENCAP='vc-encaps'; } else { $ENCAP='llc-encaps'; } + push(@pppcommand,'plugin', 'pppoatm.so',$pppsettings{'VPI'}.".".$pppsettings{'VCI'},"$ENCAP"); + if ($pppsettings{'DNS'} eq 'Automatic') { push(@pppcommand, ('usepeerdns'));} + if ($pppsettings{'AUTH'} eq 'pap') { + push(@pppcommand, ('-chap')); + } elsif ($pppsettings{'AUTH'} eq 'chap') { + push(@pppcommand, ('-pap')); + } + if ($pppsettings{'RECONNECTION'} ne 'persistent') { + if ($pppsettings{'TIMEOUT'} != 0) { + my $seconds = $pppsettings{'TIMEOUT'} * 60; + push(@pppcommand, ('idle', "$seconds")); + } + if ($pppsettings{'RECONNECTION'} eq 'dialondemand') { + push (@pppcommand, ('demand','nopersist')); + } + push (@pppcommand, + ('active-filter', + 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' )); + } + push(@pppcommand, ('noipdefault', 'defaultroute', 'user', + $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive', + 'nopcomp', 'noccp', 'novj', 'nobsdcomp', + 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3', + 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'})); + + if ($pppsettings{'DEBUG'} eq 'on') { + push(@pppcommand, ('debug')); + } + + system (@pppcommand); + } elsif ($pppsettings {'PROTOCOL'} eq 'RFC1483') { + if ($pppsettings {'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) { + my $itf='0'; + my $device = "nas$itf"; + if (open(FILE, ">${General::swroot}/red/device")) { print FILE $device; close FILE; } + $netsettings{'RED_DEV'} = $device; + if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) { + system ('/sbin/modprobe br2684'); + system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}"); + sleep 3; + } + system ('/sbin/ifconfig',"$device",'up'); + &dopppoedial(); + } elsif ($pppsettings{'ENCAP'} =~ /^(0|1)$/) { + my $itf='0'; + $iface = "nas$itf"; + if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; } + if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) { + system ('/sbin/modprobe br2684'); + system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}"); + sleep 3; + } + system ('/sbin/ifconfig',"$iface",'up'); + + if ($pppsettings{'METHOD'} eq 'STATIC') { + my @staticcommand = ('/sbin/ifconfig'); + push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'})); + if ($pppsettings{'BROADCAST'} ne '') { + push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'})); + } + system (@staticcommand); + system ("/sbin/route","add","default","gw",$pppsettings{'GATEWAY'}); + system ("/bin/touch", "${General::swroot}/red/active"); + system ("/etc/rc.d/init.d/network red update"); + } elsif ($pppsettings {'METHOD'} eq 'DHCP') { + dodhcpdial($iface,$pppsettings{'DHCP_HOSTNAME'}); + } + } elsif ($pppsettings{'ENCAP'} =~ /^(2|3)$/) { + my $itf='0'; + $iface = "atm$itf"; + if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; } + if (system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) { + if (system ('/usr/sbin/atmarpd -b -l syslog')) { + &General::log('atmarpd fail'); + exit 1; + } + # it will fail on all attempt after the first because interface still exist + system ("/usr/sbin/atmarp -c $iface 2>/dev/null"); + + if ($pppsettings{'METHOD'} eq 'STATIC') { + my @staticcommand = ('/sbin/ifconfig'); + push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}, 'up')); + if ($pppsettings{'BROADCAST'} ne '') { + push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'})); + } + system (@staticcommand); + # we have to wait a bit before launching atmarp -s + sleep 2; + my @atmarp = ('/usr/sbin/atmarp', '-s', $pppsettings{'GATEWAY'}, "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}"); + if ($pppsettings{'ENCAP'} eq '3') { + push(@atmarp, 'null' ); # routed ip vc encap + } + system (@atmarp); + system ("/sbin/route", "add", "default", "gw", $pppsettings{'GATEWAY'}); + system ("/bin/touch", "${General::swroot}/red/active"); + } + } + } + } +} diff --git a/src/install+setup/install/install2.c b/src/install+setup/install/install2.c deleted file mode 100644 index b23525e46c..0000000000 --- a/src/install+setup/install/install2.c +++ /dev/null @@ -1,415 +0,0 @@ -/* IPCop install2 program. - * - * This program is distributed under the terms of the GNU General Public - * Licence. See the file COPYING for details. - * - * (c) Lawrence Manning, 2001 - * (c) Franck Bourdonnec, 2006 - * Contains update/restore code - * - * $Id: install2.c,v 1.1.2.5 2006/02/10 06:53:57 gespinasse Exp $ - * - */ -#include "install.h" - -FILE *flog = NULL; -char *mylog; -char **ctr; - -/* - To include a translated string in the final installer, you must reference - it here with a simplr comment. This save a lot a space in the installer -*/ - -/* TR_BUILDING_INITRD */ -/* TR_HELPLINE */ -/* TR_SKIP */ -/* TR_RESTORE_CONFIGURATION */ -/* TR_RESTORE */ -/* TR_OK */ -/* TR_CANCEL */ -/* TR_ERROR */ -/* TR_INSTALLING_FILES */ -/* TR_FAILED_TO_FIND */ -/* TR_UNABLE_TO_INSTALL_FILES */ -/* TR_LOADING_PCMCIA */ - -//libsmooth -/* TR_INTERFACE */ -/* TR_ENTER_THE_IP_ADDRESS_INFORMATION */ -/* TR_STATIC */ -/* TR_DHCP_HOSTNAME */ -/* TR_IP_ADDRESS_PROMPT */ -/* TR_NETMASK_PROMPT */ -/* TR_INVALID_FIELDS */ -/* TR_IP_ADDRESS_CR */ -/* TR_NETWORK_MASK_CR */ -/* TR_DHCP_HOSTNAME_CR */ -/* TR_LOOKING_FOR_NIC */ -/* TR_MANUAL */ -/* TR_SELECT_NETWORK_DRIVER */ -/* TR_SELECT_NETWORK_DRIVER_LONG */ -/* TR_UNABLE_TO_LOAD_DRIVER_MODULE */ -/* TR_THIS_DRIVER_MODULE_IS_ALREADY_LOADED */ -/* TR_MODULE_PARAMETERS */ -/* TR_LOADING_MODULE */ -/* TR_MODULE_NAME_CANNOT_BE_BLANK */ - -//upgrade 120 -/* TR_UNABLE_TO_OPEN_SETTINGS_FILE */ -/* TR_DOMAINNAME */ -/* TR_ENTER_DOMAINNAME */ -/* TR_DOMAINNAME_CANNOT_CONTAIN_SPACES */ -/* TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM */ -/* TR_UNABLE_TO_WRITE_ETC_FSTAB */ - -// dir to find files, chrooted or not... -#define TMP_EXTRACT_CH "/tmp/ipcop" -#define TMP_EXTRACT "/harddisk" TMP_EXTRACT_CH -#define MOUNT_BACKUP_CH "/mnt/usb" -#define MOUNT_BACKUP "/harddisk" MOUNT_BACKUP_CH -/* - return 0 when dev contains a backup set - leave dev mounted -*/ -int try_mount (char *dev, char *testfile) { - char commandstring[STRING_SIZE]; - mysystem("/bin/umount " MOUNT_BACKUP); - sprintf(commandstring, "/bin/mount -t vfat -o ro %s " MOUNT_BACKUP, dev); - mysystem(commandstring); - - /*verify it's what we want */ - sprintf(commandstring, MOUNT_BACKUP "/%s.dat", testfile); - FILE *handle = fopen(commandstring, "r"); - if (handle == NULL) { - return 1; /* bad disk ! */ - } - fclose(handle); - - handle = fopen(MOUNT_BACKUP "/backup.key", "r"); - if (handle == NULL) { - return 1; /* bad disk ! */ - } - fclose(handle); - return 0; //success -} - -/* try to mount usb device until backup.tgz is found except the - destination device (scsi names are identical with usb key) - check "sda sdb sdc sdd" -*/ -int mountbackup (char *testfile, char *destination_device) { - char sourcedev[30]; - char i,j; - for (i = 'a'; i < 'e'; i++) { - sprintf (sourcedev,"/dev/sd%c ",i); - if (strcmp (destination_device, sourcedev) != 0) { - if (!try_mount (sourcedev, testfile)) return 0; - } - for (j = '1'; j < '5'; j++) { - sourcedev[8] = j; - if (strcmp (destination_device, sourcedev) != 0) { - if (!try_mount (sourcedev, testfile)) return 0; - } - } - } - return 1; -} - -int floppy_locate() { - /* Temporarily mount /proc under /harddisk/proc, - run updfstab to locate the floppy, and unmount /harddisk/proc - again. This should be run each time the user tries to restore - so it can properly detect removable devices */ - if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) { - errorbox(ctr[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM]); - return 1; - } - if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) { - errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_FSTAB]); - return 1; - } - mysystem("/bin/umount /harddisk/proc"); - return 0; -} - -/* Check the SQUID acl file exists, if not use our 1.4 copy */ -void fixup_squidacl() { - FILE *aclreadfile; - if ((aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) { - unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4"); - fclose(aclreadfile); - } else { - rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4", - "/harddisk" CONFIG_ROOT "/proxy/acl"); - } - chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99); -} -/* if we detected SCSI then fixup */ -void fixup_initrd() { - FILE *handle; - char line[STRING_SIZE]; - char commandstring[STRING_SIZE]; - - if (!(handle = fopen("/scsidriver", "r"))) - return; - - char *driver; - fgets(line, STRING_SIZE-1, handle); - fclose(handle); - line[strlen(line) - 1] = 0; - driver = strtok(line, "."); - fprintf(flog, "Detected SCSI driver %s\n", driver); - if (!strlen(driver) > 1) - return; - - fprintf(flog, "Fixing up ipfirerd.img\n"); - mysystem("/bin/chroot /harddisk /sbin/modprobe loop"); - mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO); - sprintf(commandstring, "/bin/chroot /harddisk /sbin/mkinitrd" - " --with=scsi_mod --with=%s --with=sd_mod" - " --with=sr_mod --with=libata" - " --with=ataraid /boot/ipfirerd.img "KERNEL_VERSION, - driver ); - runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); -#ifdef __i386__ - sprintf(commandstring, "/bin/chroot /harddisk /sbin/mkinitrd" - " --with=scsi_mod --with=%s --with=sd_mod" - " --with=sr_mod --with=libata" - " --with=ataraid /boot/ipfirerd-smp.img "KERNEL_VERSION"-smp", - driver ); - runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); - mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf"); -#endif -#ifdef __alpha__ - runcommandwithstatus("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf", ctr[TR_BUILDING_INITRD]); -#endif -} -/* when backup is ready in tmpdir, move files to definitive location */ -void do_copy_files() { - mysystem("/bin/chroot /harddisk /bin/cp -af "TMP_EXTRACT_CH"/. /"); - /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */ - upgrade_v12_v13(); - upgrade_v130_v140(); - /* Upgrade configuration files starting from 1.4.11 */ - mysystem("/bin/chroot /harddisk /usr/local/bin/upgrade"); -} - -int main(int argc, char *argv[]) { -#define LANG argv[1] -#define DEST_DEV argv[2] -#define WGET argv[3] - -#ifdef LANG_EN_ONLY - char **langtrs[] = { en_tr, NULL }; -#elifdef LANG_ALL - char **langtrs[] = { bz_tr, cs_tr, da_tr, de_tr, en_tr, es_tr, fr_tr, el_tr, it_tr, la_tr, hu_tr, nl_tr, no_tr, pl_tr, pt_tr, sk_tr, so_tr, fi_tr, sv_tr, tr_tr, vi_tr, NULL }; -#else - char **langtrs[] = { de_tr, en_tr, NULL }; -#endif - char message[1000]; - char title[STRING_SIZE]; - char commandstring[STRING_SIZE]; - - setlocale (LC_ALL, ""); - /* Log file/terminal stuff. */ - mylog = "/dev/tty2"; - ctr = langtrs[ atoi(LANG) ]; - - if (!(flog = fopen(mylog, "w+"))) - { - printf("Couldn't open log terminal\n"); - return 0; - } - fprintf(flog, "Install2 program started.\n"); - newtInit(); - newtCls(); - strcpy (title, NAME " v" VERSION " - " SLOGAN); - newtDrawRootText(14, 0, title); - newtPushHelpLine(ctr[TR_HELPLINE]); - - /* working dirs... */ - mkdir(MOUNT_BACKUP, S_IRWXU|S_IRWXG|S_IRWXO); - - //create the GUI screen and objects - newtComponent form, header, labelfile, labelkey, file, key, radio0, radio1, radio2, radio3, radio4, ok; - - newtCenteredWindow (55,20,ctr[TR_RESTORE]); - form = newtForm (NULL, NULL,0); - - sprintf(message, ctr[TR_RESTORE_CONFIGURATION], NAME); - header = newtTextboxReflowed (2,1,message,51,0,0,0); - newtFormAddComponent(form, header); - - // The four method of restauration - int start1=1, start2=0, start3=0, start4=0; - radio1 = newtRadiobutton (17, 5, ctr[TR_SKIP], start1, NULL); - radio2 = newtRadiobutton (17, 6, "Floppy (legacy)", start2, radio1); - radio3 = newtRadiobutton (17, 7, "Usb-storage/CDROM", start3, radio2); - if (strcmp(WGET,"none")) - radio4 = newtRadiobutton (17, 8, "HTTP/FTP", start4, radio3); - else - radio4 = NULL; - newtFormAddComponents(form, radio1, radio2, radio3, radio4, NULL); - - // The optionnal filename for 'backup' - labelfile=newtTextbox(12, 10, 35, 1, 0); - newtTextboxSetText (labelfile, "Filename"); - newtFormAddComponent(form, labelfile); - char *filevalue; - char fileinit[STRING_SIZE] = "backup"; - file = newtEntry (17, 11, fileinit, 20, &filevalue, 0); - newtFormAddComponent(form, file); - - // The optionnal password for the key - labelkey=newtTextbox(12, 13, 35, 1, 0); - newtTextboxSetText (labelkey, "Backup key password"); - newtFormAddComponent(form, labelkey); - char *keyvalue; - char keyinit[STRING_SIZE] = ""; - key = newtEntry (17, 14, keyinit, 20, &keyvalue, 0); - newtFormAddComponent(form, key); - - // The OK button - ok=newtButton (23, 16, ctr[TR_OK]); - newtFormAddComponent(form, ok); - - /* loop until succeeds or user skips out */ - int retcode = -1; - while ( retcode<0 ) { - - // run the windows - struct newtExitStruct reponse; - newtFormRun (form, &reponse); - radio0 = newtRadioGetCurrent(radio1); - int radio; - radio = radio0 == radio1 ? 1 : radio0 == radio2 ? 2 : radio0 == radio3 ? 3 : radio0 == radio4 ? 4 : 0; - strcpy(keyinit,keyvalue); //reuse actual value - strcpy(fileinit,filevalue); - - if (radio==1) { - retcode = 1; // no restore: nothing special - break; // out of the while loop - } - - mkdir(TMP_EXTRACT, S_IRWXU|S_IRWXG|S_IRWXO); - statuswindow(45, 4, title, ctr[TR_INSTALLING_FILES]); - switch (radio) { - case 4: // network - sprintf(commandstring,"/bin/wget -P " TMP_EXTRACT " %s/%s.dat", WGET, filevalue); - mysystem (commandstring); - sprintf(commandstring,"/bin/wget -P " TMP_EXTRACT " %s/%s.key", WGET, filevalue); - if (mysystem (commandstring)) { - errorbox(ctr[TR_FAILED_TO_FIND]); - break; - }; - goto COMMON; - case 3: // normal backup - if (mountbackup( filevalue, DEST_DEV )) { - errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);//mess=no device with backup found - break; - }; - // link files to a COMMON location - sprintf (commandstring, "chroot /harddisk ln -s "MOUNT_BACKUP_CH"/%s.dat " TMP_EXTRACT_CH "/%s.dat", filevalue, filevalue); - mysystem (commandstring); - sprintf (commandstring, "chroot /harddisk ln -s "MOUNT_BACKUP_CH"/%s.key " TMP_EXTRACT_CH "/%s.key", filevalue, filevalue); - mysystem (commandstring); - - COMMON: // DECRYPT THE TARBALL - // Copy the key to a new location because we decrypt it! - if (strcmp(keyvalue, "")) { // password provided: decrypt the key - sprintf(commandstring, "/bin/chroot /harddisk /usr/bin/openssl enc" - " -a -d -aes256 -salt" - " -pass pass:%s" - " -in " TMP_EXTRACT_CH "/%s.key" - " -out " TMP_EXTRACT_CH "/__tmp.key", - keyvalue, filevalue); - } else { //just copy to new name - sprintf(commandstring, "/bin/chroot /harddisk cp" - " " TMP_EXTRACT_CH "/%s.key" - " " TMP_EXTRACT_CH "/__tmp.key", - filevalue); - } - mysystem (commandstring); - - sprintf(commandstring, "/bin/chroot /harddisk /usr/bin/openssl des3" - " -d -salt" - " -in " TMP_EXTRACT_CH "/%s.dat" - " -out " TMP_EXTRACT_CH "/backup.tgz" - " -kfile " TMP_EXTRACT_CH "/__tmp.key", - filevalue); - - if (mysystem (commandstring)) { - errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);//mess=decrypt error:invalid key? - break; - } - strcpy(commandstring, "/bin/chroot /harddisk /bin/tar" - " -X " CONFIG_ROOT "/backup/exclude.system" - " -C " TMP_EXTRACT_CH - " -xzf " TMP_EXTRACT_CH "/backup.tgz"); - - if (mysystem(commandstring)) { - errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); - break; - } - sprintf(commandstring, TMP_EXTRACT "/%s.dat", filevalue); - unlink(commandstring ); //dont need them anymore - unlink( TMP_EXTRACT "/backup.tgz"); - sprintf(commandstring, TMP_EXTRACT "/%s.key", filevalue); - unlink(commandstring ); - unlink( TMP_EXTRACT "/__tmp.key"); - - /* Now copy to correct location */ - do_copy_files(); - retcode = 0; /* successfully restored */ - break; - case 2: - // diskette change - if (floppy_locate()) { - retcode = 2; // this an error! - break; - } - - /* Always extract to /tmp/ipcop for temporary extraction - just in case floppy fails. - try a compressed backup first because it's quicker to fail. - In exclude.system, files name must be without leading / or - on extraction, name will never match - */ - sprintf(commandstring, - "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C "TMP_EXTRACT_CH" -xvzf /dev/floppy > %s 2> /dev/null", mylog); - if (system(commandstring)) { - /* if it's not compressed, try uncompressed first before failing*/ - sprintf(commandstring, - "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C "TMP_EXTRACT_CH" -xvf /dev/floppy > %s 2> /dev/null", mylog); - if (system(commandstring)) { - /* command failed trying to read from floppy */ - errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); - break; - } - } - /* Now copy to correct location */ - do_copy_files(); - retcode = 0; /* successfully restored */ - }//switch - /* remove possible badly restored files */ - mysystem("/bin/chroot /harddisk /bin/rm -rf " TMP_EXTRACT_CH ); - newtPopWindow(); // close windows - }//while - newtFormDestroy(form); - - /* cleanup */ - mysystem("/bin/umount " MOUNT_BACKUP); - mysystem("/bin/chroot /harddisk /bin/rmdir " MOUNT_BACKUP_CH); - - /* others operations moved from install to install2 */ - fixup_squidacl(); - fixup_initrd(); - - fprintf(flog, "Install2 program ended.\n"); - fflush(flog); - fclose(flog); - newtFinished(); - return retcode; -} - diff --git a/src/install+setup/install/main.c b/src/install+setup/install/main.c index 9e6443f7df..33f910bff7 100644 --- a/src/install+setup/install/main.c +++ b/src/install+setup/install/main.c @@ -823,7 +823,7 @@ EXIT: { if (!unattended) { - if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL")) + if (system("/sbin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL")) printf("Unable to run setup.\n"); } else { diff --git a/src/install+setup/setup/keymap.c b/src/install+setup/setup/keymap.c index 5fec1e28b9..9d611df696 100644 --- a/src/install+setup/setup/keymap.c +++ b/src/install+setup/setup/keymap.c @@ -1,167 +1,167 @@ -/* SmoothWall setup program. - * - * This program is distributed under the terms of the GNU General Public - * Licence. See the file COPYING for details. - * - * (c) Lawrence Manning, 2001 - * Stuff for setting the keymap. - * - * $Id: keymap.c,v 1.9.2.1 2004/04/14 22:05:41 gespinasse Exp $ - * - */ - -#include "setup.h" - -extern FILE *flog; -extern char *mylog; - -extern char **ctr; - -extern int automode; - -#define MAX_FILENAMES 5000 -#define KEYMAPROOT "/usr/share/kbd/keymaps/i386/" - -static int filenamecount; -static char *filenames[MAX_FILENAMES]; -static char *displaynames[MAX_FILENAMES]; - -static int process(char *prefix, char *path); -static int cmp(const void *s1, const void *s2); - -int handlekeymap(void) -{ - int c; - int choice; - char *temp; - struct keyvalue *kv = initkeyvalues(); - int rc; - int result; - char keymap[STRING_SIZE]; - char commandstring[STRING_SIZE]; - - filenamecount = 0; - - process(KEYMAPROOT "azerty", ""); - process(KEYMAPROOT "dvorak", ""); - process(KEYMAPROOT "fgGIod", ""); - process(KEYMAPROOT "qwerty", ""); - process(KEYMAPROOT "qwertz", ""); - filenames[filenamecount] = NULL; - qsort(filenames, filenamecount, sizeof(char *), cmp); - - for (c = 0; filenames[c]; c++) - { - displaynames[c] = malloc(STRING_SIZE); - if ((temp = strrchr(filenames[c], '/'))) - strcpy(displaynames[c], temp + 1); - else - strcpy(displaynames[c], filenames[c]); - if ((temp = strstr(displaynames[c], ".map.gz"))) - *temp = '\0'; - } - displaynames[c] = NULL; - - if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) - { - freekeyvalues(kv); - errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); - return 0; - } - - strcpy(keymap, "/usr/share/kbd/keymaps/i386/qwertz/de.map.gz"); - findkey(kv, "KEYMAP", keymap); - - choice = 0; - for (c = 0; filenames[c]; c++) - { - if (strcmp(keymap, filenames[c]) == 0) - choice = c; - } - - rc = newtWinMenu(ctr[TR_KEYBOARD_MAPPING], ctr[TR_KEYBOARD_MAPPING_LONG], 50, 5, 5, 6, displaynames, &choice, - ctr[TR_OK], ctr[TR_CANCEL], NULL); - - strcpy(keymap, filenames[choice]); - - if (rc != 2) - { - replacekeyvalue(kv, "KEYMAP", keymap); - writekeyvalues(kv, CONFIG_ROOT "/main/settings"); - sprintf(commandstring, "/bin/loadkeys %s", keymap); - mysystem(commandstring); - result = 1; - } - else - result = 0; - - for (c = 0; filenames[c]; c++) - { - free(filenames[c]); - free(displaynames[c]); - } - freekeyvalues(kv); - - return result; -} - -static int process(char *prefix, char *path) -{ - DIR *dir; - struct dirent *de; - char newpath[PATH_MAX]; - - snprintf(newpath, PATH_MAX, "%s%s", prefix, path); - - if (!(dir = opendir(newpath))) - { - if (filenamecount > MAX_FILENAMES) - return 1; - - filenames[filenamecount] = (char *) strdup(newpath); - filenamecount++; - return 0; - } - - while ((de = readdir(dir))) - { - if (de->d_name[0] == '.') continue; - snprintf(newpath, PATH_MAX, "%s/%s", path, de->d_name); - process(prefix, newpath); - } - closedir(dir); - - return 1; -} - -/* Small wrapper for use with qsort() to sort filename part. */ -static int cmp(const void *s1, const void *s2) -{ - /* c1 and c2 are copies. */ - char *c1 = strdup(* (char **) s1); - char *c2 = strdup(* (char **) s2); - /* point to somewhere in cN. */ - char *f1, *f2; - char *temp; - int res; - - if ((temp = strrchr(c1, '/'))) - f1 = temp + 1; - else - f1 = c1; - if ((temp = strrchr(c2, '/'))) - f2 = temp + 1; - else - f2 = c2; - /* bang off the . */ - if ((temp = strchr(f1, '.'))) - *temp = '\0'; - if ((temp = strchr(f2, '.'))) - *temp = '\0'; - - res = strcmp(f1, f2); - - free(c1); free(c2); - - return res; -} +/* SmoothWall setup program. + * + * This program is distributed under the terms of the GNU General Public + * Licence. See the file COPYING for details. + * + * (c) Lawrence Manning, 2001 + * Stuff for setting the keymap. + * + * $Id: keymap.c,v 1.9.2.1 2004/04/14 22:05:41 gespinasse Exp $ + * + */ + +#include "setup.h" + +extern FILE *flog; +extern char *mylog; + +extern char **ctr; + +extern int automode; + +#define MAX_FILENAMES 5000 +#define KEYMAPROOT "/lib/kbd/keymaps/i386/" + +static int filenamecount; +static char *filenames[MAX_FILENAMES]; +static char *displaynames[MAX_FILENAMES]; + +static int process(char *prefix, char *path); +static int cmp(const void *s1, const void *s2); + +int handlekeymap(void) +{ + int c; + int choice; + char *temp; + struct keyvalue *kv = initkeyvalues(); + int rc; + int result; + char keymap[STRING_SIZE]; + char commandstring[STRING_SIZE]; + + filenamecount = 0; + + process(KEYMAPROOT "azerty", ""); + process(KEYMAPROOT "dvorak", ""); + process(KEYMAPROOT "fgGIod", ""); + process(KEYMAPROOT "qwerty", ""); + process(KEYMAPROOT "qwertz", ""); + filenames[filenamecount] = NULL; + qsort(filenames, filenamecount, sizeof(char *), cmp); + + for (c = 0; filenames[c]; c++) + { + displaynames[c] = malloc(STRING_SIZE); + if ((temp = strrchr(filenames[c], '/'))) + strcpy(displaynames[c], temp + 1); + else + strcpy(displaynames[c], filenames[c]); + if ((temp = strstr(displaynames[c], ".map.gz"))) + *temp = '\0'; + } + displaynames[c] = NULL; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) + { + freekeyvalues(kv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + strcpy(keymap, "/lib/kbd/keymaps/i386/qwertz/de.map.gz"); + findkey(kv, "KEYMAP", keymap); + + choice = 0; + for (c = 0; filenames[c]; c++) + { + if (strcmp(keymap, filenames[c]) == 0) + choice = c; + } + + rc = newtWinMenu(ctr[TR_KEYBOARD_MAPPING], ctr[TR_KEYBOARD_MAPPING_LONG], 50, 5, 5, 6, displaynames, &choice, + ctr[TR_OK], ctr[TR_CANCEL], NULL); + + strcpy(keymap, filenames[choice]); + + if (rc != 2) + { + replacekeyvalue(kv, "KEYMAP", keymap); + writekeyvalues(kv, CONFIG_ROOT "/main/settings"); + sprintf(commandstring, "/bin/loadkeys %s", keymap); + mysystem(commandstring); + result = 1; + } + else + result = 0; + + for (c = 0; filenames[c]; c++) + { + free(filenames[c]); + free(displaynames[c]); + } + freekeyvalues(kv); + + return result; +} + +static int process(char *prefix, char *path) +{ + DIR *dir; + struct dirent *de; + char newpath[PATH_MAX]; + + snprintf(newpath, PATH_MAX, "%s%s", prefix, path); + + if (!(dir = opendir(newpath))) + { + if (filenamecount > MAX_FILENAMES) + return 1; + + filenames[filenamecount] = (char *) strdup(newpath); + filenamecount++; + return 0; + } + + while ((de = readdir(dir))) + { + if (de->d_name[0] == '.') continue; + snprintf(newpath, PATH_MAX, "%s/%s", path, de->d_name); + process(prefix, newpath); + } + closedir(dir); + + return 1; +} + +/* Small wrapper for use with qsort() to sort filename part. */ +static int cmp(const void *s1, const void *s2) +{ + /* c1 and c2 are copies. */ + char *c1 = strdup(* (char **) s1); + char *c2 = strdup(* (char **) s2); + /* point to somewhere in cN. */ + char *f1, *f2; + char *temp; + int res; + + if ((temp = strrchr(c1, '/'))) + f1 = temp + 1; + else + f1 = c1; + if ((temp = strrchr(c2, '/'))) + f2 = temp + 1; + else + f2 = c2; + /* bang off the . */ + if ((temp = strchr(f1, '.'))) + *temp = '\0'; + if ((temp = strchr(f2, '.'))) + *temp = '\0'; + + res = strcmp(f1, f2); + + free(c1); free(c2); + + return res; +} diff --git a/src/install+setup/setup/main.c b/src/install+setup/setup/main.c index 44900e2fd2..f168220e10 100644 --- a/src/install+setup/setup/main.c +++ b/src/install+setup/setup/main.c @@ -21,36 +21,14 @@ char **ctr = NULL; int automode = 0; -extern char *bz_tr[]; -extern char *cs_tr[]; -extern char *da_tr[]; extern char *en_tr[]; -extern char *es_tr[]; -extern char *fi_tr[]; -extern char *fr_tr[]; -extern char *hu_tr[]; -extern char *la_tr[]; -extern char *nl_tr[]; extern char *de_tr[]; -extern char *tr_tr[]; -extern char *it_tr[]; -extern char *el_tr[]; -extern char *sk_tr[]; -extern char *so_tr[]; -extern char *sv_tr[]; -extern char *no_tr[]; -extern char *pl_tr[]; -extern char *pt_tr[]; -extern char *vi_tr[]; int main(int argc, char *argv[]) { #ifdef LANG_EN_ONLY char *shortlangnames[] = { "en", NULL }; char **langtrs[] = { en_tr, NULL }; -#elifdef LANG_ALL - char *shortlangnames[] = { "bz", "cs", "da", "de", "en", "es", "fr", "el", "it", "la", "hu", "nl", "no", "pl", "pt", "sk", "so", "fi", "sv", "tr", "vi", NULL }; - char **langtrs[] = { bz_tr, cs_tr, da_tr, de_tr, en_tr, es_tr, fr_tr, el_tr, it_tr, la_tr, hu_tr, nl_tr, no_tr, pl_tr, pt_tr, sk_tr, so_tr, fi_tr, sv_tr, tr_tr, vi_tr, NULL }; #else char *shortlangnames[] = { "de", "en", NULL }; char **langtrs[] = { de_tr, en_tr, NULL }; @@ -68,7 +46,7 @@ int main(int argc, char *argv[]) if (argc >= 2) mylog = argv[1]; else - mylog = strdup("/root/setup.log"); + mylog = strdup("/var/log/setup.log"); if (!(flog = fopen(mylog, "w+"))) { @@ -131,7 +109,7 @@ int main(int argc, char *argv[]) title[strlen(title) - 1] = '\0'; fclose (f_title); } else { - sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); + sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); } newtDrawRootText(14, 0, title); newtPushHelpLine(ctr[TR_HELPLINE]); @@ -214,17 +192,17 @@ int main(int argc, char *argv[]) EXIT: if (automode != 0) { - sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); + sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); if (autook) newtWinMessage(title, ctr[TR_OK], ctr[TR_SETUP_FINISHED]); else newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]); } - + fprintf(flog, "Setup program ended.\n"); fflush(flog); fclose(flog); - + newtFinished(); return 0; diff --git a/src/install+setup/setup/networking.c b/src/install+setup/setup/networking.c index 72f92d3a32..18f01d37d9 100644 --- a/src/install+setup/setup/networking.c +++ b/src/install+setup/setup/networking.c @@ -1,806 +1,814 @@ -/* SmoothWall setup program. - * - * This program is distributed under the terms of the GNU General Public - * Licence. See the file COPYING for details. - * - * (c) Lawrence Manning, 2001 - * The big one: networking. - * - * $Id: networking.c,v 1.5.2.6 2006/02/06 22:00:13 gespinasse Exp $ - * - */ - -#include "setup.h" - -#define DNS1 0 -#define DNS2 1 -#define DEFAULT_GATEWAY 2 -#define DNSGATEWAY_TOTAL 3 - -extern FILE *flog; -extern char *mylog; - -extern char **ctr; - -extern int automode; - -#define HAS_ORANGE (configtype == 1 || configtype == 3 || configtype == 5 || configtype == 7) -#define HAS_RED (configtype == 2 || configtype == 3 || configtype == 6 || configtype == 7) -#define HAS_BLUE (configtype == 4 || configtype == 5 || configtype == 6 || configtype == 7) -#define RED_IS_NOT_ETH (configtype == 0 || configtype == 1 || configtype == 4 || configtype == 5) - -extern struct nic nics[]; - -char *configtypenames[] = { - "GREEN (RED is modem/ISDN)", - "GREEN + ORANGE (RED is modem/ISDN)", - "GREEN + RED", - "GREEN + ORANGE + RED", - "GREEN + BLUE (RED is modem/ISDN) ", - "GREEN + ORANGE + BLUE (RED is modem/ISDN)", - "GREEN + BLUE + RED", - "GREEN + ORANGE + BLUE + RED", - NULL }; -int netaddresschange; - -int oktoleave(char *errormessage); -int firstmenu(void); -int configtypemenu(void); -int drivermenu(void); -int changedrivers(void); -int greenaddressmenu(void); -int addressesmenu(void); -int dnsgatewaymenu(void); - -int handlenetworking(void) -{ - int done; - int choice; - char errormessage[STRING_SIZE]; - - netaddresschange = 0; - - done = 0; - while (!done) - { - choice = firstmenu(); - - switch (choice) - { - case 1: - configtypemenu(); - break; - - case 2: - drivermenu(); - break; - - case 3: - addressesmenu(); - break; - - case 4: - dnsgatewaymenu(); - break; - - case 0: - if (oktoleave(errormessage)) - done = 1; - else - errorbox(errormessage); - break; - - default: - break; - } - } - - if (automode == 0) - { - /* Restart networking! */ - if (netaddresschange) - { - runcommandwithstatus("/etc/rc.d/rc.netaddress.down", - ctr[TR_PUSHING_NETWORK_DOWN]); - runcommandwithstatus("/etc/rc.d/rc.netaddress.up", - ctr[TR_PULLING_NETWORK_UP]); - mysystem("/etc/rc.d/rc.pcmcia start"); - } - } - - return 1; -} - -int oktoleave(char *errormessage) -{ - struct keyvalue *kv = initkeyvalues(); - char temp[STRING_SIZE]; - int configtype; - - if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) - { - freekeyvalues(kv); - errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); - return 0; - } - - strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); - if (configtype < 0 || configtype > 7) configtype = 0; - - if (HAS_BLUE) - { - strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); - if (!(strlen(temp))) - { - strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]); - goto EXIT; - } - if (!(interfacecheck(kv, "BLUE"))) - { - strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]); - goto EXIT; - } - } - if (HAS_ORANGE) - { - strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); - if (!(strlen(temp))) - { - strcpy(errormessage, ctr[TR_NO_ORANGE_INTERFACE]); - goto EXIT; - } - if (!(interfacecheck(kv, "ORANGE"))) - { - strcpy(errormessage, ctr[TR_MISSING_ORANGE_IP]); - goto EXIT; - } - } - if (HAS_RED) - { - strcpy(temp, ""); findkey(kv, "RED_DEV", temp); - if (!(strlen(temp))) - { - strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]); - goto EXIT; - } - if (!(interfacecheck(kv, "RED"))) - { - strcpy(errormessage, ctr[TR_MISSING_RED_IP]); - goto EXIT; - } - } - strcpy(errormessage, ""); -EXIT: - freekeyvalues(kv); - - if (strlen(errormessage)) - return 0; - else - return 1; -} - - -/* Shows the main menu and a summary of the current settings. */ -int firstmenu(void) -{ - char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE], - ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], - ctr[TR_ADDRESS_SETTINGS], - ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL }; - int rc; - static int choice = 0; - struct keyvalue *kv = initkeyvalues(); - char message[1000]; - char temp[STRING_SIZE]; - int x; - int result; - char networkrestart[STRING_SIZE] = ""; - - if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) - { - freekeyvalues(kv); - errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); - return 0; - } - - if (netaddresschange) - strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]); - - strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp); - if (x < 0 || x > 7) x = 0; - /* Format heading bit. */ - snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x], - networkrestart); - rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6, - sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); - - if (rc == 0 || rc == 1) - result = choice + 1; - else - result = 0; - - return result; -} - -/* Here they choose general network config, number of nics etc. */ -int configtypemenu(void) -{ - struct keyvalue *kv = initkeyvalues(); - char temp[STRING_SIZE] = "0"; - char message[1000]; - int choice; - int rc; - - if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) - { - freekeyvalues(kv); - errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); - return 0; - } - - findkey(kv, "CONFIG_TYPE", temp); choice = atol(temp); - sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME); - rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5, - 6, configtypenames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); - - if (rc == 0 || rc == 1) - { - runcommandwithstatus("/etc/rc.d/rc.netaddress.down NOTGREEN", - ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); - - sprintf(temp, "%d", choice); - replacekeyvalue(kv, "CONFIG_TYPE", temp); - replacekeyvalue(kv, "ORANGE_DEV", ""); - replacekeyvalue(kv, "BLUE_DEV", ""); - replacekeyvalue(kv, "RED_DEV", ""); - writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); - netaddresschange = 1; - } - - freekeyvalues(kv); - - return 0; -} - -/* Driver menu. Choose drivers.. */ -int drivermenu(void) -{ - struct keyvalue *kv = initkeyvalues(); - char message[1000]; - char temp[STRING_SIZE], temp1[STRING_SIZE]; - char driver[STRING_SIZE], dev[STRING_SIZE]; - int configtype; - int rc; - - if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) - { - freekeyvalues(kv); - errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); - return 0; - } - - strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); - configtype = atol(temp); - - if (configtype == 0) - { - freekeyvalues(kv); - errorbox(ctr[TR_YOUR_CONFIGURATION_IS_SINGLE_GREEN_ALREADY_HAS_DRIVER]); - return 0; - } - - strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]); - - /* This horrible big formats the heading :( */ - strcpy(driver, ""); findkey(kv, "GREEN_DISPLAYDRIVER", driver); - findnicdescription(driver, temp); - strcpy(dev, ctr[TR_UNSET]); findkey(kv, "GREEN_DEV", dev); - if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); - sprintf(temp1, "GREEN: %s (%s)\n", temp, dev); - strcat(message, temp1); - if (HAS_BLUE) - { - strcpy(driver, ""); findkey(kv, "BLUE_DISPLAYDRIVER", driver); - findnicdescription(driver, temp); - strcpy(dev, ctr[TR_UNSET]); findkey(kv, "BLUE_DEV", dev); - if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); - sprintf(temp1, "BLUE: %s (%s)\n", temp, dev); - strcat(message, temp1); - } - if (HAS_ORANGE) - { - strcpy(driver, ""); findkey(kv, "ORANGE_DISPLAYDRIVER", driver); - findnicdescription(driver, temp); - strcpy(dev, ctr[TR_UNSET]); findkey(kv, "ORANGE_DEV", dev); - if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); - sprintf(temp1, "ORANGE: %s (%s)\n", temp, dev); - strcat(message, temp1); - } - if (HAS_RED) - { - strcpy(driver, ""); findkey(kv, "RED_DISPLAYDRIVER", driver); - findnicdescription(driver, temp); - strcpy(dev, ctr[TR_UNSET]); findkey(kv, "RED_DEV", dev); - if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); - sprintf(temp1, "RED: %s (%s)\n", temp, dev); - strcat(message, temp1); - } - strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]); - rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], - ctr[TR_CANCEL], message); - if (rc == 0 || rc == 1) - { - /* Shit, got to do something.. */ - changedrivers(); - } - - freekeyvalues(kv); - - return 1; -} - -int changedrivers(void) -{ - struct keyvalue *kv = initkeyvalues(); - char message[1000]; - char temp[STRING_SIZE]; - char driver[STRING_SIZE]; - int configtype; - int rc; - int c; - int needcards, sofarallocated, countofcards, toallocate; - char *orange = "ORANGE"; - char *blue = "BLUE"; - char *red = "RED"; - char *sections[4]; - int choice; - char nexteth[STRING_SIZE]; - int abort; - char currentdriver[STRING_SIZE], currentdriveroptions[STRING_SIZE]; - char displaydriver[STRING_SIZE]; - struct stat st; - - if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) - { - freekeyvalues(kv); - errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); - return 0; - } - - strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); - configtype = atol(temp); - - runcommandwithstatus("/etc/rc.d/rc.netaddress.down NOTGREEN", - ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); - - /* Remove all modules not needed for green networking. */ - c = 0; - strcpy(driver, ""); findkey(kv, "GREEN_DRIVER", driver); - if (strcmp(driver, "pcmcia") != 0) { - stat("/proc/bus/pccard", &st); - mysystem("/etc/rc.d/rc.pcmcia stop"); - if (S_ISDIR(st.st_mode)) { - mysystem("/sbin/modprobe pcmcia_core"); - mysystem("/sbin/modprobe pcmcia-controller"); - mysystem("/sbin/modprobe ds"); - } - } - while (nics[c].modulename) - { - if (strcmp(nics[c].modulename, driver) != 0) - { - if (checkformodule(nics[c].modulename)) - { - sprintf(temp, "/sbin/rmmod %s", nics[c].modulename); - mysystem(temp); - } - } - c++; - } - - /* Blank them so the rc.netaddress.up does not get confused. */ - replacekeyvalue(kv, "ORANGE_DEV", ""); - replacekeyvalue(kv, "BLUE_DEV", ""); - replacekeyvalue(kv, "RED_DEV", ""); - - if (configtype == 0) - needcards = 1; - else if (configtype == 1 || configtype == 2 || configtype == 4) - needcards = 2; - else if (configtype == 7) - needcards = 4; - else - needcards = 3; - - /* This is the green card. */ - sofarallocated = 1; - - findkey(kv, "GREEN_DRIVER", currentdriver); - findkey(kv, "GREEN_DRIVER_OPTIONS", currentdriveroptions); - strcpy(displaydriver, currentdriver); - - if (countcards() > 1) - strcpy(currentdriver, ""); - - abort = 0; - /* Keep going till all cards are got, or they give up. */ - while (sofarallocated < needcards && !abort) - { - countofcards = countcards(); - - /* This is how many cards were added by the last module. */ - toallocate = countofcards - sofarallocated; - while (toallocate > 0 && sofarallocated < needcards) - { - findnicdescription(displaydriver, temp); - sprintf(message, ctr[TR_UNCLAIMED_DRIVER], temp); - c = 0; choice = 0; - strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); - if (HAS_BLUE && !strlen(temp)) - { - sections[c] = blue; - c++; - } - strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); - if (HAS_ORANGE && !strlen(temp)) - { - sections[c] = orange; - c++; - } - strcpy(temp, ""); findkey(kv, "RED_DEV", temp); - if (HAS_RED && !strlen(temp)) - { - sections[c] = red; - c++; - } - sections[c] = NULL; - rc = newtWinMenu(ctr[TR_CARD_ASSIGNMENT], - message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK], - ctr[TR_CANCEL], NULL); - if (rc == 0 || rc == 1) - { - /* Now we see which iface needs its settings changed. */ - sprintf(nexteth, "eth%d", sofarallocated); - if (strcmp(sections[choice], blue) == 0) - { - replacekeyvalue(kv, "BLUE_DEV", nexteth); - replacekeyvalue(kv, "BLUE_DRIVER", currentdriver); - replacekeyvalue(kv, "BLUE_DRIVER_OPTIONS", currentdriveroptions); - replacekeyvalue(kv, "BLUE_DISPLAYDRIVER", displaydriver); - sofarallocated++; - toallocate--; - strcpy(currentdriver, ""); - strcpy(currentdriveroptions, ""); - } - if (strcmp(sections[choice], orange) == 0) - { - replacekeyvalue(kv, "ORANGE_DEV", nexteth); - replacekeyvalue(kv, "ORANGE_DRIVER", currentdriver); - replacekeyvalue(kv, "ORANGE_DRIVER_OPTIONS", currentdriveroptions); - replacekeyvalue(kv, "ORANGE_DISPLAYDRIVER", displaydriver); - sofarallocated++; - toallocate--; - strcpy(currentdriver, ""); - strcpy(currentdriveroptions, ""); - } - if (strcmp(sections[choice], red) == 0) - { - replacekeyvalue(kv, "RED_DEV", nexteth); - replacekeyvalue(kv, "RED_DRIVER", currentdriver); - replacekeyvalue(kv, "RED_DRIVER_OPTIONS", currentdriveroptions); - replacekeyvalue(kv, "RED_DISPLAYDRIVER", displaydriver); - sofarallocated++; - toallocate--; - strcpy(currentdriver, ""); - strcpy(currentdriveroptions, ""); - } - } - else - { - break; - } - } - - /* Need another module! The nitty gritty code is in libsmooth. */ - if (sofarallocated < needcards) - { - rc = newtWinTernary(ctr[TR_CARD_ASSIGNMENT], ctr[TR_PROBE], - ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_NO_UNALLOCATED_CARDS]); - - if (rc == 0 || rc == 1) - { - probecards(currentdriver, currentdriveroptions); - if (!strlen(currentdriver)) - errorbox(ctr[TR_PROBE_FAILED]); - } - else if (rc == 2) - choosecards(currentdriver, currentdriveroptions); - else - abort = 1; - - strcpy(displaydriver, currentdriver); - } - } - - countofcards = countcards(); - - if (countofcards >= needcards) - { - newtWinMessage(ctr[TR_CARD_ASSIGNMENT], ctr[TR_OK], - ctr[TR_ALL_CARDS_SUCCESSFULLY_ALLOCATED]); - } - else - errorbox(ctr[TR_NOT_ENOUGH_CARDS_WERE_ALLOCATED]); - - writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); - - freekeyvalues(kv); - - netaddresschange = 1; - - return 1; -} - -/* Let user change GREEN address. */ -int greenaddressmenu(void) -{ - struct keyvalue *kv = initkeyvalues(); - char message[1000]; - int rc; - - if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) - { - freekeyvalues(kv); - errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); - return 0; - } - - sprintf(message, ctr[TR_WARNING_LONG], NAME); - rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); - - if (rc == 0 || rc == 1) - { - if (changeaddress(kv, "GREEN", 0, "")) - { - netaddresschange = 1; - writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); - writehostsfiles(); - } - } - - freekeyvalues(kv); - - return 0; -} - -/* They can change BLUE, ORANGE and GREEN too :) */ -int addressesmenu(void) -{ - struct keyvalue *kv = initkeyvalues(); - struct keyvalue *mainkv = initkeyvalues(); - int rc = 0; - char *sections[5]; - char *green = "GREEN"; - char *orange = "ORANGE"; - char *blue = "BLUE"; - char *red = "RED"; - int c = 0; - char greenaddress[STRING_SIZE]; - char oldgreenaddress[STRING_SIZE]; - char temp[STRING_SIZE]; - char temp2[STRING_SIZE]; - char message[1000]; - int configtype; - int done; - int choice; - char hostname[STRING_SIZE]; - - if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) - { - freekeyvalues(kv); - freekeyvalues(mainkv); - errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); - return 0; - } - if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) - { - freekeyvalues(kv); - freekeyvalues(mainkv); - errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); - return 0; - } - - strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); - configtype = atol(temp); - - sections[c] = green; - c++; - if (HAS_BLUE) - { - sections[c] = blue; - c++; - } - if (HAS_ORANGE) - { - sections[c] = orange; - c++; - } - if (HAS_RED) - { - sections[c] = red; - c++; - } - sections[c] = NULL; - - choice = 0; - done = 0; - while (!done) - { - rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS], - ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5, - 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); - - if (rc == 0 || rc == 1) - { - if (strcmp(sections[choice], "GREEN") == 0) - { - findkey(kv, "GREEN_ADDRESS", oldgreenaddress); - sprintf(message, ctr[TR_WARNING_LONG], NAME); - rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], - message); - if (rc == 0 || rc == 1) - { - if (changeaddress(kv, "GREEN", 0, "")) - { - netaddresschange = 1; - writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); - writehostsfiles(); - findkey(kv, "GREEN_ADDRESS", greenaddress); - snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); - snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); - replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); - chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); - } - } - } - if (strcmp(sections[choice], "BLUE") == 0) - { - if (changeaddress(kv, "BLUE", 0, "")) - netaddresschange = 1; - } - if (strcmp(sections[choice], "ORANGE") == 0) - { - if (changeaddress(kv, "ORANGE", 0, "")) - netaddresschange = 1; - } - if (strcmp(sections[choice], "RED") == 0) - { - strcpy(hostname, ""); - findkey(mainkv, "HOSTNAME", hostname); - if (changeaddress(kv, "RED", 1, hostname)) - netaddresschange = 1; - } - } - else - done = 1; - } - - writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); - freekeyvalues(kv); - freekeyvalues(mainkv); - - return 0; -} - -/* DNS and default gateway.... */ -int dnsgatewaymenu(void) -{ - struct keyvalue *kv = initkeyvalues(); - char message[1000]; - char temp[STRING_SIZE] = "0"; - struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; - char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ - int error; - int configtype; - int rc; - - if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) - { - freekeyvalues(kv); - errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); - return 0; - } - - strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); - configtype = atol(temp); - - if (RED_IS_NOT_ETH) - { - freekeyvalues(kv); - errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]); - return 0; - } - - entries[DNS1].text = ctr[TR_PRIMARY_DNS]; - strcpy(temp, ""); findkey(kv, "DNS1", temp); - values[DNS1] = strdup(temp); - entries[DNS1].value = &values[DNS1]; - entries[DNS1].flags = 0; - - entries[DNS2].text = ctr[TR_SECONDARY_DNS]; - strcpy(temp, ""); findkey(kv, "DNS2", temp); - values[DNS2] = strdup(temp); - entries[DNS2].value = &values[DNS2]; - entries[DNS2].flags = 0; - - entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; - strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); - values[DEFAULT_GATEWAY] = strdup(temp); - entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; - entries[DEFAULT_GATEWAY].flags = 0; - - entries[DNSGATEWAY_TOTAL].text = NULL; - entries[DNSGATEWAY_TOTAL].value = NULL; - entries[DNSGATEWAY_TOTAL].flags = 0; - - do - { - error = 0; - - rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], - ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, - ctr[TR_OK], ctr[TR_CANCEL], NULL); - if (rc == 0 || rc == 1) - { - strcpy(message, ctr[TR_INVALID_FIELDS]); - if (strlen(values[DNS1])) - { - if (inet_addr(values[DNS1]) == INADDR_NONE) - { - strcat(message, ctr[TR_PRIMARY_DNS_CR]); - error = 1; - } - } - if (strlen(values[DNS2])) - { - if (inet_addr(values[DNS2]) == INADDR_NONE) - { - strcat(message, ctr[TR_SECONDARY_DNS_CR]); - error = 1; - } - } - if (strlen(values[DEFAULT_GATEWAY])) - { - if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) - { - strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); - error = 1; - } - } - if (!strlen(values[DNS1]) && strlen(values[DNS2])) - { - strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); - error = 1; - } - - if (error) - errorbox(message); - else - { - replacekeyvalue(kv, "DNS1", values[DNS1]); - replacekeyvalue(kv, "DNS2", values[DNS2]); - replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); - netaddresschange = 1; - free(values[DNS1]); - free(values[DNS2]); - free(values[DEFAULT_GATEWAY]); - writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); - } - } - } - while (error); - - freekeyvalues(kv); - - return 1; -} +/* SmoothWall setup program. + * + * This program is distributed under the terms of the GNU General Public + * Licence. See the file COPYING for details. + * + * (c) Lawrence Manning, 2001 + * The big one: networking. + * + * $Id: networking.c,v 1.5.2.6 2006/02/06 22:00:13 gespinasse Exp $ + * + */ + +#include "setup.h" + +#define DNS1 0 +#define DNS2 1 +#define DEFAULT_GATEWAY 2 +#define DNSGATEWAY_TOTAL 3 + +extern FILE *flog; +extern char *mylog; + +extern char **ctr; + +extern int automode; + +#define HAS_ORANGE (configtype == 1 || configtype == 3 || configtype == 5 || configtype == 7) +#define HAS_RED (configtype == 2 || configtype == 3 || configtype == 6 || configtype == 7) +#define HAS_BLUE (configtype == 4 || configtype == 5 || configtype == 6 || configtype == 7) +#define RED_IS_NOT_ETH (configtype == 0 || configtype == 1 || configtype == 4 || configtype == 5) + +extern struct nic nics[]; + +char *configtypenames[] = { + "GREEN (RED is modem/ISDN)", + "GREEN + ORANGE (RED is modem/ISDN)", + "GREEN + RED", + "GREEN + ORANGE + RED", + "GREEN + BLUE (RED is modem/ISDN) ", + "GREEN + ORANGE + BLUE (RED is modem/ISDN)", + "GREEN + BLUE + RED", + "GREEN + ORANGE + BLUE + RED", + NULL }; +int netaddresschange; + +int oktoleave(char *errormessage); +int firstmenu(void); +int configtypemenu(void); +int drivermenu(void); +int changedrivers(void); +int greenaddressmenu(void); +int addressesmenu(void); +int dnsgatewaymenu(void); + +int handlenetworking(void) +{ + int done; + int choice; + char errormessage[STRING_SIZE]; + + netaddresschange = 0; + + done = 0; + while (!done) + { + choice = firstmenu(); + + switch (choice) + { + case 1: + configtypemenu(); + break; + + case 2: + drivermenu(); + break; + + case 3: + addressesmenu(); + break; + + case 4: + dnsgatewaymenu(); + break; + + case 0: + if (oktoleave(errormessage)) + done = 1; + else + errorbox(errormessage); + break; + + default: + break; + } + } + + if (automode == 0) + { + /* Restart networking! */ + if (netaddresschange) + { + runcommandwithstatus("/etc/rc.d/init.d/network stop", + ctr[TR_PUSHING_NETWORK_DOWN]); + runcommandwithstatus("/etc/rc.d/init.d/network start", + ctr[TR_PULLING_NETWORK_UP]); +// mysystem("/etc/rc.d/rc.pcmcia start"); + } + } + + return 1; +} + +int oktoleave(char *errormessage) +{ + struct keyvalue *kv = initkeyvalues(); + char temp[STRING_SIZE]; + int configtype; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) + { + freekeyvalues(kv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); + if (configtype < 0 || configtype > 7) configtype = 0; + + if (HAS_BLUE) + { + strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); + if (!(strlen(temp))) + { + strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]); + goto EXIT; + } + if (!(interfacecheck(kv, "BLUE"))) + { + strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]); + goto EXIT; + } + } + if (HAS_ORANGE) + { + strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); + if (!(strlen(temp))) + { + strcpy(errormessage, ctr[TR_NO_ORANGE_INTERFACE]); + goto EXIT; + } + if (!(interfacecheck(kv, "ORANGE"))) + { + strcpy(errormessage, ctr[TR_MISSING_ORANGE_IP]); + goto EXIT; + } + } + if (HAS_RED) + { + strcpy(temp, ""); findkey(kv, "RED_DEV", temp); + if (!(strlen(temp))) + { + strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]); + goto EXIT; + } + if (!(interfacecheck(kv, "RED"))) + { + strcpy(errormessage, ctr[TR_MISSING_RED_IP]); + goto EXIT; + } + } + strcpy(errormessage, ""); +EXIT: + freekeyvalues(kv); + + if (strlen(errormessage)) + return 0; + else + return 1; +} + + +/* Shows the main menu and a summary of the current settings. */ +int firstmenu(void) +{ + char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE], + ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], + ctr[TR_ADDRESS_SETTINGS], + ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL }; + int rc; + static int choice = 0; + struct keyvalue *kv = initkeyvalues(); + char message[1000]; + char temp[STRING_SIZE]; + int x; + int result; + char networkrestart[STRING_SIZE] = ""; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) + { + freekeyvalues(kv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + if (netaddresschange) + strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]); + + strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp); + if (x < 0 || x > 7) x = 0; + /* Format heading bit. */ + snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x], + networkrestart); + rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6, + sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); + + if (rc == 0 || rc == 1) + result = choice + 1; + else + result = 0; + + return result; +} + +/* Here they choose general network config, number of nics etc. */ +int configtypemenu(void) +{ + struct keyvalue *kv = initkeyvalues(); + char temp[STRING_SIZE] = "0"; + char message[1000]; + int choice; + int rc; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) + { + freekeyvalues(kv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + findkey(kv, "CONFIG_TYPE", temp); choice = atol(temp); + sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME); + rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5, + 6, configtypenames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); + + if (rc == 0 || rc == 1) + { + runcommandwithstatus("/etc/rc.d/init.d/network red down", + ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); + runcommandwithstatus("/etc/rc.d/init.d/network blue down", + ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); + runcommandwithstatus("/etc/rc.d/init.d/network orange down", + ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); + + sprintf(temp, "%d", choice); + replacekeyvalue(kv, "CONFIG_TYPE", temp); + replacekeyvalue(kv, "ORANGE_DEV", ""); + replacekeyvalue(kv, "BLUE_DEV", ""); + replacekeyvalue(kv, "RED_DEV", ""); + writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); + netaddresschange = 1; + } + + freekeyvalues(kv); + + return 0; +} + +/* Driver menu. Choose drivers.. */ +int drivermenu(void) +{ + struct keyvalue *kv = initkeyvalues(); + char message[1000]; + char temp[STRING_SIZE], temp1[STRING_SIZE]; + char driver[STRING_SIZE], dev[STRING_SIZE]; + int configtype; + int rc; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) + { + freekeyvalues(kv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); + configtype = atol(temp); + + if (configtype == 0) + { + freekeyvalues(kv); + errorbox(ctr[TR_YOUR_CONFIGURATION_IS_SINGLE_GREEN_ALREADY_HAS_DRIVER]); + return 0; + } + + strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]); + + /* This horrible big formats the heading :( */ + strcpy(driver, ""); findkey(kv, "GREEN_DISPLAYDRIVER", driver); + findnicdescription(driver, temp); + strcpy(dev, ctr[TR_UNSET]); findkey(kv, "GREEN_DEV", dev); + if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); + sprintf(temp1, "GREEN: %s (%s)\n", temp, dev); + strcat(message, temp1); + if (HAS_BLUE) + { + strcpy(driver, ""); findkey(kv, "BLUE_DISPLAYDRIVER", driver); + findnicdescription(driver, temp); + strcpy(dev, ctr[TR_UNSET]); findkey(kv, "BLUE_DEV", dev); + if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); + sprintf(temp1, "BLUE: %s (%s)\n", temp, dev); + strcat(message, temp1); + } + if (HAS_ORANGE) + { + strcpy(driver, ""); findkey(kv, "ORANGE_DISPLAYDRIVER", driver); + findnicdescription(driver, temp); + strcpy(dev, ctr[TR_UNSET]); findkey(kv, "ORANGE_DEV", dev); + if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); + sprintf(temp1, "ORANGE: %s (%s)\n", temp, dev); + strcat(message, temp1); + } + if (HAS_RED) + { + strcpy(driver, ""); findkey(kv, "RED_DISPLAYDRIVER", driver); + findnicdescription(driver, temp); + strcpy(dev, ctr[TR_UNSET]); findkey(kv, "RED_DEV", dev); + if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); + sprintf(temp1, "RED: %s (%s)\n", temp, dev); + strcat(message, temp1); + } + strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]); + rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], + ctr[TR_CANCEL], message); + if (rc == 0 || rc == 1) + { + /* Shit, got to do something.. */ + changedrivers(); + } + + freekeyvalues(kv); + + return 1; +} + +int changedrivers(void) +{ + struct keyvalue *kv = initkeyvalues(); + char message[1000]; + char temp[STRING_SIZE]; + char driver[STRING_SIZE]; + int configtype; + int rc; + int c; + int needcards, sofarallocated, countofcards, toallocate; + char *orange = "ORANGE"; + char *blue = "BLUE"; + char *red = "RED"; + char *sections[4]; + int choice; + char nexteth[STRING_SIZE]; + int abort; + char currentdriver[STRING_SIZE], currentdriveroptions[STRING_SIZE]; + char displaydriver[STRING_SIZE]; + struct stat st; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) + { + freekeyvalues(kv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); + configtype = atol(temp); + + runcommandwithstatus("/etc/rc.d/init.d/network red down", + ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); + runcommandwithstatus("/etc/rc.d/init.d/network blue down", + ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); + runcommandwithstatus("/etc/rc.d/init.d/network orange down", + ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); + + /* Remove all modules not needed for green networking. */ + c = 0; + strcpy(driver, ""); findkey(kv, "GREEN_DRIVER", driver); + if (strcmp(driver, "pcmcia") != 0) { + stat("/proc/bus/pccard", &st); + mysystem("/etc/rc.d/rc.pcmcia stop"); + if (S_ISDIR(st.st_mode)) { + mysystem("/sbin/modprobe pcmcia_core"); + mysystem("/sbin/modprobe pcmcia-controller"); + mysystem("/sbin/modprobe ds"); + } + } + while (nics[c].modulename) + { + if (strcmp(nics[c].modulename, driver) != 0) + { + if (checkformodule(nics[c].modulename)) + { + sprintf(temp, "/sbin/rmmod %s", nics[c].modulename); + mysystem(temp); + } + } + c++; + } + + /* Blank them so the rc.netaddress.up does not get confused. */ + replacekeyvalue(kv, "ORANGE_DEV", ""); + replacekeyvalue(kv, "BLUE_DEV", ""); + replacekeyvalue(kv, "RED_DEV", ""); + + if (configtype == 0) + needcards = 1; + else if (configtype == 1 || configtype == 2 || configtype == 4) + needcards = 2; + else if (configtype == 7) + needcards = 4; + else + needcards = 3; + + /* This is the green card. */ + sofarallocated = 1; + + findkey(kv, "GREEN_DRIVER", currentdriver); + findkey(kv, "GREEN_DRIVER_OPTIONS", currentdriveroptions); + strcpy(displaydriver, currentdriver); + + if (countcards() > 1) + strcpy(currentdriver, ""); + + abort = 0; + /* Keep going till all cards are got, or they give up. */ + while (sofarallocated < needcards && !abort) + { + countofcards = countcards(); + + /* This is how many cards were added by the last module. */ + toallocate = countofcards - sofarallocated; + while (toallocate > 0 && sofarallocated < needcards) + { + findnicdescription(displaydriver, temp); + sprintf(message, ctr[TR_UNCLAIMED_DRIVER], temp); + c = 0; choice = 0; + strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); + if (HAS_BLUE && !strlen(temp)) + { + sections[c] = blue; + c++; + } + strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); + if (HAS_ORANGE && !strlen(temp)) + { + sections[c] = orange; + c++; + } + strcpy(temp, ""); findkey(kv, "RED_DEV", temp); + if (HAS_RED && !strlen(temp)) + { + sections[c] = red; + c++; + } + sections[c] = NULL; + rc = newtWinMenu(ctr[TR_CARD_ASSIGNMENT], + message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK], + ctr[TR_CANCEL], NULL); + if (rc == 0 || rc == 1) + { + /* Now we see which iface needs its settings changed. */ + sprintf(nexteth, "eth%d", sofarallocated); + if (strcmp(sections[choice], blue) == 0) + { + replacekeyvalue(kv, "BLUE_DEV", nexteth); + replacekeyvalue(kv, "BLUE_DRIVER", currentdriver); + replacekeyvalue(kv, "BLUE_DRIVER_OPTIONS", currentdriveroptions); + replacekeyvalue(kv, "BLUE_DISPLAYDRIVER", displaydriver); + sofarallocated++; + toallocate--; + strcpy(currentdriver, ""); + strcpy(currentdriveroptions, ""); + } + if (strcmp(sections[choice], orange) == 0) + { + replacekeyvalue(kv, "ORANGE_DEV", nexteth); + replacekeyvalue(kv, "ORANGE_DRIVER", currentdriver); + replacekeyvalue(kv, "ORANGE_DRIVER_OPTIONS", currentdriveroptions); + replacekeyvalue(kv, "ORANGE_DISPLAYDRIVER", displaydriver); + sofarallocated++; + toallocate--; + strcpy(currentdriver, ""); + strcpy(currentdriveroptions, ""); + } + if (strcmp(sections[choice], red) == 0) + { + replacekeyvalue(kv, "RED_DEV", nexteth); + replacekeyvalue(kv, "RED_DRIVER", currentdriver); + replacekeyvalue(kv, "RED_DRIVER_OPTIONS", currentdriveroptions); + replacekeyvalue(kv, "RED_DISPLAYDRIVER", displaydriver); + sofarallocated++; + toallocate--; + strcpy(currentdriver, ""); + strcpy(currentdriveroptions, ""); + } + } + else + { + break; + } + } + + /* Need another module! The nitty gritty code is in libsmooth. */ + if (sofarallocated < needcards) + { + rc = newtWinTernary(ctr[TR_CARD_ASSIGNMENT], ctr[TR_PROBE], + ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_NO_UNALLOCATED_CARDS]); + + if (rc == 0 || rc == 1) + { + probecards(currentdriver, currentdriveroptions); + if (!strlen(currentdriver)) + errorbox(ctr[TR_PROBE_FAILED]); + } + else if (rc == 2) + choosecards(currentdriver, currentdriveroptions); + else + abort = 1; + + strcpy(displaydriver, currentdriver); + } + } + + countofcards = countcards(); + + if (countofcards >= needcards) + { + newtWinMessage(ctr[TR_CARD_ASSIGNMENT], ctr[TR_OK], + ctr[TR_ALL_CARDS_SUCCESSFULLY_ALLOCATED]); + } + else + errorbox(ctr[TR_NOT_ENOUGH_CARDS_WERE_ALLOCATED]); + + writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); + + freekeyvalues(kv); + + netaddresschange = 1; + + return 1; +} + +/* Let user change GREEN address. */ +int greenaddressmenu(void) +{ + struct keyvalue *kv = initkeyvalues(); + char message[1000]; + int rc; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) + { + freekeyvalues(kv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + sprintf(message, ctr[TR_WARNING_LONG], NAME); + rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); + + if (rc == 0 || rc == 1) + { + if (changeaddress(kv, "GREEN", 0, "")) + { + netaddresschange = 1; + writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); + writehostsfiles(); + } + } + + freekeyvalues(kv); + + return 0; +} + +/* They can change BLUE, ORANGE and GREEN too :) */ +int addressesmenu(void) +{ + struct keyvalue *kv = initkeyvalues(); + struct keyvalue *mainkv = initkeyvalues(); + int rc = 0; + char *sections[5]; + char *green = "GREEN"; + char *orange = "ORANGE"; + char *blue = "BLUE"; + char *red = "RED"; + int c = 0; + char greenaddress[STRING_SIZE]; + char oldgreenaddress[STRING_SIZE]; + char temp[STRING_SIZE]; + char temp2[STRING_SIZE]; + char message[1000]; + int configtype; + int done; + int choice; + char hostname[STRING_SIZE]; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) + { + freekeyvalues(kv); + freekeyvalues(mainkv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) + { + freekeyvalues(kv); + freekeyvalues(mainkv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); + configtype = atol(temp); + + sections[c] = green; + c++; + if (HAS_BLUE) + { + sections[c] = blue; + c++; + } + if (HAS_ORANGE) + { + sections[c] = orange; + c++; + } + if (HAS_RED) + { + sections[c] = red; + c++; + } + sections[c] = NULL; + + choice = 0; + done = 0; + while (!done) + { + rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS], + ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5, + 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); + + if (rc == 0 || rc == 1) + { + if (strcmp(sections[choice], "GREEN") == 0) + { + findkey(kv, "GREEN_ADDRESS", oldgreenaddress); + sprintf(message, ctr[TR_WARNING_LONG], NAME); + rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], + message); + if (rc == 0 || rc == 1) + { + if (changeaddress(kv, "GREEN", 0, "")) + { + netaddresschange = 1; + writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); + writehostsfiles(); + findkey(kv, "GREEN_ADDRESS", greenaddress); + snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); + snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); + replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); + chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); + } + } + } + if (strcmp(sections[choice], "BLUE") == 0) + { + if (changeaddress(kv, "BLUE", 0, "")) + netaddresschange = 1; + } + if (strcmp(sections[choice], "ORANGE") == 0) + { + if (changeaddress(kv, "ORANGE", 0, "")) + netaddresschange = 1; + } + if (strcmp(sections[choice], "RED") == 0) + { + strcpy(hostname, ""); + findkey(mainkv, "HOSTNAME", hostname); + if (changeaddress(kv, "RED", 1, hostname)) + netaddresschange = 1; + } + } + else + done = 1; + } + + writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); + freekeyvalues(kv); + freekeyvalues(mainkv); + + return 0; +} + +/* DNS and default gateway.... */ +int dnsgatewaymenu(void) +{ + struct keyvalue *kv = initkeyvalues(); + char message[1000]; + char temp[STRING_SIZE] = "0"; + struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; + char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ + int error; + int configtype; + int rc; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) + { + freekeyvalues(kv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); + configtype = atol(temp); + + if (RED_IS_NOT_ETH) + { + freekeyvalues(kv); + errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]); + return 0; + } + + entries[DNS1].text = ctr[TR_PRIMARY_DNS]; + strcpy(temp, ""); findkey(kv, "DNS1", temp); + values[DNS1] = strdup(temp); + entries[DNS1].value = &values[DNS1]; + entries[DNS1].flags = 0; + + entries[DNS2].text = ctr[TR_SECONDARY_DNS]; + strcpy(temp, ""); findkey(kv, "DNS2", temp); + values[DNS2] = strdup(temp); + entries[DNS2].value = &values[DNS2]; + entries[DNS2].flags = 0; + + entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; + strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); + values[DEFAULT_GATEWAY] = strdup(temp); + entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; + entries[DEFAULT_GATEWAY].flags = 0; + + entries[DNSGATEWAY_TOTAL].text = NULL; + entries[DNSGATEWAY_TOTAL].value = NULL; + entries[DNSGATEWAY_TOTAL].flags = 0; + + do + { + error = 0; + + rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], + ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, + ctr[TR_OK], ctr[TR_CANCEL], NULL); + if (rc == 0 || rc == 1) + { + strcpy(message, ctr[TR_INVALID_FIELDS]); + if (strlen(values[DNS1])) + { + if (inet_addr(values[DNS1]) == INADDR_NONE) + { + strcat(message, ctr[TR_PRIMARY_DNS_CR]); + error = 1; + } + } + if (strlen(values[DNS2])) + { + if (inet_addr(values[DNS2]) == INADDR_NONE) + { + strcat(message, ctr[TR_SECONDARY_DNS_CR]); + error = 1; + } + } + if (strlen(values[DEFAULT_GATEWAY])) + { + if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) + { + strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); + error = 1; + } + } + if (!strlen(values[DNS1]) && strlen(values[DNS2])) + { + strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); + error = 1; + } + + if (error) + errorbox(message); + else + { + replacekeyvalue(kv, "DNS1", values[DNS1]); + replacekeyvalue(kv, "DNS2", values[DNS2]); + replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); + netaddresschange = 1; + free(values[DNS1]); + free(values[DNS2]); + free(values[DEFAULT_GATEWAY]); + writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); + } + } + } + while (error); + + freekeyvalues(kv); + + return 1; +} diff --git a/src/install+setup/setup/passwords.c b/src/install+setup/setup/passwords.c index a2f28f97f3..4b9e61b511 100644 --- a/src/install+setup/setup/passwords.c +++ b/src/install+setup/setup/passwords.c @@ -32,7 +32,7 @@ int handlerootpassword(void) return 0; snprintf(commandstring, STRING_SIZE, - "/bin/echo 'root:%s' | /usr/sbin/chpasswd", password); + "/bin/echo 'root:%s' | /usr/sbin/chpasswd", password); if (runhiddencommandwithstatus(commandstring, ctr[TR_SETTING_ROOT_PASSWORD])) { errorbox(ctr[TR_PROBLEM_SETTING_ROOT_PASSWORD]); @@ -83,7 +83,7 @@ int getpassword(char *password, char *text) do { done = 1; - sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); + sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); rc = newtWinEntries(title, text, 50, 5, 5, 20, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); diff --git a/src/rc.d/helper/writeipac.pl b/src/rc.d/helper/writeipac.pl index 0f49791c63..ff6792f465 100644 --- a/src/rc.d/helper/writeipac.pl +++ b/src/rc.d/helper/writeipac.pl @@ -8,7 +8,7 @@ # use strict; -require 'CONFIG_ROOT/general-functions.pl'; +require '/var/ipfire/general-functions.pl'; my %settings; my $iface; -- 2.39.2