Project

General

Profile

Download (3.64 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
$shortcut_section = "routed";
32

    
33
function setup_routed() {
34
	global $config;
35
	$gw = "";
36

    
37
	if (!is_array($config['installedpackages']['routed']))
38
		return;
39
	if (!is_array($config['installedpackages']['routed']['config']))
40
		return;
41
	if (isset($config['installedpackages']['routed']['config'][0]['enable']) &&
42
		$config['installedpackages']['routed']['config'][0]['enable'] == "on") {
43
		/* if user selected individual interfaces */
44
		$ifarr = array_flip(explode(",", $config['installedpackages']['routed']['config'][0]['iface_array']));
45
                $allifs = get_interface_arr();
46
                if (!empty($ifarr)) {
47
                        foreach($allifs as $ifname) {
48
				$friendly_ifname = convert_real_interface_to_friendly_interface_name($ifname);
49
				if (array_key_exists($friendly_ifname, $ifarr))
50
					$gw .= setup_etc_gateways($ifname, 'enable');
51
				else
52
					$gw .= setup_etc_gateways($ifname, 'disable');
53
			}
54
		} else
55
			/* setup for all interfaces */
56
			$gw = setup_etc_gateways();
57
		conf_mount_rw();
58
		file_put_contents("/etc/gateways", $gw);
59
		conf_mount_ro();
60
		restart_routed();
61
	} else
62
		stop_routed();
63
}
64

    
65
function setup_etc_gateways($iface="", $mode="") {
66
	global $config;
67

    
68
	$ret = "";
69
	if ($iface != "") {
70
		$realif=convert_friendly_interface_to_real_interface_name($iface);
71
		if (!empty($realif))
72
			$ret = "if={$realif} ";
73
	}
74

    
75
	switch($mode) {
76
	case "enable":
77
		if ($config['installedpackages']['routed']['config'][0]['ripversion'] == "2") {
78
			$ret .= "ripv2 ";
79
			$passwd = $config['installedpackages']['routed']['config'][0]['passwd'];
80
			if ($passwd != "") {
81
				$ret .= "passwd={$passwd} ";
82
			}
83
                        $add_no_ag = $config['installedpackages']['routed']['config'][0]['enable_no_ag'];
84
                        $add_no_super_ag = $config['installedpackages']['routed']['config'][0]['enable_no_super_ag'];
85
                        if($add_no_ag == "on") {
86
                                $ret .= "no_ag ";
87
                        }
88
                        if($add_no_super_ag == "on") {
89
                                $ret .= "no_super_ag ";
90
                        }
91
		}
92
		break;
93
	case "disable":
94
		$ret .= "no_rip_out no_solicit no_rdisc no_rdisc_adv";
95
		break;
96

    
97
	default:
98
		break;
99

    
100
	}
101
	$ret .= "\n";
102

    
103
	return $ret;
104
}
105

    
106
function start_routed() {
107
	mwexec_bg("/sbin/routed");
108
}
109

    
110
function stop_routed() {
111
	killbyname("routed");
112
}
113

    
114
function restart_routed() {
115
	stop_routed();
116
	start_routed();
117
}
118

    
119
?>
(5-5/7)