]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/samba.cgi
UPNP.CGI hinzugefuegt
[ipfire-2.x.git] / html / cgi-bin / samba.cgi
CommitLineData
5e773594
MT
1#!/usr/bin/perl
2#
3# IPFire CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The IPFire Team
8#
9
10use strict;
11# enable only the following on debugging purpose
12use warnings;
13use CGI::Carp 'fatalsToBrowser';
14
15require '/var/ipfire/general-functions.pl';
16require "${General::swroot}/lang.pl";
17require "${General::swroot}/header.pl";
18
19my %sambasettings = ();
20my %checked = ();
21my %netsettings = ();
97de2cae 22my %ovpnsettings = ();
5e773594
MT
23my $message = "";
24my $errormessage = "";
25my $shareentry = "";
26my @shares = ();
27my @shareline = ();
28my @proto = ();
29my %selected= () ;
30my $sharefile = "/var/ipfire/samba/shares";
31&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
97de2cae 32&General::readhash("${General::swroot}/ovpn/settings", \%ovpnsettings);
5e773594
MT
33
34my %servicenames =
35(
97de2cae
MT
36 'SMB Daemon' => 'smbd',
37 'NetBIOS Nameserver' => 'nmbd',
38 'Winbind Daemon' => 'winbindd'
5e773594
MT
39);
40
41&Header::showhttpheaders();
42
43$sambasettings{'ENABLED'} = 'off';
44$sambasettings{'EDIT'} = 'no';
45$sambasettings{'VALID'} = 'yes';
46$sambasettings{'WORKGRP'} = 'homeip.net';
47$sambasettings{'NETBIOSNAME'} = 'IPFIRE';
48$sambasettings{'SRVSTRING'} = 'Samba Server %v running on IPFire 2.0';
97de2cae 49$sambasettings{'INTERFACES'} = 'eth0';
5e773594
MT
50$sambasettings{'SECURITY'} = 'share';
51$sambasettings{'OSLEVEL'} = '20';
52$sambasettings{'PDC'} = 'off';
97de2cae
MT
53$sambasettings{'GREEN'} = 'on';
54$sambasettings{'BLUE'} = 'off';
55$sambasettings{'ORANGE'} = 'off';
56$sambasettings{'VPN'} = 'off';
5e773594
MT
57$sambasettings{'WINSSERV'} = '';
58$sambasettings{'WINS'} = 'off';
59### Values that have to be initialized
60$sambasettings{'ACTION'} = '';
61
62&General::readhash("${General::swroot}/samba/settings", \%sambasettings);
63&Header::getcgihash(\%sambasettings);
64
65&Header::openpage('Samba', 1, '');
66&Header::openbigbox('100%', 'left', '', $errormessage);
67
68############################################################################################################################
69############################################################################################################################
70
71if ($sambasettings{'ACTION'} eq $Lang::tr{'save'})
72{
97de2cae 73 &General::writehash("${General::swroot}/samba/settings", \%sambasettings);
5e773594
MT
74}
75
76&General::readhash("${General::swroot}/samba/settings", \%sambasettings);
77
78if ($errormessage) {
97de2cae
MT
79 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
80 print "<class name='base'>$errormessage\n";
81 print "&nbsp;</class>\n";
82 &Header::closebox();
5e773594
MT
83}
84
85$checked{'PDC'}{'on'} = '';
86$checked{'PDC'}{'off'} = '';
87$checked{'PDC'}{"$sambasettings{'PDC'}"} = 'checked';
88$checked{'WINS'}{'on'} = '';
89$checked{'WINS'}{'off'} = '';
90$checked{'WINS'}{"$sambasettings{'WINS'}"} = 'checked';
97de2cae
MT
91$checked{'GREEN'}{'on'} = '';
92$checked{'GREEN'}{'off'} = '';
93$checked{'GREEN'}{"$sambasettings{'GREEN'}"} = 'checked';
94$checked{'BLUE'}{'on'} = '';
95$checked{'BLUE'}{'off'} = '';
96$checked{'BLUE'}{"$sambasettings{'BLUE'}"} = 'checked';
97$checked{'ORANGE'}{'on'} = '';
98$checked{'ORANGE'}{'off'} = '';
99$checked{'ORANGE'}{"$sambasettings{'ORANGE'}"} = 'checked';
100$checked{'VPN'}{'on'} = '';
101$checked{'VPN'}{'off'} = '';
102$checked{'VPN'}{"$sambasettings{'VPN'}"} = 'checked';
103
104$selected{'MAPTOGUEST'}{'Never'} = '';
105$selected{'MAPTOGUEST'}{'Bad User'} = '';
106$selected{'MAPTOGUEST'}{'Bad Password'} = '';
107$selected{'MAPTOGUEST'}{$sambasettings{'MAPTOGUEST'}} = "selected='selected'";
108$selected{'SECURITY'}{'share'} = '';
109$selected{'SECURITY'}{'user'} = '';
110$selected{'SECURITY'}{'server'} = '';
111$selected{'SECURITY'}{'domain'} = '';
112$selected{'SECURITY'}{$sambasettings{'SECURITY'}} = "selected='selected'";
5e773594
MT
113
114############################################################################################################################
115############################################################################################################################
116
117&Header::openbox('100%', 'center', 'Samba');
118print <<END
97de2cae 119 <table width='400px' cellspacing='0'>
5e773594
MT
120END
121;
97de2cae
MT
122 if ( $message ne "" ) {
123 print "<tr><td colspan='3' align='center'><font color='red'>$message</font>";
124 }
125
126 my $lines = 0;
127 my $key = '';
128 foreach $key (sort keys %servicenames)
129 {
130 if ($lines % 2) {
131 print "<tr bgcolor='${Header::table1colour}'>\n"; }
132 else {
133 print "<tr bgcolor='${Header::table2colour}'>\n"; }
134 print "<td align='left'>$key</td>\n";
135 my $shortname = $servicenames{$key};
136 my $status = &isrunning($shortname);
137 print "$status\n";
138 print <<END
139 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
140 <input type='hidden' name='ACTION' value='restart $shortname'>
141 <input type='image' src='/images/reload.gif'>
142 </form></td>
5e773594
MT
143END
144;
97de2cae
MT
145 print "</tr>\n";
146 $lines++;
147 }
148 print <<END
149 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
150 <tr><td><b>Alle Dienste:</b></td><td colspan='2'>
151 <input type='submit' name='ACTION' value='Start' />
152 <input type='submit' name='ACTION' value='Stop' />
153 <input type='submit' name='ACTION' value='$Lang::tr{'restart'}' />
154 </td></tr></form>
155 </table>
156 <hr>
157 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
158 <table width='500px'>
159 <tr><td colspan='2' align='left'>
160 <tr><td colspan='2' align='left'>
161 <tr><td colspan='2' align='left'><b>Basisoptionen</b>
162 <tr><td align='left'>Workgroup:<td><input type='text' name='WORKGRP' value='$sambasettings{'WORKGRP'}'>
163 <tr><td align='left'>NetBIOS-Name:<td><input type='text' name='NETBIOSNAME' value='$sambasettings{'NETBIOSNAME'}'>
164 <tr><td align='left'>Server-String:<td><input type='text' name='SRVSTRING' value='$sambasettings{'SRVSTRING'}'>
165 <tr><td align='left'>Interfaces:<td><input type='checkbox' name='VPN' $checked{'VPN'}{'on'}><font size='2' color='$Header::colourovpn'><b> OpenVpn - $ovpnsettings{'DDEVICE'}
166 <tr><td align='left'><td><input type='checkbox' name='GREEN' $checked{'GREEN'}{'on'}><font size='2' color='$Header::colourgreen'><b> $Lang::tr{'green'} - $netsettings{'GREEN_DEV'}
5e773594
MT
167END
168;
97de2cae
MT
169 if (&Header::blue_used()){
170 print <<END
171 <tr><td align='left'><td><input type='checkbox' name='BLUE' $checked{'BLUE'}{'on'}><font size='2' color='$Header::colourblue'><b> $Lang::tr{'wireless'} - $netsettings{'BLUE_DEV'}
5e773594
MT
172END
173;
97de2cae
MT
174 }
175 if (&Header::orange_used()){
176 print <<END
177 <tr><td align='left'><td><input type='checkbox' name='ORANGE' $checked{'ORANGE'}{'on'}><font size='2' color='$Header::colourorange'><b> $Lang::tr{'dmz'} - $netsettings{'ORANGE_DEV'}
178END
179;
180 }
181 print <<END
5e773594 182</select>
97de2cae
MT
183 <tr><td colspan='2' align='left'>
184 <tr><td colspan='2' align='left'>
185 <tr><td colspan='2' align='left'><b>Sicherheitsoptionen</b>
186 <tr><td align='left'>Security:<td><select name='SECURITY'>
187 <option value='share' $selected{'SECURITY'}{'share'}>SHARE</option>
188 <option value='user' $selected{'SECURITY'}{'user'}>USER</option>
189 <option value='server' $selected{'SECURITY'}{'server'}>SERVER</option>
190 <option value='domain' $selected{'SECURITY'}{'domain'}>DOMAIN</option>
191 </select>
192
193 <tr><td colspan='2' align='left'>
194 <tr><td colspan='2' align='left'>
195 <tr><td colspan='2' align='left'><b>Browsingoptionen</b>
196 <tr><td align='left'>OS Level:<td><input type='text' name='OSLEVEL' value='$sambasettings{'OSLEVEL'}'>
197 <tr><td align='left'>Primary Domain Controller:<td>on <input type='radio' name='PDC' value='on' $checked{'PDC'}{'on'}>/
198 <input type='radio' name='PDC' value='off' $checked{'PDC'}{'off'}> off
5e773594 199
97de2cae
MT
200 <tr><td colspan='2' align='left'>
201 <tr><td colspan='2' align='left'>
202 <tr><td colspan='2' align='left'><b>WINS-Optionen</b>
203 <tr><td align='left'>WINS-Server:<td><input type='text' name='WINSSRV' value='$sambasettings{'WINSSRV'}'>
204 <tr><td align='left'>WINS-Support:<td>on <input type='radio' name='WINS' value='on' $checked{'WINS'}{'on'}>/
205 <input type='radio' name='WINS' value='off' $checked{'WINS'}{'off'}> off
206
207 <tr><td colspan='1' align='right'><input type='submit' name='ACTION' value=$Lang::tr{'save'}>
208 </table>
209 </form>
5e773594
MT
210END
211;
212&Header::closebox();
213
214&Header::openbox('100%', 'center', 'Shares');
215
216print <<END
97de2cae
MT
217 <hr>
218 <table width='500'>
219 <tr><th width='40%'>Name der Freigabe<th width='40%'>Pfad<th width='20%'>Optionen
220END
221;
222 open( FILE, "< $sharefile" ) or die "Unable to read $sharefile";
223 @shares = <FILE>;
224 close FILE;
225 foreach $shareentry (sort @shares)
226 {
227 @shareline = split( /\;/, $shareentry );
228 print <<END
229 <tr><td align='center' bgcolor='#EAEAEA'><b>$shareline[0]</b>
230 <td align='center' bgcolor='#EAEAEA'>$shareline[2]
231 <td align='right' bgcolor='#EAEAEA'>
232 <table border='0'><tr>
5e773594
MT
233END
234;
97de2cae
MT
235 if ($shareline[1] eq 'enabled') {
236 print <<END
237 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
238 <input type='hidden' name='NAME' value='shareline[0]'>
239 <input type='hidden' name='ACTION' value='disable'>
240 <input type='image' alt='Ausschalten' src='/images/on.gif'>
241 </form>
5e773594
MT
242END
243;
97de2cae
MT
244 } elsif ($shareline[1] eq 'disabled') {
245 print <<END
246 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
247 <input type='hidden' name='NAME' value='shareline[0]'>
248 <input type='hidden' name='ACTION' value='enable'>
249 <input type='image' alt='Einschalten' src='/images/off.gif'>
250 </form>
5e773594
MT
251END
252;
97de2cae
MT
253 }
254 print <<END
255 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
256 <input type='hidden' name='NAME' value='shareline[0]'>
257 <input type='hidden' name='ACTION' value='Bearbeiten'>
258 <input type='image' alt='Bearbeiten' src='/images/edit.gif'>
259 </form>
260 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
261 <input type='hidden' name='NAME' value='shareline[0]'>
262 <input type='hidden' name='ACTION' value='Loeschen'>
263 <input type='image' alt='Loeschen' src='/images/delete.gif'>
264 </form>
265 </table>
5e773594
MT
266END
267;
97de2cae
MT
268 }
269 print <<END
270 <tr><td colspan='8' align='right' valign='middle'><b>Legende:</b>&nbsp;&nbsp;<img src='/images/edit.gif'>&nbsp;Freigabe bearbeiten | <img src='/images/delete.gif'>&nbsp;Freigabe loeschen &nbsp;
271 </table>
5e773594
MT
272END
273;
97de2cae
MT
274
275&Header::closebox();
276
277
278if ($sambasettings{'SECURITY'} eq 'user')
279{
280&Header::openbox('100%', 'center', 'User');
281
282print <<END
283 <hr>
284 <table width='500'>
285 <tr><td colspan='2' align='left'>
286 <tr><td colspan='2' align='left'><b>Benutzerverwaltung</b>
287 </table>
5e773594
MT
288END
289;
290
291&Header::closebox();
97de2cae 292}
5e773594
MT
293
294&Header::closebigbox();
295&Header::closepage();
296
297############################################################################################################################
298############################################################################################################################
299
300sub isrunning
301{
97de2cae
MT
302 my $cmd = $_[0];
303 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
304 my $pid = '';
305 my $testcmd = '';
306 my $exename;
307
308 $cmd =~ /(^[a-z]+)/;
309 $exename = $1;
5e773594 310
97de2cae
MT
311 if (open(FILE, "/var/run/${cmd}.pid"))
312 {
313 $pid = <FILE>; chomp $pid;
314 close FILE;
315 if (open(FILE, "/proc/${pid}/status"))
316 {
317 while (<FILE>)
318 {
319 if (/^Name:\W+(.*)/) {
320 $testcmd = $1; }
321 }
322 close FILE;
323 if ($testcmd =~ /$exename/)
324 {
325 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
326 }
327 }
328 }
329
330 return $status;
331}