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