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