Set version to "2.7".
[ipfire-2.x.git] / html / cgi-bin / samba.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 #                                                                             #
4 # IPFire.org - A linux based firewall                                         #
5 # Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
6 #                                                                             #
7 # This program is free software: you can redistribute it and/or modify        #
8 # it under the terms of the GNU General Public License as published by        #
9 # the Free Software Foundation, either version 3 of the License, or           #
10 # (at your option) any later version.                                         #
11 #                                                                             #
12 # This program is distributed in the hope that it will be useful,             #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
15 # GNU General Public License for more details.                                #
16 #                                                                             #
17 # You should have received a copy of the GNU General Public License           #
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
19 #                                                                             #
20 ###############################################################################
21
22 use strict;
23 # enable only the following on debugging purpose
24 #use warnings;
25 #use CGI::Carp 'fatalsToBrowser';
26
27 require '/var/ipfire/general-functions.pl';
28 require "${General::swroot}/lang.pl";
29 require "${General::swroot}/header.pl";
30
31 my %sambasettings = ();
32 my %cgisettings = ();
33 my %checked = ();
34 my %netsettings = ();
35 my %ovpnsettings = ();
36 my %color = ();
37 my %mainsettings = ();
38 my $message = "";
39 my $errormessage = "";
40
41 my @Logs = qx(ls /var/log/samba/);
42 my $Log =$Lang::tr{'no log selected'};
43
44 my $Status = qx(/usr/local/bin/sambactrl smbstatus);
45 $Status=~s/\n/<br \/>/g;
46
47 my $userentry = "";
48 my @user = ();
49 my @userline = ();
50 my $userfile = "${General::swroot}/samba/private/smbpasswd";
51 my %selected= () ;
52
53 my $defaultoption= "[Share]\npath = /var/ipfire/samba/share1\ncomment = Share - Public Access\nbrowseable = yes\nwriteable = yes\ncreate mask = 0777\ndirectory mask = 0777\npublic = yes\nforce user = samba";
54 my $defaultprinter= "[Printer]\ncomment = Printer public\npath = /var/spool/cups\nprinting = sysvn\nprintcap = lpstat\npublic = yes\nwritable = no\nprintable = yes";
55 my %printer = ();
56 my %shares = ();
57
58 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
59 &General::readhash("${General::swroot}/ovpn/settings", \%ovpnsettings);
60 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
61 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
62
63 my @ovpnnetwork = split(/\//,$ovpnsettings{'DOVPN_SUBNET'});
64 my @ovpnip      = split(/\./,$ovpnnetwork[0]);
65 $ovpnip[3]=$ovpnip[3]+1;
66
67 ############################################################################################################################
68 ############################################# Samba Dienste fr Statusberprfung ##########################################
69
70 my %servicenames = ('SMB Daemon' => 'smbd','NetBIOS Nameserver' => 'nmbd');
71 #my %servicenames = ('SMB Daemon' => 'smbd','NetBIOS Nameserver' => 'nmbd','Winbind Daemon' => 'winbindd');
72
73 &Header::showhttpheaders();
74
75 ############################################################################################################################
76 #################################### Initialisierung von Samba Variablen fr global Settings ###############################
77
78 $sambasettings{'WORKGRP'} = 'homeip.net';
79 $sambasettings{'NETBIOSNAME'} = 'IPFire';
80 $sambasettings{'SRVSTRING'} = 'Samba running on IPFire 2.7';
81 $sambasettings{'INTERFACES'} = '';
82 $sambasettings{'SECURITY'} = 'share';
83 $sambasettings{'OSLEVEL'} = '33';
84 $sambasettings{'GREEN'} = 'on';
85 $sambasettings{'BLUE'} = 'off';
86 $sambasettings{'ORANGE'} = 'off';
87 $sambasettings{'VPN'} = 'off';
88 $sambasettings{'WINSSRV'} = '';
89 $sambasettings{'WINSSUPPORT'} = 'on';
90 $sambasettings{'REMOTEANNOUNCE'} = '';
91 $sambasettings{'REMOTESYNC'} = '';
92 $sambasettings{'PASSWORDSYNC'} = 'off';
93 $sambasettings{'OTHERINTERFACES'} = '127.0.0.1';
94 $sambasettings{'GUESTACCOUNT'} = 'samba';
95 $sambasettings{'MAPTOGUEST'} = 'Never';
96 $sambasettings{'LOGLEVEL'} = '3 passdb:5 auth:5 winbind:2';
97 $sambasettings{'SYSLOGLEVEL'} = '1';
98 $sambasettings{'SYSLOGONLY'} = 'on';
99 $sambasettings{'DOSCHARSET'} = 'CP850';
100 $sambasettings{'UNIXCHARSET'} = 'UTF8';
101 $sambasettings{'DISPLAYCHARSET'} = 'CP850';
102 $sambasettings{'SOCKETOPTIONS'} = 'TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192 SO_KEEPALIVE';
103 $sambasettings{'WIDELINKS'} = 'on';
104 $sambasettings{'UNIXEXTENSION'} = 'off';
105 ### Values that have to be initialized
106 $sambasettings{'ACTION'} = '';
107 ### Samba CUPS Variablen
108 $sambasettings{'LOADPRINTERS'} = 'Yes';
109 $sambasettings{'PRINTING'} = 'cups';
110 $sambasettings{'PRINTCAPNAME'} = 'cups';
111 my $LOGLINES = '50';
112
113 ################################################## Samba PDC Variablen #####################################################
114
115 $sambasettings{'LOCALMASTER'} = 'off';
116 $sambasettings{'DOMAINMASTER'} = 'off';
117 $sambasettings{'PREFERREDMASTER'} = 'off';
118 my $PDCOPTIONS = `cat ${General::swroot}/samba/pdc`;
119
120
121 ############################################################################################################################
122
123 &General::readhash("${General::swroot}/samba/settings", \%sambasettings);
124 &Header::getcgihash(\%sambasettings);
125
126 sub refreshpage{&Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='1;'>" );print "<center><img src='/images/clock.gif' alt='' /><br/><font color='red'>$Lang::tr{'pagerefresh'}</font></center>";&Header::closebox();}
127
128 if (($sambasettings{'WIDELINKS'} eq 'on') & ($sambasettings{'UNIXEXTENSION'} eq 'on'))
129   {$errormessage = "$errormessage<br />Don't enable 'Wide links' and 'Unix extension' at the same time"; }
130
131 &Header::openpage('Samba', 1, '');
132 &Header::openbigbox('100%', 'left', '', $errormessage);
133
134 ############################################################################################################################
135 ############################################# Samba Rootskript aufrufe fr SU-Actions #######################################
136
137 if ($sambasettings{'ACTION'} eq 'smbuserdisable'){system("/usr/local/bin/sambactrl smbuserdisable $sambasettings{'NAME'}");refreshpage();}
138 if ($sambasettings{'ACTION'} eq 'smbuserenable'){system("/usr/local/bin/sambactrl smbuserenable $sambasettings{'NAME'}");refreshpage();}
139 if ($sambasettings{'ACTION'} eq 'smbuseradd'){system("/usr/local/bin/sambactrl smbuseradd $sambasettings{'USERNAME'} $sambasettings{'PASSWORD'} $sambasettings{'GROUP'} $sambasettings{'SHELL'}");refreshpage();}
140 if ($sambasettings{'ACTION'} eq 'smbpcadd'){system("/usr/local/bin/sambactrl smbpcadd $sambasettings{'PCNAME'} $sambasettings{'GROUP'} $sambasettings{'SHELL'}");refreshpage();}
141 if ($sambasettings{'ACTION'} eq 'smbchangepw'){system("/usr/local/bin/sambactrl smbchangepw $sambasettings{'USERNAME'} $sambasettings{'PASSWORD'}");refreshpage();}
142 if ($sambasettings{'ACTION'} eq 'smbrestart'){system("/usr/local/bin/sambactrl smbrestart");refreshpage();}
143 if ($sambasettings{'ACTION'} eq 'smbstart'){system("/usr/local/bin/sambactrl smbstart");refreshpage();}
144 if ($sambasettings{'ACTION'} eq 'smbstop'){system("/usr/local/bin/sambactrl smbstop");refreshpage();}
145 if ($sambasettings{'ACTION'} eq 'smbreload'){system("/usr/local/bin/sambactrl smbreload");refreshpage();}
146 if ($sambasettings{'ACTION'} eq 'globalresetyes')
147         {
148         system("/usr/local/bin/sambactrl smbglobalreset");
149         $sambasettings{'WORKGRP'} = 'homeip.net';
150         $sambasettings{'NETBIOSNAME'} = 'IPFire';
151         $sambasettings{'SRVSTRING'} = 'Samba running on IPFire 2.0';
152         $sambasettings{'INTERFACES'} = '';
153         $sambasettings{'SECURITY'} = 'share';
154         $sambasettings{'OSLEVEL'} = '65';
155         $sambasettings{'GREEN'} = 'on';
156         $sambasettings{'BLUE'} = 'off';
157         $sambasettings{'ORANGE'} = 'off';
158         $sambasettings{'VPN'} = 'off';
159         $sambasettings{'WINSSRV'} = '';
160         $sambasettings{'WINSSUPPORT'} = 'on';
161         $sambasettings{'REMOTEANNOUNCE'} = '';
162         $sambasettings{'REMOTESYNC'} = '';
163         $sambasettings{'PASSWORDSYNC'} = 'off';
164         $sambasettings{'OTHERINTERFACES'} = '127.0.0.1';
165         $sambasettings{'GUESTACCOUNT'} = 'samba';
166         $sambasettings{'MAPTOGUEST'} = 'Never';
167         $sambasettings{'LOGLEVEL'} = '3 passdb:5 auth:5 winbind:2';
168         $sambasettings{'SYSLOGLEVEL'} = '1';
169         $sambasettings{'SYSLOGONLY'} = 'on';
170         $sambasettings{'DOSCHARSET'} = 'CP850';
171         $sambasettings{'UNIXCHARSET'} = 'UTF8';
172         $sambasettings{'DISPLAYCHARSET'} = 'CP850';
173 ### Samba CUPS Variablen
174         $sambasettings{'LOADPRINTERS'} = 'Yes';
175         $sambasettings{'PRINTING'} = 'cups';
176         $sambasettings{'PRINTCAPNAME'} = 'cups';
177         $sambasettings{'PRINTERNAME'} = 'Printer';
178 ### Values that have to be initialized
179         $sambasettings{'WIDELINKS'} = 'on';
180         $sambasettings{'UNIXEXTENSION'} = 'off';
181         $sambasettings{'ACTION'} = '';
182         $sambasettings{'LOCALMASTER'} = 'off';
183         $sambasettings{'DOMAINMASTER'} = 'off';
184         $sambasettings{'PREFERREDMASTER'} = 'off';
185         $sambasettings{'SOCKETOPTIONS'} = 'TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192 SO_KEEPALIVE';
186         $PDCOPTIONS = `cat ${General::swroot}/samba/pdc`;
187         system("/usr/local/bin/sambactrl smbreload");
188         refreshpage();
189         }
190
191 ############################################################################################################################
192 ################################################ Sicherheitsabfrage für den Reset ##########################################
193
194 if ($sambasettings{'ACTION'} eq 'globalreset')
195         {
196         print <<END
197         <br />
198         <table width='95%' cellspacing='0'>
199         <tr><td bgcolor='$color{'color20'}' colspan='3' align='center'><b>$Lang::tr{'resetglobals'}</b>
200         <tr><td align='right' width='50%'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
201                                          $Lang::tr{'yes'} <input type='image' alt='$Lang::tr{'yes'}' title='$Lang::tr{'yes'}' src='/images/edit-redo.png' />
202                                         <input type='hidden' name='ACTION' value='globalresetyes' /></form></td>
203                         <td align='left'  width='50%'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
204                                         <input type='image' alt='$Lang::tr{'no'}' title='$Lang::tr{'no'}' src='/images/dialog-error.png' /> $Lang::tr{'no'} 
205                                         <input type='hidden' name='ACTION' value='cancel' /></form></td>
206         </tr>
207         </table>
208 END
209 ;
210 }
211
212 if ($sambasettings{'ACTION'} eq 'sharesreset')
213         {
214         print <<END
215         <br />
216         <table width='95%' cellspacing='0'>
217         <tr><td bgcolor='$color{'color20'}' colspan='3' align='center'><b>$Lang::tr{'resetshares'}</b>
218         <tr><td align='right'  width='50%'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
219                                          $Lang::tr{'yes'} <input type='image' alt='$Lang::tr{'yes'}' title='$Lang::tr{'yes'}' src='/images/edit-redo.png' />
220                                         <input type='hidden' name='ACTION' value='sharesresetyes' /></form></td>
221                         <td align='left'  width='50%'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
222                                         <input type='image' alt='$Lang::tr{'no'}' title='$Lang::tr{'no'}' src='/images/dialog-error.png' /> $Lang::tr{'no'} 
223                                         <input type='hidden' name='ACTION' value='cancel' /></form></td>
224         </tr>
225         </table>
226 END
227 ;
228         }
229
230 ############################################################################################################################
231 ########################################### Samba Benutzer oder PC l�chen #################################################
232
233 if ($sambasettings{'ACTION'} eq 'userdelete'){system("/usr/local/bin/sambactrl smbuserdelete $sambasettings{'NAME'}");refreshpage();}
234
235 ############################################################################################################################
236 ##################################### Umsetzen der Werte von Checkboxen und Dropdowns ######################################
237
238 if ($sambasettings{'ACTION'} eq $Lang::tr{'save'})
239 {
240 $sambasettings{'INTERFACES'} = '';
241 if ($sambasettings{'GREEN'} eq 'on'){ $sambasettings{'INTERFACES'} .= " $netsettings{'GREEN_DEV'}";}
242 if ($sambasettings{'BLUE'} eq 'on'){ $sambasettings{'INTERFACES'} .= " $netsettings{'BLUE_DEV'}";}
243 if ($sambasettings{'ORANGE'} eq 'on'){ $sambasettings{'INTERFACES'} .= " $netsettings{'ORANGE_DEV'}";}
244 if ($sambasettings{'VPN'} eq 'on'){$sambasettings{'INTERFACES'} .= " ";}
245 if ($sambasettings{'OTHERINTERFACES'} ne ''){ $sambasettings{'INTERFACES'} .= " $sambasettings{'OTHERINTERFACES'}";}
246
247 ############################################################################################################################
248 ##################################### Schreiben settings und bersetzen fr smb.conf #######################################
249
250 delete $sambasettings{'__CGI__'};delete $sambasettings{'x'};delete $sambasettings{'y'};
251 &General::writehash("${General::swroot}/samba/settings", \%sambasettings);
252
253 if ($sambasettings{'PASSWORDSYNC'} eq 'on'){ $sambasettings{'PASSWORDSYNC'} = "true";} else { $sambasettings{'PASSWORDSYNC'} = "false";}
254 if ($sambasettings{'WINSSUPPORT'} eq 'on'){ $sambasettings{'WINSSUPPORT'} = "true";$sambasettings{'WINSSRV'} = "";} else { $sambasettings{'WINSSUPPORT'} = "false";}
255 if ($sambasettings{'LOCALMASTER'} eq 'on'){ $sambasettings{'LOCALMASTER'} = "true";} else { $sambasettings{'LOCALMASTER'} = "false";}
256 if ($sambasettings{'DOMAINMASTER'} eq 'on'){ $sambasettings{'DOMAINMASTER'} = "true";} else { $sambasettings{'DOMAINMASTER'} = "false";}
257 if ($sambasettings{'PREFERREDMASTER'} eq 'on'){ $sambasettings{'PREFERREDMASTER'} = "true";} else { $sambasettings{'PREFERREDMASTER'} = "false";}
258 if ($sambasettings{'SYSLOGONLY'} eq 'on'){ $sambasettings{'SYSLOGONLY'} = "yes";} else { $sambasettings{'SYSLOGONLY'} = "no";}
259 if ($sambasettings{'WIDELINKS'} eq 'on'){ $sambasettings{'WIDELINKS'} = "yes";} else { $sambasettings{'WIDELINKS'} = "no";}
260 if ($sambasettings{'UNIXEXTENSION'} eq 'on'){ $sambasettings{'UNIXEXTENSION'} = "yes";} else { $sambasettings{'UNIXEXTENSION'} = "no";}
261
262 ############################################################################################################################
263 ############################################# Schreiben der Samba globals ##################################################
264
265         open (FILE, ">${General::swroot}/samba/global") or die "Can't save the global settings: $!";
266         flock (FILE, 2);
267         
268 print FILE <<END
269 # global.settings by IPFire Project
270
271 [global]
272 netbios name = $sambasettings{'NETBIOSNAME'}
273 server string = $sambasettings{'SRVSTRING'}
274 workgroup = $sambasettings{'WORKGRP'}
275 passdb backend = smbpasswd
276
277 wide links = $sambasettings{'WIDELINKS'}
278 unix extensions = $sambasettings{'UNIXEXTENSION'}
279
280 keep alive = 30
281 os level = $sambasettings{'OSLEVEL'}
282 fstype = NTFS
283
284 kernel oplocks = false
285 map to guest = $sambasettings{'MAPTOGUEST'}
286 smb ports = 445 139
287 dos charset = $sambasettings{'DOSCHARSET'}
288 unix charset = $sambasettings{'UNIXCHARSET'}
289 display charset = $sambasettings{'DISPLAYCHARSET'}
290
291 security = $sambasettings{'SECURITY'}
292 encrypt passwords = yes
293 guest account = $sambasettings{'GUESTACCOUNT'}
294 unix password sync = $sambasettings{'PASSWORDSYNC'}
295 null passwords = yes
296
297 bind interfaces only = true
298 interfaces = $sambasettings{'INTERFACES'}
299 socket options = $sambasettings{'SOCKETOPTIONS'}
300 remote announce = $sambasettings{'REMOTEANNOUNCE'}
301 remote browse sync = $sambasettings{'REMOTESYNC'}
302
303 username level = 1
304 wins support = $sambasettings{'WINSSUPPORT'}
305 wins server = $sambasettings{'WINSSRV'}
306
307 log file       = /var/log/samba/samba-log.%m
308 lock directory = /var/lock/samba
309 pid directory  = /var/run/
310 log level = $sambasettings{'LOGLEVEL'}
311 syslog = $sambasettings{'SYSLOGLEVEL'}
312 syslog only = $sambasettings{'SYSLOGONLY'}
313
314 preferred master = $sambasettings{'PREFERREDMASTER'}
315 domain master = $sambasettings{'DOMAINMASTER'}
316 local master = $sambasettings{'LOCALMASTER'}
317
318 END
319 ;
320 close FILE;
321
322         if (-e "${General::swroot}/cups/enable"){
323         open (FILE, ">>${General::swroot}/samba/global") or die "Can't save the global cups settings: $!";
324         flock (FILE, 2);
325         print FILE <<END
326 load printers = $sambasettings{'LOADPRINTERS'}
327 printing = $sambasettings{'PRINTING'}
328 printcap name = $sambasettings{'PRINTCAPNAME'}
329
330 END
331 ;
332 close FILE;
333         }
334
335         if ($sambasettings{'SECURITY'} eq 'user' && $sambasettings{'DOMAINMASTER'} eq 'true' )
336         {
337         open (FILE, ">${General::swroot}/samba/pdc") or die "Can't save the pdc settings: $!";
338         flock (FILE, 2);
339         chomp $sambasettings{'PDCOPTIONS'};
340         $sambasettings{'PDCOPTIONS'} =~ s/\r\n/\n/gi;
341         $sambasettings{'PDCOPTIONS'} =~ s/^\n//gi;
342         $sambasettings{'PDCOPTIONS'} =~ s/^\r//gi;
343         $sambasettings{'PDCOPTIONS'} =~ s/^.\n//gi;
344         $sambasettings{'PDCOPTIONS'} =~ s/^.\r//gi;
345         print FILE <<END
346 $sambasettings{'PDCOPTIONS'}
347 END
348 ;
349         close FILE;
350         }
351
352 if ( -e "/var/ipfire/cups/enable")
353         {
354         if ( $sambasettings{'SECURITY'} eq 'user' && $sambasettings{'DOMAINMASTER'} eq 'true' ){system("/usr/local/bin/sambactrl smbsafeconfpdccups");refreshpage();}
355         else {system("/usr/local/bin/sambactrl smbsafeconfcups");}
356         }
357 else
358         {
359         if ( $sambasettings{'SECURITY'} eq 'user' && $sambasettings{'DOMAINMASTER'} eq 'true' ){system("/usr/local/bin/sambactrl smbsafeconfpdc");refreshpage();}
360         else{system("/usr/local/bin/sambactrl smbsafeconf");}
361         }
362
363 system("/usr/local/bin/sambactrl smbreload");refreshpage();
364 }
365   &General::readhash("${General::swroot}/samba/settings", \%sambasettings);
366   
367
368 if ($errormessage)
369         {
370         &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
371         print "<class name='base'>$errormessage\n";
372         print "&nbsp;</class>\n";
373         &Header::closebox();
374         }
375
376 ############################################################################################################################
377 ########################################## Aktivieren von Checkboxen und Dropdowns #########################################
378
379 $checked{'SYSLOGONLY'}{'off'} = '';
380 $checked{'SYSLOGONLY'}{'on'} = '';
381 $checked{'SYSLOGONLY'}{$sambasettings{'SYSLOGONLY'}} = "checked='checked'";
382 $checked{'WINSSUPPORT'}{'off'} = '';
383 $checked{'WINSSUPPORT'}{'on'} = '';
384 $checked{'WINSSUPPORT'}{$sambasettings{'WINSSUPPORT'}} = "checked='checked'";
385 $checked{'PASSWORDSYNC'}{'off'} = '';
386 $checked{'PASSWORDSYNC'}{'on'} = '';
387 $checked{'PASSWORDSYNC'}{$sambasettings{'PASSWORDSYNC'}} = "checked='checked'";
388 $checked{'LOCALMASTER'}{'off'} = '';
389 $checked{'LOCALMASTER'}{'on'} = '';
390 $checked{'LOCALMASTER'}{$sambasettings{'LOCALMASTER'}} = "checked='checked'";
391 $checked{'DOMAINMASTER'}{'off'} = '';
392 $checked{'DOMAINMASTER'}{'on'} = '';
393 $checked{'DOMAINMASTER'}{$sambasettings{'DOMAINMASTER'}} = "checked='checked'";
394 $checked{'PREFERREDMASTER'}{'off'} = '';
395 $checked{'PREFERREDMASTER'}{'on'} = '';
396 $checked{'PREFERREDMASTER'}{$sambasettings{'PREFERREDMASTER'}} = "checked='checked'";
397 $checked{'WIDELINKS'}{'off'} = '';
398 $checked{'WIDELINKS'}{'on'} = '';
399 $checked{'WIDELINKS'}{$sambasettings{'WIDELINKS'}} = "checked='checked'";
400 $checked{'UNIXEXTENSION'}{'off'} = '';
401 $checked{'UNIXEXTENSION'}{'on'} = '';
402 $checked{'UNIXEXTENSION'}{$sambasettings{'UNIXEXTENSION'}} = "checked='checked'";
403 $checked{'GREEN'}{'off'} = '';
404 $checked{'GREEN'}{'on'} = '';
405 $checked{'GREEN'}{$sambasettings{'GREEN'}} = "checked='checked'";
406 $checked{'BLUE'}{'off'} = '';
407 $checked{'BLUE'}{'on'} = '';
408 $checked{'BLUE'}{$sambasettings{'BLUE'}} = "checked='checked'";
409 $checked{'ORANGE'}{'off'} = '';
410 $checked{'ORANGE'}{'on'} = '';
411 $checked{'ORANGE'}{$sambasettings{'ORANGE'}} = "checked='checked'";
412 $checked{'VPN'}{'off'} = '';
413 $checked{'VPN'}{'on'} = '';
414 $checked{'VPN'}{$sambasettings{'VPN'}} = "checked='checked'";
415
416 $selected{'MAPTOGUEST'}{$sambasettings{'MAPTOGUEST'}} = "selected='selected'";
417 $selected{'SECURITY'}{$sambasettings{'SECURITY'}} = "selected='selected'";
418
419 ############################################################################################################################
420 ################################### Aufbau der HTML Seite fr globale Sambaeinstellungen ###################################
421
422 &Header::openbox('100%', 'center', $Lang::tr{'samba'});
423 print <<END
424 <br />
425 <table width='95%' cellspacing='0'>
426 END
427 ;
428 if ( $message ne "" )
429         {
430         print "<tr><td colspan='3' align='left'><font color='red'>$message</font>";
431         }
432
433 print <<END
434 <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'all services'}</b></td></tr>
435 </table><table width='95%' cellspacing='0'>
436 END
437 ;
438
439 my $key = '';
440 foreach $key (sort keys %servicenames)
441         {
442         print "<tr><td align='left' width='40%'>$key</td>";
443         my $shortname = $servicenames{$key};
444         my $status = &isrunning($shortname);
445         print "$status</tr>";
446         }
447
448 print <<END
449 </table>
450 <br />
451 <table width='95%' cellspacing='0'>
452 <tr><td align='left' width='40%' />
453 <td align='center' ><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='smbstart' /><input type='image' alt='$Lang::tr{'smbstart'}' title='$Lang::tr{'smbstart'}' src='/images/go-up.png' /></form></td>
454 <td align='center' ><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='smbstop' /><input type='image' alt='$Lang::tr{'smbstop'}' title='$Lang::tr{'smbstop'}' src='/images/go-down.png' /></form></td>
455 <td align='center' ><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='smbrestart' /><input type='image' alt='$Lang::tr{'smbrestart'}' title='$Lang::tr{'smbrestart'}' src='/images/view-refresh.png' /></form></td></tr>
456 </table>
457 <br />
458 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
459 <table width='95%' cellspacing='0'>
460 <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'basic options'}</b></td></tr>
461 <tr><td align='left' width='40%'>$Lang::tr{'workgroup'}</td><td align='left'><input type='text' name='WORKGRP' value='$sambasettings{'WORKGRP'}' size="30" /></td></tr>
462 <tr><td align='left' width='40%'>$Lang::tr{'netbios name'}</td><td align='left'><input type='text' name='NETBIOSNAME' value='$sambasettings{'NETBIOSNAME'}' size="30" /></td></tr>
463 <tr><td align='left' width='40%'>$Lang::tr{'dos charset'}</td><td align='left'><input type='text' name='DOSCHARSET' value='$sambasettings{'DOSCHARSET'}' size="30" /></td></tr>
464 <tr><td align='left' width='40%'>$Lang::tr{'unix charset'}</td><td align='left'><input type='text' name='UNIXCHARSET' value='$sambasettings{'UNIXCHARSET'}' size="30" /></td></tr>
465 <tr><td align='left' width='40%'>$Lang::tr{'display charset'}</td><td align='left'><input type='text' name='DISPLAYCHARSET' value='$sambasettings{'DISPLAYCHARSET'}' size="30" /></td></tr>
466 <tr><td align='left' width='40%'>$Lang::tr{'server string'}</td><td align='left'><input type='text' name='SRVSTRING' value='$sambasettings{'SRVSTRING'}' size="30" /></td></tr>
467 <tr><td align='left' width='40%'>$Lang::tr{'log level'}</td><td align='left'><input type='text' name='LOGLEVEL' value='$sambasettings{'LOGLEVEL'}' size="30" /></td></tr>
468 <tr><td align='left' width='40%'>Sys$Lang::tr{'log level'}</td><td align='left'><input type='text' name='SYSLOGLEVEL' value='$sambasettings{'SYSLOGLEVEL'}' size="30" /></td></tr>
469 <tr><td align='left' width='40%'>Syslog only</td><td align='left'>on <input type='radio' name='SYSLOGONLY' value='on' $checked{'SYSLOGONLY'}{'on'} />/
470                                                                                                                                                                                         <input type='radio' name='SYSLOGONLY' value='off' $checked{'SYSLOGONLY'}{'off'} /> off</td></tr>
471 <tr><td align='left' width='40%'>$Lang::tr{'interfaces'}</td><td align='left'>on <input type='radio' name='VPN' value='on' $checked{'VPN'}{'on'} />/
472                                                                                                                                                                                 <input type='radio' name='VPN' value='off' $checked{'VPN'}{'off'} /> off |
473                                                                                                                                                                                 <font size='2' color='$Header::colourovpn'><b>   OpenVpn  -  $ovpnip[0].$ovpnip[1].$ovpnip[2].$ovpnip[3]/$ovpnnetwork[1]</b></font></td></tr>
474 <tr><td align='left' width='40%'></td><td align='left'>on <input type='radio' name='GREEN' value='on' $checked{'GREEN'}{'on'} />/
475                                                                                                                                         <input type='radio' name='GREEN' value='off' $checked{'GREEN'}{'off'} /> off |
476                                                                                                                                         <font size='2' color='$Header::colourgreen'><b>   $Lang::tr{'green'}  -  $netsettings{'GREEN_DEV'}</b></font></td></tr>
477 END
478 ;
479
480 if (&Header::blue_used())
481         {
482         print <<END
483         <tr><td align='left' width='40%'></td><td align='left'>on <input type='radio' name='BLUE' value='on' $checked{'BLUE'}{'on'} />/
484                                                                                                                                                 <input type='radio' name='BLUE' value='off' $checked{'BLUE'}{'off'} /> off |
485                                                                                                                                                 <font size='2' color='$Header::colourblue'><b>   $Lang::tr{'wireless'}  -  $netsettings{'BLUE_DEV'}</b></font></td></tr>
486 END
487 ;
488         }
489
490 if (&Header::orange_used())
491         {
492         print <<END
493         <tr><td align='left' width='40%'></td><td align='left'>on <input type='radio' name='ORANGE' value='on' $checked{'ORANGE'}{'on'} />/
494                                                                                                                                                 <input type='radio' name='ORANGE' value='off' $checked{'ORANGE'}{'off'} /> off |
495                                                                                                                                                 <font size='2' color='$Header::colourorange'><b>   $Lang::tr{'dmz'}  -  $netsettings{'ORANGE_DEV'}</b></font></td></tr>
496 END
497 ;
498         }
499
500 print <<END
501 <tr><td align='center' width='40%'>$Lang::tr{'more'}</td><td align='left'><input type='text' name='OTHERINTERFACES' value='$sambasettings{'OTHERINTERFACES'}' size="30" /></td></tr>
502 <tr><td align='left'><br /></td><td></td></tr>
503 <tr><td align='left' width='40%'>Wide links</td><td align='left'>on <input type='radio' name='WIDELINKS' value='on' $checked{'WIDELINKS'}{'on'} />/
504                                                                                                                                                                                         <input type='radio' name='WIDELINKS' value='off' $checked{'WIDELINKS'}{'off'} /> off</td></tr>
505 <tr><td align='left' width='40%'>Unix extension</td><td align='left'>on <input type='radio' name='UNIXEXTENSION' value='on' $checked{'UNIXEXTENSION'}{'on'} />/
506                                                                                                                                                                                         <input type='radio' name='UNIXEXTENSION' value='off' $checked{'UNIXEXTENSION'}{'off'} /> off</td></tr>
507 <tr><td align='left'><br /></td><td></td></tr>
508 <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'security options'}</b></td></tr>
509 <tr><td align='left' width='40%'>$Lang::tr{'security'}</td><td align='left'><select name='SECURITY' style="width: 165px">
510                                                                                                                                                                 <option value='share' $selected{'SECURITY'}{'share'}>Share</option>
511                                                                                                                                                                 <option value='user' $selected{'SECURITY'}{'user'}>User</option>
512                                                                                                                                                                 <option value='domain' $selected{'SECURITY'}{'domain'}>Domain</option>
513                                                                                                                                                                 <option value='ADS' $selected{'SECURITY'}{'ADS'}>ADS</option>
514                                                                                                                                                                 <option value='server' $selected{'SECURITY'}{'server'}>Server</option>
515                                                                                                                                                                 </select></td></tr>
516 <tr><td align='left' width='40%'>$Lang::tr{'map to guest'}</td><td align='left'><select name='MAPTOGUEST' style="width: 165px">
517                                                                                                                                                                                 <option value='Never' $selected{'MAPTOGUEST'}{'Never'}>Never</option>
518                                                                                                                                                                                 <option value='Bad User' $selected{'MAPTOGUEST'}{'Bad User'}>Bad User</option>
519                                                                                                                                                                                 <option value='Bad Password' $selected{'MAPTOGUEST'}{'Bad Password'}>Bad Password</option>
520                                                                                                                                                                                 </select></td></tr>
521 END
522 ;
523 #<tr><td align='left' width='40%'>$Lang::tr{'unix password sync'}</td><td align='left'>on <input type='radio' name='PASSWORDSYNC' value='on' $checked{'PASSWORDSYNC'}{'on'} />/
524 #                                                                                                                                                                                                               <input type='radio' name='PASSWORDSYNC' value='off' $checked{'PASSWORDSYNC'}{'off'} /> off</td></tr>
525 print <<END
526 <tr><td align='left'><br /></td><td /></tr>
527 <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'network options'}</b></td></tr>
528 <tr><td align='left' width='40%'>$Lang::tr{'os level'}</td><td align='left'><input type='text' name='OSLEVEL' value='$sambasettings{'OSLEVEL'}' size="30" /></td></tr>
529 <tr><td align='left' width='40%'>$Lang::tr{'socket options'}</td><td align='left'><input type='text' name='SOCKETOPTIONS' value='$sambasettings{'SOCKETOPTIONS'}' size="30" /></td></tr>
530 <tr><td align='left' width='40%'>$Lang::tr{'remote announce'}</td><td align='left'><input type='text' name='REMOTEANNOUNCE' value='$sambasettings{'REMOTEANNOUNCE'}' size="30" /></td></tr>
531 <tr><td align='left' width='40%'>$Lang::tr{'remote browse sync'}</td><td align='left'><input type='text' name='REMOTESYNC' value='$sambasettings{'REMOTESYNC'}' size="30" /></td></tr>
532 END
533 ;
534 if ($sambasettings{'WINSSUPPORT'} eq 'off') {print"<tr><td align='left' width='40%'>$Lang::tr{'wins server'}</td><td align='left'><input type='text' name='WINSSRV' value='$sambasettings{'WINSSRV'}' size='30' /></td></tr>";}
535         print <<END
536 <tr><td align='left' width='40%'>$Lang::tr{'wins support'}</td><td align='left'>on <input type='radio' name='WINSSUPPORT' value='on' $checked{'WINSSUPPORT'}{'on'} />/
537                                                                                                                                                                                                 <input type='radio' name='WINSSUPPORT' value='off' $checked{'WINSSUPPORT'}{'off'} /> off</td></tr>
538 END
539 ;
540
541 if ($sambasettings{'SECURITY'} eq 'user')
542         {
543         print <<END
544 <tr><td align='left' width='40%'>$Lang::tr{'local master'}</td><td align='left'>on <input type='radio' name='LOCALMASTER' value='on' $checked{'LOCALMASTER'}{'on'} />/
545                                                                                                                                                                                         <input type='radio' name='LOCALMASTER' value='off' $checked{'LOCALMASTER'}{'off'} /> off</td></tr>
546 <tr><td align='left' width='40%'>$Lang::tr{'domain master'}</td><td align='left'>on <input type='radio' name='DOMAINMASTER' value='on' $checked{'DOMAINMASTER'}{'on'} />/
547                                                                                                                                                                                                 <input type='radio' name='DOMAINMASTER' value='off' $checked{'DOMAINMASTER'}{'off'} /> off</td></tr>
548 <tr><td align='left' width='40%'>$Lang::tr{'prefered master'}</td><td align='left'>on <input type='radio' name='PREFERREDMASTER' value='on' $checked{'PREFERREDMASTER'}{'on'} />/
549                                                                                                                                                                                                         <input type='radio' name='PREFERREDMASTER' value='off' $checked{'PREFERREDMASTER'}{'off'} /> off</td></tr>
550 END
551 ;
552         }
553
554 if ($sambasettings{'SECURITY'} eq 'user' && $sambasettings{'DOMAINMASTER'} eq 'on')
555         {
556         print <<END
557         <tr><td align='left'><br /></td><td></td></tr>
558         <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'pdc options'}</b></td></tr>
559         <tr><td align='left'><br /></td><td></td></tr>
560         <tr><td colspan='2' align='center'><textarea name="PDCOPTIONS" cols="50" rows="15" Wrap="off">$PDCOPTIONS</textarea></td></tr>
561 END
562 ;
563         }
564         
565         if ( -e "/var/ipfire/cups/enable")
566         {
567         print <<END
568         <tr><td align='left'><br /></td><td></td></tr>
569         <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'printing options'}</b></td></tr>
570         <tr><td align='left' width='40%'>$Lang::tr{'load printer'}</td><td align='left'><input type='text' name='LOADPRINTERS' value='$sambasettings{'LOADPRINTERS'}' size="30" /></td></tr>
571         <tr><td align='left' width='40%'>$Lang::tr{'printing'}</td><td align='left'><input type='text' name='PRINTING' value='$sambasettings{'PRINTING'}' size="30" /></td></tr>
572         <tr><td align='left' width='40%'>$Lang::tr{'printcap name'}</td><td align='left'><input type='text' name='PRINTCAPNAME' value='$sambasettings{'PRINTCAPNAME'}' size="30" /></td></tr>
573 END
574 ;
575         }
576
577 print <<END
578 </table>
579 <br />
580 <table width='10%' cellspacing='0'>
581 <tr><td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
582                                                                                                 <input type='hidden' name='ACTION' value=$Lang::tr{'save'} />
583                                                                                                 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></form></td>
584 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
585                                                                                 <input type='hidden' name='ACTION' value='globalreset' />
586                                                                                 <input type='image' alt='$Lang::tr{'reset'}' title='$Lang::tr{'reset'}' src='/images/reload.gif' /></form></td>
587 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
588                                                                                 <input type='hidden' name='ACTION' value='globalcaption' />
589                                                                                 <input type='image' alt='$Lang::tr{'caption'}' title='$Lang::tr{'caption'}' src='/images/help-browser.png' /></form></td></tr>
590 </table>
591 END
592 ;
593
594 if ($sambasettings{'ACTION'} eq 'globalcaption')
595         {
596         print <<END
597         <br />
598         <table width='95%' cellspacing='0'>
599         <tr><td align='center' colspan='2'><b>$Lang::tr{'caption'}</b></td></tr>
600         <tr><td align='right' width='33%'><img src='/images/media-floppy.png' /></td><td align='left'>$Lang::tr{'save settings'}</td></tr>
601         <tr><td align='right' width='33%'><img src='/images/reload.gif' /></td><td align='left'>$Lang::tr{'restore settings'}</td></tr>
602         </table>
603 END
604 ;
605         }
606
607 &Header::closebox();
608
609 ############################################################################################################################
610 ########################################## Benutzerverwaltung fr Usersecurity #############################################
611
612 if ($sambasettings{'SECURITY'} eq 'user')
613         {
614         if ($sambasettings{'DOMAINMASTER'} eq 'off')
615                 {
616                 &Header::openbox('100%', 'center', $Lang::tr{'accounting user nonpdc'});
617                 }
618         else
619                 {
620                 &Header::openbox('100%', 'center', $Lang::tr{'accounting user pdc'});
621                 }
622         print <<END
623         <a name="$Lang::tr{'accounting'}"</a>
624         <br />
625         <table width='95%' cellspacing='0'>
626         <tr><td colspan='6' align='left'></td></tr>
627         <tr><td bgcolor='$color{'color20'}' colspan='7' align='left'><b>$Lang::tr{'accounting'}</b></td></tr>
628         <tr><td align='left'><u>$Lang::tr{'username'}</u></td><td align='left'><u>$Lang::tr{'password'}</u></td>
629 END
630 ;
631
632         if ($sambasettings{'DOMAINMASTER'} eq 'off')
633                 {
634                 print "<td></td>";
635                 }
636         else
637                 {
638                 print "<td align='left'><u>$Lang::tr{'type'}</u></td>";
639                 }
640
641         print "<td align='left'><u>$Lang::tr{'status'}</u></td><td colspan='3' width='5%' align='center'><u>$Lang::tr{'options'}</u></td></tr>";
642         system('/usr/local/bin/sambactrl readsmbpasswd');
643         open(FILE, "<${General::swroot}/samba/private/smbpasswd") or die "Can't read user file: $!";
644         @user = <FILE>;
645         close(FILE);
646         system('/usr/local/bin/sambactrl locksmbpasswd');
647         
648         my $lines = 0;
649         
650         foreach $userentry (sort @user)
651                 {
652                 @userline = split( /\:/, $userentry );
653     if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>";} else {print "<tr bgcolor='$color{'color22'}'>";}
654                 print "<td align='left'>$userline[0]</td><td align='left'>";
655                 if ($userline[4] =~ /N/)
656                         {
657                         print "$Lang::tr{'not set'}</td><td align='left'>";
658                         }
659                 else
660                         {
661                         print "$Lang::tr{'set'}</td><td align='left'>";
662                         }
663
664                 if ($sambasettings{'DOMAINMASTER'} eq 'off')
665                         {
666                         print "</td><td align='left'>";
667                         }
668                 else
669                         {
670                         if ($userline[0] =~ /\$/)
671                                 {
672                                 print "$Lang::tr{'pc'}</td><td align='left'>";
673                                 }
674                         else
675                                 {
676                                 print "$Lang::tr{'user'}</td><td align='left'>";
677                                 }
678                         }
679
680                 if ($userline[4] =~ /D/)
681                         {
682                         print <<END
683                         $Lang::tr{'inactive'}</td>
684                         <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
685                                         <input type='hidden' name='NAME' value='$userline[0]' />
686                                         <input type='hidden' name='ACTION' value='smbuserenable' />
687                                         <input type='image' alt='$Lang::tr{'activate'}' title='$Lang::tr{'activate'}' src='/images/off.gif' />
688                         </form></td>
689 END
690 ;
691                         }
692                 else
693                         {
694                         print <<END
695                         $Lang::tr{'active'}</td>
696                         <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
697                                         <input type='hidden' name='NAME' value='$userline[0]' />
698                                         <input type='hidden' name='ACTION' value='smbuserdisable' />
699                                         <input type='image' alt='$Lang::tr{'deactivate'}' title='$Lang::tr{'deactivate'}' src='/images/on.gif' />
700                         </form></td>
701 END
702 ;
703                         }
704
705                 if ($userline[0] =~ /\$/)
706                         {
707                         print "<td></td>";
708                         }
709                 else
710                         {
711                         print <<END
712                         <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
713                                         <input type='hidden' name='NAME' value='$userline[0]' />
714                                         <input type='hidden' name='ACTION' value='userchangepw' />
715                                         <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' />
716                         </form></td>
717 END
718 ;
719                         }
720
721                         if ($sambasettings{'DOMAINMASTER'} eq 'on' && $userline[0] =~ /\$/)
722                                 {
723                                 print <<END
724                                 <td><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
725                                                 <input type='hidden' name='NAME' value='$userline[0]' />
726                                                 <input type='hidden' name='ACTION' value='userdelete' />
727                                                 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/network-error.png' />
728                                                 </form></td></tr>
729 END
730 ;
731                                 }
732                         else
733                                 {
734                                 print <<END
735                                 <td><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
736                                                 <input type='hidden' name='NAME' value='$userline[0]' />
737                                                 <input type='hidden' name='ACTION' value='userdelete' />
738                                                 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-option-remove.png' />
739                                 </form></td></tr>
740 END
741 ;
742                                 }
743                 $lines++;
744                 }
745         print <<END
746         </table>
747         <br />
748         <table width='10%' cellspacing='0'>
749         <tr><td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
750                                                                                                         <input type='hidden' name='ACTION' value='useradd' />
751                                                                                                         <input type='image' alt='$Lang::tr{'add user'}' title='$Lang::tr{'add user'}' src='/images/user-option-add.png' /></form></td>
752 END
753 ;
754
755         if ($sambasettings{'DOMAINMASTER'} eq 'on')
756                 {
757                 print <<END
758                 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
759                                                                                                 <input type='hidden' name='ACTION' value='pcadd' />
760                                                                                                 <input type='image' alt='$Lang::tr{'pc add'}' title='$Lang::tr{'pc add'}' src='/images/network.png' /></form>
761 END
762 ;
763                 }
764         print <<END
765         <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
766                                                                                         <input type='hidden' name='ACTION' value='usercaption' />
767                                                                                         <input type='image' alt='$Lang::tr{'caption'}' title='$Lang::tr{'caption'}' src='/images/help-browser.png' /></form>
768         </td></tr>
769         </table>
770 END
771 ;
772
773         if ($sambasettings{'ACTION'} eq 'usercaption')
774                 {
775                 print <<END
776                 <br />
777                 <table width='95%' cellspacing='0'>
778                 <tr><td align='center' colspan='2'><b>$Lang::tr{'caption'}</b></td></tr>
779                 <tr><td align='right' width='33%'><img src='/images/user-option-add.png' /></td><td align='left'>$Lang::tr{'add user'}</td></tr>
780                 <tr><td align='right' width='33%'><img src='/images/network.png' /></td><td align='left'>$Lang::tr{'pc add'}</td></tr>
781                 <tr><td align='right' width='33%'><img src='/images/user-option-remove.png' /></td><td align='left'>$Lang::tr{'delete user'}</td></tr>
782                 <tr><td align='right' width='33%'><img src='/images/network-error.png' /></td><td align='left'>$Lang::tr{'delete pc'}</td></tr>
783                 <tr><td align='right' width='33%'><img src='/images/off.gif' /></td><td align='left'>$Lang::tr{'activate user'}</td></tr>
784                 <tr><td align='right' width='33%'><img src='/images/on.gif' /></td><td align='left'>$Lang::tr{'deactivate user'}</td></tr>
785                 <tr><td align='right' width='33%'><img src='/images/edit.gif' /></td><td align='left'>$Lang::tr{'change passwords'}</td></tr>
786                 <tr><td align='right' width='33%'><img src='/images/media-floppy.png' /></td><td align='left'>$Lang::tr{'save config'}</td></tr>
787                 </table>
788 END
789 ;
790                 }
791
792         if ($sambasettings{'ACTION'} eq 'userchangepw')
793                 {
794                 my $username = "$sambasettings{'NAME'}";
795                 my $password = 'samba';
796                 print <<END
797                 <br />
798                 <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
799                 <table width='95%' cellspacing='0'>
800                 <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'change passwords'}</b></td></tr>
801                 <tr><td align='left'>$Lang::tr{'username'}</td><td><input type='text' name='USERNAME' value='$username' size='30' readonly /></td></tr>
802                 <tr><td align='left'>$Lang::tr{'password'}</td><td><input type='password' name='PASSWORD' value='$password' size='30' /></td></tr>
803                 <tr><td colspan='2' align='center'><input type='hidden' name='ACTION' value='smbchangepw' />
804                                                                                                                                                                 <input type='image' alt=$Lang::tr{'save'} title=$Lang::tr{'save'} src='/images/media-floppy.png' /></td></tr>
805                 </table>
806                 </form>
807 END
808 ;
809                 }
810
811         if ($sambasettings{'ACTION'} eq 'useradd')
812                 {
813                 my $username = "user";
814                 my $password = "samba";
815                 chomp $username;
816                 $username=~s/\s//g;
817                 chomp $password;
818                 $password=~s/\s//g;
819                 print <<END
820                 <br />
821                 <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
822                 <table width='95%' cellspacing='0'>
823                 <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'add user'}</b></td></tr>
824                 <tr><td align='left'>$Lang::tr{'username'}</td><td><input type='text' name='USERNAME' value='$username' size='30' /></td></tr>
825                 <tr><td align='left'>$Lang::tr{'password'}</td><td><input type='password' name='PASSWORD' value='$password' size='30' /></td></tr>
826                 <tr><td align='left'>$Lang::tr{'unix group'}</td><td><input type='text' name='GROUP' value='sambauser' size='30' /></td></tr>
827                 <tr><td align='left'>$Lang::tr{'unix shell'}</td><td><input type='text' name='SHELL' value='/bin/false' size='30' /></td></tr>
828                 <tr><td colspan='2' align='center'><input type='hidden' name='ACTION' value='smbuseradd' />
829                                                                                                                                                                 <input type='image' alt=$Lang::tr{'save'} title=$Lang::tr{'save'} src='/images/media-floppy.png' /></td></tr>
830                 </table>
831                 </form>
832 END
833 ;
834                 }
835
836         if ($sambasettings{'ACTION'} eq 'pcadd')
837                 {
838                 my $pcname = "client\$";
839                 chomp $pcname;
840                 $pcname=~s/\s//g;
841                 print <<END
842                 <br />
843                 <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'>
844                 <table width='95%' cellspacing='0'>
845                 <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'pc add'}</b></td></tr>
846                 <tr><td align='left'>$Lang::tr{'client'}</td><td><input type='text' name='PCNAME' value='$pcname' size='30' /></td></tr>
847                 <tr><td align='left'>$Lang::tr{'unix group'}</td><td><input type='text' name='GROUP' value='sambawks' size='30' /></td></tr>
848                 <tr><td align='left'>$Lang::tr{'unix shell'}</td><td><input type='text' name='SHELL' value='/bin/false' size='30' /></td></tr>
849                 <tr><td colspan='2' align='center'><input type='hidden' name='ACTION' value='smbpcadd' />
850                                                                                                                                                                 <input type='image' title=$Lang::tr{'save'} alt=$Lang::tr{'save'} src='/images/media-floppy.png' /></td></tr>
851                 </table>
852                 </form>
853 END
854 ;
855                 }
856
857 &Header::closebox();
858 }
859
860 ############################################################################################################################
861 ############################################### Verwalten von Freigaben ####################################################
862
863 &Header::openbox('100%', 'center', $Lang::tr{'shares'});
864
865 my %shares =  config("${General::swroot}/samba/shares");
866
867
868 print <<END
869 <a name="$Lang::tr{'manage shares'}"</a>
870 <br />
871 <table width='95%' cellspacing='0'>
872 <tr><td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'manage shares'}</b>
873 <tr><td align='left'><u>$Lang::tr{'sharename'}</u></td><td colspan='2' width="5%" align='center'><u>$Lang::tr{'options'}</u></td></tr>
874 END
875 ;
876
877 my @Shares = keys(%shares);
878 my $lines = 0;
879
880 foreach my $shareentry (sort @Shares)
881         {
882         chomp $shareentry;
883         if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>";} else {print "<tr bgcolor='$color{'color22'}'>";}
884         print <<END
885         <td align='left'>$shareentry</td>
886         <td><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'>
887                         <input type='hidden' name='NAME' value='$shareentry' />
888                         <input type='hidden' name='ACTION' value='sharechange' />
889                         <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' />
890         </form></td>
891         <td><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'>
892                         <input type='hidden' name='NAME' value='$shareentry' />
893                         <input type='hidden' name='ACTION' value='smbsharedel' />
894                         <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
895         </form></td></tr>
896 END
897 ;
898   $lines++;
899         }
900
901 print <<END
902 </table>
903 <br />
904 <table width='10%' cellspacing='0'>
905 <tr><td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'>
906                                                                                                 <input type='hidden' name='ACTION' value='shareadd' />
907                                                                                                 <input type='image' alt='$Lang::tr{'add share'}' title='$Lang::tr{'add share'}' src='/images/list-add.png' />
908                                                                                                 </form></td>
909                 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'>
910                                                                                                 <input type='hidden' name='ACTION' value='sharesreset' />
911                                                                                                 <input type='image' alt='$Lang::tr{'reset'}' title='$Lang::tr{'reset'}' src='/images/reload.gif' />
912                                                                                                 </form></td>
913                 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'>
914                                                                                                 <input type='hidden' name='ACTION' value='sharecaption' />
915                                                                                                 <input type='image' alt='$Lang::tr{'caption'}' title='$Lang::tr{'caption'}' src='/images/help-browser.png' />
916                                                                                                 </form></td>
917 </tr>
918 </table>
919 END
920 ;
921
922 if ($sambasettings{'ACTION'} eq 'sharecaption')
923         {
924         print <<END
925         <br />
926         <table width='95%' cellspacing='0'>
927         <tr><td align='center' colspan='2'><b>$Lang::tr{'caption'}</b></td></tr>
928         <tr><td align='right' width='33%'><img src='/images/list-add.png' /></td><td align='left'>$Lang::tr{'add share'}</td></tr>
929         <tr><td align='right' width='33%'><img src='/images/edit.gif' /></td><td align='left'>$Lang::tr{'edit share'}</td></tr>
930         <tr><td align='right' width='33%'><img src='/images/media-floppy.png' /></td><td align='left'>$Lang::tr{'save config'}</td></tr>
931         <tr><td align='right' width='33%'><img src='/images/reload.gif' /></td><td align='left'>$Lang::tr{'reset shares'}</td></tr>
932         <tr><td align='right' width='33%'><img src='/images/user-trash.png' /></td><td align='left'>$Lang::tr{'delete share'}</td></tr>
933         </table>
934 END
935 ;
936         }
937
938 if ($sambasettings{'ACTION'} eq 'shareadd' || $sambasettings{'ACTION'} eq 'optioncaption' )
939         {
940         print <<END
941         <br />
942         <table width='95%' cellspacing='0'>
943         <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'add share'}</b></td></tr>
944         <tr><td colspan='2' align='center'></td></tr>
945         <tr><td colspan='2' align='center'>$Lang::tr{'show share options'}
946  <a href="sambahlp.cgi" target="popup" onClick="window.open ('', 'popup', 'width=580,height=600,scrollbars=yes, toolbar=no,status=no, resizable=yes,menubar=no,location=no,directories=no,top=10,left=10')"><img border="0" src="/images/help-browser.png"></a></td></tr>
947         <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'><tr><td colspan='2' align='center'><textarea name="SHAREOPTION" cols="50" rows="15" Wrap="off">$defaultoption</textarea></td></tr>
948         </table>
949         <br />
950         <table width='10%' cellspacing='0'>
951         <tr><td align='center'><input type='hidden' name='ACTION' value='smbshareadd' />
952                                                                                                         <input type='image' alt='$Lang::tr{'add share'}' title='$Lang::tr{'add share'}' src='/images/media-floppy.png' /></td></tr></form>
953         </table>
954 END
955 ;
956         }
957
958 if ($sambasettings{'ACTION'} eq 'sharechange' || $sambasettings{'ACTION'} eq 'optioncaption2' )
959         {
960         my $shareoption = $shares{$sambasettings{'NAME'}};
961         print <<END
962         <br />
963         <table width='95%' cellspacing='0'>
964         <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'edit share'}</b></td></tr>
965         <tr><td colspan='2' align='center'></td></tr>
966         <tr><td colspan='2' align='center'>$Lang::tr{'show share options'}<a href="sambahlp.cgi" target="popup" onClick="window.open ('', 'popup', 'width=580,height=600,scrollbars=yes, toolbar=no,status=no, resizable=yes,menubar=no,location=no,directories=no,top=10,left=10')"><img border="0" src="/images/help-browser.png"></a></td></tr>
967         <tr><td colspan='2' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'><textarea name="SHAREOPTION" cols="50" rows="15" Wrap="off">$shareoption</textarea></td></tr>
968         </table>
969         <br />
970         <table width='10%' cellspacing='0'>
971         <tr><td align='center'><input type='hidden' name='NAME' value='$sambasettings{'NAME'}' />
972                                                                                                         <input type='image' alt='$Lang::tr{'change share'}' title='$Lang::tr{'change share'}' src='/images/media-floppy.png' />
973                                                                                                         <input type='hidden' name='ACTION' value='smbsharechange' /></form></td></tr>
974         </table>
975 END
976 ;
977         }
978
979 if ($sambasettings{'ACTION'} eq 'sharesresetyes')
980         {
981         system('/usr/local/bin/sambactrl smbsharesreset');
982         my $shares = config("${General::swroot}/samba/shares");
983         system("/usr/local/bin/sambactrl smbreload");
984         }
985 if ($sambasettings{'ACTION'} eq 'smbshareadd')
986         {
987         $shares{'xvx'}= "$sambasettings{'SHAREOPTION'}";
988         save("shares");
989         my $shares = config("${General::swroot}/samba/shares");
990         }
991 if ($sambasettings{'ACTION'} eq 'smbsharedel')
992         {
993         delete $shares{$sambasettings{'NAME'}};
994         save("shares");
995         my %shares = config("${General::swroot}/samba/shares");
996         }
997 if ($sambasettings{'ACTION'} eq 'smbsharechange')
998         {
999         $shares{$sambasettings{'NAME'}} = $sambasettings{'SHAREOPTION'};
1000         save("shares");
1001         my %shares = config("${General::swroot}/samba/shares");
1002         }
1003
1004 &Header::closebox();
1005
1006 ############################################################################################################################
1007 ################################################ Verwalten von Druckern ####################################################
1008
1009 my %printer =  config("${General::swroot}/samba/printer");
1010
1011 if ( -e "/var/ipfire/cups/enable")
1012 {
1013 &Header::openbox('100%', 'center', $Lang::tr{'printer'});
1014
1015 my @Printers = keys(%printer);
1016 print <<END
1017 <a name="$Lang::tr{'manage printers'}"</a>
1018 <br />
1019 <table width='95%' cellspacing='0'>
1020 <tr><td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'manage printers'}</b>
1021 <tr><td align='left'><u>$Lang::tr{'printername'}</u></td><td colspan='2' width="5%" align='center'><u>$Lang::tr{'options'}</u></td></tr>
1022 END
1023 ;
1024 foreach my $printerentry (sort @Printers)
1025         {
1026         chomp $printerentry;
1027         print <<END
1028         <tr><td align='left'>$printerentry</td>
1029         <td><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage printers'}'>
1030                         <input type='hidden' name='NAME' value='$printerentry' />
1031                         <input type='hidden' name='ACTION' value='printerchange' />
1032                         <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' />
1033         </form></td>
1034         <td><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage printers'}'>
1035                         <input type='hidden' name='NAME' value='$printerentry' />
1036                         <input type='hidden' name='ACTION' value='smbprinterdel' />
1037                         <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
1038         </form></td></tr>
1039 END
1040 ;
1041         }
1042 print <<END
1043 </table>
1044 <br />
1045 <table width='10%' cellspacing='0'>
1046 <tr><td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage printers'}'>
1047                                                                                                 <input type='hidden' name='ACTION' value='printeradd' />
1048                                                                                                 <input type='image' alt='$Lang::tr{'add printer'}' title='$Lang::tr{'add printer'}' src='/images/list-add.png' />
1049                                                                                                 </form></td>
1050                 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage printers'}'>
1051                                                                                                 <input type='hidden' name='ACTION' value='printereset' />
1052                                                                                                 <input type='image' alt='$Lang::tr{'reset'}' title='$Lang::tr{'reset'}' src='/images/reload.gif' />
1053                                                                                                 </form></td>
1054                 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage printers'}'>
1055                                                                                                 <input type='hidden' name='ACTION' value='printercaption' />
1056                                                                                                 <input type='image' alt='$Lang::tr{'caption'}' title='$Lang::tr{'caption'}' src='/images/help-browser.png' />
1057                                                                                                 </form></td>
1058 </tr>
1059 </table>
1060 END
1061 ;
1062
1063 if ($sambasettings{'ACTION'} eq 'printeradd' || $sambasettings{'ACTION'} eq 'printercaption' )
1064         {
1065         print <<END
1066         <br />
1067         <table width='95%' cellspacing='0'>
1068         <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'add printer'}</b></td></tr>
1069         <tr><td colspan='2' align='center'></td></tr>
1070         <tr><td colspan='2' align='center'>$Lang::tr{'show share options'}
1071  <a href="sambahlp.cgi" target="popup" onClick="window.open ('', 'popup', 'width=580,height=600,scrollbars=yes, toolbar=no,status=no, resizable=yes,menubar=no,location=no,directories=no,top=10,left=10')"><img border="0" src="/images/help-browser.png"></a></td></tr>
1072         <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage printers'}'><tr><td colspan='2' align='center'><textarea name="PRINTEROPTION" cols="50" rows="15" Wrap="off">$defaultprinter</textarea></td></tr>
1073         </table>
1074         <br />
1075         <table width='10%' cellspacing='0'>
1076         <tr><td align='center'><input type='hidden' name='ACTION' value='smbprinteradd' />
1077                                                                                                         <input type='image' alt='$Lang::tr{'add share'}' title='$Lang::tr{'add share'}' src='/images/media-floppy.png' /></td></tr>
1078         </table>
1079         </form>
1080 END
1081 ;
1082         }
1083         
1084 if ($sambasettings{'ACTION'} eq 'printerchange' || $sambasettings{'ACTION'} eq 'printercaption2' )
1085         {
1086         my $printeroption = $printer{$sambasettings{'NAME'}};
1087         print <<END
1088         <br />
1089         <table width='95%' cellspacing='0'>
1090         <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'edit printer'}</b></td></tr>
1091         <tr><td colspan='2' align='center'></td></tr>
1092         <tr><td colspan='2' align='center'>$Lang::tr{'show share options'}<a href="sambahlp.cgi" target="popup" onClick="window.open ('', 'popup', 'width=580,height=600,scrollbars=yes, toolbar=no,status=no, resizable=yes,menubar=no,location=no,directories=no,top=10,left=10')"><img border="0" src="/images/help-browser.png"></a></td></tr>
1093         <tr><td colspan='2' align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage printers'}'><textarea name="PRINTEROPTION" cols="50" rows="15" Wrap="off">$printeroption</textarea></td></tr>
1094         </table>
1095         <br />
1096         <table width='10%' cellspacing='0'>
1097         <tr><td align='center'><input type='hidden' name='NAME' value='$sambasettings{'NAME'}' />
1098                                                                                                         <input type='image' alt='$Lang::tr{'change share'}' title='$Lang::tr{'change share'}' src='/images/media-floppy.png' />
1099                                                                                                         <input type='hidden' name='ACTION' value='smbprinterchange' /></form></td></tr>
1100         </table>
1101 END
1102 ;
1103         }
1104
1105 if ($sambasettings{'ACTION'} eq 'smbprinteradd')
1106         {
1107         $printer{'xvx'}= "$sambasettings{'PRINTEROPTION'}";
1108         save("printer");
1109         my %printer = config("${General::swroot}/samba/printer");
1110         }
1111
1112 if ($sambasettings{'ACTION'} eq 'smbprinterdel')
1113         {
1114         delete $printer{$sambasettings{'NAME'}};
1115         save("printer");
1116         my %printer = config("${General::swroot}/samba/printer");
1117         }
1118
1119 if ($sambasettings{'ACTION'} eq 'smbprinterchange')
1120         {
1121         $printer{$sambasettings{'NAME'}} = $sambasettings{'PRINTEROPTION'};
1122         save("printer");
1123         my %printer = config("${General::swroot}/samba/printer");
1124         }
1125
1126 &Header::closebox();
1127 }
1128
1129 ############################################################################################################################
1130 ############################################### Anzeige des Sambastatus ####################################################
1131
1132 &Header::openbox('100%', 'center', 'Status');
1133
1134 print <<END
1135 <br />
1136 <table width='95%' cellspacing='0'>
1137 <tr><td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'samba status'}</b></td></tr>
1138 <tr><td  align='left'>$Status</td></tr>
1139 </table>
1140 END
1141 ;
1142 &Header::closebox();
1143
1144 ############################################################################################################################
1145 ############################################### Anzeige der Sambalogs ######################################################
1146
1147
1148 if ($sambasettings{'ACTION'} eq 'showlog')
1149 {
1150 $Log = qx(tail -n $sambasettings{'LOGLINES'} /var/log/samba/$sambasettings{'LOG'});
1151 $Log=~s/\n/<br \/>/g;
1152 }
1153
1154 &Header::openbox('100%', 'center', $Lang::tr{'log'});
1155
1156 print <<END
1157 <a name="$Lang::tr{'log view'}"</a>
1158 <br />
1159 <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'log view'}'>
1160 <table width='95%' cellspacing='0'>
1161 <tr><td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'log view'}</b></td></tr>
1162 <tr><td colspan='3'  align='left'><br /></td></tr>
1163 <tr><td  align='left'><select name='LOG' style="width: 200px">
1164 END
1165 ;
1166 foreach my $log (@Logs) {chomp $log;print"<option value='$log'>$log</option>";}
1167 print <<END
1168
1169 </select></td><td  align='left'>$Lang::tr{'show last x lines'}<input type='text' name='LOGLINES' value='$LOGLINES' size="3" /></td>
1170                         <td  align='left'><input type='hidden' name='ACTION' value='showlog' /><input type='image' alt='view Log' title='view Log' src='/images/format-justify-fill.png' /></td></tr>
1171 <tr><td colspan='3'  align='left'><br /></td></tr>
1172 <tr><td colspan='3'  align='left'><font size=2>$Log</font></td></tr>
1173 <tr><td colspan='3'  align='left'><br /></td></tr>
1174 <tr><td colspan='3'  align='center'>$sambasettings{'LOG'}</td></tr>
1175 </table>
1176 </form>
1177 END
1178 ;
1179 &Header::closebox();
1180 &Header::closebigbox();
1181 &Header::closepage();
1182
1183 ############################################################################################################################
1184 ############################################ Subfunktion fr Sambadienste ###################################################
1185
1186 sub config
1187 {
1188 my $file = shift;
1189 my @allarray = `grep -n '^\\[' $file`;
1190 my @linesarray = ();
1191 my @namearray = ();
1192 my %hash = ();
1193 my $options = ();
1194 my $EOF = qx(cat $file | wc -l);
1195 foreach my $allarrayentry (@allarray)
1196  {
1197  my @allarrayline = split( /\:/, $allarrayentry );
1198  push(@linesarray,$allarrayline[0]);$allarrayline[1]=~s/\[//g;$allarrayline[1]=~s/\]//g;push(@namearray,$allarrayline[1]);
1199  }
1200         for(my $i = 0; $i <= $#namearray; $i++)
1201                 {
1202                 chomp $namearray[$i];
1203                 $namearray[$i]=~s/\[//g;$namearray[$i]=~s/\]//g;
1204                 if ( $i eq $#namearray )
1205                         {
1206                         my $lineend = $EOF-$linesarray[$i]+1;
1207                         $options=qx(tail -$lineend $file);
1208                         }
1209                 else
1210                         {
1211                         my $linestart = $EOF-$linesarray[$i]+1;
1212                         my $lineend =  $linesarray[$i+1]-$linesarray[$i];
1213                         $options=qx(tail -$linestart $file | head -$lineend);
1214                         }
1215                 $hash{$namearray[$i]} = "$options";
1216                 #print"<pre>$namearray[$i]\n$options\n</pre>"; # enable only for debuging
1217                 }
1218 return(%hash);
1219 }
1220
1221 sub save
1222 {
1223 my $smb = shift;
1224 open (FILE, ">${General::swroot}/samba/$smb") or die "Can't $smb settings $!";
1225 flock (FILE, 2);
1226
1227 if ( $smb eq 'printer')
1228         {while (my ($name, $option) = each %printer){chomp $option;$option =~ s/\r\n/\n/gi;$option =~ s/^\n//gi;$option =~ s/^\r//gi;$option =~ s/^.\n//gi;$option =~ s/^.\r//gi;print FILE "$option\n";}}
1229
1230 if ( $smb eq 'shares')
1231         {while (my ($name, $option) = each %shares){chomp $option;$option =~ s/\r\n/\n/gi;$option =~ s/^\n//gi;$option =~ s/^\r//gi;$option =~ s/^.\n//gi;$option =~ s/^.\r//gi;print FILE "$option\n";}        }
1232
1233 close FILE;
1234
1235 if ( -e "/var/ipfire/cups/enable")
1236         {
1237         if ( $sambasettings{'SECURITY'} eq 'user' && $sambasettings{'DOMAINMASTER'} eq 'true' ){system("/usr/local/bin/sambactrl smbsafeconfpdccups");}
1238         else {system("/usr/local/bin/sambactrl smbsafeconfcups");}
1239         }
1240 else
1241         {
1242         if ( $sambasettings{'SECURITY'} eq 'user' && $sambasettings{'DOMAINMASTER'} eq 'true' ){system("/usr/local/bin/sambactrl smbsafeconfpdc");}
1243         else{system("/usr/local/bin/sambactrl smbsafeconf");}
1244         }
1245
1246 system("/usr/local/bin/sambactrl smbreload");
1247 refreshpage();
1248 }
1249
1250 sub isrunning
1251         {
1252         my $cmd = $_[0];
1253         my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
1254         my $pid = '';
1255         my $testcmd = '';
1256         my $exename;
1257
1258         $cmd =~ /(^[a-z]+)/;
1259         $exename = $1;
1260
1261         if (open(FILE, "/var/run/${cmd}.pid"))
1262                 {
1263                 $pid = <FILE>; chomp $pid;
1264                 close FILE;
1265                 if (open(FILE, "/proc/${pid}/status"))
1266                         {
1267                         while (<FILE>)
1268                                 {
1269                                 if (/^Name:\W+(.*)/)
1270                                         {
1271                                         $testcmd = $1; 
1272                                         }
1273                                 }
1274                         close FILE;
1275                         if ($testcmd =~ /$exename/)
1276                                 {
1277                                 $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
1278                                 }
1279                         }
1280                 }
1281         return $status;
1282         }