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