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