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