1 # An OpenSLP webmin module
2 # by Monty Charlton <monty@caldera.com>,
4 # Copyright (c) 2000 Caldera Systems
6 # Permission to use, copy, modify, and distribute this software and its
7 # documentation under the terms of the GNU General Public License is hereby
8 # granted. No representations are made about the suitability of this software
9 # for any purpose. It is provided "as is" without express or implied warranty.
10 # See the GNU General Public License for more details.
13 BEGIN { push(@INC, ".."); };
17 #$config_file = "./config-$gconfig{'os_type'}";
18 $config_file = "$module_config_directory/config";
19 $config = &parse_config_file;
25 flock SLP, 1 || &error("$text->{'error_flock_on'} $config->{'slpd_conf'}: $!\n");
26 open(SLP, $config->{'slpd_conf'}) || &error("$text->{'error_open'} $config->{'slpd_conf'}: $!\n");
29 if (/^(\s|#|;)*net.slp.useScopes\s*=\s*(.*)/) {
30 push(@{$snda->{'useScopes'}}, split(/\s*,\s*/, $2));
31 $snda->{'useScopesDisabled'}++ if ($1 =~ /;|#/);
33 elsif (/^(\s|#|;)*net.slp.DAAddresses\s*=\s*(.*)/) {
34 push(@{$snda->{'DAAddresses'}}, split(/\s*,\s*/, $2));
35 $snda->{'DAAddressesDisabled'}++ if ($1 =~ /;|#/);
39 flock SLP, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_conf'}: $!\n");
47 flock SLP, 1 || &error("$text->{'error_flock_on'} $config->{'slpd_conf'}: $!\n");
48 open(SLP, $config->{'slpd_conf'}) || &error("$text->{'error_open'} $config->{'slpd_conf'}: $!\n");
51 if (/^(\s|#|;)*net.slp.isBroadcastOnly\s*=\s*(\S+)/) {
52 $netcfg->{'isBroadcastOnly'} = $2;
53 $netcfg->{'isBroadcastOnlyDisabled'}++ if ($1 =~ /;|#/);
55 elsif (/^(\s|#|;)*net.slp.passiveDADetection\s*=\s*(\S+)/) {
56 $netcfg->{'passiveDADetection'} = $2;
57 $netcfg->{'passiveDADetectionDisabled'}++ if ($1 =~ /;|#/);
59 elsif (/^(\s|#|;)*net.slp.activeDADetection\s*=\s*(\S+)/) {
60 $netcfg->{'activeDADetection'} = $2;
61 $netcfg->{'activeDADetectionDisabled'}++ if ($1 =~ /;|#/);
63 elsif (/^(\s|#|;)*net.slp.DAActiveDiscoveryInterval\s*=\s*(\S+)/) {
64 $netcfg->{'DAActiveDiscoveryInterval'} = $2;
65 $netcfg->{'DAActiveDiscoveryIntervalDisabled'}++ if ($1 =~ /;|#/);
67 elsif (/^(\s|#|;)*net.slp.multicastTTL\s*=\s*(\S+)/) {
68 $netcfg->{'multicastTTL'} = $2;
69 $netcfg->{'multicastTTLDisabled'}++ if ($1 =~ /;|#/);
71 elsif (/^(\s|#|;)*net.slp.DADiscoveryMaximumWait\s*=\s*(\S+)/) {
72 $netcfg->{'DADiscoveryMaximumWait'} = $2;
73 $netcfg->{'DADiscoveryMaximumWaitDisabled'}++ if ($1 =~ /;|#/);
75 elsif (/^(\s|#|;)*net.slp.DADiscoveryTimeouts\s*=\s*(.*)/) {
76 push(@{$netcfg->{'DADiscoveryTimeouts'}}, split(/\s*,\s*/, $2));
77 $netcfg->{'DADiscoveryTimeoutsDisabled'}++ if ($1 =~ /;|#/);
79 elsif (/^(\s|#|;)*net.slp.HintsFile\s*=\s*(\S+)/) {
80 $netcfg->{'HintsFile'} = $2;
81 $netcfg->{'HintsFileDisabled'}++ if ($1 =~ /;|#/);
83 elsif (/^(\s|#|;)*net.slp.multicastMaximumWait\s*=\s*(\S+)/) {
84 $netcfg->{'multicastMaximumWait'} = $2;
85 $netcfg->{'multicastMaximumWaitDisabled'}++ if ($1 =~ /;|#/);
87 elsif (/^(\s|#|;)*net.slp.multicastTimeouts\s*=\s*(.*)/) {
88 push(@{$netcfg->{'multicastTimeouts'}}, split(/\s*,\s*/, $2));
89 $netcfg->{'multicastTimeoutsDisabled'}++ if ($1 =~ /;|#/);
91 elsif (/^(\s|#|;)*net.slp.unicastMaximumWait\s*=\s*(\S+)/) {
92 $netcfg->{'unicastMaximumWait'} = $2;
93 $netcfg->{'unicastMaximumWaitDisabled'}++ if ($1 =~ /;|#/);
95 elsif (/^(\s|#|;)*net.slp.randomWaitBound\s*=\s*(\S+)/) {
96 $netcfg->{'randomWaitBound'} = $2;
97 $netcfg->{'randomWaitBoundDisabled'}++ if ($1 =~ /;|#/);
99 elsif (/^(\s|#|;)*net.slp.MTU\s*=\s*(\S+)/) {
100 $netcfg->{'MTU'} = $2;
101 $netcfg->{'MTUDisabled'}++ if ($1 =~ /;|#/);
103 elsif (/^(\s|#|;)*net\.slp\.interfaces\s*=\s*(.*)/) {
104 push(@{$netcfg->{'interfaces'}}, split(/\s*,\s*/, $2));
105 $netcfg->{'interfacesDisabled'}++ if ($1 =~ /;|#/);
109 flock SLP, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_conf'}: $!\n");
117 flock SLP, 1 || &error("$text->{'error_flock_on'} $config->{'slpd_conf'}: $!\n");
118 open(SLP, $config->{'slpd_conf'}) || &error("$text->{'error_open'} $config->{'slpd_conf'}: $!\n");
121 if (/^(\s|#|;)*net.slp.isDA\s*=\s*(\S+)/) {
122 $dacfg->{'isDA'} = $2;
123 $dacfg->{'isDADisabled'}++ if ($1 =~ /;|#/);
127 flock SLP, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_conf'}: $!\n");
135 flock SLP, 1 || &error("$text->{'error_flock_on'} $config->{'slpd_conf'}: $!\n");
136 open(SLP, $config->{'slpd_conf'}) || &error("$text->{'error_open'} $config->{'slpd_conf'}: $!\n");
139 if (/^(\s|#|;)*net.slp.traceDATraffic\s*=\s*(\S+)/) {
140 $dacfg->{'traceDATraffic'} = $2;
141 $dacfg->{'traceDATrafficDisabled'}++ if ($1 =~ /;|#/);
143 elsif (/^(\s|#|;)*net.slp.traceMsg\s*=\s*(\S+)/) {
144 $dacfg->{'traceMsg'} = $2;
145 $dacfg->{'traceMsgDisabled'}++ if ($1 =~ /;|#/);
147 elsif (/^(\s|#|;)*net.slp.traceDrop\s*=\s*(\S+)/) {
148 $dacfg->{'traceDrop'} = $2;
149 $dacfg->{'traceDropDisabled'}++ if ($1 =~ /;|#/);
151 elsif (/^(\s|#|;)*net.slp.traceReg\s*=\s*(\S+)/) {
152 $dacfg->{'traceReg'} = $2;
153 $dacfg->{'traceRegDisabled'}++ if ($1 =~ /;|#/);
158 flock SLP, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_conf'}: $!\n");
162 # enable_list_line(&list, &line)
165 flock SLP, 1 || &error("$text->{'error_flock_on'} $config->{'slpd_conf'}: $!\n");
166 open(SLP, $config->{'slpd_conf'}) || &error("$text->{'error_open'} $config->{'slpd_conf'}: $!\n");
169 flock SLP, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_conf'}: $!\n");
170 flock SLP, 2 || &error("$text->{'error_flock_on'} $config->{'slpd_conf'}: $!\n");
171 &open_tempfile(SLP, ">$config->{'slpd_conf'}") || &error("$text->{'error_open'} $config->{'slpd_conf'}: $!\n");
173 local $list = join ",", @_;
175 if (/^(\s|#|;)*net.slp.$line\s*=\s*\S+/ && $list) {
176 &print_tempfile(SLP, "net.slp.$line=$list\n");
179 &print_tempfile(SLP, $_);
182 &close_tempfile(SLP);
183 flock SLP, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_conf'}: $!\n");
186 # enable_single_val_line(&val, &line)
187 sub enable_single_val_line
189 open(SLP, $config->{slpd_conf}) || &error("$text->{'error_open'} $config->{'slpd_conf'}: $!\n");
190 flock SLP, 1 || &error("$text->{'error_flock_on'} $config->{'slpd_conf'}: $!\n");
193 flock SLP, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_conf'}: $!\n");
194 flock SLP, 2 || &error("$text->{'error_flock_on'} $config->{'slpd_conf'}: $!\n");
195 &open_tempfile(SLP, ">$config->{'slpd_conf'}") || &error("$text->{'error_open'} $config->{'slpd_conf'}: $!\n");
198 if (/^(\s|#|;)*net.slp.$line\s*=\s*\S+\s*$/) {
199 &print_tempfile(SLP, "net.slp.$line=@_[0]\n");
202 &print_tempfile(SLP, $_);
205 &close_tempfile(SLP);
206 flock SLP, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_conf'}: $!\n");
212 flock SLP, 1 || &error("$text->{'error_flock_on'} $config->{'slpd_conf'}: $!\n");
213 open(SLP, $config->{'slpd_conf'}) || &error("$text->{'error_open'} $config->{'slpd_conf'}: $!\n");
216 flock SLP, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_conf'}: $!\n");
217 flock SLP, 2 || &error("$text->{'error_flock_on'} $config->{'slpd_conf'}: $!\n");
218 &open_tempfile(SLP, ">$config->{'slpd_conf'}") || &error("$text->{'error_open'} $config->{'slpd_conf'}: $!\n");
220 if (/^(\s|#|;)*net.slp.@_[0]\s*=\s*(\S+)/) {
221 &print_tempfile(SLP, ";net.slp.@_[0]=$2\n");
224 &print_tempfile(SLP, $_);
227 &close_tempfile(SLP);
228 flock SLP, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_conf'}: $!\n");
232 sub parse_config_file
235 flock FH, 1 || &error("$text->{'error_flock_on'} $config_file: $!\n");
236 open(FH, $config_file) || &error("$text->{'error_open'} $config_file: $!\n");
238 $dummy{$1} = $2 if (/(\S+)=(.+)/)
242 flock FH, 8 || &error("$text->{'error_flock_off'} $config_file: $!\n");
249 flock PID, 1 || &error("$text->{'error_flock_on'} $config->{'slpd_pid'}: $!\n");
250 open(PID, $config->{'slpd_pid'}) || &start_slpd;
252 $pid=$1, last if (/(\d+)/)
255 flock PID, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_pid'}: $!\n");
257 kill('HUP', $pid) || &error("$text->{'error_hup'}: $config->{'slpd_pid'}\n");
267 flock PID, 1 || &error("$text->{'error_flock_on'} $config->{'slpd_pid'}: $!\n");
268 open(PID, $config->{'slpd_pid'}) || return 0;
270 $pid=$1, last if (/(\d+)/)
273 flock PID, 8 || &error("$text->{'error_flock_off'} $config->{'slpd_pid'}: $!\n");
275 # the pid file has a number in it but
276 # we need to check if slpd is _actually_ running
277 if (kill 0 => $pid) {
290 &error_setup($text->{'start_err'});
291 local $temp = &transname();
292 local $rv = &system_logged("($config->{'start_cmd'}) >$temp 2>&1");
293 local $out = `cat $temp`;
296 &webmin_log("start");
301 $out = &backquote_logged("$config->{'stop_cmd'} 2>&1");
302 &error_setup($text->{'stop_err'});
304 &error("<pre>$?\n$out</pre>");