]>
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 |
d3bea043 | 390 | <a name="$Lang::tr{'accounting'}"></a> |
92004c61 | 391 | <br /> |
d83d30d6 | 392 | <table class="tbl" width='95%' cellspacing='0'> |
32f77a0b | 393 | <tr><td colspan='6' align='left'></td></tr> |
f2fdd0c1 | 394 | <tr><td bgcolor='$color{'color20'}' colspan='7' align='left'><b>$Lang::tr{'accounting'}</b></td></tr> |
c9e1c143 | 395 | <tr><td align='left'><u>$Lang::tr{'username'}</u></td><td align='left'><u>$Lang::tr{'password'}</u></td> |
32f77a0b CS |
396 | END |
397 | ; | |
5e773594 | 398 | |
70000894 | 399 | print "<td></td>"; |
92004c61 | 400 | 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 | 401 | system('/usr/local/bin/sambactrl readsmbpasswd'); |
c41c2eb4 | 402 | open(FILE, "<${General::swroot}/samba/private/smbpasswd") or die "Can't read user file: $!"; |
32f77a0b CS |
403 | @user = <FILE>; |
404 | close(FILE); | |
405 | system('/usr/local/bin/sambactrl locksmbpasswd'); | |
a28fdc01 CS |
406 | |
407 | my $lines = 0; | |
408 | ||
32f77a0b CS |
409 | foreach $userentry (sort @user) |
410 | { | |
411 | @userline = split( /\:/, $userentry ); | |
a28fdc01 CS |
412 | if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>";} else {print "<tr bgcolor='$color{'color22'}'>";} |
413 | print "<td align='left'>$userline[0]</td><td align='left'>"; | |
32f77a0b CS |
414 | if ($userline[4] =~ /N/) |
415 | { | |
c9e1c143 | 416 | print "$Lang::tr{'not set'}</td><td align='left'>"; |
32f77a0b CS |
417 | } |
418 | else | |
419 | { | |
c9e1c143 | 420 | print "$Lang::tr{'set'}</td><td align='left'>"; |
32f77a0b CS |
421 | } |
422 | ||
70000894 | 423 | print "</td><td align='left'>"; |
32f77a0b CS |
424 | |
425 | if ($userline[4] =~ /D/) | |
426 | { | |
427 | print <<END | |
92004c61 | 428 | $Lang::tr{'inactive'}</td> |
19f5a6cc | 429 | <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> |
32f77a0b CS |
430 | <input type='hidden' name='NAME' value='$userline[0]' /> |
431 | <input type='hidden' name='ACTION' value='smbuserenable' /> | |
25943d3b | 432 | <input type='image' alt='$Lang::tr{'activate'}' title='$Lang::tr{'activate'}' src='/images/off.gif' /> |
32f77a0b CS |
433 | </form></td> |
434 | END | |
435 | ; | |
436 | } | |
437 | else | |
438 | { | |
439 | print <<END | |
92004c61 | 440 | $Lang::tr{'active'}</td> |
19f5a6cc | 441 | <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> |
32f77a0b CS |
442 | <input type='hidden' name='NAME' value='$userline[0]' /> |
443 | <input type='hidden' name='ACTION' value='smbuserdisable' /> | |
25943d3b | 444 | <input type='image' alt='$Lang::tr{'deactivate'}' title='$Lang::tr{'deactivate'}' src='/images/on.gif' /> |
32f77a0b CS |
445 | </form></td> |
446 | END | |
447 | ; | |
448 | } | |
449 | ||
450 | if ($userline[0] =~ /\$/) | |
451 | { | |
452 | print "<td></td>"; | |
453 | } | |
454 | else | |
455 | { | |
456 | print <<END | |
19f5a6cc | 457 | <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> |
32f77a0b CS |
458 | <input type='hidden' name='NAME' value='$userline[0]' /> |
459 | <input type='hidden' name='ACTION' value='userchangepw' /> | |
a08a5f33 | 460 | <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' /> |
32f77a0b CS |
461 | </form></td> |
462 | END | |
463 | ; | |
464 | } | |
465 | ||
70000894 MT |
466 | print <<END |
467 | <td><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> | |
468 | <input type='hidden' name='NAME' value='$userline[0]' /> | |
469 | <input type='hidden' name='ACTION' value='userdelete' /> | |
470 | <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-option-remove.png' /> | |
471 | </form></td></tr> | |
32f77a0b CS |
472 | END |
473 | ; | |
a28fdc01 | 474 | $lines++; |
32f77a0b CS |
475 | } |
476 | print <<END | |
477 | </table> | |
92004c61 | 478 | <br /> |
32f77a0b | 479 | <table width='10%' cellspacing='0'> |
19f5a6cc | 480 | <tr><td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> |
32f77a0b | 481 | <input type='hidden' name='ACTION' value='useradd' /> |
a08a5f33 | 482 | <input type='image' alt='$Lang::tr{'add user'}' title='$Lang::tr{'add user'}' src='/images/user-option-add.png' /></form></td> |
21110589 | 483 | </tr> |
32f77a0b CS |
484 | </table> |
485 | END | |
486 | ; | |
44254afd | 487 | |
32f77a0b CS |
488 | if ($sambasettings{'ACTION'} eq 'userchangepw') |
489 | { | |
490 | my $username = "$sambasettings{'NAME'}"; | |
491 | my $password = 'samba'; | |
492 | print <<END | |
92004c61 | 493 | <br /> |
19f5a6cc | 494 | <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> |
32f77a0b | 495 | <table width='95%' cellspacing='0'> |
f2fdd0c1 | 496 | <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'change passwords'}</b></td></tr> |
153cf640 | 497 | <tr><td align='left'>$Lang::tr{'username'}</td><td><input type='text' name='USERNAME' value='$username' size='30' readonly='readonly' /></td></tr> |
c9e1c143 | 498 | <tr><td align='left'>$Lang::tr{'password'}</td><td><input type='password' name='PASSWORD' value='$password' size='30' /></td></tr> |
32f77a0b | 499 | <tr><td colspan='2' align='center'><input type='hidden' name='ACTION' value='smbchangepw' /> |
f8aa0679 | 500 | <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></td></tr> |
32f77a0b | 501 | </table> |
94819213 | 502 | </form> |
1ee8bf5d MT |
503 | END |
504 | ; | |
32f77a0b CS |
505 | } |
506 | ||
507 | if ($sambasettings{'ACTION'} eq 'useradd') | |
508 | { | |
509 | my $username = "user"; | |
510 | my $password = "samba"; | |
511 | chomp $username; | |
512 | $username=~s/\s//g; | |
513 | chomp $password; | |
514 | $password=~s/\s//g; | |
515 | print <<END | |
92004c61 | 516 | <br /> |
19f5a6cc | 517 | <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> |
32f77a0b | 518 | <table width='95%' cellspacing='0'> |
f2fdd0c1 | 519 | <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'add user'}</b></td></tr> |
c9e1c143 CS |
520 | <tr><td align='left'>$Lang::tr{'username'}</td><td><input type='text' name='USERNAME' value='$username' size='30' /></td></tr> |
521 | <tr><td align='left'>$Lang::tr{'password'}</td><td><input type='password' name='PASSWORD' value='$password' size='30' /></td></tr> | |
522 | <tr><td align='left'>$Lang::tr{'unix group'}</td><td><input type='text' name='GROUP' value='sambauser' size='30' /></td></tr> | |
523 | <tr><td align='left'>$Lang::tr{'unix shell'}</td><td><input type='text' name='SHELL' value='/bin/false' size='30' /></td></tr> | |
32f77a0b | 524 | <tr><td colspan='2' align='center'><input type='hidden' name='ACTION' value='smbuseradd' /> |
f8aa0679 | 525 | <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></td></tr> |
32f77a0b | 526 | </table> |
94819213 | 527 | </form> |
32f77a0b CS |
528 | END |
529 | ; | |
530 | } | |
531 | ||
532 | if ($sambasettings{'ACTION'} eq 'pcadd') | |
533 | { | |
534 | my $pcname = "client\$"; | |
535 | chomp $pcname; | |
536 | $pcname=~s/\s//g; | |
537 | print <<END | |
92004c61 | 538 | <br /> |
19f5a6cc | 539 | <form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'accounting'}'> |
32f77a0b | 540 | <table width='95%' cellspacing='0'> |
f2fdd0c1 | 541 | <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'pc add'}</b></td></tr> |
c9e1c143 CS |
542 | <tr><td align='left'>$Lang::tr{'client'}</td><td><input type='text' name='PCNAME' value='$pcname' size='30' /></td></tr> |
543 | <tr><td align='left'>$Lang::tr{'unix group'}</td><td><input type='text' name='GROUP' value='sambawks' size='30' /></td></tr> | |
544 | <tr><td align='left'>$Lang::tr{'unix shell'}</td><td><input type='text' name='SHELL' value='/bin/false' size='30' /></td></tr> | |
32f77a0b | 545 | <tr><td colspan='2' align='center'><input type='hidden' name='ACTION' value='smbpcadd' /> |
f8aa0679 | 546 | <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></td></tr> |
32f77a0b | 547 | </table> |
94819213 | 548 | </form> |
32f77a0b CS |
549 | END |
550 | ; | |
551 | } | |
97de2cae MT |
552 | |
553 | &Header::closebox(); | |
1ee8bf5d | 554 | } |
14cc7eac | 555 | |
0ffbb688 MT |
556 | if ($sambasettings{'SECURITY'} eq "ADS") { |
557 | &Header::openbox('100%', 'center', $Lang::tr{'samba join a domain'}); | |
558 | ||
559 | my $AD_DOMAINNAME = uc($mainsettings{'DOMAINNAME'}); | |
560 | ||
561 | print <<END; | |
562 | <form method="POST" action="$ENV{'SCRIPT_NAME'}"> | |
563 | <input type="hidden" name="ACTION" value="join"> | |
564 | ||
d83d30d6 | 565 | <table class="tbl" width="95%"> |
0ffbb688 MT |
566 | <tbody> |
567 | <tr> | |
568 | <td width="40%"> | |
569 | $Lang::tr{'domain'} | |
570 | </td> | |
571 | <td> | |
572 | $AD_DOMAINNAME | |
573 | </td> | |
574 | </tr> | |
575 | <tr> | |
576 | <td width="40%"> | |
577 | $Lang::tr{'administrator username'} | |
578 | </td> | |
579 | <td> | |
580 | <input type="text" name="USERNAME" size="30"> | |
581 | </td> | |
582 | </tr> | |
583 | <tr> | |
584 | <td width="40%"> | |
585 | $Lang::tr{'administrator password'} | |
586 | </td> | |
587 | <td> | |
588 | <input type="password" name="PASSWORD" size="30"> | |
589 | </td> | |
590 | </tr> | |
591 | <tr> | |
592 | <td></td> | |
593 | <td> | |
594 | <input type="submit" value="$Lang::tr{'samba join domain'}"> | |
595 | </td> | |
596 | </tr> | |
597 | </tbody> | |
598 | </table> | |
599 | </form> | |
600 | END | |
601 | ||
602 | &Header::closebox(); | |
603 | } | |
604 | ||
14cc7eac MT |
605 | ############################################################################################################################ |
606 | ############################################### Verwalten von Freigaben #################################################### | |
fa7be659 | 607 | |
c9e1c143 | 608 | &Header::openbox('100%', 'center', $Lang::tr{'shares'}); |
97de2cae | 609 | |
c41c2eb4 CS |
610 | my %shares = config("${General::swroot}/samba/shares"); |
611 | ||
612 | ||
1ee8bf5d | 613 | print <<END |
d3bea043 | 614 | <a name="$Lang::tr{'manage shares'}"></a> |
92004c61 | 615 | <br /> |
d83d30d6 | 616 | <table class="tbl" width='95%' cellspacing='0' class='tbl'> |
961f3dbc AM |
617 | <tr><th bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'manage shares'}</b></th></tr> |
618 | <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 |
619 | END |
620 | ; | |
14cc7eac | 621 | |
c41c2eb4 | 622 | my @Shares = keys(%shares); |
a28fdc01 | 623 | my $lines = 0; |
961f3dbc | 624 | my $col=""; |
c41c2eb4 | 625 | foreach my $shareentry (sort @Shares) |
32f77a0b | 626 | { |
c41c2eb4 | 627 | chomp $shareentry; |
961f3dbc AM |
628 | if ($lines % 2) { |
629 | print "<tr>"; | |
630 | $col="bgcolor='$color{'color20'}'"; | |
631 | } else { | |
632 | print "<tr>"; | |
633 | $col="bgcolor='$color{'color22'}'"; | |
634 | } | |
32f77a0b | 635 | print <<END |
961f3dbc AM |
636 | <td align='left' $col>$shareentry</td> |
637 | <td $col><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'> | |
32f77a0b CS |
638 | <input type='hidden' name='NAME' value='$shareentry' /> |
639 | <input type='hidden' name='ACTION' value='sharechange' /> | |
a08a5f33 | 640 | <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' /> |
32f77a0b | 641 | </form></td> |
961f3dbc | 642 | <td $col><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'> |
32f77a0b CS |
643 | <input type='hidden' name='NAME' value='$shareentry' /> |
644 | <input type='hidden' name='ACTION' value='smbsharedel' /> | |
a08a5f33 | 645 | <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' /> |
94819213 | 646 | </form></td></tr> |
32f77a0b CS |
647 | END |
648 | ; | |
a28fdc01 | 649 | $lines++; |
32f77a0b CS |
650 | } |
651 | ||
652 | print <<END | |
653 | </table> | |
92004c61 | 654 | <br /> |
32f77a0b | 655 | <table width='10%' cellspacing='0'> |
19f5a6cc | 656 | <tr><td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'manage shares'}'> |
94819213 | 657 | <input type='hidden' name='ACTION' value='shareadd' /> |
a08a5f33 | 658 | <input type='image' alt='$Lang::tr{'add share'}' title='$Lang::tr{'add share'}' src='/images/list-add.png' /> |
32f77a0b | 659 | </form></td> |
88932936 | 660 | </tr> |
32f77a0b | 661 | </table> |
1ee8bf5d MT |
662 | END |
663 | ; | |
32f77a0b | 664 | |
21110589 | 665 | if ($sambasettings{'ACTION'} eq 'shareadd') |
32f77a0b CS |
666 | { |
667 | print <<END | |
92004c61 | 668 | <br /> |
32f77a0b | 669 | <table width='95%' cellspacing='0'> |
f2fdd0c1 | 670 | <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'add share'}</b></td></tr> |
32f77a0b | 671 | <tr><td colspan='2' align='center'></td></tr> |
19f5a6cc | 672 | <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 | 673 | </table> |
92004c61 | 674 | <br /> |
32f77a0b | 675 | <table width='10%' cellspacing='0'> |
94819213 | 676 | <tr><td align='center'><input type='hidden' name='ACTION' value='smbshareadd' /> |
a08a5f33 | 677 | <input type='image' alt='$Lang::tr{'add share'}' title='$Lang::tr{'add share'}' src='/images/media-floppy.png' /></td></tr></form> |
32f77a0b | 678 | </table> |
5e773594 MT |
679 | END |
680 | ; | |
32f77a0b | 681 | } |
5e773594 | 682 | |
21110589 | 683 | if ($sambasettings{'ACTION'} eq 'sharechange') |
32f77a0b | 684 | { |
c41c2eb4 | 685 | my $shareoption = $shares{$sambasettings{'NAME'}}; |
32f77a0b | 686 | print <<END |
92004c61 | 687 | <br /> |
32f77a0b | 688 | <table width='95%' cellspacing='0'> |
f2fdd0c1 | 689 | <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'edit share'}</b></td></tr> |
32f77a0b | 690 | <tr><td colspan='2' align='center'></td></tr> |
19f5a6cc | 691 | <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 | 692 | </table> |
92004c61 | 693 | <br /> |
32f77a0b | 694 | <table width='10%' cellspacing='0'> |
94819213 | 695 | <tr><td align='center'><input type='hidden' name='NAME' value='$sambasettings{'NAME'}' /> |
a08a5f33 | 696 | <input type='image' alt='$Lang::tr{'change share'}' title='$Lang::tr{'change share'}' src='/images/media-floppy.png' /> |
fa7be659 | 697 | <input type='hidden' name='ACTION' value='smbsharechange' /></form></td></tr> |
32f77a0b | 698 | </table> |
1ee8bf5d MT |
699 | END |
700 | ; | |
32f77a0b | 701 | } |
5e773594 | 702 | |
c41c2eb4 CS |
703 | if ($sambasettings{'ACTION'} eq 'smbshareadd') |
704 | { | |
705 | $shares{'xvx'}= "$sambasettings{'SHAREOPTION'}"; | |
706 | save("shares"); | |
707 | my $shares = config("${General::swroot}/samba/shares"); | |
708 | } | |
709 | if ($sambasettings{'ACTION'} eq 'smbsharedel') | |
710 | { | |
711 | delete $shares{$sambasettings{'NAME'}}; | |
712 | save("shares"); | |
713 | my %shares = config("${General::swroot}/samba/shares"); | |
714 | } | |
715 | if ($sambasettings{'ACTION'} eq 'smbsharechange') | |
716 | { | |
717 | $shares{$sambasettings{'NAME'}} = $sambasettings{'SHAREOPTION'}; | |
718 | save("shares"); | |
719 | my %shares = config("${General::swroot}/samba/shares"); | |
720 | } | |
721 | ||
722 | &Header::closebox(); | |
723 | ||
32f77a0b CS |
724 | ############################################################################################################################ |
725 | ############################################### Anzeige des Sambastatus #################################################### | |
726 | ||
727 | &Header::openbox('100%', 'center', 'Status'); | |
728 | ||
729 | print <<END | |
92004c61 | 730 | <br /> |
d83d30d6 | 731 | <table class="tbl" width='95%' cellspacing='0'> |
f2fdd0c1 | 732 | <tr><td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'samba status'}</b></td></tr> |
fb8e2c14 | 733 | <tr><td align='left'><small><pre>$Status</pre></small></td></tr> |
fa7be659 CS |
734 | </table> |
735 | END | |
736 | ; | |
737 | &Header::closebox(); | |
738 | ||
5e773594 MT |
739 | &Header::closebigbox(); |
740 | &Header::closepage(); | |
741 | ||
742 | ############################################################################################################################ | |
fa7be659 | 743 | ############################################ Subfunktion fr Sambadienste ################################################### |
5e773594 | 744 | |
c41c2eb4 CS |
745 | sub config |
746 | { | |
747 | my $file = shift; | |
748 | my @allarray = `grep -n '^\\[' $file`; | |
749 | my @linesarray = (); | |
750 | my @namearray = (); | |
751 | my %hash = (); | |
752 | my $options = (); | |
753 | my $EOF = qx(cat $file | wc -l); | |
754 | foreach my $allarrayentry (@allarray) | |
755 | { | |
756 | my @allarrayline = split( /\:/, $allarrayentry ); | |
757 | push(@linesarray,$allarrayline[0]);$allarrayline[1]=~s/\[//g;$allarrayline[1]=~s/\]//g;push(@namearray,$allarrayline[1]); | |
758 | } | |
759 | for(my $i = 0; $i <= $#namearray; $i++) | |
760 | { | |
761 | chomp $namearray[$i]; | |
762 | $namearray[$i]=~s/\[//g;$namearray[$i]=~s/\]//g; | |
763 | if ( $i eq $#namearray ) | |
764 | { | |
765 | my $lineend = $EOF-$linesarray[$i]+1; | |
766 | $options=qx(tail -$lineend $file); | |
767 | } | |
768 | else | |
769 | { | |
770 | my $linestart = $EOF-$linesarray[$i]+1; | |
771 | my $lineend = $linesarray[$i+1]-$linesarray[$i]; | |
772 | $options=qx(tail -$linestart $file | head -$lineend); | |
773 | } | |
774 | $hash{$namearray[$i]} = "$options"; | |
1e482cb6 | 775 | #print"<pre>$namearray[$i]\n$options\n</pre>"; # enable only for debuging |
c41c2eb4 CS |
776 | } |
777 | return(%hash); | |
778 | } | |
779 | ||
780 | sub save | |
781 | { | |
782 | my $smb = shift; | |
783 | open (FILE, ">${General::swroot}/samba/$smb") or die "Can't $smb settings $!"; | |
784 | flock (FILE, 2); | |
785 | ||
c41c2eb4 CS |
786 | if ( $smb eq 'shares') |
787 | {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";} } | |
788 | ||
789 | close FILE; | |
790 | ||
70000894 | 791 | system("/usr/local/bin/sambactrl smbsafeconf"); |
c41c2eb4 | 792 | system("/usr/local/bin/sambactrl smbreload"); |
a4a3e35c | 793 | } |
c41c2eb4 | 794 | |
5e773594 | 795 | sub isrunning |
32f77a0b CS |
796 | { |
797 | my $cmd = $_[0]; | |
798 | my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>"; | |
799 | my $pid = ''; | |
800 | my $testcmd = ''; | |
801 | my $exename; | |
802 | ||
803 | $cmd =~ /(^[a-z]+)/; | |
804 | $exename = $1; | |
805 | ||
806 | if (open(FILE, "/var/run/${cmd}.pid")) | |
807 | { | |
808 | $pid = <FILE>; chomp $pid; | |
809 | close FILE; | |
810 | if (open(FILE, "/proc/${pid}/status")) | |
811 | { | |
812 | while (<FILE>) | |
813 | { | |
814 | if (/^Name:\W+(.*)/) | |
815 | { | |
816 | $testcmd = $1; | |
817 | } | |
818 | } | |
819 | close FILE; | |
820 | if ($testcmd =~ /$exename/) | |
821 | { | |
822 | $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>"; | |
823 | } | |
824 | } | |
825 | } | |
826 | return $status; | |
c41c2eb4 | 827 | } |
0ffbb688 MT |
828 | |
829 | sub joindomain { | |
830 | my $username = shift; | |
831 | my $password = shift; | |
832 | ||
833 | my @options = ("/usr/local/bin/sambactrl", "join", $username, $password); | |
834 | my $output = qx(@options); | |
835 | ||
836 | return $output; | |
837 | } |