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