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