Changeset 1165
- Timestamp:
- 06/30/08 12:28:18 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
5106R/trunk/ui/base-network.mod/constructor/40_addGateway.pl
r1164 r1165 32 32 33 33 if (-f $conf) { 34 # 1st try (with quotes): 34 35 open(CONF, $conf) || die "Can't read configfile: $conf\n"; 35 36 while (<CONF>) { 36 if (! -f "/proc/user_beancounters") { 37 next unless /^GATEWAY=\s*(\S+)/; 38 } 39 else { 40 next unless /^GATEWAY=\"(.*)\"/; 41 } 37 next unless /^GATEWAY=\"(.*)\"/; 42 38 $gateway = $1; 43 39 } 40 close(CONF); 41 42 # 2nd try (without quotes): 43 if (!$gateway) { 44 open(CONF, $conf) || die "Can't read configfile: $conf\n"; 45 while (<CONF>) { 46 next unless /^GATEWAY=\s*(\S+)/; 47 $gateway = $1; 48 } 49 close(CONF); 50 } 44 51 } 45 close(CONF);46 52 47 53 if (!$gateway) { 48 54 $DEBUG && print STDERR "Gateway setting isn't found\n"; 55 # Attempt to determine Gateway through other means: 49 56 if ( ! -f "/proc/user_beancounters" ) { 57 # Not running on OpenVZ, so check the route to find the Gateway: 50 58 my $data = `$Network::ROUTE -n|grep '^0\.0\.0\.0'`; 51 59 if ($data =~ /0\.0\.0\.0\s+((\d+).(\d+).(\d+).(\d+))/) { … … 54 62 } 55 63 else { 56 # Setdefault OpenVZ gateway:64 # We're on OpenVZ, so set the default OpenVZ gateway: 57 65 $gateway = "192.0.2.1"; 58 66 system("/bin/cat /etc/sysconfig/network |/bin/grep -v ^GATEWAY > /etc/sysconfig/network.bak"); 59 67 system("/bin/mv /etc/sysconfig/network.bak /etc/sysconfig/network"); 60 system("/bin/echo GATEWAY=\"192.0.2.1\">> /etc/sysconfig/network");68 system("/bin/echo 'GATEWAY=\"192.0.2.1\"' >> /etc/sysconfig/network"); 61 69 system("/etc/init.d/network restart > /dev/null"); 62 70 }
