Project

General

Profile

Feature #3456 » ladvd.inc

Andrea Tuccia, 02/17/2014 04:52 AM

 
1
<?php
2
/*
3
	ladvd.inc
4
        Copyright (C) 2006 Scott Ullrich
5
	All rights reserved.
6

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

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

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

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

    
29
require_once("util.inc");
30
require_once("functions.inc");
31
require_once("pkg-utils.inc");
32
require_once("globals.inc");
33

    
34
function ladvd_install_command() {
35
	conf_mount_rw();
36
	exec("pkg_add http://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.3-release/net/ladvd-1.0.2.tbz");
37
	conf_mount_ro();
38
}
39

    
40
function ladvd_deinstall_command() {
41
	conf_mount_rw();
42
	exec("pkg_delete -f ladvd-1.0.2");
43
	conf_mount_ro();
44
}
45

    
46
function ladvd_resync_config() {
47
	global $config;
48

    
49
	conf_mount_rw();
50
	unlink_if_exists("/etc/rc.d/ladvd");
51

    
52
	$ladvd_conf = &$config['installedpackages']['ladvd']['config'][0];
53

    
54
	/* ladvd is turned off in package settings */
55
	if($ladvd_conf['enable'] == "0") {
56
		return;
57
	}
58

    
59
	$cmdline = "";
60

    
61
	if($ladvd_conf['autoenable'] != "") {
62
	    $cmdline .= "-a ";
63
	}
64

    
65
	if($ladvd_conf['silent'] != "") {
66
	    $cmdline .= "-s ";
67
	}
68

    
69
	if($ladvd_conf['management'] != "") {
70
	    $cmdline .= "-m " . convert_friendly_interface_to_real_interface_name($ladvd_conf['management']) . " ";
71
	}
72

    
73
	if($ladvd_conf['location'] != "") {
74
	    $cmdline .= "-l \"" . $ladvd_conf['location'] . "\" ";
75
	}
76

    
77
	if($ladvd_conf['lldp'] != "") {
78
	    $cmdline .= "-L ";
79
	}
80

    
81
	if($ladvd_conf['cdp'] != "") {
82
	    $cmdline .= "-C ";
83
	}
84

    
85
	if($ladvd_conf['edp'] != "") {
86
	    $cmdline .= "-E ";
87
	}
88

    
89
	if($ladvd_conf['fdp'] != "") {
90
	    $cmdline .= "-F ";
91
	}
92

    
93
	if($ladvd_conf['ndp'] != "") {
94
	    $cmdline .= "-N ";
95
	}
96

    
97
	$ifaces = explode(",", $ladvd_conf['iface_array']);
98
	$ifaces = array_map('convert_friendly_interface_to_real_interface_name', $ifaces);
99
	$cmdline .= implode(" ", $ifaces);
100

    
101
	write_rcfile(array(
102
		"file" => "ladvd.sh",
103
		"start" => "/usr/local/sbin/ladvd $cmdline",
104
		"stop" => "/usr/bin/killall -9 ladvd"
105
		)
106
	);
107

    
108
	exec("killall -9 ladvd");
109
	sleep(1);
110
	start_service("ladvd");
111
	sleep(1);
112
	conf_mount_ro();
113

    
114
}
115

    
116
?>
(2-2/4)