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