Project

General

Profile

Download (3.07 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	routed.inc
5
	Copyright (C) 2006 Bill Marquette
6
	All rights reserved.
7

    
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10

    
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13

    
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17

    
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28

    
29
*/
30

    
31
function setup_routed() {
32
	global $config;
33
	$gw = "";
34

    
35
	if (!is_array($config['installedpackages']['routed']))
36
		return;
37
	if (!is_array($config['installedpackages']['routed']['config']))
38
		return;
39
	if (isset($config['installedpackages']['routed']['config'][0]['enable']) &&
40
		$config['installedpackages']['routed']['config'][0]['enable'] == "on") {
41
		/* if user selected individual interfaces */
42
		$ifdescrs = get_configured_interface_with_descr();
43
		$ifarr = explode(",", $config['installedpackages']['routed']['config'][0]['iface_array']);
44
                if (count($ifarr) != 0) {
45
			foreach($ifdescrs as $ifdescr => $ifname) {
46
				if (in_array($ifname, $ifarr)) {
47
					$gw .= setup_etc_gateways($ifdescr, 'enable');
48
				} else {
49
					$gw .= setup_etc_gateways($ifdescr, 'disable');
50
				}
51
			}
52
		} else {
53
			/* setup for all interfaces */
54
			$gw = setup_etc_gateways();
55
		}
56
		conf_mount_rw();
57
		$fd = fopen("/etc/gateways", "w");
58
		fwrite($fd, $gw);
59
		fclose($fd);
60
		conf_mount_ro();
61
		restart_routed();
62
	} else {
63
		stop_routed();
64
	}
65
}
66

    
67
function setup_etc_gateways($iface="", $mode="") {
68
	global $config;
69

    
70
	$ret = "";
71
	if ($iface != "") {
72
		$realif=convert_friendly_interface_to_real_interface_name($iface);
73
		if ($realif)
74
			$ret = "if={$realif} ";
75
	}
76

    
77
	switch($mode) {
78
	case "enable":
79
		if ($config['installedpackages']['routed']['config'][0]['ripversion'] == "2") {
80
			$ret .= "ripv2 ";
81
			$passwd = $config['installedpackages']['routed']['config'][0]['passwd'];
82
			if ($passwd != "") {
83
				$ret .= "passwd={$passwd} ";
84
			}
85
		}
86
		break;
87
	case "disable":
88
		$ret .= "no_rip ";
89
		break;
90

    
91
	default:
92
		break;
93

    
94
	}
95
	$ret .= "\n";
96

    
97
	return $ret;
98
}
99

    
100
function start_routed() {
101
	mwexec("/sbin/routed");
102
}
103

    
104
function stop_routed() {
105
	if(isvalidproc("routed"))
106
		mwexec("killall routed");
107
}
108

    
109
function restart_routed() {
110
	stop_routed();
111
	start_routed();
112
}
113

    
114
?>
(8-8/10)