]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2005-2013 IPFire Team <info@ipfire.org> # | |
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 %color = (); | |
36 | my %mainsettings = (); | |
37 | my $message = ""; | |
38 | my $errormessage = ""; | |
39 | ||
40 | my $userentry = ""; | |
41 | my @user = (); | |
42 | my @userline = (); | |
43 | my $userfile = "${General::swroot}/samba/private/smbpasswd"; | |
44 | my %selected= () ; | |
45 | ||
46 | my $defaultoption= "[My Share]\npath = \ncomment = Share - Public Access\nbrowseable = yes\nwriteable = yes\ncreate mask = 0644\ndirectory mask = 0755\npublic = yes\nforce user = samba"; | |
47 | my %shares = (); | |
48 | ||
49 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
50 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
51 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
52 | ||
53 | ############################################################################################################################ | |
54 | ############################################# Samba Dienste fr Statusberprfung ########################################## | |
55 | ||
56 | &Header::showhttpheaders(); | |
57 | ||
58 | ############################################################################################################################ | |
59 | #################################### Initialisierung von Samba Variablen fr global Settings ############################### | |
60 | ||
61 | $sambasettings{'WORKGRP'} = 'homeip.net'; | |
62 | $sambasettings{'INTERFACES'} = ''; | |
63 | $sambasettings{'SECURITY'} = 'user'; | |
64 | $sambasettings{'REMOTEANNOUNCE'} = ''; | |
65 | $sambasettings{'REMOTESYNC'} = ''; | |
66 | $sambasettings{'GUESTACCOUNT'} = 'samba'; | |
67 | $sambasettings{'MAPTOGUEST'} = 'Bad User'; | |
68 | $sambasettings{'ENCRYPTION'} = 'optional'; | |
69 | ### Values that have to be initialized | |
70 | $sambasettings{'ACTION'} = ''; | |
71 | my $LOGLINES = '50'; | |
72 | ||
73 | ############################################################################################################################ | |
74 | ||
75 | &General::readhash("${General::swroot}/samba/settings", \%sambasettings); | |
76 | &Header::getcgihash(\%sambasettings); | |
77 | ||
78 | &Header::openpage('Samba', 1, ''); | |
79 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
80 | ||
81 | ############################################################################################################################ | |
82 | ############################################# Samba Rootskript aufrufe fr SU-Actions ####################################### | |
83 | ||
84 | if ($sambasettings{'ACTION'} eq 'smbuserdisable'){system("/usr/local/bin/sambactrl smbuserdisable $sambasettings{'NAME'}");} | |
85 | if ($sambasettings{'ACTION'} eq 'smbuserenable'){system("/usr/local/bin/sambactrl smbuserenable $sambasettings{'NAME'}");} | |
86 | if ($sambasettings{'ACTION'} eq 'smbuseradd'){system("/usr/local/bin/sambactrl smbuseradd $sambasettings{'USERNAME'} $sambasettings{'PASSWORD'} $sambasettings{'GROUP'} $sambasettings{'SHELL'}");} | |
87 | if ($sambasettings{'ACTION'} eq 'smbpcadd'){system("/usr/local/bin/sambactrl smbpcadd $sambasettings{'PCNAME'} $sambasettings{'GROUP'} $sambasettings{'SHELL'}");} | |
88 | if ($sambasettings{'ACTION'} eq 'smbchangepw'){system("/usr/local/bin/sambactrl smbchangepw $sambasettings{'USERNAME'} $sambasettings{'PASSWORD'}");} | |
89 | if ($sambasettings{'ACTION'} eq 'smbrestart'){system("/usr/local/bin/sambactrl smbrestart");} | |
90 | if ($sambasettings{'ACTION'} eq 'smbstart'){system("/usr/local/bin/sambactrl smbstart");} | |
91 | if ($sambasettings{'ACTION'} eq 'smbstop'){system("/usr/local/bin/sambactrl smbstop");} | |
92 | if ($sambasettings{'ACTION'} eq 'smbreload'){system("/usr/local/bin/sambactrl smbreload");} | |
93 | if ($sambasettings{'ACTION'} eq 'join') { | |
94 | $message .= &joindomain($sambasettings{'USERNAME'}, $sambasettings{'PASSWORD'}); | |
95 | } | |
96 | ||
97 | ############################################################################################################################ | |
98 | ########################################### Samba Benutzer oder PC l�chen ################################################# | |
99 | ||
100 | if ($sambasettings{'ACTION'} eq 'userdelete'){system("/usr/local/bin/sambactrl smbuserdelete $sambasettings{'NAME'}");} | |
101 | ||
102 | ############################################################################################################################ | |
103 | ##################################### Umsetzen der Werte von Checkboxen und Dropdowns ###################################### | |
104 | ||
105 | if ($sambasettings{'ACTION'} eq $Lang::tr{'save'}) | |
106 | { | |
107 | ############################################################################################################################ | |
108 | ##################################### Schreiben settings und bersetzen fr smb.conf ####################################### | |
109 | ||
110 | delete $sambasettings{'__CGI__'};delete $sambasettings{'x'};delete $sambasettings{'y'}; | |
111 | &General::writehash("${General::swroot}/samba/settings", \%sambasettings); | |
112 | ||
113 | ############################################################################################################################ | |
114 | ############################################# Schreiben der Samba globals ################################################## | |
115 | ||
116 | open (FILE, ">${General::swroot}/samba/global") or die "Can't save the global settings: $!"; | |
117 | flock (FILE, 2); | |
118 | ||
119 | print FILE <<END | |
120 | # global.settings by IPFire Project | |
121 | ||
122 | [global] | |
123 | server string = Samba on IPFire | |
124 | ||
125 | workgroup = $sambasettings{'WORKGRP'} | |
126 | realm = $mainsettings{'DOMAINNAME'} | |
127 | passdb backend = smbpasswd | |
128 | ||
129 | map to guest = $sambasettings{'MAPTOGUEST'} | |
130 | ||
131 | security = $sambasettings{'SECURITY'} | |
132 | guest account = $sambasettings{'GUESTACCOUNT'} | |
133 | unix password sync = no | |
134 | ||
135 | bind interfaces only = true | |
136 | interfaces = green0 blue0 127.0.0.0/8 | |
137 | remote announce = $sambasettings{'REMOTEANNOUNCE'} | |
138 | remote browse sync = $sambasettings{'REMOTESYNC'} | |
139 | ||
140 | winbind separator = + | |
141 | winbind uid = 10000-20000 | |
142 | winbind gid = 10000-20000 | |
143 | winbind use default domain = yes | |
144 | ||
145 | # Log to syslog | |
146 | logging = syslog | |
147 | ||
148 | # Enable support for Apple | |
149 | vfs objects = catia fruit streams_xattr recycle | |
150 | ||
151 | # Enable following symlinks | |
152 | wide links = yes | |
153 | ||
154 | END | |
155 | ; | |
156 | ||
157 | if ($sambasettings{'ENCRYPTION'} =~ m/(desired|required)/) { | |
158 | print FILE "smb encrypt = $1\n"; | |
159 | } | |
160 | ||
161 | print FILE <<END; | |
162 | # Export all printers | |
163 | [printers] | |
164 | path = /var/spool/samba/ | |
165 | printable = yes | |
166 | ||
167 | END | |
168 | close FILE; | |
169 | ||
170 | system("/usr/local/bin/sambactrl smbsafeconf"); | |
171 | system("/usr/local/bin/sambactrl smbreload"); | |
172 | } | |
173 | &General::readhash("${General::swroot}/samba/settings", \%sambasettings); | |
174 | ||
175 | ||
176 | if ($errormessage) | |
177 | { | |
178 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
179 | print "<class name='base'>$errormessage\n"; | |
180 | print " </class>\n"; | |
181 | &Header::closebox(); | |
182 | } | |
183 | ||
184 | if ($message) { | |
185 | $message = &Header::cleanhtml($message); | |
186 | $message =~ s/\n/<br>/g; | |
187 | ||
188 | &Header::openbox('100%', 'left', $Lang::tr{'messages'}); | |
189 | print "$message\n"; | |
190 | &Header::closebox(); | |
191 | } | |
192 | ||
193 | ############################################################################################################################ | |
194 | ########################################## Aktivieren von Checkboxen und Dropdowns ######################################### | |
195 | ||
196 | $selected{'ENCRYPTION'}{'optional'} = ''; | |
197 | $selected{'ENCRYPTION'}{'desired'} = ''; | |
198 | $selected{'ENCRYPTION'}{'required'} = ''; | |
199 | $selected{'ENCRYPTION'}{$sambasettings{'ENCRYPTION'}} = "selected='selected'"; | |
200 | ||
201 | if ( $sambasettings{'MAPTOGUEST'} eq "Never" ) { | |
202 | $sambasettings{'MAPTOGUEST'}="Bad User"; | |
203 | } | |
204 | $selected{'MAPTOGUEST'}{$sambasettings{'MAPTOGUEST'}} = "selected='selected'"; | |
205 | $selected{'SECURITY'}{$sambasettings{'SECURITY'}} = "selected='selected'"; | |
206 | ||
207 | ############################################################################################################################ | |
208 | ################################### Aufbau der HTML Seite fr globale Sambaeinstellungen ################################### | |
209 | ||
210 | &Header::openbox('100%', 'center', $Lang::tr{'samba'}); | |
211 | ||
212 | my %servicenames = ( | |
213 | "nmbd" => $Lang::tr{'netbios nameserver daemon'}, | |
214 | "smbd" => $Lang::tr{'smb daemon'}, | |
215 | "winbindd" => $Lang::tr{'winbind daemon'}, | |
216 | ); | |
217 | ||
218 | print <<END; | |
219 | <table class="tbl" width='100%' cellspacing='0'> | |
220 | <tr bgcolor='$color{'color20'}'> | |
221 | <td colspan='2' align='left'><b>$Lang::tr{'all services'}</b></td> | |
222 | </tr> | |
223 | END | |
224 | ||
225 | foreach my $service (sort keys %servicenames) { | |
226 | my $status = &isrunning($service); | |
227 | ||
228 | print <<END; | |
229 | <tr> | |
230 | <td align='left' width='40%'>$servicenames{$service}</td> | |
231 | $status | |
232 | </tr> | |
233 | END | |
234 | } | |
235 | ||
236 | print <<END | |
237 | </table> | |
238 | ||
239 | <br> | |
240 | ||
241 | <table width="100%"> | |
242 | <td width="33%" align="center"> | |
243 | <form method="POST" action="$ENV{'SCRIPT_NAME'}"> | |
244 | <input type="hidden" name="ACTION" value="smbstart"> | |
245 | <input type="submit" value="$Lang::tr{'enable'}"> | |
246 | </form> | |
247 | </td> | |
248 | ||
249 | <td width="33%" align="center"> | |
250 | <form method="POST" action="$ENV{'SCRIPT_NAME'}"> | |
251 | <input type="hidden" name="ACTION" value="smbstop"> | |
252 | <input type="submit" value="$Lang::tr{'disable'}"> | |
253 | </form> | |
254 | </td> | |
255 | ||
256 | <td width="33%" align="center"> | |
257 | <form method="POST" action="$ENV{'SCRIPT_NAME'}"> | |
258 | <input type="hidden" name="ACTION" value="smbrestart"> | |
259 | <input type="submit" value="$Lang::tr{'restart'}"> | |
260 | </form> | |
261 | </td> | |
262 | </table> | |
263 | ||
264 | <br> | |
265 | ||
266 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
267 | <table class="tbl" width='100%' cellspacing='0'> | |
268 | <tr bgcolor='$color{'color20'}'> | |
269 | <td colspan='2' align='left'><b>$Lang::tr{'basic options'}</b></td> | |
270 | </tr> | |
271 | <tr> | |
272 | <td align='left' width='40%'>$Lang::tr{'workgroup'}</td> | |
273 | <td align='left'> | |
274 | <input type='text' name='WORKGRP' value='$sambasettings{'WORKGRP'}' size="30" /> | |
275 | </td> | |
276 | </tr> | |
277 | <tr> | |
278 | <td align='left'><br /></td> | |
279 | <td></td> | |
280 | </tr> | |
281 | <tr bgcolor='$color{'color20'}'> | |
282 | <td colspan='2' align='left'><b>$Lang::tr{'security options'}</b></td> | |
283 | </tr> | |
284 | <tr> | |
285 | <td align='left' width='40%'>$Lang::tr{'security'}</td> | |
286 | <td align='left'> | |
287 | <select name='SECURITY' style="width: 165px"> | |
288 | <option value='user' $selected{'SECURITY'}{'user'}>User</option> | |
289 | <option value='ADS' $selected{'SECURITY'}{'ADS'}>ADS</option> | |
290 | <option value='server' $selected{'SECURITY'}{'server'}>Server</option> | |
291 | </select> | |
292 | </td> | |
293 | </tr> | |
294 | <tr> | |
295 | <td align='left' width='40%'>$Lang::tr{'encryption'}</td> | |
296 | <td align='left'> | |
297 | <select name='ENCRYPTION' style="width: 165px"> | |
298 | <option value='optional' $selected{'ENCRYPTION'}{'optional'}>$Lang::tr{'optional'}</option> | |
299 | <option value='desired' $selected{'ENCRYPTION'}{'desired'}>$Lang::tr{'desired'}</option> | |
300 | <option value='required' $selected{'ENCRYPTION'}{'required'}>$Lang::tr{'required'}</option> | |
301 | </select> | |
302 | </td> | |
303 | </tr> | |
304 | <tr> | |
305 | <td align='left' width='40%'>$Lang::tr{'map to guest'}</td> | |
306 | <td align='left'> | |
307 | <select name='MAPTOGUEST' style="width: 165px"> | |
308 | <option value='Bad User' $selected{'MAPTOGUEST'}{'Bad User'}>Bad User</option> | |
309 | <option value='Bad Password' $selected{'MAPTOGUEST'}{'Bad Password'}>Bad Password</option> | |
310 | </select> | |
311 | </td> | |
312 | </tr> | |
313 | <tr> | |
314 | <td align='left'><br /></td> | |
315 | <td></td> | |
316 | </tr> | |
317 | <tr bgcolor='$color{'color20'}'> | |
318 | <td colspan='2' align='left'><b>$Lang::tr{'network options'}</b></td> | |
319 | </tr> | |
320 | <tr> | |
321 | <td align='left' width='40%'>$Lang::tr{'remote announce'}</td> | |
322 | <td align='left'> | |
323 | <input type='text' name='REMOTEANNOUNCE' value='$sambasettings{'REMOTEANNOUNCE'}' size="30" /> | |
324 | </td> | |
325 | </tr> | |
326 | <tr> | |
327 | <td align='left' width='40%'>$Lang::tr{'remote browse sync'}</td> | |
328 | <td align='left'> | |
329 | <input type='text' name='REMOTESYNC' value='$sambasettings{'REMOTESYNC'}' size="30" /> | |
330 | </td> | |
331 | </tr> | |
332 | </table> | |
333 | ||
334 | <br> | |
335 | ||
336 | <table width='100%' cellspacing='0'> | |
337 | <tr> | |
338 | <td align='center'> | |
339 | <form method='POST' action='$ENV{'SCRIPT_NAME'}'> | |
340 | <input type='hidden' name='ACTION' value="$Lang::tr{'save'}"> | |
341 | <input type='submit' value="$Lang::tr{'save'}"> | |
342 | </form> | |
343 | </td> | |
344 | </tr> | |
345 | </table> | |
346 | END | |
347 | ; | |
348 | ||
349 | &Header::closebox(); | |
350 | ||
351 | ############################################################################################################################ | |
352 | ########################################## Benutzerverwaltung fr Usersecurity ############################################# | |
353 | ||
354 | if ($sambasettings{'SECURITY'} eq 'user') | |
355 | { | |
356 | &Header::openbox('100%', 'center', $Lang::tr{'user management'}); | |
357 | print <<END | |
358 | <br /> | |
359 | <table class="tbl" width='100%' cellspacing='0'> | |
360 | <tr><td colspan='6' align='left'></td></tr> | |
361 | <tr><td bgcolor='$color{'color20'}' colspan='7' align='left'><b>$Lang::tr{'accounting'}</b></td></tr> | |
362 | <tr><td align='left'><u>$Lang::tr{'username'}</u></td><td align='left'><u>$Lang::tr{'password'}</u></td> | |
363 | END | |
364 | ; | |
365 | ||
366 | print "<td></td>"; | |
367 | print "<td align='left'><u>$Lang::tr{'status'}</u></td><td colspan='3' width='5%' align='center'><u>$Lang::tr{'options'}</u></td></tr>"; | |
368 | system('/usr/local/bin/sambactrl readsmbpasswd'); | |
369 | open(FILE, "<${General::swroot}/samba/private/smbpasswd") or die "Can't read user file: $!"; | |
370 | @user = <FILE>; | |
371 | close(FILE); | |
372 | system('/usr/local/bin/sambactrl locksmbpasswd'); | |
373 | ||
374 | my $lines = 0; | |
375 | ||
376 | foreach $userentry (sort @user) | |
377 | { | |
378 | @userline = split( /\:/, $userentry ); | |
379 | if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>";} else {print "<tr bgcolor='$color{'color22'}'>";} | |
380 | print "<td align='left'>$userline[0]</td><td align='left'>"; | |
381 | if ($userline[4] =~ /N/) | |
382 | { | |
383 | print "$Lang::tr{'not set'}</td><td align='left'>"; | |
384 | } | |
385 | else | |
386 | { | |
387 | print "$Lang::tr{'set'}</td><td align='left'>"; | |
388 | } | |
389 | ||
390 | print "</td><td align='left'>"; | |
391 | ||
392 | if ($userline[4] =~ /D/) | |
393 | { | |
394 | print <<END | |
395 | $Lang::tr{'inactive'}</td> | |
396 | <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> | |
397 | <input type='hidden' name='NAME' value='$userline[0]' /> | |
398 | <input type='hidden' name='ACTION' value='smbuserenable' /> | |
399 | <input type='image' alt='$Lang::tr{'activate'}' title='$Lang::tr{'activate'}' src='/images/off.gif' /> | |
400 | </form></td> | |
401 | END | |
402 | ; | |
403 | } | |
404 | else | |
405 | { | |
406 | print <<END | |
407 | $Lang::tr{'active'}</td> | |
408 | <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> | |
409 | <input type='hidden' name='NAME' value='$userline[0]' /> | |
410 | <input type='hidden' name='ACTION' value='smbuserdisable' /> | |
411 | <input type='image' alt='$Lang::tr{'deactivate'}' title='$Lang::tr{'deactivate'}' src='/images/on.gif' /> | |
412 | </form></td> | |
413 | END | |
414 | ; | |
415 | } | |
416 | ||
417 | if ($userline[0] =~ /\$/) | |
418 | { | |
419 | print "<td></td>"; | |
420 | } | |
421 | else | |
422 | { | |
423 | print <<END | |
424 | <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> | |
425 | <input type='hidden' name='NAME' value='$userline[0]' /> | |
426 | <input type='hidden' name='ACTION' value='userchangepw' /> | |
427 | <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' /> | |
428 | </form></td> | |
429 | END | |
430 | ; | |
431 | } | |
432 | ||
433 | print <<END | |
434 | <td><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> | |
435 | <input type='hidden' name='NAME' value='$userline[0]' /> | |
436 | <input type='hidden' name='ACTION' value='userdelete' /> | |
437 | <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-option-remove.png' /> | |
438 | </form></td></tr> | |
439 | END | |
440 | ; | |
441 | $lines++; | |
442 | } | |
443 | print <<END | |
444 | </table> | |
445 | <br /> | |
446 | <table width='10%' cellspacing='0'> | |
447 | <tr><td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> | |
448 | <input type='hidden' name='ACTION' value='useradd' /> | |
449 | <input type='image' alt='$Lang::tr{'add user'}' title='$Lang::tr{'add user'}' src='/images/user-option-add.png' /></form></td> | |
450 | </tr> | |
451 | </table> | |
452 | END | |
453 | ; | |
454 | ||
455 | if ($sambasettings{'ACTION'} eq 'userchangepw') | |
456 | { | |
457 | my $username = "$sambasettings{'NAME'}"; | |
458 | my $password = 'samba'; | |
459 | print <<END | |
460 | <br /> | |
461 | <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> | |
462 | <table width='100%' cellspacing='0'> | |
463 | <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'change passwords'}</b></td></tr> | |
464 | <tr><td align='left'>$Lang::tr{'username'}</td><td><input type='text' name='USERNAME' value='$username' size='30' readonly='readonly' /></td></tr> | |
465 | <tr><td align='left'>$Lang::tr{'password'}</td><td><input type='password' name='PASSWORD' value='$password' size='30' /></td></tr> | |
466 | <tr><td colspan='2' align='center'><input type='hidden' name='ACTION' value='smbchangepw' /> | |
467 | <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></td></tr> | |
468 | </table> | |
469 | </form> | |
470 | END | |
471 | ; | |
472 | } | |
473 | ||
474 | if ($sambasettings{'ACTION'} eq 'useradd') | |
475 | { | |
476 | my $username = "user"; | |
477 | my $password = "samba"; | |
478 | chomp $username; | |
479 | $username=~s/\s//g; | |
480 | chomp $password; | |
481 | $password=~s/\s//g; | |
482 | print <<END | |
483 | <br /> | |
484 | <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> | |
485 | <table width='100%' cellspacing='0'> | |
486 | <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'add user'}</b></td></tr> | |
487 | <tr><td align='left'>$Lang::tr{'username'}</td><td><input type='text' name='USERNAME' value='$username' size='30' /></td></tr> | |
488 | <tr><td align='left'>$Lang::tr{'password'}</td><td><input type='password' name='PASSWORD' value='$password' size='30' /></td></tr> | |
489 | <tr><td align='left'>$Lang::tr{'unix group'}</td><td><input type='text' name='GROUP' value='sambauser' size='30' /></td></tr> | |
490 | <tr><td align='left'>$Lang::tr{'unix shell'}</td><td><input type='text' name='SHELL' value='/bin/false' size='30' /></td></tr> | |
491 | <tr><td colspan='2' align='center'><input type='hidden' name='ACTION' value='smbuseradd' /> | |
492 | <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></td></tr> | |
493 | </table> | |
494 | </form> | |
495 | END | |
496 | ; | |
497 | } | |
498 | ||
499 | if ($sambasettings{'ACTION'} eq 'pcadd') | |
500 | { | |
501 | my $pcname = "client\$"; | |
502 | chomp $pcname; | |
503 | $pcname=~s/\s//g; | |
504 | print <<END | |
505 | <br /> | |
506 | <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> | |
507 | <table width='100%' cellspacing='0'> | |
508 | <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'pc add'}</b></td></tr> | |
509 | <tr><td align='left'>$Lang::tr{'client'}</td><td><input type='text' name='PCNAME' value='$pcname' size='30' /></td></tr> | |
510 | <tr><td align='left'>$Lang::tr{'unix group'}</td><td><input type='text' name='GROUP' value='sambawks' size='30' /></td></tr> | |
511 | <tr><td align='left'>$Lang::tr{'unix shell'}</td><td><input type='text' name='SHELL' value='/bin/false' size='30' /></td></tr> | |
512 | <tr><td colspan='2' align='center'><input type='hidden' name='ACTION' value='smbpcadd' /> | |
513 | <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></td></tr> | |
514 | </table> | |
515 | </form> | |
516 | END | |
517 | ; | |
518 | } | |
519 | ||
520 | &Header::closebox(); | |
521 | } | |
522 | ||
523 | if ($sambasettings{'SECURITY'} eq "ADS") { | |
524 | &Header::openbox('100%', 'center', $Lang::tr{'samba join a domain'}); | |
525 | ||
526 | my $AD_DOMAINNAME = uc($mainsettings{'DOMAINNAME'}); | |
527 | ||
528 | print <<END; | |
529 | <form method="POST" action="$ENV{'SCRIPT_NAME'}"> | |
530 | <input type="hidden" name="ACTION" value="join"> | |
531 | ||
532 | <table class="tbl" width="100%"> | |
533 | <tbody> | |
534 | <tr> | |
535 | <td width="40%"> | |
536 | $Lang::tr{'domain'} | |
537 | </td> | |
538 | <td> | |
539 | $AD_DOMAINNAME | |
540 | </td> | |
541 | </tr> | |
542 | <tr> | |
543 | <td width="40%"> | |
544 | $Lang::tr{'administrator username'} | |
545 | </td> | |
546 | <td> | |
547 | <input type="text" name="USERNAME" size="30"> | |
548 | </td> | |
549 | </tr> | |
550 | <tr> | |
551 | <td width="40%"> | |
552 | $Lang::tr{'administrator password'} | |
553 | </td> | |
554 | <td> | |
555 | <input type="password" name="PASSWORD" size="30"> | |
556 | </td> | |
557 | </tr> | |
558 | <tr> | |
559 | <td></td> | |
560 | <td> | |
561 | <input type="submit" value="$Lang::tr{'samba join domain'}"> | |
562 | </td> | |
563 | </tr> | |
564 | </tbody> | |
565 | </table> | |
566 | </form> | |
567 | END | |
568 | ||
569 | &Header::closebox(); | |
570 | } | |
571 | ||
572 | ############################################################################################################################ | |
573 | ############################################### Verwalten von Freigaben #################################################### | |
574 | ||
575 | &Header::openbox('100%', 'center', $Lang::tr{'shares'}); | |
576 | ||
577 | my %shares = config("${General::swroot}/samba/shares"); | |
578 | ||
579 | print <<END; | |
580 | <table class="tbl" width='100%' cellspacing='0'> | |
581 | <tr> | |
582 | <th align='left'>$Lang::tr{'sharename'}</th> | |
583 | <th colspan='2' width="5%" align='center'></th> | |
584 | </tr> | |
585 | END | |
586 | ||
587 | my @shares = keys(%shares); | |
588 | my $lines = 0; | |
589 | my $col=""; | |
590 | foreach my $shareentry (sort @shares) { | |
591 | chomp $shareentry; | |
592 | ||
593 | if ($lines % 2) { | |
594 | $col = "bgcolor='$color{'color20'}'"; | |
595 | } else { | |
596 | $col = "bgcolor='$color{'color22'}'"; | |
597 | } | |
598 | ||
599 | print <<END; | |
600 | <tr> | |
601 | <td align='left' $col>$shareentry</td> | |
602 | <td $col> | |
603 | <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'> | |
604 | <input type='hidden' name='NAME' value='$shareentry' /> | |
605 | <input type='hidden' name='ACTION' value='sharechange' /> | |
606 | <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' /> | |
607 | </form> | |
608 | </td> | |
609 | <td $col> | |
610 | <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'> | |
611 | <input type='hidden' name='NAME' value='$shareentry' /> | |
612 | <input type='hidden' name='ACTION' value='smbsharedel' /> | |
613 | <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' /> | |
614 | </form> | |
615 | </td> | |
616 | </tr> | |
617 | END | |
618 | ; | |
619 | $lines++; | |
620 | } | |
621 | ||
622 | print <<END; | |
623 | </table> | |
624 | ||
625 | <br> | |
626 | ||
627 | <table width='100%' cellspacing='0'> | |
628 | <tr> | |
629 | <td align='center'> | |
630 | <form method='POST' action='$ENV{'SCRIPT_NAME'}'> | |
631 | <input type='hidden' name='ACTION' value='shareadd'> | |
632 | <input type='submit' value='$Lang::tr{'add share'}'> | |
633 | </form> | |
634 | </td> | |
635 | </tr> | |
636 | </table> | |
637 | END | |
638 | ||
639 | if ($sambasettings{'ACTION'} eq 'shareadd') { | |
640 | print <<END; | |
641 | <br /> | |
642 | ||
643 | <form method='POST' action='$ENV{'SCRIPT_NAME'}'> | |
644 | <table width='100%' cellspacing='0'> | |
645 | <tr bgcolor='$color{'color20'}'> | |
646 | <td align='left'><b>$Lang::tr{'add share'}</b></td> | |
647 | </tr> | |
648 | <tr> | |
649 | <td align='center'> | |
650 | <textarea name="SHAREOPTION" cols="121" rows="15">$defaultoption</textarea> | |
651 | </td> | |
652 | </tr> | |
653 | <tr> | |
654 | <td align='center'> | |
655 | <input type='hidden' name='ACTION' value='smbshareadd'> | |
656 | <input type='submit' value='$Lang::tr{'save'}'> | |
657 | </td> | |
658 | </tr> | |
659 | </table> | |
660 | </form> | |
661 | END | |
662 | } | |
663 | ||
664 | if ($sambasettings{'ACTION'} eq 'sharechange') { | |
665 | my $shareoption = $shares{$sambasettings{'NAME'}}; | |
666 | ||
667 | print <<END; | |
668 | <br /> | |
669 | ||
670 | <form method='POST' action='$ENV{'SCRIPT_NAME'}'> | |
671 | <input type='hidden' name='NAME' value='$sambasettings{'NAME'}'> | |
672 | ||
673 | <table width='100%' cellspacing='0'> | |
674 | <tr bgcolor='$color{'color20'}'> | |
675 | <td align='left'><b>$Lang::tr{'edit share'}</b></td> | |
676 | </tr> | |
677 | <tr> | |
678 | <td align='center'> | |
679 | <textarea name="SHAREOPTION" cols="121" rows="15">$shareoption</textarea> | |
680 | </td> | |
681 | </tr> | |
682 | <tr> | |
683 | <td align='center'> | |
684 | <input type='hidden' name='ACTION' value='smbsharechange'> | |
685 | <input type='submit' value='$Lang::tr{'save'}'> | |
686 | </td> | |
687 | </tr> | |
688 | </table> | |
689 | </form> | |
690 | END | |
691 | } | |
692 | ||
693 | if ($sambasettings{'ACTION'} eq 'smbshareadd') | |
694 | { | |
695 | $shares{'xvx'}= "$sambasettings{'SHAREOPTION'}"; | |
696 | save("shares"); | |
697 | my $shares = config("${General::swroot}/samba/shares"); | |
698 | } | |
699 | if ($sambasettings{'ACTION'} eq 'smbsharedel') | |
700 | { | |
701 | delete $shares{$sambasettings{'NAME'}}; | |
702 | save("shares"); | |
703 | my %shares = config("${General::swroot}/samba/shares"); | |
704 | } | |
705 | if ($sambasettings{'ACTION'} eq 'smbsharechange') | |
706 | { | |
707 | $shares{$sambasettings{'NAME'}} = $sambasettings{'SHAREOPTION'}; | |
708 | save("shares"); | |
709 | my %shares = config("${General::swroot}/samba/shares"); | |
710 | } | |
711 | ||
712 | &Header::closebox(); | |
713 | ||
714 | ############################################################################################################################ | |
715 | ############################################### Anzeige des Sambastatus #################################################### | |
716 | ||
717 | &Header::openbox('100%', 'left', $Lang::tr{'status'}); | |
718 | ||
719 | my $status = qx(/usr/local/bin/sambactrl smbstatus); | |
720 | $status = &Header::cleanhtml($status); | |
721 | ||
722 | print <<END; | |
723 | <small> | |
724 | <pre>$status</pre> | |
725 | </small> | |
726 | END | |
727 | ||
728 | &Header::closebox(); | |
729 | ||
730 | &Header::closebigbox(); | |
731 | &Header::closepage(); | |
732 | ||
733 | ############################################################################################################################ | |
734 | ############################################ Subfunktion fr Sambadienste ################################################### | |
735 | ||
736 | sub config | |
737 | { | |
738 | my $file = shift; | |
739 | my @allarray = `grep -n '^\\[' $file`; | |
740 | my @linesarray = (); | |
741 | my @namearray = (); | |
742 | my %hash = (); | |
743 | my $options = (); | |
744 | my $EOF = qx(cat $file | wc -l); | |
745 | foreach my $allarrayentry (@allarray) | |
746 | { | |
747 | my @allarrayline = split( /\:/, $allarrayentry ); | |
748 | push(@linesarray,$allarrayline[0]);$allarrayline[1]=~s/\[//g;$allarrayline[1]=~s/\]//g;push(@namearray,$allarrayline[1]); | |
749 | } | |
750 | for(my $i = 0; $i <= $#namearray; $i++) | |
751 | { | |
752 | chomp $namearray[$i]; | |
753 | $namearray[$i]=~s/\[//g;$namearray[$i]=~s/\]//g; | |
754 | if ( $i eq $#namearray ) | |
755 | { | |
756 | my $lineend = $EOF-$linesarray[$i]+1; | |
757 | $options=qx(tail -$lineend $file); | |
758 | } | |
759 | else | |
760 | { | |
761 | my $linestart = $EOF-$linesarray[$i]+1; | |
762 | my $lineend = $linesarray[$i+1]-$linesarray[$i]; | |
763 | $options=qx(tail -$linestart $file | head -$lineend); | |
764 | } | |
765 | $hash{$namearray[$i]} = "$options"; | |
766 | #print"<pre>$namearray[$i]\n$options\n</pre>"; # enable only for debuging | |
767 | } | |
768 | return(%hash); | |
769 | } | |
770 | ||
771 | sub save | |
772 | { | |
773 | my $smb = shift; | |
774 | open (FILE, ">${General::swroot}/samba/$smb") or die "Can't $smb settings $!"; | |
775 | flock (FILE, 2); | |
776 | ||
777 | if ( $smb eq 'shares') | |
778 | {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";} } | |
779 | ||
780 | close FILE; | |
781 | ||
782 | system("/usr/local/bin/sambactrl smbsafeconf"); | |
783 | system("/usr/local/bin/sambactrl smbreload"); | |
784 | } | |
785 | ||
786 | sub isrunning | |
787 | { | |
788 | my $cmd = $_[0]; | |
789 | my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>"; | |
790 | my $pid = ''; | |
791 | my $testcmd = ''; | |
792 | my $exename; | |
793 | ||
794 | $cmd =~ /(^[a-z]+)/; | |
795 | $exename = $1; | |
796 | ||
797 | if (open(FILE, "/var/run/${cmd}.pid")) | |
798 | { | |
799 | $pid = <FILE>; chomp $pid; | |
800 | close FILE; | |
801 | if (open(FILE, "/proc/${pid}/status")) | |
802 | { | |
803 | while (<FILE>) | |
804 | { | |
805 | if (/^Name:\W+(.*)/) | |
806 | { | |
807 | $testcmd = $1; | |
808 | } | |
809 | } | |
810 | close FILE; | |
811 | if ($testcmd =~ /$exename/) | |
812 | { | |
813 | $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>"; | |
814 | } | |
815 | } | |
816 | } | |
817 | return $status; | |
818 | } | |
819 | ||
820 | sub joindomain { | |
821 | my $username = shift; | |
822 | my $password = shift; | |
823 | ||
824 | my @options = ("/usr/local/bin/sambactrl", "join", $username, $password); | |
825 | my $output = qx(@options); | |
826 | ||
827 | return $output; | |
828 | } |