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