]>
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 | ||
98e11f47 MT |
611 | print <<END; |
612 | <table class="tbl" width='95%' cellspacing='0'> | |
613 | <tr> | |
614 | <th align='left'>$Lang::tr{'sharename'}</th> | |
615 | <th colspan='2' width="5%" align='center'></th> | |
616 | </tr> | |
1ee8bf5d | 617 | END |
14cc7eac | 618 | |
98e11f47 | 619 | my @shares = keys(%shares); |
a28fdc01 | 620 | my $lines = 0; |
961f3dbc | 621 | my $col=""; |
98e11f47 | 622 | foreach my $shareentry (sort @shares) { |
c41c2eb4 | 623 | chomp $shareentry; |
98e11f47 | 624 | |
961f3dbc | 625 | if ($lines % 2) { |
98e11f47 | 626 | $col = "bgcolor='$color{'color20'}'"; |
961f3dbc | 627 | } else { |
98e11f47 | 628 | $col = "bgcolor='$color{'color22'}'"; |
32f77a0b CS |
629 | } |
630 | ||
98e11f47 MT |
631 | print <<END; |
632 | <tr> | |
633 | <td align='left' $col>$shareentry</td> | |
634 | <td $col> | |
635 | <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'> | |
636 | <input type='hidden' name='NAME' value='$shareentry' /> | |
637 | <input type='hidden' name='ACTION' value='sharechange' /> | |
638 | <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' /> | |
639 | </form> | |
640 | </td> | |
641 | <td $col> | |
642 | <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'> | |
643 | <input type='hidden' name='NAME' value='$shareentry' /> | |
644 | <input type='hidden' name='ACTION' value='smbsharedel' /> | |
645 | <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' /> | |
646 | </form> | |
647 | </td> | |
648 | </tr> | |
1ee8bf5d MT |
649 | END |
650 | ; | |
98e11f47 MT |
651 | $lines++; |
652 | } | |
32f77a0b | 653 | |
98e11f47 | 654 | print <<END; |
32f77a0b | 655 | </table> |
98e11f47 MT |
656 | |
657 | <br> | |
658 | ||
659 | <table width='100%' cellspacing='0'> | |
660 | <tr> | |
661 | <td align='center'> | |
662 | <form method='POST' action='$ENV{'SCRIPT_NAME'}'> | |
663 | <input type='hidden' name='ACTION' value='shareadd'> | |
664 | <input type='submit' value='$Lang::tr{'add share'}'> | |
665 | </form> | |
666 | </td> | |
667 | </tr> | |
32f77a0b | 668 | </table> |
5e773594 | 669 | END |
5e773594 | 670 | |
98e11f47 MT |
671 | if ($sambasettings{'ACTION'} eq 'shareadd') { |
672 | print <<END; | |
673 | <br /> | |
674 | ||
675 | <form method='POST' action='$ENV{'SCRIPT_NAME'}'> | |
676 | <table width='95%' cellspacing='0'> | |
677 | <tr bgcolor='$color{'color20'}'> | |
678 | <td align='left'><b>$Lang::tr{'add share'}</b></td> | |
679 | </tr> | |
680 | <tr> | |
681 | <td align='center'> | |
682 | <textarea name="SHAREOPTION" cols="121" rows="15">$defaultoption</textarea> | |
683 | </td> | |
684 | </tr> | |
685 | <tr> | |
686 | <td align='center'> | |
687 | <input type='hidden' name='ACTION' value='smbshareadd'> | |
688 | <input type='submit' value='$Lang::tr{'save'}'> | |
689 | </td> | |
690 | </tr> | |
691 | </table> | |
692 | </form> | |
693 | END | |
694 | } | |
695 | ||
696 | if ($sambasettings{'ACTION'} eq 'sharechange') { | |
c41c2eb4 | 697 | my $shareoption = $shares{$sambasettings{'NAME'}}; |
98e11f47 MT |
698 | |
699 | print <<END; | |
700 | <br /> | |
701 | ||
702 | <form method='POST' action='$ENV{'SCRIPT_NAME'}'> | |
703 | <input type='hidden' name='NAME' value='$sambasettings{'NAME'}'> | |
704 | ||
705 | <table width='95%' cellspacing='0'> | |
706 | <tr bgcolor='$color{'color20'}'> | |
707 | <td align='left'><b>$Lang::tr{'edit share'}</b></td> | |
708 | </tr> | |
709 | <tr> | |
710 | <td align='center'> | |
711 | <textarea name="SHAREOPTION" cols="121" rows="15">$shareoption</textarea> | |
712 | </td> | |
713 | </tr> | |
714 | <tr> | |
715 | <td align='center'> | |
716 | <input type='hidden' name='ACTION' value='smbsharechange'> | |
717 | <input type='submit' value='$Lang::tr{'save'}'> | |
718 | </td> | |
719 | </tr> | |
720 | </table> | |
721 | </form> | |
1ee8bf5d | 722 | END |
98e11f47 | 723 | } |
5e773594 | 724 | |
c41c2eb4 CS |
725 | if ($sambasettings{'ACTION'} eq 'smbshareadd') |
726 | { | |
727 | $shares{'xvx'}= "$sambasettings{'SHAREOPTION'}"; | |
728 | save("shares"); | |
729 | my $shares = config("${General::swroot}/samba/shares"); | |
730 | } | |
731 | if ($sambasettings{'ACTION'} eq 'smbsharedel') | |
732 | { | |
733 | delete $shares{$sambasettings{'NAME'}}; | |
734 | save("shares"); | |
735 | my %shares = config("${General::swroot}/samba/shares"); | |
736 | } | |
737 | if ($sambasettings{'ACTION'} eq 'smbsharechange') | |
738 | { | |
739 | $shares{$sambasettings{'NAME'}} = $sambasettings{'SHAREOPTION'}; | |
740 | save("shares"); | |
741 | my %shares = config("${General::swroot}/samba/shares"); | |
742 | } | |
743 | ||
744 | &Header::closebox(); | |
745 | ||
32f77a0b CS |
746 | ############################################################################################################################ |
747 | ############################################### Anzeige des Sambastatus #################################################### | |
748 | ||
749 | &Header::openbox('100%', 'center', 'Status'); | |
750 | ||
751 | print <<END | |
92004c61 | 752 | <br /> |
d83d30d6 | 753 | <table class="tbl" width='95%' cellspacing='0'> |
f2fdd0c1 | 754 | <tr><td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'samba status'}</b></td></tr> |
fb8e2c14 | 755 | <tr><td align='left'><small><pre>$Status</pre></small></td></tr> |
fa7be659 CS |
756 | </table> |
757 | END | |
758 | ; | |
759 | &Header::closebox(); | |
760 | ||
5e773594 MT |
761 | &Header::closebigbox(); |
762 | &Header::closepage(); | |
763 | ||
764 | ############################################################################################################################ | |
fa7be659 | 765 | ############################################ Subfunktion fr Sambadienste ################################################### |
5e773594 | 766 | |
c41c2eb4 CS |
767 | sub config |
768 | { | |
769 | my $file = shift; | |
770 | my @allarray = `grep -n '^\\[' $file`; | |
771 | my @linesarray = (); | |
772 | my @namearray = (); | |
773 | my %hash = (); | |
774 | my $options = (); | |
775 | my $EOF = qx(cat $file | wc -l); | |
776 | foreach my $allarrayentry (@allarray) | |
777 | { | |
778 | my @allarrayline = split( /\:/, $allarrayentry ); | |
779 | push(@linesarray,$allarrayline[0]);$allarrayline[1]=~s/\[//g;$allarrayline[1]=~s/\]//g;push(@namearray,$allarrayline[1]); | |
780 | } | |
781 | for(my $i = 0; $i <= $#namearray; $i++) | |
782 | { | |
783 | chomp $namearray[$i]; | |
784 | $namearray[$i]=~s/\[//g;$namearray[$i]=~s/\]//g; | |
785 | if ( $i eq $#namearray ) | |
786 | { | |
787 | my $lineend = $EOF-$linesarray[$i]+1; | |
788 | $options=qx(tail -$lineend $file); | |
789 | } | |
790 | else | |
791 | { | |
792 | my $linestart = $EOF-$linesarray[$i]+1; | |
793 | my $lineend = $linesarray[$i+1]-$linesarray[$i]; | |
794 | $options=qx(tail -$linestart $file | head -$lineend); | |
795 | } | |
796 | $hash{$namearray[$i]} = "$options"; | |
1e482cb6 | 797 | #print"<pre>$namearray[$i]\n$options\n</pre>"; # enable only for debuging |
c41c2eb4 CS |
798 | } |
799 | return(%hash); | |
800 | } | |
801 | ||
802 | sub save | |
803 | { | |
804 | my $smb = shift; | |
805 | open (FILE, ">${General::swroot}/samba/$smb") or die "Can't $smb settings $!"; | |
806 | flock (FILE, 2); | |
807 | ||
c41c2eb4 CS |
808 | if ( $smb eq 'shares') |
809 | {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";} } | |
810 | ||
811 | close FILE; | |
812 | ||
70000894 | 813 | system("/usr/local/bin/sambactrl smbsafeconf"); |
c41c2eb4 | 814 | system("/usr/local/bin/sambactrl smbreload"); |
a4a3e35c | 815 | } |
c41c2eb4 | 816 | |
5e773594 | 817 | sub isrunning |
32f77a0b CS |
818 | { |
819 | my $cmd = $_[0]; | |
820 | my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>"; | |
821 | my $pid = ''; | |
822 | my $testcmd = ''; | |
823 | my $exename; | |
824 | ||
825 | $cmd =~ /(^[a-z]+)/; | |
826 | $exename = $1; | |
827 | ||
828 | if (open(FILE, "/var/run/${cmd}.pid")) | |
829 | { | |
830 | $pid = <FILE>; chomp $pid; | |
831 | close FILE; | |
832 | if (open(FILE, "/proc/${pid}/status")) | |
833 | { | |
834 | while (<FILE>) | |
835 | { | |
836 | if (/^Name:\W+(.*)/) | |
837 | { | |
838 | $testcmd = $1; | |
839 | } | |
840 | } | |
841 | close FILE; | |
842 | if ($testcmd =~ /$exename/) | |
843 | { | |
844 | $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>"; | |
845 | } | |
846 | } | |
847 | } | |
848 | return $status; | |
c41c2eb4 | 849 | } |
0ffbb688 MT |
850 | |
851 | sub joindomain { | |
852 | my $username = shift; | |
853 | my $password = shift; | |
854 | ||
855 | my @options = ("/usr/local/bin/sambactrl", "join", $username, $password); | |
856 | my $output = qx(@options); | |
857 | ||
858 | return $output; | |
859 | } |