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