Project

General

Profile

Download (3.64 KB) Statistics
| Branch: | Tag: | Revision:
1 7a7cc84b Bill Marquette
<?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 d71fc5d3 jim-p
$shortcut_section = "routed";
32
33 7a7cc84b Bill Marquette
function setup_routed() {
34
	global $config;
35
	$gw = "";
36
37 7dbaa205 Ermal Lu?i
	if (!is_array($config['installedpackages']['routed']))
38
		return;
39
	if (!is_array($config['installedpackages']['routed']['config']))
40
		return;
41 7a7cc84b Bill Marquette
	if (isset($config['installedpackages']['routed']['config'][0]['enable']) &&
42 7dbaa205 Ermal Lu?i
		$config['installedpackages']['routed']['config'][0]['enable'] == "on") {
43 7a7cc84b Bill Marquette
		/* if user selected individual interfaces */
44 13f0762d Bill Marquette
		$ifarr = array_flip(explode(",", $config['installedpackages']['routed']['config'][0]['iface_array']));
45
                $allifs = get_interface_arr();
46 227f2be5 Ermal
                if (!empty($ifarr)) {
47 13f0762d Bill Marquette
                        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 7a7cc84b Bill Marquette
			}
54 227f2be5 Ermal
		} else
55 7a7cc84b Bill Marquette
			/* setup for all interfaces */
56
			$gw = setup_etc_gateways();
57 5db11366 Ermal Lu?i
		conf_mount_rw();
58 227f2be5 Ermal
		file_put_contents("/etc/gateways", $gw);
59 5db11366 Ermal Lu?i
		conf_mount_ro();
60 7a7cc84b Bill Marquette
		restart_routed();
61 227f2be5 Ermal
	} else
62 7a7cc84b Bill Marquette
		stop_routed();
63
}
64
65
function setup_etc_gateways($iface="", $mode="") {
66
	global $config;
67
68 5db11366 Ermal Lu?i
	$ret = "";
69 7a7cc84b Bill Marquette
	if ($iface != "") {
70 5db11366 Ermal Lu?i
		$realif=convert_friendly_interface_to_real_interface_name($iface);
71 227f2be5 Ermal
		if (!empty($realif))
72 5db11366 Ermal Lu?i
			$ret = "if={$realif} ";
73 7a7cc84b Bill Marquette
	}
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 b30e3be4 Andrew Lowther
                        $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 7a7cc84b Bill Marquette
		}
92
		break;
93
	case "disable":
94 13f0762d Bill Marquette
		$ret .= "no_rip_out no_solicit no_rdisc no_rdisc_adv";
95 7a7cc84b Bill Marquette
		break;
96
97
	default:
98
		break;
99
100
	}
101
	$ret .= "\n";
102
103
	return $ret;
104
}
105
106
function start_routed() {
107 227f2be5 Ermal
	mwexec_bg("/sbin/routed");
108 7a7cc84b Bill Marquette
}
109
110
function stop_routed() {
111 227f2be5 Ermal
	killbyname("routed");
112 7a7cc84b Bill Marquette
}
113
114
function restart_routed() {
115
	stop_routed();
116
	start_routed();
117
}
118
119 7dbaa205 Ermal Lu?i
?>